MediaWiki REL1_33
ResourceLoaderSkinModuleTest.php
Go to the documentation of this file.
1<?php
2
4
9
10 use MediaWikiCoversValidator;
11
12 public static function provideGetStyles() {
13 // phpcs:disable Generic.Files.LineLength
14 return [
15 [
16 'parent' => [],
17 'logo' => '/logo.png',
18 'expected' => [
19 'all' => [ '.mw-wiki-logo { background-image: url(/logo.png); }' ],
20 ],
21 ],
22 [
23 'parent' => [
24 'screen' => '.example {}',
25 ],
26 'logo' => '/logo.png',
27 'expected' => [
28 'screen' => [ '.example {}' ],
29 'all' => [ '.mw-wiki-logo { background-image: url(/logo.png); }' ],
30 ],
31 ],
32 [
33 'parent' => [],
34 'logo' => [
35 '1x' => '/logo.png',
36 '1.5x' => '/logo@1.5x.png',
37 '2x' => '/logo@2x.png',
38 ],
39 'expected' => [
40 'all' => [ <<<CSS
41.mw-wiki-logo { background-image: url(/logo.png); }
42CSS
43 ],
44 '(-webkit-min-device-pixel-ratio: 1.5), (min--moz-device-pixel-ratio: 1.5), (min-resolution: 1.5dppx), (min-resolution: 144dpi)' => [ <<<CSS
45.mw-wiki-logo { background-image: url(/logo@1.5x.png);background-size: 135px auto; }
46CSS
47 ],
48 '(-webkit-min-device-pixel-ratio: 2), (min--moz-device-pixel-ratio: 2), (min-resolution: 2dppx), (min-resolution: 192dpi)' => [ <<<CSS
49.mw-wiki-logo { background-image: url(/logo@2x.png);background-size: 135px auto; }
50CSS
51 ],
52 ],
53 ],
54 [
55 'parent' => [],
56 'logo' => [
57 '1x' => '/logo.png',
58 'svg' => '/logo.svg',
59 ],
60 'expected' => [
61 'all' => [ <<<CSS
62.mw-wiki-logo { background-image: url(/logo.png); }
63CSS
64 , <<<CSS
65.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; }
66CSS
67 ],
68 ],
69 ],
70 ];
71 // phpcs:enable
72 }
73
78 public function testGetStyles( $parent, $logo, $expected ) {
79 $module = $this->getMockBuilder( ResourceLoaderSkinModule::class )
80 ->disableOriginalConstructor()
81 ->setMethods( [ 'readStyleFiles', 'getConfig', 'getLogoData' ] )
82 ->getMock();
83 $module->expects( $this->once() )->method( 'readStyleFiles' )
84 ->willReturn( $parent );
85 $module->expects( $this->once() )->method( 'getConfig' )
86 ->willReturn( new HashConfig() );
87 $module->expects( $this->once() )->method( 'getLogoData' )
88 ->willReturn( $logo );
89
90 $ctx = $this->getMockBuilder( ResourceLoaderContext::class )
91 ->disableOriginalConstructor()->getMock();
92
93 $this->assertEquals(
94 $expected,
95 $module->getStyles( $ctx )
96 );
97 }
98
102 public function testIsKnownEmpty() {
103 $module = $this->getMockBuilder( ResourceLoaderSkinModule::class )
104 ->disableOriginalConstructor()->setMethods( null )->getMock();
105 $ctx = $this->getMockBuilder( ResourceLoaderContext::class )
106 ->disableOriginalConstructor()->getMock();
107
108 $this->assertFalse( $module->isKnownEmpty( $ctx ) );
109 }
110
115 public function testGetLogoData( $config, $expected, $baseDir = null ) {
116 if ( $baseDir ) {
117 $this->setMwGlobals( 'IP', $baseDir );
118 }
119 // Allow testing of protected method
120 $module = TestingAccessWrapper::newFromObject( new ResourceLoaderSkinModule() );
121
122 $this->assertEquals(
123 $expected,
124 $module->getLogoData( new HashConfig( $config ) )
125 );
126 }
127
128 public function provideGetLogoData() {
129 return [
130 'simple' => [
131 'config' => [
132 'ResourceBasePath' => '/w',
133 'Logo' => '/img/default.png',
134 'LogoHD' => false,
135 ],
136 'expected' => '/img/default.png',
137 ],
138 'default and 2x' => [
139 'config' => [
140 'ResourceBasePath' => '/w',
141 'Logo' => '/img/default.png',
142 'LogoHD' => [
143 '2x' => '/img/two-x.png',
144 ],
145 ],
146 'expected' => [
147 '1x' => '/img/default.png',
148 '2x' => '/img/two-x.png',
149 ],
150 ],
151 'default and all HiDPIs' => [
152 'config' => [
153 'ResourceBasePath' => '/w',
154 'Logo' => '/img/default.png',
155 'LogoHD' => [
156 '1.5x' => '/img/one-point-five.png',
157 '2x' => '/img/two-x.png',
158 ],
159 ],
160 'expected' => [
161 '1x' => '/img/default.png',
162 '1.5x' => '/img/one-point-five.png',
163 '2x' => '/img/two-x.png',
164 ],
165 ],
166 'default and SVG' => [
167 'config' => [
168 'ResourceBasePath' => '/w',
169 'Logo' => '/img/default.png',
170 'LogoHD' => [
171 'svg' => '/img/vector.svg',
172 ],
173 ],
174 'expected' => [
175 '1x' => '/img/default.png',
176 'svg' => '/img/vector.svg',
177 ],
178 ],
179 'everything' => [
180 'config' => [
181 'ResourceBasePath' => '/w',
182 'Logo' => '/img/default.png',
183 'LogoHD' => [
184 '1.5x' => '/img/one-point-five.png',
185 '2x' => '/img/two-x.png',
186 'svg' => '/img/vector.svg',
187 ],
188 ],
189 'expected' => [
190 '1x' => '/img/default.png',
191 'svg' => '/img/vector.svg',
192 ],
193 ],
194 'versioned url' => [
195 'config' => [
196 'ResourceBasePath' => '/w',
197 'Logo' => '/w/test.jpg',
198 'LogoHD' => false,
199 'UploadPath' => '/w/images',
200 ],
201 'expected' => '/w/test.jpg?edcf2',
202 'baseDir' => dirname( dirname( __DIR__ ) ) . '/data/media',
203 ],
204 ];
205 }
206
213 public function testPreloadLinkHeaders( $config, $result ) {
214 $this->setMwGlobals( $config );
215 $ctx = $this->getMockBuilder( ResourceLoaderContext::class )
216 ->disableOriginalConstructor()->getMock();
217 $module = new ResourceLoaderSkinModule();
218
219 $this->assertEquals( [ $result ], $module->getHeaders( $ctx ) );
220 }
221
222 public function providePreloadLinks() {
223 return [
224 [
225 [
226 'wgResourceBasePath' => '/w',
227 'wgLogo' => '/img/default.png',
228 'wgLogoHD' => [
229 '1.5x' => '/img/one-point-five.png',
230 '2x' => '/img/two-x.png',
231 ],
232 ],
233 'Link: </img/default.png>;rel=preload;as=image;media=' .
234 'not all and (min-resolution: 1.5dppx),' .
235 '</img/one-point-five.png>;rel=preload;as=image;media=' .
236 '(min-resolution: 1.5dppx) and (max-resolution: 1.999999dppx),' .
237 '</img/two-x.png>;rel=preload;as=image;media=(min-resolution: 2dppx)'
238 ],
239 [
240 [
241 'wgResourceBasePath' => '/w',
242 'wgLogo' => '/img/default.png',
243 'wgLogoHD' => false,
244 ],
245 'Link: </img/default.png>;rel=preload;as=image'
246 ],
247 [
248 [
249 'wgResourceBasePath' => '/w',
250 'wgLogo' => '/img/default.png',
251 'wgLogoHD' => [
252 '2x' => '/img/two-x.png',
253 ],
254 ],
255 'Link: </img/default.png>;rel=preload;as=image;media=' .
256 'not all and (min-resolution: 2dppx),' .
257 '</img/two-x.png>;rel=preload;as=image;media=(min-resolution: 2dppx)'
258 ],
259 [
260 [
261 'wgResourceBasePath' => '/w',
262 'wgLogo' => '/img/default.png',
263 'wgLogoHD' => [
264 'svg' => '/img/vector.svg',
265 ],
266 ],
267 'Link: </img/vector.svg>;rel=preload;as=image'
268
269 ],
270 [
271 [
272 'wgResourceBasePath' => '/w',
273 'wgLogo' => '/w/test.jpg',
274 'wgLogoHD' => false,
275 'wgUploadPath' => '/w/images',
276 'IP' => dirname( dirname( __DIR__ ) ) . '/data/media',
277 ],
278 'Link: </w/test.jpg?edcf2>;rel=preload;as=image',
279 ],
280 ];
281 }
282}
and that you know you can do these things To protect your we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights These restrictions translate to certain responsibilities for you if you distribute copies of the or if you modify it For if you distribute copies of such a whether gratis or for a you must give the recipients all the rights that you have You must make sure that receive or can get the source code And you must show them these terms so they know their rights We protect your rights with two and(2) offer you this license which gives you legal permission to copy
A Config instance which stores all settings as a member variable.
setMwGlobals( $pairs, $value=null)
Sets a global, maintaining a stashed version of the previous global to be restored in tearDown.
testGetStyles( $parent, $logo, $expected)
provideGetStyles ResourceLoaderSkinModule
testGetLogoData( $config, $expected, $baseDir=null)
provideGetLogoData ResourceLoaderSkinModule::getLogoData
testIsKnownEmpty()
ResourceLoaderSkinModule::isKnownEmpty.
testPreloadLinkHeaders( $config, $result)
providePreloadLinks ResourceLoaderSkinModule::getPreloadLinks ResourceLoaderSkinModule::getLogoPreloa...
$parent