Index: trunk/phase3/maintenance/tests/phpunit/includes/ResourceLoaderTest.php |
— | — | @@ -2,15 +2,70 @@ |
3 | 3 | |
4 | 4 | class ResourceLoaderTest extends PHPUnit_Framework_TestCase { |
5 | 5 | |
| 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 | + |
6 | 18 | /* Provider Methods */ |
7 | 19 | |
8 | | - public function provide() { |
9 | | - |
| 20 | + public function provideValidModules() { |
| 21 | + return array( |
| 22 | + array( 'TEST.validModule1', new ResourceLoaderTestModule() ), |
| 23 | + ); |
10 | 24 | } |
11 | 25 | |
12 | 26 | /* 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 | + } |
13 | 38 | |
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 ) ); |
16 | 50 | } |
| 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 | + } |
17 | 64 | } |
| 65 | + |
| 66 | +/* Stubs */ |
| 67 | + |
| 68 | +class ResourceLoaderTestModule extends ResourceLoaderModule { } |
| 69 | + |
| 70 | +/* Hooks */ |
| 71 | + |
| 72 | +$wgHooks['ResourceLoaderRegisterModules'][] = 'ResourceLoaderTest::resourceLoaderRegisterModules'; |
\ No newline at end of file |