diff options
Diffstat (limited to 'tests/languages/en/UtilsEnTest.php')
-rw-r--r-- | tests/languages/en/UtilsEnTest.php | 119 |
1 files changed, 119 insertions, 0 deletions
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 | |||
3 | require_once 'tests/UtilsTest.php'; | ||
4 | |||
5 | |||
6 | class 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 | } | ||