function ThemeTest::testUninstallingThemes
Same name in other branches
- 9 core/modules/system/tests/src/Functional/System/ThemeTest.php \Drupal\Tests\system\Functional\System\ThemeTest::testUninstallingThemes()
- 10 core/modules/system/tests/src/Functional/System/ThemeTest.php \Drupal\Tests\system\Functional\System\ThemeTest::testUninstallingThemes()
- 11.x core/modules/system/tests/src/Functional/System/ThemeTest.php \Drupal\Tests\system\Functional\System\ThemeTest::testUninstallingThemes()
Test uninstalling of themes works.
File
-
core/
modules/ system/ tests/ src/ Functional/ System/ ThemeTest.php, line 396
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 testUninstallingThemes() {
// Install Bartik and set it as the default theme.
\Drupal::service('theme_installer')->install([
'bartik',
]);
// Set up seven as the admin theme.
\Drupal::service('theme_installer')->install([
'seven',
]);
$edit = [
'admin_theme' => 'seven',
'use_admin_theme' => TRUE,
];
$this->drupalPostForm('admin/appearance', $edit, t('Save configuration'));
$this->drupalGet('admin/appearance');
$this->clickLink(t('Set as default'));
// Check that seven cannot be uninstalled as it is the admin theme.
$this->assertNoRaw('Uninstall Seven theme', 'A link to uninstall the Seven theme does not appear on the theme settings page.');
// Check that bartik cannot be uninstalled as it is the default theme.
$this->assertNoRaw('Uninstall Bartik theme', 'A link to uninstall the Bartik theme does not appear on the theme settings page.');
// Check that the classy theme cannot be uninstalled as it is a base theme
// of seven and bartik.
$this->assertNoRaw('Uninstall Classy theme', 'A link to uninstall the Classy theme does not appear on the theme settings page.');
// Install Stark and set it as the default theme.
\Drupal::service('theme_installer')->install([
'stark',
]);
$edit = [
'admin_theme' => 'stark',
'use_admin_theme' => TRUE,
];
$this->drupalPostForm('admin/appearance', $edit, t('Save configuration'));
// Check that seven can be uninstalled now.
$this->assertRaw('Uninstall Seven theme', 'A link to uninstall the Seven theme does appear on the theme settings page.');
// Check that the classy theme still cannot be uninstalled as it is a
// base theme of bartik.
$this->assertNoRaw('Uninstall Classy theme', 'A link to uninstall the Classy theme does not appear on the theme settings page.');
// Change the default theme to stark, stark is second in the list.
$this->clickLink(t('Set as default'), 1);
// Check that bartik can be uninstalled now.
$this->assertRaw('Uninstall Bartik theme', 'A link to uninstall the Bartik theme does appear on the theme settings page.');
// Check that the classy theme still can't be uninstalled as neither of its
// base themes have been.
$this->assertNoRaw('Uninstall Classy theme', 'A link to uninstall the Classy theme does not appear on the theme settings page.');
// Uninstall each of the three themes starting with Bartik.
$this->clickLink(t('Uninstall'));
$this->assertRaw('The <em class="placeholder">Bartik</em> theme has been uninstalled');
// Seven is the second in the list.
$this->clickLink(t('Uninstall'));
$this->assertRaw('The <em class="placeholder">Seven</em> theme has been uninstalled');
// Check that the classy theme still can't be uninstalled as it is hidden.
$this->assertNoRaw('Uninstall Classy theme', 'A link to uninstall the Classy theme does not appear on the theme settings page.');
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.