MediaWiki REL1_31
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 testAccessors() {
125 $this->assertSame( $derived->getRequest(), $context->getRequest() );
126 $this->assertSame( $derived->getResourceLoader(), $context->getResourceLoader() );
127 }
128}
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.
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:2806
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:2811