[Form] Removed automatic distribution of the locale in the Form component. This leads to more problems than it solves.
This commit is contained in:
parent
c468db5c5b
commit
fdbc064f06
@ -67,10 +67,6 @@ class FrameworkExtension extends Extension
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($config['i18n']) && $config['i18n']) {
|
||||
FormContext::setLocale(\Locale::getDefault());
|
||||
}
|
||||
|
||||
if (isset($config['ide'])) {
|
||||
switch ($config['ide']) {
|
||||
case 'textmate':
|
||||
|
@ -23,7 +23,7 @@ class CountryField extends ChoiceField
|
||||
{
|
||||
protected function configure()
|
||||
{
|
||||
$this->addOption('choices', Locale::getDisplayCountries($this->locale));
|
||||
$this->addOption('choices', Locale::getDisplayCountries(\Locale::getDefault()));
|
||||
|
||||
parent::configure();
|
||||
}
|
||||
|
@ -104,7 +104,7 @@ class DateField extends HybridField
|
||||
$this->addOption('user_timezone', 'UTC');
|
||||
|
||||
$this->formatter = new \IntlDateFormatter(
|
||||
$this->locale,
|
||||
\Locale::getDefault(),
|
||||
self::$intlFormats[$this->getOption('format')],
|
||||
\IntlDateFormatter::NONE
|
||||
);
|
||||
|
@ -49,7 +49,6 @@ use Symfony\Component\Form\ValueTransformer\TransformationFailedException;
|
||||
class Field extends Configurable implements FieldInterface
|
||||
{
|
||||
protected $taintedData = null;
|
||||
protected $locale = null;
|
||||
|
||||
private $errors = array();
|
||||
private $key = '';
|
||||
@ -74,7 +73,6 @@ class Field extends Configurable implements FieldInterface
|
||||
$this->addOption('normalization_transformer');
|
||||
|
||||
$this->key = (string)$key;
|
||||
$this->locale = FormContext::getLocale();
|
||||
|
||||
parent::__construct($options);
|
||||
|
||||
@ -412,20 +410,6 @@ class Field extends Configurable implements FieldInterface
|
||||
return $this->errors;
|
||||
}
|
||||
|
||||
/**
|
||||
* Injects the locale into the given object, if set.
|
||||
*
|
||||
* The locale is injected only if the object implements Localizable.
|
||||
*
|
||||
* @param object $object
|
||||
*/
|
||||
protected function injectLocale($object)
|
||||
{
|
||||
if ($object instanceof Localizable) {
|
||||
$object->setLocale($this->locale);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the ValueTransformer.
|
||||
*
|
||||
@ -433,8 +417,6 @@ class Field extends Configurable implements FieldInterface
|
||||
*/
|
||||
protected function setNormalizationTransformer(ValueTransformerInterface $normalizationTransformer)
|
||||
{
|
||||
$this->injectLocale($normalizationTransformer);
|
||||
|
||||
$this->normalizationTransformer = $normalizationTransformer;
|
||||
}
|
||||
|
||||
@ -455,8 +437,6 @@ class Field extends Configurable implements FieldInterface
|
||||
*/
|
||||
protected function setValueTransformer(ValueTransformerInterface $valueTransformer)
|
||||
{
|
||||
$this->injectLocale($valueTransformer);
|
||||
|
||||
$this->valueTransformer = $valueTransformer;
|
||||
}
|
||||
|
||||
|
@ -65,26 +65,6 @@ class FormContext implements FormContextInterface
|
||||
*/
|
||||
protected $csrfFieldName = '_token';
|
||||
|
||||
/**
|
||||
* Globally sets the locale for new forms and fields
|
||||
*
|
||||
* @param string $locale A valid locale, such as "en", "de_DE" etc.
|
||||
*/
|
||||
public static function setLocale($locale)
|
||||
{
|
||||
self::$locale = $locale;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the locale used for new forms and fields
|
||||
*
|
||||
* @return string A valid locale, such as "en", "de_DE" etc.
|
||||
*/
|
||||
public static function getLocale()
|
||||
{
|
||||
return self::$locale;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
|
@ -24,7 +24,6 @@ use Symfony\Component\Validator\ValidatorInterface;
|
||||
*
|
||||
* <code>
|
||||
* $form = $context
|
||||
* ->locale('en_US')
|
||||
* ->validationGroups('Address')
|
||||
* ->getForm('author');
|
||||
* </code>
|
||||
|
@ -25,7 +25,6 @@ use Symfony\Component\Validator\ValidatorInterface;
|
||||
*
|
||||
* <code>
|
||||
* $defaultContext = new FormContext();
|
||||
* $defaultContext->locale('en_US');
|
||||
* $defaultContext->csrfProtection(true);
|
||||
* $factory = new FormFactory($defaultContext);
|
||||
*
|
||||
@ -39,7 +38,6 @@ use Symfony\Component\Validator\ValidatorInterface;
|
||||
*
|
||||
* <code>
|
||||
* $form = $factory
|
||||
* ->locale('de_DE')
|
||||
* ->csrfProtection(false)
|
||||
* ->getForm('author');
|
||||
* </code>
|
||||
|
@ -26,7 +26,7 @@ class LanguageField extends ChoiceField
|
||||
*/
|
||||
protected function configure()
|
||||
{
|
||||
$this->addOption('choices', Locale::getDisplayLanguages($this->locale));
|
||||
$this->addOption('choices', Locale::getDisplayLanguages(\Locale::getDefault()));
|
||||
|
||||
parent::configure();
|
||||
}
|
||||
|
@ -26,7 +26,7 @@ class LocaleField extends ChoiceField
|
||||
*/
|
||||
protected function configure()
|
||||
{
|
||||
$this->addOption('choices', Locale::getDisplayLocales($this->locale));
|
||||
$this->addOption('choices', Locale::getDisplayLocales(\Locale::getDefault()));
|
||||
|
||||
parent::configure();
|
||||
}
|
||||
|
@ -1,27 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien.potencier@symfony-project.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Form;
|
||||
|
||||
/**
|
||||
* Marks classes that you can inject a locale into.
|
||||
*
|
||||
* @author Bernhard Schussek <bernhard.schussek@symfony-project.com>
|
||||
*/
|
||||
interface Localizable
|
||||
{
|
||||
/**
|
||||
* Sets the locale of the class.
|
||||
*
|
||||
* @param string $locale
|
||||
*/
|
||||
function setLocale($locale);
|
||||
}
|
@ -70,12 +70,12 @@ class MoneyField extends NumberField
|
||||
return '{{ widget }}';
|
||||
}
|
||||
|
||||
if (!isset(self::$patterns[$this->locale])) {
|
||||
self::$patterns[$this->locale] = array();
|
||||
if (!isset(self::$patterns[\Locale::getDefault()])) {
|
||||
self::$patterns[\Locale::getDefault()] = array();
|
||||
}
|
||||
|
||||
if (!isset(self::$patterns[$this->locale][$this->getOption('currency')])) {
|
||||
$format = new \NumberFormatter($this->locale, \NumberFormatter::CURRENCY);
|
||||
if (!isset(self::$patterns[\Locale::getDefault()][$this->getOption('currency')])) {
|
||||
$format = new \NumberFormatter(\Locale::getDefault(), \NumberFormatter::CURRENCY);
|
||||
$pattern = $format->formatCurrency('123', $this->getOption('currency'));
|
||||
|
||||
// the spacings between currency symbol and number are ignored, because
|
||||
@ -87,14 +87,14 @@ class MoneyField extends NumberField
|
||||
preg_match('/^([^\s\xc2\xa0]*)[\s\xc2\xa0]*123[,.]00[\s\xc2\xa0]*([^\s\xc2\xa0]*)$/', $pattern, $matches);
|
||||
|
||||
if (!empty($matches[1])) {
|
||||
self::$patterns[$this->locale] = $matches[1].' {{ widget }}';
|
||||
self::$patterns[\Locale::getDefault()] = $matches[1].' {{ widget }}';
|
||||
} else if (!empty($matches[2])) {
|
||||
self::$patterns[$this->locale] = '{{ widget }} '.$matches[2];
|
||||
self::$patterns[\Locale::getDefault()] = '{{ widget }} '.$matches[2];
|
||||
} else {
|
||||
self::$patterns[$this->locale] = '{{ widget }}';
|
||||
self::$patterns[\Locale::getDefault()] = '{{ widget }}';
|
||||
}
|
||||
}
|
||||
|
||||
return self::$patterns[$this->locale];
|
||||
return self::$patterns[\Locale::getDefault()];
|
||||
}
|
||||
}
|
||||
|
@ -11,7 +11,9 @@
|
||||
|
||||
namespace Symfony\Component\Form\ValueTransformer;
|
||||
|
||||
abstract class BaseDateTimeTransformer extends BaseValueTransformer
|
||||
use Symfony\Component\Form\Configurable;
|
||||
|
||||
abstract class BaseDateTimeTransformer extends Configurable implements ValueTransformerInterface
|
||||
{
|
||||
const NONE = 'none';
|
||||
const FULL = 'full';
|
||||
|
@ -1,46 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien.potencier@symfony-project.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Form\ValueTransformer;
|
||||
|
||||
use Symfony\Component\Form\Configurable;
|
||||
|
||||
/**
|
||||
* Implements functionality shared by most value transformers
|
||||
*
|
||||
* @author Bernhard Schussek <bernhard.schussek@symfony-project.com>
|
||||
*/
|
||||
abstract class BaseValueTransformer extends Configurable implements ValueTransformerInterface
|
||||
{
|
||||
/**
|
||||
* The locale of this transformer as accepted by the class Locale
|
||||
* @var string
|
||||
*/
|
||||
protected $locale;
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function __construct(array $options = array())
|
||||
{
|
||||
$this->locale = class_exists('\Locale', false) ? \Locale::getDefault() : 'en';
|
||||
|
||||
parent::__construct($options);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function setLocale($locale)
|
||||
{
|
||||
$this->locale = $locale;
|
||||
}
|
||||
}
|
@ -11,6 +11,7 @@
|
||||
|
||||
namespace Symfony\Component\Form\ValueTransformer;
|
||||
|
||||
use Symfony\Component\Form\Configurable;
|
||||
use Symfony\Component\Form\Exception\UnexpectedTypeException;
|
||||
|
||||
/**
|
||||
@ -19,7 +20,7 @@ use Symfony\Component\Form\Exception\UnexpectedTypeException;
|
||||
* @author Bernhard Schussek <bernhard.schussek@symfony-project.com>
|
||||
* @author Florian Eckerstorfer <florian@eckerstorfer.org>
|
||||
*/
|
||||
class BooleanToStringTransformer extends BaseValueTransformer
|
||||
class BooleanToStringTransformer extends Configurable implements ValueTransformerInterface
|
||||
{
|
||||
/**
|
||||
* Transforms a Boolean into a string.
|
||||
|
@ -11,6 +11,7 @@
|
||||
|
||||
namespace Symfony\Component\Form\ValueTransformer;
|
||||
|
||||
use Symfony\Component\Form\Configurable;
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
|
||||
/**
|
||||
@ -33,7 +34,7 @@ use Doctrine\Common\Collections\Collection;
|
||||
* @author Benjamin Eberlei <kontakt@beberlei.de>
|
||||
* @author Bernhard Schussek <bernhard.schussek@symfony-project.com>
|
||||
*/
|
||||
class CollectionToStringTransformer extends BaseValueTransformer
|
||||
class CollectionToStringTransformer extends Configurable implements ValueTransformerInterface
|
||||
{
|
||||
protected function configure()
|
||||
{
|
||||
|
@ -21,7 +21,6 @@ use Symfony\Component\Form\Exception\UnexpectedTypeException;
|
||||
* * "input": The type of the normalized format ("time" or "timestamp"). Default: "datetime"
|
||||
* * "output": The type of the transformed format ("string" or "array"). Default: "string"
|
||||
* * "format": The format of the time string ("short", "medium", "long" or "full"). Default: "short"
|
||||
* * "locale": The locale of the localized string. Default: Result of Locale::getDefault()
|
||||
*
|
||||
* @author Bernhard Schussek <bernhard.schussek@symfony-project.com>
|
||||
* @author Florian Eckerstorfer <florian@eckerstorfer.org>
|
||||
|
@ -21,7 +21,6 @@ use Symfony\Component\Form\Exception\UnexpectedTypeException;
|
||||
* * "input": The type of the normalized format ("time" or "timestamp"). Default: "datetime"
|
||||
* * "output": The type of the transformed format ("string" or "array"). Default: "string"
|
||||
* * "format": The format of the time string ("short", "medium", "long" or "full"). Default: "short"
|
||||
* * "locale": The locale of the localized string. Default: Result of Locale::getDefault()
|
||||
*
|
||||
* @author Bernhard Schussek <bernhard.schussek@symfony-project.com>
|
||||
* @author Florian Eckerstorfer <florian@eckerstorfer.org>
|
||||
@ -126,6 +125,6 @@ class DateTimeToLocalizedStringTransformer extends BaseDateTimeTransformer
|
||||
$timeFormat = $this->getIntlFormatConstant($this->getOption('time_format'));
|
||||
$timezone = $this->getOption('output_timezone');
|
||||
|
||||
return new \IntlDateFormatter($this->locale, $dateFormat, $timeFormat, $timezone);
|
||||
return new \IntlDateFormatter(\Locale::getDefault(), $dateFormat, $timeFormat, $timezone);
|
||||
}
|
||||
}
|
@ -11,6 +11,7 @@
|
||||
|
||||
namespace Symfony\Component\Form\ValueTransformer;
|
||||
|
||||
use Symfony\Component\Form\Configurable;
|
||||
use Symfony\Component\Form\Exception\UnexpectedTypeException;
|
||||
|
||||
/**
|
||||
@ -19,7 +20,7 @@ use Symfony\Component\Form\Exception\UnexpectedTypeException;
|
||||
* @author Bernhard Schussek <bernhard.schussek@symfony-project.com>
|
||||
* @author Florian Eckerstorfer <florian@eckerstorfer.org>
|
||||
*/
|
||||
class DateTimeToStringTransformer extends BaseValueTransformer
|
||||
class DateTimeToStringTransformer extends Configurable implements ValueTransformerInterface
|
||||
{
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
|
@ -11,6 +11,7 @@
|
||||
|
||||
namespace Symfony\Component\Form\ValueTransformer;
|
||||
|
||||
use Symfony\Component\Form\Configurable;
|
||||
use Symfony\Component\Form\Exception\UnexpectedTypeException;
|
||||
|
||||
/**
|
||||
@ -19,7 +20,7 @@ use Symfony\Component\Form\Exception\UnexpectedTypeException;
|
||||
* @author Bernhard Schussek <bernhard.schussek@symfony-project.com>
|
||||
* @author Florian Eckerstorfer <florian@eckerstorfer.org>
|
||||
*/
|
||||
class DateTimeToTimestampTransformer extends BaseValueTransformer
|
||||
class DateTimeToTimestampTransformer extends Configurable implements ValueTransformerInterface
|
||||
{
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
|
@ -11,6 +11,7 @@
|
||||
|
||||
namespace Symfony\Component\Form\ValueTransformer;
|
||||
|
||||
use Symfony\Component\Form\Configurable;
|
||||
use Symfony\Component\Form\Exception\UnexpectedTypeException;
|
||||
|
||||
/**
|
||||
@ -20,7 +21,7 @@ use Symfony\Component\Form\Exception\UnexpectedTypeException;
|
||||
* @author Bernhard Schussek <bernhard.schussek@symfony-project.com>
|
||||
* @author Florian Eckerstorfer <florian@eckerstorfer.org>
|
||||
*/
|
||||
class NumberToLocalizedStringTransformer extends BaseValueTransformer
|
||||
class NumberToLocalizedStringTransformer extends Configurable implements ValueTransformerInterface
|
||||
{
|
||||
const ROUND_FLOOR = \NumberFormatter::ROUND_FLOOR;
|
||||
const ROUND_DOWN = \NumberFormatter::ROUND_DOWN;
|
||||
@ -100,7 +101,7 @@ class NumberToLocalizedStringTransformer extends BaseValueTransformer
|
||||
*/
|
||||
protected function getNumberFormatter()
|
||||
{
|
||||
$formatter = new \NumberFormatter($this->locale, \NumberFormatter::DECIMAL);
|
||||
$formatter = new \NumberFormatter(\Locale::getDefault(), \NumberFormatter::DECIMAL);
|
||||
|
||||
if ($this->getOption('precision') !== null) {
|
||||
$formatter->setAttribute(\NumberFormatter::FRACTION_DIGITS, $this->getOption('precision'));
|
||||
|
@ -11,6 +11,7 @@
|
||||
|
||||
namespace Symfony\Component\Form\ValueTransformer;
|
||||
|
||||
use Symfony\Component\Form\Configurable;
|
||||
use Symfony\Component\Form\Exception\UnexpectedTypeException;
|
||||
|
||||
/**
|
||||
@ -19,7 +20,7 @@ use Symfony\Component\Form\Exception\UnexpectedTypeException;
|
||||
* @author Bernhard Schussek <bernhard.schussek@symfony-project.com>
|
||||
* @author Florian Eckerstorfer <florian@eckerstorfer.org>
|
||||
*/
|
||||
class PercentToLocalizedStringTransformer extends BaseValueTransformer
|
||||
class PercentToLocalizedStringTransformer extends Configurable implements ValueTransformerInterface
|
||||
{
|
||||
const FRACTIONAL = 'fractional';
|
||||
const INTEGER = 'integer';
|
||||
@ -113,7 +114,7 @@ class PercentToLocalizedStringTransformer extends BaseValueTransformer
|
||||
*/
|
||||
protected function getNumberFormatter()
|
||||
{
|
||||
$formatter = new \NumberFormatter($this->locale, \NumberFormatter::DECIMAL);
|
||||
$formatter = new \NumberFormatter(\Locale::getDefault(), \NumberFormatter::DECIMAL);
|
||||
|
||||
$formatter->setAttribute(\NumberFormatter::FRACTION_DIGITS, $this->getOption('precision'));
|
||||
|
||||
|
@ -52,12 +52,4 @@ class ReversedTransformer implements ValueTransformerInterface
|
||||
{
|
||||
return $this->reversedTransformer->transform($value);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function setLocale($locale)
|
||||
{
|
||||
$this->reversedTransformer->setLocale($locale);
|
||||
}
|
||||
}
|
||||
|
@ -74,14 +74,4 @@ class ValueTransformerChain implements ValueTransformerInterface
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function setLocale($locale)
|
||||
{
|
||||
foreach ($this->transformers as $transformer) {
|
||||
$transformer->setLocale($locale);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -11,14 +11,12 @@
|
||||
|
||||
namespace Symfony\Component\Form\ValueTransformer;
|
||||
|
||||
use Symfony\Component\Form\Localizable;
|
||||
|
||||
/**
|
||||
* Transforms a value between different representations.
|
||||
*
|
||||
* @author Bernhard Schussek <bernhard.schussek@symfony-project.com>
|
||||
*/
|
||||
interface ValueTransformerInterface extends Localizable
|
||||
interface ValueTransformerInterface
|
||||
{
|
||||
/**
|
||||
* Transforms a value from the original representation to a transformed representation.
|
||||
|
@ -18,7 +18,7 @@ class CountryFieldTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testCountriesAreSelectable()
|
||||
{
|
||||
FormContext::setLocale('de_AT');
|
||||
\Locale::setDefault('de_AT');
|
||||
|
||||
$field = new CountryField('country');
|
||||
$choices = $field->getOtherChoices();
|
||||
|
@ -20,7 +20,7 @@ class DateFieldTest extends DateTimeTestCase
|
||||
{
|
||||
protected function setUp()
|
||||
{
|
||||
FormContext::setLocale('de_AT');
|
||||
\Locale::setDefault('de_AT');
|
||||
}
|
||||
|
||||
public function testBind_fromInput_dateTime()
|
||||
|
@ -145,20 +145,6 @@ class FieldTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertEquals('news_article_title', $this->field->getId());
|
||||
}
|
||||
|
||||
public function testLocaleIsPassedToValueTransformer()
|
||||
{
|
||||
FormContext::setLocale('de_DE');
|
||||
|
||||
$transformer = $this->getMock('Symfony\Component\Form\ValueTransformer\ValueTransformerInterface');
|
||||
$transformer->expects($this->exactly(1))
|
||||
->method('setLocale')
|
||||
->with($this->equalTo('de_DE'));
|
||||
|
||||
$field = new TestField('title', array(
|
||||
'value_transformer' => $transformer,
|
||||
));
|
||||
}
|
||||
|
||||
public function testIsRequiredReturnsOwnValueIfNoParent()
|
||||
{
|
||||
$this->field->setRequired(true);
|
||||
|
@ -18,7 +18,7 @@ class LanguageFieldTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testCountriesAreSelectable()
|
||||
{
|
||||
FormContext::setLocale('de_AT');
|
||||
\Locale::setDefault('de_AT');
|
||||
|
||||
$field = new LanguageField('language');
|
||||
$choices = $field->getOtherChoices();
|
||||
|
@ -18,7 +18,7 @@ class LocaleFieldTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testLocalesAreSelectable()
|
||||
{
|
||||
FormContext::setLocale('de_AT');
|
||||
\Locale::setDefault('de_AT');
|
||||
|
||||
$field = new LocaleField('language');
|
||||
$choices = $field->getOtherChoices();
|
||||
|
@ -25,6 +25,8 @@ class DateTimeToLocalizedStringTransformerTest extends DateTimeTestCase
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
\Locale::setDefault('de_AT');
|
||||
|
||||
$this->dateTime = new \DateTime('2010-02-03 04:05:06 UTC');
|
||||
$this->dateTimeWithoutSeconds = new \DateTime('2010-02-03 04:05:00 UTC');
|
||||
}
|
||||
@ -46,7 +48,6 @@ class DateTimeToLocalizedStringTransformerTest extends DateTimeTestCase
|
||||
'output_timezone' => 'UTC',
|
||||
'date_format' => 'short',
|
||||
));
|
||||
$transformer->setLocale('de_AT');
|
||||
$this->assertEquals('03.02.10 04:05', $transformer->transform($this->dateTime));
|
||||
}
|
||||
|
||||
@ -57,7 +58,7 @@ class DateTimeToLocalizedStringTransformerTest extends DateTimeTestCase
|
||||
'output_timezone' => 'UTC',
|
||||
'date_format' => 'medium',
|
||||
));
|
||||
$transformer->setLocale('de_AT');
|
||||
|
||||
$this->assertEquals('03.02.2010 04:05', $transformer->transform($this->dateTime));
|
||||
}
|
||||
|
||||
@ -68,7 +69,7 @@ class DateTimeToLocalizedStringTransformerTest extends DateTimeTestCase
|
||||
'output_timezone' => 'UTC',
|
||||
'date_format' => 'long',
|
||||
));
|
||||
$transformer->setLocale('de_AT');
|
||||
|
||||
$this->assertEquals('03. Februar 2010 04:05', $transformer->transform($this->dateTime));
|
||||
}
|
||||
|
||||
@ -79,7 +80,7 @@ class DateTimeToLocalizedStringTransformerTest extends DateTimeTestCase
|
||||
'output_timezone' => 'UTC',
|
||||
'date_format' => 'full',
|
||||
));
|
||||
$transformer->setLocale('de_AT');
|
||||
|
||||
$this->assertEquals('Mittwoch, 03. Februar 2010 04:05', $transformer->transform($this->dateTime));
|
||||
}
|
||||
|
||||
@ -90,7 +91,7 @@ class DateTimeToLocalizedStringTransformerTest extends DateTimeTestCase
|
||||
'output_timezone' => 'UTC',
|
||||
'time_format' => 'short',
|
||||
));
|
||||
$transformer->setLocale('de_AT');
|
||||
|
||||
$this->assertEquals('03.02.2010 04:05', $transformer->transform($this->dateTime));
|
||||
}
|
||||
|
||||
@ -101,7 +102,7 @@ class DateTimeToLocalizedStringTransformerTest extends DateTimeTestCase
|
||||
'output_timezone' => 'UTC',
|
||||
'time_format' => 'medium',
|
||||
));
|
||||
$transformer->setLocale('de_AT');
|
||||
|
||||
$this->assertEquals('03.02.2010 04:05:06', $transformer->transform($this->dateTime));
|
||||
}
|
||||
|
||||
@ -112,7 +113,7 @@ class DateTimeToLocalizedStringTransformerTest extends DateTimeTestCase
|
||||
'output_timezone' => 'UTC',
|
||||
'time_format' => 'long',
|
||||
));
|
||||
$transformer->setLocale('de_AT');
|
||||
|
||||
$this->assertEquals('03.02.2010 04:05:06 GMT+00:00', $transformer->transform($this->dateTime));
|
||||
}
|
||||
|
||||
@ -123,17 +124,19 @@ class DateTimeToLocalizedStringTransformerTest extends DateTimeTestCase
|
||||
'output_timezone' => 'UTC',
|
||||
'time_format' => 'full',
|
||||
));
|
||||
$transformer->setLocale('de_AT');
|
||||
|
||||
$this->assertEquals('03.02.2010 04:05:06 GMT+00:00', $transformer->transform($this->dateTime));
|
||||
}
|
||||
|
||||
public function testTransformToDifferentLocale()
|
||||
{
|
||||
\Locale::setDefault('en_US');
|
||||
|
||||
$transformer = new DateTimeToLocalizedStringTransformer(array(
|
||||
'input_timezone' => 'UTC',
|
||||
'output_timezone' => 'UTC',
|
||||
));
|
||||
$transformer->setLocale('en_US');
|
||||
|
||||
$this->assertEquals('Feb 3, 2010 4:05 AM', $transformer->transform($this->dateTime));
|
||||
}
|
||||
|
||||
@ -150,7 +153,7 @@ class DateTimeToLocalizedStringTransformerTest extends DateTimeTestCase
|
||||
'input_timezone' => 'America/New_York',
|
||||
'output_timezone' => 'Asia/Hong_Kong',
|
||||
));
|
||||
$transformer->setLocale('de_AT');
|
||||
|
||||
|
||||
$input = new \DateTime('2010-02-03 04:05:06 America/New_York');
|
||||
|
||||
@ -187,7 +190,7 @@ class DateTimeToLocalizedStringTransformerTest extends DateTimeTestCase
|
||||
'output_timezone' => 'UTC',
|
||||
'date_format' => 'short',
|
||||
));
|
||||
$transformer->setLocale('de_AT');
|
||||
|
||||
$this->assertDateTimeEquals($this->dateTimeWithoutSeconds, $transformer->reverseTransform('03.02.10 04:05', null));
|
||||
}
|
||||
|
||||
@ -198,7 +201,7 @@ class DateTimeToLocalizedStringTransformerTest extends DateTimeTestCase
|
||||
'output_timezone' => 'UTC',
|
||||
'date_format' => 'medium',
|
||||
));
|
||||
$transformer->setLocale('de_AT');
|
||||
|
||||
$this->assertDateTimeEquals($this->dateTimeWithoutSeconds, $transformer->reverseTransform('03.02.2010 04:05', null));
|
||||
}
|
||||
|
||||
@ -209,7 +212,7 @@ class DateTimeToLocalizedStringTransformerTest extends DateTimeTestCase
|
||||
'output_timezone' => 'UTC',
|
||||
'date_format' => 'long',
|
||||
));
|
||||
$transformer->setLocale('de_AT');
|
||||
|
||||
$this->assertDateTimeEquals($this->dateTimeWithoutSeconds, $transformer->reverseTransform('03. Februar 2010 04:05', null));
|
||||
}
|
||||
|
||||
@ -220,7 +223,7 @@ class DateTimeToLocalizedStringTransformerTest extends DateTimeTestCase
|
||||
'output_timezone' => 'UTC',
|
||||
'date_format' => 'full',
|
||||
));
|
||||
$transformer->setLocale('de_AT');
|
||||
|
||||
$this->assertDateTimeEquals($this->dateTimeWithoutSeconds, $transformer->reverseTransform('Mittwoch, 03. Februar 2010 04:05', null));
|
||||
}
|
||||
|
||||
@ -231,7 +234,7 @@ class DateTimeToLocalizedStringTransformerTest extends DateTimeTestCase
|
||||
'output_timezone' => 'UTC',
|
||||
'time_format' => 'short',
|
||||
));
|
||||
$transformer->setLocale('de_AT');
|
||||
|
||||
$this->assertDateTimeEquals($this->dateTimeWithoutSeconds, $transformer->reverseTransform('03.02.2010 04:05', null));
|
||||
}
|
||||
|
||||
@ -242,7 +245,7 @@ class DateTimeToLocalizedStringTransformerTest extends DateTimeTestCase
|
||||
'output_timezone' => 'UTC',
|
||||
'time_format' => 'medium',
|
||||
));
|
||||
$transformer->setLocale('de_AT');
|
||||
|
||||
$this->assertDateTimeEquals($this->dateTime, $transformer->reverseTransform('03.02.2010 04:05:06', null));
|
||||
}
|
||||
|
||||
@ -253,7 +256,7 @@ class DateTimeToLocalizedStringTransformerTest extends DateTimeTestCase
|
||||
'output_timezone' => 'UTC',
|
||||
'time_format' => 'long',
|
||||
));
|
||||
$transformer->setLocale('de_AT');
|
||||
|
||||
$this->assertDateTimeEquals($this->dateTime, $transformer->reverseTransform('03.02.2010 04:05:06 GMT+00:00', null));
|
||||
}
|
||||
|
||||
@ -264,17 +267,19 @@ class DateTimeToLocalizedStringTransformerTest extends DateTimeTestCase
|
||||
'output_timezone' => 'UTC',
|
||||
'time_format' => 'full',
|
||||
));
|
||||
$transformer->setLocale('de_AT');
|
||||
|
||||
$this->assertDateTimeEquals($this->dateTime, $transformer->reverseTransform('03.02.2010 04:05:06 GMT+00:00', null));
|
||||
}
|
||||
|
||||
public function testReverseTransformFromDifferentLocale()
|
||||
{
|
||||
\Locale::setDefault('en_US');
|
||||
|
||||
$transformer = new DateTimeToLocalizedStringTransformer(array(
|
||||
'input_timezone' => 'UTC',
|
||||
'output_timezone' => 'UTC',
|
||||
));
|
||||
$transformer->setLocale('en_US');
|
||||
|
||||
$this->assertDateTimeEquals($this->dateTimeWithoutSeconds, $transformer->reverseTransform('Feb 3, 2010 04:05 AM', null));
|
||||
}
|
||||
|
||||
@ -284,7 +289,7 @@ class DateTimeToLocalizedStringTransformerTest extends DateTimeTestCase
|
||||
'input_timezone' => 'America/New_York',
|
||||
'output_timezone' => 'Asia/Hong_Kong',
|
||||
));
|
||||
$transformer->setLocale('de_AT');
|
||||
|
||||
|
||||
$dateTime = new \DateTime('2010-02-03 04:05:00 Asia/Hong_Kong');
|
||||
$dateTime->setTimezone(new \DateTimeZone('America/New_York'));
|
||||
|
@ -19,12 +19,18 @@ use Symfony\Tests\Component\Form\LocalizedTestCase;
|
||||
|
||||
class MoneyToLocalizedStringTransformerTest extends LocalizedTestCase
|
||||
{
|
||||
protected function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
\Locale::setDefault('de_AT');
|
||||
}
|
||||
|
||||
public function testTransform()
|
||||
{
|
||||
$transformer = new MoneyToLocalizedStringTransformer(array(
|
||||
'divisor' => 100,
|
||||
));
|
||||
$transformer->setLocale('de_AT');
|
||||
|
||||
$this->assertEquals('1,23', $transformer->transform(123));
|
||||
}
|
||||
@ -52,7 +58,6 @@ class MoneyToLocalizedStringTransformerTest extends LocalizedTestCase
|
||||
$transformer = new MoneyToLocalizedStringTransformer(array(
|
||||
'divisor' => 100,
|
||||
));
|
||||
$transformer->setLocale('de_AT');
|
||||
|
||||
$this->assertEquals(123, $transformer->reverseTransform('1,23', null));
|
||||
}
|
||||
|
@ -18,10 +18,16 @@ use Symfony\Tests\Component\Form\LocalizedTestCase;
|
||||
|
||||
class NumberToLocalizedStringTransformerTest extends LocalizedTestCase
|
||||
{
|
||||
protected function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
\Locale::setDefault('de_AT');
|
||||
}
|
||||
|
||||
public function testTransform()
|
||||
{
|
||||
$transformer = new NumberToLocalizedStringTransformer();
|
||||
$transformer->setLocale('de_AT');
|
||||
|
||||
$this->assertEquals('1', $transformer->transform(1));
|
||||
$this->assertEquals('1,5', $transformer->transform(1.5));
|
||||
@ -41,7 +47,6 @@ class NumberToLocalizedStringTransformerTest extends LocalizedTestCase
|
||||
$transformer = new NumberToLocalizedStringTransformer(array(
|
||||
'grouping' => true,
|
||||
));
|
||||
$transformer->setLocale('de_AT');
|
||||
|
||||
$this->assertEquals('1.234,5', $transformer->transform(1234.5));
|
||||
$this->assertEquals('12.345,912', $transformer->transform(12345.9123));
|
||||
@ -52,7 +57,6 @@ class NumberToLocalizedStringTransformerTest extends LocalizedTestCase
|
||||
$transformer = new NumberToLocalizedStringTransformer(array(
|
||||
'precision' => 2,
|
||||
));
|
||||
$transformer->setLocale('de_AT');
|
||||
|
||||
$this->assertEquals('1234,50', $transformer->transform(1234.5));
|
||||
$this->assertEquals('678,92', $transformer->transform(678.916));
|
||||
@ -63,14 +67,12 @@ class NumberToLocalizedStringTransformerTest extends LocalizedTestCase
|
||||
$transformer = new NumberToLocalizedStringTransformer(array(
|
||||
'rounding-mode' => NumberToLocalizedStringTransformer::ROUND_DOWN,
|
||||
));
|
||||
$transformer->setLocale('de_AT');
|
||||
$this->assertEquals('1234,547', $transformer->transform(1234.547), '->transform() only applies rounding mode if precision set');
|
||||
|
||||
$transformer = new NumberToLocalizedStringTransformer(array(
|
||||
'rounding-mode' => NumberToLocalizedStringTransformer::ROUND_DOWN,
|
||||
'precision' => 2,
|
||||
));
|
||||
$transformer->setLocale('de_AT');
|
||||
$this->assertEquals('1234,54', $transformer->transform(1234.547), '->transform() rounding-mode works');
|
||||
|
||||
}
|
||||
@ -78,7 +80,6 @@ class NumberToLocalizedStringTransformerTest extends LocalizedTestCase
|
||||
public function testReverseTransform()
|
||||
{
|
||||
$transformer = new NumberToLocalizedStringTransformer();
|
||||
$transformer->setLocale('de_AT');
|
||||
|
||||
$this->assertEquals(1, $transformer->reverseTransform('1', null));
|
||||
$this->assertEquals(1.5, $transformer->reverseTransform('1,5', null));
|
||||
@ -98,7 +99,6 @@ class NumberToLocalizedStringTransformerTest extends LocalizedTestCase
|
||||
$transformer = new NumberToLocalizedStringTransformer(array(
|
||||
'grouping' => true,
|
||||
));
|
||||
$transformer->setLocale('de_AT');
|
||||
|
||||
$this->assertEquals(1234.5, $transformer->reverseTransform('1.234,5', null));
|
||||
$this->assertEquals(12345.912, $transformer->reverseTransform('12.345,912', null));
|
||||
|
@ -18,10 +18,16 @@ use Symfony\Tests\Component\Form\LocalizedTestCase;
|
||||
|
||||
class PercentToLocalizedStringTransformerTest extends LocalizedTestCase
|
||||
{
|
||||
protected function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
\Locale::setDefault('de_AT');
|
||||
}
|
||||
|
||||
public function testTransform()
|
||||
{
|
||||
$transformer = new PercentToLocalizedStringTransformer();
|
||||
$transformer->setLocale('de_AT');
|
||||
|
||||
$this->assertEquals('10', $transformer->transform(0.1));
|
||||
$this->assertEquals('15', $transformer->transform(0.15));
|
||||
@ -41,7 +47,6 @@ class PercentToLocalizedStringTransformerTest extends LocalizedTestCase
|
||||
$transformer = new PercentToLocalizedStringTransformer(array(
|
||||
'type' => 'integer',
|
||||
));
|
||||
$transformer->setLocale('de_AT');
|
||||
|
||||
$this->assertEquals('0', $transformer->transform(0.1));
|
||||
$this->assertEquals('1', $transformer->transform(1));
|
||||
@ -54,7 +59,6 @@ class PercentToLocalizedStringTransformerTest extends LocalizedTestCase
|
||||
$transformer = new PercentToLocalizedStringTransformer(array(
|
||||
'precision' => 2,
|
||||
));
|
||||
$transformer->setLocale('de_AT');
|
||||
|
||||
$this->assertEquals('12,34', $transformer->transform(0.1234));
|
||||
}
|
||||
@ -62,7 +66,6 @@ class PercentToLocalizedStringTransformerTest extends LocalizedTestCase
|
||||
public function testReverseTransform()
|
||||
{
|
||||
$transformer = new PercentToLocalizedStringTransformer();
|
||||
$transformer->setLocale('de_AT');
|
||||
|
||||
$this->assertEquals(0.1, $transformer->reverseTransform('10', null));
|
||||
$this->assertEquals(0.15, $transformer->reverseTransform('15', null));
|
||||
@ -82,7 +85,6 @@ class PercentToLocalizedStringTransformerTest extends LocalizedTestCase
|
||||
$transformer = new PercentToLocalizedStringTransformer(array(
|
||||
'type' => 'integer',
|
||||
));
|
||||
$transformer->setLocale('de_AT');
|
||||
|
||||
$this->assertEquals(10, $transformer->reverseTransform('10', null));
|
||||
$this->assertEquals(15, $transformer->reverseTransform('15', null));
|
||||
@ -95,7 +97,6 @@ class PercentToLocalizedStringTransformerTest extends LocalizedTestCase
|
||||
$transformer = new PercentToLocalizedStringTransformer(array(
|
||||
'precision' => 2,
|
||||
));
|
||||
$transformer->setLocale('de_AT');
|
||||
|
||||
$this->assertEquals(0.1234, $transformer->reverseTransform('12,34', null));
|
||||
}
|
||||
|
@ -50,20 +50,4 @@ class ValueTransformerChainTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
$this->assertEquals('baz', $chain->reverseTransform('foo', null));
|
||||
}
|
||||
|
||||
public function testSetLocale()
|
||||
{
|
||||
$transformer1 = $this->getMock('Symfony\Component\Form\ValueTransformer\ValueTransformerInterface');
|
||||
$transformer1->expects($this->once())
|
||||
->method('setLocale')
|
||||
->with($this->identicalTo('de_DE'));
|
||||
$transformer2 = $this->getMock('Symfony\Component\Form\ValueTransformer\ValueTransformerInterface');
|
||||
$transformer2->expects($this->once())
|
||||
->method('setLocale')
|
||||
->with($this->identicalTo('de_DE'));
|
||||
|
||||
$chain = new ValueTransformerChain(array($transformer1, $transformer2));
|
||||
|
||||
$chain->setLocale('de_DE');
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user