[Form] FormValidator removed code related to removed option

This commit is contained in:
Peter Rehm 2016-03-09 19:53:41 +01:00 committed by Fabien Potencier
parent f990f1bea0
commit 05fe6f9b07
2 changed files with 7 additions and 60 deletions

View File

@ -43,9 +43,10 @@ class FormValidator extends ConstraintValidator
if ($form->isSynchronized()) {
// Validate the form data only if transformation succeeded
$groups = self::getValidationGroups($form);
$data = $form->getData();
// Validate the data against its own constraints
if (self::allowDataWalking($form)) {
if ($form->isRoot() && (is_object($data) || is_array($data))) {
foreach ($groups as $group) {
$validator->atPath('data')->validate($form->getData(), null, $group);
}
@ -114,38 +115,6 @@ class FormValidator extends ConstraintValidator
}
}
/**
* Returns whether the data of a form may be walked.
*
* @param FormInterface $form The form to test.
*
* @return bool Whether the graph walker may walk the data.
*/
private static function allowDataWalking(FormInterface $form)
{
$data = $form->getData();
// Scalar values cannot have mapped constraints
if (!is_object($data) && !is_array($data)) {
return false;
}
// Root forms are always validated
if ($form->isRoot()) {
return true;
}
// Non-root forms are validated if validation cascading
// is enabled in all ancestor forms
while (null !== ($form = $form->getParent())) {
if (!$form->getConfig()->getOption('cascade_validation')) {
return false;
}
}
return true;
}
/**
* Returns the validation groups of the given form.
*

View File

@ -104,29 +104,7 @@ class FormValidatorTest extends AbstractConstraintValidatorTest
$this->assertNoViolation();
}
public function testValidateIfParentWithCascadeValidation()
{
$object = $this->getMock('\stdClass');
$parent = $this->getBuilder('parent', null, array('cascade_validation' => true))
->setCompound(true)
->setDataMapper($this->getDataMapper())
->getForm();
$options = array('validation_groups' => array('group1', 'group2'));
$form = $this->getBuilder('name', '\stdClass', $options)->getForm();
$parent->add($form);
$form->setData($object);
$this->expectValidateAt(0, 'data', $object, 'group1');
$this->expectValidateAt(1, 'data', $object, 'group2');
$this->validator->validate($form, new Form());
$this->assertNoViolation();
}
public function testValidateIfChildWithValidConstraint()
public function testValidateChildIfValidConstraint()
{
$object = $this->getMock('\stdClass');
@ -150,11 +128,11 @@ class FormValidatorTest extends AbstractConstraintValidatorTest
$this->assertNoViolation();
}
public function testDontValidateIfParentWithoutCascadeValidation()
public function testDontValidateIfParentWithoutValidConstraint()
{
$object = $this->getMock('\stdClass');
$parent = $this->getBuilder('parent', null, array('cascade_validation' => false))
$parent = $this->getBuilder('parent', null)
->setCompound(true)
->setDataMapper($this->getDataMapper())
->getForm();
@ -184,13 +162,13 @@ class FormValidatorTest extends AbstractConstraintValidatorTest
$this->assertNoViolation();
}
public function testValidateConstraintsEvenIfNoCascadeValidation()
public function testValidateConstraintsOptionEvenIfNoValidConstraint()
{
$object = $this->getMock('\stdClass');
$constraint1 = new NotNull(array('groups' => array('group1', 'group2')));
$constraint2 = new NotBlank(array('groups' => 'group2'));
$parent = $this->getBuilder('parent', null, array('cascade_validation' => false))
$parent = $this->getBuilder('parent', null)
->setCompound(true)
->setDataMapper($this->getDataMapper())
->getForm();