function ContextDefinitionTest::testConstraints

Same name and namespace in other branches
  1. 9 core/tests/Drupal/KernelTests/Core/Plugin/Annotation/ContextDefinitionTest.php \Drupal\KernelTests\Core\Plugin\Annotation\ContextDefinitionTest::testConstraints()
  2. 10 core/tests/Drupal/KernelTests/Core/Plugin/Annotation/ContextDefinitionTest.php \Drupal\KernelTests\Core\Plugin\Annotation\ContextDefinitionTest::testConstraints()
  3. 11.x core/tests/Drupal/KernelTests/Core/Plugin/Annotation/ContextDefinitionTest.php \Drupal\KernelTests\Core\Plugin\Annotation\ContextDefinitionTest::testConstraints()

Tests adding constraints via annotations.

File

core/tests/Drupal/KernelTests/Core/Plugin/Annotation/ContextDefinitionTest.php, line 22

Class

ContextDefinitionTest
@coversDefaultClass <a href="/api/drupal/core%21lib%21Drupal%21Core%21Annotation%21ContextDefinition.php/class/ContextDefinition/8.9.x" title="Defines a context definition annotation object." class="local">\Drupal\Core\Annotation\ContextDefinition</a> @group Plugin

Namespace

Drupal\KernelTests\Core\Plugin\Annotation

Code

public function testConstraints() {
    $definition = $this->container
        ->get('plugin.manager.block')
        ->getDefinition('test_context_aware');
    $this->assertArrayHasKey('context_definitions', $definition);
    $this->assertArrayHasKey('user', $definition['context_definitions']);
    $this->assertInstanceOf(ContextDefinition::class, $definition['context_definitions']['user']);
    $this->assertEquals([
        'NotNull' => [],
    ], $definition['context_definitions']['user']->getConstraints());
    $this->assertEquals("User Context", $definition['context_definitions']['user']->getLabel());
}

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