SolrTTMServerTest.php

Go to the documentation of this file.
00001 <?php
00015 class SolrTTMServerTest extends MediaWikiTestCase {
00016     protected function setUp() {
00017         parent::setUp();
00018 
00019         global $wgHooks, $wgTranslateTranslationServices, $wgTranslateTestTTMServer;
00020         $this->setMwGlobals( array(
00021             'wgHooks' => $wgHooks,
00022             'wgTranslateCC' => array(),
00023             'wgTranslateMessageIndex' => array( 'DatabaseMessageIndex' ),
00024             'wgTranslateWorkflowStates' => false,
00025             'wgEnablePageTranslation' => false,
00026             'wgTranslateGroupFiles' => array(),
00027             'wgTranslateTranslationServices' => array(),
00028         ) );
00029         $wgTranslateTranslationServices['TTMServer'] = $wgTranslateTestTTMServer;
00030 
00031         $wgHooks['TranslatePostInitGroups'] = array( array( $this, 'addGroups' ) );
00032         MessageGroups::clearCache();
00033         MessageIndexRebuildJob::newJob()->run();
00034         // Also clear the "old" value when running multiple tests together
00035         MessageIndexRebuildJob::newJob()->run();
00036         self::runJobs();
00037     }
00038 
00039     public function addGroups( &$list ) {
00040         $list['ttmserver-test'] = new MockWikiMessageGroup( 'ttmserver-test', array(
00041             'one' => '1', 'two' => 'kaksi', 'three' => '3' ) );
00042 
00043         return true;
00044     }
00045 
00046     public function testSearchableTTMServer() {
00047         global $wgTranslateTestTTMServer;
00048         if ( !$wgTranslateTestTTMServer ) {
00049             $this->markTestSkipped( 'No test TTMServer available' );
00050         }
00051 
00052         $server = TTMServer::factory( $wgTranslateTestTTMServer );
00053         $solarium = $server->getSolarium();
00054 
00055         // Empty it
00056         $update = $solarium->createUpdate();
00057         $update->addDeleteQuery( '*:*' );
00058         $update->addCommit();
00059         $solarium->update( $update );
00060 
00061         // Check that it is empty indeed
00062         $select = $solarium->createSelect();
00063         $select->setRows( 0 );
00064         $select->setQuery( '*:*' );
00065         $result = $solarium->select( $select );
00066         $this->assertEquals( 0, $result->getNumFound() );
00067 
00068         // Add one definition
00069         $title = Title::newFromText( 'MediaWiki:one/en' );
00070         $page = WikiPage::factory( $title );
00071         $page->doEdit( '1', __METHOD__ );
00072 
00073         $select = $solarium->createSelect();
00074         $select->setRows( 1 );
00075         $select->setQuery( '*:*' );
00076         $result = $solarium->select( $select );
00077         $this->assertEquals( 1, $result->getNumFound() );
00078         $doc = null;
00079         foreach ( $result as $doc ) {
00080             // @todo FIXME Empty foreach statement.
00081         }
00082         $this->assertEquals( wfWikiId(), $doc->wiki );
00083         $this->assertEquals( 'en', $doc->language );
00084         $this->assertEquals( '1', $doc->content );
00085         $this->assertEquals( array( 'ttmserver-test' ), $doc->group );
00086 
00087         // Add one translation
00088         $title = Title::newFromText( 'MediaWiki:one/fi' );
00089         $page = WikiPage::factory( $title );
00090         $page->doEdit( 'yksi', __METHOD__ );
00091 
00092         $select = $solarium->createSelect();
00093         $select->setRows( 1 );
00094         $select->setQuery( 'language:fi' );
00095         $result = $solarium->select( $select );
00096         $this->assertEquals( 1, $result->getNumFound() );
00097         $doc = null;
00098         foreach ( $result as $doc ) {
00099             // @todo FIXME Empty foreach statement.
00100         }
00101         $this->assertEquals( 'yksi', $doc->content );
00102         $this->assertEquals( array( 'ttmserver-test' ), $doc->group );
00103 
00104         // Update definition
00105         $title = Title::newFromText( 'MediaWiki:one/en' );
00106         $page = WikiPage::factory( $title );
00107         $page->doEdit( '1-updated', __METHOD__ );
00108 
00109         $select = $solarium->createSelect();
00110         $select->setQuery( 'language:en' );
00111         $result = $solarium->select( $select );
00112         $this->assertEquals( 2, $result->getNumFound(), 'Old and new definition exists' );
00113 
00114         // Translation is fuzzied
00115         $title = Title::newFromText( 'MediaWiki:one/fi' );
00116         $page = WikiPage::factory( $title );
00117         $page->doEdit( '!!FUZZY!!yksi', __METHOD__ );
00118 
00119         $select = $solarium->createSelect();
00120         $select->setQuery( 'language:fi' );
00121         $result = $solarium->select( $select );
00122         $this->assertEquals( 0, $result->getNumFound() );
00123 
00124         // Translation is udpated
00125         $title = Title::newFromText( 'MediaWiki:one/fi' );
00126         $page = WikiPage::factory( $title );
00127         $page->doEdit( 'yksi-päiv', __METHOD__ );
00128 
00129         $select = $solarium->createSelect();
00130         $select->setQuery( 'language:fi' );
00131         $result = $solarium->select( $select );
00132         $this->assertEquals( 1, $result->getNumFound() );
00133         $doc = null;
00134         foreach ( $result as $doc ) {
00135             // @todo FIXME Empty foreach statement.
00136         }
00137         $this->assertEquals( 'yksi-päiv', $doc->content );
00138 
00139         // And now the messages should be orphaned
00140         global $wgHooks;
00141         $wgHooks['TranslatePostInitGroups'] = array();
00142         MessageGroups::clearCache();
00143         MessageIndexRebuildJob::newJob()->run();
00144         self::runJobs();
00145 
00146         $select = $solarium->createSelect();
00147         $select->setQuery( '*:*' );
00148         $result = $solarium->select( $select );
00149         $this->assertEquals( 2, $result->getNumFound(), 'One definition and one translation exists' );
00150         foreach ( $result as $doc ) {
00151             $this->assertEquals( null, $doc->group, 'Messages are orphaned' );
00152         }
00153 
00154         // And message deletion
00155         $title = Title::newFromText( 'MediaWiki:one/fi' );
00156         $page = WikiPage::factory( $title );
00157         $page->doDeleteArticle( __METHOD__ );
00158 
00159         $select = $solarium->createSelect();
00160         $select->setQuery( 'language:fi' );
00161         $result = $solarium->select( $select );
00162         $this->assertEquals( 0, $result->getNumFound() );
00163     }
00164 
00165     protected static function runJobs() {
00166         do {
00167             $job = Job::pop();
00168             if ( !$job ) {
00169                 break;
00170             }
00171             $job->run();
00172         } while ( true );
00173     }
00174 }
Generated on Tue Oct 29 00:00:24 2013 for MediaWiki Translate Extension by  doxygen 1.6.3