function ThemeNegotiatorTest::testDetermineActiveThemeWithAccessCheck

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

Tests determining with two negotiators of which just one returns access.

See also

\Drupal\Core\Theme\ThemeNegotiator::determineActiveTheme()

File

core/tests/Drupal/Tests/Core/Theme/ThemeNegotiatorTest.php, line 133

Class

ThemeNegotiatorTest
@coversDefaultClass \Drupal\Core\Theme\ThemeNegotiator @group Theme

Namespace

Drupal\Tests\Core\Theme

Code

public function testDetermineActiveThemeWithAccessCheck() : void {
    $negotiators = [];
    $negotiator = $this->createMock('Drupal\\Core\\Theme\\ThemeNegotiatorInterface');
    $negotiator->expects($this->once())
        ->method('determineActiveTheme')
        ->willReturn('example_test');
    $negotiator->expects($this->once())
        ->method('applies')
        ->willReturn(TRUE);
    $negotiators['test_negotiator_1'] = $negotiator;
    $negotiator = $this->createMock('Drupal\\Core\\Theme\\ThemeNegotiatorInterface');
    $negotiator->expects($this->once())
        ->method('determineActiveTheme')
        ->willReturn('example_test2');
    $negotiator->expects($this->once())
        ->method('applies')
        ->willReturn(TRUE);
    $negotiators['test_negotiator_2'] = $negotiator;
    foreach ($negotiators as $id => $negotiator) {
        $this->container
            ->set($id, $negotiator);
    }
    $this->themeAccessCheck
        ->expects($this->exactly(2))
        ->method('checkAccess')
        ->willReturnMap([
        [
            'example_test',
            FALSE,
        ],
        [
            'example_test2',
            TRUE,
        ],
    ]);
    $route_match = new RouteMatch('test_route', new Route('/test-route'), [], []);
    $theme = $this->createThemeNegotiator(array_keys($negotiators))
        ->determineActiveTheme($route_match);
    $this->assertEquals('example_test2', $theme);
}

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