@@ -275,4 +275,51 @@ public function testOnSubmitDealsWithArrayBackedIteratorAggregate()
275
275
$ this ->assertArrayNotHasKey (0 , $ event ->getData ());
276
276
$ this ->assertArrayNotHasKey (2 , $ event ->getData ());
277
277
}
278
+
279
+ public function testOnSubmitDeleteEmptyNotCompoundEntriesIfAllowDelete ()
280
+ {
281
+ $ this ->form ->setData (array ('0 ' => 'first ' , '1 ' => 'second ' ));
282
+ $ this ->form ->add ($ this ->getForm ('0 ' ));
283
+ $ this ->form ->add ($ this ->getForm ('1 ' ));
284
+
285
+ $ data = array (0 => 'first ' , 1 => '' );
286
+ foreach ($ data as $ child => $ dat ) {
287
+ $ this ->form ->get ($ child )->setData ($ dat );
288
+ }
289
+ $ event = new FormEvent ($ this ->form , $ data );
290
+ $ listener = new ResizeFormListener ('text ' , array (), false , true , true );
291
+ $ listener ->onSubmit ($ event );
292
+
293
+ $ this ->assertEquals (array (0 => 'first ' ), $ event ->getData ());
294
+ }
295
+
296
+ public function testOnSubmitDeleteEmptyCompoundEntriesIfAllowDelete ()
297
+ {
298
+ $ this ->form ->setData (array ('0 ' => array ('name ' => 'John ' ), '1 ' => array ('name ' => 'Jane ' )));
299
+ $ form1 = $ this ->getBuilder ('0 ' )
300
+ ->setCompound (true )
301
+ ->setDataMapper ($ this ->getDataMapper ())
302
+ ->getForm ();
303
+ $ form1 ->add ($ this ->getForm ('name ' ));
304
+ $ form2 = $ this ->getBuilder ('1 ' )
305
+ ->setCompound (true )
306
+ ->setDataMapper ($ this ->getDataMapper ())
307
+ ->getForm ();
308
+ $ form2 ->add ($ this ->getForm ('name ' ));
309
+ $ this ->form ->add ($ form1 );
310
+ $ this ->form ->add ($ form2 );
311
+
312
+ $ data = array ('0 ' => array ('name ' => 'John ' ), '1 ' => array ('name ' => '' ));
313
+ foreach ($ data as $ child => $ dat ) {
314
+ $ this ->form ->get ($ child )->setData ($ dat );
315
+ }
316
+ $ event = new FormEvent ($ this ->form , $ data );
317
+ $ callback = function ($ data ) {
318
+ return '' === $ data ['name ' ];
319
+ };
320
+ $ listener = new ResizeFormListener ('text ' , array (), false , true , $ callback );
321
+ $ listener ->onSubmit ($ event );
322
+
323
+ $ this ->assertEquals (array ('0 ' => array ('name ' => 'John ' )), $ event ->getData ());
324
+ }
278
325
}
0 commit comments