function ContextHandlerTest::testFilterPluginDefinitionsByContexts

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

@covers ::filterPluginDefinitionsByContexts

@dataProvider providerTestFilterPluginDefinitionsByContexts

File

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

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 testFilterPluginDefinitionsByContexts($has_context, $definitions, $expected) {
    if ($has_context) {
        $context = $this->createMock('Drupal\\Core\\Plugin\\Context\\ContextInterface');
        $expected_context_definition = (new ContextDefinition('string'))->setConstraints([
            'Blank' => [],
        ]);
        $context->expects($this->atLeastOnce())
            ->method('getContextDefinition')
            ->willReturn($expected_context_definition);
        $contexts = [
            $context,
        ];
    }
    else {
        $contexts = [];
    }
    $this->assertSame($expected, $this->contextHandler
        ->filterPluginDefinitionsByContexts($contexts, $definitions));
}

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