From e2c7c3373d1810726b37a7d6df6aa7361ff6f153 Mon Sep 17 00:00:00 2001 From: Johan de Ruijter Date: Fri, 25 Sep 2020 11:24:52 +0200 Subject: [PATCH] [Form] [Validator] Add failing testcase to demonstrate group sequence issue When using group sequences on a form, sometimes constraints are ignored even though they should fail. --- .../FormValidatorFunctionalTest.php | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/Symfony/Component/Form/Tests/Extension/Validator/Constraints/FormValidatorFunctionalTest.php b/src/Symfony/Component/Form/Tests/Extension/Validator/Constraints/FormValidatorFunctionalTest.php index d4ca0cb1bf..f133eb20dc 100644 --- a/src/Symfony/Component/Form/Tests/Extension/Validator/Constraints/FormValidatorFunctionalTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/Validator/Constraints/FormValidatorFunctionalTest.php @@ -232,6 +232,34 @@ class FormValidatorFunctionalTest extends TestCase $this->assertInstanceOf(Length::class, $errors[0]->getCause()->getConstraint()); } + public function testConstraintsInDifferentGroupsOnSingleFieldWithAdditionalFieldThatHasNoConstraintsAddedBeforeTheFieldWithConstraints() + { + $form = $this->formFactory->create(FormType::class, null, [ + 'validation_groups' => new GroupSequence(['group1', 'group2']), + ]) + ->add('bar') + ->add('foo', TextType::class, [ + 'constraints' => [ + new NotBlank([ + 'groups' => ['group1'], + ]), + new Length([ + 'groups' => ['group2'], + 'max' => 3, + ]), + ], + ]); + $form->submit([ + 'foo' => 'test@example.com', + ]); + + $errors = $form->getErrors(true); + + $this->assertFalse($form->isValid()); + $this->assertCount(1, $errors); + $this->assertInstanceOf(Length::class, $errors[0]->getCause()->getConstraint()); + } + public function testCascadeValidationToChildFormsUsingPropertyPaths() { $form = $this->formFactory->create(FormType::class, null, [