MessageGroupsTest.php
Go to the documentation of this file.00001 <?php
00014 class MessageGroupsTest extends MediaWikiTestCase {
00015 protected function setUp() {
00016 parent::setUp();
00017
00018 $conf = array(
00019 __DIR__ . '/data/ParentGroups.yaml',
00020 );
00021
00022 global $wgHooks;
00023 $this->setMwGlobals( array(
00024 'wgHooks' => $wgHooks,
00025 'wgTranslateCC' => array(),
00026 'wgTranslateMessageIndex' => array( 'DatabaseMessageIndex' ),
00027 'wgTranslateWorkflowStates' => false,
00028 'wgEnablePageTranslation' => false,
00029 'wgTranslateGroupFiles' => $conf,
00030 'wgTranslateTranslationServices' => array(),
00031 ) );
00032 $wgHooks['TranslatePostInitGroups'] = array();
00033 MessageGroups::clearCache();
00034 MessageIndexRebuildJob::newJob()->run();
00035 }
00036
00040 public function testGetParentGroups( $expected, $target ) {
00041 $group = MessageGroups::getGroup( $target );
00042 $got = MessageGroups::getParentGroups( $group );
00043 $this->assertEquals( $expected, $got );
00044 }
00045
00046 public static function provideGroups() {
00047 $cases = array();
00048 $cases[] = array(
00049 array( array( 'root1' ), array( 'root2' ) ),
00050 'twoparents'
00051 );
00052
00053 $cases[] = array(
00054 array( array( 'root3', 'sub1' ), array( 'root3', 'sub2' ) ),
00055 'oneparent-twopaths'
00056 );
00057
00058 $cases[] = array(
00059 array(
00060 array( 'root4' ),
00061 array( 'root4', 'nested1' ),
00062 array( 'root4', 'nested1', 'nested2' ),
00063 array( 'root4', 'nested2' ),
00064 ),
00065 'multilevelnested'
00066 );
00067
00068 return $cases;
00069 }
00070
00071 public function testHaveSingleSourceLanguage() {
00072 $this->setMwGlobals( array(
00073 'wgTranslateGroupFiles' => array( __DIR__ . '/data/MixedSourceLanguageGroups.yaml' ),
00074 ) );
00075 MessageGroups::clearCache();
00076
00077 $enGroup1 = MessageGroups::getGroup( 'EnglishGroup1' );
00078 $enGroup2 = MessageGroups::getGroup( 'EnglishGroup2' );
00079 $teGroup1 = MessageGroups::getGroup( 'TeluguGroup1' );
00080
00081 $this->assertEquals( 'en', MessageGroups::haveSingleSourceLanguage(
00082 array( $enGroup1, $enGroup2 ) )
00083 );
00084 $this->assertEquals( '', MessageGroups::haveSingleSourceLanguage(
00085 array( $enGroup1, $enGroup2, $teGroup1 ) )
00086 );
00087 }
00088 }