From 0cddc90622e2d219f71fc5b57a1ff4747d99d992 Mon Sep 17 00:00:00 2001 From: Peter Rehm Date: Wed, 9 Mar 2016 19:53:41 +0100 Subject: [PATCH 1/2] Removed code for deprecated cascade_validation option --- .../Validator/Constraints/FormValidator.php | 35 ++----------------- .../Constraints/FormValidatorTest.php | 30 +++------------- 2 files changed, 6 insertions(+), 59 deletions(-) diff --git a/src/Symfony/Component/Form/Extension/Validator/Constraints/FormValidator.php b/src/Symfony/Component/Form/Extension/Validator/Constraints/FormValidator.php index a706e5668622b..13b8e3d1248ad 100644 --- a/src/Symfony/Component/Form/Extension/Validator/Constraints/FormValidator.php +++ b/src/Symfony/Component/Form/Extension/Validator/Constraints/FormValidator.php @@ -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); } @@ -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. * diff --git a/src/Symfony/Component/Form/Tests/Extension/Validator/Constraints/FormValidatorTest.php b/src/Symfony/Component/Form/Tests/Extension/Validator/Constraints/FormValidatorTest.php index a6d0c9ffb1f1b..c18e21d684278 100644 --- a/src/Symfony/Component/Form/Tests/Extension/Validator/Constraints/FormValidatorTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/Validator/Constraints/FormValidatorTest.php @@ -103,28 +103,6 @@ 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() { $object = $this->getMock('\stdClass'); @@ -149,11 +127,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(); @@ -183,13 +161,13 @@ public function testMissingConstraintIndex() $this->assertNoViolation(); } - public function testValidateConstraintsEvenIfNoCascadeValidation() + public function testValidateConstraintsOptionEvenIfParentWithoutValidConstraint() { $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(); From 17d11258595bad627fe786e0bca803d938d7a59e Mon Sep 17 00:00:00 2001 From: Peter Rehm Date: Sun, 3 Apr 2016 18:14:37 +0200 Subject: [PATCH 2/2] Renamed test methods --- .../Extension/Validator/Constraints/FormValidatorTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Component/Form/Tests/Extension/Validator/Constraints/FormValidatorTest.php b/src/Symfony/Component/Form/Tests/Extension/Validator/Constraints/FormValidatorTest.php index c18e21d684278..f328ba005759d 100644 --- a/src/Symfony/Component/Form/Tests/Extension/Validator/Constraints/FormValidatorTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/Validator/Constraints/FormValidatorTest.php @@ -103,7 +103,7 @@ public function testValidateConstraints() $this->assertNoViolation(); } - public function testValidateIfChildWithValidConstraint() + public function testValidateChildIfValidConstraint() { $object = $this->getMock('\stdClass'); @@ -161,7 +161,7 @@ public function testMissingConstraintIndex() $this->assertNoViolation(); } - public function testValidateConstraintsOptionEvenIfParentWithoutValidConstraint() + public function testValidateConstraintsOptionEvenIfNoValidConstraint() { $object = $this->getMock('\stdClass'); $constraint1 = new NotNull(array('groups' => array('group1', 'group2'))); pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy