diff options
author | Luke Shumaker <lukeshu@sbcglobal.net> | 2016-05-01 15:32:59 -0400 |
---|---|---|
committer | Luke Shumaker <lukeshu@sbcglobal.net> | 2016-05-01 15:32:59 -0400 |
commit | 6dc1997577fab2c366781fd7048144935afa0012 (patch) | |
tree | 8918d28c7ab4342f0738985e37af1dfc42d0e93a /tests/phpunit/includes/resourceloader/ResourceLoaderModuleTest.php | |
parent | 150f94f051128f367bc89f6b7e5f57eb2a69fc62 (diff) | |
parent | fa89acd685cb09cdbe1c64cbb721ec64975bbbc1 (diff) |
Merge commit 'fa89acd'
# Conflicts:
# .gitignore
# extensions/ArchInterWiki.sql
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' + ); + } } |