resourceloader: Make various CSSMin performance optimizations and cleanups
[lhc/web/wiklou.git] / tests / phpunit / includes / libs / CSSMinTest.php
1 <?php
2
3 use Wikimedia\TestingAccessWrapper;
4
5 /**
6 * @group ResourceLoader
7 * @group CSSMin
8 */
9 class CSSMinTest extends MediaWikiTestCase {
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
22 /**
23 * @dataProvider provideSerializeStringValue
24 * @covers CSSMin::serializeStringValue
25 */
26 public function testSerializeStringValue( $input, $expected ) {
27 $output = CSSMin::serializeStringValue( $input );
28 $this->assertEquals(
29 $expected,
30 $output,
31 'Serialized output must be in the expected form.'
32 );
33 }
34
35 public static function provideSerializeStringValue() {
36 return [
37 [ 'Hello World!', '"Hello World!"' ],
38 [ "Null\0Null", "\"Null\\fffd Null\"" ],
39 [ '"', '"\\""' ],
40 [ "'", '"\'"' ],
41 [ "\\", '"\\\\"' ],
42 [ "Tab\tTab", '"Tab\\9 Tab"' ],
43 [ "Space tab \t space", '"Space tab \\9 space"' ],
44 [ "Line\nfeed", '"Line\\a feed"' ],
45 [ "Return\rreturn", '"Return\\d return"' ],
46 [ "Next\xc2\x85line", "\"Next\xc2\x85line\"" ],
47 [ "Del\x7fDel", '"Del\\7f Del"' ],
48 [ "nb\xc2\xa0sp", "\"nb\xc2\xa0sp\"" ],
49 [ "AMP&amp;AMP", "\"AMP&amp;AMP\"" ],
50 [ '!"#$%&\'()*+,-./0123456789:;<=>?', '"!\\"#$%&\'()*+,-./0123456789:;<=>?"' ],
51 [ '@[\\]^_`{|}~', '"@[\\\\]^_`{|}~"' ],
52 [ 'ä', '"ä"' ],
53 [ 'Ä', '"Ä"' ],
54 [ '€', '"€"' ],
55 [ '𝒞', '"𝒞"' ], // U+1D49E 'MATHEMATICAL SCRIPT CAPITAL C'
56 ];
57 }
58
59 /**
60 * @dataProvider provideMimeType
61 * @covers CSSMin::getMimeType
62 */
63 public function testGetMimeType( $fileContents, $fileExtension, $expected ) {
64 $fileName = wfTempDir() . DIRECTORY_SEPARATOR . uniqid( 'MW_PHPUnit_CSSMinTest_' ) . '.'
65 . $fileExtension;
66 $this->addTmpFiles( $fileName );
67 file_put_contents( $fileName, $fileContents );
68 $this->assertSame( $expected, CSSMin::getMimeType( $fileName ) );
69 }
70
71 public static function provideMimeType() {
72 return [
73 'JPEG with short extension' => [
74 "\xFF\xD8\xFF",
75 'jpg',
76 'image/jpeg'
77 ],
78 'JPEG with long extension' => [
79 "\xFF\xD8\xFF",
80 'jpeg',
81 'image/jpeg'
82 ],
83 'PNG' => [
84 "\x89\x50\x4E\x47\x0D\x0A\x1A\x0A",
85 'png',
86 'image/png'
87 ],
88
89 'PNG extension but JPEG content' => [
90 "\xFF\xD8\xFF",
91 'png',
92 'image/png'
93 ],
94 'JPEG extension but PNG content' => [
95 "\x89\x50\x4E\x47\x0D\x0A\x1A\x0A",
96 'jpg',
97 'image/jpeg'
98 ],
99 'PNG extension but SVG content' => [
100 '<?xml version="1.0"?><svg></svg>',
101 'png',
102 'image/png'
103 ],
104 'SVG extension but PNG content' => [
105 "\x89\x50\x4E\x47\x0D\x0A\x1A\x0A",
106 'svg',
107 'image/svg+xml'
108 ],
109
110 'SVG with all headers' => [
111 '<?xml version="1.0"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" '
112 . '"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg></svg>',
113 'svg',
114 'image/svg+xml'
115 ],
116 'SVG with XML header only' => [
117 '<?xml version="1.0"?><svg></svg>',
118 'svg',
119 'image/svg+xml'
120 ],
121 'SVG with DOCTYPE only' => [
122 '<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" '
123 . '"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg></svg>',
124 'svg',
125 'image/svg+xml'
126 ],
127 'SVG without any header' => [
128 '<svg></svg>',
129 'svg',
130 'image/svg+xml'
131 ],
132 ];
133 }
134
135 /**
136 * @dataProvider provideMinifyCases
137 * @covers CSSMin::minify
138 */
139 public function testMinify( $code, $expectedOutput ) {
140 $minified = CSSMin::minify( $code );
141
142 $this->assertEquals(
143 $expectedOutput,
144 $minified,
145 'Minified output should be in the form expected.'
146 );
147 }
148
149 public static function provideMinifyCases() {
150 return [
151 // Whitespace
152 [ "\r\t\f \v\n\r", "" ],
153 [ "foo, bar {\n\tprop: value;\n}", "foo,bar{prop:value}" ],
154
155 // Loose comments
156 [ "/* foo */", "" ],
157 [ "/*******\n foo\n *******/", "" ],
158 [ "/*!\n foo\n */", "" ],
159
160 // Inline comments in various different places
161 [ "/* comment */foo, bar {\n\tprop: value;\n}", "foo,bar{prop:value}" ],
162 [ "foo/* comment */, bar {\n\tprop: value;\n}", "foo,bar{prop:value}" ],
163 [ "foo,/* comment */ bar {\n\tprop: value;\n}", "foo,bar{prop:value}" ],
164 [ "foo, bar/* comment */ {\n\tprop: value;\n}", "foo,bar{prop:value}" ],
165 [ "foo, bar {\n\t/* comment */prop: value;\n}", "foo,bar{prop:value}" ],
166 [ "foo, bar {\n\tprop: /* comment */value;\n}", "foo,bar{prop:value}" ],
167 [ "foo, bar {\n\tprop: value /* comment */;\n}", "foo,bar{prop:value }" ],
168 [ "foo, bar {\n\tprop: value; /* comment */\n}", "foo,bar{prop:value; }" ],
169
170 // Keep track of things that aren't as minified as much as they
171 // could be (T37493)
172 [ 'foo { prop: value ;}', 'foo{prop:value }' ],
173 [ 'foo { prop : value; }', 'foo{prop :value}' ],
174 [ 'foo { prop: value ; }', 'foo{prop:value }' ],
175 [ 'foo { font-family: "foo" , "bar"; }', 'foo{font-family:"foo" ,"bar"}' ],
176 [ "foo { src:\n\turl('foo') ,\n\turl('bar') ; }", "foo{src:url('foo') ,url('bar') }" ],
177
178 // Interesting cases with string values
179 // - Double quotes, single quotes
180 [ 'foo { content: ""; }', 'foo{content:""}' ],
181 [ "foo { content: ''; }", "foo{content:''}" ],
182 [ 'foo { content: "\'"; }', 'foo{content:"\'"}' ],
183 [ "foo { content: '\"'; }", "foo{content:'\"'}" ],
184 // - Whitespace in string values
185 [ 'foo { content: " "; }', 'foo{content:" "}' ],
186
187 // Whitespaces after opening and before closing parentheses and brackets
188 [ 'a:not( [ href ] ) { prop: url( foobar.png ); }', 'a:not([href]){prop:url(foobar.png)}' ],
189
190 // Ensure that the invalid "url (" will not become the valid "url(" by minification
191 [ 'foo { prop: url ( foobar.png ); }', 'foo{prop:url (foobar.png)}' ],
192 ];
193 }
194
195 public static function provideIsRemoteUrl() {
196 return [
197 [ true, 'http://localhost/w/red.gif?123' ],
198 [ true, 'https://example.org/x.png' ],
199 [ true, '//example.org/x.y.z/image.png' ],
200 [ true, '//localhost/styles.css?query=yes' ],
201 [ true, 'data:image/gif;base64,R0lGODlhAQABAIAAAP8AADAAACwAAAAAAQABAAACAkQBADs=' ],
202 [ false, '' ],
203 [ false, '/' ],
204 [ true, '//' ],
205 [ false, 'x.gif' ],
206 [ false, '/x.gif' ],
207 [ false, './x.gif' ],
208 [ false, '../x.gif' ],
209 ];
210 }
211
212 /**
213 * @dataProvider provideIsRemoteUrl
214 * @covers CSSMin::isRemoteUrl
215 */
216 public function testIsRemoteUrl( $expect, $url ) {
217 $class = TestingAccessWrapper::newFromClass( CSSMin::class );
218 $this->assertEquals( $class->isRemoteUrl( $url ), $expect );
219 }
220
221 public static function provideIsLocalUrls() {
222 return [
223 [ false, '' ],
224 [ false, '/' ],
225 [ false, '//' ],
226 [ false, 'x.gif' ],
227 [ true, '/x.gif' ],
228 [ false, './x.gif' ],
229 [ false, '../x.gif' ],
230 ];
231 }
232
233 /**
234 * @dataProvider provideIsLocalUrls
235 * @covers CSSMin::isLocalUrl
236 */
237 public function testIsLocalUrl( $expect, $url ) {
238 $class = TestingAccessWrapper::newFromClass( CSSMin::class );
239 $this->assertEquals( $class->isLocalUrl( $url ), $expect );
240 }
241
242 /**
243 * This test tests funky parameters to CSSMin::remap.
244 *
245 * @see testRemapRemapping for testing of the basic functionality
246 * @dataProvider provideRemapCases
247 * @covers CSSMin::remap
248 * @covers CSSMin::remapOne
249 */
250 public function testRemap( $message, $params, $expectedOutput ) {
251 $remapped = call_user_func_array( 'CSSMin::remap', $params );
252
253 $messageAdd = " Case: $message";
254 $this->assertEquals(
255 $expectedOutput,
256 $remapped,
257 'CSSMin::remap should return the expected url form.' . $messageAdd
258 );
259 }
260
261 public static function provideRemapCases() {
262 // Parameter signature:
263 // CSSMin::remap( $code, $local, $remote, $embedData = true )
264 return [
265 [
266 'Simple case',
267 [ 'foo { prop: url(bar.png); }', false, 'http://example.org', false ],
268 'foo { prop: url(http://example.org/bar.png); }',
269 ],
270 [
271 'Without trailing slash',
272 [ 'foo { prop: url(../bar.png); }', false, 'http://example.org/quux', false ],
273 'foo { prop: url(http://example.org/bar.png); }',
274 ],
275 [
276 'With trailing slash on remote (T29052)',
277 [ 'foo { prop: url(../bar.png); }', false, 'http://example.org/quux/', false ],
278 'foo { prop: url(http://example.org/bar.png); }',
279 ],
280 [
281 'Guard against stripping double slashes from query',
282 [ 'foo { prop: url(bar.png?corge=//grault); }', false, 'http://example.org/quux/', false ],
283 'foo { prop: url(http://example.org/quux/bar.png?corge=//grault); }',
284 ],
285 [
286 'Expand absolute paths',
287 [ 'foo { prop: url(/w/skin/images/bar.png); }', false, 'http://example.org/quux', false ],
288 'foo { prop: url(https://expand.example/w/skin/images/bar.png); }',
289 ],
290 [
291 "Don't barf at behavior: url(#default#behaviorName) - T162973",
292 [ 'foo { behavior: url(#default#bar); }', false, '/w/', false ],
293 'foo { behavior: url("#default#bar"); }',
294 ],
295 ];
296 }
297
298 /**
299 * Cases with empty url() for CSSMin::remap.
300 *
301 * Regression test for T191237.
302 *
303 * @dataProvider provideRemapEmptyUrl
304 * @covers CSSMin
305 */
306 public function testRemapEmptyUrl( $params, $expected ) {
307 $remapped = call_user_func_array( 'CSSMin::remap', $params );
308 $this->assertEquals( $expected, $remapped, 'Ignore empty url' );
309 }
310
311 public static function provideRemapEmptyUrl() {
312 return [
313 'Empty' => [
314 [ "background-image: url();", false, '/example', false ],
315 "background-image: url();",
316 ],
317 'Single quote' => [
318 [ "background-image: url('');", false, '/example', false ],
319 "background-image: url('');",
320 ],
321 'Double quote' => [
322 [ 'background-image: url("");', false, '/example', false ],
323 'background-image: url("");',
324 ],
325 ];
326 }
327
328 /**
329 * This tests the basic functionality of CSSMin::remap.
330 *
331 * @see testRemap for testing of funky parameters
332 * @dataProvider provideRemapRemappingCases
333 * @covers CSSMin
334 */
335 public function testRemapRemapping( $message, $input, $expectedOutput ) {
336 $localPath = __DIR__ . '/../../data/cssmin';
337 $remotePath = 'http://localhost/w';
338
339 $realOutput = CSSMin::remap( $input, $localPath, $remotePath );
340 $this->assertEquals( $expectedOutput, $realOutput, "CSSMin::remap: $message" );
341 }
342
343 public static function provideRemapRemappingCases() {
344 // red.gif and green.gif are one-pixel 35-byte GIFs.
345 // large.png is a 35K PNG that should be non-embeddable.
346 // Full paths start with http://localhost/w/.
347 // Timestamps in output are replaced with 'timestamp'.
348
349 // data: URIs for red.gif, green.gif, circle.svg
350 $red = 'data:image/gif;base64,R0lGODlhAQABAIAAAP8AADAAACwAAAAAAQABAAACAkQBADs=';
351 $green = 'data:image/gif;base64,R0lGODlhAQABAIAAAACAADAAACwAAAAAAQABAAACAkQBADs=';
352 $svg = 'data:image/svg+xml,%3Csvg xmlns=%22http://www.w3.org/2000/svg%22 width=%228'
353 . '%22 height=%228%22 viewBox=%220 0 8 8%22%3E %3Ccircle cx=%224%22 cy=%224%22 '
354 . 'r=%222%22/%3E %3Ca xmlns:xlink=%22http://www.w3.org/1999/xlink%22 xlink:title='
355 . '%22%3F%3E%22%3Etest%3C/a%3E %3C/svg%3E';
356
357 // phpcs:disable Generic.Files.LineLength
358 return [
359 [
360 'Regular file',
361 'foo { background: url(red.gif); }',
362 'foo { background: url(http://localhost/w/red.gif?34ac6); }',
363 ],
364 [
365 'Regular file (missing)',
366 'foo { background: url(theColorOfHerHair.gif); }',
367 'foo { background: url(http://localhost/w/theColorOfHerHair.gif); }',
368 ],
369 [
370 'Remote URL',
371 'foo { background: url(http://example.org/w/foo.png); }',
372 'foo { background: url(http://example.org/w/foo.png); }',
373 ],
374 [
375 'Protocol-relative remote URL',
376 'foo { background: url(//example.org/w/foo.png); }',
377 'foo { background: url(//example.org/w/foo.png); }',
378 ],
379 [
380 'Remote URL with query',
381 'foo { background: url(http://example.org/w/foo.png?query=yes); }',
382 'foo { background: url(http://example.org/w/foo.png?query=yes); }',
383 ],
384 [
385 'Protocol-relative remote URL with query',
386 'foo { background: url(//example.org/w/foo.png?query=yes); }',
387 'foo { background: url(//example.org/w/foo.png?query=yes); }',
388 ],
389 [
390 'Domain-relative URL',
391 'foo { background: url(/static/foo.png); }',
392 'foo { background: url(https://expand.example/static/foo.png); }',
393 ],
394 [
395 'Domain-relative URL with query',
396 'foo { background: url(/static/foo.png?query=yes); }',
397 'foo { background: url(https://expand.example/static/foo.png?query=yes); }',
398 ],
399 [
400 'Remote URL (unnecessary quotes not preserved)',
401 'foo { background: url("http://example.org/w/unnecessary-quotes.png"); }',
402 'foo { background: url(http://example.org/w/unnecessary-quotes.png); }',
403 ],
404 [
405 'Embedded file',
406 'foo { /* @embed */ background: url(red.gif); }',
407 "foo { background: url($red); background: url(http://localhost/w/red.gif?34ac6)!ie; }",
408 ],
409 [
410 'Embedded file, other comments before the rule',
411 "foo { /* Bar. */ /* @embed */ background: url(red.gif); }",
412 "foo { /* Bar. */ background: url($red); /* Bar. */ background: url(http://localhost/w/red.gif?34ac6)!ie; }",
413 ],
414 [
415 'Can not re-embed data: URIs',
416 "foo { /* @embed */ background: url($red); }",
417 "foo { background: url($red); }",
418 ],
419 [
420 'Can not remap data: URIs',
421 "foo { background: url($red); }",
422 "foo { background: url($red); }",
423 ],
424 [
425 'Can not embed remote URLs',
426 'foo { /* @embed */ background: url(http://example.org/w/foo.png); }',
427 'foo { background: url(http://example.org/w/foo.png); }',
428 ],
429 [
430 'Embedded file (inline @embed)',
431 'foo { background: /* @embed */ url(red.gif); }',
432 "foo { background: url($red); "
433 . "background: url(http://localhost/w/red.gif?34ac6)!ie; }",
434 ],
435 [
436 'Can not embed large files',
437 'foo { /* @embed */ background: url(large.png); }',
438 "foo { background: url(http://localhost/w/large.png?e3d1f); }",
439 ],
440 [
441 'SVG files are embedded without base64 encoding and unnecessary IE 6 and 7 fallback',
442 'foo { /* @embed */ background: url(circle.svg); }',
443 "foo { background: url(\"$svg\"); }",
444 ],
445 [
446 'Two regular files in one rule',
447 'foo { background: url(red.gif), url(green.gif); }',
448 'foo { background: url(http://localhost/w/red.gif?34ac6), '
449 . 'url(http://localhost/w/green.gif?13651); }',
450 ],
451 [
452 'Two embedded files in one rule',
453 'foo { /* @embed */ background: url(red.gif), url(green.gif); }',
454 "foo { background: url($red), url($green); "
455 . "background: url(http://localhost/w/red.gif?34ac6), "
456 . "url(http://localhost/w/green.gif?13651)!ie; }",
457 ],
458 [
459 'Two embedded files in one rule (inline @embed)',
460 'foo { background: /* @embed */ url(red.gif), /* @embed */ url(green.gif); }',
461 "foo { background: url($red), url($green); "
462 . "background: url(http://localhost/w/red.gif?34ac6), "
463 . "url(http://localhost/w/green.gif?13651)!ie; }",
464 ],
465 [
466 'Two embedded files in one rule (inline @embed), one too large',
467 'foo { background: /* @embed */ url(red.gif), /* @embed */ url(large.png); }',
468 "foo { background: url($red), url(http://localhost/w/large.png?e3d1f); "
469 . "background: url(http://localhost/w/red.gif?34ac6), "
470 . "url(http://localhost/w/large.png?e3d1f)!ie; }",
471 ],
472 [
473 'Practical example with some noise',
474 'foo { /* @embed */ background: #f9f9f9 url(red.gif) 0 0 no-repeat; }',
475 "foo { background: #f9f9f9 url($red) 0 0 no-repeat; "
476 . "background: #f9f9f9 url(http://localhost/w/red.gif?34ac6) 0 0 no-repeat!ie; }",
477 ],
478 [
479 'Does not mess with other properties',
480 'foo { color: red; background: url(red.gif); font-size: small; }',
481 'foo { color: red; background: url(http://localhost/w/red.gif?34ac6); font-size: small; }',
482 ],
483 [
484 'Spacing and miscellanea not changed (1)',
485 'foo { background: url(red.gif); }',
486 'foo { background: url(http://localhost/w/red.gif?34ac6); }',
487 ],
488 [
489 'Spacing and miscellanea not changed (2)',
490 'foo {background:url(red.gif)}',
491 'foo {background:url(http://localhost/w/red.gif?34ac6)}',
492 ],
493 [
494 'Spaces within url() parentheses are ignored',
495 'foo { background: url( red.gif ); }',
496 'foo { background: url(http://localhost/w/red.gif?34ac6); }',
497 ],
498 [
499 '@import rule to local file (should we remap this?)',
500 '@import url(/styles.css)',
501 '@import url(https://expand.example/styles.css)',
502 ],
503 [
504 '@import rule to local file (should we remap this?)',
505 '@import url(/styles.css)',
506 '@import url(https://expand.example/styles.css)',
507 ],
508 [
509 '@import rule to URL',
510 '@import url(//localhost/styles.css?query=val)',
511 '@import url(//localhost/styles.css?query=val)',
512 ],
513 [
514 'Background URL (double quotes)',
515 'foo { background: url("//localhost/styles.css?quoted=double") }',
516 'foo { background: url(//localhost/styles.css?quoted=double) }',
517 ],
518 [
519 'Background URL (single quotes)',
520 'foo { background: url(\'//localhost/styles.css?quoted=single\') }',
521 'foo { background: url(//localhost/styles.css?quoted=single) }',
522 ],
523 [
524 'Background URL (containing parentheses; T60473)',
525 'foo { background: url("//localhost/styles.css?query=(parens)") }',
526 'foo { background: url("//localhost/styles.css?query=(parens)") }',
527 ],
528 [
529 'Background URL (double quoted, containing single quotes; T60473)',
530 'foo { background: url("//localhost/styles.css?quote=\'") }',
531 'foo { background: url("//localhost/styles.css?quote=\'") }',
532 ],
533 [
534 'Background URL (single quoted, containing double quotes; T60473)',
535 'foo { background: url(\'//localhost/styles.css?quote="\') }',
536 'foo { background: url("//localhost/styles.css?quote=\"") }',
537 ],
538 [
539 'Simple case with comments before url',
540 'foo { prop: /* some {funny;} comment */ url(bar.png); }',
541 'foo { prop: /* some {funny;} comment */ url(http://localhost/w/bar.png); }',
542 ],
543 [
544 'Simple case with comments after url',
545 'foo { prop: url(red.gif)/* some {funny;} comment */ ; }',
546 'foo { prop: url(http://localhost/w/red.gif?34ac6)/* some {funny;} comment */ ; }',
547 ],
548 [
549 'Embedded file with comment before url',
550 'foo { /* @embed */ background: /* some {funny;} comment */ url(red.gif); }',
551 "foo { background: /* some {funny;} comment */ url($red); background: /* some {funny;} comment */ url(http://localhost/w/red.gif?34ac6)!ie; }",
552 ],
553 [
554 'Embedded file with comments inside and outside the rule',
555 'foo { /* @embed */ background: url(red.gif) /* some {foo;} comment */; /* some {bar;} comment */ }',
556 "foo { background: url($red) /* some {foo;} comment */; background: url(http://localhost/w/red.gif?34ac6) /* some {foo;} comment */!ie; /* some {bar;} comment */ }",
557 ],
558 [
559 'Embedded file with comment outside the rule',
560 'foo { /* @embed */ background: url(red.gif); /* some {funny;} comment */ }',
561 "foo { background: url($red); background: url(http://localhost/w/red.gif?34ac6)!ie; /* some {funny;} comment */ }",
562 ],
563 [
564 'Rule with two urls, each with comments',
565 '{ background: /*asd*/ url(something.png); background: /*jkl*/ url(something.png); }',
566 '{ background: /*asd*/ url(http://localhost/w/something.png); background: /*jkl*/ url(http://localhost/w/something.png); }',
567 ],
568 [
569 'Sanity check for offending line from jquery.ui.theme.css (T62077)',
570 '.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}*/; }',
571 '.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}*/; }',
572 ],
573 ];
574 // phpcs:enable
575 }
576
577 /**
578 * This tests basic functionality of CSSMin::buildUrlValue.
579 *
580 * @dataProvider provideBuildUrlValueCases
581 * @covers CSSMin::buildUrlValue
582 */
583 public function testBuildUrlValue( $message, $input, $expectedOutput ) {
584 $this->assertEquals(
585 $expectedOutput,
586 CSSMin::buildUrlValue( $input ),
587 "CSSMin::buildUrlValue: $message"
588 );
589 }
590
591 public static function provideBuildUrlValueCases() {
592 return [
593 [
594 'Full URL',
595 'scheme://user@domain:port/~user/fi%20le.png?query=yes&really=y+s',
596 'url(scheme://user@domain:port/~user/fi%20le.png?query=yes&really=y+s)',
597 ],
598 [
599 'data: URI',
600 'data:image/png;base64,R0lGODlh/+==',
601 'url(data:image/png;base64,R0lGODlh/+==)',
602 ],
603 [
604 'URL with quotes',
605 "https://en.wikipedia.org/wiki/Wendy's",
606 "url(\"https://en.wikipedia.org/wiki/Wendy's\")",
607 ],
608 [
609 'URL with parentheses',
610 'https://en.wikipedia.org/wiki/Boston_(band)',
611 'url("https://en.wikipedia.org/wiki/Boston_(band)")',
612 ],
613 ];
614 }
615
616 /**
617 * Seperated because they are currently broken (T37492)
618 *
619 * @group Broken
620 * @dataProvider provideStringCases
621 * @covers CSSMin::remap
622 */
623 public function testMinifyWithCSSStringValues( $code, $expectedOutput ) {
624 $this->testMinifyOutput( $code, $expectedOutput );
625 }
626
627 public static function provideStringCases() {
628 return [
629 // String values should be respected
630 // - More than one space in a string value
631 [ 'foo { content: " "; }', 'foo{content:" "}' ],
632 // - Using a tab in a string value (turns into a space)
633 [ "foo { content: '\t'; }", "foo{content:'\t'}" ],
634 // - Using css-like syntax in string values
635 [
636 'foo::after { content: "{;}"; position: absolute; }',
637 'foo::after{content:"{;}";position:absolute}'
638 ],
639 ];
640 }
641 }