function ContextHandlerTest::testApplyContextMapping
Same name in this branch
- 8.9.x core/tests/Drupal/KernelTests/Core/Plugin/ContextHandlerTest.php \Drupal\KernelTests\Core\Plugin\ContextHandlerTest::testApplyContextMapping()
Same name in other branches
- 9 core/tests/Drupal/KernelTests/Core/Plugin/ContextHandlerTest.php \Drupal\KernelTests\Core\Plugin\ContextHandlerTest::testApplyContextMapping()
- 9 core/tests/Drupal/Tests/Core/Plugin/ContextHandlerTest.php \Drupal\Tests\Core\Plugin\ContextHandlerTest::testApplyContextMapping()
- 10 core/tests/Drupal/KernelTests/Core/Plugin/ContextHandlerTest.php \Drupal\KernelTests\Core\Plugin\ContextHandlerTest::testApplyContextMapping()
- 10 core/tests/Drupal/Tests/Core/Plugin/ContextHandlerTest.php \Drupal\Tests\Core\Plugin\ContextHandlerTest::testApplyContextMapping()
- 11.x core/tests/Drupal/KernelTests/Core/Plugin/ContextHandlerTest.php \Drupal\KernelTests\Core\Plugin\ContextHandlerTest::testApplyContextMapping()
- 11.x core/tests/Drupal/Tests/Core/Plugin/ContextHandlerTest.php \Drupal\Tests\Core\Plugin\ContextHandlerTest::testApplyContextMapping()
@covers ::applyContextMapping
File
-
core/
tests/ Drupal/ Tests/ Core/ Plugin/ ContextHandlerTest.php, line 315
Class
- ContextHandlerTest
- @coversDefaultClass \Drupal\Core\Plugin\Context\ContextHandler @group Plugin
Namespace
Drupal\Tests\Core\PluginCode
public function testApplyContextMapping() {
$context_hit = $this->createMock('Drupal\\Core\\Plugin\\Context\\ContextInterface');
$context_hit->expects($this->atLeastOnce())
->method('hasContextValue')
->willReturn(TRUE);
$context_miss = $this->createMock('Drupal\\Core\\Plugin\\Context\\ContextInterface');
$contexts = [
'hit' => $context_hit,
'miss' => $context_miss,
];
$context_definition = $this->createMock('Drupal\\Core\\Plugin\\Context\\ContextDefinitionInterface');
$plugin = $this->createMock('Drupal\\Core\\Plugin\\ContextAwarePluginInterface');
$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_hit);
// 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_hit);
$plugin->expects($this->once())
->method('getContext')
->with('hit')
->willReturn($plugin_context);
$this->contextHandler
->applyContextMapping($plugin, $contexts);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.