7 use Shaarli\Config\ConfigManager
;
10 * Class LanguagesFrTest
12 * Test the translation system in PHP and gettext mode with French language.
16 class LanguagesFrTest
extends \PHPUnit_Framework_TestCase
19 * @var string Config file path (without extension).
21 protected static $configFile = 'tests/utils/config/configJson';
31 public function setUp()
33 $this->conf
= new ConfigManager(self
::$configFile);
34 $this->conf
->set('translation.language', 'fr');
38 * Reset the locale since gettext seems to mess with it, making it too long
40 public static function tearDownAfterClass()
42 if (! empty(getenv('UT_LOCALE'))) {
43 setlocale(LC_ALL
, getenv('UT_LOCALE'));
48 * Test t() with a simple non identified value.
50 public function testTranslateSingleNotIDGettext()
52 $this->conf
->set('translation.mode', 'gettext');
53 new Languages('en', $this->conf
);
54 $text = 'abcdé 564 fgK';
55 $this->assertEquals($text, t($text));
59 * Test t() with a simple identified value in gettext mode.
61 public function testTranslateSingleIDGettext()
63 $this->conf
->set('translation.mode', 'gettext');
64 new Languages('en', $this->conf
);
66 $this->assertEquals('permalien', t($text));
70 * Test t() with a non identified plural form in gettext mode.
72 public function testTranslatePluralNotIDGettext()
74 $this->conf
->set('translation.mode', 'gettext');
75 new Languages('en', $this->conf
);
77 $nText = 'sandwiches';
78 // Not ID, so English fallback, and in english, plural 0
79 $this->assertEquals('sandwiches', t($text, $nText, 0));
80 $this->assertEquals('sandwich', t($text, $nText, 1));
81 $this->assertEquals('sandwiches', t($text, $nText, 2));
85 * Test t() with an identified plural form in gettext mode.
87 public function testTranslatePluralIDGettext()
89 $this->conf
->set('translation.mode', 'gettext');
90 new Languages('en', $this->conf
);
93 $this->assertEquals('shaare', t($text, $nText, 0));
94 $this->assertEquals('shaare', t($text, $nText, 1));
95 $this->assertEquals('shaares', t($text, $nText, 2));
99 * Test t() with a simple non identified value.
101 public function testTranslateSingleNotIDPhp()
103 $this->conf
->set('translation.mode', 'php');
104 new Languages('en', $this->conf
);
105 $text = 'abcdé 564 fgK';
106 $this->assertEquals($text, t($text));
110 * Test t() with a simple identified value in PHP mode.
112 public function testTranslateSingleIDPhp()
114 $this->conf
->set('translation.mode', 'php');
115 new Languages('en', $this->conf
);
117 $this->assertEquals('permalien', t($text));
121 * Test t() with a non identified plural form in PHP mode.
123 public function testTranslatePluralNotIDPhp()
125 $this->conf
->set('translation.mode', 'php');
126 new Languages('en', $this->conf
);
128 $nText = 'sandwiches';
129 // Not ID, so English fallback, and in english, plural 0
130 $this->assertEquals('sandwiches', t($text, $nText, 0));
131 $this->assertEquals('sandwich', t($text, $nText, 1));
132 $this->assertEquals('sandwiches', t($text, $nText, 2));
136 * Test t() with an identified plural form in PHP mode.
138 public function testTranslatePluralIDPhp()
140 $this->conf
->set('translation.mode', 'php');
141 new Languages('en', $this->conf
);
144 // In english, zero is followed by plural form
145 $this->assertEquals('shaare', t($text, $nText, 0));
146 $this->assertEquals('shaare', t($text, $nText, 1));
147 $this->assertEquals('shaares', t($text, $nText, 2));
151 * Test t() with an extension language file in gettext mode
153 public function testTranslationExtensionGettext()
155 $this->conf
->set('translation.mode', 'gettext');
156 $this->conf
->set('translation.extensions.test', 'tests/utils/languages/');
157 new Languages('en', $this->conf
);
158 $txt = 'car'; // ignore me poedit
159 $this->assertEquals('voiture', t($txt, $txt, 1, 'test'));
160 $this->assertEquals('Fouille', t('Search', 'Search', 1, 'test'));
164 * Test t() with an extension language file in PHP mode
166 public function testTranslationExtensionPhp()
168 $this->conf
->set('translation.mode', 'php');
169 $this->conf
->set('translation.extensions.test', 'tests/utils/languages/');
170 new Languages('en', $this->conf
);
171 $txt = 'car'; // ignore me poedit
172 $this->assertEquals('voiture', t($txt, $txt, 1, 'test'));
173 $this->assertEquals('Fouille', t('Search', 'Search', 1, 'test'));