4 * @group ResourceLoader
6 class ResourceLoaderSkinModuleTest
extends PHPUnit\Framework\TestCase
{
8 use MediaWikiCoversValidator
;
10 public static function provideGetStyles() {
11 // phpcs:disable Generic.Files.LineLength
15 'logo' => '/logo.png',
17 'all' => [ '.mw-wiki-logo { background-image: url(/logo.png); }' ],
22 'screen' => '.example {}',
24 'logo' => '/logo.png',
26 'screen' => [ '.example {}' ],
27 'all' => [ '.mw-wiki-logo { background-image: url(/logo.png); }' ],
34 '1.5x' => '/logo@1.5x.png',
35 '2x' => '/logo@2x.png',
39 .mw-wiki-logo { background-image: url(/logo.png); }
42 '(-webkit-min-device-pixel-ratio: 1.5), (min--moz-device-pixel-ratio: 1.5), (min-resolution: 1.5dppx), (min-resolution: 144dpi)' => [ <<<CSS
43 .mw-wiki-logo { background-image: url(/logo@1.5x.png);background-size: 135px auto; }
46 '(-webkit-min-device-pixel-ratio: 2), (min--moz-device-pixel-ratio: 2), (min-resolution: 2dppx), (min-resolution: 192dpi)' => [ <<<CSS
47 .mw-wiki-logo { background-image: url(/logo@2x.png);background-size: 135px auto; }
60 .mw-wiki-logo { background-image: url(/logo.png); }
63 .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; }
73 * @dataProvider provideGetStyles
74 * @covers ResourceLoaderSkinModule
76 public function testGetStyles( $parent, $logo, $expected ) {
77 $module = $this->getMockBuilder( ResourceLoaderSkinModule
::class )
78 ->disableOriginalConstructor()
79 ->setMethods( [ 'readStyleFiles', 'getConfig', 'getLogoData' ] )
81 $module->expects( $this->once() )->method( 'readStyleFiles' )
82 ->willReturn( $parent );
83 $module->expects( $this->once() )->method( 'getConfig' )
84 ->willReturn( new HashConfig() );
85 $module->expects( $this->once() )->method( 'getLogoData' )
86 ->willReturn( $logo );
88 $ctx = $this->getMockBuilder( ResourceLoaderContext
::class )
89 ->disableOriginalConstructor()->getMock();
93 $module->getStyles( $ctx )
98 * @covers ResourceLoaderSkinModule::isKnownEmpty
100 public function testIsKnownEmpty() {
101 $module = $this->getMockBuilder( ResourceLoaderSkinModule
::class )
102 ->disableOriginalConstructor()->setMethods( null )->getMock();
103 $ctx = $this->getMockBuilder( ResourceLoaderContext
::class )
104 ->disableOriginalConstructor()->getMock();
106 $this->assertFalse( $module->isKnownEmpty( $ctx ) );
110 * @dataProvider provideGetLogo
111 * @covers ResourceLoaderSkinModule::getLogo
113 public function testGetLogo( $config, $expected, $baseDir = null ) {
115 $oldIP = $GLOBALS['IP'];
116 $GLOBALS['IP'] = $baseDir;
117 $teardown = new Wikimedia\
ScopedCallback( function () use ( $oldIP ) {
118 $GLOBALS['IP'] = $oldIP;
124 ResourceLoaderSkinModule
::getLogo( new HashConfig( $config ) )
128 public function provideGetLogo() {
132 'ResourceBasePath' => '/w',
133 'Logo' => '/img/default.png',
136 'expected' => '/img/default.png',
138 'default and 2x' => [
140 'ResourceBasePath' => '/w',
141 'Logo' => '/img/default.png',
143 '2x' => '/img/two-x.png',
147 '1x' => '/img/default.png',
148 '2x' => '/img/two-x.png',
151 'default and all HiDPIs' => [
153 'ResourceBasePath' => '/w',
154 'Logo' => '/img/default.png',
156 '1.5x' => '/img/one-point-five.png',
157 '2x' => '/img/two-x.png',
161 '1x' => '/img/default.png',
162 '1.5x' => '/img/one-point-five.png',
163 '2x' => '/img/two-x.png',
166 'default and SVG' => [
168 'ResourceBasePath' => '/w',
169 'Logo' => '/img/default.png',
171 'svg' => '/img/vector.svg',
175 '1x' => '/img/default.png',
176 'svg' => '/img/vector.svg',
181 'ResourceBasePath' => '/w',
182 'Logo' => '/img/default.png',
184 '1.5x' => '/img/one-point-five.png',
185 '2x' => '/img/two-x.png',
186 'svg' => '/img/vector.svg',
190 '1x' => '/img/default.png',
191 'svg' => '/img/vector.svg',
196 'ResourceBasePath' => '/w',
197 'Logo' => '/w/test.jpg',
199 'UploadPath' => '/w/images',
201 'expected' => '/w/test.jpg?edcf2',
202 'baseDir' => dirname( dirname( __DIR__
) ) . '/data/media',