diff options
Diffstat (limited to 'www/wiki/extensions/Translate/tests/phpunit/TTMServerTest.php')
-rw-r--r-- | www/wiki/extensions/Translate/tests/phpunit/TTMServerTest.php | 42 |
1 files changed, 29 insertions, 13 deletions
diff --git a/www/wiki/extensions/Translate/tests/phpunit/TTMServerTest.php b/www/wiki/extensions/Translate/tests/phpunit/TTMServerTest.php index c5869ce2..ed434ddc 100644 --- a/www/wiki/extensions/Translate/tests/phpunit/TTMServerTest.php +++ b/www/wiki/extensions/Translate/tests/phpunit/TTMServerTest.php @@ -1,11 +1,9 @@ <?php /** - * Tests for TTMServer - * * @file * @author Niklas Laxström * @copyright Copyright © 2012-2013, Niklas Laxström - * @license GPL-2.0+ + * @license GPL-2.0-or-later */ class TTMServerTest extends MediaWikiTestCase { @@ -16,15 +14,15 @@ class TTMServerTest extends MediaWikiTestCase { $this->config = $wgTranslateTranslationServices; parent::setUp(); - $wgTranslateTranslationServices = array(); - $wgTranslateTranslationServices['localtm'] = array( + $wgTranslateTranslationServices = []; + $wgTranslateTranslationServices['localtm'] = [ 'url' => 'http://example.com/sandwiki/api.php', 'displayname' => 'example.com', 'cutoff' => 0.75, 'type' => 'ttmserver', - ); + ]; - $wgTranslateTranslationServices['apitm'] = array( + $wgTranslateTranslationServices['apitm'] = [ 'url' => 'http://example.com/w/api.php', 'displayname' => 'example.com', 'cutoff' => 0.75, @@ -32,7 +30,7 @@ class TTMServerTest extends MediaWikiTestCase { 'timeout-async' => 4, 'type' => 'ttmserver', 'class' => 'RemoteTTMServer', - ); + ]; } protected function tearDown() { @@ -48,26 +46,27 @@ class TTMServerTest extends MediaWikiTestCase { get_class( $server ), 'Fake server given when default server is disabled' ); - global $wgTranslateTranslationServices; - $wgTranslateTranslationServices['TTMServer'] = array( + global $wgTranslateTranslationServices, + $wgTranslateTranslationDefaultService; + $wgTranslateTranslationServices[$wgTranslateTranslationDefaultService] = [ 'database' => false, // Passed to wfGetDB 'cutoff' => 0.75, 'type' => 'ttmserver', 'public' => false, - ); + ]; $server = TTMServer::primary(); $this->assertEquals( 'DatabaseTTMServer', get_class( $server ), 'Real server given when default server is enabled' ); - unset( $wgTranslateTranslationServices['TTMServer'] ); + unset( $wgTranslateTranslationServices[$wgTranslateTranslationDefaultService] ); } public function testFakeTTMServer() { $server = new FakeTTMServer(); $this->assertEquals( - array(), + [], $server->query( 'en', 'fi', 'daa' ), 'FakeTTMServer returns no suggestions for all queries' ); @@ -80,4 +79,21 @@ class TTMServerTest extends MediaWikiTestCase { 'FakeTTMServer returns null on update' ); } + + public function testMirrorsConfig() { + global $wgTranslateTranslationServices; + $wgTranslateTranslationServices['primary'] = [ + 'class' => 'ElasticSearchTTMServer', + 'mirrors' => [ 'secondary' ] + ]; + $wgTranslateTranslationServices['secondary'] = [ + 'class' => 'ElasticSearchTTMServer', + 'mirrors' => [ 'primary', 'unknown' ] + ]; + $primary = TTMServer::factory( $wgTranslateTranslationServices['primary'] ); + $this->assertEquals( [ 'secondary' ], $primary->getMirrors() ); + $secondary = TTMServer::factory( $wgTranslateTranslationServices['secondary'] ); + $this->setExpectedException( TTMServerException::class ); + $secondary->getMirrors(); + } } |