[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.
This commit is contained in:
Johan de Ruijter 2020-09-25 11:24:52 +02:00 committed by Christian Flothmann
parent 1b6894781c
commit e2c7c3373d
1 changed files with 28 additions and 0 deletions

View File

@ -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, [