ThemeLegacyTest.php in Drupal 9
File
core/modules/system/tests/src/Functional/Theme/ThemeLegacyTest.php
View source
<?php
namespace Drupal\Tests\system\Functional\Theme;
use Drupal\Tests\BrowserTestBase;
class ThemeLegacyTest extends BrowserTestBase {
protected static $modules = [
'theme_test',
'theme_legacy_test',
];
protected $defaultTheme = 'stark';
protected function setUp() : void {
parent::setUp();
\Drupal::service('theme_installer')
->install([
'test_legacy_theme',
]);
}
public function testFunctionOverride() {
$this
->drupalGet('theme-test/function-template-overridden');
$this
->assertSession()
->pageTextContains('Success: Template overrides theme function.', 'Theme function overridden by test_theme template.');
}
public function testThemeFunctionSuggestionsAlter() {
$this
->drupalGet('theme-test/function-suggestion-alter');
$this
->assertSession()
->pageTextContains('Original theme function.');
$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.');
\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.');
}
public function testSuggestionsAlterInclude() {
$this
->drupalGet('theme-test/suggestion-alter-include');
$this
->assertSession()
->pageTextContains('Original function before altering theme suggestions.');
\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.');
}
}