r74012 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r74011‎ | r74012 | r74013 >
Date:06:54, 30 September 2010
Author:tparscal
Status:ok
Tags:
Comment:
Added some content for basic unit tests for ResourceLoader class.
Modified paths:
  • /trunk/phase3/maintenance/tests/phpunit/includes/ResourceLoaderTest.php (modified) (history)

Diff [purge]

Index: trunk/phase3/maintenance/tests/phpunit/includes/ResourceLoaderTest.php
@@ -2,15 +2,70 @@
33
44 class ResourceLoaderTest extends PHPUnit_Framework_TestCase {
55
 6+ protected static $resourceLoaderRegisterModulesHook;
 7+
 8+ /* Hook Methods */
 9+
 10+ /**
 11+ * ResourceLoaderRegisterModules hook
 12+ */
 13+ public static function resourceLoaderRegisterModules( &$resourceLoader ) {
 14+ self::$resourceLoaderRegisterModulesHook = true;
 15+ return true;
 16+ }
 17+
618 /* Provider Methods */
719
8 - public function provide() {
9 -
 20+ public function provideValidModules() {
 21+ return array(
 22+ array( 'TEST.validModule1', new ResourceLoaderTestModule() ),
 23+ );
1024 }
1125
1226 /* Test Methods */
 27+
 28+ /**
 29+ * Ensures that the ResourceLoaderRegisterModules hook is called when a new ResourceLoader object is constructed
 30+ * @covers ResourceLoader::__construct
 31+ */
 32+ public function testCreatingNewResourceLoaderCallsRegistrationHook() {
 33+ self::$resourceLoaderRegisterModulesHook = false;
 34+ $resourceLoader = new ResourceLoader();
 35+ $this->assertTrue( self::$resourceLoaderRegisterModulesHook );
 36+ return $resourceLoader;
 37+ }
1338
14 - public function test() {
15 -
 39+ /**
 40+ * @dataProvider provideValidModules
 41+ * @depends testCreatingNewResourceLoaderCallsRegistrationHook
 42+ * @covers ResourceLoader::register
 43+ * @covers ResourceLoader::getModule
 44+ */
 45+ public function testRegisteredValidModulesAreAccessible(
 46+ $name, ResourceLoaderModule $module, ResourceLoader $resourceLoader
 47+ ) {
 48+ $resourceLoader->register( $name, $module );
 49+ $this->assertEquals( $module, $resourceLoader->getModule( $name ) );
1650 }
 51+
 52+ /**
 53+ * Allthough ResourceLoader::register uses type hinting to prevent arbitrary information being passed through as a
 54+ * ResourceLoaderModule object, null can still get through.
 55+ *
 56+ * @depends testCreatingNewResourceLoaderCallsRegistrationHook
 57+ * @covers ResourceLoader::register
 58+ * @covers ResourceLoader::getModule
 59+ * @expectedException MWException
 60+ */
 61+ public function testRegisteringNullModuleThrowsAnException( ResourceLoader $resourceLoader ) {
 62+ $resourceLoader->register( 'TEST.nullModule', null );
 63+ }
1764 }
 65+
 66+/* Stubs */
 67+
 68+class ResourceLoaderTestModule extends ResourceLoaderModule { }
 69+
 70+/* Hooks */
 71+
 72+$wgHooks['ResourceLoaderRegisterModules'][] = 'ResourceLoaderTest::resourceLoaderRegisterModules';
\ No newline at end of file

Status & tagging log