3 class ResourceLoaderTest
extends MediaWikiTestCase
{
5 protected static $resourceLoaderRegisterModulesHook;
10 * ResourceLoaderRegisterModules hook
12 public static function resourceLoaderRegisterModules( &$resourceLoader ) {
13 self
::$resourceLoaderRegisterModulesHook = true;
18 /* Provider Methods */
19 public static function provideValidModules() {
21 array( 'TEST.validModule1', new ResourceLoaderTestModule() ),
28 * Ensures that the ResourceLoaderRegisterModules hook is called when a new ResourceLoader object is constructed
29 * @covers ResourceLoader::__construct
31 public function testCreatingNewResourceLoaderCallsRegistrationHook() {
32 self
::$resourceLoaderRegisterModulesHook = false;
33 $resourceLoader = new ResourceLoader();
34 $this->assertTrue( self
::$resourceLoaderRegisterModulesHook );
36 return $resourceLoader;
40 * @dataProvider provideValidModules
41 * @depends testCreatingNewResourceLoaderCallsRegistrationHook
42 * @covers ResourceLoader::register
43 * @covers ResourceLoader::getModule
45 public function testRegisteredValidModulesAreAccessible(
46 $name, ResourceLoaderModule
$module, ResourceLoader
$resourceLoader
48 $resourceLoader->register( $name, $module );
49 $this->assertEquals( $module, $resourceLoader->getModule( $name ) );
53 * @dataProvider providePackedModules
55 public function testMakePackedModulesString( $desc, $modules, $packed ) {
56 $this->assertEquals( $packed, ResourceLoader
::makePackedModulesString( $modules ), $desc );
60 * @dataProvider providePackedModules
62 public function testexpandModuleNames( $desc, $modules, $packed ) {
63 $this->assertEquals( $modules, ResourceLoaderContext
::expandModuleNames( $packed ), $desc );
66 public static function providePackedModules() {
69 'Example from makePackedModulesString doc comment',
70 array( 'foo.bar', 'foo.baz', 'bar.baz', 'bar.quux' ),
71 'foo.bar,baz|bar.baz,quux',
74 'Example from expandModuleNames doc comment',
75 array( 'jquery.foo', 'jquery.bar', 'jquery.ui.baz', 'jquery.ui.quux' ),
76 'jquery.foo,bar|jquery.ui.baz,quux',
79 'Regression fixed in r88706 with dotless names',
80 array( 'foo', 'bar', 'baz' ),
84 'Prefixless modules after a prefixed module',
85 array( 'single.module', 'foobar', 'foobaz' ),
86 'single.module|foobar,foobaz',
94 class ResourceLoaderTestModule
extends ResourceLoaderModule
{
99 $wgHooks['ResourceLoaderRegisterModules'][] = 'ResourceLoaderTest::resourceLoaderRegisterModules';