MediaWiki  1.32.0
DerivativeResourceLoaderContextTest.php
Go to the documentation of this file.
1 <?php
2 
7 class 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  ] );
19  return new ResourceLoaderContext( new ResourceLoader(), $request );
20  }
21 
22  public function testGetInherited() {
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() {
40 
41  $derived->setModules( [ 'test.override' ] );
42  $this->assertEquals( $derived->getModules(), [ 'test.override' ] );
43  }
44 
45  public function testLanguage() {
47  $derived = new DerivativeResourceLoaderContext( $context );
48 
49  $derived->setLanguage( 'nl' );
50  $this->assertEquals( $derived->getLanguage(), 'nl' );
51  }
52 
53  public function testDirection() {
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() {
68 
69  $derived->setSkin( 'override' );
70  $this->assertEquals( $derived->getSkin(), 'override' );
71  }
72 
73  public function testUser() {
75 
76  $derived->setUser( 'Example' );
77  $this->assertEquals( $derived->getUser(), 'Example' );
78  }
79 
80  public function testDebug() {
82 
83  $derived->setDebug( true );
84  $this->assertEquals( $derived->getDebug(), true );
85  }
86 
87  public function testOnly() {
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() {
99 
100  $derived->setVersion( 'hw1' );
101  $this->assertEquals( $derived->getVersion(), 'hw1' );
102  }
103 
104  public function testRaw() {
106 
107  $derived->setRaw( true );
108  $this->assertEquals( $derived->getRaw(), true );
109  }
110 
111  public function testGetHash() {
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() {
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() {
139  $derived = new DerivativeResourceLoaderContext( $context );
140  $this->assertSame( $derived->getRequest(), $context->getRequest() );
141  $this->assertSame( $derived->getResourceLoader(), $context->getResourceLoader() );
142  }
143 }
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:2675
DerivativeResourceLoaderContextTest\testSkin
testSkin()
Definition: DerivativeResourceLoaderContextTest.php:66
DerivativeResourceLoaderContextTest\getContext
static getContext()
Definition: DerivativeResourceLoaderContextTest.php:11
DerivativeResourceLoaderContextTest\testGetHash
testGetHash()
Definition: DerivativeResourceLoaderContextTest.php:111
DerivativeResourceLoaderContextTest\testUser
testUser()
Definition: DerivativeResourceLoaderContextTest.php:73
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:104
DerivativeResourceLoaderContextTest\testAccessors
testAccessors()
Definition: DerivativeResourceLoaderContextTest.php:137
DerivativeResourceLoaderContextTest\testModules
testModules()
Definition: DerivativeResourceLoaderContextTest.php:38
use
as see the revision history and available at free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to use
Definition: MIT-LICENSE.txt:10
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:2675
DerivativeResourceLoaderContextTest\testGetInherited
testGetInherited()
Definition: DerivativeResourceLoaderContextTest.php:22
DerivativeResourceLoaderContextTest\testLanguage
testLanguage()
Definition: DerivativeResourceLoaderContextTest.php:45
DerivativeResourceLoaderContext
Allows changing specific properties of a context object, without changing the main one.
Definition: DerivativeResourceLoaderContext.php:30
DerivativeResourceLoaderContextTest\testVersion
testVersion()
Definition: DerivativeResourceLoaderContextTest.php:97
Title
Represents a title within MediaWiki.
Definition: Title.php:39
DerivativeResourceLoaderContextTest\testDebug
testDebug()
Definition: DerivativeResourceLoaderContextTest.php:80
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:2036
$t
$t
Definition: testCompression.php:69
DerivativeResourceLoaderContextTest\testDirection
testDirection()
Definition: DerivativeResourceLoaderContextTest.php:53
DerivativeResourceLoaderContextTest\testContentOverrides
testContentOverrides()
Definition: DerivativeResourceLoaderContextTest.php:122
DerivativeResourceLoaderContextTest\testOnly
testOnly()
Definition: DerivativeResourceLoaderContextTest.php:87