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