MediaWiki  1.23.8
LanguageConverterTest.php
Go to the documentation of this file.
1 <?php
2 
5  protected $lang = null;
7  protected $lc = null;
8 
9  protected function setUp() {
10  parent::setUp();
11 
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  ) );
20 
21  $this->lang = new LanguageToTest();
22  $this->lc = new TestConverter(
23  $this->lang, 'tg',
24  array( 'tg', 'tg-latn' )
25  );
26  }
27 
28  protected function tearDown() {
29  unset( $this->lc );
30  unset( $this->lang );
31 
32  parent::tearDown();
33  }
34 
38  public function testGetPreferredVariantDefaults() {
39  $this->assertEquals( 'tg', $this->lc->getPreferredVariant() );
40  }
41 
46  public function testGetPreferredVariantHeaders() {
47  global $wgRequest;
48  $wgRequest->setHeader( 'Accept-Language', 'tg-latn' );
49 
50  $this->assertEquals( 'tg-latn', $this->lc->getPreferredVariant() );
51  }
52 
57  public function testGetPreferredVariantHeaderWeight() {
58  global $wgRequest;
59  $wgRequest->setHeader( 'Accept-Language', 'tg;q=1' );
60 
61  $this->assertEquals( 'tg', $this->lc->getPreferredVariant() );
62  }
63 
68  public function testGetPreferredVariantHeaderWeight2() {
69  global $wgRequest;
70  $wgRequest->setHeader( 'Accept-Language', 'tg-latn;q=1' );
71 
72  $this->assertEquals( 'tg-latn', $this->lc->getPreferredVariant() );
73  }
74 
79  public function testGetPreferredVariantHeaderMulti() {
80  global $wgRequest;
81  $wgRequest->setHeader( 'Accept-Language', 'en, tg-latn;q=1' );
82 
83  $this->assertEquals( 'tg-latn', $this->lc->getPreferredVariant() );
84  }
85 
89  public function testGetPreferredVariantUserOption() {
91 
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' );
98 
99  $this->assertEquals( 'tg-latn', $this->lc->getPreferredVariant() );
100  }
101 
108 
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' );
116 
117  $this->assertEquals( 'tg-latn', $this->lc->getPreferredVariant() );
118  }
119 
125  public function testGetPreferredVariantHeaderUserVsUrl() {
126  global $wgContLang, $wgRequest, $wgUser;
127 
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() );
137  }
138 
143  global $wgDefaultLanguageVariant;
144 
145  $wgDefaultLanguageVariant = 'tg-latn';
146  $this->assertEquals( 'tg-latn', $this->lc->getPreferredVariant() );
147  }
148 
154  global $wgDefaultLanguageVariant, $wgRequest, $wgContLang;
155 
156  $wgContLang = Language::factory( 'tg-latn' );
157  $wgDefaultLanguageVariant = 'tg';
158  $wgRequest->setVal( 'variant', null );
159  $this->assertEquals( 'tg', $this->lc->getPreferredVariant() );
160  }
161 }
162 
166 class TestConverter extends LanguageConverter {
167  private $table = array(
168  'б' => 'b',
169  'в' => 'v',
170  'г' => 'g',
171  );
172 
173  function loadDefaultTables() {
174  $this->mTables = array(
175  'tg-latn' => new ReplacementArray( $this->table ),
176  'tg' => new ReplacementArray()
177  );
178  }
179 }
180 
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 );
186  }
187 }
$wgUser
$wgUser
Definition: Setup.php:552
FauxRequest
WebRequest clone which takes values from a provided array.
Definition: WebRequest.php:1275
User\newFromId
static newFromId( $id)
Static factory method for creation from a given user ID.
Definition: User.php:412
php
skin txt MediaWiki includes four core it has been set as the default in MediaWiki since the replacing Monobook it had been been the default skin since before being replaced by Vector largely rewritten in while keeping its appearance Several legacy skins were removed in the as the burden of supporting them became too heavy to bear Those in etc for skin dependent CSS etc for skin dependent JavaScript These can also be customised on a per user by etc This feature has led to a wide variety of user styles becoming that gallery is a good place to ending in php
Definition: skin.txt:62
LanguageConverterTest\$lc
TestConverter $lc
Definition: LanguageConverterTest.php:5
EmptyBagOStuff
A BagOStuff object with no objects in it.
Definition: EmptyBagOStuff.php:29
LanguageConverterTest\testGetPreferredVariantDefaults
testGetPreferredVariantDefaults()
@covers LanguageConverter::getPreferredVariant
Definition: LanguageConverterTest.php:36
LanguageToTest\__construct
__construct()
Definition: LanguageConverterTest.php:180
LanguageConverterTest\testGetPreferredVariantUserOptionForForeignLanguage
testGetPreferredVariantUserOptionForForeignLanguage()
@covers LanguageConverter::getPreferredVariant @covers LanguageConverter::getUserVariant
Definition: LanguageConverterTest.php:104
$wgContLang
this class mediates it Skin Encapsulates a look and feel for the wiki All of the functions that render HTML and make choices about how to render it are here and are called from various other places when and is meant to be subclassed with other skins that may override some of its functions The User object contains a reference to a and so rather than having a global skin object we just rely on the global User and get the skin with $wgUser and also has some character encoding functions and other locale stuff The current user interface language is instantiated as and the content language as $wgContLang
Definition: design.txt:56
LanguageConverterTest\$lang
LanguageToTest $lang
Definition: LanguageConverterTest.php:4
LanguageConverterTest\testGetPreferredVariantHeaderWeight2
testGetPreferredVariantHeaderWeight2()
@covers LanguageConverter::getPreferredVariant @covers LanguageConverter::getHeaderVariant
Definition: LanguageConverterTest.php:66
LanguageConverterTest\testGetPreferredVariantUserOption
testGetPreferredVariantUserOption()
@covers LanguageConverter::getPreferredVariant
Definition: LanguageConverterTest.php:87
TestConverter
Test converter (from Tajiki to latin orthography)
Definition: LanguageConverterTest.php:164
table
deferred txt A few of the database updates required by various functions here can be deferred until after the result page is displayed to the user For updating the view updating the linked to tables after a etc PHP does not yet have any way to tell the server to actually return and disconnect while still running these but it might have such a feature in the future We handle these by creating a deferred update object and putting those objects on a global then executing the whole list after the page is displayed We don t do anything smart like collating updates to the same table or such because the list is almost always going to have just one item on if so it s not worth the trouble Since there is a job queue in the jobs table
Definition: deferred.txt:11
MediaWikiTestCase\setMwGlobals
setMwGlobals( $pairs, $value=null)
Definition: MediaWikiTestCase.php:302
TestConverter\loadDefaultTables
loadDefaultTables()
Definition: LanguageConverterTest.php:171
LanguageConverterTest\tearDown
tearDown()
Definition: LanguageConverterTest.php:26
LanguageConverterTest
Definition: LanguageConverterTest.php:3
array
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.
LanguageConverterTest\setUp
setUp()
Definition: LanguageConverterTest.php:7
global
when a variable name is used in a it is silently declared as a new masking the global
Definition: design.txt:93
ReplacementArray
Replacement array for FSS with fallback to strtr() Supports lazy initialisation of FSS resource.
Definition: StringUtils.php:411
MediaWikiLangTestCase
Base class that store and restore the Language objects.
Definition: MediaWikiLangTestCase.php:6
LanguageConverterTest\testGetPreferredVariantDefaultLanguageVsUrlVariant
testGetPreferredVariantDefaultLanguageVsUrlVariant()
@covers LanguageConverter::getPreferredVariant @covers LanguageConverter::getURLVariant
Definition: LanguageConverterTest.php:151
TestConverter\$table
$table
Definition: LanguageConverterTest.php:165
LanguageConverterTest\testGetPreferredVariantHeaderUserVsUrl
testGetPreferredVariantHeaderUserVsUrl()
@covers LanguageConverter::getPreferredVariant @covers LanguageConverter::getUserVariant @covers Lang...
Definition: LanguageConverterTest.php:123
LanguageConverterTest\testGetPreferredVariantDefaultLanguageVariant
testGetPreferredVariantDefaultLanguageVariant()
@covers LanguageConverter::getPreferredVariant
Definition: LanguageConverterTest.php:140
LanguageConverterTest\testGetPreferredVariantHeaders
testGetPreferredVariantHeaders()
@covers LanguageConverter::getPreferredVariant @covers LanguageConverter::getHeaderVariant
Definition: LanguageConverterTest.php:44
User
User
Definition: All_system_messages.txt:425
LanguageToTest
Definition: LanguageConverterTest.php:179
Language\factory
static factory( $code)
Get a cached or new language object for a given language code.
Definition: Language.php:184
LanguageConverterTest\testGetPreferredVariantHeaderWeight
testGetPreferredVariantHeaderWeight()
@covers LanguageConverter::getPreferredVariant @covers LanguageConverter::getHeaderVariant
Definition: LanguageConverterTest.php:55
LanguageConverterTest\testGetPreferredVariantHeaderMulti
testGetPreferredVariantHeaderMulti()
@covers LanguageConverter::getPreferredVariant @covers LanguageConverter::getHeaderVariant
Definition: LanguageConverterTest.php:77
User
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
Definition: User.php:59
Language
Internationalisation code.
Definition: Language.php:74