4 * FIXME Temporary disabled per T225244
9 * @covers ApiQueryLanguageinfo
11 class ApiQueryLanguageinfoTest
extends ApiTestCase
{
13 protected function setUp() {
15 // register custom language names so this test is independent of CLDR
16 $this->setTemporaryHook(
17 'LanguageGetTranslatedLanguageNames',
18 function ( array &$names, $code ) {
21 $names['sh'] = 'Serbo-Croatian';
22 $names['qtp'] = 'a custom language code MediaWiki knows nothing about';
25 $names['de'] = 'alemão';
32 private function doQuery( array $params, $microtimeFunction = null ): array {
35 'meta' => 'languageinfo',
39 if ( $microtimeFunction !== null ) {
40 // hook into the module manager to override the factory function
41 // so we can call the constructor with the custom $microtimeFunction
42 $this->setTemporaryHook(
43 'ApiQuery::moduleManager',
44 function ( ApiModuleManager
$moduleManager ) use ( $microtimeFunction ) {
45 $moduleManager->addModule(
48 ApiQueryLanguageinfo
::class,
49 function ( $parent, $name ) use ( $microtimeFunction ) {
50 return new ApiQueryLanguageinfo(
61 $res = $this->doApiRequest( $params );
63 $this->assertArrayNotHasKey( 'warnings', $res[0] );
65 return [ $res[0]['query']['languageinfo'], $res[0]['continue'] ??
null ];
68 public function testAllPropsForSingleLanguage() {
69 list( $response, $continue ) = $this->doQuery( [
70 'liprop' => 'code|bcp47|dir|autonym|name|fallbacks|variants',
74 $this->assertArrayEquals( [
78 'autonym' => 'srpskohrvatski / српскохрватски',
79 'name' => 'Serbo-Croatian',
80 'fallbacks' => [ 'bs', 'sr-el', 'hr' ],
82 'variants' => [ 'sh' ],
87 public function testAllPropsForSingleCustomLanguage() {
88 list( $response, $continue ) = $this->doQuery( [
89 'liprop' => 'code|bcp47|dir|autonym|name|fallbacks|variants',
90 'licode' => 'qtp', // reserved for local use by ISO 639; registered in setUp()
93 $this->assertArrayEquals( [
98 'name' => 'a custom language code MediaWiki knows nothing about',
101 'variants' => [ 'qtp' ],
106 public function testNameInOtherLanguageForSingleLanguage() {
107 list( $response, $continue ) = $this->doQuery( [
113 $this->assertArrayEquals( [ 'de' => [ 'name' => 'alemão' ] ], $response );
116 public function testContinuationNecessary() {
118 $microtimeFunction = function () use ( &$time ) {
119 return $time +
= 0.75;
122 list( $response, $continue ) = $this->doQuery( [], $microtimeFunction );
124 $this->assertCount( 2, $response );
125 $this->assertArrayHasKey( 'licontinue', $continue );
128 public function testContinuationNotNecessary() {
130 $microtimeFunction = function () use ( &$time ) {
134 list( $response, $continue ) = $this->doQuery( [
136 ], $microtimeFunction );
138 $this->assertNull( $continue );
141 public function testContinuationInAlphabeticalOrderNotParameterOrder() {
143 $microtimeFunction = function () use ( &$time ) {
144 return $time +
= 0.75;
146 $params = [ 'licode' => 'en|ru|zh|de|yue' ];
148 list( $response, $continue ) = $this->doQuery( $params, $microtimeFunction );
150 $this->assertCount( 2, $response );
151 $this->assertArrayHasKey( 'licontinue', $continue );
152 $this->assertSame( [ 'de', 'en' ], array_keys( $response ) );
155 $params = $continue +
$params;
156 list( $response, $continue ) = $this->doQuery( $params, $microtimeFunction );
158 $this->assertCount( 2, $response );
159 $this->assertArrayHasKey( 'licontinue', $continue );
160 $this->assertSame( [ 'ru', 'yue' ], array_keys( $response ) );
163 $params = $continue +
$params;
164 list( $response, $continue ) = $this->doQuery( $params, $microtimeFunction );
166 $this->assertCount( 1, $response );
167 $this->assertNull( $continue );
168 $this->assertSame( [ 'zh' ], array_keys( $response ) );
171 public function testResponseHasModulePathEvenIfEmpty() {
172 list( $response, $continue ) = $this->doQuery( [ 'licode' => '' ] );
173 $this->assertEmpty( $response );
174 // the real test is that $res[0]['query']['languageinfo'] in doQuery() didn’t fail