]> git.immae.eu Git - github/shaarli/Shaarli.git/blob - tests/LanguagesTest.php
Optimize and cleanup imports
[github/shaarli/Shaarli.git] / tests / LanguagesTest.php
1 <?php
2
3 namespace Shaarli;
4
5 use Shaarli\Config\ConfigManager;
6
7 /**
8 * Class LanguagesTest.
9 */
10 class LanguagesTest extends \PHPUnit\Framework\TestCase
11 {
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
81 /**
82 * Test t() with a simple non identified value.
83 */
84 public function testTranslateSingleNotIDPhp()
85 {
86 $this->conf->set('translation.mode', 'php');
87 new Languages('en', $this->conf);
88 $text = 'abcdé 564 fgK';
89 $this->assertEquals($text, t($text));
90 }
91
92 /**
93 * Test t() with a simple identified value in PHP mode.
94 */
95 public function testTranslateSingleIDPhp()
96 {
97 $this->conf->set('translation.mode', 'php');
98 new Languages('en', $this->conf);
99 $text = 'permalink';
100 $this->assertEquals($text, t($text));
101 }
102
103 /**
104 * Test t() with a non identified plural form in PHP mode.
105 */
106 public function testTranslatePluralNotIDPhp()
107 {
108 $this->conf->set('translation.mode', 'php');
109 new Languages('en', $this->conf);
110 $text = 'sandwich';
111 $nText = 'sandwiches';
112 $this->assertEquals('sandwiches', t($text, $nText, 0));
113 $this->assertEquals('sandwich', t($text, $nText, 1));
114 $this->assertEquals('sandwiches', t($text, $nText, 2));
115 }
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 coming from the theme in gettext mode
180 */
181 public function testTranslationThemeExtensionGettext()
182 {
183 $this->conf->set('translation.mode', 'gettext');
184 $this->conf->set('raintpl_tpl', 'tests/utils/customtpl/');
185 $this->conf->set('theme', 'dummy');
186 new Languages('en', $this->conf);
187 $txt = 'rooster'; // ignore me poedit
188 $this->assertEquals('rooster', t($txt, $txt, 1, 'dummy'));
189 }
190
191 /**
192 * Test t() with an extension language file coming from the theme in PHP mode
193 */
194 public function testTranslationThemeExtensionPhp()
195 {
196 $this->conf->set('translation.mode', 'php');
197 $this->conf->set('raintpl_tpl', 'tests/utils/customtpl/');
198 $this->conf->set('theme', 'dummy');
199 new Languages('en', $this->conf);
200 $txt = 'rooster'; // ignore me poedit
201 $this->assertEquals('rooster', t($txt, $txt, 1, 'dummy'));
202 }
203
204 /**
205 * Test t() with an extension language file in gettext mode
206 */
207 public function testTranslationExtensionGettext()
208 {
209 $this->conf->set('translation.mode', 'gettext');
210 $this->conf->set('translation.extensions.test', 'tests/utils/languages/');
211 new Languages('en', $this->conf);
212 $txt = 'car'; // ignore me poedit
213 $this->assertEquals('car', t($txt, $txt, 1, 'test'));
214 $this->assertEquals('Search', t('Search', 'Search', 1, 'test'));
215 }
216
217 /**
218 * Test t() with an extension language file in PHP mode
219 */
220 public function testTranslationExtensionPhp()
221 {
222 $this->conf->set('translation.mode', 'php');
223 $this->conf->set('translation.extensions.test', 'tests/utils/languages/');
224 new Languages('en', $this->conf);
225 $txt = 'car'; // ignore me poedit
226 $this->assertEquals('car', t($txt, $txt, 1, 'test'));
227 $this->assertEquals('Search', t('Search', 'Search', 1, 'test'));
228 }
229 }