Krinkle has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/361622 )
Change subject: resourceloader: Add basic tests for getScript() and buildContent() ...................................................................... resourceloader: Add basic tests for getScript() and buildContent() Bug: T162719 Change-Id: I37d64da77682adfef61e78033d639b623d7c9c2b --- A tests/phpunit/data/resourceloader/script-comment.js A tests/phpunit/data/resourceloader/script-nosemi.js M tests/phpunit/includes/resourceloader/ResourceLoaderFileModuleTest.php M tests/phpunit/includes/resourceloader/ResourceLoaderModuleTest.php 4 files changed, 66 insertions(+), 3 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core refs/changes/22/361622/1 diff --git a/tests/phpunit/data/resourceloader/script-comment.js b/tests/phpunit/data/resourceloader/script-comment.js new file mode 100644 index 0000000..46b60f9 --- /dev/null +++ b/tests/phpunit/data/resourceloader/script-comment.js @@ -0,0 +1,3 @@ +/* eslint-disable */ +mw.foo() +// mw.bar(); diff --git a/tests/phpunit/data/resourceloader/script-nosemi.js b/tests/phpunit/data/resourceloader/script-nosemi.js new file mode 100644 index 0000000..2b1550f --- /dev/null +++ b/tests/phpunit/data/resourceloader/script-nosemi.js @@ -0,0 +1,2 @@ +/* eslint-disable */ +mw.foo() diff --git a/tests/phpunit/includes/resourceloader/ResourceLoaderFileModuleTest.php b/tests/phpunit/includes/resourceloader/ResourceLoaderFileModuleTest.php index 9750ea4..ded56e9 100644 --- a/tests/phpunit/includes/resourceloader/ResourceLoaderFileModuleTest.php +++ b/tests/phpunit/includes/resourceloader/ResourceLoaderFileModuleTest.php @@ -132,10 +132,30 @@ */ public function testDeprecatedModules( $name, $expected ) { $modules = self::getModules(); - $rl = new ResourceLoaderFileModule( $modules[$name] ); - $rl->setName( $name ); + $module = new ResourceLoaderFileModule( $modules[$name] ); + $module->setName( $name ); $ctx = $this->getResourceLoaderContext(); - $this->assertEquals( $rl->getScript( $ctx ), $expected ); + $this->assertEquals( $module->getScript( $ctx ), $expected ); + } + + /** + * @covers ResourceLoaderFileModule::getScript + */ + public function testGetScript() { + $module = new ResourceLoaderFileModule( [ + 'localBasePath' => __DIR__ . '/../../data/resourceloader', + 'scripts' => [ 'script-nosemi.js', 'script-comment.js' ], + ] ); + $module->setName( 'testing' ); + $ctx = $this->getResourceLoaderContext(); + $this->assertEquals( + "/* eslint-disable */\nmw.foo()\n" . + "\n" . + "/* eslint-disable */\nmw.foo()\n// mw.bar();\n" . + "\n", + $module->getScript( $ctx ), + 'scripts are concatenated with a new-line' + ); } /** diff --git a/tests/phpunit/includes/resourceloader/ResourceLoaderModuleTest.php b/tests/phpunit/includes/resourceloader/ResourceLoaderModuleTest.php index 17861d8..937a144 100644 --- a/tests/phpunit/includes/resourceloader/ResourceLoaderModuleTest.php +++ b/tests/phpunit/includes/resourceloader/ResourceLoaderModuleTest.php @@ -94,6 +94,44 @@ ); } + public static function provideBuildContentScripts() { + return [ + [ + 'mw.foo()', + "mw.foo();\n", + ], + [ + "mw.foo();", + "mw.foo();", + ], + [ + "mw.foo();\n", + "mw.foo();\n", + ], + [ + "mw.foo()\n", + "mw.foo()\n;\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 -- To view, visit https://gerrit.wikimedia.org/r/361622 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I37d64da77682adfef61e78033d639b623d7c9c2b Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/core Gerrit-Branch: master Gerrit-Owner: Krinkle <krinklem...@gmail.com> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits