function ContextHandlerTest::testApplyContextMappingConfigurableAssigned

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

@covers ::applyContextMapping

File

core/tests/Drupal/Tests/Core/Plugin/ContextHandlerTest.php, line 496

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> @group Plugin

Namespace

Drupal\Tests\Core\Plugin

Code

public function testApplyContextMappingConfigurableAssigned() {
    $context = $this->createMock('Drupal\\Core\\Plugin\\Context\\ContextInterface');
    $context->expects($this->atLeastOnce())
        ->method('hasContextValue')
        ->willReturn(TRUE);
    $contexts = [
        'name' => $context,
    ];
    $context_definition = $this->createMock('Drupal\\Core\\Plugin\\Context\\ContextDefinitionInterface');
    $plugin = $this->createMock('Drupal\\Tests\\Core\\Plugin\\TestConfigurableContextAwarePluginInterface');
    $plugin->expects($this->once())
        ->method('getContextMapping')
        ->willReturn([]);
    $plugin->expects($this->once())
        ->method('getContextDefinitions')
        ->will($this->returnValue([
        'hit' => $context_definition,
    ]));
    $plugin->expects($this->once())
        ->method('setContext')
        ->with('hit', $context);
    // Make sure that the cacheability metadata is passed to the plugin context.
    $plugin_context = $this->createMock('Drupal\\Core\\Plugin\\Context\\ContextInterface');
    $plugin_context->expects($this->once())
        ->method('addCacheableDependency')
        ->with($context);
    $plugin->expects($this->once())
        ->method('getContext')
        ->with('hit')
        ->willReturn($plugin_context);
    $this->contextHandler
        ->applyContextMapping($plugin, $contexts, [
        'hit' => 'name',
    ]);
}

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