Projet

Général

Profil

Paste
Télécharger (3,47 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / ctools / tests / css.test @ f0456308

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