TranslationFuzzyUpdaterTest.php

Go to the documentation of this file.
00001 <?php
00015 class TranslationFuzzyUpdaterTest 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( 'ugakey' => '$1 of $2', );
00035         $list['test-group'] = new MockWikiMessageGroup( 'test-group', $messages );
00036 
00037         return false;
00038     }
00039 
00040     public function testParsing() {
00041         $title = Title::newFromText( 'MediaWiki:Ugakey/nl' );
00042         $page = WikiPage::factory( $title );
00043         $status = $page->doEdit( '$1 van $2', __METHOD__ );
00044         $value = $status->getValue();
00048         $rev = $value['revision'];
00049         $revision = $rev->getId();
00050 
00051         $dbw = wfGetDB( DB_MASTER );
00052         $conds = array(
00053             'rt_page' => $title->getArticleID(),
00054             'rt_type' => RevTag::getType( 'fuzzy' ),
00055             'rt_revision' => $revision
00056         );
00057 
00058         $index = array_keys( $conds );
00059         $dbw->replace( 'revtag', array( $index ), $conds, __METHOD__ );
00060 
00061         $handle = new MessageHandle( $title );
00062         $this->assertTrue( $handle->isValid(), 'Message is known' );
00063         $this->assertTrue( $handle->isFuzzy(), 'Message is fuzzy after database fuzzying' );
00064         // Update the translation without the fuzzy string
00065         $page->doEdit( '$1 van $2', __METHOD__ );
00066         $this->assertFalse( $handle->isFuzzy(), 'Message is unfuzzy after edit' );
00067 
00068         $page->doEdit( '!!FUZZY!!$1 van $2', __METHOD__ );
00069         $this->assertTrue( $handle->isFuzzy(), 'Message is fuzzy after manual fuzzying' );
00070 
00071         // Update the translation without the fuzzy string
00072         $page->doEdit( '$1 van $2', __METHOD__ );
00073         $this->assertFalse( $handle->isFuzzy(), 'Message is unfuzzy after edit' );
00074     }
00075 }
Generated on Tue Oct 29 00:00:24 2013 for MediaWiki Translate Extension by  doxygen 1.6.3