MediaWiki  REL1_21
CSSMinTest.php
Go to the documentation of this file.
00001 <?php
00008 class CSSMinTest extends MediaWikiTestCase {
00009 
00010         protected function setUp() {
00011                 parent::setUp();
00012 
00013                 $server = 'http://doc.example.org';
00014 
00015                 $this->setMwGlobals( array(
00016                         'wgServer' => $server,
00017                         'wgCanonicalServer' => $server,
00018                 ) );
00019         }
00020 
00024         function testMinify( $code, $expectedOutput ) {
00025                 $minified = CSSMin::minify( $code );
00026 
00027                 $this->assertEquals( $expectedOutput, $minified, 'Minified output should be in the form expected.' );
00028         }
00029 
00030         function provideMinifyCases() {
00031                 return array(
00032                         // Whitespace
00033                         array( "\r\t\f \v\n\r", "" ),
00034                         array( "foo, bar {\n\tprop: value;\n}", "foo,bar{prop:value}" ),
00035 
00036                         // Loose comments
00037                         array( "/* foo */", "" ),
00038                         array( "/*******\n foo\n *******/", "" ),
00039                         array( "/*!\n foo\n */", "" ),
00040 
00041                         // Inline comments in various different places
00042                         array( "/* comment */foo, bar {\n\tprop: value;\n}", "foo,bar{prop:value}" ),
00043                         array( "foo/* comment */, bar {\n\tprop: value;\n}", "foo,bar{prop:value}" ),
00044                         array( "foo,/* comment */ bar {\n\tprop: value;\n}", "foo,bar{prop:value}" ),
00045                         array( "foo, bar/* comment */ {\n\tprop: value;\n}", "foo,bar{prop:value}" ),
00046                         array( "foo, bar {\n\t/* comment */prop: value;\n}", "foo,bar{prop:value}" ),
00047                         array( "foo, bar {\n\tprop: /* comment */value;\n}", "foo,bar{prop:value}" ),
00048                         array( "foo, bar {\n\tprop: value /* comment */;\n}", "foo,bar{prop:value }" ),
00049                         array( "foo, bar {\n\tprop: value; /* comment */\n}", "foo,bar{prop:value; }" ),
00050 
00051                         // Keep track of things that aren't as minified as much as they
00052                         // could be (bug 35493)
00053                         array( 'foo { prop: value ;}', 'foo{prop:value }' ),
00054                         array( 'foo { prop : value; }', 'foo{prop :value}' ),
00055                         array( 'foo { prop: value ; }', 'foo{prop:value }' ),
00056                         array( 'foo { font-family: "foo" , "bar"; }', 'foo{font-family:"foo" ,"bar"}' ),
00057                         array( "foo { src:\n\turl('foo') ,\n\turl('bar') ; }", "foo{src:url('foo') ,url('bar') }" ),
00058 
00059                         // Interesting cases with string values
00060                         // - Double quotes, single quotes
00061                         array( 'foo { content: ""; }', 'foo{content:""}' ),
00062                         array( "foo { content: ''; }", "foo{content:''}" ),
00063                         array( 'foo { content: "\'"; }', 'foo{content:"\'"}' ),
00064                         array( "foo { content: '\"'; }", "foo{content:'\"'}" ),
00065                         // - Whitespace in string values
00066                         array( 'foo { content: " "; }', 'foo{content:" "}' ),
00067                 );
00068         }
00069 
00073         function testRemap( $message, $params, $expectedOutput ) {
00074                 $remapped = call_user_func_array( 'CSSMin::remap', $params );
00075 
00076                 $messageAdd = " Case: $message";
00077                 $this->assertEquals( $expectedOutput, $remapped, 'CSSMin::remap should return the expected url form.' . $messageAdd );
00078         }
00079 
00080         function provideRemapCases() {
00081                 // Parameter signature:
00082                 // CSSMin::remap( $code, $local, $remote, $embedData = true )
00083                 return array(
00084                         array(
00085                                 'Simple case',
00086                                 array( 'foo { prop: url(bar.png); }', false, 'http://example.org', false ),
00087                                 'foo { prop: url(http://example.org/bar.png); }',
00088                         ),
00089                         array(
00090                                 'Without trailing slash',
00091                                 array( 'foo { prop: url(../bar.png); }', false, 'http://example.org/quux', false ),
00092                                 'foo { prop: url(http://example.org/quux/../bar.png); }',
00093                         ),
00094                         array(
00095                                 'With trailing slash on remote (bug 27052)',
00096                                 array( 'foo { prop: url(../bar.png); }', false, 'http://example.org/quux/', false ),
00097                                 'foo { prop: url(http://example.org/quux/../bar.png); }',
00098                         ),
00099                         array(
00100                                 'Guard against stripping double slashes from query',
00101                                 array( 'foo { prop: url(bar.png?corge=//grault); }', false, 'http://example.org/quux/', false ),
00102                                 'foo { prop: url(http://example.org/quux/bar.png?corge=//grault); }',
00103                         ),
00104                         array(
00105                                 'Expand absolute paths',
00106                                 array( 'foo { prop: url(/w/skin/images/bar.png); }', false, 'http://example.org/quux', false ),
00107                                 'foo { prop: url(http://doc.example.org/w/skin/images/bar.png); }',
00108                         ),
00109                 );
00110         }
00111 
00118         function testMinifyWithCSSStringValues( $code, $expectedOutput ) {
00119                 $this->testMinifyOutput( $code, $expectedOutput );
00120         }
00121 
00122         function provideStringCases() {
00123                 return array(
00124                         // String values should be respected
00125                         // - More than one space in a string value
00126                         array( 'foo { content: "  "; }', 'foo{content:"  "}' ),
00127                         // - Using a tab in a string value (turns into a space)
00128                         array( "foo { content: '\t'; }", "foo{content:'\t'}" ),
00129                         // - Using css-like syntax in string values
00130                         array( 'foo::after { content: "{;}"; position: absolute; }', 'foo::after{content:"{;}";position:absolute}' ),
00131                 );
00132         }
00133 }