14 'scripts' => [
'foo.js',
'bar.js' ],
15 'dependencies' => [
'jquery',
'mediawiki' ],
16 'messages' => [
'hello',
'world' ],
20 $version = json_encode( $module->getVersionHash(
$context ) );
26 json_encode( $module->getVersionHash(
$context ) ),
27 'Instance is insignificant'
32 'dependencies' => [
'mediawiki',
'jquery' ],
36 json_encode( $module->getVersionHash(
$context ) ),
37 'Order of dependencies is insignificant'
42 'messages' => [
'world',
'hello' ],
46 json_encode( $module->getVersionHash(
$context ) ),
47 'Order of messages is insignificant'
52 'scripts' => [
'bar.js',
'foo.js' ],
54 $this->assertNotEquals(
56 json_encode( $module->getVersionHash(
$context ) ),
57 'Order of scripts is significant'
62 $this->assertNotEquals(
64 json_encode( $module->getVersionHash(
$context ) ),
65 'Class is significant'
73 $this->
setMwGlobals(
'wgResourceLoaderValidateJS',
true );
78 'script' =>
"var a = 'this is';\n {\ninvalid"
82 '"JavaScript parse error: Parse error: Unexpected token; ' .
83 'token } expected in file \'input\' on line 3"' .
86 'Replace invalid syntax with error logging'
90 'script' =>
"\n'valid';"
95 'Leave valid scripts as-is'
118 "mw.foo()\n// mw.bar();",
119 "mw.foo()\n// mw.bar();\n",
122 "mw.foo()\n// mw.bar()",
123 "mw.foo()\n// mw.bar()\n",
126 "mw.foo()// mw.bar();",
127 "mw.foo()// mw.bar();\n",
141 $this->assertEquals( $raw, $module->getScript(
$context ),
'Raw script' );
143 [
'scripts' => $build ],
144 $module->getModuleContent(
$context ),
154 $getRelativePaths =
new ReflectionMethod( ResourceLoaderModule::class,
'getRelativePaths' );
155 $getRelativePaths->setAccessible(
true );
156 $expandRelativePaths =
new ReflectionMethod( ResourceLoaderModule::class,
'expandRelativePaths' );
157 $expandRelativePaths->setAccessible(
true );
160 'IP' =>
'/srv/example/mediawiki/core',
163 '/srv/example/mediawiki/core/resources/foo.js',
164 '/srv/example/mediawiki/core/extensions/Example/modules/bar.js',
165 '/srv/example/mediawiki/skins/Example/baz.css',
166 '/srv/example/mediawiki/skins/Example/images/quux.png',
170 'extensions/Example/modules/bar.js',
171 '../skins/Example/baz.css',
172 '../skins/Example/images/quux.png',
176 $getRelativePaths->invoke(
null, $raw ),
177 'Insert placeholders'
181 $expandRelativePaths->invoke(
null, $canonical ),
182 'Substitute placeholders'
194 $this->assertSame( [], $module->getHeaders(
$context ),
'Default' );
196 $module = $this->getMockBuilder( ResourceLoaderTestModule::class )
197 ->setMethods( [
'getPreloadLinks' ] )->getMock();
198 $module->method(
'getPreloadLinks' )->willReturn( [
199 'https://example.org/script.js' => [
'as' =>
'script' ],
203 'Link: <https://example.org/script.js>;rel=preload;as=script'
206 'Preload one resource'
209 $module = $this->getMockBuilder( ResourceLoaderTestModule::class )
210 ->setMethods( [
'getPreloadLinks' ] )->getMock();
211 $module->method(
'getPreloadLinks' )->willReturn( [
212 'https://example.org/script.js' => [
'as' =>
'script' ],
213 '/example.png' => [
'as' =>
'image' ],
217 'Link: <https://example.org/script.js>;rel=preload;as=script,' .
218 '</example.png>;rel=preload;as=image'
221 'Preload two resources'
ResourceLoader module based on local JavaScript/CSS files.
testValidateScriptFile()
ResourceLoaderModule::validateScriptFile.
testGetVersionHash()
ResourceLoaderModule::getVersionHash ResourceLoaderModule::getModifiedTime ResourceLoaderModule::getM...
testGetHeaders()
ResourceLoaderModule::getHeaders ResourceLoaderModule::getPreloadLinks.
testPlaceholderize()
ResourceLoaderModule::getRelativePaths ResourceLoaderModule::expandRelativePaths.
testBuildContentScripts( $raw, $build, $message=null)
provideBuildContentScripts ResourceLoaderModule::buildContent
static provideBuildContentScripts()
getResourceLoaderContext( $options=[], ResourceLoader $rl=null)
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