Jarry1250 has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/213800

Change subject: Further tests for switchTranslationSet()
......................................................................

Further tests for switchTranslationSet()

Seems to have good coverage now, yay!

Change-Id: Ic0e5df88a50aad18bd4cfeb09510da192b90c924
---
M TranslateSvgUtils.php
M tests/phpunit/SVGFileTest.php
2 files changed, 39 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/TranslateSvg 
refs/changes/00/213800/1

diff --git a/TranslateSvgUtils.php b/TranslateSvgUtils.php
index 9a48648..8ec9e05 100644
--- a/TranslateSvgUtils.php
+++ b/TranslateSvgUtils.php
@@ -283,6 +283,7 @@
         * @param string $langCode Language code (e.g. en-gb, fr)
         * @param string $fallbackLanguage Code of the language for which the 
"fallback" magic word is equivalent
         * @return string The autonym of the language with that code (English, 
français, Nederlands)
+        * @todo: Should probably distinguish between locales
         */
        public static function fetchLanguageName( $langCode, $fallbackLanguage 
) {
                $langCode = ( $langCode === 'fallback' ) ? $fallbackLanguage : 
$langCode;
diff --git a/tests/phpunit/SVGFileTest.php b/tests/phpunit/SVGFileTest.php
index 92ddef5..7cab3b6 100644
--- a/tests/phpunit/SVGFileTest.php
+++ b/tests/phpunit/SVGFileTest.php
@@ -493,6 +493,44 @@
                $this->assertArrayEquals( array( 'started' => array(), 
'expanded' => array() ), $ret );
        }
 
+       public function testSwitchTranslationSet() {
+               $tempPath = tempnam( wfTempDir(), 'test' );
+
+               // Simple addition of a French translation and change in 
fallback
+               file_put_contents( $tempPath, '<svg><text 
id="text1">Hello</text></svg>' );
+               $svg = new SVGFile( $tempPath, 'en' );
+               $translations = $svg->getInFileTranslations();
+               $translations['text1']['fallback']['text'] .= '!';
+               $translations['text1']['fr'] = 
$translations['text1']['fallback'];
+               $translations['text1']['fr']['text'] = 'Bonjour!';
+               $ret = $svg->switchToTranslationSet( $translations );
+               $this->assertArrayEquals( array( 'started' => array( 'français' 
), 'expanded' => array( 'English') ), $ret );
+               $this->assertContains( '<switch><text id="text1" 
systemLanguage="fr">Bonjour!</text><text id="text1">Hello!</text></switch>', 
$svg->saveToString() );
+
+               // More complex: contains a child tspan
+               file_put_contents( $tempPath, '<svg><text id="text1">Hello 
<tspan id="tspan1">my friend</tspan></text></svg>' );
+               $svg = new SVGFile( $tempPath, 'en' );
+               $translations = $svg->getInFileTranslations();
+               $translations['text1']['fallback']['text'] .= '!';
+               $translations['text1']['fr'] = 
$translations['text1']['fallback'];
+               $translations['text1']['fr']['text'] = 'Bonjour $1!';
+               $translations['tspan1']['fr'] = 
$translations['tspan1']['fallback'];
+               $translations['tspan1']['fr']['text'] = 'mon ami';
+               $ret = $svg->switchToTranslationSet( $translations );
+               $this->assertArrayEquals( array( 'started' => array( 'français' 
), 'expanded' => array( 'English' ) ), $ret );
+               $this->assertContains( '<text id="text1" 
systemLanguage="fr">Bonjour <tspan id="tspan1">mon ami</tspan>!</text>', 
$svg->saveToString() );
+
+               // Also more complex: correct order should be 
sublocale-language-fallback
+               file_put_contents( $tempPath, '<svg><text 
id="text1">Hello</text></svg>' );
+               $svg = new SVGFile( $tempPath, 'en' );
+               $translations = $svg->getInFileTranslations();
+               $translations['text1']['fr'] = 
$translations['text1']['fallback'];
+               $translations['text1']['fr-fr'] = 
$translations['text1']['fallback'];
+               $ret = $svg->switchToTranslationSet( $translations );
+               $this->assertArrayEquals( array( 'started' => array( 'français' 
), 'expanded' => array() ), $ret );
+               $this->assertEquals( 1, preg_match( 
'/"fr_FR".*"fr".*"text1">/', $svg->saveToString() ) );
+       }
+
        public function testSaveToString() {
                // Check that we are not actually destroying the XML file
                $this->assertGreaterThan( 1500, strlen( 
$this->svg->saveToString() ) );

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ic0e5df88a50aad18bd4cfeb09510da192b90c924
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/TranslateSvg
Gerrit-Branch: master
Gerrit-Owner: Jarry1250 <[email protected]>

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

Reply via email to