You are here

public function RegistryTest::test40xThemeSuggestions in Drupal 8

Same name and namespace in other branches
  1. 9 core/tests/Drupal/KernelTests/Core/Theme/RegistryTest.php \Drupal\KernelTests\Core\Theme\RegistryTest::test40xThemeSuggestions()

Tests page theme suggestions for 40x responses.

@dataProvider provider40xThemeSuggestions

File

core/tests/Drupal/KernelTests/Core/Theme/RegistryTest.php, line 206

Class

RegistryTest
Tests the behavior of the ThemeRegistry class.

Namespace

Drupal\KernelTests\Core\Theme

Code

public function test40xThemeSuggestions($route, $suggestion) {

  /** @var \Drupal\Core\Path\PathMatcherInterface $path_matcher */
  $path_matcher = $this
    ->prophesize(PathMatcherInterface::class);
  $path_matcher
    ->isFrontPage()
    ->willReturn(FALSE);
  \Drupal::getContainer()
    ->set('path.matcher', $path_matcher
    ->reveal());

  /** @var \Drupal\Core\Path\CurrentPathStack $path_current */
  $path_current = $this
    ->prophesize(CurrentPathStack::class);
  $path_current
    ->getPath()
    ->willReturn('/node/123');
  \Drupal::getContainer()
    ->set('path.current', $path_current
    ->reveal());

  /** @var \Drupal\Core\Routing\RouteMatchInterface $route_matcher */
  $route_matcher = $this
    ->prophesize(RouteMatchInterface::class);
  $route_matcher
    ->getRouteName()
    ->willReturn($route);
  \Drupal::getContainer()
    ->set('current_route_match', $route_matcher
    ->reveal());
  $suggestions = \Drupal::moduleHandler()
    ->invokeAll('theme_suggestions_page', [
    [],
  ]);
  $this
    ->assertSame([
    'page__node',
    'page__node__%',
    'page__node__123',
    'page__4xx',
    $suggestion,
  ], $suggestions);
}