MediaWiki REL1_31
ResourceLoaderTestCase.php
Go to the documentation of this file.
1<?php
2
4use Psr\Log\LoggerInterface;
5use Psr\Log\NullLogger;
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 'lang' => 'en',
30 'dir' => 'ltr',
31 'skin' => 'vector',
32 'modules' => 'startup',
33 'only' => 'scripts',
34 ];
35 $resourceLoader = $rl ?: new ResourceLoader();
36 $request = new FauxRequest( [
37 'lang' => $options['lang'],
38 'modules' => $options['modules'],
39 'only' => $options['only'],
40 'skin' => $options['skin'],
41 'target' => 'phpunit',
42 ] );
43 $ctx = $this->getMockBuilder( ResourceLoaderContext::class )
44 ->setConstructorArgs( [ $resourceLoader, $request ] )
45 ->setMethods( [ 'getDirection' ] )
46 ->getMock();
47 $ctx->method( 'getDirection' )->willReturn( $options['dir'] );
48 return $ctx;
49 }
50
51 public static function getSettings() {
52 return [
53 // For ResourceLoader::inDebugMode since it doesn't have context
54 'ResourceLoaderDebug' => true,
55
56 // Avoid influence from wgInvalidateCacheOnLocalSettingsChange
57 'CacheEpoch' => '20140101000000',
58
59 // For ResourceLoader::__construct()
60 'ResourceLoaderSources' => [],
61
62 // For wfScript()
63 'ScriptPath' => '/w',
64 'Script' => '/w/index.php',
65 'LoadScript' => '/w/load.php',
66 ];
67 }
68
69 protected function setUp() {
70 parent::setUp();
71
73
74 $globals = [];
75 foreach ( self::getSettings() as $key => $value ) {
76 $globals['wg' . $key] = $value;
77 }
78 $this->setMwGlobals( $globals );
79 }
80}
81
82/* Stubs */
83
85 protected $messages = [];
86 protected $dependencies = [];
87 protected $group = null;
88 protected $source = 'local';
89 protected $script = '';
90 protected $styles = '';
91 protected $skipFunction = null;
92 protected $isRaw = false;
93 protected $isKnownEmpty = false;
95 protected $targets = [ 'phpunit' ];
96 protected $shouldEmbed = null;
97
98 public function __construct( $options = [] ) {
99 foreach ( $options as $key => $value ) {
100 $this->$key = $value;
101 }
102 }
103
105 return $this->validateScriptFile( 'input', $this->script );
106 }
107
109 return [ '' => $this->styles ];
110 }
111
112 public function getMessages() {
113 return $this->messages;
114 }
115
117 return $this->dependencies;
118 }
119
120 public function getGroup() {
121 return $this->group;
122 }
123
124 public function getSource() {
125 return $this->source;
126 }
127
128 public function getType() {
129 return $this->type;
130 }
131
132 public function getSkipFunction() {
133 return $this->skipFunction;
134 }
135
136 public function isRaw() {
137 return $this->isRaw;
138 }
140 return $this->isKnownEmpty;
141 }
142
144 return $this->shouldEmbed !== null ? $this->shouldEmbed : parent::shouldEmbedModule( $context );
145 }
146
147 public function enableModuleContentVersion() {
148 return true;
149 }
150}
151
153 protected $lessVars = [];
154
155 public function __construct( $options = [], $test = [] ) {
156 parent::__construct( $options );
157
158 foreach ( $test as $key => $value ) {
159 $this->$key = $value;
160 }
161 }
162
164 return $this->lessVars;
165 }
166}
167
170
172 // TODO: This won't be needed once ResourceLoader is empty by default
173 // and default registrations are done from ServiceWiring instead.
174 public function __construct( Config $config = null, LoggerInterface $logger = null ) {
175 $this->setLogger( $logger ?: new NullLogger() );
176 $this->config = $config ?: MediaWikiServices::getInstance()->getMainConfig();
177 // Source "local" is required by StartupModule
178 $this->addSource( 'local', $this->config->get( 'LoadScript' ) );
179 $this->setMessageBlobStore( new MessageBlobStore( $this, $this->getLogger() ) );
180 }
181
182 public function getErrors() {
183 return $this->errors;
184 }
185}
__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 origin 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.
static clearCache()
Reset static members used for caching.
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:2806
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:2001
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
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:2818
Interface for configuration instances.
Definition Config.php:28