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. 8.9.x 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 24

Class

ContextDefinitionTest
@coversDefaultClass \Drupal\Core\Annotation\ContextDefinition[[api-linebreak]] @group Plugin

Namespace

Drupal\KernelTests\Core\Plugin\Annotation

Code

public function testConstraints() : void {
  $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.