MediaWiki REL1_33
ResourceLoaderTestCase.php
Go to the documentation of this file.
1<?php
2
6
8 // Version hash for a blank file module.
9 // Result of ResourceLoader::makeHash(), ResourceLoaderTestModule
10 // and ResourceLoaderFileModule::getDefinitionSummary().
11 const BLANK_VERSION = '09p30q0';
12
23 protected function getResourceLoaderContext( $options = [], ResourceLoader $rl = null ) {
24 if ( is_string( $options ) ) {
25 // Back-compat for extension tests
26 $options = [ 'lang' => $options ];
27 }
28 $options += [
29 'debug' => 'true',
30 'lang' => 'en',
31 'dir' => 'ltr',
32 'skin' => 'vector',
33 'modules' => 'startup',
34 'only' => 'scripts',
35 'safemode' => null,
36 ];
37 $resourceLoader = $rl ?: new ResourceLoader();
38 $request = new FauxRequest( [
39 'debug' => $options['debug'],
40 'lang' => $options['lang'],
41 'modules' => $options['modules'],
42 'only' => $options['only'],
43 'safemode' => $options['safemode'],
44 'skin' => $options['skin'],
45 'target' => 'phpunit',
46 ] );
47 $ctx = $this->getMockBuilder( ResourceLoaderContext::class )
48 ->setConstructorArgs( [ $resourceLoader, $request ] )
49 ->setMethods( [ 'getDirection' ] )
50 ->getMock();
51 $ctx->method( 'getDirection' )->willReturn( $options['dir'] );
52 return $ctx;
53 }
54
55 public static function getSettings() {
56 return [
57 // For ResourceLoader::inDebugMode since it doesn't have context
58 'ResourceLoaderDebug' => true,
59
60 // Avoid influence from wgInvalidateCacheOnLocalSettingsChange
61 'CacheEpoch' => '20140101000000',
62
63 // For wfScript()
64 'ScriptPath' => '/w',
65 'Script' => '/w/index.php',
66 'LoadScript' => '/w/load.php',
67 ];
68 }
69
70 protected function setUp() {
71 parent::setUp();
72
73 ResourceLoader::clearCache();
74
75 $globals = [];
76 foreach ( self::getSettings() as $key => $value ) {
77 $globals['wg' . $key] = $value;
78 }
79 $this->setMwGlobals( $globals );
80 }
81}
82
83/* Stubs */
84
86 protected $messages = [];
87 protected $dependencies = [];
88 protected $group = null;
89 protected $source = 'local';
90 protected $script = '';
91 protected $styles = '';
92 protected $skipFunction = null;
93 protected $isRaw = false;
94 protected $isKnownEmpty = false;
96 protected $targets = [ 'phpunit' ];
97 protected $shouldEmbed = null;
98
99 public function __construct( $options = [] ) {
100 foreach ( $options as $key => $value ) {
101 $this->$key = $value;
102 }
103 }
104
106 return $this->validateScriptFile( 'input', $this->script );
107 }
108
110 return [ '' => $this->styles ];
111 }
112
113 public function getMessages() {
114 return $this->messages;
115 }
116
118 return $this->dependencies;
119 }
120
121 public function getGroup() {
122 return $this->group;
123 }
124
125 public function getSource() {
126 return $this->source;
127 }
128
129 public function getType() {
130 return $this->type;
131 }
132
133 public function getSkipFunction() {
134 return $this->skipFunction;
135 }
136
137 public function isRaw() {
138 return $this->isRaw;
139 }
141 return $this->isKnownEmpty;
142 }
143
145 return $this->shouldEmbed ?? parent::shouldEmbedModule( $context );
146 }
147
148 public function enableModuleContentVersion() {
149 return true;
150 }
151}
152
154 protected $lessVars = [];
155
156 public function __construct( $options = [], $test = [] ) {
157 parent::__construct( $options );
158
159 foreach ( $test as $key => $value ) {
160 $this->$key = $value;
161 }
162 }
163
165 return $this->lessVars;
166 }
167}
168
171
173 // TODO: This won't be needed once ResourceLoader is empty by default
174 // and default registrations are done from ServiceWiring instead.
175 public function __construct( Config $config = null, LoggerInterface $logger = null ) {
176 $this->setLogger( $logger ?: new NullLogger() );
177 $this->config = $config ?: MediaWikiServices::getInstance()->getMainConfig();
178 // Source "local" is required by StartupModule
179 $this->addSource( 'local', $this->config->get( 'LoadScript' ) );
180 $this->setMessageBlobStore( new MessageBlobStore( $this, $this->getLogger() ) );
181 }
182
183 public function getErrors() {
184 return $this->errors;
185 }
186}
and that you know you can do these things To protect your we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights These restrictions translate to certain responsibilities for you if you distribute copies of the or if you modify it For if you distribute copies of such a whether gratis or for a you must give the recipients all the rights that you have You must make sure that receive or can get the source code And you must show them these terms so they know their rights We protect your rights with two and(2) offer you this license which gives you legal permission to copy
__construct(Config $config=null, LoggerInterface $logger=null)
Register core modules and runs registration hooks.
WebRequest clone which takes values from a provided array.
setMwGlobals( $pairs, $value=null)
Sets a global, maintaining a stashed version of the previous global to be restored in tearDown.
MediaWikiServices is the service locator for the application scope of MediaWiki.
This class generates message blobs for use by ResourceLoader modules.
Object passed around to modules which contains information about the state of a specific loader reque...
ResourceLoader module based on local JavaScript/CSS files.
getLessVars(ResourceLoaderContext $context)
Get module-specific LESS variables, if any.
Abstraction for ResourceLoader modules, with name registration and maxage functionality.
validateScriptFile( $fileName, $contents)
Validate a given script file; if valid returns the original source.
getResourceLoaderContext( $options=[], ResourceLoader $rl=null)
shouldEmbedModule(ResourceLoaderContext $context)
Check whether this module should be embeded rather than linked.
getScript(ResourceLoaderContext $context)
Get all JS for this module for a given language and skin.
isKnownEmpty(ResourceLoaderContext $context)
Check whether this module is known to be empty.
isRaw()
Whether this module's JS expects to work without the client-side ResourceLoader module.
getMessages()
Get the messages needed for this module.
enableModuleContentVersion()
Whether to generate version hash based on module content.
getStyles(ResourceLoaderContext $context)
Get all CSS for this module for a given skin.
getType()
Get the module's load type.
getGroup()
Get the group this module is in.
getDependencies(ResourceLoaderContext $context=null)
Get a list of modules this module depends on.
getSource()
Get the source of this module.
getSkipFunction()
Get the skip function.
Dynamic JavaScript and CSS resource loading system.
setMessageBlobStore(MessageBlobStore $blobStore)
LoggerInterface $logger
setLogger(LoggerInterface $logger)
addSource( $id, $loadUrl=null)
Add a foreign source of modules.
array $errors
Errors accumulated during current respond() call.
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:2843
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 & $options
Definition hooks.txt:1999
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:2848
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 such as when responding to a resource loader request or generating HTML output & $resourceLoader
Definition hooks.txt:2859
script(document.cookie)%253c/script%253e</pre ></div > !! end !! test XSS is escaped(inline) !!input< source lang
Interface for configuration instances.
Definition Config.php:28