Merge "Type hint against LinkTarget in WatchedItemStore"
[lhc/web/wiklou.git] / tests / phpunit / includes / resourceloader / ResourceLoaderImageModuleTest.php
index e5b338e..dad9f1e 100644 (file)
@@ -59,7 +59,7 @@ class ResourceLoaderImageModuleTest extends ResourceLoaderTestCase {
                return [
                        [
                                [
-                                       'class' => 'ResourceLoaderImageModule',
+                                       'class' => ResourceLoaderImageModule::class,
                                        'prefix' => 'oo-ui-icon',
                                        'variants' => self::$commonImageVariants,
                                        'images' => self::$commonImageData,
@@ -100,7 +100,7 @@ class ResourceLoaderImageModuleTest extends ResourceLoaderTestCase {
                        ],
                        [
                                [
-                                       'class' => 'ResourceLoaderImageModule',
+                                       'class' => ResourceLoaderImageModule::class,
                                        'selectorWithoutVariant' => '.mw-ui-icon-{name}:after, .mw-ui-icon-{name}:before',
                                        'selectorWithVariant' =>
                                                '.mw-ui-icon-{name}-{variant}:after, .mw-ui-icon-{name}-{variant}:before',
@@ -144,6 +144,55 @@ class ResourceLoaderImageModuleTest extends ResourceLoaderTestCase {
                ];
        }
 
+       /**
+        * Test reading files from elsewhere than localBasePath using ResourceLoaderFilePath.
+        *
+        * This mimics modules modified by skins using 'ResourceModuleSkinStyles' and 'OOUIThemePaths'
+        * skin attributes.
+        *
+        * @covers ResourceLoaderFilePath::getLocalBasePath
+        * @covers ResourceLoaderFilePath::getRemoteBasePath
+        */
+       public function testResourceLoaderFilePath() {
+               $basePath = __DIR__ . '/../../data/blahblah';
+               $filePath = __DIR__ . '/../../data/rlfilepath';
+               $testModule = new ResourceLoaderImageModule( [
+                       'localBasePath' => $basePath,
+                       'remoteBasePath' => 'blahblah',
+                       'prefix' => 'foo',
+                       'images' => [
+                               'eye' => new ResourceLoaderFilePath( 'eye.svg', $filePath, 'rlfilepath' ),
+                               'flag' => [
+                                       'file' => [
+                                               'ltr' => new ResourceLoaderFilePath( 'flag-ltr.svg', $filePath, 'rlfilepath' ),
+                                               'rtl' => new ResourceLoaderFilePath( 'flag-rtl.svg', $filePath, 'rlfilepath' ),
+                                       ],
+                               ],
+                       ],
+               ] );
+               $expectedModule = new ResourceLoaderImageModule( [
+                       'localBasePath' => $filePath,
+                       'remoteBasePath' => 'rlfilepath',
+                       'prefix' => 'foo',
+                       'images' => [
+                               'eye' => 'eye.svg',
+                               'flag' => [
+                                       'file' => [
+                                               'ltr' => 'flag-ltr.svg',
+                                               'rtl' => 'flag-rtl.svg',
+                                       ],
+                               ],
+                       ],
+               ] );
+
+               $context = $this->getResourceLoaderContext();
+               $this->assertEquals(
+                       $expectedModule->getModuleContent( $context ),
+                       $testModule->getModuleContent( $context ),
+                       "Using ResourceLoaderFilePath works correctly"
+               );
+       }
+
        /**
         * @dataProvider providerGetModules
         * @covers ResourceLoaderImageModule::getStyles
@@ -239,7 +288,7 @@ TEXT
        }
 
        private function getImageMock( ResourceLoaderContext $context, $dataUriReturnValue ) {
-               $image = $this->getMockBuilder( 'ResourceLoaderImage' )
+               $image = $this->getMockBuilder( ResourceLoaderImage::class )
                        ->disableOriginalConstructor()
                        ->getMock();
                $image->method( 'getDataUri' )