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