@@ -342,6 +342,115 @@ public function testBuildFinalFormTree()
342
342
),$ this ->dataCollector ->getData ());
343
343
}
344
344
345
+ public function testSerializeWithFormAddedMultipleTimes ()
346
+ {
347
+ $ form1 =$ this ->createForm ('form1 ' );
348
+ $ form2 =$ this ->createForm ('form2 ' );
349
+ $ child1 =$ this ->createForm ('child1 ' );
350
+
351
+ $ form1View =new FormView ();
352
+ $ form2View =new FormView ();
353
+ $ child1View =new FormView ();
354
+ $ child1View ->vars ['is_selected ' ] =function ($ choice ,array $ values ) {
355
+ return in_array ($ choice ,$ values ,true );
356
+ };
357
+
358
+ $ form1 ->add ($ child1 );
359
+ $ form2 ->add ($ child1 );
360
+
361
+ $ form1View ->children ['child1 ' ] =$ child1View ;
362
+ $ form2View ->children ['child1 ' ] =$ child1View ;
363
+
364
+ $ this ->dataExtractor ->expects ($ this ->at (0 ))
365
+ ->method ('extractConfiguration ' )
366
+ ->with ($ form1 )
367
+ ->will ($ this ->returnValue (array ('config ' =>'foo ' )));
368
+ $ this ->dataExtractor ->expects ($ this ->at (1 ))
369
+ ->method ('extractConfiguration ' )
370
+ ->with ($ child1 )
371
+ ->will ($ this ->returnValue (array ('config ' =>'bar ' )));
372
+
373
+ $ this ->dataExtractor ->expects ($ this ->at (2 ))
374
+ ->method ('extractDefaultData ' )
375
+ ->with ($ form1 )
376
+ ->will ($ this ->returnValue (array ('default_data ' =>'foo ' )));
377
+ $ this ->dataExtractor ->expects ($ this ->at (3 ))
378
+ ->method ('extractDefaultData ' )
379
+ ->with ($ child1 )
380
+ ->will ($ this ->returnValue (array ('default_data ' =>'bar ' )));
381
+
382
+ $ this ->dataExtractor ->expects ($ this ->at (4 ))
383
+ ->method ('extractSubmittedData ' )
384
+ ->with ($ form1 )
385
+ ->will ($ this ->returnValue (array ('submitted_data ' =>'foo ' )));
386
+ $ this ->dataExtractor ->expects ($ this ->at (5 ))
387
+ ->method ('extractSubmittedData ' )
388
+ ->with ($ child1 )
389
+ ->will ($ this ->returnValue (array ('submitted_data ' =>'bar ' )));
390
+
391
+ $ this ->dataExtractor ->expects ($ this ->at (6 ))
392
+ ->method ('extractViewVariables ' )
393
+ ->with ($ form1View )
394
+ ->will ($ this ->returnValue (array ('view_vars ' =>'foo ' )));
395
+
396
+ $ this ->dataExtractor ->expects ($ this ->at (7 ))
397
+ ->method ('extractViewVariables ' )
398
+ ->with ($ child1View )
399
+ ->will ($ this ->returnValue (array ('view_vars ' =>$ child1View ->vars )));
400
+
401
+
402
+ $ this ->dataExtractor ->expects ($ this ->at (8 ))
403
+ ->method ('extractConfiguration ' )
404
+ ->with ($ form2 )
405
+ ->will ($ this ->returnValue (array ('config ' =>'foo ' )));
406
+ $ this ->dataExtractor ->expects ($ this ->at (9 ))
407
+ ->method ('extractConfiguration ' )
408
+ ->with ($ child1 )
409
+ ->will ($ this ->returnValue (array ('config ' =>'bar ' )));
410
+
411
+ $ this ->dataExtractor ->expects ($ this ->at (10 ))
412
+ ->method ('extractDefaultData ' )
413
+ ->with ($ form2 )
414
+ ->will ($ this ->returnValue (array ('default_data ' =>'foo ' )));
415
+ $ this ->dataExtractor ->expects ($ this ->at (11 ))
416
+ ->method ('extractDefaultData ' )
417
+ ->with ($ child1 )
418
+ ->will ($ this ->returnValue (array ('default_data ' =>'bar ' )));
419
+
420
+ $ this ->dataExtractor ->expects ($ this ->at (12 ))
421
+ ->method ('extractSubmittedData ' )
422
+ ->with ($ form2 )
423
+ ->will ($ this ->returnValue (array ('submitted_data ' =>'foo ' )));
424
+ $ this ->dataExtractor ->expects ($ this ->at (13 ))
425
+ ->method ('extractSubmittedData ' )
426
+ ->with ($ child1 )
427
+ ->will ($ this ->returnValue (array ('submitted_data ' =>'bar ' )));
428
+
429
+ $ this ->dataExtractor ->expects ($ this ->at (14 ))
430
+ ->method ('extractViewVariables ' )
431
+ ->with ($ form2View )
432
+ ->will ($ this ->returnValue (array ('view_vars ' =>'foo ' )));
433
+
434
+ $ this ->dataExtractor ->expects ($ this ->at (15 ))
435
+ ->method ('extractViewVariables ' )
436
+ ->with ($ child1View )
437
+ ->will ($ this ->returnValue (array ('view_vars ' =>$ child1View ->vars )));
438
+
439
+ $ this ->dataCollector ->collectConfiguration ($ form1 );
440
+ $ this ->dataCollector ->collectDefaultData ($ form1 );
441
+ $ this ->dataCollector ->collectSubmittedData ($ form1 );
442
+ $ this ->dataCollector ->collectViewVariables ($ form1View );
443
+ $ this ->dataCollector ->buildFinalFormTree ($ form1 ,$ form1View );
444
+
445
+ $ this ->dataCollector ->collectConfiguration ($ form2 );
446
+ $ this ->dataCollector ->collectDefaultData ($ form2 );
447
+ $ this ->dataCollector ->collectSubmittedData ($ form2 );
448
+ $ this ->dataCollector ->collectViewVariables ($ form2View );
449
+ $ this ->dataCollector ->buildFinalFormTree ($ form2 ,$ form2View );
450
+
451
+ $ this ->dataCollector ->serialize ();
452
+ }
453
+
345
454
public function testFinalFormReliesOnFormViewStructure ()
346
455
{
347
456
$ this ->form ->add ($ child1 =$ this ->createForm ('first ' ));