| 1 |
lars |
1 |
<?php
|
|
|
2 |
// $Id: db_test_base.php 242710 2007-09-19 21:38:50Z quipo $
|
|
|
3 |
|
|
|
4 |
|
|
|
5 |
require_once 'simple_include.php';
|
|
|
6 |
require_once 'translation2_include.php';
|
|
|
7 |
require_once 'dbms.php';
|
|
|
8 |
//require_once 'common_tests.php';
|
|
|
9 |
|
|
|
10 |
class TestOfContainerDB extends UnitTestCase { //TestOfTranslation2 {
|
|
|
11 |
var $tr;
|
|
|
12 |
function TestOfContainerDB($name='Test of Container DB') {
|
|
|
13 |
$this->UnitTestCase($name);
|
|
|
14 |
}
|
|
|
15 |
function setUp() {
|
|
|
16 |
$driver = 'DB';
|
|
|
17 |
$this->tr = Translation2::factory($driver, dbms::getDbInfo(), dbms::getParams());
|
|
|
18 |
}
|
|
|
19 |
function tearDown() {
|
|
|
20 |
unset($this->tr);
|
|
|
21 |
}
|
|
|
22 |
function testFactory() {
|
|
|
23 |
if (PEAR::isError($this->tr)) {
|
|
|
24 |
var_dump($this->tr->getUserInfo());
|
|
|
25 |
var_dump($this->tr->getMessage());
|
|
|
26 |
}
|
|
|
27 |
$this->assertTrue(!PEAR::isError($this->tr));
|
|
|
28 |
}
|
|
|
29 |
function testGet() {
|
|
|
30 |
$this->assertEqual('gennaio', $this->tr->get('month_01', 'calendar', 'it'));
|
|
|
31 |
$this->assertEqual('january', $this->tr->get('month_01', 'calendar', 'en'));
|
|
|
32 |
$this->assertFalse(PEAR::isError($this->tr->setLang('en'))); //set default lang
|
|
|
33 |
$this->assertEqual('sunday', $this->tr->get('day_0', 'calendar'));
|
|
|
34 |
$this->assertEqual('monday', $this->tr->get('day_1', 'calendar'));
|
|
|
35 |
$this->tr->setPageID('calendar'); //set default lang AND default pageID
|
|
|
36 |
$this->assertEqual('sunday', $this->tr->get('day_0'));
|
|
|
37 |
$this->assertEqual('monday', $this->tr->get('day_1'));
|
|
|
38 |
}
|
|
|
39 |
function testGetRaw() {
|
|
|
40 |
$this->tr->setLang('it');
|
|
|
41 |
$this->tr->setParams(array(
|
|
|
42 |
'user' => 'Joe',
|
|
|
43 |
'day' => '15',
|
|
|
44 |
'month' => $this->tr->get('month_01', 'calendar'),
|
|
|
45 |
'year' => '2004',
|
|
|
46 |
'weekday' => $this->tr->get('day_5', 'calendar')
|
|
|
47 |
));
|
|
|
48 |
$expected = 'ciao, &&user&&, oggi è il &&day&& &&month&& &&year&& (&&weekday&&)';
|
|
|
49 |
$this->assertEqual($expected, $this->tr->getRaw('hello_user'));
|
|
|
50 |
|
|
|
51 |
$this->tr =& $this->tr->getDecorator('SpecialChars');
|
|
|
52 |
$this->assertEqual('venerdì', $this->tr->getRaw('day_5', 'calendar', 'it'));
|
|
|
53 |
}
|
|
|
54 |
function testGetPage() {
|
|
|
55 |
$this->tr->setLang('en');
|
|
|
56 |
$expected = array(
|
|
|
57 |
'first string' => 'first string',
|
|
|
58 |
'second string' => 'second string',
|
|
|
59 |
);
|
|
|
60 |
$this->assertEqual($expected, $this->tr->getPage('small page'));
|
|
|
61 |
$this->tr->setLang('it');
|
|
|
62 |
$expected = array(
|
|
|
63 |
'first string' => 'prima stringa',
|
|
|
64 |
'second string' => 'seconda stringa',
|
|
|
65 |
);
|
|
|
66 |
$this->assertEqual($expected, $this->tr->getPage('small page'));
|
|
|
67 |
}
|
|
|
68 |
function testGetRawPage() {
|
|
|
69 |
$expected = array(
|
|
|
70 |
'first string' => 'first string',
|
|
|
71 |
'second string' => 'second string',
|
|
|
72 |
);
|
|
|
73 |
$this->assertEqual($expected, $this->tr->getRawPage('small page', 'en'));
|
|
|
74 |
$expected = array(
|
|
|
75 |
'first string' => 'prima stringa',
|
|
|
76 |
'second string' => 'seconda stringa',
|
|
|
77 |
);
|
|
|
78 |
$this->assertEqual($expected, $this->tr->getRawPage('small page', 'it'));
|
|
|
79 |
}
|
|
|
80 |
function testConficts() {
|
|
|
81 |
$this->tr->setLang('en');
|
|
|
82 |
$this->tr->setPageID('in_page');
|
|
|
83 |
//pageID=TRANSLATION2_DEFAULT_PAGEID => get current pageID
|
|
|
84 |
$this->assertEqual('conflicting text - in page', $this->tr->get('prova_conflitto'));
|
|
|
85 |
//pageID=null => get strings with pageID = NULL
|
|
|
86 |
$this->assertEqual('conflicting text - Global', $this->tr->get('prova_conflitto', null));
|
|
|
87 |
//force pageID
|
|
|
88 |
$this->assertEqual('conflicting text - in page', $this->tr->get('prova_conflitto', 'in_page'));
|
|
|
89 |
}
|
|
|
90 |
function testParameterSubstitution() {
|
|
|
91 |
$this->tr->setLang('en');
|
|
|
92 |
$this->tr->setParams(array(
|
|
|
93 |
'user' => 'Joe',
|
|
|
94 |
'day' => '15',
|
|
|
95 |
'month' => $this->tr->get('month_01', 'calendar'),
|
|
|
96 |
'year' => '2004',
|
|
|
97 |
'weekday' => $this->tr->get('day_5', 'calendar')
|
|
|
98 |
));
|
|
|
99 |
$expected = 'hello Joe, today is friday, 15th january 2004';
|
|
|
100 |
$this->assertEqual($expected, $this->tr->get('hello_user'));
|
|
|
101 |
$this->tr->setLang('it');
|
|
|
102 |
$this->tr->setParams(array(
|
|
|
103 |
'user' => 'Joe',
|
|
|
104 |
'day' => '15',
|
|
|
105 |
'month' => $this->tr->get('month_01', 'calendar'),
|
|
|
106 |
'year' => '2004',
|
|
|
107 |
'weekday' => $this->tr->get('day_5', 'calendar')
|
|
|
108 |
));
|
|
|
109 |
$expected = 'ciao, Joe, oggi è il 15 gennaio 2004 (venerdì)';
|
|
|
110 |
$this->assertEqual($expected, $this->tr->get('hello_user'));
|
|
|
111 |
}
|
|
|
112 |
function testGetStringID() {
|
|
|
113 |
$this->tr->setLang('en');
|
|
|
114 |
$this->tr->setPageID('calendar');
|
|
|
115 |
$this->assertEqual('month_01', $this->tr->getStringID('january'));
|
|
|
116 |
$this->tr->setLang('it');
|
|
|
117 |
$this->assertEqual('month_01', $this->tr->getStringID('gennaio'));
|
|
|
118 |
}
|
|
|
119 |
function testGetLang() {
|
|
|
120 |
$this->tr->setLang('en');
|
|
|
121 |
$this->assertEqual('english', $this->tr->getLang());
|
|
|
122 |
$this->assertEqual('iso-8859-1', $this->tr->getLang('en', 'encoding'));
|
|
|
123 |
$this->assertEqual('my meta info', $this->tr->getLang('en', 'meta'));
|
|
|
124 |
$expected = array(
|
|
|
125 |
'id' => 'it',
|
|
|
126 |
'lang_id' => 'it',
|
|
|
127 |
'name' => 'italiano',
|
|
|
128 |
'meta' => 'charset: iso-8859-1',
|
|
|
129 |
'error_text' => 'non disponibile in Italiano',
|
|
|
130 |
'encoding' => 'iso-8859-1',
|
|
|
131 |
);
|
|
|
132 |
$this->assertEqual($expected, $this->tr->getLang('it', 'array'));
|
|
|
133 |
}
|
|
|
134 |
function testGetLangs() {
|
|
|
135 |
$expected = array(
|
|
|
136 |
'it',
|
|
|
137 |
'en',
|
|
|
138 |
'de',
|
|
|
139 |
);
|
|
|
140 |
$this->assertEqual($expected, $this->tr->getLangs('ids'));
|
|
|
141 |
$expected = array(
|
|
|
142 |
'it' => 'italiano',
|
|
|
143 |
'en' => 'english',
|
|
|
144 |
'de' => 'deutsch',
|
|
|
145 |
);
|
|
|
146 |
$this->assertEqual($expected, $this->tr->getLangs('names'));
|
|
|
147 |
$expected = array(
|
|
|
148 |
'it' => array(
|
|
|
149 |
'id' => 'it',
|
|
|
150 |
'lang_id' => 'it',
|
|
|
151 |
'name' => 'italiano',
|
|
|
152 |
'meta' => 'charset: iso-8859-1',
|
|
|
153 |
'error_text' => 'non disponibile in Italiano',
|
|
|
154 |
'encoding' => 'iso-8859-1',
|
|
|
155 |
),
|
|
|
156 |
'en' => array(
|
|
|
157 |
'id' => 'en',
|
|
|
158 |
'lang_id' => 'en',
|
|
|
159 |
'name' => 'english',
|
|
|
160 |
'meta' => 'my meta info',
|
|
|
161 |
'error_text' => 'not available in English',
|
|
|
162 |
'encoding' => 'iso-8859-1',
|
|
|
163 |
),
|
|
|
164 |
'de' => array(
|
|
|
165 |
'id' => 'de',
|
|
|
166 |
'lang_id' => 'de',
|
|
|
167 |
'name' => 'deutsch',
|
|
|
168 |
'meta' => 'charset: iso-8859-1',
|
|
|
169 |
'error_text' => 'kein Text auf Deutsch verfügbar',
|
|
|
170 |
'encoding' => 'iso-8859-1',
|
|
|
171 |
),
|
|
|
172 |
);
|
|
|
173 |
$this->assertEqual($expected, $this->tr->getLangs('array'));
|
|
|
174 |
}
|
|
|
175 |
function testDefaultTextDecorator() {
|
|
|
176 |
$this->tr->setLang('it');
|
|
|
177 |
//without decorator
|
|
|
178 |
$this->assertEqual('', $this->tr->get('isempty'));
|
|
|
179 |
$expected = array(
|
|
|
180 |
'only_english' => null,
|
|
|
181 |
'only_italian' => 'testo solo in italiano',
|
|
|
182 |
'hello_user' => 'ciao, &&user&&, oggi è il &&day&& &&month&& &&year&& (&&weekday&&)',
|
|
|
183 |
'isempty' => null,
|
|
|
184 |
'prova_conflitto' => 'testo con conflitto - globale',
|
|
|
185 |
'test' => 'stringa di prova',
|
|
|
186 |
'Entirely new string' => null,
|
|
|
187 |
);
|
|
|
188 |
//with decorator
|
|
|
189 |
$this->tr =& $this->tr->getDecorator('DefaultText');
|
|
|
190 |
$this->assertEqual('isempty', $this->tr->get('isempty'));
|
|
|
191 |
$this->assertEqual($expected, $this->tr->getRawPage());
|
|
|
192 |
$expected = array(
|
|
|
193 |
'only_english' => 'only_english',
|
|
|
194 |
'only_italian' => 'testo solo in italiano',
|
|
|
195 |
'hello_user' => 'ciao, &&user&&, oggi è il &&day&& &&month&& &&year&& (&&weekday&&)',
|
|
|
196 |
'isempty' => 'isempty',
|
|
|
197 |
'prova_conflitto' => 'testo con conflitto - globale',
|
|
|
198 |
'test' => 'stringa di prova',
|
|
|
199 |
'Entirely new string' => 'Entirely new string',
|
|
|
200 |
);
|
|
|
201 |
$this->assertEqual($expected, $this->tr->getPage());
|
|
|
202 |
|
|
|
203 |
//parameter replacement
|
|
|
204 |
$this->tr->setParams(array('foo' => 'bar'));
|
|
|
205 |
$this->assertEqual('String bar not in DB', $this->tr->get('String &&foo&& not in DB'));
|
|
|
206 |
$this->tr->setParams(array('foo' => 'bar'));
|
|
|
207 |
$this->assertEqual('String bar not in DB', $this->tr->get('String not in DB', null, 'it', 'String &&foo&& not in DB'));
|
|
|
208 |
}
|
|
|
209 |
function testErrorTextDecorator() {
|
|
|
210 |
$lang = 'it';
|
|
|
211 |
$this->tr->setLang($lang);
|
|
|
212 |
//without decorator
|
|
|
213 |
$this->assertEqual('', $this->tr->get('isempty'));
|
|
|
214 |
$expected = array(
|
|
|
215 |
'only_english' => null,
|
|
|
216 |
'only_italian' => 'testo solo in italiano',
|
|
|
217 |
'hello_user' => 'ciao, &&user&&, oggi è il &&day&& &&month&& &&year&& (&&weekday&&)',
|
|
|
218 |
'isempty' => null,
|
|
|
219 |
'prova_conflitto' => 'testo con conflitto - globale',
|
|
|
220 |
'test' => 'stringa di prova',
|
|
|
221 |
'Entirely new string' => null,
|
|
|
222 |
);
|
|
|
223 |
$error_text = $this->tr->getLang($lang, 'error_text');
|
|
|
224 |
//with decorator
|
|
|
225 |
$this->tr =& $this->tr->getDecorator('ErrorText');
|
|
|
226 |
$this->assertEqual($error_text, $this->tr->get('isempty'));
|
|
|
227 |
$this->assertEqual($expected, $this->tr->getRawPage());
|
|
|
228 |
$expected = array(
|
|
|
229 |
'only_english' => $error_text,
|
|
|
230 |
'only_italian' => 'testo solo in italiano',
|
|
|
231 |
'hello_user' => 'ciao, &&user&&, oggi è il &&day&& &&month&& &&year&& (&&weekday&&)',
|
|
|
232 |
'isempty' => $error_text,
|
|
|
233 |
'prova_conflitto' => 'testo con conflitto - globale',
|
|
|
234 |
'test' => 'stringa di prova',
|
|
|
235 |
'Entirely new string' => $error_text,
|
|
|
236 |
);
|
|
|
237 |
$this->assertEqual($expected, $this->tr->getPage());
|
|
|
238 |
}
|
|
|
239 |
function testLangDecorator() {
|
|
|
240 |
$this->tr->setLang('it');
|
|
|
241 |
$this->tr =& $this->tr->getDecorator('Lang');
|
|
|
242 |
$this->tr->setOption('fallbackLang', 'en');
|
|
|
243 |
$this->assertEqual('only english text', $this->tr->get('only_english'));
|
|
|
244 |
$expected = array(
|
|
|
245 |
'only_english' => null,
|
|
|
246 |
'only_italian' => 'testo solo in italiano',
|
|
|
247 |
'hello_user' => 'ciao, &&user&&, oggi è il &&day&& &&month&& &&year&& (&&weekday&&)',
|
|
|
248 |
'isempty' => null,
|
|
|
249 |
'prova_conflitto' => 'testo con conflitto - globale',
|
|
|
250 |
'test' => 'stringa di prova',
|
|
|
251 |
'Entirely new string' => null,
|
|
|
252 |
);
|
|
|
253 |
$this->assertEqual($expected, $this->tr->getRawPage());
|
|
|
254 |
$this->tr =& $this->tr->getDecorator('Lang');
|
|
|
255 |
$this->tr->setOption('fallbackLang', 'de');
|
|
|
256 |
$expected = array(
|
|
|
257 |
'only_english' => 'only english text',
|
|
|
258 |
'only_italian' => 'testo solo in italiano',
|
|
|
259 |
'hello_user' => 'ciao, &&user&&, oggi è il &&day&& &&month&& &&year&& (&&weekday&&)',
|
|
|
260 |
'isempty' => 'this string is empty in English and Italian, but not in German!',
|
|
|
261 |
'test' => 'stringa di prova',
|
|
|
262 |
'prova_conflitto' => 'testo con conflitto - globale',
|
|
|
263 |
'Entirely new string' => 'Entirely new string',
|
|
|
264 |
);
|
|
|
265 |
$this->assertEqual($expected, $this->tr->getPage());
|
|
|
266 |
}
|
|
|
267 |
function testIconvDecorator() {
|
|
|
268 |
$this->assertEqual('venerdì', $this->tr->get('day_5', 'calendar', 'it'));
|
|
|
269 |
$this->tr =& $this->tr->getDecorator('Iconv');
|
|
|
270 |
$this->tr->setOptions(array('encoding' => 'UTF-8'));
|
|
|
271 |
$this->assertEqual('venerdì', $this->tr->get('day_5', 'calendar', 'it'));
|
|
|
272 |
}
|
|
|
273 |
function testSpecialCharsDecorator() {
|
|
|
274 |
$this->assertEqual('venerdì', $this->tr->get('day_5', 'calendar', 'it'));
|
|
|
275 |
$this->tr =& $this->tr->getDecorator('SpecialChars');
|
|
|
276 |
$this->assertEqual('venerdì', $this->tr->get('day_5', 'calendar', 'it'));
|
|
|
277 |
}
|
|
|
278 |
function testCacheMemoryDecorator() {
|
|
|
279 |
$this->tr->setLang('en');
|
|
|
280 |
$original = 'hello &&user&&, today is &&weekday&&, &&day&&th &&month&& &&year&&';
|
|
|
281 |
$this->assertEqual($original, $this->tr->get('hello_user'));
|
|
|
282 |
$this->tr =& $this->tr->getDecorator('CacheMemory');
|
|
|
283 |
$replacements = array('Joe', 'Boe', 'Moe');
|
|
|
284 |
foreach ($replacements as $v) {
|
|
|
285 |
$this->tr->setParams(array('user' => $v));
|
|
|
286 |
$v = str_replace('&&user&&', $v, $original);
|
|
|
287 |
$this->assertEqual($v, $this->tr->get('hello_user'));
|
|
|
288 |
}
|
|
|
289 |
}
|
|
|
290 |
function testMultipleDecorators() {
|
|
|
291 |
$this->tr->setLang('en');
|
|
|
292 |
$this->assertEqual(null, $this->tr->get('only_italian'));
|
|
|
293 |
$this->tr =& $this->tr->getDecorator('Lang');
|
|
|
294 |
$this->tr->setOption('fallbackLang', 'de');
|
|
|
295 |
$this->assertEqual(null, $this->tr->get('only_italian'));
|
|
|
296 |
//in-between decorator
|
|
|
297 |
$this->tr =& $this->tr->getDecorator('Iconv');
|
|
|
298 |
//set option of the Lang decorator, passing through the Iconv decorator
|
|
|
299 |
$this->tr->setOption('fallbackLang', 'it');
|
|
|
300 |
$this->assertEqual('testo solo in italiano', $this->tr->get('only_italian'));
|
|
|
301 |
}
|
|
|
302 |
}
|
|
|
303 |
?>
|