summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'MLEB/Translate/tests/phpunit/unit')
-rw-r--r--MLEB/Translate/tests/phpunit/unit/PageTranslation/ParserOutputTest.php98
-rw-r--r--MLEB/Translate/tests/phpunit/unit/PageTranslation/SectionTest.php23
-rw-r--r--MLEB/Translate/tests/phpunit/unit/PageTranslation/TranslatablePageInsertablesSuggesterTest.php41
-rw-r--r--MLEB/Translate/tests/phpunit/unit/PageTranslation/TranslatablePageParserTest.php349
-rw-r--r--MLEB/Translate/tests/phpunit/unit/PageTranslation/TranslationUnitTest.php295
-rw-r--r--MLEB/Translate/tests/phpunit/unit/Statistics/TranslatorActivityTest.php43
-rw-r--r--MLEB/Translate/tests/phpunit/unit/Synchronization/GroupSynchronizationCacheTest.php193
-rw-r--r--MLEB/Translate/tests/phpunit/unit/Synchronization/MessageUpdateParameterTest.php17
-rw-r--r--MLEB/Translate/tests/phpunit/unit/TranslatorInterface/Insertable/CombinedInsertablesSuggesterTest.php90
-rw-r--r--MLEB/Translate/tests/phpunit/unit/TranslatorInterface/Insertable/HtmlTagInsertablesSuggesterTest.php (renamed from MLEB/Translate/tests/phpunit/unit/insertables/HtmlTagInsertablesSuggesterTest.php)12
-rw-r--r--MLEB/Translate/tests/phpunit/unit/TranslatorInterface/Insertable/InsertableFactoryTest.php56
-rw-r--r--MLEB/Translate/tests/phpunit/unit/TranslatorInterface/Insertable/MediaWikiInsertablesSuggesterTest.php38
-rw-r--r--MLEB/Translate/tests/phpunit/unit/TranslatorInterface/Insertable/NumericalParameterInsertablesSuggesterTest.php39
-rw-r--r--MLEB/Translate/tests/phpunit/unit/TranslatorInterface/Insertable/RegexInsertablesSuggesterTest.php70
-rw-r--r--MLEB/Translate/tests/phpunit/unit/TtmServer/TtmServerFactoryTest.php59
-rw-r--r--MLEB/Translate/tests/phpunit/unit/Utilities/GettextPluralTest.php10
-rw-r--r--MLEB/Translate/tests/phpunit/unit/Utilities/JsonCodecTest.php129
-rw-r--r--MLEB/Translate/tests/phpunit/unit/Utilities/ParsingPlaceholderFactoryTest.php4
-rw-r--r--MLEB/Translate/tests/phpunit/unit/Utilities/SmartFormatPluralTest.php10
-rw-r--r--MLEB/Translate/tests/phpunit/unit/Utilities/UnicodePluralTest.php10
-rw-r--r--MLEB/Translate/tests/phpunit/unit/Validation/Validators/BaseValidatorTestCase.php (renamed from MLEB/Translate/tests/phpunit/unit/MessageValidator/Validators/BaseValidatorTestCase.php)7
-rw-r--r--MLEB/Translate/tests/phpunit/unit/Validation/Validators/BraceBalanceValidatorTest.php (renamed from MLEB/Translate/tests/phpunit/unit/MessageValidator/Validators/BraceBalanceValidatorTest.php)4
-rw-r--r--MLEB/Translate/tests/phpunit/unit/Validation/Validators/EscapeCharacterValidatorTest.php (renamed from MLEB/Translate/tests/phpunit/unit/MessageValidator/Validators/EscapeCharacterValidatorTest.php)4
-rw-r--r--MLEB/Translate/tests/phpunit/unit/Validation/Validators/GettextNewlineValidatorTest.php (renamed from MLEB/Translate/tests/phpunit/unit/MessageValidator/Validators/GettextNewlineValidatorTest.php)4
-rw-r--r--MLEB/Translate/tests/phpunit/unit/Validation/Validators/GettextPluralValidatorTest.php (renamed from MLEB/Translate/tests/phpunit/unit/MessageValidator/Validators/GettextPluralValidatorTest.php)4
-rw-r--r--MLEB/Translate/tests/phpunit/unit/Validation/Validators/InsertableRegexValidatorTest.php (renamed from MLEB/Translate/tests/phpunit/unit/MessageValidator/Validators/InsertableRegexValidatorTest.php)4
-rw-r--r--MLEB/Translate/tests/phpunit/unit/Validation/Validators/InsertableRubyVariableValidatorTest.php (renamed from MLEB/Translate/tests/phpunit/unit/MessageValidator/Validators/InsertableRubyVariableValidatorTest.php)4
-rw-r--r--MLEB/Translate/tests/phpunit/unit/Validation/Validators/IosVariableValidatorTest.php (renamed from MLEB/Translate/tests/phpunit/unit/MessageValidator/Validators/IosVariableValidatorTest.php)4
-rw-r--r--MLEB/Translate/tests/phpunit/unit/Validation/Validators/MatchSetValidatorTest.php (renamed from MLEB/Translate/tests/phpunit/unit/MessageValidator/Validators/MatchSetValidatorTest.php)4
-rw-r--r--MLEB/Translate/tests/phpunit/unit/Validation/Validators/MediaWikiLinkValidatorTest.php (renamed from MLEB/Translate/tests/phpunit/unit/MessageValidator/Validators/MediaWikiLinkValidatorTest.php)4
-rw-r--r--MLEB/Translate/tests/phpunit/unit/Validation/Validators/MediaWikiPageNameValidatorTest.php (renamed from MLEB/Translate/tests/phpunit/unit/MessageValidator/Validators/MediaWikiPageNameValidatorTest.php)4
-rw-r--r--MLEB/Translate/tests/phpunit/unit/Validation/Validators/MediaWikiParameterValidatorTest.php (renamed from MLEB/Translate/tests/phpunit/unit/MessageValidator/Validators/MediaWikiParameterValidatorTest.php)4
-rw-r--r--MLEB/Translate/tests/phpunit/unit/Validation/Validators/MediaWikiTimeListValidatorTest.php (renamed from MLEB/Translate/tests/phpunit/unit/MessageValidator/Validators/MediaWikiTimeListValidatorTest.php)4
-rw-r--r--MLEB/Translate/tests/phpunit/unit/Validation/Validators/NewlineValidatorTest.php (renamed from MLEB/Translate/tests/phpunit/unit/MessageValidator/Validators/NewlineValidatorTest.php)4
-rw-r--r--MLEB/Translate/tests/phpunit/unit/Validation/Validators/NumericalParameterValidatorTest.php (renamed from MLEB/Translate/tests/phpunit/unit/MessageValidator/Validators/NumericalParameterValidatorTest.php)4
-rw-r--r--MLEB/Translate/tests/phpunit/unit/Validation/Validators/PrintfValidatorTest.php (renamed from MLEB/Translate/tests/phpunit/unit/MessageValidator/Validators/PrintfValidatorTest.php)4
-rw-r--r--MLEB/Translate/tests/phpunit/unit/Validation/Validators/PythonInterpolationValidatorTest.php (renamed from MLEB/Translate/tests/phpunit/unit/MessageValidator/Validators/PythonInterpolationValidatorTest.php)4
-rw-r--r--MLEB/Translate/tests/phpunit/unit/Validation/Validators/ReplacementValidatorTest.php (renamed from MLEB/Translate/tests/phpunit/unit/MessageValidator/Validators/ReplacementValidatorTest.php)4
-rw-r--r--MLEB/Translate/tests/phpunit/unit/Validation/Validators/SmartFormatPluralValidatorTest.php (renamed from MLEB/Translate/tests/phpunit/unit/MessageValidator/Validators/SmartFormatPluralValidatorTest.php)4
-rw-r--r--MLEB/Translate/tests/phpunit/unit/Validation/Validators/UnicodePluralValidatorTest.php (renamed from MLEB/Translate/tests/phpunit/unit/MessageValidator/Validators/UnicodePluralValidatorTest.php)4
-rw-r--r--MLEB/Translate/tests/phpunit/unit/tag/TPParseTest.php194
-rw-r--r--MLEB/Translate/tests/phpunit/unit/tag/TPSectionTest.php114
-rw-r--r--MLEB/Translate/tests/phpunit/unit/tag/TranslatablePageTest.php152
-rw-r--r--MLEB/Translate/tests/phpunit/unit/utils/ArrayFlattenerTest.php4
-rw-r--r--MLEB/Translate/tests/phpunit/unit/utils/MessageSourceChangeTest.php12
45 files changed, 1380 insertions, 765 deletions
diff --git a/MLEB/Translate/tests/phpunit/unit/PageTranslation/ParserOutputTest.php b/MLEB/Translate/tests/phpunit/unit/PageTranslation/ParserOutputTest.php
new file mode 100644
index 00000000..93f35c8d
--- /dev/null
+++ b/MLEB/Translate/tests/phpunit/unit/PageTranslation/ParserOutputTest.php
@@ -0,0 +1,98 @@
+<?php
+declare( strict_types = 1 );
+
+namespace MediaWiki\Extension\Translate\PageTranslation;
+
+use InvalidArgumentException;
+use Language;
+use MediaWikiUnitTestCase;
+
+/**
+ * @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();
+ $units['<1>']->text = 'Hello';
+
+ $output = new ParserOutput(
+ 'A<0>B',
+ [ '<0>' => new Section( '<translate>', '<1>', '</translate>' ) ],
+ $units
+ );
+
+ $language = $this->createStub( Language::class );
+ $language->method( 'getHtmlCode' )->willReturn( 'en-GB' );
+
+ $this->assertSame( 'AHelloB', $output->sourcePageTextForRendering( $language ) );
+ }
+
+ public function testSourcePageTextForSaving() {
+ $units = [];
+ $units['<1>'] = new TranslationUnit();
+ $units['<1>']->text = 'Hello';
+ $units['<1>']->id = '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() );
+ }
+}
diff --git a/MLEB/Translate/tests/phpunit/unit/PageTranslation/SectionTest.php b/MLEB/Translate/tests/phpunit/unit/PageTranslation/SectionTest.php
new file mode 100644
index 00000000..1cfcb5f1
--- /dev/null
+++ b/MLEB/Translate/tests/phpunit/unit/PageTranslation/SectionTest.php
@@ -0,0 +1,23 @@
+<?php
+declare( strict_types = 1 );
+
+namespace MediaWiki\Extension\Translate\PageTranslation;
+
+use MediaWikiUnitTestCase;
+
+/**
+ * @author Niklas Laxström
+ * @license GPL-2.0-or-later
+ * @covers \MediaWiki\Extension\Translate\PageTranslation\Section
+ */
+class SectionTest extends MediaWikiUnitTestCase {
+ public function test() {
+ $section = new Section( '<translate>', '2045903458', '</translate>' );
+ $this->assertSame( '2045903458', $section->contents() );
+ $this->assertSame( '<translate>2045903458</translate>', $section->wrappedContents() );
+
+ $section = new Section( '<translate>', "\n\n<0>\n\n", '</translate>' );
+ $this->assertSame( "\n<0>\n", $section->contents() );
+ $this->assertSame( "<translate>\n\n<0>\n\n</translate>", $section->wrappedContents() );
+ }
+}
diff --git a/MLEB/Translate/tests/phpunit/unit/PageTranslation/TranslatablePageInsertablesSuggesterTest.php b/MLEB/Translate/tests/phpunit/unit/PageTranslation/TranslatablePageInsertablesSuggesterTest.php
new file mode 100644
index 00000000..fbf36125
--- /dev/null
+++ b/MLEB/Translate/tests/phpunit/unit/PageTranslation/TranslatablePageInsertablesSuggesterTest.php
@@ -0,0 +1,41 @@
+<?php
+/**
+ * @file
+ * @author Niklas Laxström
+ * @license GPL-2.0-or-later
+ */
+
+namespace MediaWiki\Extension\Translate\PageTranslation;
+
+use MediaWiki\Extension\Translate\TranslatorInterface\Insertable\Insertable;
+use MediaWikiUnitTestCase;
+
+/** @covers \MediaWiki\Extension\Translate\PageTranslation\TranslatablePageInsertablesSuggester */
+class TranslatablePageInsertablesSuggesterTest extends MediaWikiUnitTestCase {
+ /** @dataProvider getInsertablesProvider */
+ public function testGetInsertables( $input, $expected ) {
+ $suggester = new TranslatablePageInsertablesSuggester();
+ $this->assertEquals( $expected, $suggester->getInsertables( $input ) );
+ }
+
+ public function getInsertablesProvider() {
+ return [
+ [
+ 'Hi $1, I am $myname $myLastName.',
+ [
+ new Insertable( '$1', '$1', '' ),
+ new Insertable( '$myname', '$myname', '' ),
+ new Insertable( '$myLastName', '$myLastName', '' ),
+ ]
+ ],
+ [
+ 'Insertables can $have-hyphens, $number9 and $under_scores',
+ [
+ new Insertable( '$have-hyphens', '$have-hyphens', '' ),
+ new Insertable( '$number9', '$number9', '' ),
+ new Insertable( '$under_scores', '$under_scores', '' ),
+ ]
+ ],
+ ];
+ }
+}
diff --git a/MLEB/Translate/tests/phpunit/unit/PageTranslation/TranslatablePageParserTest.php b/MLEB/Translate/tests/phpunit/unit/PageTranslation/TranslatablePageParserTest.php
new file mode 100644
index 00000000..17a1a706
--- /dev/null
+++ b/MLEB/Translate/tests/phpunit/unit/PageTranslation/TranslatablePageParserTest.php
@@ -0,0 +1,349 @@
+<?php
+declare( strict_types = 1 );
+
+namespace MediaWiki\Extension\Translate\PageTranslation;
+
+use MediaWiki\Extension\Translate\Utilities\ParsingPlaceholderFactory;
+use MediaWikiUnitTestCase;
+
+/**
+ * @author Niklas Laxström
+ * @license GPL-2.0-or-later
+ * @covers \MediaWiki\Extension\Translate\PageTranslation\TranslatablePageParser
+ */
+class TranslatablePageParserTest extends MediaWikiUnitTestCase {
+ /** @dataProvider provideTestContainsMarkup */
+ public function testContainsMarkup( string $input, bool $expected ) {
+ $parser = new TranslatablePageParser( new ParsingPlaceholderFactory() );
+ $this->assertSame( $expected, $parser->containsMarkup( $input ) );
+ }
+
+ public function provideTestContainsMarkup() {
+ yield [ 'Plain page', false ];
+
+ yield [ '<languages/>', false ];
+
+ yield [ '<translate>Board, Run!</translate>', true ];
+
+ yield [ '<translate nowrap>Board, Run!</translate>', true ];
+
+ yield [ '<translate unknown="attributes">Board, Run!</translate>', true ];
+
+ yield [ '</translate>', true ];
+
+ yield [ '<nowiki><translate></nowiki>', false ];
+ }
+
+ /** @dataProvider provideTestCleanupTags */
+ public function testCleanupTags( string $input, string $expected ) {
+ $parser = new TranslatablePageParser( new ParsingPlaceholderFactory() );
+ $this->assertSame( $expected, $parser->cleanupTags( $input ) );
+ }
+
+ public function provideTestCleanupTags() {
+ yield 'Unbalanced tag in a section preview' => [
+ "== Hello ==\n</translate>",
+ '== Hello ==',
+ ];
+
+ yield 'Unbalanced tags, no whitespace' => [
+ "</translate><translate>",
+ '',
+ ];
+
+ yield 'Balanced tags, non-removable whitespace' => [
+ "1\n2<translate>3\n4</translate>5\n6",
+ "1\n23\n45\n6",
+ ];
+
+ yield 'Balanced tags, removable whitespace' => [
+ "1<translate>\n\n</translate>2",
+ '12',
+ ];
+
+ yield 'Old style translation variable tag is collapsed' => [
+ '[[<tvar|wmf>Special:MyLanguage/Wikimedia Foundation</>|Wikimedia Foundation]].',
+ '[[Special:MyLanguage/Wikimedia Foundation|Wikimedia Foundation]].',
+ ];
+
+ yield 'Translation variable tag is collapsed' => [
+ '[[<tvar name=wmf>Special:MyLanguage/Wikimedia Foundation</tvar>|Wikimedia Foundation]].',
+ '[[Special:MyLanguage/Wikimedia Foundation|Wikimedia Foundation]].',
+ ];
+
+ yield 'Tag inside a nowiki is retained' => [
+ 'You can use the <nowiki><translate></nowiki> tag.',
+ 'You can use the <nowiki><translate></nowiki> tag.',
+ ];
+
+ yield 'Broken tag is retained' => [
+ 'What if I <translate and </translate>.',
+ 'What if I <translate and .',
+ ];
+
+ yield 'Tag with nowrap is removed' => [
+ '<abbr title="<translate nowrap>Careful unselfish true engineer</translate>">CUTE</abbr>',
+ '<abbr title="Careful unselfish true engineer">CUTE</abbr>',
+ ];
+
+ yield 'No content to remove' => [
+ 'Plain page',
+ 'Plain page',
+ ];
+
+ yield 'Language tag should not be removed by this method' => [
+ '<languages/>',
+ '<languages/>',
+ ];
+
+ yield 'Unclosed tag is removed' => [
+ '<translate>No worries, I will try to remember to close this tag',
+ 'No worries, I will try to remember to close this tag',
+
+ ];
+
+ yield 'Complex old translation variable syntax is parsed and replaced with contents' => [
+ '<translate nowrap>I have <tvar|!><:D></></translate>!',
+ 'I have <:D>!',
+ ];
+
+ yield 'Complex translation variable syntax is parsed and replaced with contents' => [
+ '<translate nowrap>I have <tvar name="--$"><:D></tvar></translate>!',
+ 'I have <:D>!',
+ ];
+
+ yield 'No extra newlines is added' => [
+ 'A<translate>B<translate>C</translate>D</translate>E',
+ 'ABCDE',
+ ];
+
+ yield 'Reasonable amount of newlines is stripped' => [
+ "A\n<translate>\n\nB</translate>\nC\n<translate>D\n\n\n\n</translate>E",
+ "A\n\nB\nC\nD\n\n\nE",
+
+ ];
+
+ yield 'Section markers are removed from headings' => [
+ "<translate>\n== Head of the header == <!--T:1-->\n</translate>",
+ "== Head of the header ==",
+ ];
+
+ yield 'Section markers are removed, but not other text' => [
+ ' <!--T:10--> text <!--T:11--> more text <!--T:12--> even more',
+ ' text more text even more',
+ ];
+ }
+
+ /** @dataProvider provideTestParse */
+ public function testParse(
+ string $input,
+ string $expectedTranslationTemplate,
+ string $expectedSourceTemplate,
+ array $expectedUnits
+ ) {
+ $parser = new TranslatablePageParser( new TestingParsingPlaceholderFactory() );
+ $output = $parser->parse( $input );
+ $this->assertSame( $expectedTranslationTemplate, $output->translationPageTemplate() );
+ $this->assertSame( $expectedSourceTemplate, $output->sourcePageTemplate() );
+ $this->assertEquals( $expectedUnits, $output->units() );
+ }
+
+ public function provideTestParse() {
+ // Test case 1 //
+ $s1 = new TranslationUnit();
+ $s1->text = '== Unit tests ==';
+ $s1->id = -1;
+
+ $s2 = new TranslationUnit();
+ $s2->text = 'Introduction to unit tests.';
+ $s2->id = -1;
+
+ $s3 = new TranslationUnit();
+ $s3->text = 'They are fun.';
+ $s3->id = -1;
+
+ $s4 = new TranslationUnit();
+ $s4->text = 'Smilie';
+ $s4->id = -1;
+ $s4->setCanWrap( false );
+ $s4->setIsInline( true );
+
+ yield [
+ <<<INPUT
+<languages/>
+<translate>
+== Unit tests ==
+
+Introduction to unit tests.
+
+They are fun.
+</translate>
+
+<abbr title="<translate nowrap>Smilie</translate>">:)</abbr>
+INPUT
+ , <<<TRANSLATION_TEMPLATE
+<languages/>
+<1>
+
+<2>
+
+<3>
+
+<abbr title="<5>">:)</abbr>
+TRANSLATION_TEMPLATE
+ , <<<SOURCE_TEMPLATE
+<languages/>
+<translate>
+<1>
+
+<2>
+
+<3>
+</translate>
+
+<abbr title="<translate nowrap><5></translate>">:)</abbr>
+SOURCE_TEMPLATE
+ ,
+ [
+ '<1>' => $s1,
+ '<2>' => $s2,
+ '<3>' => $s3,
+ '<5>' => $s4,
+ ]
+ ];
+
+ // Test case 2 //
+ $s1 = new TranslationUnit();
+ $s1->text = '== Unit tests ==';
+ $s1->id = '11';
+
+ $s2 = new TranslationUnit();
+ $s2->text = 'Introduction to unit tests.';
+ $s2->id = '22';
+
+ $s3 = new TranslationUnit();
+ $s3->text = 'They are fun.';
+ $s3->id = '33';
+
+ $s4 = new TranslationUnit();
+ $s4->text = 'Smilie';
+ $s4->id = '44';
+ $s4->setCanWrap( false );
+ $s4->setIsInline( true );
+
+ yield [
+ <<<INPUT
+<languages/>
+<translate>
+== Unit tests == <!--T:11-->
+
+<!--T:22-->
+Introduction to unit tests.
+
+<!--T:33-->
+They are fun.
+</translate>
+
+<abbr title="<translate nowrap><!--T:44--> Smilie</translate>">:)</abbr>
+INPUT
+ , <<<TRANSLATION_TEMPLATE
+<languages/>
+<1>
+
+<2>
+
+<3>
+
+<abbr title="<5>">:)</abbr>
+TRANSLATION_TEMPLATE
+ , <<<SOURCE_TEMPLATE
+<languages/>
+<translate>
+<1>
+
+<2>
+
+<3>
+</translate>
+
+<abbr title="<translate nowrap><5></translate>">:)</abbr>
+SOURCE_TEMPLATE
+ ,
+ [
+ '<1>' => $s1,
+ '<2>' => $s2,
+ '<3>' => $s3,
+ '<5>' => $s4,
+ ]
+ ];
+ }
+
+ /** @dataProvider provideTestParseSection */
+ public function testParseSection(
+ string $input,
+ string $expectedTemplate,
+ array $expectedUnits,
+ string $comment
+ ) {
+ $parser = new TranslatablePageParser( new TestingParsingPlaceholderFactory() );
+ $canWrap = true;
+ $result = $parser->parseSection( $input, $canWrap );
+ $this->assertSame( $expectedTemplate, $result['template'], $comment );
+ $this->assertEquals( $expectedUnits, $result['sections'], $comment );
+ }
+
+ public static function provideTestParseSection() {
+ $u = new TranslationUnit();
+ $u->text = 'Hello';
+ $u->id = -1;
+ $u->setIsInline( true );
+ yield [
+ 'Hello',
+ '<0>',
+ [ '<0>' => $u ],
+ 'No surrounding whitespace',
+ ];
+
+ $u = new TranslationUnit();
+ $u->text = 'Hello';
+ $u->id = -1;
+ yield [
+ "\nHello",
+ "\n<0>",
+ [ '<0>' => $u ],
+ 'With surrounding whitespace',
+ ];
+
+ $u0 = new TranslationUnit();
+ $u0->text = 'Hello world';
+ $u0->id = -1;
+
+ $u1 = new TranslationUnit();
+ $u1->text = 'Bunny';
+ $u1->id = -1;
+ yield [
+ "\nHello world\n\nBunny\n",
+ "\n<0>\n\n<1>\n",
+ [ '<0>' => $u0, '<1>' => $u1 ],
+ 'Splitting at one empty line',
+ ];
+
+ $u0 = new TranslationUnit();
+ $u0->text = 'First';
+ $u0->id = -1;
+
+ $u1 = new TranslationUnit();
+ $u1->text = 'Second';
+ $u1->id = -1;
+
+ $u2 = new TranslationUnit();
+ $u2->text = 'Third';
+ $u2->id = -1;
+ yield [
+ "First\n\n\n\n\nSecond\n\nThird",
+ "<0>\n\n\n\n\n<1>\n\n<2>",
+ [ '<0>' => $u0, '<1>' => $u1, '<2>' => $u2 ],
+ 'Splitting with multiple empty lines',
+ ];
+ }
+}
diff --git a/MLEB/Translate/tests/phpunit/unit/PageTranslation/TranslationUnitTest.php b/MLEB/Translate/tests/phpunit/unit/PageTranslation/TranslationUnitTest.php
new file mode 100644
index 00000000..f87860ca
--- /dev/null
+++ b/MLEB/Translate/tests/phpunit/unit/PageTranslation/TranslationUnitTest.php
@@ -0,0 +1,295 @@
+<?php
+declare( strict_types = 1 );
+
+namespace MediaWiki\Extension\Translate\PageTranslation;
+
+use FatMessage;
+use Language;
+use MediaWikiUnitTestCase;
+
+/**
+ * @author Niklas Laxström
+ * @license GPL-2.0-or-later
+ * @covers \MediaWiki\Extension\Translate\PageTranslation\TranslationUnit
+ */
+class TranslationUnitTest extends MediaWikiUnitTestCase {
+ public function setUp(): void {
+ parent::setUp();
+
+ if ( !defined( 'TRANSLATE_FUZZY' ) ) {
+ define( 'TRANSLATE_FUZZY', '!!FUZZY!!' );
+ }
+ }
+
+ /** @dataProvider providerTestGetMarkedText */
+ public function testGetMarkedText(
+ string $name, string $text, bool $inline, string $expected
+ ) {
+ $section = new TranslationUnit();
+ $section->name = $name;
+ $section->text = $text;
+ $section->setIsInline( $inline );
+
+ $output = $section->getMarkedText();
+
+ $this->assertEquals( $expected, $output );
+ }
+
+ /** @dataProvider providerTestGetTextWithVariables */
+ public function testGetTextWithVariables( string $text, string $expected ) {
+ $section = new TranslationUnit();
+ $section->text = $text;
+
+ $output = $section->getTextWithVariables();
+
+ $this->assertEquals( $expected, $output );
+ }
+
+ /** @dataProvider providerTestGetTextForTrans */
+ public function testGetTextForTrans( string $text, string $expected ) {
+ $section = new TranslationUnit();
+ $section->text = $text;
+
+ $output = $section->getTextForTrans();
+
+ $this->assertEquals( $expected, $output );
+ }
+
+ public static function providerTestGetMarkedText() {
+ $cases = [];
+
+ // Inline syntax
+ $cases[] = [
+ 'name',
+ 'Hello',
+ true,
+ '<!--T:name--> Hello',
+ ];
+
+ // Normal syntax
+ $cases[] = [
+ 'name',
+ 'Hello',
+ false,
+ "<!--T:name-->\nHello",
+ ];
+
+ // Inline should not matter for headings, which have special syntax, but test both values
+ $cases[] = [
+ 'name',
+ '== Hello ==',
+ true,
+ '== Hello == <!--T:name-->',
+ ];
+
+ $cases[] = [
+ 'name',
+ '====== Hello ======',
+ false,
+ '====== Hello ====== <!--T:name-->',
+ ];
+
+ return $cases;
+ }
+
+ public static function providerTestGetTextWithVariables() {
+ $cases = [];
+
+ // syntax
+ $cases[] = [
+ "<tvar|abc>Peter\n cat!</>",
+ '$abc',
+ ];
+
+ $cases[] = [
+ "<tvar|1>Hello</>\n<tvar|2>Hello</>",
+ "$1\n$2",
+ ];
+
+ return $cases;
+ }
+
+ public static function providerTestGetTextForTrans() {
+ $cases = [];
+
+ // syntax
+ $cases[] = [
+ "<tvar|abc>Peter\n cat!</>",
+ "Peter\n cat!",
+ ];
+
+ $cases[] = [
+ "<tvar|1>Hello</>\n<tvar|2>Hello</>",
+ "Hello\nHello",
+ ];
+
+ return $cases;
+ }
+
+ /** @dataProvider provideTestGetTextForRendering */
+ public function testGetTextForRendering(
+ string $source,
+ ?string $translation,
+ bool $fuzzy,
+ bool $inline,
+ string $expected
+ ) {
+ $unit = new TranslationUnit();
+ $unit->text = $source;
+ $unit->setIsInline( $inline );
+
+ $msg = null;
+ if ( $translation !== null ) {
+ $msg = new FatMessage( '', $unit->getTextWithVariables() );
+ $msg->setTranslation( $translation );
+ if ( $fuzzy ) {
+ $msg->addTag( 'fuzzy' );
+ }
+ }
+
+ $sourceLanguage = $this->createStub( Language::class );
+ $sourceLanguage->method( 'getHtmlCode' )->willReturn( 'en-GB' );
+ $sourceLanguage->method( 'getCode' )->willReturn( 'en-gb' );
+ $sourceLanguage->method( 'getDir' )->willReturn( 'ltr' );
+
+ $targetLanguage = $this->createStub( Language::class );
+ $targetLanguage->method( 'getHtmlCode' )->willReturn( 'ar' );
+ $targetLanguage->method( 'getCode' )->willReturn( 'ar' );
+ $targetLanguage->method( 'getDir' )->willReturn( 'rtl' );
+
+ $wrapUntranslated = true;
+ $actual = $unit->getTextForRendering(
+ $msg,
+ $sourceLanguage,
+ $targetLanguage,
+ $wrapUntranslated
+ );
+ $this->assertEquals( $expected, $actual );
+ }
+
+ public function provideTestGetTextForRendering() {
+ $fuzzy = true;
+ $inline = true;
+ $block = false;
+
+ yield 'language wrapping' => [
+ 'Hello <tvar|abc>peter</>!',
+ null,
+ !$fuzzy,
+ $inline,
+ '<span lang="en-GB" dir="ltr" class="mw-content-ltr">Hello peter!</span>'
+ ];
+
+ yield 'old translation variable syntax' => [
+ 'Hello <tvar|abc>peter</>!',
+ 'Hejsan $abc!',
+ !$fuzzy,
+ $inline,
+ 'Hejsan peter!'
+ ];
+
+ yield 'translation variable syntax without quotes' => [
+ 'Hello <tvar name=abc>peter</tvar>!',
+ 'Hejsan $abc!',
+ !$fuzzy,
+ $inline,
+ 'Hejsan peter!'
+ ];
+
+ yield 'translation variable syntax with double quotes' => [
+ 'Hello <tvar name="abc">peter</tvar>!',
+ 'Hejsan $abc!',
+ !$fuzzy,
+ $inline,
+ 'Hejsan peter!'
+ ];
+
+ yield 'translation variable syntax with single quotes' => [
+ 'Hello <tvar name=\'abc\'>peter</tvar>!',
+ 'Hejsan $abc!',
+ !$fuzzy,
+ $inline,
+ 'Hejsan peter!'
+ ];
+
+ yield 'translation variable syntax with spaces' => [
+ 'Hello <tvar name = abc >peter</tvar>!',
+ 'Hejsan $abc!',
+ !$fuzzy,
+ $inline,
+ 'Hejsan peter!'
+ ];
+
+ yield 'mixed variable syntax' => [
+ 'Hello <tvar name=2>peter</tvar> and <tvar|1>peter</>!',
+ 'Hejsan $1 and $2!',
+ !$fuzzy,
+ $inline,
+ 'Hejsan peter and peter!'
+ ];
+
+ yield 'special characters in variable name' => [
+ 'Hello <tvar name=abc_123-АБВ$>peter</tvar>!',
+ 'Hejsan $abc_123-АБВ$!',
+ !$fuzzy,
+ $inline,
+ 'Hejsan peter!'
+ ];
+
+ yield 'inline fuzzy wrapping' => [
+ 'Hello <tvar|abc>peter</>!',
+ 'Hejsan $abc!',
+ $fuzzy,
+ $inline,
+ '<span class="mw-translate-fuzzy">Hejsan peter!</span>'
+ ];
+
+ yield 'block language wrapping' => [
+ 'Hello <tvar|abc>peter</>!',
+ null,
+ !$fuzzy,
+ $block,
+ "<div lang=\"en-GB\" dir=\"ltr\" class=\"mw-content-ltr\">\nHello peter!\n</div>"
+ ];
+
+ yield 'block variables' => [
+ 'Hello <tvar name=abc>peter</tvar>!',
+ 'Hejsan $abc!',
+ !$fuzzy,
+ $block,
+ 'Hejsan peter!'
+ ];
+
+ yield 'block fuzzy wrapping' => [
+ 'Hello <tvar|abc>peter</>!',
+ 'Hejsan $abc!',
+ $fuzzy,
+ $block,
+ "<div class=\"mw-translate-fuzzy\">\nHejsan peter!\n</div>"
+ ];
+
+ yield 'translation language in the source' => [
+ '{{TRANSLATIONLANGUAGE}}',
+ null,
+ !$fuzzy,
+ $inline,
+ '<span lang="en-GB" dir="ltr" class="mw-content-ltr">en-gb</span>'
+ ];
+
+ yield 'translation language in the translation' => [
+ '{{TRANSLATIONLANGUAGE}}',
+ '{{TRANSLATIONLANGUAGE}}',
+ $fuzzy,
+ $inline,
+ '<span class="mw-translate-fuzzy">ar</span>'
+ ];
+
+ yield 'translation language in a variable' => [
+ 'Lang: <tvar|code>{{TRANSLATIONLANGUAGE}}</>',
+ 'Lang: $code',
+ !$fuzzy,
+ $inline,
+ 'Lang: ar'
+ ];
+ }
+}
diff --git a/MLEB/Translate/tests/phpunit/unit/Statistics/TranslatorActivityTest.php b/MLEB/Translate/tests/phpunit/unit/Statistics/TranslatorActivityTest.php
index 3c00fe15..48602904 100644
--- a/MLEB/Translate/tests/phpunit/unit/Statistics/TranslatorActivityTest.php
+++ b/MLEB/Translate/tests/phpunit/unit/Statistics/TranslatorActivityTest.php
@@ -1,30 +1,29 @@
<?php
-/**
- * @file
- * @author Niklas Laxström
- * @license GPL-2.0-or-later
- */
+declare( strict_types = 1 );
-namespace MediaWiki\Extensions\Translate\Statistics;
+namespace MediaWiki\Extension\Translate\Statistics;
use EmptyBagOStuff;
use HashBagOStuff;
use InvalidArgumentException;
use JobQueueGroup;
+use MediaWiki\Languages\LanguageNameUtils;
use MediaWikiUnitTestCase;
use Wikimedia\Timestamp\ConvertibleTimestamp;
/**
- * @covers \MediaWiki\Extensions\Translate\Statistics\TranslatorActivity
+ * @author Niklas Laxström
+ * @license GPL-2.0-or-later
+ * @covers \MediaWiki\Extension\Translate\Statistics\TranslatorActivity
*/
class TranslatorActivityTest extends MediaWikiUnitTestCase {
public function testInvalidLanguage() {
$cache = $this->createMock( EmptyBagOStuff::class );
$query = $this->createMock( TranslatorActivityQuery::class );
$jobQueue = $this->createMock( JobQueueGroup::class );
- $languageValidator = function ( string $language ): bool {
- return false;
- };
+ $languageValidator = $this->createMock( LanguageNameUtils::class );
+ $languageValidator->method( 'isKnownLanguageTag' )->willReturn( false );
+
$service = new TranslatorActivity( $cache, $query, $jobQueue, $languageValidator );
$this->expectException( InvalidArgumentException::class );
@@ -51,9 +50,9 @@ class TranslatorActivityTest extends MediaWikiUnitTestCase {
->with( $this->equalTo( $language ) );
$jobQueue = $this->createMock( JobQueueGroup::class );
$jobQueue->expects( $this->never() )->method( 'push' );
- $languageValidator = function ( string $language ): bool {
- return true;
- };
+ $languageValidator = $this->createMock( LanguageNameUtils::class );
+ $languageValidator->method( 'isKnownLanguageTag' )->willReturn( true );
+
$service = new TranslatorActivity( $cache, $query, $jobQueue, $languageValidator );
ConvertibleTimestamp::setFakeTime( $fakeTime1 );
@@ -80,9 +79,9 @@ class TranslatorActivityTest extends MediaWikiUnitTestCase {
->with( $this->equalTo( $language ) );
$jobQueue = $this->createMock( JobQueueGroup::class );
$jobQueue->expects( $this->once() )->method( 'push' );
- $languageValidator = function ( string $language ): bool {
- return true;
- };
+ $languageValidator = $this->createMock( LanguageNameUtils::class );
+ $languageValidator->method( 'isKnownLanguageTag' )->willReturn( true );
+
$service = new TranslatorActivity( $cache, $query, $jobQueue, $languageValidator );
ConvertibleTimestamp::setFakeTime( $fakeTime1 );
@@ -114,9 +113,9 @@ class TranslatorActivityTest extends MediaWikiUnitTestCase {
->with( $this->equalTo( $language ) );
$jobQueue = $this->createMock( JobQueueGroup::class );
$jobQueue->expects( $this->never() )->method( 'push' );
- $languageValidator = function ( string $language ): bool {
- return true;
- };
+ $languageValidator = $this->createMock( LanguageNameUtils::class );
+ $languageValidator->method( 'isKnownLanguageTag' )->willReturn( true );
+
$service = new TranslatorActivity( $cache, $query, $jobQueue, $languageValidator );
ConvertibleTimestamp::setFakeTime( $fakeTime1 );
@@ -132,11 +131,13 @@ class TranslatorActivityTest extends MediaWikiUnitTestCase {
private function getExampleData(): array {
$translators = [
- 'Hunter' => [
+ [
+ TranslatorActivityQuery::USER_NAME => 'Hunter',
TranslatorActivityQuery::USER_TRANSLATIONS => 1234,
TranslatorActivityQuery::USER_LAST_ACTIVITY => 10,
],
- 'Farmer' => [
+ [
+ TranslatorActivityQuery::USER_NAME => 'Farmer',
TranslatorActivityQuery::USER_TRANSLATIONS => 2,
TranslatorActivityQuery::USER_LAST_ACTIVITY => 20,
],
diff --git a/MLEB/Translate/tests/phpunit/unit/Synchronization/GroupSynchronizationCacheTest.php b/MLEB/Translate/tests/phpunit/unit/Synchronization/GroupSynchronizationCacheTest.php
deleted file mode 100644
index 8a612ee1..00000000
--- a/MLEB/Translate/tests/phpunit/unit/Synchronization/GroupSynchronizationCacheTest.php
+++ /dev/null
@@ -1,193 +0,0 @@
-<?php
-
-namespace MediaWiki\Extensions\Translate\Synchronization;
-
-use HashBagOStuff;
-use MediaWikiUnitTestCase;
-
-/**
- * @covers \MediaWiki\Extensions\Translate\Synchronization\GroupSynchronizationCache
- * @covers \MediaWiki\Extensions\Translate\Synchronization\GroupSynchronizationResponse
- */
-class GroupSynchronizationCacheTest extends MediaWikiUnitTestCase {
- /** @var GroupSynchronizationCache */
- private $groupSyncCache;
-
- protected function setUp(): void {
- $this->groupSyncCache = $this->getGroupSynchronizationCache();
- }
-
- public function testIsGroupBeingProcessed() {
- $groupId = 'hello';
- $this->groupSyncCache->startSync( $groupId );
-
- $this->assertTrue( $this->groupSyncCache->isGroupBeingProcessed( $groupId ) );
-
- $this->groupSyncCache->endSync( $groupId );
-
- $this->assertFalse( $this->groupSyncCache->isGroupBeingProcessed( $groupId ) );
- }
-
- public function testGetGroupMessageKeys() {
- $groupId = 'hello';
- $title = 'Title';
-
- $this->groupSyncCache->startSync( $groupId );
- $this->groupSyncCache->addMessages(
- $groupId,
- $this->getMessageParam( $groupId, $title )
- );
-
- $this->assertEquals(
- [ $title ], $this->groupSyncCache->getGroupMessageKeys( $groupId )
- );
-
- $this->groupSyncCache->removeMessages( $title );
-
- $this->assertEquals(
- [ $title ],
- $this->groupSyncCache->getGroupMessageKeys( $groupId ),
- 'Removing a message does not update the group message list.'
- );
- }
-
- public function testGetGroupsInSync() {
- $groupId = 'hello';
-
- $this->groupSyncCache->startSync( $groupId );
- $this->assertEquals( [ $groupId ], $this->groupSyncCache->getGroupsInSync() );
-
- $this->groupSyncCache->endSync( $groupId );
- $this->assertEquals( [], $this->groupSyncCache->getGroupsInSync() );
- }
-
- public function testEndSync() {
- $groupId = 'group-id';
- $title = 'hello';
-
- $this->groupSyncCache->startSync( $groupId );
- $this->groupSyncCache->addMessages(
- $groupId, $this->getMessageParam( $groupId, $title )
- );
- $this->assertNotEmpty( $this->groupSyncCache->getMessages( $title )[$title] );
- $this->assertTrue( $this->groupSyncCache->isGroupBeingProcessed( $groupId ) );
-
- $this->groupSyncCache->endSync( $groupId );
-
- $message = $this->groupSyncCache->getMessages( $title )[$title];
- $this->assertEmpty( $message );
- }
-
- /**
- * @dataProvider provideGetSynchronizationStatus
- */
- public function testGetSynchronizationStatus(
- GroupSynchronizationCache $syncCache,
- string $groupId,
- array $titlesToAdd,
- array $titlesToRemove,
- bool $hasTimedOut = false
- ) {
- $syncCache->startSync( $groupId );
-
- $this->assertTrue( $syncCache->isGroupBeingProcessed( $groupId ) );
-
- foreach ( $titlesToAdd as $title ) {
- $syncCache->addMessages(
- $groupId, $this->getMessageParam( $groupId, $title )
- );
- }
-
- $this->assertEquals( $titlesToAdd, $syncCache->getGroupMessageKeys( $groupId ) );
-
- $syncCache->removeMessages( ...$titlesToRemove );
-
- $groupSyncResponse = $syncCache->getSynchronizationStatus( $groupId );
-
- $diffArray = array_values( array_diff( $titlesToAdd, $titlesToRemove ) );
- $this->assertEquals( $diffArray, $syncCache->getGroupMessageKeys( $groupId ) );
-
- if ( $diffArray === [] ) {
- $this->assertEmpty( $this->groupSyncCache->getGroupsInSync() );
- }
-
- $this->assertEquals( $diffArray === [], $groupSyncResponse->isDone() );
- $this->assertEquals( $hasTimedOut, $groupSyncResponse->hasTimedOut() );
- $this->assertEquals(
- $diffArray,
- $groupSyncResponse->getRemainingMessages()
- );
- $this->assertEquals( $groupId, $groupSyncResponse->getGroupId() );
- }
-
- public function testGetMulti() {
- $groupId = 'hello';
-
- $this->groupSyncCache->addMessages( $groupId,
- $this->getMessageParam( $groupId, 'Title' ),
- $this->getMessageParam( $groupId, 'Title_ABC' )
- );
-
- $messages = $this->groupSyncCache->getMessages( 'Title', 'Title_ABC', 'Title_ABCD' );
- $this->assertEquals( [ 'Title', 'Title_ABC', 'Title_ABCD' ], array_keys( $messages ) );
-
- $messages = $this->groupSyncCache->getMessages( 'Title_ABCD' );
- $this->assertNull( $messages['Title_ABCD'] );
- }
-
- public function provideGetSynchronizationStatus() {
- $groupId = 'hello';
- $syncCache = $this->getGroupSynchronizationCache();
- yield [
- $syncCache,
- $groupId,
- [ 'Title', 'Title1' ],
- [ 'Title' ],
- false
- ];
-
- $syncCache = $this->getGroupSynchronizationCache();
- yield [
- $syncCache,
- $groupId,
- [ 'Hello' ],
- [ 'Hello' ],
- false
- ];
-
- $syncCache = $this->getGroupSynchronizationCache( -1 );
- yield [
- $syncCache,
- $groupId,
- [ 'Hello' ],
- [ 'Hello' ],
- false
- ];
-
- $syncCache = $this->getGroupSynchronizationCache( -1 );
- yield [
- $syncCache,
- $groupId,
- [ 'Hello', 'Title' ],
- [ 'Hello' ],
- true
- ];
- }
-
- private function getMessageParam( string $groupId, string $title ): MessageUpdateParameter {
- return new MessageUpdateParameter( [
- 'fuzzy' => true,
- 'content' => 'Hello',
- 'title' => $title,
- 'groupId' => $groupId
- ] );
- }
-
- private function getGroupSynchronizationCache( int $timeout = null ): GroupSynchronizationCache {
- if ( $timeout ) {
- return new GroupSynchronizationCache( new HashBagOStuff(), $timeout );
- }
-
- return new GroupSynchronizationCache( new HashBagOStuff() );
- }
-}
diff --git a/MLEB/Translate/tests/phpunit/unit/Synchronization/MessageUpdateParameterTest.php b/MLEB/Translate/tests/phpunit/unit/Synchronization/MessageUpdateParameterTest.php
index 22e4f639..1f901b97 100644
--- a/MLEB/Translate/tests/phpunit/unit/Synchronization/MessageUpdateParameterTest.php
+++ b/MLEB/Translate/tests/phpunit/unit/Synchronization/MessageUpdateParameterTest.php
@@ -1,18 +1,14 @@
<?php
-namespace MediaWiki\Extensions\Translate\Synchronization;
+namespace MediaWiki\Extension\Translate\Synchronization;
use MediaWikiUnitTestCase;
use MessageUpdateJob;
use Title;
-/**
- * @covers \MediaWiki\Extensions\Translate\Synchronization\MessageUpdateParameter
- */
+/** @covers \MediaWiki\Extension\Translate\Synchronization\MessageUpdateParameter */
class MessageUpdateParameterTest extends MediaWikiUnitTestCase {
- /**
- * @dataProvider provideSerializable
- */
+ /** @dataProvider provideSerializable */
public function testSerializable(
string $title,
string $content,
@@ -32,9 +28,7 @@ class MessageUpdateParameterTest extends MediaWikiUnitTestCase {
$this->assertEquals( $messageParam, $serializedMessageParam );
}
- /**
- * @dataProvider provideSerializable
- */
+ /** @dataProvider provideSerializable */
public function testCreateFromJob(
string $title,
string $content,
@@ -52,10 +46,13 @@ class MessageUpdateParameterTest extends MediaWikiUnitTestCase {
$this->assertEquals( $content, $messageParams->getContent() );
$this->assertEquals( $isRename, $messageParams->isRename() );
$this->assertEquals( $isFuzzy, $messageParams->isFuzzy() );
+
if ( $isRename ) {
$this->assertEquals( $target, $messageParams->getTargetValue() );
$this->assertEquals( $replacement, $messageParams->getReplacementValue() );
$this->assertEquals( $otherLangs, $messageParams->getOtherLangs() );
+ } else {
+ $this->assertNull( $messageParams->getOtherLangs() );
}
}
diff --git a/MLEB/Translate/tests/phpunit/unit/TranslatorInterface/Insertable/CombinedInsertablesSuggesterTest.php b/MLEB/Translate/tests/phpunit/unit/TranslatorInterface/Insertable/CombinedInsertablesSuggesterTest.php
new file mode 100644
index 00000000..1f2d82b1
--- /dev/null
+++ b/MLEB/Translate/tests/phpunit/unit/TranslatorInterface/Insertable/CombinedInsertablesSuggesterTest.php
@@ -0,0 +1,90 @@
+<?php
+/**
+ * @file
+ * @author Geoffrey Mon
+ * @license GPL-2.0-or-later
+ */
+
+namespace MediaWiki\Extension\Translate\TranslatorInterface\Insertable;
+
+use MediaWikiUnitTestCase;
+
+/** @covers \MediaWiki\Extension\Translate\TranslatorInterface\Insertable\CombinedInsertablesSuggester */
+class CombinedInsertablesSuggesterTest extends MediaWikiUnitTestCase {
+ /** @dataProvider getInsertablesProvider */
+ public function testGetInsertables( $suggesters, $input, $expected ) {
+ $suggester = new CombinedInsertablesSuggester( $suggesters );
+ $this->assertArrayEquals( $expected, $suggester->getInsertables( $input ) );
+ }
+
+ public function getInsertablesProvider() {
+ return [
+ // Test basic combination of multiple InsertablesSuggesters
+ [
+ [
+ new TestingInsertablesSuggester(),
+ new NumericalParameterInsertablesSuggester(),
+ ],
+ 'test $1 foo $2 bar $3spam eggs',
+ [
+ new Insertable( 'Test', 'Test', '' ),
+ new Insertable( '$1', '$1', '' ),
+ new Insertable( '$2', '$2', '' ),
+ new Insertable( '$3', '$3', '' ),
+ ]
+ ],
+ // Test removal of duplicate suggestions
+ [
+ [
+ new NumericalParameterInsertablesSuggester(),
+ new NumericalParameterInsertablesSuggester(),
+ ],
+ 'test $1 duplicates $2 $3',
+ [
+ new Insertable( '$1', '$1', '' ),
+ new Insertable( '$2', '$2', '' ),
+ new Insertable( '$3', '$3', '' ),
+ ]
+ ],
+ // Test removal of duplicate suggestions
+ [
+ [
+ new TestingDuplicateInsertablesSuggester(),
+ new NumericalParameterInsertablesSuggester(),
+ ],
+ 'test $1 duplicates $2 $3',
+ [
+ new Insertable( '$1', '$1', '' ),
+ new Insertable( '$2', '$2', '' ),
+ new Insertable( '$3', '$3', '' ),
+ new Insertable( 'Test', 'Test', '' ),
+ new Insertable( '', 'Test', 'Test' ),
+ ]
+ ],
+ // Test no InsertablesSuggesters
+ [
+ [],
+ 'test $1 duplicates $2 $3',
+ []
+ ],
+ ];
+ }
+}
+
+class TestingInsertablesSuggester implements InsertablesSuggester {
+ public function getInsertables( string $text ): array {
+ return [ new Insertable( 'Test', 'Test', '' ) ];
+ }
+}
+
+class TestingDuplicateInsertablesSuggester implements InsertablesSuggester {
+ public function getInsertables( string $text ): array {
+ return [
+ new Insertable( '$1', '$1', '' ),
+ new Insertable( '$1', '$1', '' ),
+ new Insertable( 'Test', 'Test', '' ),
+ new Insertable( 'Test', 'Test', '' ),
+ new Insertable( '', 'Test', 'Test' ),
+ ];
+ }
+}
diff --git a/MLEB/Translate/tests/phpunit/unit/insertables/HtmlTagInsertablesSuggesterTest.php b/MLEB/Translate/tests/phpunit/unit/TranslatorInterface/Insertable/HtmlTagInsertablesSuggesterTest.php
index ebd1ee8f..fd439254 100644
--- a/MLEB/Translate/tests/phpunit/unit/insertables/HtmlTagInsertablesSuggesterTest.php
+++ b/MLEB/Translate/tests/phpunit/unit/TranslatorInterface/Insertable/HtmlTagInsertablesSuggesterTest.php
@@ -5,13 +5,13 @@
* @license GPL-2.0-or-later
*/
-/**
- * @covers HtmlTagInsertablesSuggester
- */
+namespace MediaWiki\Extension\Translate\TranslatorInterface\Insertable;
+
+use MediaWikiUnitTestCase;
+
+/** @covers \MediaWiki\Extension\Translate\TranslatorInterface\Insertable\HtmlTagInsertablesSuggester */
class HtmlTagInsertablesSuggesterTest extends MediaWikiUnitTestCase {
- /**
- * @dataProvider getTestHtmlTagInsertablesSuggesterProvider
- */
+ /** @dataProvider getTestHtmlTagInsertablesSuggesterProvider */
public function testHtmlTagInsertablesSuggester( $text, $expected, $comment = '' ) {
$suggester = new HtmlTagInsertablesSuggester();
$actual = $suggester->getInsertables( $text );
diff --git a/MLEB/Translate/tests/phpunit/unit/TranslatorInterface/Insertable/InsertableFactoryTest.php b/MLEB/Translate/tests/phpunit/unit/TranslatorInterface/Insertable/InsertableFactoryTest.php
new file mode 100644
index 00000000..7b20fa12
--- /dev/null
+++ b/MLEB/Translate/tests/phpunit/unit/TranslatorInterface/Insertable/InsertableFactoryTest.php
@@ -0,0 +1,56 @@
+<?php
+declare( strict_types = 1 );
+
+namespace MediaWiki\Extension\Translate\TranslatorInterface\Insertable;
+
+use InvalidArgumentException;
+use MediaWikiUnitTestCase;
+use MockTranslateValidator;
+
+/** @covers \MediaWiki\Extension\Translate\TranslatorInterface\Insertable\InsertableFactory */
+class InsertableFactoryTest extends MediaWikiUnitTestCase {
+ /**
+ * @dataProvider getPreProvidedInsertables
+ * @dataProvider getCustomInsertables
+ */
+ public function testValidLoadInstance( string $className, $params = null ) {
+ $instance = InsertableFactory::make( $className, $params );
+ $this->assertInstanceOf(
+ InsertablesSuggester::class,
+ $instance,
+ 'Existing class returns an instance of the InsertableSuggester'
+ );
+ }
+
+ public function testNonExistentInsertable() {
+ $this->expectException( InvalidArgumentException::class );
+ $this->expectExceptionMessageMatches( '/could not find/i' );
+ InsertableFactory::make( 'TranslateNonExistentClass', '' );
+ }
+
+ public function testInvalidInsertable() {
+ $this->expectException( InvalidArgumentException::class );
+ $this->expectExceptionMessageMatches( '/does not implement/i' );
+ InsertableFactory::make( MockTranslateValidator::class, '' );
+ }
+
+ public function getPreprovidedInsertables() {
+ yield [ HtmlTagInsertablesSuggester::class ];
+
+ yield [
+ RegexInsertablesSuggester::class,
+ [ 'regex' => 'abcd' ]
+ ];
+
+ yield [ RegexInsertablesSuggester::class, 'abcd' ];
+
+ yield 'Preprovided insertables without fully qualified namespace' => [
+ // Not using ::class since that would add the fully qualified namespace
+ 'NumericalParameterInsertablesSuggester'
+ ];
+ }
+
+ public function getCustomInsertables() {
+ yield [ \MockCustomInsertableSuggester::class ];
+ }
+}
diff --git a/MLEB/Translate/tests/phpunit/unit/TranslatorInterface/Insertable/MediaWikiInsertablesSuggesterTest.php b/MLEB/Translate/tests/phpunit/unit/TranslatorInterface/Insertable/MediaWikiInsertablesSuggesterTest.php
new file mode 100644
index 00000000..a8e419c3
--- /dev/null
+++ b/MLEB/Translate/tests/phpunit/unit/TranslatorInterface/Insertable/MediaWikiInsertablesSuggesterTest.php
@@ -0,0 +1,38 @@
+<?php
+/**
+ * @file
+ * @author Niklas Laxström
+ * @license GPL-2.0-or-later
+ */
+
+namespace MediaWiki\Extension\Translate\TranslatorInterface\Insertable;
+
+use MediaWikiUnitTestCase;
+
+/** @covers \MediaWiki\Extension\Translate\TranslatorInterface\Insertable\MediaWikiInsertablesSuggester */
+class MediaWikiInsertablesSuggesterTest extends MediaWikiUnitTestCase {
+ /** @dataProvider getInsertablesProvider */
+ public function testGetInsertables( $input, $expected ) {
+ $suggester = new MediaWikiInsertablesSuggester();
+ $this->assertEquals( $expected, $suggester->getInsertables( $input ) );
+ }
+
+ public function getInsertablesProvider() {
+ return [
+ [ 'Hi $1', [
+ new Insertable( '$1', '$1', '' )
+ ] ],
+ [ 'Hello $1user', [
+ new Insertable( '$1user', '$1user', '' ),
+ ] ],
+ [ '{{GENDER:$1|he|she}}', [
+ new Insertable( '$1', '$1', '' ),
+ new Insertable( 'GENDER:$1', '{{GENDER:$1|', '}}' ),
+ ] ],
+ // Parameterless gender
+ [ '{{GENDER:|he|she}}', [
+ new Insertable( 'GENDER:', '{{GENDER:|', '}}' ),
+ ] ],
+ ];
+ }
+}
diff --git a/MLEB/Translate/tests/phpunit/unit/TranslatorInterface/Insertable/NumericalParameterInsertablesSuggesterTest.php b/MLEB/Translate/tests/phpunit/unit/TranslatorInterface/Insertable/NumericalParameterInsertablesSuggesterTest.php
new file mode 100644
index 00000000..a8913585
--- /dev/null
+++ b/MLEB/Translate/tests/phpunit/unit/TranslatorInterface/Insertable/NumericalParameterInsertablesSuggesterTest.php
@@ -0,0 +1,39 @@
+<?php
+/**
+ * @file
+ * @author Geoffrey Mon
+ * @license GPL-2.0-or-later
+ */
+
+namespace MediaWiki\Extension\Translate\TranslatorInterface\Insertable;
+
+use MediaWikiUnitTestCase;
+
+/** @covers \MediaWiki\Extension\Translate\TranslatorInterface\Insertable\NumericalParameterInsertablesSuggester */
+class NumericalParameterInsertablesSuggesterTest extends MediaWikiUnitTestCase {
+ /** @dataProvider getInsertablesProvider */
+ public function testGetInsertables( $input, $expected ) {
+ $suggester = new NumericalParameterInsertablesSuggester();
+ $this->assertEquals( $expected, $suggester->getInsertables( $input ) );
+ }
+
+ public function getInsertablesProvider() {
+ return [
+ [ '$1 $2 $3', [
+ new Insertable( '$1', '$1', '' ),
+ new Insertable( '$2', '$2', '' ),
+ new Insertable( '$3', '$3', '' ),
+ ] ],
+ [ 'test $1 foo $2 bar $3spam eggs', [
+ new Insertable( '$1', '$1', '' ),
+ new Insertable( '$2', '$2', '' ),
+ new Insertable( '$3', '$3', '' ),
+ ] ],
+ [ '$1 or $2, $15!', [
+ new Insertable( '$1', '$1', '' ),
+ new Insertable( '$2', '$2', '' ),
+ new Insertable( '$15', '$15', '' ),
+ ] ],
+ ];
+ }
+}
diff --git a/MLEB/Translate/tests/phpunit/unit/TranslatorInterface/Insertable/RegexInsertablesSuggesterTest.php b/MLEB/Translate/tests/phpunit/unit/TranslatorInterface/Insertable/RegexInsertablesSuggesterTest.php
new file mode 100644
index 00000000..e17be4fd
--- /dev/null
+++ b/MLEB/Translate/tests/phpunit/unit/TranslatorInterface/Insertable/RegexInsertablesSuggesterTest.php
@@ -0,0 +1,70 @@
+<?php
+/**
+ * @file
+ * @author Abijeet Patro
+ * @license GPL-2.0-or-later
+ */
+
+namespace MediaWiki\Extension\Translate\TranslatorInterface\Insertable;
+
+use MediaWikiUnitTestCase;
+
+/** @covers \MediaWiki\Extension\Translate\TranslatorInterface\Insertable\RegexInsertablesSuggester */
+class RegexInsertablesSuggesterTest extends MediaWikiUnitTestCase {
+ /** @dataProvider getTestRegexInsertableProvider */
+ public function testRegexInsertable( $text, $params, $expectedVals ) {
+ $insertablesSuggester = new RegexInsertablesSuggester( $params );
+ $insertables = $insertablesSuggester->getInsertables( $text );
+
+ $this->assertCount( count( $expectedVals ), $insertables,
+ 'should return all the expected insertables.' );
+
+ foreach ( $expectedVals as $i => $values ) {
+ $this->assertEquals( $values['display'], $insertables[$i]->getDisplayText(),
+ 'should return the correct display text.' );
+ $this->assertEquals( $values['pre'], $insertables[$i]->getPreText(),
+ 'should return the correct pre text.' );
+ $this->assertEquals( $values['post'], $insertables[$i]->getPostText(),
+ 'should return the correct post text.' );
+ }
+ }
+
+ public function getTestRegexInsertableProvider() {
+ yield [
+ 'Hello $name! I\'m $myname',
+ [
+ 'regex' => '/\$[a-z0-9]+/'
+ ],
+ [
+ [ 'display' => '$name', 'pre' => '$name', 'post' => '' ],
+ [ 'display' => '$myname', 'pre' => '$myname', 'post' => '' ],
+ ]
+ ];
+
+ yield [
+ '<html> <rocks>',
+ [
+ 'regex' => '/(?<display>\<[a-z]+>)/',
+ 'display' => '$display',
+ ],
+ [
+ [ 'display' => '<html>', 'pre' => '<html>', 'post' => '' ],
+ [ 'display' => '<rocks>', 'pre' => '<rocks>', 'post' => '' ]
+ ]
+ ];
+
+ yield [
+ '[Hello]($1) [World]($2)',
+ [
+ 'regex' => '/(?<pre>\[)[^]]+(?<post>\]\([^)]+\))/',
+ 'display' => '$pre$post',
+ 'pre' => '$pre',
+ 'post' => '$post'
+ ],
+ [
+ [ 'display' => '[]($1)', 'pre' => '[', 'post' => ']($1)' ],
+ [ 'display' => '[]($2)', 'pre' => '[', 'post' => ']($2)' ]
+ ]
+ ];
+ }
+}
diff --git a/MLEB/Translate/tests/phpunit/unit/TtmServer/TtmServerFactoryTest.php b/MLEB/Translate/tests/phpunit/unit/TtmServer/TtmServerFactoryTest.php
new file mode 100644
index 00000000..4bcdf8e4
--- /dev/null
+++ b/MLEB/Translate/tests/phpunit/unit/TtmServer/TtmServerFactoryTest.php
@@ -0,0 +1,59 @@
+<?php
+declare( strict_types = 1 );
+
+namespace MediaWiki\Extension\Translate\TtmServer;
+
+use DatabaseTTMServer;
+use MediaWikiUnitTestCase;
+
+/**
+ * @since 2021.01
+ * @license GPL-2.0-or-later
+ * @author Niklas Laxström
+ * @covers \MediaWiki\Extension\Translate\TtmServer\TtmServerFactory
+ */
+class TtmServerFactoryTest extends MediaWikiUnitTestCase {
+ public function testGetNames() {
+ $factory = new TtmServerFactory( [ 'one' => [], 'two' => [] ] );
+ $actual = $factory->getNames();
+ $this->assertArrayEquals( [ 'one', 'two' ], $actual );
+ }
+
+ public function testHas() {
+ $factory = new TtmServerFactory( [ 'exists' => [] ], 'exists' );
+ $this->assertFalse( $factory->has( 'unknown' ) );
+ $this->assertTrue( $factory->has( 'exists' ) );
+ }
+
+ public function testCreate() {
+ $name = '1';
+ $factory = new TtmServerFactory(
+ [
+ $name => [
+ 'database' => false,
+ // Passed to wfGetDB
+ 'cutoff' => 0.75,
+ 'type' => 'ttmserver',
+ 'public' => false,
+ ],
+ ],
+ $name
+ );
+
+ $actual = $factory->create( $name );
+ $this->assertInstanceOf( DatabaseTTMServer::class, $actual );
+ }
+
+ /** @dataProvider provideCreateFailure */
+ public function testCreateFailure( array $input ) {
+ $factory = new TtmServerFactory( $input );
+ $this->expectException( ServiceCreationFailure::class );
+ $factory->create( '' );
+ }
+
+ public function provideCreateFailure() {
+ yield 'unknown' => [ [] ];
+ yield 'malformed' => [ [ '' => 'gibberish' ] ];
+ yield 'incomplete config' => [ [ '' => [ 'someoption' => 'somevalue' ] ] ];
+ }
+}
diff --git a/MLEB/Translate/tests/phpunit/unit/Utilities/GettextPluralTest.php b/MLEB/Translate/tests/phpunit/unit/Utilities/GettextPluralTest.php
index b2e1db28..bf4f727e 100644
--- a/MLEB/Translate/tests/phpunit/unit/Utilities/GettextPluralTest.php
+++ b/MLEB/Translate/tests/phpunit/unit/Utilities/GettextPluralTest.php
@@ -4,15 +4,11 @@
* @license GPL-2.0-or-later
*/
-use MediaWiki\Extensions\Translate\Utilities\GettextPlural;
+use MediaWiki\Extension\Translate\Utilities\GettextPlural;
-/**
- * @coversDefaultClass \MediaWiki\Extensions\Translate\Utilities\GettextPlural
- */
+/** @coversDefaultClass \MediaWiki\Extension\Translate\Utilities\GettextPlural */
class GettextPluralTest extends MediaWikiUnitTestCase {
- /**
- * @covers ::getPluralRule
- */
+ /** @covers ::getPluralRule */
public function testGetPluralRule() {
$expected = 'nplurals=2; plural=(n != 1);';
$actual = GettextPlural::getPluralRule( 'en' );
diff --git a/MLEB/Translate/tests/phpunit/unit/Utilities/JsonCodecTest.php b/MLEB/Translate/tests/phpunit/unit/Utilities/JsonCodecTest.php
new file mode 100644
index 00000000..9dc60874
--- /dev/null
+++ b/MLEB/Translate/tests/phpunit/unit/Utilities/JsonCodecTest.php
@@ -0,0 +1,129 @@
+<?php
+declare( strict_types = 1 );
+
+namespace MediaWiki\Extension\Translate\Utilities\Json;
+
+use InvalidArgumentException;
+use JsonSerializable;
+use MediaWikiUnitTestCase;
+use MockJsonUnserializableSubClass;
+use MockJsonUnserializableSuperClass;
+use stdClass;
+use Wikimedia\Assert\PreconditionException;
+
+/**
+ * Remove once we need to support only MW >= 1.36
+ * See Change-Id: I5433090ae8e2b3f2a4590cc404baf838025546ce
+ *
+ * @covers \MediaWiki\Extension\Translate\Utilities\Json\JsonCodec
+ * @covers \MediaWiki\Extension\Translate\Utilities\Json\JsonUnserializableTrait
+ */
+class JsonCodecTest extends MediaWikiUnitTestCase {
+
+ private function getCodec(): JsonCodec {
+ return new JsonCodec();
+ }
+
+ public function provideSimpleTypes() {
+ yield 'Integer' => [ 1, json_encode( 1 ) ];
+ yield 'Boolean' => [ true, json_encode( true ) ];
+ yield 'Null' => [ null, json_encode( null ) ];
+ yield 'Array' => [ [ 1, 2, 3 ], json_encode( [ 1, 2, 3 ] ) ];
+ yield 'Assoc array' => [ [ 'a' => 'b' ], json_encode( [ 'a' => 'b' ] ) ];
+ $object = new stdClass();
+ $object->c = 'd';
+ yield 'Object' => [ (array)$object, json_encode( $object ) ];
+ }
+
+ /**
+ * @dataProvider provideSimpleTypes
+ * @param mixed $value
+ */
+ public function testSimpleTypesUnserialize( $value, string $serialization ) {
+ $this->assertSame( $value, $this->getCodec()->unserialize( $serialization ) );
+ }
+
+ public function testInvalidJsonDataForClassExpectation() {
+ $this->expectException( InvalidArgumentException::class );
+ $this->getCodec()->unserialize( 'bad string', MockJsonUnserializableSuperClass::class );
+ }
+
+ public function testExpectedClassMustBeUnserializable() {
+ $this->expectException( PreconditionException::class );
+ $this->getCodec()->unserialize( '{}', self::class );
+ }
+
+ public function testUnexpectedClassUnserialized() {
+ $this->expectException( InvalidArgumentException::class );
+ $superClassInstance = new MockJsonUnserializableSuperClass( 'Godzilla' );
+ $this->getCodec()->unserialize(
+ $superClassInstance->jsonSerialize(),
+ MockJsonUnserializableSubClass::class
+ );
+ }
+
+ public function testExpectedClassUnserialized() {
+ $subClassInstance = new MockJsonUnserializableSubClass( 'Godzilla', 'But we are ready!' );
+ $this->assertNotNull( $this->getCodec()->unserialize(
+ $subClassInstance->jsonSerialize(),
+ MockJsonUnserializableSuperClass::class
+ ) );
+ $this->assertNotNull( $this->getCodec()->unserialize(
+ $subClassInstance->jsonSerialize(),
+ MockJsonUnserializableSubClass::class
+ ) );
+ }
+
+ public function testRoundTripSuperClass() {
+ $superClassInstance = new MockJsonUnserializableSuperClass( 'Super Value' );
+ $json = $superClassInstance->jsonSerialize();
+ $superClassUnserialized = $this->getCodec()->unserialize( $json );
+ $this->assertInstanceOf( MockJsonUnserializableSuperClass::class, $superClassInstance );
+ $this->assertSame( $superClassInstance->getSuperClassField(), $superClassUnserialized->getSuperClassField() );
+ }
+
+ public function testRoundTripSubClass() {
+ $subClassInstance = new MockJsonUnserializableSubClass( 'Super Value', 'Sub Value' );
+ $json = $subClassInstance->jsonSerialize();
+ $superClassUnserialized = $this->getCodec()->unserialize( $json );
+ $this->assertInstanceOf( MockJsonUnserializableSubClass::class, $subClassInstance );
+ $this->assertSame( $subClassInstance->getSuperClassField(), $superClassUnserialized->getSuperClassField() );
+ $this->assertSame( $subClassInstance->getSubClassField(), $superClassUnserialized->getSubClassField() );
+ }
+
+ public function provideSerializeThrowsOnFailure() {
+ yield 'crash in serialization, gzipped data' => [
+ "\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\x03\xcb\x48\xcd\xc9\xc9\x57\x28\xcf\x2f'
+ . '\xca\x49\x01\x00\x85\x11\x4a\x0d\x0b\x00\x00\x00"
+ ];
+ }
+
+ /**
+ * @dataProvider provideSerializeThrowsOnFailure
+ * @covers \MediaWiki\Extension\Translate\Utilities\Json\JsonCodec::serialize
+ * @param mixed $value
+ */
+ public function testSerializeThrowsOnFailure( $value ) {
+ $this->expectException( InvalidArgumentException::class );
+ $this->getCodec()->serialize( $value );
+ }
+
+ public function provideSerializeSuccess() {
+ $serializableInstance = new class() implements JsonSerializable {
+ public function jsonSerialize() {
+ return json_encode( [ 'c' => 'd' ] );
+ }
+ };
+ yield 'array' => [ [ 'a' => 'b' ], '{"a":"b"}' ];
+ yield 'JsonSerializable' => [ $serializableInstance, '{"c":"d"}' ];
+ }
+
+ /**
+ * @dataProvider provideSerializeSuccess
+ * @covers \MediaWiki\Extension\Translate\Utilities\Json\JsonCodec::serialize
+ * @param mixed $value
+ */
+ public function testSerializeSuccess( $value, string $expected ) {
+ $this->assertSame( $expected, $this->getCodec()->serialize( $value ) );
+ }
+}
diff --git a/MLEB/Translate/tests/phpunit/unit/Utilities/ParsingPlaceholderFactoryTest.php b/MLEB/Translate/tests/phpunit/unit/Utilities/ParsingPlaceholderFactoryTest.php
index 9fd16330..76a719b0 100644
--- a/MLEB/Translate/tests/phpunit/unit/Utilities/ParsingPlaceholderFactoryTest.php
+++ b/MLEB/Translate/tests/phpunit/unit/Utilities/ParsingPlaceholderFactoryTest.php
@@ -1,12 +1,12 @@
<?php
declare( strict_types = 1 );
-use MediaWiki\Extensions\Translate\Utilities\ParsingPlaceholderFactory;
+use MediaWiki\Extension\Translate\Utilities\ParsingPlaceholderFactory;
/**
* @author Niklas Laxström
* @license GPL-2.0-or-later
- * @covers \MediaWiki\Extensions\Translate\Utilities\ParsingPlaceholderFactory
+ * @covers \MediaWiki\Extension\Translate\Utilities\ParsingPlaceholderFactory
*/
class ParsingPlaceholderFactoryTest extends MediaWikiUnitTestCase {
public function testMake() {
diff --git a/MLEB/Translate/tests/phpunit/unit/Utilities/SmartFormatPluralTest.php b/MLEB/Translate/tests/phpunit/unit/Utilities/SmartFormatPluralTest.php
index 488279a5..9ed3a8ed 100644
--- a/MLEB/Translate/tests/phpunit/unit/Utilities/SmartFormatPluralTest.php
+++ b/MLEB/Translate/tests/phpunit/unit/Utilities/SmartFormatPluralTest.php
@@ -4,15 +4,11 @@
* @license GPL-2.0-or-later
*/
-use MediaWiki\Extensions\Translate\Utilities\SmartFormatPlural;
+use MediaWiki\Extension\Translate\Utilities\SmartFormatPlural;
-/**
- * @covers \MediaWiki\Extensions\Translate\Utilities\SmartFormatPlural
- */
+/** @covers \MediaWiki\Extension\Translate\Utilities\SmartFormatPlural */
class SmartFormatPluralTest extends MediaWikiUnitTestCase {
- /**
- * @dataProvider provideTestGetPluralInstances
- */
+ /** @dataProvider provideTestGetPluralInstances */
public function testGetPluralInstances( $input, $expected ) {
$actual = SmartFormatPlural::getPluralInstances( $input );
$this->assertEquals( $expected, $actual );
diff --git a/MLEB/Translate/tests/phpunit/unit/Utilities/UnicodePluralTest.php b/MLEB/Translate/tests/phpunit/unit/Utilities/UnicodePluralTest.php
index a98af4fe..a7f4498d 100644
--- a/MLEB/Translate/tests/phpunit/unit/Utilities/UnicodePluralTest.php
+++ b/MLEB/Translate/tests/phpunit/unit/Utilities/UnicodePluralTest.php
@@ -4,15 +4,11 @@
* @license GPL-2.0-or-later
*/
-use MediaWiki\Extensions\Translate\Utilities\UnicodePlural;
+use MediaWiki\Extension\Translate\Utilities\UnicodePlural;
-/**
- * @coversDefaultClass \MediaWiki\Extensions\Translate\Utilities\UnicodePlural
- */
+/** @coversDefaultClass \MediaWiki\Extension\Translate\Utilities\UnicodePlural */
class UnicodePluralTest extends MediaWikiUnitTestCase {
- /**
- * @covers ::getPluralKeywords
- */
+ /** @covers ::getPluralKeywords */
public function testGetPluralKeywords() {
$expected = [ 'one', 'other' ];
$actual = UnicodePlural::getPluralKeywords( 'en' );
diff --git a/MLEB/Translate/tests/phpunit/unit/MessageValidator/Validators/BaseValidatorTestCase.php b/MLEB/Translate/tests/phpunit/unit/Validation/Validators/BaseValidatorTestCase.php
index 9932ffc2..46d8ec60 100644
--- a/MLEB/Translate/tests/phpunit/unit/MessageValidator/Validators/BaseValidatorTestCase.php
+++ b/MLEB/Translate/tests/phpunit/unit/Validation/Validators/BaseValidatorTestCase.php
@@ -1,11 +1,12 @@
<?php
declare( strict_types = 1 );
-use MediaWiki\Extensions\Translate\Validation\MessageValidator;
-use MediaWiki\Extensions\Translate\Validation\ValidationIssue;
-use MediaWiki\Extensions\Translate\Validation\ValidationIssues;
+use MediaWiki\Extension\Translate\Validation\MessageValidator;
+use MediaWiki\Extension\Translate\Validation\ValidationIssue;
+use MediaWiki\Extension\Translate\Validation\ValidationIssues;
/**
+ * Base class for translation validator tests
* @license GPL-2.0-or-later
*/
class BaseValidatorTestCase extends MediaWikiUnitTestCase {
diff --git a/MLEB/Translate/tests/phpunit/unit/MessageValidator/Validators/BraceBalanceValidatorTest.php b/MLEB/Translate/tests/phpunit/unit/Validation/Validators/BraceBalanceValidatorTest.php
index 477ff075..2e0f6dcc 100644
--- a/MLEB/Translate/tests/phpunit/unit/MessageValidator/Validators/BraceBalanceValidatorTest.php
+++ b/MLEB/Translate/tests/phpunit/unit/Validation/Validators/BraceBalanceValidatorTest.php
@@ -1,11 +1,11 @@
<?php
declare( strict_types = 1 );
-use MediaWiki\Extensions\Translate\MessageValidator\Validators\BraceBalanceValidator;
+use MediaWiki\Extension\Translate\Validation\Validators\BraceBalanceValidator;
/**
* @license GPL-2.0-or-later
- * @covers \MediaWiki\Extensions\Translate\MessageValidator\Validators\BraceBalanceValidator
+ * @covers \MediaWiki\Extension\Translate\Validation\Validators\BraceBalanceValidator
*/
class BraceBalanceValidatorTest extends BaseValidatorTestCase {
/** @dataProvider provideTestCases */
diff --git a/MLEB/Translate/tests/phpunit/unit/MessageValidator/Validators/EscapeCharacterValidatorTest.php b/MLEB/Translate/tests/phpunit/unit/Validation/Validators/EscapeCharacterValidatorTest.php
index 25661253..f1744827 100644
--- a/MLEB/Translate/tests/phpunit/unit/MessageValidator/Validators/EscapeCharacterValidatorTest.php
+++ b/MLEB/Translate/tests/phpunit/unit/Validation/Validators/EscapeCharacterValidatorTest.php
@@ -1,11 +1,11 @@
<?php
declare( strict_types = 1 );
-use MediaWiki\Extensions\Translate\MessageValidator\Validators\EscapeCharacterValidator;
+use MediaWiki\Extension\Translate\Validation\Validators\EscapeCharacterValidator;
/**
* @license GPL-2.0-or-later
- * @covers \MediaWiki\Extensions\Translate\MessageValidator\Validators\EscapeCharacterValidator
+ * @covers \MediaWiki\Extension\Translate\Validation\Validators\EscapeCharacterValidator
*/
class EscapeCharacterValidatorTest extends BaseValidatorTestCase {
/** @dataProvider provideTestCases */
diff --git a/MLEB/Translate/tests/phpunit/unit/MessageValidator/Validators/GettextNewlineValidatorTest.php b/MLEB/Translate/tests/phpunit/unit/Validation/Validators/GettextNewlineValidatorTest.php
index 3dade6a3..e2828f1b 100644
--- a/MLEB/Translate/tests/phpunit/unit/MessageValidator/Validators/GettextNewlineValidatorTest.php
+++ b/MLEB/Translate/tests/phpunit/unit/Validation/Validators/GettextNewlineValidatorTest.php
@@ -1,11 +1,11 @@
<?php
declare( strict_types = 1 );
-use MediaWiki\Extensions\Translate\MessageValidator\Validators\GettextNewlineValidator;
+use MediaWiki\Extension\Translate\Validation\Validators\GettextNewlineValidator;
/**
* @license GPL-2.0-or-later
- * @covers \MediaWiki\Extensions\Translate\MessageValidator\Validators\GettextNewlineValidator
+ * @covers \MediaWiki\Extension\Translate\Validation\Validators\GettextNewlineValidator
*/
class GettextNewlineValidatorTest extends BaseValidatorTestCase {
/** @dataProvider provideTestCases */
diff --git a/MLEB/Translate/tests/phpunit/unit/MessageValidator/Validators/GettextPluralValidatorTest.php b/MLEB/Translate/tests/phpunit/unit/Validation/Validators/GettextPluralValidatorTest.php
index da81da39..a3e6dc83 100644
--- a/MLEB/Translate/tests/phpunit/unit/MessageValidator/Validators/GettextPluralValidatorTest.php
+++ b/MLEB/Translate/tests/phpunit/unit/Validation/Validators/GettextPluralValidatorTest.php
@@ -1,12 +1,12 @@
<?php
declare( strict_types = 1 );
-use MediaWiki\Extensions\Translate\MessageValidator\Validators\GettextPluralValidator;
+use MediaWiki\Extension\Translate\Validation\Validators\GettextPluralValidator;
/**
* @author Niklas Laxström
* @license GPL-2.0-or-later
- * @covers \MediaWiki\Extensions\Translate\MessageValidator\Validators\GettextPluralValidator
+ * @covers \MediaWiki\Extension\Translate\Validation\Validators\GettextPluralValidator
*/
class GettextPluralValidatorTest extends BaseValidatorTestCase {
/** @dataProvider provideTestCases */
diff --git a/MLEB/Translate/tests/phpunit/unit/MessageValidator/Validators/InsertableRegexValidatorTest.php b/MLEB/Translate/tests/phpunit/unit/Validation/Validators/InsertableRegexValidatorTest.php
index 219379ee..dc008579 100644
--- a/MLEB/Translate/tests/phpunit/unit/MessageValidator/Validators/InsertableRegexValidatorTest.php
+++ b/MLEB/Translate/tests/phpunit/unit/Validation/Validators/InsertableRegexValidatorTest.php
@@ -1,11 +1,11 @@
<?php
declare( strict_types = 1 );
-use MediaWiki\Extensions\Translate\MessageValidator\Validators\InsertableRegexValidator;
+use MediaWiki\Extension\Translate\Validation\Validators\InsertableRegexValidator;
/**
* @license GPL-2.0-or-later
- * @covers \MediaWiki\Extensions\Translate\MessageValidator\Validators\InsertableRegexValidator
+ * @covers \MediaWiki\Extension\Translate\Validation\Validators\InsertableRegexValidator
*/
class InsertableRegexValidatorTest extends BaseValidatorTestCase {
/** @dataProvider provideTestCases */
diff --git a/MLEB/Translate/tests/phpunit/unit/MessageValidator/Validators/InsertableRubyVariableValidatorTest.php b/MLEB/Translate/tests/phpunit/unit/Validation/Validators/InsertableRubyVariableValidatorTest.php
index 3b4c3e3b..af67dfac 100644
--- a/MLEB/Translate/tests/phpunit/unit/MessageValidator/Validators/InsertableRubyVariableValidatorTest.php
+++ b/MLEB/Translate/tests/phpunit/unit/Validation/Validators/InsertableRubyVariableValidatorTest.php
@@ -1,11 +1,11 @@
<?php
declare( strict_types = 1 );
-use MediaWiki\Extensions\Translate\MessageValidator\Validators\InsertableRubyVariableValidator;
+use MediaWiki\Extension\Translate\Validation\Validators\InsertableRubyVariableValidator;
/**
* @license GPL-2.0-or-later
- * @covers \MediaWiki\Extensions\Translate\MessageValidator\Validators\InsertableRubyVariableValidator
+ * @covers \MediaWiki\Extension\Translate\Validation\Validators\InsertableRubyVariableValidator
*/
class InsertableRubyValidatorTest extends BaseValidatorTestCase {
/** @dataProvider provideTestCases */
diff --git a/MLEB/Translate/tests/phpunit/unit/MessageValidator/Validators/IosVariableValidatorTest.php b/MLEB/Translate/tests/phpunit/unit/Validation/Validators/IosVariableValidatorTest.php
index 9a2de037..e7a0e1db 100644
--- a/MLEB/Translate/tests/phpunit/unit/MessageValidator/Validators/IosVariableValidatorTest.php
+++ b/MLEB/Translate/tests/phpunit/unit/Validation/Validators/IosVariableValidatorTest.php
@@ -1,11 +1,11 @@
<?php
declare( strict_types = 1 );
-use MediaWiki\Extensions\Translate\MessageValidator\Validators\IosVariableValidator;
+use MediaWiki\Extension\Translate\Validation\Validators\IosVariableValidator;
/**
* @license GPL-2.0-or-later
- * @covers \MediaWiki\Extensions\Translate\MessageValidator\Validators\IosVariableValidator
+ * @covers \MediaWiki\Extension\Translate\Validation\Validators\IosVariableValidator
*/
class IosVariableValidatorTest extends BaseValidatorTestCase {
/** @dataProvider provideTestCases */
diff --git a/MLEB/Translate/tests/phpunit/unit/MessageValidator/Validators/MatchSetValidatorTest.php b/MLEB/Translate/tests/phpunit/unit/Validation/Validators/MatchSetValidatorTest.php
index 3c0ebcd8..9ca10165 100644
--- a/MLEB/Translate/tests/phpunit/unit/MessageValidator/Validators/MatchSetValidatorTest.php
+++ b/MLEB/Translate/tests/phpunit/unit/Validation/Validators/MatchSetValidatorTest.php
@@ -1,11 +1,11 @@
<?php
declare( strict_types = 1 );
-use MediaWiki\Extensions\Translate\MessageValidator\Validators\MatchSetValidator;
+use MediaWiki\Extension\Translate\Validation\Validators\MatchSetValidator;
/**
* @license GPL-2.0-or-later
- * @covers \MediaWiki\Extensions\Translate\MessageValidator\Validators\MatchSetValidator
+ * @covers \MediaWiki\Extension\Translate\Validation\Validators\MatchSetValidator
*/
class MatchSetValidatorTest extends BaseValidatorTestCase {
/** @dataProvider provideTestCases */
diff --git a/MLEB/Translate/tests/phpunit/unit/MessageValidator/Validators/MediaWikiLinkValidatorTest.php b/MLEB/Translate/tests/phpunit/unit/Validation/Validators/MediaWikiLinkValidatorTest.php
index 2cbf17c0..eaaa1155 100644
--- a/MLEB/Translate/tests/phpunit/unit/MessageValidator/Validators/MediaWikiLinkValidatorTest.php
+++ b/MLEB/Translate/tests/phpunit/unit/Validation/Validators/MediaWikiLinkValidatorTest.php
@@ -1,11 +1,11 @@
<?php
declare( strict_types = 1 );
-use MediaWiki\Extensions\Translate\MessageValidator\Validators\MediaWikiLinkValidator;
+use MediaWiki\Extension\Translate\Validation\Validators\MediaWikiLinkValidator;
/**
* @license GPL-2.0-or-later
- * @covers \MediaWiki\Extensions\Translate\MessageValidator\Validators\MediaWikiLinkValidator
+ * @covers \MediaWiki\Extension\Translate\Validation\Validators\MediaWikiLinkValidator
*/
class MediaWikiLinkValidatorTest extends BaseValidatorTestCase {
/** @dataProvider provideTestCases */
diff --git a/MLEB/Translate/tests/phpunit/unit/MessageValidator/Validators/MediaWikiPageNameValidatorTest.php b/MLEB/Translate/tests/phpunit/unit/Validation/Validators/MediaWikiPageNameValidatorTest.php
index a024b398..fbc47ed5 100644
--- a/MLEB/Translate/tests/phpunit/unit/MessageValidator/Validators/MediaWikiPageNameValidatorTest.php
+++ b/MLEB/Translate/tests/phpunit/unit/Validation/Validators/MediaWikiPageNameValidatorTest.php
@@ -1,11 +1,11 @@
<?php
declare( strict_types = 1 );
-use MediaWiki\Extensions\Translate\MessageValidator\Validators\MediaWikiPageNameValidator;
+use MediaWiki\Extension\Translate\Validation\Validators\MediaWikiPageNameValidator;
/**
* @license GPL-2.0-or-later
- * @covers \MediaWiki\Extensions\Translate\MessageValidator\Validators\MediaWikiPageNameValidator
+ * @covers \MediaWiki\Extension\Translate\Validation\Validators\MediaWikiPageNameValidator
*/
class MediaWikiPageNameValidatorTest extends BaseValidatorTestCase {
/** @dataProvider provideTestCases */
diff --git a/MLEB/Translate/tests/phpunit/unit/MessageValidator/Validators/MediaWikiParameterValidatorTest.php b/MLEB/Translate/tests/phpunit/unit/Validation/Validators/MediaWikiParameterValidatorTest.php
index 2e824779..f2ba8d86 100644
--- a/MLEB/Translate/tests/phpunit/unit/MessageValidator/Validators/MediaWikiParameterValidatorTest.php
+++ b/MLEB/Translate/tests/phpunit/unit/Validation/Validators/MediaWikiParameterValidatorTest.php
@@ -1,11 +1,11 @@
<?php
declare( strict_types = 1 );
-use MediaWiki\Extensions\Translate\MessageValidator\Validators\MediaWikiParameterValidator;
+use MediaWiki\Extension\Translate\Validation\Validators\MediaWikiParameterValidator;
/**
* @license GPL-2.0-or-later
- * @covers \MediaWiki\Extensions\Translate\MessageValidator\Validators\MediaWikiParameterValidator
+ * @covers \MediaWiki\Extension\Translate\Validation\Validators\MediaWikiParameterValidator
*/
class MediaWikiParameterValidatorTest extends BaseValidatorTestCase {
/** @dataProvider provideTestCases */
diff --git a/MLEB/Translate/tests/phpunit/unit/MessageValidator/Validators/MediaWikiTimeListValidatorTest.php b/MLEB/Translate/tests/phpunit/unit/Validation/Validators/MediaWikiTimeListValidatorTest.php
index 98097733..127274c7 100644
--- a/MLEB/Translate/tests/phpunit/unit/MessageValidator/Validators/MediaWikiTimeListValidatorTest.php
+++ b/MLEB/Translate/tests/phpunit/unit/Validation/Validators/MediaWikiTimeListValidatorTest.php
@@ -1,12 +1,12 @@
<?php
declare( strict_types = 1 );
-use MediaWiki\Extensions\Translate\MessageValidator\Validators\MediaWikiTimeListValidator;
+use MediaWiki\Extension\Translate\Validation\Validators\MediaWikiTimeListValidator;
/**
* @author Niklas Laxström
* @license GPL-2.0-or-later
- * @covers \MediaWiki\Extensions\Translate\MessageValidator\Validators\MediaWikiTimeListValidator
+ * @covers \MediaWiki\Extension\Translate\Validation\Validators\MediaWikiTimeListValidator
*/
class MediaWikiTimeListValidatorTest extends BaseValidatorTestCase {
/** @dataProvider provideTestCases */
diff --git a/MLEB/Translate/tests/phpunit/unit/MessageValidator/Validators/NewlineValidatorTest.php b/MLEB/Translate/tests/phpunit/unit/Validation/Validators/NewlineValidatorTest.php
index 14853688..6e310f50 100644
--- a/MLEB/Translate/tests/phpunit/unit/MessageValidator/Validators/NewlineValidatorTest.php
+++ b/MLEB/Translate/tests/phpunit/unit/Validation/Validators/NewlineValidatorTest.php
@@ -1,11 +1,11 @@
<?php
declare( strict_types = 1 );
-use MediaWiki\Extensions\Translate\MessageValidator\Validators\NewlineValidator;
+use MediaWiki\Extension\Translate\Validation\Validators\NewlineValidator;
/**
* @license GPL-2.0-or-later
- * @covers \MediaWiki\Extensions\Translate\MessageValidator\Validators\NewlineValidator
+ * @covers \MediaWiki\Extension\Translate\Validation\Validators\NewlineValidator
*/
class NewlineValidatorTest extends BaseValidatorTestCase {
/** @dataProvider provideTestCases */
diff --git a/MLEB/Translate/tests/phpunit/unit/MessageValidator/Validators/NumericalParameterValidatorTest.php b/MLEB/Translate/tests/phpunit/unit/Validation/Validators/NumericalParameterValidatorTest.php
index 5d900b4f..c4665c8c 100644
--- a/MLEB/Translate/tests/phpunit/unit/MessageValidator/Validators/NumericalParameterValidatorTest.php
+++ b/MLEB/Translate/tests/phpunit/unit/Validation/Validators/NumericalParameterValidatorTest.php
@@ -1,11 +1,11 @@
<?php
declare( strict_types = 1 );
-use MediaWiki\Extensions\Translate\MessageValidator\Validators\NumericalParameterValidator;
+use MediaWiki\Extension\Translate\Validation\Validators\NumericalParameterValidator;
/**
* @license GPL-2.0-or-later
- * @covers \MediaWiki\Extensions\Translate\MessageValidator\Validators\NumericalParameterValidator
+ * @covers \MediaWiki\Extension\Translate\Validation\Validators\NumericalParameterValidator
*/
class NumericalParameterValidatorTest extends BaseValidatorTestCase {
/** @dataProvider provideTestCases */
diff --git a/MLEB/Translate/tests/phpunit/unit/MessageValidator/Validators/PrintfValidatorTest.php b/MLEB/Translate/tests/phpunit/unit/Validation/Validators/PrintfValidatorTest.php
index 6ea13a10..666d7bfd 100644
--- a/MLEB/Translate/tests/phpunit/unit/MessageValidator/Validators/PrintfValidatorTest.php
+++ b/MLEB/Translate/tests/phpunit/unit/Validation/Validators/PrintfValidatorTest.php
@@ -1,11 +1,11 @@
<?php
declare( strict_types = 1 );
-use MediaWiki\Extensions\Translate\MessageValidator\Validators\PrintfValidator;
+use MediaWiki\Extension\Translate\Validation\Validators\PrintfValidator;
/**
* @license GPL-2.0-or-later
- * @covers \MediaWiki\Extensions\Translate\MessageValidator\Validators\PrintfValidator
+ * @covers \MediaWiki\Extension\Translate\Validation\Validators\PrintfValidator
*/
class PrintfValidatorTest extends BaseValidatorTestCase {
/** @dataProvider provideTestCases */
diff --git a/MLEB/Translate/tests/phpunit/unit/MessageValidator/Validators/PythonInterpolationValidatorTest.php b/MLEB/Translate/tests/phpunit/unit/Validation/Validators/PythonInterpolationValidatorTest.php
index 709adb8f..456b2b51 100644
--- a/MLEB/Translate/tests/phpunit/unit/MessageValidator/Validators/PythonInterpolationValidatorTest.php
+++ b/MLEB/Translate/tests/phpunit/unit/Validation/Validators/PythonInterpolationValidatorTest.php
@@ -1,11 +1,11 @@
<?php
declare( strict_types = 1 );
-use MediaWiki\Extensions\Translate\MessageValidator\Validators\PythonInterpolationValidator;
+use MediaWiki\Extension\Translate\Validation\Validators\PythonInterpolationValidator;
/**
* @license GPL-2.0-or-later
- * @covers \MediaWiki\Extensions\Translate\MessageValidator\Validators\PythonInterpolationValidator
+ * @covers \MediaWiki\Extension\Translate\Validation\Validators\PythonInterpolationValidator
*/
class PythonInterpolationValidatorTest extends BaseValidatorTestCase {
/** @dataProvider provideTestCases */
diff --git a/MLEB/Translate/tests/phpunit/unit/MessageValidator/Validators/ReplacementValidatorTest.php b/MLEB/Translate/tests/phpunit/unit/Validation/Validators/ReplacementValidatorTest.php
index 44c2a5e7..31cf88a1 100644
--- a/MLEB/Translate/tests/phpunit/unit/MessageValidator/Validators/ReplacementValidatorTest.php
+++ b/MLEB/Translate/tests/phpunit/unit/Validation/Validators/ReplacementValidatorTest.php
@@ -1,12 +1,12 @@
<?php
declare( strict_types = 1 );
-use MediaWiki\Extensions\Translate\MessageValidator\Validators\ReplacementValidator;
+use MediaWiki\Extension\Translate\Validation\Validators\ReplacementValidator;
/**
* @author Niklas Laxström
* @license GPL-2.0-or-later
- * @covers \MediaWiki\Extensions\Translate\MessageValidator\Validators\ReplacementValidator
+ * @covers \MediaWiki\Extension\Translate\Validation\Validators\ReplacementValidator
*/
class ReplacementValidatorTest extends BaseValidatorTestCase {
/** @dataProvider provideTestCases */
diff --git a/MLEB/Translate/tests/phpunit/unit/MessageValidator/Validators/SmartFormatPluralValidatorTest.php b/MLEB/Translate/tests/phpunit/unit/Validation/Validators/SmartFormatPluralValidatorTest.php
index 8c2d233e..5303fef2 100644
--- a/MLEB/Translate/tests/phpunit/unit/MessageValidator/Validators/SmartFormatPluralValidatorTest.php
+++ b/MLEB/Translate/tests/phpunit/unit/Validation/Validators/SmartFormatPluralValidatorTest.php
@@ -1,11 +1,11 @@
<?php
declare( strict_types = 1 );
-use MediaWiki\Extensions\Translate\MessageValidator\Validators\SmartFormatPluralValidator;
+use MediaWiki\Extension\Translate\Validation\Validators\SmartFormatPluralValidator;
/**
* @license GPL-2.0-or-later
- * @covers \MediaWiki\Extensions\Translate\MessageValidator\Validators\SmartFormatPluralValidator
+ * @covers \MediaWiki\Extension\Translate\Validation\Validators\SmartFormatPluralValidator
*/
class SmartFormatPluralValidatorTest extends BaseValidatorTestCase {
/** @dataProvider provideTestCases */
diff --git a/MLEB/Translate/tests/phpunit/unit/MessageValidator/Validators/UnicodePluralValidatorTest.php b/MLEB/Translate/tests/phpunit/unit/Validation/Validators/UnicodePluralValidatorTest.php
index 1bd86f2f..df9a7604 100644
--- a/MLEB/Translate/tests/phpunit/unit/MessageValidator/Validators/UnicodePluralValidatorTest.php
+++ b/MLEB/Translate/tests/phpunit/unit/Validation/Validators/UnicodePluralValidatorTest.php
@@ -1,11 +1,11 @@
<?php
declare( strict_types = 1 );
-use MediaWiki\Extensions\Translate\MessageValidator\Validators\UnicodePluralValidator;
+use MediaWiki\Extension\Translate\Validation\Validators\UnicodePluralValidator;
/**
* @license GPL-2.0-or-later
- * @covers \MediaWiki\Extensions\Translate\MessageValidator\Validators\UnicodePluralValidator
+ * @covers \MediaWiki\Extension\Translate\Validation\Validators\UnicodePluralValidator
*/
class UnicodePluralValidatorTest extends BaseValidatorTestCase {
/** @dataProvider provideTestCases */
diff --git a/MLEB/Translate/tests/phpunit/unit/tag/TPParseTest.php b/MLEB/Translate/tests/phpunit/unit/tag/TPParseTest.php
deleted file mode 100644
index 1228d58a..00000000
--- a/MLEB/Translate/tests/phpunit/unit/tag/TPParseTest.php
+++ /dev/null
@@ -1,194 +0,0 @@
-<?php
-declare( strict_types = 1 );
-
-/**
- * @author Niklas Laxström
- * @license GPL-2.0-or-later
- * @covers \TPParse
- */
-class TPParseTest extends \MediaWikiUnitTestCase {
- public function setUp(): void {
- parent::setUp();
-
- if ( !defined( 'TRANSLATE_FUZZY' ) ) {
- define( 'TRANSLATE_FUZZY', '!!FUZZY!!' );
- }
- }
-
- /** @dataProvider provideTestSectionWrapping */
- public function testSectionWrapping(
- bool $inline,
- bool $canWrap,
- array $messages,
- string $expected,
- string $comment
- ) {
- $title = Title::makeTitle( NS_MAIN, __CLASS__ );
- $prefix = $title->getPrefixedDBkey() . '/';
-
- $sections = $collection = [];
- foreach ( $messages as $id => $m ) {
- /** @var FatMessage $m */
- $section = new TPSection();
- $section->id = $id;
- $section->text = $m->definition();
- $section->setIsInline( $inline );
- $section->setCanWrap( $canWrap );
-
- $sections[$id] = $section;
- $collection[$prefix . $id] = $m;
- }
-
- $parse = new TPParse( $title );
- $parse->sections = $sections;
-
- $glue = $inline ? ' | ' : "\n\n";
- $parse->template = implode( $glue, array_keys( $sections ) );
-
- $actual = $parse->getTranslationPageText( $collection );
- $this->assertSame(
- $expected,
- $actual,
- $comment
- );
- }
-
- public function provideTestSectionWrapping() {
- $inline = true;
- $block = false;
-
- $wrap = true;
- $nowrap = false;
-
- $sectionText = 'Hello';
- $fuzzyClass = 'mw-translate-fuzzy';
-
- $okMessage = new FatMessage( 'ignoredKey', $sectionText );
- $okMessage->setTranslation( 'Hallo' );
-
- $fuzzyMessage = new FatMessage( 'ignoredKey', $sectionText );
- $fuzzyMessage->setTranslation( 'hallo' );
- $fuzzyMessage->addTag( 'fuzzy' );
-
- $untranslatedMessage = new FatMessage( 'ignoredKey', $sectionText );
-
- $identicalMessage = new FatMessage( 'ignoredKey', $sectionText );
- $identicalMessage->setTranslation( $sectionText );
-
- yield [
- $inline,
- $wrap,
- [ $okMessage ],
- 'Hallo',
- 'OK inline translation is not wrapped'
- ];
-
- yield [
- $inline,
- $nowrap,
- [ $okMessage ],
- 'Hallo',
- 'OK inline translation is not wrapped in nowrap'
- ];
-
- yield [
- $block,
- $wrap,
- [ $okMessage ],
- $okMessage->translation(),
- 'OK block translation is not wrapped'
- ];
-
- yield [
- $block,
- $nowrap,
- [ $okMessage ],
- $okMessage->translation(),
- 'OK block translation is not wrapped in nowrap'
- ];
-
- yield [
- $inline,
- $wrap,
- [ $fuzzyMessage ],
- "<span class=\"$fuzzyClass\">hallo</span>",
- 'Fuzzy inline translation is wrapped'
- ];
-
- yield [
- $inline,
- $nowrap,
- [ $fuzzyMessage ],
- 'hallo',
- 'Fuzzy inline translation is not wrapped in nowrap'
- ];
-
- yield [
- $block,
- $wrap,
- [ $fuzzyMessage ],
- "<div class=\"$fuzzyClass\">\nhallo\n</div>",
- 'Fuzzy block translation is wrapped'
- ];
-
- yield [
- $block,
- $nowrap,
- [ $fuzzyMessage ],
- 'hallo',
- 'Fuzzy block translation is not wrapped in nowrap'
- ];
-
- yield [
- $inline,
- $wrap,
- [ $identicalMessage ],
- 'Hello',
- 'Identically translated inline message is not wrapped'
- ];
-
- yield [
- $block,
- $nowrap,
- [ $identicalMessage ],
- 'Hello',
- 'Identically translated block message is not wrapped in nowrap'
- ];
-
- yield [
- $inline,
- $wrap,
- [ $okMessage, $fuzzyMessage, $identicalMessage, $untranslatedMessage ],
- "Hallo | <span class=\"$fuzzyClass\">hallo</span> | Hello | Hello",
- 'Different kinds of inline messages together are appropriately wrapped'
- ];
-
- yield [
- $inline,
- $nowrap,
- [ $okMessage, $fuzzyMessage, $identicalMessage, $untranslatedMessage ],
- 'Hallo | hallo | Hello | Hello',
- 'Different kinds of inline messages together are not wrapped in nowrap'
- ];
-
- $blockText = <<<WIKITEXT
-Hallo
-
-<div class="{$fuzzyClass}">
-hallo
-</div>
-
-Hello
-
-Hello
-WIKITEXT;
-
- yield [
- $block,
- $wrap,
- [ $okMessage, $fuzzyMessage, $identicalMessage, $untranslatedMessage ],
- $blockText,
- 'Different kinds of block messages together are wrapped appropriately'
- ];
- }
-}
diff --git a/MLEB/Translate/tests/phpunit/unit/tag/TPSectionTest.php b/MLEB/Translate/tests/phpunit/unit/tag/TPSectionTest.php
deleted file mode 100644
index ae39b9b9..00000000
--- a/MLEB/Translate/tests/phpunit/unit/tag/TPSectionTest.php
+++ /dev/null
@@ -1,114 +0,0 @@
-<?php
-declare( strict_types = 1 );
-
-/**
- * @author Niklas Laxström
- * @license GPL-2.0-or-later
- * @covers \TPSection
- */
-class TPSectionTest extends \MediaWikiUnitTestCase {
- /** @dataProvider providerTestGetMarkedText */
- public function testGetMarkedText(
- string $name, string $text, bool $inline, string $expected
- ) {
- $section = new TPSection();
- $section->name = $name;
- $section->text = $text;
- $section->setIsInline( $inline );
-
- $output = $section->getMarkedText();
-
- $this->assertEquals( $expected, $output );
- }
-
- /** @dataProvider providerTestGetTextWithVariables */
- public function testGetTextWithVariables( string $text, string $expected ) {
- $section = new TPSection();
- $section->text = $text;
-
- $output = $section->getTextWithVariables();
-
- $this->assertEquals( $expected, $output );
- }
-
- /** @dataProvider providerTestGetTextForTrans */
- public function testGetTextForTrans( string $text, string $expected ) {
- $section = new TPSection();
- $section->text = $text;
-
- $output = $section->getTextForTrans();
-
- $this->assertEquals( $expected, $output );
- }
-
- public static function providerTestGetMarkedText() {
- $cases = [];
-
- // Inline syntax
- $cases[] = [
- 'name',
- 'Hello',
- true,
- '<!--T:name--> Hello',
- ];
-
- // Normal syntax
- $cases[] = [
- 'name',
- 'Hello',
- false,
- "<!--T:name-->\nHello",
- ];
-
- // Inline should not matter for headings, which have special syntax, but test both values
- $cases[] = [
- 'name',
- '== Hello ==',
- true,
- '== Hello == <!--T:name-->',
- ];
-
- $cases[] = [
- 'name',
- '====== Hello ======',
- false,
- '====== Hello ====== <!--T:name-->',
- ];
-
- return $cases;
- }
-
- public static function providerTestGetTextWithVariables() {
- $cases = [];
-
- // syntax
- $cases[] = [
- "<tvar|abc>Peter\n cat!</>",
- '$abc',
- ];
-
- $cases[] = [
- "<tvar|1>Hello</>\n<tvar|2>Hello</>",
- "$1\n$2",
- ];
-
- return $cases;
- }
-
- public static function providerTestGetTextForTrans() {
- $cases = [];
-
- // syntax
- $cases[] = [
- "<tvar|abc>Peter\n cat!</>",
- "Peter\n cat!",
- ];
-
- $cases[] = [
- "<tvar|1>Hello</>\n<tvar|2>Hello</>",
- "Hello\nHello",
- ];
-
- return $cases;
- }
-}
diff --git a/MLEB/Translate/tests/phpunit/unit/tag/TranslatablePageTest.php b/MLEB/Translate/tests/phpunit/unit/tag/TranslatablePageTest.php
index a2b180ec..a1b16295 100644
--- a/MLEB/Translate/tests/phpunit/unit/tag/TranslatablePageTest.php
+++ b/MLEB/Translate/tests/phpunit/unit/tag/TranslatablePageTest.php
@@ -9,158 +9,6 @@ use MediaWiki\Linker\LinkTarget;
* @covers \TranslatablePage
*/
class TranslatablePageTest extends \MediaWikiUnitTestCase {
- /** @dataProvider provideTestGetTranslationPageText */
- public function testGetTranslationPageText( string $pageContents, string $expected ) {
- $title = Title::makeTitle( NS_MAIN, __CLASS__ );
- $page = TranslatablePage::newFromText( $title, $pageContents );
- $prefix = $title->getPrefixedDBkey() . '/';
- $parse = $page->getParse();
-
- $collection = [];
- $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'
- );
- }
-
- public function provideTestGetTranslationPageText() {
- yield [
- '<translate>Hello <tvar|abc>peter!</></translate>',
- 'Hello peter!'
- ];
-
- yield [
- '<translate nowrap>Hello <tvar|abc>peter!</></translate>',
- 'Hello peter!'
- ];
- }
-
- /** @dataProvider provideTestSectionise */
- public function testSectionise( string $input, string $pattern, string $comment ) {
- $canWrap = true;
- $result = TranslatablePage::sectionise( $input, $canWrap );
- $pattern = addcslashes( $pattern, '~' );
- $this->assertRegExp( "~^$pattern$~", $result['template'], $comment );
- }
-
- public static function provideTestSectionise() {
- // Ugly implicit assumption
- $ph = "\x7fUNIQ[a-z0-9]{8,16}-\d+";
-
- $cases = [];
-
- yield [
- 'Hello',
- "$ph",
- 'No surrounding whitespace',
- ];
-
- yield [
- "\nHello",
- "\n$ph",
- 'With surrounding whitespace',
- ];
-
- yield [
- "\nHello world\n\nBunny\n",
- "\n$ph\n\n$ph\n",
- 'Splitting at one empty line',
- ];
-
- yield [
- "First\n\n\n\n\nSecond\n\nThird",
- "$ph\n\n\n\n\n$ph\n\n$ph",
- 'Splitting with multiple empty lines',
- ];
-
- return $cases;
- }
-
- /** @dataProvider provideTestCleanupTags */
- public function testCleanupTags( string $input, string $expected, string $comment ) {
- $output = TranslatablePage::cleanupTags( $input );
- $this->assertEquals( $expected, $output, $comment );
- }
-
- public static function provideTestCleanupTags() {
- yield [
- "== Hello ==\n</translate>",
- '== Hello ==',
- 'Unbalanced tag in a section preview',
- ];
-
- yield [
- "</translate><translate>",
- '',
- 'Unbalanced tags, no whitespace',
- ];
-
- yield [
- "1\n2<translate>3\n4</translate>5\n6",
- "1\n23\n45\n6",
- 'Balanced tags, non-removable whitespace',
- ];
-
- yield [
- "1<translate>\n\n</translate>2",
- '12',
- 'Balanced tags, removable whitespace',
- ];
-
- yield [
- '[[<tvar|wmf>Special:MyLanguage/Wikimedia Foundation</>|Wikimedia Foundation]].',
- '[[Special:MyLanguage/Wikimedia Foundation|Wikimedia Foundation]].',
- 'TVAR tag is collapsed',
- ];
-
- yield [
- 'You can use the <nowiki><translate></nowiki> tag.',
- 'You can use the <nowiki><translate></nowiki> tag.',
- 'Tag inside a nowiki is retained',
- ];
-
- yield [
- 'What if I <translate and </translate>.',
- 'What if I <translate and .',
- 'Broken tag is retained',
- ];
-
- yield [
- '<abbr title="<translate nowrap>Careful unselfish true engineer</translate>">CUTE</abbr>',
- '<abbr title="Careful unselfish true engineer">CUTE</abbr>',
- 'Nowrap is removed',
- ];
- }
-
/** @dataProvider provideTestParseTranslationUnit */
public function testParseTranslationUnit( LinkTarget $input, array $expected ) {
$output = TranslatablePage::parseTranslationUnit( $input );
diff --git a/MLEB/Translate/tests/phpunit/unit/utils/ArrayFlattenerTest.php b/MLEB/Translate/tests/phpunit/unit/utils/ArrayFlattenerTest.php
index 1b72e56a..bb4f7a2c 100644
--- a/MLEB/Translate/tests/phpunit/unit/utils/ArrayFlattenerTest.php
+++ b/MLEB/Translate/tests/phpunit/unit/utils/ArrayFlattenerTest.php
@@ -5,9 +5,7 @@
* @license GPL-2.0-or-later
*/
-/**
- * @coversDefaultClass \ArrayFlattener
- */
+/** @coversDefaultClass \ArrayFlattener */
class ArrayFlattenerTest extends \MediaWikiUnitTestCase {
/**
* @dataProvider provideTestFlatten
diff --git a/MLEB/Translate/tests/phpunit/unit/utils/MessageSourceChangeTest.php b/MLEB/Translate/tests/phpunit/unit/utils/MessageSourceChangeTest.php
index 7929f5e9..99b71beb 100644
--- a/MLEB/Translate/tests/phpunit/unit/utils/MessageSourceChangeTest.php
+++ b/MLEB/Translate/tests/phpunit/unit/utils/MessageSourceChangeTest.php
@@ -4,15 +4,11 @@
* @license GPL-2.0-or-later
*/
-use MediaWiki\Extensions\Translate\MessageSync\MessageSourceChange;
+use MediaWiki\Extension\Translate\MessageSync\MessageSourceChange;
-/**
- * @covers MediaWiki\Extensions\Translate\MessageSync\MessageSourceChange
- */
+/** @covers MediaWiki\Extension\Translate\MessageSync\MessageSourceChange */
class MessageSourceChangeTest extends MediaWikiUnitTestCase {
- /**
- * @var MessageSourceChange
- */
+ /** @var MessageSourceChange */
protected $change;
/**
@@ -136,7 +132,7 @@ class MessageSourceChangeTest extends MediaWikiUnitTestCase {
'en-gb', 'renameDeleted', [ MessageSourceChange::CHANGE ]
);
$this->assertNull(
- $changed, 'findMessage returns null when searching changes for renamed message.'
+ $changed, 'findMessage returns null when searching changes for renamed message.'
);
$this->change->breakRename( 'en-gb', 'renameAdded' );