X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=tests%2Fphpunit%2Fincludes%2Fresourceloader%2FResourceLoaderModuleTest.php;h=7c7f1cf5c403f8f85312b28ecb8314b2440c196d;hb=a0947c9507065a83afe52b078f0f6d1c6163875e;hp=17861d8929be995b26edea61cdc8d8092aa9dea9;hpb=c6b1dede111e00d8993c4177c9678d17d035e5ed;p=lhc%2Fweb%2Fwiklou.git diff --git a/tests/phpunit/includes/resourceloader/ResourceLoaderModuleTest.php b/tests/phpunit/includes/resourceloader/ResourceLoaderModuleTest.php index 17861d8929..7c7f1cf5c4 100644 --- a/tests/phpunit/includes/resourceloader/ResourceLoaderModuleTest.php +++ b/tests/phpunit/includes/resourceloader/ResourceLoaderModuleTest.php @@ -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: ;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: ;rel=preload;as=script,' . + ';rel=preload;as=image' + ], + $module->getHeaders( $context ), + 'Preload two resources' + ); + } }