@@ -175,21 +175,7 @@ public function testErrorPathOnCollections()
175
175
->setMetadataFactory ($ metadataFactory )
176
176
->getValidator ();
177
177
178
- $ form = Forms::createFormFactoryBuilder ()
179
- ->addExtension (new ValidatorExtension ($ validator ))
180
- ->getFormFactory ()
181
- ->create (FormTypeTest::TESTED_TYPE , new Organization ([]), [
182
- 'data_class ' => Organization::class,
183
- 'by_reference ' => false ,
184
- ])
185
- ->add ('authors ' , CollectionTypeTest::TESTED_TYPE , [
186
- 'entry_type ' => AuthorType::class,
187
- 'allow_add ' => true ,
188
- 'allow_delete ' => true ,
189
- ])
190
- ;
191
-
192
- $ form ->submit ([
178
+ $ submitData = [
193
179
'authors ' => [
194
180
0 => [
195
181
'firstName ' => '' , // Fires a Not Blank Error
@@ -205,7 +191,23 @@ public function testErrorPathOnCollections()
205
191
'lastName ' => 'lastName3 ' ,
206
192
],
207
193
],
208
- ]);
194
+ ];
195
+
196
+ $ form = Forms::createFormFactoryBuilder ()
197
+ ->addExtension (new ValidatorExtension ($ validator ))
198
+ ->getFormFactory ()
199
+ ->create (FormTypeTest::TESTED_TYPE , new Organization ([]), [
200
+ 'data_class ' => Organization::class,
201
+ 'by_reference ' => false ,
202
+ ])
203
+ ->add ('authors ' , CollectionTypeTest::TESTED_TYPE , [
204
+ 'entry_type ' => AuthorType::class,
205
+ 'allow_add ' => true ,
206
+ 'allow_delete ' => true ,
207
+ ])
208
+ ;
209
+
210
+ $ form ->submit ($ submitData );
209
211
210
212
//Form behaves right (...?). It has index 0, 2 and 3 (1 has been removed)
211
213
$ this ->assertTrue ($ form ->get ('authors ' )->has ('0 ' ));
@@ -225,11 +227,53 @@ public function testErrorPathOnCollections()
225
227
];
226
228
227
229
$ this ->assertContains ('data.authors[0].firstName ' , $ errorPaths );
228
- $ this ->assertNotContains ('data.authors[1].firstName ' , $ errorPaths );
230
+ $ this ->assertContains ('data.authors[1].firstName ' , $ errorPaths );
229
231
$ this ->assertContains ('data.authors[2].firstName ' , $ errorPaths );
230
- $ this ->assertContains ('data.authors[3].firstName ' , $ errorPaths );
232
+ $ this ->assertNotContains ('data.authors[3].firstName ' , $ errorPaths );
231
233
232
234
//In fact, root form should NOT contain errors but it does
235
+ $ this ->assertCount (1 , $ form ->getErrors (false ));
236
+
237
+ //Let's to this again, but with new "reindex_on_submit" option set to true
238
+ $ form = Forms::createFormFactoryBuilder ()
239
+ ->addExtension (new ValidatorExtension ($ validator ))
240
+ ->getFormFactory ()
241
+ ->create (FormTypeTest::TESTED_TYPE , new Organization ([]), [
242
+ 'data_class ' => Organization::class,
243
+ 'by_reference ' => false ,
244
+ ])
245
+ ->add ('authors ' , CollectionTypeTest::TESTED_TYPE , [
246
+ 'entry_type ' => AuthorType::class,
247
+ 'allow_add ' => true ,
248
+ 'allow_delete ' => true ,
249
+ 'reindex_on_submit ' => true ,
250
+ ])
251
+ ;
252
+
253
+ $ form ->submit ($ submitData );
254
+
255
+ //Errors paths are not messing up now, because we reindexed the form on submit
256
+ $ this ->assertTrue ($ form ->get ('authors ' )->has ('0 ' ));
257
+ $ this ->assertTrue ($ form ->get ('authors ' )->has ('1 ' ));
258
+ $ this ->assertTrue ($ form ->get ('authors ' )->has ('2 ' ));
259
+ $ this ->assertNotTrue ($ form ->get ('authors ' )->has ('3 ' ));
260
+
261
+ //Form does have 3 not blank errors
262
+ $ errors = $ form ->getErrors (true );
263
+ $ this ->assertCount (3 , $ errors );
264
+
265
+ $ errorPaths = [
266
+ $ errors [0 ]->getCause ()->getPropertyPath (),
267
+ $ errors [1 ]->getCause ()->getPropertyPath (),
268
+ $ errors [2 ]->getCause ()->getPropertyPath (),
269
+ ];
270
+
271
+ $ this ->assertContains ('data.authors[0].firstName ' , $ errorPaths );
272
+ $ this ->assertContains ('data.authors[1].firstName ' , $ errorPaths );
273
+ $ this ->assertContains ('data.authors[2].firstName ' , $ errorPaths );
274
+ $ this ->assertNotContains ('data.authors[3].firstName ' , $ errorPaths );
275
+
276
+ //Root form does NOT contain errors
233
277
$ this ->assertCount (0 , $ form ->getErrors (false ));
234
278
}
235
279
}
0 commit comments