From cb2ab955f118cadaed2b955a1ce23f1250ae8327 Mon Sep 17 00:00:00 2001 From: Timo Tijhof Date: Mon, 16 Apr 2018 23:05:46 +0100 Subject: [PATCH] resourceloader: Clean up CSSMinTest * Consistently name data providers as "provide.." and make them static. * Document why wgServer is being mocked. * Use TestingAccessWrapper instead of ad-hoc sub class for accessing protected methods. Change-Id: Ife2d98091200bbc8fb16b7ac6eafd3f2c22c1463 --- tests/phpunit/includes/libs/CSSMinTest.php | 45 ++++++++-------------- 1 file changed, 17 insertions(+), 28 deletions(-) diff --git a/tests/phpunit/includes/libs/CSSMinTest.php b/tests/phpunit/includes/libs/CSSMinTest.php index 59a1c7c9b7..02b3549a62 100644 --- a/tests/phpunit/includes/libs/CSSMinTest.php +++ b/tests/phpunit/includes/libs/CSSMinTest.php @@ -1,9 +1,6 @@ setMwGlobals( [ 'wgServer' => $server, 'wgCanonicalServer' => $server, @@ -23,7 +20,7 @@ class CSSMinTest extends MediaWikiTestCase { } /** - * @dataProvider serializeStringValueProvider + * @dataProvider provideSerializeStringValue * @covers CSSMin::serializeStringValue */ public function testSerializeStringValue( $input, $expected ) { @@ -35,7 +32,7 @@ class CSSMinTest extends MediaWikiTestCase { ); } - public function serializeStringValueProvider() { + public static function provideSerializeStringValue() { return [ [ 'Hello World!', '"Hello World!"' ], [ "Null\0Null", "\"Null\\fffd Null\"" ], @@ -60,7 +57,7 @@ class CSSMinTest extends MediaWikiTestCase { } /** - * @dataProvider mimeTypeProvider + * @dataProvider provideMimeType * @covers CSSMin::getMimeType */ public function testGetMimeType( $fileContents, $fileExtension, $expected ) { @@ -71,7 +68,7 @@ class CSSMinTest extends MediaWikiTestCase { $this->assertSame( $expected, CSSMin::getMimeType( $fileName ) ); } - public function mimeTypeProvider() { + public static function provideMimeType() { return [ 'JPEG with short extension' => [ "\xFF\xD8\xFF", @@ -214,7 +211,8 @@ class CSSMinTest extends MediaWikiTestCase { * @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() { @@ -231,7 +229,8 @@ class CSSMinTest extends MediaWikiTestCase { * @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 ); } /** @@ -280,7 +279,7 @@ class CSSMinTest extends MediaWikiTestCase { [ '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", @@ -384,12 +383,12 @@ class CSSMinTest extends MediaWikiTestCase { [ '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); }', ], [ 'Remote URL (unnecessary quotes not preserved)', @@ -493,12 +492,12 @@ class CSSMinTest extends MediaWikiTestCase { [ '@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', @@ -634,13 +633,3 @@ class CSSMinTest extends MediaWikiTestCase { ]; } } - -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 ); - } -} -- 2.20.1