3 class LanguageConverterTest
extends MediaWikiLangTestCase
{
4 protected $lang = null;
9 global $wgMemc, $wgRequest, $wgUser, $wgContLang;
12 $wgRequest = new FauxRequest( array() );
13 $wgMemc = new EmptyBagOStuff
;
14 $wgContLang = Language
::factory( 'tg' );
15 $this->lang
= new LanguageToTest();
16 $this->lc
= new TestConverter( $this->lang
, 'tg',
17 array( 'tg', 'tg-latn' ) );
28 function testGetPreferredVariantDefaults() {
29 $this->assertEquals( 'tg', $this->lc
->getPreferredVariant() );
32 function testGetPreferredVariantHeaders() {
34 $wgRequest->setHeader( 'Accept-Language', 'tg-latn' );
36 $this->assertEquals( 'tg-latn', $this->lc
->getPreferredVariant() );
39 function testGetPreferredVariantHeaderWeight() {
41 $wgRequest->setHeader( 'Accept-Language', 'tg;q=1' );
43 $this->assertEquals( 'tg', $this->lc
->getPreferredVariant() );
46 function testGetPreferredVariantHeaderWeight2() {
48 $wgRequest->setHeader( 'Accept-Language', 'tg-latn;q=1' );
50 $this->assertEquals( 'tg-latn', $this->lc
->getPreferredVariant() );
53 function testGetPreferredVariantHeaderMulti() {
55 $wgRequest->setHeader( 'Accept-Language', 'en, tg-latn;q=1' );
57 $this->assertEquals( 'tg-latn', $this->lc
->getPreferredVariant() );
60 function testGetPreferredVariantUserOption() {
64 $wgUser->load(); // from 'defaults'
66 $wgUser->mDataLoaded
= true;
67 $wgUser->mOptionsLoaded
= true;
68 $wgUser->setOption( 'variant', 'tg-latn' );
70 $this->assertEquals( 'tg-latn', $this->lc
->getPreferredVariant() );
73 function testGetPreferredVariantHeaderUserVsUrl() {
74 global $wgRequest, $wgUser, $wgContLang;
76 $wgContLang = Language
::factory( 'tg-latn' );
77 $wgRequest->setVal( 'variant', 'tg' );
78 $wgUser = User
::newFromId( "admin" );
80 $wgUser->mFrom
= 'defaults';
81 $wgUser->mOptionsLoaded
= true;
82 $wgUser->setOption( 'variant', 'tg-latn' ); // The user's data is ignored
83 // because the variant is set in the URL.
84 $this->assertEquals( 'tg', $this->lc
->getPreferredVariant() );
88 function testGetPreferredVariantDefaultLanguageVariant() {
89 global $wgDefaultLanguageVariant;
91 $wgDefaultLanguageVariant = 'tg-latn';
92 $this->assertEquals( 'tg-latn', $this->lc
->getPreferredVariant() );
95 function testGetPreferredVariantDefaultLanguageVsUrlVariant() {
96 global $wgDefaultLanguageVariant, $wgRequest, $wgContLang;
98 $wgContLang = Language
::factory( 'tg-latn' );
99 $wgDefaultLanguageVariant = 'tg';
100 $wgRequest->setVal( 'variant', null );
101 $this->assertEquals( 'tg', $this->lc
->getPreferredVariant() );
106 * Test converter (from Tajiki to latin orthography)
108 class TestConverter
extends LanguageConverter
{
109 private $table = array(
115 function loadDefaultTables() {
116 $this->mTables
= array(
117 'tg-latn' => new ReplacementArray( $this->table
),
118 'tg' => new ReplacementArray()
124 class LanguageToTest
extends Language
{
125 function __construct() {
126 parent
::__construct();
127 $variants = array( 'tg', 'tg-latn' );
128 $this->mConverter
= new TestConverter( $this, 'tg', $variants );