Blame view

sources/3rdparty/kriswallsmith/assetic/tests/Assetic/Test/Util/CssUtilsTest.php 1.81 KB
6d9380f96   Cédric Dupont   Update sources OC...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
  <?php
  
  /*
   * This file is part of the Assetic package, an OpenSky project.
   *
   * (c) 2010-2014 OpenSky Project Inc
   *
   * For the full copyright and license information, please view the LICENSE
   * file that was distributed with this source code.
   */
  
  namespace Assetic\Test\Util;
  
  use Assetic\Util\CssUtils;
  
  class CssUtilsTest extends \PHPUnit_Framework_TestCase
  {
      public function testFilterUrls()
      {
          $content = 'body { background: url(../images/bg.gif); }';
  
          $matches = array();
          $actual = CssUtils::filterUrls($content, function($match) use(& $matches) {
              $matches[] = $match['url'];
          });
  
          $this->assertEquals(array('../images/bg.gif'), $matches);
      }
  
      public function testExtractImports()
      {
          // These don't work yet (todo):
          // @import url("fineprint.css") print;
          // @import url("bluish.css") projection, tv;
          // @import url('landscape.css') screen and (orientation:landscape);
  
          $content = <<<CSS
  @import 'custom.css';
  @import "common.css" screen, projection;
  body { background: url(../images/bg.gif); }
  CSS;
  
          $expected = array('common.css', 'custom.css');
          $actual = CssUtils::extractImports($content);
  
          $this->assertEquals($expected, array_intersect($expected, $actual), '::extractImports() returns all expected URLs');
          $this->assertEquals(array(), array_diff($actual, $expected), '::extractImports() does not return unexpected URLs');
      }
  
      public function testFilterCommentless()
      {
          $content = 'A/*B*/C/*D*/E';
  
          $filtered = '';
          $result = CssUtils::filterCommentless($content, function($part) use(& $filtered) {
              $filtered .= $part;
              return $part;
          });
  
          $this->assertEquals('ACE', $filtered);
          $this->assertEquals($content, $result);
      }
  }