- <?php
- * @file
- * Tests for color module.
- */
-
- * Tests the Color module functionality.
- */
- class ColorTestCase extends BackdropWebTestCase {
- protected $profile = 'testing';
- protected $bigUser;
- protected $themes;
- protected $colorTests;
-
-
- * {@inheritdoc}
- */
- public function setUp() {
- parent::setUp('color', 'config');
-
-
- $this->bigUser = $this->backdropCreateUser(array(
- 'administer themes',
- 'access content',
- 'administer site configuration',
- 'synchronize configuration',
- ));
-
-
- $this->themes = array(
- 'bartik' => array(
- 'palette_input' => 'palette[bg]',
- 'scheme' => 'goldfish',
- 'scheme_color' => '#3b3b3b',
- ),
- );
- theme_enable(array_keys($this->themes));
-
-
- $this->colorTests = array(
- '#000' => TRUE,
- '#123456' => TRUE,
- '#abcdef' => TRUE,
- '123456' => TRUE,
- '#0' => FALSE,
- '#00' => FALSE,
- '#0000' => FALSE,
- '#00000' => FALSE,
- '#00000g' => FALSE,
- );
- }
-
-
- * Tests the Color module functionality.
- */
- public function testColor() {
- foreach ($this->themes as $theme => $test_values) {
- config_set('system.core', 'theme_default', $theme);
- $settings_path = 'admin/appearance/settings/' . $theme;
-
- $this->backdropLogin($this->bigUser);
- $this->backdropGet($settings_path);
- $this->assertResponse(200);
- $edit['scheme'] = '';
- $edit[$test_values['palette_input']] = '#123456';
- $this->backdropPost($settings_path, $edit, t('Save theme settings'));
-
- $this->backdropGet('<front>');
- $stylesheets = theme_get_setting('color.stylesheets', $theme);
- $this->assertPattern('|' . file_create_url($stylesheets[0]) . '|', 'Make sure the color stylesheet is included in the content. (' . $theme . ')');
-
- $stylesheet_content = implode("\n", file($stylesheets[0]));
- $this->assertTrue(strpos($stylesheet_content, 'color: #123456') !== FALSE, 'Make sure the color we changed is in the color stylesheet. (' . $theme . ')');
-
- $this->backdropGet($settings_path);
- $this->assertResponse(200);
- $edit['scheme'] = $test_values['scheme'];
- $this->backdropPost($settings_path, $edit, t('Save theme settings'));
-
- $this->backdropGet('<front>');
- backdrop_static_reset();
- $stylesheets = theme_get_setting('color.stylesheets', $theme);
- $stylesheet_content = implode("\n", file($stylesheets[0]));
- $this->assertTrue(strpos($stylesheet_content, 'color: ' . $test_values['scheme_color']) !== FALSE, 'Make sure the color we changed is in the color stylesheet. (' . $theme . ')');
-
-
- config_set('system.core', 'preprocess_css', 1);
- $this->backdropGet('<front>');
- $stylesheets = state_get('css_cache_files', array());
- $stylesheet_content = '';
- foreach ($stylesheets as $key => $uri) {
- $stylesheet_content .= implode("\n", file(backdrop_realpath($uri)));
- }
- $this->assertTrue(strpos($stylesheet_content, 'public://') === FALSE, 'Make sure the color paths have been translated to local paths. (' . $theme . ')');
- config_set('system.core', 'preprocess_css', 0);
- }
- }
-
-
- * Tests whether the provided color is valid.
- */
- public function testValidColor() {
- config_set('system.core', 'theme_default', 'bartik');
- $settings_path = 'admin/appearance/settings/bartik';
-
- $this->backdropLogin($this->bigUser);
- $edit['scheme'] = '';
-
- foreach ($this->colorTests as $color => $is_valid) {
- $edit['palette[bg]'] = $color;
- $this->backdropPost($settings_path, $edit, t('Save theme settings'));
-
- if ($is_valid) {
- $this->assertText('The configuration options have been saved.');
- }
- else {
- $this->assertText('Main background must be a valid color.');
- }
- }
- }
-
-
- * Test if the CSS files for a theme are updated when editing Configuration.
- */
- public function testUpdateCssFilesOnConfigSave() {
- config_set('system.core', 'theme_default', 'bartik');
- $settings_path = 'admin/appearance/settings/bartik';
- $import_path = 'admin/config/development/configuration/single';
-
-
- $this->backdropLogin($this->bigUser);
- $this->backdropGet($settings_path);
- $this->assertResponse(200);
- $edit = array(
- 'scheme' => '',
- 'palette[top]' => '#123456',
- );
- $this->backdropPost($settings_path, $edit, t('Save theme settings'));
-
-
- $this->backdropGet($import_path);
- $config = config('bartik.settings');
- $data = array_merge(array('_config_name' => 'bartik.settings'), $config->get());
- $data['color']['palette']['top'] = '#654321';
- $edit = array('import' => json_encode($data));
- $this->backdropPost($import_path, $edit, t('Import'));
-
-
- $stylesheets = theme_get_setting('color.stylesheets', 'bartik');
- $stylesheet_content = '';
- foreach ($stylesheets as $stylesheet) {
- $stylesheet_content .= implode("\n", file($stylesheet));
- }
- $this->assertTrue(strpos($stylesheet_content, 'color: #654321') !== FALSE, 'Make sure the color we changed is in the color stylesheet.');
- }
-
-
- * Test the Bartik legacy color mode.
- */
- public function testBartikLegacy() {
- config_set('system.core', 'theme_default', 'bartik');
- $settings_path = 'admin/appearance/settings/bartik';
-
- $info = array();
- include BACKDROP_ROOT . '/' . backdrop_get_path('theme', 'bartik') . '/color/color.inc';
-
- $default_palette = $info['schemes']['default']['colors'];
- $blue_lagoon_palette = $info['schemes']['blue_lagoon']['colors'];
-
-
- $edit = array();
- foreach ($blue_lagoon_palette as $key => $color) {
- $edit["palette[$key]"] = $color;
- }
- $this->backdropLogin($this->bigUser);
- $this->backdropPost($settings_path, $edit, t('Save theme settings'));
-
-
- $this->assertTrue(config_get('bartik.settings', 'color_legacy'), 'Legacy color flag set in Bartik configuration.');
- $this->assertNull(config_get('bartik.settings', 'color'), 'No other color settings saved.');
- $this->backdropGet('');
- $this->assertRaw('bartik/css/colors-legacy.css', 'Legacy color CSS found on the homepage.');
- $this->assertNoRaw('bartik/css/legacy.css', 'Default color CSS correctly not used on the homepage.');
-
-
- $edit['palette[top]'] = '#292929';
- $this->backdropPost($settings_path, $edit, t('Save theme settings'));
-
-
- $this->assertFalse(config_get('bartik.settings', 'color_legacy'), 'Legacy color flag set to FALSE in Bartik configuration.');
- $this->backdropGet('');
- $this->assertNoRaw('bartik/css/colors-legacy.css', 'Legacy color CSS correctly not found found on the homepage.');
- $this->assertNoRaw('bartik/css/colors.css', 'Default color CSS correctly not used on the homepage.');
-
-
- $edit = array(
- 'scheme' => 'default',
- );
- foreach ($default_palette as $key => $color) {
- $edit["palette[$key]"] = $color;
- }
- $this->backdropPost($settings_path, $edit, t('Save theme settings'));
- $this->assertFalse(config_get('bartik.settings', 'color_legacy'), 'Legacy color flag set to FALSE in Bartik configuration.');
- $this->assertNull(config_get('bartik.settings', 'color'), 'Color settings emptied out.');
- $this->assertNoRaw('bartik/css/colors-legacy.css', 'Legacy color CSS correctly not found found on the homepage.');
- $this->assertRaw('bartik/css/colors.css', 'Default color CSS found on the homepage.');
- }
-
- }