public function ContextHandlerTest::testApplyContextMappingNoValueNonRequired in Drupal 9
Same name and namespace in other branches
- 8 core/tests/Drupal/Tests/Core/Plugin/ContextHandlerTest.php \Drupal\Tests\Core\Plugin\ContextHandlerTest::testApplyContextMappingNoValueNonRequired()
@covers ::applyContextMapping
File
- core/
tests/ Drupal/ Tests/ Core/ Plugin/ ContextHandlerTest.php, line 463 - Contains \Drupal\Tests\Core\Plugin\ContextHandlerTest.
Class
- ContextHandlerTest
- @coversDefaultClass \Drupal\Core\Plugin\Context\ContextHandler @group Plugin
Namespace
Drupal\Tests\Core\PluginCode
public function testApplyContextMappingNoValueNonRequired() {
$context = $this
->createMock('Drupal\\Core\\Plugin\\Context\\ContextInterface');
$context
->expects($this
->never())
->method('getContextValue');
$context
->expects($this
->atLeastOnce())
->method('hasContextValue')
->willReturn(FALSE);
$contexts = [
'hit' => $context,
];
$context_definition = $this
->createMock('Drupal\\Core\\Plugin\\Context\\ContextDefinitionInterface');
$context_definition
->expects($this
->atLeastOnce())
->method('isRequired')
->willReturn(FALSE);
$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
->never())
->method('setContext');
$this->contextHandler
->applyContextMapping($plugin, $contexts);
}