Projet

Général

Profil

Révision 7e72b748

Ajouté par Assos Assos il y a plus de 6 ans

Weekly update of contrib modules

Voir les différences:

drupal7/sites/all/modules/ctools/tests/css.test
1 1
<?php
2
/**
3
 * @file
4
 * Tests for different parts of the ctools plugin system.
5
 */
6 2

  
7 3
/**
8 4
 * Test menu links depending on user permissions.
9 5
 */
10 6
class CtoolsCssTestCase extends DrupalWebTestCase {
7

  
8
  /**
9
   * {@inheritDoc}
10
   */
11 11
  public static function getInfo() {
12 12
    return array(
13 13
      'name' => 'CSS Tools tests',
14
      'description' => '...',
14
      'description' => 'Confirm the custom CSS handling works.',
15 15
      'group' => 'ctools',
16
      'dependencies' => array('ctools'),
16 17
    );
17 18
  }
18 19

  
19
  function setUp() {
20
    // Additionally enable contact module.
21
    parent::setUp('ctools');
20
  /**
21
   * {@inheritDoc}
22
   */
23
  function setUp(array $modules = array()) {
24
    $modules[] = 'ctools';
25
    parent::setUp($modules);
26
    ctools_include('css');
22 27
  }
23 28

  
24 29
  /**
25
   * Test that cached plugins are loaded correctly.
30
   * Test that Stored CSS snippets can be retrieved, filtered or otherwise.
26 31
   */
27
  function testCssStuff() {
32
  public function testCssStoreFilterRetrieve() {
28 33
    $css = "#some-id .some-class {\n  color: black;\n  illegal-key: foo;\n}";
29 34
    $filtered_css = '#some-id .some-class{color:black;}';
30 35

  
31
    ctools_include('css');
36
    $this->assertNull(ctools_css_retrieve('missing-css-test'), 'Missing css snippet is not found');
37

  
32 38
    $filename1 = ctools_css_store('unfiltered-css-test', $css, FALSE);
33 39
    $filename2 = ctools_css_store('filtered-css-test', $css, TRUE);
34 40

  
41
    $file_contents = file_get_contents($filename1);
42
    $this->assertEqual($css, $file_contents, 'Unfiltered css file contents are correct');
43

  
35 44
    $this->assertEqual($filename1, ctools_css_retrieve('unfiltered-css-test'), 'Unfiltered css file successfully fetched');
36 45
    $file_contents = file_get_contents($filename1);
37 46
    $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 47

  
42 48
    $this->assertEqual($filename2, ctools_css_retrieve('filtered-css-test'), 'Filtered css file succcesfully fetched');
43 49
    $file_contents = file_get_contents($filename2);
44 50
    $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
  /**
54
   * @todo Test  db-row-exist but file-not-exist case in ctools_css_retrieve().
55
   */
51 56

  
57
  /**
58
   * Test that Stored CSS snippets can be correctly overwritten.
59
   */
60
  public function testCssStoreOverwrite() {
61
    $css1 = "#some-id .some-class {\n  color: black;\n  illegal-key: foo;\n}";
62

  
63
    $css2 = "#other-id .other-class {\n  color: blue;\n  illegal-key: foo;\n}";
64
    $filtered_css2 = '#other-id .other-class{color:blue;}';
65

  
66
    ctools_css_store('unfiltered-css-test', $css1, FALSE);
67
    ctools_css_store('filtered-css-test', $css1, TRUE);
68

  
69
    // Now overwrite the first css with the second version.
70

  
71
    $filename3 = ctools_css_store('unfiltered-css-test', $css2, FALSE);
72
    $filename4 = ctools_css_store('filtered-css-test', $css2, TRUE);
73

  
74
    $file_contents3 = file_get_contents($filename3);
75
    $file_contents4 = file_get_contents($filename4);
76

  
77
    $this->assertEqual($css2, $file_contents3, 'Unfiltered CSS has overwritten earlier contents.');
78
    $this->assertEqual($filtered_css2, $file_contents4, 'Filtered CSS has overwritten earlier contents.');
79
  }
52 80

  
53
    // Test that in case that url can be used, the value surives when a colon is in it.
81
  /**
82
   * Test that in case that url is used, the colons survives filtering.
83
   */
84
  public function testCssFilterURLHandling() {
54 85
    $css = "#some-id {\n  background-image: url(http://example.com/example.gif);\n}";
55 86
    $css_data = ctools_css_disassemble($css);
56 87
    $empty_array = array();
57 88
    $disallowed_values_regex = '/(expression)/';
58
    $filtered = ctools_css_assemble(ctools_css_filter_css_data($css_data, $empty_array, $empty_array, '', $disallowed_values_regex));
89

  
90
    $intermediate = ctools_css_filter_css_data($css_data, $empty_array, $empty_array, '', $disallowed_values_regex);
91
    $filtered = ctools_css_assemble($intermediate);
92

  
59 93
    $url = (strpos($filtered, 'http://example.com/example.gif') !== FALSE);
60 94
    $this->assertTrue($url, 'CSS with multiple colons can survive.');
95
  }
61 96

  
62
    // Test that in case the CSS has two properties defined are merged.
97
  /**
98
   * Test that when the CSS has two properties defined they are merged.
99
   */
100
  public function testCssFilterMergeProperties() {
63 101
    $css = "#some-id {\n  font-size: 12px;\n}\n#some-id {\n  color: blue;\n}";
64 102
    $filtered = ctools_css_filter($css);
65 103
    $font_size = (strpos($filtered, 'font-size:12px;') !== FALSE);
......
78 116
    $color = (strpos($filtered, 'color:red') !== FALSE);
79 117
    $this->assertTrue($font_size && $color, 'Multiple properties are retained.');
80 118
  }
119

  
81 120
}

Formats disponibles : Unified diff