function RegistryTest::testThemeSuggestions

Same name in other branches
  1. 8.9.x core/tests/Drupal/KernelTests/Core/Theme/RegistryTest.php \Drupal\KernelTests\Core\Theme\RegistryTest::testThemeSuggestions()
  2. 10 core/tests/Drupal/KernelTests/Core/Theme/RegistryTest.php \Drupal\KernelTests\Core\Theme\RegistryTest::testThemeSuggestions()
  3. 11.x core/tests/Drupal/KernelTests/Core/Theme/RegistryTest.php \Drupal\KernelTests\Core\Theme\RegistryTest::testThemeSuggestions()

Tests front node theme suggestion generation.

File

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

Class

RegistryTest
Tests the behavior of the ThemeRegistry class.

Namespace

Drupal\KernelTests\Core\Theme

Code

public function testThemeSuggestions() {
    // Mock the current page as the front page.
    
    /** @var \Drupal\Core\Path\PathMatcherInterface $path_matcher */
    $path_matcher = $this->prophesize(PathMatcherInterface::class);
    $path_matcher->isFrontPage()
        ->willReturn(TRUE);
    $this->container
        ->set('path.matcher', $path_matcher->reveal());
    
    /** @var \Drupal\Core\Path\CurrentPathStack $path_matcher */
    $path_current = $this->prophesize(CurrentPathStack::class);
    $path_current->getPath()
        ->willReturn('/node/1');
    $this->container
        ->set('path.current', $path_current->reveal());
    // Check suggestions provided through hook_theme_suggestions_html().
    $suggestions = \Drupal::moduleHandler()->invokeAll('theme_suggestions_html', [
        [],
    ]);
    $this->assertSame([
        'html__node',
        'html__node__%',
        'html__node__1',
        'html__front',
    ], $suggestions, 'Found expected html node suggestions.');
    // Check suggestions provided through hook_theme_suggestions_page().
    $suggestions = \Drupal::moduleHandler()->invokeAll('theme_suggestions_page', [
        [],
    ]);
    $this->assertSame([
        'page__node',
        'page__node__%',
        'page__node__1',
        'page__front',
    ], $suggestions, 'Found expected page node suggestions.');
}

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