You are here

public function ThemeNegotiatorTest::testDetermineActiveThemeWithPriority in Drupal 8

Same name and namespace in other branches
  1. 9 core/tests/Drupal/Tests/Core/Theme/ThemeNegotiatorTest.php \Drupal\Tests\Core\Theme\ThemeNegotiatorTest::testDetermineActiveThemeWithPriority()

Tests determining with two negotiators checking the priority.

See also

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

File

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

Class

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

Namespace

Drupal\Tests\Core\Theme

Code

public function testDetermineActiveThemeWithPriority() {
  $negotiators = [];
  $negotiator = $this
    ->createMock('Drupal\\Core\\Theme\\ThemeNegotiatorInterface');
  $negotiator
    ->expects($this
    ->once())
    ->method('determineActiveTheme')
    ->will($this
    ->returnValue('example_test'));
  $negotiator
    ->expects($this
    ->once())
    ->method('applies')
    ->will($this
    ->returnValue(TRUE));
  $negotiators['test_negotiator_1'] = $negotiator;
  $negotiator = $this
    ->createMock('Drupal\\Core\\Theme\\ThemeNegotiatorInterface');
  $negotiator
    ->expects($this
    ->never())
    ->method('determineActiveTheme');
  $negotiator
    ->expects($this
    ->never())
    ->method('applies');
  $negotiators['test_negotiator_2'] = $negotiator;
  foreach ($negotiators as $id => $negotiator) {
    $this->container
      ->set($id, $negotiator);
  }
  $this->themeAccessCheck
    ->expects($this
    ->any())
    ->method('checkAccess')
    ->will($this
    ->returnValue(TRUE));
  $route_match = new RouteMatch('test_route', new Route('/test-route'), [], []);
  $theme = $this
    ->createThemeNegotiator(array_keys($negotiators))
    ->determineActiveTheme($route_match);
  $this
    ->assertEquals('example_test', $theme);
}