2009-09-01 20:40:40 +00:00
<?php
/**
* @file
* Tests for color module.
*/
/**
* Test color functionality.
*/
class ColorTestCase extends DrupalWebTestCase {
protected $big_user;
2010-08-08 19:35:49 +00:00
protected $themes;
2011-06-09 00:56:24 +00:00
protected $colorTests;
2009-09-01 20:40:40 +00:00
public static function getInfo() {
return array(
'name' => 'Color functionality',
2010-08-08 19:35:49 +00:00
'description' => 'Modify the Bartik and Garland theme colors and make sure the changes are reflected on the frontend',
2009-09-01 20:40:40 +00:00
'group' => 'Color',
);
}
function setUp() {
parent::setUp('color');
2010-07-08 03:41:27 +00:00
2009-09-01 20:40:40 +00:00
// Create users.
2009-12-01 22:30:31 +00:00
$this->big_user = $this->drupalCreateUser(array('administer themes'));
2010-07-08 03:41:27 +00:00
2010-08-08 19:35:49 +00:00
// This tests the color module in both Bartik and Garland.
$this->themes = array(
'bartik' => array(
'palette_input' => 'palette[bg]',
2010-08-12 16:59:04 +00:00
'scheme' => 'slate',
2010-08-08 19:35:49 +00:00
'scheme_color' => '#3b3b3b',
),
'garland' => array(
'palette_input' => 'palette[link]',
'scheme' => 'greenbeam',
'scheme_color' => '#0c7a00',
),
);
theme_enable(array_keys($this->themes));
2011-06-09 00:56:24 +00:00
// Array filled with valid and not valid color values
$this->colorTests = array(
'#000' => TRUE,
'#123456' => TRUE,
'#abcdef' => TRUE,
'#0' => FALSE,
'#00' => FALSE,
'#0000' => FALSE,
'#00000' => FALSE,
'123456' => FALSE,
'#00000g' => FALSE,
);
2009-09-01 20:40:40 +00:00
}
/**
* Test color module functionality.
*/
function testColor() {
2010-08-08 19:35:49 +00:00
foreach ($this->themes as $theme => $test_values) {
$this->_testColor($theme, $test_values);
}
}
/**
* Tests color module functionality using the given theme.
*/
function _testColor($theme, $test_values) {
variable_set('theme_default', $theme);
$settings_path = 'admin/appearance/settings/' . $theme;
2009-09-01 20:40:40 +00:00
$this->drupalLogin($this->big_user);
2010-08-08 19:35:49 +00:00
$this->drupalGet($settings_path);
2009-09-01 20:40:40 +00:00
$this->assertResponse(200);
$edit['scheme'] = '';
2010-08-08 19:35:49 +00:00
$edit[$test_values['palette_input']] = '#123456';
$this->drupalPost($settings_path, $edit, t('Save configuration'));
2009-09-01 20:40:40 +00:00
$this->drupalGet('<front>');
2010-08-08 19:35:49 +00:00
$stylesheets = variable_get('color_' . $theme . '_stylesheets', array());
$this->assertPattern('|' . file_create_url($stylesheets[0]) . '|', 'Make sure the color stylesheet is included in the content. (' . $theme . ')');
2009-09-01 20:40:40 +00:00
$stylesheet_content = join("\n", file($stylesheets[0]));
2010-11-13 14:06:43 +00:00
$this->assertTrue(strpos($stylesheet_content, 'color: #123456') !== FALSE, 'Make sure the color we changed is in the color stylesheet. (' . $theme . ')');
2010-04-03 08:05:08 +00:00
2010-08-08 19:35:49 +00:00
$this->drupalGet($settings_path);
2010-04-03 08:05:08 +00:00
$this->assertResponse(200);
2010-08-08 19:35:49 +00:00
$edit['scheme'] = $test_values['scheme'];
$this->drupalPost($settings_path, $edit, t('Save configuration'));
2010-04-03 08:05:08 +00:00
$this->drupalGet('<front>');
2010-08-08 19:35:49 +00:00
$stylesheets = variable_get('color_' . $theme . '_stylesheets', array());
2010-04-03 08:05:08 +00:00
$stylesheet_content = join("\n", file($stylesheets[0]));
2010-11-13 14:06:43 +00:00
$this->assertTrue(strpos($stylesheet_content, 'color: ' . $test_values['scheme_color']) !== FALSE, 'Make sure the color we changed is in the color stylesheet. (' . $theme . ')');
// Test with aggregated CSS turned on.
variable_set('preprocess_css', 1);
$this->drupalGet('<front>');
$stylesheets = variable_get('drupal_css_cache_files', array());
$stylesheet_content = '';
foreach ($stylesheets as $key => $uri) {
$stylesheet_content .= join("\n", file(drupal_realpath($uri)));
}
$this->assertTrue(strpos($stylesheet_content, 'public://') === FALSE, 'Make sure the color paths have been translated to local paths. (' . $theme . ')');
variable_set('preprocess_css', 0);
2009-09-01 20:40:40 +00:00
}
2011-06-09 00:56:24 +00:00
/**
* Test to see if the provided color is valid
*/
function testValidColor() {
variable_set('theme_default', 'bartik');
$settings_path = 'admin/appearance/settings/bartik';
$this->drupalLogin($this->big_user);
$edit['scheme'] = '';
foreach ($this->colorTests as $color => $is_valid) {
$edit['palette[bg]'] = $color;
$this->drupalPost($settings_path, $edit, t('Save configuration'));
if($is_valid) {
$this->assertText('The configuration options have been saved.');
}
else {
$this->assertText('Main background must be a valid hexadecimal CSS color value.');
}
}
}
2009-09-01 20:40:40 +00:00
}