summaryrefslogtreecommitdiff
path: root/www/wiki/extensions/Translate/tests/phpunit/api/ApiQueryMessageCollectionTest.php
blob: 17424a80b85101d754652664354f72432fc9c336 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
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.' );
	}
}