2017-07-08 03:34:56 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @group ResourceLoader
|
|
|
|
|
*/
|
2018-02-17 12:29:13 +00:00
|
|
|
class ResourceLoaderSkinModuleTest extends PHPUnit\Framework\TestCase {
|
2017-07-08 03:34:56 +00:00
|
|
|
|
2017-12-29 23:22:37 +00:00
|
|
|
use MediaWikiCoversValidator;
|
|
|
|
|
|
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 )
|
|
|
|
|
->disableOriginalConstructor()
|
2017-05-22 18:12:26 +00:00
|
|
|
->setMethods( [ 'readStyleFiles', 'getConfig', '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( 'getConfig' )
|
|
|
|
|
->willReturn( new HashConfig() );
|
|
|
|
|
$module->expects( $this->once() )->method( 'getLogoData' )
|
|
|
|
|
->willReturn( $logo );
|
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
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @covers ResourceLoaderSkinModule::isKnownEmpty
|
|
|
|
|
*/
|
|
|
|
|
public function testIsKnownEmpty() {
|
|
|
|
|
$module = $this->getMockBuilder( ResourceLoaderSkinModule::class )
|
|
|
|
|
->disableOriginalConstructor()->setMethods( null )->getMock();
|
|
|
|
|
$ctx = $this->getMockBuilder( ResourceLoaderContext::class )
|
|
|
|
|
->disableOriginalConstructor()->getMock();
|
|
|
|
|
|
|
|
|
|
$this->assertFalse( $module->isKnownEmpty( $ctx ) );
|
|
|
|
|
}
|
2017-05-22 18:12:26 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @dataProvider provideGetLogo
|
|
|
|
|
* @covers ResourceLoaderSkinModule::getLogo
|
|
|
|
|
*/
|
|
|
|
|
public function testGetLogo( $config, $expected, $baseDir = null ) {
|
|
|
|
|
if ( $baseDir ) {
|
|
|
|
|
$oldIP = $GLOBALS['IP'];
|
|
|
|
|
$GLOBALS['IP'] = $baseDir;
|
|
|
|
|
$teardown = new Wikimedia\ScopedCallback( function () use ( $oldIP ) {
|
|
|
|
|
$GLOBALS['IP'] = $oldIP;
|
|
|
|
|
} );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$this->assertEquals(
|
|
|
|
|
$expected,
|
|
|
|
|
ResourceLoaderSkinModule::getLogo( new HashConfig( $config ) )
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function provideGetLogo() {
|
|
|
|
|
return [
|
|
|
|
|
'simple' => [
|
|
|
|
|
'config' => [
|
|
|
|
|
'ResourceBasePath' => '/w',
|
|
|
|
|
'Logo' => '/img/default.png',
|
|
|
|
|
'LogoHD' => false,
|
|
|
|
|
],
|
|
|
|
|
'expected' => '/img/default.png',
|
|
|
|
|
],
|
|
|
|
|
'default and 2x' => [
|
|
|
|
|
'config' => [
|
|
|
|
|
'ResourceBasePath' => '/w',
|
|
|
|
|
'Logo' => '/img/default.png',
|
|
|
|
|
'LogoHD' => [
|
|
|
|
|
'2x' => '/img/two-x.png',
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
'expected' => [
|
|
|
|
|
'1x' => '/img/default.png',
|
|
|
|
|
'2x' => '/img/two-x.png',
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
'default and all HiDPIs' => [
|
|
|
|
|
'config' => [
|
|
|
|
|
'ResourceBasePath' => '/w',
|
|
|
|
|
'Logo' => '/img/default.png',
|
|
|
|
|
'LogoHD' => [
|
|
|
|
|
'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',
|
|
|
|
|
'Logo' => '/img/default.png',
|
|
|
|
|
'LogoHD' => [
|
|
|
|
|
'svg' => '/img/vector.svg',
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
'expected' => [
|
|
|
|
|
'1x' => '/img/default.png',
|
|
|
|
|
'svg' => '/img/vector.svg',
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
'everything' => [
|
|
|
|
|
'config' => [
|
|
|
|
|
'ResourceBasePath' => '/w',
|
|
|
|
|
'Logo' => '/img/default.png',
|
|
|
|
|
'LogoHD' => [
|
|
|
|
|
'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',
|
|
|
|
|
'Logo' => '/w/test.jpg',
|
|
|
|
|
'LogoHD' => false,
|
|
|
|
|
'UploadPath' => '/w/images',
|
|
|
|
|
],
|
|
|
|
|
'expected' => '/w/test.jpg?edcf2',
|
|
|
|
|
'baseDir' => dirname( dirname( __DIR__ ) ) . '/data/media',
|
|
|
|
|
],
|
|
|
|
|
];
|
|
|
|
|
}
|
2017-07-08 03:34:56 +00:00
|
|
|
}
|