function OliveroTest::testThemeSettingsColorHexCode
Tests the theme settings color input.
File
-
core/
themes/ olivero/ tests/ src/ Functional/ OliveroTest.php, line 186
Class
- OliveroTest
- Tests the Olivero theme.
Namespace
Drupal\Tests\olivero\FunctionalCode
public function testThemeSettingsColorHexCode() : void {
$this->drupalLogin($this->drupalCreateUser([
'access administration pages',
'view the administration theme',
'administer themes',
]));
// Define invalid and valid hex color codes.
$invalid_hex_codes = [
'xyz',
'#xyz',
'#ffff',
'#00000',
'#FFFFF ',
'00#000',
];
$valid_hex_codes = [
'0F0',
'#F0F',
'#2ecc71',
'0074cc',
];
// Visit Olivero's theme settings page.
$this->drupalGet('admin/appearance/settings/olivero');
// Test invalid hex color codes.
foreach ($invalid_hex_codes as $invalid_hex) {
$this->submitForm([
'base_primary_color' => $invalid_hex,
], 'Save configuration');
// Invalid hex codes should throw error.
$this->assertSession()
->statusMessageContains('"' . $invalid_hex . '" is not a valid hexadecimal color.', 'error');
$this->assertTrue($this->getSession()
->getPage()
->findField('base_primary_color')
->hasClass('error'));
}
// Test valid hex color codes.
foreach ($valid_hex_codes as $valid_hex) {
$this->submitForm([
'base_primary_color' => $valid_hex,
], 'Save configuration');
$this->assertSession()
->statusMessageContains('The configuration options have been saved.', 'status');
$this->assertSame($valid_hex, \Drupal::service('config.factory')->getEditable('olivero.settings')
->get('base_primary_color'));
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.