3 class ResourceLoaderTest
extends ResourceLoaderTestCase
{
5 protected static $resourceLoaderRegisterModulesHook;
7 protected function setUp() {
10 // $wgResourceLoaderLESSFunctions, $wgResourceLoaderLESSImportPaths; $wgResourceLoaderLESSVars;
12 $this->setMwGlobals( array(
13 'wgResourceLoaderLESSFunctions' => array(
14 'test-sum' => function ( $frame, $less ) {
16 foreach ( $frame[2] as $arg ) {
22 'wgResourceLoaderLESSImportPaths' => array(
23 dirname( dirname( __DIR__
) ) . '/data/less/common',
25 'wgResourceLoaderLESSVars' => array(
36 * ResourceLoaderRegisterModules hook
38 public static function resourceLoaderRegisterModules( &$resourceLoader ) {
39 self
::$resourceLoaderRegisterModulesHook = true;
44 /* Provider Methods */
45 public static function provideValidModules() {
47 array( 'TEST.validModule1', new ResourceLoaderTestModule() ),
54 * Ensures that the ResourceLoaderRegisterModules hook is called when a new
55 * ResourceLoader object is constructed.
56 * @covers ResourceLoader::__construct
58 public function testCreatingNewResourceLoaderCallsRegistrationHook() {
59 self
::$resourceLoaderRegisterModulesHook = false;
60 $resourceLoader = new ResourceLoader();
61 $this->assertTrue( self
::$resourceLoaderRegisterModulesHook );
63 return $resourceLoader;
67 * @dataProvider provideValidModules
68 * @depends testCreatingNewResourceLoaderCallsRegistrationHook
69 * @covers ResourceLoader::register
70 * @covers ResourceLoader::getModule
72 public function testRegisteredValidModulesAreAccessible(
73 $name, ResourceLoaderModule
$module, ResourceLoader
$resourceLoader
75 $resourceLoader->register( $name, $module );
76 $this->assertEquals( $module, $resourceLoader->getModule( $name ) );
80 * @covers ResourceLoaderFileModule::compileLessFile
82 public function testLessFileCompilation() {
83 $context = self
::getResourceLoaderContext();
84 $basePath = __DIR__
. '/../../data/less/module';
85 $module = new ResourceLoaderFileModule( array(
86 'localBasePath' => $basePath,
87 'styles' => array( 'styles.less' ),
89 $styles = $module->getStyles( $context );
90 $this->assertStringEqualsFile( $basePath . '/styles.css', $styles['all'] );
94 * @dataProvider providePackedModules
95 * @covers ResourceLoader::makePackedModulesString
97 public function testMakePackedModulesString( $desc, $modules, $packed ) {
98 $this->assertEquals( $packed, ResourceLoader
::makePackedModulesString( $modules ), $desc );
102 * @dataProvider providePackedModules
103 * @covers ResourceLoaderContext::expandModuleNames
105 public function testexpandModuleNames( $desc, $modules, $packed ) {
106 $this->assertEquals( $modules, ResourceLoaderContext
::expandModuleNames( $packed ), $desc );
109 public static function providePackedModules() {
112 'Example from makePackedModulesString doc comment',
113 array( 'foo.bar', 'foo.baz', 'bar.baz', 'bar.quux' ),
114 'foo.bar,baz|bar.baz,quux',
117 'Example from expandModuleNames doc comment',
118 array( 'jquery.foo', 'jquery.bar', 'jquery.ui.baz', 'jquery.ui.quux' ),
119 'jquery.foo,bar|jquery.ui.baz,quux',
122 'Regression fixed in r88706 with dotless names',
123 array( 'foo', 'bar', 'baz' ),
127 'Prefixless modules after a prefixed module',
128 array( 'single.module', 'foobar', 'foobaz' ),
129 'single.module|foobar,foobaz',
137 $wgHooks['ResourceLoaderRegisterModules'][] = 'ResourceLoaderTest::resourceLoaderRegisterModules';