function ColorTest::testColor
Same name and namespace in other branches
- 8.9.x core/modules/color/tests/src/Functional/ColorTest.php \Drupal\Tests\color\Functional\ColorTest::testColor()
Tests the Color module functionality.
File
-
core/
modules/ color/ tests/ src/ Functional/ ColorTest.php, line 52
Class
- ColorTest
- Modify theme colors and make sure the changes are reflected on the frontend.
Namespace
Drupal\Tests\color\FunctionalCode
public function testColor() : void {
$settings_path = 'admin/appearance/settings/color_test_theme';
$assert_session = $this->assertSession();
$this->drupalLogin($this->bigUser);
$this->drupalGet($settings_path);
$assert_session->statusCodeEquals(200);
$assert_session->pageTextContainsOnce('Color set');
$edit['scheme'] = '';
$edit['palette[bg]'] = '#123456';
$this->drupalGet($settings_path);
$this->submitForm($edit, 'Save configuration');
$this->drupalGet('<front>');
$stylesheets = $this->config('color.theme.color_test_theme')
->get('stylesheets');
/** @var \Drupal\Core\File\FileUrlGeneratorInterface $file_url_generator */
$file_url_generator = \Drupal::service('file_url_generator');
// Make sure the color stylesheet is included in the content.
foreach ($stylesheets as $stylesheet) {
$assert_session->responseMatches('|' . $file_url_generator->generateString($stylesheet) . '|');
$stylesheet_content = implode("\n", file($stylesheet));
$this->assertStringContainsString('color: #123456', $stylesheet_content, 'Make sure the color we changed is in the color stylesheet.');
}
$edit['scheme'] = 'custom';
$this->drupalGet($settings_path);
$this->submitForm($edit, 'Save configuration');
$this->drupalGet('<front>');
$stylesheets = $this->config('color.theme.color_test_theme')
->get('stylesheets');
foreach ($stylesheets as $stylesheet) {
$stylesheet_content = implode("\n", file($stylesheet));
$this->assertStringContainsString('color: #3b3b3b', $stylesheet_content, 'Make sure the color we changed is in the color stylesheet.');
}
// Test with aggregated CSS turned on.
$config = $this->config('system.performance');
$config->set('css.preprocess', 1);
$config->save();
$this->drupalGet('<front>');
$stylesheets = \Drupal::state()->get('drupal_css_cache_files', []);
$stylesheet_content = '';
foreach ($stylesheets as $uri) {
$stylesheet_content .= implode("\n", file(\Drupal::service('file_system')->realpath($uri)));
}
$this->assertStringNotContainsString('public://', $stylesheet_content, 'Make sure the color paths have been translated to local paths.');
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.