MediaWiki REL1_33
CSSMinTest.php
Go to the documentation of this file.
1<?php
2
3use Wikimedia\TestingAccessWrapper;
4
10
11 protected function setUp() {
12 parent::setUp();
13
14 // For wfExpandUrl
15 $server = 'https://expand.example';
16 $this->setMwGlobals( [
17 'wgServer' => $server,
18 'wgCanonicalServer' => $server,
19 ] );
20 }
21
26 public function testGetLocalFileReferences( $input, $expected ) {
28 $this->assertEquals(
29 $expected,
30 $output,
31 'getLocalFileReferences() must find the local file properly'
32 );
33 }
34
35 public static function providesReferencedFiles() {
36 // input, array of expected local file names
37 return [
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")', [] ],
43 ];
44 }
45
50 public function testSerializeStringValue( $input, $expected ) {
52 $this->assertEquals(
53 $expected,
54 $output,
55 'Serialized output must be in the expected form.'
56 );
57 }
58
59 public static function provideSerializeStringValue() {
60 return [
61 [ 'Hello World!', '"Hello World!"' ],
62 [ "Null\0Null", "\"Null\u{FFFD}Null\"" ],
63 [ '"', '"\\""' ],
64 [ "'", '"\'"' ],
65 [ "\\", '"\\\\"' ],
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\u{0085}line", "\"Next\u{0085}line\"" ],
71 [ "Del\x7fDel", '"Del\\7f Del"' ],
72 [ "nb\u{00A0}sp", "\"nb\u{00A0}sp\"" ],
73 [ "AMP&amp;AMP", "\"AMP&amp;AMP\"" ],
74 [ '!"#$%&\'()*+,-./0123456789:;<=>?', '"!\\"#$%&\'()*+,-./0123456789:;<=>?"' ],
75 [ '@[\\]^_`{|}~', '"@[\\\\]^_`{|}~"' ],
76 [ 'ä', '"ä"' ],
77 [ 'Ä', '"Ä"' ],
78 [ '€', '"€"' ],
79 [ '𝒞', '"𝒞"' ], // U+1D49E 'MATHEMATICAL SCRIPT CAPITAL C'
80 ];
81 }
82
87 public function testGetMimeType( $fileContents, $fileExtension, $expected ) {
88 $fileName = wfTempDir() . DIRECTORY_SEPARATOR . uniqid( 'MW_PHPUnit_CSSMinTest_' ) . '.'
89 . $fileExtension;
90 $this->addTmpFiles( $fileName );
91 file_put_contents( $fileName, $fileContents );
92 $this->assertSame( $expected, CSSMin::getMimeType( $fileName ) );
93 }
94
95 public static function provideMimeType() {
96 return [
97 'JPEG with short extension' => [
98 "\xFF\xD8\xFF",
99 'jpg',
100 'image/jpeg'
101 ],
102 'JPEG with long extension' => [
103 "\xFF\xD8\xFF",
104 'jpeg',
105 'image/jpeg'
106 ],
107 'PNG' => [
108 "\x89\x50\x4E\x47\x0D\x0A\x1A\x0A",
109 'png',
110 'image/png'
111 ],
112
113 'PNG extension but JPEG content' => [
114 "\xFF\xD8\xFF",
115 'png',
116 'image/png'
117 ],
118 'JPEG extension but PNG content' => [
119 "\x89\x50\x4E\x47\x0D\x0A\x1A\x0A",
120 'jpg',
121 'image/jpeg'
122 ],
123 'PNG extension but SVG content' => [
124 '<?xml version="1.0"?><svg></svg>',
125 'png',
126 'image/png'
127 ],
128 'SVG extension but PNG content' => [
129 "\x89\x50\x4E\x47\x0D\x0A\x1A\x0A",
130 'svg',
131 'image/svg+xml'
132 ],
133
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>',
137 'svg',
138 'image/svg+xml'
139 ],
140 'SVG with XML header only' => [
141 '<?xml version="1.0"?><svg></svg>',
142 'svg',
143 'image/svg+xml'
144 ],
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>',
148 'svg',
149 'image/svg+xml'
150 ],
151 'SVG without any header' => [
152 '<svg></svg>',
153 'svg',
154 'image/svg+xml'
155 ],
156 ];
157 }
158
163 public function testMinify( $code, $expectedOutput ) {
164 $minified = CSSMin::minify( $code );
165
166 $this->assertEquals(
167 $expectedOutput,
168 $minified,
169 'Minified output should be in the form expected.'
170 );
171 }
172
173 public static function provideMinifyCases() {
174 return [
175 // Whitespace
176 [ "\r\t\f \v\n\r", "" ],
177 [ "foo, bar {\n\tprop: value;\n}", "foo,bar{prop:value}" ],
178
179 // Loose comments
180 [ "/* foo */", "" ],
181 [ "/*******\n foo\n *******/", "" ],
182 [ "/*!\n foo\n */", "" ],
183
184 // Inline comments in various different places
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; }" ],
193
194 // Keep track of things that aren't as minified as much as they
195 // could be (T37493)
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') }" ],
201
202 // Interesting cases with string values
203 // - Double quotes, single quotes
204 [ 'foo { content: ""; }', 'foo{content:""}' ],
205 [ "foo { content: ''; }", "foo{content:''}" ],
206 [ 'foo { content: "\'"; }', 'foo{content:"\'"}' ],
207 [ "foo { content: '\"'; }", "foo{content:'\"'}" ],
208 // - Whitespace in string values
209 [ 'foo { content: " "; }', 'foo{content:" "}' ],
210
211 // Whitespaces after opening and before closing parentheses and brackets
212 [ 'a:not( [ href ] ) { prop: url( foobar.png ); }', 'a:not([href]){prop:url(foobar.png)}' ],
213
214 // Ensure that the invalid "url (" will not become the valid "url(" by minification
215 [ 'foo { prop: url ( foobar.png ); }', 'foo{prop:url (foobar.png)}' ],
216 ];
217 }
218
219 public static function provideIsRemoteUrl() {
220 return [
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=' ],
226 [ false, '' ],
227 [ false, '/' ],
228 [ true, '//' ],
229 [ false, 'x.gif' ],
230 [ false, '/x.gif' ],
231 [ false, './x.gif' ],
232 [ false, '../x.gif' ],
233 ];
234 }
235
240 public function testIsRemoteUrl( $expect, $url ) {
241 $class = TestingAccessWrapper::newFromClass( CSSMin::class );
242 $this->assertEquals( $class->isRemoteUrl( $url ), $expect );
243 }
244
245 public static function provideIsLocalUrls() {
246 return [
247 [ false, '' ],
248 [ false, '/' ],
249 [ false, '//' ],
250 [ false, 'x.gif' ],
251 [ true, '/x.gif' ],
252 [ false, './x.gif' ],
253 [ false, '../x.gif' ],
254 ];
255 }
256
261 public function testIsLocalUrl( $expect, $url ) {
262 $class = TestingAccessWrapper::newFromClass( CSSMin::class );
263 $this->assertEquals( $class->isLocalUrl( $url ), $expect );
264 }
265
274 public function testRemap( $message, $params, $expectedOutput ) {
275 $remapped = call_user_func_array( 'CSSMin::remap', $params );
276
277 $messageAdd = " Case: $message";
278 $this->assertEquals(
279 $expectedOutput,
280 $remapped,
281 'CSSMin::remap should return the expected url form.' . $messageAdd
282 );
283 }
284
285 public static function provideRemapCases() {
286 // Parameter signature:
287 // CSSMin::remap( $code, $local, $remote, $embedData = true )
288 return [
289 [
290 'Simple case',
291 [ 'foo { prop: url(bar.png); }', false, 'http://example.org', false ],
292 'foo { prop: url(http://example.org/bar.png); }',
293 ],
294 [
295 'Without trailing slash',
296 [ 'foo { prop: url(../bar.png); }', false, 'http://example.org/quux', false ],
297 'foo { prop: url(http://example.org/bar.png); }',
298 ],
299 [
300 'With trailing slash on remote (T29052)',
301 [ 'foo { prop: url(../bar.png); }', false, 'http://example.org/quux/', false ],
302 'foo { prop: url(http://example.org/bar.png); }',
303 ],
304 [
305 'Guard against stripping double slashes from query',
306 [ 'foo { prop: url(bar.png?corge=//grault); }', false, 'http://example.org/quux/', false ],
307 'foo { prop: url(http://example.org/quux/bar.png?corge=//grault); }',
308 ],
309 [
310 'Expand absolute paths',
311 [ 'foo { prop: url(/w/skin/images/bar.png); }', false, 'http://example.org/quux', false ],
312 'foo { prop: url(https://expand.example/w/skin/images/bar.png); }',
313 ],
314 [
315 "Don't barf at behavior: url(#default#behaviorName) - T162973",
316 [ 'foo { behavior: url(#default#bar); }', false, '/w/', false ],
317 'foo { behavior: url("#default#bar"); }',
318 ],
319 [
320 'Keeps anchors',
321 [ 'url(#other)', false, '/', false ],
322 'url("#other")'
323 ],
324 [
325 'Keeps anchors after a path',
326 [ 'url(images/file.svg#id)', false, '/', false ],
327 'url("/images/file.svg#id")'
328 ],
329 ];
330 }
331
340 public function testRemapEmptyUrl( $params, $expected ) {
341 $remapped = call_user_func_array( 'CSSMin::remap', $params );
342 $this->assertEquals( $expected, $remapped, 'Ignore empty url' );
343 }
344
345 public static function provideRemapEmptyUrl() {
346 return [
347 'Empty' => [
348 [ "background-image: url();", false, '/example', false ],
349 "background-image: url();",
350 ],
351 'Single quote' => [
352 [ "background-image: url('');", false, '/example', false ],
353 "background-image: url('');",
354 ],
355 'Double quote' => [
356 [ 'background-image: url("");', false, '/example', false ],
357 'background-image: url("");',
358 ],
359 'Single quote with outer spacing' => [
360 [ "background-image: url( '' );", false, '/example', false ],
361 "background-image: url( '' );",
362 ],
363 ];
364 }
365
373 public function testRemapRemapping( $message, $input, $expectedOutput ) {
374 $localPath = __DIR__ . '/../../data/cssmin';
375 $remotePath = 'http://localhost/w';
376
377 $realOutput = CSSMin::remap( $input, $localPath, $remotePath );
378 $this->assertEquals( $expectedOutput, $realOutput, "CSSMin::remap: $message" );
379 }
380
381 public static function provideRemapRemappingCases() {
382 // red.gif and green.gif are one-pixel 35-byte GIFs.
383 // large.png is a 35K PNG that should be non-embeddable.
384 // Full paths start with http://localhost/w/.
385 // Timestamps in output are replaced with 'timestamp'.
386
387 // data: URIs for red.gif, green.gif, circle.svg
388 $red = 'data:image/gif;base64,R0lGODlhAQABAIAAAP8AADAAACwAAAAAAQABAAACAkQBADs=';
389 $green = 'data:image/gif;base64,R0lGODlhAQABAIAAAACAADAAACwAAAAAAQABAAACAkQBADs=';
390 $svg = 'data:image/svg+xml,%3Csvg xmlns=%22http://www.w3.org/2000/svg%22 width=%228'
391 . '%22 height=%228%22 viewBox=%220 0 8 8%22%3E %3Ccircle cx=%224%22 cy=%224%22 '
392 . 'r=%222%22/%3E %3Ca xmlns:xlink=%22http://www.w3.org/1999/xlink%22 xlink:title='
393 . '%22%3F%3E%22%3Etest%3C/a%3E %3C/svg%3E';
394
395 // phpcs:disable Generic.Files.LineLength
396 return [
397 [
398 'Regular file',
399 'foo { background: url(red.gif); }',
400 'foo { background: url(http://localhost/w/red.gif?34ac6); }',
401 ],
402 [
403 'Regular file (missing)',
404 'foo { background: url(theColorOfHerHair.gif); }',
405 'foo { background: url(http://localhost/w/theColorOfHerHair.gif); }',
406 ],
407 [
408 'Remote URL',
409 'foo { background: url(http://example.org/w/foo.png); }',
410 'foo { background: url(http://example.org/w/foo.png); }',
411 ],
412 [
413 'Protocol-relative remote URL',
414 'foo { background: url(//example.org/w/foo.png); }',
415 'foo { background: url(//example.org/w/foo.png); }',
416 ],
417 [
418 'Remote URL with query',
419 'foo { background: url(http://example.org/w/foo.png?query=yes); }',
420 'foo { background: url(http://example.org/w/foo.png?query=yes); }',
421 ],
422 [
423 'Protocol-relative remote URL with query',
424 'foo { background: url(//example.org/w/foo.png?query=yes); }',
425 'foo { background: url(//example.org/w/foo.png?query=yes); }',
426 ],
427 [
428 'Domain-relative URL',
429 'foo { background: url(/static/foo.png); }',
430 'foo { background: url(https://expand.example/static/foo.png); }',
431 ],
432 [
433 'Domain-relative URL with query',
434 'foo { background: url(/static/foo.png?query=yes); }',
435 'foo { background: url(https://expand.example/static/foo.png?query=yes); }',
436 ],
437 [
438 'Path-relative URL with query',
439 "foo { background: url(?query=yes); }",
440 'foo { background: url(http://localhost/w/?query=yes); }',
441 ],
442 [
443 'Remote URL (unnecessary quotes not preserved)',
444 'foo { background: url("http://example.org/w/unnecessary-quotes.png"); }',
445 'foo { background: url(http://example.org/w/unnecessary-quotes.png); }',
446 ],
447 [
448 'Embedded file',
449 'foo { /* @embed */ background: url(red.gif); }',
450 "foo { background: url($red); background: url(http://localhost/w/red.gif?34ac6)!ie; }",
451 ],
452 [
453 'Embedded file, other comments before the rule',
454 "foo { /* Bar. */ /* @embed */ background: url(red.gif); }",
455 "foo { /* Bar. */ background: url($red); /* Bar. */ background: url(http://localhost/w/red.gif?34ac6)!ie; }",
456 ],
457 [
458 'Can not re-embed data: URIs',
459 "foo { /* @embed */ background: url($red); }",
460 "foo { background: url($red); }",
461 ],
462 [
463 'Can not remap data: URIs',
464 "foo { background: url($red); }",
465 "foo { background: url($red); }",
466 ],
467 [
468 'Can not embed remote URLs',
469 'foo { /* @embed */ background: url(http://example.org/w/foo.png); }',
470 'foo { background: url(http://example.org/w/foo.png); }',
471 ],
472 [
473 'Embedded file (inline @embed)',
474 'foo { background: /* @embed */ url(red.gif); }',
475 "foo { background: url($red); "
476 . "background: url(http://localhost/w/red.gif?34ac6)!ie; }",
477 ],
478 [
479 'Can not embed large files',
480 'foo { /* @embed */ background: url(large.png); }',
481 "foo { background: url(http://localhost/w/large.png?e3d1f); }",
482 ],
483 [
484 'SVG files are embedded without base64 encoding and unnecessary IE 6 and 7 fallback',
485 'foo { /* @embed */ background: url(circle.svg); }',
486 "foo { background: url(\"$svg\"); }",
487 ],
488 [
489 'Two regular files in one rule',
490 'foo { background: url(red.gif), url(green.gif); }',
491 'foo { background: url(http://localhost/w/red.gif?34ac6), '
492 . 'url(http://localhost/w/green.gif?13651); }',
493 ],
494 [
495 'Two embedded files in one rule',
496 'foo { /* @embed */ background: url(red.gif), url(green.gif); }',
497 "foo { background: url($red), url($green); "
498 . "background: url(http://localhost/w/red.gif?34ac6), "
499 . "url(http://localhost/w/green.gif?13651)!ie; }",
500 ],
501 [
502 'Two embedded files in one rule (inline @embed)',
503 'foo { background: /* @embed */ url(red.gif), /* @embed */ url(green.gif); }',
504 "foo { background: url($red), url($green); "
505 . "background: url(http://localhost/w/red.gif?34ac6), "
506 . "url(http://localhost/w/green.gif?13651)!ie; }",
507 ],
508 [
509 'Two embedded files in one rule (inline @embed), one too large',
510 'foo { background: /* @embed */ url(red.gif), /* @embed */ url(large.png); }',
511 "foo { background: url($red), url(http://localhost/w/large.png?e3d1f); "
512 . "background: url(http://localhost/w/red.gif?34ac6), "
513 . "url(http://localhost/w/large.png?e3d1f)!ie; }",
514 ],
515 [
516 'Practical example with some noise',
517 'foo { /* @embed */ background: #f9f9f9 url(red.gif) 0 0 no-repeat; }',
518 "foo { background: #f9f9f9 url($red) 0 0 no-repeat; "
519 . "background: #f9f9f9 url(http://localhost/w/red.gif?34ac6) 0 0 no-repeat!ie; }",
520 ],
521 [
522 'Does not mess with other properties',
523 'foo { color: red; background: url(red.gif); font-size: small; }',
524 'foo { color: red; background: url(http://localhost/w/red.gif?34ac6); font-size: small; }',
525 ],
526 [
527 'Spacing and miscellanea not changed (1)',
528 'foo { background: url(red.gif); }',
529 'foo { background: url(http://localhost/w/red.gif?34ac6); }',
530 ],
531 [
532 'Spacing and miscellanea not changed (2)',
533 'foo {background:url(red.gif)}',
534 'foo {background:url(http://localhost/w/red.gif?34ac6)}',
535 ],
536 [
537 'Spaces within url() parentheses are ignored',
538 'foo { background: url( red.gif ); }',
539 'foo { background: url(http://localhost/w/red.gif?34ac6); }',
540 ],
541 [
542 '@import rule to local file (should we remap this?)',
543 '@import url(/styles.css)',
544 '@import url(https://expand.example/styles.css)',
545 ],
546 [
547 '@import rule to local file (should we remap this?)',
548 '@import url(/styles.css)',
549 '@import url(https://expand.example/styles.css)',
550 ],
551 [
552 '@import rule to URL',
553 '@import url(//localhost/styles.css?query=val)',
554 '@import url(//localhost/styles.css?query=val)',
555 ],
556 [
557 'Background URL (double quotes)',
558 'foo { background: url("//localhost/styles.css?quoted=double") }',
559 'foo { background: url(//localhost/styles.css?quoted=double) }',
560 ],
561 [
562 'Background URL (single quotes)',
563 'foo { background: url(\'//localhost/styles.css?quoted=single\') }',
564 'foo { background: url(//localhost/styles.css?quoted=single) }',
565 ],
566 [
567 'Background URL (double quoted, containing parentheses; T60473)',
568 'foo { background: url("//localhost/styles.css?query=(parens)") }',
569 'foo { background: url("//localhost/styles.css?query=(parens)") }',
570 ],
571 [
572 'Background URL (double quoted, containing single quotes; T60473)',
573 'foo { background: url("//localhost/styles.css?quote=\'") }',
574 'foo { background: url("//localhost/styles.css?quote=\'") }',
575 ],
576 [
577 'Background URL (single quoted, containing double quotes; T60473)',
578 'foo { background: url(\'//localhost/styles.css?quote="\') }',
579 'foo { background: url("//localhost/styles.css?quote=\"") }',
580 ],
581 [
582 'Background URL (double quoted with outer spacing)',
583 'foo { background: url( "http://localhost/styles.css?quoted=double" ) }',
584 'foo { background: url(http://localhost/styles.css?quoted=double) }',
585 ],
586 [
587 'Background URL (single quoted, containing spaces, with outer spacing)',
588 "foo { background: url( ' red.gif ' ); }",
589 'foo { background: url("http://localhost/w/ red.gif "); }',
590 ],
591 [
592 'Simple case with comments before url',
593 'foo { prop: /* some {funny;} comment */ url(bar.png); }',
594 'foo { prop: /* some {funny;} comment */ url(http://localhost/w/bar.png); }',
595 ],
596 [
597 'Simple case with comments after url',
598 'foo { prop: url(red.gif)/* some {funny;} comment */ ; }',
599 'foo { prop: url(http://localhost/w/red.gif?34ac6)/* some {funny;} comment */ ; }',
600 ],
601 [
602 'Embedded file with comment before url',
603 'foo { /* @embed */ background: /* some {funny;} comment */ url(red.gif); }',
604 "foo { background: /* some {funny;} comment */ url($red); background: /* some {funny;} comment */ url(http://localhost/w/red.gif?34ac6)!ie; }",
605 ],
606 [
607 'Embedded file with comments inside and outside the rule',
608 'foo { /* @embed */ background: url(red.gif) /* some {foo;} comment */; /* some {bar;} comment */ }',
609 "foo { background: url($red) /* some {foo;} comment */; background: url(http://localhost/w/red.gif?34ac6) /* some {foo;} comment */!ie; /* some {bar;} comment */ }",
610 ],
611 [
612 'Embedded file with comment outside the rule',
613 'foo { /* @embed */ background: url(red.gif); /* some {funny;} comment */ }',
614 "foo { background: url($red); background: url(http://localhost/w/red.gif?34ac6)!ie; /* some {funny;} comment */ }",
615 ],
616 [
617 'Rule with two urls, each with comments',
618 '{ background: /*asd*/ url(something.png); background: /*jkl*/ url(something.png); }',
619 '{ background: /*asd*/ url(http://localhost/w/something.png); background: /*jkl*/ url(http://localhost/w/something.png); }',
620 ],
621 [
622 'Sanity check for offending line from jquery.ui.theme.css (T62077)',
623 '.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}*/; }',
624 '.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}*/; }',
625 ],
626 ];
627 // phpcs:enable
628 }
629
636 public function testBuildUrlValue( $message, $input, $expectedOutput ) {
637 $this->assertEquals(
638 $expectedOutput,
640 "CSSMin::buildUrlValue: $message"
641 );
642 }
643
644 public static function provideBuildUrlValueCases() {
645 return [
646 [
647 'Full URL',
648 'scheme://user@domain:port/~user/fi%20le.png?query=yes&really=y+s',
649 'url(scheme://user@domain:port/~user/fi%20le.png?query=yes&really=y+s)',
650 ],
651 [
652 'data: URI',
653 'data:image/png;base64,R0lGODlh/+==',
654 'url(data:image/png;base64,R0lGODlh/+==)',
655 ],
656 [
657 'URL with quotes',
658 "https://en.wikipedia.org/wiki/Wendy's",
659 "url(\"https://en.wikipedia.org/wiki/Wendy's\")",
660 ],
661 [
662 'URL with parentheses',
663 'https://en.wikipedia.org/wiki/Boston_(band)',
664 'url("https://en.wikipedia.org/wiki/Boston_(band)")',
665 ],
666 ];
667 }
668
676 public function testMinifyWithCSSStringValues( $code, $expectedOutput ) {
677 $this->testMinifyOutput( $code, $expectedOutput );
678 }
679
680 public static function provideStringCases() {
681 return [
682 // String values should be respected
683 // - More than one space in a string value
684 [ 'foo { content: " "; }', 'foo{content:" "}' ],
685 // - Using a tab in a string value (turns into a space)
686 [ "foo { content: '\t'; }", "foo{content:'\t'}" ],
687 // - Using css-like syntax in string values
688 [
689 'foo::after { content: "{;}"; position: absolute; }',
690 'foo::after{content:"{;}";position:absolute}'
691 ],
692 ];
693 }
694}
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
wfTempDir()
Tries to get the system directory for temporary files.
ResourceLoader CSSMin.
Definition CSSMinTest.php:9
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 provideMimeType()
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)
Separated because they are currently broken (T37492)
testIsRemoteUrl( $expect, $url)
provideIsRemoteUrl CSSMin::isRemoteUrl
static serializeStringValue( $value)
Serialize a string (escape and quote) for use as a CSS string value.
Definition CSSMin.php:190
static buildUrlValue( $url)
Build a CSS 'url()' value for the given URL, quoting parentheses (and other funny characters) and esc...
Definition CSSMin.php:217
static getMimeType( $file)
Definition CSSMin.php:202
static getLocalFileReferences( $source, $path)
Get a list of local files referenced in a stylesheet (includes non-existent files).
Definition CSSMin.php:63
static minify( $css)
Removes whitespace from CSS data.
Definition CSSMin.php:540
static remap( $source, $local, $remote, $embedData=true)
Remaps CSS URL paths and automatically embeds data URIs for CSS rules or url() values preceded by an ...
Definition CSSMin.php:239
setMwGlobals( $pairs, $value=null)
Sets a global, maintaining a stashed version of the previous global to be restored in tearDown.
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that When $user is not it can be in the form of< username >< more info > e g for bot passwords intended to be added to log contexts Fields it might only if the login was with a bot password 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
Definition hooks.txt:856
static configuration should be added through ResourceLoaderGetConfigVars instead can be used to get the real title e g db for database replication lag or jobqueue for job queue size converted to pseudo seconds It is possible to add more fields and they will be returned to the user in the API response after the basic globals have been set but before ordinary actions take place $output
Definition hooks.txt:2272
processing should stop and the error should be shown to the user * false
Definition hooks.txt:187
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition injection.txt:37
if(is_array($mode)) switch( $mode) $input
$params