MediaWiki REL1_32
DerivativeResourceLoaderContextTest.php
Go to the documentation of this file.
1<?php
2
7class DerivativeResourceLoaderContextTest extends PHPUnit\Framework\TestCase {
8
9 use MediaWikiCoversValidator;
10
11 protected static function getContext() {
12 $request = new FauxRequest( [
13 'lang' => 'zh',
14 'modules' => 'test.context',
15 'only' => 'scripts',
16 'skin' => 'fallback',
17 'target' => 'test',
18 ] );
20 }
21
22 public function testGetInherited() {
23 $derived = new DerivativeResourceLoaderContext( self::getContext() );
24
25 // Request parameters
26 $this->assertEquals( $derived->getDebug(), false );
27 $this->assertEquals( $derived->getLanguage(), 'zh' );
28 $this->assertEquals( $derived->getModules(), [ 'test.context' ] );
29 $this->assertEquals( $derived->getOnly(), 'scripts' );
30 $this->assertEquals( $derived->getSkin(), 'fallback' );
31 $this->assertEquals( $derived->getUser(), null );
32
33 // Misc
34 $this->assertEquals( $derived->getDirection(), 'ltr' );
35 $this->assertEquals( $derived->getHash(), 'zh|fallback|||scripts|||||' );
36 }
37
38 public function testModules() {
39 $derived = new DerivativeResourceLoaderContext( self::getContext() );
40
41 $derived->setModules( [ 'test.override' ] );
42 $this->assertEquals( $derived->getModules(), [ 'test.override' ] );
43 }
44
45 public function testLanguage() {
48
49 $derived->setLanguage( 'nl' );
50 $this->assertEquals( $derived->getLanguage(), 'nl' );
51 }
52
53 public function testDirection() {
54 $derived = new DerivativeResourceLoaderContext( self::getContext() );
55
56 $derived->setLanguage( 'nl' );
57 $this->assertEquals( $derived->getDirection(), 'ltr' );
58
59 $derived->setLanguage( 'he' );
60 $this->assertEquals( $derived->getDirection(), 'rtl' );
61
62 $derived->setDirection( 'ltr' );
63 $this->assertEquals( $derived->getDirection(), 'ltr' );
64 }
65
66 public function testSkin() {
67 $derived = new DerivativeResourceLoaderContext( self::getContext() );
68
69 $derived->setSkin( 'override' );
70 $this->assertEquals( $derived->getSkin(), 'override' );
71 }
72
73 public function testUser() {
74 $derived = new DerivativeResourceLoaderContext( self::getContext() );
75
76 $derived->setUser( 'Example' );
77 $this->assertEquals( $derived->getUser(), 'Example' );
78 }
79
80 public function testDebug() {
81 $derived = new DerivativeResourceLoaderContext( self::getContext() );
82
83 $derived->setDebug( true );
84 $this->assertEquals( $derived->getDebug(), true );
85 }
86
87 public function testOnly() {
88 $derived = new DerivativeResourceLoaderContext( self::getContext() );
89
90 $derived->setOnly( 'styles' );
91 $this->assertEquals( $derived->getOnly(), 'styles' );
92
93 $derived->setOnly( null );
94 $this->assertEquals( $derived->getOnly(), null );
95 }
96
97 public function testVersion() {
98 $derived = new DerivativeResourceLoaderContext( self::getContext() );
99
100 $derived->setVersion( 'hw1' );
101 $this->assertEquals( $derived->getVersion(), 'hw1' );
102 }
103
104 public function testRaw() {
105 $derived = new DerivativeResourceLoaderContext( self::getContext() );
106
107 $derived->setRaw( true );
108 $this->assertEquals( $derived->getRaw(), true );
109 }
110
111 public function testGetHash() {
112 $derived = new DerivativeResourceLoaderContext( self::getContext() );
113
114 $this->assertEquals( $derived->getHash(), 'zh|fallback|||scripts|||||' );
115
116 $derived->setLanguage( 'nl' );
117 $derived->setUser( 'Example' );
118 // Assert that subclass is able to clear parent class "hash" member
119 $this->assertEquals( $derived->getHash(), 'nl|fallback||Example|scripts|||||' );
120 }
121
122 public function testContentOverrides() {
123 $derived = new DerivativeResourceLoaderContext( self::getContext() );
124
125 $this->assertNull( $derived->getContentOverrideCallback() );
126
127 $override = function ( Title $t ) {
128 return null;
129 };
130 $derived->setContentOverrideCallback( $override );
131 $this->assertSame( $override, $derived->getContentOverrideCallback() );
132
133 $derived2 = new DerivativeResourceLoaderContext( $derived );
134 $this->assertSame( $override, $derived2->getContentOverrideCallback() );
135 }
136
137 public function testAccessors() {
140 $this->assertSame( $derived->getRequest(), $context->getRequest() );
141 $this->assertSame( $derived->getResourceLoader(), $context->getResourceLoader() );
142 }
143}
ResourceLoader DerivativeResourceLoaderContext.
Allows changing specific properties of a context object, without changing the main one.
WebRequest clone which takes values from a provided array.
Object passed around to modules which contains information about the state of a specific loader reque...
Dynamic JavaScript and CSS resource loading system.
Represents a title within MediaWiki.
Definition Title.php:39
do that in ParserLimitReportFormat instead use this to modify the parameters of the image all existing parser cache entries will be invalid To avoid you ll need to handle that somehow(e.g. with the RejectParserCacheValue hook) because MediaWiki won 't do it for you. & $defaults also a ContextSource after deleting those rows but within the same transaction you ll probably need to make sure the header is varied on $request
Definition hooks.txt:2880
do that in ParserLimitReportFormat instead use this to modify the parameters of the image all existing parser cache entries will be invalid To avoid you ll need to handle that somehow(e.g. with the RejectParserCacheValue hook) because MediaWiki won 't do it for you. & $defaults also a ContextSource after deleting those rows but within the same transaction you ll probably need to make sure the header is varied on and they can depend only on the ResourceLoaderContext $context
Definition hooks.txt:2885