3use Wikimedia\TestingAccessWrapper;
10 use MediaWikiCoversValidator;
13 return strtr( $text, [
20 'ResourceLoaderSources' => [],
21 'ResourceModuleSkinStyles' => [],
22 'ResourceModules' => [],
23 'EnableJavaScriptTest' =>
false,
24 'ResourceLoaderDebug' =>
false,
25 'LoadScript' =>
'/w/load.php',
33 'target' =>
'phpunit',
45 'test.private' => [
'group' =>
'private' ],
46 'test.shouldembed.empty' => [
'shouldEmbed' =>
true,
'isKnownEmpty' =>
true ],
47 'test.shouldembed' => [
'shouldEmbed' =>
true ],
48 'test.user' => [
'group' =>
'user' ],
51 'test.styles.mixed' => [],
52 'test.styles.noscript' => [
54 'group' =>
'noscript',
56 'test.styles.user' => [
60 'test.styles.user.empty' => [
63 'isKnownEmpty' =>
true,
65 'test.styles.private' => [
68 'styles' =>
'.private{}',
70 'test.styles.shouldembed' => [
72 'shouldEmbed' =>
true,
73 'styles' =>
'.shouldembed{}',
75 'test.styles.deprecated' => [
77 'deprecated' =>
'Deprecation message.',
81 'test.scripts.user' => [
'group' =>
'user' ],
82 'test.scripts.user.empty' => [
'group' =>
'user',
'isKnownEmpty' =>
true ],
83 'test.scripts.raw' => [
'isRaw' =>
true ],
84 'test.scripts.shouldembed' => [
'shouldEmbed' =>
true ],
86 'test.ordering.a' => [
'shouldEmbed' =>
false ],
87 'test.ordering.b' => [
'shouldEmbed' =>
false ],
88 'test.ordering.c' => [
'shouldEmbed' =>
true,
'styles' =>
'.orderingC{}' ],
89 'test.ordering.d' => [
'shouldEmbed' =>
true,
'styles' =>
'.orderingD{}' ],
90 'test.ordering.e' => [
'shouldEmbed' =>
false ],
92 return array_map(
function (
$options ) {
102 $this->assertInternalType(
'array', $client->getDocumentAttributes() );
115 $context->getResourceLoader()->register( self::makeSampleModules() );
118 $client->setModules( [
121 'test.shouldembed.empty',
126 $client->setModuleStyles( [
128 'test.styles.user.empty',
129 'test.styles.private',
131 'test.styles.shouldembed',
132 'test.styles.deprecated',
133 'test.unregistered.styles',
135 $client->setModuleScripts( [
138 'test.scripts.user.empty',
139 'test.scripts.shouldembed',
140 'test.unregistered.scripts',
145 'test.private' =>
'loading',
146 'test.shouldembed.empty' =>
'ready',
147 'test.shouldembed' =>
'loading',
148 'test.user' =>
'loading',
149 'test.styles.pure' =>
'ready',
150 'test.styles.user.empty' =>
'ready',
151 'test.styles.private' =>
'ready',
152 'test.styles.shouldembed' =>
'ready',
153 'test.styles.deprecated' =>
'ready',
154 'test.scripts' =>
'loading',
155 'test.scripts.user' =>
'loading',
156 'test.scripts.user.empty' =>
'ready',
157 'test.scripts.shouldembed' =>
'loading',
164 'test.styles.deprecated',
169 'test.scripts.shouldembed',
172 'styles' => [
'test.styles.private',
'test.styles.shouldembed' ],
179 'styleDeprecations' => [
182 [
'This page is using the deprecated ResourceLoader module "test.styles.deprecated".
183Deprecation message.' ]
188 $access = TestingAccessWrapper::newFromObject( $client );
189 $this->assertEquals( $expected, $access->getData() );
201 $context->getResourceLoader()->register( self::makeSampleModules() );
206 $client->setConfig( [
'key' =>
'value' ] );
207 $client->setModules( [
211 $client->setModuleStyles( [
213 'test.styles.private',
214 'test.styles.deprecated',
216 $client->setModuleScripts( [
219 $client->setExemptStates( [
220 'test.exempt' =>
'ready',
224 $expected =
'<script>document.documentElement.className = document.documentElement.className.replace( /(^|\s)client-nojs(\s|$)/, "$1client-js$2" );</script>' .
"\n"
225 .
'<script>(window.RLQ=window.RLQ||[]).push(function(){'
226 .
'mw.config.set({"key":"value"});'
227 .
'mw.loader.state({"test.exempt":"ready","test.private":"loading","test.styles.pure":"ready","test.styles.private":"ready","test.styles.deprecated":"ready","test.scripts":"loading"});'
228 .
'mw.loader.implement("test.private@{blankVer}",function($,jQuery,require,module){},{"css":[]});'
229 .
'RLPAGEMODULES=["test"];mw.loader.load(RLPAGEMODULES);'
230 .
'mw.loader.load("/w/load.php?debug=false\u0026lang=nl\u0026modules=test.scripts\u0026only=scripts\u0026skin=fallback");'
231 .
'});</script>' .
"\n"
232 .
'<link rel="stylesheet" href="/w/load.php?debug=false&lang=nl&modules=test.styles.deprecated%2Cpure&only=styles&skin=fallback"/>' .
"\n"
233 .
'<style>.private{}</style>' .
"\n"
234 .
'<script async="" src="/w/load.php?debug=false&lang=nl&modules=startup&only=scripts&skin=fallback"></script>';
238 $this->assertEquals( $expected, $client->getHeadHtml() );
249 [
'target' =>
'example' ]
253 $expected =
'<script>document.documentElement.className = document.documentElement.className.replace( /(^|\s)client-nojs(\s|$)/, "$1client-js$2" );</script>' .
"\n"
254 .
'<script async="" src="/w/load.php?debug=false&lang=nl&modules=startup&only=scripts&skin=fallback&target=example"></script>';
257 $this->assertEquals( $expected, $client->getHeadHtml() );
268 [
'safemode' =>
'1' ]
272 $expected =
'<script>document.documentElement.className = document.documentElement.className.replace( /(^|\s)client-nojs(\s|$)/, "$1client-js$2" );</script>' .
"\n"
273 .
'<script async="" src="/w/load.php?debug=false&lang=nl&modules=startup&only=scripts&safemode=1&skin=fallback"></script>';
276 $this->assertEquals( $expected, $client->getHeadHtml() );
291 $expected =
'<script>document.documentElement.className = document.documentElement.className.replace( /(^|\s)client-nojs(\s|$)/, "$1client-js$2" );</script>' .
"\n"
292 .
'<script async="" src="/w/load.php?debug=false&lang=nl&modules=startup&only=scripts&skin=fallback"></script>';
295 $this->assertEquals( $expected, $client->getHeadHtml() );
304 $context->getResourceLoader()->register( self::makeSampleModules() );
307 $client->setConfig( [
'key' =>
'value' ] );
308 $client->setModules( [
310 'test.private.bottom',
312 $client->setModuleStyles( [
313 'test.styles.deprecated',
315 $client->setModuleScripts( [
319 $expected =
'<script>(window.RLQ=window.RLQ||[]).push(function(){'
320 .
'mw.log.warn("This page is using the deprecated ResourceLoader module \"test.styles.deprecated\".\nDeprecation message.");'
324 $this->assertEquals( $expected, $client->getBodyHtml() );
332 'modules' => [
'test.unknown' ],
338 'modules' => [
'test.styles.private' ],
340 'output' =>
'<style>.private{}</style>',
344 'modules' => [
'test.private' ],
346 'output' =>
'<script>(window.RLQ=window.RLQ||[]).push(function(){mw.loader.implement("test.private@{blankVer}",function($,jQuery,require,module){},{"css":[]});});</script>',
351 'modules' => [
'test.scripts.raw' ],
353 'output' =>
'<script async="" src="/w/load.php?debug=false&lang=nl&modules=test.scripts.raw&only=scripts&skin=fallback"></script>',
356 'context' => [
'sync' =>
true ],
357 'modules' => [
'test.scripts.raw' ],
359 'output' =>
'<script src="/w/load.php?debug=false&lang=nl&modules=test.scripts.raw&only=scripts&skin=fallback&sync=1"></script>',
363 'modules' => [
'test.scripts.user' ],
365 'output' =>
'<script>(window.RLQ=window.RLQ||[]).push(function(){mw.loader.load("/w/load.php?debug=false\u0026lang=nl\u0026modules=test.scripts.user\u0026only=scripts\u0026skin=fallback\u0026user=Example\u0026version=0a56zyi");});</script>',
369 'modules' => [
'test.user' ],
371 'output' =>
'<script>(window.RLQ=window.RLQ||[]).push(function(){mw.loader.load("/w/load.php?debug=false\u0026lang=nl\u0026modules=test.user\u0026skin=fallback\u0026user=Example\u0026version=0a56zyi");});</script>',
374 'context' => [
'debug' =>
true ],
375 'modules' => [
'test.styles.pure',
'test.styles.mixed' ],
377 'output' =>
'<link rel="stylesheet" href="/w/load.php?debug=true&lang=nl&modules=test.styles.mixed&only=styles&skin=fallback"/>' .
"\n"
378 .
'<link rel="stylesheet" href="/w/load.php?debug=true&lang=nl&modules=test.styles.pure&only=styles&skin=fallback"/>',
381 'context' => [
'debug' =>
false ],
382 'modules' => [
'test.styles.pure',
'test.styles.mixed' ],
384 'output' =>
'<link rel="stylesheet" href="/w/load.php?debug=false&lang=nl&modules=test.styles.mixed%2Cpure&only=styles&skin=fallback"/>',
388 'modules' => [
'test.styles.noscript' ],
390 'output' =>
'<noscript><link rel="stylesheet" href="/w/load.php?debug=false&lang=nl&modules=test.styles.noscript&only=styles&skin=fallback"/></noscript>',
394 'modules' => [
'test.shouldembed' ],
396 'output' =>
'<script>(window.RLQ=window.RLQ||[]).push(function(){mw.loader.implement("test.shouldembed@09p30q0",function($,jQuery,require,module){},{"css":[]});});</script>',
400 'modules' => [
'test.styles.shouldembed' ],
402 'output' =>
'<style>.shouldembed{}</style>',
406 'modules' => [
'test.scripts.shouldembed' ],
408 'output' =>
'<script>(window.RLQ=window.RLQ||[]).push(function(){mw.loader.state({"test.scripts.shouldembed":"ready"});});</script>',
412 'modules' => [
'test',
'test.shouldembed' ],
414 'output' =>
'<script>(window.RLQ=window.RLQ||[]).push(function(){mw.loader.load("/w/load.php?debug=false\u0026lang=nl\u0026modules=test\u0026skin=fallback");mw.loader.implement("test.shouldembed@09p30q0",function($,jQuery,require,module){},{"css":[]});});</script>',
418 'modules' => [
'test.styles.pure',
'test.styles.shouldembed' ],
421 '<link rel="stylesheet" href="/w/load.php?debug=false&lang=nl&modules=test.styles.pure&only=styles&skin=fallback"/>' .
"\n"
422 .
'<style>.shouldembed{}</style>'
426 'modules' => [
'test.ordering.a',
'test.ordering.e',
'test.ordering.b',
'test.ordering.d',
'test.ordering.c' ],
429 '<link rel="stylesheet" href="/w/load.php?debug=false&lang=nl&modules=test.ordering.a%2Cb&only=styles&skin=fallback"/>' .
"\n"
430 .
'<style>.orderingC{}.orderingD{}</style>' .
"\n"
431 .
'<link rel="stylesheet" href="/w/load.php?debug=false&lang=nl&modules=test.ordering.e&only=styles&skin=fallback"/>'
451 $context->getResourceLoader()->register( self::makeSampleModules() );
454 $this->assertEquals( $expected, (
string)$actual );
WebRequest clone which takes values from a provided array.
A Config instance which stores all settings as a member variable.
static makeModule(array $options=[])
testGetData()
ResourceLoaderClientHtml::__construct ResourceLoaderClientHtml::setModules ResourceLoaderClientHtml::...
testGetHeadHtml()
ResourceLoaderClientHtml::setConfig ResourceLoaderClientHtml::setExemptStates ResourceLoaderClientHtm...
static makeSampleModules()
testGetHeadHtmlWithNullTarget()
Confirm that a null 'target' is the same as no target.
testGetDocumentAttributes()
ResourceLoaderClientHtml::getDocumentAttributes.
testGetHeadHtmlWithSafemode()
Confirm that 'safemode' is passed down to startup.
testGetBodyHtml()
ResourceLoaderClientHtml::getBodyHtml ResourceLoaderClientHtml::getLoad.
testGetHeadHtmlWithTarget()
Confirm that 'target' is passed down to the startup module's load url.
testMakeLoad(array $extraQuery, array $modules, $type, $expected)
provideMakeLoad ResourceLoaderClientHtml::makeLoad ResourceLoaderClientHtml::makeContext ResourceLoad...
static makeContext( $extraQuery=[])
static expandVariables( $text)
Bootstrap a ResourceLoader client on an HTML page.
static makeLoad(ResourceLoaderContext $mainContext, array $modules, $only, array $extraQuery=[], $nonce=null)
Explicily load or embed modules on a page.
Object passed around to modules which contains information about the state of a specific loader reque...
Dynamic JavaScript and CSS resource loading system.
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
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
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
processing should stop and the error should be shown to the user * false
The wiki should then use memcached to cache various data To use multiple just add more items to the array To increase the weight of a make its entry a array("192.168.0.1:11211", 2))