function ColorTest::testValidColor
Same name and namespace in other branches
- 8.9.x core/modules/color/tests/src/Functional/ColorTest.php \Drupal\Tests\color\Functional\ColorTest::testValidColor()
Tests whether the provided color is valid.
File
-
core/
modules/ color/ tests/ src/ Functional/ ColorTest.php, line 106
Class
- ColorTest
- Modify theme colors and make sure the changes are reflected on the frontend.
Namespace
Drupal\Tests\color\FunctionalCode
public function testValidColor() : void {
$settings_path = 'admin/appearance/settings/color_test_theme';
$assert_session = $this->assertSession();
// Array filled with valid and not valid color values.
$colorTests = [
'#000' => TRUE,
'#123456' => TRUE,
'#abcdef' => TRUE,
'#0' => FALSE,
'#00' => FALSE,
'#0000' => FALSE,
'#00000' => FALSE,
'123456' => FALSE,
'#00000g' => FALSE,
];
$this->drupalLogin($this->bigUser);
$edit['scheme'] = '';
foreach ($colorTests as $color => $is_valid) {
$edit['palette[bg]'] = $color;
$this->drupalGet($settings_path);
$this->submitForm($edit, 'Save configuration');
if ($is_valid) {
$assert_session->pageTextContains('The configuration options have been saved.');
}
else {
$assert_session->pageTextContains('You must enter a valid hexadecimal color value for Main background.');
}
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.