feature #16715 [Form] Remove choices_as_values option on ChoiceType (nicolas-grekas)
This PR was merged into the 3.0-dev branch.
Discussion
----------
[Form] Remove choices_as_values option on ChoiceType
| Q | A
| ------------- | ---
| Bug fix? | no
| New feature? | yes
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets | -
| License | MIT
| Doc PR | -
Commits
-------
ed0e26a
[Form] Remove choices_as_values option on ChoiceType
This commit is contained in:
commit
833495278b
@ -259,7 +259,6 @@ abstract class DoctrineType extends AbstractType
|
||||
'em' => null,
|
||||
'query_builder' => null,
|
||||
'choices' => null,
|
||||
'choices_as_values' => true,
|
||||
'choice_loader' => $choiceLoader,
|
||||
'choice_label' => array(__CLASS__, 'createChoiceLabel'),
|
||||
'choice_name' => $choiceName,
|
||||
|
@ -22,7 +22,7 @@
|
||||
"require-dev": {
|
||||
"symfony/stopwatch": "~2.8|~3.0",
|
||||
"symfony/dependency-injection": "~2.8|~3.0",
|
||||
"symfony/form": "~2.8|~3.0",
|
||||
"symfony/form": "~3.0,>3.0-BETA1",
|
||||
"symfony/http-kernel": "~2.8|~3.0",
|
||||
"symfony/property-access": "~2.8|~3.0",
|
||||
"symfony/property-info": "~2.8|3.0",
|
||||
|
@ -1,190 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Form\ChoiceList;
|
||||
|
||||
@trigger_error('The '.__NAMESPACE__.'\ArrayKeyChoiceList class is deprecated since version 2.8 and will be removed in 3.0. Use '.__NAMESPACE__.'\ArrayChoiceList instead.', E_USER_DEPRECATED);
|
||||
|
||||
use Symfony\Component\Form\Exception\InvalidArgumentException;
|
||||
|
||||
/**
|
||||
* A list of choices that can be stored in the keys of a PHP array.
|
||||
*
|
||||
* PHP arrays accept only strings and integers as array keys. Other scalar types
|
||||
* are cast to integers and strings according to the description of
|
||||
* {@link toArrayKey()}. This implementation applies the same casting rules for
|
||||
* the choices passed to the constructor and to {@link getValuesForChoices()}.
|
||||
*
|
||||
* By default, the choices are cast to strings and used as values. Optionally,
|
||||
* you may pass custom values. The keys of the value array must match the keys
|
||||
* of the choice array.
|
||||
*
|
||||
* Example:
|
||||
*
|
||||
* ```php
|
||||
* $choices = array('' => 'Don\'t know', 0 => 'No', 1 => 'Yes');
|
||||
* $choiceList = new ArrayKeyChoiceList(array_keys($choices));
|
||||
*
|
||||
* $values = $choiceList->getValues()
|
||||
* // => array('', '0', '1')
|
||||
*
|
||||
* $selectedValues = $choiceList->getValuesForChoices(array(true));
|
||||
* // => array('1')
|
||||
* ```
|
||||
*
|
||||
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||
*
|
||||
* @deprecated since version 2.8, to be removed in 3.0. Use ArrayChoiceList instead.
|
||||
*/
|
||||
class ArrayKeyChoiceList extends ArrayChoiceList
|
||||
{
|
||||
/**
|
||||
* Whether the choices are used as values.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
private $useChoicesAsValues = false;
|
||||
|
||||
/**
|
||||
* Casts the given choice to an array key.
|
||||
*
|
||||
* PHP arrays accept only strings and integers as array keys. Integer
|
||||
* strings such as "42" are automatically cast to integers. The boolean
|
||||
* values "true" and "false" are cast to the integers 1 and 0. Every other
|
||||
* scalar value is cast to a string.
|
||||
*
|
||||
* @param mixed $choice The choice
|
||||
*
|
||||
* @return int|string The choice as PHP array key
|
||||
*
|
||||
* @throws InvalidArgumentException If the choice is not scalar
|
||||
*
|
||||
* @internal Must not be used outside this class
|
||||
*/
|
||||
public static function toArrayKey($choice)
|
||||
{
|
||||
if (!is_scalar($choice) && null !== $choice) {
|
||||
throw new InvalidArgumentException(sprintf(
|
||||
'The value of type "%s" cannot be converted to a valid array key.',
|
||||
gettype($choice)
|
||||
));
|
||||
}
|
||||
|
||||
if (is_bool($choice) || (string) (int) $choice === (string) $choice) {
|
||||
return (int) $choice;
|
||||
}
|
||||
|
||||
return (string) $choice;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a list with the given choices and values.
|
||||
*
|
||||
* The given choice array must have the same array keys as the value array.
|
||||
* Each choice must be castable to an integer/string according to the
|
||||
* casting rules described in {@link toArrayKey()}.
|
||||
*
|
||||
* If no values are given, the choices are cast to strings and used as
|
||||
* values.
|
||||
*
|
||||
* @param array|\Traversable $choices The selectable choices
|
||||
* @param callable $value The callable for creating the value
|
||||
* for a choice. If `null` is passed, the
|
||||
* choices are cast to strings and used
|
||||
* as values
|
||||
*
|
||||
* @throws InvalidArgumentException If the keys of the choices don't match
|
||||
* the keys of the values or if any of the
|
||||
* choices is not scalar
|
||||
*/
|
||||
public function __construct($choices, callable $value = null)
|
||||
{
|
||||
// If no values are given, use the choices as values
|
||||
// Since the choices are stored in the collection keys, i.e. they are
|
||||
// strings or integers, we are guaranteed to be able to convert them
|
||||
// to strings
|
||||
if (null === $value) {
|
||||
$value = function ($choice) {
|
||||
return (string) $choice;
|
||||
};
|
||||
|
||||
$this->useChoicesAsValues = true;
|
||||
}
|
||||
|
||||
parent::__construct($choices, $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getChoicesForValues(array $values)
|
||||
{
|
||||
if ($this->useChoicesAsValues) {
|
||||
$values = array_map('strval', $values);
|
||||
|
||||
// If the values are identical to the choices, so we can just return
|
||||
// them to improve performance a little bit
|
||||
return array_map(array(__CLASS__, 'toArrayKey'), array_intersect($values, array_keys($this->choices)));
|
||||
}
|
||||
|
||||
return parent::getChoicesForValues($values);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getValuesForChoices(array $choices)
|
||||
{
|
||||
$choices = array_map(array(__CLASS__, 'toArrayKey'), $choices);
|
||||
|
||||
if ($this->useChoicesAsValues) {
|
||||
// If the choices are identical to the values, we can just return
|
||||
// them to improve performance a little bit
|
||||
return array_map('strval', array_intersect($choices, $this->choices));
|
||||
}
|
||||
|
||||
return parent::getValuesForChoices($choices);
|
||||
}
|
||||
|
||||
/**
|
||||
* Flattens and flips an array into the given output variable.
|
||||
*
|
||||
* @param array $choices The array to flatten
|
||||
* @param callable $value The callable for generating choice values
|
||||
* @param array $choicesByValues The flattened choices indexed by the
|
||||
* corresponding values
|
||||
* @param array $keysByValues The original keys indexed by the
|
||||
* corresponding values
|
||||
*
|
||||
* @internal Must not be used by user-land code
|
||||
*/
|
||||
protected function flatten(array $choices, $value, &$choicesByValues, &$keysByValues, &$structuredValues)
|
||||
{
|
||||
if (null === $choicesByValues) {
|
||||
$choicesByValues = array();
|
||||
$keysByValues = array();
|
||||
$structuredValues = array();
|
||||
}
|
||||
|
||||
foreach ($choices as $choice => $key) {
|
||||
if (is_array($key)) {
|
||||
$this->flatten($key, $value, $choicesByValues, $keysByValues, $structuredValues[$choice]);
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
$choiceValue = (string) call_user_func($value, $choice);
|
||||
$choicesByValues[$choiceValue] = $choice;
|
||||
$keysByValues[$choiceValue] = $key;
|
||||
$structuredValues[$key] = $choiceValue;
|
||||
}
|
||||
}
|
||||
}
|
@ -135,35 +135,6 @@ class CachingFactoryDecorator implements ChoiceListFactoryInterface
|
||||
return $this->lists[$hash];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @deprecated Added for backwards compatibility in Symfony 2.7, to be
|
||||
* removed in Symfony 3.0.
|
||||
*/
|
||||
public function createListFromFlippedChoices($choices, $value = null, $triggerDeprecationNotice = true)
|
||||
{
|
||||
if ($choices instanceof \Traversable) {
|
||||
$choices = iterator_to_array($choices);
|
||||
}
|
||||
|
||||
// The value is not validated on purpose. The decorated factory may
|
||||
// decide which values to accept and which not.
|
||||
|
||||
// We ignore the choice groups for caching. If two choice lists are
|
||||
// requested with the same choices, but a different grouping, the same
|
||||
// choice list is returned.
|
||||
self::flatten($choices, $flatChoices);
|
||||
|
||||
$hash = self::generateHash(array($flatChoices, $value), 'fromFlippedChoices');
|
||||
|
||||
if (!isset($this->lists[$hash])) {
|
||||
$this->lists[$hash] = $this->decoratedFactory->createListFromFlippedChoices($choices, $value, $triggerDeprecationNotice);
|
||||
}
|
||||
|
||||
return $this->lists[$hash];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
|
@ -39,28 +39,6 @@ interface ChoiceListFactoryInterface
|
||||
*/
|
||||
public function createListFromChoices($choices, $value = null);
|
||||
|
||||
/**
|
||||
* Creates a choice list for the given choices.
|
||||
*
|
||||
* The choices should be passed in the keys of the choices array. Since the
|
||||
* choices array will be flipped, the entries of the array must be strings
|
||||
* or integers.
|
||||
*
|
||||
* Optionally, a callable can be passed for generating the choice values.
|
||||
* The callable receives the choice as first and the array key as the second
|
||||
* argument.
|
||||
*
|
||||
* @param array|\Traversable $choices The choices
|
||||
* @param null|callable $value The callable generating the choice
|
||||
* values
|
||||
*
|
||||
* @return ChoiceListInterface The choice list
|
||||
*
|
||||
* @deprecated Added for backwards compatibility in Symfony 2.7, to be
|
||||
* removed in Symfony 3.0.
|
||||
*/
|
||||
public function createListFromFlippedChoices($choices, $value = null);
|
||||
|
||||
/**
|
||||
* Creates a choice list that is loaded with the given loader.
|
||||
*
|
||||
|
@ -11,7 +11,6 @@
|
||||
|
||||
namespace Symfony\Component\Form\ChoiceList\Factory;
|
||||
|
||||
use Symfony\Component\Form\ChoiceList\ArrayKeyChoiceList;
|
||||
use Symfony\Component\Form\ChoiceList\ArrayChoiceList;
|
||||
use Symfony\Component\Form\ChoiceList\ChoiceListInterface;
|
||||
use Symfony\Component\Form\ChoiceList\LazyChoiceList;
|
||||
@ -35,21 +34,6 @@ class DefaultChoiceListFactory implements ChoiceListFactoryInterface
|
||||
return new ArrayChoiceList($choices, $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @deprecated Added for backwards compatibility in Symfony 2.7, to be
|
||||
* removed in Symfony 3.0.
|
||||
*/
|
||||
public function createListFromFlippedChoices($choices, $value = null, $triggerDeprecationNotice = true)
|
||||
{
|
||||
if ($triggerDeprecationNotice) {
|
||||
@trigger_error('The '.__METHOD__.' is deprecated since version 2.7 and will be removed in 3.0.', E_USER_DEPRECATED);
|
||||
}
|
||||
|
||||
return new ArrayKeyChoiceList($choices, $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
|
@ -104,25 +104,6 @@ class PropertyAccessDecorator implements ChoiceListFactoryInterface
|
||||
return $this->decoratedFactory->createListFromChoices($choices, $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @param array|\Traversable $choices The choices
|
||||
* @param null|callable|string|PropertyPath $value The callable or path for
|
||||
* generating the choice values
|
||||
*
|
||||
* @return ChoiceListInterface The choice list
|
||||
*
|
||||
* @deprecated Added for backwards compatibility in Symfony 2.7, to be
|
||||
* removed in Symfony 3.0.
|
||||
*/
|
||||
public function createListFromFlippedChoices($choices, $value = null, $triggerDeprecationNotice = true)
|
||||
{
|
||||
// Property paths are not supported here, because array keys can never
|
||||
// be objects
|
||||
return $this->decoratedFactory->createListFromFlippedChoices($choices, $value, $triggerDeprecationNotice);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
|
@ -260,20 +260,19 @@ class ChoiceType extends AbstractType
|
||||
// Harden against NULL values (like in EntityType and ModelType)
|
||||
$choices = null !== $options['choices'] ? $options['choices'] : array();
|
||||
|
||||
// BC when choices are in the keys, not in the values
|
||||
if (!$options['choices_as_values']) {
|
||||
return $choiceListFactory->createListFromFlippedChoices($choices, $options['choice_value'], false);
|
||||
}
|
||||
|
||||
return $choiceListFactory->createListFromChoices($choices, $options['choice_value']);
|
||||
};
|
||||
|
||||
$choicesAsValuesNormalizer = function (Options $options, $choicesAsValues) {
|
||||
if (true !== $choicesAsValues) {
|
||||
@trigger_error('The value "false" for the "choices_as_values" option is deprecated since version 2.8 and will not be supported anymore in 3.0. Set this option to "true" and flip the contents of the "choices" option instead.', E_USER_DEPRECATED);
|
||||
if (null !== $choicesAsValues) {
|
||||
if (true !== $choicesAsValues) {
|
||||
throw new \RuntimeException('The "choices_as_values" option should not be used. Remove it and flip the contents of the "choices" option instead.');
|
||||
}
|
||||
// To be uncommented in 3.1
|
||||
//@trigger_error('The "choices_as_values" option is deprecated since version 3.1 and will be removed in 4.0. You should not use it anymore.', E_USER_DEPRECATED);
|
||||
}
|
||||
|
||||
return $choicesAsValues;
|
||||
return true;
|
||||
};
|
||||
|
||||
$placeholderNormalizer = function (Options $options, $placeholder) {
|
||||
@ -309,7 +308,7 @@ class ChoiceType extends AbstractType
|
||||
'expanded' => false,
|
||||
'choice_list' => null, // deprecated
|
||||
'choices' => array(),
|
||||
'choices_as_values' => false,
|
||||
'choices_as_values' => null, // to be deprecated in 3.1
|
||||
'choice_loader' => null,
|
||||
'choice_label' => null,
|
||||
'choice_name' => null,
|
||||
@ -336,7 +335,6 @@ class ChoiceType extends AbstractType
|
||||
$resolver->setAllowedTypes('choice_list', array('null', 'Symfony\Component\Form\ChoiceList\ChoiceListInterface'));
|
||||
$resolver->setAllowedTypes('choices', array('null', 'array', '\Traversable'));
|
||||
$resolver->setAllowedTypes('choice_translation_domain', array('null', 'bool', 'string'));
|
||||
$resolver->setAllowedTypes('choices_as_values', 'bool');
|
||||
$resolver->setAllowedTypes('choice_loader', array('null', 'Symfony\Component\Form\ChoiceList\Loader\ChoiceLoaderInterface'));
|
||||
$resolver->setAllowedTypes('choice_label', array('null', 'callable', 'string', 'Symfony\Component\PropertyAccess\PropertyPath'));
|
||||
$resolver->setAllowedTypes('choice_name', array('null', 'callable', 'string', 'Symfony\Component\PropertyAccess\PropertyPath'));
|
||||
|
@ -24,7 +24,6 @@ class CountryType extends AbstractType
|
||||
{
|
||||
$resolver->setDefaults(array(
|
||||
'choices' => array_flip(Intl::getRegionBundle()->getCountryNames()),
|
||||
'choices_as_values' => true,
|
||||
'choice_translation_domain' => false,
|
||||
));
|
||||
}
|
||||
|
@ -24,7 +24,6 @@ class CurrencyType extends AbstractType
|
||||
{
|
||||
$resolver->setDefaults(array(
|
||||
'choices' => array_flip(Intl::getCurrencyBundle()->getCurrencyNames()),
|
||||
'choices_as_values' => true,
|
||||
'choice_translation_domain' => false,
|
||||
));
|
||||
}
|
||||
|
@ -93,15 +93,12 @@ class DateType extends AbstractType
|
||||
if ('choice' === $options['widget']) {
|
||||
// Only pass a subset of the options to children
|
||||
$yearOptions['choices'] = $this->formatTimestamps($formatter, '/y+/', $this->listYears($options['years']));
|
||||
$yearOptions['choices_as_values'] = true;
|
||||
$yearOptions['placeholder'] = $options['placeholder']['year'];
|
||||
$yearOptions['choice_translation_domain'] = $options['choice_translation_domain']['year'];
|
||||
$monthOptions['choices'] = $this->formatTimestamps($formatter, '/[M|L]+/', $this->listMonths($options['months']));
|
||||
$monthOptions['choices_as_values'] = true;
|
||||
$monthOptions['placeholder'] = $options['placeholder']['month'];
|
||||
$monthOptions['choice_translation_domain'] = $options['choice_translation_domain']['month'];
|
||||
$dayOptions['choices'] = $this->formatTimestamps($formatter, '/d+/', $this->listDays($options['days']));
|
||||
$dayOptions['choices_as_values'] = true;
|
||||
$dayOptions['placeholder'] = $options['placeholder']['day'];
|
||||
$dayOptions['choice_translation_domain'] = $options['choice_translation_domain']['day'];
|
||||
}
|
||||
|
@ -24,7 +24,6 @@ class LanguageType extends AbstractType
|
||||
{
|
||||
$resolver->setDefaults(array(
|
||||
'choices' => array_flip(Intl::getLanguageBundle()->getLanguageNames()),
|
||||
'choices_as_values' => true,
|
||||
'choice_translation_domain' => false,
|
||||
));
|
||||
}
|
||||
|
@ -24,7 +24,6 @@ class LocaleType extends AbstractType
|
||||
{
|
||||
$resolver->setDefaults(array(
|
||||
'choices' => array_flip(Intl::getLocaleBundle()->getLocaleNames()),
|
||||
'choices_as_values' => true,
|
||||
'choice_translation_domain' => false,
|
||||
));
|
||||
}
|
||||
|
@ -68,7 +68,6 @@ class TimeType extends AbstractType
|
||||
|
||||
// Only pass a subset of the options to children
|
||||
$hourOptions['choices'] = $hours;
|
||||
$hourOptions['choices_as_values'] = true;
|
||||
$hourOptions['placeholder'] = $options['placeholder']['hour'];
|
||||
$hourOptions['choice_translation_domain'] = $options['choice_translation_domain']['hour'];
|
||||
|
||||
@ -78,7 +77,6 @@ class TimeType extends AbstractType
|
||||
}
|
||||
|
||||
$minuteOptions['choices'] = $minutes;
|
||||
$minuteOptions['choices_as_values'] = true;
|
||||
$minuteOptions['placeholder'] = $options['placeholder']['minute'];
|
||||
$minuteOptions['choice_translation_domain'] = $options['choice_translation_domain']['minute'];
|
||||
}
|
||||
@ -91,7 +89,6 @@ class TimeType extends AbstractType
|
||||
}
|
||||
|
||||
$secondOptions['choices'] = $seconds;
|
||||
$secondOptions['choices_as_values'] = true;
|
||||
$secondOptions['placeholder'] = $options['placeholder']['second'];
|
||||
$secondOptions['choice_translation_domain'] = $options['choice_translation_domain']['second'];
|
||||
}
|
||||
|
@ -37,7 +37,6 @@ class TimezoneType extends AbstractType
|
||||
{
|
||||
$resolver->setDefaults(array(
|
||||
'choices' => self::getFlippedTimezones(),
|
||||
'choices_as_values' => true,
|
||||
'choice_translation_domain' => false,
|
||||
));
|
||||
}
|
||||
|
@ -213,7 +213,6 @@ abstract class AbstractBootstrap3LayoutTest extends AbstractLayoutTest
|
||||
{
|
||||
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\ChoiceType', '&a', array(
|
||||
'choices' => array('Choice&A' => '&a', 'Choice&B' => '&b'),
|
||||
'choices_as_values' => true,
|
||||
'multiple' => false,
|
||||
'expanded' => false,
|
||||
));
|
||||
@ -236,7 +235,6 @@ abstract class AbstractBootstrap3LayoutTest extends AbstractLayoutTest
|
||||
{
|
||||
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\ChoiceType', '&a', array(
|
||||
'choices' => array('Choice&A' => '&a', 'Choice&B' => '&b'),
|
||||
'choices_as_values' => true,
|
||||
'multiple' => false,
|
||||
'expanded' => false,
|
||||
'choice_translation_domain' => false,
|
||||
@ -260,7 +258,6 @@ abstract class AbstractBootstrap3LayoutTest extends AbstractLayoutTest
|
||||
{
|
||||
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\ChoiceType', '&a', array(
|
||||
'choices' => array('Choice&A' => '&a', 'Choice&B' => '&b'),
|
||||
'choices_as_values' => true,
|
||||
'multiple' => false,
|
||||
'expanded' => false,
|
||||
'required' => false,
|
||||
@ -287,7 +284,6 @@ abstract class AbstractBootstrap3LayoutTest extends AbstractLayoutTest
|
||||
{
|
||||
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\ChoiceType', '&a', array(
|
||||
'choices' => array('Choice&A' => '&a', 'Choice&B' => '&b'),
|
||||
'choices_as_values' => true,
|
||||
'choice_attr' => array('Choice&B' => array('class' => 'foo&bar')),
|
||||
'multiple' => false,
|
||||
'expanded' => false,
|
||||
@ -311,7 +307,6 @@ abstract class AbstractBootstrap3LayoutTest extends AbstractLayoutTest
|
||||
{
|
||||
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\ChoiceType', '&a', array(
|
||||
'choices' => array('Choice&A' => '&a', 'Choice&B' => '&b'),
|
||||
'choices_as_values' => true,
|
||||
'preferred_choices' => array('&b'),
|
||||
'multiple' => false,
|
||||
'expanded' => false,
|
||||
@ -336,7 +331,6 @@ abstract class AbstractBootstrap3LayoutTest extends AbstractLayoutTest
|
||||
{
|
||||
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\ChoiceType', '&a', array(
|
||||
'choices' => array('Choice&A' => '&a', 'Choice&B' => '&b'),
|
||||
'choices_as_values' => true,
|
||||
'preferred_choices' => array('&b'),
|
||||
'multiple' => false,
|
||||
'expanded' => false,
|
||||
@ -360,7 +354,6 @@ abstract class AbstractBootstrap3LayoutTest extends AbstractLayoutTest
|
||||
{
|
||||
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\ChoiceType', '&a', array(
|
||||
'choices' => array('Choice&A' => '&a', 'Choice&B' => '&b'),
|
||||
'choices_as_values' => true,
|
||||
'preferred_choices' => array('&b'),
|
||||
'multiple' => false,
|
||||
'expanded' => false,
|
||||
@ -385,7 +378,6 @@ abstract class AbstractBootstrap3LayoutTest extends AbstractLayoutTest
|
||||
{
|
||||
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\ChoiceType', '&a', array(
|
||||
'choices' => array('Choice&A' => '&a', 'Choice&B' => '&b'),
|
||||
'choices_as_values' => true,
|
||||
'preferred_choices' => array('&a', '&b'),
|
||||
'multiple' => false,
|
||||
'expanded' => false,
|
||||
@ -403,7 +395,6 @@ abstract class AbstractBootstrap3LayoutTest extends AbstractLayoutTest
|
||||
{
|
||||
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\ChoiceType', '&a', array(
|
||||
'choices' => array('Choice&A' => '&a', 'Choice&B' => '&b'),
|
||||
'choices_as_values' => true,
|
||||
'required' => false,
|
||||
'multiple' => false,
|
||||
'expanded' => false,
|
||||
@ -428,7 +419,6 @@ abstract class AbstractBootstrap3LayoutTest extends AbstractLayoutTest
|
||||
{
|
||||
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array(
|
||||
'choices' => array('Choice&A' => '&a', 'Choice&B' => '&b'),
|
||||
'choices_as_values' => true,
|
||||
'required' => false,
|
||||
'multiple' => false,
|
||||
'expanded' => false,
|
||||
@ -453,7 +443,6 @@ abstract class AbstractBootstrap3LayoutTest extends AbstractLayoutTest
|
||||
{
|
||||
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\ChoiceType', '&a', array(
|
||||
'choices' => array('Choice&A' => '&a', 'Choice&B' => '&b'),
|
||||
'choices_as_values' => true,
|
||||
'multiple' => false,
|
||||
'expanded' => false,
|
||||
'required' => false,
|
||||
@ -479,7 +468,6 @@ abstract class AbstractBootstrap3LayoutTest extends AbstractLayoutTest
|
||||
{
|
||||
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\ChoiceType', '&a', array(
|
||||
'choices' => array('Choice&A' => '&a', 'Choice&B' => '&b'),
|
||||
'choices_as_values' => true,
|
||||
'required' => true,
|
||||
'multiple' => false,
|
||||
'expanded' => false,
|
||||
@ -505,7 +493,6 @@ abstract class AbstractBootstrap3LayoutTest extends AbstractLayoutTest
|
||||
{
|
||||
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\ChoiceType', '&a', array(
|
||||
'choices' => array('Choice&A' => '&a', 'Choice&B' => '&b'),
|
||||
'choices_as_values' => true,
|
||||
'required' => true,
|
||||
'multiple' => false,
|
||||
'expanded' => false,
|
||||
@ -533,7 +520,6 @@ abstract class AbstractBootstrap3LayoutTest extends AbstractLayoutTest
|
||||
'Group&1' => array('Choice&A' => '&a', 'Choice&B' => '&b'),
|
||||
'Group&2' => array('Choice&C' => '&c'),
|
||||
),
|
||||
'choices_as_values' => true,
|
||||
'multiple' => false,
|
||||
'expanded' => false,
|
||||
));
|
||||
@ -562,7 +548,6 @@ abstract class AbstractBootstrap3LayoutTest extends AbstractLayoutTest
|
||||
{
|
||||
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\ChoiceType', array('&a'), array(
|
||||
'choices' => array('Choice&A' => '&a', 'Choice&B' => '&b'),
|
||||
'choices_as_values' => true,
|
||||
'required' => true,
|
||||
'multiple' => true,
|
||||
'expanded' => false,
|
||||
@ -587,7 +572,6 @@ abstract class AbstractBootstrap3LayoutTest extends AbstractLayoutTest
|
||||
{
|
||||
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\ChoiceType', array('&a'), array(
|
||||
'choices' => array('Choice&A' => '&a', 'Choice&B' => '&b'),
|
||||
'choices_as_values' => true,
|
||||
'choice_attr' => array('Choice&B' => array('class' => 'foo&bar')),
|
||||
'required' => true,
|
||||
'multiple' => true,
|
||||
@ -613,7 +597,6 @@ abstract class AbstractBootstrap3LayoutTest extends AbstractLayoutTest
|
||||
{
|
||||
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\ChoiceType', array('&a'), array(
|
||||
'choices' => array('Choice&A' => '&a', 'Choice&B' => '&b'),
|
||||
'choices_as_values' => true,
|
||||
'multiple' => true,
|
||||
'expanded' => false,
|
||||
'placeholder' => 'Test&Me',
|
||||
@ -637,7 +620,6 @@ abstract class AbstractBootstrap3LayoutTest extends AbstractLayoutTest
|
||||
{
|
||||
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\ChoiceType', array('&a'), array(
|
||||
'choices' => array('Choice&A' => '&a', 'Choice&B' => '&b'),
|
||||
'choices_as_values' => true,
|
||||
'required' => false,
|
||||
'multiple' => true,
|
||||
'expanded' => false,
|
||||
@ -661,7 +643,6 @@ abstract class AbstractBootstrap3LayoutTest extends AbstractLayoutTest
|
||||
{
|
||||
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\ChoiceType', '&a', array(
|
||||
'choices' => array('Choice&A' => '&a', 'Choice&B' => '&b'),
|
||||
'choices_as_values' => true,
|
||||
'multiple' => false,
|
||||
'expanded' => true,
|
||||
));
|
||||
@ -697,7 +678,6 @@ abstract class AbstractBootstrap3LayoutTest extends AbstractLayoutTest
|
||||
{
|
||||
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\ChoiceType', '&a', array(
|
||||
'choices' => array('Choice&A' => '&a', 'Choice&B' => '&b'),
|
||||
'choices_as_values' => true,
|
||||
'multiple' => false,
|
||||
'expanded' => true,
|
||||
'choice_translation_domain' => false,
|
||||
@ -734,7 +714,6 @@ abstract class AbstractBootstrap3LayoutTest extends AbstractLayoutTest
|
||||
{
|
||||
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\ChoiceType', '&a', array(
|
||||
'choices' => array('Choice&A' => '&a', 'Choice&B' => '&b'),
|
||||
'choices_as_values' => true,
|
||||
'choice_attr' => array('Choice&B' => array('class' => 'foo&bar')),
|
||||
'multiple' => false,
|
||||
'expanded' => true,
|
||||
@ -771,7 +750,6 @@ abstract class AbstractBootstrap3LayoutTest extends AbstractLayoutTest
|
||||
{
|
||||
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\ChoiceType', '&a', array(
|
||||
'choices' => array('Choice&A' => '&a', 'Choice&B' => '&b'),
|
||||
'choices_as_values' => true,
|
||||
'multiple' => false,
|
||||
'expanded' => true,
|
||||
'placeholder' => 'Test&Me',
|
||||
@ -817,7 +795,6 @@ abstract class AbstractBootstrap3LayoutTest extends AbstractLayoutTest
|
||||
{
|
||||
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\ChoiceType', '&a', array(
|
||||
'choices' => array('Choice&A' => '&a', 'Choice&B' => '&b'),
|
||||
'choices_as_values' => true,
|
||||
'multiple' => false,
|
||||
'expanded' => true,
|
||||
'translation_domain' => false,
|
||||
@ -864,7 +841,6 @@ abstract class AbstractBootstrap3LayoutTest extends AbstractLayoutTest
|
||||
{
|
||||
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\ChoiceType', true, array(
|
||||
'choices' => array('Choice&A' => '1', 'Choice&B' => '0'),
|
||||
'choices_as_values' => true,
|
||||
'multiple' => false,
|
||||
'expanded' => true,
|
||||
));
|
||||
@ -900,7 +876,6 @@ abstract class AbstractBootstrap3LayoutTest extends AbstractLayoutTest
|
||||
{
|
||||
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\ChoiceType', array('&a', '&c'), array(
|
||||
'choices' => array('Choice&A' => '&a', 'Choice&B' => '&b', 'Choice&C' => '&c'),
|
||||
'choices_as_values' => true,
|
||||
'multiple' => true,
|
||||
'expanded' => true,
|
||||
'required' => true,
|
||||
@ -946,7 +921,6 @@ abstract class AbstractBootstrap3LayoutTest extends AbstractLayoutTest
|
||||
{
|
||||
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\ChoiceType', array('&a', '&c'), array(
|
||||
'choices' => array('Choice&A' => '&a', 'Choice&B' => '&b', 'Choice&C' => '&c'),
|
||||
'choices_as_values' => true,
|
||||
'multiple' => true,
|
||||
'expanded' => true,
|
||||
'required' => true,
|
||||
@ -993,7 +967,6 @@ abstract class AbstractBootstrap3LayoutTest extends AbstractLayoutTest
|
||||
{
|
||||
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\ChoiceType', array('&a', '&c'), array(
|
||||
'choices' => array('Choice&A' => '&a', 'Choice&B' => '&b', 'Choice&C' => '&c'),
|
||||
'choices_as_values' => true,
|
||||
'choice_attr' => array('Choice&B' => array('class' => 'foo&bar')),
|
||||
'multiple' => true,
|
||||
'expanded' => true,
|
||||
|
@ -692,7 +692,6 @@ abstract class AbstractDivLayoutTest extends AbstractLayoutTest
|
||||
{
|
||||
$form = $this->factory->createNamedBuilder('name_c', 'Symfony\Component\Form\Extension\Core\Type\ChoiceType', 'a', array(
|
||||
'choices' => array('ChoiceA' => 'a', 'ChoiceB' => 'b'),
|
||||
'choices_as_values' => true,
|
||||
'expanded' => true,
|
||||
))
|
||||
->getForm();
|
||||
|
@ -488,7 +488,6 @@ abstract class AbstractLayoutTest extends \Symfony\Component\Form\Test\FormInteg
|
||||
{
|
||||
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\ChoiceType', '&a', array(
|
||||
'choices' => array('Choice&A' => '&a', 'Choice&B' => '&b'),
|
||||
'choices_as_values' => true,
|
||||
'multiple' => false,
|
||||
'expanded' => false,
|
||||
));
|
||||
@ -522,7 +521,6 @@ abstract class AbstractLayoutTest extends \Symfony\Component\Form\Test\FormInteg
|
||||
{
|
||||
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\ChoiceType', '&a', array(
|
||||
'choices' => array('Choice&A' => '&a', 'Choice&B' => '&b'),
|
||||
'choices_as_values' => true,
|
||||
'multiple' => false,
|
||||
'expanded' => false,
|
||||
'choice_translation_domain' => false,
|
||||
@ -545,7 +543,6 @@ abstract class AbstractLayoutTest extends \Symfony\Component\Form\Test\FormInteg
|
||||
{
|
||||
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\ChoiceType', '&a', array(
|
||||
'choices' => array('Choice&A' => '&a', 'Choice&B' => '&b'),
|
||||
'choices_as_values' => true,
|
||||
'multiple' => false,
|
||||
'expanded' => false,
|
||||
'required' => false,
|
||||
@ -571,7 +568,6 @@ abstract class AbstractLayoutTest extends \Symfony\Component\Form\Test\FormInteg
|
||||
{
|
||||
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\ChoiceType', '&a', array(
|
||||
'choices' => array('Choice&A' => '&a', 'Choice&B' => '&b'),
|
||||
'choices_as_values' => true,
|
||||
'choice_attr' => array('Choice&B' => array('class' => 'foo&bar')),
|
||||
'multiple' => false,
|
||||
'expanded' => false,
|
||||
@ -594,7 +590,6 @@ abstract class AbstractLayoutTest extends \Symfony\Component\Form\Test\FormInteg
|
||||
{
|
||||
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\ChoiceType', '&a', array(
|
||||
'choices' => array('Choice&A' => '&a', 'Choice&B' => '&b'),
|
||||
'choices_as_values' => true,
|
||||
'preferred_choices' => array('&b'),
|
||||
'multiple' => false,
|
||||
'expanded' => false,
|
||||
@ -618,7 +613,6 @@ abstract class AbstractLayoutTest extends \Symfony\Component\Form\Test\FormInteg
|
||||
{
|
||||
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\ChoiceType', '&a', array(
|
||||
'choices' => array('Choice&A' => '&a', 'Choice&B' => '&b'),
|
||||
'choices_as_values' => true,
|
||||
'preferred_choices' => array('&b'),
|
||||
'multiple' => false,
|
||||
'expanded' => false,
|
||||
@ -641,7 +635,6 @@ abstract class AbstractLayoutTest extends \Symfony\Component\Form\Test\FormInteg
|
||||
{
|
||||
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\ChoiceType', '&a', array(
|
||||
'choices' => array('Choice&A' => '&a', 'Choice&B' => '&b'),
|
||||
'choices_as_values' => true,
|
||||
'preferred_choices' => array('&b'),
|
||||
'multiple' => false,
|
||||
'expanded' => false,
|
||||
@ -665,7 +658,6 @@ abstract class AbstractLayoutTest extends \Symfony\Component\Form\Test\FormInteg
|
||||
{
|
||||
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\ChoiceType', '&a', array(
|
||||
'choices' => array('Choice&A' => '&a', 'Choice&B' => '&b'),
|
||||
'choices_as_values' => true,
|
||||
'preferred_choices' => array('&a', '&b'),
|
||||
'multiple' => false,
|
||||
'expanded' => false,
|
||||
@ -682,7 +674,6 @@ abstract class AbstractLayoutTest extends \Symfony\Component\Form\Test\FormInteg
|
||||
{
|
||||
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\ChoiceType', '&a', array(
|
||||
'choices' => array('Choice&A' => '&a', 'Choice&B' => '&b'),
|
||||
'choices_as_values' => true,
|
||||
'required' => false,
|
||||
'multiple' => false,
|
||||
'expanded' => false,
|
||||
@ -706,7 +697,6 @@ abstract class AbstractLayoutTest extends \Symfony\Component\Form\Test\FormInteg
|
||||
{
|
||||
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array(
|
||||
'choices' => array('Choice&A' => '&a', 'Choice&B' => '&b'),
|
||||
'choices_as_values' => true,
|
||||
'required' => false,
|
||||
'multiple' => false,
|
||||
'expanded' => false,
|
||||
@ -730,7 +720,6 @@ abstract class AbstractLayoutTest extends \Symfony\Component\Form\Test\FormInteg
|
||||
{
|
||||
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\ChoiceType', '&a', array(
|
||||
'choices' => array('Choice&A' => '&a', 'Choice&B' => '&b'),
|
||||
'choices_as_values' => true,
|
||||
'multiple' => false,
|
||||
'expanded' => false,
|
||||
'required' => false,
|
||||
@ -755,7 +744,6 @@ abstract class AbstractLayoutTest extends \Symfony\Component\Form\Test\FormInteg
|
||||
{
|
||||
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\ChoiceType', '&a', array(
|
||||
'choices' => array('Choice&A' => '&a', 'Choice&B' => '&b'),
|
||||
'choices_as_values' => true,
|
||||
'required' => true,
|
||||
'multiple' => false,
|
||||
'expanded' => false,
|
||||
@ -783,7 +771,6 @@ abstract class AbstractLayoutTest extends \Symfony\Component\Form\Test\FormInteg
|
||||
{
|
||||
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\ChoiceType', '&a', array(
|
||||
'choices' => array('Choice&A' => '&a', 'Choice&B' => '&b'),
|
||||
'choices_as_values' => true,
|
||||
'required' => true,
|
||||
'multiple' => false,
|
||||
'expanded' => false,
|
||||
@ -813,7 +800,6 @@ abstract class AbstractLayoutTest extends \Symfony\Component\Form\Test\FormInteg
|
||||
'Group&1' => array('Choice&A' => '&a', 'Choice&B' => '&b'),
|
||||
'Group&2' => array('Choice&C' => '&c'),
|
||||
),
|
||||
'choices_as_values' => true,
|
||||
'multiple' => false,
|
||||
'expanded' => false,
|
||||
));
|
||||
@ -841,7 +827,6 @@ abstract class AbstractLayoutTest extends \Symfony\Component\Form\Test\FormInteg
|
||||
{
|
||||
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\ChoiceType', array('&a'), array(
|
||||
'choices' => array('Choice&A' => '&a', 'Choice&B' => '&b'),
|
||||
'choices_as_values' => true,
|
||||
'required' => true,
|
||||
'multiple' => true,
|
||||
'expanded' => false,
|
||||
@ -865,7 +850,6 @@ abstract class AbstractLayoutTest extends \Symfony\Component\Form\Test\FormInteg
|
||||
{
|
||||
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\ChoiceType', array('&a'), array(
|
||||
'choices' => array('Choice&A' => '&a', 'Choice&B' => '&b'),
|
||||
'choices_as_values' => true,
|
||||
'choice_attr' => array('Choice&B' => array('class' => 'foo&bar')),
|
||||
'required' => true,
|
||||
'multiple' => true,
|
||||
@ -890,7 +874,6 @@ abstract class AbstractLayoutTest extends \Symfony\Component\Form\Test\FormInteg
|
||||
{
|
||||
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\ChoiceType', array('&a'), array(
|
||||
'choices' => array('Choice&A' => '&a', 'Choice&B' => '&b'),
|
||||
'choices_as_values' => true,
|
||||
'multiple' => true,
|
||||
'expanded' => false,
|
||||
'placeholder' => 'Test&Me',
|
||||
@ -913,7 +896,6 @@ abstract class AbstractLayoutTest extends \Symfony\Component\Form\Test\FormInteg
|
||||
{
|
||||
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\ChoiceType', array('&a'), array(
|
||||
'choices' => array('Choice&A' => '&a', 'Choice&B' => '&b'),
|
||||
'choices_as_values' => true,
|
||||
'required' => false,
|
||||
'multiple' => true,
|
||||
'expanded' => false,
|
||||
@ -936,7 +918,6 @@ abstract class AbstractLayoutTest extends \Symfony\Component\Form\Test\FormInteg
|
||||
{
|
||||
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\ChoiceType', '&a', array(
|
||||
'choices' => array('Choice&A' => '&a', 'Choice&B' => '&b'),
|
||||
'choices_as_values' => true,
|
||||
'multiple' => false,
|
||||
'expanded' => true,
|
||||
));
|
||||
@ -959,7 +940,6 @@ abstract class AbstractLayoutTest extends \Symfony\Component\Form\Test\FormInteg
|
||||
{
|
||||
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\ChoiceType', '&a', array(
|
||||
'choices' => array('Choice&A' => '&a', 'Choice&B' => '&b'),
|
||||
'choices_as_values' => true,
|
||||
'multiple' => false,
|
||||
'expanded' => true,
|
||||
'choice_translation_domain' => false,
|
||||
@ -983,7 +963,6 @@ abstract class AbstractLayoutTest extends \Symfony\Component\Form\Test\FormInteg
|
||||
{
|
||||
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\ChoiceType', '&a', array(
|
||||
'choices' => array('Choice&A' => '&a', 'Choice&B' => '&b'),
|
||||
'choices_as_values' => true,
|
||||
'choice_attr' => array('Choice&B' => array('class' => 'foo&bar')),
|
||||
'multiple' => false,
|
||||
'expanded' => true,
|
||||
@ -1007,7 +986,6 @@ abstract class AbstractLayoutTest extends \Symfony\Component\Form\Test\FormInteg
|
||||
{
|
||||
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\ChoiceType', '&a', array(
|
||||
'choices' => array('Choice&A' => '&a', 'Choice&B' => '&b'),
|
||||
'choices_as_values' => true,
|
||||
'multiple' => false,
|
||||
'expanded' => true,
|
||||
'placeholder' => 'Test&Me',
|
||||
@ -1033,7 +1011,6 @@ abstract class AbstractLayoutTest extends \Symfony\Component\Form\Test\FormInteg
|
||||
{
|
||||
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\ChoiceType', '&a', array(
|
||||
'choices' => array('Choice&A' => '&a', 'Choice&B' => '&b'),
|
||||
'choices_as_values' => true,
|
||||
'multiple' => false,
|
||||
'expanded' => true,
|
||||
'translation_domain' => false,
|
||||
@ -1060,7 +1037,6 @@ abstract class AbstractLayoutTest extends \Symfony\Component\Form\Test\FormInteg
|
||||
{
|
||||
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\ChoiceType', true, array(
|
||||
'choices' => array('Choice&A' => '1', 'Choice&B' => '0'),
|
||||
'choices_as_values' => true,
|
||||
'multiple' => false,
|
||||
'expanded' => true,
|
||||
));
|
||||
@ -1083,7 +1059,6 @@ abstract class AbstractLayoutTest extends \Symfony\Component\Form\Test\FormInteg
|
||||
{
|
||||
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\ChoiceType', array('&a', '&c'), array(
|
||||
'choices' => array('Choice&A' => '&a', 'Choice&B' => '&b', 'Choice&C' => '&c'),
|
||||
'choices_as_values' => true,
|
||||
'multiple' => true,
|
||||
'expanded' => true,
|
||||
'required' => true,
|
||||
@ -1109,7 +1084,6 @@ abstract class AbstractLayoutTest extends \Symfony\Component\Form\Test\FormInteg
|
||||
{
|
||||
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\ChoiceType', array('&a', '&c'), array(
|
||||
'choices' => array('Choice&A' => '&a', 'Choice&B' => '&b', 'Choice&C' => '&c'),
|
||||
'choices_as_values' => true,
|
||||
'multiple' => true,
|
||||
'expanded' => true,
|
||||
'required' => true,
|
||||
@ -1136,7 +1110,6 @@ abstract class AbstractLayoutTest extends \Symfony\Component\Form\Test\FormInteg
|
||||
{
|
||||
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\ChoiceType', array('&a', '&c'), array(
|
||||
'choices' => array('Choice&A' => '&a', 'Choice&B' => '&b', 'Choice&C' => '&c'),
|
||||
'choices_as_values' => true,
|
||||
'choice_attr' => array('Choice&B' => array('class' => 'foo&bar')),
|
||||
'multiple' => true,
|
||||
'expanded' => true,
|
||||
|
@ -1,183 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Form\Tests\ChoiceList;
|
||||
|
||||
use Symfony\Component\Form\ChoiceList\ArrayKeyChoiceList;
|
||||
|
||||
/**
|
||||
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||
*
|
||||
* @group legacy
|
||||
*/
|
||||
class ArrayKeyChoiceListTest extends AbstractChoiceListTest
|
||||
{
|
||||
private $object;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->object = new \stdClass();
|
||||
}
|
||||
|
||||
protected function createChoiceList()
|
||||
{
|
||||
return new ArrayKeyChoiceList(array_flip($this->getChoices()));
|
||||
}
|
||||
|
||||
protected function getChoices()
|
||||
{
|
||||
return array(0, 1, 'a', 'b', '');
|
||||
}
|
||||
|
||||
protected function getValues()
|
||||
{
|
||||
return array('0', '1', 'a', 'b', '');
|
||||
}
|
||||
|
||||
public function testUseChoicesAsValuesByDefault()
|
||||
{
|
||||
$list = new ArrayKeyChoiceList(array('' => 'Empty', 0 => 'Zero', 1 => 'One', '1.23' => 'Float'));
|
||||
|
||||
$this->assertSame(array('', '0', '1', '1.23'), $list->getValues());
|
||||
$this->assertSame(array('' => '', 0 => 0, 1 => 1, '1.23' => '1.23'), $list->getChoices());
|
||||
$this->assertSame(array('' => 'Empty', 0 => 'Zero', 1 => 'One', '1.23' => 'Float'), $list->getOriginalKeys());
|
||||
}
|
||||
|
||||
public function testNoChoices()
|
||||
{
|
||||
$list = new ArrayKeyChoiceList(array());
|
||||
|
||||
$this->assertSame(array(), $list->getValues());
|
||||
}
|
||||
|
||||
public function testGetChoicesForValuesConvertsValuesToStrings()
|
||||
{
|
||||
$this->assertSame(array(0), $this->list->getChoicesForValues(array(0)));
|
||||
$this->assertSame(array(0), $this->list->getChoicesForValues(array('0')));
|
||||
$this->assertSame(array(1), $this->list->getChoicesForValues(array(1)));
|
||||
$this->assertSame(array(1), $this->list->getChoicesForValues(array('1')));
|
||||
$this->assertSame(array('a'), $this->list->getChoicesForValues(array('a')));
|
||||
$this->assertSame(array('b'), $this->list->getChoicesForValues(array('b')));
|
||||
$this->assertSame(array(''), $this->list->getChoicesForValues(array('')));
|
||||
// "1" === (string) true
|
||||
$this->assertSame(array(1), $this->list->getChoicesForValues(array(true)));
|
||||
// "" === (string) false
|
||||
$this->assertSame(array(''), $this->list->getChoicesForValues(array(false)));
|
||||
// "" === (string) null
|
||||
$this->assertSame(array(''), $this->list->getChoicesForValues(array(null)));
|
||||
$this->assertSame(array(), $this->list->getChoicesForValues(array(1.23)));
|
||||
}
|
||||
|
||||
public function testGetValuesForChoicesConvertsChoicesToArrayKeys()
|
||||
{
|
||||
$this->assertSame(array('0'), $this->list->getValuesForChoices(array(0)));
|
||||
$this->assertSame(array('0'), $this->list->getValuesForChoices(array('0')));
|
||||
$this->assertSame(array('1'), $this->list->getValuesForChoices(array(1)));
|
||||
$this->assertSame(array('1'), $this->list->getValuesForChoices(array('1')));
|
||||
$this->assertSame(array('a'), $this->list->getValuesForChoices(array('a')));
|
||||
$this->assertSame(array('b'), $this->list->getValuesForChoices(array('b')));
|
||||
// Always cast booleans to 0 and 1, because:
|
||||
// array(true => 'Yes', false => 'No') === array(1 => 'Yes', 0 => 'No')
|
||||
// see ChoiceTypeTest::testSetDataSingleNonExpandedAcceptsBoolean
|
||||
$this->assertSame(array('0'), $this->list->getValuesForChoices(array(false)));
|
||||
$this->assertSame(array('1'), $this->list->getValuesForChoices(array(true)));
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider provideConvertibleChoices
|
||||
*/
|
||||
public function testConvertChoicesIfNecessary(array $choices, array $converted)
|
||||
{
|
||||
$list = new ArrayKeyChoiceList($choices);
|
||||
|
||||
$this->assertSame($converted, $list->getChoices());
|
||||
}
|
||||
|
||||
public function provideConvertibleChoices()
|
||||
{
|
||||
return array(
|
||||
array(array(0 => 'Label'), array(0 => 0)),
|
||||
array(array(1 => 'Label'), array(1 => 1)),
|
||||
array(array('1.23' => 'Label'), array('1.23' => '1.23')),
|
||||
array(array('foobar' => 'Label'), array('foobar' => 'foobar')),
|
||||
// The default value of choice fields is NULL. It should be treated
|
||||
// like the empty value for this choice list type
|
||||
array(array(null => 'Label'), array('' => '')),
|
||||
array(array('1.23' => 'Label'), array('1.23' => '1.23')),
|
||||
// Always cast booleans to 0 and 1, because:
|
||||
// array(true => 'Yes', false => 'No') === array(1 => 'Yes', 0 => 'No')
|
||||
// see ChoiceTypeTest::testSetDataSingleNonExpandedAcceptsBoolean
|
||||
array(array(true => 'Label'), array(1 => 1)),
|
||||
array(array(false => 'Label'), array(0 => 0)),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider provideInvalidChoices
|
||||
* @expectedException \Symfony\Component\Form\Exception\InvalidArgumentException
|
||||
*/
|
||||
public function testGetValuesForChoicesFailsIfInvalidChoices(array $choices)
|
||||
{
|
||||
$this->list->getValuesForChoices($choices);
|
||||
}
|
||||
|
||||
public function provideInvalidChoices()
|
||||
{
|
||||
return array(
|
||||
array(array(new \stdClass())),
|
||||
array(array(array(1, 2))),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider provideConvertibleValues
|
||||
*/
|
||||
public function testConvertValuesToStrings($value, $converted)
|
||||
{
|
||||
$callback = function () use ($value) {
|
||||
return $value;
|
||||
};
|
||||
|
||||
$list = new ArrayKeyChoiceList(array('choice' => 'Label'), $callback);
|
||||
|
||||
$this->assertSame(array($converted), $list->getValues());
|
||||
}
|
||||
|
||||
public function provideConvertibleValues()
|
||||
{
|
||||
return array(
|
||||
array(0, '0'),
|
||||
array(1, '1'),
|
||||
array('0', '0'),
|
||||
array('1', '1'),
|
||||
array('1.23', '1.23'),
|
||||
array('foobar', 'foobar'),
|
||||
array('', ''),
|
||||
);
|
||||
}
|
||||
|
||||
public function testCreateChoiceListWithValueCallback()
|
||||
{
|
||||
$callback = function ($choice) {
|
||||
return ':'.$choice;
|
||||
};
|
||||
|
||||
$choiceList = new ArrayKeyChoiceList(array('foo' => 'Foo', 'bar' => 'Bar', 'baz' => 'Baz'), $callback);
|
||||
|
||||
$this->assertSame(array(':foo', ':bar', ':baz'), $choiceList->getValues());
|
||||
$this->assertSame(array(':foo' => 'foo', ':bar' => 'bar', ':baz' => 'baz'), $choiceList->getChoices());
|
||||
$this->assertSame(array(':foo' => 'Foo', ':bar' => 'Bar', ':baz' => 'Baz'), $choiceList->getOriginalKeys());
|
||||
$this->assertSame(array(1 => 'foo', 2 => 'baz'), $choiceList->getChoicesForValues(array(1 => ':foo', 2 => ':baz')));
|
||||
$this->assertSame(array(1 => ':foo', 2 => ':baz'), $choiceList->getValuesForChoices(array(1 => 'foo', 2 => 'baz')));
|
||||
}
|
||||
}
|
@ -13,7 +13,6 @@ namespace Symfony\Component\Form\Tests\Extension\Core\Type;
|
||||
|
||||
use Symfony\Component\Form\ChoiceList\View\ChoiceGroupView;
|
||||
use Symfony\Component\Form\ChoiceList\View\ChoiceView;
|
||||
use Symfony\Component\Form\Extension\Core\ChoiceList\ObjectChoiceList;
|
||||
|
||||
class ChoiceTypeTest extends \Symfony\Component\Form\Test\TypeTestCase
|
||||
{
|
||||
@ -25,14 +24,6 @@ class ChoiceTypeTest extends \Symfony\Component\Form\Test\TypeTestCase
|
||||
'Roman' => 'e',
|
||||
);
|
||||
|
||||
private $numericChoicesFlipped = array(
|
||||
0 => 'Bernhard',
|
||||
1 => 'Fabien',
|
||||
2 => 'Kris',
|
||||
3 => 'Jon',
|
||||
4 => 'Roman',
|
||||
);
|
||||
|
||||
private $objectChoices;
|
||||
|
||||
protected $groupedChoices = array(
|
||||
@ -47,18 +38,6 @@ class ChoiceTypeTest extends \Symfony\Component\Form\Test\TypeTestCase
|
||||
),
|
||||
);
|
||||
|
||||
protected $groupedChoicesFlipped = array(
|
||||
'Symfony' => array(
|
||||
'a' => 'Bernhard',
|
||||
'b' => 'Fabien',
|
||||
'c' => 'Kris',
|
||||
),
|
||||
'Doctrine' => array(
|
||||
'd' => 'Jon',
|
||||
'e' => 'Roman',
|
||||
),
|
||||
);
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
@ -112,7 +91,6 @@ class ChoiceTypeTest extends \Symfony\Component\Form\Test\TypeTestCase
|
||||
public function testChoiceListAndChoicesCanBeEmpty()
|
||||
{
|
||||
$this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array(
|
||||
'choices_as_values' => true,
|
||||
));
|
||||
}
|
||||
|
||||
@ -121,20 +99,6 @@ class ChoiceTypeTest extends \Symfony\Component\Form\Test\TypeTestCase
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array(
|
||||
'expanded' => true,
|
||||
'choices' => $this->choices,
|
||||
'choices_as_values' => true,
|
||||
));
|
||||
|
||||
$this->assertCount(count($this->choices), $form, 'Each choice should become a new field');
|
||||
}
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
*/
|
||||
public function testExpandedFlippedChoicesOptionsTurnIntoChildren()
|
||||
{
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array(
|
||||
'expanded' => true,
|
||||
'choices' => array_flip($this->choices),
|
||||
));
|
||||
|
||||
$this->assertCount(count($this->choices), $form, 'Each choice should become a new field');
|
||||
@ -147,7 +111,6 @@ class ChoiceTypeTest extends \Symfony\Component\Form\Test\TypeTestCase
|
||||
'expanded' => true,
|
||||
'required' => false,
|
||||
'choices' => $this->choices,
|
||||
'choices_as_values' => true,
|
||||
));
|
||||
|
||||
$this->assertTrue(isset($form['placeholder']));
|
||||
@ -161,7 +124,6 @@ class ChoiceTypeTest extends \Symfony\Component\Form\Test\TypeTestCase
|
||||
'expanded' => true,
|
||||
'required' => true,
|
||||
'choices' => $this->choices,
|
||||
'choices_as_values' => true,
|
||||
));
|
||||
|
||||
$this->assertFalse(isset($form['placeholder']));
|
||||
@ -175,7 +137,6 @@ class ChoiceTypeTest extends \Symfony\Component\Form\Test\TypeTestCase
|
||||
'expanded' => true,
|
||||
'required' => false,
|
||||
'choices' => $this->choices,
|
||||
'choices_as_values' => true,
|
||||
));
|
||||
|
||||
$this->assertFalse(isset($form['placeholder']));
|
||||
@ -192,7 +153,6 @@ class ChoiceTypeTest extends \Symfony\Component\Form\Test\TypeTestCase
|
||||
'Empty' => '',
|
||||
'Not empty' => 1,
|
||||
),
|
||||
'choices_as_values' => true,
|
||||
));
|
||||
|
||||
$this->assertFalse(isset($form['placeholder']));
|
||||
@ -204,29 +164,6 @@ class ChoiceTypeTest extends \Symfony\Component\Form\Test\TypeTestCase
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array(
|
||||
'expanded' => true,
|
||||
'choices' => $this->groupedChoices,
|
||||
'choices_as_values' => true,
|
||||
));
|
||||
|
||||
$flattened = array();
|
||||
foreach ($this->groupedChoices as $choices) {
|
||||
$flattened = array_merge($flattened, array_keys($choices));
|
||||
}
|
||||
|
||||
$this->assertCount($form->count(), $flattened, 'Each nested choice should become a new field, not the groups');
|
||||
|
||||
foreach ($flattened as $value => $choice) {
|
||||
$this->assertTrue($form->has($value), 'Flattened choice is named after it\'s value');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
*/
|
||||
public function testExpandedChoicesFlippedOptionsAreFlattened()
|
||||
{
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array(
|
||||
'expanded' => true,
|
||||
'choices' => $this->groupedChoicesFlipped,
|
||||
));
|
||||
|
||||
$flattened = array();
|
||||
@ -255,7 +192,6 @@ class ChoiceTypeTest extends \Symfony\Component\Form\Test\TypeTestCase
|
||||
'Symfony' => array($obj1, $obj2, $obj3),
|
||||
'Doctrine' => array($obj4, $obj5),
|
||||
),
|
||||
'choices_as_values' => true,
|
||||
'choice_name' => 'id',
|
||||
));
|
||||
|
||||
@ -274,7 +210,6 @@ class ChoiceTypeTest extends \Symfony\Component\Form\Test\TypeTestCase
|
||||
'expanded' => true,
|
||||
'required' => true,
|
||||
'choices' => $this->choices,
|
||||
'choices_as_values' => true,
|
||||
));
|
||||
|
||||
foreach ($form as $child) {
|
||||
@ -289,7 +224,6 @@ class ChoiceTypeTest extends \Symfony\Component\Form\Test\TypeTestCase
|
||||
'expanded' => true,
|
||||
'required' => true,
|
||||
'choices' => $this->choices,
|
||||
'choices_as_values' => true,
|
||||
));
|
||||
|
||||
foreach ($form as $child) {
|
||||
@ -304,7 +238,6 @@ class ChoiceTypeTest extends \Symfony\Component\Form\Test\TypeTestCase
|
||||
'expanded' => true,
|
||||
'required' => false,
|
||||
'choices' => $this->choices,
|
||||
'choices_as_values' => true,
|
||||
));
|
||||
|
||||
foreach ($form as $child) {
|
||||
@ -318,7 +251,6 @@ class ChoiceTypeTest extends \Symfony\Component\Form\Test\TypeTestCase
|
||||
'multiple' => false,
|
||||
'expanded' => false,
|
||||
'choices' => $this->choices,
|
||||
'choices_as_values' => true,
|
||||
));
|
||||
|
||||
$form->submit('b');
|
||||
@ -334,7 +266,6 @@ class ChoiceTypeTest extends \Symfony\Component\Form\Test\TypeTestCase
|
||||
'multiple' => false,
|
||||
'expanded' => false,
|
||||
'choices' => $this->choices,
|
||||
'choices_as_values' => true,
|
||||
));
|
||||
|
||||
$form->submit('foobar');
|
||||
@ -350,7 +281,6 @@ class ChoiceTypeTest extends \Symfony\Component\Form\Test\TypeTestCase
|
||||
'multiple' => false,
|
||||
'expanded' => false,
|
||||
'choices' => $this->choices,
|
||||
'choices_as_values' => true,
|
||||
));
|
||||
|
||||
$form->submit(null);
|
||||
@ -369,7 +299,6 @@ class ChoiceTypeTest extends \Symfony\Component\Form\Test\TypeTestCase
|
||||
'multiple' => false,
|
||||
'expanded' => false,
|
||||
'choices' => array(),
|
||||
'choices_as_values' => true,
|
||||
));
|
||||
|
||||
$form->submit(null);
|
||||
@ -385,7 +314,6 @@ class ChoiceTypeTest extends \Symfony\Component\Form\Test\TypeTestCase
|
||||
'multiple' => false,
|
||||
'expanded' => false,
|
||||
'choices' => $this->choices,
|
||||
'choices_as_values' => true,
|
||||
));
|
||||
|
||||
$form->submit('');
|
||||
@ -403,7 +331,6 @@ class ChoiceTypeTest extends \Symfony\Component\Form\Test\TypeTestCase
|
||||
'choices' => array(
|
||||
'Empty' => 'EMPTY_CHOICE',
|
||||
),
|
||||
'choices_as_values' => true,
|
||||
'choice_value' => function () {
|
||||
return '';
|
||||
},
|
||||
@ -425,7 +352,6 @@ class ChoiceTypeTest extends \Symfony\Component\Form\Test\TypeTestCase
|
||||
'multiple' => false,
|
||||
'expanded' => false,
|
||||
'choices' => array(),
|
||||
'choices_as_values' => true,
|
||||
));
|
||||
|
||||
$form->submit('');
|
||||
@ -441,7 +367,6 @@ class ChoiceTypeTest extends \Symfony\Component\Form\Test\TypeTestCase
|
||||
'multiple' => false,
|
||||
'expanded' => false,
|
||||
'choices' => $this->choices,
|
||||
'choices_as_values' => true,
|
||||
));
|
||||
|
||||
$form->submit(false);
|
||||
@ -460,7 +385,6 @@ class ChoiceTypeTest extends \Symfony\Component\Form\Test\TypeTestCase
|
||||
'multiple' => false,
|
||||
'expanded' => false,
|
||||
'choices' => array(),
|
||||
'choices_as_values' => true,
|
||||
));
|
||||
|
||||
$form->submit(false);
|
||||
@ -476,7 +400,6 @@ class ChoiceTypeTest extends \Symfony\Component\Form\Test\TypeTestCase
|
||||
'multiple' => false,
|
||||
'expanded' => false,
|
||||
'choices' => $this->objectChoices,
|
||||
'choices_as_values' => true,
|
||||
'choice_label' => 'name',
|
||||
'choice_value' => 'id',
|
||||
));
|
||||
@ -495,7 +418,6 @@ class ChoiceTypeTest extends \Symfony\Component\Form\Test\TypeTestCase
|
||||
'multiple' => true,
|
||||
'expanded' => false,
|
||||
'choices' => $this->choices,
|
||||
'choices_as_values' => true,
|
||||
));
|
||||
|
||||
$form->submit(array('a', 'b'));
|
||||
@ -511,7 +433,6 @@ class ChoiceTypeTest extends \Symfony\Component\Form\Test\TypeTestCase
|
||||
'multiple' => true,
|
||||
'expanded' => false,
|
||||
'choices' => $this->choices,
|
||||
'choices_as_values' => true,
|
||||
));
|
||||
|
||||
$form->submit(array());
|
||||
@ -530,7 +451,6 @@ class ChoiceTypeTest extends \Symfony\Component\Form\Test\TypeTestCase
|
||||
'multiple' => true,
|
||||
'expanded' => false,
|
||||
'choices' => array(),
|
||||
'choices_as_values' => true,
|
||||
));
|
||||
|
||||
$form->submit(array());
|
||||
@ -546,7 +466,6 @@ class ChoiceTypeTest extends \Symfony\Component\Form\Test\TypeTestCase
|
||||
'multiple' => true,
|
||||
'expanded' => false,
|
||||
'choices' => $this->choices,
|
||||
'choices_as_values' => true,
|
||||
));
|
||||
|
||||
$form->submit('foobar');
|
||||
@ -562,7 +481,6 @@ class ChoiceTypeTest extends \Symfony\Component\Form\Test\TypeTestCase
|
||||
'multiple' => true,
|
||||
'expanded' => false,
|
||||
'choices' => $this->choices,
|
||||
'choices_as_values' => true,
|
||||
));
|
||||
|
||||
$form->submit(array('a', 'foobar'));
|
||||
@ -578,7 +496,6 @@ class ChoiceTypeTest extends \Symfony\Component\Form\Test\TypeTestCase
|
||||
'multiple' => true,
|
||||
'expanded' => false,
|
||||
'choices' => $this->objectChoices,
|
||||
'choices_as_values' => true,
|
||||
'choice_label' => 'name',
|
||||
'choice_value' => 'id',
|
||||
));
|
||||
@ -597,7 +514,6 @@ class ChoiceTypeTest extends \Symfony\Component\Form\Test\TypeTestCase
|
||||
'expanded' => true,
|
||||
'required' => true,
|
||||
'choices' => $this->choices,
|
||||
'choices_as_values' => true,
|
||||
));
|
||||
|
||||
$form->submit('b');
|
||||
@ -626,7 +542,6 @@ class ChoiceTypeTest extends \Symfony\Component\Form\Test\TypeTestCase
|
||||
'expanded' => true,
|
||||
'required' => true,
|
||||
'choices' => $this->choices,
|
||||
'choices_as_values' => true,
|
||||
));
|
||||
|
||||
$form->submit('foobar');
|
||||
@ -655,7 +570,6 @@ class ChoiceTypeTest extends \Symfony\Component\Form\Test\TypeTestCase
|
||||
'expanded' => true,
|
||||
'required' => false,
|
||||
'choices' => $this->choices,
|
||||
'choices_as_values' => true,
|
||||
));
|
||||
|
||||
$form->submit('b');
|
||||
@ -686,7 +600,6 @@ class ChoiceTypeTest extends \Symfony\Component\Form\Test\TypeTestCase
|
||||
'expanded' => true,
|
||||
'required' => false,
|
||||
'choices' => $this->choices,
|
||||
'choices_as_values' => true,
|
||||
));
|
||||
|
||||
$form->submit('foobar');
|
||||
@ -715,7 +628,6 @@ class ChoiceTypeTest extends \Symfony\Component\Form\Test\TypeTestCase
|
||||
'expanded' => true,
|
||||
'required' => true,
|
||||
'choices' => $this->choices,
|
||||
'choices_as_values' => true,
|
||||
));
|
||||
|
||||
$form->submit(null);
|
||||
@ -747,7 +659,6 @@ class ChoiceTypeTest extends \Symfony\Component\Form\Test\TypeTestCase
|
||||
'expanded' => true,
|
||||
'required' => true,
|
||||
'choices' => array(),
|
||||
'choices_as_values' => true,
|
||||
));
|
||||
|
||||
$form->submit(null);
|
||||
@ -765,7 +676,6 @@ class ChoiceTypeTest extends \Symfony\Component\Form\Test\TypeTestCase
|
||||
'expanded' => true,
|
||||
'required' => true,
|
||||
'choices' => $this->choices,
|
||||
'choices_as_values' => true,
|
||||
));
|
||||
|
||||
$form->submit('');
|
||||
@ -797,7 +707,6 @@ class ChoiceTypeTest extends \Symfony\Component\Form\Test\TypeTestCase
|
||||
'expanded' => true,
|
||||
'required' => true,
|
||||
'choices' => array(),
|
||||
'choices_as_values' => true,
|
||||
));
|
||||
|
||||
$form->submit('');
|
||||
@ -815,7 +724,6 @@ class ChoiceTypeTest extends \Symfony\Component\Form\Test\TypeTestCase
|
||||
'expanded' => true,
|
||||
'required' => true,
|
||||
'choices' => $this->choices,
|
||||
'choices_as_values' => true,
|
||||
));
|
||||
|
||||
$form->submit(false);
|
||||
@ -847,7 +755,6 @@ class ChoiceTypeTest extends \Symfony\Component\Form\Test\TypeTestCase
|
||||
'expanded' => true,
|
||||
'required' => true,
|
||||
'choices' => array(),
|
||||
'choices_as_values' => true,
|
||||
));
|
||||
|
||||
$form->submit(false);
|
||||
@ -865,7 +772,6 @@ class ChoiceTypeTest extends \Symfony\Component\Form\Test\TypeTestCase
|
||||
'expanded' => true,
|
||||
'required' => false,
|
||||
'choices' => $this->choices,
|
||||
'choices_as_values' => true,
|
||||
));
|
||||
|
||||
$form->submit(null);
|
||||
@ -899,7 +805,6 @@ class ChoiceTypeTest extends \Symfony\Component\Form\Test\TypeTestCase
|
||||
'expanded' => true,
|
||||
'required' => false,
|
||||
'choices' => array(),
|
||||
'choices_as_values' => true,
|
||||
));
|
||||
|
||||
$form->submit(null);
|
||||
@ -917,7 +822,6 @@ class ChoiceTypeTest extends \Symfony\Component\Form\Test\TypeTestCase
|
||||
'expanded' => true,
|
||||
'required' => false,
|
||||
'choices' => $this->choices,
|
||||
'choices_as_values' => true,
|
||||
));
|
||||
|
||||
$form->submit('');
|
||||
@ -951,7 +855,6 @@ class ChoiceTypeTest extends \Symfony\Component\Form\Test\TypeTestCase
|
||||
'expanded' => true,
|
||||
'required' => false,
|
||||
'choices' => array(),
|
||||
'choices_as_values' => true,
|
||||
));
|
||||
|
||||
$form->submit('');
|
||||
@ -969,7 +872,6 @@ class ChoiceTypeTest extends \Symfony\Component\Form\Test\TypeTestCase
|
||||
'expanded' => true,
|
||||
'required' => false,
|
||||
'choices' => $this->choices,
|
||||
'choices_as_values' => true,
|
||||
));
|
||||
|
||||
$form->submit(false);
|
||||
@ -1003,7 +905,6 @@ class ChoiceTypeTest extends \Symfony\Component\Form\Test\TypeTestCase
|
||||
'expanded' => true,
|
||||
'required' => false,
|
||||
'choices' => array(),
|
||||
'choices_as_values' => true,
|
||||
));
|
||||
|
||||
$form->submit(false);
|
||||
@ -1023,7 +924,6 @@ class ChoiceTypeTest extends \Symfony\Component\Form\Test\TypeTestCase
|
||||
'Empty' => '',
|
||||
'Not empty' => 1,
|
||||
),
|
||||
'choices_as_values' => true,
|
||||
));
|
||||
|
||||
$form->submit('');
|
||||
@ -1043,7 +943,6 @@ class ChoiceTypeTest extends \Symfony\Component\Form\Test\TypeTestCase
|
||||
'multiple' => false,
|
||||
'expanded' => true,
|
||||
'choices' => $this->objectChoices,
|
||||
'choices_as_values' => true,
|
||||
'choice_label' => 'name',
|
||||
'choice_value' => 'id',
|
||||
));
|
||||
@ -1065,38 +964,12 @@ class ChoiceTypeTest extends \Symfony\Component\Form\Test\TypeTestCase
|
||||
$this->assertNull($form[4]->getViewData());
|
||||
}
|
||||
|
||||
public function testSubmitSingleExpandedNumericChoices()
|
||||
{
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array(
|
||||
'multiple' => false,
|
||||
'expanded' => true,
|
||||
'choices' => $this->numericChoicesFlipped,
|
||||
));
|
||||
|
||||
$form->submit('1');
|
||||
|
||||
$this->assertSame(1, $form->getData());
|
||||
$this->assertTrue($form->isSynchronized());
|
||||
|
||||
$this->assertFalse($form[0]->getData());
|
||||
$this->assertTrue($form[1]->getData());
|
||||
$this->assertFalse($form[2]->getData());
|
||||
$this->assertFalse($form[3]->getData());
|
||||
$this->assertFalse($form[4]->getData());
|
||||
$this->assertNull($form[0]->getViewData());
|
||||
$this->assertSame('1', $form[1]->getViewData());
|
||||
$this->assertNull($form[2]->getViewData());
|
||||
$this->assertNull($form[3]->getViewData());
|
||||
$this->assertNull($form[4]->getViewData());
|
||||
}
|
||||
|
||||
public function testSubmitMultipleExpanded()
|
||||
{
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array(
|
||||
'multiple' => true,
|
||||
'expanded' => true,
|
||||
'choices' => $this->choices,
|
||||
'choices_as_values' => true,
|
||||
));
|
||||
|
||||
$form->submit(array('a', 'c'));
|
||||
@ -1124,7 +997,6 @@ class ChoiceTypeTest extends \Symfony\Component\Form\Test\TypeTestCase
|
||||
'multiple' => true,
|
||||
'expanded' => true,
|
||||
'choices' => $this->choices,
|
||||
'choices_as_values' => true,
|
||||
));
|
||||
|
||||
$form->submit('foobar');
|
||||
@ -1152,7 +1024,6 @@ class ChoiceTypeTest extends \Symfony\Component\Form\Test\TypeTestCase
|
||||
'multiple' => true,
|
||||
'expanded' => true,
|
||||
'choices' => $this->choices,
|
||||
'choices_as_values' => true,
|
||||
));
|
||||
|
||||
$form->submit(array('a', 'foobar'));
|
||||
@ -1180,7 +1051,6 @@ class ChoiceTypeTest extends \Symfony\Component\Form\Test\TypeTestCase
|
||||
'multiple' => true,
|
||||
'expanded' => true,
|
||||
'choices' => $this->choices,
|
||||
'choices_as_values' => true,
|
||||
));
|
||||
|
||||
$form->submit(array());
|
||||
@ -1209,7 +1079,6 @@ class ChoiceTypeTest extends \Symfony\Component\Form\Test\TypeTestCase
|
||||
'multiple' => true,
|
||||
'expanded' => true,
|
||||
'choices' => array(),
|
||||
'choices_as_values' => true,
|
||||
));
|
||||
|
||||
$form->submit(array());
|
||||
@ -1228,7 +1097,6 @@ class ChoiceTypeTest extends \Symfony\Component\Form\Test\TypeTestCase
|
||||
'Not Empty' => 1,
|
||||
'Not Empty 2' => 2,
|
||||
),
|
||||
'choices_as_values' => true,
|
||||
));
|
||||
|
||||
$form->submit(array('', '2'));
|
||||
@ -1250,7 +1118,6 @@ class ChoiceTypeTest extends \Symfony\Component\Form\Test\TypeTestCase
|
||||
'multiple' => true,
|
||||
'expanded' => true,
|
||||
'choices' => $this->objectChoices,
|
||||
'choices_as_values' => true,
|
||||
'choice_label' => 'name',
|
||||
'choice_value' => 'id',
|
||||
));
|
||||
@ -1272,38 +1139,12 @@ class ChoiceTypeTest extends \Symfony\Component\Form\Test\TypeTestCase
|
||||
$this->assertNull($form[4]->getViewData());
|
||||
}
|
||||
|
||||
public function testSubmitMultipleExpandedNumericChoices()
|
||||
{
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array(
|
||||
'multiple' => true,
|
||||
'expanded' => true,
|
||||
'choices' => $this->numericChoicesFlipped,
|
||||
));
|
||||
|
||||
$form->submit(array('1', '2'));
|
||||
|
||||
$this->assertSame(array(1, 2), $form->getData());
|
||||
$this->assertTrue($form->isSynchronized());
|
||||
|
||||
$this->assertFalse($form[0]->getData());
|
||||
$this->assertTrue($form[1]->getData());
|
||||
$this->assertTrue($form[2]->getData());
|
||||
$this->assertFalse($form[3]->getData());
|
||||
$this->assertFalse($form[4]->getData());
|
||||
$this->assertNull($form[0]->getViewData());
|
||||
$this->assertSame('1', $form[1]->getViewData());
|
||||
$this->assertSame('2', $form[2]->getViewData());
|
||||
$this->assertNull($form[3]->getViewData());
|
||||
$this->assertNull($form[4]->getViewData());
|
||||
}
|
||||
|
||||
public function testSingleSelectedObjectChoices()
|
||||
{
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', $this->objectChoices[3], array(
|
||||
'multiple' => false,
|
||||
'expanded' => false,
|
||||
'choices' => $this->objectChoices,
|
||||
'choices_as_values' => true,
|
||||
'choice_label' => 'name',
|
||||
'choice_value' => 'id',
|
||||
));
|
||||
@ -1321,7 +1162,6 @@ class ChoiceTypeTest extends \Symfony\Component\Form\Test\TypeTestCase
|
||||
'multiple' => true,
|
||||
'expanded' => false,
|
||||
'choices' => $this->objectChoices,
|
||||
'choices_as_values' => true,
|
||||
'choice_label' => 'name',
|
||||
'choice_value' => 'id',
|
||||
));
|
||||
@ -1333,50 +1173,10 @@ class ChoiceTypeTest extends \Symfony\Component\Form\Test\TypeTestCase
|
||||
$this->assertFalse($selectedChecker($view->vars['choices'][1]->value, $view->vars['value']));
|
||||
}
|
||||
|
||||
/**
|
||||
* We need this functionality to create choice fields for Boolean types,
|
||||
* e.g. false => 'No', true => 'Yes'.
|
||||
*
|
||||
* @group legacy
|
||||
*/
|
||||
public function testSetDataSingleNonExpandedAcceptsBoolean()
|
||||
{
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array(
|
||||
'multiple' => false,
|
||||
'expanded' => false,
|
||||
'choices' => $this->numericChoicesFlipped,
|
||||
));
|
||||
|
||||
$form->setData(false);
|
||||
|
||||
$this->assertFalse($form->getData());
|
||||
$this->assertEquals('0', $form->getViewData());
|
||||
$this->assertTrue($form->isSynchronized());
|
||||
}
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
*/
|
||||
public function testSetDataMultipleNonExpandedAcceptsBoolean()
|
||||
{
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array(
|
||||
'multiple' => true,
|
||||
'expanded' => false,
|
||||
'choices' => $this->numericChoicesFlipped,
|
||||
));
|
||||
|
||||
$form->setData(array(false, true));
|
||||
|
||||
$this->assertEquals(array(false, true), $form->getData());
|
||||
$this->assertEquals(array('0', '1'), $form->getViewData());
|
||||
$this->assertTrue($form->isSynchronized());
|
||||
}
|
||||
|
||||
public function testPassRequiredToView()
|
||||
{
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array(
|
||||
'choices' => $this->choices,
|
||||
'choices_as_values' => true,
|
||||
));
|
||||
$view = $form->createView();
|
||||
|
||||
@ -1388,7 +1188,6 @@ class ChoiceTypeTest extends \Symfony\Component\Form\Test\TypeTestCase
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array(
|
||||
'required' => false,
|
||||
'choices' => $this->choices,
|
||||
'choices_as_values' => true,
|
||||
));
|
||||
$view = $form->createView();
|
||||
|
||||
@ -1400,7 +1199,6 @@ class ChoiceTypeTest extends \Symfony\Component\Form\Test\TypeTestCase
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array(
|
||||
'multiple' => true,
|
||||
'choices' => $this->choices,
|
||||
'choices_as_values' => true,
|
||||
));
|
||||
$view = $form->createView();
|
||||
|
||||
@ -1412,7 +1210,6 @@ class ChoiceTypeTest extends \Symfony\Component\Form\Test\TypeTestCase
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array(
|
||||
'expanded' => true,
|
||||
'choices' => $this->choices,
|
||||
'choices_as_values' => true,
|
||||
));
|
||||
$view = $form->createView();
|
||||
|
||||
@ -1423,7 +1220,6 @@ class ChoiceTypeTest extends \Symfony\Component\Form\Test\TypeTestCase
|
||||
{
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array(
|
||||
'choices' => $this->choices,
|
||||
'choices_as_values' => true,
|
||||
));
|
||||
$view = $form->createView();
|
||||
|
||||
@ -1434,7 +1230,6 @@ class ChoiceTypeTest extends \Symfony\Component\Form\Test\TypeTestCase
|
||||
{
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array(
|
||||
'choices' => $this->choices,
|
||||
'choices_as_values' => true,
|
||||
'choice_translation_domain' => true,
|
||||
));
|
||||
$view = $form->createView();
|
||||
@ -1446,7 +1241,6 @@ class ChoiceTypeTest extends \Symfony\Component\Form\Test\TypeTestCase
|
||||
{
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array(
|
||||
'choices' => $this->choices,
|
||||
'choices_as_values' => true,
|
||||
'translation_domain' => 'foo',
|
||||
));
|
||||
$view = $form->createView();
|
||||
@ -1462,7 +1256,6 @@ class ChoiceTypeTest extends \Symfony\Component\Form\Test\TypeTestCase
|
||||
))
|
||||
->add('child', 'Symfony\Component\Form\Extension\Core\Type\ChoiceType', array(
|
||||
'choices' => array(),
|
||||
'choices_as_values' => true,
|
||||
))
|
||||
->getForm()
|
||||
->createView();
|
||||
@ -1476,7 +1269,6 @@ class ChoiceTypeTest extends \Symfony\Component\Form\Test\TypeTestCase
|
||||
'multiple' => false,
|
||||
'required' => true,
|
||||
'choices' => $this->choices,
|
||||
'choices_as_values' => true,
|
||||
));
|
||||
$view = $form->createView();
|
||||
|
||||
@ -1489,7 +1281,6 @@ class ChoiceTypeTest extends \Symfony\Component\Form\Test\TypeTestCase
|
||||
'multiple' => false,
|
||||
'required' => false,
|
||||
'choices' => $this->choices,
|
||||
'choices_as_values' => true,
|
||||
));
|
||||
$view = $form->createView();
|
||||
|
||||
@ -1507,7 +1298,6 @@ class ChoiceTypeTest extends \Symfony\Component\Form\Test\TypeTestCase
|
||||
'required' => $required,
|
||||
'placeholder' => $placeholder,
|
||||
'choices' => $this->choices,
|
||||
'choices_as_values' => true,
|
||||
));
|
||||
$view = $form->createView();
|
||||
|
||||
@ -1526,7 +1316,6 @@ class ChoiceTypeTest extends \Symfony\Component\Form\Test\TypeTestCase
|
||||
'required' => $required,
|
||||
'placeholder' => $placeholder,
|
||||
'choices' => array('A' => 'a', 'Empty' => ''),
|
||||
'choices_as_values' => true,
|
||||
));
|
||||
$view = $form->createView();
|
||||
|
||||
@ -1583,7 +1372,6 @@ class ChoiceTypeTest extends \Symfony\Component\Form\Test\TypeTestCase
|
||||
$choices = array('A' => 'a', 'B' => 'b', 'C' => 'c', 'D' => 'd');
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array(
|
||||
'choices' => $choices,
|
||||
'choices_as_values' => true,
|
||||
));
|
||||
$view = $form->createView();
|
||||
|
||||
@ -1600,7 +1388,6 @@ class ChoiceTypeTest extends \Symfony\Component\Form\Test\TypeTestCase
|
||||
$choices = array('A' => 'a', 'B' => 'b', 'C' => 'c', 'D' => 'd');
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array(
|
||||
'choices' => $choices,
|
||||
'choices_as_values' => true,
|
||||
'preferred_choices' => array('b', 'd'),
|
||||
));
|
||||
$view = $form->createView();
|
||||
@ -1619,7 +1406,6 @@ class ChoiceTypeTest extends \Symfony\Component\Form\Test\TypeTestCase
|
||||
{
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array(
|
||||
'choices' => $this->groupedChoices,
|
||||
'choices_as_values' => true,
|
||||
'preferred_choices' => array('b', 'd'),
|
||||
));
|
||||
$view = $form->createView();
|
||||
@ -1651,7 +1437,6 @@ class ChoiceTypeTest extends \Symfony\Component\Form\Test\TypeTestCase
|
||||
$obj4 = (object) array('value' => 'd', 'label' => 'D');
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array(
|
||||
'choices' => array($obj1, $obj2, $obj3, $obj4),
|
||||
'choices_as_values' => true,
|
||||
'choice_label' => 'label',
|
||||
'choice_value' => 'value',
|
||||
));
|
||||
@ -1671,7 +1456,6 @@ class ChoiceTypeTest extends \Symfony\Component\Form\Test\TypeTestCase
|
||||
'multiple' => true,
|
||||
'expanded' => false,
|
||||
'choices' => $this->choices,
|
||||
'choices_as_values' => true,
|
||||
));
|
||||
$view = $form->createView();
|
||||
|
||||
@ -1683,7 +1467,6 @@ class ChoiceTypeTest extends \Symfony\Component\Form\Test\TypeTestCase
|
||||
{
|
||||
$this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array(
|
||||
'choices' => array(),
|
||||
'choices_as_values' => true,
|
||||
));
|
||||
}
|
||||
|
||||
@ -1696,7 +1479,6 @@ class ChoiceTypeTest extends \Symfony\Component\Form\Test\TypeTestCase
|
||||
|
||||
$form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array(
|
||||
'choices' => array($obj1, $obj2, $obj3, $obj4),
|
||||
'choices_as_values' => true,
|
||||
'choice_label' => 'label',
|
||||
'choice_value' => 'value',
|
||||
// Used to break because "data_class" was inferred, which needs to
|
||||
|
Reference in New Issue
Block a user