MessageCollectionTest.php

Go to the documentation of this file.
00001 <?php
00015 class MessageCollectionTest extends MediaWikiTestCase {
00016     protected function setUp() {
00017         parent::setUp();
00018 
00019         global $wgHooks;
00020         $this->setMwGlobals( array(
00021             'wgHooks' => $wgHooks,
00022             'wgTranslateCC' => array(),
00023             'wgTranslateMessageIndex' => array( 'DatabaseMessageIndex' ),
00024             'wgTranslateWorkflowStates' => false,
00025             'wgTranslateGroupFiles' => array(),
00026             'wgTranslateTranslationServices' => array(),
00027         ) );
00028         $wgHooks['TranslatePostInitGroups'] = array( array( $this, 'getTestGroups' ) );
00029         MessageGroups::clearCache();
00030         MessageIndexRebuildJob::newJob()->run();
00031     }
00032 
00033     public function getTestGroups( &$list ) {
00034         $messages = array(
00035             'translated' => 'bunny',
00036             'untranslated' => 'fanny',
00037         );
00038         $list['test-group'] = new MockWikiMessageGroup( 'test-group', $messages );
00039 
00040         return false;
00041     }
00042 
00043     public function testMessage() {
00044         $user = new MockSuperUser();
00045         $user->setId( 123 );
00046         $title = Title::newFromText( 'MediaWiki:translated/fi' );
00047         $page = WikiPage::factory( $title );
00048         $status = $page->doEdit( 'pupuliini', __METHOD__, false, 0, $user );
00049         $value = $status->getValue();
00050         $rev = $value['revision'];
00051         $revision = $rev->getId();
00052 
00053         $group = MessageGroups::getGroup( 'test-group' );
00054         $collection = $group->initCollection( 'fi' );
00055         $collection->loadTranslations();
00056 
00058         $translated = $collection['translated'];
00059         $this->assertInstanceof( 'TMessage', $translated );
00060         $this->assertEquals( 'translated', $translated->key() );
00061         $this->assertEquals( 'bunny', $translated->definition() );
00062         $this->assertEquals( 'pupuliini', $translated->translation() );
00063         $this->assertEquals( 'SuperUser', $translated->getProperty( 'last-translator-text' ) );
00064         $this->assertEquals( 123, $translated->getProperty( 'last-translator-id' ) );
00065         $this->assertEquals(
00066             'translated',
00067             $translated->getProperty( 'status' ),
00068             'message status is translated'
00069         );
00070         $this->assertEquals( $revision, $translated->getProperty( 'revision' ) );
00071 
00073         $untranslated = $collection['untranslated'];
00074         $this->assertInstanceof( 'TMessage', $untranslated );
00075         $this->assertEquals( null, $untranslated->translation(), 'no translation is null' );
00076         $this->assertEquals( false, $untranslated->getProperty( 'last-translator-text' ) );
00077         $this->assertEquals( false, $untranslated->getProperty( 'last-translator-id' ) );
00078         $this->assertEquals(
00079             'untranslated',
00080             $untranslated->getProperty( 'status' ),
00081             'message status is untranslated'
00082         );
00083         $this->assertEquals( false, $untranslated->getProperty( 'revision' ) );
00084     }
00085 }
Generated on Tue Oct 29 00:00:24 2013 for MediaWiki Translate Extension by  doxygen 1.6.3