function ContextHandlerTest::testApplyContextMappingMissingNotRequired

Same name and namespace in other branches
  1. 8.9.x core/tests/Drupal/Tests/Core/Plugin/ContextHandlerTest.php \Drupal\Tests\Core\Plugin\ContextHandlerTest::testApplyContextMappingMissingNotRequired()
  2. 10 core/tests/Drupal/Tests/Core/Plugin/ContextHandlerTest.php \Drupal\Tests\Core\Plugin\ContextHandlerTest::testApplyContextMappingMissingNotRequired()
  3. 11.x 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 393

Class

ContextHandlerTest
@coversDefaultClass <a href="/api/drupal/core%21lib%21Drupal%21Core%21Plugin%21Context%21ContextHandler.php/class/ContextHandler/9" 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 testApplyContextMappingMissingNotRequired() {
    $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(FALSE);
    $plugin = $this->createMock('Drupal\\Tests\\Core\\Plugin\\TestConfigurableContextAwarePluginInterface');
    $plugin->expects($this->once())
        ->method('getContextMapping')
        ->willReturn([
        'optional' => 'missing',
    ]);
    $plugin->expects($this->once())
        ->method('getContextDefinitions')
        ->willReturn([
        'optional' => $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->contextHandler
        ->applyContextMapping($plugin, $contexts);
}

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