function ContextHandlerTest::testApplyContextMappingAlreadyApplied

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

@covers ::applyContextMapping

File

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

Class

ContextHandlerTest
@coversDefaultClass <a href="/api/drupal/core%21lib%21Drupal%21Core%21Plugin%21Context%21ContextHandler.php/class/ContextHandler/8.9.x" title="Provides methods to handle sets of contexts." class="local">\Drupal\Core\Plugin\Context\ContextHandler</a>

Namespace

Drupal\KernelTests\Core\Plugin

Code

public function testApplyContextMappingAlreadyApplied() {
    $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);
    $plugin->setContext('a_context_id', $context);
    (new ContextHandler())->applyContextMapping($plugin, []);
    $result = $plugin->getContext('a_context_id');
    $this->assertInstanceOf(EntityContext::class, $result);
    $this->assertSame($context, $result);
}

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