|
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;
|
@@ -328,6 +329,35 @@ public function testCascadeValidationToChildFormsWithTwoValidConstraints2()
|
328 | 329 | $this->assertSame('children[author].data.email', $violations[1]->getPropertyPath());
|
329 | 330 | }
|
330 | 331 |
|
| 332 | + public function testCascadeValidationToArrayChildForm() |
| 333 | + { |
| 334 | + $form = $this->formFactory->create(FormType::class, null, [ |
| 335 | + 'data_class' => Review::class, |
| 336 | + ]) |
| 337 | + ->add('title') |
| 338 | + ->add('customers', CollectionType::class, [ |
| 339 | + 'mapped' => false, |
| 340 | + 'entry_type' => CustomerType::class, |
| 341 | + 'allow_add' => true, |
| 342 | + 'constraints' => [new Valid()] |
| 343 | + ]); |
| 344 | + |
| 345 | + $form->submit([ |
| 346 | + 'title' => 'Sample Title', |
| 347 | + 'customers' => [ |
| 348 | + ['email' => null], |
| 349 | + ], |
| 350 | + ]); |
| 351 | + |
| 352 | + $violations = $this->validator->validate($form); |
| 353 | + |
| 354 | + $this->assertCount(2, $violations); |
| 355 | + $this->assertSame('This value should not be blank.', $violations[0]->getMessage()); |
| 356 | + $this->assertSame('data.rating', $violations[0]->getPropertyPath()); |
| 357 | + $this->assertSame('This value should not be blank.', $violations[1]->getMessage()); |
| 358 | + $this->assertSame('children[customers].data[0].email', $violations[1]->getPropertyPath()); |
| 359 | + } |
| 360 | + |
331 | 361 | public function testCascadeValidationToChildFormsUsingPropertyPathsValidatedInSequence()
|
332 | 362 | {
|
333 | 363 | $form = $this->formFactory->create(FormType::class, null, [
|
|
0 commit comments