Index: trunk/phase3/tests/LanguageConverterTest.php |
— | — | @@ -7,8 +7,12 @@ |
8 | 8 | protected $lc = null; |
9 | 9 | |
10 | 10 | function setUp() { |
11 | | - global $wgMemc; |
| 11 | + global $wgMemc, $wgRequest, $wgUser, $wgContLang; |
| 12 | + |
| 13 | + $wgUser = new User; |
| 14 | + $wgRequest = new FauxRequest(array()); |
12 | 15 | $wgMemc = new FakeMemCachedClient; |
| 16 | + $wgContLang = Language::factory( 'tg' ); |
13 | 17 | $this->lang = new LanguageTest(); |
14 | 18 | $this->lc = new TestConverter( $this->lang, 'tg', |
15 | 19 | array( 'tg', 'tg-latn' ) ); |
— | — | @@ -21,92 +25,100 @@ |
22 | 26 | unset($this->lang); |
23 | 27 | } |
24 | 28 | |
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() { |
34 | 30 | $this->assertEquals('tg', $this->lc->getPreferredVariant(false, false)); |
35 | 31 | $this->assertEquals('tg', $this->lc->getPreferredVariant(false, true)); |
36 | 32 | $this->assertEquals('tg', $this->lc->getPreferredVariant(true, false)); |
37 | 33 | $this->assertEquals('tg', $this->lc->getPreferredVariant(true, true)); |
| 34 | + } |
38 | 35 | |
| 36 | + function testGetPreferredVariantHeaders() { |
| 37 | + global $wgRequest; |
39 | 38 | $wgRequest->setHeader('Accept-Language', 'tg-latn'); |
40 | | - $this->lc = new TestConverter( $this->lang, 'tg', |
41 | | - array( 'tg', 'tg-latn' ) ); |
| 39 | + |
42 | 40 | $this->assertEquals('tg', $this->lc->getPreferredVariant(false, false)); |
43 | 41 | $this->assertEquals('tg-latn', $this->lc->getPreferredVariant(false, true)); |
44 | 42 | $this->assertEquals('tg', $this->lc->getPreferredVariant(true, false)); |
45 | 43 | $this->assertEquals('tg', $this->lc->getPreferredVariant(true, true)); |
| 44 | + } |
46 | 45 | |
| 46 | + function testGetPreferredVariantHeaderWeight() { |
| 47 | + global $wgRequest; |
47 | 48 | $wgRequest->setHeader('Accept-Language', 'tg;q=1'); |
48 | | - $this->lc = new TestConverter( $this->lang, 'tg', |
49 | | - array( 'tg', 'tg-latn' ) ); |
| 49 | + |
50 | 50 | $this->assertEquals('tg', $this->lc->getPreferredVariant(false, false)); |
51 | 51 | $this->assertEquals('tg', $this->lc->getPreferredVariant(false, true)); |
52 | 52 | $this->assertEquals('tg', $this->lc->getPreferredVariant(true, false)); |
53 | 53 | $this->assertEquals('tg', $this->lc->getPreferredVariant(true, true)); |
| 54 | + } |
54 | 55 | |
| 56 | + function testGetPreferredVariantHeaderWeight2() { |
| 57 | + global $wgRequest; |
55 | 58 | $wgRequest->setHeader('Accept-Language', 'tg-latn;q=1'); |
56 | | - $this->lc = new TestConverter( $this->lang, 'tg', |
57 | | - array( 'tg', 'tg-latn' ) ); |
| 59 | + |
58 | 60 | $this->assertEquals('tg', $this->lc->getPreferredVariant(false, false)); |
59 | 61 | $this->assertEquals('tg-latn', $this->lc->getPreferredVariant(false, true)); |
60 | 62 | $this->assertEquals('tg', $this->lc->getPreferredVariant(true, false)); |
61 | 63 | $this->assertEquals('tg', $this->lc->getPreferredVariant(true, true)); |
| 64 | + } |
62 | 65 | |
| 66 | + function testGetPreferredVariantHeaderMulti() { |
| 67 | + global $wgRequest; |
63 | 68 | $wgRequest->setHeader('Accept-Language', 'en, tg-latn;q=1'); |
64 | | - $this->lc = new TestConverter( $this->lang, 'tg', |
65 | | - array( 'tg', 'tg-latn' ) ); |
| 69 | + |
66 | 70 | $this->assertEquals('tg', $this->lc->getPreferredVariant(false, false)); |
67 | 71 | $this->assertEquals('tg-latn', $this->lc->getPreferredVariant(false, true)); |
68 | 72 | $this->assertEquals('tg', $this->lc->getPreferredVariant(true, false)); |
69 | 73 | $this->assertEquals('tg', $this->lc->getPreferredVariant(true, true)); |
70 | | - $wgRequest->setHeader('Accept-Language', ''); |
| 74 | + } |
71 | 75 | |
72 | | - $wgUser = User::newFromId("admin"); |
73 | | - $wgContLang = Language::factory( 'tg-latn' ); |
| 76 | + function testGetPreferredVariantUserOption() { |
| 77 | + global $wgUser; |
| 78 | + |
| 79 | + $wgUser = new User; |
74 | 80 | $wgUser->setId(1); |
75 | 81 | $wgUser->setOption('variant', 'tg-latn'); |
76 | | - $this->lc = new TestConverter( $this->lang, 'tg', |
77 | | - array( 'tg', 'tg-latn' ) ); |
78 | 82 | |
79 | 83 | $this->assertEquals('tg', $this->lc->getPreferredVariant(false, false)); |
80 | 84 | $this->assertEquals('tg', $this->lc->getPreferredVariant(false, true)); |
81 | 85 | $this->assertEquals('tg-latn', $this->lc->getPreferredVariant(true, false)); |
82 | 86 | $this->assertEquals('tg-latn', $this->lc->getPreferredVariant(true, true)); |
| 87 | + } |
83 | 88 | |
| 89 | + function testGetPreferredVariantHeaderUserVsUrl() { |
| 90 | + global $wgRequest, $wgUser, $wgContLang; |
| 91 | + |
| 92 | + $wgContLang = Language::factory( 'tg-latn' ); |
84 | 93 | $wgRequest->setVal('variant', 'tg'); |
| 94 | + $wgUser = User::newFromId("admin"); |
| 95 | + $wgUser->setId(1); |
85 | 96 | $wgUser->setOption('variant', 'tg-latn'); // The user's data is ignored |
86 | 97 | // because the variant is set in the URL. |
87 | | - $this->lc = new TestConverter( $this->lang, 'tg', |
88 | | - array( 'tg', 'tg-latn' ) ); |
89 | 98 | $this->assertEquals('tg', $this->lc->getPreferredVariant(true, false)); |
90 | 99 | $this->assertEquals('tg', $this->lc->getPreferredVariant(true, true)); |
| 100 | + } |
91 | 101 | |
92 | | - $wgRequest->setVal('variant', null); |
| 102 | + |
| 103 | + function testGetPreferredVariantDefaultLanguageVariant() { |
| 104 | + global $wgDefaultLanguageVariant; |
| 105 | + |
93 | 106 | $wgDefaultLanguageVariant = 'tg-latn'; |
94 | | - $this->lc = new TestConverter( $this->lang, 'tg', |
95 | | - array( 'tg', 'tg-latn' ) ); |
96 | 107 | $this->assertEquals('tg-latn', $this->lc->getPreferredVariant(false, false)); |
97 | 108 | $this->assertEquals('tg-latn', $this->lc->getPreferredVariant(false, true)); |
98 | 109 | $this->assertEquals('tg-latn', $this->lc->getPreferredVariant(true, false)); |
99 | 110 | $this->assertEquals('tg-latn', $this->lc->getPreferredVariant(true, true)); |
| 111 | + } |
100 | 112 | |
| 113 | + function testGetPreferredVariantDefaultLanguageVsUrlVariant() { |
| 114 | + global $wgDefaultLanguageVariant, $wgRequest, $wgContLang; |
| 115 | + |
| 116 | + $wgContLang = Language::factory( 'tg-latn' ); |
| 117 | + $wgDefaultLanguageVariant = 'tg'; |
101 | 118 | $wgRequest->setVal('variant', null); |
102 | | - $wgDefaultLanguageVariant = 'tg'; |
103 | | - $this->lc = new TestConverter( $this->lang, 'tg', |
104 | | - array( 'tg', 'tg-latn' ) ); |
105 | 119 | $this->assertEquals('tg', $this->lc->getPreferredVariant(false, false)); |
106 | 120 | $this->assertEquals('tg', $this->lc->getPreferredVariant(false, true)); |
107 | 121 | $this->assertEquals('tg-latn', $this->lc->getPreferredVariant(true, false)); |
108 | 122 | $this->assertEquals('tg-latn', $this->lc->getPreferredVariant(true, true)); |
109 | | - |
110 | | - |
111 | 123 | } |
112 | 124 | } |
113 | 125 | |