1 |
85ad3d82
|
Assos Assos
|
<?php
|
2 |
|
|
|
3 |
|
|
/**
|
4 |
|
|
* Test menu links depending on user permissions.
|
5 |
|
|
*/
|
6 |
|
|
class CtoolsCssTestCase extends DrupalWebTestCase {
|
7 |
7e72b748
|
Assos Assos
|
|
8 |
|
|
/**
|
9 |
c304a780
|
Assos Assos
|
* {@inheritdoc}
|
10 |
7e72b748
|
Assos Assos
|
*/
|
11 |
85ad3d82
|
Assos Assos
|
public static function getInfo() {
|
12 |
|
|
return array(
|
13 |
|
|
'name' => 'CSS Tools tests',
|
14 |
7e72b748
|
Assos Assos
|
'description' => 'Confirm the custom CSS handling works.',
|
15 |
1e39edcb
|
Assos Assos
|
'group' => 'ctools',
|
16 |
7e72b748
|
Assos Assos
|
'dependencies' => array('ctools'),
|
17 |
85ad3d82
|
Assos Assos
|
);
|
18 |
|
|
}
|
19 |
|
|
|
20 |
7e72b748
|
Assos Assos
|
/**
|
21 |
c304a780
|
Assos Assos
|
* {@inheritdoc}
|
22 |
7e72b748
|
Assos Assos
|
*/
|
23 |
c304a780
|
Assos Assos
|
public function setUp(array $modules = array()) {
|
24 |
7e72b748
|
Assos Assos
|
$modules[] = 'ctools';
|
25 |
|
|
parent::setUp($modules);
|
26 |
|
|
ctools_include('css');
|
27 |
85ad3d82
|
Assos Assos
|
}
|
28 |
|
|
|
29 |
|
|
/**
|
30 |
7e72b748
|
Assos Assos
|
* Test that Stored CSS snippets can be retrieved, filtered or otherwise.
|
31 |
85ad3d82
|
Assos Assos
|
*/
|
32 |
7e72b748
|
Assos Assos
|
public function testCssStoreFilterRetrieve() {
|
33 |
85ad3d82
|
Assos Assos
|
$css = "#some-id .some-class {\n color: black;\n illegal-key: foo;\n}";
|
34 |
|
|
$filtered_css = '#some-id .some-class{color:black;}';
|
35 |
|
|
|
36 |
7e72b748
|
Assos Assos
|
$this->assertNull(ctools_css_retrieve('missing-css-test'), 'Missing css snippet is not found');
|
37 |
|
|
|
38 |
85ad3d82
|
Assos Assos
|
$filename1 = ctools_css_store('unfiltered-css-test', $css, FALSE);
|
39 |
|
|
$filename2 = ctools_css_store('filtered-css-test', $css, TRUE);
|
40 |
|
|
|
41 |
7e72b748
|
Assos Assos
|
$file_contents = file_get_contents($filename1);
|
42 |
|
|
$this->assertEqual($css, $file_contents, 'Unfiltered css file contents are correct');
|
43 |
|
|
|
44 |
85ad3d82
|
Assos Assos
|
$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 |
7e72b748
|
Assos Assos
|
}
|
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 |
85ad3d82
|
Assos Assos
|
|
76 |
7e72b748
|
Assos Assos
|
/**
|
77 |
|
|
* Test that in case that url is used, the colons survives filtering.
|
78 |
|
|
*/
|
79 |
|
|
public function testCssFilterURLHandling() {
|
80 |
85ad3d82
|
Assos Assos
|
$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 |
7e72b748
|
Assos Assos
|
|
85 |
|
|
$intermediate = ctools_css_filter_css_data($css_data, $empty_array, $empty_array, '', $disallowed_values_regex);
|
86 |
|
|
$filtered = ctools_css_assemble($intermediate);
|
87 |
|
|
|
88 |
85ad3d82
|
Assos Assos
|
$url = (strpos($filtered, 'http://example.com/example.gif') !== FALSE);
|
89 |
|
|
$this->assertTrue($url, 'CSS with multiple colons can survive.');
|
90 |
7e72b748
|
Assos Assos
|
}
|
91 |
85ad3d82
|
Assos Assos
|
|
92 |
7e72b748
|
Assos Assos
|
/**
|
93 |
|
|
* Test that when the CSS has two properties defined they are merged.
|
94 |
|
|
*/
|
95 |
|
|
public function testCssFilterMergeProperties() {
|
96 |
85ad3d82
|
Assos Assos
|
$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 |
7e72b748
|
Assos Assos
|
|
115 |
85ad3d82
|
Assos Assos
|
} |