TTMServerTest.php

Go to the documentation of this file.
00001 <?php
00011 class TTMServerTest extends MediaWikiTestCase {
00012     protected $config;
00013 
00014     protected function setUp() {
00015         global $wgTranslateTranslationServices;
00016         $this->config = $wgTranslateTranslationServices;
00017         parent::setUp();
00018 
00019         $wgTranslateTranslationServices = array();
00020         $wgTranslateTranslationServices['localtm'] = array(
00021             'url' => 'http://example.com/sandwiki/api.php',
00022             'displayname' => 'example.com',
00023             'cutoff' => 0.75,
00024             'type' => 'ttmserver',
00025         );
00026 
00027         $wgTranslateTranslationServices['apitm'] = array(
00028             'url' => 'http://example.com/w/api.php',
00029             'displayname' => 'example.com',
00030             'cutoff' => 0.75,
00031             'timeout-sync' => 4,
00032             'timeout-async' => 4,
00033             'type' => 'ttmserver',
00034             'class' => 'RemoteTTMServer',
00035         );
00036     }
00037 
00038     protected function tearDown() {
00039         global $wgTranslateTranslationServices;
00040         $wgTranslateTranslationServices = $this->config;
00041         parent::tearDown();
00042     }
00043 
00044     public function testConstruct() {
00045         $server = TTMServer::primary();
00046         $this->assertEquals(
00047             'FakeTTMServer',
00048             get_class( $server ),
00049             'Fake server given when default server is disabled'
00050         );
00051         global $wgTranslateTranslationServices;
00052         $wgTranslateTranslationServices['TTMServer'] = array(
00053             'database' => false, // Passed to wfGetDB
00054             'cutoff' => 0.75,
00055             'type' => 'ttmserver',
00056             'public' => false,
00057         );
00058         $server = TTMServer::primary();
00059         $this->assertEquals(
00060             'DatabaseTTMServer',
00061             get_class( $server ),
00062             'Real server given when default server is enabled'
00063         );
00064         unset( $wgTranslateTranslationServices['TTMServer'] );
00065     }
00066 
00067     public function testFakeTTMServer() {
00068         $server = new FakeTTMServer();
00069         $this->assertEquals(
00070             array(),
00071             $server->query( 'en', 'fi', 'daa' ),
00072             'FakeTTMServer returns no suggestions for all queries'
00073         );
00074 
00075         $title = new Title();
00076         $handle = new MessageHandle( $title );
00077 
00078         $this->assertNull(
00079             $server->update( $handle, 'text' ),
00080             'FakeTTMServer returns null on update'
00081         );
00082     }
00083 }
Generated on Tue Oct 29 00:00:24 2013 for MediaWiki Translate Extension by  doxygen 1.6.3