'script' => "var a = 'this is';\n {\ninvalid"
] );
$this->assertEquals(
- $module->getScript( $context ),
'mw.log.error(' .
'"JavaScript parse error: Parse error: Unexpected token; ' .
'token } expected in file \'input\' on line 3"' .
');',
+ $module->getScript( $context ),
'Replace invalid syntax with error logging'
);
'script' => "\n'valid';"
] );
$this->assertEquals(
- $module->getScript( $context ),
"\n'valid';",
+ $module->getScript( $context ),
'Leave valid scripts as-is'
);
}
+ public static function provideBuildContentScripts() {
+ return [
+ [
+ "mw.foo()",
+ "mw.foo()\n",
+ ],
+ [
+ "mw.foo();",
+ "mw.foo();\n",
+ ],
+ [
+ "mw.foo();\n",
+ "mw.foo();\n",
+ ],
+ [
+ "mw.foo()\n",
+ "mw.foo()\n",
+ ],
+ [
+ "mw.foo()\n// mw.bar();",
+ "mw.foo()\n// mw.bar();\n",
+ ],
+ [
+ "mw.foo()\n// mw.bar()",
+ "mw.foo()\n// mw.bar()\n",
+ ],
+ [
+ "mw.foo()// mw.bar();",
+ "mw.foo()// mw.bar();\n",
+ ],
+ ];
+ }
+
+ /**
+ * @dataProvider provideBuildContentScripts
+ * @covers ResourceLoaderModule::buildContent
+ */
+ public function testBuildContentScripts( $raw, $build, $message = null ) {
+ $context = $this->getResourceLoaderContext();
+ $module = new ResourceLoaderTestModule( [
+ 'script' => $raw
+ ] );
+ $this->assertEquals( $raw, $module->getScript( $context ), 'Raw script' );
+ $this->assertEquals(
+ [ 'scripts' => $build ],
+ $module->getModuleContent( $context ),
+ $message
+ );
+ }
+
/**
* @covers ResourceLoaderModule::getRelativePaths
* @covers ResourceLoaderModule::expandRelativePaths
'../skins/Example/images/quux.png',
];
$this->assertEquals(
- $getRelativePaths->invoke( null, $raw ),
$canonical,
+ $getRelativePaths->invoke( null, $raw ),
'Insert placeholders'
);
$this->assertEquals(
- $expandRelativePaths->invoke( null, $canonical ),
$raw,
+ $expandRelativePaths->invoke( null, $canonical ),
'Substitute placeholders'
);
}