3 class LanguageConverterTest
extends MediaWikiLangTestCase
{
4 protected $lang = null;
7 protected function setUp() {
10 $this->setMwGlobals( array(
11 'wgContLang' => Language
::factory( 'tg' ),
12 'wgLanguageCode' => 'tg',
13 'wgDefaultLanguageVariant' => false,
14 'wgMemc' => new EmptyBagOStuff
,
15 'wgRequest' => new FauxRequest( array() ),
19 $this->lang
= new LanguageToTest();
20 $this->lc
= new TestConverter(
22 array( 'tg', 'tg-latn' )
26 protected function tearDown() {
33 function testGetPreferredVariantDefaults() {
34 $this->assertEquals( 'tg', $this->lc
->getPreferredVariant() );
37 function testGetPreferredVariantHeaders() {
39 $wgRequest->setHeader( 'Accept-Language', 'tg-latn' );
41 $this->assertEquals( 'tg-latn', $this->lc
->getPreferredVariant() );
44 function testGetPreferredVariantHeaderWeight() {
46 $wgRequest->setHeader( 'Accept-Language', 'tg;q=1' );
48 $this->assertEquals( 'tg', $this->lc
->getPreferredVariant() );
51 function testGetPreferredVariantHeaderWeight2() {
53 $wgRequest->setHeader( 'Accept-Language', 'tg-latn;q=1' );
55 $this->assertEquals( 'tg-latn', $this->lc
->getPreferredVariant() );
58 function testGetPreferredVariantHeaderMulti() {
60 $wgRequest->setHeader( 'Accept-Language', 'en, tg-latn;q=1' );
62 $this->assertEquals( 'tg-latn', $this->lc
->getPreferredVariant() );
65 function testGetPreferredVariantUserOption() {
69 $wgUser->load(); // from 'defaults'
71 $wgUser->mDataLoaded
= true;
72 $wgUser->mOptionsLoaded
= true;
73 $wgUser->setOption( 'variant', 'tg-latn' );
75 $this->assertEquals( 'tg-latn', $this->lc
->getPreferredVariant() );
78 function testGetPreferredVariantHeaderUserVsUrl() {
79 global $wgContLang, $wgRequest, $wgUser;
81 $wgContLang = Language
::factory( 'tg-latn' );
82 $wgRequest->setVal( 'variant', 'tg' );
83 $wgUser = User
::newFromId( "admin" );
85 $wgUser->mFrom
= 'defaults';
86 $wgUser->mOptionsLoaded
= true;
87 // The user's data is ignored because the variant is set in the URL.
88 $wgUser->setOption( 'variant', 'tg-latn' );
89 $this->assertEquals( 'tg', $this->lc
->getPreferredVariant() );
93 function testGetPreferredVariantDefaultLanguageVariant() {
94 global $wgDefaultLanguageVariant;
96 $wgDefaultLanguageVariant = 'tg-latn';
97 $this->assertEquals( 'tg-latn', $this->lc
->getPreferredVariant() );
100 function testGetPreferredVariantDefaultLanguageVsUrlVariant() {
101 global $wgDefaultLanguageVariant, $wgRequest, $wgContLang;
103 $wgContLang = Language
::factory( 'tg-latn' );
104 $wgDefaultLanguageVariant = 'tg';
105 $wgRequest->setVal( 'variant', null );
106 $this->assertEquals( 'tg', $this->lc
->getPreferredVariant() );
111 * Test converter (from Tajiki to latin orthography)
113 class TestConverter
extends LanguageConverter
{
114 private $table = array(
120 function loadDefaultTables() {
121 $this->mTables
= array(
122 'tg-latn' => new ReplacementArray( $this->table
),
123 'tg' => new ReplacementArray()
128 class LanguageToTest
extends Language
{
129 function __construct() {
130 parent
::__construct();
131 $variants = array( 'tg', 'tg-latn' );
132 $this->mConverter
= new TestConverter( $this, 'tg', $variants );