css.test 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. /**
  3. * @file
  4. * Tests for different parts of the ctools plugin system.
  5. */
  6. /**
  7. * Test menu links depending on user permissions.
  8. */
  9. class CtoolsCssTestCase extends DrupalWebTestCase {
  10. public static function getInfo() {
  11. return array(
  12. 'name' => 'CSS Tools tests',
  13. 'description' => '...',
  14. 'group' => 'Chaos Tools Suite',
  15. );
  16. }
  17. function setUp() {
  18. // Additionally enable contact module.
  19. parent::setUp('ctools');
  20. }
  21. /**
  22. * Test that cached plugins are loaded correctly.
  23. */
  24. function testCssStuff() {
  25. $css = "#some-id .some-class {\n color: black;\n illegal-key: foo;\n}";
  26. $filtered_css = '#some-id .some-class{color:black;}';
  27. ctools_include('css');
  28. $filename1 = ctools_css_store('unfiltered-css-test', $css, FALSE);
  29. $filename2 = ctools_css_store('filtered-css-test', $css, TRUE);
  30. $this->assertEqual($filename1, ctools_css_retrieve('unfiltered-css-test'), 'Unfiltered css file successfully fetched');
  31. $file_contents = file_get_contents($filename1);
  32. $this->assertEqual($css, $file_contents, 'Unfiltered css file contents are correct');
  33. // $match = $filename1 == ctools_css_retrieve('unfiltered-css-test') ? 'Match' : 'No match';
  34. // $output .= '<pre>Unfiltered: ' . $filename1 . ' ' . $match . '</pre>';
  35. // $output .= '<pre>' . file_get_contents($filename1) . '</pre>';
  36. $this->assertEqual($filename2, ctools_css_retrieve('filtered-css-test'), 'Filtered css file succcesfully fetched');
  37. $file_contents = file_get_contents($filename2);
  38. $this->assertEqual($filtered_css, $file_contents, 'Filtered css file contents are correct');
  39. // $match = $filename2 == ctools_css_retrieve('filtered-css-test') ? 'Match' : 'No match';
  40. // $output .= '<pre>Filtered: ' . $filename2 . ' ' . $match . '</pre>';
  41. // $output .= '<pre>' . file_get_contents($filename2) . '</pre>';
  42. //
  43. // drupal_add_css($filename2, array('type' => 'file'));
  44. // return array('#markup' => $output);
  45. // Test that in case that url can be used, the value surives when a colon is in it.
  46. $css = "#some-id {\n background-image: url(http://example.com/example.gif);\n}";
  47. $css_data = ctools_css_disassemble($css);
  48. $empty_array = array();
  49. $disallowed_values_regex = '/(expression)/';
  50. $filtered = ctools_css_assemble(ctools_css_filter_css_data($css_data, $empty_array, $empty_array, '', $disallowed_values_regex));
  51. $url = (strpos($filtered, 'http://example.com/example.gif') !== FALSE);
  52. $this->assertTrue($url, 'CSS with multiple colons can survive.');
  53. // Test that in case the CSS has two properties defined are merged.
  54. $css = "#some-id {\n font-size: 12px;\n}\n#some-id {\n color: blue;\n}";
  55. $filtered = ctools_css_filter($css);
  56. $font_size = (strpos($filtered, 'font-size:12px;') !== FALSE);
  57. $color = (strpos($filtered, 'color:blue') !== FALSE);
  58. $this->assertTrue($font_size && $color, 'Multiple properties are merged.');
  59. $css = '@import url("other.css");p {color: red;}';
  60. $filtered = ctools_css_filter($css);
  61. $other_css = (strpos($filtered, 'other.css') === FALSE);
  62. $color = (strpos($filtered, 'color:red') !== FALSE);
  63. $this->assertTrue($other_css && $color, 'CSS is properly sanitized.');
  64. $css = ';p {color: red; font-size: 12px;}';
  65. $filtered = ctools_css_filter($css);
  66. $font_size = (strpos($filtered, 'font-size:12px;') !== FALSE);
  67. $color = (strpos($filtered, 'color:red') !== FALSE);
  68. $this->assertTrue($font_size && $color, 'Multiple properties are retained.');
  69. }
  70. }