3 class ResourceLoaderTest
extends MediaWikiTestCase
{
5 protected static $resourceLoaderRegisterModulesHook;
10 * ResourceLoaderRegisterModules hook
12 public static function resourceLoaderRegisterModules( &$resourceLoader ) {
13 self
::$resourceLoaderRegisterModulesHook = true;
17 /* Provider Methods */
18 public static function provideValidModules() {
20 array( 'TEST.validModule1', new ResourceLoaderTestModule() ),
27 * Ensures that the ResourceLoaderRegisterModules hook is called when a new ResourceLoader object is constructed
28 * @covers ResourceLoader::__construct
30 public function testCreatingNewResourceLoaderCallsRegistrationHook() {
31 self
::$resourceLoaderRegisterModulesHook = false;
32 $resourceLoader = new ResourceLoader();
33 $this->assertTrue( self
::$resourceLoaderRegisterModulesHook );
34 return $resourceLoader;
38 * @dataProvider provideValidModules
39 * @depends testCreatingNewResourceLoaderCallsRegistrationHook
40 * @covers ResourceLoader::register
41 * @covers ResourceLoader::getModule
43 public function testRegisteredValidModulesAreAccessible(
44 $name, ResourceLoaderModule
$module, ResourceLoader
$resourceLoader
46 $resourceLoader->register( $name, $module );
47 $this->assertEquals( $module, $resourceLoader->getModule( $name ) );
51 * @dataProvider providePackedModules
53 public function testMakePackedModulesString( $desc, $modules, $packed ) {
54 $this->assertEquals( $packed, ResourceLoader
::makePackedModulesString( $modules ), $desc );
58 * @dataProvider providePackedModules
60 public function testexpandModuleNames( $desc, $modules, $packed ) {
61 $this->assertEquals( $modules, ResourceLoaderContext
::expandModuleNames( $packed ), $desc );
64 public static function providePackedModules() {
67 'Example from makePackedModulesString doc comment',
68 array( 'foo.bar', 'foo.baz', 'bar.baz', 'bar.quux' ),
69 'foo.bar,baz|bar.baz,quux',
72 'Example from expandModuleNames doc comment',
73 array( 'jquery.foo', 'jquery.bar', 'jquery.ui.baz', 'jquery.ui.quux' ),
74 'jquery.foo,bar|jquery.ui.baz,quux',
77 'Regression fixed in r88706 with dotless names',
78 array( 'foo', 'bar', 'baz' ),
87 class ResourceLoaderTestModule
extends ResourceLoaderModule
{}
91 $wgHooks['ResourceLoaderRegisterModules'][] = 'ResourceLoaderTest::resourceLoaderRegisterModules';