summaryrefslogtreecommitdiff
path: root/www/wiki/extensions/Translate/tests/phpunit/api/ApiQueryMessageCollectionTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'www/wiki/extensions/Translate/tests/phpunit/api/ApiQueryMessageCollectionTest.php')
-rw-r--r--www/wiki/extensions/Translate/tests/phpunit/api/ApiQueryMessageCollectionTest.php61
1 files changed, 61 insertions, 0 deletions
diff --git a/www/wiki/extensions/Translate/tests/phpunit/api/ApiQueryMessageCollectionTest.php b/www/wiki/extensions/Translate/tests/phpunit/api/ApiQueryMessageCollectionTest.php
new file mode 100644
index 00000000..17424a80
--- /dev/null
+++ b/www/wiki/extensions/Translate/tests/phpunit/api/ApiQueryMessageCollectionTest.php
@@ -0,0 +1,61 @@
+<?php
+/**
+ * @file
+ * @author Abijeet Patro
+ * @license GPL-2.0-or-later
+ */
+
+/**
+ * @group medium
+ */
+class ApiQueryMessageCollectionTest extends ApiTestCase {
+ protected function setUp() {
+ parent::setUp();
+
+ $this->setTemporaryHook(
+ 'TranslatePostInitGroups',
+ function ( &$list ) {
+ $exampleMessageGroup = new WikiMessageGroup( 'theid', 'thesource' );
+ $exampleMessageGroup->setLabel( 'thelabel' ); // Example
+ $exampleMessageGroup->setNamespace( 5 ); // Example
+ $list['theid'] = $exampleMessageGroup;
+
+ $anotherExampleMessageGroup = new WikiMessageGroup( 'anotherid', 'thesource' );
+ $anotherExampleMessageGroup->setLabel( 'thelabel' ); // Example
+ $anotherExampleMessageGroup->setNamespace( 5 ); // Example
+ $list['anotherid'] = $anotherExampleMessageGroup;
+
+ return false;
+ }
+ );
+
+ $mg = MessageGroups::singleton();
+ $mg->setCache( new WANObjectCache( [ 'cache' => wfGetCache( 'hash' ) ] ) );
+ $mg->recache();
+ }
+
+ public function testSameAsSourceLanguage() {
+ global $wgLanguageCode;
+
+ $groups = MessageGroups::getAllGroups();
+ list( $response ) = $this->doApiRequest(
+ [
+ 'mcgroup' => $groups['anotherid']->getId(),
+ 'action' => 'query',
+ 'list' => 'messagecollection',
+ 'mcprop' => 'definition|translation|tags|properties',
+ // @see https://gerrit.wikimedia.org/r/#/c/160222/
+ 'continue' => '',
+ 'errorformat' => 'html',
+ 'mclanguage' => $wgLanguageCode
+ ]
+ );
+
+ $this->assertArrayHasKey( 'warnings', $response,
+ 'warning triggered when source language same as target language.' );
+ $this->assertCount( 1, $response['warnings'],
+ 'warning triggered when source language same as target language.' );
+ $this->assertArrayNotHasKey( 'errors', $response,
+ 'no error triggered when source language same as target language.' );
+ }
+}