class AdminTest
Same name in this branch
- main core/modules/system/tests/src/Functional/System/AdminTest.php \Drupal\Tests\system\Functional\System\AdminTest
Same name and namespace in other branches
- 11.x core/modules/system/tests/src/Functional/System/AdminTest.php \Drupal\Tests\system\Functional\System\AdminTest
- 10 core/modules/system/tests/src/Functional/System/AdminTest.php \Drupal\Tests\system\Functional\System\AdminTest
- 9 core/modules/system/tests/src/Functional/System/AdminTest.php \Drupal\Tests\system\Functional\System\AdminTest
- 8.9.x core/modules/system/tests/src/Functional/System/AdminTest.php \Drupal\Tests\system\Functional\System\AdminTest
- 11.x core/themes/admin/tests/src/Functional/AdminTest.php \Drupal\Tests\admin\Functional\AdminTest
Tests the Admin theme.
Attributes
#[Group('admin')]
#[RunTestsInSeparateProcesses]
Hierarchy
- class \Drupal\Tests\BrowserTestBase uses \Drupal\Tests\DrupalTestCaseTrait, \Drupal\Core\Test\FunctionalTestSetupTrait, \Drupal\Tests\UiHelperTrait, \Drupal\Core\Test\TestSetupTrait, \Drupal\Tests\block\Traits\BlockCreationTrait, \Drupal\Tests\RandomGeneratorTrait, \Drupal\Tests\node\Traits\NodeCreationTrait, \Drupal\Tests\node\Traits\ContentTypeCreationTrait, \Drupal\Tests\ConfigTestTrait, \Drupal\Tests\TestRequirementsTrait, \Drupal\Tests\user\Traits\UserCreationTrait, \Drupal\Tests\XdebugRequestTrait, \Drupal\Tests\PhpUnitCompatibilityTrait, \Drupal\TestTools\Extension\DeprecationBridge\ExpectDeprecationTrait, \Drupal\Tests\ExtensionListTestTrait extends \PHPUnit\Framework\TestCase
- class \Drupal\Tests\admin\Functional\AdminTest extends \Drupal\Tests\BrowserTestBase
Expanded class hierarchy of AdminTest
File
-
core/
themes/ admin/ tests/ src/ Functional/ AdminTest.php, line 14
Namespace
Drupal\Tests\admin\FunctionalView source
class AdminTest extends BrowserTestBase {
/**
* {@inheritdoc}
*/
protected static $modules = [
// Install the shortcut module so that admin.settings has its schema checked.
// There's currently no way for Admin to provide a default and have valid
// configuration as themes cannot react to a module install.
'shortcut',
'toolbar',
'node',
];
/**
* {@inheritdoc}
*/
protected $defaultTheme = 'stark';
/**
* {@inheritdoc}
*/
protected function setUp() : void {
parent::setUp();
$this->assertTrue(\Drupal::service('theme_installer')->install([
'admin',
]));
$this->container
->get('config.factory')
->getEditable('system.theme')
->set('default', 'admin')
->set('admin', 'admin')
->save();
$adminUser = $this->drupalCreateUser([
'access administration pages',
'administer themes',
'access toolbar',
'access content overview',
]);
$this->drupalLogin($adminUser);
}
/**
* Tests that the Admin theme always adds its message CSS and Classy's.
*/
public function testDefaultAdminSettings() : void {
$response = $this->drupalGet('/admin/content');
$this->assertSession()
->statusCodeEquals(200);
$this->assertStringContainsString('"dark_mode":"0"', $response);
$this->assertStringContainsString('"preset_accent_color":"blue"', $response);
$this->assertStringContainsString('"preset_focus_color":"gin"', $response);
$this->assertSession()
->responseContains('admin.css');
}
/**
* Tests the dark mode setting.
*/
public function testDarkModeSetting() : void {
\Drupal::configFactory()->getEditable('admin.settings')
->set('enable_dark_mode', '1')
->save();
$response = $this->drupalGet('/admin/content');
$this->assertSession()
->statusCodeEquals(200);
$this->assertStringContainsString('"dark_mode":"1"', $response);
}
/**
* Tests color accent setting.
*/
public function testAccentColorSetting() : void {
\Drupal::configFactory()->getEditable('admin.settings')
->set('preset_accent_color', 'red')
->save();
$response = $this->drupalGet('/admin/content');
$this->assertSession()
->statusCodeEquals(200);
$this->assertStringContainsString('"preset_accent_color":"red"', $response);
}
/**
* Tests focus color setting.
*/
public function testFocusColorSetting() : void {
\Drupal::configFactory()->getEditable('admin.settings')
->set('preset_focus_color', 'blue')
->save();
$response = $this->drupalGet('/admin/content');
$this->assertSession()
->statusCodeEquals(200);
$this->assertStringContainsString('"preset_focus_color":"blue"', $response);
}
/**
* Test user settings.
*/
public function testUserSettings() : void {
\Drupal::configFactory()->getEditable('admin.settings')
->set('show_user_theme_settings', TRUE)
->save();
$user1 = $this->createUser();
$this->drupalLogin($user1);
// Change something on the logged in user form.
$this->assertStringContainsString('"dark_mode":"0"', $this->drupalGet($user1->toUrl('edit-form')));
$this->submitForm([
'enable_user_settings' => TRUE,
'enable_dark_mode' => '1',
], 'Save');
$this->assertStringContainsString('"dark_mode":"1"', $this->drupalGet($user1->toUrl('edit-form')));
// Login as admin.
$this->drupalLogin($this->rootUser);
$this->assertStringContainsString('"dark_mode":"0"', $this->drupalGet('edit-form'));
}
/**
* Disabled: Test user settings.
*/
public function disabledTestUserSettings() : void {
$user1 = $this->createUser();
$this->drupalLogin($user1);
// Change something on user1 edit form.
$this->drupalGet($user1->toUrl('edit-form'));
$this->submitForm([
'enable_user_settings' => TRUE,
'high_contrast_mode' => TRUE,
'enable_dark_mode' => '1',
], 'Save');
// Check logged-in's user is not affected.
$loggedInUserResponse = $this->drupalGet('edit-form');
$this->assertStringContainsString('"high_contrast_mode":false', $loggedInUserResponse);
$this->assertStringContainsString('"dark_mode":"0"', $loggedInUserResponse);
// Check settings of user1.
$this->drupalLogin($user1);
$rootUserResponse = $this->drupalGet($user1->toUrl('edit-form'));
$this->assertStringContainsString('"high_contrast_mode":true', $rootUserResponse);
$this->assertStringContainsString('"dark_mode":"1"', $rootUserResponse);
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.