[Locale] fixed tests
This commit is contained in:
parent
86da1b3bf4
commit
90d6dc3791
|
@ -89,7 +89,9 @@ class DateTimeToLocalizedStringTransformerTest extends DateTimeTestCase
|
|||
{
|
||||
$transformer = new DateTimeToLocalizedStringTransformer('UTC', 'UTC', null, \IntlDateFormatter::LONG);
|
||||
|
||||
$this->assertEquals('03.02.2010 04:05:06 GMT+00:00', $transformer->transform($this->dateTime));
|
||||
$expected = $this->isLowerThanIcuVersion('4.8') ? '03.02.2010 04:05:06 GMT+00:00' : '03.02.2010 04:05:06 GMT';
|
||||
|
||||
$this->assertEquals($expected, $transformer->transform($this->dateTime));
|
||||
}
|
||||
|
||||
public function testTransformFullTime()
|
||||
|
@ -100,7 +102,9 @@ class DateTimeToLocalizedStringTransformerTest extends DateTimeTestCase
|
|||
|
||||
$transformer = new DateTimeToLocalizedStringTransformer('UTC', 'UTC', null, \IntlDateFormatter::FULL);
|
||||
|
||||
$this->assertEquals('03.02.2010 04:05:06 GMT+00:00', $transformer->transform($this->dateTime));
|
||||
$expected = $this->isLowerThanIcuVersion('4.8') ? '03.02.2010 04:05:06 GMT+00:00' : '03.02.2010 04:05:06 GMT';
|
||||
|
||||
$this->assertEquals($expected, $transformer->transform($this->dateTime));
|
||||
}
|
||||
|
||||
public function testTransformToDifferentLocale()
|
||||
|
|
|
@ -175,7 +175,11 @@ class FullTransformer
|
|||
{
|
||||
$that = $this;
|
||||
|
||||
$escapedPattern = preg_quote($pattern, '/');
|
||||
// $escapedPattern = preg_quote($pattern, '/');
|
||||
|
||||
// ICU 4.8 recognizes slash ("/") in a value to be parsed as a dash ("-") when parsing a value that
|
||||
// TODO: how to escape the regex metachars and still recognize "/" as "-" and vice-versa?
|
||||
$escapedPattern = preg_replace('/\-|\//', '[\/\-]', $pattern);
|
||||
|
||||
$reverseMatchingRegExp = preg_replace_callback($this->regExp, function($matches) use ($that) {
|
||||
$length = strlen($matches[0]);
|
||||
|
|
|
@ -33,7 +33,10 @@ class TimeZoneTransformer extends Transformer
|
|||
throw new NotImplementedException('Time zone different than GMT or UTC is not supported as a formatting output.');
|
||||
}
|
||||
|
||||
return $dateTime->format('\G\M\TP');
|
||||
// From ICU >= 4.8, the zero offset is not more used, example: GMT instead of GMT+00:00
|
||||
$format = (0 !== (int) $dateTime->format('O')) ? '\G\M\TP' : '\G\M\T';
|
||||
|
||||
return $dateTime->format($format);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -468,6 +468,23 @@ class StubLocale
|
|||
throw new MethodNotImplementedException(__METHOD__);
|
||||
}
|
||||
|
||||
public static function getDataDirectory()
|
||||
{
|
||||
static $dataDirectory;
|
||||
|
||||
if (null === $dataDirectory) {
|
||||
$dataDirectory = 'current';
|
||||
|
||||
if (getenv('ICU_DATA_VERSION')) {
|
||||
$dataDirectory = getenv('ICU_DATA_VERSION');
|
||||
} elseif (file_exists(__DIR__.'/../Resources/data/data-version.php')) {
|
||||
$dataDirectory = include __DIR__.'/../Resources/data/data-version.php';
|
||||
}
|
||||
}
|
||||
|
||||
return __DIR__.'/../Resources/data/'.$dataDirectory;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the stub ICU data
|
||||
*
|
||||
|
@ -488,7 +505,7 @@ class StubLocale
|
|||
}
|
||||
|
||||
if (empty(self::${$cacheVariable})) {
|
||||
self::${$cacheVariable} = include __DIR__.'/../Resources/data/'.$dataDirectory.'/stub/'.$stubDataDir.'/en.php';
|
||||
self::${$cacheVariable} = include $dataDirectory.'/stub/'.$stubDataDir.'/en.php';
|
||||
}
|
||||
|
||||
return self::${$cacheVariable};
|
||||
|
|
|
@ -121,10 +121,8 @@ class StubIntlDateFormatterTest extends LocaleTestCase
|
|||
$formatData = array(
|
||||
/* general */
|
||||
array('y-M-d', 0, '1970-1-1'),
|
||||
array("yyyy.MM.dd 'at' HH:mm:ss zzz", 0, '1970.01.01 at 00:00:00 GMT+00:00'),
|
||||
array("EEE, MMM d, ''yy", 0, "Thu, Jan 1, '70"),
|
||||
array('h:mm a', 0, '12:00 AM'),
|
||||
array('K:mm a, z', 0, '0:00 AM, GMT+00:00'),
|
||||
array('yyyyy.MMMM.dd hh:mm aaa', 0, '01970.January.01 12:00 AM'),
|
||||
|
||||
/* escaping */
|
||||
|
@ -285,26 +283,36 @@ class StubIntlDateFormatterTest extends LocaleTestCase
|
|||
array('s', 3601, '1'),
|
||||
array('s', 3630, '30'),
|
||||
array('s', 43200, '0'), // 12 hours
|
||||
|
||||
/* timezone */
|
||||
array('z', 0, 'GMT+00:00'),
|
||||
array('zz', 0, 'GMT+00:00'),
|
||||
array('zzz', 0, 'GMT+00:00'),
|
||||
array('zzzz', 0, 'GMT+00:00'),
|
||||
array('zzzzz', 0, 'GMT+00:00'),
|
||||
);
|
||||
|
||||
// Timezone
|
||||
if ($this->isIntlExtensionLoaded() && $this->isGreaterOrEqualThanIcuVersion('4.8')) {
|
||||
// general
|
||||
$formatData[] = array("yyyy.MM.dd 'at' HH:mm:ss zzz", 0, '1970.01.01 at 00:00:00 GMT');
|
||||
$formatData[] = array('K:mm a, z', 0, '0:00 AM, GMT');
|
||||
|
||||
// timezone
|
||||
$formatData[] = array('z', 0, 'GMT');
|
||||
$formatData[] = array('zz', 0, 'GMT');
|
||||
$formatData[] = array('zzz', 0, 'GMT');
|
||||
$formatData[] = array('zzzz', 0, 'GMT');
|
||||
$formatData[] = array('zzzzz', 0, 'GMT');
|
||||
}
|
||||
|
||||
// As of PHP 5.3.4, IntlDateFormatter::format() accepts DateTime instances
|
||||
if ($this->isGreaterOrEqualThanPhpVersion('5.3.4')) {
|
||||
$dateTime = new \DateTime('@0');
|
||||
|
||||
/* general, DateTime */
|
||||
$formatData[] = array('y-M-d', $dateTime, '1970-1-1');
|
||||
$formatData[] = array("yyyy.MM.dd 'at' HH:mm:ss zzz", $dateTime, '1970.01.01 at 00:00:00 GMT+00:00');
|
||||
$formatData[] = array("EEE, MMM d, ''yy", $dateTime, "Thu, Jan 1, '70");
|
||||
$formatData[] = array('h:mm a', $dateTime, '12:00 AM');
|
||||
$formatData[] = array('K:mm a, z', $dateTime, '0:00 AM, GMT+00:00');
|
||||
$formatData[] = array('yyyyy.MMMM.dd hh:mm aaa', $dateTime, '01970.January.01 12:00 AM');
|
||||
|
||||
if ($this->isIntlExtensionLoaded() && $this->isGreaterOrEqualThanIcuVersion('4.8')) {
|
||||
$formatData[] = array("yyyy.MM.dd 'at' HH:mm:ss zzz", $dateTime, '1970.01.01 at 00:00:00 GMT');
|
||||
$formatData[] = array('K:mm a, z', $dateTime, '0:00 AM, GMT');
|
||||
}
|
||||
}
|
||||
|
||||
return $formatData;
|
||||
|
@ -428,7 +436,9 @@ class StubIntlDateFormatterTest extends LocaleTestCase
|
|||
$this->skipIfIntlExtensionIsNotLoaded();
|
||||
$formatter = $this->createIntlFormatter('zzzz');
|
||||
$formatter->setTimeZoneId('Pacific/Fiji');
|
||||
$this->assertEquals('Fiji Time', $formatter->format(0));
|
||||
|
||||
$expected = $this->isGreaterOrEqualThanIcuVersion('49') ? 'Fiji Standard Time' : 'Fiji Time';
|
||||
$this->assertEquals($expected, $formatter->format(0));
|
||||
}
|
||||
|
||||
public function testFormatWithGmtTimezoneStub()
|
||||
|
@ -559,17 +569,22 @@ class StubIntlDateFormatterTest extends LocaleTestCase
|
|||
|
||||
public function dateAndTimeTypeProvider()
|
||||
{
|
||||
return array(
|
||||
$data = array(
|
||||
array(0, StubIntlDateFormatter::FULL, StubIntlDateFormatter::NONE, 'Thursday, January 1, 1970'),
|
||||
array(0, StubIntlDateFormatter::LONG, StubIntlDateFormatter::NONE, 'January 1, 1970'),
|
||||
array(0, StubIntlDateFormatter::MEDIUM, StubIntlDateFormatter::NONE, 'Jan 1, 1970'),
|
||||
array(0, StubIntlDateFormatter::SHORT, StubIntlDateFormatter::NONE, '1/1/70'),
|
||||
|
||||
array(0, StubIntlDateFormatter::NONE, StubIntlDateFormatter::FULL, '12:00:00 AM GMT+00:00'),
|
||||
array(0, StubIntlDateFormatter::NONE, StubIntlDateFormatter::LONG, '12:00:00 AM GMT+00:00'),
|
||||
array(0, StubIntlDateFormatter::NONE, StubIntlDateFormatter::MEDIUM, '12:00:00 AM'),
|
||||
array(0, StubIntlDateFormatter::NONE, StubIntlDateFormatter::SHORT, '12:00 AM'),
|
||||
);
|
||||
|
||||
if ($this->isIntlExtensionLoaded() && $this->isGreaterOrEqualThanIcuVersion('4.8')) {
|
||||
$data[] = array(0, StubIntlDateFormatter::NONE, StubIntlDateFormatter::FULL, '12:00:00 AM GMT');
|
||||
$data[] = array(0, StubIntlDateFormatter::NONE, StubIntlDateFormatter::LONG, '12:00:00 AM GMT');
|
||||
}
|
||||
|
||||
$data[] = array(0, StubIntlDateFormatter::NONE, StubIntlDateFormatter::MEDIUM, '12:00:00 AM');
|
||||
$data[] = array(0, StubIntlDateFormatter::NONE, StubIntlDateFormatter::SHORT, '12:00 AM');
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function testGetCalendar()
|
||||
|
@ -668,7 +683,7 @@ class StubIntlDateFormatterTest extends LocaleTestCase
|
|||
|
||||
public function parseProvider()
|
||||
{
|
||||
return array(
|
||||
$data = array(
|
||||
// years
|
||||
array('y-M-d', '1970-1-1', 0),
|
||||
array('yy-M-d', '70-1-1', 0),
|
||||
|
@ -807,6 +822,15 @@ class StubIntlDateFormatterTest extends LocaleTestCase
|
|||
array("''y", "'1970", 0),
|
||||
array("H 'o'' clock'", "0 o' clock", 0),
|
||||
);
|
||||
|
||||
if ($this->isIntlExtensionLoaded() && $this->isGreaterOrEqualThanIcuVersion('4.8')) {
|
||||
$data[] = array('y-M-d', '1970/1/1', 0);
|
||||
$data[] = array('yy-M-d', '70/1/1', 0);
|
||||
$data[] = array('y/M/d', '1970-1-1', 0);
|
||||
$data[] = array('yy/M/d', '70-1-1', 0);
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -846,9 +870,6 @@ class StubIntlDateFormatterTest extends LocaleTestCase
|
|||
public function parseErrorProvider()
|
||||
{
|
||||
return array(
|
||||
array('y-M-d', '1970/1/1'),
|
||||
array('yy-M-d', '70/1/1'),
|
||||
|
||||
// 1 char month
|
||||
array('y-MMMMM-d', '1970-J-1'),
|
||||
array('y-MMMMM-d', '1970-S-1'),
|
||||
|
|
|
@ -11,9 +11,11 @@
|
|||
|
||||
namespace Symfony\Component\Locale\Tests\Stub;
|
||||
|
||||
use Symfony\Component\Locale\Locale;
|
||||
use Symfony\Component\Locale\Stub\StubLocale;
|
||||
use Symfony\Component\Locale\Tests\TestCase as LocaleTestCase;
|
||||
|
||||
class StubLocaleTest extends \PHPUnit_Framework_TestCase
|
||||
class StubLocaleTest extends LocaleTestCase
|
||||
{
|
||||
/**
|
||||
* @expectedException InvalidArgumentException
|
||||
|
@ -65,8 +67,10 @@ class StubLocaleTest extends \PHPUnit_Framework_TestCase
|
|||
|
||||
public function testGetCurrenciesData()
|
||||
{
|
||||
$symbol = $this->isSameAsIcuVersion('4.8') ? 'BR$' : 'R$';
|
||||
|
||||
$currencies = StubLocale::getCurrenciesData('en');
|
||||
$this->assertEquals('R$', $currencies['BRL']['symbol']);
|
||||
$this->assertEquals($symbol, $currencies['BRL']['symbol']);
|
||||
$this->assertEquals('Brazilian Real', $currencies['BRL']['name']);
|
||||
$this->assertEquals(2, $currencies['BRL']['fractionDigits']);
|
||||
$this->assertEquals(0, $currencies['BRL']['roundingIncrement']);
|
||||
|
|
|
@ -161,7 +161,7 @@ class StubNumberFormatterTest extends LocaleTestCase
|
|||
public function testFormatCurrencyWithCurrencyStyleCostaRicanColonsRoundingStub($value, $currency, $symbol, $expected)
|
||||
{
|
||||
$formatter = $this->getStubFormatterWithCurrencyStyle();
|
||||
$this->assertEquals(sprintf($expected, '₡'), $formatter->formatCurrency($value, $currency));
|
||||
$this->assertEquals(sprintf($expected, $symbol), $formatter->formatCurrency($value, $currency));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -177,7 +177,7 @@ class StubNumberFormatterTest extends LocaleTestCase
|
|||
|
||||
public function formatCurrencyWithCurrencyStyleCostaRicanColonsRoundingProvider()
|
||||
{
|
||||
$crc = $this->isIntlExtensionLoaded() && $this->isSameAsIcuVersion('4.8') ? 'CRC' : '₡';
|
||||
$crc = $this->isIntlExtensionLoaded() && $this->isGreaterOrEqualThanIcuVersion('4.8') ? 'CRC' : '₡';
|
||||
|
||||
return array(
|
||||
array(100, 'CRC', $crc, '%s100'),
|
||||
|
@ -192,7 +192,7 @@ class StubNumberFormatterTest extends LocaleTestCase
|
|||
public function testFormatCurrencyWithCurrencyStyleBrazilianRealRoundingStub($value, $currency, $symbol, $expected)
|
||||
{
|
||||
$formatter = $this->getStubFormatterWithCurrencyStyle();
|
||||
$this->assertEquals(sprintf($expected, 'R'), $formatter->formatCurrency($value, $currency));
|
||||
$this->assertEquals(sprintf($expected, $symbol), $formatter->formatCurrency($value, $currency));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -232,7 +232,7 @@ class StubNumberFormatterTest extends LocaleTestCase
|
|||
public function testFormatCurrencyWithCurrencyStyleSwissRoundingStub($value, $currency, $symbol, $expected)
|
||||
{
|
||||
$formatter = $this->getStubFormatterWithCurrencyStyle();
|
||||
$this->assertEquals(sprintf($expected, 'CHF'), $formatter->formatCurrency($value, $currency));
|
||||
$this->assertEquals(sprintf($expected, $symbol), $formatter->formatCurrency($value, $currency));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Reference in New Issue