diff options
author | Alex Legler <alex@a3li.li> | 2014-12-23 17:49:26 +0100 |
---|---|---|
committer | Alex Legler <alex@a3li.li> | 2014-12-23 17:49:26 +0100 |
commit | e352fff59842ca14fbfd81ee1c4a64297bb598c5 (patch) | |
tree | 153f268484aa5cc41cacf912bdce8c4847df222d /MLEB/Translate/tests/phpunit/MessageGroupsTest.php | |
download | extensions-e352fff59842ca14fbfd81ee1c4a64297bb598c5.tar.gz extensions-e352fff59842ca14fbfd81ee1c4a64297bb598c5.tar.bz2 extensions-e352fff59842ca14fbfd81ee1c4a64297bb598c5.zip |
Add initial set of additional extensions
Diffstat (limited to 'MLEB/Translate/tests/phpunit/MessageGroupsTest.php')
-rw-r--r-- | MLEB/Translate/tests/phpunit/MessageGroupsTest.php | 88 |
1 files changed, 88 insertions, 0 deletions
diff --git a/MLEB/Translate/tests/phpunit/MessageGroupsTest.php b/MLEB/Translate/tests/phpunit/MessageGroupsTest.php new file mode 100644 index 00000000..a2543fa6 --- /dev/null +++ b/MLEB/Translate/tests/phpunit/MessageGroupsTest.php @@ -0,0 +1,88 @@ +<?php +/** + * Unit tests. + * + * @author Niklas Laxström + * @copyright Copyright © 2012 Niklas Laxström + * @file + * @license GPL-2.0+ + */ + +/** + * @group Database + */ +class MessageGroupsTest extends MediaWikiTestCase { + protected function setUp() { + parent::setUp(); + + $conf = array( + __DIR__ . '/data/ParentGroups.yaml', + ); + + global $wgHooks; + $this->setMwGlobals( array( + 'wgHooks' => $wgHooks, + 'wgTranslateCC' => array(), + 'wgTranslateMessageIndex' => array( 'DatabaseMessageIndex' ), + 'wgTranslateWorkflowStates' => false, + 'wgEnablePageTranslation' => false, + 'wgTranslateGroupFiles' => $conf, + 'wgTranslateTranslationServices' => array(), + ) ); + $wgHooks['TranslatePostInitGroups'] = array(); + MessageGroups::clearCache(); + MessageIndexRebuildJob::newJob()->run(); + } + + /** + * @dataProvider provideGroups + */ + public function testGetParentGroups( $expected, $target ) { + $group = MessageGroups::getGroup( $target ); + $got = MessageGroups::getParentGroups( $group ); + $this->assertEquals( $expected, $got ); + } + + public static function provideGroups() { + $cases = array(); + $cases[] = array( + array( array( 'root1' ), array( 'root2' ) ), + 'twoparents' + ); + + $cases[] = array( + array( array( 'root3', 'sub1' ), array( 'root3', 'sub2' ) ), + 'oneparent-twopaths' + ); + + $cases[] = array( + array( + array( 'root4' ), + array( 'root4', 'nested1' ), + array( 'root4', 'nested1', 'nested2' ), + array( 'root4', 'nested2' ), + ), + 'multilevelnested' + ); + + return $cases; + } + + public function testHaveSingleSourceLanguage() { + $this->setMwGlobals( array( + 'wgTranslateGroupFiles' => array( __DIR__ . '/data/MixedSourceLanguageGroups.yaml' ), + ) ); + MessageGroups::clearCache(); + + $enGroup1 = MessageGroups::getGroup( 'EnglishGroup1' ); + $enGroup2 = MessageGroups::getGroup( 'EnglishGroup2' ); + $teGroup1 = MessageGroups::getGroup( 'TeluguGroup1' ); + + $this->assertEquals( 'en', MessageGroups::haveSingleSourceLanguage( + array( $enGroup1, $enGroup2 ) ) + ); + $this->assertEquals( '', MessageGroups::haveSingleSourceLanguage( + array( $enGroup1, $enGroup2, $teGroup1 ) ) + ); + } +} |