Remove messages.inc, rebuildLanguage.php, writeMessagesArray.inc
[mediawiki.git] / tests / phpunit / includes / LanguageConverterTest.php
blobd4ccca99c0f3a0937c20b2b6dcc1f72955dfd615
1 <?php
3 class LanguageConverterTest extends MediaWikiLangTestCase {
4 /** @var LanguageToTest */
5 protected $lang = null;
6 /** @var TestConverter */
7 protected $lc = null;
9 protected function setUp() {
10 parent::setUp();
12 $this->setMwGlobals( array(
13 'wgContLang' => Language::factory( 'tg' ),
14 'wgLanguageCode' => 'tg',
15 'wgDefaultLanguageVariant' => false,
16 'wgMemc' => new EmptyBagOStuff,
17 'wgRequest' => new FauxRequest( array() ),
18 'wgUser' => new User,
19 ) );
21 $this->lang = new LanguageToTest();
22 $this->lc = new TestConverter(
23 $this->lang, 'tg',
24 array( 'tg', 'tg-latn' )
28 protected function tearDown() {
29 unset( $this->lc );
30 unset( $this->lang );
32 parent::tearDown();
35 /**
36 * @covers LanguageConverter::getPreferredVariant
38 public function testGetPreferredVariantDefaults() {
39 $this->assertEquals( 'tg', $this->lc->getPreferredVariant() );
42 /**
43 * @covers LanguageConverter::getPreferredVariant
44 * @covers LanguageConverter::getHeaderVariant
46 public function testGetPreferredVariantHeaders() {
47 global $wgRequest;
48 $wgRequest->setHeader( 'Accept-Language', 'tg-latn' );
50 $this->assertEquals( 'tg-latn', $this->lc->getPreferredVariant() );
53 /**
54 * @covers LanguageConverter::getPreferredVariant
55 * @covers LanguageConverter::getHeaderVariant
57 public function testGetPreferredVariantHeaderWeight() {
58 global $wgRequest;
59 $wgRequest->setHeader( 'Accept-Language', 'tg;q=1' );
61 $this->assertEquals( 'tg', $this->lc->getPreferredVariant() );
64 /**
65 * @covers LanguageConverter::getPreferredVariant
66 * @covers LanguageConverter::getHeaderVariant
68 public function testGetPreferredVariantHeaderWeight2() {
69 global $wgRequest;
70 $wgRequest->setHeader( 'Accept-Language', 'tg-latn;q=1' );
72 $this->assertEquals( 'tg-latn', $this->lc->getPreferredVariant() );
75 /**
76 * @covers LanguageConverter::getPreferredVariant
77 * @covers LanguageConverter::getHeaderVariant
79 public function testGetPreferredVariantHeaderMulti() {
80 global $wgRequest;
81 $wgRequest->setHeader( 'Accept-Language', 'en, tg-latn;q=1' );
83 $this->assertEquals( 'tg-latn', $this->lc->getPreferredVariant() );
86 /**
87 * @covers LanguageConverter::getPreferredVariant
89 public function testGetPreferredVariantUserOption() {
90 global $wgUser;
92 $wgUser = new User;
93 $wgUser->load(); // from 'defaults'
94 $wgUser->mId = 1;
95 $wgUser->mDataLoaded = true;
96 $wgUser->mOptionsLoaded = true;
97 $wgUser->setOption( 'variant', 'tg-latn' );
99 $this->assertEquals( 'tg-latn', $this->lc->getPreferredVariant() );
103 * @covers LanguageConverter::getPreferredVariant
104 * @covers LanguageConverter::getUserVariant
106 public function testGetPreferredVariantUserOptionForForeignLanguage() {
107 global $wgContLang, $wgUser;
109 $wgContLang = Language::factory( 'en' );
110 $wgUser = new User;
111 $wgUser->load(); // from 'defaults'
112 $wgUser->mId = 1;
113 $wgUser->mDataLoaded = true;
114 $wgUser->mOptionsLoaded = true;
115 $wgUser->setOption( 'variant-tg', 'tg-latn' );
117 $this->assertEquals( 'tg-latn', $this->lc->getPreferredVariant() );
121 * @covers LanguageConverter::getPreferredVariant
122 * @covers LanguageConverter::getUserVariant
123 * @covers LanguageConverter::getURLVariant
125 public function testGetPreferredVariantHeaderUserVsUrl() {
126 global $wgContLang, $wgRequest, $wgUser;
128 $wgContLang = Language::factory( 'tg-latn' );
129 $wgRequest->setVal( 'variant', 'tg' );
130 $wgUser = User::newFromId( "admin" );
131 $wgUser->setId( 1 );
132 $wgUser->mFrom = 'defaults';
133 $wgUser->mOptionsLoaded = true;
134 // The user's data is ignored because the variant is set in the URL.
135 $wgUser->setOption( 'variant', 'tg-latn' );
136 $this->assertEquals( 'tg', $this->lc->getPreferredVariant() );
140 * @covers LanguageConverter::getPreferredVariant
142 public function testGetPreferredVariantDefaultLanguageVariant() {
143 global $wgDefaultLanguageVariant;
145 $wgDefaultLanguageVariant = 'tg-latn';
146 $this->assertEquals( 'tg-latn', $this->lc->getPreferredVariant() );
150 * @covers LanguageConverter::getPreferredVariant
151 * @covers LanguageConverter::getURLVariant
153 public function testGetPreferredVariantDefaultLanguageVsUrlVariant() {
154 global $wgDefaultLanguageVariant, $wgRequest, $wgContLang;
156 $wgContLang = Language::factory( 'tg-latn' );
157 $wgDefaultLanguageVariant = 'tg';
158 $wgRequest->setVal( 'variant', null );
159 $this->assertEquals( 'tg', $this->lc->getPreferredVariant() );
164 * Test converter (from Tajiki to latin orthography)
166 class TestConverter extends LanguageConverter {
167 private $table = array(
168 'б' => 'b',
169 'в' => 'v',
170 'г' => 'g',
173 function loadDefaultTables() {
174 $this->mTables = array(
175 'tg-latn' => new ReplacementArray( $this->table ),
176 'tg' => new ReplacementArray()
181 class LanguageToTest extends Language {
182 function __construct() {
183 parent::__construct();
184 $variants = array( 'tg', 'tg-latn' );
185 $this->mConverter = new TestConverter( $this, 'tg', $variants );