You are here

public function ContextHandlerTest::testApplyContextMapping in Drupal 10

Same name in this branch
  1. 10 core/tests/Drupal/Tests/Core/Plugin/ContextHandlerTest.php \Drupal\Tests\Core\Plugin\ContextHandlerTest::testApplyContextMapping()
  2. 10 core/tests/Drupal/KernelTests/Core/Plugin/ContextHandlerTest.php \Drupal\KernelTests\Core\Plugin\ContextHandlerTest::testApplyContextMapping()
Same name and namespace in other branches
  1. 8 core/tests/Drupal/KernelTests/Core/Plugin/ContextHandlerTest.php \Drupal\KernelTests\Core\Plugin\ContextHandlerTest::testApplyContextMapping()
  2. 9 core/tests/Drupal/KernelTests/Core/Plugin/ContextHandlerTest.php \Drupal\KernelTests\Core\Plugin\ContextHandlerTest::testApplyContextMapping()

@covers ::applyContextMapping

File

core/tests/Drupal/KernelTests/Core/Plugin/ContextHandlerTest.php, line 32

Class

ContextHandlerTest
@coversDefaultClass \Drupal\Core\Plugin\Context\ContextHandler

Namespace

Drupal\KernelTests\Core\Plugin

Code

public function testApplyContextMapping() {
  $entity = EntityTest::create([]);
  $context_definition = EntityContextDefinition::fromEntity($entity);
  $context = EntityContext::fromEntity($entity);
  $definition = [
    'context_definitions' => [
      'a_context_id' => $context_definition,
    ],
  ];
  $plugin = new TestContextAwarePlugin([], 'test_plugin_id', $definition);
  (new ContextHandler())
    ->applyContextMapping($plugin, [
    'a_context_id' => $context,
  ]);
  $result = $plugin
    ->getContext('a_context_id');
  $this
    ->assertInstanceOf(EntityContext::class, $result);
  $this
    ->assertSame($context, $result);
}