MediaWiki  1.30.0
DerivativeResourceLoaderContextTest.php
Go to the documentation of this file.
1 <?php
2 
7 class DerivativeResourceLoaderContextTest extends PHPUnit_Framework_TestCase {
8 
9  protected static function getContext() {
10  $request = new FauxRequest( [
11  'lang' => 'zh',
12  'modules' => 'test.context',
13  'only' => 'scripts',
14  'skin' => 'fallback',
15  'target' => 'test',
16  ] );
17  return new ResourceLoaderContext( new ResourceLoader(), $request );
18  }
19 
20  public function testGetInherited() {
22 
23  // Request parameters
24  $this->assertEquals( $derived->getDebug(), false );
25  $this->assertEquals( $derived->getLanguage(), 'zh' );
26  $this->assertEquals( $derived->getModules(), [ 'test.context' ] );
27  $this->assertEquals( $derived->getOnly(), 'scripts' );
28  $this->assertEquals( $derived->getSkin(), 'fallback' );
29  $this->assertEquals( $derived->getUser(), null );
30 
31  // Misc
32  $this->assertEquals( $derived->getDirection(), 'ltr' );
33  $this->assertEquals( $derived->getHash(), 'zh|fallback|||scripts|||||' );
34  }
35 
36  public function testModules() {
38 
39  $derived->setModules( [ 'test.override' ] );
40  $this->assertEquals( $derived->getModules(), [ 'test.override' ] );
41  }
42 
43  public function testLanguage() {
45  $derived = new DerivativeResourceLoaderContext( $context );
46 
47  $derived->setLanguage( 'nl' );
48  $this->assertEquals( $derived->getLanguage(), 'nl' );
49  }
50 
51  public function testDirection() {
53 
54  $derived->setLanguage( 'nl' );
55  $this->assertEquals( $derived->getDirection(), 'ltr' );
56 
57  $derived->setLanguage( 'he' );
58  $this->assertEquals( $derived->getDirection(), 'rtl' );
59 
60  $derived->setDirection( 'ltr' );
61  $this->assertEquals( $derived->getDirection(), 'ltr' );
62  }
63 
64  public function testSkin() {
66 
67  $derived->setSkin( 'override' );
68  $this->assertEquals( $derived->getSkin(), 'override' );
69  }
70 
71  public function testUser() {
73 
74  $derived->setUser( 'Example' );
75  $this->assertEquals( $derived->getUser(), 'Example' );
76  }
77 
78  public function testDebug() {
80 
81  $derived->setDebug( true );
82  $this->assertEquals( $derived->getDebug(), true );
83  }
84 
85  public function testOnly() {
87 
88  $derived->setOnly( 'styles' );
89  $this->assertEquals( $derived->getOnly(), 'styles' );
90 
91  $derived->setOnly( null );
92  $this->assertEquals( $derived->getOnly(), null );
93  }
94 
95  public function testVersion() {
97 
98  $derived->setVersion( 'hw1' );
99  $this->assertEquals( $derived->getVersion(), 'hw1' );
100  }
101 
102  public function testRaw() {
104 
105  $derived->setRaw( true );
106  $this->assertEquals( $derived->getRaw(), true );
107  }
108 
109  public function testGetHash() {
111 
112  $this->assertEquals( $derived->getHash(), 'zh|fallback|||scripts|||||' );
113 
114  $derived->setLanguage( 'nl' );
115  $derived->setUser( 'Example' );
116  // Assert that subclass is able to clear parent class "hash" member
117  $this->assertEquals( $derived->getHash(), 'nl|fallback||Example|scripts|||||' );
118  }
119 
120  public function testAccessors() {
122  $derived = new DerivativeResourceLoaderContext( $context );
123  $this->assertSame( $derived->getRequest(), $context->getRequest() );
124  $this->assertSame( $derived->getResourceLoader(), $context->getResourceLoader() );
125  }
126 }
ResourceLoaderContext
Object passed around to modules which contains information about the state of a specific loader reque...
Definition: ResourceLoaderContext.php:32
FauxRequest
WebRequest clone which takes values from a provided array.
Definition: FauxRequest.php:33
false
processing should stop and the error should be shown to the user * false
Definition: hooks.txt:187
$context
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:2581
DerivativeResourceLoaderContextTest\testSkin
testSkin()
Definition: DerivativeResourceLoaderContextTest.php:64
DerivativeResourceLoaderContextTest\getContext
static getContext()
Definition: DerivativeResourceLoaderContextTest.php:9
DerivativeResourceLoaderContextTest\testGetHash
testGetHash()
Definition: DerivativeResourceLoaderContextTest.php:109
DerivativeResourceLoaderContextTest\testUser
testUser()
Definition: DerivativeResourceLoaderContextTest.php:71
getContext
getContext()
php
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
DerivativeResourceLoaderContextTest\testRaw
testRaw()
Definition: DerivativeResourceLoaderContextTest.php:102
DerivativeResourceLoaderContextTest\testAccessors
testAccessors()
Definition: DerivativeResourceLoaderContextTest.php:120
DerivativeResourceLoaderContextTest\testModules
testModules()
Definition: DerivativeResourceLoaderContextTest.php:36
DerivativeResourceLoaderContextTest
ResourceLoader DerivativeResourceLoaderContext.
Definition: DerivativeResourceLoaderContextTest.php:7
$request
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:2581
DerivativeResourceLoaderContextTest\testGetInherited
testGetInherited()
Definition: DerivativeResourceLoaderContextTest.php:20
DerivativeResourceLoaderContextTest\testLanguage
testLanguage()
Definition: DerivativeResourceLoaderContextTest.php:43
DerivativeResourceLoaderContext
Allows changing specific properties of a context object, without changing the main one.
Definition: DerivativeResourceLoaderContext.php:30
DerivativeResourceLoaderContextTest\testVersion
testVersion()
Definition: DerivativeResourceLoaderContextTest.php:95
DerivativeResourceLoaderContextTest\testDebug
testDebug()
Definition: DerivativeResourceLoaderContextTest.php:78
true
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses just before the function returns a value If you return true
Definition: hooks.txt:1965
DerivativeResourceLoaderContextTest\testDirection
testDirection()
Definition: DerivativeResourceLoaderContextTest.php:51
DerivativeResourceLoaderContextTest\testOnly
testOnly()
Definition: DerivativeResourceLoaderContextTest.php:85