diff --git a/src/Symfony/Bridge/Doctrine/Form/ChoiceList/EntityChoiceList.php b/src/Symfony/Bridge/Doctrine/Form/ChoiceList/EntityChoiceList.php
index 34a73d1a03..c1fe98245a 100644
--- a/src/Symfony/Bridge/Doctrine/Form/ChoiceList/EntityChoiceList.php
+++ b/src/Symfony/Bridge/Doctrine/Form/ChoiceList/EntityChoiceList.php
@@ -110,22 +110,6 @@ class EntityChoiceList extends ObjectChoiceList
return parent::getChoices();
}
- /**
- * Returns the labels for the entities
- *
- * @return array
- *
- * @see Symfony\Component\Form\Extension\Core\ChoiceList\ChoiceListInterface
- */
- public function getLabels()
- {
- if (!$this->loaded) {
- $this->load();
- }
-
- return parent::getLabels();
- }
-
/**
* Returns the values for the entities
*
@@ -143,70 +127,37 @@ class EntityChoiceList extends ObjectChoiceList
}
/**
- * Returns the values of the entities that should be presented to the user
- * with priority.
+ * Returns the choice views of the preferred choices as nested array with
+ * the choice groups as top-level keys.
*
* @return array
*
* @see Symfony\Component\Form\Extension\Core\ChoiceList\ChoiceListInterface
*/
- public function getPreferredValues()
+ public function getPreferredViews()
{
if (!$this->loaded) {
$this->load();
}
- return parent::getPreferredValues();
+ return parent::getPreferredViews();
}
/**
- * Returns the values of the entities that should be presented to the user
- * with priority as nested array with the choice groups as top-level keys.
+ * Returns the choice views of the choices that are not preferred as nested
+ * array with the choice groups as top-level keys.
*
* @return array
*
* @see Symfony\Component\Form\Extension\Core\ChoiceList\ChoiceListInterface
*/
- public function getPreferredValueHierarchy()
+ public function getRemainingViews()
{
if (!$this->loaded) {
$this->load();
}
- return parent::getPreferredValueHierarchy();
- }
-
- /**
- * Returns the values of the entities that are not preferred.
- *
- * @return array
- *
- * @see Symfony\Component\Form\Extension\Core\ChoiceList\ChoiceListInterface
- */
- public function getRemainingValues()
- {
- if (!$this->loaded) {
- $this->load();
- }
-
- return parent::getRemainingValues();
- }
-
- /**
- * Returns the values of the entities that are not preferred as nested array
- * with the choice groups as top-level keys.
- *
- * @return array
- *
- * @see Symfony\Component\Form\Extension\Core\ChoiceList\ChoiceListInterface
- */
- public function getRemainingValueHierarchy()
- {
- if (!$this->loaded) {
- $this->load();
- }
-
- return parent::getRemainingValueHierarchy();
+ return parent::getRemainingViews();
}
/**
diff --git a/src/Symfony/Bridge/Twig/Extension/FormExtension.php b/src/Symfony/Bridge/Twig/Extension/FormExtension.php
index 2de31d73ba..cd9f808a45 100644
--- a/src/Symfony/Bridge/Twig/Extension/FormExtension.php
+++ b/src/Symfony/Bridge/Twig/Extension/FormExtension.php
@@ -15,6 +15,7 @@ use Symfony\Bridge\Twig\TokenParser\FormThemeTokenParser;
use Symfony\Component\Form\FormView;
use Symfony\Component\Form\Exception\FormException;
use Symfony\Component\Form\Extension\Csrf\CsrfProvider\CsrfProviderInterface;
+use Symfony\Component\Form\Extension\Core\View\ChoiceView;
use Symfony\Component\Form\Util\FormUtil;
/**
@@ -95,9 +96,9 @@ class FormExtension extends \Twig_Extension
return FormUtil::isChoiceGroup($label);
}
- public function isChoiceSelected(FormView $view, $choice)
+ public function isChoiceSelected(FormView $view, ChoiceView $choice)
{
- return FormUtil::isChoiceSelected($choice, $view->get('value'));
+ return FormUtil::isChoiceSelected($choice->getValue(), $view->get('value'));
}
/**
diff --git a/src/Symfony/Bridge/Twig/Resources/views/Form/form_div_layout.html.twig b/src/Symfony/Bridge/Twig/Resources/views/Form/form_div_layout.html.twig
index 4639a1c408..f07d31f17b 100644
--- a/src/Symfony/Bridge/Twig/Resources/views/Form/form_div_layout.html.twig
+++ b/src/Symfony/Bridge/Twig/Resources/views/Form/form_div_layout.html.twig
@@ -29,12 +29,12 @@
{% for index, choice in options %}
{% if _form_is_choice_group(choice) %}
{% else %}
-
+
{% endif %}
{% endfor %}
{% endspaceless %}
diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/views/Form/choice_options.html.php b/src/Symfony/Bundle/FrameworkBundle/Resources/views/Form/choice_options.html.php
index 12281606d4..66c664fb1d 100644
--- a/src/Symfony/Bundle/FrameworkBundle/Resources/views/Form/choice_options.html.php
+++ b/src/Symfony/Bundle/FrameworkBundle/Resources/views/Form/choice_options.html.php
@@ -1,11 +1,11 @@
$choice): ?>
isChoiceGroup($choice)): ?>
-
+
diff --git a/src/Symfony/Bundle/FrameworkBundle/Templating/Helper/FormHelper.php b/src/Symfony/Bundle/FrameworkBundle/Templating/Helper/FormHelper.php
index 084381aa1e..3fac287cf3 100644
--- a/src/Symfony/Bundle/FrameworkBundle/Templating/Helper/FormHelper.php
+++ b/src/Symfony/Bundle/FrameworkBundle/Templating/Helper/FormHelper.php
@@ -16,6 +16,7 @@ use Symfony\Component\Templating\EngineInterface;
use Symfony\Component\Form\FormView;
use Symfony\Component\Form\Exception\FormException;
use Symfony\Component\Form\Extension\Csrf\CsrfProvider\CsrfProviderInterface;
+use Symfony\Component\Form\Extension\Core\View\ChoiceView;
use Symfony\Component\Form\Util\FormUtil;
/**
@@ -63,9 +64,9 @@ class FormHelper extends Helper
return FormUtil::isChoiceGroup($label);
}
- public function isChoiceSelected(FormView $view, $choice)
+ public function isChoiceSelected(FormView $view, ChoiceView $choice)
{
- return FormUtil::isChoiceSelected($choice, $view->get('value'));
+ return FormUtil::isChoiceSelected($choice->getValue(), $view->get('value'));
}
/**
diff --git a/src/Symfony/Component/Form/Extension/Core/ChoiceList/ChoiceList.php b/src/Symfony/Component/Form/Extension/Core/ChoiceList/ChoiceList.php
index 9605d211ce..5059fb2454 100644
--- a/src/Symfony/Component/Form/Extension/Core/ChoiceList/ChoiceList.php
+++ b/src/Symfony/Component/Form/Extension/Core/ChoiceList/ChoiceList.php
@@ -13,6 +13,7 @@ namespace Symfony\Component\Form\Extension\Core\ChoiceList;
use Symfony\Component\Form\Util\FormUtil;
use Symfony\Component\Form\Exception\UnexpectedTypeException;
+use Symfony\Component\Form\Extension\Core\View\ChoiceView;
/**
* Base class for choice list implementations.
@@ -59,43 +60,20 @@ class ChoiceList implements ChoiceListInterface
private $values = array();
/**
- * The choice labels with the indices of the matching choices as keys.
- *
- * @var array
- */
- private $labels = array();
-
- /**
- * The preferred values as flat array with the indices of the matching
- * choices as keys.
- *
- * @var array
- */
- private $preferredValues = array();
-
- /**
- * The non-preferred values as flat array with the indices of the matching
- * choices as keys.
- *
- * @var array
- */
- private $remainingValues = array();
-
- /**
- * The preferred values as hierarchy containing also the choice groups
+ * The preferred view objects as hierarchy containing also the choice groups
* with the indices of the matching choices as bottom-level keys.
*
* @var array
*/
- private $preferredValueHierarchy = array();
+ private $preferredViews = array();
/**
- * The non-preferred values as hierarchy containing also the choice groups
- * with the indices of the matching choices as bottom-level keys.
+ * The non-preferred view objects as hierarchy containing also the choice
+ * groups with the indices of the matching choices as bottom-level keys.
*
* @var array
*/
- private $remainingValueHierarchy = array();
+ private $remainingViews = array();
/**
* The strategy used for creating choice indices.
@@ -153,15 +131,12 @@ class ChoiceList implements ChoiceListInterface
{
$this->choices = array();
$this->values = array();
- $this->labels = array();
- $this->preferredValues = array();
- $this->preferredValueHierarchy = array();
- $this->remainingValues = array();
- $this->remainingValueHierarchy = array();
+ $this->preferredViews = array();
+ $this->remainingViews = array();
$this->addChoices(
- $this->preferredValueHierarchy,
- $this->remainingValueHierarchy,
+ $this->preferredViews,
+ $this->remainingViews,
$choices,
$labels,
$preferredChoices
@@ -180,18 +155,6 @@ class ChoiceList implements ChoiceListInterface
return $this->choices;
}
- /**
- * Returns the labels for the choices
- *
- * @return array
- *
- * @see Symfony\Component\Form\Extension\Core\ChoiceList\ChoiceListInterface
- */
- public function getLabels()
- {
- return $this->labels;
- }
-
/**
* Returns the values for the choices
*
@@ -205,56 +168,29 @@ class ChoiceList implements ChoiceListInterface
}
/**
- * Returns the values of the choices that should be presented to the user
- * with priority.
+ * Returns the choice views of the preferred choices as nested array with
+ * the choice groups as top-level keys.
*
* @return array
*
* @see Symfony\Component\Form\Extension\Core\ChoiceList\ChoiceListInterface
*/
- public function getPreferredValues()
+ public function getPreferredViews()
{
- return $this->preferredValues;
+ return $this->preferredViews;
}
/**
- * Returns the values of the choices that should be presented to the user
- * with priority as nested array with the choice groups as top-level keys.
+ * Returns the choice views of the choices that are not preferred as nested
+ * array with the choice groups as top-level keys.
*
* @return array
*
* @see Symfony\Component\Form\Extension\Core\ChoiceList\ChoiceListInterface
*/
- public function getPreferredValueHierarchy()
+ public function getRemainingViews()
{
- return $this->preferredValueHierarchy;
- }
-
- /**
- * Returns the values of the choices that are not preferred.
- *
- * @return array
- *
- * @see Symfony\Component\Form\Extension\Core\ChoiceList\ChoiceListInterface
- */
- public function getRemainingValues()
- {
- return $this->remainingValues;
- }
-
- /**
- * Returns the values of the choices that are not preferred as nested array
- * with the choice groups as top-level keys.
- *
- * @return array A nested array containing the values with the corresponding
- * choice indices as keys on the lower levels and the choice
- * group names in the keys of the topmost level.
- *
- * @see getPreferredValueHierarchy
- */
- public function getRemainingValueHierarchy()
- {
- return $this->remainingValueHierarchy;
+ return $this->remainingViews;
}
/**
@@ -395,9 +331,9 @@ class ChoiceList implements ChoiceListInterface
* Recursively adds the given choices to the list.
*
* @param array $bucketForPreferred The bucket where to store the preferred
- * values.
+ * view objects.
* @param array $bucketForRemaining The bucket where to store the
- * non-preferred values.
+ * non-preferred view objects.
* @param array $choices The list of choices.
* @param array $labels The labels corresponding to the choices.
* @param array $preferredChoices The preferred choices.
@@ -447,9 +383,9 @@ class ChoiceList implements ChoiceListInterface
*
* @param string $group The name of the group.
* @param array $bucketForPreferred The bucket where to store the preferred
- * values.
+ * view objects.
* @param array $bucketForRemaining The bucket where to store the
- * non-preferred values.
+ * non-preferred view objects.
* @param array $choices The list of choices in the group.
* @param array $labels The labels corresponding to the choices in the group.
* @param array $preferredChoices The preferred choices.
@@ -482,9 +418,9 @@ class ChoiceList implements ChoiceListInterface
* Adds a new choice.
*
* @param array $bucketForPreferred The bucket where to store the preferred
- * values.
+ * view objects.
* @param array $bucketForRemaining The bucket where to store the
- * non-preferred values.
+ * non-preferred view objects.
* @param mixed $choice The choice to add.
* @param string $label The label for the choice.
* @param array $preferredChoices The preferred choices.
@@ -495,17 +431,15 @@ class ChoiceList implements ChoiceListInterface
// Always store values as strings to facilitate comparisons
$value = $this->fixValue($this->createValue($choice));
+ $view = new ChoiceView($value, $label);
$this->choices[$index] = $this->fixChoice($choice);
- $this->labels[$index] = $label;
$this->values[$index] = $value;
if ($this->isPreferred($choice, $preferredChoices)) {
- $bucketForPreferred[$index] = $value;
- $this->preferredValues[$index] = $value;
+ $bucketForPreferred[$index] = $view;
} else {
- $bucketForRemaining[$index] = $value;
- $this->remainingValues[$index] = $value;
+ $bucketForRemaining[$index] = $view;
}
}
diff --git a/src/Symfony/Component/Form/Extension/Core/ChoiceList/ChoiceListInterface.php b/src/Symfony/Component/Form/Extension/Core/ChoiceList/ChoiceListInterface.php
index 85df8d8d88..206727dde3 100644
--- a/src/Symfony/Component/Form/Extension/Core/ChoiceList/ChoiceListInterface.php
+++ b/src/Symfony/Component/Form/Extension/Core/ChoiceList/ChoiceListInterface.php
@@ -40,13 +40,6 @@ interface ChoiceListInterface
*/
function getChoices();
- /**
- * Returns the labels for the choices
- *
- * @return array The labels with the corresponding choice indices as keys.
- */
- function getLabels();
-
/**
* Returns the values for the choices
*
@@ -55,43 +48,26 @@ interface ChoiceListInterface
function getValues();
/**
- * Returns the values of the choices that should be presented to the user
- * with priority.
+ * Returns the choice views of the preferred choices as nested array with
+ * the choice groups as top-level keys.
*
- * @return array The values with the corresponding choice indices as keys.
+ * @return array A nested array containing the views with the corresponding
+ * choice indices as keys on the lowest levels and the choice
+ * group names in the keys of the higher levels.
*/
- function getPreferredValues();
+ function getPreferredViews();
/**
- * Returns the values of the choices that should be presented to the user
- * with priority as nested array with the choice groups as top-level keys.
+ * Returns the choice views of the choices that are not preferred as nested
+ * array with the choice groups as top-level keys.
*
- * @return array A nested array containing the values with the corresponding
- * choice indices as keys on the lower levels and the choice
- * group names in the keys of the topmost level.
- */
- function getPreferredValueHierarchy();
-
- /**
- * Returns the values of the choices that are not preferred.
- *
- * @return array The values with the corresponding choice indices as keys.
+ * @return array A nested array containing the views with the corresponding
+ * choice indices as keys on the lowest levels and the choice
+ * group names in the keys of the higher levels.
*
* @see getPreferredValues
*/
- function getRemainingValues();
-
- /**
- * Returns the values of the choices that are not preferred as nested array
- * with the choice groups as top-level keys.
- *
- * @return array A nested array containing the values with the corresponding
- * choice indices as keys on the lower levels and the choice
- * group names in the keys of the topmost level.
- *
- * @see getPreferredValueHierarchy
- */
- function getRemainingValueHierarchy();
+ function getRemainingViews();
/**
* Returns the choices corresponding to the given values.
diff --git a/src/Symfony/Component/Form/Extension/Core/Type/ChoiceType.php b/src/Symfony/Component/Form/Extension/Core/Type/ChoiceType.php
index 378a795e6b..358c4317b6 100644
--- a/src/Symfony/Component/Form/Extension/Core/Type/ChoiceType.php
+++ b/src/Symfony/Component/Form/Extension/Core/Type/ChoiceType.php
@@ -52,28 +52,8 @@ class ChoiceType extends AbstractType
}
if ($options['expanded']) {
- // Load choices already if expanded
- $values = $options['choice_list']->getValues();
- $labels = $options['choice_list']->getLabels();
-
- foreach ($values as $i => $value) {
- if ($options['multiple']) {
- $builder->add((string) $i, 'checkbox', array(
- 'value' => $value,
- 'label' => $labels[$i],
- // The user can check 0 or more checkboxes. If required
- // is true, he is required to check all of them.
- 'required' => false,
- 'translation_domain' => $options['translation_domain'],
- ));
- } else {
- $builder->add((string) $i, 'radio', array(
- 'value' => $value,
- 'label' => $labels[$i],
- 'translation_domain' => $options['translation_domain'],
- ));
- }
- }
+ $this->addSubFields($builder, $options['choice_list']->getPreferredViews(), $options);
+ $this->addSubFields($builder, $options['choice_list']->getRemainingViews(), $options);
}
// empty value
@@ -129,9 +109,8 @@ class ChoiceType extends AbstractType
$view
->set('multiple', $form->getAttribute('multiple'))
->set('expanded', $form->getAttribute('expanded'))
- ->set('preferred_choices', $choiceList->getPreferredValueHierarchy())
- ->set('choices', $choiceList->getRemainingValueHierarchy())
- ->set('choice_labels', $choiceList->getLabels())
+ ->set('preferred_choices', $choiceList->getPreferredViews())
+ ->set('choices', $choiceList->getRemainingViews())
->set('separator', '-------------------')
->set('empty_value', $form->getAttribute('empty_value'))
;
@@ -181,4 +160,36 @@ class ChoiceType extends AbstractType
{
return 'choice';
}
+
+ /**
+ * Adds the sub fields for an expanded choice field.
+ *
+ * @param FormBuilder $builder The form builder.
+ * @param array $choiceViews The choice view objects.
+ * @param array $options The build options.
+ */
+ private function addSubFields(FormBuilder $builder, array $choiceViews, array $options)
+ {
+ foreach ($choiceViews as $i => $choiceView) {
+ if (is_array($choiceView)) {
+ // Flatten groups
+ $this->addSubFields($builder, $choiceView, $options);
+ } elseif ($options['multiple']) {
+ $builder->add((string) $i, 'checkbox', array(
+ 'value' => $choiceView->getValue(),
+ 'label' => $choiceView->getLabel(),
+ // The user can check 0 or more checkboxes. If required
+ // is true, he is required to check all of them.
+ 'required' => false,
+ 'translation_domain' => $options['translation_domain'],
+ ));
+ } else {
+ $builder->add((string) $i, 'radio', array(
+ 'value' => $choiceView->getValue(),
+ 'label' => $choiceView->getLabel(),
+ 'translation_domain' => $options['translation_domain'],
+ ));
+ }
+ }
+ }
}
diff --git a/src/Symfony/Component/Form/Extension/Core/View/ChoiceView.php b/src/Symfony/Component/Form/Extension/Core/View/ChoiceView.php
new file mode 100644
index 0000000000..4e04247900
--- /dev/null
+++ b/src/Symfony/Component/Form/Extension/Core/View/ChoiceView.php
@@ -0,0 +1,66 @@
+
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Symfony\Component\Form\Extension\Core\View;
+
+/**
+ * Represents a choice in templates.
+ *
+ * @author Bernhard Schussek
+ */
+class ChoiceView
+{
+ /**
+ * The view representation of the choice.
+ *
+ * @var string
+ */
+ private $value;
+
+ /**
+ * The label displayed to humans.
+ *
+ * @var string
+ */
+ private $label;
+
+ /**
+ * Creates a new ChoiceView.
+ *
+ * @param string $value The view representation of the choice.
+ * @param string $label The label displayed to humans.
+ */
+ public function __construct($value, $label)
+ {
+ $this->value = $value;
+ $this->label = $label;
+ }
+
+ /**
+ * Returns the choice value.
+ *
+ * @return string The view representation of the choice.
+ */
+ public function getValue()
+ {
+ return $this->value;
+ }
+
+ /**
+ * Returns the choice label.
+ *
+ * @return string The label displayed to humans.
+ */
+ public function getLabel()
+ {
+ return $this->label;
+ }
+}
\ No newline at end of file
diff --git a/tests/Symfony/Tests/Bridge/Doctrine/Form/ChoiceList/EntityChoiceListTest.php b/tests/Symfony/Tests/Bridge/Doctrine/Form/ChoiceList/EntityChoiceListTest.php
index 66e2121b7f..2dc3e698ad 100644
--- a/tests/Symfony/Tests/Bridge/Doctrine/Form/ChoiceList/EntityChoiceListTest.php
+++ b/tests/Symfony/Tests/Bridge/Doctrine/Form/ChoiceList/EntityChoiceListTest.php
@@ -19,6 +19,7 @@ use Symfony\Tests\Bridge\Doctrine\DoctrineOrmTestCase;
use Symfony\Tests\Bridge\Doctrine\Fixtures\ItemGroupEntity;
use Symfony\Tests\Bridge\Doctrine\Fixtures\SingleIdentEntity;
use Symfony\Bridge\Doctrine\Form\ChoiceList\EntityChoiceList;
+use Symfony\Component\Form\Extension\Core\View\ChoiceView;
class EntityChoiceListTest extends DoctrineOrmTestCase
{
@@ -133,10 +134,10 @@ class EntityChoiceListTest extends DoctrineOrmTestCase
);
$this->assertSame(array(1 => $entity1, 2 => $entity2), $choiceList->getChoices());
- $this->assertSame(array(
- 'group1' => array(1 => '1'),
- 'group2' => array(2 => '2')
- ), $choiceList->getRemainingValueHierarchy());
+ $this->assertEquals(array(
+ 'group1' => array(1 => new ChoiceView('1', 'Foo')),
+ 'group2' => array(2 => new ChoiceView('2', 'Bar'))
+ ), $choiceList->getRemainingViews());
}
public function testGroupBySupportsString()
@@ -167,10 +168,10 @@ class EntityChoiceListTest extends DoctrineOrmTestCase
$this->assertEquals(array(1 => $item1, 2 => $item2, 3 => $item3, 4 => $item4), $choiceList->getChoices());
$this->assertEquals(array(
- 'Group1' => array(1 => '1', 2 => '2'),
- 'Group2' => array(3 => '3'),
- 4 => '4'
- ), $choiceList->getRemainingValueHierarchy());
+ 'Group1' => array(1 => new ChoiceView('1', 'Foo'), 2 => new ChoiceView('2', 'Bar')),
+ 'Group2' => array(3 => new ChoiceView('3', 'Baz')),
+ 4 => new ChoiceView('4', 'Boo!')
+ ), $choiceList->getRemainingViews());
}
public function testGroupByInvalidPropertyPathReturnsFlatChoices()
diff --git a/tests/Symfony/Tests/Bridge/Doctrine/Form/Type/EntityTypeTest.php b/tests/Symfony/Tests/Bridge/Doctrine/Form/Type/EntityTypeTest.php
index 5ff457f879..8c4f65abb1 100644
--- a/tests/Symfony/Tests/Bridge/Doctrine/Form/Type/EntityTypeTest.php
+++ b/tests/Symfony/Tests/Bridge/Doctrine/Form/Type/EntityTypeTest.php
@@ -29,6 +29,7 @@ use Symfony\Tests\Bridge\Doctrine\Fixtures\CompositeStringIdentEntity;
use Symfony\Bridge\Doctrine\Form\DoctrineOrmExtension;
use Doctrine\ORM\Tools\SchemaTool;
use Doctrine\Common\Collections\ArrayCollection;
+use Symfony\Component\Form\Extension\Core\View\ChoiceView;
class EntityTypeTest extends TypeTestCase
{
@@ -109,8 +110,7 @@ class EntityTypeTest extends TypeTestCase
'property' => 'name'
));
- $this->assertSame(array(1 => '1', 2 => '2'), $field->createView()->get('choices'));
- $this->assertSame(array(1 => 'Foo', 2 => 'Bar'), $field->createView()->get('choice_labels'));
+ $this->assertEquals(array(1 => new ChoiceView('1', 'Foo'), 2 => new ChoiceView('2', 'Bar')), $field->createView()->get('choices'));
}
public function testSetDataToUninitializedEntityWithNonRequiredToString()
@@ -126,8 +126,7 @@ class EntityTypeTest extends TypeTestCase
'required' => false,
));
- $this->assertSame(array(1 => '1', 2 => '2'), $field->createView()->get('choices'));
- $this->assertSame(array(1 => 'Foo', 2 => 'Bar'), $field->createView()->get('choice_labels'));
+ $this->assertEquals(array(1 => new ChoiceView('1', 'Foo'), 2 => new ChoiceView('2', 'Bar')), $field->createView()->get('choices'));
}
public function testSetDataToUninitializedEntityWithNonRequiredQueryBuilder()
@@ -146,8 +145,7 @@ class EntityTypeTest extends TypeTestCase
'query_builder' => $qb
));
- $this->assertSame(array(1 => '1', 2 => '2'), $field->createView()->get('choices'));
- $this->assertSame(array(1 => 'Foo', 2 => 'Bar'), $field->createView()->get('choice_labels'));
+ $this->assertEquals(array(1 => new ChoiceView('1', 'Foo'), 2 => new ChoiceView('2', 'Bar')), $field->createView()->get('choices'));
}
/**
@@ -491,8 +489,7 @@ class EntityTypeTest extends TypeTestCase
$field->bind('2');
- $this->assertSame(array(1 => '1', 2 => '2'), $field->createView()->get('choices'));
- $this->assertSame(array(1 => 'Foo', 2 => 'Bar'), $field->createView()->get('choice_labels'));
+ $this->assertEquals(array(1 => new ChoiceView('1', 'Foo'), 2 => new ChoiceView('2', 'Bar')), $field->createView()->get('choices'));
$this->assertTrue($field->isSynchronized());
$this->assertSame($entity2, $field->getData());
$this->assertSame('2', $field->getClientData());
@@ -518,12 +515,11 @@ class EntityTypeTest extends TypeTestCase
$field->bind('2');
$this->assertSame('2', $field->getClientData());
- $this->assertSame(array(
- 'Group1' => array(1 => '1', 2 => '2'),
- 'Group2' => array(3 => '3'),
- '4' => '4'
+ $this->assertEquals(array(
+ 'Group1' => array(1 => new ChoiceView('1', 'Foo'), 2 => new ChoiceView('2', 'Bar')),
+ 'Group2' => array(3 => new ChoiceView('3', 'Baz')),
+ '4' => new ChoiceView('4', 'Boo!')
), $field->createView()->get('choices'));
- $this->assertSame(array(1 => 'Foo', 2 => 'Bar', 3 => 'Baz', 4 => 'Boo!'), $field->createView()->get('choice_labels'));
}
public function testDisallowChoicesThatAreNotIncluded_choicesSingleIdentifier()
diff --git a/tests/Symfony/Tests/Component/Form/Extension/Core/ChoiceList/ChoiceListTest.php b/tests/Symfony/Tests/Component/Form/Extension/Core/ChoiceList/ChoiceListTest.php
index 9dc537a6ee..db37a57868 100644
--- a/tests/Symfony/Tests/Component/Form/Extension/Core/ChoiceList/ChoiceListTest.php
+++ b/tests/Symfony/Tests/Component/Form/Extension/Core/ChoiceList/ChoiceListTest.php
@@ -12,6 +12,7 @@
namespace Symfony\Tests\Component\Form\Extension\Core\ChoiceList;
use Symfony\Component\Form\Extension\Core\ChoiceList\ChoiceList;
+use Symfony\Component\Form\Extension\Core\View\ChoiceView;
class ChoiceListTest extends \PHPUnit_Framework_TestCase
{
@@ -67,29 +68,23 @@ class ChoiceListTest extends \PHPUnit_Framework_TestCase
);
$this->assertSame(array($this->obj1, $this->obj2, $this->obj3, $this->obj4), $this->list->getChoices());
- $this->assertSame(array('A', 'B', 'C', 'D'), $this->list->getLabels());
-
- $this->assertSame(array(1 => '1'), $this->list->getPreferredValues());
- $this->assertSame(array(1 => '1'), $this->list->getPreferredValueHierarchy());
- $this->assertSame(array(0 => '0', 2 => '2', 3 => '3'), $this->list->getRemainingValues());
- $this->assertSame(array(0 => '0', 2 => '2', 3 => '3'), $this->list->getRemainingValueHierarchy());
+ $this->assertSame(array('0', '1', '2', '3'), $this->list->getValues());
+ $this->assertEquals(array(1 => new ChoiceView('1', 'B')), $this->list->getPreferredViews());
+ $this->assertEquals(array(0 => new ChoiceView('0', 'A'), 2 => new ChoiceView('2', 'C'), 3 => new ChoiceView('3', 'D')), $this->list->getRemainingViews());
}
public function testInitNestedArray()
{
$this->assertSame(array($this->obj1, $this->obj2, $this->obj3, $this->obj4), $this->list->getChoices());
- $this->assertSame(array('A', 'B', 'C', 'D'), $this->list->getLabels());
-
- $this->assertSame(array(1 => '1', 2 => '2'), $this->list->getPreferredValues());
- $this->assertSame(array(
- 'Group 1' => array(1 => '1'),
- 'Group 2' => array(2 => '2')
- ), $this->list->getPreferredValueHierarchy());
- $this->assertSame(array(0 => '0', 3 => '3'), $this->list->getRemainingValues());
- $this->assertSame(array(
- 'Group 1' => array(0 => '0'),
- 'Group 2' => array(3 => '3')
- ), $this->list->getRemainingValueHierarchy());
+ $this->assertSame(array('0', '1', '2', '3'), $this->list->getValues());
+ $this->assertEquals(array(
+ 'Group 1' => array(1 => new ChoiceView('1', 'B')),
+ 'Group 2' => array(2 => new ChoiceView('2', 'C'))
+ ), $this->list->getPreferredViews());
+ $this->assertEquals(array(
+ 'Group 1' => array(0 => new ChoiceView('0', 'A')),
+ 'Group 2' => array(3 => new ChoiceView('3', 'D'))
+ ), $this->list->getRemainingViews());
}
public function testGetIndicesForChoices()
diff --git a/tests/Symfony/Tests/Component/Form/Extension/Core/ChoiceList/ObjectChoiceListTest.php b/tests/Symfony/Tests/Component/Form/Extension/Core/ChoiceList/ObjectChoiceListTest.php
index 8e807a86b0..5635cab57c 100644
--- a/tests/Symfony/Tests/Component/Form/Extension/Core/ChoiceList/ObjectChoiceListTest.php
+++ b/tests/Symfony/Tests/Component/Form/Extension/Core/ChoiceList/ObjectChoiceListTest.php
@@ -12,6 +12,7 @@
namespace Symfony\Tests\Component\Form\Extension\Core\ChoiceList;
use Symfony\Component\Form\Extension\Core\ChoiceList\ObjectChoiceList;
+use Symfony\Component\Form\Extension\Core\View\ChoiceView;
class ObjectChoiceListTest_EntityWithToString
{
@@ -79,29 +80,23 @@ class ObjectChoiceListTest extends \PHPUnit_Framework_TestCase
);
$this->assertSame(array($this->obj1, $this->obj2, $this->obj3, $this->obj4), $this->list->getChoices());
- $this->assertSame(array('A', 'B', 'C', 'D'), $this->list->getLabels());
-
- $this->assertSame(array(1 => '1'), $this->list->getPreferredValues());
- $this->assertSame(array(1 => '1'), $this->list->getPreferredValueHierarchy());
- $this->assertSame(array(0 => '0', 2 => '2', 3 => '3'), $this->list->getRemainingValues());
- $this->assertSame(array(0 => '0', 2 => '2', 3 => '3'), $this->list->getRemainingValueHierarchy());
+ $this->assertSame(array('0', '1', '2', '3'), $this->list->getValues());
+ $this->assertEquals(array(1 => new ChoiceView('1', 'B')), $this->list->getPreferredViews());
+ $this->assertEquals(array(0 => new ChoiceView('0', 'A'), 2 => new ChoiceView('2', 'C'), 3 => new ChoiceView('3', 'D')), $this->list->getRemainingViews());
}
public function testInitNestedArray()
{
$this->assertSame(array($this->obj1, $this->obj2, $this->obj3, $this->obj4), $this->list->getChoices());
- $this->assertSame(array('A', 'B', 'C', 'D'), $this->list->getLabels());
-
- $this->assertSame(array(1 => '1', 2 => '2'), $this->list->getPreferredValues());
- $this->assertSame(array(
- 'Group 1' => array(1 => '1'),
- 'Group 2' => array(2 => '2')
- ), $this->list->getPreferredValueHierarchy());
- $this->assertSame(array(0 => '0', 3 => '3'), $this->list->getRemainingValues());
- $this->assertSame(array(
- 'Group 1' => array(0 => '0'),
- 'Group 2' => array(3 => '3')
- ), $this->list->getRemainingValueHierarchy());
+ $this->assertSame(array('0', '1', '2', '3'), $this->list->getValues());
+ $this->assertEquals(array(
+ 'Group 1' => array(1 => new ChoiceView('1', 'B')),
+ 'Group 2' => array(2 => new ChoiceView('2', 'C'))
+ ), $this->list->getPreferredViews());
+ $this->assertEquals(array(
+ 'Group 1' => array(0 => new ChoiceView('0', 'A')),
+ 'Group 2' => array(3 => new ChoiceView('3', 'D'))
+ ), $this->list->getRemainingViews());
}
public function testInitArrayWithGroupPath()
@@ -126,20 +121,17 @@ class ObjectChoiceListTest extends \PHPUnit_Framework_TestCase
);
$this->assertSame(array($this->obj1, $this->obj2, $this->obj3, $this->obj4, $obj5, $obj6), $this->list->getChoices());
- $this->assertSame(array('A', 'B', 'C', 'D', 'E', 'F'), $this->list->getLabels());
-
- $this->assertSame(array(1 => '1', 2 => '2'), $this->list->getPreferredValues());
- $this->assertSame(array(
- 'Group 1' => array(1 => '1'),
- 'Group 2' => array(2 => '2')
- ), $this->list->getPreferredValueHierarchy());
- $this->assertSame(array(0 => '0', 3 => '3', 4 => '4', 5 => '5'), $this->list->getRemainingValues());
- $this->assertSame(array(
- 'Group 1' => array(0 => '0'),
- 'Group 2' => array(3 => '3'),
- 4 => '4',
- 5 => '5',
- ), $this->list->getRemainingValueHierarchy());
+ $this->assertSame(array('0', '1', '2', '3', '4', '5'), $this->list->getValues());
+ $this->assertEquals(array(
+ 'Group 1' => array(1 => new ChoiceView('1', 'B')),
+ 'Group 2' => array(2 => new ChoiceView('2', 'C'))
+ ), $this->list->getPreferredViews());
+ $this->assertEquals(array(
+ 'Group 1' => array(0 => new ChoiceView('0', 'A')),
+ 'Group 2' => array(3 => new ChoiceView('3', 'D')),
+ 4 => new ChoiceView('4', 'E'),
+ 5 => new ChoiceView('5', 'F'),
+ ), $this->list->getRemainingViews());
}
/**
@@ -179,14 +171,9 @@ class ObjectChoiceListTest extends \PHPUnit_Framework_TestCase
);
$this->assertSame(array($this->obj1, $this->obj2, $this->obj3, $this->obj4), $this->list->getChoices());
- $this->assertSame(array('A', 'B', 'C', 'D'), $this->list->getLabels());
-
- // Values are always converted to strings to avoid problems with
- // comparisons
- $this->assertSame(array(1 => '20', 2 => '30'), $this->list->getPreferredValues());
- $this->assertSame(array(1 => '20', 2 => '30'), $this->list->getPreferredValueHierarchy());
- $this->assertSame(array(0 => '10', 3 => '40'), $this->list->getRemainingValues());
- $this->assertSame(array(0 => '10', 3 => '40'), $this->list->getRemainingValueHierarchy());
+ $this->assertSame(array('10', '20', '30', '40'), $this->list->getValues());
+ $this->assertEquals(array(1 => new ChoiceView('20', 'B'), 2 => new ChoiceView('30', 'C')), $this->list->getPreferredViews());
+ $this->assertEquals(array(0 => new ChoiceView('10', 'A'), 3 => new ChoiceView('40', 'D')), $this->list->getRemainingViews());
}
public function testInitArrayWithIndexPath()
@@ -206,12 +193,9 @@ class ObjectChoiceListTest extends \PHPUnit_Framework_TestCase
);
$this->assertSame(array(10 => $this->obj1, 20 => $this->obj2, 30 => $this->obj3, 40 => $this->obj4), $this->list->getChoices());
- $this->assertSame(array(10 => 'A', 20 => 'B', 30 => 'C', 40 => 'D'), $this->list->getLabels());
-
- $this->assertSame(array(20 => '1', 30 => '2'), $this->list->getPreferredValues());
- $this->assertSame(array(20 => '1', 30 => '2'), $this->list->getPreferredValueHierarchy());
- $this->assertSame(array(10 => '0', 40 => '3'), $this->list->getRemainingValues());
- $this->assertSame(array(10 => '0', 40 => '3'), $this->list->getRemainingValueHierarchy());
+ $this->assertSame(array(10 => '0', 20 => '1', 30 => '2', 40 => '3'), $this->list->getValues());
+ $this->assertEquals(array(20 => new ChoiceView('1', 'B'), 30 => new ChoiceView('2', 'C')), $this->list->getPreferredViews());
+ $this->assertEquals(array(10 => new ChoiceView('0', 'A'), 40 => new ChoiceView('3', 'D')), $this->list->getRemainingViews());
}
public function testInitArrayUsesToString()
@@ -226,7 +210,8 @@ class ObjectChoiceListTest extends \PHPUnit_Framework_TestCase
);
$this->assertSame(array($this->obj1, $this->obj2, $this->obj3, $this->obj4), $this->list->getChoices());
- $this->assertSame(array('A', 'B', 'C', 'D'), $this->list->getLabels());
+ $this->assertSame(array('0', '1', '2', '3'), $this->list->getValues());
+ $this->assertEquals(array(0 => new ChoiceView('0', 'A'), 1 => new ChoiceView('1', 'B'), 2 => new ChoiceView('2', 'C'), 3 => new ChoiceView('3', 'D')), $this->list->getRemainingViews());
}
/**
@@ -239,11 +224,8 @@ class ObjectChoiceListTest extends \PHPUnit_Framework_TestCase
$this->obj3 = (object) array('name' => 'C');
$this->obj4 = new ObjectChoiceListTest_EntityWithToString('D');
- $this->list = new ObjectChoiceList(
+ new ObjectChoiceList(
array($this->obj1, $this->obj2, $this->obj3, $this->obj4)
);
-
- $this->assertSame(array($this->obj1, $this->obj2, $this->obj3, $this->obj4), $this->list->getChoices());
- $this->assertSame(array('A', 'B', 'C', 'D'), $this->list->getLabels());
}
}
diff --git a/tests/Symfony/Tests/Component/Form/Extension/Core/ChoiceList/SimpleChoiceListTest.php b/tests/Symfony/Tests/Component/Form/Extension/Core/ChoiceList/SimpleChoiceListTest.php
index 508695cfda..cb6afcd815 100644
--- a/tests/Symfony/Tests/Component/Form/Extension/Core/ChoiceList/SimpleChoiceListTest.php
+++ b/tests/Symfony/Tests/Component/Form/Extension/Core/ChoiceList/SimpleChoiceListTest.php
@@ -12,8 +12,8 @@
namespace Symfony\Tests\Component\Form\Extension\Core\ChoiceList;
use Symfony\Component\Form\Extension\Core\ChoiceList\ChoiceList;
-
use Symfony\Component\Form\Extension\Core\ChoiceList\SimpleChoiceList;
+use Symfony\Component\Form\Extension\Core\View\ChoiceView;
class SimpleChoiceListTest extends \PHPUnit_Framework_TestCase
{
@@ -54,12 +54,9 @@ class SimpleChoiceListTest extends \PHPUnit_Framework_TestCase
$this->list = new SimpleChoiceList($choices, array('b'), ChoiceList::GENERATE, ChoiceList::GENERATE);
$this->assertSame(array(0 => 'a', 1 => 'b', 2 => 'c'), $this->list->getChoices());
- $this->assertSame(array(0 => 'A', 1 => 'B', 2 => 'C'), $this->list->getLabels());
-
- $this->assertSame(array(1 => '1'), $this->list->getPreferredValues());
- $this->assertSame(array(1 => '1'), $this->list->getPreferredValueHierarchy());
- $this->assertSame(array(0 => '0', 2 => '2'), $this->list->getRemainingValues());
- $this->assertSame(array(0 => '0', 2 => '2'), $this->list->getRemainingValueHierarchy());
+ $this->assertSame(array(0 => '0', 1 => '1', 2 => '2'), $this->list->getValues());
+ $this->assertEquals(array(1 => new ChoiceView('1', 'B')), $this->list->getPreferredViews());
+ $this->assertEquals(array(0 => new ChoiceView('0', 'A'), 2 => new ChoiceView('2', 'C')), $this->list->getRemainingViews());
}
public function testInitArrayValueCopyChoice()
@@ -68,12 +65,9 @@ class SimpleChoiceListTest extends \PHPUnit_Framework_TestCase
$this->list = new SimpleChoiceList($choices, array('b'), ChoiceList::COPY_CHOICE, ChoiceList::GENERATE);
$this->assertSame(array(0 => 'a', 1 => 'b', 2 => 'c'), $this->list->getChoices());
- $this->assertSame(array(0 => 'A', 1 => 'B', 2 => 'C'), $this->list->getLabels());
-
- $this->assertSame(array(1 => 'b'), $this->list->getPreferredValues());
- $this->assertSame(array(1 => 'b'), $this->list->getPreferredValueHierarchy());
- $this->assertSame(array(0 => 'a', 2 => 'c'), $this->list->getRemainingValues());
- $this->assertSame(array(0 => 'a', 2 => 'c'), $this->list->getRemainingValueHierarchy());
+ $this->assertSame(array(0 => 'a', 1 => 'b', 2 => 'c'), $this->list->getValues());
+ $this->assertEquals(array(1 => new ChoiceView('b', 'B')), $this->list->getPreferredViews());
+ $this->assertEquals(array(0 => new ChoiceView('a', 'A'), 2 => new ChoiceView('c', 'C')), $this->list->getRemainingViews());
}
public function testInitArrayIndexCopyChoice()
@@ -82,29 +76,23 @@ class SimpleChoiceListTest extends \PHPUnit_Framework_TestCase
$this->list = new SimpleChoiceList($choices, array('b'), ChoiceList::GENERATE, ChoiceList::COPY_CHOICE);
$this->assertSame(array('a' => 'a', 'b' => 'b', 'c' => 'c'), $this->list->getChoices());
- $this->assertSame(array('a' => 'A', 'b' => 'B', 'c' => 'C'), $this->list->getLabels());
-
- $this->assertSame(array('b' => '1'), $this->list->getPreferredValues());
- $this->assertSame(array('b' => '1'), $this->list->getPreferredValueHierarchy());
- $this->assertSame(array('a' => '0', 'c' => '2'), $this->list->getRemainingValues());
- $this->assertSame(array('a' => '0', 'c' => '2'), $this->list->getRemainingValueHierarchy());
+ $this->assertSame(array('a' => '0', 'b' => '1', 'c' => '2'), $this->list->getValues());
+ $this->assertEquals(array('b' => new ChoiceView('1', 'B')), $this->list->getPreferredViews());
+ $this->assertEquals(array('a' => new ChoiceView('0', 'A'), 'c' => new ChoiceView('2', 'C')), $this->list->getRemainingViews());
}
public function testInitNestedArray()
{
$this->assertSame(array(0 => 'a', 1 => 'b', 2 => 'c', 3 => 'd'), $this->list->getChoices());
- $this->assertSame(array(0 => 'A', 1 => 'B', 2 => 'C', 3 => 'D'), $this->list->getLabels());
-
- $this->assertSame(array(1 => '1', 2 => '2'), $this->list->getPreferredValues());
- $this->assertSame(array(
- 'Group 1' => array(1 => '1'),
- 'Group 2' => array(2 => '2')
- ), $this->list->getPreferredValueHierarchy());
- $this->assertSame(array(0 => '0', 3 => '3'), $this->list->getRemainingValues());
- $this->assertSame(array(
- 'Group 1' => array(0 => '0'),
- 'Group 2' => array(3 => '3')
- ), $this->list->getRemainingValueHierarchy());
+ $this->assertSame(array(0 => '0', 1 => '1', 2 => '2', 3 => '3'), $this->list->getValues());
+ $this->assertEquals(array(
+ 'Group 1' => array(1 => new ChoiceView('1', 'B')),
+ 'Group 2' => array(2 => new ChoiceView('2', 'C'))
+ ), $this->list->getPreferredViews());
+ $this->assertEquals(array(
+ 'Group 1' => array(0 => new ChoiceView('0', 'A')),
+ 'Group 2' => array(3 => new ChoiceView('3', 'D'))
+ ), $this->list->getRemainingViews());
}
public function testGetIndicesForChoices()
diff --git a/tests/Symfony/Tests/Component/Form/Extension/Core/Type/ChoiceTypeTest.php b/tests/Symfony/Tests/Component/Form/Extension/Core/Type/ChoiceTypeTest.php
index 8dae89442d..cf26d5ea29 100644
--- a/tests/Symfony/Tests/Component/Form/Extension/Core/Type/ChoiceTypeTest.php
+++ b/tests/Symfony/Tests/Component/Form/Extension/Core/Type/ChoiceTypeTest.php
@@ -12,9 +12,8 @@
namespace Symfony\Tests\Component\Form\Extension\Core\Type;
use Symfony\Component\Form\Extension\Core\ChoiceList\ObjectChoiceList;
-
use Symfony\Component\Form\Extension\Core\ChoiceList\SimpleChoiceList;
-
+use Symfony\Component\Form\Extension\Core\View\ChoiceView;
use Symfony\Component\Form\Exception\UnexpectedTypeException;
class ChoiceTypeTest extends TypeTestCase
@@ -600,8 +599,12 @@ class ChoiceTypeTest extends TypeTestCase
));
$view = $form->createView();
- $this->assertSame(array('0', '1', '2', '3'), $view->get('choices'));
- $this->assertSame(array('A', 'B', 'C', 'D'), $view->get('choice_labels'));
+ $this->assertEquals(array(
+ new ChoiceView('0', 'A'),
+ new ChoiceView('1', 'B'),
+ new ChoiceView('2', 'C'),
+ new ChoiceView('3', 'D'),
+ ), $view->get('choices'));
}
public function testPassPreferredChoicesToView()
@@ -613,9 +616,14 @@ class ChoiceTypeTest extends TypeTestCase
));
$view = $form->createView();
- $this->assertSame(array(0 => '0', 2 => '2'), $view->get('choices'));
- $this->assertSame(array(1 => '1', 3 => '3'), $view->get('preferred_choices'));
- $this->assertSame(array('A', 'B', 'C', 'D'), $view->get('choice_labels'));
+ $this->assertEquals(array(
+ 0 => new ChoiceView('0', 'A'),
+ 2 => new ChoiceView('2', 'C'),
+ ), $view->get('choices'));
+ $this->assertEquals(array(
+ 1 => new ChoiceView('1', 'B'),
+ 3 => new ChoiceView('3', 'D'),
+ ), $view->get('preferred_choices'));
}
public function testPassHierarchicalChoicesToView()
@@ -626,9 +634,23 @@ class ChoiceTypeTest extends TypeTestCase
));
$view = $form->createView();
- $this->assertSame(array('Symfony' => array(0 => '0', 2 => '2'), 'Doctrine' => array(4 => '4')), $view->get('choices'));
- $this->assertSame(array('Symfony' => array(1 => '1'), 'Doctrine' => array(3 => '3')), $view->get('preferred_choices'));
- $this->assertSame(array(0 => 'Bernhard', 1 => 'Fabien', 2 => 'Kris', 3 => 'Jon', 4 => 'Roman'), $view->get('choice_labels'));
+ $this->assertEquals(array(
+ 'Symfony' => array(
+ 0 => new ChoiceView('0', 'Bernhard'),
+ 2 => new ChoiceView('2', 'Kris'),
+ ),
+ 'Doctrine' => array(
+ 4 => new ChoiceView('4', 'Roman'),
+ ),
+ ), $view->get('choices'));
+ $this->assertEquals(array(
+ 'Symfony' => array(
+ 1 => new ChoiceView('1', 'Fabien'),
+ ),
+ 'Doctrine' => array(
+ 3 => new ChoiceView('3', 'Jon'),
+ ),
+ ), $view->get('preferred_choices'));
}
public function testAdjustFullNameForMultipleNonExpanded()
diff --git a/tests/Symfony/Tests/Component/Form/Extension/Core/Type/CountryTypeTest.php b/tests/Symfony/Tests/Component/Form/Extension/Core/Type/CountryTypeTest.php
index a6a150a490..5d819af566 100644
--- a/tests/Symfony/Tests/Component/Form/Extension/Core/Type/CountryTypeTest.php
+++ b/tests/Symfony/Tests/Component/Form/Extension/Core/Type/CountryTypeTest.php
@@ -11,6 +11,7 @@
namespace Symfony\Tests\Component\Form\Extension\Core\Type;
+use Symfony\Component\Form\Extension\Core\View\ChoiceView;
class CountryTypeTest extends LocalizedTestCase
{
@@ -21,18 +22,12 @@ class CountryTypeTest extends LocalizedTestCase
$form = $this->factory->create('country');
$view = $form->createView();
$choices = $view->get('choices');
- $labels = $view->get('choice_labels');
- $this->assertContains('DE', $choices);
- $this->assertEquals('Deutschland', $labels['DE']);
- $this->assertContains('GB', $choices);
- $this->assertEquals('Vereinigtes Königreich', $labels['GB']);
- $this->assertContains('US', $choices);
- $this->assertEquals('Vereinigte Staaten', $labels['US']);
- $this->assertContains('FR', $choices);
- $this->assertEquals('Frankreich', $labels['FR']);
- $this->assertContains('MY', $choices);
- $this->assertEquals('Malaysia', $labels['MY']);
+ $this->assertEquals(new ChoiceView('DE', 'Deutschland'), $choices['DE']);
+ $this->assertEquals(new ChoiceView('GB', 'Vereinigtes Königreich'), $choices['GB']);
+ $this->assertEquals(new ChoiceView('US', 'Vereinigte Staaten'), $choices['US']);
+ $this->assertEquals(new ChoiceView('FR', 'Frankreich'), $choices['FR']);
+ $this->assertEquals(new ChoiceView('MY', 'Malaysia'), $choices['MY']);
}
public function testUnknownCountryIsNotIncluded()
diff --git a/tests/Symfony/Tests/Component/Form/Extension/Core/Type/DateTypeTest.php b/tests/Symfony/Tests/Component/Form/Extension/Core/Type/DateTypeTest.php
index d1b9c45023..1be7affc70 100644
--- a/tests/Symfony/Tests/Component/Form/Extension/Core/Type/DateTypeTest.php
+++ b/tests/Symfony/Tests/Component/Form/Extension/Core/Type/DateTypeTest.php
@@ -11,8 +11,9 @@
namespace Symfony\Tests\Component\Form\Extension\Core\Type;
-require_once __DIR__ . '/LocalizedTestCase.php';
+use Symfony\Component\Form\Extension\Core\View\ChoiceView;
+require_once __DIR__ . '/LocalizedTestCase.php';
class DateTypeTest extends LocalizedTestCase
{
@@ -325,7 +326,10 @@ class DateTypeTest extends LocalizedTestCase
$view = $form->createView();
- $this->assertSame(array(2010 => '2010', 2011 => '2011'), $view->getChild('year')->get('choice_labels'));
+ $this->assertEquals(array(
+ 2010 => new ChoiceView('2010', '2010'),
+ 2011 => new ChoiceView('2011', '2011'),
+ ), $view->getChild('year')->get('choices'));
}
public function testMonthsOption()
@@ -336,7 +340,10 @@ class DateTypeTest extends LocalizedTestCase
$view = $form->createView();
- $this->assertSame(array(6 => '06', 7 => '07'), $view->getChild('month')->get('choice_labels'));
+ $this->assertEquals(array(
+ 6 => new ChoiceView('6', '06'),
+ 7 => new ChoiceView('7', '07'),
+ ), $view->getChild('month')->get('choices'));
}
public function testMonthsOptionNumericIfFormatContainsNoMonth()
@@ -348,7 +355,10 @@ class DateTypeTest extends LocalizedTestCase
$view = $form->createView();
- $this->assertSame(array(6 => '06', 7 => '07'), $view->getChild('month')->get('choice_labels'));
+ $this->assertEquals(array(
+ 6 => new ChoiceView('6', '06'),
+ 7 => new ChoiceView('7', '07'),
+ ), $view->getChild('month')->get('choices'));
}
public function testMonthsOptionShortFormat()
@@ -360,7 +370,10 @@ class DateTypeTest extends LocalizedTestCase
$view = $form->createView();
- $this->assertSame(array(1 => 'Jän', 4 => 'Apr'), $view->getChild('month')->get('choice_labels'));
+ $this->assertEquals(array(
+ 1 => new ChoiceView('1', 'Jän'),
+ 4 => new ChoiceView('4', 'Apr')
+ ), $view->getChild('month')->get('choices'));
}
public function testMonthsOptionLongFormat()
@@ -372,7 +385,10 @@ class DateTypeTest extends LocalizedTestCase
$view = $form->createView();
- $this->assertSame(array(1 => 'Jänner', 4 => 'April'), $view->getChild('month')->get('choice_labels'));
+ $this->assertEquals(array(
+ 1 => new ChoiceView('1', 'Jänner'),
+ 4 => new ChoiceView('4', 'April'),
+ ), $view->getChild('month')->get('choices'));
}
public function testMonthsOptionLongFormatWithDifferentTimezone()
@@ -384,7 +400,10 @@ class DateTypeTest extends LocalizedTestCase
$view = $form->createView();
- $this->assertSame(array(1 => 'Jänner', 4 => 'April'), $view->getChild('month')->get('choice_labels'));
+ $this->assertEquals(array(
+ 1 => new ChoiceView('1', 'Jänner'),
+ 4 => new ChoiceView('4', 'April'),
+ ), $view->getChild('month')->get('choices'));
}
public function testIsDayWithinRangeReturnsTrueIfWithin()
@@ -395,7 +414,10 @@ class DateTypeTest extends LocalizedTestCase
$view = $form->createView();
- $this->assertSame(array(6 => '06', 7 => '07'), $view->getChild('day')->get('choice_labels'));
+ $this->assertEquals(array(
+ 6 => new ChoiceView('6', '06'),
+ 7 => new ChoiceView('7', '07'),
+ ), $view->getChild('day')->get('choices'));
}
public function testIsPartiallyFilledReturnsFalseIfSingleText()
diff --git a/tests/Symfony/Tests/Component/Form/Extension/Core/Type/LanguageTypeTest.php b/tests/Symfony/Tests/Component/Form/Extension/Core/Type/LanguageTypeTest.php
index b8a1595bb9..fc80a0e06c 100644
--- a/tests/Symfony/Tests/Component/Form/Extension/Core/Type/LanguageTypeTest.php
+++ b/tests/Symfony/Tests/Component/Form/Extension/Core/Type/LanguageTypeTest.php
@@ -11,6 +11,7 @@
namespace Symfony\Tests\Component\Form\Extension\Core\Type;
+use Symfony\Component\Form\Extension\Core\View\ChoiceView;
class LanguageTypeTest extends LocalizedTestCase
{
@@ -23,16 +24,11 @@ class LanguageTypeTest extends LocalizedTestCase
$choices = $view->get('choices');
$labels = $view->get('choice_labels');
- $this->assertContains('en', $choices);
- $this->assertEquals('Englisch', $labels[array_search('en', $choices)]);
- $this->assertContains('en_GB', $choices);
- $this->assertEquals('Britisches Englisch', $labels[array_search('en_GB', $choices)]);
- $this->assertContains('en_US', $choices);
- $this->assertEquals('Amerikanisches Englisch', $labels[array_search('en_US', $choices)]);
- $this->assertContains('fr', $choices);
- $this->assertEquals('Französisch', $labels[array_search('fr', $choices)]);
- $this->assertContains('my', $choices);
- $this->assertEquals('Birmanisch', $labels[array_search('my', $choices)]);
+ $this->assertContains(new ChoiceView('en', 'Englisch'), $choices, '', false, false);
+ $this->assertContains(new ChoiceView('en_GB', 'Britisches Englisch'), $choices, '', false, false);
+ $this->assertContains(new ChoiceView('en_US', 'Amerikanisches Englisch'), $choices, '', false, false);
+ $this->assertContains(new ChoiceView('fr', 'Französisch'), $choices, '', false, false);
+ $this->assertContains(new ChoiceView('my', 'Birmanisch'), $choices, '', false, false);
}
public function testMultipleLanguagesIsNotIncluded()
@@ -41,6 +37,6 @@ class LanguageTypeTest extends LocalizedTestCase
$view = $form->createView();
$choices = $view->get('choices');
- $this->assertArrayNotHasKey('mul', $choices);
+ $this->assertNotContains(new ChoiceView('mul', 'Mehrsprachig'), $choices, '', false, false);
}
}
diff --git a/tests/Symfony/Tests/Component/Form/Extension/Core/Type/LocaleTypeTest.php b/tests/Symfony/Tests/Component/Form/Extension/Core/Type/LocaleTypeTest.php
index ebd89940de..8f4bd97869 100644
--- a/tests/Symfony/Tests/Component/Form/Extension/Core/Type/LocaleTypeTest.php
+++ b/tests/Symfony/Tests/Component/Form/Extension/Core/Type/LocaleTypeTest.php
@@ -11,6 +11,7 @@
namespace Symfony\Tests\Component\Form\Extension\Core\Type;
+use Symfony\Component\Form\Extension\Core\View\ChoiceView;
class LocaleTypeTest extends LocalizedTestCase
{
@@ -21,13 +22,9 @@ class LocaleTypeTest extends LocalizedTestCase
$form = $this->factory->create('locale');
$view = $form->createView();
$choices = $view->get('choices');
- $labels = $view->get('choice_labels');
- $this->assertContains('en', $choices);
- $this->assertEquals('Englisch', $labels[array_search('en', $choices)]);
- $this->assertContains('en_GB', $choices);
- $this->assertEquals('Englisch (Vereinigtes Königreich)', $labels[array_search('en_GB', $choices)]);
- $this->assertContains('zh_Hant_MO', $choices);
- $this->assertEquals('Chinesisch (traditionell, Sonderverwaltungszone Macao)', $labels[array_search('zh_Hant_MO', $choices)]);
+ $this->assertContains(new ChoiceView('en', 'Englisch'), $choices, '', false, false);
+ $this->assertContains(new ChoiceView('en_GB', 'Englisch (Vereinigtes Königreich)'), $choices, '', false, false);
+ $this->assertContains(new ChoiceView('zh_Hant_MO', 'Chinesisch (traditionell, Sonderverwaltungszone Macao)'), $choices, '', false, false);
}
}
diff --git a/tests/Symfony/Tests/Component/Form/Extension/Core/Type/TimeTypeTest.php b/tests/Symfony/Tests/Component/Form/Extension/Core/Type/TimeTypeTest.php
index 1b46c75207..34676ddf19 100644
--- a/tests/Symfony/Tests/Component/Form/Extension/Core/Type/TimeTypeTest.php
+++ b/tests/Symfony/Tests/Component/Form/Extension/Core/Type/TimeTypeTest.php
@@ -11,6 +11,8 @@
namespace Symfony\Tests\Component\Form\Extension\Core\Type;
+use Symfony\Component\Form\Extension\Core\View\ChoiceView;
+
require_once __DIR__ . '/LocalizedTestCase.php';
@@ -243,7 +245,10 @@ class TimeTypeTest extends LocalizedTestCase
$view = $form->createView();
- $this->assertSame(array(6 => '06', 7 => '07'), $view->getChild('hour')->get('choice_labels'));
+ $this->assertEquals(array(
+ 6 => new ChoiceView('6', '06'),
+ 7 => new ChoiceView('7', '07'),
+ ), $view->getChild('hour')->get('choices'));
}
public function testIsMinuteWithinRange_returnsTrueIfWithin()
@@ -254,7 +259,10 @@ class TimeTypeTest extends LocalizedTestCase
$view = $form->createView();
- $this->assertSame(array(6 => '06', 7 => '07'), $view->getChild('minute')->get('choice_labels'));
+ $this->assertEquals(array(
+ 6 => new ChoiceView('6', '06'),
+ 7 => new ChoiceView('7', '07'),
+ ), $view->getChild('minute')->get('choices'));
}
public function testIsSecondWithinRange_returnsTrueIfWithin()
@@ -266,7 +274,10 @@ class TimeTypeTest extends LocalizedTestCase
$view = $form->createView();
- $this->assertSame(array(6 => '06', 7 => '07'), $view->getChild('second')->get('choice_labels'));
+ $this->assertEquals(array(
+ 6 => new ChoiceView('6', '06'),
+ 7 => new ChoiceView('7', '07'),
+ ), $view->getChild('second')->get('choices'));
}
public function testIsPartiallyFilled_returnsFalseIfCompletelyEmpty()
diff --git a/tests/Symfony/Tests/Component/Form/Extension/Core/Type/TimezoneTypeTest.php b/tests/Symfony/Tests/Component/Form/Extension/Core/Type/TimezoneTypeTest.php
index be7db448fe..f8f5126c32 100644
--- a/tests/Symfony/Tests/Component/Form/Extension/Core/Type/TimezoneTypeTest.php
+++ b/tests/Symfony/Tests/Component/Form/Extension/Core/Type/TimezoneTypeTest.php
@@ -11,6 +11,7 @@
namespace Symfony\Tests\Component\Form\Extension\Core\Type;
+use Symfony\Component\Form\Extension\Core\View\ChoiceView;
class TimezoneTypeTest extends TypeTestCase
{
@@ -22,11 +23,9 @@ class TimezoneTypeTest extends TypeTestCase
$labels = $view->get('choice_labels');
$this->assertArrayHasKey('Africa', $choices);
- $this->assertContains('Africa/Kinshasa', $choices['Africa']);
- $this->assertEquals('Kinshasa', $labels[array_search('Africa/Kinshasa', $choices['Africa'])]);
+ $this->assertContains(new ChoiceView('Africa/Kinshasa', 'Kinshasa'), $choices['Africa'], '', false, false);
$this->assertArrayHasKey('America', $choices);
- $this->assertContains('America/New_York', $choices['America']);
- $this->assertEquals('New York', $labels[array_search('America/New_York', $choices['America'])]);
+ $this->assertContains(new ChoiceView('America/New_York', 'New York'), $choices['America'], '', false, false);
}
}