1919use Symfony \Component \Form \Tests \Extension \Core \Type \FormTypeTest ;
2020use Symfony \Component \Form \Tests \Extension \Core \Type \TextTypeTest ;
2121use Symfony \Component \Form \Tests \Fixtures \Author ;
22- use Symfony \Component \OptionsResolver \Exception \InvalidOptionsException ;
2322use Symfony \Component \Form \Tests \Fixtures \AuthorType ;
2423use Symfony \Component \Form \Tests \Fixtures \Organization ;
24+ use Symfony \Component \OptionsResolver \Exception \InvalidOptionsException ;
2525use Symfony \Component \Validator \Constraints \GroupSequence ;
2626use Symfony \Component \Validator \Constraints \Length ;
2727use Symfony \Component \Validator \Constraints \NotBlank ;
@@ -192,21 +192,7 @@ public function testErrorPathOnCollections()
192192 ->setMetadataFactory ($ metadataFactory )
193193 ->getValidator ();
194194
195- $ form = Forms::createFormFactoryBuilder ()
196- ->addExtension (new ValidatorExtension ($ validator ))
197- ->getFormFactory ()
198- ->create (FormTypeTest::TESTED_TYPE ,new Organization ([]), [
199- 'data_class ' => Organization::class,
200- 'by_reference ' =>false ,
201- ])
202- ->add ('authors ' , CollectionTypeTest::TESTED_TYPE , [
203- 'entry_type ' => AuthorType::class,
204- 'allow_add ' =>true ,
205- 'allow_delete ' =>true ,
206- ])
207- ;
208-
209- $ form ->submit ([
195+ $ submitData = [
210196'authors ' => [
2111970 => [
212198'firstName ' =>'' ,// Fires a Not Blank Error
@@ -222,7 +208,23 @@ public function testErrorPathOnCollections()
222208'lastName ' =>'lastName3 ' ,
223209 ],
224210 ],
225- ]);
211+ ];
212+
213+ $ form = Forms::createFormFactoryBuilder ()
214+ ->addExtension (new ValidatorExtension ($ validator ))
215+ ->getFormFactory ()
216+ ->create (FormTypeTest::TESTED_TYPE ,new Organization ([]), [
217+ 'data_class ' => Organization::class,
218+ 'by_reference ' =>false ,
219+ ])
220+ ->add ('authors ' , CollectionTypeTest::TESTED_TYPE , [
221+ 'entry_type ' => AuthorType::class,
222+ 'allow_add ' =>true ,
223+ 'allow_delete ' =>true ,
224+ ])
225+ ;
226+
227+ $ form ->submit ($ submitData );
226228
227229//Form behaves right (...?). It has index 0, 2 and 3 (1 has been removed)
228230$ this ->assertTrue ($ form ->get ('authors ' )->has ('0 ' ));
@@ -242,11 +244,53 @@ public function testErrorPathOnCollections()
242244 ];
243245
244246$ this ->assertContains ('data.authors[0].firstName ' ,$ errorPaths );
245- $ this ->assertNotContains ('data.authors[1].firstName ' ,$ errorPaths );
247+ $ this ->assertContains ('data.authors[1].firstName ' ,$ errorPaths );
246248$ this ->assertContains ('data.authors[2].firstName ' ,$ errorPaths );
247- $ this ->assertContains ('data.authors[3].firstName ' ,$ errorPaths );
249+ $ this ->assertNotContains ('data.authors[3].firstName ' ,$ errorPaths );
248250
249251//In fact, root form should NOT contain errors but it does
252+ $ this ->assertCount (1 ,$ form ->getErrors (false ));
253+
254+ //Let's do this again, but with "keep_as_list" option set to true
255+ $ form = Forms::createFormFactoryBuilder ()
256+ ->addExtension (new ValidatorExtension ($ validator ))
257+ ->getFormFactory ()
258+ ->create (FormTypeTest::TESTED_TYPE ,new Organization ([]), [
259+ 'data_class ' => Organization::class,
260+ 'by_reference ' =>false ,
261+ ])
262+ ->add ('authors ' , CollectionTypeTest::TESTED_TYPE , [
263+ 'entry_type ' => AuthorType::class,
264+ 'allow_add ' =>true ,
265+ 'allow_delete ' =>true ,
266+ 'keep_as_list ' =>true ,
267+ ])
268+ ;
269+
270+ $ form ->submit ($ submitData );
271+
272+ //Errors paths are not messing up now
273+ $ this ->assertTrue ($ form ->get ('authors ' )->has ('0 ' ));
274+ $ this ->assertTrue ($ form ->get ('authors ' )->has ('1 ' ));
275+ $ this ->assertTrue ($ form ->get ('authors ' )->has ('2 ' ));
276+ $ this ->assertNotTrue ($ form ->get ('authors ' )->has ('3 ' ));
277+
278+ //Form does have 3 not blank errors
279+ $ errors =$ form ->getErrors (true );
280+ $ this ->assertCount (3 ,$ errors );
281+
282+ $ errorPaths = [
283+ $ errors [0 ]->getCause ()->getPropertyPath (),
284+ $ errors [1 ]->getCause ()->getPropertyPath (),
285+ $ errors [2 ]->getCause ()->getPropertyPath (),
286+ ];
287+
288+ $ this ->assertContains ('data.authors[0].firstName ' ,$ errorPaths );
289+ $ this ->assertContains ('data.authors[1].firstName ' ,$ errorPaths );
290+ $ this ->assertContains ('data.authors[2].firstName ' ,$ errorPaths );
291+ $ this ->assertNotContains ('data.authors[3].firstName ' ,$ errorPaths );
292+
293+ //Root form does NOT contain errors
250294$ this ->assertCount (0 ,$ form ->getErrors (false ));
251295 }
252296}