Skip to content

Commit 5ccbef1

Browse files
committed
bug symfony#18081 [Form] FormValidator removed code related to removed cascade_validation option (peterrehm)
This PR was submitted for the master branch but it was merged into the 3.0 branch instead (closes symfony#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 | symfony#18063 | License | MIT Commits ------- 05fe6f9 [Form] FormValidator removed code related to removed option
2 parents f990f1b + 05fe6f9 commit 5ccbef1

File tree

2 files changed

+7
-60
lines changed

2 files changed

+7
-60
lines changed

src/Symfony/Component/Form/Extension/Validator/Constraints/FormValidator.php

Lines changed: 2 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,10 @@ public function validate($form, Constraint $constraint)
4343
if ($form->isSynchronized()) {
4444
// Validate the form data only if transformation succeeded
4545
$groups = self::getValidationGroups($form);
46+
$data = $form->getData();
4647

4748
// Validate the data against its own constraints
48-
if (self::allowDataWalking($form)) {
49+
if ($form->isRoot() && (is_object($data) || is_array($data))) {
4950
foreach ($groups as $group) {
5051
$validator->atPath('data')->validate($form->getData(), null, $group);
5152
}
@@ -114,38 +115,6 @@ public function validate($form, Constraint $constraint)
114115
}
115116
}
116117

117-
/**
118-
* Returns whether the data of a form may be walked.
119-
*
120-
* @param FormInterface $form The form to test.
121-
*
122-
* @return bool Whether the graph walker may walk the data.
123-
*/
124-
private static function allowDataWalking(FormInterface $form)
125-
{
126-
$data = $form->getData();
127-
128-
// Scalar values cannot have mapped constraints
129-
if (!is_object($data) && !is_array($data)) {
130-
return false;
131-
}
132-
133-
// Root forms are always validated
134-
if ($form->isRoot()) {
135-
return true;
136-
}
137-
138-
// Non-root forms are validated if validation cascading
139-
// is enabled in all ancestor forms
140-
while (null !== ($form = $form->getParent())) {
141-
if (!$form->getConfig()->getOption('cascade_validation')) {
142-
return false;
143-
}
144-
}
145-
146-
return true;
147-
}
148-
149118
/**
150119
* Returns the validation groups of the given form.
151120
*

src/Symfony/Component/Form/Tests/Extension/Validator/Constraints/FormValidatorTest.php

Lines changed: 5 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -104,29 +104,7 @@ public function testValidateConstraints()
104104
$this->assertNoViolation();
105105
}
106106

107-
public function testValidateIfParentWithCascadeValidation()
108-
{
109-
$object = $this->getMock('\stdClass');
110-
111-
$parent = $this->getBuilder('parent', null, array('cascade_validation' => true))
112-
->setCompound(true)
113-
->setDataMapper($this->getDataMapper())
114-
->getForm();
115-
$options = array('validation_groups' => array('group1', 'group2'));
116-
$form = $this->getBuilder('name', '\stdClass', $options)->getForm();
117-
$parent->add($form);
118-
119-
$form->setData($object);
120-
121-
$this->expectValidateAt(0, 'data', $object, 'group1');
122-
$this->expectValidateAt(1, 'data', $object, 'group2');
123-
124-
$this->validator->validate($form, new Form());
125-
126-
$this->assertNoViolation();
127-
}
128-
129-
public function testValidateIfChildWithValidConstraint()
107+
public function testValidateChildIfValidConstraint()
130108
{
131109
$object = $this->getMock('\stdClass');
132110

@@ -150,11 +128,11 @@ public function testValidateIfChildWithValidConstraint()
150128
$this->assertNoViolation();
151129
}
152130

153-
public function testDontValidateIfParentWithoutCascadeValidation()
131+
public function testDontValidateIfParentWithoutValidConstraint()
154132
{
155133
$object = $this->getMock('\stdClass');
156134

157-
$parent = $this->getBuilder('parent', null, array('cascade_validation' => false))
135+
$parent = $this->getBuilder('parent', null)
158136
->setCompound(true)
159137
->setDataMapper($this->getDataMapper())
160138
->getForm();
@@ -184,13 +162,13 @@ public function testMissingConstraintIndex()
184162
$this->assertNoViolation();
185163
}
186164

187-
public function testValidateConstraintsEvenIfNoCascadeValidation()
165+
public function testValidateConstraintsOptionEvenIfNoValidConstraint()
188166
{
189167
$object = $this->getMock('\stdClass');
190168
$constraint1 = new NotNull(array('groups' => array('group1', 'group2')));
191169
$constraint2 = new NotBlank(array('groups' => 'group2'));
192170

193-
$parent = $this->getBuilder('parent', null, array('cascade_validation' => false))
171+
$parent = $this->getBuilder('parent', null)
194172
->setCompound(true)
195173
->setDataMapper($this->getDataMapper())
196174
->getForm();

0 commit comments

Comments
 (0)