summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'Translate/tests/phpunit/unit/PageTranslation/ParserOutputTest.php')
-rw-r--r--Translate/tests/phpunit/unit/PageTranslation/ParserOutputTest.php100
1 files changed, 100 insertions, 0 deletions
diff --git a/Translate/tests/phpunit/unit/PageTranslation/ParserOutputTest.php b/Translate/tests/phpunit/unit/PageTranslation/ParserOutputTest.php
new file mode 100644
index 00000000..9cad2b5c
--- /dev/null
+++ b/Translate/tests/phpunit/unit/PageTranslation/ParserOutputTest.php
@@ -0,0 +1,100 @@
+<?php
+declare( strict_types = 1 );
+
+namespace MediaWiki\Extension\Translate\PageTranslation;
+
+use InvalidArgumentException;
+use Language;
+use MediaWikiUnitTestCase;
+use Parser;
+
+/**
+ * @author Niklas Laxström
+ * @license GPL-2.0-or-later
+ * @covers \MediaWiki\Extension\Translate\PageTranslation\ParserOutput
+ */
+class ParserOutputTest extends MediaWikiUnitTestCase {
+ public function testConstructor() {
+ $actual = new ParserOutput( '', [], [] );
+ $this->assertInstanceOf( ParserOutput::class, $actual );
+ }
+
+ public function testConstructorFail() {
+ $this->expectException( InvalidArgumentException::class );
+ $actual = new ParserOutput( '', [ (object)[] ], [] );
+ $this->assertInstanceOf( ParserOutput::class, $actual );
+ }
+
+ public function testConstructorFail2() {
+ $this->expectException( InvalidArgumentException::class );
+ $actual = new ParserOutput( '', [], [ (object)[] ] );
+ $this->assertInstanceOf( ParserOutput::class, $actual );
+ }
+
+ public function testSourcePageTemplate() {
+ $output = new ParserOutput(
+ 'A<0>B',
+ [ '<0>' => new Section( '<translate>', '<1>', '</translate>' ) ],
+ []
+ );
+
+ $this->assertSame( 'A<translate><1></translate>B', $output->sourcePageTemplate() );
+ }
+
+ public function testTranslationPageTemplate() {
+ $output = new ParserOutput(
+ 'A<0>B',
+ [ '<0>' => new Section( '<translate>', '<1>', '</translate>' ) ],
+ []
+ );
+
+ $this->assertSame( 'A<1>B', $output->translationPageTemplate() );
+ }
+
+ public function testUnits() {
+ $units = [];
+ $units['<1>'] = new TranslationUnit( '' );
+
+ $output = new ParserOutput(
+ 'A<0>B',
+ [ '<0>' => new Section( '<translate>', '<1>', '</translate>' ) ],
+ $units
+ );
+
+ $this->assertSame( $units, $output->units() );
+ }
+
+ public function testSourcePageTextForRendering() {
+ $units = [];
+ $units['<1>'] = new TranslationUnit( 'Hello' );
+
+ $output = new ParserOutput(
+ 'A<0>B',
+ [ '<0>' => new Section( '<translate>', '<1>', '</translate>' ) ],
+ $units
+ );
+
+ $language = $this->createStub( Language::class );
+ $parser = $this->createStub( Parser::class );
+ $language->method( 'getHtmlCode' )
+ ->willReturn( 'en-GB' );
+ $language->method( 'getCode' )
+ ->willReturn( 'en-GB' );
+
+ $this->assertSame( 'AHelloB', $output->sourcePageTextForRendering( $language ) );
+ }
+
+ public function testSourcePageTextForSaving() {
+ $units = [];
+ $units['<1>'] = new TranslationUnit( 'Hello', 'abc' );
+ $units['<1>']->setIsInline( true );
+
+ $output = new ParserOutput(
+ 'A<0>B',
+ [ '<0>' => new Section( '<translate>', '<1>', '</translate>' ) ],
+ $units
+ );
+
+ $this->assertSame( 'A<translate><!--T:abc--> Hello</translate>B', $output->sourcePageTextForSaving() );
+ }
+}