10000 [WIP] [3.0] [Form] fix tests added by #17760 by removing `choices_as_values` by HeahDude · Pull Request #17886 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[WIP] [3.0] [Form] fix tests added by #17760 by removing choices_as_values #17886

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
Expand Down
Origin 8000 al file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,6 @@ class ChoiceTypeTest extends \Symfony\Component\Form\Test\TypeTestCase
'n/a' => '',
);

private $numericChoicesFlipped = array(
0 => 'Bernhard',
1 => 'Fabien',
2 => 'Kris',
3 => 'Jon',
4 => 'Roman',
);

private $objectChoices;

protected $groupedChoices = array(
Expand Down Expand Up @@ -110,9 +102,8 @@ 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();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you're merging this into 3.0, you can use ChoiceType::class, not sure if that's preferable though.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@iltar, I know, I even proposed to use constants in core type tests (see #17699 (comment)) as of 2.8 but this is actually to be consistent with other tests ;)


$this->assertSame('1', $view->vars['choices'][0]->value);
Expand All @@ -125,19 +116,17 @@ 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();

$this->assertTrue($view->vars['is_selected']($view->vars['choices'][1]->value, $view->vars['value']), 'False value should be pre selected');
}

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,
))->createView();

Expand All @@ -148,9 +137,8 @@ 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,
))->createView();

Expand Down Expand Up @@ -217,7 +205,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,
Expand All @@ -226,7 +214,6 @@ public function testPlaceholderWithBooleanChoices()
'No' => false,
),
'placeholder' => 'Select an option',
'choices_as_values' => true,
));

$view = $form->createView();
Expand All @@ -239,7 +226,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,
Expand All @@ -248,7 +235,6 @@ public function testPlaceholderWithBooleanChoicesWithFalseAsPreSetData()
'No' => false,
),
'placeholder' => 'Select an option',
'choices_as_values' => true,
));

$view = $form->createView();
Expand All @@ -261,7 +247,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,
Expand All @@ -270,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');
Expand All @@ -286,7 +271,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,
Expand All @@ -295,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');
Expand Down
0