2012-06-20 03:13:52 +00:00
|
|
|
<?php
|
|
|
|
|
/**
|
|
|
|
|
* This file test the CSSMin library shipped with Mediawiki.
|
|
|
|
|
*
|
|
|
|
|
* @author Timo Tijhof
|
|
|
|
|
*/
|
|
|
|
|
|
2017-04-27 21:33:35 +00:00
|
|
|
/**
|
|
|
|
|
* @group ResourceLoader
|
|
|
|
|
* @group CSSMin
|
|
|
|
|
*/
|
2012-06-20 03:13:52 +00:00
|
|
|
class CSSMinTest extends MediaWikiTestCase {
|
|
|
|
|
|
2012-10-08 10:56:20 +00:00
|
|
|
protected function setUp() {
|
2012-06-20 03:13:52 +00:00
|
|
|
parent::setUp();
|
|
|
|
|
|
2012-10-08 10:56:20 +00:00
|
|
|
$server = 'http://doc.example.org';
|
2012-06-20 03:13:52 +00:00
|
|
|
|
2016-02-17 09:09:32 +00:00
|
|
|
$this->setMwGlobals( [
|
2012-10-08 10:56:20 +00:00
|
|
|
'wgServer' => $server,
|
|
|
|
|
'wgCanonicalServer' => $server,
|
2016-02-17 09:09:32 +00:00
|
|
|
] );
|
2012-06-20 03:13:52 +00:00
|
|
|
}
|
|
|
|
|
|
2017-03-26 16:08:06 +00:00
|
|
|
/**
|
|
|
|
|
* @dataProvider mimeTypeProvider
|
2017-07-28 04:40:21 +00:00
|
|
|
* @covers CSSMin::getMimeType
|
2017-03-26 16:08:06 +00:00
|
|
|
*/
|
|
|
|
|
public function testGetMimeType( $fileContents, $fileExtension, $expected ) {
|
|
|
|
|
$fileName = wfTempDir() . DIRECTORY_SEPARATOR . uniqid( 'MW_PHPUnit_CSSMinTest_' ) . '.'
|
|
|
|
|
. $fileExtension;
|
|
|
|
|
$this->addTmpFiles( $fileName );
|
|
|
|
|
file_put_contents( $fileName, $fileContents );
|
|
|
|
|
$this->assertSame( $expected, CSSMin::getMimeType( $fileName ) );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function mimeTypeProvider() {
|
|
|
|
|
return [
|
|
|
|
|
'JPEG with short extension' => [
|
|
|
|
|
"\xFF\xD8\xFF",
|
|
|
|
|
'jpg',
|
|
|
|
|
'image/jpeg'
|
|
|
|
|
],
|
|
|
|
|
'JPEG with long extension' => [
|
|
|
|
|
"\xFF\xD8\xFF",
|
|
|
|
|
'jpeg',
|
|
|
|
|
'image/jpeg'
|
|
|
|
|
],
|
|
|
|
|
'PNG' => [
|
|
|
|
|
"\x89\x50\x4E\x47\x0D\x0A\x1A\x0A",
|
|
|
|
|
'png',
|
|
|
|
|
'image/png'
|
|
|
|
|
],
|
|
|
|
|
|
|
|
|
|
'PNG extension but JPEG content' => [
|
|
|
|
|
"\xFF\xD8\xFF",
|
|
|
|
|
'png',
|
|
|
|
|
'image/png'
|
|
|
|
|
],
|
|
|
|
|
'JPEG extension but PNG content' => [
|
|
|
|
|
"\x89\x50\x4E\x47\x0D\x0A\x1A\x0A",
|
|
|
|
|
'jpg',
|
|
|
|
|
'image/jpeg'
|
|
|
|
|
],
|
|
|
|
|
'PNG extension but SVG content' => [
|
|
|
|
|
'<?xml version="1.0"?><svg></svg>',
|
|
|
|
|
'png',
|
|
|
|
|
'image/png'
|
|
|
|
|
],
|
|
|
|
|
'SVG extension but PNG content' => [
|
|
|
|
|
"\x89\x50\x4E\x47\x0D\x0A\x1A\x0A",
|
|
|
|
|
'svg',
|
|
|
|
|
'image/svg+xml'
|
|
|
|
|
],
|
|
|
|
|
|
|
|
|
|
'SVG with all headers' => [
|
|
|
|
|
'<?xml version="1.0"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" '
|
|
|
|
|
. '"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg></svg>',
|
|
|
|
|
'svg',
|
|
|
|
|
'image/svg+xml'
|
|
|
|
|
],
|
|
|
|
|
'SVG with XML header only' => [
|
|
|
|
|
'<?xml version="1.0"?><svg></svg>',
|
|
|
|
|
'svg',
|
|
|
|
|
'image/svg+xml'
|
|
|
|
|
],
|
|
|
|
|
'SVG with DOCTYPE only' => [
|
|
|
|
|
'<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" '
|
|
|
|
|
. '"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg></svg>',
|
|
|
|
|
'svg',
|
|
|
|
|
'image/svg+xml'
|
|
|
|
|
],
|
|
|
|
|
'SVG without any header' => [
|
|
|
|
|
'<svg></svg>',
|
|
|
|
|
'svg',
|
|
|
|
|
'image/svg+xml'
|
|
|
|
|
],
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
2012-06-20 03:13:52 +00:00
|
|
|
/**
|
|
|
|
|
* @dataProvider provideMinifyCases
|
2013-10-24 16:45:52 +00:00
|
|
|
* @covers CSSMin::minify
|
2012-06-20 03:13:52 +00:00
|
|
|
*/
|
2013-10-23 22:51:31 +00:00
|
|
|
public function testMinify( $code, $expectedOutput ) {
|
2012-06-20 03:13:52 +00:00
|
|
|
$minified = CSSMin::minify( $code );
|
|
|
|
|
|
2014-04-24 16:06:46 +00:00
|
|
|
$this->assertEquals(
|
|
|
|
|
$expectedOutput,
|
|
|
|
|
$minified,
|
|
|
|
|
'Minified output should be in the form expected.'
|
|
|
|
|
);
|
2012-06-20 03:13:52 +00:00
|
|
|
}
|
|
|
|
|
|
2013-03-22 02:12:37 +00:00
|
|
|
public static function provideMinifyCases() {
|
2016-02-17 09:09:32 +00:00
|
|
|
return [
|
2012-06-20 03:13:52 +00:00
|
|
|
// Whitespace
|
2016-02-17 09:09:32 +00:00
|
|
|
[ "\r\t\f \v\n\r", "" ],
|
|
|
|
|
[ "foo, bar {\n\tprop: value;\n}", "foo,bar{prop:value}" ],
|
2012-06-20 03:13:52 +00:00
|
|
|
|
|
|
|
|
// Loose comments
|
2016-02-17 09:09:32 +00:00
|
|
|
[ "/* foo */", "" ],
|
|
|
|
|
[ "/*******\n foo\n *******/", "" ],
|
|
|
|
|
[ "/*!\n foo\n */", "" ],
|
2012-06-20 03:13:52 +00:00
|
|
|
|
|
|
|
|
// Inline comments in various different places
|
2016-02-17 09:09:32 +00:00
|
|
|
[ "/* comment */foo, bar {\n\tprop: value;\n}", "foo,bar{prop:value}" ],
|
|
|
|
|
[ "foo/* comment */, bar {\n\tprop: value;\n}", "foo,bar{prop:value}" ],
|
|
|
|
|
[ "foo,/* comment */ bar {\n\tprop: value;\n}", "foo,bar{prop:value}" ],
|
|
|
|
|
[ "foo, bar/* comment */ {\n\tprop: value;\n}", "foo,bar{prop:value}" ],
|
|
|
|
|
[ "foo, bar {\n\t/* comment */prop: value;\n}", "foo,bar{prop:value}" ],
|
|
|
|
|
[ "foo, bar {\n\tprop: /* comment */value;\n}", "foo,bar{prop:value}" ],
|
|
|
|
|
[ "foo, bar {\n\tprop: value /* comment */;\n}", "foo,bar{prop:value }" ],
|
|
|
|
|
[ "foo, bar {\n\tprop: value; /* comment */\n}", "foo,bar{prop:value; }" ],
|
2012-06-20 03:13:52 +00:00
|
|
|
|
|
|
|
|
// Keep track of things that aren't as minified as much as they
|
2017-02-20 23:45:58 +00:00
|
|
|
// could be (T37493)
|
2016-02-17 09:09:32 +00:00
|
|
|
[ 'foo { prop: value ;}', 'foo{prop:value }' ],
|
|
|
|
|
[ 'foo { prop : value; }', 'foo{prop :value}' ],
|
|
|
|
|
[ 'foo { prop: value ; }', 'foo{prop:value }' ],
|
|
|
|
|
[ 'foo { font-family: "foo" , "bar"; }', 'foo{font-family:"foo" ,"bar"}' ],
|
|
|
|
|
[ "foo { src:\n\turl('foo') ,\n\turl('bar') ; }", "foo{src:url('foo') ,url('bar') }" ],
|
2012-06-20 03:13:52 +00:00
|
|
|
|
|
|
|
|
// Interesting cases with string values
|
|
|
|
|
// - Double quotes, single quotes
|
2016-02-17 09:09:32 +00:00
|
|
|
[ 'foo { content: ""; }', 'foo{content:""}' ],
|
|
|
|
|
[ "foo { content: ''; }", "foo{content:''}" ],
|
|
|
|
|
[ 'foo { content: "\'"; }', 'foo{content:"\'"}' ],
|
|
|
|
|
[ "foo { content: '\"'; }", "foo{content:'\"'}" ],
|
2012-06-20 03:13:52 +00:00
|
|
|
// - Whitespace in string values
|
2016-02-17 09:09:32 +00:00
|
|
|
[ 'foo { content: " "; }', 'foo{content:" "}' ],
|
2017-12-06 16:16:41 +00:00
|
|
|
|
|
|
|
|
// Whitespaces after opening and before closing parentheses and brackets
|
|
|
|
|
[ 'a:not( [ href ] ) { prop: url( foobar.png ); }', 'a:not([href]){prop:url(foobar.png)}' ],
|
|
|
|
|
|
|
|
|
|
// Ensure that the invalid "url (" will not become the valid "url(" by minification
|
|
|
|
|
[ 'foo { prop: url ( foobar.png ); }', 'foo{prop:url (foobar.png)}' ],
|
2016-02-17 09:09:32 +00:00
|
|
|
];
|
2012-06-20 03:13:52 +00:00
|
|
|
}
|
|
|
|
|
|
2017-05-04 02:54:52 +00:00
|
|
|
public static function provideIsRemoteUrl() {
|
|
|
|
|
return [
|
|
|
|
|
[ true, 'http://localhost/w/red.gif?123' ],
|
|
|
|
|
[ true, 'https://example.org/x.png' ],
|
|
|
|
|
[ true, '//example.org/x.y.z/image.png' ],
|
|
|
|
|
[ true, '//localhost/styles.css?query=yes' ],
|
|
|
|
|
[ true, 'data:image/gif;base64,R0lGODlhAQABAIAAAP8AADAAACwAAAAAAQABAAACAkQBADs=' ],
|
|
|
|
|
[ false, 'x.gif' ],
|
|
|
|
|
[ false, '/x.gif' ],
|
|
|
|
|
[ false, './x.gif' ],
|
|
|
|
|
[ false, '../x.gif' ],
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @dataProvider provideIsRemoteUrl
|
2017-07-28 04:40:21 +00:00
|
|
|
* @covers CSSMin::isRemoteUrl
|
2017-05-04 02:54:52 +00:00
|
|
|
*/
|
|
|
|
|
public function testIsRemoteUrl( $expect, $url ) {
|
|
|
|
|
$this->assertEquals( CSSMinTestable::isRemoteUrl( $url ), $expect );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static function provideIsLocalUrls() {
|
|
|
|
|
return [
|
|
|
|
|
[ false, 'x.gif' ],
|
|
|
|
|
[ true, '/x.gif' ],
|
|
|
|
|
[ false, './x.gif' ],
|
|
|
|
|
[ false, '../x.gif' ],
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @dataProvider provideIsLocalUrls
|
2017-07-28 04:40:21 +00:00
|
|
|
* @covers CSSMin::isLocalUrl
|
2017-05-04 02:54:52 +00:00
|
|
|
*/
|
|
|
|
|
public function testIsLocalUrl( $expect, $url ) {
|
|
|
|
|
$this->assertEquals( CSSMinTestable::isLocalUrl( $url ), $expect );
|
|
|
|
|
}
|
|
|
|
|
|
2012-06-20 03:13:52 +00:00
|
|
|
/**
|
2017-07-28 04:40:21 +00:00
|
|
|
* This test tests funky parameters to CSSMin::remap.
|
2013-11-09 23:52:14 +00:00
|
|
|
*
|
2017-07-28 04:40:21 +00:00
|
|
|
* @see testRemapRemapping for testing of the basic functionality
|
2012-06-20 03:13:52 +00:00
|
|
|
* @dataProvider provideRemapCases
|
2013-10-24 16:45:52 +00:00
|
|
|
* @covers CSSMin::remap
|
2017-07-28 04:40:21 +00:00
|
|
|
* @covers CSSMin::remapOne
|
2012-06-20 03:13:52 +00:00
|
|
|
*/
|
2013-10-23 22:51:31 +00:00
|
|
|
public function testRemap( $message, $params, $expectedOutput ) {
|
2012-06-20 03:13:52 +00:00
|
|
|
$remapped = call_user_func_array( 'CSSMin::remap', $params );
|
|
|
|
|
|
|
|
|
|
$messageAdd = " Case: $message";
|
2014-04-24 16:06:46 +00:00
|
|
|
$this->assertEquals(
|
|
|
|
|
$expectedOutput,
|
|
|
|
|
$remapped,
|
|
|
|
|
'CSSMin::remap should return the expected url form.' . $messageAdd
|
|
|
|
|
);
|
2012-06-20 03:13:52 +00:00
|
|
|
}
|
|
|
|
|
|
2013-03-22 02:12:37 +00:00
|
|
|
public static function provideRemapCases() {
|
2012-06-20 03:13:52 +00:00
|
|
|
// Parameter signature:
|
|
|
|
|
// CSSMin::remap( $code, $local, $remote, $embedData = true )
|
2016-02-17 09:09:32 +00:00
|
|
|
return [
|
|
|
|
|
[
|
2012-06-20 03:13:52 +00:00
|
|
|
'Simple case',
|
2016-02-17 09:09:32 +00:00
|
|
|
[ 'foo { prop: url(bar.png); }', false, 'http://example.org', false ],
|
2012-06-20 03:13:52 +00:00
|
|
|
'foo { prop: url(http://example.org/bar.png); }',
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
[
|
2012-06-20 03:13:52 +00:00
|
|
|
'Without trailing slash',
|
2016-02-17 09:09:32 +00:00
|
|
|
[ 'foo { prop: url(../bar.png); }', false, 'http://example.org/quux', false ],
|
2015-08-16 17:32:13 +00:00
|
|
|
'foo { prop: url(http://example.org/bar.png); }',
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
[
|
2017-02-20 23:45:58 +00:00
|
|
|
'With trailing slash on remote (T29052)',
|
2016-02-17 09:09:32 +00:00
|
|
|
[ 'foo { prop: url(../bar.png); }', false, 'http://example.org/quux/', false ],
|
2015-08-16 17:32:13 +00:00
|
|
|
'foo { prop: url(http://example.org/bar.png); }',
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
[
|
2012-06-20 03:13:52 +00:00
|
|
|
'Guard against stripping double slashes from query',
|
2016-02-17 09:09:32 +00:00
|
|
|
[ 'foo { prop: url(bar.png?corge=//grault); }', false, 'http://example.org/quux/', false ],
|
2012-06-20 03:13:52 +00:00
|
|
|
'foo { prop: url(http://example.org/quux/bar.png?corge=//grault); }',
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
[
|
2012-06-20 03:13:52 +00:00
|
|
|
'Expand absolute paths',
|
2016-02-17 09:09:32 +00:00
|
|
|
[ 'foo { prop: url(/w/skin/images/bar.png); }', false, 'http://example.org/quux', false ],
|
2012-10-08 10:56:20 +00:00
|
|
|
'foo { prop: url(http://doc.example.org/w/skin/images/bar.png); }',
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
2017-04-27 21:33:35 +00:00
|
|
|
[
|
|
|
|
|
"Don't barf at behavior: url(#default#behaviorName) - T162973",
|
|
|
|
|
[ 'foo { behavior: url(#default#bar); }', false, '/w/', false ],
|
2017-09-29 11:53:02 +00:00
|
|
|
'foo { behavior: url("#default#bar"); }',
|
2017-04-27 21:33:35 +00:00
|
|
|
],
|
2016-02-17 09:09:32 +00:00
|
|
|
];
|
2012-06-20 03:13:52 +00:00
|
|
|
}
|
|
|
|
|
|
2013-11-09 23:52:14 +00:00
|
|
|
/**
|
2017-07-28 04:40:21 +00:00
|
|
|
* This tests the basic functionality of CSSMin::remap.
|
2013-11-09 23:52:14 +00:00
|
|
|
*
|
2017-07-28 04:40:21 +00:00
|
|
|
* @see testRemap for testing of funky parameters
|
2013-11-09 23:52:14 +00:00
|
|
|
* @dataProvider provideRemapRemappingCases
|
2017-07-28 04:40:21 +00:00
|
|
|
* @covers CSSMin
|
2013-11-09 23:52:14 +00:00
|
|
|
*/
|
|
|
|
|
public function testRemapRemapping( $message, $input, $expectedOutput ) {
|
2016-11-02 09:25:40 +00:00
|
|
|
$localPath = __DIR__ . '/../../data/cssmin';
|
|
|
|
|
$remotePath = 'http://localhost/w';
|
2013-11-09 23:52:14 +00:00
|
|
|
|
|
|
|
|
$realOutput = CSSMin::remap( $input, $localPath, $remotePath );
|
2015-08-17 02:15:40 +00:00
|
|
|
$this->assertEquals( $expectedOutput, $realOutput, "CSSMin::remap: $message" );
|
2013-11-09 23:52:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static function provideRemapRemappingCases() {
|
|
|
|
|
// red.gif and green.gif are one-pixel 35-byte GIFs.
|
|
|
|
|
// large.png is a 35K PNG that should be non-embeddable.
|
|
|
|
|
// Full paths start with http://localhost/w/.
|
|
|
|
|
// Timestamps in output are replaced with 'timestamp'.
|
|
|
|
|
|
2014-09-17 21:14:46 +00:00
|
|
|
// data: URIs for red.gif, green.gif, circle.svg
|
2013-11-09 23:52:14 +00:00
|
|
|
$red = 'data:image/gif;base64,R0lGODlhAQABAIAAAP8AADAAACwAAAAAAQABAAACAkQBADs=';
|
|
|
|
|
$green = 'data:image/gif;base64,R0lGODlhAQABAIAAAACAADAAACwAAAAAAQABAAACAkQBADs=';
|
2018-01-09 03:05:40 +00:00
|
|
|
$svg = 'data:image/svg+xml,%3Csvg xmlns=%22http://www.w3.org/2000/svg%22 width=%228'
|
|
|
|
|
. '%22 height=%228%22 viewBox=%220 0 8 8%22%3E %3Ccircle cx=%224%22 cy=%224%22 '
|
|
|
|
|
. 'r=%222%22/%3E %3Ca xmlns:xlink=%22http://www.w3.org/1999/xlink%22 xlink:title='
|
|
|
|
|
. '%22%3F%3E%22%3Etest%3C/a%3E %3C/svg%3E';
|
2013-11-09 23:52:14 +00:00
|
|
|
|
2018-01-01 13:10:16 +00:00
|
|
|
// phpcs:disable Generic.Files.LineLength
|
2016-03-19 01:05:19 +00:00
|
|
|
return [
|
|
|
|
|
[
|
2013-11-09 23:52:14 +00:00
|
|
|
'Regular file',
|
|
|
|
|
'foo { background: url(red.gif); }',
|
2015-08-17 02:15:40 +00:00
|
|
|
'foo { background: url(http://localhost/w/red.gif?34ac6); }',
|
2016-03-19 01:05:19 +00:00
|
|
|
],
|
|
|
|
|
[
|
2013-12-11 20:21:36 +00:00
|
|
|
'Regular file (missing)',
|
|
|
|
|
'foo { background: url(theColorOfHerHair.gif); }',
|
|
|
|
|
'foo { background: url(http://localhost/w/theColorOfHerHair.gif); }',
|
2016-03-19 01:05:19 +00:00
|
|
|
],
|
|
|
|
|
[
|
2013-11-09 23:52:14 +00:00
|
|
|
'Remote URL',
|
|
|
|
|
'foo { background: url(http://example.org/w/foo.png); }',
|
|
|
|
|
'foo { background: url(http://example.org/w/foo.png); }',
|
2016-03-19 01:05:19 +00:00
|
|
|
],
|
|
|
|
|
[
|
2013-12-11 19:11:44 +00:00
|
|
|
'Protocol-relative remote URL',
|
|
|
|
|
'foo { background: url(//example.org/w/foo.png); }',
|
|
|
|
|
'foo { background: url(//example.org/w/foo.png); }',
|
2016-03-19 01:05:19 +00:00
|
|
|
],
|
|
|
|
|
[
|
2013-12-11 19:11:44 +00:00
|
|
|
'Remote URL with query',
|
|
|
|
|
'foo { background: url(http://example.org/w/foo.png?query=yes); }',
|
|
|
|
|
'foo { background: url(http://example.org/w/foo.png?query=yes); }',
|
2016-03-19 01:05:19 +00:00
|
|
|
],
|
|
|
|
|
[
|
2013-12-11 19:11:44 +00:00
|
|
|
'Protocol-relative remote URL with query',
|
|
|
|
|
'foo { background: url(//example.org/w/foo.png?query=yes); }',
|
|
|
|
|
'foo { background: url(//example.org/w/foo.png?query=yes); }',
|
2016-03-19 01:05:19 +00:00
|
|
|
],
|
|
|
|
|
[
|
2013-12-11 19:11:44 +00:00
|
|
|
'Domain-relative URL',
|
|
|
|
|
'foo { background: url(/static/foo.png); }',
|
|
|
|
|
'foo { background: url(http://doc.example.org/static/foo.png); }',
|
2016-03-19 01:05:19 +00:00
|
|
|
],
|
|
|
|
|
[
|
2013-12-11 19:11:44 +00:00
|
|
|
'Domain-relative URL with query',
|
|
|
|
|
'foo { background: url(/static/foo.png?query=yes); }',
|
|
|
|
|
'foo { background: url(http://doc.example.org/static/foo.png?query=yes); }',
|
2016-03-19 01:05:19 +00:00
|
|
|
],
|
|
|
|
|
[
|
2013-12-11 21:00:29 +00:00
|
|
|
'Remote URL (unnecessary quotes not preserved)',
|
2017-05-04 02:54:52 +00:00
|
|
|
'foo { background: url("http://example.org/w/unnecessary-quotes.png"); }',
|
|
|
|
|
'foo { background: url(http://example.org/w/unnecessary-quotes.png); }',
|
2016-03-19 01:05:19 +00:00
|
|
|
],
|
|
|
|
|
[
|
2013-11-09 23:52:14 +00:00
|
|
|
'Embedded file',
|
|
|
|
|
'foo { /* @embed */ background: url(red.gif); }',
|
2015-08-17 02:15:40 +00:00
|
|
|
"foo { background: url($red); background: url(http://localhost/w/red.gif?34ac6)!ie; }",
|
2016-03-19 01:05:19 +00:00
|
|
|
],
|
|
|
|
|
[
|
2014-09-20 21:26:13 +00:00
|
|
|
'Embedded file, other comments before the rule',
|
|
|
|
|
"foo { /* Bar. */ /* @embed */ background: url(red.gif); }",
|
2015-08-17 02:15:40 +00:00
|
|
|
"foo { /* Bar. */ background: url($red); /* Bar. */ background: url(http://localhost/w/red.gif?34ac6)!ie; }",
|
2016-03-19 01:05:19 +00:00
|
|
|
],
|
|
|
|
|
[
|
2014-06-05 16:38:41 +00:00
|
|
|
'Can not re-embed data: URIs',
|
|
|
|
|
"foo { /* @embed */ background: url($red); }",
|
|
|
|
|
"foo { background: url($red); }",
|
2016-03-19 01:05:19 +00:00
|
|
|
],
|
|
|
|
|
[
|
2014-06-05 16:38:41 +00:00
|
|
|
'Can not remap data: URIs',
|
|
|
|
|
"foo { background: url($red); }",
|
|
|
|
|
"foo { background: url($red); }",
|
2016-03-19 01:05:19 +00:00
|
|
|
],
|
|
|
|
|
[
|
2013-11-09 23:52:14 +00:00
|
|
|
'Can not embed remote URLs',
|
|
|
|
|
'foo { /* @embed */ background: url(http://example.org/w/foo.png); }',
|
2013-11-09 17:59:45 +00:00
|
|
|
'foo { background: url(http://example.org/w/foo.png); }',
|
2016-03-19 01:05:19 +00:00
|
|
|
],
|
|
|
|
|
[
|
2013-11-09 17:59:45 +00:00
|
|
|
'Embedded file (inline @embed)',
|
|
|
|
|
'foo { background: /* @embed */ url(red.gif); }',
|
2014-04-24 16:06:46 +00:00
|
|
|
"foo { background: url($red); "
|
2015-08-17 02:15:40 +00:00
|
|
|
. "background: url(http://localhost/w/red.gif?34ac6)!ie; }",
|
2016-03-19 01:05:19 +00:00
|
|
|
],
|
|
|
|
|
[
|
2013-11-09 23:52:14 +00:00
|
|
|
'Can not embed large files',
|
|
|
|
|
'foo { /* @embed */ background: url(large.png); }',
|
2015-08-17 02:15:40 +00:00
|
|
|
"foo { background: url(http://localhost/w/large.png?e3d1f); }",
|
2016-03-19 01:05:19 +00:00
|
|
|
],
|
|
|
|
|
[
|
2014-09-22 12:21:47 +00:00
|
|
|
'SVG files are embedded without base64 encoding and unnecessary IE 6 and 7 fallback',
|
2014-09-17 21:14:46 +00:00
|
|
|
'foo { /* @embed */ background: url(circle.svg); }',
|
2017-09-29 11:53:02 +00:00
|
|
|
"foo { background: url(\"$svg\"); }",
|
2016-03-19 01:05:19 +00:00
|
|
|
],
|
|
|
|
|
[
|
2013-11-09 17:59:45 +00:00
|
|
|
'Two regular files in one rule',
|
|
|
|
|
'foo { background: url(red.gif), url(green.gif); }',
|
2015-08-17 02:15:40 +00:00
|
|
|
'foo { background: url(http://localhost/w/red.gif?34ac6), '
|
|
|
|
|
. 'url(http://localhost/w/green.gif?13651); }',
|
2016-03-19 01:05:19 +00:00
|
|
|
],
|
|
|
|
|
[
|
2013-11-09 17:59:45 +00:00
|
|
|
'Two embedded files in one rule',
|
|
|
|
|
'foo { /* @embed */ background: url(red.gif), url(green.gif); }',
|
2014-04-24 16:06:46 +00:00
|
|
|
"foo { background: url($red), url($green); "
|
2015-08-17 02:15:40 +00:00
|
|
|
. "background: url(http://localhost/w/red.gif?34ac6), "
|
|
|
|
|
. "url(http://localhost/w/green.gif?13651)!ie; }",
|
2016-03-19 01:05:19 +00:00
|
|
|
],
|
|
|
|
|
[
|
2013-11-09 17:59:45 +00:00
|
|
|
'Two embedded files in one rule (inline @embed)',
|
|
|
|
|
'foo { background: /* @embed */ url(red.gif), /* @embed */ url(green.gif); }',
|
2014-04-24 16:06:46 +00:00
|
|
|
"foo { background: url($red), url($green); "
|
2015-08-17 02:15:40 +00:00
|
|
|
. "background: url(http://localhost/w/red.gif?34ac6), "
|
|
|
|
|
. "url(http://localhost/w/green.gif?13651)!ie; }",
|
2016-03-19 01:05:19 +00:00
|
|
|
],
|
|
|
|
|
[
|
2013-11-09 17:59:45 +00:00
|
|
|
'Two embedded files in one rule (inline @embed), one too large',
|
|
|
|
|
'foo { background: /* @embed */ url(red.gif), /* @embed */ url(large.png); }',
|
2015-08-17 02:15:40 +00:00
|
|
|
"foo { background: url($red), url(http://localhost/w/large.png?e3d1f); "
|
|
|
|
|
. "background: url(http://localhost/w/red.gif?34ac6), "
|
|
|
|
|
. "url(http://localhost/w/large.png?e3d1f)!ie; }",
|
2016-03-19 01:05:19 +00:00
|
|
|
],
|
|
|
|
|
[
|
2013-11-09 23:52:14 +00:00
|
|
|
'Practical example with some noise',
|
|
|
|
|
'foo { /* @embed */ background: #f9f9f9 url(red.gif) 0 0 no-repeat; }',
|
2014-04-24 16:06:46 +00:00
|
|
|
"foo { background: #f9f9f9 url($red) 0 0 no-repeat; "
|
2015-08-17 02:15:40 +00:00
|
|
|
. "background: #f9f9f9 url(http://localhost/w/red.gif?34ac6) 0 0 no-repeat!ie; }",
|
2016-03-19 01:05:19 +00:00
|
|
|
],
|
|
|
|
|
[
|
2013-11-09 23:52:14 +00:00
|
|
|
'Does not mess with other properties',
|
|
|
|
|
'foo { color: red; background: url(red.gif); font-size: small; }',
|
2015-08-17 02:15:40 +00:00
|
|
|
'foo { color: red; background: url(http://localhost/w/red.gif?34ac6); font-size: small; }',
|
2016-03-19 01:05:19 +00:00
|
|
|
],
|
|
|
|
|
[
|
2013-11-09 23:52:14 +00:00
|
|
|
'Spacing and miscellanea not changed (1)',
|
|
|
|
|
'foo { background: url(red.gif); }',
|
2015-08-17 02:15:40 +00:00
|
|
|
'foo { background: url(http://localhost/w/red.gif?34ac6); }',
|
2016-03-19 01:05:19 +00:00
|
|
|
],
|
|
|
|
|
[
|
2013-11-09 23:52:14 +00:00
|
|
|
'Spacing and miscellanea not changed (2)',
|
|
|
|
|
'foo {background:url(red.gif)}',
|
2015-08-17 02:15:40 +00:00
|
|
|
'foo {background:url(http://localhost/w/red.gif?34ac6)}',
|
2016-03-19 01:05:19 +00:00
|
|
|
],
|
|
|
|
|
[
|
2013-11-09 17:59:45 +00:00
|
|
|
'Spaces within url() parentheses are ignored',
|
|
|
|
|
'foo { background: url( red.gif ); }',
|
2015-08-17 02:15:40 +00:00
|
|
|
'foo { background: url(http://localhost/w/red.gif?34ac6); }',
|
2016-03-19 01:05:19 +00:00
|
|
|
],
|
|
|
|
|
[
|
2013-12-11 19:11:44 +00:00
|
|
|
'@import rule to local file (should we remap this?)',
|
|
|
|
|
'@import url(/styles.css)',
|
|
|
|
|
'@import url(http://doc.example.org/styles.css)',
|
2016-03-19 01:05:19 +00:00
|
|
|
],
|
|
|
|
|
[
|
2017-05-04 02:54:52 +00:00
|
|
|
'@import rule to local file (should we remap this?)',
|
|
|
|
|
'@import url(/styles.css)',
|
|
|
|
|
'@import url(http://doc.example.org/styles.css)',
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
'@import rule to URL',
|
|
|
|
|
'@import url(//localhost/styles.css?query=val)',
|
|
|
|
|
'@import url(//localhost/styles.css?query=val)',
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
'Background URL (double quotes)',
|
|
|
|
|
'foo { background: url("//localhost/styles.css?quoted=double") }',
|
|
|
|
|
'foo { background: url(//localhost/styles.css?quoted=double) }',
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
'Background URL (single quotes)',
|
|
|
|
|
'foo { background: url(\'//localhost/styles.css?quoted=single\') }',
|
|
|
|
|
'foo { background: url(//localhost/styles.css?quoted=single) }',
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
'Background URL (containing parentheses; T60473)',
|
|
|
|
|
'foo { background: url("//localhost/styles.css?query=(parens)") }',
|
2017-09-29 11:53:02 +00:00
|
|
|
'foo { background: url("//localhost/styles.css?query=(parens)") }',
|
2017-05-04 02:54:52 +00:00
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
'Background URL (double quoted, containing single quotes; T60473)',
|
|
|
|
|
'foo { background: url("//localhost/styles.css?quote=\'") }',
|
2017-09-29 11:53:02 +00:00
|
|
|
'foo { background: url("//localhost/styles.css?quote=\'") }',
|
2017-05-04 02:54:52 +00:00
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
'Background URL (single quoted, containing double quotes; T60473)',
|
|
|
|
|
'foo { background: url(\'//localhost/styles.css?quote="\') }',
|
2017-09-29 11:53:02 +00:00
|
|
|
'foo { background: url("//localhost/styles.css?quote=\"") }',
|
2016-03-19 01:05:19 +00:00
|
|
|
],
|
|
|
|
|
[
|
2014-06-12 21:55:33 +00:00
|
|
|
'Simple case with comments before url',
|
|
|
|
|
'foo { prop: /* some {funny;} comment */ url(bar.png); }',
|
|
|
|
|
'foo { prop: /* some {funny;} comment */ url(http://localhost/w/bar.png); }',
|
2016-03-19 01:05:19 +00:00
|
|
|
],
|
|
|
|
|
[
|
2014-06-12 21:55:33 +00:00
|
|
|
'Simple case with comments after url',
|
|
|
|
|
'foo { prop: url(red.gif)/* some {funny;} comment */ ; }',
|
2015-08-17 02:15:40 +00:00
|
|
|
'foo { prop: url(http://localhost/w/red.gif?34ac6)/* some {funny;} comment */ ; }',
|
2016-03-19 01:05:19 +00:00
|
|
|
],
|
|
|
|
|
[
|
2014-06-12 21:55:33 +00:00
|
|
|
'Embedded file with comment before url',
|
|
|
|
|
'foo { /* @embed */ background: /* some {funny;} comment */ url(red.gif); }',
|
2015-08-17 02:15:40 +00:00
|
|
|
"foo { background: /* some {funny;} comment */ url($red); background: /* some {funny;} comment */ url(http://localhost/w/red.gif?34ac6)!ie; }",
|
2016-03-19 01:05:19 +00:00
|
|
|
],
|
|
|
|
|
[
|
2014-06-12 21:55:33 +00:00
|
|
|
'Embedded file with comments inside and outside the rule',
|
|
|
|
|
'foo { /* @embed */ background: url(red.gif) /* some {foo;} comment */; /* some {bar;} comment */ }',
|
2015-08-17 02:15:40 +00:00
|
|
|
"foo { background: url($red) /* some {foo;} comment */; background: url(http://localhost/w/red.gif?34ac6) /* some {foo;} comment */!ie; /* some {bar;} comment */ }",
|
2016-03-19 01:05:19 +00:00
|
|
|
],
|
|
|
|
|
[
|
2014-06-12 21:55:33 +00:00
|
|
|
'Embedded file with comment outside the rule',
|
|
|
|
|
'foo { /* @embed */ background: url(red.gif); /* some {funny;} comment */ }',
|
2015-08-17 02:15:40 +00:00
|
|
|
"foo { background: url($red); background: url(http://localhost/w/red.gif?34ac6)!ie; /* some {funny;} comment */ }",
|
2016-03-19 01:05:19 +00:00
|
|
|
],
|
|
|
|
|
[
|
2014-06-12 21:55:33 +00:00
|
|
|
'Rule with two urls, each with comments',
|
|
|
|
|
'{ background: /*asd*/ url(something.png); background: /*jkl*/ url(something.png); }',
|
|
|
|
|
'{ background: /*asd*/ url(http://localhost/w/something.png); background: /*jkl*/ url(http://localhost/w/something.png); }',
|
2016-03-19 01:05:19 +00:00
|
|
|
],
|
|
|
|
|
[
|
2017-02-20 23:45:58 +00:00
|
|
|
'Sanity check for offending line from jquery.ui.theme.css (T62077)',
|
2014-06-12 21:55:33 +00:00
|
|
|
'.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}*/; }',
|
|
|
|
|
'.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}*/; }',
|
2016-03-19 01:05:19 +00:00
|
|
|
],
|
|
|
|
|
];
|
2018-01-01 13:10:16 +00:00
|
|
|
// phpcs:enable
|
2013-11-09 23:52:14 +00:00
|
|
|
}
|
|
|
|
|
|
2013-12-11 21:00:29 +00:00
|
|
|
/**
|
|
|
|
|
* This tests basic functionality of CSSMin::buildUrlValue.
|
|
|
|
|
*
|
|
|
|
|
* @dataProvider provideBuildUrlValueCases
|
|
|
|
|
* @covers CSSMin::buildUrlValue
|
|
|
|
|
*/
|
|
|
|
|
public function testBuildUrlValue( $message, $input, $expectedOutput ) {
|
|
|
|
|
$this->assertEquals(
|
|
|
|
|
$expectedOutput,
|
|
|
|
|
CSSMin::buildUrlValue( $input ),
|
|
|
|
|
"CSSMin::buildUrlValue: $message"
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static function provideBuildUrlValueCases() {
|
2016-02-17 09:09:32 +00:00
|
|
|
return [
|
|
|
|
|
[
|
2013-12-11 21:00:29 +00:00
|
|
|
'Full URL',
|
|
|
|
|
'scheme://user@domain:port/~user/fi%20le.png?query=yes&really=y+s',
|
|
|
|
|
'url(scheme://user@domain:port/~user/fi%20le.png?query=yes&really=y+s)',
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
[
|
2013-12-11 21:00:29 +00:00
|
|
|
'data: URI',
|
|
|
|
|
'data:image/png;base64,R0lGODlh/+==',
|
|
|
|
|
'url(data:image/png;base64,R0lGODlh/+==)',
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
[
|
2017-09-29 11:53:02 +00:00
|
|
|
'URL with quotes',
|
2013-12-11 21:00:29 +00:00
|
|
|
"https://en.wikipedia.org/wiki/Wendy's",
|
2017-09-29 11:53:02 +00:00
|
|
|
"url(\"https://en.wikipedia.org/wiki/Wendy's\")",
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
[
|
2013-12-11 21:00:29 +00:00
|
|
|
'URL with parentheses',
|
|
|
|
|
'https://en.wikipedia.org/wiki/Boston_(band)',
|
2017-09-29 11:53:02 +00:00
|
|
|
'url("https://en.wikipedia.org/wiki/Boston_(band)")',
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
];
|
2013-12-11 21:00:29 +00:00
|
|
|
}
|
|
|
|
|
|
2012-06-20 03:13:52 +00:00
|
|
|
/**
|
2017-02-20 23:45:58 +00:00
|
|
|
* Seperated because they are currently broken (T37492)
|
2012-06-20 03:13:52 +00:00
|
|
|
*
|
|
|
|
|
* @group Broken
|
|
|
|
|
* @dataProvider provideStringCases
|
2013-10-24 16:45:52 +00:00
|
|
|
* @covers CSSMin::remap
|
2012-06-20 03:13:52 +00:00
|
|
|
*/
|
2013-10-23 22:51:31 +00:00
|
|
|
public function testMinifyWithCSSStringValues( $code, $expectedOutput ) {
|
2012-06-20 03:13:52 +00:00
|
|
|
$this->testMinifyOutput( $code, $expectedOutput );
|
|
|
|
|
}
|
|
|
|
|
|
2013-03-22 02:12:37 +00:00
|
|
|
public static function provideStringCases() {
|
2016-02-17 09:09:32 +00:00
|
|
|
return [
|
2012-06-20 03:13:52 +00:00
|
|
|
// String values should be respected
|
|
|
|
|
// - More than one space in a string value
|
2016-02-17 09:09:32 +00:00
|
|
|
[ 'foo { content: " "; }', 'foo{content:" "}' ],
|
2012-06-20 03:13:52 +00:00
|
|
|
// - Using a tab in a string value (turns into a space)
|
2016-02-17 09:09:32 +00:00
|
|
|
[ "foo { content: '\t'; }", "foo{content:'\t'}" ],
|
2012-06-20 03:13:52 +00:00
|
|
|
// - Using css-like syntax in string values
|
2016-02-17 09:09:32 +00:00
|
|
|
[
|
2014-04-24 16:06:46 +00:00
|
|
|
'foo::after { content: "{;}"; position: absolute; }',
|
|
|
|
|
'foo::after{content:"{;}";position:absolute}'
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
];
|
2012-06-20 03:13:52 +00:00
|
|
|
}
|
|
|
|
|
}
|
2016-02-10 18:37:07 +00:00
|
|
|
|
|
|
|
|
class CSSMinTestable extends CSSMin {
|
|
|
|
|
// Make some protected methods public
|
|
|
|
|
public static function isRemoteUrl( $maybeUrl ) {
|
|
|
|
|
return parent::isRemoteUrl( $maybeUrl );
|
|
|
|
|
}
|
|
|
|
|
public static function isLocalUrl( $maybeUrl ) {
|
|
|
|
|
return parent::isLocalUrl( $maybeUrl );
|
|
|
|
|
}
|
|
|
|
|
}
|