Merge "Date range filtering in Special:NewFiles"
[lhc/web/wiklou.git] / tests / phpunit / includes / OutputPageTest.php
1 <?php
2
3 use Wikimedia\TestingAccessWrapper;
4
5 /**
6 *
7 * @author Matthew Flaschen
8 *
9 * @group Database
10 * @group Output
11 *
12 * @todo factor tests in this class into providers and test methods
13 */
14 class OutputPageTest extends MediaWikiTestCase {
15 const SCREEN_MEDIA_QUERY = 'screen and (min-width: 982px)';
16 const SCREEN_ONLY_MEDIA_QUERY = 'only screen and (min-width: 982px)';
17
18 /**
19 * @covers OutputPage::addMeta
20 * @covers OutputPage::getMetaTags
21 * @covers OutputPage::getHeadLinksArray
22 */
23 public function testMetaTags() {
24 $outputPage = $this->newInstance();
25 $outputPage->addMeta( 'http:expires', '0' );
26 $outputPage->addMeta( 'keywords', 'first' );
27 $outputPage->addMeta( 'keywords', 'second' );
28 $outputPage->addMeta( 'og:title', 'Ta-duh' );
29
30 $expected = [
31 [ 'http:expires', '0' ],
32 [ 'keywords', 'first' ],
33 [ 'keywords', 'second' ],
34 [ 'og:title', 'Ta-duh' ],
35 ];
36 $this->assertSame( $expected, $outputPage->getMetaTags() );
37
38 $links = $outputPage->getHeadLinksArray();
39 $this->assertContains( '<meta http-equiv="expires" content="0"/>', $links );
40 $this->assertContains( '<meta name="keywords" content="first"/>', $links );
41 $this->assertContains( '<meta name="keywords" content="second"/>', $links );
42 $this->assertContains( '<meta property="og:title" content="Ta-duh"/>', $links );
43 $this->assertArrayNotHasKey( 'meta-robots', $links );
44 }
45
46 /**
47 * @covers OutputPage::setIndexPolicy
48 * @covers OutputPage::setFollowPolicy
49 * @covers OutputPage::getHeadLinksArray
50 */
51 public function testRobotsPolicies() {
52 $outputPage = $this->newInstance();
53 $outputPage->setIndexPolicy( 'noindex' );
54 $outputPage->setFollowPolicy( 'nofollow' );
55
56 $links = $outputPage->getHeadLinksArray();
57 $this->assertContains( '<meta name="robots" content="noindex,nofollow"/>', $links );
58 }
59
60 /**
61 * Tests a particular case of transformCssMedia, using the given input, globals,
62 * expected return, and message
63 *
64 * Asserts that $expectedReturn is returned.
65 *
66 * options['printableQuery'] - value of query string for printable, or omitted for none
67 * options['handheldQuery'] - value of query string for handheld, or omitted for none
68 * options['media'] - passed into the method under the same name
69 * options['expectedReturn'] - expected return value
70 * options['message'] - PHPUnit message for assertion
71 *
72 * @param array $args Key-value array of arguments as shown above
73 */
74 protected function assertTransformCssMediaCase( $args ) {
75 $queryData = [];
76 if ( isset( $args['printableQuery'] ) ) {
77 $queryData['printable'] = $args['printableQuery'];
78 }
79
80 if ( isset( $args['handheldQuery'] ) ) {
81 $queryData['handheld'] = $args['handheldQuery'];
82 }
83
84 $fauxRequest = new FauxRequest( $queryData, false );
85 $this->setMwGlobals( [
86 'wgRequest' => $fauxRequest,
87 ] );
88
89 $actualReturn = OutputPage::transformCssMedia( $args['media'] );
90 $this->assertSame( $args['expectedReturn'], $actualReturn, $args['message'] );
91 }
92
93 /**
94 * Tests print requests
95 * @covers OutputPage::transformCssMedia
96 */
97 public function testPrintRequests() {
98 $this->assertTransformCssMediaCase( [
99 'printableQuery' => '1',
100 'media' => 'screen',
101 'expectedReturn' => null,
102 'message' => 'On printable request, screen returns null'
103 ] );
104
105 $this->assertTransformCssMediaCase( [
106 'printableQuery' => '1',
107 'media' => self::SCREEN_MEDIA_QUERY,
108 'expectedReturn' => null,
109 'message' => 'On printable request, screen media query returns null'
110 ] );
111
112 $this->assertTransformCssMediaCase( [
113 'printableQuery' => '1',
114 'media' => self::SCREEN_ONLY_MEDIA_QUERY,
115 'expectedReturn' => null,
116 'message' => 'On printable request, screen media query with only returns null'
117 ] );
118
119 $this->assertTransformCssMediaCase( [
120 'printableQuery' => '1',
121 'media' => 'print',
122 'expectedReturn' => '',
123 'message' => 'On printable request, media print returns empty string'
124 ] );
125 }
126
127 /**
128 * Tests screen requests, without either query parameter set
129 * @covers OutputPage::transformCssMedia
130 */
131 public function testScreenRequests() {
132 $this->assertTransformCssMediaCase( [
133 'media' => 'screen',
134 'expectedReturn' => 'screen',
135 'message' => 'On screen request, screen media type is preserved'
136 ] );
137
138 $this->assertTransformCssMediaCase( [
139 'media' => 'handheld',
140 'expectedReturn' => 'handheld',
141 'message' => 'On screen request, handheld media type is preserved'
142 ] );
143
144 $this->assertTransformCssMediaCase( [
145 'media' => self::SCREEN_MEDIA_QUERY,
146 'expectedReturn' => self::SCREEN_MEDIA_QUERY,
147 'message' => 'On screen request, screen media query is preserved.'
148 ] );
149
150 $this->assertTransformCssMediaCase( [
151 'media' => self::SCREEN_ONLY_MEDIA_QUERY,
152 'expectedReturn' => self::SCREEN_ONLY_MEDIA_QUERY,
153 'message' => 'On screen request, screen media query with only is preserved.'
154 ] );
155
156 $this->assertTransformCssMediaCase( [
157 'media' => 'print',
158 'expectedReturn' => 'print',
159 'message' => 'On screen request, print media type is preserved'
160 ] );
161 }
162
163 /**
164 * Tests handheld behavior
165 * @covers OutputPage::transformCssMedia
166 */
167 public function testHandheld() {
168 $this->assertTransformCssMediaCase( [
169 'handheldQuery' => '1',
170 'media' => 'handheld',
171 'expectedReturn' => '',
172 'message' => 'On request with handheld querystring and media is handheld, returns empty string'
173 ] );
174
175 $this->assertTransformCssMediaCase( [
176 'handheldQuery' => '1',
177 'media' => 'screen',
178 'expectedReturn' => null,
179 'message' => 'On request with handheld querystring and media is screen, returns null'
180 ] );
181 }
182
183 public static function provideTransformFilePath() {
184 $baseDir = dirname( __DIR__ ) . '/data/media';
185 return [
186 // File that matches basePath, and exists. Hash found and appended.
187 [
188 'baseDir' => $baseDir, 'basePath' => '/w',
189 '/w/test.jpg',
190 '/w/test.jpg?edcf2'
191 ],
192 // File that matches basePath, but not found on disk. Empty query.
193 [
194 'baseDir' => $baseDir, 'basePath' => '/w',
195 '/w/unknown.png',
196 '/w/unknown.png?'
197 ],
198 // File not matching basePath. Ignored.
199 [
200 'baseDir' => $baseDir, 'basePath' => '/w',
201 '/files/test.jpg'
202 ],
203 // Empty string. Ignored.
204 [
205 'baseDir' => $baseDir, 'basePath' => '/w',
206 '',
207 ''
208 ],
209 // Similar path, but with domain component. Ignored.
210 [
211 'baseDir' => $baseDir, 'basePath' => '/w',
212 '//example.org/w/test.jpg'
213 ],
214 [
215 'baseDir' => $baseDir, 'basePath' => '/w',
216 'https://example.org/w/test.jpg'
217 ],
218 // Unrelated path with domain component. Ignored.
219 [
220 'baseDir' => $baseDir, 'basePath' => '/w',
221 'https://example.org/files/test.jpg'
222 ],
223 [
224 'baseDir' => $baseDir, 'basePath' => '/w',
225 '//example.org/files/test.jpg'
226 ],
227 // Unrelated path with domain, and empty base path (root mw install). Ignored.
228 [
229 'baseDir' => $baseDir, 'basePath' => '',
230 'https://example.org/files/test.jpg'
231 ],
232 [
233 'baseDir' => $baseDir, 'basePath' => '',
234 // T155310
235 '//example.org/files/test.jpg'
236 ],
237 // Check UploadPath before ResourceBasePath (T155146)
238 [
239 'baseDir' => dirname( $baseDir ), 'basePath' => '',
240 'uploadDir' => $baseDir, 'uploadPath' => '/images',
241 '/images/test.jpg',
242 '/images/test.jpg?edcf2'
243 ],
244 ];
245 }
246
247 /**
248 * @dataProvider provideTransformFilePath
249 * @covers OutputPage::transformFilePath
250 * @covers OutputPage::transformResourcePath
251 */
252 public function testTransformResourcePath( $baseDir, $basePath, $uploadDir = null,
253 $uploadPath = null, $path = null, $expected = null
254 ) {
255 if ( $path === null ) {
256 // Skip optional $uploadDir and $uploadPath
257 $path = $uploadDir;
258 $expected = $uploadPath;
259 $uploadDir = "$baseDir/images";
260 $uploadPath = "$basePath/images";
261 }
262 $this->setMwGlobals( 'IP', $baseDir );
263 $conf = new HashConfig( [
264 'ResourceBasePath' => $basePath,
265 'UploadDirectory' => $uploadDir,
266 'UploadPath' => $uploadPath,
267 ] );
268
269 MediaWiki\suppressWarnings();
270 $actual = OutputPage::transformResourcePath( $conf, $path );
271 MediaWiki\restoreWarnings();
272
273 $this->assertEquals( $expected ?: $path, $actual );
274 }
275
276 public static function provideMakeResourceLoaderLink() {
277 // @codingStandardsIgnoreStart Generic.Files.LineLength
278 return [
279 // Single only=scripts load
280 [
281 [ 'test.foo', ResourceLoaderModule::TYPE_SCRIPTS ],
282 "<script>(window.RLQ=window.RLQ||[]).push(function(){"
283 . 'mw.loader.load("http://127.0.0.1:8080/w/load.php?debug=false\u0026lang=en\u0026modules=test.foo\u0026only=scripts\u0026skin=fallback");'
284 . "});</script>"
285 ],
286 // Multiple only=styles load
287 [
288 [ [ 'test.baz', 'test.foo', 'test.bar' ], ResourceLoaderModule::TYPE_STYLES ],
289
290 '<link rel="stylesheet" href="http://127.0.0.1:8080/w/load.php?debug=false&amp;lang=en&amp;modules=test.bar%2Cbaz%2Cfoo&amp;only=styles&amp;skin=fallback"/>'
291 ],
292 // Private embed (only=scripts)
293 [
294 [ 'test.quux', ResourceLoaderModule::TYPE_SCRIPTS ],
295 "<script>(window.RLQ=window.RLQ||[]).push(function(){"
296 . "mw.test.baz({token:123});mw.loader.state({\"test.quux\":\"ready\"});"
297 . "});</script>"
298 ],
299 ];
300 // @codingStandardsIgnoreEnd
301 }
302
303 /**
304 * See ResourceLoaderClientHtmlTest for full coverage.
305 *
306 * @dataProvider provideMakeResourceLoaderLink
307 * @covers OutputPage::makeResourceLoaderLink
308 */
309 public function testMakeResourceLoaderLink( $args, $expectedHtml ) {
310 $this->setMwGlobals( [
311 'wgResourceLoaderDebug' => false,
312 'wgLoadScript' => 'http://127.0.0.1:8080/w/load.php',
313 ] );
314 $class = new ReflectionClass( 'OutputPage' );
315 $method = $class->getMethod( 'makeResourceLoaderLink' );
316 $method->setAccessible( true );
317 $ctx = new RequestContext();
318 $ctx->setSkin( SkinFactory::getDefaultInstance()->makeSkin( 'fallback' ) );
319 $ctx->setLanguage( 'en' );
320 $out = new OutputPage( $ctx );
321 $rl = $out->getResourceLoader();
322 $rl->setMessageBlobStore( new NullMessageBlobStore() );
323 $rl->register( [
324 'test.foo' => new ResourceLoaderTestModule( [
325 'script' => 'mw.test.foo( { a: true } );',
326 'styles' => '.mw-test-foo { content: "style"; }',
327 ] ),
328 'test.bar' => new ResourceLoaderTestModule( [
329 'script' => 'mw.test.bar( { a: true } );',
330 'styles' => '.mw-test-bar { content: "style"; }',
331 ] ),
332 'test.baz' => new ResourceLoaderTestModule( [
333 'script' => 'mw.test.baz( { a: true } );',
334 'styles' => '.mw-test-baz { content: "style"; }',
335 ] ),
336 'test.quux' => new ResourceLoaderTestModule( [
337 'script' => 'mw.test.baz( { token: 123 } );',
338 'styles' => '/* pref-animate=off */ .mw-icon { transition: none; }',
339 'group' => 'private',
340 ] ),
341 ] );
342 $links = $method->invokeArgs( $out, $args );
343 $actualHtml = strval( $links );
344 $this->assertEquals( $expectedHtml, $actualHtml );
345 }
346
347 public static function provideBuildExemptModules() {
348 return [
349 'empty' => [
350 'exemptStyleModules' => [],
351 '<meta name="ResourceLoaderDynamicStyles" content=""/>',
352 ],
353 'empty sets' => [
354 'exemptStyleModules' => [ 'site' => [], 'noscript' => [], 'private' => [], 'user' => [] ],
355 '<meta name="ResourceLoaderDynamicStyles" content=""/>',
356 ],
357 // @codingStandardsIgnoreStart Generic.Files.LineLength
358 'default logged-out' => [
359 'exemptStyleModules' => [ 'site' => [ 'site.styles' ] ],
360 '<meta name="ResourceLoaderDynamicStyles" content=""/>' . "\n" .
361 '<link rel="stylesheet" href="/w/load.php?debug=false&amp;lang=en&amp;modules=site.styles&amp;only=styles&amp;skin=fallback"/>',
362 ],
363 'default logged-in' => [
364 'exemptStyleModules' => [ 'site' => [ 'site.styles' ], 'user' => [ 'user.styles' ] ],
365 '<meta name="ResourceLoaderDynamicStyles" content=""/>' . "\n" .
366 '<link rel="stylesheet" href="/w/load.php?debug=false&amp;lang=en&amp;modules=site.styles&amp;only=styles&amp;skin=fallback"/>' . "\n" .
367 '<link rel="stylesheet" href="/w/load.php?debug=false&amp;lang=en&amp;modules=user.styles&amp;only=styles&amp;skin=fallback&amp;version=1e9z0ox"/>',
368 ],
369 'custom modules' => [
370 'exemptStyleModules' => [
371 'site' => [ 'site.styles', 'example.site.a', 'example.site.b' ],
372 'user' => [ 'user.styles', 'example.user' ],
373 ],
374 '<meta name="ResourceLoaderDynamicStyles" content=""/>' . "\n" .
375 '<link rel="stylesheet" href="/w/load.php?debug=false&amp;lang=en&amp;modules=example.site.a%2Cb%7Csite.styles&amp;only=styles&amp;skin=fallback"/>' . "\n" .
376 '<link rel="stylesheet" href="/w/load.php?debug=false&amp;lang=en&amp;modules=example.user%7Cuser.styles&amp;only=styles&amp;skin=fallback&amp;version=17f1vjw"/>',
377 ],
378 // @codingStandardsIgnoreEnd Generic.Files.LineLength
379 ];
380 }
381
382 /**
383 * @dataProvider provideBuildExemptModules
384 * @covers OutputPage::buildExemptModules
385 */
386 public function testBuildExemptModules( array $exemptStyleModules, $expect ) {
387 $this->setMwGlobals( [
388 'wgResourceLoaderDebug' => false,
389 'wgLoadScript' => '/w/load.php',
390 // Stub wgCacheEpoch as it influences getVersionHash used for the
391 // urls in the expected HTML
392 'wgCacheEpoch' => '20140101000000',
393 ] );
394
395 // Set up stubs
396 $ctx = new RequestContext();
397 $ctx->setSkin( SkinFactory::getDefaultInstance()->makeSkin( 'fallback' ) );
398 $ctx->setLanguage( 'en' );
399 $outputPage = $this->getMockBuilder( 'OutputPage' )
400 ->setConstructorArgs( [ $ctx ] )
401 ->setMethods( [ 'isUserCssPreview', 'buildCssLinksArray' ] )
402 ->getMock();
403 $outputPage->expects( $this->any() )
404 ->method( 'isUserCssPreview' )
405 ->willReturn( false );
406 $outputPage->expects( $this->any() )
407 ->method( 'buildCssLinksArray' )
408 ->willReturn( [] );
409 $rl = $outputPage->getResourceLoader();
410 $rl->setMessageBlobStore( new NullMessageBlobStore() );
411
412 // Register custom modules
413 $rl->register( [
414 'example.site.a' => new ResourceLoaderTestModule( [ 'group' => 'site' ] ),
415 'example.site.b' => new ResourceLoaderTestModule( [ 'group' => 'site' ] ),
416 'example.user' => new ResourceLoaderTestModule( [ 'group' => 'user' ] ),
417 ] );
418
419 $outputPage = TestingAccessWrapper::newFromObject( $outputPage );
420 $outputPage->rlExemptStyleModules = $exemptStyleModules;
421 $this->assertEquals(
422 $expect,
423 strval( $outputPage->buildExemptModules() )
424 );
425 }
426
427 /**
428 * @dataProvider provideVaryHeaders
429 * @covers OutputPage::addVaryHeader
430 * @covers OutputPage::getVaryHeader
431 * @covers OutputPage::getKeyHeader
432 */
433 public function testVaryHeaders( $calls, $vary, $key ) {
434 // get rid of default Vary fields
435 $outputPage = $this->getMockBuilder( 'OutputPage' )
436 ->setConstructorArgs( [ new RequestContext() ] )
437 ->setMethods( [ 'getCacheVaryCookies' ] )
438 ->getMock();
439 $outputPage->expects( $this->any() )
440 ->method( 'getCacheVaryCookies' )
441 ->will( $this->returnValue( [] ) );
442 TestingAccessWrapper::newFromObject( $outputPage )->mVaryHeader = [];
443
444 foreach ( $calls as $call ) {
445 call_user_func_array( [ $outputPage, 'addVaryHeader' ], $call );
446 }
447 $this->assertEquals( $vary, $outputPage->getVaryHeader(), 'Vary:' );
448 $this->assertEquals( $key, $outputPage->getKeyHeader(), 'Key:' );
449 }
450
451 public function provideVaryHeaders() {
452 // note: getKeyHeader() automatically adds Vary: Cookie
453 return [
454 [ // single header
455 [
456 [ 'Cookie' ],
457 ],
458 'Vary: Cookie',
459 'Key: Cookie',
460 ],
461 [ // non-unique headers
462 [
463 [ 'Cookie' ],
464 [ 'Accept-Language' ],
465 [ 'Cookie' ],
466 ],
467 'Vary: Cookie, Accept-Language',
468 'Key: Cookie,Accept-Language',
469 ],
470 [ // two headers with single options
471 [
472 [ 'Cookie', [ 'param=phpsessid' ] ],
473 [ 'Accept-Language', [ 'substr=en' ] ],
474 ],
475 'Vary: Cookie, Accept-Language',
476 'Key: Cookie;param=phpsessid,Accept-Language;substr=en',
477 ],
478 [ // one header with multiple options
479 [
480 [ 'Cookie', [ 'param=phpsessid', 'param=userId' ] ],
481 ],
482 'Vary: Cookie',
483 'Key: Cookie;param=phpsessid;param=userId',
484 ],
485 [ // Duplicate option
486 [
487 [ 'Cookie', [ 'param=phpsessid' ] ],
488 [ 'Cookie', [ 'param=phpsessid' ] ],
489 [ 'Accept-Language', [ 'substr=en', 'substr=en' ] ],
490 ],
491 'Vary: Cookie, Accept-Language',
492 'Key: Cookie;param=phpsessid,Accept-Language;substr=en',
493 ],
494 [ // Same header, different options
495 [
496 [ 'Cookie', [ 'param=phpsessid' ] ],
497 [ 'Cookie', [ 'param=userId' ] ],
498 ],
499 'Vary: Cookie',
500 'Key: Cookie;param=phpsessid;param=userId',
501 ],
502 ];
503 }
504
505 /**
506 * @covers OutputPage::haveCacheVaryCookies
507 */
508 public function testHaveCacheVaryCookies() {
509 $request = new FauxRequest();
510 $context = new RequestContext();
511 $context->setRequest( $request );
512 $outputPage = new OutputPage( $context );
513
514 // No cookies are set.
515 $this->assertFalse( $outputPage->haveCacheVaryCookies() );
516
517 // 'Token' is present but empty, so it shouldn't count.
518 $request->setCookie( 'Token', '' );
519 $this->assertFalse( $outputPage->haveCacheVaryCookies() );
520
521 // 'Token' present and nonempty.
522 $request->setCookie( 'Token', '123' );
523 $this->assertTrue( $outputPage->haveCacheVaryCookies() );
524 }
525
526 /*
527 * @covers OutputPage::addCategoryLinks
528 * @covers OutputPage::getCategories
529 */
530 public function testGetCategories() {
531 $fakeResultWrapper = new FakeResultWrapper( [
532 (object) [
533 'pp_value' => 1,
534 'page_title' => 'Test'
535 ],
536 (object) [
537 'page_title' => 'Test2'
538 ]
539 ] );
540 $outputPage = $this->getMockBuilder( 'OutputPage' )
541 ->setConstructorArgs( [ new RequestContext() ] )
542 ->setMethods( [ 'addCategoryLinksToLBAndGetResult' ] )
543 ->getMock();
544 $outputPage->expects( $this->any() )
545 ->method( 'addCategoryLinksToLBAndGetResult' )
546 ->will( $this->returnValue( $fakeResultWrapper ) );
547
548 $outputPage->addCategoryLinks( [
549 'Test' => 'Test',
550 'Test2' => 'Test2',
551 ] );
552 $this->assertEquals( [ 0 => 'Test', '1' => 'Test2' ], $outputPage->getCategories() );
553 $this->assertEquals( [ 0 => 'Test2' ], $outputPage->getCategories( 'normal' ) );
554 $this->assertEquals( [ 0 => 'Test' ], $outputPage->getCategories( 'hidden' ) );
555 }
556
557 /**
558 * @dataProvider provideLinkHeaders
559 * @covers OutputPage::addLinkHeader
560 * @covers OutputPage::getLinkHeader
561 */
562 public function testLinkHeaders( $headers, $result ) {
563 $outputPage = $this->newInstance();
564
565 foreach ( $headers as $header ) {
566 $outputPage->addLinkHeader( $header );
567 }
568
569 $this->assertEquals( $result, $outputPage->getLinkHeader() );
570 }
571
572 public function provideLinkHeaders() {
573 return [
574 [
575 [],
576 false
577 ],
578 [
579 [ '<https://foo/bar.jpg>;rel=preload;as=image' ],
580 'Link: <https://foo/bar.jpg>;rel=preload;as=image',
581 ],
582 [
583 [ '<https://foo/bar.jpg>;rel=preload;as=image','<https://foo/baz.jpg>;rel=preload;as=image' ],
584 'Link: <https://foo/bar.jpg>;rel=preload;as=image,<https://foo/baz.jpg>;rel=preload;as=image',
585 ],
586 ];
587 }
588
589 /**
590 * @dataProvider providePreloadLinkHeaders
591 * @covers OutputPage::addLogoPreloadLinkHeaders
592 * @covers ResourceLoaderSkinModule::getLogo
593 */
594 public function testPreloadLinkHeaders( $config, $result, $baseDir = null ) {
595 if ( $baseDir ) {
596 $this->setMwGlobals( 'IP', $baseDir );
597 }
598 $out = TestingAccessWrapper::newFromObject( $this->newInstance( $config ) );
599 $out->addLogoPreloadLinkHeaders();
600
601 $this->assertEquals( $result, $out->getLinkHeader() );
602 }
603
604 public function providePreloadLinkHeaders() {
605 return [
606 [
607 [
608 'ResourceBasePath' => '/w',
609 'Logo' => '/img/default.png',
610 'LogoHD' => [
611 '1.5x' => '/img/one-point-five.png',
612 '2x' => '/img/two-x.png',
613 ],
614 ],
615 'Link: </img/default.png>;rel=preload;as=image;media=' .
616 'not all and (min-resolution: 1.5dppx),' .
617 '</img/one-point-five.png>;rel=preload;as=image;media=' .
618 '(min-resolution: 1.5dppx) and (max-resolution: 1.999999dppx),' .
619 '</img/two-x.png>;rel=preload;as=image;media=(min-resolution: 2dppx)'
620 ],
621 [
622 [
623 'ResourceBasePath' => '/w',
624 'Logo' => '/img/default.png',
625 'LogoHD' => false,
626 ],
627 'Link: </img/default.png>;rel=preload;as=image'
628 ],
629 [
630 [
631 'ResourceBasePath' => '/w',
632 'Logo' => '/img/default.png',
633 'LogoHD' => [
634 '2x' => '/img/two-x.png',
635 ],
636 ],
637 'Link: </img/default.png>;rel=preload;as=image;media=' .
638 'not all and (min-resolution: 2dppx),' .
639 '</img/two-x.png>;rel=preload;as=image;media=(min-resolution: 2dppx)'
640 ],
641 [
642 [
643 'ResourceBasePath' => '/w',
644 'Logo' => '/w/test.jpg',
645 'LogoHD' => false,
646 'UploadPath' => '/w/images',
647 ],
648 'Link: </w/test.jpg?edcf2>;rel=preload;as=image',
649 'baseDir' => dirname( __DIR__ ) . '/data/media',
650 ],
651 ];
652 }
653
654 /**
655 * @return OutputPage
656 */
657 private function newInstance( $config = [] ) {
658 $context = new RequestContext();
659
660 $context->setConfig( new HashConfig( $config + [
661 'AppleTouchIcon' => false,
662 'DisableLangConversion' => true,
663 'EnableAPI' => false,
664 'EnableCanonicalServerLink' => false,
665 'Favicon' => false,
666 'Feed' => false,
667 'LanguageCode' => false,
668 'ReferrerPolicy' => false,
669 'RightsPage' => false,
670 'RightsUrl' => false,
671 'UniversalEditButton' => false,
672 ] ) );
673
674 return new OutputPage( $context );
675 }
676 }
677
678 /**
679 * MessageBlobStore that doesn't do anything
680 */
681 class NullMessageBlobStore extends MessageBlobStore {
682 public function get( ResourceLoader $resourceLoader, $modules, $lang ) {
683 return [];
684 }
685
686 public function insertMessageBlob( $name, ResourceLoaderModule $module, $lang ) {
687 return false;
688 }
689
690 public function updateModule( $name, ResourceLoaderModule $module, $lang ) {
691 }
692
693 public function updateMessage( $key ) {
694 }
695
696 public function clear() {
697 }
698 }