summaryrefslogtreecommitdiff
path: root/www/wiki/extensions/Translate/tests/phpunit/TPParseTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'www/wiki/extensions/Translate/tests/phpunit/TPParseTest.php')
-rw-r--r--www/wiki/extensions/Translate/tests/phpunit/TPParseTest.php58
1 files changed, 58 insertions, 0 deletions
diff --git a/www/wiki/extensions/Translate/tests/phpunit/TPParseTest.php b/www/wiki/extensions/Translate/tests/phpunit/TPParseTest.php
new file mode 100644
index 00000000..d70689b8
--- /dev/null
+++ b/www/wiki/extensions/Translate/tests/phpunit/TPParseTest.php
@@ -0,0 +1,58 @@
+<?php
+/**
+ * @author Niklas Laxström
+ * @license GPL-2.0-or-later
+ * @file
+ */
+
+/**
+ * @ingroup PageTranslation
+ */
+class TPParseTest extends MediaWikiTestCase {
+ public function testGetTranslationPageText() {
+ $title = Title::newFromText( __CLASS__ );
+ $page = TranslatablePage::newFromText(
+ $title,
+ '<translate>Hello <tvar|abc>peter!</></translate>'
+ );
+ $prefix = $title->getPrefixedDBkey() . '/';
+ $parse = $page->getParse();
+
+ $collection = [];
+ $expected = 'Hello peter!';
+
+ $actual = $parse->getTranslationPageText( $collection );
+ $this->assertEquals(
+ $expected,
+ $actual,
+ 'Variable declarations are substituted when no translation'
+ );
+
+ foreach ( $parse->sections as $section ) {
+ $key = $prefix . $section->id;
+ $message = new FatMessage( $key, $section->getText() );
+ $message->setTranslation( $section->getText() );
+ $collection[$key] = $message;
+ }
+
+ $actual = $parse->getTranslationPageText( $collection );
+ $this->assertEquals(
+ $expected,
+ $actual,
+ 'Variable declarations are substituted in source language'
+ );
+
+ foreach ( $parse->sections as $section ) {
+ $key = $prefix . $section->id;
+ $message = new FatMessage( $key, $section->getText() );
+ $message->setTranslation( $section->getTextForTrans() );
+ $collection[$key] = $message;
+ }
+ $actual = $parse->getTranslationPageText( $collection );
+ $this->assertEquals(
+ $expected,
+ $actual,
+ 'Variable declarations are substituted in translation'
+ );
+ }
+}