@covers tags for unit tests
[lhc/web/wiklou.git] / tests / phpunit / includes / libs / CSSMinTest.php
1 <?php
2 /**
3 * This file test the CSSMin library shipped with Mediawiki.
4 *
5 * @author Timo Tijhof
6 */
7
8 class CSSMinTest extends MediaWikiTestCase {
9
10 protected function setUp() {
11 parent::setUp();
12
13 $server = 'http://doc.example.org';
14
15 $this->setMwGlobals( array(
16 'wgServer' => $server,
17 'wgCanonicalServer' => $server,
18 ) );
19 }
20
21 /**
22 * @dataProvider provideMinifyCases
23 * @covers CSSMin::minify
24 */
25 public function testMinify( $code, $expectedOutput ) {
26 $minified = CSSMin::minify( $code );
27
28 $this->assertEquals( $expectedOutput, $minified, 'Minified output should be in the form expected.' );
29 }
30
31 public static function provideMinifyCases() {
32 return array(
33 // Whitespace
34 array( "\r\t\f \v\n\r", "" ),
35 array( "foo, bar {\n\tprop: value;\n}", "foo,bar{prop:value}" ),
36
37 // Loose comments
38 array( "/* foo */", "" ),
39 array( "/*******\n foo\n *******/", "" ),
40 array( "/*!\n foo\n */", "" ),
41
42 // Inline comments in various different places
43 array( "/* comment */foo, bar {\n\tprop: value;\n}", "foo,bar{prop:value}" ),
44 array( "foo/* comment */, bar {\n\tprop: value;\n}", "foo,bar{prop:value}" ),
45 array( "foo,/* comment */ bar {\n\tprop: value;\n}", "foo,bar{prop:value}" ),
46 array( "foo, bar/* comment */ {\n\tprop: value;\n}", "foo,bar{prop:value}" ),
47 array( "foo, bar {\n\t/* comment */prop: value;\n}", "foo,bar{prop:value}" ),
48 array( "foo, bar {\n\tprop: /* comment */value;\n}", "foo,bar{prop:value}" ),
49 array( "foo, bar {\n\tprop: value /* comment */;\n}", "foo,bar{prop:value }" ),
50 array( "foo, bar {\n\tprop: value; /* comment */\n}", "foo,bar{prop:value; }" ),
51
52 // Keep track of things that aren't as minified as much as they
53 // could be (bug 35493)
54 array( 'foo { prop: value ;}', 'foo{prop:value }' ),
55 array( 'foo { prop : value; }', 'foo{prop :value}' ),
56 array( 'foo { prop: value ; }', 'foo{prop:value }' ),
57 array( 'foo { font-family: "foo" , "bar"; }', 'foo{font-family:"foo" ,"bar"}' ),
58 array( "foo { src:\n\turl('foo') ,\n\turl('bar') ; }", "foo{src:url('foo') ,url('bar') }" ),
59
60 // Interesting cases with string values
61 // - Double quotes, single quotes
62 array( 'foo { content: ""; }', 'foo{content:""}' ),
63 array( "foo { content: ''; }", "foo{content:''}" ),
64 array( 'foo { content: "\'"; }', 'foo{content:"\'"}' ),
65 array( "foo { content: '\"'; }", "foo{content:'\"'}" ),
66 // - Whitespace in string values
67 array( 'foo { content: " "; }', 'foo{content:" "}' ),
68 );
69 }
70
71 /**
72 * @dataProvider provideRemapCases
73 * @covers CSSMin::remap
74 */
75 public function testRemap( $message, $params, $expectedOutput ) {
76 $remapped = call_user_func_array( 'CSSMin::remap', $params );
77
78 $messageAdd = " Case: $message";
79 $this->assertEquals( $expectedOutput, $remapped, 'CSSMin::remap should return the expected url form.' . $messageAdd );
80 }
81
82 public static function provideRemapCases() {
83 // Parameter signature:
84 // CSSMin::remap( $code, $local, $remote, $embedData = true )
85 return array(
86 array(
87 'Simple case',
88 array( 'foo { prop: url(bar.png); }', false, 'http://example.org', false ),
89 'foo { prop: url(http://example.org/bar.png); }',
90 ),
91 array(
92 'Without trailing slash',
93 array( 'foo { prop: url(../bar.png); }', false, 'http://example.org/quux', false ),
94 'foo { prop: url(http://example.org/quux/../bar.png); }',
95 ),
96 array(
97 'With trailing slash on remote (bug 27052)',
98 array( 'foo { prop: url(../bar.png); }', false, 'http://example.org/quux/', false ),
99 'foo { prop: url(http://example.org/quux/../bar.png); }',
100 ),
101 array(
102 'Guard against stripping double slashes from query',
103 array( 'foo { prop: url(bar.png?corge=//grault); }', false, 'http://example.org/quux/', false ),
104 'foo { prop: url(http://example.org/quux/bar.png?corge=//grault); }',
105 ),
106 array(
107 'Expand absolute paths',
108 array( 'foo { prop: url(/w/skin/images/bar.png); }', false, 'http://example.org/quux', false ),
109 'foo { prop: url(http://doc.example.org/w/skin/images/bar.png); }',
110 ),
111 );
112 }
113
114 /**
115 * Seperated because they are currently broken (bug 35492)
116 *
117 * @group Broken
118 * @dataProvider provideStringCases
119 * @covers CSSMin::remap
120 */
121 public function testMinifyWithCSSStringValues( $code, $expectedOutput ) {
122 $this->testMinifyOutput( $code, $expectedOutput );
123 }
124
125 public static function provideStringCases() {
126 return array(
127 // String values should be respected
128 // - More than one space in a string value
129 array( 'foo { content: " "; }', 'foo{content:" "}' ),
130 // - Using a tab in a string value (turns into a space)
131 array( "foo { content: '\t'; }", "foo{content:'\t'}" ),
132 // - Using css-like syntax in string values
133 array( 'foo::after { content: "{;}"; position: absolute; }', 'foo::after{content:"{;}";position:absolute}' ),
134 );
135 }
136 }