|
15 | 15 | use Symfony\Component\Form\AbstractType;
|
16 | 16 | use Symfony\Component\Form\CallbackTransformer;
|
17 | 17 | use Symfony\Component\Form\Exception\TransformationFailedException;
|
| 18 | +use Symfony\Component\Form\Extension\Core\Type\CollectionType; |
18 | 19 | use Symfony\Component\Form\Extension\Core\Type\DateType;
|
19 | 20 | use Symfony\Component\Form\Extension\Core\Type\FormType;
|
20 | 21 | use Symfony\Component\Form\Extension\Core\Type\IntegerType;
|
@@ -321,6 +322,35 @@ public function testCascadeValidationToChildFormsWithTwoValidConstraints2()
|
321 | 322 | $this->assertSame('children[author].data.email', $violations[1]->getPropertyPath());
|
322 | 323 | }
|
323 | 324 |
|
| 325 | + public function testCascadeValidationToArrayChildForm() |
| 326 | + { |
| 327 | + $form = $this->formFactory->create(FormType::class, null, [ |
| 328 | + 'data_class' => Review::class, |
| 329 | + ]) |
| 330 | + ->add('title') |
| 331 | + ->add('customers', CollectionType::class, [ |
| 332 | + 'mapped' => false, |
| 333 | + 'entry_type' => CustomerType::class, |
| 334 | + 'allow_add' => true, |
| 335 | + 'constraints' => [new Valid()], |
| 336 | + ]); |
| 337 | + |
| 338 | + $form->submit([ |
| 339 | + 'title' => 'Sample Title', |
| 340 | + 'customers' => [ |
| 341 | + ['email' => null], |
| 342 | + ], |
| 343 | + ]); |
| 344 | + |
| 345 | + $violations = $this->validator->validate($form); |
| 346 | + |
| 347 | + $this->assertCount(2, $violations); |
| 348 | + $this->assertSame('This value should not be blank.', $violations[0]->getMessage()); |
| 349 | + $this->assertSame('data.rating', $violations[0]->getPropertyPath()); |
| 350 | + $this->assertSame('This value should not be blank.', $violations[1]->getMessage()); |
| 351 | + $this->assertSame('children[customers].data[0].email', $violations[1]->getPropertyPath()); |
| 352 | + } |
| 353 | + |
324 | 354 | public function testCascadeValidationToChildFormsUsingPropertyPathsValidatedInSequence()
|
325 | 355 | {
|
326 | 356 | $form = $this->formFactory->create(FormType::class, null, [
|
|
0 commit comments