123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- <?php
- class CtoolsCssTestCase extends DrupalWebTestCase {
- public static function getInfo() {
- return array(
- 'name' => 'CSS Tools tests',
- 'description' => '...',
- 'group' => 'Chaos Tools Suite',
- );
- }
- function setUp() {
-
- parent::setUp('ctools');
- }
-
- function testCssStuff() {
- $css = "#some-id .some-class {\n color: black;\n illegal-key: foo;\n}";
- $filtered_css = '#some-id .some-class{color:black;}';
- ctools_include('css');
- $filename1 = ctools_css_store('unfiltered-css-test', $css, FALSE);
- $filename2 = ctools_css_store('filtered-css-test', $css, TRUE);
- $this->assertEqual($filename1, ctools_css_retrieve('unfiltered-css-test'), 'Unfiltered css file successfully fetched');
- $file_contents = file_get_contents($filename1);
- $this->assertEqual($css, $file_contents, 'Unfiltered css file contents are correct');
- $this->assertEqual($filename2, ctools_css_retrieve('filtered-css-test'), 'Filtered css file succcesfully fetched');
- $file_contents = file_get_contents($filename2);
- $this->assertEqual($filtered_css, $file_contents, 'Filtered css file contents are correct');
-
-
- $css = "#some-id {\n background-image: url(http://example.com/example.gif);\n}";
- $css_data = ctools_css_disassemble($css);
- $empty_array = array();
- $disallowed_values_regex = '/(expression)/';
- $filtered = ctools_css_assemble(ctools_css_filter_css_data($css_data, $empty_array, $empty_array, '', $disallowed_values_regex));
- $url = (strpos($filtered, 'http://example.com/example.gif') !== FALSE);
- $this->assertTrue($url, 'CSS with multiple colons can survive.');
-
- $css = "#some-id {\n font-size: 12px;\n}\n#some-id {\n color: blue;\n}";
- $filtered = ctools_css_filter($css);
- $font_size = (strpos($filtered, 'font-size:12px;') !== FALSE);
- $color = (strpos($filtered, 'color:blue') !== FALSE);
- $this->assertTrue($font_size && $color, 'Multiple properties are merged.');
- $css = '@import url("other.css");p {color: red;}';
- $filtered = ctools_css_filter($css);
- $other_css = (strpos($filtered, 'other.css') === FALSE);
- $color = (strpos($filtered, 'color:red') !== FALSE);
- $this->assertTrue($other_css && $color, 'CSS is properly sanitized.');
- $css = ';p {color: red; font-size: 12px;}';
- $filtered = ctools_css_filter($css);
- $font_size = (strpos($filtered, 'font-size:12px;') !== FALSE);
- $color = (strpos($filtered, 'color:red') !== FALSE);
- $this->assertTrue($font_size && $color, 'Multiple properties are retained.');
- }
- }
|