public function ContextHandlerTest::testApplyContextMappingMissingNotRequired in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/tests/Drupal/Tests/Core/Plugin/ContextHandlerTest.php \Drupal\Tests\Core\Plugin\ContextHandlerTest::testApplyContextMappingMissingNotRequired()
@covers ::applyContextMapping
File
- core/tests/ Drupal/ Tests/ Core/ Plugin/ ContextHandlerTest.php, line 320 
- Contains \Drupal\Tests\Core\Plugin\ContextHandlerTest.
Class
- ContextHandlerTest
- @coversDefaultClass \Drupal\Core\Plugin\Context\ContextHandler @group Plugin
Namespace
Drupal\Tests\Core\PluginCode
public function testApplyContextMappingMissingNotRequired() {
  $context = $this
    ->getMock('Drupal\\Core\\Plugin\\Context\\ContextInterface');
  $context
    ->expects($this
    ->never())
    ->method('getContextValue');
  $contexts = array(
    'name' => $context,
  );
  $context_definition = $this
    ->getMock('Drupal\\Core\\Plugin\\Context\\ContextDefinitionInterface');
  $context_definition
    ->expects($this
    ->atLeastOnce())
    ->method('isRequired')
    ->willReturn(FALSE);
  $plugin = $this
    ->getMock('Drupal\\Tests\\Core\\Plugin\\TestConfigurableContextAwarePluginInterface');
  $plugin
    ->expects($this
    ->once())
    ->method('getContextMapping')
    ->willReturn([
    'optional' => 'missing',
  ]);
  $plugin
    ->expects($this
    ->once())
    ->method('getContextDefinitions')
    ->will($this
    ->returnValue(array(
    'optional' => $context_definition,
  )));
  $plugin
    ->expects($this
    ->never())
    ->method('setContextValue');
  // No context, so no cacheability metadata can be passed along.
  $plugin
    ->expects($this
    ->never())
    ->method('getContext');
  $this->contextHandler
    ->applyContextMapping($plugin, $contexts);
}