function ContextHandlerTest::testFilterPluginDefinitionsByContexts

Same name in other branches
  1. 9 core/tests/Drupal/Tests/Core/Plugin/ContextHandlerTest.php \Drupal\Tests\Core\Plugin\ContextHandlerTest::testFilterPluginDefinitionsByContexts()
  2. 8.9.x 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 175

Class

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

Namespace

Drupal\Tests\Core\Plugin

Code

public function testFilterPluginDefinitionsByContexts($has_context, $definitions, $expected) : void {
    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.