Skin: Make skins aware of their registered skin name
[lhc/web/wiklou.git] / tests / phpunit / includes / resourceloader / ResourceLoaderModuleTest.php
index 17861d8..7c7f1cf 100644 (file)
@@ -94,6 +94,56 @@ class ResourceLoaderModuleTest extends ResourceLoaderTestCase {
                );
        }
 
+       public static function provideBuildContentScripts() {
+               return [
+                       [
+                               "mw.foo()",
+                               "mw.foo()\n",
+                       ],
+                       [
+                               "mw.foo();",
+                               "mw.foo();\n",
+                       ],
+                       [
+                               "mw.foo();\n",
+                               "mw.foo();\n",
+                       ],
+                       [
+                               "mw.foo()\n",
+                               "mw.foo()\n",
+                       ],
+                       [
+                               "mw.foo()\n// mw.bar();",
+                               "mw.foo()\n// mw.bar();\n",
+                       ],
+                       [
+                               "mw.foo()\n// mw.bar()",
+                               "mw.foo()\n// mw.bar()\n",
+                       ],
+                       [
+                               "mw.foo()// mw.bar();",
+                               "mw.foo()// mw.bar();\n",
+                       ],
+               ];
+       }
+
+       /**
+        * @dataProvider provideBuildContentScripts
+        * @covers ResourceLoaderModule::buildContent
+        */
+       public function testBuildContentScripts( $raw, $build, $message = null ) {
+               $context = $this->getResourceLoaderContext();
+               $module = new ResourceLoaderTestModule( [
+                       'script' => $raw
+               ] );
+               $this->assertEquals( $raw, $module->getScript( $context ), 'Raw script' );
+               $this->assertEquals(
+                       [ 'scripts' => $build ],
+                       $module->getModuleContent( $context ),
+                       $message
+               );
+       }
+
        /**
         * @covers ResourceLoaderModule::getRelativePaths
         * @covers ResourceLoaderModule::expandRelativePaths
@@ -130,4 +180,43 @@ class ResourceLoaderModuleTest extends ResourceLoaderTestCase {
                        'Substitute placeholders'
                );
        }
+
+       /**
+        * @covers ResourceLoaderModule::getHeaders
+        * @covers ResourceLoaderModule::getPreloadLinks
+        */
+       public function testGetHeaders() {
+               $context = $this->getResourceLoaderContext();
+
+               $module = new ResourceLoaderTestModule();
+               $this->assertSame( [], $module->getHeaders( $context ), 'Default' );
+
+               $module = $this->getMockBuilder( ResourceLoaderTestModule::class )
+                       ->setMethods( [ 'getPreloadLinks' ] )->getMock();
+               $module->method( 'getPreloadLinks' )->willReturn( [
+                        'https://example.org/script.js' => [ 'as' => 'script' ],
+               ] );
+               $this->assertSame(
+                       [
+                               'Link: <https://example.org/script.js>;rel=preload;as=script'
+                       ],
+                       $module->getHeaders( $context ),
+                       'Preload one resource'
+               );
+
+               $module = $this->getMockBuilder( ResourceLoaderTestModule::class )
+                       ->setMethods( [ 'getPreloadLinks' ] )->getMock();
+               $module->method( 'getPreloadLinks' )->willReturn( [
+                        'https://example.org/script.js' => [ 'as' => 'script' ],
+                        '/example.png' => [ 'as' => 'image' ],
+               ] );
+               $this->assertSame(
+                       [
+                               'Link: <https://example.org/script.js>;rel=preload;as=script,' .
+                                       '</example.png>;rel=preload;as=image'
+                       ],
+                       $module->getHeaders( $context ),
+                       'Preload two resources'
+               );
+       }
 }