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

Change subject: (bug 42612) Have PythonSingleFFS observe codeMap
......................................................................


(bug 42612) Have PythonSingleFFS observe codeMap

Bug: 42612
Change-Id: I28d7dcababef93be53b510a66ebc4f8f41ea8c03
---
M ffs/PythonSingleFFS.php
A tests/data/pythontest.py
A tests/ffs/PythonSingleFFSTest.php
3 files changed, 78 insertions(+), 1 deletion(-)

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



diff --git a/ffs/PythonSingleFFS.php b/ffs/PythonSingleFFS.php
index 5b9025e..91680a4 100644
--- a/ffs/PythonSingleFFS.php
+++ b/ffs/PythonSingleFFS.php
@@ -57,6 +57,7 @@
        }
 
        public function read( $code ) {
+               $code = $this->group->mapCode( $code );
                $filename = $this->group->getSourceFilePath( $code );
                if ( !file_exists( $filename ) ) {
                        return false;
@@ -119,6 +120,7 @@
        protected function writeReal( MessageCollection $collection ) {
                $mangler = $this->group->getMangler();
                $code = $collection->getLanguage();
+               $code = $this->group->mapCode( $code );
 
                $block = $this->generateMessageBlock( $collection, $mangler );
                if ( $block === '' ) {
@@ -128,7 +130,7 @@
                // Ugly code, relies on side effects
                $this->read( 'mul' );
                $filename = $this->group->getSourceFilePath( $code );
-               $cache = & self::$cache[$filename];
+               $cache = &self::$cache[$filename];
 
                // Generating authors
                if ( isset( $cache['sections'][$code] ) ) {
diff --git a/tests/data/pythontest.py b/tests/data/pythontest.py
new file mode 100644
index 0000000..921383d
--- /dev/null
+++ b/tests/data/pythontest.py
@@ -0,0 +1,13 @@
+# -*- coding: utf-8 -*-
+msg = {
+       'en': {
+               'user': u'Users',
+       },
+       'qqq': {
+               'user': u'The people who report bugs and request features.',
+       },
+       # Author: Nike
+       'encrypted': {
+               'user': u'Käyttäjät',
+       }
+}
diff --git a/tests/ffs/PythonSingleFFSTest.php 
b/tests/ffs/PythonSingleFFSTest.php
new file mode 100644
index 0000000..ebcd7e9
--- /dev/null
+++ b/tests/ffs/PythonSingleFFSTest.php
@@ -0,0 +1,62 @@
+<?php
+/**
+ * Tests for PythonSingle message file format.
+ *
+ * @file
+ * @author Niklas Laxström
+ * @copyright Copyright © 2013, Niklas Laxström
+ * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 
2.0 or later
+ */
+
+/**
+ * @see PythonSingleFFS
+ */
+class PythonSingleFFSTest extends MediaWikiTestCase {
+       protected $groupConfiguration;
+
+       public function setUp() {
+               parent::setUp();
+               $this->groupConfiguration = array(
+                       'BASIC' => array(
+                               'class' => 'FileBasedMessageGroup',
+                               'id' => 'test-id',
+                               'label' => 'Test Label',
+                               'namespace' => 'NS_MEDIAWIKI',
+                               'description' => 'Test description',
+                       ),
+                       'FILES' => array(
+                               'class' => 'PythonSingleFFS',
+                               'sourcePattern' => __DIR__ . 
'/../data/pythontest.py',
+                               'targetPattern' => __DIR__ . 
'/../data/pythontest.py',
+                               'codeMap' => array(
+                                       'fi' => 'encrypted',
+                               )
+                       ),
+               );
+       }
+
+       public function testParsing() {
+               /** @var FileBasedMessageGroup $group */
+               $group = MessageGroupBase::factory( $this->groupConfiguration );
+               $ffs = new PythonSingleFFS( $group );
+
+               $command = wfEscapeShellArg( "import simplejson as json; print 
'mui'" );
+               $ret = wfShellExec( "python -c $command" );
+               if ( trim( $ret ) !== 'mui' ) {
+                       $this->markTestSkipped( 'Dependency python simplejson 
not installed' );
+                       return;
+               }
+
+               $parsed = $ffs->read( 'en' );
+               $expected = array(
+                       'MESSAGES' => array( 'user' => 'Users' )
+               );
+               $this->assertEquals( $expected, $parsed );
+
+               $parsed = $ffs->read( 'fi' );
+               $expected = array(
+                       'MESSAGES' => array( 'user' => 'Käyttäjät' )
+               );
+               $this->assertEquals( $expected, $parsed );
+       }
+}

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I28d7dcababef93be53b510a66ebc4f8f41ea8c03
Gerrit-PatchSet: 4
Gerrit-Project: mediawiki/extensions/Translate
Gerrit-Branch: master
Gerrit-Owner: Siebrand <[email protected]>
Gerrit-Reviewer: Amire80 <[email protected]>
Gerrit-Reviewer: Nikerabbit <[email protected]>
Gerrit-Reviewer: Siebrand <[email protected]>
Gerrit-Reviewer: jenkins-bot

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

Reply via email to