diff options
Diffstat (limited to 'tests/phpunit/includes/resourceloader/ResourceLoaderModuleTest.php')
-rw-r--r-- | tests/phpunit/includes/resourceloader/ResourceLoaderModuleTest.php | 58 |
1 files changed, 38 insertions, 20 deletions
diff --git a/tests/phpunit/includes/resourceloader/ResourceLoaderModuleTest.php b/tests/phpunit/includes/resourceloader/ResourceLoaderModuleTest.php index 6d1ed4e0..41653fb0 100644 --- a/tests/phpunit/includes/resourceloader/ResourceLoaderModuleTest.php +++ b/tests/phpunit/includes/resourceloader/ResourceLoaderModuleTest.php @@ -3,10 +3,9 @@ class ResourceLoaderModuleTest extends ResourceLoaderTestCase { /** - * @covers ResourceLoaderModule::getDefinitionSummary - * @covers ResourceLoaderFileModule::getDefinitionSummary + * @covers ResourceLoaderModule::getVersionHash */ - public function testDefinitionSummary() { + public function testGetVersionHash() { $context = $this->getResourceLoaderContext(); $baseParams = array( @@ -16,15 +15,13 @@ class ResourceLoaderModuleTest extends ResourceLoaderTestCase { ); $module = new ResourceLoaderFileModule( $baseParams ); - - $jsonSummary = json_encode( $module->getDefinitionSummary( $context ) ); + $version = json_encode( $module->getVersionHash( $context ) ); // Exactly the same $module = new ResourceLoaderFileModule( $baseParams ); - $this->assertEquals( - $jsonSummary, - json_encode( $module->getDefinitionSummary( $context ) ), + $version, + json_encode( $module->getVersionHash( $context ) ), 'Instance is insignificant' ); @@ -32,10 +29,9 @@ class ResourceLoaderModuleTest extends ResourceLoaderTestCase { $module = new ResourceLoaderFileModule( array( 'dependencies' => array( 'mediawiki', 'jquery' ), ) + $baseParams ); - $this->assertEquals( - $jsonSummary, - json_encode( $module->getDefinitionSummary( $context ) ), + $version, + json_encode( $module->getVersionHash( $context ) ), 'Order of dependencies is insignificant' ); @@ -43,10 +39,9 @@ class ResourceLoaderModuleTest extends ResourceLoaderTestCase { $module = new ResourceLoaderFileModule( array( 'messages' => array( 'world', 'hello' ), ) + $baseParams ); - $this->assertEquals( - $jsonSummary, - json_encode( $module->getDefinitionSummary( $context ) ), + $version, + json_encode( $module->getVersionHash( $context ) ), 'Order of messages is insignificant' ); @@ -54,20 +49,43 @@ class ResourceLoaderModuleTest extends ResourceLoaderTestCase { $module = new ResourceLoaderFileModule( array( 'scripts' => array( 'bar.js', 'foo.js' ), ) + $baseParams ); - $this->assertNotEquals( - $jsonSummary, - json_encode( $module->getDefinitionSummary( $context ) ), + $version, + json_encode( $module->getVersionHash( $context ) ), 'Order of scripts is significant' ); // Subclass $module = new ResourceLoaderFileModuleTestModule( $baseParams ); - $this->assertNotEquals( - $jsonSummary, - json_encode( $module->getDefinitionSummary( $context ) ), + $version, + json_encode( $module->getVersionHash( $context ) ), 'Class is significant' ); } + + /** + * @covers ResourceLoaderModule::validateScriptFile + */ + public function testValidateScriptFile() { + $context = $this->getResourceLoaderContext(); + + $module = new ResourceLoaderTestModule( array( + '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");', + 'Replace invalid syntax with error logging' + ); + + $module = new ResourceLoaderTestModule( array( + 'script' => "\n'valid';" + ) ); + $this->assertEquals( + $module->getScript( $context ), + "\n'valid';", + 'Leave valid scripts as-is' + ); + } } |