MediaWiki REL1_31
ResourceLoaderSkinModuleTest.php
Go to the documentation of this file.
1<?php
2
6class ResourceLoaderSkinModuleTest extends PHPUnit\Framework\TestCase {
7
8 use MediaWikiCoversValidator;
9
10 public static function provideGetStyles() {
11 // phpcs:disable Generic.Files.LineLength
12 return [
13 [
14 'parent' => [],
15 'logo' => '/logo.png',
16 'expected' => [
17 'all' => [ '.mw-wiki-logo { background-image: url(/logo.png); }' ],
18 ],
19 ],
20 [
21 'parent' => [
22 'screen' => '.example {}',
23 ],
24 'logo' => '/logo.png',
25 'expected' => [
26 'screen' => [ '.example {}' ],
27 'all' => [ '.mw-wiki-logo { background-image: url(/logo.png); }' ],
28 ],
29 ],
30 [
31 'parent' => [],
32 'logo' => [
33 '1x' => '/logo.png',
34 '1.5x' => '/logo@1.5x.png',
35 '2x' => '/logo@2x.png',
36 ],
37 'expected' => [
38 'all' => [ <<<CSS
39.mw-wiki-logo { background-image: url(/logo.png); }
40CSS
41 ],
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; }
44CSS
45 ],
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; }
48CSS
49 ],
50 ],
51 ],
52 [
53 'parent' => [],
54 'logo' => [
55 '1x' => '/logo.png',
56 'svg' => '/logo.svg',
57 ],
58 'expected' => [
59 'all' => [ <<<CSS
60.mw-wiki-logo { background-image: url(/logo.png); }
61CSS
62 , <<<CSS
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; }
64CSS
65 ],
66 ],
67 ],
68 ];
69 // phpcs:enable
70 }
71
77 public function testGetStyles( $parent, $logo, $expected ) {
78 $module = $this->getMockBuilder( ResourceLoaderSkinModule::class )
79 ->disableOriginalConstructor()
80 ->setMethods( [ 'readStyleFiles', 'getConfig', 'getLogoData' ] )
81 ->getMock();
82 $module->expects( $this->once() )->method( 'readStyleFiles' )
83 ->willReturn( $parent );
84 $module->expects( $this->once() )->method( 'getConfig' )
85 ->willReturn( new HashConfig() );
86 $module->expects( $this->once() )->method( 'getLogoData' )
87 ->willReturn( $logo );
88
89 $ctx = $this->getMockBuilder( ResourceLoaderContext::class )
90 ->disableOriginalConstructor()->getMock();
91
92 $this->assertEquals(
93 $expected,
94 $module->getStyles( $ctx )
95 );
96 }
97
101 public function testIsKnownEmpty() {
102 $module = $this->getMockBuilder( ResourceLoaderSkinModule::class )
103 ->disableOriginalConstructor()->setMethods( null )->getMock();
104 $ctx = $this->getMockBuilder( ResourceLoaderContext::class )
105 ->disableOriginalConstructor()->getMock();
106
107 $this->assertFalse( $module->isKnownEmpty( $ctx ) );
108 }
109
114 public function testGetLogo( $config, $expected, $baseDir = null ) {
115 if ( $baseDir ) {
116 $oldIP = $GLOBALS['IP'];
117 $GLOBALS['IP'] = $baseDir;
118 $teardown = new Wikimedia\ScopedCallback( function () use ( $oldIP ) {
119 $GLOBALS['IP'] = $oldIP;
120 } );
121 }
122
123 $this->assertEquals(
124 $expected,
126 );
127 }
128
129 public function provideGetLogo() {
130 return [
131 'simple' => [
132 'config' => [
133 'ResourceBasePath' => '/w',
134 'Logo' => '/img/default.png',
135 'LogoHD' => false,
136 ],
137 'expected' => '/img/default.png',
138 ],
139 'default and 2x' => [
140 'config' => [
141 'ResourceBasePath' => '/w',
142 'Logo' => '/img/default.png',
143 'LogoHD' => [
144 '2x' => '/img/two-x.png',
145 ],
146 ],
147 'expected' => [
148 '1x' => '/img/default.png',
149 '2x' => '/img/two-x.png',
150 ],
151 ],
152 'default and all HiDPIs' => [
153 'config' => [
154 'ResourceBasePath' => '/w',
155 'Logo' => '/img/default.png',
156 'LogoHD' => [
157 '1.5x' => '/img/one-point-five.png',
158 '2x' => '/img/two-x.png',
159 ],
160 ],
161 'expected' => [
162 '1x' => '/img/default.png',
163 '1.5x' => '/img/one-point-five.png',
164 '2x' => '/img/two-x.png',
165 ],
166 ],
167 'default and SVG' => [
168 'config' => [
169 'ResourceBasePath' => '/w',
170 'Logo' => '/img/default.png',
171 'LogoHD' => [
172 'svg' => '/img/vector.svg',
173 ],
174 ],
175 'expected' => [
176 '1x' => '/img/default.png',
177 'svg' => '/img/vector.svg',
178 ],
179 ],
180 'everything' => [
181 'config' => [
182 'ResourceBasePath' => '/w',
183 'Logo' => '/img/default.png',
184 'LogoHD' => [
185 '1.5x' => '/img/one-point-five.png',
186 '2x' => '/img/two-x.png',
187 'svg' => '/img/vector.svg',
188 ],
189 ],
190 'expected' => [
191 '1x' => '/img/default.png',
192 'svg' => '/img/vector.svg',
193 ],
194 ],
195 'versioned url' => [
196 'config' => [
197 'ResourceBasePath' => '/w',
198 'Logo' => '/w/test.jpg',
199 'LogoHD' => false,
200 'UploadPath' => '/w/images',
201 ],
202 'expected' => '/w/test.jpg?edcf2',
203 'baseDir' => dirname( dirname( __DIR__ ) ) . '/data/media',
204 ],
205 ];
206 }
207}
$GLOBALS['IP']
A Config instance which stores all settings as a member variable.
testGetStyles( $parent, $logo, $expected)
provideGetStyles ResourceLoaderSkinModule::normalizeStyles ResourceLoaderSkinModule::getStyles
testIsKnownEmpty()
ResourceLoaderSkinModule::isKnownEmpty.
testGetLogo( $config, $expected, $baseDir=null)
provideGetLogo ResourceLoaderSkinModule::getLogo