aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/languages
diff options
context:
space:
mode:
authorArthurHoaro <arthur@hoa.ro>2018-07-28 11:07:55 +0200
committerArthurHoaro <arthur@hoa.ro>2018-07-28 11:07:55 +0200
commit83faedadff76c5bdca036f39f13943f63b27e164 (patch)
tree6f44cede16ec6a60f10b9699e211e0818f06d2c8 /tests/languages
parent1d9eb22a3df85b67fe6652c0876cd7382c2fb525 (diff)
parent658988f3aeba7a5a938783249ccf2765251e5597 (diff)
downloadShaarli-83faedadff76c5bdca036f39f13943f63b27e164.tar.gz
Shaarli-83faedadff76c5bdca036f39f13943f63b27e164.tar.zst
Shaarli-83faedadff76c5bdca036f39f13943f63b27e164.zip
Merge tag 'v0.9.7' into stable
Release v0.9.7
Diffstat (limited to 'tests/languages')
-rw-r--r--tests/languages/bootstrap.php6
-rw-r--r--tests/languages/de/UtilsDeTest.php119
-rw-r--r--tests/languages/en/UtilsEnTest.php119
-rw-r--r--tests/languages/fr/LanguagesFrTest.php175
-rw-r--r--tests/languages/fr/UtilsFrTest.php119
5 files changed, 538 insertions, 0 deletions
diff --git a/tests/languages/bootstrap.php b/tests/languages/bootstrap.php
new file mode 100644
index 00000000..da6ac2e4
--- /dev/null
+++ b/tests/languages/bootstrap.php
@@ -0,0 +1,6 @@
1<?php
2require_once 'tests/bootstrap.php';
3
4if (! empty(getenv('UT_LOCALE'))) {
5 setlocale(LC_ALL, getenv('UT_LOCALE'));
6}
diff --git a/tests/languages/de/UtilsDeTest.php b/tests/languages/de/UtilsDeTest.php
new file mode 100644
index 00000000..4569c923
--- /dev/null
+++ b/tests/languages/de/UtilsDeTest.php
@@ -0,0 +1,119 @@
1<?php
2
3require_once 'tests/UtilsTest.php';
4
5
6class UtilsDeTest extends UtilsTest
7{
8 /**
9 * Test date_format().
10 */
11 public function testDateFormat()
12 {
13 $date = DateTime::createFromFormat('Ymd_His', '20170101_101112');
14 $this->assertRegExp('/1\. Januar 2017 (um )?10:11:12 GMT\+0?3(:00)?/', format_date($date, true, true));
15 }
16
17 /**
18 * Test date_format() without time.
19 */
20 public function testDateFormatNoTime()
21 {
22 $date = DateTime::createFromFormat('Ymd_His', '20170101_101112');
23 $this->assertRegExp('/1\. Januar 2017/', format_date($date, false,true));
24 }
25
26 /**
27 * Test date_format() using builtin PHP function strftime.
28 */
29 public function testDateFormatDefault()
30 {
31 $date = DateTime::createFromFormat('Ymd_His', '20170101_101112');
32 $this->assertEquals('So 01 Jan 2017 10:11:12 EAT', format_date($date, true, false));
33 }
34
35 /**
36 * Test date_format() using builtin PHP function strftime without time.
37 */
38 public function testDateFormatDefaultNoTime()
39 {
40 $date = DateTime::createFromFormat('Ymd_His', '20170201_101112');
41 $this->assertEquals('01.02.2017', format_date($date, false, false));
42 }
43
44 /**
45 * Test autoLocale with a simple value
46 */
47 public function testAutoLocaleValid()
48 {
49 $current = setlocale(LC_ALL, 0);
50 $header = 'en-us';
51 autoLocale($header);
52 $this->assertEquals('en_US.utf8', setlocale(LC_ALL, 0));
53
54 setlocale(LC_ALL, $current);
55 }
56
57 /**
58 * Test autoLocale with an alternative locale value
59 */
60 public function testAutoLocaleValidAlternative()
61 {
62 $current = setlocale(LC_ALL, 0);
63 $header = 'en_us.UTF8';
64 autoLocale($header);
65 $this->assertEquals('en_US.utf8', setlocale(LC_ALL, 0));
66
67 setlocale(LC_ALL, $current);
68 }
69
70 /**
71 * Test autoLocale with multiples value, the first one is valid
72 */
73 public function testAutoLocaleMultipleFirstValid()
74 {
75 $current = setlocale(LC_ALL, 0);
76 $header = 'en-us,de-de';
77 autoLocale($header);
78 $this->assertEquals('en_US.utf8', setlocale(LC_ALL, 0));
79
80 setlocale(LC_ALL, $current);
81 }
82
83 /**
84 * Test autoLocale with multiples value, the second one is available
85 */
86 public function testAutoLocaleMultipleSecondAvailable()
87 {
88 $current = setlocale(LC_ALL, 0);
89 $header = 'mag_IN,fr-fr';
90 autoLocale($header);
91 $this->assertEquals('fr_FR.utf8', setlocale(LC_ALL, 0));
92
93 setlocale(LC_ALL, $current);
94 }
95
96 /**
97 * Test autoLocale without value: defaults to en_US.
98 */
99 public function testAutoLocaleBlank()
100 {
101 $current = setlocale(LC_ALL, 0);
102 autoLocale('');
103 $this->assertEquals('en_US.utf8', setlocale(LC_ALL, 0));
104
105 setlocale(LC_ALL, $current);
106 }
107
108 /**
109 * Test autoLocale with an unavailable value: defaults to en_US.
110 */
111 public function testAutoLocaleUnavailable()
112 {
113 $current = setlocale(LC_ALL, 0);
114 autoLocale('mag_IN');
115 $this->assertEquals('en_US.utf8', setlocale(LC_ALL, 0));
116
117 setlocale(LC_ALL, $current);
118 }
119}
diff --git a/tests/languages/en/UtilsEnTest.php b/tests/languages/en/UtilsEnTest.php
new file mode 100644
index 00000000..a74063ae
--- /dev/null
+++ b/tests/languages/en/UtilsEnTest.php
@@ -0,0 +1,119 @@
1<?php
2
3require_once 'tests/UtilsTest.php';
4
5
6class UtilsEnTest extends UtilsTest
7{
8 /**
9 * Test date_format().
10 */
11 public function testDateFormat()
12 {
13 $date = DateTime::createFromFormat('Ymd_His', '20170101_101112');
14 $this->assertRegExp('/January 1, 2017 (at )?10:11:12 AM GMT\+0?3(:00)?/', format_date($date, true, true));
15 }
16
17 /**
18 * Test date_format() without time.
19 */
20 public function testDateFormatNoTime()
21 {
22 $date = DateTime::createFromFormat('Ymd_His', '20170101_101112');
23 $this->assertRegExp('/January 1, 2017/', format_date($date, false, true));
24 }
25
26 /**
27 * Test date_format() using builtin PHP function strftime.
28 */
29 public function testDateFormatDefault()
30 {
31 $date = DateTime::createFromFormat('Ymd_His', '20170101_101112');
32 $this->assertEquals('Sun 01 Jan 2017 10:11:12 AM EAT', format_date($date, true, false));
33 }
34
35 /**
36 * Test date_format() using builtin PHP function strftime without time.
37 */
38 public function testDateFormatDefaultNoTime()
39 {
40 $date = DateTime::createFromFormat('Ymd_His', '20170201_101112');
41 $this->assertEquals('02/01/2017', format_date($date, false, false));
42 }
43
44 /**
45 * Test autoLocale with a simple value
46 */
47 public function testAutoLocaleValid()
48 {
49 $current = setlocale(LC_ALL, 0);
50 $header = 'de-de';
51 autoLocale($header);
52 $this->assertEquals('de_DE.utf8', setlocale(LC_ALL, 0));
53
54 setlocale(LC_ALL, $current);
55 }
56
57 /**
58 * Test autoLocale with an alternative locale value
59 */
60 public function testAutoLocaleValidAlternative()
61 {
62 $current = setlocale(LC_ALL, 0);
63 $header = 'de_de.UTF8';
64 autoLocale($header);
65 $this->assertEquals('de_DE.utf8', setlocale(LC_ALL, 0));
66
67 setlocale(LC_ALL, $current);
68 }
69
70 /**
71 * Test autoLocale with multiples value, the first one is valid
72 */
73 public function testAutoLocaleMultipleFirstValid()
74 {
75 $current = setlocale(LC_ALL, 0);
76 $header = 'de-de;en-us';
77 autoLocale($header);
78 $this->assertEquals('de_DE.utf8', setlocale(LC_ALL, 0));
79
80 setlocale(LC_ALL, $current);
81 }
82
83 /**
84 * Test autoLocale with multiples value, the second one is available
85 */
86 public function testAutoLocaleMultipleSecondAvailable()
87 {
88 $current = setlocale(LC_ALL, 0);
89 $header = 'mag_IN,fr-fr';
90 autoLocale($header);
91 $this->assertEquals('fr_FR.utf8', setlocale(LC_ALL, 0));
92
93 setlocale(LC_ALL, $current);
94 }
95
96 /**
97 * Test autoLocale without value: defaults to en_US.
98 */
99 public function testAutoLocaleBlank()
100 {
101 $current = setlocale(LC_ALL, 0);
102 autoLocale('');
103 $this->assertEquals('en_US.utf8', setlocale(LC_ALL, 0));
104
105 setlocale(LC_ALL, $current);
106 }
107
108 /**
109 * Test autoLocale with an unavailable value: defaults to en_US.
110 */
111 public function testAutoLocaleUnavailable()
112 {
113 $current = setlocale(LC_ALL, 0);
114 autoLocale('mag_IN');
115 $this->assertEquals('en_US.utf8', setlocale(LC_ALL, 0));
116
117 setlocale(LC_ALL, $current);
118 }
119}
diff --git a/tests/languages/fr/LanguagesFrTest.php b/tests/languages/fr/LanguagesFrTest.php
new file mode 100644
index 00000000..79d05172
--- /dev/null
+++ b/tests/languages/fr/LanguagesFrTest.php
@@ -0,0 +1,175 @@
1<?php
2
3
4namespace Shaarli;
5
6
7use Shaarli\Config\ConfigManager;
8
9/**
10 * Class LanguagesFrTest
11 *
12 * Test the translation system in PHP and gettext mode with French language.
13 *
14 * @package Shaarli
15 */
16class LanguagesFrTest extends \PHPUnit_Framework_TestCase
17{
18 /**
19 * @var string Config file path (without extension).
20 */
21 protected static $configFile = 'tests/utils/config/configJson';
22
23 /**
24 * @var ConfigManager
25 */
26 protected $conf;
27
28 /**
29 * Init: force French
30 */
31 public function setUp()
32 {
33 $this->conf = new ConfigManager(self::$configFile);
34 $this->conf->set('translation.language', 'fr');
35 }
36
37 /**
38 * Reset the locale since gettext seems to mess with it, making it too long
39 */
40 public static function tearDownAfterClass()
41 {
42 if (! empty(getenv('UT_LOCALE'))) {
43 setlocale(LC_ALL, getenv('UT_LOCALE'));
44 }
45 }
46
47 /**
48 * Test t() with a simple non identified value.
49 */
50 public function testTranslateSingleNotIDGettext()
51 {
52 $this->conf->set('translation.mode', 'gettext');
53 new Languages('en', $this->conf);
54 $text = 'abcdé 564 fgK';
55 $this->assertEquals($text, t($text));
56 }
57
58 /**
59 * Test t() with a simple identified value in gettext mode.
60 */
61 public function testTranslateSingleIDGettext()
62 {
63 $this->conf->set('translation.mode', 'gettext');
64 new Languages('en', $this->conf);
65 $text = 'permalink';
66 $this->assertEquals('permalien', t($text));
67 }
68
69 /**
70 * Test t() with a non identified plural form in gettext mode.
71 */
72 public function testTranslatePluralNotIDGettext()
73 {
74 $this->conf->set('translation.mode', 'gettext');
75 new Languages('en', $this->conf);
76 $text = 'sandwich';
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));
82 }
83
84 /**
85 * Test t() with an identified plural form in gettext mode.
86 */
87 public function testTranslatePluralIDGettext()
88 {
89 $this->conf->set('translation.mode', 'gettext');
90 new Languages('en', $this->conf);
91 $text = 'shaare';
92 $nText = 'shaares';
93 $this->assertEquals('shaare', t($text, $nText, 0));
94 $this->assertEquals('shaare', t($text, $nText, 1));
95 $this->assertEquals('shaares', t($text, $nText, 2));
96 }
97
98 /**
99 * Test t() with a simple non identified value.
100 */
101 public function testTranslateSingleNotIDPhp()
102 {
103 $this->conf->set('translation.mode', 'php');
104 new Languages('en', $this->conf);
105 $text = 'abcdé 564 fgK';
106 $this->assertEquals($text, t($text));
107 }
108
109 /**
110 * Test t() with a simple identified value in PHP mode.
111 */
112 public function testTranslateSingleIDPhp()
113 {
114 $this->conf->set('translation.mode', 'php');
115 new Languages('en', $this->conf);
116 $text = 'permalink';
117 $this->assertEquals('permalien', t($text));
118 }
119
120 /**
121 * Test t() with a non identified plural form in PHP mode.
122 */
123 public function testTranslatePluralNotIDPhp()
124 {
125 $this->conf->set('translation.mode', 'php');
126 new Languages('en', $this->conf);
127 $text = 'sandwich';
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));
133 }
134
135 /**
136 * Test t() with an identified plural form in PHP mode.
137 */
138 public function testTranslatePluralIDPhp()
139 {
140 $this->conf->set('translation.mode', 'php');
141 new Languages('en', $this->conf);
142 $text = 'shaare';
143 $nText = 'shaares';
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));
148 }
149
150 /**
151 * Test t() with an extension language file in gettext mode
152 */
153 public function testTranslationExtensionGettext()
154 {
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'));
161 }
162
163 /**
164 * Test t() with an extension language file in PHP mode
165 */
166 public function testTranslationExtensionPhp()
167 {
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'));
174 }
175}
diff --git a/tests/languages/fr/UtilsFrTest.php b/tests/languages/fr/UtilsFrTest.php
new file mode 100644
index 00000000..3dbb126f
--- /dev/null
+++ b/tests/languages/fr/UtilsFrTest.php
@@ -0,0 +1,119 @@
1<?php
2
3require_once 'tests/UtilsTest.php';
4
5
6class UtilsFrTest extends UtilsTest
7{
8 /**
9 * Test date_format().
10 */
11 public function testDateFormat()
12 {
13 $date = DateTime::createFromFormat('Ymd_His', '20170101_101112');
14 $this->assertRegExp('/1 janvier 2017 (à )?10:11:12 UTC\+0?3(:00)?/', format_date($date));
15 }
16
17 /**
18 * Test date_format() without time.
19 */
20 public function testDateFormatNoTime()
21 {
22 $date = DateTime::createFromFormat('Ymd_His', '20170101_101112');
23 $this->assertRegExp('/1 janvier 2017/', format_date($date, false, true));
24 }
25
26 /**
27 * Test date_format() using builtin PHP function strftime.
28 */
29 public function testDateFormatDefault()
30 {
31 $date = DateTime::createFromFormat('Ymd_His', '20170101_101112');
32 $this->assertEquals('dim. 01 janv. 2017 10:11:12 EAT', format_date($date, true, false));
33 }
34
35 /**
36 * Test date_format() using builtin PHP function strftime without time.
37 */
38 public function testDateFormatDefaultNoTime()
39 {
40 $date = DateTime::createFromFormat('Ymd_His', '20170201_101112');
41 $this->assertEquals('01/02/2017', format_date($date, false, false));
42 }
43
44 /**
45 * Test autoLocale with a simple value
46 */
47 public function testAutoLocaleValid()
48 {
49 $current = setlocale(LC_ALL, 0);
50 $header = 'de-de';
51 autoLocale($header);
52 $this->assertEquals('de_DE.utf8', setlocale(LC_ALL, 0));
53
54 setlocale(LC_ALL, $current);
55 }
56
57 /**
58 * Test autoLocale with an alternative locale value
59 */
60 public function testAutoLocaleValidAlternative()
61 {
62 $current = setlocale(LC_ALL, 0);
63 $header = 'de_de.UTF8';
64 autoLocale($header);
65 $this->assertEquals('de_DE.utf8', setlocale(LC_ALL, 0));
66
67 setlocale(LC_ALL, $current);
68 }
69
70 /**
71 * Test autoLocale with multiples value, the first one is valid
72 */
73 public function testAutoLocaleMultipleFirstValid()
74 {
75 $current = setlocale(LC_ALL, 0);
76 $header = 'de-de;en-us';
77 autoLocale($header);
78 $this->assertEquals('de_DE.utf8', setlocale(LC_ALL, 0));
79
80 setlocale(LC_ALL, $current);
81 }
82
83 /**
84 * Test autoLocale with multiples value, the second one is available
85 */
86 public function testAutoLocaleMultipleSecondAvailable()
87 {
88 $current = setlocale(LC_ALL, 0);
89 $header = 'mag_IN,de-de';
90 autoLocale($header);
91 $this->assertEquals('de_DE.utf8', setlocale(LC_ALL, 0));
92
93 setlocale(LC_ALL, $current);
94 }
95
96 /**
97 * Test autoLocale without value: defaults to en_US.
98 */
99 public function testAutoLocaleBlank()
100 {
101 $current = setlocale(LC_ALL, 0);
102 autoLocale('');
103 $this->assertEquals('en_US.utf8', setlocale(LC_ALL, 0));
104
105 setlocale(LC_ALL, $current);
106 }
107
108 /**
109 * Test autoLocale with an unavailable value: defaults to en_US.
110 */
111 public function testAutoLocaleUnavailable()
112 {
113 $current = setlocale(LC_ALL, 0);
114 autoLocale('mag_IN');
115 $this->assertEquals('en_US.utf8', setlocale(LC_ALL, 0));
116
117 setlocale(LC_ALL, $current);
118 }
119}