From: Timo Tijhof Date: Wed, 18 Jan 2017 05:58:46 +0000 (+0000) Subject: tests: Add unit tests for OutputPage::transformResourcePath X-Git-Tag: 1.31.0-rc.0~4298^2 X-Git-Url: https://git.cyclocoop.org/%7B%24www_url%7Dadmin/compta/banques/?a=commitdiff_plain;h=a9d14289d71c71546bf48a039b238b4780445c86;p=lhc%2Fweb%2Fwiklou.git tests: Add unit tests for OutputPage::transformResourcePath Bug: T155310 Change-Id: Ic5a4af705c3734a7992037e59dc43fafe447ba12 --- diff --git a/tests/phpunit/includes/OutputPageTest.php b/tests/phpunit/includes/OutputPageTest.php index c3faf0d0ba..f0c8f7abc8 100644 --- a/tests/phpunit/includes/OutputPageTest.php +++ b/tests/phpunit/includes/OutputPageTest.php @@ -135,6 +135,42 @@ class OutputPageTest extends MediaWikiTestCase { ] ); } + public static function provideTransformFilePath() { + $baseDir = dirname( __DIR__ ) . '/data/media'; + return [ + // File that matches basePath, and exists. Hash found and appended. + [ 'baseDir' => $baseDir, 'basePath' => '/w', '/w/test.jpg', '/w/test.jpg?edcf2' ], + // File that matches basePath, but not found on disk. Empty query. + [ 'baseDir' => $baseDir, 'basePath' => '/w', '/w/unknown.png', '/w/unknown.png?' ], + // File not matching basePath. Ignored. + [ 'baseDir' => $baseDir, 'basePath' => '/w', '/files/test.jpg' ], + // Empty string. Ignored. + [ 'baseDir' => $baseDir, 'basePath' => '/w', '', '' ], + // Similar path, but with domain component. Ignored. + [ 'baseDir' => $baseDir, 'basePath' => '/w', '//example.org/w/test.jpg' ], + [ 'baseDir' => $baseDir, 'basePath' => '/w', 'https://example.org/w/test.jpg' ], + // Unrelated path with domain component. Ignored. + [ 'baseDir' => $baseDir, 'basePath' => '/w', 'https://example.org/files/test.jpg' ], + [ 'baseDir' => $baseDir, 'basePath' => '/w', '//example.org/files/test.jpg' ], + ]; + } + + /** + * @dataProvider provideTransformFilePath + * @covers OutputPage::transformFilePath + * @covers OutputPage::transformResourcePath + */ + public function testTransformResourcePath( $baseDir, $basePath, $path, $expected = null ) { + $this->setMwGlobals( 'IP', $baseDir ); + $conf = new HashConfig( [ 'ResourceBasePath' => $basePath ] ); + + MediaWiki\suppressWarnings(); + $actual = OutputPage::transformResourcePath( $conf, $path ); + MediaWiki\restoreWarnings(); + + $this->assertEquals( $expected ?: $path, $actual ); + } + public static function provideMakeResourceLoaderLink() { // @codingStandardsIgnoreStart Generic.Files.LineLength return [ @@ -287,7 +323,7 @@ class OutputPageTest extends MediaWikiTestCase { /** * @covers OutputPage::haveCacheVaryCookies */ - function testHaveCacheVaryCookies() { + public function testHaveCacheVaryCookies() { $request = new FauxRequest(); $context = new RequestContext(); $context->setRequest( $request ); @@ -309,7 +345,7 @@ class OutputPageTest extends MediaWikiTestCase { * @covers OutputPage::addCategoryLinks * @covers OutputPage::getCategories */ - function testGetCategories() { + public function testGetCategories() { $fakeResultWrapper = new FakeResultWrapper( [ (object) [ 'pp_value' => 1,