objectcache: update MemcachedPeclBagOStuff for pecl memcached 3.0.0
[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, 'x.gif' ],
203 [ false, '/x.gif' ],
204 [ false, './x.gif' ],
205 [ false, '../x.gif' ],
206 ];
207 }
208
209 /**
210 * @dataProvider provideIsRemoteUrl
211 * @covers CSSMin::isRemoteUrl
212 */
213 public function testIsRemoteUrl( $expect, $url ) {
214 $class = TestingAccessWrapper::newFromClass( CSSMin::class );
215 $this->assertEquals( $class->isRemoteUrl( $url ), $expect );
216 }
217
218 public static function provideIsLocalUrls() {
219 return [
220 [ false, 'x.gif' ],
221 [ true, '/x.gif' ],
222 [ false, './x.gif' ],
223 [ false, '../x.gif' ],
224 ];
225 }
226
227 /**
228 * @dataProvider provideIsLocalUrls
229 * @covers CSSMin::isLocalUrl
230 */
231 public function testIsLocalUrl( $expect, $url ) {
232 $class = TestingAccessWrapper::newFromClass( CSSMin::class );
233 $this->assertEquals( $class->isLocalUrl( $url ), $expect );
234 }
235
236 /**
237 * This test tests funky parameters to CSSMin::remap.
238 *
239 * @see testRemapRemapping for testing of the basic functionality
240 * @dataProvider provideRemapCases
241 * @covers CSSMin::remap
242 * @covers CSSMin::remapOne
243 */
244 public function testRemap( $message, $params, $expectedOutput ) {
245 $remapped = call_user_func_array( 'CSSMin::remap', $params );
246
247 $messageAdd = " Case: $message";
248 $this->assertEquals(
249 $expectedOutput,
250 $remapped,
251 'CSSMin::remap should return the expected url form.' . $messageAdd
252 );
253 }
254
255 public static function provideRemapCases() {
256 // Parameter signature:
257 // CSSMin::remap( $code, $local, $remote, $embedData = true )
258 return [
259 [
260 'Simple case',
261 [ 'foo { prop: url(bar.png); }', false, 'http://example.org', false ],
262 'foo { prop: url(http://example.org/bar.png); }',
263 ],
264 [
265 'Without trailing slash',
266 [ 'foo { prop: url(../bar.png); }', false, 'http://example.org/quux', false ],
267 'foo { prop: url(http://example.org/bar.png); }',
268 ],
269 [
270 'With trailing slash on remote (T29052)',
271 [ 'foo { prop: url(../bar.png); }', false, 'http://example.org/quux/', false ],
272 'foo { prop: url(http://example.org/bar.png); }',
273 ],
274 [
275 'Guard against stripping double slashes from query',
276 [ 'foo { prop: url(bar.png?corge=//grault); }', false, 'http://example.org/quux/', false ],
277 'foo { prop: url(http://example.org/quux/bar.png?corge=//grault); }',
278 ],
279 [
280 'Expand absolute paths',
281 [ 'foo { prop: url(/w/skin/images/bar.png); }', false, 'http://example.org/quux', false ],
282 'foo { prop: url(https://expand.example/w/skin/images/bar.png); }',
283 ],
284 [
285 "Don't barf at behavior: url(#default#behaviorName) - T162973",
286 [ 'foo { behavior: url(#default#bar); }', false, '/w/', false ],
287 'foo { behavior: url("#default#bar"); }',
288 ],
289 ];
290 }
291
292 /**
293 * Cases with empty url() for CSSMin::remap.
294 *
295 * Regression test for T191237.
296 *
297 * @dataProvider provideRemapEmptyUrl
298 * @covers CSSMin
299 */
300 public function testRemapEmptyUrl( $params, $expected ) {
301 $remapped = call_user_func_array( 'CSSMin::remap', $params );
302 $this->assertEquals( $expected, $remapped, 'Ignore empty url' );
303 }
304
305 public static function provideRemapEmptyUrl() {
306 return [
307 'Empty' => [
308 [ "background-image: url();", false, '/example', false ],
309 "background-image: url();",
310 ],
311 'Single quote' => [
312 [ "background-image: url('');", false, '/example', false ],
313 "background-image: url('');",
314 ],
315 'Double quote' => [
316 [ 'background-image: url("");', false, '/example', false ],
317 'background-image: url("");',
318 ],
319 ];
320 }
321
322 /**
323 * This tests the basic functionality of CSSMin::remap.
324 *
325 * @see testRemap for testing of funky parameters
326 * @dataProvider provideRemapRemappingCases
327 * @covers CSSMin
328 */
329 public function testRemapRemapping( $message, $input, $expectedOutput ) {
330 $localPath = __DIR__ . '/../../data/cssmin';
331 $remotePath = 'http://localhost/w';
332
333 $realOutput = CSSMin::remap( $input, $localPath, $remotePath );
334 $this->assertEquals( $expectedOutput, $realOutput, "CSSMin::remap: $message" );
335 }
336
337 public static function provideRemapRemappingCases() {
338 // red.gif and green.gif are one-pixel 35-byte GIFs.
339 // large.png is a 35K PNG that should be non-embeddable.
340 // Full paths start with http://localhost/w/.
341 // Timestamps in output are replaced with 'timestamp'.
342
343 // data: URIs for red.gif, green.gif, circle.svg
344 $red = 'data:image/gif;base64,R0lGODlhAQABAIAAAP8AADAAACwAAAAAAQABAAACAkQBADs=';
345 $green = 'data:image/gif;base64,R0lGODlhAQABAIAAAACAADAAACwAAAAAAQABAAACAkQBADs=';
346 $svg = 'data:image/svg+xml,%3Csvg xmlns=%22http://www.w3.org/2000/svg%22 width=%228'
347 . '%22 height=%228%22 viewBox=%220 0 8 8%22%3E %3Ccircle cx=%224%22 cy=%224%22 '
348 . 'r=%222%22/%3E %3Ca xmlns:xlink=%22http://www.w3.org/1999/xlink%22 xlink:title='
349 . '%22%3F%3E%22%3Etest%3C/a%3E %3C/svg%3E';
350
351 // phpcs:disable Generic.Files.LineLength
352 return [
353 [
354 'Regular file',
355 'foo { background: url(red.gif); }',
356 'foo { background: url(http://localhost/w/red.gif?34ac6); }',
357 ],
358 [
359 'Regular file (missing)',
360 'foo { background: url(theColorOfHerHair.gif); }',
361 'foo { background: url(http://localhost/w/theColorOfHerHair.gif); }',
362 ],
363 [
364 'Remote URL',
365 'foo { background: url(http://example.org/w/foo.png); }',
366 'foo { background: url(http://example.org/w/foo.png); }',
367 ],
368 [
369 'Protocol-relative remote URL',
370 'foo { background: url(//example.org/w/foo.png); }',
371 'foo { background: url(//example.org/w/foo.png); }',
372 ],
373 [
374 'Remote URL with query',
375 'foo { background: url(http://example.org/w/foo.png?query=yes); }',
376 'foo { background: url(http://example.org/w/foo.png?query=yes); }',
377 ],
378 [
379 'Protocol-relative remote URL with query',
380 'foo { background: url(//example.org/w/foo.png?query=yes); }',
381 'foo { background: url(//example.org/w/foo.png?query=yes); }',
382 ],
383 [
384 'Domain-relative URL',
385 'foo { background: url(/static/foo.png); }',
386 'foo { background: url(https://expand.example/static/foo.png); }',
387 ],
388 [
389 'Domain-relative URL with query',
390 'foo { background: url(/static/foo.png?query=yes); }',
391 'foo { background: url(https://expand.example/static/foo.png?query=yes); }',
392 ],
393 [
394 'Remote URL (unnecessary quotes not preserved)',
395 'foo { background: url("http://example.org/w/unnecessary-quotes.png"); }',
396 'foo { background: url(http://example.org/w/unnecessary-quotes.png); }',
397 ],
398 [
399 'Embedded file',
400 'foo { /* @embed */ background: url(red.gif); }',
401 "foo { background: url($red); background: url(http://localhost/w/red.gif?34ac6)!ie; }",
402 ],
403 [
404 'Embedded file, other comments before the rule',
405 "foo { /* Bar. */ /* @embed */ background: url(red.gif); }",
406 "foo { /* Bar. */ background: url($red); /* Bar. */ background: url(http://localhost/w/red.gif?34ac6)!ie; }",
407 ],
408 [
409 'Can not re-embed data: URIs',
410 "foo { /* @embed */ background: url($red); }",
411 "foo { background: url($red); }",
412 ],
413 [
414 'Can not remap data: URIs',
415 "foo { background: url($red); }",
416 "foo { background: url($red); }",
417 ],
418 [
419 'Can not embed remote URLs',
420 'foo { /* @embed */ background: url(http://example.org/w/foo.png); }',
421 'foo { background: url(http://example.org/w/foo.png); }',
422 ],
423 [
424 'Embedded file (inline @embed)',
425 'foo { background: /* @embed */ url(red.gif); }',
426 "foo { background: url($red); "
427 . "background: url(http://localhost/w/red.gif?34ac6)!ie; }",
428 ],
429 [
430 'Can not embed large files',
431 'foo { /* @embed */ background: url(large.png); }',
432 "foo { background: url(http://localhost/w/large.png?e3d1f); }",
433 ],
434 [
435 'SVG files are embedded without base64 encoding and unnecessary IE 6 and 7 fallback',
436 'foo { /* @embed */ background: url(circle.svg); }',
437 "foo { background: url(\"$svg\"); }",
438 ],
439 [
440 'Two regular files in one rule',
441 'foo { background: url(red.gif), url(green.gif); }',
442 'foo { background: url(http://localhost/w/red.gif?34ac6), '
443 . 'url(http://localhost/w/green.gif?13651); }',
444 ],
445 [
446 'Two embedded files in one rule',
447 'foo { /* @embed */ background: url(red.gif), url(green.gif); }',
448 "foo { background: url($red), url($green); "
449 . "background: url(http://localhost/w/red.gif?34ac6), "
450 . "url(http://localhost/w/green.gif?13651)!ie; }",
451 ],
452 [
453 'Two embedded files in one rule (inline @embed)',
454 'foo { background: /* @embed */ url(red.gif), /* @embed */ url(green.gif); }',
455 "foo { background: url($red), url($green); "
456 . "background: url(http://localhost/w/red.gif?34ac6), "
457 . "url(http://localhost/w/green.gif?13651)!ie; }",
458 ],
459 [
460 'Two embedded files in one rule (inline @embed), one too large',
461 'foo { background: /* @embed */ url(red.gif), /* @embed */ url(large.png); }',
462 "foo { background: url($red), url(http://localhost/w/large.png?e3d1f); "
463 . "background: url(http://localhost/w/red.gif?34ac6), "
464 . "url(http://localhost/w/large.png?e3d1f)!ie; }",
465 ],
466 [
467 'Practical example with some noise',
468 'foo { /* @embed */ background: #f9f9f9 url(red.gif) 0 0 no-repeat; }',
469 "foo { background: #f9f9f9 url($red) 0 0 no-repeat; "
470 . "background: #f9f9f9 url(http://localhost/w/red.gif?34ac6) 0 0 no-repeat!ie; }",
471 ],
472 [
473 'Does not mess with other properties',
474 'foo { color: red; background: url(red.gif); font-size: small; }',
475 'foo { color: red; background: url(http://localhost/w/red.gif?34ac6); font-size: small; }',
476 ],
477 [
478 'Spacing and miscellanea not changed (1)',
479 'foo { background: url(red.gif); }',
480 'foo { background: url(http://localhost/w/red.gif?34ac6); }',
481 ],
482 [
483 'Spacing and miscellanea not changed (2)',
484 'foo {background:url(red.gif)}',
485 'foo {background:url(http://localhost/w/red.gif?34ac6)}',
486 ],
487 [
488 'Spaces within url() parentheses are ignored',
489 'foo { background: url( red.gif ); }',
490 'foo { background: url(http://localhost/w/red.gif?34ac6); }',
491 ],
492 [
493 '@import rule to local file (should we remap this?)',
494 '@import url(/styles.css)',
495 '@import url(https://expand.example/styles.css)',
496 ],
497 [
498 '@import rule to local file (should we remap this?)',
499 '@import url(/styles.css)',
500 '@import url(https://expand.example/styles.css)',
501 ],
502 [
503 '@import rule to URL',
504 '@import url(//localhost/styles.css?query=val)',
505 '@import url(//localhost/styles.css?query=val)',
506 ],
507 [
508 'Background URL (double quotes)',
509 'foo { background: url("//localhost/styles.css?quoted=double") }',
510 'foo { background: url(//localhost/styles.css?quoted=double) }',
511 ],
512 [
513 'Background URL (single quotes)',
514 'foo { background: url(\'//localhost/styles.css?quoted=single\') }',
515 'foo { background: url(//localhost/styles.css?quoted=single) }',
516 ],
517 [
518 'Background URL (double quoted, containing parentheses; T60473)',
519 'foo { background: url("//localhost/styles.css?query=(parens)") }',
520 'foo { background: url("//localhost/styles.css?query=(parens)") }',
521 ],
522 [
523 'Background URL (double quoted, containing single quotes; T60473)',
524 'foo { background: url("//localhost/styles.css?quote=\'") }',
525 'foo { background: url("//localhost/styles.css?quote=\'") }',
526 ],
527 [
528 'Background URL (single quoted, containing double quotes; T60473)',
529 'foo { background: url(\'//localhost/styles.css?quote="\') }',
530 'foo { background: url("//localhost/styles.css?quote=\"") }',
531 ],
532 [
533 'Background URL (double quoted with outer spacing)',
534 'foo { background: url( "http://localhost/styles.css?quoted=double" ) }',
535 'foo { background: url(http://localhost/styles.css?quoted=double) }',
536 ],
537 [
538 'Simple case with comments before url',
539 'foo { prop: /* some {funny;} comment */ url(bar.png); }',
540 'foo { prop: /* some {funny;} comment */ url(http://localhost/w/bar.png); }',
541 ],
542 [
543 'Simple case with comments after url',
544 'foo { prop: url(red.gif)/* some {funny;} comment */ ; }',
545 'foo { prop: url(http://localhost/w/red.gif?34ac6)/* some {funny;} comment */ ; }',
546 ],
547 [
548 'Embedded file with comment before url',
549 'foo { /* @embed */ background: /* some {funny;} comment */ url(red.gif); }',
550 "foo { background: /* some {funny;} comment */ url($red); background: /* some {funny;} comment */ url(http://localhost/w/red.gif?34ac6)!ie; }",
551 ],
552 [
553 'Embedded file with comments inside and outside the rule',
554 'foo { /* @embed */ background: url(red.gif) /* some {foo;} comment */; /* some {bar;} comment */ }',
555 "foo { background: url($red) /* some {foo;} comment */; background: url(http://localhost/w/red.gif?34ac6) /* some {foo;} comment */!ie; /* some {bar;} comment */ }",
556 ],
557 [
558 'Embedded file with comment outside the rule',
559 'foo { /* @embed */ background: url(red.gif); /* some {funny;} comment */ }',
560 "foo { background: url($red); background: url(http://localhost/w/red.gif?34ac6)!ie; /* some {funny;} comment */ }",
561 ],
562 [
563 'Rule with two urls, each with comments',
564 '{ background: /*asd*/ url(something.png); background: /*jkl*/ url(something.png); }',
565 '{ background: /*asd*/ url(http://localhost/w/something.png); background: /*jkl*/ url(http://localhost/w/something.png); }',
566 ],
567 [
568 'Sanity check for offending line from jquery.ui.theme.css (T62077)',
569 '.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}*/; }',
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(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}*/; }',
571 ],
572 ];
573 // phpcs:enable
574 }
575
576 /**
577 * This tests basic functionality of CSSMin::buildUrlValue.
578 *
579 * @dataProvider provideBuildUrlValueCases
580 * @covers CSSMin::buildUrlValue
581 */
582 public function testBuildUrlValue( $message, $input, $expectedOutput ) {
583 $this->assertEquals(
584 $expectedOutput,
585 CSSMin::buildUrlValue( $input ),
586 "CSSMin::buildUrlValue: $message"
587 );
588 }
589
590 public static function provideBuildUrlValueCases() {
591 return [
592 [
593 'Full URL',
594 'scheme://user@domain:port/~user/fi%20le.png?query=yes&really=y+s',
595 'url(scheme://user@domain:port/~user/fi%20le.png?query=yes&really=y+s)',
596 ],
597 [
598 'data: URI',
599 'data:image/png;base64,R0lGODlh/+==',
600 'url(data:image/png;base64,R0lGODlh/+==)',
601 ],
602 [
603 'URL with quotes',
604 "https://en.wikipedia.org/wiki/Wendy's",
605 "url(\"https://en.wikipedia.org/wiki/Wendy's\")",
606 ],
607 [
608 'URL with parentheses',
609 'https://en.wikipedia.org/wiki/Boston_(band)',
610 'url("https://en.wikipedia.org/wiki/Boston_(band)")',
611 ],
612 ];
613 }
614
615 /**
616 * Seperated because they are currently broken (T37492)
617 *
618 * @group Broken
619 * @dataProvider provideStringCases
620 * @covers CSSMin::remap
621 */
622 public function testMinifyWithCSSStringValues( $code, $expectedOutput ) {
623 $this->testMinifyOutput( $code, $expectedOutput );
624 }
625
626 public static function provideStringCases() {
627 return [
628 // String values should be respected
629 // - More than one space in a string value
630 [ 'foo { content: " "; }', 'foo{content:" "}' ],
631 // - Using a tab in a string value (turns into a space)
632 [ "foo { content: '\t'; }", "foo{content:'\t'}" ],
633 // - Using css-like syntax in string values
634 [
635 'foo::after { content: "{;}"; position: absolute; }',
636 'foo::after{content:"{;}";position:absolute}'
637 ],
638 ];
639 }
640 }