Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Form] Fixed regression: Empty values were not accepted anymore for collapsed, optional choice fields #14465

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

Merged
merged 1 commit into from
May 5, 2015
Merged
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 @@ -46,6 +46,10 @@ public function reverseTransform($value)
$choices = $this->choiceList->getChoicesForValues(array((string) $value));

if (1 !== count($choices)) {
if (null === $value || '' === $value) {
return;
}

throw new TransformationFailedException(sprintf('The choice "%s" does not exist or is not unique', $value));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ public function testSubmitSingleNonExpanded()

$this->assertEquals('b', $form->getData());
$this->assertEquals('b', $form->getViewData());
$this->assertTrue($form->isSynchronized());
}

public function testSubmitSingleNonExpandedInvalidChoice()
Expand Down Expand Up @@ -269,6 +270,7 @@ public function testSubmitSingleNonExpandedNull()

$this->assertNull($form->getData());
$this->assertSame('', $form->getViewData());
$this->assertTrue($form->isSynchronized());
}

// In edge cases (for example, when choices are loaded dynamically by a
Expand All @@ -286,6 +288,7 @@ public function testSubmitSingleNonExpandedNullNoChoices()

$this->assertNull($form->getData());
$this->assertSame('', $form->getViewData());
$this->assertTrue($form->isSynchronized());
}

public function testSubmitSingleNonExpandedEmpty()
Expand All @@ -300,6 +303,27 @@ public function testSubmitSingleNonExpandedEmpty()

$this->assertNull($form->getData());
$this->assertSame('', $form->getViewData());
$this->assertTrue($form->isSynchronized());
}

public function testSubmitSingleNonExpandedEmptyExplicitEmptyChoice()
{
$form = $this->factory->create('choice', null, array(
'multiple' => false,
'expanded' => false,
'choices' => array(
'EMPTY_CHOICE' => 'Empty',
Copy link
Contributor

Choose a reason for hiding this comment

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

doesn't this have to use choices_as_values: true to not use the deprecated functionality? I guess the trigger_error is missing for the old choices structure.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You are right. I'll add the trigger_error statement in a separate PR.

),
'choice_value' => function () {
return '';
},
));

$form->submit('');

$this->assertSame('EMPTY_CHOICE', $form->getData());
$this->assertSame('', $form->getViewData());
$this->assertTrue($form->isSynchronized());
}

// In edge cases (for example, when choices are loaded dynamically by a
Expand All @@ -317,6 +341,7 @@ public function testSubmitSingleNonExpandedEmptyNoChoices()

$this->assertNull($form->getData());
$this->assertSame('', $form->getViewData());
$this->assertTrue($form->isSynchronized());
}

public function testSubmitSingleNonExpandedFalse()
Expand All @@ -331,6 +356,7 @@ public function testSubmitSingleNonExpandedFalse()

$this->assertNull($form->getData());
$this->assertSame('', $form->getViewData());
$this->assertTrue($form->isSynchronized());
}

// In edge cases (for example, when choices are loaded dynamically by a
Expand All @@ -348,6 +374,7 @@ public function testSubmitSingleNonExpandedFalseNoChoices()

$this->assertNull($form->getData());
$this->assertSame('', $form->getViewData());
$this->assertTrue($form->isSynchronized());
}

public function testSubmitSingleNonExpandedObjectChoices()
Expand All @@ -366,6 +393,7 @@ public function testSubmitSingleNonExpandedObjectChoices()

$this->assertEquals($this->objectChoices[1], $form->getData());
$this->assertEquals('2', $form->getViewData());
$this->assertTrue($form->isSynchronized());
}

/**
Expand All @@ -392,6 +420,7 @@ public function testLegacySubmitSingleNonExpandedObjectChoices()

$this->assertEquals($this->objectChoices[1], $form->getData());
$this->assertEquals('2', $form->getViewData());
$this->assertTrue($form->isSynchronized());
}

public function testSubmitMultipleNonExpanded()
Expand All @@ -406,6 +435,7 @@ public function testSubmitMultipleNonExpanded()

$this->assertEquals(array('a', 'b'), $form->getData());
$this->assertEquals(array('a', 'b'), $form->getViewData());
$this->assertTrue($form->isSynchronized());
}

public function testSubmitMultipleNonExpandedEmpty()
Expand All @@ -420,6 +450,7 @@ public function testSubmitMultipleNonExpandedEmpty()

$this->assertSame(array(), $form->getData());
$this->assertSame(array(), $form->getViewData());
$this->assertTrue($form->isSynchronized());
}

// In edge cases (for example, when choices are loaded dynamically by a
Expand All @@ -437,6 +468,7 @@ public function testSubmitMultipleNonExpandedEmptyNoChoices()

$this->assertSame(array(), $form->getData());
$this->assertSame(array(), $form->getViewData());
$this->assertTrue($form->isSynchronized());
}

public function testSubmitMultipleNonExpandedInvalidScalarChoice()
Expand Down Expand Up @@ -484,6 +516,7 @@ public function testSubmitMultipleNonExpandedObjectChoices()

$this->assertEquals(array($this->objectChoices[1], $this->objectChoices[2]), $form->getData());
$this->assertEquals(array('2', '3'), $form->getViewData());
$this->assertTrue($form->isSynchronized());
}

/**
Expand All @@ -509,6 +542,7 @@ public function testLegacySubmitMultipleNonExpandedObjectChoices()

$this->assertEquals(array($this->objectChoices[1], $this->objectChoices[2]), $form->getData());
$this->assertEquals(array('2', '3'), $form->getViewData());
$this->assertTrue($form->isSynchronized());
}

public function testSubmitSingleExpandedRequired()
Expand Down Expand Up @@ -933,6 +967,8 @@ public function testSubmitSingleExpandedWithEmptyChild()
$form->submit('');

$this->assertNull($form->getData());
$this->assertTrue($form->isSynchronized());

$this->assertTrue($form[0]->getData());
$this->assertFalse($form[1]->getData());
$this->assertSame('', $form[0]->getViewData());
Expand All @@ -953,6 +989,8 @@ public function testSubmitSingleExpandedObjectChoices()
$form->submit('2');

$this->assertSame($this->objectChoices[1], $form->getData());
$this->assertTrue($form->isSynchronized());

$this->assertFalse($form[0]->getData());
$this->assertTrue($form[1]->getData());
$this->assertFalse($form[2]->getData());
Expand Down Expand Up @@ -987,6 +1025,8 @@ public function testLegacySubmitSingleExpandedObjectChoices()
$form->submit('2');

$this->assertSame($this->objectChoices[1], $form->getData());
$this->assertTrue($form->isSynchronized());

$this->assertFalse($form[0]->getData());
$this->assertTrue($form[1]->getData());
$this->assertFalse($form[2]->getData());
Expand All @@ -1010,6 +1050,8 @@ public function testSubmitSingleExpandedNumericChoices()
$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());
Expand Down Expand Up @@ -1114,6 +1156,8 @@ public function testSubmitMultipleExpandedEmpty()
$form->submit(array());

$this->assertSame(array(), $form->getData());
$this->assertTrue($form->isSynchronized());

$this->assertFalse($form[0]->getData());
$this->assertFalse($form[1]->getData());
$this->assertFalse($form[2]->getData());
Expand All @@ -1140,6 +1184,7 @@ public function testSubmitMultipleExpandedEmptyNoChoices()
$form->submit(array());

$this->assertSame(array(), $form->getData());
$this->assertTrue($form->isSynchronized());
}

public function testSubmitMultipleExpandedWithEmptyChild()
Expand All @@ -1157,6 +1202,8 @@ public function testSubmitMultipleExpandedWithEmptyChild()
$form->submit(array('', '2'));

$this->assertSame(array('', 2), $form->getData());
$this->assertTrue($form->isSynchronized());

$this->assertTrue($form[0]->getData());
$this->assertFalse($form[1]->getData());
$this->assertTrue($form[2]->getData());
Expand All @@ -1179,6 +1226,8 @@ public function testSubmitMultipleExpandedObjectChoices()
$form->submit(array('1', '2'));

$this->assertSame(array($this->objectChoices[0], $this->objectChoices[1]), $form->getData());
$this->assertTrue($form->isSynchronized());

$this->assertTrue($form[0]->getData());
$this->assertTrue($form[1]->getData());
$this->assertFalse($form[2]->getData());
Expand Down Expand Up @@ -1213,6 +1262,8 @@ public function testLegacySubmitMultipleExpandedObjectChoices()
$form->submit(array('1', '2'));

$this->assertSame(array($this->objectChoices[0], $this->objectChoices[1]), $form->getData());
$this->assertTrue($form->isSynchronized());

$this->assertTrue($form[0]->getData());
$this->assertTrue($form[1]->getData());
$this->assertFalse($form[2]->getData());
Expand All @@ -1236,6 +1287,8 @@ public function testSubmitMultipleExpandedNumericChoices()
$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());
Expand Down Expand Up @@ -1264,6 +1317,7 @@ public function testSetDataSingleNonExpandedAcceptsBoolean()

$this->assertFalse($form->getData());
$this->assertEquals('0', $form->getViewData());
$this->assertTrue($form->isSynchronized());
}

public function testSetDataMultipleNonExpandedAcceptsBoolean()
Expand All @@ -1278,6 +1332,7 @@ public function testSetDataMultipleNonExpandedAcceptsBoolean()

$this->assertEquals(array(false, true), $form->getData());
$this->assertEquals(array('0', '1'), $form->getViewData());
$this->assertTrue($form->isSynchronized());
}

public function testPassRequiredToView()
Expand Down Expand Up @@ -1344,7 +1399,7 @@ public function testChoiceTranslationDomainWithTrueValueToView()
$this->assertNull($view->vars['choice_translation_domain']);
}

public function testDefaulChoiceTranslationDomainIsSameAsTranslationDomainToView()
public function testDefaultChoiceTranslationDomainIsSameAsTranslationDomainToView()
{
$form = $this->factory->create('choice', null, array(
'choices' => $this->choices,
Expand Down