@@ -798,6 +798,81 @@ public function testValidateFormDataDoesNotWalkScalars()
798
798
DelegatingValidator::validateFormData ($ form , $ context );
799
799
}
800
800
801
+ public function testValidateFormChildren ()
802
+ {
803
+ $ graphWalker = $ this ->getMockGraphWalker ();
804
+ $ metadataFactory = $ this ->getMockMetadataFactory ();
805
+ $ context = new ExecutionContext ('Root ' , $ graphWalker , $ metadataFactory );
806
+ $ form = $ this ->getBuilder ()
807
+ ->setAttribute ('cascade_validation ' , true )
808
+ ->setAttribute ('validation_groups ' , array ('group1 ' , 'group2 ' ))
809
+ ->getForm ();
810
+ $ form ->add ($ this ->getForm ('firstName ' ));
811
+
812
+ $ graphWalker ->expects ($ this ->at (0 ))
813
+ ->method ('walkReference ' )
814
+ ->with ($ form ->getChildren (), 'group1 ' , 'children ' , true );
815
+ $ graphWalker ->expects ($ this ->at (1 ))
816
+ ->method ('walkReference ' )
817
+ ->with ($ form ->getChildren (), 'group2 ' , 'children ' , true );
818
+
819
+ DelegatingValidator::validateFormChildren ($ form , $ context );
820
+ }
821
+
822
+ public function testValidateFormChildrenAppendsPropertyPath ()
823
+ {
824
+ $ graphWalker = $ this ->getMockGraphWalker ();
825
+ $ metadataFactory = $ this ->getMockMetadataFactory ();
826
+ $ context = new ExecutionContext ('Root ' , $ graphWalker , $ metadataFactory );
827
+ $ context ->setPropertyPath ('path ' );
828
+ $ form = $ this ->getBuilder ()
829
+ ->setAttribute ('cascade_validation ' , true )
830
+ ->getForm ();
831
+ $ form ->add ($ this ->getForm ('firstName ' ));
832
+
833
+ $ graphWalker ->expects ($ this ->once ())
834
+ ->method ('walkReference ' )
835
+ ->with ($ form ->getChildren (), 'Default ' , 'path.children ' , true );
836
+
837
+ DelegatingValidator::validateFormChildren ($ form , $ context );
838
+ }
839
+
840
+ public function testValidateFormChildrenSetsCurrentPropertyToData ()
841
+ {
842
+ $ graphWalker = $ this ->getMockGraphWalker ();
843
+ $ metadataFactory = $ this ->getMockMetadataFactory ();
844
+ $ context = new ExecutionContext ('Root ' , $ graphWalker , $ metadataFactory );
845
+ $ form = $ this ->getBuilder ()
846
+ ->setAttribute ('cascade_validation ' , true )
847
+ ->getForm ();
848
+ $ form ->add ($ this ->getForm ('firstName ' ));
849
+ $ test = $ this ;
850
+
851
+ $ graphWalker ->expects ($ this ->once ())
852
+ ->method ('walkReference ' )
853
+ ->will ($ this ->returnCallback (function () use ($ context , $ test ) {
854
+ $ test ->assertEquals ('children ' , $ context ->getCurrentProperty ());
855
+ }));
856
+
857
+ DelegatingValidator::validateFormChildren ($ form , $ context );
858
+ }
859
+
860
+ public function testValidateFormChildrenDoesNothingIfDisabled ()
861
+ {
862
+ $ graphWalker = $ this ->getMockGraphWalker ();
863
+ $ metadataFactory = $ this ->getMockMetadataFactory ();
864
+ $ context = new ExecutionContext ('Root ' , $ graphWalker , $ metadataFactory );
865
+ $ form = $ this ->getBuilder ()
866
+ ->setAttribute ('cascade_validation ' , false )
867
+ ->getForm ();
868
+ $ form ->add ($ this ->getForm ('firstName ' ));
869
+
870
+ $ graphWalker ->expects ($ this ->never ())
871
+ ->method ('walkReference ' );
872
+
873
+ DelegatingValidator::validateFormChildren ($ form , $ context );
874
+ }
875
+
801
876
public function testValidateIgnoresNonRoot ()
802
877
{
803
878
$ form = $ this ->getMockForm ();
0 commit comments