@@ -704,151 +704,6 @@ public function testCauseForNotAllowedExtraFieldsIsTheFormConstraint()
704
704
$ this ->assertSame ($ constraint , $ context ->getViolations ()->get (0 )->getConstraint ());
705
705
}
706
706
707
- public function testNonCompositeConstraintValidatedOnce ()
708
- {
709
- $ form = $ this
710
- ->getBuilder ('form ' , null , [
711
- 'constraints ' => [new NotBlank (['groups ' => ['foo ' , 'bar ' ]])],
712
- 'validation_groups ' => ['foo ' , 'bar ' ],
713
- ])
714
- ->setCompound (false )
715
- ->getForm ();
716
- $ form ->submit ('' );
717
-
718
- $ context = new ExecutionContext (Validation::createValidator (), $ form , new IdentityTranslator ());
719
- $ this ->validator ->initialize ($ context );
720
- $ this ->validator ->validate ($ form , new Form ());
721
-
722
- $ this ->assertCount (1 , $ context ->getViolations ());
723
- $ this ->assertSame ('This value should not be blank. ' , $ context ->getViolations ()[0 ]->getMessage ());
724
- $ this ->assertSame ('data ' , $ context ->getViolations ()[0 ]->getPropertyPath ());
725
- }
726
-
727
- public function testCompositeConstraintValidatedInEachGroup ()
728
- {
729
- $ form = $ this ->getBuilder ('form ' , null , [
730
- 'constraints ' => [
731
- new Collection ([
732
- 'field1 ' => new NotBlank ([
733
- 'groups ' => ['field1 ' ],
734
- ]),
735
- 'field2 ' => new NotBlank ([
736
- 'groups ' => ['field2 ' ],
737
- ]),
738
- ]),
739
- ],
740
- 'validation_groups ' => ['field1 ' , 'field2 ' ],
741
- ])
742
- ->setData ([])
743
- ->setCompound (true )
744
- ->setDataMapper (new PropertyPathMapper ())
745
- ->getForm ();
746
- $ form ->add ($ this ->getForm ('field1 ' ));
747
- $ form ->add ($ this ->getForm ('field2 ' ));
748
- $ form ->submit ([
749
- 'field1 ' => '' ,
750
- 'field2 ' => '' ,
751
- ]);
752
-
753
- $ context = new ExecutionContext (Validation::createValidator (), $ form , new IdentityTranslator ());
754
- $ this ->validator ->initialize ($ context );
755
- $ this ->validator ->validate ($ form , new Form ());
756
-
757
- $ this ->assertCount (2 , $ context ->getViolations ());
758
- $ this ->assertSame ('This value should not be blank. ' , $ context ->getViolations ()[0 ]->getMessage ());
759
- $ this ->assertSame ('data[field1] ' , $ context ->getViolations ()[0 ]->getPropertyPath ());
760
- $ this ->assertSame ('This value should not be blank. ' , $ context ->getViolations ()[1 ]->getMessage ());
761
- $ this ->assertSame ('data[field2] ' , $ context ->getViolations ()[1 ]->getPropertyPath ());
762
- }
763
-
764
- public function testCompositeConstraintValidatedInSequence ()
765
- {
766
- $ form = $ this ->getCompoundForm ([], [
767
- 'constraints ' => [
768
- new Collection ([
769
- 'field1 ' => new NotBlank ([
770
- 'groups ' => ['field1 ' ],
771
- ]),
772
- 'field2 ' => new NotBlank ([
773
- 'groups ' => ['field2 ' ],
774
- ]),
775
- ]),
776
- ],
777
- 'validation_groups ' => new GroupSequence (['field1 ' , 'field2 ' ]),
778
- ])
779
- ->add ($ this ->getForm ('field1 ' ))
780
- ->add ($ this ->getForm ('field2 ' ))
781
- ;
782
-
783
- $ form ->submit ([
784
- 'field1 ' => '' ,
785
- 'field2 ' => '' ,
786
- ]);
787
-
788
- $ context = new ExecutionContext (Validation::createValidator (), $ form , new IdentityTranslator ());
789
- $ this ->validator ->initialize ($ context );
790
- $ this ->validator ->validate ($ form , new Form ());
791
-
792
- $ this ->assertCount (1 , $ context ->getViolations ());
793
- $ this ->assertSame ('This value should not be blank. ' , $ context ->getViolations ()[0 ]->getMessage ());
794
- $ this ->assertSame ('data[field1] ' , $ context ->getViolations ()[0 ]->getPropertyPath ());
795
- }
796
-
797
- public function testCascadeValidationToChildFormsUsingPropertyPaths ()
798
- {
799
- $ form = $ this ->getCompoundForm ([], [
800
- 'validation_groups ' => ['group1 ' , 'group2 ' ],
801
- ])
802
- ->add ('field1 ' , null , [
803
- 'constraints ' => [new NotBlank (['groups ' => 'group1 ' ])],
804
- 'property_path ' => '[foo] ' ,
805
- ])
806
- ->add ('field2 ' , null , [
807
- 'constraints ' => [new NotBlank (['groups ' => 'group2 ' ])],
808
- 'property_path ' => '[bar] ' ,
809
- ])
810
- ;
811
-
812
- $ form ->submit ([
813
- 'field1 ' => '' ,
814
- 'field2 ' => '' ,
815
- ]);
816
-
817
- $ context = new ExecutionContext (Validation::createValidator (), $ form , new IdentityTranslator ());
818
- $ this ->validator ->initialize ($ context );
819
- $ this ->validator ->validate ($ form , new Form ());
820
-
821
- $ this ->assertCount (2 , $ context ->getViolations ());
822
- $ this ->assertSame ('This value should not be blank. ' , $ context ->getViolations ()[0 ]->getMessage ());
823
- $ this ->assertSame ('children[field1].data ' , $ context ->getViolations ()[0 ]->getPropertyPath ());
824
- $ this ->assertSame ('This value should not be blank. ' , $ context ->getViolations ()[1 ]->getMessage ());
825
- $ this ->assertSame ('children[field2].data ' , $ context ->getViolations ()[1 ]->getPropertyPath ());
826
- }
827
-
828
- public function testCascadeValidationToChildFormsUsingPropertyPathsValidatedInSequence ()
829
- {
830
- $ form = $ this ->getCompoundForm ([], [
831
- 'validation_groups ' => new GroupSequence (['group1 ' , 'group2 ' ]),
832
- ])
833
- ->add ('field1 ' , null , [
834
- 'constraints ' => [new NotBlank (['groups ' => 'group1 ' ])],
835
- 'property_path ' => '[foo] ' ,
836
- ])
837
- ;
838
-
839
- $ form ->submit ([
840
- 'field1 ' => '' ,
841
- ]);
842
-
843
- $ context = new ExecutionContext (Validation::createValidator (), $ form , new IdentityTranslator ());
844
- $ this ->validator ->initialize ($ context );
845
- $ this ->validator ->validate ($ form , new Form ());
846
-
847
- $ this ->assertCount (1 , $ context ->getViolations ());
848
- $ this ->assertSame ('This value should not be blank. ' , $ context ->getViolations ()[0 ]->getMessage ());
849
- $ this ->assertSame ('children[field1].data ' , $ context ->getViolations ()[0 ]->getPropertyPath ());
850
- }
851
-
852
707
protected function createValidator ()
853
708
{
854
709
return new FormValidator ();
0 commit comments