Pass phpcs-strict on some test files (10/11)
[mediawiki.git] / tests / phpunit / includes / resourceloader / ResourceLoaderTest.php
blobd3736f50a92eadcae4ae5a78fb4e870f2f3fc515
1 <?php
3 class ResourceLoaderTest extends ResourceLoaderTestCase {
5 protected static $resourceLoaderRegisterModulesHook;
7 protected function setUp() {
8 parent::setUp();
10 // $wgResourceLoaderLESSFunctions, $wgResourceLoaderLESSImportPaths; $wgResourceLoaderLESSVars;
12 $this->setMwGlobals( array(
13 'wgResourceLoaderLESSFunctions' => array(
14 'test-sum' => function ( $frame, $less ) {
15 $sum = 0;
16 foreach ( $frame[2] as $arg ) {
17 $sum += (int)$arg[1];
19 return $sum;
22 'wgResourceLoaderLESSImportPaths' => array(
23 dirname( dirname( __DIR__ ) ) . '/data/less/common',
25 'wgResourceLoaderLESSVars' => array(
26 'foo' => '2px',
27 'Foo' => '#eeeeee',
28 'bar' => 5,
30 ) );
33 /* Hook Methods */
35 /**
36 * ResourceLoaderRegisterModules hook
38 public static function resourceLoaderRegisterModules( &$resourceLoader ) {
39 self::$resourceLoaderRegisterModulesHook = true;
41 return true;
44 /* Provider Methods */
45 public static function provideValidModules() {
46 return array(
47 array( 'TEST.validModule1', new ResourceLoaderTestModule() ),
51 /* Test Methods */
53 /**
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;
66 /**
67 * @dataProvider provideValidModules
68 * @depends testCreatingNewResourceLoaderCallsRegistrationHook
69 * @covers ResourceLoader::register
70 * @covers ResourceLoader::getModule
72 public function testRegisteredValidModulesAreAccessible(
73 $name, ResourceLoaderModule $module, ResourceLoader $resourceLoader
74 ) {
75 $resourceLoader->register( $name, $module );
76 $this->assertEquals( $module, $resourceLoader->getModule( $name ) );
79 /**
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' ),
88 ) );
89 $styles = $module->getStyles( $context );
90 $this->assertStringEqualsFile( $basePath . '/styles.css', $styles['all'] );
93 /**
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() {
110 return array(
111 array(
112 'Example from makePackedModulesString doc comment',
113 array( 'foo.bar', 'foo.baz', 'bar.baz', 'bar.quux' ),
114 'foo.bar,baz|bar.baz,quux',
116 array(
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',
121 array(
122 'Regression fixed in r88706 with dotless names',
123 array( 'foo', 'bar', 'baz' ),
124 'foo,bar,baz',
126 array(
127 'Prefixless modules after a prefixed module',
128 array( 'single.module', 'foobar', 'foobaz' ),
129 'single.module|foobar,foobaz',
135 /* Hooks */
136 global $wgHooks;
137 $wgHooks['ResourceLoaderRegisterModules'][] = 'ResourceLoaderTest::resourceLoaderRegisterModules';