]> git.agnieray.net Git - galette.git/blob - tests/Galette/Core/tests/units/I18n.php
Remove 'svn' lines
[galette.git] / tests / Galette / Core / tests / units / I18n.php
1 <?php
2
3 /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
4
5 /**
6 * i18n tests
7 *
8 * PHP version 5
9 *
10 * Copyright © 2013-2023 The Galette Team
11 *
12 * This file is part of Galette (http://galette.tuxfamily.org).
13 *
14 * Galette is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation, either version 3 of the License, or
17 * (at your option) any later version.
18 *
19 * Galette is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * You should have received a copy of the GNU General Public License
25 * along with Galette. If not, see <http://www.gnu.org/licenses/>.
26 *
27 * @category Core
28 * @package GaletteTests
29 *
30 * @author Johan Cwiklinski <johan@x-tnd.be>
31 * @copyright 2013-2023 The Galette Team
32 * @license http://www.gnu.org/licenses/gpl-3.0.html GPL License 3.0 or (at your option) any later version
33 * @link http://galette.tuxfamily.org
34 * @since 2013-01-13
35 */
36
37 namespace Galette\Core\test\units;
38
39 use PHPUnit\Framework\TestCase;
40
41 /**
42 * I18n tests class
43 *
44 * @category Core
45 * @name i18n
46 * @package GaletteTests
47 * @author Johan Cwiklinski <johan@x-tnd.be>
48 * @copyright 2013-2023 The Galette Team
49 * @license http://www.gnu.org/licenses/gpl-3.0.html GPL License 3.0 or (at your option) any later version
50 * @link http://galette.tuxfamily.org
51 * @since 2013-01-13
52 */
53 class I18n extends TestCase
54 {
55 private \Galette\Core\Db $zdb;
56 private ?\Galette\Core\I18n $i18n = null;
57
58 /**
59 * Set up tests
60 *
61 * @return void
62 */
63 public function setUp(): void
64 {
65 $this->zdb = new \Galette\Core\Db();
66 $this->i18n = new \Galette\Core\I18n(
67 \Galette\Core\I18n::DEFAULT_LANG
68 );
69 }
70
71 /**
72 * Tear down tests
73 *
74 * @return void
75 */
76 public function tearDown(): void
77 {
78 if (TYPE_DB === 'mysql') {
79 $this->assertSame([], $this->zdb->getWarnings());
80 }
81 }
82
83 /**
84 * Test lang autodetect
85 *
86 * @return void
87 */
88 public function testAutoLang()
89 {
90 $this->i18n = new \Galette\Core\I18n();
91
92 $this->assertSame(\Galette\Core\I18n::DEFAULT_LANG, $this->i18n->getID());
93
94 //simulate fr from browser
95 $_SERVER['HTTP_ACCEPT_LANGUAGE'] = 'fr_BE';
96 $this->i18n = new \Galette\Core\I18n();
97
98 $this->assertSame('fr_FR', $this->i18n->getID());
99
100 //simulate en from browser
101 $_SERVER['HTTP_ACCEPT_LANGUAGE'] = 'en_GB';
102 $this->i18n = new \Galette\Core\I18n();
103
104 $this->assertSame('en_US', $this->i18n->getID());
105
106 //simulate unknown lang from browser
107 $_SERVER['HTTP_ACCEPT_LANGUAGE'] = 'un_KN';
108 $this->i18n = new \Galette\Core\I18n();
109
110 $this->assertSame(\Galette\Core\I18n::DEFAULT_LANG, $this->i18n->getID());
111 }
112
113 /**
114 * Test languages list
115 *
116 * @return void
117 */
118 public function testGetList()
119 {
120 $list = $this->i18n->getList();
121
122 $this->assertGreaterThan(3, count($list));
123
124 foreach ($list as $elt) {
125 $this->assertInstanceOf('\Galette\Core\I18n', $elt);
126 }
127 }
128
129 /**
130 * Test languages list as array
131 *
132 * @return void
133 */
134 public function testGetArrayList()
135 {
136 $list = $this->i18n->getArrayList();
137
138 $this->assertGreaterThan(3, count($list));
139 }
140
141 /**
142 * Test getting language name from its ID
143 *
144 * @return void
145 */
146 public function testGetNameFromid()
147 {
148 $lang = $this->i18n->getNameFromId('en_US');
149 $this->assertSame('English', $lang);
150
151 $lang = $this->i18n->getNameFromId('fr_FR');
152 $this->assertSame('Français', $lang);
153 }
154
155 /**
156 * Test retrieving language information
157 *
158 * @return void
159 */
160 public function testGetLangInfos()
161 {
162 $id = $this->i18n->getID();
163 $longid = $this->i18n->getLongID();
164 $name = $this->i18n->getName();
165 $abbrev = $this->i18n->getAbbrev();
166
167 $this->assertSame('en_US', $id);
168 $this->assertSame('en_US', $longid);
169 $this->assertSame('English', $name);
170 $this->assertSame('en', $abbrev);
171
172 $this->i18n->changeLanguage('fr_FR');
173 $id = $this->i18n->getID();
174 $longid = $this->i18n->getLongID();
175 $name = $this->i18n->getName();
176 $abbrev = $this->i18n->getAbbrev();
177
178 $this->assertSame('fr_FR', $id);
179 $this->assertSame('fr_FR.utf8', $longid);
180 $this->assertSame('Français', $name);
181 $this->assertSame('fr', $abbrev);
182 }
183
184 /**
185 * Change to an unknown language
186 *
187 * @return void
188 */
189 public function testChangeUnknownLanguage()
190 {
191 $this->i18n->changeLanguage('un_KN');
192 $id = $this->i18n->getID();
193
194 $this->assertSame(\Galette\Core\I18n::DEFAULT_LANG, $id);
195 }
196
197 /**
198 * Check (non) UTF strings
199 *
200 * @return void
201 */
202 public function testSeemUtf8()
203 {
204 $is_utf = $this->i18n->seemUtf8('HéhéHÉHÉâ-ô߬- ©»«<ëßßä€êþÿûîœô');
205 $is_iso = $this->i18n->seemUtf8(mb_convert_encoding('Héhé', 'ISO-8859-1'));
206
207 $this->assertTrue($is_utf);
208 $this->assertFalse($is_iso);
209 }
210 }