function ContextHandlerTest::testGetMatchingContexts

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

@covers ::getMatchingContexts

@dataProvider providerTestGetMatchingContexts

File

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

Class

ContextHandlerTest
@coversDefaultClass <a href="/api/drupal/core%21lib%21Drupal%21Core%21Plugin%21Context%21ContextHandler.php/class/ContextHandler/11.x" 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 testGetMatchingContexts($contexts, $requirement, $expected = NULL) : void {
    $contexts = array_map(function ($context) {
        $mock = $this->createMock('Drupal\\Core\\Plugin\\Context\\ContextInterface');
        $mock->expects($this->atLeastOnce())
            ->method('getContextDefinition')
            ->willReturn($context);
        return $mock;
    }, $contexts);
    if (is_null($expected)) {
        $expected = $contexts;
    }
    $this->assertSame($expected, $this->contextHandler
        ->getMatchingContexts($contexts, $requirement));
}

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