* @covers ResourceLoaderModule::expandRelativePaths
*/
public function testPlaceholderize() {
- $getRelativePaths = new ReflectionMethod( 'ResourceLoaderModule', 'getRelativePaths' );
+ $getRelativePaths = new ReflectionMethod( ResourceLoaderModule::class, 'getRelativePaths' );
$getRelativePaths->setAccessible( true );
- $expandRelativePaths = new ReflectionMethod( 'ResourceLoaderModule', 'expandRelativePaths' );
+ $expandRelativePaths = new ReflectionMethod( ResourceLoaderModule::class, 'expandRelativePaths' );
$expandRelativePaths->setAccessible( true );
$this->setMwGlobals( [
'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'
+ );
+ }
}