]>
git.agnieray.net Git - galette.git/blob - tests/Galette/Core/tests/units/I18n.php
039a3e34d8804270b79b9282832aa169d67a7b69
3 /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
10 * Copyright © 2013-2023 The Galette Team
12 * This file is part of Galette (http://galette.tuxfamily.org).
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.
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.
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/>.
28 * @package GaletteTests
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
34 * @link http://galette.tuxfamily.org
38 namespace Galette\Core\test\units
;
47 * @package GaletteTests
48 * @author Johan Cwiklinski <johan@x-tnd.be>
49 * @copyright 2013-2023 The Galette Team
50 * @license http://www.gnu.org/licenses/gpl-3.0.html GPL License 3.0 or (at your option) any later version
51 * @link http://galette.tuxfamily.org
54 class I18n
extends atoum
56 private \Galette\Core\Db
$zdb;
57 private ?\Galette\Core\I18n
$i18n = null;
62 * @param string $method Tested method name
66 public function beforeTestMethod($method)
68 $this->zdb
= new \Galette\Core\
Db();
69 $this->i18n
= new \Galette\Core\
I18n(
70 \Galette\Core\I18n
::DEFAULT_LANG
77 * @param string $method Calling method
81 public function afterTestMethod($method)
83 if (TYPE_DB
=== 'mysql') {
84 $this->array($this->zdb
->getWarnings())->isIdenticalTo([]);
89 * Test lang autodetect
93 public function testAutoLang()
95 $this->i18n
= new \Galette\Core\
I18n();
97 $this->variable($this->i18n
->getID())->isIdenticalTo(\Galette\Core\I18n
::DEFAULT_LANG
);
99 //simulate fr from browser
100 $_SERVER['HTTP_ACCEPT_LANGUAGE'] = 'fr_BE';
101 $this->i18n
= new \Galette\Core\
I18n();
103 $this->variable($this->i18n
->getID())
104 ->isIdenticalTo('fr_FR');
106 //simulate en from browser
107 $_SERVER['HTTP_ACCEPT_LANGUAGE'] = 'en_GB';
108 $this->i18n
= new \Galette\Core\
I18n();
110 $this->variable($this->i18n
->getID())->isIdenticalTo('en_US');
112 //simulate unknown lang from browser
113 $_SERVER['HTTP_ACCEPT_LANGUAGE'] = 'un_KN';
114 $this->i18n
= new \Galette\Core\
I18n();
116 $this->variable($this->i18n
->getID())
117 ->isIdenticalTo(\Galette\Core\I18n
::DEFAULT_LANG
);
121 * Test languages list
125 public function testGetList()
127 $list = $this->i18n
->getList();
130 ->size
->isGreaterThan(3);
132 foreach ($list as $elt) {
134 ->isInstanceOf('\Galette\Core\I18n');
139 * Test languages list as array
143 public function testGetArrayList()
145 $list = $this->i18n
->getArrayList();
148 ->size
->isGreaterThan(3);
152 * Test getting language name from its ID
156 public function testGetNameFromid()
158 $lang = $this->i18n
->getNameFromId('en_US');
159 $this->variable($lang)->isIdenticalTo('English');
161 $lang = $this->i18n
->getNameFromId('fr_FR');
162 $this->variable($lang)->isIdenticalTo('Français');
166 * Test retrieving language information
170 public function testGetLangInfos()
172 $id = $this->i18n
->getID();
173 $longid = $this->i18n
->getLongID();
174 $name = $this->i18n
->getName();
175 $abbrev = $this->i18n
->getAbbrev();
177 $this->variable($id)->isIdenticalTo('en_US');
178 $this->variable($longid)->isIdenticalTo('en_US');
179 $this->variable($name)->isIdenticalTo('English');
180 $this->variable($abbrev)->isIdenticalTo('en');
182 $this->i18n
->changeLanguage('fr_FR');
183 $id = $this->i18n
->getID();
184 $longid = $this->i18n
->getLongID();
185 $name = $this->i18n
->getName();
186 $abbrev = $this->i18n
->getAbbrev();
188 $this->variable($id)->isIdenticalTo('fr_FR');
189 $this->variable($longid)->isIdenticalTo('fr_FR.utf8');
190 $this->variable($name)->isIdenticalTo('Français');
191 $this->variable($abbrev)->isIdenticalTo('fr');
195 * Change to an unknown language
199 public function testChangeUnknownLanguage()
201 $this->i18n
->changeLanguage('un_KN');
202 $id = $this->i18n
->getID();
204 $this->variable($id)->isIdenticalTo(\Galette\Core\I18n
::DEFAULT_LANG
);
208 * Check (non) UTF strings
212 public function testSeemUtf8()
214 $is_utf = $this->i18n
->seemUtf8('HéhéHÉHÉâ-ô߬- ©»«<ëßßä€êþÿûîœô');
215 $is_iso = $this->i18n
->seemUtf8(mb_convert_encoding('Héhé', 'ISO-8859-1'));
217 $this->boolean($is_utf)->isTrue();
218 $this->boolean($is_iso)->isFalse();