3 class ResourceLoaderModuleTest
extends ResourceLoaderTestCase
{
6 * @covers ResourceLoaderModule::getVersionHash
8 public function testGetVersionHash() {
9 $context = $this->getResourceLoaderContext();
12 'scripts' => [ 'foo.js', 'bar.js' ],
13 'dependencies' => [ 'jquery', 'mediawiki' ],
14 'messages' => [ 'hello', 'world' ],
17 $module = new ResourceLoaderFileModule( $baseParams );
18 $version = json_encode( $module->getVersionHash( $context ) );
21 $module = new ResourceLoaderFileModule( $baseParams );
24 json_encode( $module->getVersionHash( $context ) ),
25 'Instance is insignificant'
28 // Re-order dependencies
29 $module = new ResourceLoaderFileModule( [
30 'dependencies' => [ 'mediawiki', 'jquery' ],
34 json_encode( $module->getVersionHash( $context ) ),
35 'Order of dependencies is insignificant'
39 $module = new ResourceLoaderFileModule( [
40 'messages' => [ 'world', 'hello' ],
44 json_encode( $module->getVersionHash( $context ) ),
45 'Order of messages is insignificant'
49 $module = new ResourceLoaderFileModule( [
50 'scripts' => [ 'bar.js', 'foo.js' ],
52 $this->assertNotEquals(
54 json_encode( $module->getVersionHash( $context ) ),
55 'Order of scripts is significant'
59 $module = new ResourceLoaderFileModuleTestModule( $baseParams );
60 $this->assertNotEquals(
62 json_encode( $module->getVersionHash( $context ) ),
63 'Class is significant'
68 * @covers ResourceLoaderModule::validateScriptFile
70 public function testValidateScriptFile() {
71 $this->setMwGlobals( 'wgResourceLoaderValidateJS', true );
73 $context = $this->getResourceLoaderContext();
75 $module = new ResourceLoaderTestModule( [
76 'script' => "var a = 'this is';\n {\ninvalid"
79 $module->getScript( $context ),
81 '"JavaScript parse error: Parse error: Unexpected token; ' .
82 'token } expected in file \'input\' on line 3"' .
84 'Replace invalid syntax with error logging'
87 $module = new ResourceLoaderTestModule( [
88 'script' => "\n'valid';"
91 $module->getScript( $context ),
93 'Leave valid scripts as-is'
98 * @covers ResourceLoaderModule::getRelativePaths
99 * @covers ResourceLoaderModule::expandRelativePaths
101 public function testPlaceholderize() {
102 $getRelativePaths = new ReflectionMethod( 'ResourceLoaderModule', 'getRelativePaths' );
103 $getRelativePaths->setAccessible( true );
104 $expandRelativePaths = new ReflectionMethod( 'ResourceLoaderModule', 'expandRelativePaths' );
105 $expandRelativePaths->setAccessible( true );
107 $this->setMwGlobals( [
108 'IP' => '/srv/example/mediawiki/core',
111 '/srv/example/mediawiki/core/resources/foo.js',
112 '/srv/example/mediawiki/core/extensions/Example/modules/bar.js',
113 '/srv/example/mediawiki/skins/Example/baz.css',
114 '/srv/example/mediawiki/skins/Example/images/quux.png',
118 'extensions/Example/modules/bar.js',
119 '../skins/Example/baz.css',
120 '../skins/Example/images/quux.png',
123 $getRelativePaths->invoke( null, $raw ),
125 'Insert placeholders'
128 $expandRelativePaths->invoke( null, $canonical ),
130 'Substitute placeholders'