function RegistryTest::test40xThemeSuggestions

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

Class

RegistryTest
Tests the behavior of the ThemeRegistry class.

Namespace

Drupal\KernelTests\Core\Theme

Code

public function test40xThemeSuggestions(int $httpCode, string $suggestion) : void {
    $path_matcher = $this->prophesize(PathMatcherInterface::class);
    $path_matcher->isFrontPage()
        ->willReturn(FALSE);
    \Drupal::getContainer()->set('path.matcher', $path_matcher->reveal());
    $path_current = $this->prophesize(CurrentPathStack::class);
    $path_current->getPath()
        ->willReturn('/node/123');
    \Drupal::getContainer()->set('path.current', $path_current->reveal());
    $exception = $this->prophesize(HttpExceptionInterface::class);
    $exception->getStatusCode()
        ->willReturn($httpCode);
    \Drupal::requestStack()->getCurrentRequest()->attributes
        ->set('exception', $exception->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.