MediaWiki  REL1_19
ResourceLoaderTest.php
Go to the documentation of this file.
00001 <?php
00002 
00003 class ResourceLoaderTest extends MediaWikiTestCase {
00004 
00005         protected static $resourceLoaderRegisterModulesHook;
00006 
00007         /* Hook Methods */
00008 
00012         public static function resourceLoaderRegisterModules( &$resourceLoader ) {
00013                 self::$resourceLoaderRegisterModulesHook = true;
00014                 return true;
00015         }
00016 
00017         /* Provider Methods */
00018         public function provideValidModules() {
00019                 return array(
00020                         array( 'TEST.validModule1', new ResourceLoaderTestModule() ),
00021                 );
00022         }
00023 
00024         /* Test Methods */
00025 
00030         public function testCreatingNewResourceLoaderCallsRegistrationHook() {
00031                 self::$resourceLoaderRegisterModulesHook = false;
00032                 $resourceLoader = new ResourceLoader();
00033                 $this->assertTrue( self::$resourceLoaderRegisterModulesHook );
00034                 return $resourceLoader;
00035         }
00036 
00043         public function testRegisteredValidModulesAreAccessible(
00044                 $name, ResourceLoaderModule $module, ResourceLoader $resourceLoader
00045         ) {
00046                 $resourceLoader->register( $name, $module );
00047                 $this->assertEquals( $module, $resourceLoader->getModule( $name ) );
00048         }
00049 
00053         public function testMakePackedModulesString( $desc, $modules, $packed ) {
00054                 $this->assertEquals( $packed, ResourceLoader::makePackedModulesString( $modules ), $desc );
00055         }
00056 
00060         public function testexpandModuleNames( $desc, $modules, $packed ) {
00061                 $this->assertEquals( $modules, ResourceLoaderContext::expandModuleNames( $packed ), $desc );
00062         }
00063 
00064         public function providePackedModules() {
00065                 return array(
00066                         array(
00067                                 'Example from makePackedModulesString doc comment',
00068                                 array( 'foo.bar', 'foo.baz', 'bar.baz', 'bar.quux' ),
00069                                 'foo.bar,baz|bar.baz,quux',
00070                         ),
00071                         array(
00072                                 'Example from expandModuleNames doc comment',
00073                                 array( 'jquery.foo', 'jquery.bar', 'jquery.ui.baz', 'jquery.ui.quux' ),
00074                                 'jquery.foo,bar|jquery.ui.baz,quux',
00075                         ),
00076                         array(
00077                                 'Regression fixed in r88706 with dotless names',
00078                                 array( 'foo', 'bar', 'baz' ),
00079                                 'foo,bar,baz',
00080                         )
00081                 );
00082         }
00083 }
00084 
00085 /* Stubs */
00086 
00087 class ResourceLoaderTestModule extends ResourceLoaderModule { }
00088 
00089 /* Hooks */
00090 global $wgHooks;
00091 $wgHooks['ResourceLoaderRegisterModules'][] = 'ResourceLoaderTest::resourceLoaderRegisterModules';