1
|
<?php
|
2
|
|
3
|
/**
|
4
|
* Test menu links depending on user permissions.
|
5
|
*/
|
6
|
class CtoolsCssTestCase extends DrupalWebTestCase {
|
7
|
|
8
|
/**
|
9
|
* {@inheritdoc}
|
10
|
*/
|
11
|
public static function getInfo() {
|
12
|
return array(
|
13
|
'name' => 'CSS Tools tests',
|
14
|
'description' => 'Confirm the custom CSS handling works.',
|
15
|
'group' => 'ctools',
|
16
|
'dependencies' => array('ctools'),
|
17
|
);
|
18
|
}
|
19
|
|
20
|
/**
|
21
|
* {@inheritdoc}
|
22
|
*/
|
23
|
public function setUp(array $modules = array()) {
|
24
|
$modules[] = 'ctools';
|
25
|
parent::setUp($modules);
|
26
|
ctools_include('css');
|
27
|
}
|
28
|
|
29
|
/**
|
30
|
* Test that Stored CSS snippets can be retrieved, filtered or otherwise.
|
31
|
*/
|
32
|
public function testCssStoreFilterRetrieve() {
|
33
|
$css = "#some-id .some-class {\n color: black;\n illegal-key: foo;\n}";
|
34
|
$filtered_css = '#some-id .some-class{color:black;}';
|
35
|
|
36
|
$this->assertNull(ctools_css_retrieve('missing-css-test'), 'Missing css snippet is not found');
|
37
|
|
38
|
$filename1 = ctools_css_store('unfiltered-css-test', $css, FALSE);
|
39
|
$filename2 = ctools_css_store('filtered-css-test', $css, TRUE);
|
40
|
|
41
|
$file_contents = file_get_contents($filename1);
|
42
|
$this->assertEqual($css, $file_contents, 'Unfiltered css file contents are correct');
|
43
|
|
44
|
$this->assertEqual($filename1, ctools_css_retrieve('unfiltered-css-test'), 'Unfiltered css file successfully fetched');
|
45
|
$file_contents = file_get_contents($filename1);
|
46
|
$this->assertEqual($css, $file_contents, 'Unfiltered css file contents are correct');
|
47
|
|
48
|
$this->assertEqual($filename2, ctools_css_retrieve('filtered-css-test'), 'Filtered css file succcesfully fetched');
|
49
|
$file_contents = file_get_contents($filename2);
|
50
|
$this->assertEqual($filtered_css, $file_contents, 'Filtered css file contents are correct');
|
51
|
}
|
52
|
|
53
|
/**
|
54
|
* Test that Stored CSS snippets can be correctly overwritten.
|
55
|
*/
|
56
|
public function testCssStoreOverwrite() {
|
57
|
$css1 = "#some-id .some-class {\n color: black;\n illegal-key: foo;\n}";
|
58
|
|
59
|
$css2 = "#other-id .other-class {\n color: blue;\n illegal-key: foo;\n}";
|
60
|
$filtered_css2 = '#other-id .other-class{color:blue;}';
|
61
|
|
62
|
ctools_css_store('unfiltered-css-test', $css1, FALSE);
|
63
|
ctools_css_store('filtered-css-test', $css1, TRUE);
|
64
|
|
65
|
// Now overwrite the first css with the second version.
|
66
|
$filename3 = ctools_css_store('unfiltered-css-test', $css2, FALSE);
|
67
|
$filename4 = ctools_css_store('filtered-css-test', $css2, TRUE);
|
68
|
|
69
|
$file_contents3 = file_get_contents($filename3);
|
70
|
$file_contents4 = file_get_contents($filename4);
|
71
|
|
72
|
$this->assertEqual($css2, $file_contents3, 'Unfiltered CSS has overwritten earlier contents.');
|
73
|
$this->assertEqual($filtered_css2, $file_contents4, 'Filtered CSS has overwritten earlier contents.');
|
74
|
}
|
75
|
|
76
|
/**
|
77
|
* Test that in case that url is used, the colons survives filtering.
|
78
|
*/
|
79
|
public function testCssFilterURLHandling() {
|
80
|
$css = "#some-id {\n background-image: url(http://example.com/example.gif);\n}";
|
81
|
$css_data = ctools_css_disassemble($css);
|
82
|
$empty_array = array();
|
83
|
$disallowed_values_regex = '/(expression)/';
|
84
|
|
85
|
$intermediate = ctools_css_filter_css_data($css_data, $empty_array, $empty_array, '', $disallowed_values_regex);
|
86
|
$filtered = ctools_css_assemble($intermediate);
|
87
|
|
88
|
$url = (strpos($filtered, 'http://example.com/example.gif') !== FALSE);
|
89
|
$this->assertTrue($url, 'CSS with multiple colons can survive.');
|
90
|
}
|
91
|
|
92
|
/**
|
93
|
* Test that when the CSS has two properties defined they are merged.
|
94
|
*/
|
95
|
public function testCssFilterMergeProperties() {
|
96
|
$css = "#some-id {\n font-size: 12px;\n}\n#some-id {\n color: blue;\n}";
|
97
|
$filtered = ctools_css_filter($css);
|
98
|
$font_size = (strpos($filtered, 'font-size:12px;') !== FALSE);
|
99
|
$color = (strpos($filtered, 'color:blue') !== FALSE);
|
100
|
$this->assertTrue($font_size && $color, 'Multiple properties are merged.');
|
101
|
|
102
|
$css = '@import url("other.css");p {color: red;}';
|
103
|
$filtered = ctools_css_filter($css);
|
104
|
$other_css = (strpos($filtered, 'other.css') === FALSE);
|
105
|
$color = (strpos($filtered, 'color:red') !== FALSE);
|
106
|
$this->assertTrue($other_css && $color, 'CSS is properly sanitized.');
|
107
|
|
108
|
$css = ';p {color: red; font-size: 12px;}';
|
109
|
$filtered = ctools_css_filter($css);
|
110
|
$font_size = (strpos($filtered, 'font-size:12px;') !== FALSE);
|
111
|
$color = (strpos($filtered, 'color:red') !== FALSE);
|
112
|
$this->assertTrue($font_size && $color, 'Multiple properties are retained.');
|
113
|
}
|
114
|
|
115
|
}
|