function ContextHandlerTest::testApplyContextMappingNoValueRequired

Same name in other branches
  1. 9 core/tests/Drupal/Tests/Core/Plugin/ContextHandlerTest.php \Drupal\Tests\Core\Plugin\ContextHandlerTest::testApplyContextMappingNoValueRequired()
  2. 8.9.x core/tests/Drupal/Tests/Core/Plugin/ContextHandlerTest.php \Drupal\Tests\Core\Plugin\ContextHandlerTest::testApplyContextMappingNoValueRequired()
  3. 11.x core/tests/Drupal/Tests/Core/Plugin/ContextHandlerTest.php \Drupal\Tests\Core\Plugin\ContextHandlerTest::testApplyContextMappingNoValueRequired()

@covers ::applyContextMapping

File

core/tests/Drupal/Tests/Core/Plugin/ContextHandlerTest.php, line 415

Class

ContextHandlerTest
@coversDefaultClass \Drupal\Core\Plugin\Context\ContextHandler @group Plugin

Namespace

Drupal\Tests\Core\Plugin

Code

public function testApplyContextMappingNoValueRequired() : void {
    $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(TRUE);
    $plugin = $this->createMock('Drupal\\Tests\\Core\\Plugin\\TestConfigurableContextAwarePluginInterface');
    $plugin->expects($this->once())
        ->method('getContextMapping')
        ->willReturn([]);
    $plugin->expects($this->once())
        ->method('getContextDefinitions')
        ->willReturn([
        'hit' => $context_definition,
    ]);
    $plugin->expects($this->never())
        ->method('setContext');
    $this->expectException(MissingValueContextException::class);
    $this->expectExceptionMessage('Required contexts without a value: hit');
    $this->contextHandler
        ->applyContextMapping($plugin, $contexts);
}

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