X-Git-Url: https://git.cyclocoop.org/%7B%24admin_url%7Dmembres/modifier.php?a=blobdiff_plain;f=tests%2Fphpunit%2Fincludes%2Fresourceloader%2FResourceLoaderSkinModuleTest.php;h=23b0cb911b9995248a996a750758e22adee809d1;hb=e9044fe58dc46551a6eb630ed8f9ac97a12e075b;hp=61ab8a521d288530e226dde6dd3ac74bf907b3b2;hpb=e85682ed109e13432f8ee376e16eb89325f05373;p=lhc%2Fweb%2Fwiklou.git diff --git a/tests/phpunit/includes/resourceloader/ResourceLoaderSkinModuleTest.php b/tests/phpunit/includes/resourceloader/ResourceLoaderSkinModuleTest.php index 61ab8a521d..23b0cb911b 100644 --- a/tests/phpunit/includes/resourceloader/ResourceLoaderSkinModuleTest.php +++ b/tests/phpunit/includes/resourceloader/ResourceLoaderSkinModuleTest.php @@ -1,11 +1,11 @@ setMwGlobals( 'IP', $baseDir ); } + // Allow testing of protected method + $module = TestingAccessWrapper::newFromObject( new ResourceLoaderSkinModule() ); $this->assertEquals( $expected, - ResourceLoaderSkinModule::getLogo( new HashConfig( $config ) ) + $module->getLogoData( new HashConfig( $config ) ) ); } - public function provideGetLogo() { + public function provideGetLogoData() { return [ 'simple' => [ 'config' => [ @@ -203,4 +201,80 @@ CSS ], ]; } + + /** + * @dataProvider providePreloadLinks + * @covers ResourceLoaderSkinModule::getPreloadLinks + * @covers ResourceLoaderSkinModule::getLogoPreloadlinks + * @covers ResourceLoaderSkinModule::getLogoData + */ + public function testPreloadLinkHeaders( $config, $result ) { + $this->setMwGlobals( $config ); + $ctx = $this->getMockBuilder( ResourceLoaderContext::class ) + ->disableOriginalConstructor()->getMock(); + $module = new ResourceLoaderSkinModule(); + + $this->assertEquals( [ $result ], $module->getHeaders( $ctx ) ); + } + + public function providePreloadLinks() { + return [ + [ + [ + 'wgResourceBasePath' => '/w', + 'wgLogo' => '/img/default.png', + 'wgLogoHD' => [ + '1.5x' => '/img/one-point-five.png', + '2x' => '/img/two-x.png', + ], + ], + 'Link: ;rel=preload;as=image;media=' . + 'not all and (min-resolution: 1.5dppx),' . + ';rel=preload;as=image;media=' . + '(min-resolution: 1.5dppx) and (max-resolution: 1.999999dppx),' . + ';rel=preload;as=image;media=(min-resolution: 2dppx)' + ], + [ + [ + 'wgResourceBasePath' => '/w', + 'wgLogo' => '/img/default.png', + 'wgLogoHD' => false, + ], + 'Link: ;rel=preload;as=image' + ], + [ + [ + 'wgResourceBasePath' => '/w', + 'wgLogo' => '/img/default.png', + 'wgLogoHD' => [ + '2x' => '/img/two-x.png', + ], + ], + 'Link: ;rel=preload;as=image;media=' . + 'not all and (min-resolution: 2dppx),' . + ';rel=preload;as=image;media=(min-resolution: 2dppx)' + ], + [ + [ + 'wgResourceBasePath' => '/w', + 'wgLogo' => '/img/default.png', + 'wgLogoHD' => [ + 'svg' => '/img/vector.svg', + ], + ], + 'Link: ;rel=preload;as=image' + + ], + [ + [ + 'wgResourceBasePath' => '/w', + 'wgLogo' => '/w/test.jpg', + 'wgLogoHD' => false, + 'wgUploadPath' => '/w/images', + 'IP' => dirname( dirname( __DIR__ ) ) . '/data/media', + ], + 'Link: ;rel=preload;as=image', + ], + ]; + } }