From 9a2e47d1885f0fe73f351e5f006ce4e22fd7634b Mon Sep 17 00:00:00 2001 From: Timo Tijhof Date: Mon, 26 Jan 2015 15:07:15 -0800 Subject: [PATCH] CSSMin: Add tests for isRemoteUrl and isLocalUrl Change-Id: I5a84eb62eaac96d0dd7f7e27bf76f64e7d7657cf --- tests/phpunit/includes/libs/CSSMinTest.php | 39 ++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/tests/phpunit/includes/libs/CSSMinTest.php b/tests/phpunit/includes/libs/CSSMinTest.php index 6fa3acf81f..6142f9675b 100644 --- a/tests/phpunit/includes/libs/CSSMinTest.php +++ b/tests/phpunit/includes/libs/CSSMinTest.php @@ -141,6 +141,45 @@ class CSSMinTest extends MediaWikiTestCase { ); } + public static function provideIsRemoteUrl() { + return array( + array( true, 'http://localhost/w/red.gif?123' ), + array( true, 'https://example.org/x.png' ), + array( true, '//example.org/x.y.z/image.png' ), + array( true, '//localhost/styles.css?query=yes' ), + array( true, 'data:image/gif;base64,R0lGODlhAQABAIAAAP8AADAAACwAAAAAAQABAAACAkQBADs=' ), + array( false, 'x.gif' ), + array( false, '/x.gif' ), + array( false, './x.gif' ), + array( false, '../x.gif' ), + ); + } + + /** + * @dataProvider provideIsRemoteUrl + * @cover CSSMin::isRemoteUrl + */ + public function testIsRemoteUrl( $expect, $url ) { + $this->assertEquals( CSSMin::isRemoteUrl( $url ), $expect ); + } + + public static function provideIsLocalUrls() { + return array( + array( false, 'x.gif' ), + array( true, '/x.gif' ), + array( false, './x.gif' ), + array( false, '../x.gif' ), + ); + } + + /** + * @dataProvider provideIsLocalUrls + * @cover CSSMin::isLocalUrl + */ + public function testIsLocalUrl( $expect, $url ) { + $this->assertEquals( CSSMin::isLocalUrl( $url ), $expect ); + } + 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. -- 2.20.1