public function setUp() { if (Registry::isRegistered('Zend_Locale')) { $registry = Zend\Registry::getInstance(); unset($registry['Zend_Locale']); } Data\Data::removeCache(); $this->_locale = setlocale(LC_ALL, 0); setlocale(LC_ALL, 'de'); }
/** * Disables the set cache * * @param boolean $flag True disables any set cache, default is false * @return void */ public static function disableCache($flag) { Data\Data::disableCache($flag); }
/** * test for reading intervalformat from locale * expected array */ public function testUnit() { $value = Data::getList('de_AT', 'unit'); $result = array('day' => array('one' => '{0} Tag', 'other' => '{0} Tage'), 'hour' => array('one' => '{0} Stunde', 'other' => '{0} Stunden'), 'minute' => array('one' => '{0} Minute', 'other' => '{0} Minuten'), 'month' => array('one' => '{0} Monat', 'other' => '{0} Monate'), 'second' => array('one' => '{0} Sekunde', 'other' => '{0} Sekunden'), 'week' => array('one' => '{0} Woche', 'other' => '{0} Wochen'), 'year' => array('one' => '{0} Jahr', 'other' => '{0} Jahre')); $this->assertEquals($result, $value); $value = Data::getContent('de_AT', 'unit', array('day', 'one')); $this->assertEquals('{0} Tag', $value); }
/** * Returns the ISO Token for all localized constants * * @param string $token Token to normalize * @param string $locale Locale to search * @return string */ protected static function _getLocalizedToken($token, $locale) { switch ($token) { case self::ISO_8601: return "yyyy-MM-ddThh:mm:ss"; break; case self::RFC_2822: return "EEE, dd MMM yyyy HH:mm:ss"; break; case self::DATES: return Data::getContent($locale, 'date'); break; case self::DATE_FULL: return Data::getContent($locale, 'date', array('gregorian', 'full')); break; case self::DATE_LONG: return Data::getContent($locale, 'date', array('gregorian', 'long')); break; case self::DATE_MEDIUM: return Data::getContent($locale, 'date', array('gregorian', 'medium')); break; case self::DATE_SHORT: return Data::getContent($locale, 'date', array('gregorian', 'short')); break; case self::TIMES: return Data::getContent($locale, 'date'); break; case self::TIME_FULL: return Data::getContent($locale, 'time', array('gregorian', 'full')); break; case self::TIME_LONG: return Data::getContent($locale, 'date', array('gregorian', 'long')); break; case self::TIME_MEDIUM: return Data::getContent($locale, 'date', array('gregorian', 'medium')); break; case self::TIME_SHORT: return Data::getContent($locale, 'date', array('gregorian', 'short')); break; case self::DATETIME: return Data::getContent($locale, 'datetime'); break; case self::DATETIME_FULL: return Data::getContent($locale, 'datetime', array('gregorian', 'full')); break; case self::DATETIME_LONG: return Data::getContent($locale, 'datetime', array('gregorian', 'long')); break; case self::DATETIME_MEDIUM: return Data::getContent($locale, 'datetime', array('gregorian', 'medium')); break; case self::DATETIME_SHORT: return Data::getContent($locale, 'datetime', array('gregorian', 'short')); break; case self::ATOM: case self::RFC_3339: case self::W3C: return "yyyy-MM-DD HH:mm:ss"; break; case self::COOKIE: case self::RFC_850: return "EEEE, dd-MM-yyyy HH:mm:ss"; break; case self::RFC_822: case self::RFC_1036: case self::RFC_1123: case self::RSS: return "EEE, dd MM yyyy HH:mm:ss"; break; } return $token; }
/** * test setOption * expected boolean */ public function testSetOption() { $this->assertEquals(8, count(Format::setOptions(array('format_type' => 'php')))); $this->assertTrue(is_array(Format::setOptions())); try { $this->assertTrue(Format::setOptions(array('format_type' => 'xxx'))); $this->fail("exception expected"); } catch (LocaleException $e) { // success } try { $this->assertTrue(Format::setOptions(array('myformat' => 'xxx'))); $this->fail("exception expected"); } catch (LocaleException $e) { // success } $format = Format::setOptions(array('locale' => 'de', 'number_format' => Format::STANDARD)); $test = Data::getContent('de', 'decimalnumber'); $this->assertEquals($test, $format['number_format']); try { $this->assertFalse(Format::setOptions(array('number_format' => array('x' => 'x')))); $this->fail("exception expected"); } catch (LocaleException $e) { // success } $format = Format::setOptions(array('locale' => 'de', 'date_format' => Format::STANDARD)); $test = Format::getDateFormat('de'); $this->assertEquals($test, $format['date_format']); try { $this->assertFalse(Format::setOptions(array('date_format' => array('x' => 'x')))); $this->fail("exception expected"); } catch (LocaleException $e) { // success } try { $this->assertFalse(is_array(Format::setOptions(array('fix_date' => 'no')))); $this->fail("exception expected"); } catch (LocaleException $e) { // success } $format = Format::setOptions(array('locale' => Format::STANDARD)); $locale = new Locale(); $this->assertEquals($locale->toString(), $format['locale']); try { $this->assertFalse(is_array(Format::setOptions(array('locale' => 'nolocale')))); $this->fail("exception expected"); } catch (LocaleException $e) { // success } try { $this->assertFalse(is_array(Format::setOptions(array('precision' => 50)))); $this->fail("exception expected"); } catch (LocaleException $e) { // success } // test interaction between class-wide default date format and using locale's default format try { $result = array('date_format' => 'MMM d, y', 'locale' => 'en_US', 'month' => '7', 'day' => '4', 'year' => '2007'); Format::setOptions(array('format_type' => 'iso', 'date_format' => 'MMM d, y', 'locale' => 'en_US')); // test setUp } catch (LocaleException $e) { $this->fail("exception expected"); } try { // uses global date_format with global locale $this->assertSame($result, Format::getDate('July 4, 2007')); } catch (LocaleException $e) { $this->fail("exception expected"); } try { // uses global date_format with given locale $this->assertSame($result, Format::getDate('July 4, 2007', array('locale' => 'en_US'))); } catch (LocaleException $e) { $this->fail("exception expected"); } try { // sets a new global date format Format::setOptions(array('date_format' => 'M-d-y')); } catch (LocaleException $e) { $this->fail("exception expected"); } try { // uses global date format with given locale // but this date format differs from the original set... (MMMM d, yyyy != M-d-y) $expected = Format::getDate('July 4, 2007', array('locale' => 'en_US')); $this->assertSame($expected['year'], $result['year']); $this->assertSame($expected['month'], $result['month']); $this->assertSame($expected['day'], $result['day']); } catch (LocaleException $e) { $this->fail("exception expected"); } try { // the following should not be used... instead of null, Locale::ZFDEFAULT should be used // uses given local with standard format from this locale $this->assertSame($result, Format::getDate('July 4, 2007', array('locale' => 'en_US', 'date_format' => null))); } catch (LocaleException $e) { $this->fail("exception expected"); } try { // uses given locale with standard format from this locale $this->assertSame($result, Format::getDate('July 4, 2007', array('locale' => 'en_US', 'date_format' => Format::STANDARD))); } catch (LocaleException $e) { $this->fail("exception expected"); } try { // uses standard locale with standard format from this locale $expect = Format::getDate('July 4, 2007', array('locale' => Format::STANDARD)); $testlocale = new Locale(); $this->assertEquals($testlocale->toString(), $expect['locale']); } catch (LocaleException $e) { $this->fail("exception expected"); } Format::setOptions(array('date_format' => null, 'locale' => null)); // test tearDown }