]>
Commit | Line | Data |
---|---|---|
edf3ff5a A |
1 | <?php |
2 | ||
12266213 A |
3 | namespace Shaarli; |
4 | ||
5 | use Shaarli\Config\ConfigManager; | |
edf3ff5a A |
6 | |
7 | /** | |
8 | * Class LanguagesTest. | |
9 | */ | |
12266213 | 10 | class LanguagesTest extends \PHPUnit_Framework_TestCase |
edf3ff5a | 11 | { |
12266213 A |
12 | /** |
13 | * @var string Config file path (without extension). | |
14 | */ | |
15 | protected static $configFile = 'tests/utils/config/configJson'; | |
16 | ||
17 | /** | |
18 | * @var ConfigManager | |
19 | */ | |
20 | protected $conf; | |
21 | ||
22 | /** | |
23 | * | |
24 | */ | |
25 | public function setUp() | |
26 | { | |
27 | $this->conf = new ConfigManager(self::$configFile); | |
28 | } | |
29 | ||
30 | /** | |
31 | * Test t() with a simple non identified value. | |
32 | */ | |
33 | public function testTranslateSingleNotIDGettext() | |
34 | { | |
35 | $this->conf->set('translation.mode', 'gettext'); | |
36 | new Languages('en', $this->conf); | |
37 | $text = 'abcdé 564 fgK'; | |
38 | $this->assertEquals($text, t($text)); | |
39 | } | |
40 | ||
41 | /** | |
42 | * Test t() with a simple identified value in gettext mode. | |
43 | */ | |
44 | public function testTranslateSingleIDGettext() | |
45 | { | |
46 | $this->conf->set('translation.mode', 'gettext'); | |
47 | new Languages('en', $this->conf); | |
48 | $text = 'permalink'; | |
49 | $this->assertEquals($text, t($text)); | |
50 | } | |
51 | ||
52 | /** | |
53 | * Test t() with a non identified plural form in gettext mode. | |
54 | */ | |
55 | public function testTranslatePluralNotIDGettext() | |
56 | { | |
57 | $this->conf->set('translation.mode', 'gettext'); | |
58 | new Languages('en', $this->conf); | |
59 | $text = 'sandwich'; | |
60 | $nText = 'sandwiches'; | |
61 | $this->assertEquals('sandwiches', t($text, $nText, 0)); | |
62 | $this->assertEquals('sandwich', t($text, $nText, 1)); | |
63 | $this->assertEquals('sandwiches', t($text, $nText, 2)); | |
64 | } | |
65 | ||
66 | /** | |
67 | * Test t() with an identified plural form in gettext mode. | |
68 | */ | |
69 | public function testTranslatePluralIDGettext() | |
70 | { | |
71 | $this->conf->set('translation.mode', 'gettext'); | |
72 | new Languages('en', $this->conf); | |
73 | $text = 'shaare'; | |
74 | $nText = 'shaares'; | |
75 | // In english, zero is followed by plural form | |
76 | $this->assertEquals('shaares', t($text, $nText, 0)); | |
77 | $this->assertEquals('shaare', t($text, $nText, 1)); | |
78 | $this->assertEquals('shaares', t($text, $nText, 2)); | |
79 | } | |
80 | ||
edf3ff5a A |
81 | /** |
82 | * Test t() with a simple non identified value. | |
83 | */ | |
12266213 | 84 | public function testTranslateSingleNotIDPhp() |
edf3ff5a | 85 | { |
12266213 A |
86 | $this->conf->set('translation.mode', 'php'); |
87 | new Languages('en', $this->conf); | |
edf3ff5a A |
88 | $text = 'abcdé 564 fgK'; |
89 | $this->assertEquals($text, t($text)); | |
90 | } | |
91 | ||
92 | /** | |
12266213 | 93 | * Test t() with a simple identified value in PHP mode. |
edf3ff5a | 94 | */ |
12266213 | 95 | public function testTranslateSingleIDPhp() |
edf3ff5a | 96 | { |
12266213 A |
97 | $this->conf->set('translation.mode', 'php'); |
98 | new Languages('en', $this->conf); | |
99 | $text = 'permalink'; | |
100 | $this->assertEquals($text, t($text)); | |
edf3ff5a A |
101 | } |
102 | ||
103 | /** | |
12266213 | 104 | * Test t() with a non identified plural form in PHP mode. |
edf3ff5a | 105 | */ |
12266213 | 106 | public function testTranslatePluralNotIDPhp() |
edf3ff5a | 107 | { |
12266213 A |
108 | $this->conf->set('translation.mode', 'php'); |
109 | new Languages('en', $this->conf); | |
edf3ff5a A |
110 | $text = 'sandwich'; |
111 | $nText = 'sandwiches'; | |
12266213 | 112 | $this->assertEquals('sandwiches', t($text, $nText, 0)); |
edf3ff5a A |
113 | $this->assertEquals('sandwich', t($text, $nText, 1)); |
114 | $this->assertEquals('sandwiches', t($text, $nText, 2)); | |
115 | } | |
12266213 A |
116 | |
117 | /** | |
118 | * Test t() with an identified plural form in PHP mode. | |
119 | */ | |
120 | public function testTranslatePluralIDPhp() | |
121 | { | |
122 | $this->conf->set('translation.mode', 'php'); | |
123 | new Languages('en', $this->conf); | |
124 | $text = 'shaare'; | |
125 | $nText = 'shaares'; | |
126 | // In english, zero is followed by plural form | |
127 | $this->assertEquals('shaares', t($text, $nText, 0)); | |
128 | $this->assertEquals('shaare', t($text, $nText, 1)); | |
129 | $this->assertEquals('shaares', t($text, $nText, 2)); | |
130 | } | |
131 | ||
132 | /** | |
133 | * Test t() with an invalid language set in the configuration in gettext mode. | |
134 | */ | |
135 | public function testTranslateWithInvalidConfLanguageGettext() | |
136 | { | |
137 | $this->conf->set('translation.mode', 'gettext'); | |
138 | $this->conf->set('translation.language', 'nope'); | |
139 | new Languages('fr', $this->conf); | |
140 | $text = 'grumble'; | |
141 | $this->assertEquals($text, t($text)); | |
142 | } | |
143 | ||
144 | /** | |
145 | * Test t() with an invalid language set in the configuration in PHP mode. | |
146 | */ | |
147 | public function testTranslateWithInvalidConfLanguagePhp() | |
148 | { | |
149 | $this->conf->set('translation.mode', 'php'); | |
150 | $this->conf->set('translation.language', 'nope'); | |
151 | new Languages('fr', $this->conf); | |
152 | $text = 'grumble'; | |
153 | $this->assertEquals($text, t($text)); | |
154 | } | |
155 | ||
156 | /** | |
157 | * Test t() with an invalid language set with auto language in gettext mode. | |
158 | */ | |
159 | public function testTranslateWithInvalidAutoLanguageGettext() | |
160 | { | |
161 | $this->conf->set('translation.mode', 'gettext'); | |
162 | new Languages('nope', $this->conf); | |
163 | $text = 'grumble'; | |
164 | $this->assertEquals($text, t($text)); | |
165 | } | |
166 | ||
167 | /** | |
168 | * Test t() with an invalid language set with auto language in PHP mode. | |
169 | */ | |
170 | public function testTranslateWithInvalidAutoLanguagePhp() | |
171 | { | |
172 | $this->conf->set('translation.mode', 'php'); | |
173 | new Languages('nope', $this->conf); | |
174 | $text = 'grumble'; | |
175 | $this->assertEquals($text, t($text)); | |
176 | } | |
177 | ||
178 | /** | |
179 | * Test t() with an extension language file in gettext mode | |
180 | */ | |
181 | public function testTranslationExtensionGettext() | |
182 | { | |
183 | $this->conf->set('translation.mode', 'gettext'); | |
184 | $this->conf->set('translation.extensions.test', 'tests/utils/languages/'); | |
185 | new Languages('en', $this->conf); | |
f39580c6 A |
186 | $txt = 'car'; // ignore me poedit |
187 | $this->assertEquals('car', t($txt, $txt, 1, 'test')); | |
12266213 A |
188 | $this->assertEquals('Search', t('Search', 'Search', 1, 'test')); |
189 | } | |
190 | ||
191 | /** | |
192 | * Test t() with an extension language file in PHP mode | |
193 | */ | |
194 | public function testTranslationExtensionPhp() | |
195 | { | |
196 | $this->conf->set('translation.mode', 'php'); | |
197 | $this->conf->set('translation.extensions.test', 'tests/utils/languages/'); | |
198 | new Languages('en', $this->conf); | |
f39580c6 A |
199 | $txt = 'car'; // ignore me poedit |
200 | $this->assertEquals('car', t($txt, $txt, 1, 'test')); | |
12266213 A |
201 | $this->assertEquals('Search', t('Search', 'Search', 1, 'test')); |
202 | } | |
edf3ff5a | 203 | } |