2017-07-08 03:34:56 +00:00
|
|
|
<?php
|
|
|
|
|
|
2018-08-20 23:58:41 +00:00
|
|
|
use Wikimedia\TestingAccessWrapper;
|
|
|
|
|
|
2017-07-08 03:34:56 +00:00
|
|
|
/**
|
|
|
|
|
* @group ResourceLoader
|
|
|
|
|
*/
|
2020-06-30 15:09:24 +00:00
|
|
|
class ResourceLoaderSkinModuleTest extends MediaWikiIntegrationTestCase {
|
2021-04-20 22:15:29 +00:00
|
|
|
public function provideGetBackwardsCompatibleFeatures() {
|
|
|
|
|
return [
|
2021-04-05 22:36:00 +00:00
|
|
|
[
|
|
|
|
|
[
|
|
|
|
|
'features' => [
|
|
|
|
|
'content-parser-output' => true,
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
'content-body' => true,
|
|
|
|
|
],
|
|
|
|
|
'The new `content-parser-output` module was renamed to `content-body`.'
|
|
|
|
|
],
|
2021-04-20 22:15:29 +00:00
|
|
|
[
|
|
|
|
|
[],
|
|
|
|
|
[
|
|
|
|
|
'logo' => true,
|
|
|
|
|
'legacy' => true
|
|
|
|
|
],
|
|
|
|
|
'For historic reasons if nothing is declared logo and legacy features are enabled.'
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
[
|
|
|
|
|
'features' => [
|
|
|
|
|
'content' => true,
|
|
|
|
|
]
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
'content-thumbnails' => true,
|
|
|
|
|
],
|
|
|
|
|
'The `content` feature is mapped to `content-thumbnails`.'
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
[
|
|
|
|
|
'features' => [
|
|
|
|
|
'content-links' => true,
|
|
|
|
|
]
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
'content-links-external' => true,
|
|
|
|
|
'content-links' => true,
|
|
|
|
|
],
|
|
|
|
|
'The `content-links` feature will also enable `content-links-external` if it not specified.'
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
[
|
|
|
|
|
'features' => [
|
|
|
|
|
'element' => true,
|
|
|
|
|
]
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
'element' => true,
|
|
|
|
|
'content-links' => true,
|
|
|
|
|
],
|
|
|
|
|
'The `element` feature will turn on `content-links` if not specified.'
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
[
|
|
|
|
|
'features' => [
|
|
|
|
|
'content-links-external' => false,
|
|
|
|
|
'content-links' => true,
|
|
|
|
|
]
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
'content-links-external' => false,
|
|
|
|
|
'content-links' => true,
|
|
|
|
|
],
|
|
|
|
|
'The `content-links` feature has no impact on content-links-external value.'
|
|
|
|
|
],
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @dataProvider provideGetBackwardsCompatibleFeatures
|
|
|
|
|
* @covers ResourceLoaderSkinModule::getBackwardsCompatibleFeatures
|
|
|
|
|
*/
|
|
|
|
|
public function testGetBackwardsCompatibleFeatures( $options, $expected, $msg ) {
|
|
|
|
|
$actual = ResourceLoaderSkinModule::getBackwardsCompatibleFeatures( $options );
|
|
|
|
|
$this->assertEquals( $expected, $actual, $msg );
|
|
|
|
|
}
|
2017-07-08 03:34:56 +00:00
|
|
|
|
2020-01-07 19:18:51 +00:00
|
|
|
public static function provideGetAvailableLogos() {
|
|
|
|
|
return [
|
|
|
|
|
[
|
|
|
|
|
[
|
|
|
|
|
'Logos' => [],
|
|
|
|
|
'Logo' => '/logo.png',
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
'1x' => '/logo.png',
|
|
|
|
|
]
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
[
|
|
|
|
|
'Logos' => [
|
|
|
|
|
'svg' => '/logo.svg',
|
|
|
|
|
'2x' => 'logo-2x.png'
|
|
|
|
|
],
|
|
|
|
|
'Logo' => '/logo.png',
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
'svg' => '/logo.svg',
|
|
|
|
|
'2x' => 'logo-2x.png',
|
|
|
|
|
'1x' => '/logo.png',
|
|
|
|
|
]
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
[
|
|
|
|
|
'Logos' => [
|
|
|
|
|
'wordmark' => '/logo-wordmark.png',
|
|
|
|
|
'1x' => '/logo.png',
|
|
|
|
|
'svg' => '/logo.svg',
|
|
|
|
|
'2x' => 'logo-2x.png'
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
'wordmark' => '/logo-wordmark.png',
|
|
|
|
|
'1x' => '/logo.png',
|
|
|
|
|
'svg' => '/logo.svg',
|
|
|
|
|
'2x' => 'logo-2x.png',
|
|
|
|
|
]
|
|
|
|
|
]
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
2017-07-08 03:34:56 +00:00
|
|
|
public static function provideGetStyles() {
|
2018-01-01 13:10:16 +00:00
|
|
|
// phpcs:disable Generic.Files.LineLength
|
2017-07-08 03:34:56 +00:00
|
|
|
return [
|
|
|
|
|
[
|
|
|
|
|
'parent' => [],
|
2017-05-22 18:12:26 +00:00
|
|
|
'logo' => '/logo.png',
|
2017-07-08 03:34:56 +00:00
|
|
|
'expected' => [
|
|
|
|
|
'all' => [ '.mw-wiki-logo { background-image: url(/logo.png); }' ],
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
'parent' => [
|
|
|
|
|
'screen' => '.example {}',
|
|
|
|
|
],
|
2017-05-22 18:12:26 +00:00
|
|
|
'logo' => '/logo.png',
|
2017-07-08 03:34:56 +00:00
|
|
|
'expected' => [
|
|
|
|
|
'screen' => [ '.example {}' ],
|
|
|
|
|
'all' => [ '.mw-wiki-logo { background-image: url(/logo.png); }' ],
|
|
|
|
|
],
|
|
|
|
|
],
|
2017-05-22 18:12:26 +00:00
|
|
|
[
|
|
|
|
|
'parent' => [],
|
|
|
|
|
'logo' => [
|
|
|
|
|
'1x' => '/logo.png',
|
|
|
|
|
'1.5x' => '/logo@1.5x.png',
|
|
|
|
|
'2x' => '/logo@2x.png',
|
|
|
|
|
],
|
|
|
|
|
'expected' => [
|
|
|
|
|
'all' => [ <<<CSS
|
|
|
|
|
.mw-wiki-logo { background-image: url(/logo.png); }
|
|
|
|
|
CSS
|
|
|
|
|
],
|
|
|
|
|
'(-webkit-min-device-pixel-ratio: 1.5), (min--moz-device-pixel-ratio: 1.5), (min-resolution: 1.5dppx), (min-resolution: 144dpi)' => [ <<<CSS
|
|
|
|
|
.mw-wiki-logo { background-image: url(/logo@1.5x.png);background-size: 135px auto; }
|
|
|
|
|
CSS
|
|
|
|
|
],
|
|
|
|
|
'(-webkit-min-device-pixel-ratio: 2), (min--moz-device-pixel-ratio: 2), (min-resolution: 2dppx), (min-resolution: 192dpi)' => [ <<<CSS
|
|
|
|
|
.mw-wiki-logo { background-image: url(/logo@2x.png);background-size: 135px auto; }
|
|
|
|
|
CSS
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
'parent' => [],
|
|
|
|
|
'logo' => [
|
|
|
|
|
'1x' => '/logo.png',
|
|
|
|
|
'svg' => '/logo.svg',
|
|
|
|
|
],
|
|
|
|
|
'expected' => [
|
|
|
|
|
'all' => [ <<<CSS
|
|
|
|
|
.mw-wiki-logo { background-image: url(/logo.png); }
|
|
|
|
|
CSS
|
|
|
|
|
, <<<CSS
|
|
|
|
|
.mw-wiki-logo { background-image: -webkit-linear-gradient(transparent, transparent), url(/logo.svg); background-image: linear-gradient(transparent, transparent), url(/logo.svg);background-size: 135px auto; }
|
|
|
|
|
CSS
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
],
|
2017-07-08 03:34:56 +00:00
|
|
|
];
|
2018-01-01 13:10:16 +00:00
|
|
|
// phpcs:enable
|
2017-07-08 03:34:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @dataProvider provideGetStyles
|
2018-05-04 16:30:33 +00:00
|
|
|
* @covers ResourceLoaderSkinModule
|
2017-07-08 03:34:56 +00:00
|
|
|
*/
|
2017-05-22 18:12:26 +00:00
|
|
|
public function testGetStyles( $parent, $logo, $expected ) {
|
2017-07-08 03:34:56 +00:00
|
|
|
$module = $this->getMockBuilder( ResourceLoaderSkinModule::class )
|
2021-03-20 15:18:58 +00:00
|
|
|
->onlyMethods( [ 'readStyleFiles', 'getConfig', 'getLogoData' ] )
|
2020-09-15 19:24:11 +00:00
|
|
|
->disableOriginalConstructor()
|
2017-07-08 03:34:56 +00:00
|
|
|
->getMock();
|
|
|
|
|
$module->expects( $this->once() )->method( 'readStyleFiles' )
|
|
|
|
|
->willReturn( $parent );
|
2021-04-22 08:40:46 +00:00
|
|
|
$module->method( 'getConfig' )
|
2020-09-15 19:24:11 +00:00
|
|
|
->willReturn( new HashConfig( [
|
|
|
|
|
'UseNewMediaStructure' => true,
|
|
|
|
|
] ) );
|
2017-05-22 18:12:26 +00:00
|
|
|
$module->expects( $this->once() )->method( 'getLogoData' )
|
|
|
|
|
->willReturn( $logo );
|
2017-07-08 03:34:56 +00:00
|
|
|
|
|
|
|
|
$ctx = $this->getMockBuilder( ResourceLoaderContext::class )
|
|
|
|
|
->disableOriginalConstructor()->getMock();
|
|
|
|
|
|
2020-09-15 19:24:11 +00:00
|
|
|
$module->__construct();
|
2017-07-08 03:34:56 +00:00
|
|
|
$this->assertEquals(
|
2017-05-22 18:12:26 +00:00
|
|
|
$expected,
|
|
|
|
|
$module->getStyles( $ctx )
|
2017-07-08 03:34:56 +00:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2020-01-07 19:18:51 +00:00
|
|
|
/**
|
|
|
|
|
* @dataProvider provideGetAvailableLogos
|
|
|
|
|
* @covers ResourceLoaderSkinModule::getAvailableLogos
|
|
|
|
|
*/
|
|
|
|
|
public function testGetAvailableLogos( $config, $expected ) {
|
|
|
|
|
$logos = ResourceLoaderSkinModule::getAvailableLogos( new HashConfig( $config ) );
|
|
|
|
|
$this->assertSame( $logos, $expected );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @covers ResourceLoaderSkinModule::getAvailableLogos
|
|
|
|
|
*/
|
|
|
|
|
public function testGetAvailableLogosRuntimeException() {
|
|
|
|
|
$this->expectException( \RuntimeException::class );
|
|
|
|
|
ResourceLoaderSkinModule::getAvailableLogos( new HashConfig( [
|
|
|
|
|
'Logo' => false,
|
|
|
|
|
'Logos' => false,
|
|
|
|
|
'LogoHD' => false,
|
|
|
|
|
] ) );
|
|
|
|
|
}
|
|
|
|
|
|
2017-07-08 03:34:56 +00:00
|
|
|
/**
|
|
|
|
|
* @covers ResourceLoaderSkinModule::isKnownEmpty
|
|
|
|
|
*/
|
|
|
|
|
public function testIsKnownEmpty() {
|
|
|
|
|
$module = $this->getMockBuilder( ResourceLoaderSkinModule::class )
|
2021-03-20 15:18:58 +00:00
|
|
|
->disableOriginalConstructor()->onlyMethods( [] )->getMock();
|
2017-07-08 03:34:56 +00:00
|
|
|
$ctx = $this->getMockBuilder( ResourceLoaderContext::class )
|
|
|
|
|
->disableOriginalConstructor()->getMock();
|
|
|
|
|
|
|
|
|
|
$this->assertFalse( $module->isKnownEmpty( $ctx ) );
|
|
|
|
|
}
|
2017-05-22 18:12:26 +00:00
|
|
|
|
|
|
|
|
/**
|
2018-08-20 23:58:41 +00:00
|
|
|
* @dataProvider provideGetLogoData
|
|
|
|
|
* @covers ResourceLoaderSkinModule::getLogoData
|
2017-05-22 18:12:26 +00:00
|
|
|
*/
|
2018-08-20 23:58:41 +00:00
|
|
|
public function testGetLogoData( $config, $expected, $baseDir = null ) {
|
2017-05-22 18:12:26 +00:00
|
|
|
if ( $baseDir ) {
|
2018-08-20 23:58:41 +00:00
|
|
|
$this->setMwGlobals( 'IP', $baseDir );
|
2017-05-22 18:12:26 +00:00
|
|
|
}
|
2018-08-20 23:58:41 +00:00
|
|
|
// Allow testing of protected method
|
|
|
|
|
$module = TestingAccessWrapper::newFromObject( new ResourceLoaderSkinModule() );
|
2017-05-22 18:12:26 +00:00
|
|
|
|
|
|
|
|
$this->assertEquals(
|
|
|
|
|
$expected,
|
2018-08-20 23:58:41 +00:00
|
|
|
$module->getLogoData( new HashConfig( $config ) )
|
2017-05-22 18:12:26 +00:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2018-08-20 23:58:41 +00:00
|
|
|
public function provideGetLogoData() {
|
2017-05-22 18:12:26 +00:00
|
|
|
return [
|
2020-02-05 21:12:02 +00:00
|
|
|
'wordmark' => [
|
|
|
|
|
'config' => [
|
|
|
|
|
'ResourceBasePath' => '/w',
|
|
|
|
|
'Logos' => [
|
|
|
|
|
'1x' => '/img/default.png',
|
|
|
|
|
'wordmark' => '/img/wordmark.png',
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
'expected' => '/img/default.png',
|
|
|
|
|
],
|
2017-05-22 18:12:26 +00:00
|
|
|
'simple' => [
|
|
|
|
|
'config' => [
|
|
|
|
|
'ResourceBasePath' => '/w',
|
2020-01-07 19:18:51 +00:00
|
|
|
'Logos' => [
|
|
|
|
|
'1x' => '/img/default.png',
|
|
|
|
|
],
|
2017-05-22 18:12:26 +00:00
|
|
|
],
|
|
|
|
|
'expected' => '/img/default.png',
|
|
|
|
|
],
|
|
|
|
|
'default and 2x' => [
|
|
|
|
|
'config' => [
|
|
|
|
|
'ResourceBasePath' => '/w',
|
2020-01-07 19:18:51 +00:00
|
|
|
'Logos' => [
|
|
|
|
|
'1x' => '/img/default.png',
|
2017-05-22 18:12:26 +00:00
|
|
|
'2x' => '/img/two-x.png',
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
'expected' => [
|
|
|
|
|
'1x' => '/img/default.png',
|
|
|
|
|
'2x' => '/img/two-x.png',
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
'default and all HiDPIs' => [
|
|
|
|
|
'config' => [
|
|
|
|
|
'ResourceBasePath' => '/w',
|
2020-01-07 19:18:51 +00:00
|
|
|
'Logos' => [
|
|
|
|
|
'1x' => '/img/default.png',
|
2017-05-22 18:12:26 +00:00
|
|
|
'1.5x' => '/img/one-point-five.png',
|
|
|
|
|
'2x' => '/img/two-x.png',
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
'expected' => [
|
|
|
|
|
'1x' => '/img/default.png',
|
|
|
|
|
'1.5x' => '/img/one-point-five.png',
|
|
|
|
|
'2x' => '/img/two-x.png',
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
'default and SVG' => [
|
|
|
|
|
'config' => [
|
|
|
|
|
'ResourceBasePath' => '/w',
|
2020-01-07 19:18:51 +00:00
|
|
|
'Logos' => [
|
|
|
|
|
'1x' => '/img/default.png',
|
2017-05-22 18:12:26 +00:00
|
|
|
'svg' => '/img/vector.svg',
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
'expected' => [
|
|
|
|
|
'1x' => '/img/default.png',
|
|
|
|
|
'svg' => '/img/vector.svg',
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
'everything' => [
|
|
|
|
|
'config' => [
|
|
|
|
|
'ResourceBasePath' => '/w',
|
2020-01-07 19:18:51 +00:00
|
|
|
'Logos' => [
|
|
|
|
|
'1x' => '/img/default.png',
|
2017-05-22 18:12:26 +00:00
|
|
|
'1.5x' => '/img/one-point-five.png',
|
|
|
|
|
'2x' => '/img/two-x.png',
|
|
|
|
|
'svg' => '/img/vector.svg',
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
'expected' => [
|
|
|
|
|
'1x' => '/img/default.png',
|
|
|
|
|
'svg' => '/img/vector.svg',
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
'versioned url' => [
|
|
|
|
|
'config' => [
|
|
|
|
|
'ResourceBasePath' => '/w',
|
|
|
|
|
'UploadPath' => '/w/images',
|
2020-01-07 19:18:51 +00:00
|
|
|
'Logos' => [
|
|
|
|
|
'1x' => '/w/test.jpg',
|
|
|
|
|
],
|
2017-05-22 18:12:26 +00:00
|
|
|
],
|
|
|
|
|
'expected' => '/w/test.jpg?edcf2',
|
|
|
|
|
'baseDir' => dirname( dirname( __DIR__ ) ) . '/data/media',
|
|
|
|
|
],
|
|
|
|
|
];
|
|
|
|
|
}
|
2018-08-20 23:58:41 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @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',
|
2020-01-07 19:18:51 +00:00
|
|
|
'wgLogo' => false,
|
|
|
|
|
'wgLogoHD' => false,
|
|
|
|
|
'wgLogos' => [
|
|
|
|
|
'1x' => '/img/default.png',
|
2018-08-20 23:58:41 +00:00
|
|
|
'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',
|
2020-01-07 19:18:51 +00:00
|
|
|
'wgLogo' => false,
|
2018-08-20 23:58:41 +00:00
|
|
|
'wgLogoHD' => false,
|
2020-01-07 19:18:51 +00:00
|
|
|
'wgLogos' => [
|
|
|
|
|
'1x' => '/img/default.png',
|
|
|
|
|
],
|
2018-08-20 23:58:41 +00:00
|
|
|
],
|
|
|
|
|
'Link: </img/default.png>;rel=preload;as=image'
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
[
|
|
|
|
|
'wgResourceBasePath' => '/w',
|
2020-01-07 19:18:51 +00:00
|
|
|
'wgLogo' => false,
|
|
|
|
|
'wgLogoHD' => false,
|
|
|
|
|
'wgLogos' => [
|
|
|
|
|
'1x' => '/img/default.png',
|
2018-08-20 23:58:41 +00:00
|
|
|
'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',
|
2020-01-07 19:18:51 +00:00
|
|
|
'wgLogo' => false,
|
|
|
|
|
'wgLogoHD' => false,
|
|
|
|
|
'wgLogos' => [
|
|
|
|
|
'1x' => '/img/default.png',
|
2018-08-20 23:58:41 +00:00
|
|
|
'svg' => '/img/vector.svg',
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
'Link: </img/vector.svg>;rel=preload;as=image'
|
|
|
|
|
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
[
|
|
|
|
|
'wgResourceBasePath' => '/w',
|
2020-01-07 19:18:51 +00:00
|
|
|
'wgLogo' => false,
|
2018-08-20 23:58:41 +00:00
|
|
|
'wgLogoHD' => false,
|
2020-01-07 19:18:51 +00:00
|
|
|
'wgLogos' => [
|
|
|
|
|
'1x' => '/w/test.jpg',
|
|
|
|
|
],
|
2018-08-20 23:58:41 +00:00
|
|
|
'wgUploadPath' => '/w/images',
|
|
|
|
|
'IP' => dirname( dirname( __DIR__ ) ) . '/data/media',
|
|
|
|
|
],
|
|
|
|
|
'Link: </w/test.jpg?edcf2>;rel=preload;as=image',
|
|
|
|
|
],
|
|
|
|
|
];
|
|
|
|
|
}
|
2020-06-10 14:09:09 +00:00
|
|
|
|
2020-10-18 20:16:37 +00:00
|
|
|
/**
|
|
|
|
|
* @covers ResourceLoaderSkinModule::getPreloadLinks
|
|
|
|
|
*/
|
|
|
|
|
public function testNoPreloadLogos() {
|
|
|
|
|
$module = new ResourceLoaderSkinModule( [ 'features' => [ 'logo' => false ] ] );
|
|
|
|
|
$context =
|
|
|
|
|
$this->getMockBuilder( ResourceLoaderContext::class )
|
|
|
|
|
->disableOriginalConstructor()
|
|
|
|
|
->getMock();
|
|
|
|
|
$preloadLinks = $module->getPreloadLinks( $context );
|
|
|
|
|
$this->assertArrayEquals( [], $preloadLinks );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @covers ResourceLoaderSkinModule::getPreloadLinks
|
|
|
|
|
*/
|
|
|
|
|
public function testPreloadLogos() {
|
|
|
|
|
$module = new ResourceLoaderSkinModule();
|
|
|
|
|
$context = $this->getMockBuilder( ResourceLoaderContext::class )
|
|
|
|
|
->disableOriginalConstructor()->getMock();
|
|
|
|
|
$preloadLinks = $module->getPreloadLinks( $context );
|
|
|
|
|
$this->assertNotSameSize( [], $preloadLinks );
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-10 14:09:09 +00:00
|
|
|
/**
|
|
|
|
|
* Covers ResourceLoaderSkinModule::FEATURE_FILES, but not annotatable.
|
|
|
|
|
*
|
|
|
|
|
* @dataProvider provideFeatureFiles
|
|
|
|
|
* @coversNothing
|
|
|
|
|
*
|
|
|
|
|
* @param string $file
|
|
|
|
|
*/
|
|
|
|
|
public function testFeatureFilesExist( string $file ) : void {
|
|
|
|
|
$this->assertFileExists( $file );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function provideFeatureFiles() : Generator {
|
|
|
|
|
global $IP;
|
|
|
|
|
|
|
|
|
|
$featureFiles = ( new ReflectionClass( ResourceLoaderSkinModule::class ) )
|
|
|
|
|
->getConstant( 'FEATURE_FILES' );
|
|
|
|
|
|
|
|
|
|
foreach ( $featureFiles as $feature => $files ) {
|
|
|
|
|
foreach ( $files as $media => $stylesheets ) {
|
|
|
|
|
foreach ( $stylesheets as $stylesheet ) {
|
|
|
|
|
yield "$feature: $media: $stylesheet" => [ "$IP/$stylesheet" ];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-08-24 11:37:11 +00:00
|
|
|
|
2021-01-08 21:23:29 +00:00
|
|
|
public static function provideGetStyleFilesFeatureStylesOrder() {
|
|
|
|
|
list( $defaultLocalBasePath, $defaultRemoteBasePath ) =
|
|
|
|
|
ResourceLoaderFileModule::extractBasePaths();
|
|
|
|
|
$featureFiles = ( new ReflectionClass( ResourceLoaderSkinModule::class ) )
|
|
|
|
|
->getConstant( 'FEATURE_FILES' );
|
|
|
|
|
|
|
|
|
|
$normalizePath = new ResourceLoaderFilePath(
|
|
|
|
|
$featureFiles['normalize']['all'][0],
|
|
|
|
|
$defaultLocalBasePath,
|
|
|
|
|
$defaultRemoteBasePath
|
|
|
|
|
);
|
|
|
|
|
$elementsPath = new ResourceLoaderFilePath(
|
|
|
|
|
$featureFiles['elements']['screen'][0],
|
|
|
|
|
$defaultLocalBasePath,
|
|
|
|
|
$defaultRemoteBasePath
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
return [
|
2020-08-24 11:37:11 +00:00
|
|
|
[
|
2021-01-08 21:23:29 +00:00
|
|
|
[ 'elements', 'normalize' ],
|
|
|
|
|
[
|
2020-12-07 19:02:58 +00:00
|
|
|
'test.styles/styles.css' => [
|
|
|
|
|
'media' => 'screen'
|
|
|
|
|
]
|
2021-01-08 21:23:29 +00:00
|
|
|
],
|
|
|
|
|
[ $normalizePath ],
|
|
|
|
|
[ $elementsPath, 'test.styles/styles.css' ],
|
|
|
|
|
'opt-out by default policy results in correct order'
|
|
|
|
|
],
|
2020-12-07 19:02:58 +00:00
|
|
|
[
|
2021-01-08 21:23:29 +00:00
|
|
|
[
|
2021-03-23 23:20:07 +00:00
|
|
|
'content-parser-output' => false,
|
2020-12-07 19:02:58 +00:00
|
|
|
'elements' => true,
|
|
|
|
|
'normalize' => true,
|
|
|
|
|
'toc' => false,
|
|
|
|
|
],
|
2021-01-08 21:23:29 +00:00
|
|
|
[
|
2020-08-24 11:37:11 +00:00
|
|
|
'test.styles/styles.css' => [
|
|
|
|
|
'media' => 'screen'
|
|
|
|
|
]
|
2021-01-08 21:23:29 +00:00
|
|
|
],
|
|
|
|
|
[ $normalizePath ],
|
|
|
|
|
[ $elementsPath, 'test.styles/styles.css' ],
|
|
|
|
|
'opt-in by default policy results in correct order'
|
|
|
|
|
],
|
2020-08-24 11:37:11 +00:00
|
|
|
|
2021-01-08 21:23:29 +00:00
|
|
|
[
|
|
|
|
|
[ 'normalize' ],
|
|
|
|
|
[ 'test.styles/styles.css' => [ 'media' => 'screen' ] ],
|
|
|
|
|
[ $normalizePath ],
|
|
|
|
|
[ 'test.styles/styles.css' ],
|
|
|
|
|
'module provided styles come after skin defined'
|
2020-12-07 19:02:58 +00:00
|
|
|
],
|
2020-08-24 11:37:11 +00:00
|
|
|
];
|
2021-01-08 21:23:29 +00:00
|
|
|
}
|
2020-08-24 11:37:11 +00:00
|
|
|
|
2021-01-08 21:23:29 +00:00
|
|
|
/**
|
|
|
|
|
* @covers ResourceLoaderSkinModule::getStyleFiles
|
|
|
|
|
* @dataProvider provideGetStyleFilesFeatureStylesOrder
|
|
|
|
|
* @param array $features
|
|
|
|
|
* @param array $styles
|
|
|
|
|
* @param array $expectedAllStyles array of styles
|
|
|
|
|
* @param array $expectedScreenStyles array of styles
|
|
|
|
|
* @param string $msg to show for debugging
|
|
|
|
|
*/
|
|
|
|
|
public function testGetStyleFilesFeatureStylesOrder(
|
|
|
|
|
$features, $styles, $expectedAllStyles, $expectedScreenStyles, $msg
|
|
|
|
|
) : void {
|
|
|
|
|
$ctx = $this->createMock( ResourceLoaderContext::class );
|
|
|
|
|
$module = new ResourceLoaderSkinModule(
|
|
|
|
|
[
|
|
|
|
|
// The ordering should be controlled by ResourceLoaderSkinModule
|
|
|
|
|
// `normalize` will be outputted before `elements` despite the ordering
|
|
|
|
|
'features' => $features,
|
|
|
|
|
'styles' => $styles,
|
|
|
|
|
]
|
2020-12-07 19:02:58 +00:00
|
|
|
);
|
|
|
|
|
|
2021-01-08 21:23:29 +00:00
|
|
|
$expected = [
|
|
|
|
|
'all' => $expectedAllStyles,
|
|
|
|
|
'screen' => $expectedScreenStyles,
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
$actual = $module->getStyleFiles( $ctx );
|
|
|
|
|
unset( $actual['print'] ); // not testing print for now
|
2020-08-24 11:37:11 +00:00
|
|
|
$this->assertEquals(
|
2021-01-08 21:23:29 +00:00
|
|
|
array_values( $expected ),
|
|
|
|
|
array_values( $actual )
|
2020-08-24 11:37:11 +00:00
|
|
|
);
|
|
|
|
|
}
|
2017-07-08 03:34:56 +00:00
|
|
|
}
|