12 'scripts' => [
'foo.js',
'bar.js' ],
13 'dependencies' => [
'jquery',
'mediawiki' ],
14 'messages' => [
'hello',
'world' ],
18 $version = json_encode( $module->getVersionHash(
$context ) );
24 json_encode( $module->getVersionHash(
$context ) ),
25 'Instance is insignificant'
30 'dependencies' => [
'mediawiki',
'jquery' ],
34 json_encode( $module->getVersionHash(
$context ) ),
35 'Order of dependencies is insignificant'
40 'messages' => [
'world',
'hello' ],
44 json_encode( $module->getVersionHash(
$context ) ),
45 'Order of messages is insignificant'
50 'scripts' => [
'bar.js',
'foo.js' ],
52 $this->assertNotEquals(
54 json_encode( $module->getVersionHash(
$context ) ),
55 'Order of scripts is significant'
60 $this->assertNotEquals(
62 json_encode( $module->getVersionHash(
$context ) ),
63 'Class is significant'
72 $module = $this->getMockBuilder( ResourceLoaderModule::class )
73 ->setMethods( [
'getDefinitionSummary' ] )->getMock();
74 $module->method(
'getDefinitionSummary' )->willReturn( [
'a' =>
'summary' ] );
76 $this->setExpectedException( LogicException::class,
'must call parent' );
84 $this->
setMwGlobals(
'wgResourceLoaderValidateJS',
true );
89 'script' =>
"var a = 'this is';\n {\ninvalid"
93 '"JavaScript parse error: Parse error: Unexpected token; ' .
94 'token } expected in file \'input\' on line 3"' .
97 'Replace invalid syntax with error logging'
101 'script' =>
"\n'valid';"
106 'Leave valid scripts as-is'
129 "mw.foo()\n// mw.bar();",
130 "mw.foo()\n// mw.bar();\n",
133 "mw.foo()\n// mw.bar()",
134 "mw.foo()\n// mw.bar()\n",
137 "mw.foo()// mw.bar();",
138 "mw.foo()// mw.bar();\n",
152 $this->assertEquals( $raw, $module->getScript(
$context ),
'Raw script' );
155 $module->getModuleContent(
$context )[
'scripts' ],
165 $getRelativePaths =
new ReflectionMethod( ResourceLoaderModule::class,
'getRelativePaths' );
166 $getRelativePaths->setAccessible(
true );
167 $expandRelativePaths =
new ReflectionMethod( ResourceLoaderModule::class,
'expandRelativePaths' );
168 $expandRelativePaths->setAccessible(
true );
171 'IP' =>
'/srv/example/mediawiki/core',
174 '/srv/example/mediawiki/core/resources/foo.js',
175 '/srv/example/mediawiki/core/extensions/Example/modules/bar.js',
176 '/srv/example/mediawiki/skins/Example/baz.css',
177 '/srv/example/mediawiki/skins/Example/images/quux.png',
181 'extensions/Example/modules/bar.js',
182 '../skins/Example/baz.css',
183 '../skins/Example/images/quux.png',
187 $getRelativePaths->invoke(
null, $raw ),
188 'Insert placeholders'
192 $expandRelativePaths->invoke(
null, $canonical ),
193 'Substitute placeholders'
205 $this->assertSame( [], $module->getHeaders(
$context ),
'Default' );
207 $module = $this->getMockBuilder( ResourceLoaderTestModule::class )
208 ->setMethods( [
'getPreloadLinks' ] )->getMock();
209 $module->method(
'getPreloadLinks' )->willReturn( [
210 'https://example.org/script.js' => [
'as' =>
'script' ],
214 'Link: <https://example.org/script.js>;rel=preload;as=script'
217 'Preload one resource'
220 $module = $this->getMockBuilder( ResourceLoaderTestModule::class )
221 ->setMethods( [
'getPreloadLinks' ] )->getMock();
222 $module->method(
'getPreloadLinks' )->willReturn( [
223 'https://example.org/script.js' => [
'as' =>
'script' ],
224 '/example.png' => [
'as' =>
'image' ],
228 'Link: <https://example.org/script.js>;rel=preload;as=script,' .
229 '</example.png>;rel=preload;as=image'
232 'Preload two resources'
ResourceLoader module based on local JavaScript/CSS files.
testValidateScriptFile()
ResourceLoaderModule::validateScriptFile.
testGetVersionHash_parentDefinition()
ResourceLoaderModule::getVersionHash.
testGetVersionHash()
ResourceLoaderModule::getVersionHash.
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