test: coverage recording now needs to be explicit
[mediawiki.git] / tests / phpunit / includes / ResourceLoaderTest.php
blobfa228a68368facbb023b6dbe03443d0ef3c39914
1 <?php
3 class ResourceLoaderTest extends MediaWikiTestCase {
5 protected static $resourceLoaderRegisterModulesHook;
7 /* Hook Methods */
9 /**
10 * ResourceLoaderRegisterModules hook
12 public static function resourceLoaderRegisterModules( &$resourceLoader ) {
13 self::$resourceLoaderRegisterModulesHook = true;
15 return true;
18 /* Provider Methods */
19 public static function provideValidModules() {
20 return array(
21 array( 'TEST.validModule1', new ResourceLoaderTestModule() ),
25 /* Test Methods */
27 /**
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;
39 /**
40 * @dataProvider provideValidModules
41 * @depends testCreatingNewResourceLoaderCallsRegistrationHook
42 * @covers ResourceLoader::register
43 * @covers ResourceLoader::getModule
45 public function testRegisteredValidModulesAreAccessible(
46 $name, ResourceLoaderModule $module, ResourceLoader $resourceLoader
47 ) {
48 $resourceLoader->register( $name, $module );
49 $this->assertEquals( $module, $resourceLoader->getModule( $name ) );
52 /**
53 * @dataProvider providePackedModules
55 public function testMakePackedModulesString( $desc, $modules, $packed ) {
56 $this->assertEquals( $packed, ResourceLoader::makePackedModulesString( $modules ), $desc );
59 /**
60 * @dataProvider providePackedModules
62 public function testexpandModuleNames( $desc, $modules, $packed ) {
63 $this->assertEquals( $modules, ResourceLoaderContext::expandModuleNames( $packed ), $desc );
66 public static function providePackedModules() {
67 return array(
68 array(
69 'Example from makePackedModulesString doc comment',
70 array( 'foo.bar', 'foo.baz', 'bar.baz', 'bar.quux' ),
71 'foo.bar,baz|bar.baz,quux',
73 array(
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',
78 array(
79 'Regression fixed in r88706 with dotless names',
80 array( 'foo', 'bar', 'baz' ),
81 'foo,bar,baz',
83 array(
84 'Prefixless modules after a prefixed module',
85 array( 'single.module', 'foobar', 'foobaz' ),
86 'single.module|foobar,foobaz',
92 /* Stubs */
94 class ResourceLoaderTestModule extends ResourceLoaderModule {
97 /* Hooks */
98 global $wgHooks;
99 $wgHooks['ResourceLoaderRegisterModules'][] = 'ResourceLoaderTest::resourceLoaderRegisterModules';