ContextDefinitionTest.php

Same filename in this branch
  1. 8.9.x core/tests/Drupal/KernelTests/Core/Plugin/Annotation/ContextDefinitionTest.php
  2. 8.9.x core/tests/Drupal/Tests/Core/Plugin/Context/ContextDefinitionTest.php
Same filename in other branches
  1. 9 core/tests/Drupal/KernelTests/Core/Plugin/ContextDefinitionTest.php
  2. 9 core/tests/Drupal/KernelTests/Core/Plugin/Annotation/ContextDefinitionTest.php
  3. 9 core/tests/Drupal/Tests/Core/Plugin/Context/ContextDefinitionTest.php
  4. 10 core/tests/Drupal/KernelTests/Core/Plugin/ContextDefinitionTest.php
  5. 10 core/tests/Drupal/KernelTests/Core/Plugin/Annotation/ContextDefinitionTest.php
  6. 10 core/tests/Drupal/Tests/Core/Plugin/Context/ContextDefinitionTest.php
  7. 11.x core/tests/Drupal/KernelTests/Core/Plugin/ContextDefinitionTest.php
  8. 11.x core/tests/Drupal/KernelTests/Core/Plugin/Annotation/ContextDefinitionTest.php
  9. 11.x core/tests/Drupal/Tests/Core/Plugin/Context/ContextDefinitionTest.php

Namespace

Drupal\KernelTests\Core\Plugin

File

core/tests/Drupal/KernelTests/Core/Plugin/ContextDefinitionTest.php

View source
<?php

namespace Drupal\KernelTests\Core\Plugin;

use Drupal\Core\Plugin\Context\ContextDefinition;
use Drupal\Core\Plugin\Context\EntityContext;
use Drupal\entity_test\Entity\EntityTest;
use Drupal\KernelTests\KernelTestBase;

/**
 * @coversDefaultClass \Drupal\Core\Plugin\Context\ContextDefinition
 * @group Plugin
 */
class ContextDefinitionTest extends KernelTestBase {
    
    /**
     * {@inheritdoc}
     */
    public static $modules = [
        'entity_test',
        'user',
    ];
    
    /**
     * @covers ::isSatisfiedBy
     */
    public function testIsSatisfiedBy() {
        $this->installEntitySchema('user');
        $value = EntityTest::create([]);
        // Assert that the entity has at least one violation.
        $this->assertNotEmpty($value->validate());
        // Assert that these violations do not prevent it from satisfying the
        // requirements of another object.
        $requirement = new ContextDefinition('any');
        $context = EntityContext::fromEntity($value);
        $this->assertTrue($requirement->isSatisfiedBy($context));
    }

}

Classes

Title Deprecated Summary
ContextDefinitionTest @coversDefaultClass \Drupal\Core\Plugin\Context\ContextDefinition @group Plugin

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.