diff options
author | Timo Tijhof <krinklemail@gmail.com> | 2018-08-21 00:58:41 +0100 |
---|---|---|
committer | Timo Tijhof <krinklemail@gmail.com> | 2018-08-28 23:50:50 +0100 |
commit | 3ff2615992ffb02a35931e4f19c09a602da689e0 (patch) | |
tree | b48006f31b3057841654c1ae857e82c953483283 /tests/phpunit/includes/resourceloader/ResourceLoaderSkinModuleTest.php | |
parent | 5d0b5a402e384897288ad569da8d534fa2e432cb (diff) | |
download | mediawikicore-3ff2615992ffb02a35931e4f19c09a602da689e0.tar.gz mediawikicore-3ff2615992ffb02a35931e4f19c09a602da689e0.zip |
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
Diffstat (limited to 'tests/phpunit/includes/resourceloader/ResourceLoaderSkinModuleTest.php')
-rw-r--r-- | tests/phpunit/includes/resourceloader/ResourceLoaderSkinModuleTest.php | 98 |
1 files changed, 87 insertions, 11 deletions
diff --git a/tests/phpunit/includes/resourceloader/ResourceLoaderSkinModuleTest.php b/tests/phpunit/includes/resourceloader/ResourceLoaderSkinModuleTest.php index 61ab8a521d28..231979d689ce 100644 --- a/tests/phpunit/includes/resourceloader/ResourceLoaderSkinModuleTest.php +++ b/tests/phpunit/includes/resourceloader/ResourceLoaderSkinModuleTest.php @@ -1,9 +1,11 @@ <?php +use Wikimedia\TestingAccessWrapper; + /** * @group ResourceLoader */ -class ResourceLoaderSkinModuleTest extends PHPUnit\Framework\TestCase { +class ResourceLoaderSkinModuleTest extends MediaWikiTestCase { use MediaWikiCoversValidator; @@ -107,25 +109,23 @@ CSS } /** - * @dataProvider provideGetLogo - * @covers ResourceLoaderSkinModule::getLogo + * @dataProvider provideGetLogoData + * @covers ResourceLoaderSkinModule::getLogoData */ - public function testGetLogo( $config, $expected, $baseDir = null ) { + public function testGetLogoData( $config, $expected, $baseDir = null ) { if ( $baseDir ) { - $oldIP = $GLOBALS['IP']; - $GLOBALS['IP'] = $baseDir; - $teardown = new Wikimedia\ScopedCallback( function () use ( $oldIP ) { - $GLOBALS['IP'] = $oldIP; - } ); + $this->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: </img/default.png>;rel=preload;as=image;media=' . + 'not all and (min-resolution: 1.5dppx),' . + '</img/one-point-five.png>;rel=preload;as=image;media=' . + '(min-resolution: 1.5dppx) and (max-resolution: 1.999999dppx),' . + '</img/two-x.png>;rel=preload;as=image;media=(min-resolution: 2dppx)' + ], + [ + [ + 'wgResourceBasePath' => '/w', + 'wgLogo' => '/img/default.png', + 'wgLogoHD' => false, + ], + 'Link: </img/default.png>;rel=preload;as=image' + ], + [ + [ + 'wgResourceBasePath' => '/w', + 'wgLogo' => '/img/default.png', + 'wgLogoHD' => [ + '2x' => '/img/two-x.png', + ], + ], + 'Link: </img/default.png>;rel=preload;as=image;media=' . + 'not all and (min-resolution: 2dppx),' . + '</img/two-x.png>;rel=preload;as=image;media=(min-resolution: 2dppx)' + ], + [ + [ + 'wgResourceBasePath' => '/w', + 'wgLogo' => '/img/default.png', + 'wgLogoHD' => [ + 'svg' => '/img/vector.svg', + ], + ], + 'Link: </img/vector.svg>;rel=preload;as=image' + + ], + [ + [ + 'wgResourceBasePath' => '/w', + 'wgLogo' => '/w/test.jpg', + 'wgLogoHD' => false, + 'wgUploadPath' => '/w/images', + 'IP' => dirname( dirname( __DIR__ ) ) . '/data/media', + ], + 'Link: </w/test.jpg?edcf2>;rel=preload;as=image', + ], + ]; + } } |