[Form] Preventing validation of children if parent with Valid constraint has no validation groups

This commit is contained in:
Marek Štípek 2019-03-18 21:30:37 +01:00
parent 42c08b8966
commit f45f0d03fc
2 changed files with 27 additions and 0 deletions

View File

@ -44,6 +44,11 @@ class FormValidator extends ConstraintValidator
if ($form->isSubmitted() && $form->isSynchronized()) {
// Validate the form data only if transformation succeeded
$groups = self::getValidationGroups($form);
if (!$groups) {
return;
}
$data = $form->getData();
// Validate the data against its own constraints

View File

@ -220,6 +220,28 @@ class FormValidatorTest extends ConstraintValidatorTestCase
$this->assertNoViolation();
}
public function testDontValidateChildConstraintsIfCallableNoValidationGroups()
{
$formOptions = [
'constraints' => [new Valid()],
'validation_groups' => [],
];
$form = $this->getBuilder('name', null, $formOptions)
->setCompound(true)
->setDataMapper(new PropertyPathMapper())
->getForm();
$childOptions = ['constraints' => [new NotBlank()]];
$child = $this->getCompoundForm(new \stdClass(), $childOptions);
$form->add($child);
$form->submit([]);
$this->expectNoValidate();
$this->validator->validate($form, new Form());
$this->assertNoViolation();
}
public function testDontValidateIfNotSynchronized()
{
$object = new \stdClass();