function RegistryTest::test40xThemeSuggestions

Same name and namespace in other branches
  1. 8.9.x core/tests/Drupal/KernelTests/Core/Theme/RegistryTest.php \Drupal\KernelTests\Core\Theme\RegistryTest::test40xThemeSuggestions()
  2. 10 core/tests/Drupal/KernelTests/Core/Theme/RegistryTest.php \Drupal\KernelTests\Core\Theme\RegistryTest::test40xThemeSuggestions()
  3. 11.x 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 214

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);
}

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