Merge "(bug 40857) fix non-array sidebar links handling in CologneBlue"
[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 */
24 function testMinify( $code, $expectedOutput ) {
25 $minified = CSSMin::minify( $code );
26
27 $this->assertEquals( $expectedOutput, $minified, 'Minified output should be in the form expected.' );
28 }
29
30 function provideMinifyCases() {
31 return array(
32 // Whitespace
33 array( "\r\t\f \v\n\r", "" ),
34 array( "foo, bar {\n\tprop: value;\n}", "foo,bar{prop:value}" ),
35
36 // Loose comments
37 array( "/* foo */", "" ),
38 array( "/*******\n foo\n *******/", "" ),
39 array( "/*!\n foo\n */", "" ),
40
41 // Inline comments in various different places
42 array( "/* comment */foo, bar {\n\tprop: value;\n}", "foo,bar{prop:value}" ),
43 array( "foo/* comment */, 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, bar/* comment */ {\n\tprop: value;\n}", "foo,bar{prop:value}" ),
46 array( "foo, bar {\n\t/* comment */prop: value;\n}", "foo,bar{prop:value}" ),
47 array( "foo, bar {\n\tprop: /* comment */value;\n}", "foo,bar{prop:value}" ),
48 array( "foo, bar {\n\tprop: value /* comment */;\n}", "foo,bar{prop:value }" ),
49 array( "foo, bar {\n\tprop: value; /* comment */\n}", "foo,bar{prop:value; }" ),
50
51 // Keep track of things that aren't as minified as much as they
52 // could be (bug 35493)
53 array( 'foo { prop: value ;}', 'foo{prop:value }' ),
54 array( 'foo { prop : value; }', 'foo{prop :value}' ),
55 array( 'foo { prop: value ; }', 'foo{prop:value }' ),
56 array( 'foo { font-family: "foo" , "bar"; }', 'foo{font-family:"foo" ,"bar"}' ),
57 array( "foo { src:\n\turl('foo') ,\n\turl('bar') ; }", "foo{src:url('foo') ,url('bar') }" ),
58
59 // Interesting cases with string values
60 // - Double quotes, single quotes
61 array( 'foo { content: ""; }', 'foo{content:""}' ),
62 array( "foo { content: ''; }", "foo{content:''}" ),
63 array( 'foo { content: "\'"; }', 'foo{content:"\'"}' ),
64 array( "foo { content: '\"'; }", "foo{content:'\"'}" ),
65 // - Whitespace in string values
66 array( 'foo { content: " "; }', 'foo{content:" "}' ),
67 );
68 }
69
70 /**
71 * @dataProvider provideRemapCases
72 */
73 function testRemap( $message, $params, $expectedOutput ) {
74 $remapped = call_user_func_array( 'CSSMin::remap', $params );
75
76 $messageAdd = " Case: $message";
77 $this->assertEquals( $expectedOutput, $remapped, 'CSSMin::remap should return the expected url form.' . $messageAdd );
78 }
79
80 function provideRemapCases() {
81 // Parameter signature:
82 // CSSMin::remap( $code, $local, $remote, $embedData = true )
83 return array(
84 array(
85 'Simple case',
86 array( 'foo { prop: url(bar.png); }', false, 'http://example.org', false ),
87 'foo { prop: url(http://example.org/bar.png); }',
88 ),
89 array(
90 'Without trailing slash',
91 array( 'foo { prop: url(../bar.png); }', false, 'http://example.org/quux', false ),
92 'foo { prop: url(http://example.org/quux/../bar.png); }',
93 ),
94 array(
95 'With trailing slash on remote (bug 27052)',
96 array( 'foo { prop: url(../bar.png); }', false, 'http://example.org/quux/', false ),
97 'foo { prop: url(http://example.org/quux/../bar.png); }',
98 ),
99 array(
100 'Guard against stripping double slashes from query',
101 array( 'foo { prop: url(bar.png?corge=//grault); }', false, 'http://example.org/quux/', false ),
102 'foo { prop: url(http://example.org/quux/bar.png?corge=//grault); }',
103 ),
104 array(
105 'Expand absolute paths',
106 array( 'foo { prop: url(/w/skin/images/bar.png); }', false, 'http://example.org/quux', false ),
107 'foo { prop: url(http://doc.example.org/w/skin/images/bar.png); }',
108 ),
109 );
110 }
111
112 /**
113 * Seperated because they are currently broken (bug 35492)
114 *
115 * @group Broken
116 * @dataProvider provideStringCases
117 */
118 function testMinifyWithCSSStringValues( $code, $expectedOutput ) {
119 $this->testMinifyOutput( $code, $expectedOutput );
120 }
121
122 function provideStringCases() {
123 return array(
124 // String values should be respected
125 // - More than one space in a string value
126 array( 'foo { content: " "; }', 'foo{content:" "}' ),
127 // - Using a tab in a string value (turns into a space)
128 array( "foo { content: '\t'; }", "foo{content:'\t'}" ),
129 // - Using css-like syntax in string values
130 array( 'foo::after { content: "{;}"; position: absolute; }', 'foo::after{content:"{;}";position:absolute}' ),
131 );
132 }
133 }