11 use MediaWikiCoversValidator;
15 $context->getResourceLoader()->register( self::makeSampleModules() );
18 $client->setModules( [
21 'test.shouldembed.empty',
26 $client->setModuleStyles( [
28 'test.styles.user.empty',
29 'test.styles.private',
31 'test.styles.shouldembed',
32 'test.styles.deprecated',
33 'test.unregistered.styles',
48 'test.private' =>
'loading',
49 'test.shouldembed' =>
'loading',
50 'test.user' =>
'loading',
53 'test.shouldembed.empty' =>
'ready',
54 'test.styles.pure' =>
'ready',
55 'test.styles.user.empty' =>
'ready',
56 'test.styles.private' =>
'ready',
57 'test.styles.shouldembed' =>
'ready',
58 'test.styles.deprecated' =>
'ready',
65 'test.styles.deprecated',
68 'styles' => [
'test.styles.private',
'test.styles.shouldembed' ],
75 'styleDeprecations' => [
78 [
'This page is using the deprecated ResourceLoader module "test.styles.deprecated".
79Deprecation message.' ]
84 $access = TestingAccessWrapper::newFromObject( $client );
90 $context->getResourceLoader()->register( self::makeSampleModules() );
95 $client->setConfig( [
'key' =>
'value' ] );
96 $client->setModules( [
100 $client->setModuleStyles( [
102 'test.styles.private',
103 'test.styles.deprecated',
105 $client->setExemptStates( [
106 'test.exempt' =>
'ready',
110 $expected =
'<script>document.documentElement.className = document.documentElement.className.replace( /(^|\s)client-nojs(\s|$)/, "$1client-js$2" );</script>' .
"\n"
111 .
'<script>(window.RLQ=window.RLQ||[]).push(function(){'
112 .
'mw.config.set({"key":"value"});'
113 .
'mw.loader.state({"test.exempt":"ready","test.private":"loading","test.styles.pure":"ready","test.styles.private":"ready","test.styles.deprecated":"ready"});'
114 .
'mw.loader.implement("test.private@{blankVer}",null,{"css":[]});'
115 .
'RLPAGEMODULES=["test"];mw.loader.load(RLPAGEMODULES);'
116 .
'});</script>' .
"\n"
117 .
'<link rel="stylesheet" href="/w/load.php?lang=nl&modules=test.styles.deprecated%2Cpure&only=styles&skin=fallback"/>' .
"\n"
118 .
'<style>.private{}</style>' .
"\n"
119 .
'<script async="" src="/w/load.php?lang=nl&modules=startup&only=scripts&skin=fallback"></script>';
123 $this->
assertSame( $expected, (
string)$client->getHeadHtml() );
132 [
'target' =>
'example' ]
136 $expected =
'<script>document.documentElement.className = document.documentElement.className.replace( /(^|\s)client-nojs(\s|$)/, "$1client-js$2" );</script>' .
"\n"
137 .
'<script async="" src="/w/load.php?lang=nl&modules=startup&only=scripts&skin=fallback&target=example"></script>';
140 $this->
assertSame( $expected, (
string)$client->getHeadHtml() );
149 [
'safemode' =>
'1' ]
153 $expected =
'<script>document.documentElement.className = document.documentElement.className.replace( /(^|\s)client-nojs(\s|$)/, "$1client-js$2" );</script>' .
"\n"
154 .
'<script async="" src="/w/load.php?lang=nl&modules=startup&only=scripts&safemode=1&skin=fallback"></script>';
157 $this->
assertSame( $expected, (
string)$client->getHeadHtml() );
170 $expected =
'<script>document.documentElement.className = document.documentElement.className.replace( /(^|\s)client-nojs(\s|$)/, "$1client-js$2" );</script>' .
"\n"
171 .
'<script async="" src="/w/load.php?lang=nl&modules=startup&only=scripts&skin=fallback"></script>';
174 $this->
assertSame( $expected, (
string)$client->getHeadHtml() );
179 $context->getResourceLoader()->register( self::makeSampleModules() );
182 $client->setConfig( [
'key' =>
'value' ] );
183 $client->setModules( [
185 'test.private.bottom',
187 $client->setModuleStyles( [
188 'test.styles.deprecated',
191 $expected =
'<script>(window.RLQ=window.RLQ||[]).push(function(){'
192 .
'mw.log.warn("This page is using the deprecated ResourceLoader module \"test.styles.deprecated\".\nDeprecation message.");'
196 $this->
assertSame( $expected, (
string)$client->getBodyHtml() );
204 'modules' => [
'test.unknown' ],
211 'modules' => [
'test.styles.private' ],
214 'output' =>
'<style>.private{}</style>',
218 'modules' => [
'test.private' ],
221 'output' =>
'<script>(window.RLQ=window.RLQ||[]).push(function(){mw.loader.implement("test.private@{blankVer}",null,{"css":[]});});</script>',
226 'modules' => [
'test.scripts.raw' ],
229 'output' =>
'<script async="" src="/w/load.php?lang=nl&modules=test.scripts.raw&only=scripts&skin=fallback"></script>',
233 'modules' => [
'test.scripts.raw' ],
235 'extra' => [
'sync' =>
'1' ],
236 'output' =>
'<script src="/w/load.php?lang=nl&modules=test.scripts.raw&only=scripts&skin=fallback&sync=1"></script>',
240 'modules' => [
'test.scripts.user' ],
243 'output' =>
'<script>(window.RLQ=window.RLQ||[]).push(function(){mw.loader.load("/w/load.php?lang=nl\u0026modules=test.scripts.user\u0026only=scripts\u0026skin=fallback\u0026user=Example\u0026version=0a56zyi");});</script>',
247 'modules' => [
'test.user' ],
250 'output' =>
'<script>(window.RLQ=window.RLQ||[]).push(function(){mw.loader.load("/w/load.php?lang=nl\u0026modules=test.user\u0026skin=fallback\u0026user=Example\u0026version=0a56zyi");});</script>',
253 'context' => [
'debug' =>
'true' ],
254 'modules' => [
'test.styles.pure',
'test.styles.mixed' ],
257 'output' =>
'<link rel="stylesheet" href="/w/load.php?debug=true&lang=nl&modules=test.styles.mixed&only=styles&skin=fallback"/>' .
"\n"
258 .
'<link rel="stylesheet" href="/w/load.php?debug=true&lang=nl&modules=test.styles.pure&only=styles&skin=fallback"/>',
261 'context' => [
'debug' =>
'false' ],
262 'modules' => [
'test.styles.pure',
'test.styles.mixed' ],
265 'output' =>
'<link rel="stylesheet" href="/w/load.php?lang=nl&modules=test.styles.mixed%2Cpure&only=styles&skin=fallback"/>',
269 'modules' => [
'test.styles.noscript' ],
272 'output' =>
'<noscript><link rel="stylesheet" href="/w/load.php?lang=nl&modules=test.styles.noscript&only=styles&skin=fallback"/></noscript>',
276 'modules' => [
'test.shouldembed' ],
279 'output' =>
'<script>(window.RLQ=window.RLQ||[]).push(function(){mw.loader.implement("test.shouldembed@09p30q0",null,{"css":[]});});</script>',
283 'modules' => [
'test.styles.shouldembed' ],
286 'output' =>
'<style>.shouldembed{}</style>',
290 'modules' => [
'test.scripts.shouldembed' ],
293 'output' =>
'<script>(window.RLQ=window.RLQ||[]).push(function(){mw.loader.state({"test.scripts.shouldembed":"ready"});});</script>',
297 'modules' => [
'test',
'test.shouldembed' ],
300 'output' =>
'<script>(window.RLQ=window.RLQ||[]).push(function(){mw.loader.load("/w/load.php?lang=nl\u0026modules=test\u0026skin=fallback");mw.loader.implement("test.shouldembed@09p30q0",null,{"css":[]});});</script>',
304 'modules' => [
'test.styles.pure',
'test.styles.shouldembed' ],
308 '<link rel="stylesheet" href="/w/load.php?lang=nl&modules=test.styles.pure&only=styles&skin=fallback"/>' .
"\n"
309 .
'<style>.shouldembed{}</style>'
313 'modules' => [
'test.ordering.a',
'test.ordering.e',
'test.ordering.b',
'test.ordering.d',
'test.ordering.c' ],
317 '<link rel="stylesheet" href="/w/load.php?lang=nl&modules=test.ordering.a%2Cb&only=styles&skin=fallback"/>' .
"\n"
318 .
'<style>.orderingC{}.orderingD{}</style>' .
"\n"
319 .
'<link rel="stylesheet" href="/w/load.php?lang=nl&modules=test.ordering.e&only=styles&skin=fallback"/>'
339 $context->getResourceLoader()->register( self::makeSampleModules() );
342 $this->
assertSame( $expected, (
string)$actual );
351 return strtr( $text, [
358 'ResourceModuleSkinStyles' => [],
359 'ResourceModules' => [],
360 'EnableJavaScriptTest' =>
false,
361 'LoadScript' =>
'/w/load.php',
367 'skin' =>
'fallback',
369 'target' =>
'phpunit',
381 'test.private' => [
'group' =>
'private' ],
382 'test.shouldembed.empty' => [
'shouldEmbed' =>
true,
'isKnownEmpty' =>
true ],
383 'test.shouldembed' => [
'shouldEmbed' =>
true ],
384 'test.user' => [
'group' =>
'user' ],
387 'test.styles.mixed' => [],
388 'test.styles.noscript' => [
390 'group' =>
'noscript',
392 'test.styles.user' => [
396 'test.styles.user.empty' => [
399 'isKnownEmpty' =>
true,
401 'test.styles.private' => [
403 'group' =>
'private',
404 'styles' =>
'.private{}',
406 'test.styles.shouldembed' => [
408 'shouldEmbed' =>
true,
409 'styles' =>
'.shouldembed{}',
411 'test.styles.deprecated' => [
413 'deprecated' =>
'Deprecation message.',
416 'test.scripts' => [],
417 'test.scripts.user' => [
'group' =>
'user' ],
418 'test.scripts.user.empty' => [
'group' =>
'user',
'isKnownEmpty' =>
true ],
419 'test.scripts.raw' => [
'isRaw' =>
true ],
420 'test.scripts.shouldembed' => [
'shouldEmbed' =>
true ],
422 'test.ordering.a' => [
'shouldEmbed' =>
false ],
423 'test.ordering.b' => [
'shouldEmbed' =>
false ],
424 'test.ordering.c' => [
'shouldEmbed' =>
true,
'styles' =>
'.orderingC{}' ],
425 'test.ordering.d' => [
'shouldEmbed' =>
true,
'styles' =>
'.orderingD{}' ],
426 'test.ordering.e' => [
'shouldEmbed' =>
false ],
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
WebRequest clone which takes values from a provided array.
A Config instance which stores all settings as a member variable.
ResourceLoader ResourceLoaderClientHtml.
static makeModule(array $options=[])
static makeSampleModules()
testGetHeadHtmlWithNullTarget()
Confirm that a null 'target' is the same as no target.
testGetDocumentAttributes()
testGetHeadHtmlWithSafemode()
Confirm that 'safemode' is passed down to startup.
testGetHeadHtmlWithTarget()
Confirm that 'target' is passed down to the startup module's load url.
testMakeLoad(array $contextQuery, array $modules, $type, array $extraQuery, $expected)
provideMakeLoad ResourceLoaderClientHtml ResourceLoaderModule::getModuleContent ResourceLoader
static makeContext( $extraQuery=[])
static expandVariables( $text)
Load and configure 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))