Merge "Revert "ApiSandbox: Display params as JSON on request page""
[lhc/web/wiklou.git] / tests / phpunit / includes / OutputPageTest.php
index 6269872..0e83006 100644 (file)
@@ -7,7 +7,6 @@
  * @group Output
  *
  * @todo factor tests in this class into providers and test methods
- *
  */
 class OutputPageTest extends MediaWikiTestCase {
        const SCREEN_MEDIA_QUERY = 'screen and (min-width: 982px)';
@@ -136,6 +135,45 @@ 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' ],
+                       // Unrelated path with domain, and empty base path (root mw install). Ignored.
+                       [ 'baseDir' => $baseDir, 'basePath' => '', 'https://example.org/files/test.jpg' ],
+                       [ 'baseDir' => $baseDir, 'basePath' => '', '//example.org/files/test.jpg' ], // T155310
+               ];
+       }
+
+       /**
+        * @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 [
@@ -288,7 +326,7 @@ class OutputPageTest extends MediaWikiTestCase {
        /**
         * @covers OutputPage::haveCacheVaryCookies
         */
-       function testHaveCacheVaryCookies() {
+       public function testHaveCacheVaryCookies() {
                $request = new FauxRequest();
                $context = new RequestContext();
                $context->setRequest( $request );
@@ -310,7 +348,7 @@ class OutputPageTest extends MediaWikiTestCase {
         * @covers OutputPage::addCategoryLinks
         * @covers OutputPage::getCategories
         */
-       function testGetCategories() {
+       public function testGetCategories() {
                $fakeResultWrapper = new FakeResultWrapper( [
                        (object) [
                                'pp_value' => 1,