public function ContextHandlerTest::testApplyContextMappingMissingRequired in Drupal 10
Same name and namespace in other branches
- 8 core/tests/Drupal/Tests/Core/Plugin/ContextHandlerTest.php \Drupal\Tests\Core\Plugin\ContextHandlerTest::testApplyContextMappingMissingRequired()
- 9 core/tests/Drupal/Tests/Core/Plugin/ContextHandlerTest.php \Drupal\Tests\Core\Plugin\ContextHandlerTest::testApplyContextMappingMissingRequired()
@covers ::applyContextMapping
File
- core/
tests/ Drupal/ Tests/ Core/ Plugin/ ContextHandlerTest.php, line 356 - Contains \Drupal\Tests\Core\Plugin\ContextHandlerTest.
Class
- ContextHandlerTest
- @coversDefaultClass \Drupal\Core\Plugin\Context\ContextHandler @group Plugin
Namespace
Drupal\Tests\Core\PluginCode
public function testApplyContextMappingMissingRequired() {
$context = $this
->createMock('Drupal\\Core\\Plugin\\Context\\ContextInterface');
$context
->expects($this
->never())
->method('getContextValue');
$contexts = [
'name' => $context,
];
$context_definition = $this
->createMock('Drupal\\Core\\Plugin\\Context\\ContextDefinitionInterface');
$context_definition
->expects($this
->atLeastOnce())
->method('isRequired')
->willReturn(TRUE);
$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');
// No context, so no cacheability metadata can be passed along.
$plugin
->expects($this
->any())
->method('getContext')
->willThrowException(new ContextException());
$this
->expectException(MissingValueContextException::class);
$this
->expectExceptionMessage('Required contexts without a value: hit');
$this->contextHandler
->applyContextMapping($plugin, $contexts);
}