]> git.agnieray.net Git - galette.git/blob - tests/Galette/Core/tests/units/I18n.php
7c341b0843e8c3d143f4ba0a04260ca0f5469f94
[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-2014 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-2014 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 * @version SVN: $Id$
34 * @link http://galette.tuxfamily.org
35 * @since 2013-01-13
36 */
37
38 namespace Galette\Core\test\units;
39
40 use \atoum;
41
42 /**
43 * I18n tests class
44 *
45 * @category Core
46 * @name i18n
47 * @package GaletteTests
48 * @author Johan Cwiklinski <johan@x-tnd.be>
49 * @copyright 2013-2014 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
52 * @since 2013-01-13
53 */
54 class I18n extends atoum
55 {
56 private $i18n = null;
57
58 /**
59 * Set up tests
60 *
61 * @param string $testMethod Tested method name
62 *
63 * @return void
64 */
65 public function beforeTestMethod($testMethod)
66 {
67 $this->i18n = new \Galette\Core\I18n(
68 \Galette\Core\I18n::DEFAULT_LANG
69 );
70 }
71
72 /**
73 * Test lang autodetect
74 *
75 * @return void
76 */
77 public function testAutoLang()
78 {
79 $this->i18n = new \Galette\Core\I18n();
80
81 $this->variable($this->i18n->getID())
82 ->isIdenticalTo('fr_FR');
83
84 //simulate fr from browser
85 $_SERVER['HTTP_ACCEPT_LANGUAGE'] = 'fr_BE';
86 $this->i18n = new \Galette\Core\I18n();
87
88 $this->variable($this->i18n->getID())
89 ->isIdenticalTo('fr_FR');
90
91 //simulate en from browser
92 $_SERVER['HTTP_ACCEPT_LANGUAGE'] = 'en_GB';
93 $this->i18n = new \Galette\Core\I18n();
94
95 $this->variable($this->i18n->getID())
96 ->isIdenticalTo('en_US');
97
98 //simulate unknown lang from browser
99 $_SERVER['HTTP_ACCEPT_LANGUAGE'] = 'un_KN';
100 $this->i18n = new \Galette\Core\I18n();
101
102 $this->variable($this->i18n->getID())
103 ->isIdenticalTo('fr_FR');
104 }
105
106 /**
107 * Test languages list
108 *
109 * @return void
110 */
111 public function testGetList()
112 {
113 $list = $this->i18n->getList();
114
115 $this->array($list)
116 ->size->isGreaterThan(3);
117
118 foreach ($list as $elt) {
119 $this->object($elt)
120 ->isInstanceOf('\Galette\Core\I18n');
121 }
122 }
123
124 /**
125 * Test languages list as array
126 *
127 * @return void
128 */
129 public function testGetArrayList()
130 {
131 $list = $this->i18n->getArrayList();
132
133 $this->array($list)
134 ->size->isGreaterThan(3);
135 }
136
137 /**
138 * Test getting language name from its ID
139 *
140 * @return void
141 */
142 public function testGetNameFromid()
143 {
144 $lang = $this->i18n->getNameFromId('en_US');
145
146 $this->variable($lang)
147 ->isIdenticalTo('English');
148 }
149
150 /**
151 * Test retrieving language information
152 *
153 * @return void
154 */
155 public function testGetLangInfos()
156 {
157 $id = $this->i18n->getID();
158 $longid = $this->i18n->getLongID();
159 $name = $this->i18n->getName();
160 $abbrev = $this->i18n->getAbbrev();
161
162 $this->variable($id)
163 ->isIdenticalTo('fr_FR');
164 $this->variable($longid)
165 ->isIdenticalTo('fr_FR.utf8');
166 $this->variable($name)
167 ->isIdenticalTo('Français');
168 $this->variable($abbrev)
169 ->isIdenticalTo('fr');
170 }
171
172 /**
173 * Change to an unknown language
174 *
175 * @return void
176 */
177 public function testChangeUnknownLanguage()
178 {
179 $this->i18n->changeLanguage('un_KN');
180 $id = $this->i18n->getID();
181
182 $this->variable($id)
183 ->isIdenticalTo('fr_FR');
184 }
185
186 /**
187 * Check (non) UTF strings
188 *
189 * @return void
190 */
191 public function testSeemUtf8()
192 {
193 $is_utf = $this->i18n->seemUtf8('HéhéHÉHÉâ-ô߬- ©»«<ëßßä€êþÿûîœô');
194 $is_iso = $this->i18n->seemUtf8(utf8_decode('Héhé'));
195
196 $this->boolean($is_utf)->isTrue();
197 $this->boolean($is_iso)->isFalse();
198 }
199 }