Jarry1250 has submitted this change and it was merged.
Change subject: Extract reorderTexts() and add an extra invocation
......................................................................
Extract reorderTexts() and add an extra invocation
Extra invocation means roundtripping shouldn't change SVG XML at all
(whitespace notwithstanding), so we can add a test for that.
Fix other tests which relied on order not being changed.
Change-Id: I85d2b47c0723d7f17b0d182810b2f8a6ba3d6dd3
---
M SVGFile.php
M tests/phpunit/SVGFileTest.php
2 files changed, 31 insertions(+), 22 deletions(-)
Approvals:
Jarry1250: Verified; Looks good to me, approved
diff --git a/SVGFile.php b/SVGFile.php
index 39bacad..609833b 100644
--- a/SVGFile.php
+++ b/SVGFile.php
@@ -258,6 +258,8 @@
}
}
+ $this->reorderTexts();
+
$this->isTranslationReady = true;
return true;
}
@@ -491,29 +493,12 @@
}
}
}
+ $this->reorderTexts();
- // Move sublocales to the beginning of their switch elements
- $sublocales = $this->xpath->query(
- "//text[contains(@systemLanguage,'_')]" . "|" .
"//svg:text[contains(@systemLanguage,'_')]"
- );
- $count = $sublocales->length;
- for ( $i = 0; $i < $count; $i++ ) {
- $firstSibling = $sublocales->item( $i
)->parentNode->childNodes->item( 0 );
- $sublocales->item( $i )->parentNode->insertBefore(
$sublocales->item( $i ), $firstSibling );
- }
-
- // Move fallbacks to the end of their switch elements
- $fallbacks = $this->xpath->query(
- "//text[not(@systemLanguage)]" . "|" .
"//svg:text[not(@systemLanguage)]"
- );
- $count = $fallbacks->length;
- for ( $i = 0; $i < $count; $i++ ) {
- $fallbacks->item( $i )->parentNode->appendChild(
$fallbacks->item( $i ) );
- }
return array(
- 'expanded' => array_unique( $expanded ),
- 'started' => array_unique( $started )
+ 'started' => array_unique( $started ),
+ 'expanded' => array_unique( $expanded )
);
}
@@ -557,4 +542,25 @@
return new SVGFile( $file->getLocalRefPath(),
$group->getSourceLanguage() );
}
+
+ protected function reorderTexts() {
+ // Move sublocales to the beginning of their switch elements
+ $sublocales = $this->xpath->query(
+ "//text[contains(@systemLanguage,'_')]" . "|" .
"//svg:text[contains(@systemLanguage,'_')]"
+ );
+ $count = $sublocales->length;
+ for( $i = 0; $i < $count; $i++ ){
+ $firstSibling = $sublocales->item( $i
)->parentNode->childNodes->item( 0 );
+ $sublocales->item( $i )->parentNode->insertBefore(
$sublocales->item( $i ), $firstSibling );
+ }
+
+ // Move fallbacks to the end of their switch elements
+ $fallbacks = $this->xpath->query(
+ "//text[not(@systemLanguage)]" . "|" .
"//svg:text[not(@systemLanguage)]"
+ );
+ $count = $fallbacks->length;
+ for( $i = 0; $i < $count; $i++ ){
+ $fallbacks->item( $i )->parentNode->appendChild(
$fallbacks->item( $i ) );
+ }
+ }
}
diff --git a/tests/phpunit/SVGFileTest.php b/tests/phpunit/SVGFileTest.php
index 5843f77..116e389 100644
--- a/tests/phpunit/SVGFileTest.php
+++ b/tests/phpunit/SVGFileTest.php
@@ -281,14 +281,14 @@
public function testGetSavedLanguages() {
$expected = array(
- 'de', 'fr', 'en', 'nl', 'tlh-ca'
+ 'de', 'fr', 'nl', 'tlh-ca', 'en'
);
$this->assertEquals( $expected, $this->svg->getSavedLanguages()
);
}
public function testGetSavedLanguagesFiltered() {
$expected = array(
- 'full' => array( 'fr', 'en', 'nl', 'tlh-ca' ),
+ 'full' => array( 'fr', 'nl', 'tlh-ca', 'en' ),
'partial' => array( 'de' )
);
$this->assertEquals( $expected,
$this->svg->getSavedLanguagesFiltered() );
@@ -414,6 +414,7 @@
public function testSwitchTranslationSetRoundtrip() {
// Functions already tested above
+ $origXml = $this->svg->saveToString();
$current = $this->svg->getInFileTranslations();
$filteredTextNodes = $this->svg->getFilteredTextNodes();
$ret = $this->svg->switchToTranslationSet( array_merge(
$current, $filteredTextNodes ) );
@@ -421,6 +422,8 @@
$this->assertArrayEquals( $current,
$this->svg->getInFileTranslations() );
$this->assertArrayEquals( $filteredTextNodes,
$this->svg->getFilteredTextNodes() );
$this->assertArrayEquals( array( 'started' => array(),
'expanded' => array() ), $ret );
+
+ $this->assertEquals( str_replace( ' ', '', $origXml ),
str_replace( ' ', '', $this->svg->saveToString() ) );
}
public function testSaveToString() {
--
To view, visit https://gerrit.wikimedia.org/r/213796
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I85d2b47c0723d7f17b0d182810b2f8a6ba3d6dd3
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/TranslateSvg
Gerrit-Branch: master
Gerrit-Owner: Jarry1250 <[email protected]>
Gerrit-Reviewer: Jarry1250 <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits