6 use Shaarli\Config\ConfigManager
;
9 * Class LanguagesFrTest
11 * Test the translation system in PHP and gettext mode with French language.
15 class LanguagesFrTest
extends \PHPUnit\Framework\TestCase
18 * @var string Config file path (without extension).
20 protected static $configFile = 'tests/utils/config/configJson';
30 public function setUp()
32 $this->conf
= new ConfigManager(self
::$configFile);
33 $this->conf
->set('translation.language', 'fr');
37 * Reset the locale since gettext seems to mess with it, making it too long
39 public static function tearDownAfterClass()
41 if (! empty(getenv('UT_LOCALE'))) {
42 setlocale(LC_ALL
, getenv('UT_LOCALE'));
47 * Test t() with a simple non identified value.
49 public function testTranslateSingleNotIDGettext()
51 $this->conf
->set('translation.mode', 'gettext');
52 new Languages('en', $this->conf
);
53 $text = 'abcdé 564 fgK';
54 $this->assertEquals($text, t($text));
58 * Test t() with a simple identified value in gettext mode.
60 public function testTranslateSingleIDGettext()
62 $this->conf
->set('translation.mode', 'gettext');
63 new Languages('en', $this->conf
);
65 $this->assertEquals('permalien', t($text));
69 * Test t() with a non identified plural form in gettext mode.
71 public function testTranslatePluralNotIDGettext()
73 $this->conf
->set('translation.mode', 'gettext');
74 new Languages('en', $this->conf
);
76 $nText = 'sandwiches';
77 // Not ID, so English fallback, and in english, plural 0
78 $this->assertEquals('sandwiches', t($text, $nText, 0));
79 $this->assertEquals('sandwich', t($text, $nText, 1));
80 $this->assertEquals('sandwiches', t($text, $nText, 2));
84 * Test t() with an identified plural form in gettext mode.
86 public function testTranslatePluralIDGettext()
88 $this->conf
->set('translation.mode', 'gettext');
89 new Languages('en', $this->conf
);
92 $this->assertEquals('shaare', t($text, $nText, 0));
93 $this->assertEquals('shaare', t($text, $nText, 1));
94 $this->assertEquals('shaares', t($text, $nText, 2));
98 * Test t() with a simple non identified value.
100 public function testTranslateSingleNotIDPhp()
102 $this->conf
->set('translation.mode', 'php');
103 new Languages('en', $this->conf
);
104 $text = 'abcdé 564 fgK';
105 $this->assertEquals($text, t($text));
109 * Test t() with a simple identified value in PHP mode.
111 public function testTranslateSingleIDPhp()
113 $this->conf
->set('translation.mode', 'php');
114 new Languages('en', $this->conf
);
116 $this->assertEquals('permalien', t($text));
120 * Test t() with a non identified plural form in PHP mode.
122 public function testTranslatePluralNotIDPhp()
124 $this->conf
->set('translation.mode', 'php');
125 new Languages('en', $this->conf
);
127 $nText = 'sandwiches';
128 // Not ID, so English fallback, and in english, plural 0
129 $this->assertEquals('sandwiches', t($text, $nText, 0));
130 $this->assertEquals('sandwich', t($text, $nText, 1));
131 $this->assertEquals('sandwiches', t($text, $nText, 2));
135 * Test t() with an identified plural form in PHP mode.
137 public function testTranslatePluralIDPhp()
139 $this->conf
->set('translation.mode', 'php');
140 new Languages('en', $this->conf
);
143 // In english, zero is followed by plural form
144 $this->assertEquals('shaare', t($text, $nText, 0));
145 $this->assertEquals('shaare', t($text, $nText, 1));
146 $this->assertEquals('shaares', t($text, $nText, 2));
150 * Test t() with an extension language file in gettext mode
152 public function testTranslationExtensionGettext()
154 $this->conf
->set('translation.mode', 'gettext');
155 $this->conf
->set('translation.extensions.test', 'tests/utils/languages/');
156 new Languages('en', $this->conf
);
157 $txt = 'car'; // ignore me poedit
158 $this->assertEquals('voiture', t($txt, $txt, 1, 'test'));
159 $this->assertEquals('Fouille', t('Search', 'Search', 1, 'test'));
163 * Test t() with an extension language file in PHP mode
165 public function testTranslationExtensionPhp()
167 $this->conf
->set('translation.mode', 'php');
168 $this->conf
->set('translation.extensions.test', 'tests/utils/languages/');
169 new Languages('en', $this->conf
);
170 $txt = 'car'; // ignore me poedit
171 $this->assertEquals('voiture', t($txt, $txt, 1, 'test'));
172 $this->assertEquals('Fouille', t('Search', 'Search', 1, 'test'));
176 * Test t() with an extension language file coming from the theme in gettext mode
178 public function testTranslationThemeExtensionGettext()
180 $this->conf
->set('translation.mode', 'gettext');
181 $this->conf
->set('raintpl_tpl', 'tests/utils/customtpl/');
182 $this->conf
->set('theme', 'dummy');
183 new Languages('en', $this->conf
);
184 $txt = 'rooster'; // ignore me poedit
185 $this->assertEquals('coq', t($txt, $txt, 1, 'dummy'));
189 * Test t() with an extension language file coming from the theme in PHP mode
191 public function testTranslationThemeExtensionPhp()
193 $this->conf
->set('translation.mode', 'php');
194 $this->conf
->set('raintpl_tpl', 'tests/utils/customtpl/');
195 $this->conf
->set('theme', 'dummy');
196 new Languages('en', $this->conf
);
197 $txt = 'rooster'; // ignore me poedit
198 $this->assertEquals('coq', t($txt, $txt, 1, 'dummy'));