Merge "Revert "Follow-up ee320648fd1: output mw-content-{ltr,rtl} unconditionally""
[lhc/web/wiklou.git] / tests / phpunit / includes / registration / ExtensionProcessorTest.php
index 96df354..d47ffa9 100644 (file)
@@ -36,6 +36,10 @@ class ExtensionProcessorTest extends MediaWikiTestCase {
        }
 
        public static function provideRegisterHooks() {
+               // Format:
+               // Current $wgHooks
+               // Content in extension.json
+               // Expected value of $wgHooks
                return array(
                        // No hooks
                        array(
@@ -64,6 +68,22 @@ class ExtensionProcessorTest extends MediaWikiTestCase {
                                        'FooBaz' => array( 'FooBazCallback' ),
                                ),
                        ),
+                       // Callbacks for FooBaz wrapped in an array
+                       array(
+                               array(),
+                               array( 'Hooks' => array( 'FooBaz' => array( 'Callback1' ) ) ) + self::$default,
+                               array(
+                                       'FooBaz' => array( 'Callback1' ),
+                               ),
+                       ),
+                       // Multiple callbacks for FooBaz hook
+                       array(
+                               array(),
+                               array( 'Hooks' => array( 'FooBaz' => array( 'Callback1', 'Callback2' ) ) ) + self::$default,
+                               array(
+                                       'FooBaz' => array( 'Callback1', 'Callback2' ),
+                               ),
+                       ),
                );
        }
 
@@ -97,6 +117,224 @@ class ExtensionProcessorTest extends MediaWikiTestCase {
                $this->assertArrayNotHasKey( 'wg@IGNORED', $extracted['globals'] );
        }
 
+       public static function provideExtracttExtensionMessagesFiles() {
+               $dir = __DIR__ . '/FooBar/';
+               return array(
+                       array(
+                               array( 'ExtensionMessagesFiles' => array( 'FooBarAlias' => 'FooBar.alias.php' ) ),
+                               array( 'wgExtensionMessagesFiles' => array( 'FooBarAlias' => $dir . 'FooBar.alias.php' ) )
+                       ),
+                       array(
+                               array(
+                                       'ExtensionMessagesFiles' => array(
+                                               'FooBarAlias' => 'FooBar.alias.php',
+                                               'FooBarMagic' => 'FooBar.magic.i18n.php',
+                                       ),
+                               ),
+                               array(
+                                       'wgExtensionMessagesFiles' => array(
+                                               'FooBarAlias' => $dir . 'FooBar.alias.php',
+                                               'FooBarMagic' => $dir . 'FooBar.magic.i18n.php',
+                                       ),
+                               ),
+                       ),
+               );
+       }
+
+       /**
+        * @covers ExtensionProcessor::extracttExtensionMessagesFiles
+        * @dataProvider provideExtracttExtensionMessagesFiles
+        */
+       public function testExtracttExtensionMessagesFiles( $input, $expected ) {
+               $processor = new ExtensionProcessor();
+               $processor->extractInfo( $this->dir, $input + self::$default );
+               $out = $processor->getExtractedInfo();
+               foreach ( $expected as $key => $value ) {
+                       $this->assertEquals( $value, $out['globals'][$key] );
+               }
+       }
+
+
+       public static function provideExtractMessagesDirs() {
+               $dir = __DIR__ . '/FooBar/';
+               return array(
+                       array(
+                               array( 'MessagesDirs' => array( 'VisualEditor' => 'i18n' ) ),
+                               array( 'wgMessagesDirs' => array( 'VisualEditor' => array( $dir . 'i18n' ) ) )
+                       ),
+                       array(
+                               array( 'MessagesDirs' => array( 'VisualEditor' => array( 'i18n', 'foobar' ) ) ),
+                               array( 'wgMessagesDirs' => array( 'VisualEditor' => array( $dir . 'i18n', $dir . 'foobar' ) ) )
+                       ),
+               );
+       }
+
+       /**
+        * @covers ExtensionProcessor::extractMessagesDirs
+        * @dataProvider provideExtractMessagesDirs
+        */
+       public function testExtractMessagesDirs( $input, $expected ) {
+               $processor = new ExtensionProcessor();
+               $processor->extractInfo( $this->dir, $input + self::$default );
+               $out = $processor->getExtractedInfo();
+               foreach ( $expected as $key => $value ) {
+                       $this->assertEquals( $value, $out['globals'][$key] );
+               }
+       }
+
+       /**
+        * @covers ExtensionProcessor::extractResourceLoaderModules
+        * @dataProvider provideExtractResourceLoaderModules
+        */
+       public function testExtractResourceLoaderModules( $input, $expected ) {
+               $processor = new ExtensionProcessor();
+               $processor->extractInfo( $this->dir, $input + self::$default );
+               $out = $processor->getExtractedInfo();
+               foreach ( $expected as $key => $value ) {
+                       $this->assertEquals( $value, $out['globals'][$key] );
+               }
+       }
+
+       public static function provideExtractResourceLoaderModules() {
+               $dir = __DIR__ . '/FooBar/';
+               return array(
+                       // Generic module with localBasePath/remoteExtPath specified
+                       array(
+                               // Input
+                               array(
+                                       'ResourceModules' => array(
+                                               'test.foo' => array(
+                                                       'styles' => 'foobar.js',
+                                                       'localBasePath' => '',
+                                                       'remoteExtPath' => 'FooBar',
+                                               ),
+                                       ),
+                               ),
+                               // Expected
+                               array(
+                                       'wgResourceModules' => array(
+                                               'test.foo' => array(
+                                                       'styles' => 'foobar.js',
+                                                       'localBasePath' => $dir,
+                                                       'remoteExtPath' => 'FooBar',
+                                               ),
+                                       ),
+                               ),
+                       ),
+                       // ResourceFileModulePaths specified:
+                       array(
+                               // Input
+                               array(
+                                       'ResourceFileModulePaths' => array(
+                                               'localBasePath' => '',
+                                               'remoteExtPath' => 'FooBar',
+                                       ),
+                                       'ResourceModules' => array(
+                                               // No paths
+                                               'test.foo' => array(
+                                                       'styles' => 'foo.js',
+                                               ),
+                                               // Different paths set
+                                               'test.bar' => array(
+                                                       'styles' => 'bar.js',
+                                                       'localBasePath' => 'subdir',
+                                                       'remoteExtPath' => 'FooBar/subdir',
+                                               ),
+                                               // Custom class with no paths set
+                                               'test.class' => array(
+                                                       'class' => 'FooBarModule',
+                                                       'extra' => 'argument',
+                                               ),
+                                               // Custom class with a localBasePath
+                                               'test.class.with.path' => array(
+                                                       'class' => 'FooBarPathModule',
+                                                       'extra' => 'argument',
+                                                       'localBasePath' => '',
+                                               )
+                                       ),
+                               ),
+                               // Expected
+                               array(
+                                       'wgResourceModules' => array(
+                                               'test.foo' => array(
+                                                       'styles' => 'foo.js',
+                                                       'localBasePath' => $dir,
+                                                       'remoteExtPath' => 'FooBar',
+                                               ),
+                                               'test.bar' => array(
+                                                       'styles' => 'bar.js',
+                                                       'localBasePath' => $dir . 'subdir',
+                                                       'remoteExtPath' => 'FooBar/subdir',
+                                               ),
+                                               'test.class' => array(
+                                                       'class' => 'FooBarModule',
+                                                       'extra' => 'argument',
+                                                       'localBasePath' => $dir,
+                                                       'remoteExtPath' => 'FooBar',
+                                               ),
+                                               'test.class.with.path' => array(
+                                                       'class' => 'FooBarPathModule',
+                                                       'extra' => 'argument',
+                                                       'localBasePath' => $dir,
+                                                       'remoteExtPath' => 'FooBar',
+                                               )
+                                       ),
+                               ),
+                       ),
+                       // ResourceModuleSkinStyles with file module paths
+                       array(
+                               // Input
+                               array(
+                                       'ResourceFileModulePaths' => array(
+                                               'localBasePath' => '',
+                                               'remoteSkinPath' => 'FooBar',
+                                       ),
+                                       'ResourceModuleSkinStyles' => array(
+                                               'foobar' => array(
+                                                       'test.foo' => 'foo.css',
+                                               )
+                                       ),
+                               ),
+                               // Expected
+                               array(
+                                       'wgResourceModuleSkinStyles' => array(
+                                               'foobar' => array(
+                                                       'test.foo' => 'foo.css',
+                                                       'localBasePath' => $dir,
+                                                       'remoteSkinPath' => 'FooBar',
+                                               ),
+                                       ),
+                               ),
+                       ),
+                       // ResourceModuleSkinStyles with file module paths and an override
+                       array(
+                               // Input
+                               array(
+                                       'ResourceFileModulePaths' => array(
+                                               'localBasePath' => '',
+                                               'remoteSkinPath' => 'FooBar',
+                                       ),
+                                       'ResourceModuleSkinStyles' => array(
+                                               'foobar' => array(
+                                                       'test.foo' => 'foo.css',
+                                                       'remoteSkinPath' => 'BarFoo'
+                                               ),
+                                       ),
+                               ),
+                               // Expected
+                               array(
+                                       'wgResourceModuleSkinStyles' => array(
+                                               'foobar' => array(
+                                                       'test.foo' => 'foo.css',
+                                                       'localBasePath' => $dir,
+                                                       'remoteSkinPath' => 'BarFoo',
+                                               ),
+                                       ),
+                               ),
+                       ),
+               );
+       }
+
        public static function provideSetToGlobal() {
                return array(
                        array(