22
22
use Symfony \Component \Form \FormConfigBuilder ;
23
23
use Symfony \Component \Form \FormError ;
24
24
use Symfony \Component \Form \FormInterface ;
25
+ use Symfony \Component \Form \Tests \Extension \Validator \ViolationMapper \Fixtures \Issue ;
25
26
use Symfony \Component \PropertyAccess \PropertyPath ;
26
27
use Symfony \Component \Validator \ConstraintViolation ;
27
28
use Symfony \Component \Validator \ConstraintViolationInterface ;
@@ -70,12 +71,12 @@ protected function setUp()
70
71
$ this ->params = ['foo ' => 'bar ' ];
71
72
}
72
73
73
- protected function getForm ($ name = 'name ' , $ propertyPath = null , $ dataClass = null , $ errorMapping = [], $ inheritData = false , $ synchronized = true )
74
+ protected function getForm ($ name = 'name ' , $ propertyPath = null , $ dataClass = null , $ errorMapping = [], $ inheritData = false , $ synchronized = true , array $ options = [] )
74
75
{
75
76
$ config = new FormConfigBuilder ($ name , $ dataClass , $ this ->dispatcher , [
76
77
'error_mapping ' => $ errorMapping ,
77
- ]);
78
- $ config ->setMapped (true );
78
+ ] + $ options );
79
+ $ config ->setMapped (isset ( $ options [ ' mapped ' ]) ? $ options [ ' mapped ' ] : true );
79
80
$ config ->setInheritData ($ inheritData );
80
81
$ config ->setPropertyPath ($ propertyPath );
81
82
$ config ->setCompound (true );
@@ -96,9 +97,9 @@ function () { throw new TransformationFailedException(); }
96
97
*
97
98
* @return ConstraintViolation
98
99
*/
99
- protected function getConstraintViolation ($ propertyPath )
100
+ protected function getConstraintViolation ($ propertyPath, $ root = null )
100
101
{
101
- return new ConstraintViolation ($ this ->message , $ this ->messageTemplate , $ this ->params , null , $ propertyPath , null );
102
+ return new ConstraintViolation ($ this ->message , $ this ->messageTemplate , $ this ->params , $ root , $ propertyPath , null );
102
103
}
103
104
104
105
/**
@@ -112,6 +113,33 @@ protected function getFormError(ConstraintViolationInterface $violation, FormInt
112
113
return $ error ;
113
114
}
114
115
116
+ public function testMappingErrorsWhenFormIsNotMapped ()
117
+ {
118
+ $ form = $ this ->getForm ('name ' , null , Issue::class, [
119
+ 'child1 ' => 'child2 ' ,
120
+ ]);
121
+
122
+ $ violation = $ this ->getConstraintViolation ('children[child1].data ' , $ form );
123
+
124
+ $ child1Form = $ this ->getForm ('child1 ' , null , null , [], false , true , [
125
+ 'mapped ' => false ,
126
+ ]);
127
+ $ child2Form = $ this ->getForm ('child2 ' , null , null , [], false , true , [
128
+ 'mapped ' => false ,
129
+ ]);
130
+
131
+ $ form ->add ($ child1Form );
132
+ $ form ->add ($ child2Form );
133
+
134
+ $ form ->submit ([]);
135
+
136
+ $ this ->mapper ->mapViolation ($ violation , $ form );
137
+
138
+ $ this ->assertCount (0 , $ form ->getErrors ());
139
+ $ this ->assertCount (0 , $ form ->get ('child1 ' )->getErrors ());
140
+ $ this ->assertCount (1 , $ form ->get ('child2 ' )->getErrors ());
141
+ }
142
+
115
143
public function testMapToFormInheritingParentDataIfDataDoesNotMatch ()
116
144
{
117
145
$ violation = $ this ->getConstraintViolation ('children[address].data.foo ' );
0 commit comments