@@ -342,6 +342,114 @@ 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
+ $ this ->dataExtractor ->expects ($ this ->at (8 ))
402
+ ->method ('extractConfiguration ' )
403
+ ->with ($ form2 )
404
+ ->will ($ this ->returnValue (array ('config ' => 'foo ' )));
405
+ $ this ->dataExtractor ->expects ($ this ->at (9 ))
406
+ ->method ('extractConfiguration ' )
407
+ ->with ($ child1 )
408
+ ->will ($ this ->returnValue (array ('config ' => 'bar ' )));
409
+
410
+ $ this ->dataExtractor ->expects ($ this ->at (10 ))
411
+ ->method ('extractDefaultData ' )
412
+ ->with ($ form2 )
413
+ ->will ($ this ->returnValue (array ('default_data ' => 'foo ' )));
414
+ $ this ->dataExtractor ->expects ($ this ->at (11 ))
415
+ ->method ('extractDefaultData ' )
416
+ ->with ($ child1 )
417
+ ->will ($ this ->returnValue (array ('default_data ' => 'bar ' )));
418
+
419
+ $ this ->dataExtractor ->expects ($ this ->at (12 ))
420
+ ->method ('extractSubmittedData ' )
421
+ ->with ($ form2 )
422
+ ->will ($ this ->returnValue (array ('submitted_data ' => 'foo ' )));
423
+ $ this ->dataExtractor ->expects ($ this ->at (13 ))
424
+ ->method ('extractSubmittedData ' )
425
+ ->with ($ child1 )
426
+ ->will ($ this ->returnValue (array ('submitted_data ' => 'bar ' )));
427
+
428
+ $ this ->dataExtractor ->expects ($ this ->at (14 ))
429
+ ->method ('extractViewVariables ' )
430
+ ->with ($ form2View )
431
+ ->will ($ this ->returnValue (array ('view_vars ' => 'foo ' )));
432
+
433
+ $ this ->dataExtractor ->expects ($ this ->at (15 ))
434
+ ->method ('extractViewVariables ' )
435
+ ->with ($ child1View )
436
+ ->will ($ this ->returnValue (array ('view_vars ' => $ child1View ->vars )));
437
+
438
+ $ this ->dataCollector ->collectConfiguration ($ form1 );
439
+ $ this ->dataCollector ->collectDefaultData ($ form1 );
440
+ $ this ->dataCollector ->collectSubmittedData ($ form1 );
441
+ $ this ->dataCollector ->collectViewVariables ($ form1View );
442
+ $ this ->dataCollector ->buildFinalFormTree ($ form1 , $ form1View );
443
+
444
+ $ this ->dataCollector ->collectConfiguration ($ form2 );
445
+ $ this ->dataCollector ->collectDefaultData ($ form2 );
446
+ $ this ->dataCollector ->collectSubmittedData ($ form2 );
447
+ $ this ->dataCollector ->collectViewVariables ($ form2View );
448
+ $ this ->dataCollector ->buildFinalFormTree ($ form2 , $ form2View );
449
+
450
+ $ this ->dataCollector ->serialize ();
451
+ }
452
+
345
453
public function testFinalFormReliesOnFormViewStructure ()
346
454
{
347
455
$ this ->form ->add ($ child1 = $ this ->createForm ('first ' ));
0 commit comments