From 52b503105d389d1796698114573ff618b2ad34a2 Mon Sep 17 00:00:00 2001 From: ArthurHoaro Date: Sat, 7 Jan 2017 14:30:42 +0100 Subject: Improve datetime display Use php-intl extension to display datetimes a bit more nicely, depending on the locale. What changes: * the day is no longer displayed * day number and month are ordered according to the locale * the timezone is more readable (UTC+1 instead of CET) --- tests/languages/bootstrap.php | 7 +++++++ tests/languages/de/UtilsDeTest.php | 25 +++++++++++++++++++++++++ tests/languages/en/UtilsEnTest.php | 25 +++++++++++++++++++++++++ tests/languages/fr/UtilsFrTest.php | 25 +++++++++++++++++++++++++ 4 files changed, 82 insertions(+) create mode 100644 tests/languages/bootstrap.php create mode 100644 tests/languages/de/UtilsDeTest.php create mode 100644 tests/languages/en/UtilsEnTest.php create mode 100644 tests/languages/fr/UtilsFrTest.php (limited to 'tests/languages') diff --git a/tests/languages/bootstrap.php b/tests/languages/bootstrap.php new file mode 100644 index 00000000..95609210 --- /dev/null +++ b/tests/languages/bootstrap.php @@ -0,0 +1,7 @@ +assertRegExp('/1. Januar 2017 (um )?10:11:12 GMT\+0?3(:00)?/', format_date($date, true)); + } + + /** + * Test date_format() using builtin PHP function strftime. + */ + public function testDateFormatDefault() + { + $date = DateTime::createFromFormat('Ymd_His', '20170101_101112'); + $this->assertEquals('So 01 Jan 2017 10:11:12 EAT', format_date($date, false)); + } +} diff --git a/tests/languages/en/UtilsEnTest.php b/tests/languages/en/UtilsEnTest.php new file mode 100644 index 00000000..60bcb653 --- /dev/null +++ b/tests/languages/en/UtilsEnTest.php @@ -0,0 +1,25 @@ +assertRegExp('/January 1, 2017 (at )?10:11:12 AM GMT\+0?3(:00)?/', format_date($date, true)); + } + + /** + * Test date_format() using builtin PHP function strftime. + */ + public function testDateFormatDefault() + { + $date = DateTime::createFromFormat('Ymd_His', '20170101_101112'); + $this->assertEquals('Sun 01 Jan 2017 10:11:12 AM EAT', format_date($date, false)); + } +} diff --git a/tests/languages/fr/UtilsFrTest.php b/tests/languages/fr/UtilsFrTest.php new file mode 100644 index 00000000..890308d3 --- /dev/null +++ b/tests/languages/fr/UtilsFrTest.php @@ -0,0 +1,25 @@ +assertRegExp('/1 janvier 2017 (à )?10:11:12 UTC\+0?3(:00)?/', format_date($date)); + } + + /** + * Test date_format() using builtin PHP function strftime. + */ + public function testDateFormatDefault() + { + $date = DateTime::createFromFormat('Ymd_His', '20170101_101112'); + $this->assertEquals('dim. 01 janv. 2017 10:11:12 EAT', format_date($date, false)); + } +} -- cgit v1.2.3 From 03b9cb600a85fed79b8afa72ccdad2725da5f3da Mon Sep 17 00:00:00 2001 From: ArthurHoaro Date: Tue, 7 Mar 2017 19:27:17 +0100 Subject: Fix autoLocale error and cover it with unit tests --- tests/languages/de/UtilsDeTest.php | 76 ++++++++++++++++++++++++++++++++++++++ tests/languages/en/UtilsEnTest.php | 76 ++++++++++++++++++++++++++++++++++++++ tests/languages/fr/UtilsFrTest.php | 76 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 228 insertions(+) (limited to 'tests/languages') diff --git a/tests/languages/de/UtilsDeTest.php b/tests/languages/de/UtilsDeTest.php index 8a740389..545fa572 100644 --- a/tests/languages/de/UtilsDeTest.php +++ b/tests/languages/de/UtilsDeTest.php @@ -22,4 +22,80 @@ class UtilsDeTest extends UtilsTest $date = DateTime::createFromFormat('Ymd_His', '20170101_101112'); $this->assertEquals('So 01 Jan 2017 10:11:12 EAT', format_date($date, false)); } + + /** + * Test autoLocale with a simple value + */ + public function testAutoLocaleValid() + { + $current = setlocale(LC_ALL, 0); + $header = 'en-us'; + autoLocale($header); + $this->assertEquals('en_US.utf8', setlocale(LC_ALL, 0)); + + setlocale(LC_ALL, $current); + } + + /** + * Test autoLocale with an alternative locale value + */ + public function testAutoLocaleValidAlternative() + { + $current = setlocale(LC_ALL, 0); + $header = 'en_us.UTF8'; + autoLocale($header); + $this->assertEquals('en_US.utf8', setlocale(LC_ALL, 0)); + + setlocale(LC_ALL, $current); + } + + /** + * Test autoLocale with multiples value, the first one is valid + */ + public function testAutoLocaleMultipleFirstValid() + { + $current = setlocale(LC_ALL, 0); + $header = 'en-us,de-de'; + autoLocale($header); + $this->assertEquals('en_US.utf8', setlocale(LC_ALL, 0)); + + setlocale(LC_ALL, $current); + } + + /** + * Test autoLocale with multiples value, the second one is valid + */ + public function testAutoLocaleMultipleSecondValid() + { + $current = setlocale(LC_ALL, 0); + $header = 'pt_BR,fr-fr'; + autoLocale($header); + $this->assertEquals('fr_FR.utf8', setlocale(LC_ALL, 0)); + + setlocale(LC_ALL, $current); + } + + /** + * Test autoLocale without value: defaults to en_US. + */ + public function testAutoLocaleBlank() + { + $current = setlocale(LC_ALL, 0); + autoLocale(''); + $this->assertEquals('en_US.utf8', setlocale(LC_ALL, 0)); + + setlocale(LC_ALL, $current); + } + + /** + * Test autoLocale with an invalid value: defaults to en_US. + */ + public function testAutoLocaleInvalid() + { + $current = setlocale(LC_ALL, 0); + autoLocale('pt_BR'); + $this->assertEquals('en_US.utf8', setlocale(LC_ALL, 0)); + + setlocale(LC_ALL, $current); + } } diff --git a/tests/languages/en/UtilsEnTest.php b/tests/languages/en/UtilsEnTest.php index 60bcb653..7c829ac7 100644 --- a/tests/languages/en/UtilsEnTest.php +++ b/tests/languages/en/UtilsEnTest.php @@ -22,4 +22,80 @@ class UtilsEnTest extends UtilsTest $date = DateTime::createFromFormat('Ymd_His', '20170101_101112'); $this->assertEquals('Sun 01 Jan 2017 10:11:12 AM EAT', format_date($date, false)); } + + /** + * Test autoLocale with a simple value + */ + public function testAutoLocaleValid() + { + $current = setlocale(LC_ALL, 0); + $header = 'de-de'; + autoLocale($header); + $this->assertEquals('de_DE.utf8', setlocale(LC_ALL, 0)); + + setlocale(LC_ALL, $current); + } + + /** + * Test autoLocale with an alternative locale value + */ + public function testAutoLocaleValidAlternative() + { + $current = setlocale(LC_ALL, 0); + $header = 'de_de.UTF8'; + autoLocale($header); + $this->assertEquals('de_DE.utf8', setlocale(LC_ALL, 0)); + + setlocale(LC_ALL, $current); + } + + /** + * Test autoLocale with multiples value, the first one is valid + */ + public function testAutoLocaleMultipleFirstValid() + { + $current = setlocale(LC_ALL, 0); + $header = 'de-de;en-us'; + autoLocale($header); + $this->assertEquals('de_DE.utf8', setlocale(LC_ALL, 0)); + + setlocale(LC_ALL, $current); + } + + /** + * Test autoLocale with multiples value, the second one is valid + */ + public function testAutoLocaleMultipleSecondValid() + { + $current = setlocale(LC_ALL, 0); + $header = 'pt_BR,fr-fr'; + autoLocale($header); + $this->assertEquals('fr_FR.utf8', setlocale(LC_ALL, 0)); + + setlocale(LC_ALL, $current); + } + + /** + * Test autoLocale without value: defaults to en_US. + */ + public function testAutoLocaleBlank() + { + $current = setlocale(LC_ALL, 0); + autoLocale(''); + $this->assertEquals('en_US.utf8', setlocale(LC_ALL, 0)); + + setlocale(LC_ALL, $current); + } + + /** + * Test autoLocale with an invalid value: defaults to en_US. + */ + public function testAutoLocaleInvalid() + { + $current = setlocale(LC_ALL, 0); + autoLocale('pt_BR'); + $this->assertEquals('en_US.utf8', setlocale(LC_ALL, 0)); + + setlocale(LC_ALL, $current); + } } diff --git a/tests/languages/fr/UtilsFrTest.php b/tests/languages/fr/UtilsFrTest.php index 890308d3..45996ee2 100644 --- a/tests/languages/fr/UtilsFrTest.php +++ b/tests/languages/fr/UtilsFrTest.php @@ -22,4 +22,80 @@ class UtilsFrTest extends UtilsTest $date = DateTime::createFromFormat('Ymd_His', '20170101_101112'); $this->assertEquals('dim. 01 janv. 2017 10:11:12 EAT', format_date($date, false)); } + + /** + * Test autoLocale with a simple value + */ + public function testAutoLocaleValid() + { + $current = setlocale(LC_ALL, 0); + $header = 'de-de'; + autoLocale($header); + $this->assertEquals('de_DE.utf8', setlocale(LC_ALL, 0)); + + setlocale(LC_ALL, $current); + } + + /** + * Test autoLocale with an alternative locale value + */ + public function testAutoLocaleValidAlternative() + { + $current = setlocale(LC_ALL, 0); + $header = 'de_de.UTF8'; + autoLocale($header); + $this->assertEquals('de_DE.utf8', setlocale(LC_ALL, 0)); + + setlocale(LC_ALL, $current); + } + + /** + * Test autoLocale with multiples value, the first one is valid + */ + public function testAutoLocaleMultipleFirstValid() + { + $current = setlocale(LC_ALL, 0); + $header = 'de-de;en-us'; + autoLocale($header); + $this->assertEquals('de_DE.utf8', setlocale(LC_ALL, 0)); + + setlocale(LC_ALL, $current); + } + + /** + * Test autoLocale with multiples value, the second one is valid + */ + public function testAutoLocaleMultipleSecondValid() + { + $current = setlocale(LC_ALL, 0); + $header = 'pt_BR,de-de'; + autoLocale($header); + $this->assertEquals('de_DE.utf8', setlocale(LC_ALL, 0)); + + setlocale(LC_ALL, $current); + } + + /** + * Test autoLocale without value: defaults to en_US. + */ + public function testAutoLocaleBlank() + { + $current = setlocale(LC_ALL, 0); + autoLocale(''); + $this->assertEquals('en_US.utf8', setlocale(LC_ALL, 0)); + + setlocale(LC_ALL, $current); + } + + /** + * Test autoLocale with an invalid value: defaults to en_US. + */ + public function testAutoLocaleInvalid() + { + $current = setlocale(LC_ALL, 0); + autoLocale('pt_BR'); + $this->assertEquals('en_US.utf8', setlocale(LC_ALL, 0)); + + setlocale(LC_ALL, $current); + } } -- cgit v1.2.3 From 81bd104daa26204b8deffcd2d0723d234c9514a6 Mon Sep 17 00:00:00 2001 From: ArthurHoaro Date: Tue, 28 Mar 2017 20:40:14 +0200 Subject: Theme: use format_date function for daily date --- tests/languages/de/UtilsDeTest.php | 22 ++++++++++++++++++++-- tests/languages/en/UtilsEnTest.php | 22 ++++++++++++++++++++-- tests/languages/fr/UtilsFrTest.php | 20 +++++++++++++++++++- 3 files changed, 59 insertions(+), 5 deletions(-) (limited to 'tests/languages') diff --git a/tests/languages/de/UtilsDeTest.php b/tests/languages/de/UtilsDeTest.php index 545fa572..6c9c9adc 100644 --- a/tests/languages/de/UtilsDeTest.php +++ b/tests/languages/de/UtilsDeTest.php @@ -11,7 +11,16 @@ class UtilsDeTest extends UtilsTest public function testDateFormat() { $date = DateTime::createFromFormat('Ymd_His', '20170101_101112'); - $this->assertRegExp('/1. Januar 2017 (um )?10:11:12 GMT\+0?3(:00)?/', format_date($date, true)); + $this->assertRegExp('/1\. Januar 2017 (um )?10:11:12 GMT\+0?3(:00)?/', format_date($date, true, true)); + } + + /** + * Test date_format() without time. + */ + public function testDateFormatNoTime() + { + $date = DateTime::createFromFormat('Ymd_His', '20170101_101112'); + $this->assertRegExp('/1\. Januar 2017/', format_date($date, false,true)); } /** @@ -20,7 +29,16 @@ class UtilsDeTest extends UtilsTest public function testDateFormatDefault() { $date = DateTime::createFromFormat('Ymd_His', '20170101_101112'); - $this->assertEquals('So 01 Jan 2017 10:11:12 EAT', format_date($date, false)); + $this->assertEquals('So 01 Jan 2017 10:11:12 EAT', format_date($date, true, false)); + } + + /** + * Test date_format() using builtin PHP function strftime without time. + */ + public function testDateFormatDefaultNoTime() + { + $date = DateTime::createFromFormat('Ymd_His', '20170201_101112'); + $this->assertEquals('01.02.2017', format_date($date, false, false)); } /** diff --git a/tests/languages/en/UtilsEnTest.php b/tests/languages/en/UtilsEnTest.php index 7c829ac7..d8680b2b 100644 --- a/tests/languages/en/UtilsEnTest.php +++ b/tests/languages/en/UtilsEnTest.php @@ -11,7 +11,16 @@ class UtilsEnTest extends UtilsTest public function testDateFormat() { $date = DateTime::createFromFormat('Ymd_His', '20170101_101112'); - $this->assertRegExp('/January 1, 2017 (at )?10:11:12 AM GMT\+0?3(:00)?/', format_date($date, true)); + $this->assertRegExp('/January 1, 2017 (at )?10:11:12 AM GMT\+0?3(:00)?/', format_date($date, true, true)); + } + + /** + * Test date_format() without time. + */ + public function testDateFormatNoTime() + { + $date = DateTime::createFromFormat('Ymd_His', '20170101_101112'); + $this->assertRegExp('/January 1, 2017/', format_date($date, false, true)); } /** @@ -20,7 +29,16 @@ class UtilsEnTest extends UtilsTest public function testDateFormatDefault() { $date = DateTime::createFromFormat('Ymd_His', '20170101_101112'); - $this->assertEquals('Sun 01 Jan 2017 10:11:12 AM EAT', format_date($date, false)); + $this->assertEquals('Sun 01 Jan 2017 10:11:12 AM EAT', format_date($date, true, false)); + } + + /** + * Test date_format() using builtin PHP function strftime without time. + */ + public function testDateFormatDefaultNoTime() + { + $date = DateTime::createFromFormat('Ymd_His', '20170201_101112'); + $this->assertEquals('02/01/2017', format_date($date, false, false)); } /** diff --git a/tests/languages/fr/UtilsFrTest.php b/tests/languages/fr/UtilsFrTest.php index 45996ee2..0d50a878 100644 --- a/tests/languages/fr/UtilsFrTest.php +++ b/tests/languages/fr/UtilsFrTest.php @@ -14,13 +14,31 @@ class UtilsFrTest extends UtilsTest $this->assertRegExp('/1 janvier 2017 (à )?10:11:12 UTC\+0?3(:00)?/', format_date($date)); } + /** + * Test date_format() without time. + */ + public function testDateFormatNoTime() + { + $date = DateTime::createFromFormat('Ymd_His', '20170101_101112'); + $this->assertRegExp('/1 janvier 2017/', format_date($date, false, true)); + } + /** * Test date_format() using builtin PHP function strftime. */ public function testDateFormatDefault() { $date = DateTime::createFromFormat('Ymd_His', '20170101_101112'); - $this->assertEquals('dim. 01 janv. 2017 10:11:12 EAT', format_date($date, false)); + $this->assertEquals('dim. 01 janv. 2017 10:11:12 EAT', format_date($date, true, false)); + } + + /** + * Test date_format() using builtin PHP function strftime without time. + */ + public function testDateFormatDefaultNoTime() + { + $date = DateTime::createFromFormat('Ymd_His', '20170201_101112'); + $this->assertEquals('01/02/2017', format_date($date, false, false)); } /** -- cgit v1.2.3 From b5c33d702ac973e7bc1401e484c6b8799eea1e91 Mon Sep 17 00:00:00 2001 From: VirtualTam Date: Tue, 19 Sep 2017 19:17:16 +0200 Subject: Tests: update localization tests Rely on `mag_IN` (Magahi - INDIA) being unavailable when running localization test suites, instead of `pt_BR` that is now available from Travis build images. Signed-off-by: VirtualTam --- tests/languages/de/UtilsDeTest.php | 12 ++++++------ tests/languages/en/UtilsEnTest.php | 12 ++++++------ tests/languages/fr/UtilsFrTest.php | 12 ++++++------ 3 files changed, 18 insertions(+), 18 deletions(-) (limited to 'tests/languages') diff --git a/tests/languages/de/UtilsDeTest.php b/tests/languages/de/UtilsDeTest.php index 6c9c9adc..4569c923 100644 --- a/tests/languages/de/UtilsDeTest.php +++ b/tests/languages/de/UtilsDeTest.php @@ -81,12 +81,12 @@ class UtilsDeTest extends UtilsTest } /** - * Test autoLocale with multiples value, the second one is valid + * Test autoLocale with multiples value, the second one is available */ - public function testAutoLocaleMultipleSecondValid() + public function testAutoLocaleMultipleSecondAvailable() { $current = setlocale(LC_ALL, 0); - $header = 'pt_BR,fr-fr'; + $header = 'mag_IN,fr-fr'; autoLocale($header); $this->assertEquals('fr_FR.utf8', setlocale(LC_ALL, 0)); @@ -106,12 +106,12 @@ class UtilsDeTest extends UtilsTest } /** - * Test autoLocale with an invalid value: defaults to en_US. + * Test autoLocale with an unavailable value: defaults to en_US. */ - public function testAutoLocaleInvalid() + public function testAutoLocaleUnavailable() { $current = setlocale(LC_ALL, 0); - autoLocale('pt_BR'); + autoLocale('mag_IN'); $this->assertEquals('en_US.utf8', setlocale(LC_ALL, 0)); setlocale(LC_ALL, $current); diff --git a/tests/languages/en/UtilsEnTest.php b/tests/languages/en/UtilsEnTest.php index d8680b2b..a74063ae 100644 --- a/tests/languages/en/UtilsEnTest.php +++ b/tests/languages/en/UtilsEnTest.php @@ -81,12 +81,12 @@ class UtilsEnTest extends UtilsTest } /** - * Test autoLocale with multiples value, the second one is valid + * Test autoLocale with multiples value, the second one is available */ - public function testAutoLocaleMultipleSecondValid() + public function testAutoLocaleMultipleSecondAvailable() { $current = setlocale(LC_ALL, 0); - $header = 'pt_BR,fr-fr'; + $header = 'mag_IN,fr-fr'; autoLocale($header); $this->assertEquals('fr_FR.utf8', setlocale(LC_ALL, 0)); @@ -106,12 +106,12 @@ class UtilsEnTest extends UtilsTest } /** - * Test autoLocale with an invalid value: defaults to en_US. + * Test autoLocale with an unavailable value: defaults to en_US. */ - public function testAutoLocaleInvalid() + public function testAutoLocaleUnavailable() { $current = setlocale(LC_ALL, 0); - autoLocale('pt_BR'); + autoLocale('mag_IN'); $this->assertEquals('en_US.utf8', setlocale(LC_ALL, 0)); setlocale(LC_ALL, $current); diff --git a/tests/languages/fr/UtilsFrTest.php b/tests/languages/fr/UtilsFrTest.php index 0d50a878..3dbb126f 100644 --- a/tests/languages/fr/UtilsFrTest.php +++ b/tests/languages/fr/UtilsFrTest.php @@ -81,12 +81,12 @@ class UtilsFrTest extends UtilsTest } /** - * Test autoLocale with multiples value, the second one is valid + * Test autoLocale with multiples value, the second one is available */ - public function testAutoLocaleMultipleSecondValid() + public function testAutoLocaleMultipleSecondAvailable() { $current = setlocale(LC_ALL, 0); - $header = 'pt_BR,de-de'; + $header = 'mag_IN,de-de'; autoLocale($header); $this->assertEquals('de_DE.utf8', setlocale(LC_ALL, 0)); @@ -106,12 +106,12 @@ class UtilsFrTest extends UtilsTest } /** - * Test autoLocale with an invalid value: defaults to en_US. + * Test autoLocale with an unavailable value: defaults to en_US. */ - public function testAutoLocaleInvalid() + public function testAutoLocaleUnavailable() { $current = setlocale(LC_ALL, 0); - autoLocale('pt_BR'); + autoLocale('mag_IN'); $this->assertEquals('en_US.utf8', setlocale(LC_ALL, 0)); setlocale(LC_ALL, $current); -- cgit v1.2.3 From 12266213d098a53c5f005b9afcbbe62771fd580c Mon Sep 17 00:00:00 2001 From: ArthurHoaro Date: Tue, 9 May 2017 18:12:15 +0200 Subject: Shaarli's translation * translation system and unit tests * Translations everywhere Dont use translation merge It is not available with PHP builtin gettext, so it would have lead to inconsistency. --- tests/languages/bootstrap.php | 7 +- tests/languages/fr/LanguagesFrTest.php | 173 +++++++++++++++++++++++++++++++++ 2 files changed, 176 insertions(+), 4 deletions(-) create mode 100644 tests/languages/fr/LanguagesFrTest.php (limited to 'tests/languages') diff --git a/tests/languages/bootstrap.php b/tests/languages/bootstrap.php index 95609210..da6ac2e4 100644 --- a/tests/languages/bootstrap.php +++ b/tests/languages/bootstrap.php @@ -1,7 +1,6 @@ conf = new ConfigManager(self::$configFile); + $this->conf->set('translation.language', 'fr'); + } + + /** + * Reset the locale since gettext seems to mess with it, making it too long + */ + public static function tearDownAfterClass() + { + if (! empty(getenv('UT_LOCALE'))) { + setlocale(LC_ALL, getenv('UT_LOCALE')); + } + } + + /** + * Test t() with a simple non identified value. + */ + public function testTranslateSingleNotIDGettext() + { + $this->conf->set('translation.mode', 'gettext'); + new Languages('en', $this->conf); + $text = 'abcdé 564 fgK'; + $this->assertEquals($text, t($text)); + } + + /** + * Test t() with a simple identified value in gettext mode. + */ + public function testTranslateSingleIDGettext() + { + $this->conf->set('translation.mode', 'gettext'); + new Languages('en', $this->conf); + $text = 'permalink'; + $this->assertEquals('permalien', t($text)); + } + + /** + * Test t() with a non identified plural form in gettext mode. + */ + public function testTranslatePluralNotIDGettext() + { + $this->conf->set('translation.mode', 'gettext'); + new Languages('en', $this->conf); + $text = 'sandwich'; + $nText = 'sandwiches'; + // Not ID, so English fallback, and in english, plural 0 + $this->assertEquals('sandwiches', t($text, $nText, 0)); + $this->assertEquals('sandwich', t($text, $nText, 1)); + $this->assertEquals('sandwiches', t($text, $nText, 2)); + } + + /** + * Test t() with an identified plural form in gettext mode. + */ + public function testTranslatePluralIDGettext() + { + $this->conf->set('translation.mode', 'gettext'); + new Languages('en', $this->conf); + $text = 'shaare'; + $nText = 'shaares'; + $this->assertEquals('shaare', t($text, $nText, 0)); + $this->assertEquals('shaare', t($text, $nText, 1)); + $this->assertEquals('shaares', t($text, $nText, 2)); + } + + /** + * Test t() with a simple non identified value. + */ + public function testTranslateSingleNotIDPhp() + { + $this->conf->set('translation.mode', 'php'); + new Languages('en', $this->conf); + $text = 'abcdé 564 fgK'; + $this->assertEquals($text, t($text)); + } + + /** + * Test t() with a simple identified value in PHP mode. + */ + public function testTranslateSingleIDPhp() + { + $this->conf->set('translation.mode', 'php'); + new Languages('en', $this->conf); + $text = 'permalink'; + $this->assertEquals('permalien', t($text)); + } + + /** + * Test t() with a non identified plural form in PHP mode. + */ + public function testTranslatePluralNotIDPhp() + { + $this->conf->set('translation.mode', 'php'); + new Languages('en', $this->conf); + $text = 'sandwich'; + $nText = 'sandwiches'; + // Not ID, so English fallback, and in english, plural 0 + $this->assertEquals('sandwiches', t($text, $nText, 0)); + $this->assertEquals('sandwich', t($text, $nText, 1)); + $this->assertEquals('sandwiches', t($text, $nText, 2)); + } + + /** + * Test t() with an identified plural form in PHP mode. + */ + public function testTranslatePluralIDPhp() + { + $this->conf->set('translation.mode', 'php'); + new Languages('en', $this->conf); + $text = 'shaare'; + $nText = 'shaares'; + // In english, zero is followed by plural form + $this->assertEquals('shaare', t($text, $nText, 0)); + $this->assertEquals('shaare', t($text, $nText, 1)); + $this->assertEquals('shaares', t($text, $nText, 2)); + } + + /** + * Test t() with an extension language file in gettext mode + */ + public function testTranslationExtensionGettext() + { + $this->conf->set('translation.mode', 'gettext'); + $this->conf->set('translation.extensions.test', 'tests/utils/languages/'); + new Languages('en', $this->conf); + $this->assertEquals('voiture', t('car', 'car', 1, 'test')); + $this->assertEquals('Fouille', t('Search', 'Search', 1, 'test')); + } + + /** + * Test t() with an extension language file in PHP mode + */ + public function testTranslationExtensionPhp() + { + $this->conf->set('translation.mode', 'php'); + $this->conf->set('translation.extensions.test', 'tests/utils/languages/'); + new Languages('en', $this->conf); + $this->assertEquals('voiture', t('car', 'car', 1, 'test')); + $this->assertEquals('Fouille', t('Search', 'Search', 1, 'test')); + } +} -- cgit v1.2.3 From f39580c6fd171b849cec5832b4912182696341f2 Mon Sep 17 00:00:00 2001 From: ArthurHoaro Date: Thu, 25 May 2017 13:26:05 +0200 Subject: Add language selection in the configure page of the default theme --- tests/languages/fr/LanguagesFrTest.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'tests/languages') diff --git a/tests/languages/fr/LanguagesFrTest.php b/tests/languages/fr/LanguagesFrTest.php index c05a0f98..79d05172 100644 --- a/tests/languages/fr/LanguagesFrTest.php +++ b/tests/languages/fr/LanguagesFrTest.php @@ -155,7 +155,8 @@ class LanguagesFrTest extends \PHPUnit_Framework_TestCase $this->conf->set('translation.mode', 'gettext'); $this->conf->set('translation.extensions.test', 'tests/utils/languages/'); new Languages('en', $this->conf); - $this->assertEquals('voiture', t('car', 'car', 1, 'test')); + $txt = 'car'; // ignore me poedit + $this->assertEquals('voiture', t($txt, $txt, 1, 'test')); $this->assertEquals('Fouille', t('Search', 'Search', 1, 'test')); } @@ -167,7 +168,8 @@ class LanguagesFrTest extends \PHPUnit_Framework_TestCase $this->conf->set('translation.mode', 'php'); $this->conf->set('translation.extensions.test', 'tests/utils/languages/'); new Languages('en', $this->conf); - $this->assertEquals('voiture', t('car', 'car', 1, 'test')); + $txt = 'car'; // ignore me poedit + $this->assertEquals('voiture', t($txt, $txt, 1, 'test')); $this->assertEquals('Fouille', t('Search', 'Search', 1, 'test')); } } -- cgit v1.2.3