3 * This file test the CSSMin library shipped with Mediawiki.
8 class CSSMinTest
extends MediaWikiTestCase
{
10 protected function setUp() {
13 $server = 'http://doc.example.org';
15 $this->setMwGlobals( array(
16 'wgServer' => $server,
17 'wgCanonicalServer' => $server,
22 * @dataProvider provideMinifyCases
23 * @covers CSSMin::minify
25 public function testMinify( $code, $expectedOutput ) {
26 $minified = CSSMin
::minify( $code );
28 $this->assertEquals( $expectedOutput, $minified, 'Minified output should be in the form expected.' );
31 public static function provideMinifyCases() {
34 array( "\r\t\f \v\n\r", "" ),
35 array( "foo, bar {\n\tprop: value;\n}", "foo,bar{prop:value}" ),
38 array( "/* foo */", "" ),
39 array( "/*******\n foo\n *******/", "" ),
40 array( "/*!\n foo\n */", "" ),
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; }" ),
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') }" ),
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:" "}' ),
72 * @dataProvider provideRemapCases
73 * @covers CSSMin::remap
75 public function testRemap( $message, $params, $expectedOutput ) {
76 $remapped = call_user_func_array( 'CSSMin::remap', $params );
78 $messageAdd = " Case: $message";
79 $this->assertEquals( $expectedOutput, $remapped, 'CSSMin::remap should return the expected url form.' . $messageAdd );
82 public static function provideRemapCases() {
83 // Parameter signature:
84 // CSSMin::remap( $code, $local, $remote, $embedData = true )
88 array( 'foo { prop: url(bar.png); }', false, 'http://example.org', false ),
89 'foo { prop: url(http://example.org/bar.png); }',
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); }',
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); }',
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); }',
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); }',
115 * Seperated because they are currently broken (bug 35492)
118 * @dataProvider provideStringCases
119 * @covers CSSMin::remap
121 public function testMinifyWithCSSStringValues( $code, $expectedOutput ) {
122 $this->testMinifyOutput( $code, $expectedOutput );
125 public static function provideStringCases() {
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}' ),