jenkins-bot has submitted this change and it was merged.

Change subject: registration: Fix handling of MessagesDirs array and add tests
......................................................................


registration: Fix handling of MessagesDirs array and add tests

Previously the code was designed to handle:
  "MessagesDirs": {
    "FooBar": "i18n"
  }

However, it can also be an array, and some extensions (VisualEditor)
use it like:

  "MessagesDirs": {
    "FooBar": [
      "i18n",
      "also-i18n"
    ]
  }

This properly handles both strings and arrays and adds tests to verify
the behavior.

Change-Id: Iff1523b86f754cac1f5b8d822d4324c5fbfc1a50
---
M includes/registration/ExtensionProcessor.php
M tests/phpunit/includes/registration/ExtensionProcessorTest.php
2 files changed, 32 insertions(+), 3 deletions(-)

Approvals:
  Catrope: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/includes/registration/ExtensionProcessor.php 
b/includes/registration/ExtensionProcessor.php
index 25222f6..8a6530b 100644
--- a/includes/registration/ExtensionProcessor.php
+++ b/includes/registration/ExtensionProcessor.php
@@ -204,9 +204,11 @@
        protected function extractMessageSettings( $dir, array $info ) {
                foreach ( array( 'ExtensionMessagesFiles', 'MessagesDirs' ) as 
$key ) {
                        if ( isset( $info[$key] ) ) {
-                               $this->globals["wg$key"] += array_map( 
function( $file ) use ( $dir ) {
-                                       return "$dir/$file";
-                               }, $info[$key] );
+                               foreach ( $info[$key] as $name => $files ) {
+                                       foreach ( (array)$files as $file ) {
+                                               
$this->globals["wg$key"][$name][] = "$dir/$file";
+                                       }
+                               }
                                $this->processed[] = $key;
                        }
                }
diff --git a/tests/phpunit/includes/registration/ExtensionProcessorTest.php 
b/tests/phpunit/includes/registration/ExtensionProcessorTest.php
index 96df354..0d31878 100644
--- a/tests/phpunit/includes/registration/ExtensionProcessorTest.php
+++ b/tests/phpunit/includes/registration/ExtensionProcessorTest.php
@@ -97,6 +97,33 @@
                $this->assertArrayNotHasKey( 'wg@IGNORED', 
$extracted['globals'] );
        }
 
+       public static function provideExtractMessageSettings() {
+               $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::extractMessageSettings
+        * @dataProvider provideExtractMessageSettings
+        */
+       public function testExtractMessageSettings( $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 provideSetToGlobal() {
                return array(
                        array(

-- 
To view, visit https://gerrit.wikimedia.org/r/187801
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: Iff1523b86f754cac1f5b8d822d4324c5fbfc1a50
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Legoktm <[email protected]>
Gerrit-Reviewer: Catrope <[email protected]>
Gerrit-Reviewer: Chad <[email protected]>
Gerrit-Reviewer: Gilles <[email protected]>
Gerrit-Reviewer: Jforrester <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to