3use Wikimedia\TestingAccessWrapper;
15 $server =
'https://expand.example';
17 'wgServer' => $server,
18 'wgCanonicalServer' => $server,
31 'getLocalFileReferences() must find the local file properly'
38 [
'url("//example.org")', [] ],
39 [
'url("https://example.org")', [] ],
40 [
'url("#default#")', [] ],
41 [
'url("WikiFont-Glyphs.svg#wikiglyph")', [
'/WikiFont-Glyphs.svg' ] ],
42 [
'url("#some-anchor")', [] ],
55 'Serialized output must be in the expected form.'
61 [
'Hello World!',
'"Hello World!"' ],
62 [
"Null\0Null",
"\"Null\\fffd Null\"" ],
66 [
"Tab\tTab",
'"Tab\\9 Tab"' ],
67 [
"Space tab \t space",
'"Space tab \\9 space"' ],
68 [
"Line\nfeed",
'"Line\\a feed"' ],
69 [
"Return\rreturn",
'"Return\\d return"' ],
70 [
"Next\xc2\x85line",
"\"Next\xc2\x85line\"" ],
71 [
"Del\x7fDel",
'"Del\\7f Del"' ],
72 [
"nb\xc2\xa0sp",
"\"nb\xc2\xa0sp\"" ],
73 [
"AMP&AMP",
"\"AMP&AMP\"" ],
74 [
'!"#$%&\'()*+,-./0123456789:;<=>?',
'"!\\"#$%&\'()*+,-./0123456789:;<=>?"' ],
75 [
'@[\\]^_`{|}~',
'"@[\\\\]^_`{|}~"' ],
88 $fileName =
wfTempDir() . DIRECTORY_SEPARATOR . uniqid(
'MW_PHPUnit_CSSMinTest_' ) .
'.'
91 file_put_contents( $fileName, $fileContents );
92 $this->assertSame( $expected, CSSMin::getMimeType( $fileName ) );
97 'JPEG with short extension' => [
102 'JPEG with long extension' => [
108 "\x89\x50\x4E\x47\x0D\x0A\x1A\x0A",
113 'PNG extension but JPEG content' => [
118 'JPEG extension but PNG content' => [
119 "\x89\x50\x4E\x47\x0D\x0A\x1A\x0A",
123 'PNG extension but SVG content' => [
124 '<?xml version="1.0"?><svg></svg>',
128 'SVG extension but PNG content' => [
129 "\x89\x50\x4E\x47\x0D\x0A\x1A\x0A",
134 'SVG with all headers' => [
135 '<?xml version="1.0"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" '
136 .
'"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg></svg>',
140 'SVG with XML header only' => [
141 '<?xml version="1.0"?><svg></svg>',
145 'SVG with DOCTYPE only' => [
146 '<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" '
147 .
'"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg></svg>',
151 'SVG without any header' => [
164 $minified = CSSMin::minify(
$code );
169 'Minified output should be in the form expected.'
176 [
"\r\t\f \v\n\r",
"" ],
177 [
"foo, bar {\n\tprop: value;\n}",
"foo,bar{prop:value}" ],
181 [
"/*******\n foo\n *******/",
"" ],
182 [
"/*!\n foo\n */",
"" ],
185 [
"/* comment */foo, bar {\n\tprop: value;\n}",
"foo,bar{prop:value}" ],
186 [
"foo/* comment */, bar {\n\tprop: value;\n}",
"foo,bar{prop:value}" ],
187 [
"foo,/* comment */ bar {\n\tprop: value;\n}",
"foo,bar{prop:value}" ],
188 [
"foo, bar/* comment */ {\n\tprop: value;\n}",
"foo,bar{prop:value}" ],
189 [
"foo, bar {\n\t/* comment */prop: value;\n}",
"foo,bar{prop:value}" ],
190 [
"foo, bar {\n\tprop: /* comment */value;\n}",
"foo,bar{prop:value}" ],
191 [
"foo, bar {\n\tprop: value /* comment */;\n}",
"foo,bar{prop:value }" ],
192 [
"foo, bar {\n\tprop: value; /* comment */\n}",
"foo,bar{prop:value; }" ],
196 [
'foo { prop: value ;}',
'foo{prop:value }' ],
197 [
'foo { prop : value; }',
'foo{prop :value}' ],
198 [
'foo { prop: value ; }',
'foo{prop:value }' ],
199 [
'foo { font-family: "foo" , "bar"; }',
'foo{font-family:"foo" ,"bar"}' ],
200 [
"foo { src:\n\turl('foo') ,\n\turl('bar') ; }",
"foo{src:url('foo') ,url('bar') }" ],
204 [
'foo { content: ""; }',
'foo{content:""}' ],
205 [
"foo { content: ''; }",
"foo{content:''}" ],
206 [
'foo { content: "\'"; }',
'foo{content:"\'"}' ],
207 [
"foo { content: '\"'; }",
"foo{content:'\"'}" ],
209 [
'foo { content: " "; }',
'foo{content:" "}' ],
212 [
'a:not( [ href ] ) { prop: url( foobar.png ); }',
'a:not([href]){prop:url(foobar.png)}' ],
215 [
'foo { prop: url ( foobar.png ); }',
'foo{prop:url (foobar.png)}' ],
221 [
true,
'http://localhost/w/red.gif?123' ],
222 [
true,
'https://example.org/x.png' ],
223 [
true,
'//example.org/x.y.z/image.png' ],
224 [
true,
'//localhost/styles.css?query=yes' ],
225 [
true,
'data:image/gif;base64,R0lGODlhAQABAIAAAP8AADAAACwAAAAAAQABAAACAkQBADs=' ],
228 [
false,
'./x.gif' ],
229 [
false,
'../x.gif' ],
238 $class = TestingAccessWrapper::newFromClass( CSSMin::class );
239 $this->assertEquals( $class->isRemoteUrl( $url ), $expect );
246 [
false,
'./x.gif' ],
247 [
false,
'../x.gif' ],
256 $class = TestingAccessWrapper::newFromClass( CSSMin::class );
257 $this->assertEquals( $class->isLocalUrl( $url ), $expect );
269 $remapped = call_user_func_array(
'CSSMin::remap',
$params );
271 $messageAdd =
" Case: $message";
275 'CSSMin::remap should return the expected url form.' . $messageAdd
285 [
'foo { prop: url(bar.png); }',
false,
'http://example.org',
false ],
286 'foo { prop: url(http://example.org/bar.png); }',
289 'Without trailing slash',
290 [
'foo { prop: url(../bar.png); }',
false,
'http://example.org/quux',
false ],
291 'foo { prop: url(http://example.org/bar.png); }',
294 'With trailing slash on remote (T29052)',
295 [
'foo { prop: url(../bar.png); }',
false,
'http://example.org/quux/',
false ],
296 'foo { prop: url(http://example.org/bar.png); }',
299 'Guard against stripping double slashes from query',
300 [
'foo { prop: url(bar.png?corge=//grault); }',
false,
'http://example.org/quux/',
false ],
301 'foo { prop: url(http://example.org/quux/bar.png?corge=//grault); }',
304 'Expand absolute paths',
305 [
'foo { prop: url(/w/skin/images/bar.png); }',
false,
'http://example.org/quux',
false ],
306 'foo { prop: url(https://expand.example/w/skin/images/bar.png); }',
309 "Don't barf at behavior: url(#default#behaviorName) - T162973",
310 [
'foo { behavior: url(#default#bar); }',
false,
'/w/',
false ],
311 'foo { behavior: url("#default#bar"); }',
315 [
'url(#other)',
false,
'/',
false ],
319 'Keeps anchors after a path',
320 [
'url(images/file.svg#id)',
false,
'/',
false ],
321 'url("/images/file.svg#id")'
335 $remapped = call_user_func_array(
'CSSMin::remap',
$params );
336 $this->assertEquals( $expected, $remapped,
'Ignore empty url' );
342 [
"background-image: url();",
false,
'/example',
false ],
343 "background-image: url();",
346 [
"background-image: url('');",
false,
'/example',
false ],
347 "background-image: url('');",
350 [
'background-image: url("");',
false,
'/example',
false ],
351 'background-image: url("");',
364 $localPath = __DIR__ .
'/../../data/cssmin';
365 $remotePath =
'http://localhost/w';
367 $realOutput = CSSMin::remap(
$input, $localPath, $remotePath );
368 $this->assertEquals( $expectedOutput, $realOutput,
"CSSMin::remap: $message" );
378 $red =
'data:image/gif;base64,R0lGODlhAQABAIAAAP8AADAAACwAAAAAAQABAAACAkQBADs=';
379 $green =
'data:image/gif;base64,R0lGODlhAQABAIAAAACAADAAACwAAAAAAQABAAACAkQBADs=';
380 $svg =
'data:image/svg+xml,%3Csvg xmlns=%22http://www.w3.org/2000/svg%22 width=%228'
381 .
'%22 height=%228%22 viewBox=%220 0 8 8%22%3E %3Ccircle cx=%224%22 cy=%224%22 '
382 .
'r=%222%22/%3E %3Ca xmlns:xlink=%22http://www.w3.org/1999/xlink%22 xlink:title='
383 .
'%22%3F%3E%22%3Etest%3C/a%3E %3C/svg%3E';
389 'foo { background: url(red.gif); }',
390 'foo { background: url(http://localhost/w/red.gif?34ac6); }',
393 'Regular file (missing)',
394 'foo { background: url(theColorOfHerHair.gif); }',
395 'foo { background: url(http://localhost/w/theColorOfHerHair.gif); }',
399 'foo { background: url(http://example.org/w/foo.png); }',
400 'foo { background: url(http://example.org/w/foo.png); }',
403 'Protocol-relative remote URL',
404 'foo { background: url(//example.org/w/foo.png); }',
405 'foo { background: url(//example.org/w/foo.png); }',
408 'Remote URL with query',
409 'foo { background: url(http://example.org/w/foo.png?query=yes); }',
410 'foo { background: url(http://example.org/w/foo.png?query=yes); }',
413 'Protocol-relative remote URL with query',
414 'foo { background: url(//example.org/w/foo.png?query=yes); }',
415 'foo { background: url(//example.org/w/foo.png?query=yes); }',
418 'Domain-relative URL',
419 'foo { background: url(/static/foo.png); }',
420 'foo { background: url(https://expand.example/static/foo.png); }',
423 'Domain-relative URL with query',
424 'foo { background: url(/static/foo.png?query=yes); }',
425 'foo { background: url(https://expand.example/static/foo.png?query=yes); }',
428 'Remote URL (unnecessary quotes not preserved)',
429 'foo { background: url("http://example.org/w/unnecessary-quotes.png"); }',
430 'foo { background: url(http://example.org/w/unnecessary-quotes.png); }',
434 'foo { /* @embed */ background: url(red.gif); }',
435 "foo { background: url($red); background: url(http://localhost/w/red.gif?34ac6)!ie; }",
438 'Embedded file, other comments before the rule',
439 "foo { /* Bar. */ /* @embed */ background: url(red.gif); }",
440 "foo { /* Bar. */ background: url($red); /* Bar. */ background: url(http://localhost/w/red.gif?34ac6)!ie; }",
443 'Can not re-embed data: URIs',
444 "foo { /* @embed */ background: url($red); }",
445 "foo { background: url($red); }",
448 'Can not remap data: URIs',
449 "foo { background: url($red); }",
450 "foo { background: url($red); }",
453 'Can not embed remote URLs',
454 'foo { /* @embed */ background: url(http://example.org/w/foo.png); }',
455 'foo { background: url(http://example.org/w/foo.png); }',
458 'Embedded file (inline @embed)',
459 'foo { background: /* @embed */ url(red.gif); }',
460 "foo { background: url($red); "
461 .
"background: url(http://localhost/w/red.gif?34ac6)!ie; }",
464 'Can not embed large files',
465 'foo { /* @embed */ background: url(large.png); }',
466 "foo { background: url(http://localhost/w/large.png?e3d1f); }",
469 'SVG files are embedded without base64 encoding and unnecessary IE 6 and 7 fallback',
470 'foo { /* @embed */ background: url(circle.svg); }',
471 "foo { background: url(\"$svg\"); }",
474 'Two regular files in one rule',
475 'foo { background: url(red.gif), url(green.gif); }',
476 'foo { background: url(http://localhost/w/red.gif?34ac6), '
477 .
'url(http://localhost/w/green.gif?13651); }',
480 'Two embedded files in one rule',
481 'foo { /* @embed */ background: url(red.gif), url(green.gif); }',
482 "foo { background: url($red), url($green); "
483 .
"background: url(http://localhost/w/red.gif?34ac6), "
484 .
"url(http://localhost/w/green.gif?13651)!ie; }",
487 'Two embedded files in one rule (inline @embed)',
488 'foo { background: /* @embed */ url(red.gif), /* @embed */ url(green.gif); }',
489 "foo { background: url($red), url($green); "
490 .
"background: url(http://localhost/w/red.gif?34ac6), "
491 .
"url(http://localhost/w/green.gif?13651)!ie; }",
494 'Two embedded files in one rule (inline @embed), one too large',
495 'foo { background: /* @embed */ url(red.gif), /* @embed */ url(large.png); }',
496 "foo { background: url($red), url(http://localhost/w/large.png?e3d1f); "
497 .
"background: url(http://localhost/w/red.gif?34ac6), "
498 .
"url(http://localhost/w/large.png?e3d1f)!ie; }",
501 'Practical example with some noise',
502 'foo { /* @embed */ background: #f9f9f9 url(red.gif) 0 0 no-repeat; }',
503 "foo { background: #f9f9f9 url($red) 0 0 no-repeat; "
504 .
"background: #f9f9f9 url(http://localhost/w/red.gif?34ac6) 0 0 no-repeat!ie; }",
507 'Does not mess with other properties',
508 'foo { color: red; background: url(red.gif); font-size: small; }',
509 'foo { color: red; background: url(http://localhost/w/red.gif?34ac6); font-size: small; }',
512 'Spacing and miscellanea not changed (1)',
513 'foo { background: url(red.gif); }',
514 'foo { background: url(http://localhost/w/red.gif?34ac6); }',
517 'Spacing and miscellanea not changed (2)',
518 'foo {background:url(red.gif)}',
519 'foo {background:url(http://localhost/w/red.gif?34ac6)}',
522 'Spaces within url() parentheses are ignored',
523 'foo { background: url( red.gif ); }',
524 'foo { background: url(http://localhost/w/red.gif?34ac6); }',
527 '@import rule to local file (should we remap this?)',
528 '@import url(/styles.css)',
529 '@import url(https://expand.example/styles.css)',
532 '@import rule to local file (should we remap this?)',
533 '@import url(/styles.css)',
534 '@import url(https://expand.example/styles.css)',
537 '@import rule to URL',
538 '@import url(//localhost/styles.css?query=val)',
539 '@import url(//localhost/styles.css?query=val)',
542 'Background URL (double quotes)',
543 'foo { background: url("//localhost/styles.css?quoted=double") }',
544 'foo { background: url(//localhost/styles.css?quoted=double) }',
547 'Background URL (single quotes)',
548 'foo { background: url(\'//localhost/styles.css?quoted=single\') }',
549 'foo { background: url(//localhost/styles.css?quoted=single) }',
552 'Background URL (double quoted, containing parentheses; T60473)',
553 'foo { background: url("//localhost/styles.css?query=(parens)") }',
554 'foo { background: url("//localhost/styles.css?query=(parens)") }',
557 'Background URL (double quoted, containing single quotes; T60473)',
558 'foo { background: url("//localhost/styles.css?quote=\'") }',
559 'foo { background: url("//localhost/styles.css?quote=\'") }',
562 'Background URL (single quoted, containing double quotes; T60473)',
563 'foo { background: url(\'//localhost/styles.css?quote="\') }',
564 'foo { background: url("//localhost/styles.css?quote=\"") }',
567 'Background URL (double quoted with outer spacing)',
568 'foo { background: url( "http://localhost/styles.css?quoted=double" ) }',
569 'foo { background: url(http://localhost/styles.css?quoted=double) }',
572 'Simple case with comments before url',
573 'foo { prop: /* some {funny;} comment */ url(bar.png); }',
574 'foo { prop: /* some {funny;} comment */ url(http://localhost/w/bar.png); }',
577 'Simple case with comments after url',
578 'foo { prop: url(red.gif)/* some {funny;} comment */ ; }',
579 'foo { prop: url(http://localhost/w/red.gif?34ac6)/* some {funny;} comment */ ; }',
582 'Embedded file with comment before url',
583 'foo { /* @embed */ background: /* some {funny;} comment */ url(red.gif); }',
584 "foo { background: /* some {funny;} comment */ url($red); background: /* some {funny;} comment */ url(http://localhost/w/red.gif?34ac6)!ie; }",
587 'Embedded file with comments inside and outside the rule',
588 'foo { /* @embed */ background: url(red.gif) /* some {foo;} comment */; /* some {bar;} comment */ }',
589 "foo { background: url($red) /* some {foo;} comment */; background: url(http://localhost/w/red.gif?34ac6) /* some {foo;} comment */!ie; /* some {bar;} comment */ }",
592 'Embedded file with comment outside the rule',
593 'foo { /* @embed */ background: url(red.gif); /* some {funny;} comment */ }',
594 "foo { background: url($red); background: url(http://localhost/w/red.gif?34ac6)!ie; /* some {funny;} comment */ }",
597 'Rule with two urls, each with comments',
598 '{ background: /*asd*/ url(something.png); background: /*jkl*/ url(something.png); }',
599 '{ background: /*asd*/ url(http://localhost/w/something.png); background: /*jkl*/ url(http://localhost/w/something.png); }',
602 'Sanity check for offending line from jquery.ui.theme.css (T62077)',
603 '.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}*/; }',
604 '.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}*/; }',
619 CSSMin::buildUrlValue(
$input ),
620 "CSSMin::buildUrlValue: $message"
628 'scheme://user@domain:port/~user/fi%20le.png?query=yes&really=y+s',
629 'url(scheme://user@domain:port/~user/fi%20le.png?query=yes&really=y+s)',
633 'data:image/png;base64,R0lGODlh/+==',
634 'url(data:image/png;base64,R0lGODlh/+==)',
638 "https://en.wikipedia.org/wiki/Wendy's",
639 "url(\"https://en.wikipedia.org/wiki/Wendy's\")",
642 'URL with parentheses',
643 'https://en.wikipedia.org/wiki/Boston_(band)',
644 'url("https://en.wikipedia.org/wiki/Boston_(band)")',
657 $this->testMinifyOutput(
$code, $expectedOutput );
664 [
'foo { content: " "; }',
'foo{content:" "}' ],
666 [
"foo { content: '\t'; }",
"foo{content:'\t'}" ],
669 'foo::after { content: "{;}"; position: absolute; }',
670 'foo::after{content:"{;}";position:absolute}'
wfTempDir()
Tries to get the system directory for temporary files.
testGetLocalFileReferences( $input, $expected)
providesReferencedFiles CSSMin::getLocalFileReferences
static provideBuildUrlValueCases()
testBuildUrlValue( $message, $input, $expectedOutput)
This tests basic functionality of CSSMin::buildUrlValue.
static providesReferencedFiles()
static provideStringCases()
static provideSerializeStringValue()
static provideRemapEmptyUrl()
testGetMimeType( $fileContents, $fileExtension, $expected)
provideMimeType CSSMin::getMimeType
static provideRemapCases()
static provideMinifyCases()
testMinify( $code, $expectedOutput)
provideMinifyCases CSSMin::minify
static provideIsLocalUrls()
testRemapEmptyUrl( $params, $expected)
Cases with empty url() for CSSMin::remap.
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
testSerializeStringValue( $input, $expected)
provideSerializeStringValue CSSMin::serializeStringValue
testMinifyWithCSSStringValues( $code, $expectedOutput)
Seperated because they are currently broken (T37492)
testIsRemoteUrl( $expect, $url)
provideIsRemoteUrl CSSMin::isRemoteUrl
static configuration should be added through ResourceLoaderGetConfigVars instead can be used to get the real title after the basic globals have been set but before ordinary actions take place $output
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