From 3ff2615992ffb02a35931e4f19c09a602da689e0 Mon Sep 17 00:00:00 2001 From: Timo Tijhof Date: Tue, 21 Aug 2018 00:58:41 +0100 Subject: [PATCH] resourceloader: Remove unused static SkinModule::getLogo method This existed for internal use by OutputPage, which is no longer the case as of I11b390f2e4f5e7db. Also move the unit tests from OutputPageTest, to ResourceLoaderSkinModuleTest. Change-Id: I8b23f976f5f89b1005b387a827f75031f5c96141 --- .../ResourceLoaderSkinModule.php | 13 +-- tests/phpunit/includes/OutputPageTest.php | 76 -------------- .../ResourceLoaderSkinModuleTest.php | 98 ++++++++++++++++--- 3 files changed, 88 insertions(+), 99 deletions(-) diff --git a/includes/resourceloader/ResourceLoaderSkinModule.php b/includes/resourceloader/ResourceLoaderSkinModule.php index 69313bfbed..2455596233 100644 --- a/includes/resourceloader/ResourceLoaderSkinModule.php +++ b/includes/resourceloader/ResourceLoaderSkinModule.php @@ -176,25 +176,14 @@ class ResourceLoaderSkinModule extends ResourceLoaderFileModule { } /** - * Non-static proxy to ::getLogo (for overloading in sub classes or tests). - * - * @codeCoverageIgnore * @since 1.31 - * @param Config $conf - * @return string|array - */ - protected function getLogoData( Config $conf ) { - return static::getLogo( $conf ); - } - - /** * @param Config $conf * @return string|array Single url if no variants are defined, * or an array of logo urls keyed by dppx in form "x". * Key "1x" is always defined. Key "svg" may also be defined, * in which case variants other than "1x" are omitted. */ - public static function getLogo( Config $conf ) { + protected function getLogoData( Config $conf ) { $logo = $conf->get( 'Logo' ); $logoHD = $conf->get( 'LogoHD' ); diff --git a/tests/phpunit/includes/OutputPageTest.php b/tests/phpunit/includes/OutputPageTest.php index 1f3ee27fce..42ea9ed54b 100644 --- a/tests/phpunit/includes/OutputPageTest.php +++ b/tests/phpunit/includes/OutputPageTest.php @@ -2037,82 +2037,6 @@ class OutputPageTest extends MediaWikiTestCase { ] ); } - /** - * @dataProvider providePreloadLinkHeaders - * @covers ResourceLoaderSkinModule::getPreloadLinks - * @covers ResourceLoaderSkinModule::getLogoPreloadlinks - * @covers ResourceLoaderSkinModule::getLogo - */ - 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 providePreloadLinkHeaders() { - 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( __DIR__ ) . '/data/media', - ], - 'Link: ;rel=preload;as=image', - ], - ]; - } - /** * @return OutputPage */ diff --git a/tests/phpunit/includes/resourceloader/ResourceLoaderSkinModuleTest.php b/tests/phpunit/includes/resourceloader/ResourceLoaderSkinModuleTest.php index 61ab8a521d..231979d689 100644 --- a/tests/phpunit/includes/resourceloader/ResourceLoaderSkinModuleTest.php +++ b/tests/phpunit/includes/resourceloader/ResourceLoaderSkinModuleTest.php @@ -1,9 +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 +203,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', + ], + ]; + } } -- 2.20.1