ApiTranslationReviewTest.php

Go to the documentation of this file.
00001 <?php
00013 class ApiTranslationReviewTest extends MediaWikiTestCase {
00014     protected function setUp() {
00015         parent::setUp();
00016 
00017         global $wgHooks;
00018         $this->setMwGlobals( array(
00019             'wgHooks' => $wgHooks,
00020             'wgTranslateCC' => array(),
00021             'wgTranslateMessageIndex' => array( 'DatabaseMessageIndex' ),
00022             'wgTranslateWorkflowStates' => false,
00023             'wgEnablePageTranslation' => false,
00024             'wgTranslateGroupFiles' => array(),
00025             'wgGroupPermissions' => 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             'ugakey1' => 'value1',
00036             'ugakey2' => 'value2',
00037         );
00038 
00039         $list['testgroup'] = new MockWikiMessageGroup( 'testgroup', $messages );
00040 
00041         return false;
00042     }
00043 
00044     public function testgetReviewBlockers() {
00045         $superUser1 = new MockSuperUser();
00046         $superUser1->setId( 1 );
00047 
00048         $superUser2 = new MockSuperUser();
00049         $superUser2->setId( 2 );
00050 
00051         $plainUser = User::newFromName( 'PlainUser' );
00052 
00053         $title = Title::makeTitle( NS_MEDIAWIKI, 'Ugakey1/fi' );
00054         WikiPage::factory( $title )->doEdit( 'trans1', __METHOD__, 0, false, $superUser1 );
00055 
00056         $title = Title::makeTitle( NS_MEDIAWIKI, 'Ugakey2/fi' );
00057         WikiPage::factory( $title )->doEdit( '!!FUZZY!!trans2', __METHOD__, 0, false, $superUser2 );
00058 
00059         $title = Title::makeTitle( NS_MEDIAWIKI, 'Ugakey3/fi' );
00060         WikiPage::factory( $title )->doEdit( 'unknown message', __METHOD__, 0, false, $superUser1 );
00061 
00062         $testcases = array(
00063             array(
00064                 'permissiondenied',
00065                 $plainUser,
00066                 'Ugakey1/fi',
00067                 'Unpriviledged user is not allowed to change state'
00068             ),
00069             array(
00070                 'owntranslation',
00071                 $superUser1,
00072                 'Ugakey1/fi',
00073                 'Cannot approve own translation'
00074             ),
00075             array(
00076                 'fuzzymessage',
00077                 $superUser1,
00078                 'Ugakey2/fi',
00079                 'Cannot approve fuzzy translation'
00080             ),
00081             array(
00082                 'unknownmessage',
00083                 $superUser1,
00084                 'Ugakey3/fi',
00085                 'Cannot approve unknown translation'
00086             ),
00087             array(
00088                 '',
00089                 $superUser2,
00090                 'Ugakey1/fi',
00091                 'Can approve non-fuzzy known non-own translation'
00092             ),
00093         );
00094 
00095         foreach ( $testcases as $case ) {
00096             list( $expected, $user, $page, $comment ) = $case;
00097             $revision = Revision::newFromTitle( Title::makeTitle( NS_MEDIAWIKI, $page ) );
00098             $ok = ApiTranslationReview::getReviewBlockers( $user, $revision );
00099             $this->assertEquals( $expected, $ok, $comment );
00100         }
00101     }
00102 }
00103 
00104 
Generated on Tue Oct 29 00:00:24 2013 for MediaWiki Translate Extension by  doxygen 1.6.3