aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/languages
diff options
context:
space:
mode:
authorArthurHoaro <arthur@hoa.ro>2017-03-07 19:27:17 +0100
committerArthurHoaro <arthur@hoa.ro>2017-03-07 19:27:17 +0100
commit03b9cb600a85fed79b8afa72ccdad2725da5f3da (patch)
tree7d3b4090960953edcf7cec663d45e879dfb99f2b /tests/languages
parent36c8fb1ef869c29e783f0dd5ebef2fb5566e2611 (diff)
downloadShaarli-03b9cb600a85fed79b8afa72ccdad2725da5f3da.tar.gz
Shaarli-03b9cb600a85fed79b8afa72ccdad2725da5f3da.tar.zst
Shaarli-03b9cb600a85fed79b8afa72ccdad2725da5f3da.zip
Fix autoLocale error and cover it with unit tests
Diffstat (limited to 'tests/languages')
-rw-r--r--tests/languages/de/UtilsDeTest.php76
-rw-r--r--tests/languages/en/UtilsEnTest.php76
-rw-r--r--tests/languages/fr/UtilsFrTest.php76
3 files changed, 228 insertions, 0 deletions
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
22 $date = DateTime::createFromFormat('Ymd_His', '20170101_101112'); 22 $date = DateTime::createFromFormat('Ymd_His', '20170101_101112');
23 $this->assertEquals('So 01 Jan 2017 10:11:12 EAT', format_date($date, false)); 23 $this->assertEquals('So 01 Jan 2017 10:11:12 EAT', format_date($date, false));
24 } 24 }
25
26 /**
27 * Test autoLocale with a simple value
28 */
29 public function testAutoLocaleValid()
30 {
31 $current = setlocale(LC_ALL, 0);
32 $header = 'en-us';
33 autoLocale($header);
34 $this->assertEquals('en_US.utf8', setlocale(LC_ALL, 0));
35
36 setlocale(LC_ALL, $current);
37 }
38
39 /**
40 * Test autoLocale with an alternative locale value
41 */
42 public function testAutoLocaleValidAlternative()
43 {
44 $current = setlocale(LC_ALL, 0);
45 $header = 'en_us.UTF8';
46 autoLocale($header);
47 $this->assertEquals('en_US.utf8', setlocale(LC_ALL, 0));
48
49 setlocale(LC_ALL, $current);
50 }
51
52 /**
53 * Test autoLocale with multiples value, the first one is valid
54 */
55 public function testAutoLocaleMultipleFirstValid()
56 {
57 $current = setlocale(LC_ALL, 0);
58 $header = 'en-us,de-de';
59 autoLocale($header);
60 $this->assertEquals('en_US.utf8', setlocale(LC_ALL, 0));
61
62 setlocale(LC_ALL, $current);
63 }
64
65 /**
66 * Test autoLocale with multiples value, the second one is valid
67 */
68 public function testAutoLocaleMultipleSecondValid()
69 {
70 $current = setlocale(LC_ALL, 0);
71 $header = 'pt_BR,fr-fr';
72 autoLocale($header);
73 $this->assertEquals('fr_FR.utf8', setlocale(LC_ALL, 0));
74
75 setlocale(LC_ALL, $current);
76 }
77
78 /**
79 * Test autoLocale without value: defaults to en_US.
80 */
81 public function testAutoLocaleBlank()
82 {
83 $current = setlocale(LC_ALL, 0);
84 autoLocale('');
85 $this->assertEquals('en_US.utf8', setlocale(LC_ALL, 0));
86
87 setlocale(LC_ALL, $current);
88 }
89
90 /**
91 * Test autoLocale with an invalid value: defaults to en_US.
92 */
93 public function testAutoLocaleInvalid()
94 {
95 $current = setlocale(LC_ALL, 0);
96 autoLocale('pt_BR');
97 $this->assertEquals('en_US.utf8', setlocale(LC_ALL, 0));
98
99 setlocale(LC_ALL, $current);
100 }
25} 101}
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
22 $date = DateTime::createFromFormat('Ymd_His', '20170101_101112'); 22 $date = DateTime::createFromFormat('Ymd_His', '20170101_101112');
23 $this->assertEquals('Sun 01 Jan 2017 10:11:12 AM EAT', format_date($date, false)); 23 $this->assertEquals('Sun 01 Jan 2017 10:11:12 AM EAT', format_date($date, false));
24 } 24 }
25
26 /**
27 * Test autoLocale with a simple value
28 */
29 public function testAutoLocaleValid()
30 {
31 $current = setlocale(LC_ALL, 0);
32 $header = 'de-de';
33 autoLocale($header);
34 $this->assertEquals('de_DE.utf8', setlocale(LC_ALL, 0));
35
36 setlocale(LC_ALL, $current);
37 }
38
39 /**
40 * Test autoLocale with an alternative locale value
41 */
42 public function testAutoLocaleValidAlternative()
43 {
44 $current = setlocale(LC_ALL, 0);
45 $header = 'de_de.UTF8';
46 autoLocale($header);
47 $this->assertEquals('de_DE.utf8', setlocale(LC_ALL, 0));
48
49 setlocale(LC_ALL, $current);
50 }
51
52 /**
53 * Test autoLocale with multiples value, the first one is valid
54 */
55 public function testAutoLocaleMultipleFirstValid()
56 {
57 $current = setlocale(LC_ALL, 0);
58 $header = 'de-de;en-us';
59 autoLocale($header);
60 $this->assertEquals('de_DE.utf8', setlocale(LC_ALL, 0));
61
62 setlocale(LC_ALL, $current);
63 }
64
65 /**
66 * Test autoLocale with multiples value, the second one is valid
67 */
68 public function testAutoLocaleMultipleSecondValid()
69 {
70 $current = setlocale(LC_ALL, 0);
71 $header = 'pt_BR,fr-fr';
72 autoLocale($header);
73 $this->assertEquals('fr_FR.utf8', setlocale(LC_ALL, 0));
74
75 setlocale(LC_ALL, $current);
76 }
77
78 /**
79 * Test autoLocale without value: defaults to en_US.
80 */
81 public function testAutoLocaleBlank()
82 {
83 $current = setlocale(LC_ALL, 0);
84 autoLocale('');
85 $this->assertEquals('en_US.utf8', setlocale(LC_ALL, 0));
86
87 setlocale(LC_ALL, $current);
88 }
89
90 /**
91 * Test autoLocale with an invalid value: defaults to en_US.
92 */
93 public function testAutoLocaleInvalid()
94 {
95 $current = setlocale(LC_ALL, 0);
96 autoLocale('pt_BR');
97 $this->assertEquals('en_US.utf8', setlocale(LC_ALL, 0));
98
99 setlocale(LC_ALL, $current);
100 }
25} 101}
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
22 $date = DateTime::createFromFormat('Ymd_His', '20170101_101112'); 22 $date = DateTime::createFromFormat('Ymd_His', '20170101_101112');
23 $this->assertEquals('dim. 01 janv. 2017 10:11:12 EAT', format_date($date, false)); 23 $this->assertEquals('dim. 01 janv. 2017 10:11:12 EAT', format_date($date, false));
24 } 24 }
25
26 /**
27 * Test autoLocale with a simple value
28 */
29 public function testAutoLocaleValid()
30 {
31 $current = setlocale(LC_ALL, 0);
32 $header = 'de-de';
33 autoLocale($header);
34 $this->assertEquals('de_DE.utf8', setlocale(LC_ALL, 0));
35
36 setlocale(LC_ALL, $current);
37 }
38
39 /**
40 * Test autoLocale with an alternative locale value
41 */
42 public function testAutoLocaleValidAlternative()
43 {
44 $current = setlocale(LC_ALL, 0);
45 $header = 'de_de.UTF8';
46 autoLocale($header);
47 $this->assertEquals('de_DE.utf8', setlocale(LC_ALL, 0));
48
49 setlocale(LC_ALL, $current);
50 }
51
52 /**
53 * Test autoLocale with multiples value, the first one is valid
54 */
55 public function testAutoLocaleMultipleFirstValid()
56 {
57 $current = setlocale(LC_ALL, 0);
58 $header = 'de-de;en-us';
59 autoLocale($header);
60 $this->assertEquals('de_DE.utf8', setlocale(LC_ALL, 0));
61
62 setlocale(LC_ALL, $current);
63 }
64
65 /**
66 * Test autoLocale with multiples value, the second one is valid
67 */
68 public function testAutoLocaleMultipleSecondValid()
69 {
70 $current = setlocale(LC_ALL, 0);
71 $header = 'pt_BR,de-de';
72 autoLocale($header);
73 $this->assertEquals('de_DE.utf8', setlocale(LC_ALL, 0));
74
75 setlocale(LC_ALL, $current);
76 }
77
78 /**
79 * Test autoLocale without value: defaults to en_US.
80 */
81 public function testAutoLocaleBlank()
82 {
83 $current = setlocale(LC_ALL, 0);
84 autoLocale('');
85 $this->assertEquals('en_US.utf8', setlocale(LC_ALL, 0));
86
87 setlocale(LC_ALL, $current);
88 }
89
90 /**
91 * Test autoLocale with an invalid value: defaults to en_US.
92 */
93 public function testAutoLocaleInvalid()
94 {
95 $current = setlocale(LC_ALL, 0);
96 autoLocale('pt_BR');
97 $this->assertEquals('en_US.utf8', setlocale(LC_ALL, 0));
98
99 setlocale(LC_ALL, $current);
100 }
25} 101}