Skip to content

Commit

Permalink
bug #18081 [Form] FormValidator removed code related to removed `casc…
Browse files Browse the repository at this point in the history
…ade_validation` option (peterrehm)

This PR was submitted for the master branch but it was merged into the 3.0 branch instead (closes #18081).

Discussion
----------

[Form] FormValidator removed code related to removed `cascade_validation` option

| Q             | A
| ------------- | ---
| Branch        | 3.0
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #18063
| License       | MIT

Commits
-------

05fe6f9 [Form] FormValidator removed code related to removed  option
  • Loading branch information
fabpot committed Apr 7, 2016
2 parents f990f1b + 05fe6f9 commit 5ccbef1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 60 deletions.
Expand Up @@ -43,9 +43,10 @@ public function validate($form, Constraint $constraint)
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);
}
Expand Down Expand Up @@ -114,38 +115,6 @@ public function validate($form, Constraint $constraint)
}
}

/**
* 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.
*
Expand Down
Expand Up @@ -104,29 +104,7 @@ public function testValidateConstraints()
$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');

Expand All @@ -150,11 +128,11 @@ public function testValidateIfChildWithValidConstraint()
$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();
Expand Down Expand Up @@ -184,13 +162,13 @@ public function testMissingConstraintIndex()
$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();
Expand Down

0 comments on commit 5ccbef1

Please sign in to comment.