7 * This source file is subject to the new BSD license that is bundled
8 * with this package in the file LICENSE.txt.
9 * It is also available through the world-wide-web at this URL:
10 * http://framework.zend.com/license/new-bsd
11 * If you did not receive a copy of the license and are unable to
12 * obtain it through the world-wide-web, please send an email
13 * to license@zend.com so we can send you a copy immediately.
16 * @package Zend_Locale
17 * @subpackage UnitTests
18 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19 * @license http://framework.zend.com/license/new-bsd New BSD License
23 if (!defined('PHPUnit_MAIN_METHOD')) {
24 define('PHPUnit_MAIN_METHOD', 'Zend_LocaleTest::main');
27 require_once dirname(__FILE__
) . '/../TestHelper.php';
29 // define('TESTS_ZEND_LOCALE_BCMATH_ENABLED', false); // uncomment to disable use of bcmath extension by Zend_Date
34 require_once 'Zend/Locale.php';
35 require_once 'Zend/Cache.php';
39 * @package Zend_Locale
40 * @subpackage UnitTests
41 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
42 * @license http://framework.zend.com/license/new-bsd New BSD License
45 class Zend_LocaleTest
extends PHPUnit_Framework_TestCase
48 * Runs the test methods of this class.
52 public static function main()
54 $suite = new PHPUnit_Framework_TestSuite("Zend_LocaleTest");
55 $result = PHPUnit_TextUI_TestRunner
::run($suite);
58 private $_cache = null;
59 private $_locale = null;
61 public function setUp()
63 $this->_locale
= setlocale(LC_ALL
, 0);
64 setlocale(LC_ALL
, 'de');
65 require_once 'Zend/Cache.php';
66 $this->_cache
= Zend_Cache
::factory('Core', 'File',
67 array('lifetime' => 120, 'automatic_serialization' => true),
68 array('cache_dir' => dirname(__FILE__
) . '/_files/'));
69 Zend_LocaleTestHelper
::resetObject();
70 Zend_LocaleTestHelper
::setCache($this->_cache
);
72 // compatibilityMode is true until 1.8 therefor we have to change it
73 Zend_LocaleTestHelper
::$compatibilityMode = false;
74 putenv("HTTP_ACCEPT_LANGUAGE=,de,en-UK-US;q=0.5,fr_FR;q=0.2");
77 public function tearDown()
79 $this->_cache
->clean(Zend_Cache
::CLEANING_MODE_ALL
);
80 if (is_string($this->_locale
) && strpos($this->_locale
, ';')) {
82 foreach (explode(';', $this->_locale
) as $l) {
83 $tmp = explode('=', $l);
84 $locales[$tmp[0]] = $tmp[1];
86 setlocale(LC_ALL
, $locales);
89 setlocale(LC_ALL
, $this->_locale
);
93 * test for object creation
94 * expected object instance
96 public function testObjectCreation()
98 $this->assertTrue(Zend_LocaleTestHelper
::isLocale('de'));
100 $this->assertTrue(new Zend_LocaleTestHelper() instanceof Zend_Locale
);
101 $this->assertTrue(new Zend_LocaleTestHelper('root') instanceof Zend_Locale
);
103 $locale = new Zend_LocaleTestHelper(Zend_Locale
::ENVIRONMENT
);
104 $this->assertTrue($locale instanceof Zend_Locale
);
105 } catch (Zend_Locale_Exception
$e) {
106 // ignore environments where the locale can not be detected
107 $this->assertContains('Autodetection', $e->getMessage());
111 $this->assertTrue(new Zend_LocaleTestHelper(Zend_Locale
::BROWSER
) instanceof Zend_Locale
);
112 } catch (Zend_Locale_Exception
$e) {
113 // ignore environments where the locale can not be detected
114 $this->assertContains('Autodetection', $e->getMessage());
117 $locale = new Zend_LocaleTestHelper('de');
118 $this->assertTrue(new Zend_LocaleTestHelper($locale) instanceof Zend_Locale
);
120 $locale = new Zend_LocaleTestHelper('auto');
121 $this->assertTrue(new Zend_LocaleTestHelper($locale) instanceof Zend_Locale
);
123 // compatibility tests
124 set_error_handler(array($this, 'errorHandlerIgnore'));
125 Zend_LocaleTestHelper
::$compatibilityMode = true;
126 $this->assertEquals('de', Zend_LocaleTestHelper
::isLocale('de'));
127 restore_error_handler();
131 * test for serialization
134 public function testSerialize()
136 $value = new Zend_LocaleTestHelper('de_DE');
137 $serial = $value->serialize();
138 $this->assertTrue(!empty($serial));
140 $newvalue = unserialize($serial);
141 $this->assertTrue($value->equals($newvalue));
148 public function testToString()
150 $value = new Zend_LocaleTestHelper('de_DE');
151 $this->assertEquals('de_DE', $value->toString());
152 $this->assertEquals('de_DE', $value->__toString());
159 public function testgetOrder()
161 Zend_LocaleTestHelper
::setDefault('de');
162 $value = new Zend_LocaleTestHelper();
163 $default = $value->getOrder();
164 $this->assertTrue(array_key_exists('de', $default));
166 $default = $value->getOrder(Zend_Locale
::BROWSER
);
167 $this->assertTrue(is_array($default));
169 $default = $value->getOrder(Zend_Locale
::ENVIRONMENT
);
170 $this->assertTrue(is_array($default));
172 $default = $value->getOrder(Zend_Locale
::ZFDEFAULT
);
173 $this->assertTrue(is_array($default));
177 * test getEnvironment
180 public function testLocaleDetail()
182 $value = new Zend_LocaleTestHelper('de_AT');
183 $this->assertEquals('de', $value->getLanguage());
184 $this->assertEquals('AT', $value->getRegion());
186 $value = new Zend_LocaleTestHelper('en_US');
187 $this->assertEquals('en', $value->getLanguage());
188 $this->assertEquals('US', $value->getRegion());
190 $value = new Zend_LocaleTestHelper('en');
191 $this->assertEquals('en', $value->getLanguage());
192 $this->assertFalse($value->getRegion());
196 * test getEnvironment
199 public function testEnvironment()
201 $value = new Zend_LocaleTestHelper();
202 $default = $value->getEnvironment();
203 $this->assertTrue(is_array($default));
210 public function testBrowser()
212 $value = new Zend_LocaleTestHelper();
213 $default = $value->getBrowser();
214 $this->assertTrue(is_array($default));
221 public function testCloning()
223 $value = new Zend_LocaleTestHelper('de_DE');
224 $newvalue = clone $value;
225 $this->assertEquals($value->toString(), $newvalue->toString());
232 public function testsetLocale()
234 $value = new Zend_LocaleTestHelper('de_DE');
235 $value->setLocale('en_US');
236 $this->assertEquals('en_US', $value->toString());
238 $value->setLocale('en_AA');
239 $this->assertEquals('en', $value->toString());
241 $value->setLocale('xx_AA');
242 $this->assertEquals('root', $value->toString());
244 $value->setLocale('auto');
245 $this->assertTrue(is_string($value->toString()));
248 $value->setLocale('browser');
249 $this->assertTrue(is_string($value->toString()));
250 } catch (Zend_Locale_Exception
$e) {
251 // ignore environments where the locale can not be detected
252 $this->assertContains('Autodetection', $e->getMessage());
256 $value->setLocale('environment');
257 $this->assertTrue(is_string($value->toString()));
258 } catch (Zend_Locale_Exception
$e) {
259 // ignore environments where the locale can not be detected
260 $this->assertContains('Autodetection', $e->getMessage());
265 * test getLanguageTranslationList
268 public function testgetLanguageTranslationList()
270 set_error_handler(array($this, 'errorHandlerIgnore'));
271 $list = Zend_LocaleTestHelper
::getLanguageTranslationList();
272 $this->assertTrue(is_array($list));
273 $list = Zend_LocaleTestHelper
::getLanguageTranslationList('de');
274 $this->assertTrue(is_array($list));
275 restore_error_handler();
279 * test getLanguageTranslation
282 public function testgetLanguageTranslation()
284 set_error_handler(array($this, 'errorHandlerIgnore'));
285 $this->assertEquals('Deutsch', Zend_LocaleTestHelper
::getLanguageTranslation('de', 'de_AT'));
286 $this->assertEquals('German', Zend_LocaleTestHelper
::getLanguageTranslation('de', 'en'));
287 $this->assertFalse(Zend_LocaleTestHelper
::getLanguageTranslation('xyz'));
288 $this->assertTrue(is_string(Zend_LocaleTestHelper
::getLanguageTranslation('de', 'auto')));
289 restore_error_handler();
293 * test getScriptTranslationList
296 public function testgetScriptTranslationList()
298 set_error_handler(array($this, 'errorHandlerIgnore'));
299 $list = Zend_LocaleTestHelper
::getScriptTranslationList();
300 $this->assertTrue(is_array($list));
302 $list = Zend_LocaleTestHelper
::getScriptTranslationList('de');
303 $this->assertTrue(is_array($list));
304 restore_error_handler();
308 * test getScriptTranslationList
311 public function testgetScriptTranslation()
313 set_error_handler(array($this, 'errorHandlerIgnore'));
314 $this->assertEquals('Arabisch', Zend_LocaleTestHelper
::getScriptTranslation('Arab', 'de_AT'));
315 $this->assertEquals('Arabic', Zend_LocaleTestHelper
::getScriptTranslation('Arab', 'en'));
316 $this->assertFalse(Zend_LocaleTestHelper
::getScriptTranslation('xyz'));
317 restore_error_handler();
321 * test getCountryTranslationList
324 public function testgetCountryTranslationList()
326 set_error_handler(array($this, 'errorHandlerIgnore'));
327 $list = Zend_LocaleTestHelper
::getCountryTranslationList();
328 $this->assertTrue(is_array($list));
330 $list = Zend_LocaleTestHelper
::getCountryTranslationList('de');
331 $this->assertEquals("Vereinigte Staaten", $list['US']);
332 restore_error_handler();
336 * test getCountryTranslation
339 public function testgetCountryTranslation()
341 set_error_handler(array($this, 'errorHandlerIgnore'));
342 $this->assertEquals('Deutschland', Zend_LocaleTestHelper
::getCountryTranslation('DE', 'de_DE'));
343 $this->assertEquals('Germany', Zend_LocaleTestHelper
::getCountryTranslation('DE', 'en'));
344 $this->assertFalse(Zend_LocaleTestHelper
::getCountryTranslation('xyz'));
345 restore_error_handler();
349 * test getTerritoryTranslationList
352 public function testgetTerritoryTranslationList()
354 set_error_handler(array($this, 'errorHandlerIgnore'));
355 $list = Zend_LocaleTestHelper
::getTerritoryTranslationList();
356 $this->assertTrue(is_array($list));
358 $list = Zend_LocaleTestHelper
::getTerritoryTranslationList('de');
359 $this->assertTrue(is_array($list));
360 restore_error_handler();
364 * test getTerritoryTranslation
367 public function testgetTerritoryTranslation()
369 set_error_handler(array($this, 'errorHandlerIgnore'));
370 $this->assertEquals('Afrika', Zend_LocaleTestHelper
::getTerritoryTranslation('002', 'de_AT'));
371 $this->assertEquals('Africa', Zend_LocaleTestHelper
::getTerritoryTranslation('002', 'en'));
372 $this->assertFalse(Zend_LocaleTestHelper
::getTerritoryTranslation('xyz'));
373 $this->assertTrue(is_string(Zend_LocaleTestHelper
::getTerritoryTranslation('002', 'auto')));
374 restore_error_handler();
378 * test getTranslation
381 public function testgetTranslation()
384 $temp = Zend_LocaleTestHelper
::getTranslation('xx');
386 } catch (Zend_Locale_Exception
$e) {
387 $this->assertContains('Unknown detail (', $e->getMessage());
390 $this->assertEquals('Deutsch', Zend_LocaleTestHelper
::getTranslation('de', 'language', 'de_DE'));
391 $this->assertEquals('German', Zend_LocaleTestHelper
::getTranslation('de', 'language', 'en'));
392 $this->assertFalse(Zend_LocaleTestHelper
::getTranslation('xx', 'language'));
394 $this->assertEquals('Lateinisch', Zend_LocaleTestHelper
::getTranslation('Latn', 'script', 'de_DE'));
395 $this->assertEquals('Latin', Zend_LocaleTestHelper
::getTranslation('Latn', 'script', 'en'));
396 $this->assertFalse(Zend_LocaleTestHelper
::getTranslation('xyxy', 'script'));
398 $this->assertEquals('Österreich', Zend_LocaleTestHelper
::getTranslation('AT', 'country', 'de_DE'));
399 $this->assertEquals('Austria', Zend_LocaleTestHelper
::getTranslation('AT', 'country', 'en'));
400 $this->assertFalse(Zend_LocaleTestHelper
::getTranslation('xx', 'country'));
402 $this->assertEquals('Afrika', Zend_LocaleTestHelper
::getTranslation('002', 'territory', 'de_DE'));
403 $this->assertEquals('Africa', Zend_LocaleTestHelper
::getTranslation('002', 'territory', 'en'));
404 $this->assertFalse(Zend_LocaleTestHelper
::getTranslation('xxx', 'territory'));
406 $this->assertEquals('Januar', Zend_LocaleTestHelper
::getTranslation('1', 'month', 'de_DE'));
407 $this->assertEquals('January', Zend_LocaleTestHelper
::getTranslation('1', 'month', 'en'));
408 $this->assertFalse(Zend_LocaleTestHelper
::getTranslation('x', 'month'));
410 $this->assertEquals('Jan', Zend_LocaleTestHelper
::getTranslation(array('gregorian', 'format', 'abbreviated', '1'), 'month', 'de_DE'));
411 $this->assertEquals('Jan', Zend_LocaleTestHelper
::getTranslation(array('gregorian', 'format', 'abbreviated', '1'), 'month', 'en'));
412 $this->assertFalse(Zend_LocaleTestHelper
::getTranslation(array('gregorian', 'format', 'abbreviated', 'x'), 'month'));
414 $this->assertEquals('J', Zend_LocaleTestHelper
::getTranslation(array('gregorian', 'stand-alone', 'narrow', '1'), 'month', 'de_DE'));
415 $this->assertEquals('J', Zend_LocaleTestHelper
::getTranslation(array('gregorian', 'stand-alone', 'narrow', '1'), 'month', 'en'));
416 $this->assertFalse(Zend_LocaleTestHelper
::getTranslation(array('gregorian', 'stand-alone', 'narrow', 'x'), 'month'));
418 $this->assertEquals('Sonntag', Zend_LocaleTestHelper
::getTranslation('sun', 'day', 'de_DE'));
419 $this->assertEquals('Sunday', Zend_LocaleTestHelper
::getTranslation('sun', 'day', 'en'));
420 $this->assertFalse(Zend_LocaleTestHelper
::getTranslation('xxx', 'day'));
422 $this->assertEquals('So.', Zend_LocaleTestHelper
::getTranslation(array('gregorian', 'format', 'abbreviated', 'sun'), 'day', 'de_DE'));
423 $this->assertEquals('Sun', Zend_LocaleTestHelper
::getTranslation(array('gregorian', 'format', 'abbreviated', 'sun'), 'day', 'en'));
424 $this->assertFalse(Zend_LocaleTestHelper
::getTranslation(array('gregorian', 'format', 'abbreviated', 'xxx'), 'day'));
426 $this->assertEquals('S', Zend_LocaleTestHelper
::getTranslation(array('gregorian', 'stand-alone', 'narrow', 'sun'), 'day', 'de_DE'));
427 $this->assertEquals('S', Zend_LocaleTestHelper
::getTranslation(array('gregorian', 'stand-alone', 'narrow', 'sun'), 'day', 'en'));
428 $this->assertFalse(Zend_LocaleTestHelper
::getTranslation(array('gregorian', 'stand-alone', 'narrow', 'xxx'), 'day'));
430 $this->assertEquals('EEEE, d. MMMM y', Zend_LocaleTestHelper
::getTranslation('full', 'date', 'de_DE'));
431 $this->assertEquals('EEEE, MMMM d, y', Zend_LocaleTestHelper
::getTranslation('full', 'date', 'en'));
432 $this->assertFalse(Zend_LocaleTestHelper
::getTranslation('xxxx', 'date'));
434 $this->assertEquals("HH:mm:ss zzzz", Zend_LocaleTestHelper
::getTranslation('full', 'time', 'de_DE'));
435 $this->assertEquals('h:mm:ss a zzzz', Zend_LocaleTestHelper
::getTranslation('full', 'time', 'en'));
436 $this->assertFalse(Zend_LocaleTestHelper
::getTranslation('xxxx', 'time'));
438 $this->assertEquals('Wien', Zend_LocaleTestHelper
::getTranslation('Europe/Vienna', 'citytotimezone', 'de_DE'));
439 $this->assertEquals("St. John's", Zend_LocaleTestHelper
::getTranslation('America/St_Johns', 'citytotimezone', 'en'));
440 $this->assertFalse(Zend_LocaleTestHelper
::getTranslation('xxxx', 'citytotimezone'));
442 $this->assertEquals('Euro', Zend_LocaleTestHelper
::getTranslation('EUR', 'nametocurrency', 'de_DE'));
443 $this->assertEquals('Euro', Zend_LocaleTestHelper
::getTranslation('EUR', 'nametocurrency', 'en'));
444 $this->assertFalse(Zend_LocaleTestHelper
::getTranslation('xxx', 'nametocurrency'));
446 $this->assertEquals('EUR', Zend_LocaleTestHelper
::getTranslation('Euro', 'currencytoname', 'de_DE'));
447 $this->assertEquals('EUR', Zend_LocaleTestHelper
::getTranslation('Euro', 'currencytoname', 'en'));
448 $this->assertFalse(Zend_LocaleTestHelper
::getTranslation('xxx', 'currencytoname'));
450 $this->assertEquals('Fr.', Zend_LocaleTestHelper
::getTranslation('CHF', 'currencysymbol', 'de_DE'));
451 $this->assertEquals('Fr.', Zend_LocaleTestHelper
::getTranslation('CHF', 'currencysymbol', 'en'));
452 $this->assertFalse(Zend_LocaleTestHelper
::getTranslation('xxx', 'currencysymbol'));
454 $this->assertEquals('EUR', Zend_LocaleTestHelper
::getTranslation('AT', 'currencytoregion', 'de_DE'));
455 $this->assertEquals('EUR', Zend_LocaleTestHelper
::getTranslation('AT', 'currencytoregion', 'en'));
456 $this->assertFalse(Zend_LocaleTestHelper
::getTranslation('xxx', 'currencytoregion'));
458 $this->assertEquals('011 014 015 017 018', Zend_LocaleTestHelper
::getTranslation('002', 'regiontoterritory', 'de_DE'));
459 $this->assertEquals('011 014 015 017 018', Zend_LocaleTestHelper
::getTranslation('002', 'regiontoterritory', 'en'));
460 $this->assertFalse(Zend_LocaleTestHelper
::getTranslation('xxx', 'regiontoterritory'));
462 $this->assertEquals('AT BE CH DE LI LU', Zend_LocaleTestHelper
::getTranslation('de', 'territorytolanguage', 'de_DE'));
463 $this->assertEquals('AT BE CH DE LI LU', Zend_LocaleTestHelper
::getTranslation('de', 'territorytolanguage', 'en'));
464 $this->assertFalse(Zend_LocaleTestHelper
::getTranslation('xxx', 'territorytolanguage'));
468 * test getTranslationList
471 public function testgetTranslationList()
474 $temp = Zend_LocaleTestHelper
::getTranslationList();
476 } catch (Zend_Locale_Exception
$e) {
477 $this->assertContains('Unknown list (', $e->getMessage());
480 $this->assertTrue(in_array('Deutsch', Zend_LocaleTestHelper
::getTranslationList('language', 'de_DE')));
481 $this->assertTrue(in_array('German', Zend_LocaleTestHelper
::getTranslationList('language', 'en')));
483 $this->assertTrue(in_array('Lateinisch', Zend_LocaleTestHelper
::getTranslationList('script', 'de_DE')));
484 $this->assertTrue(in_array('Latin', Zend_LocaleTestHelper
::getTranslationList('script', 'en')));
486 $this->assertTrue(in_array('Afrika', Zend_LocaleTestHelper
::getTranslationList('territory', 'de_DE')));
487 $this->assertTrue(in_array('Africa', Zend_LocaleTestHelper
::getTranslationList('territory', 'en')));
489 $this->assertTrue(in_array('Chinesischer Kalender', Zend_LocaleTestHelper
::getTranslationList('type', 'de_DE', 'calendar')));
490 $this->assertTrue(in_array('Chinese Calendar', Zend_LocaleTestHelper
::getTranslationList('type', 'en', 'calendar')));
492 $this->assertTrue(in_array('Januar', Zend_LocaleTestHelper
::getTranslationList('month', 'de_DE')));
493 $this->assertTrue(in_array('January', Zend_LocaleTestHelper
::getTranslationList('month', 'en')));
495 $this->assertTrue(in_array('Jan', Zend_LocaleTestHelper
::getTranslationList('month', 'de_DE', array('gregorian', 'format', 'abbreviated'))));
496 $this->assertTrue(in_array('Jan', Zend_LocaleTestHelper
::getTranslationList('month', 'en', array('gregorian', 'format', 'abbreviated'))));
498 $this->assertTrue(in_array('J', Zend_LocaleTestHelper
::getTranslationList('month', 'de_DE', array('gregorian', 'stand-alone', 'narrow'))));
499 $this->assertTrue(in_array('J', Zend_LocaleTestHelper
::getTranslationList('month', 'en', array('gregorian', 'stand-alone', 'narrow'))));
501 $this->assertTrue(in_array('Sonntag', Zend_LocaleTestHelper
::getTranslationList('day', 'de_DE')));
502 $this->assertTrue(in_array('Sunday', Zend_LocaleTestHelper
::getTranslationList('day', 'en')));
504 $this->assertTrue(in_array('So.', Zend_LocaleTestHelper
::getTranslationList('day', 'de_DE', array('gregorian', 'format', 'abbreviated'))));
505 $this->assertTrue(in_array('Sun', Zend_LocaleTestHelper
::getTranslationList('day', 'en', array('gregorian', 'format', 'abbreviated'))));
507 $this->assertTrue(in_array('S', Zend_LocaleTestHelper
::getTranslationList('day', 'de_DE', array('gregorian', 'stand-alone', 'narrow'))));
508 $this->assertTrue(in_array('S', Zend_LocaleTestHelper
::getTranslationList('day', 'en', array('gregorian', 'stand-alone', 'narrow'))));
510 $this->assertTrue(in_array('EEEE, d. MMMM y', Zend_LocaleTestHelper
::getTranslationList('date', 'de_DE')));
511 $this->assertTrue(in_array('EEEE, MMMM d, y', Zend_LocaleTestHelper
::getTranslationList('date', 'en')));
513 $this->assertTrue(in_array("HH:mm:ss zzzz", Zend_LocaleTestHelper
::getTranslationList('time', 'de_DE')));
514 $this->assertTrue(in_array("h:mm:ss a z", Zend_LocaleTestHelper
::getTranslationList('time', 'en')));
516 $this->assertTrue(in_array('Wien', Zend_LocaleTestHelper
::getTranslationList('citytotimezone', 'de_DE')));
517 $this->assertTrue(in_array("St. John's", Zend_LocaleTestHelper
::getTranslationList('citytotimezone', 'en')));
519 $this->assertTrue(in_array('Euro', Zend_LocaleTestHelper
::getTranslationList('nametocurrency', 'de_DE')));
520 $this->assertTrue(in_array('Euro', Zend_LocaleTestHelper
::getTranslationList('nametocurrency', 'en')));
522 $this->assertTrue(in_array('EUR', Zend_LocaleTestHelper
::getTranslationList('currencytoname', 'de_DE')));
523 $this->assertTrue(in_array('EUR', Zend_LocaleTestHelper
::getTranslationList('currencytoname', 'en')));
525 $this->assertTrue(in_array('Fr.', Zend_LocaleTestHelper
::getTranslationList('currencysymbol', 'de_DE')));
526 $this->assertTrue(in_array('Fr.', Zend_LocaleTestHelper
::getTranslationList('currencysymbol', 'en')));
528 $this->assertTrue(in_array('EUR', Zend_LocaleTestHelper
::getTranslationList('currencytoregion', 'de_DE')));
529 $this->assertTrue(in_array('EUR', Zend_LocaleTestHelper
::getTranslationList('currencytoregion', 'en')));
531 $this->assertTrue(in_array('AU NF NZ', Zend_LocaleTestHelper
::getTranslationList('regiontoterritory', 'de_DE')));
532 $this->assertTrue(in_array('AU NF NZ', Zend_LocaleTestHelper
::getTranslationList('regiontoterritory', 'en')));
534 $this->assertTrue(in_array('CZ', Zend_LocaleTestHelper
::getTranslationList('territorytolanguage', 'de_DE')));
535 $this->assertTrue(in_array('CZ', Zend_LocaleTestHelper
::getTranslationList('territorytolanguage', 'en')));
537 $char = Zend_LocaleTestHelper
::getTranslationList('characters', 'de_DE');
538 $this->assertEquals("[a ä b-o ö p-s ß t u ü v-z]", $char['characters']);
539 $this->assertEquals("[á à ă â å ā æ ç é è ĕ ê ë ē í ì ĭ î ï ī ñ ó ò ŏ ô ø ō œ ú ù ŭ û ū ÿ]", $char['auxiliary']);
540 $this->assertEquals("[a-z]", $char['currencySymbol']);
542 $char = Zend_LocaleTestHelper
::getTranslationList('characters', 'en');
543 $this->assertEquals("[a-z]", $char['characters']);
544 $this->assertEquals("[á à ă â å ä ã ā æ ç é è ĕ ê ë ē í ì ĭ î ï ī ñ ó ò ŏ ô ö ø ō œ ß ú ù ŭ û ü ū ÿ]", $char['auxiliary']);
545 $this->assertEquals("[a-c č d-l ł m-z]", $char['currencySymbol']);
552 public function testEquals()
554 $value = new Zend_LocaleTestHelper('de_DE');
555 $serial = new Zend_LocaleTestHelper('de_DE');
556 $serial2 = new Zend_LocaleTestHelper('de_AT');
557 $this->assertTrue($value->equals($serial));
558 $this->assertFalse($value->equals($serial2));
565 public function testgetQuestion()
567 $list = Zend_LocaleTestHelper
::getQuestion();
568 $this->assertTrue(isset($list['yes']));
570 $list = Zend_LocaleTestHelper
::getQuestion('de');
571 $this->assertEquals('ja', $list['yes']);
573 $this->assertTrue(is_array(Zend_LocaleTestHelper
::getQuestion('auto')));
576 $this->assertTrue(is_array(Zend_LocaleTestHelper
::getQuestion('browser')));
577 } catch (Zend_Locale_Exception
$e) {
578 $this->assertContains('Autodetection', $e->getMessage());
582 $this->assertTrue(is_array(Zend_LocaleTestHelper
::getQuestion('environment')));
583 } catch (Zend_Locale_Exception
$e) {
584 $this->assertContains('ocale', $e->getMessage());
592 public function testgetBrowser()
594 Zend_LocaleTestHelper
::resetObject();
595 $value = new Zend_LocaleTestHelper();
596 $list = $value->getBrowser();
598 $this->markTestSkipped('Browser autodetection not possible in current environment');
600 $this->assertTrue(isset($list['de']));
601 $this->assertEquals(array('de' => 1, 'en_UK' => 0.5, 'en_US' => 0.5,
602 'en' => 0.5, 'fr_FR' => 0.2, 'fr' => 0.2), $list);
604 Zend_LocaleTestHelper
::resetObject();
605 putenv("HTTP_ACCEPT_LANGUAGE=");
607 $value = new Zend_LocaleTestHelper();
608 $list = $value->getBrowser();
609 $this->assertEquals(array(), $list);
613 * test getHttpCharset
616 public function testgetHttpCharset()
618 Zend_LocaleTestHelper
::resetObject();
619 putenv("HTTP_ACCEPT_CHARSET=");
620 $value = new Zend_LocaleTestHelper();
621 $list = $value->getHttpCharset();
622 $this->assertTrue(empty($list));
624 Zend_LocaleTestHelper
::resetObject();
625 putenv("HTTP_ACCEPT_CHARSET=,iso-8859-1, utf-8, utf-16, *;q=0.1");
626 $value = new Zend_LocaleTestHelper();
627 $list = $value->getHttpCharset();
628 $this->assertTrue(isset($list['utf-8']));
635 public function testIsLocale()
637 $locale = new Zend_LocaleTestHelper('ar');
638 $this->assertTrue(Zend_LocaleTestHelper
::isLocale($locale));
639 $this->assertTrue(Zend_LocaleTestHelper
::isLocale('de'));
640 $this->assertTrue(Zend_LocaleTestHelper
::isLocale('de_AT'));
641 $this->assertTrue(Zend_LocaleTestHelper
::isLocale('de_xx'));
642 $this->assertFalse(Zend_LocaleTestHelper
::isLocale('yy'));
643 $this->assertFalse(Zend_LocaleTestHelper
::isLocale(1234));
644 $this->assertFalse(Zend_LocaleTestHelper
::isLocale('', true));
645 $this->assertFalse(Zend_LocaleTestHelper
::isLocale('', false));
646 $this->assertTrue(Zend_LocaleTestHelper
::isLocale('auto'));
647 $this->assertTrue(Zend_LocaleTestHelper
::isLocale('browser'));
648 if (count(Zend_Locale
::getEnvironment()) != 0) {
649 $this->assertTrue(Zend_LocaleTestHelper
::isLocale('environment'));
652 set_error_handler(array($this, 'errorHandlerIgnore'));
653 Zend_LocaleTestHelper
::$compatibilityMode = true;
654 $this->assertEquals('ar', Zend_LocaleTestHelper
::isLocale($locale));
655 $this->assertEquals('de', Zend_LocaleTestHelper
::isLocale('de'));
656 $this->assertEquals('de_AT', Zend_LocaleTestHelper
::isLocale('de_AT'));
657 $this->assertEquals('de', Zend_LocaleTestHelper
::isLocale('de_xx'));
658 $this->assertFalse(Zend_LocaleTestHelper
::isLocale('yy'));
659 $this->assertFalse(Zend_LocaleTestHelper
::isLocale(1234));
660 $this->assertFalse(Zend_LocaleTestHelper
::isLocale('', true));
661 $this->assertFalse(Zend_LocaleTestHelper
::isLocale('', false));
662 $this->assertTrue(is_string(Zend_LocaleTestHelper
::isLocale('auto')));
663 $this->assertTrue(is_string(Zend_LocaleTestHelper
::isLocale('browser')));
664 if (count(Zend_Locale
::getEnvironment()) != 0) {
665 $this->assertTrue(is_string(Zend_LocaleTestHelper
::isLocale('environment')));
667 restore_error_handler();
674 public function testGetLocaleList()
676 $this->assertTrue(is_array(Zend_LocaleTestHelper
::getLocaleList()));
683 public function testsetDefault()
686 Zend_LocaleTestHelper
::setDefault('auto');
688 } catch (Zend_Locale_Exception
$e) {
689 $this->assertContains("full qualified locale", $e->getMessage());
693 Zend_LocaleTestHelper
::setDefault('de_XX');
694 $locale = new Zend_LocaleTestHelper();
695 $this->assertTrue($locale instanceof Zend_Locale
); // should defer to 'de' or any other standard locale
696 } catch (Zend_Locale_Exception
$e) {
697 $this->fail(); // de_XX should automatically degrade to 'de'
701 Zend_LocaleTestHelper
::setDefault('xy_ZZ');
703 } catch (Zend_Locale_Exception
$e) {
704 $this->assertContains("Unknown locale", $e->getMessage());
708 Zend_LocaleTestHelper
::setDefault('de', 101);
710 } catch (Zend_Locale_Exception
$e) {
711 $this->assertContains("Quality must be between", $e->getMessage());
715 Zend_LocaleTestHelper
::setDefault('de', 90);
716 $locale = new Zend_LocaleTestHelper();
717 $this->assertTrue($locale instanceof Zend_Locale
); // should defer to 'de' or any other standard locale
718 } catch (Zend_Locale_Exception
$e) {
723 Zend_LocaleTestHelper
::setDefault('de-AT', 90);
724 $locale = new Zend_LocaleTestHelper();
725 $this->assertTrue($locale instanceof Zend_Locale
);
726 } catch (Zend_Locale_Exception
$e) {
734 public function testgetDefault() {
735 Zend_LocaleTestHelper
::setDefault('de');
736 $this->assertTrue(array_key_exists('de', Zend_LocaleTestHelper
::getDefault()));
738 // compatibility tests
739 set_error_handler(array($this, 'errorHandlerIgnore'));
740 Zend_LocaleTestHelper
::$compatibilityMode = true;
741 $this->assertTrue(array_key_exists('de', Zend_LocaleTestHelper
::getDefault(Zend_Locale
::BROWSER
)));
742 restore_error_handler();
746 * Caching method tests
748 public function testCaching()
750 $cache = Zend_LocaleTestHelper
::getCache();
751 $this->assertTrue($cache instanceof Zend_Cache_Core
);
752 $this->assertTrue(Zend_LocaleTestHelper
::hasCache());
754 Zend_LocaleTestHelper
::clearCache();
755 $this->assertTrue(Zend_LocaleTestHelper
::hasCache());
757 Zend_LocaleTestHelper
::removeCache();
758 $this->assertFalse(Zend_LocaleTestHelper
::hasCache());
762 * Caching method tests
764 public function testFindingTheProperLocale()
766 $this->assertTrue(is_string(Zend_LocaleTestHelper
::findLocale()));
767 $this->assertEquals('de', Zend_LocaleTestHelper
::findLocale('de'));
768 $this->assertEquals('de', Zend_LocaleTestHelper
::findLocale('de_XX'));
771 $locale = Zend_LocaleTestHelper
::findLocale('xx_YY');
773 } catch (Zend_Locale_Exception
$e) {
774 $this->assertContains('is no known locale', $e->getMessage());
777 Zend_Registry
::set('Zend_Locale', 'de');
778 $this->assertEquals('de', Zend_LocaleTestHelper
::findLocale());
785 public function testZF3617() {
786 $value = new Zend_LocaleTestHelper('en-US');
787 $this->assertEquals('en_US', $value->toString());
793 public function testZF4963() {
794 $value = new Zend_LocaleTestHelper();
795 $locale = $value->toString();
796 $this->assertTrue(!empty($locale));
798 $this->assertFalse(Zend_LocaleTestHelper
::isLocale(null));
800 $value = new Zend_LocaleTestHelper(0);
801 $value = $value->toString();
802 $this->assertTrue(!empty($value));
804 $this->assertFalse(Zend_LocaleTestHelper
::isLocale(0));
808 * test MultiPartLocales
811 public function testLongLocale()
813 $locale = new Zend_LocaleTestHelper('de_Latn_DE');
814 $this->assertEquals('de_DE', $locale->toString());
815 $this->assertTrue(Zend_LocaleTestHelper
::isLocale('de_Latn_CAR_DE_sup3_win'));
817 $locale = new Zend_LocaleTestHelper('de_Latn_DE');
818 $this->assertEquals('de_DE', $locale->toString());
820 $this->assertEquals('fr_FR', Zend_Locale
::findLocale('fr-Arab-FR'));
827 public function testSunLocale()
829 $this->assertTrue(Zend_LocaleTestHelper
::isLocale('de_DE.utf8'));
830 $this->assertFalse(Zend_LocaleTestHelper
::isLocale('de.utf8.DE'));
836 public function testFailedLocaleOnPreTranslations()
838 $this->assertEquals('Andorra', Zend_LocaleTestHelper
::getTranslation('AD', 'country', 'gl_GL'));
842 * Ignores a raised PHP error when in effect, but throws a flag to indicate an error occurred
844 * @param integer $errno
845 * @param string $errstr
846 * @param string $errfile
847 * @param integer $errline
848 * @param array $errcontext
851 public function errorHandlerIgnore($errno, $errstr, $errfile, $errline, array $errcontext)
853 $this->_errorOccurred
= true;
857 class Zend_LocaleTestHelper
extends Zend_Locale
859 public static function resetObject()
862 self
::$_environment = null;
863 self
::$_browser = null;
867 // Call Zend_LocaleTest::main() if this source file is executed directly.
868 if (PHPUnit_MAIN_METHOD
== "Zend_LocaleTest::main") {
869 Zend_LocaleTest
::main();