public function ThemeTest::testInstallAndSetAsDefault in Drupal 9
Same name and namespace in other branches
- 8 core/modules/system/tests/src/Functional/System/ThemeTest.php \Drupal\Tests\system\Functional\System\ThemeTest::testInstallAndSetAsDefault()
Tests installing a theme and setting it as default.
File
- core/
modules/ system/ tests/ src/ Functional/ System/ ThemeTest.php, line 464
Class
- ThemeTest
- Tests the theme interface functionality by enabling and switching themes, and using an administration theme.
Namespace
Drupal\Tests\system\Functional\SystemCode
public function testInstallAndSetAsDefault() {
$themes = [
'bartik' => 'Bartik',
'test_core_semver' => 'Theme test with semver core version',
];
foreach ($themes as $theme_machine_name => $theme_name) {
$this
->drupalGet('admin/appearance');
$this
->getSession()
->getPage()
->findLink("Install {$theme_name} as default theme")
->click();
// Test the confirmation message.
$this
->assertSession()
->pageTextContains("{$theme_name} is now the default theme.");
// Make sure the theme is now set as the default theme in config.
$this
->assertEquals($theme_machine_name, $this
->config('system.theme')
->get('default'));
// This checks for a regression. See https://www.drupal.org/node/2498691.
$this
->assertSession()
->pageTextNotContains("The {$theme_machine_name} theme was not found.");
$themes = \Drupal::service('theme_handler')
->rebuildThemeData();
$version = $themes[$theme_machine_name]->info['version'];
// Confirm the theme is indicated as the default theme and administration
// theme because the admin theme is the default theme.
$out = $this
->getSession()
->getPage()
->getContent();
$this
->assertTrue((bool) preg_match("/{$theme_name} " . preg_quote($version) . '\\s{2,}\\(default theme, administration theme\\)/', $out));
}
}