function ThemeLegacyTest::testThemeFunctionSuggestionsAlter

Same name in other branches
  1. 8.9.x core/modules/system/tests/src/Functional/Theme/ThemeLegacyTest.php \Drupal\Tests\system\Functional\Theme\ThemeLegacyTest::testThemeFunctionSuggestionsAlter()

Tests that theme suggestion alter hooks work for theme functions.

File

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

Class

ThemeLegacyTest
Tests legacy theme functions.

Namespace

Drupal\Tests\system\Functional\Theme

Code

public function testThemeFunctionSuggestionsAlter() {
    $this->drupalGet('theme-test/function-suggestion-alter');
    $this->assertSession()
        ->pageTextContains('Original theme function.');
    // Install test_theme and test that themes can alter theme suggestions.
    $this->config('system.theme')
        ->set('default', 'test_legacy_theme')
        ->save();
    $this->drupalGet('theme-test/function-suggestion-alter');
    $this->assertSession()
        ->pageTextContains('Theme function overridden based on new theme suggestion provided by the test_legacy_theme theme.');
    // Enable the theme_suggestions_test module to test modules implementing
    // suggestions alter hooks.
    \Drupal::service('module_installer')->install([
        'theme_legacy_suggestions_test',
    ]);
    $this->resetAll();
    $this->drupalGet('theme-test/function-suggestion-alter');
    $this->assertSession()
        ->pageTextContains('Theme function overridden based on new theme suggestion provided by a module.');
}

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