1 |
85ad3d82
|
Assos Assos
|
<?php
|
2 |
|
|
|
3 |
|
|
/**
|
4 |
|
|
* @file
|
5 |
|
|
* Tests for color module.
|
6 |
|
|
*/
|
7 |
|
|
|
8 |
|
|
/**
|
9 |
|
|
* Tests the Color module functionality.
|
10 |
|
|
*/
|
11 |
|
|
class ColorTestCase extends DrupalWebTestCase {
|
12 |
|
|
protected $big_user;
|
13 |
|
|
protected $themes;
|
14 |
|
|
protected $colorTests;
|
15 |
|
|
|
16 |
|
|
public static function getInfo() {
|
17 |
|
|
return array(
|
18 |
|
|
'name' => 'Color functionality',
|
19 |
|
|
'description' => 'Modify the Bartik and Garland theme colors and make sure the changes are reflected on the frontend',
|
20 |
|
|
'group' => 'Color',
|
21 |
|
|
);
|
22 |
|
|
}
|
23 |
|
|
|
24 |
|
|
function setUp() {
|
25 |
|
|
parent::setUp('color');
|
26 |
|
|
|
27 |
|
|
// Create users.
|
28 |
|
|
$this->big_user = $this->drupalCreateUser(array('administer themes'));
|
29 |
|
|
|
30 |
|
|
// This tests the color module in both Bartik and Garland.
|
31 |
|
|
$this->themes = array(
|
32 |
|
|
'bartik' => array(
|
33 |
|
|
'palette_input' => 'palette[bg]',
|
34 |
|
|
'scheme' => 'slate',
|
35 |
|
|
'scheme_color' => '#3b3b3b',
|
36 |
|
|
),
|
37 |
|
|
'garland' => array(
|
38 |
|
|
'palette_input' => 'palette[link]',
|
39 |
|
|
'scheme' => 'greenbeam',
|
40 |
|
|
'scheme_color' => '#0c7a00',
|
41 |
|
|
),
|
42 |
|
|
);
|
43 |
|
|
theme_enable(array_keys($this->themes));
|
44 |
|
|
|
45 |
|
|
// Array filled with valid and not valid color values
|
46 |
|
|
$this->colorTests = array(
|
47 |
|
|
'#000' => TRUE,
|
48 |
|
|
'#123456' => TRUE,
|
49 |
|
|
'#abcdef' => TRUE,
|
50 |
|
|
'#0' => FALSE,
|
51 |
|
|
'#00' => FALSE,
|
52 |
|
|
'#0000' => FALSE,
|
53 |
|
|
'#00000' => FALSE,
|
54 |
|
|
'123456' => FALSE,
|
55 |
|
|
'#00000g' => FALSE,
|
56 |
|
|
);
|
57 |
|
|
}
|
58 |
|
|
|
59 |
|
|
/**
|
60 |
|
|
* Tests the Color module functionality.
|
61 |
|
|
*/
|
62 |
|
|
function testColor() {
|
63 |
|
|
foreach ($this->themes as $theme => $test_values) {
|
64 |
|
|
$this->_testColor($theme, $test_values);
|
65 |
|
|
}
|
66 |
|
|
}
|
67 |
|
|
|
68 |
|
|
/**
|
69 |
|
|
* Tests the Color module functionality using the given theme.
|
70 |
|
|
*/
|
71 |
|
|
function _testColor($theme, $test_values) {
|
72 |
|
|
variable_set('theme_default', $theme);
|
73 |
|
|
$settings_path = 'admin/appearance/settings/' . $theme;
|
74 |
|
|
|
75 |
|
|
$this->drupalLogin($this->big_user);
|
76 |
|
|
$this->drupalGet($settings_path);
|
77 |
|
|
$this->assertResponse(200);
|
78 |
|
|
$edit['scheme'] = '';
|
79 |
|
|
$edit[$test_values['palette_input']] = '#123456';
|
80 |
|
|
$this->drupalPost($settings_path, $edit, t('Save configuration'));
|
81 |
|
|
|
82 |
|
|
$this->drupalGet('<front>');
|
83 |
|
|
$stylesheets = variable_get('color_' . $theme . '_stylesheets', array());
|
84 |
|
|
$this->assertPattern('|' . file_create_url($stylesheets[0]) . '|', 'Make sure the color stylesheet is included in the content. (' . $theme . ')');
|
85 |
|
|
|
86 |
|
|
$stylesheet_content = join("\n", file($stylesheets[0]));
|
87 |
|
|
$this->assertTrue(strpos($stylesheet_content, 'color: #123456') !== FALSE, 'Make sure the color we changed is in the color stylesheet. (' . $theme . ')');
|
88 |
|
|
|
89 |
|
|
$this->drupalGet($settings_path);
|
90 |
|
|
$this->assertResponse(200);
|
91 |
|
|
$edit['scheme'] = $test_values['scheme'];
|
92 |
|
|
$this->drupalPost($settings_path, $edit, t('Save configuration'));
|
93 |
|
|
|
94 |
|
|
$this->drupalGet('<front>');
|
95 |
|
|
$stylesheets = variable_get('color_' . $theme . '_stylesheets', array());
|
96 |
|
|
$stylesheet_content = join("\n", file($stylesheets[0]));
|
97 |
|
|
$this->assertTrue(strpos($stylesheet_content, 'color: ' . $test_values['scheme_color']) !== FALSE, 'Make sure the color we changed is in the color stylesheet. (' . $theme . ')');
|
98 |
|
|
|
99 |
|
|
// Test with aggregated CSS turned on.
|
100 |
|
|
variable_set('preprocess_css', 1);
|
101 |
|
|
$this->drupalGet('<front>');
|
102 |
|
|
$stylesheets = variable_get('drupal_css_cache_files', array());
|
103 |
|
|
$stylesheet_content = '';
|
104 |
|
|
foreach ($stylesheets as $key => $uri) {
|
105 |
|
|
$stylesheet_content .= join("\n", file(drupal_realpath($uri)));
|
106 |
|
|
}
|
107 |
|
|
$this->assertTrue(strpos($stylesheet_content, 'public://') === FALSE, 'Make sure the color paths have been translated to local paths. (' . $theme . ')');
|
108 |
|
|
variable_set('preprocess_css', 0);
|
109 |
|
|
}
|
110 |
|
|
|
111 |
|
|
/**
|
112 |
|
|
* Tests whether the provided color is valid.
|
113 |
|
|
*/
|
114 |
|
|
function testValidColor() {
|
115 |
|
|
variable_set('theme_default', 'bartik');
|
116 |
|
|
$settings_path = 'admin/appearance/settings/bartik';
|
117 |
|
|
|
118 |
|
|
$this->drupalLogin($this->big_user);
|
119 |
|
|
$edit['scheme'] = '';
|
120 |
|
|
|
121 |
|
|
foreach ($this->colorTests as $color => $is_valid) {
|
122 |
|
|
$edit['palette[bg]'] = $color;
|
123 |
|
|
$this->drupalPost($settings_path, $edit, t('Save configuration'));
|
124 |
|
|
|
125 |
|
|
if($is_valid) {
|
126 |
|
|
$this->assertText('The configuration options have been saved.');
|
127 |
|
|
}
|
128 |
|
|
else {
|
129 |
|
|
$this->assertText('Main background must be a valid hexadecimal CSS color value.');
|
130 |
|
|
}
|
131 |
|
|
}
|
132 |
|
|
}
|
133 |
|
|
} |