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
24 function testMinify( $code, $expectedOutput ) {
25 $minified = CSSMin
::minify( $code );
27 $this->assertEquals( $expectedOutput, $minified, 'Minified output should be in the form expected.' );
30 public static function provideMinifyCases() {
33 array( "\r\t\f \v\n\r", "" ),
34 array( "foo, bar {\n\tprop: value;\n}", "foo,bar{prop:value}" ),
37 array( "/* foo */", "" ),
38 array( "/*******\n foo\n *******/", "" ),
39 array( "/*!\n foo\n */", "" ),
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; }" ),
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') }" ),
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:" "}' ),
71 * @dataProvider provideRemapCases
73 function testRemap( $message, $params, $expectedOutput ) {
74 $remapped = call_user_func_array( 'CSSMin::remap', $params );
76 $messageAdd = " Case: $message";
77 $this->assertEquals( $expectedOutput, $remapped, 'CSSMin::remap should return the expected url form.' . $messageAdd );
80 public static function provideRemapCases() {
81 // Parameter signature:
82 // CSSMin::remap( $code, $local, $remote, $embedData = true )
86 array( 'foo { prop: url(bar.png); }', false, 'http://example.org', false ),
87 'foo { prop: url(http://example.org/bar.png); }',
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); }',
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); }',
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); }',
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); }',
113 * Seperated because they are currently broken (bug 35492)
116 * @dataProvider provideStringCases
118 function testMinifyWithCSSStringValues( $code, $expectedOutput ) {
119 $this->testMinifyOutput( $code, $expectedOutput );
122 public static function provideStringCases() {
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}' ),