public function ThemeTest::testAdministrationTheme 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::testAdministrationTheme()
Tests the administration theme functionality.
File
- core/
modules/ system/ tests/ src/ Functional/ System/ ThemeTest.php, line 280
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 testAdministrationTheme() {
$this->container
->get('theme_installer')
->install([
'seven',
]);
// Install an administration theme and show it on the node admin pages.
$edit = [
'admin_theme' => 'seven',
'use_admin_theme' => TRUE,
];
$this
->drupalGet('admin/appearance');
$this
->submitForm($edit, 'Save configuration');
// Check that the administration theme is used on an administration page.
$this
->drupalGet('admin/config');
$this
->assertSession()
->responseContains('core/themes/seven');
// Check that the site default theme used on node page.
$this
->drupalGet('node/' . $this->node
->id());
$this
->assertSession()
->responseContains('core/themes/classy');
// Check that the administration theme is used on the add content page.
$this
->drupalGet('node/add');
$this
->assertSession()
->responseContains('core/themes/seven');
// Check that the administration theme is used on the edit content page.
$this
->drupalGet('node/' . $this->node
->id() . '/edit');
$this
->assertSession()
->responseContains('core/themes/seven');
// 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 the administration theme is used on an administration page.
$this
->drupalGet('admin/config');
$this
->assertSession()
->responseContains('core/themes/seven');
// 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/seven');
$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/classy');
// 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/classy');
// Check that the site default theme used on the add content page.
$this
->drupalGet('node/add');
$this
->assertSession()
->responseContains('core/themes/classy');
}