17 $server =
'http://doc.example.org';
20 'wgServer' => $server,
21 'wgCanonicalServer' => $server,
30 $fileName =
wfTempDir() . DIRECTORY_SEPARATOR . uniqid(
'MW_PHPUnit_CSSMinTest_' ) .
'.'
33 file_put_contents( $fileName, $fileContents );
34 $this->assertSame( $expected, CSSMin::getMimeType( $fileName ) );
39 'JPEG with short extension' => [
44 'JPEG with long extension' => [
50 "\x89\x50\x4E\x47\x0D\x0A\x1A\x0A",
55 'PNG extension but JPEG content' => [
60 'JPEG extension but PNG content' => [
61 "\x89\x50\x4E\x47\x0D\x0A\x1A\x0A",
65 'PNG extension but SVG content' => [
66 '<?xml version="1.0"?><svg></svg>',
70 'SVG extension but PNG content' => [
71 "\x89\x50\x4E\x47\x0D\x0A\x1A\x0A",
76 'SVG with all headers' => [
77 '<?xml version="1.0"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" '
78 .
'"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg></svg>',
82 'SVG with XML header only' => [
83 '<?xml version="1.0"?><svg></svg>',
87 'SVG with DOCTYPE only' => [
88 '<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" '
89 .
'"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg></svg>',
93 'SVG without any header' => [
106 $minified = CSSMin::minify(
$code );
111 'Minified output should be in the form expected.'
118 [
"\r\t\f \v\n\r",
"" ],
119 [
"foo, bar {\n\tprop: value;\n}",
"foo,bar{prop:value}" ],
123 [
"/*******\n foo\n *******/",
"" ],
124 [
"/*!\n foo\n */",
"" ],
127 [
"/* comment */foo, bar {\n\tprop: value;\n}",
"foo,bar{prop:value}" ],
128 [
"foo/* comment */, bar {\n\tprop: value;\n}",
"foo,bar{prop:value}" ],
129 [
"foo,/* comment */ bar {\n\tprop: value;\n}",
"foo,bar{prop:value}" ],
130 [
"foo, bar/* comment */ {\n\tprop: value;\n}",
"foo,bar{prop:value}" ],
131 [
"foo, bar {\n\t/* comment */prop: value;\n}",
"foo,bar{prop:value}" ],
132 [
"foo, bar {\n\tprop: /* comment */value;\n}",
"foo,bar{prop:value}" ],
133 [
"foo, bar {\n\tprop: value /* comment */;\n}",
"foo,bar{prop:value }" ],
134 [
"foo, bar {\n\tprop: value; /* comment */\n}",
"foo,bar{prop:value; }" ],
138 [
'foo { prop: value ;}',
'foo{prop:value }' ],
139 [
'foo { prop : value; }',
'foo{prop :value}' ],
140 [
'foo { prop: value ; }',
'foo{prop:value }' ],
141 [
'foo { font-family: "foo" , "bar"; }',
'foo{font-family:"foo" ,"bar"}' ],
142 [
"foo { src:\n\turl('foo') ,\n\turl('bar') ; }",
"foo{src:url('foo') ,url('bar') }" ],
146 [
'foo { content: ""; }',
'foo{content:""}' ],
147 [
"foo { content: ''; }",
"foo{content:''}" ],
148 [
'foo { content: "\'"; }',
'foo{content:"\'"}' ],
149 [
"foo { content: '\"'; }",
"foo{content:'\"'}" ],
151 [
'foo { content: " "; }',
'foo{content:" "}' ],
157 [
true,
'http://localhost/w/red.gif?123' ],
158 [
true,
'https://example.org/x.png' ],
159 [
true,
'//example.org/x.y.z/image.png' ],
160 [
true,
'//localhost/styles.css?query=yes' ],
161 [
true,
'data:image/gif;base64,R0lGODlhAQABAIAAAP8AADAAACwAAAAAAQABAAACAkQBADs=' ],
164 [
false,
'./x.gif' ],
165 [
false,
'../x.gif' ],
181 [
false,
'./x.gif' ],
182 [
false,
'../x.gif' ],
203 $remapped = call_user_func_array(
'CSSMin::remap',
$params );
205 $messageAdd =
" Case: $message";
209 'CSSMin::remap should return the expected url form.' . $messageAdd
219 [
'foo { prop: url(bar.png); }',
false,
'http://example.org',
false ],
220 'foo { prop: url(http://example.org/bar.png); }',
223 'Without trailing slash',
224 [
'foo { prop: url(../bar.png); }',
false,
'http://example.org/quux',
false ],
225 'foo { prop: url(http://example.org/bar.png); }',
228 'With trailing slash on remote (T29052)',
229 [
'foo { prop: url(../bar.png); }',
false,
'http://example.org/quux/',
false ],
230 'foo { prop: url(http://example.org/bar.png); }',
233 'Guard against stripping double slashes from query',
234 [
'foo { prop: url(bar.png?corge=//grault); }',
false,
'http://example.org/quux/',
false ],
235 'foo { prop: url(http://example.org/quux/bar.png?corge=//grault); }',
238 'Expand absolute paths',
239 [
'foo { prop: url(/w/skin/images/bar.png); }',
false,
'http://example.org/quux',
false ],
240 'foo { prop: url(http://doc.example.org/w/skin/images/bar.png); }',
243 "Don't barf at behavior: url(#default#behaviorName) - T162973",
244 [
'foo { behavior: url(#default#bar); }',
false,
'/w/',
false ],
245 'foo { behavior: url("#default#bar"); }',
258 $localPath = __DIR__ .
'/../../data/cssmin';
259 $remotePath =
'http://localhost/w';
261 $realOutput = CSSMin::remap(
$input, $localPath, $remotePath );
262 $this->assertEquals( $expectedOutput, $realOutput,
"CSSMin::remap: $message" );
272 $red =
'data:image/gif;base64,R0lGODlhAQABAIAAAP8AADAAACwAAAAAAQABAAACAkQBADs=';
273 $green =
'data:image/gif;base64,R0lGODlhAQABAIAAAACAADAAACwAAAAAAQABAAACAkQBADs=';
274 $svg =
'data:image/svg+xml,%3C%3Fxml version=%221.0%22 encoding=%22UTF-8%22%3F%3E%0A'
275 .
'%3Csvg xmlns=%22http://www.w3.org/2000/svg%22 width=%228%22 height='
276 .
'%228%22%3E%0A%09%3Ccircle cx=%224%22 cy=%224%22 r=%222%22/%3E%0A%3C/svg%3E%0A';
282 'foo { background: url(red.gif); }',
283 'foo { background: url(http://localhost/w/red.gif?34ac6); }',
286 'Regular file (missing)',
287 'foo { background: url(theColorOfHerHair.gif); }',
288 'foo { background: url(http://localhost/w/theColorOfHerHair.gif); }',
292 'foo { background: url(http://example.org/w/foo.png); }',
293 'foo { background: url(http://example.org/w/foo.png); }',
296 'Protocol-relative remote URL',
297 'foo { background: url(//example.org/w/foo.png); }',
298 'foo { background: url(//example.org/w/foo.png); }',
301 'Remote URL with query',
302 'foo { background: url(http://example.org/w/foo.png?query=yes); }',
303 'foo { background: url(http://example.org/w/foo.png?query=yes); }',
306 'Protocol-relative remote URL with query',
307 'foo { background: url(//example.org/w/foo.png?query=yes); }',
308 'foo { background: url(//example.org/w/foo.png?query=yes); }',
311 'Domain-relative URL',
312 'foo { background: url(/static/foo.png); }',
313 'foo { background: url(http://doc.example.org/static/foo.png); }',
316 'Domain-relative URL with query',
317 'foo { background: url(/static/foo.png?query=yes); }',
318 'foo { background: url(http://doc.example.org/static/foo.png?query=yes); }',
321 'Remote URL (unnecessary quotes not preserved)',
322 'foo { background: url("http://example.org/w/unnecessary-quotes.png"); }',
323 'foo { background: url(http://example.org/w/unnecessary-quotes.png); }',
327 'foo { /* @embed */ background: url(red.gif); }',
328 "foo { background: url($red); background: url(http://localhost/w/red.gif?34ac6)!ie; }",
331 'Embedded file, other comments before the rule',
332 "foo { /* Bar. */ /* @embed */ background: url(red.gif); }",
333 "foo { /* Bar. */ background: url($red); /* Bar. */ background: url(http://localhost/w/red.gif?34ac6)!ie; }",
336 'Can not re-embed data: URIs',
337 "foo { /* @embed */ background: url($red); }",
338 "foo { background: url($red); }",
341 'Can not remap data: URIs',
342 "foo { background: url($red); }",
343 "foo { background: url($red); }",
346 'Can not embed remote URLs',
347 'foo { /* @embed */ background: url(http://example.org/w/foo.png); }',
348 'foo { background: url(http://example.org/w/foo.png); }',
351 'Embedded file (inline @embed)',
352 'foo { background: /* @embed */ url(red.gif); }',
353 "foo { background: url($red); "
354 .
"background: url(http://localhost/w/red.gif?34ac6)!ie; }",
357 'Can not embed large files',
358 'foo { /* @embed */ background: url(large.png); }',
359 "foo { background: url(http://localhost/w/large.png?e3d1f); }",
362 'SVG files are embedded without base64 encoding and unnecessary IE 6 and 7 fallback',
363 'foo { /* @embed */ background: url(circle.svg); }',
364 "foo { background: url(\"$svg\"); }",
367 'Two regular files in one rule',
368 'foo { background: url(red.gif), url(green.gif); }',
369 'foo { background: url(http://localhost/w/red.gif?34ac6), '
370 .
'url(http://localhost/w/green.gif?13651); }',
373 'Two embedded files in one rule',
374 'foo { /* @embed */ background: url(red.gif), url(green.gif); }',
375 "foo { background: url($red), url($green); "
376 .
"background: url(http://localhost/w/red.gif?34ac6), "
377 .
"url(http://localhost/w/green.gif?13651)!ie; }",
380 'Two embedded files in one rule (inline @embed)',
381 'foo { background: /* @embed */ url(red.gif), /* @embed */ url(green.gif); }',
382 "foo { background: url($red), url($green); "
383 .
"background: url(http://localhost/w/red.gif?34ac6), "
384 .
"url(http://localhost/w/green.gif?13651)!ie; }",
387 'Two embedded files in one rule (inline @embed), one too large',
388 'foo { background: /* @embed */ url(red.gif), /* @embed */ url(large.png); }',
389 "foo { background: url($red), url(http://localhost/w/large.png?e3d1f); "
390 .
"background: url(http://localhost/w/red.gif?34ac6), "
391 .
"url(http://localhost/w/large.png?e3d1f)!ie; }",
394 'Practical example with some noise',
395 'foo { /* @embed */ background: #f9f9f9 url(red.gif) 0 0 no-repeat; }',
396 "foo { background: #f9f9f9 url($red) 0 0 no-repeat; "
397 .
"background: #f9f9f9 url(http://localhost/w/red.gif?34ac6) 0 0 no-repeat!ie; }",
400 'Does not mess with other properties',
401 'foo { color: red; background: url(red.gif); font-size: small; }',
402 'foo { color: red; background: url(http://localhost/w/red.gif?34ac6); font-size: small; }',
405 'Spacing and miscellanea not changed (1)',
406 'foo { background: url(red.gif); }',
407 'foo { background: url(http://localhost/w/red.gif?34ac6); }',
410 'Spacing and miscellanea not changed (2)',
411 'foo {background:url(red.gif)}',
412 'foo {background:url(http://localhost/w/red.gif?34ac6)}',
415 'Spaces within url() parentheses are ignored',
416 'foo { background: url( red.gif ); }',
417 'foo { background: url(http://localhost/w/red.gif?34ac6); }',
420 '@import rule to local file (should we remap this?)',
421 '@import url(/styles.css)',
422 '@import url(http://doc.example.org/styles.css)',
425 '@import rule to local file (should we remap this?)',
426 '@import url(/styles.css)',
427 '@import url(http://doc.example.org/styles.css)',
430 '@import rule to URL',
431 '@import url(//localhost/styles.css?query=val)',
432 '@import url(//localhost/styles.css?query=val)',
435 'Background URL (double quotes)',
436 'foo { background: url("//localhost/styles.css?quoted=double") }',
437 'foo { background: url(//localhost/styles.css?quoted=double) }',
440 'Background URL (single quotes)',
441 'foo { background: url(\'//localhost/styles.css?quoted=single\') }',
442 'foo { background: url(//localhost/styles.css?quoted=single) }',
445 'Background URL (containing parentheses; T60473)',
446 'foo { background: url("//localhost/styles.css?query=(parens)") }',
447 'foo { background: url("//localhost/styles.css?query=(parens)") }',
450 'Background URL (double quoted, containing single quotes; T60473)',
451 'foo { background: url("//localhost/styles.css?quote=\'") }',
452 'foo { background: url("//localhost/styles.css?quote=\'") }',
455 'Background URL (single quoted, containing double quotes; T60473)',
456 'foo { background: url(\'//localhost/styles.css?quote="\') }',
457 'foo { background: url("//localhost/styles.css?quote=\"") }',
460 'Simple case with comments before url',
461 'foo { prop: /* some {funny;} comment */ url(bar.png); }',
462 'foo { prop: /* some {funny;} comment */ url(http://localhost/w/bar.png); }',
465 'Simple case with comments after url',
466 'foo { prop: url(red.gif)/* some {funny;} comment */ ; }',
467 'foo { prop: url(http://localhost/w/red.gif?34ac6)/* some {funny;} comment */ ; }',
470 'Embedded file with comment before url',
471 'foo { /* @embed */ background: /* some {funny;} comment */ url(red.gif); }',
472 "foo { background: /* some {funny;} comment */ url($red); background: /* some {funny;} comment */ url(http://localhost/w/red.gif?34ac6)!ie; }",
475 'Embedded file with comments inside and outside the rule',
476 'foo { /* @embed */ background: url(red.gif) /* some {foo;} comment */; /* some {bar;} comment */ }',
477 "foo { background: url($red) /* some {foo;} comment */; background: url(http://localhost/w/red.gif?34ac6) /* some {foo;} comment */!ie; /* some {bar;} comment */ }",
480 'Embedded file with comment outside the rule',
481 'foo { /* @embed */ background: url(red.gif); /* some {funny;} comment */ }',
482 "foo { background: url($red); background: url(http://localhost/w/red.gif?34ac6)!ie; /* some {funny;} comment */ }",
485 'Rule with two urls, each with comments',
486 '{ background: /*asd*/ url(something.png); background: /*jkl*/ url(something.png); }',
487 '{ background: /*asd*/ url(http://localhost/w/something.png); background: /*jkl*/ url(http://localhost/w/something.png); }',
490 'Sanity check for offending line from jquery.ui.theme.css (T62077)',
491 '.ui-state-default, .ui-widget-content .ui-state-default, .ui-widget-header .ui-state-default { border: 1px solid #d3d3d3/*{borderColorDefault}*/; background: #e6e6e6/*{bgColorDefault}*/ url(images/ui-bg_glass_75_e6e6e6_1x400.png)/*{bgImgUrlDefault}*/ 50%/*{bgDefaultXPos}*/ 50%/*{bgDefaultYPos}*/ repeat-x/*{bgDefaultRepeat}*/; font-weight: normal/*{fwDefault}*/; color: #555555/*{fcDefault}*/; }',
492 '.ui-state-default, .ui-widget-content .ui-state-default, .ui-widget-header .ui-state-default { border: 1px solid #d3d3d3/*{borderColorDefault}*/; background: #e6e6e6/*{bgColorDefault}*/ url(http://localhost/w/images/ui-bg_glass_75_e6e6e6_1x400.png)/*{bgImgUrlDefault}*/ 50%/*{bgDefaultXPos}*/ 50%/*{bgDefaultYPos}*/ repeat-x/*{bgDefaultRepeat}*/; font-weight: normal/*{fwDefault}*/; color: #555555/*{fcDefault}*/; }',
507 CSSMin::buildUrlValue(
$input ),
508 "CSSMin::buildUrlValue: $message"
516 'scheme://user@domain:port/~user/fi%20le.png?query=yes&really=y+s',
517 'url(scheme://user@domain:port/~user/fi%20le.png?query=yes&really=y+s)',
521 'data:image/png;base64,R0lGODlh/+==',
522 'url(data:image/png;base64,R0lGODlh/+==)',
526 "https://en.wikipedia.org/wiki/Wendy's",
527 "url(\"https://en.wikipedia.org/wiki/Wendy's\")",
530 'URL with parentheses',
531 'https://en.wikipedia.org/wiki/Boston_(band)',
532 'url("https://en.wikipedia.org/wiki/Boston_(band)")',
545 $this->testMinifyOutput(
$code, $expectedOutput );
552 [
'foo { content: " "; }',
'foo{content:" "}' ],
554 [
"foo { content: '\t'; }",
"foo{content:'\t'}" ],
557 'foo::after { content: "{;}"; position: absolute; }',
558 'foo::after{content:"{;}";position:absolute}'
567 return parent::isRemoteUrl( $maybeUrl );
570 return parent::isLocalUrl( $maybeUrl );
wfTempDir()
Tries to get the system directory for temporary files.
This file test the CSSMin library shipped with Mediawiki.
static provideBuildUrlValueCases()
testBuildUrlValue( $message, $input, $expectedOutput)
This tests basic functionality of CSSMin::buildUrlValue.
static provideStringCases()
testGetMimeType( $fileContents, $fileExtension, $expected)
mimeTypeProvider CSSMin::getMimeType
static provideRemapCases()
static provideMinifyCases()
testMinify( $code, $expectedOutput)
provideMinifyCases CSSMin::minify
static provideIsLocalUrls()
testRemap( $message, $params, $expectedOutput)
This test tests funky parameters to CSSMin::remap.
testRemapRemapping( $message, $input, $expectedOutput)
This tests the basic functionality of CSSMin::remap.
static provideIsRemoteUrl()
static provideRemapRemappingCases()
testIsLocalUrl( $expect, $url)
provideIsLocalUrls CSSMin::isLocalUrl
testMinifyWithCSSStringValues( $code, $expectedOutput)
Seperated because they are currently broken (T37492)
testIsRemoteUrl( $expect, $url)
provideIsRemoteUrl CSSMin::isRemoteUrl
static isLocalUrl( $maybeUrl)
Is this CSS rule referencing a local URL?
static isRemoteUrl( $maybeUrl)
Is this CSS rule referencing a remote URL?
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that probably a stub it is not rendered in wiki pages or galleries in category pages allow injecting custom HTML after the section Any uses of the hook need to handle escaping see BaseTemplate::getToolbox and BaseTemplate::makeListItem for details on the format of individual items inside of this array or by returning and letting standard HTTP rendering take place modifiable or by returning false and taking over the output modifiable & $code
processing should stop and the error should be shown to the user * false
if(is_array($mode)) switch( $mode) $input