From 841cd6f3e239673c6bb589f384253af37a99409a Mon Sep 17 00:00:00 2001 From: Jules Pietri Date: Mon, 22 Feb 2016 14:16:13 +0100 Subject: [PATCH 1/3] [Form] add tests to `ChoiceType` for a `false` choice --- .../Form/Tests/Extension/Core/Type/ChoiceTypeTest.php | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/src/Symfony/Component/Form/Tests/Extension/Core/Type/ChoiceTypeTest.php b/src/Symfony/Component/Form/Tests/Extension/Core/Type/ChoiceTypeTest.php index ad289c644315..f22dc5491214 100644 --- a/src/Symfony/Component/Form/Tests/Extension/Core/Type/ChoiceTypeTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/Core/Type/ChoiceTypeTest.php @@ -29,15 +29,7 @@ class ChoiceTypeTest extends \Symfony\Component\Form\Test\TypeTestCase 'No' => false, 'n/a' => '', ); - - private $numericChoicesFlipped = array( - 0 => 'Bernhard', - 1 => 'Fabien', - 2 => 'Kris', - 3 => 'Jon', - 4 => 'Roman', - ); - + private $objectChoices; protected $groupedChoices = array( From f41fa21eeda94969d724f12eb5d206fe8a70d6fe Mon Sep 17 00:00:00 2001 From: Jules Pietri Date: Mon, 22 Feb 2016 14:49:13 +0100 Subject: [PATCH 2/3] [Form] fix tests added by #17760 with FQCN --- .../Tests/Extension/Core/Type/ChoiceTypeTest.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/Symfony/Component/Form/Tests/Extension/Core/Type/ChoiceTypeTest.php b/src/Symfony/Component/Form/Tests/Extension/Core/Type/ChoiceTypeTest.php index f22dc5491214..40accfe25f7a 100644 --- a/src/Symfony/Component/Form/Tests/Extension/Core/Type/ChoiceTypeTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/Core/Type/ChoiceTypeTest.php @@ -102,7 +102,7 @@ public function testExpandedChoicesOptionsTurnIntoChildren() public function testChoiceListWithScalarValues() { - $view = $this->factory->create('choice', null, array( + $view = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array( 'choices' => $this->scalarChoices, 'choices_as_values' => true, ))->createView(); @@ -117,7 +117,7 @@ public function testChoiceListWithScalarValues() public function testChoiceListWithScalarValuesAndFalseAsPreSetData() { - $view = $this->factory->create('choice', false, array( + $view = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', false, array( 'choices' => $this->scalarChoices, 'choices_as_values' => true, ))->createView(); @@ -127,7 +127,7 @@ public function testChoiceListWithScalarValuesAndFalseAsPreSetData() public function testExpandedChoiceListWithScalarValues() { - $view = $this->factory->create('choice', null, array( + $view = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array( 'choices' => $this->scalarChoices, 'choices_as_values' => true, 'expanded' => true, @@ -140,7 +140,7 @@ public function testExpandedChoiceListWithScalarValues() public function testExpandedChoiceListWithScalarValuesAndFalseAsPreSetData() { - $view = $this->factory->create('choice', false, array( + $view = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', false, array( 'choices' => $this->scalarChoices, 'choices_as_values' => true, 'expanded' => true, @@ -209,7 +209,7 @@ public function testPlaceholderNotPresentIfEmptyChoice() public function testPlaceholderWithBooleanChoices() { - $form = $this->factory->create('choice', null, array( + $form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array( 'multiple' => false, 'expanded' => false, 'required' => false, @@ -231,7 +231,7 @@ public function testPlaceholderWithBooleanChoices() public function testPlaceholderWithBooleanChoicesWithFalseAsPreSetData() { - $form = $this->factory->create('choice', false, array( + $form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', false, array( 'multiple' => false, 'expanded' => false, 'required' => false, @@ -253,7 +253,7 @@ public function testPlaceholderWithBooleanChoicesWithFalseAsPreSetData() public function testPlaceholderWithExpandedBooleanChoices() { - $form = $this->factory->create('choice', null, array( + $form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array( 'multiple' => false, 'expanded' => true, 'required' => false, @@ -278,7 +278,7 @@ public function testPlaceholderWithExpandedBooleanChoices() public function testPlaceholderWithExpandedBooleanChoicesAndWithFalseAsPreSetData() { - $form = $this->factory->create('choice', false, array( + $form = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', false, array( 'multiple' => false, 'expanded' => true, 'required' => false, From e7234d8dcbe1fcd1b319f4c4992c91a3c96bd1bb Mon Sep 17 00:00:00 2001 From: Jules Pietri Date: Mon, 22 Feb 2016 15:11:29 +0100 Subject: [PATCH 3/3] [Form] fix tests added by #17760 by removing `choices_as_values` --- .../Component/Form/Extension/Core/Type/ChoiceType.php | 2 +- .../Form/Tests/Extension/Core/Type/ChoiceTypeTest.php | 10 +--------- 2 files changed, 2 insertions(+), 10 deletions(-) diff --git a/src/Symfony/Component/Form/Extension/Core/Type/ChoiceType.php b/src/Symfony/Component/Form/Extension/Core/Type/ChoiceType.php index bc4e0876d842..996f5cfcf990 100644 --- a/src/Symfony/Component/Form/Extension/Core/Type/ChoiceType.php +++ b/src/Symfony/Component/Form/Extension/Core/Type/ChoiceType.php @@ -148,7 +148,7 @@ public function buildForm(FormBuilderInterface $builder, array $options) // with the string value so it can be matched in // {@link \Symfony\Component\Form\Extension\Core\DataMapper\RadioListMapper::mapDataToForms()} $builder->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) { - $choiceList = $event->getForm()->getConfig()->getOption('choice_list'); + $choiceList = $event->getForm()->getConfig()->getAttribute('choice_list'); $value = current($choiceList->getValuesForChoices(array($event->getData()))); $event->setData((string) $value); }); diff --git a/src/Symfony/Component/Form/Tests/Extension/Core/Type/ChoiceTypeTest.php b/src/Symfony/Component/Form/Tests/Extension/Core/Type/ChoiceTypeTest.php index 40accfe25f7a..a9cc7b1d42d5 100644 --- a/src/Symfony/Component/Form/Tests/Extension/Core/Type/ChoiceTypeTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/Core/Type/ChoiceTypeTest.php @@ -29,7 +29,7 @@ class ChoiceTypeTest extends \Symfony\Component\Form\Test\TypeTestCase 'No' => false, 'n/a' => '', ); - + private $objectChoices; protected $groupedChoices = array( @@ -104,7 +104,6 @@ public function testChoiceListWithScalarValues() { $view = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array( 'choices' => $this->scalarChoices, - 'choices_as_values' => true, ))->createView(); $this->assertSame('1', $view->vars['choices'][0]->value); @@ -119,7 +118,6 @@ public function testChoiceListWithScalarValuesAndFalseAsPreSetData() { $view = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', false, array( 'choices' => $this->scalarChoices, - 'choices_as_values' => true, ))->createView(); $this->assertTrue($view->vars['is_selected']($view->vars['choices'][1]->value, $view->vars['value']), 'False value should be pre selected'); @@ -129,7 +127,6 @@ public function testExpandedChoiceListWithScalarValues() { $view = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', null, array( 'choices' => $this->scalarChoices, - 'choices_as_values' => true, 'expanded' => true, ))->createView(); @@ -142,7 +139,6 @@ public function testExpandedChoiceListWithScalarValuesAndFalseAsPreSetData() { $view = $this->factory->create('Symfony\Component\Form\Extension\Core\Type\ChoiceType', false, array( 'choices' => $this->scalarChoices, - 'choices_as_values' => true, 'expanded' => true, ))->createView(); @@ -218,7 +214,6 @@ public function testPlaceholderWithBooleanChoices() 'No' => false, ), 'placeholder' => 'Select an option', - 'choices_as_values' => true, )); $view = $form->createView(); @@ -240,7 +235,6 @@ public function testPlaceholderWithBooleanChoicesWithFalseAsPreSetData() 'No' => false, ), 'placeholder' => 'Select an option', - 'choices_as_values' => true, )); $view = $form->createView(); @@ -262,7 +256,6 @@ public function testPlaceholderWithExpandedBooleanChoices() 'No' => false, ), 'placeholder' => 'Select an option', - 'choices_as_values' => true, )); $this->assertTrue(isset($form['placeholder']), 'Placeholder should be set'); @@ -287,7 +280,6 @@ public function testPlaceholderWithExpandedBooleanChoicesAndWithFalseAsPreSetDat 'No' => false, ), 'placeholder' => 'Select an option', - 'choices_as_values' => true, )); $this->assertTrue(isset($form['placeholder']), 'Placeholder should be set');