MediaWiki REL1_31
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\\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\xc2\x85line", "\"Next\xc2\x85line\"" ],
71 [ "Del\x7fDel", '"Del\\7f Del"' ],
72 [ "nb\xc2\xa0sp", "\"nb\xc2\xa0sp\"" ],
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, 'x.gif' ],
227 [ false, '/x.gif' ],
228 [ false, './x.gif' ],
229 [ false, '../x.gif' ],
230 ];
231 }
232
237 public function testIsRemoteUrl( $expect, $url ) {
238 $class = TestingAccessWrapper::newFromClass( CSSMin::class );
239 $this->assertEquals( $class->isRemoteUrl( $url ), $expect );
240 }
241
242 public static function provideIsLocalUrls() {
243 return [
244 [ false, 'x.gif' ],
245 [ true, '/x.gif' ],
246 [ false, './x.gif' ],
247 [ false, '../x.gif' ],
248 ];
249 }
250
255 public function testIsLocalUrl( $expect, $url ) {
256 $class = TestingAccessWrapper::newFromClass( CSSMin::class );
257 $this->assertEquals( $class->isLocalUrl( $url ), $expect );
258 }
259
268 public function testRemap( $message, $params, $expectedOutput ) {
269 $remapped = call_user_func_array( 'CSSMin::remap', $params );
270
271 $messageAdd = " Case: $message";
272 $this->assertEquals(
273 $expectedOutput,
274 $remapped,
275 'CSSMin::remap should return the expected url form.' . $messageAdd
276 );
277 }
278
279 public static function provideRemapCases() {
280 // Parameter signature:
281 // CSSMin::remap( $code, $local, $remote, $embedData = true )
282 return [
283 [
284 'Simple case',
285 [ 'foo { prop: url(bar.png); }', false, 'http://example.org', false ],
286 'foo { prop: url(http://example.org/bar.png); }',
287 ],
288 [
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); }',
292 ],
293 [
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); }',
297 ],
298 [
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); }',
302 ],
303 [
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); }',
307 ],
308 [
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"); }',
312 ],
313 [
314 'Keeps anchors',
315 [ 'url(#other)', false, '/', false ],
316 'url("#other")'
317 ],
318 [
319 'Keeps anchors after a path',
320 [ 'url(images/file.svg#id)', false, '/', false ],
321 'url("/images/file.svg#id")'
322 ],
323 ];
324 }
325
334 public function testRemapEmptyUrl( $params, $expected ) {
335 $remapped = call_user_func_array( 'CSSMin::remap', $params );
336 $this->assertEquals( $expected, $remapped, 'Ignore empty url' );
337 }
338
339 public static function provideRemapEmptyUrl() {
340 return [
341 'Empty' => [
342 [ "background-image: url();", false, '/example', false ],
343 "background-image: url();",
344 ],
345 'Single quote' => [
346 [ "background-image: url('');", false, '/example', false ],
347 "background-image: url('');",
348 ],
349 'Double quote' => [
350 [ 'background-image: url("");', false, '/example', false ],
351 'background-image: url("");',
352 ],
353 ];
354 }
355
363 public function testRemapRemapping( $message, $input, $expectedOutput ) {
364 $localPath = __DIR__ . '/../../data/cssmin';
365 $remotePath = 'http://localhost/w';
366
367 $realOutput = CSSMin::remap( $input, $localPath, $remotePath );
368 $this->assertEquals( $expectedOutput, $realOutput, "CSSMin::remap: $message" );
369 }
370
371 public static function provideRemapRemappingCases() {
372 // red.gif and green.gif are one-pixel 35-byte GIFs.
373 // large.png is a 35K PNG that should be non-embeddable.
374 // Full paths start with http://localhost/w/.
375 // Timestamps in output are replaced with 'timestamp'.
376
377 // data: URIs for red.gif, green.gif, circle.svg
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';
384
385 // phpcs:disable Generic.Files.LineLength
386 return [
387 [
388 'Regular file',
389 'foo { background: url(red.gif); }',
390 'foo { background: url(http://localhost/w/red.gif?34ac6); }',
391 ],
392 [
393 'Regular file (missing)',
394 'foo { background: url(theColorOfHerHair.gif); }',
395 'foo { background: url(http://localhost/w/theColorOfHerHair.gif); }',
396 ],
397 [
398 'Remote URL',
399 'foo { background: url(http://example.org/w/foo.png); }',
400 'foo { background: url(http://example.org/w/foo.png); }',
401 ],
402 [
403 'Protocol-relative remote URL',
404 'foo { background: url(//example.org/w/foo.png); }',
405 'foo { background: url(//example.org/w/foo.png); }',
406 ],
407 [
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); }',
411 ],
412 [
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); }',
416 ],
417 [
418 'Domain-relative URL',
419 'foo { background: url(/static/foo.png); }',
420 'foo { background: url(https://expand.example/static/foo.png); }',
421 ],
422 [
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); }',
426 ],
427 [
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); }',
431 ],
432 [
433 'Embedded file',
434 'foo { /* @embed */ background: url(red.gif); }',
435 "foo { background: url($red); background: url(http://localhost/w/red.gif?34ac6)!ie; }",
436 ],
437 [
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; }",
441 ],
442 [
443 'Can not re-embed data: URIs',
444 "foo { /* @embed */ background: url($red); }",
445 "foo { background: url($red); }",
446 ],
447 [
448 'Can not remap data: URIs',
449 "foo { background: url($red); }",
450 "foo { background: url($red); }",
451 ],
452 [
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); }',
456 ],
457 [
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; }",
462 ],
463 [
464 'Can not embed large files',
465 'foo { /* @embed */ background: url(large.png); }',
466 "foo { background: url(http://localhost/w/large.png?e3d1f); }",
467 ],
468 [
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\"); }",
472 ],
473 [
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); }',
478 ],
479 [
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; }",
485 ],
486 [
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; }",
492 ],
493 [
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; }",
499 ],
500 [
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; }",
505 ],
506 [
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; }',
510 ],
511 [
512 'Spacing and miscellanea not changed (1)',
513 'foo { background: url(red.gif); }',
514 'foo { background: url(http://localhost/w/red.gif?34ac6); }',
515 ],
516 [
517 'Spacing and miscellanea not changed (2)',
518 'foo {background:url(red.gif)}',
519 'foo {background:url(http://localhost/w/red.gif?34ac6)}',
520 ],
521 [
522 'Spaces within url() parentheses are ignored',
523 'foo { background: url( red.gif ); }',
524 'foo { background: url(http://localhost/w/red.gif?34ac6); }',
525 ],
526 [
527 '@import rule to local file (should we remap this?)',
528 '@import url(/styles.css)',
529 '@import url(https://expand.example/styles.css)',
530 ],
531 [
532 '@import rule to local file (should we remap this?)',
533 '@import url(/styles.css)',
534 '@import url(https://expand.example/styles.css)',
535 ],
536 [
537 '@import rule to URL',
538 '@import url(//localhost/styles.css?query=val)',
539 '@import url(//localhost/styles.css?query=val)',
540 ],
541 [
542 'Background URL (double quotes)',
543 'foo { background: url("//localhost/styles.css?quoted=double") }',
544 'foo { background: url(//localhost/styles.css?quoted=double) }',
545 ],
546 [
547 'Background URL (single quotes)',
548 'foo { background: url(\'//localhost/styles.css?quoted=single\') }',
549 'foo { background: url(//localhost/styles.css?quoted=single) }',
550 ],
551 [
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)") }',
555 ],
556 [
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=\'") }',
560 ],
561 [
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=\"") }',
565 ],
566 [
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) }',
570 ],
571 [
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); }',
575 ],
576 [
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 */ ; }',
580 ],
581 [
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; }",
585 ],
586 [
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 */ }",
590 ],
591 [
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 */ }",
595 ],
596 [
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); }',
600 ],
601 [
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}*/; }',
605 ],
606 ];
607 // phpcs:enable
608 }
609
616 public function testBuildUrlValue( $message, $input, $expectedOutput ) {
617 $this->assertEquals(
618 $expectedOutput,
620 "CSSMin::buildUrlValue: $message"
621 );
622 }
623
624 public static function provideBuildUrlValueCases() {
625 return [
626 [
627 'Full URL',
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)',
630 ],
631 [
632 'data: URI',
633 'data:image/png;base64,R0lGODlh/+==',
634 'url(data:image/png;base64,R0lGODlh/+==)',
635 ],
636 [
637 'URL with quotes',
638 "https://en.wikipedia.org/wiki/Wendy's",
639 "url(\"https://en.wikipedia.org/wiki/Wendy's\")",
640 ],
641 [
642 'URL with parentheses',
643 'https://en.wikipedia.org/wiki/Boston_(band)',
644 'url("https://en.wikipedia.org/wiki/Boston_(band)")',
645 ],
646 ];
647 }
648
656 public function testMinifyWithCSSStringValues( $code, $expectedOutput ) {
657 $this->testMinifyOutput( $code, $expectedOutput );
658 }
659
660 public static function provideStringCases() {
661 return [
662 // String values should be respected
663 // - More than one space in a string value
664 [ 'foo { content: " "; }', 'foo{content:" "}' ],
665 // - Using a tab in a string value (turns into a space)
666 [ "foo { content: '\t'; }", "foo{content:'\t'}" ],
667 // - Using css-like syntax in string values
668 [
669 'foo::after { content: "{;}"; position: absolute; }',
670 'foo::after{content:"{;}";position:absolute}'
671 ],
672 ];
673 }
674}
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)
Seperated 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:221
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:547
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:243
setMwGlobals( $pairs, $value=null)
Sets a global, maintaining a stashed version of the previous global to be restored in tearDown.
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
Definition hooks.txt:2255
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
Definition hooks.txt:865
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