aboutsummaryrefslogtreecommitdiffstats
path: root/tests/phpunit/includes/ResourceLoaderTest.php
diff options
context:
space:
mode:
authorChad Horohoe <demon@users.mediawiki.org>2010-12-14 16:26:35 +0000
committerChad Horohoe <demon@users.mediawiki.org>2010-12-14 16:26:35 +0000
commit23f69f10ed07c7fbe7d752882a88d55351ce2e3d (patch)
tree43054aea852645def63951fcbf45eb2cf2551adb /tests/phpunit/includes/ResourceLoaderTest.php
parent5903e492a5c60f65182d6339f63693aa2dca92f0 (diff)
downloadmediawikicore-23f69f10ed07c7fbe7d752882a88d55351ce2e3d.tar.gz
mediawikicore-23f69f10ed07c7fbe7d752882a88d55351ce2e3d.zip
Per wikitech-l discussion: Move tests from maintenance/tests/ to tests/. They're not strictly maintenance scripts, and some people want to do a selective checkout that doesn't include the tests. There's still debate on whether we should include these in the release downloads, but we had a pretty firm consensus to move this.
Notes
Notes: http://mediawiki.org/wiki/Special:Code/MediaWiki/78383
Diffstat (limited to 'tests/phpunit/includes/ResourceLoaderTest.php')
-rw-r--r--tests/phpunit/includes/ResourceLoaderTest.php71
1 files changed, 71 insertions, 0 deletions
diff --git a/tests/phpunit/includes/ResourceLoaderTest.php b/tests/phpunit/includes/ResourceLoaderTest.php
new file mode 100644
index 000000000000..8de178a951dd
--- /dev/null
+++ b/tests/phpunit/includes/ResourceLoaderTest.php
@@ -0,0 +1,71 @@
+<?php
+
+class ResourceLoaderTest extends PHPUnit_Framework_TestCase {
+
+ protected static $resourceLoaderRegisterModulesHook;
+
+ /* Hook Methods */
+
+ /**
+ * ResourceLoaderRegisterModules hook
+ */
+ public static function resourceLoaderRegisterModules( &$resourceLoader ) {
+ self::$resourceLoaderRegisterModulesHook = true;
+ return true;
+ }
+
+ /* Provider Methods */
+ public function provideValidModules() {
+ return array(
+ array( 'TEST.validModule1', new ResourceLoaderTestModule() ),
+ );
+ }
+
+ /* Test Methods */
+
+ /**
+ * Ensures that the ResourceLoaderRegisterModules hook is called when a new ResourceLoader object is constructed
+ * @covers ResourceLoader::__construct
+ */
+ public function testCreatingNewResourceLoaderCallsRegistrationHook() {
+ self::$resourceLoaderRegisterModulesHook = false;
+ $resourceLoader = new ResourceLoader();
+ $this->assertTrue( self::$resourceLoaderRegisterModulesHook );
+ return $resourceLoader;
+ }
+
+ /**
+ * @dataProvider provideValidModules
+ * @depends testCreatingNewResourceLoaderCallsRegistrationHook
+ * @covers ResourceLoader::register
+ * @covers ResourceLoader::getModule
+ */
+ public function testRegisteredValidModulesAreAccessible(
+ $name, ResourceLoaderModule $module, ResourceLoader $resourceLoader
+ ) {
+ $resourceLoader->register( $name, $module );
+ $this->assertEquals( $module, $resourceLoader->getModule( $name ) );
+ }
+
+ /**
+ * Allthough ResourceLoader::register uses type hinting to prevent arbitrary information being passed through as a
+ * ResourceLoaderModule object, null can still get through.
+ *
+ * @depends testCreatingNewResourceLoaderCallsRegistrationHook
+ * @covers ResourceLoader::register
+ * @covers ResourceLoader::getModule
+ * @expectedException MWException
+ */
+ public function testRegisteringNullModuleThrowsAnException( ResourceLoader $resourceLoader ) {
+ $this->markTestIncomplete( "Broken by r77011" );
+ $resourceLoader->register( 'TEST.nullModule', null );
+ }
+}
+
+/* Stubs */
+
+class ResourceLoaderTestModule extends ResourceLoaderModule { }
+
+/* Hooks */
+global $wgHooks;
+$wgHooks['ResourceLoaderRegisterModules'][] = 'ResourceLoaderTest::resourceLoaderRegisterModules'; \ No newline at end of file