ContextDefinitionTest.php

Same filename in this branch
  1. 9 core/tests/Drupal/KernelTests/Core/Plugin/ContextDefinitionTest.php
  2. 9 core/tests/Drupal/Tests/Core/Plugin/Context/ContextDefinitionTest.php
Same filename and directory in other branches
  1. 8.9.x core/tests/Drupal/KernelTests/Core/Plugin/ContextDefinitionTest.php
  2. 8.9.x core/tests/Drupal/KernelTests/Core/Plugin/Annotation/ContextDefinitionTest.php
  3. 8.9.x 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\Annotation

File

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

View source
<?php

namespace Drupal\KernelTests\Core\Plugin\Annotation;

use Drupal\Core\Plugin\Context\ContextDefinition;
use Drupal\KernelTests\KernelTestBase;

/**
 * @coversDefaultClass \Drupal\Core\Annotation\ContextDefinition
 * @group Plugin
 */
class ContextDefinitionTest extends KernelTestBase {
  
  /**
   * {@inheritdoc}
   */
  protected static $modules = [
    'block_test',
  ];
  
  /**
   * Tests adding constraints via annotations.
   */
  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());
  }

}

Classes

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

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