Merge "RCFilters: Style the Saved Links placeholder and add a title"
[lhc/web/wiklou.git] / tests / phpunit / includes / resourceloader / ResourceLoaderTest.php
index e0a82d0..0833047 100644 (file)
@@ -1,5 +1,7 @@
 <?php
 
+use Wikimedia\TestingAccessWrapper;
+
 class ResourceLoaderTest extends ResourceLoaderTestCase {
 
        protected function setUp() {
@@ -49,13 +51,26 @@ class ResourceLoaderTest extends ResourceLoaderTestCase {
         * @covers ResourceLoader::register
         * @covers ResourceLoader::getModule
         */
-       public function testRegisterValid() {
+       public function testRegisterValidObject() {
                $module = new ResourceLoaderTestModule();
                $resourceLoader = new EmptyResourceLoader();
                $resourceLoader->register( 'test', $module );
                $this->assertEquals( $module, $resourceLoader->getModule( 'test' ) );
        }
 
+       /**
+        * @covers ResourceLoader::register
+        * @covers ResourceLoader::getModule
+        */
+       public function testRegisterValidArray() {
+               $module = new ResourceLoaderTestModule();
+               $resourceLoader = new EmptyResourceLoader();
+               // Covers case of register() setting $rl->moduleInfos,
+               // but $rl->modules lazy-populated by getModule()
+               $resourceLoader->register( 'test', [ 'object' => $module ] );
+               $this->assertEquals( $module, $resourceLoader->getModule( 'test' ) );
+       }
+
        /**
         * @covers ResourceLoader::register
         */
@@ -128,6 +143,23 @@ class ResourceLoaderTest extends ResourceLoaderTestCase {
                );
        }
 
+       /**
+        * @covers ResourceLoader::getModule
+        */
+       public function testGetModuleFactory() {
+               $factory = function( array $info ) {
+                       $this->assertArrayHasKey( 'kitten', $info );
+                       return new ResourceLoaderTestModule( $info );
+               };
+
+               $rl = new EmptyResourceLoader();
+               $rl->register( 'test', [ 'factory' => $factory, 'kitten' => 'little ball of fur' ] );
+               $this->assertInstanceOf(
+                       ResourceLoaderTestModule::class,
+                       $rl->getModule( 'test' )
+               );
+       }
+
        /**
         * @covers ResourceLoader::getModule
         */
@@ -384,6 +416,33 @@ mw.example();
                );
        }
 
+       /**
+        * @covers ResourceLoader::makeLoaderRegisterScript
+        */
+       public function testMakeLoaderRegisterScript() {
+               $this->assertEquals(
+                       'mw.loader.register( [
+    [
+        "test.name",
+        "1234567"
+    ]
+] );',
+                       ResourceLoader::makeLoaderRegisterScript( [
+                               [ 'test.name', '1234567' ],
+                       ] ),
+                       'Nested array parameter'
+               );
+
+               $this->assertEquals(
+                       'mw.loader.register( "test.name", "1234567" );',
+                       ResourceLoader::makeLoaderRegisterScript(
+                               'test.name',
+                               '1234567'
+                       ),
+                       'Variadic parameters'
+               );
+       }
+
        /**
         * @covers ResourceLoader::makeLoaderSourcesScript
         */