<?php
-/**
- * This file test the CSSMin library shipped with Mediawiki.
- *
- * @author Timo Tijhof
- */
+
+use Wikimedia\TestingAccessWrapper;
/**
* @group ResourceLoader
protected function setUp() {
parent::setUp();
- $server = 'http://doc.example.org';
-
+ // For wfExpandUrl
+ $server = 'https://expand.example';
$this->setMwGlobals( [
'wgServer' => $server,
'wgCanonicalServer' => $server,
}
/**
- * @dataProvider serializeStringValueProvider
+ * @dataProvider provideSerializeStringValue
* @covers CSSMin::serializeStringValue
*/
public function testSerializeStringValue( $input, $expected ) {
);
}
- public function serializeStringValueProvider() {
+ public static function provideSerializeStringValue() {
return [
[ 'Hello World!', '"Hello World!"' ],
- [ "Null\0Null", "\"Null\\fffd Null\"" ],
+ [ "Null\0Null", "\"Null\xEF\xBF\xBDNull\"" ],
[ '"', '"\\""' ],
[ "'", '"\'"' ],
[ "\\", '"\\\\"' ],
}
/**
- * @dataProvider mimeTypeProvider
+ * @dataProvider provideMimeType
* @covers CSSMin::getMimeType
*/
public function testGetMimeType( $fileContents, $fileExtension, $expected ) {
$this->assertSame( $expected, CSSMin::getMimeType( $fileName ) );
}
- public function mimeTypeProvider() {
+ public static function provideMimeType() {
return [
'JPEG with short extension' => [
"\xFF\xD8\xFF",
[ true, '//example.org/x.y.z/image.png' ],
[ true, '//localhost/styles.css?query=yes' ],
[ true, 'data:image/gif;base64,R0lGODlhAQABAIAAAP8AADAAACwAAAAAAQABAAACAkQBADs=' ],
+ [ false, '' ],
+ [ false, '/' ],
+ [ true, '//' ],
[ false, 'x.gif' ],
[ false, '/x.gif' ],
[ false, './x.gif' ],
* @covers CSSMin::isRemoteUrl
*/
public function testIsRemoteUrl( $expect, $url ) {
- $this->assertEquals( CSSMinTestable::isRemoteUrl( $url ), $expect );
+ $class = TestingAccessWrapper::newFromClass( CSSMin::class );
+ $this->assertEquals( $class->isRemoteUrl( $url ), $expect );
}
public static function provideIsLocalUrls() {
return [
+ [ false, '' ],
+ [ false, '/' ],
+ [ false, '//' ],
[ false, 'x.gif' ],
[ true, '/x.gif' ],
[ false, './x.gif' ],
* @covers CSSMin::isLocalUrl
*/
public function testIsLocalUrl( $expect, $url ) {
- $this->assertEquals( CSSMinTestable::isLocalUrl( $url ), $expect );
+ $class = TestingAccessWrapper::newFromClass( CSSMin::class );
+ $this->assertEquals( $class->isLocalUrl( $url ), $expect );
}
/**
[
'Expand absolute paths',
[ 'foo { prop: url(/w/skin/images/bar.png); }', false, 'http://example.org/quux', false ],
- 'foo { prop: url(http://doc.example.org/w/skin/images/bar.png); }',
+ 'foo { prop: url(https://expand.example/w/skin/images/bar.png); }',
],
[
"Don't barf at behavior: url(#default#behaviorName) - T162973",
[ 'background-image: url("");', false, '/example', false ],
'background-image: url("");',
],
+ 'Single quote with outer spacing' => [
+ [ "background-image: url( '' );", false, '/example', false ],
+ "background-image: url( '' );",
+ ],
];
}
[
'Domain-relative URL',
'foo { background: url(/static/foo.png); }',
- 'foo { background: url(http://doc.example.org/static/foo.png); }',
+ 'foo { background: url(https://expand.example/static/foo.png); }',
],
[
'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); }',
+ 'foo { background: url(https://expand.example/static/foo.png?query=yes); }',
+ ],
+ [
+ 'Path-relative URL with query',
+ "foo { background: url(?query=yes); }",
+ 'foo { background: url(http://localhost/w/?query=yes); }',
],
[
'Remote URL (unnecessary quotes not preserved)',
[
'@import rule to local file (should we remap this?)',
'@import url(/styles.css)',
- '@import url(http://doc.example.org/styles.css)',
+ '@import url(https://expand.example/styles.css)',
],
[
'@import rule to local file (should we remap this?)',
'@import url(/styles.css)',
- '@import url(http://doc.example.org/styles.css)',
+ '@import url(https://expand.example/styles.css)',
],
[
'@import rule to URL',
'foo { background: url(//localhost/styles.css?quoted=single) }',
],
[
- 'Background URL (containing parentheses; T60473)',
+ 'Background URL (double quoted, containing parentheses; T60473)',
'foo { background: url("//localhost/styles.css?query=(parens)") }',
'foo { background: url("//localhost/styles.css?query=(parens)") }',
],
'foo { background: url(\'//localhost/styles.css?quote="\') }',
'foo { background: url("//localhost/styles.css?quote=\"") }',
],
+ [
+ 'Background URL (double quoted with outer spacing)',
+ 'foo { background: url( "http://localhost/styles.css?quoted=double" ) }',
+ 'foo { background: url(http://localhost/styles.css?quoted=double) }',
+ ],
+ [
+ 'Background URL (single quoted, containing spaces, with outer spacing)',
+ "foo { background: url( ' red.gif ' ); }",
+ 'foo { background: url("http://localhost/w/ red.gif "); }',
+ ],
[
'Simple case with comments before url',
'foo { prop: /* some {funny;} comment */ url(bar.png); }',
];
}
}
-
-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 );
- }
-}