You are here

public function ThemeLegacyTest::testSuggestionsAlterInclude in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/system/tests/src/Functional/Theme/ThemeLegacyTest.php \Drupal\Tests\system\Functional\Theme\ThemeLegacyTest::testSuggestionsAlterInclude()

Tests that theme suggestion alter hooks work with theme hook includes.

File

core/modules/system/tests/src/Functional/Theme/ThemeLegacyTest.php, line 67

Class

ThemeLegacyTest
Tests legacy theme functions.

Namespace

Drupal\Tests\system\Functional\Theme

Code

public function testSuggestionsAlterInclude() {

  // Check the original theme output.
  $this
    ->drupalGet('theme-test/suggestion-alter-include');
  $this
    ->assertSession()
    ->pageTextContains('Original function before altering theme suggestions.');

  // Enable theme_suggestions_test module and make two requests to make sure
  // the include file is always loaded. The file will always be included for
  // the first request because the theme registry is being rebuilt.
  \Drupal::service('module_installer')
    ->install([
    'theme_legacy_suggestions_test',
  ]);
  $this
    ->resetAll();
  $this
    ->drupalGet('theme-test/suggestion-alter-include');
  $this
    ->assertSession()
    ->pageTextContains('Function suggested via suggestion alter hook found in include file.', 'Include file loaded for initial request.');
  $this
    ->drupalGet('theme-test/suggestion-alter-include');
  $this
    ->assertSession()
    ->pageTextContains('Function suggested via suggestion alter hook found in include file.', 'Include file loaded for second request.');
}