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
|
|
|
|
|
*/
|
2021-03-18 04:08:05 +00:00
|
|
|
class ResourceLoaderSkinModuleTest extends ResourceLoaderTestCase {
|
2021-03-18 03:20:36 +00:00
|
|
|
public static function provideApplyFeaturesCompatibility() {
|
2021-04-20 22:15:29 +00:00
|
|
|
return [
|
2021-05-13 23:13:52 +00:00
|
|
|
[
|
|
|
|
|
[
|
|
|
|
|
'content-thumbnails' => true,
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
'content-media' => true,
|
|
|
|
|
],
|
|
|
|
|
'The `content-thumbnails` feature is mapped to `content-media`.'
|
|
|
|
|
],
|
2021-04-05 22:36:00 +00:00
|
|
|
[
|
|
|
|
|
[
|
2021-03-18 03:20:36 +00:00
|
|
|
'content-parser-output' => true,
|
2021-04-05 22:36:00 +00:00
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
'content-body' => true,
|
|
|
|
|
],
|
|
|
|
|
'The new `content-parser-output` module was renamed to `content-body`.'
|
|
|
|
|
],
|
2021-04-20 22:15:29 +00:00
|
|
|
[
|
|
|
|
|
[
|
2021-03-18 03:20:36 +00:00
|
|
|
'content' => true,
|
2021-04-20 22:15:29 +00:00
|
|
|
],
|
|
|
|
|
[
|
2021-05-13 23:13:52 +00:00
|
|
|
'content-media' => true,
|
2021-04-20 22:15:29 +00:00
|
|
|
],
|
2021-05-13 23:13:52 +00:00
|
|
|
'The `content` feature is mapped to `content-media`.'
|
2021-04-20 22:15:29 +00:00
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
[
|
2021-03-18 03:20:36 +00:00
|
|
|
'content-links' => true,
|
2021-04-20 22:15:29 +00:00
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
'content-links-external' => true,
|
|
|
|
|
'content-links' => true,
|
|
|
|
|
],
|
|
|
|
|
'The `content-links` feature will also enable `content-links-external` if it not specified.'
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
[
|
2021-03-18 03:20:36 +00:00
|
|
|
'element' => true,
|
2021-04-20 22:15:29 +00:00
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
'element' => true,
|
|
|
|
|
'content-links' => true,
|
|
|
|
|
],
|
|
|
|
|
'The `element` feature will turn on `content-links` if not specified.'
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
[
|
2021-03-18 03:20:36 +00:00
|
|
|
'content-links-external' => false,
|
|
|
|
|
'content-links' => true,
|
2021-04-20 22:15:29 +00:00
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
'content-links-external' => false,
|
|
|
|
|
'content-links' => true,
|
|
|
|
|
],
|
|
|
|
|
'The `content-links` feature has no impact on content-links-external value.'
|
|
|
|
|
],
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2021-03-18 03:20:36 +00:00
|
|
|
* @dataProvider provideApplyFeaturesCompatibility
|
|
|
|
|
* @covers ResourceLoaderSkinModule::applyFeaturesCompatibility
|
2021-04-20 22:15:29 +00:00
|
|
|
*/
|
2021-03-18 03:20:36 +00:00
|
|
|
public function testApplyFeaturesCompatibility( array $features, array $expected, $msg ) {
|
|
|
|
|
// Test protected method
|
|
|
|
|
$class = TestingAccessWrapper::newFromClass( ResourceLoaderSkinModule::class );
|
|
|
|
|
$actual = $class->applyFeaturesCompatibility( $features );
|
2021-04-20 22:15:29 +00:00
|
|
|
$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' => [
|
2021-09-08 20:40:51 +00:00
|
|
|
'wordmark' => [
|
|
|
|
|
'src' => '/logo-wordmark.png',
|
|
|
|
|
'width' => 100,
|
|
|
|
|
'height' => 15,
|
|
|
|
|
],
|
2020-01-07 19:18:51 +00:00
|
|
|
'1x' => '/logo.png',
|
|
|
|
|
'svg' => '/logo.svg',
|
|
|
|
|
'2x' => 'logo-2x.png'
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
[
|
2021-09-08 20:40:51 +00:00
|
|
|
'wordmark' => [
|
|
|
|
|
'src' => '/logo-wordmark.png',
|
|
|
|
|
'width' => 100,
|
|
|
|
|
'height' => 15,
|
|
|
|
|
'style' => 'width: 6.25em; height: 0.9375em;',
|
|
|
|
|
],
|
2020-01-07 19:18:51 +00:00
|
|
|
'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-18 03:20:36 +00:00
|
|
|
->onlyMethods( [ 'readStyleFiles', 'getLogoData' ] )
|
2017-07-08 03:34:56 +00:00
|
|
|
->getMock();
|
|
|
|
|
$module->expects( $this->once() )->method( 'readStyleFiles' )
|
|
|
|
|
->willReturn( $parent );
|
2017-05-22 18:12:26 +00:00
|
|
|
$module->expects( $this->once() )->method( 'getLogoData' )
|
|
|
|
|
->willReturn( $logo );
|
2021-03-18 03:20:36 +00:00
|
|
|
$module->setConfig( new HashConfig( [
|
2018-02-13 22:51:22 +00:00
|
|
|
'ParserEnableLegacyMediaDOM' => false,
|
2021-03-18 04:08:05 +00:00
|
|
|
] + self::getSettings() ) );
|
2017-07-08 03:34:56 +00:00
|
|
|
|
|
|
|
|
$ctx = $this->getMockBuilder( ResourceLoaderContext::class )
|
|
|
|
|
->disableOriginalConstructor()->getMock();
|
|
|
|
|
|
|
|
|
|
$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',
|
2021-09-08 20:40:51 +00:00
|
|
|
'wordmark' => [
|
|
|
|
|
'src' => '/img/wordmark.png',
|
|
|
|
|
'width' => 120,
|
|
|
|
|
'height' => 20,
|
|
|
|
|
],
|
2020-02-05 21:12:02 +00:00
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
'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
|
|
|
|
|
*/
|
2021-03-18 04:08:05 +00:00
|
|
|
public function testPreloadLinkHeaders( $config, $installPath, $result ) {
|
|
|
|
|
$this->setMwGlobals( [ 'IP' => $installPath ] );
|
2018-08-20 23:58:41 +00:00
|
|
|
$ctx = $this->getMockBuilder( ResourceLoaderContext::class )
|
|
|
|
|
->disableOriginalConstructor()->getMock();
|
|
|
|
|
$module = new ResourceLoaderSkinModule();
|
2021-03-18 04:08:05 +00:00
|
|
|
$module->setConfig( new HashConfig( $config + self::getSettings() ) );
|
2018-08-20 23:58:41 +00:00
|
|
|
|
|
|
|
|
$this->assertEquals( [ $result ], $module->getHeaders( $ctx ) );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function providePreloadLinks() {
|
|
|
|
|
return [
|
|
|
|
|
[
|
|
|
|
|
[
|
2021-03-18 04:08:05 +00:00
|
|
|
'ResourceBasePath' => '/w',
|
|
|
|
|
'Logo' => false,
|
|
|
|
|
'LogoHD' => false,
|
|
|
|
|
'Logos' => [
|
2020-01-07 19:18:51 +00:00
|
|
|
'1x' => '/img/default.png',
|
2018-08-20 23:58:41 +00:00
|
|
|
'1.5x' => '/img/one-point-five.png',
|
|
|
|
|
'2x' => '/img/two-x.png',
|
|
|
|
|
],
|
|
|
|
|
],
|
2021-03-18 04:08:05 +00:00
|
|
|
'/dummy',
|
2018-08-20 23:58:41 +00:00
|
|
|
'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)'
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
[
|
2021-03-18 04:08:05 +00:00
|
|
|
'ResourceBasePath' => '/w',
|
|
|
|
|
'Logo' => false,
|
|
|
|
|
'LogoHD' => false,
|
|
|
|
|
'Logos' => [
|
2020-01-07 19:18:51 +00:00
|
|
|
'1x' => '/img/default.png',
|
|
|
|
|
],
|
2018-08-20 23:58:41 +00:00
|
|
|
],
|
2021-03-18 04:08:05 +00:00
|
|
|
'/dummy',
|
2018-08-20 23:58:41 +00:00
|
|
|
'Link: </img/default.png>;rel=preload;as=image'
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
[
|
2021-03-18 04:08:05 +00:00
|
|
|
'ResourceBasePath' => '/w',
|
|
|
|
|
'Logo' => false,
|
|
|
|
|
'LogoHD' => false,
|
|
|
|
|
'Logos' => [
|
2020-01-07 19:18:51 +00:00
|
|
|
'1x' => '/img/default.png',
|
2018-08-20 23:58:41 +00:00
|
|
|
'2x' => '/img/two-x.png',
|
|
|
|
|
],
|
|
|
|
|
],
|
2021-03-18 04:08:05 +00:00
|
|
|
'/dummy',
|
2018-08-20 23:58:41 +00:00
|
|
|
'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)'
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
[
|
2021-03-18 04:08:05 +00:00
|
|
|
'ResourceBasePath' => '/w',
|
|
|
|
|
'Logo' => false,
|
|
|
|
|
'LogoHD' => false,
|
|
|
|
|
'Logos' => [
|
2020-01-07 19:18:51 +00:00
|
|
|
'1x' => '/img/default.png',
|
2018-08-20 23:58:41 +00:00
|
|
|
'svg' => '/img/vector.svg',
|
|
|
|
|
],
|
|
|
|
|
],
|
2021-03-18 04:08:05 +00:00
|
|
|
'/dummy',
|
2018-08-20 23:58:41 +00:00
|
|
|
'Link: </img/vector.svg>;rel=preload;as=image'
|
|
|
|
|
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
[
|
2021-03-18 04:08:05 +00:00
|
|
|
'ResourceBasePath' => '/w',
|
|
|
|
|
'Logo' => false,
|
|
|
|
|
'LogoHD' => false,
|
|
|
|
|
'Logos' => [
|
2020-01-07 19:18:51 +00:00
|
|
|
'1x' => '/w/test.jpg',
|
|
|
|
|
],
|
2021-03-18 04:08:05 +00:00
|
|
|
'UploadPath' => '/w/images',
|
2018-08-20 23:58:41 +00:00
|
|
|
],
|
2021-03-18 04:08:05 +00:00
|
|
|
dirname( dirname( __DIR__ ) ) . '/data/media',
|
2018-08-20 23:58:41 +00:00
|
|
|
'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();
|
2021-03-18 04:08:05 +00:00
|
|
|
$module->setConfig( self::getMinimalConfig() );
|
2020-10-18 20:16:37 +00:00
|
|
|
$context = $this->getMockBuilder( ResourceLoaderContext::class )
|
|
|
|
|
->disableOriginalConstructor()->getMock();
|
2021-03-18 04:08:05 +00:00
|
|
|
|
2020-10-18 20:16:37 +00:00
|
|
|
$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
|
|
|
|
|
*/
|
2021-07-22 03:11:47 +00:00
|
|
|
public function testFeatureFilesExist( string $file ): void {
|
2020-06-10 14:09:09 +00:00
|
|
|
$this->assertFileExists( $file );
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-22 03:11:47 +00:00
|
|
|
public function provideFeatureFiles(): Generator {
|
2020-06-10 14:09:09 +00:00
|
|
|
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() {
|
2021-03-18 04:08:05 +00:00
|
|
|
global $IP;
|
2021-01-08 21:23:29 +00:00
|
|
|
$featureFiles = ( new ReflectionClass( ResourceLoaderSkinModule::class ) )
|
|
|
|
|
->getConstant( 'FEATURE_FILES' );
|
|
|
|
|
|
|
|
|
|
$normalizePath = new ResourceLoaderFilePath(
|
|
|
|
|
$featureFiles['normalize']['all'][0],
|
2021-03-18 04:08:05 +00:00
|
|
|
$IP,
|
|
|
|
|
'/w'
|
2021-01-08 21:23:29 +00:00
|
|
|
);
|
|
|
|
|
$elementsPath = new ResourceLoaderFilePath(
|
|
|
|
|
$featureFiles['elements']['screen'][0],
|
2021-03-18 04:08:05 +00:00
|
|
|
$IP,
|
|
|
|
|
'/w'
|
2021-01-08 21:23:29 +00:00
|
|
|
);
|
2021-05-24 23:11:32 +00:00
|
|
|
$cbPath = new ResourceLoaderFilePath(
|
|
|
|
|
$featureFiles['content-body']['screen'][0],
|
|
|
|
|
$IP,
|
|
|
|
|
'/w'
|
|
|
|
|
);
|
2021-01-08 21:23:29 +00:00
|
|
|
|
|
|
|
|
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-18 03:20:36 +00:00
|
|
|
'content-body' => 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-05-24 23:11:32 +00:00
|
|
|
[
|
|
|
|
|
[ 'content-parser-output' ],
|
|
|
|
|
[ 'test.styles/all.css' ],
|
|
|
|
|
[
|
|
|
|
|
$cbPath
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
'test.styles/all.css'
|
|
|
|
|
],
|
|
|
|
|
'content-parser-output mapped to content-body styles'
|
|
|
|
|
],
|
|
|
|
|
|
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
|
2021-07-22 03:11:47 +00:00
|
|
|
): void {
|
2021-01-08 21:23:29 +00:00
|
|
|
$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-03-18 04:08:05 +00:00
|
|
|
$module->setConfig( self::getMinimalConfig() );
|
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
|
|
|
);
|
|
|
|
|
}
|
resourceloader: Restore feedback for SkinModule invalid argument
This was added in 381499a675 in response to the issue that when a skin
adopts a feature that was new in MW 1.36, it caused an exception when
that version of the skin is then installed on MW 1.35. That's expected,
and generally helpful because the default support policy requires
like-for-like (MW 1.35 with REL1_35, this applies to all skins and
extensions, except for a few like Translate and SemanticMediaWiki).
However, while supporting LTS within master is unusual, there are
indeed the Translate/SemanticMediaWiki projects, and this problem has
already been solved years ago there by using a conditional with
$wgVersion. The proposed approach on T271441 actually also involves
such a conditional, but late at runtime instead of in the module
definition. Anyway, the way it was fixed in Timeless already solves
the problem by not passing down the invalid feature in the first
place, thus making the 381499a675 patch obsolete. I'm not aware of
any skin in Gerrit having such a compat policy, but if they exist,
they can fix it the same way, by defining the module in code with
a condition, just as Translate/SemanticMediaWiki do.
Bug: T271441
Change-Id: If97b3d04ac1e3355ee4f229db11e524d24ebd27a
2021-03-18 17:22:37 +00:00
|
|
|
|
|
|
|
|
public static function provideInvalidFeatures() {
|
|
|
|
|
yield 'listed unknown' => [
|
|
|
|
|
[ 'logo', 'unknown' ],
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
yield 'enabled unknown' => [
|
|
|
|
|
[
|
|
|
|
|
'logo' => true,
|
|
|
|
|
'toc' => false,
|
|
|
|
|
'unknown' => true,
|
|
|
|
|
],
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
yield 'disbled unknown' => [
|
|
|
|
|
[
|
|
|
|
|
'logo' => true,
|
|
|
|
|
'toc' => false,
|
|
|
|
|
'unknown' => false,
|
|
|
|
|
],
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @covers ResourceLoaderSkinModule
|
|
|
|
|
* @dataProvider provideInvalidFeatures
|
|
|
|
|
*/
|
|
|
|
|
public function testConstructInvalidFeatures( array $features ) {
|
|
|
|
|
$this->expectException( InvalidArgumentException::class );
|
|
|
|
|
$this->expectExceptionMessage( "Feature 'unknown' is not recognised" );
|
|
|
|
|
$module = new ResourceLoaderSkinModule( [
|
|
|
|
|
'features' => $features,
|
|
|
|
|
] );
|
|
|
|
|
}
|
2017-07-08 03:34:56 +00:00
|
|
|
}
|