function ThemeTest::testAdministrationTheme
Same name in other branches
- 8.9.x core/modules/system/tests/src/Functional/System/ThemeTest.php \Drupal\Tests\system\Functional\System\ThemeTest::testAdministrationTheme()
- 10 core/modules/system/tests/src/Functional/System/ThemeTest.php \Drupal\Tests\system\Functional\System\ThemeTest::testAdministrationTheme()
- 11.x core/modules/system/tests/src/Functional/System/ThemeTest.php \Drupal\Tests\system\Functional\System\ThemeTest::testAdministrationTheme()
Tests the administration theme functionality.
File
-
core/
modules/ system/ tests/ src/ Functional/ System/ ThemeTest.php, line 289
Class
- ThemeTest
- Tests the theme administration user interface.
Namespace
Drupal\Tests\system\Functional\SystemCode
public function testAdministrationTheme() {
$this->container
->get('theme_installer')
->install([
'claro',
]);
// Install an administration theme and show it on the node admin pages.
$edit = [
'admin_theme' => 'claro',
'use_admin_theme' => TRUE,
];
$this->drupalGet('admin/appearance');
$this->submitForm($edit, 'Save configuration');
// Check the display of non stable themes.
$themes = \Drupal::service('theme_handler')->rebuildThemeData();
$experimental_version = $themes['experimental_theme_test']->info['version'];
$deprecated_version = $themes['deprecated_theme_test']->info['version'];
$this->drupalGet('admin/appearance');
$this->assertSession()
->pageTextContains('Experimental test ' . $experimental_version . ' (experimental theme)');
$this->assertSession()
->pageTextContains('Test deprecated theme ' . $deprecated_version . ' (Deprecated)');
$this->assertSession()
->elementExists('xpath', "//a[contains(@href, 'http://example.com/deprecated_theme')]");
// Check that the administration theme is used on an administration page.
$this->drupalGet('admin/config');
$this->assertSession()
->responseContains('core/themes/claro');
// Check that the site default theme used on node page.
$this->drupalGet('node/' . $this->node
->id());
$this->assertSession()
->responseContains('core/themes/starterkit_theme');
// Check that the administration theme is used on the add content page.
$this->drupalGet('node/add');
$this->assertSession()
->responseContains('core/themes/claro');
// Check that the administration theme is used on the edit content page.
$this->drupalGet('node/' . $this->node
->id() . '/edit');
$this->assertSession()
->responseContains('core/themes/claro');
// Disable the admin theme on the node admin pages.
$edit = [
'use_admin_theme' => FALSE,
];
$this->drupalGet('admin/appearance');
$this->submitForm($edit, 'Save configuration');
// Check that obsolete themes are not displayed.
$this->drupalGet('admin/appearance');
$this->assertSession()
->pageTextNotContains('Obsolete test theme');
// Check that the administration theme is used on an administration page.
$this->drupalGet('admin/config');
$this->assertSession()
->responseContains('core/themes/claro');
// Ensure that the admin theme is also visible on the 403 page.
$normal_user = $this->drupalCreateUser([
'view the administration theme',
]);
$this->drupalLogin($normal_user);
// Check that the administration theme is used on an administration page.
$this->drupalGet('admin/config');
$this->assertSession()
->statusCodeEquals(403);
$this->assertSession()
->responseContains('core/themes/claro');
$this->drupalLogin($this->adminUser);
// Check that the site default theme used on the add content page.
$this->drupalGet('node/add');
$this->assertSession()
->responseContains('core/themes/starterkit_theme');
// Reset to the default theme settings.
$edit = [
'admin_theme' => '',
'use_admin_theme' => FALSE,
];
$this->drupalGet('admin/appearance');
$this->submitForm($edit, 'Save configuration');
// Check that the site default theme used on administration page.
$this->drupalGet('admin');
$this->assertSession()
->responseContains('core/themes/starterkit_theme');
// Check that the site default theme used on the add content page.
$this->drupalGet('node/add');
$this->assertSession()
->responseContains('core/themes/starterkit_theme');
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.