@@ -342,6 +342,117 @@ 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
+
365
+ $ this ->dataExtractor ->expects ($ this ->at (0 ))
366
+ ->method ('extractConfiguration ' )
367
+ ->with ($ form1 )
368
+ ->will ($ this ->returnValue (array ('config ' =>'foo ' )));
369
+ $ this ->dataExtractor ->expects ($ this ->at (1 ))
370
+ ->method ('extractConfiguration ' )
371
+ ->with ($ child1 )
372
+ ->will ($ this ->returnValue (array ('config ' =>'bar ' )));
373
+
374
+ $ this ->dataExtractor ->expects ($ this ->at (2 ))
375
+ ->method ('extractDefaultData ' )
376
+ ->with ($ form1 )
377
+ ->will ($ this ->returnValue (array ('default_data ' =>'foo ' )));
378
+ $ this ->dataExtractor ->expects ($ this ->at (3 ))
379
+ ->method ('extractDefaultData ' )
380
+ ->with ($ child1 )
381
+ ->will ($ this ->returnValue (array ('default_data ' =>'bar ' )));
382
+
383
+ $ this ->dataExtractor ->expects ($ this ->at (4 ))
384
+ ->method ('extractSubmittedData ' )
385
+ ->with ($ form1 )
386
+ ->will ($ this ->returnValue (array ('submitted_data ' =>'foo ' )));
387
+ $ this ->dataExtractor ->expects ($ this ->at (5 ))
388
+ ->method ('extractSubmittedData ' )
389
+ ->with ($ child1 )
390
+ ->will ($ this ->returnValue (array ('submitted_data ' =>'bar ' )));
391
+
392
+ $ this ->dataExtractor ->expects ($ this ->at (6 ))
393
+ ->method ('extractViewVariables ' )
394
+ ->with ($ form1View )
395
+ ->will ($ this ->returnValue (array ('view_vars ' =>'foo ' )));
396
+
397
+ $ this ->dataExtractor ->expects ($ this ->at (7 ))
398
+ ->method ('extractViewVariables ' )
399
+ ->with ($ child1View )
400
+ ->will ($ this ->returnValue (array ('view_vars ' =>$ child1View ->vars )));
401
+
402
+
403
+ $ this ->dataExtractor ->expects ($ this ->at (8 ))
404
+ ->method ('extractConfiguration ' )
405
+ ->with ($ form2 )
406
+ ->will ($ this ->returnValue (array ('config ' =>'foo ' )));
407
+ $ this ->dataExtractor ->expects ($ this ->at (9 ))
408
+ ->method ('extractConfiguration ' )
409
+ ->with ($ child1 )
410
+ ->will ($ this ->returnValue (array ('config ' =>'bar ' )));
411
+
412
+ $ this ->dataExtractor ->expects ($ this ->at (10 ))
413
+ ->method ('extractDefaultData ' )
414
+ ->with ($ form2 )
415
+ ->will ($ this ->returnValue (array ('default_data ' =>'foo ' )));
416
+ $ this ->dataExtractor ->expects ($ this ->at (11 ))
417
+ ->method ('extractDefaultData ' )
418
+ ->with ($ child1 )
419
+ ->will ($ this ->returnValue (array ('default_data ' =>'bar ' )));
420
+
421
+ $ this ->dataExtractor ->expects ($ this ->at (12 ))
422
+ ->method ('extractSubmittedData ' )
423
+ ->with ($ form2 )
424
+ ->will ($ this ->returnValue (array ('submitted_data ' =>'foo ' )));
425
+ $ this ->dataExtractor ->expects ($ this ->at (13 ))
426
+ ->method ('extractSubmittedData ' )
427
+ ->with ($ child1 )
428
+ ->will ($ this ->returnValue (array ('submitted_data ' =>'bar ' )));
429
+
430
+ $ this ->dataExtractor ->expects ($ this ->at (14 ))
431
+ ->method ('extractViewVariables ' )
432
+ ->with ($ form2View )
433
+ ->will ($ this ->returnValue (array ('view_vars ' =>'foo ' )));
434
+
435
+ $ this ->dataExtractor ->expects ($ this ->at (15 ))
436
+ ->method ('extractViewVariables ' )
437
+ ->with ($ child1View )
438
+ ->will ($ this ->returnValue (array ('view_vars ' =>$ child1View ->vars )));
439
+
440
+
441
+ $ this ->dataCollector ->collectConfiguration ($ form1 );
442
+ $ this ->dataCollector ->collectDefaultData ($ form1 );
443
+ $ this ->dataCollector ->collectSubmittedData ($ form1 );
444
+ $ this ->dataCollector ->collectViewVariables ($ form1View );
445
+ $ this ->dataCollector ->buildFinalFormTree ($ form1 ,$ form1View );
446
+
447
+ $ this ->dataCollector ->collectConfiguration ($ form2 );
448
+ $ this ->dataCollector ->collectDefaultData ($ form2 );
449
+ $ this ->dataCollector ->collectSubmittedData ($ form2 );
450
+ $ this ->dataCollector ->collectViewVariables ($ form2View );
451
+ $ this ->dataCollector ->buildFinalFormTree ($ form2 ,$ form2View );
452
+
453
+ $ this ->dataCollector ->serialize ();
454
+ }
455
+
345
456
public function testFinalFormReliesOnFormViewStructure ()
346
457
{
347
458
$ this ->form ->add ($ child1 =$ this ->createForm ('first ' ));