r61561 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r61560‎ | r61561 | r61562 >
Date:06:58, 27 January 2010
Author:mah
Status:ok
Tags:
Comment:
Break up tests so problems are easier to track down.
Modified paths:
  • /trunk/phase3/tests/LanguageConverterTest.php (modified) (history)

Diff [purge]

Index: trunk/phase3/tests/LanguageConverterTest.php
@@ -7,8 +7,12 @@
88 protected $lc = null;
99
1010 function setUp() {
11 - global $wgMemc;
 11+ global $wgMemc, $wgRequest, $wgUser, $wgContLang;
 12+
 13+ $wgUser = new User;
 14+ $wgRequest = new FauxRequest(array());
1215 $wgMemc = new FakeMemCachedClient;
 16+ $wgContLang = Language::factory( 'tg' );
1317 $this->lang = new LanguageTest();
1418 $this->lc = new TestConverter( $this->lang, 'tg',
1519 array( 'tg', 'tg-latn' ) );
@@ -21,92 +25,100 @@
2226 unset($this->lang);
2327 }
2428
25 - function testGetPreferredVariant() {
26 - global $wgRequest, $wgUsePathInfo, $wgLanguageCode,
27 - $wgVariantArticlePath, $wgUser, $wgContLang,
28 - $wgDefaultLanguageVariant;
29 -
30 - $wgRequest = new FauxRequest(array());
31 - $wgUser = new User;
32 - $wgContLang = Language::factory( 'tg' );
33 -
 29+ function testGetPreferredVariantDefaults() {
3430 $this->assertEquals('tg', $this->lc->getPreferredVariant(false, false));
3531 $this->assertEquals('tg', $this->lc->getPreferredVariant(false, true));
3632 $this->assertEquals('tg', $this->lc->getPreferredVariant(true, false));
3733 $this->assertEquals('tg', $this->lc->getPreferredVariant(true, true));
 34+ }
3835
 36+ function testGetPreferredVariantHeaders() {
 37+ global $wgRequest;
3938 $wgRequest->setHeader('Accept-Language', 'tg-latn');
40 - $this->lc = new TestConverter( $this->lang, 'tg',
41 - array( 'tg', 'tg-latn' ) );
 39+
4240 $this->assertEquals('tg', $this->lc->getPreferredVariant(false, false));
4341 $this->assertEquals('tg-latn', $this->lc->getPreferredVariant(false, true));
4442 $this->assertEquals('tg', $this->lc->getPreferredVariant(true, false));
4543 $this->assertEquals('tg', $this->lc->getPreferredVariant(true, true));
 44+ }
4645
 46+ function testGetPreferredVariantHeaderWeight() {
 47+ global $wgRequest;
4748 $wgRequest->setHeader('Accept-Language', 'tg;q=1');
48 - $this->lc = new TestConverter( $this->lang, 'tg',
49 - array( 'tg', 'tg-latn' ) );
 49+
5050 $this->assertEquals('tg', $this->lc->getPreferredVariant(false, false));
5151 $this->assertEquals('tg', $this->lc->getPreferredVariant(false, true));
5252 $this->assertEquals('tg', $this->lc->getPreferredVariant(true, false));
5353 $this->assertEquals('tg', $this->lc->getPreferredVariant(true, true));
 54+ }
5455
 56+ function testGetPreferredVariantHeaderWeight2() {
 57+ global $wgRequest;
5558 $wgRequest->setHeader('Accept-Language', 'tg-latn;q=1');
56 - $this->lc = new TestConverter( $this->lang, 'tg',
57 - array( 'tg', 'tg-latn' ) );
 59+
5860 $this->assertEquals('tg', $this->lc->getPreferredVariant(false, false));
5961 $this->assertEquals('tg-latn', $this->lc->getPreferredVariant(false, true));
6062 $this->assertEquals('tg', $this->lc->getPreferredVariant(true, false));
6163 $this->assertEquals('tg', $this->lc->getPreferredVariant(true, true));
 64+ }
6265
 66+ function testGetPreferredVariantHeaderMulti() {
 67+ global $wgRequest;
6368 $wgRequest->setHeader('Accept-Language', 'en, tg-latn;q=1');
64 - $this->lc = new TestConverter( $this->lang, 'tg',
65 - array( 'tg', 'tg-latn' ) );
 69+
6670 $this->assertEquals('tg', $this->lc->getPreferredVariant(false, false));
6771 $this->assertEquals('tg-latn', $this->lc->getPreferredVariant(false, true));
6872 $this->assertEquals('tg', $this->lc->getPreferredVariant(true, false));
6973 $this->assertEquals('tg', $this->lc->getPreferredVariant(true, true));
70 - $wgRequest->setHeader('Accept-Language', '');
 74+ }
7175
72 - $wgUser = User::newFromId("admin");
73 - $wgContLang = Language::factory( 'tg-latn' );
 76+ function testGetPreferredVariantUserOption() {
 77+ global $wgUser;
 78+
 79+ $wgUser = new User;
7480 $wgUser->setId(1);
7581 $wgUser->setOption('variant', 'tg-latn');
76 - $this->lc = new TestConverter( $this->lang, 'tg',
77 - array( 'tg', 'tg-latn' ) );
7882
7983 $this->assertEquals('tg', $this->lc->getPreferredVariant(false, false));
8084 $this->assertEquals('tg', $this->lc->getPreferredVariant(false, true));
8185 $this->assertEquals('tg-latn', $this->lc->getPreferredVariant(true, false));
8286 $this->assertEquals('tg-latn', $this->lc->getPreferredVariant(true, true));
 87+ }
8388
 89+ function testGetPreferredVariantHeaderUserVsUrl() {
 90+ global $wgRequest, $wgUser, $wgContLang;
 91+
 92+ $wgContLang = Language::factory( 'tg-latn' );
8493 $wgRequest->setVal('variant', 'tg');
 94+ $wgUser = User::newFromId("admin");
 95+ $wgUser->setId(1);
8596 $wgUser->setOption('variant', 'tg-latn'); // The user's data is ignored
8697 // because the variant is set in the URL.
87 - $this->lc = new TestConverter( $this->lang, 'tg',
88 - array( 'tg', 'tg-latn' ) );
8998 $this->assertEquals('tg', $this->lc->getPreferredVariant(true, false));
9099 $this->assertEquals('tg', $this->lc->getPreferredVariant(true, true));
 100+ }
91101
92 - $wgRequest->setVal('variant', null);
 102+
 103+ function testGetPreferredVariantDefaultLanguageVariant() {
 104+ global $wgDefaultLanguageVariant;
 105+
93106 $wgDefaultLanguageVariant = 'tg-latn';
94 - $this->lc = new TestConverter( $this->lang, 'tg',
95 - array( 'tg', 'tg-latn' ) );
96107 $this->assertEquals('tg-latn', $this->lc->getPreferredVariant(false, false));
97108 $this->assertEquals('tg-latn', $this->lc->getPreferredVariant(false, true));
98109 $this->assertEquals('tg-latn', $this->lc->getPreferredVariant(true, false));
99110 $this->assertEquals('tg-latn', $this->lc->getPreferredVariant(true, true));
 111+ }
100112
 113+ function testGetPreferredVariantDefaultLanguageVsUrlVariant() {
 114+ global $wgDefaultLanguageVariant, $wgRequest, $wgContLang;
 115+
 116+ $wgContLang = Language::factory( 'tg-latn' );
 117+ $wgDefaultLanguageVariant = 'tg';
101118 $wgRequest->setVal('variant', null);
102 - $wgDefaultLanguageVariant = 'tg';
103 - $this->lc = new TestConverter( $this->lang, 'tg',
104 - array( 'tg', 'tg-latn' ) );
105119 $this->assertEquals('tg', $this->lc->getPreferredVariant(false, false));
106120 $this->assertEquals('tg', $this->lc->getPreferredVariant(false, true));
107121 $this->assertEquals('tg-latn', $this->lc->getPreferredVariant(true, false));
108122 $this->assertEquals('tg-latn', $this->lc->getPreferredVariant(true, true));
109 -
110 -
111123 }
112124 }
113125

Status & tagging log