@@ -102,6 +102,117 @@ protected function getFormError()
102
102
return new FormError ($ this ->message , $ this ->params );
103
103
}
104
104
105
+ public function testMapToVirtualFormIfDataDoesNotMatch ()
106
+ {
107
+ $ violation = $ this ->getConstraintViolation ('children[address].data.foo ' );
108
+ $ parent = $ this ->getForm ('parent ' );
109
+ $ child = $ this ->getForm ('address ' , 'address ' , null , array (), true );
110
+ $ grandChild = $ this ->getForm ('street ' );
111
+
112
+ $ parent ->add ($ child );
113
+ $ child ->add ($ grandChild );
114
+
115
+ $ this ->mapper ->mapViolation ($ violation , $ parent );
116
+
117
+ $ this ->assertFalse ($ parent ->hasErrors (), $ parent ->getName () . ' should not have an error, but has one ' );
118
+ $ this ->assertEquals (array ($ this ->getFormError ()), $ child ->getErrors (), $ child ->getName () . ' should have an error, but has none ' );
119
+ $ this ->assertFalse ($ grandChild ->hasErrors (), $ grandChild ->getName () . ' should not have an error, but has one ' );
120
+ }
121
+
122
+ public function testFollowDotRules ()
123
+ {
124
+ $ violation = $ this ->getConstraintViolation ('data.foo ' );
125
+ $ parent = $ this ->getForm ('parent ' , null , null , array (
126
+ 'foo ' => 'address ' ,
127
+ ));
128
+ $ child = $ this ->getForm ('address ' , null , null , array (
129
+ '. ' => 'street ' ,
130
+ ));
131
+ $ grandChild = $ this ->getForm ('street ' , null , null , array (
132
+ '. ' => 'name ' ,
133
+ ));
134
+ $ grandGrandChild = $ this ->getForm ('name ' );
135
+
136
+ $ parent ->add ($ child );
137
+ $ child ->add ($ grandChild );
138
+ $ grandChild ->add ($ grandGrandChild );
139
+
140
+ $ this ->mapper ->mapViolation ($ violation , $ parent );
141
+
142
+ $ this ->assertFalse ($ parent ->hasErrors (), $ parent ->getName () . ' should not have an error, but has one ' );
143
+ $ this ->assertFalse ($ child ->hasErrors (), $ child ->getName () . ' should not have an error, but has one ' );
144
+ $ this ->assertFalse ($ grandChild ->hasErrors (), $ grandChild ->getName () . ' should not have an error, but has one ' );
145
+ $ this ->assertEquals (array ($ this ->getFormError ()), $ grandGrandChild ->getErrors (), $ grandGrandChild ->getName () . ' should have an error, but has none ' );
146
+ }
147
+
148
+ public function testAbortMappingIfNotSynchronized ()
149
+ {
150
+ $ violation = $ this ->getConstraintViolation ('children[address].data.street ' );
151
+ $ parent = $ this ->getForm ('parent ' );
152
+ $ child = $ this ->getForm ('address ' , 'address ' , null , array (), false , false );
153
+ // even though "street" is synchronized, it should not have any errors
154
+ // due to its parent not being synchronized
155
+ $ grandChild = $ this ->getForm ('street ' , 'street ' );
156
+
157
+ $ parent ->add ($ child );
158
+ $ child ->add ($ grandChild );
159
+
160
+ // bind to invoke the transformer and mark the form unsynchronized
161
+ $ parent ->bind (array ());
162
+
163
+ $ this ->mapper ->mapViolation ($ violation , $ parent );
164
+
165
+ $ this ->assertFalse ($ parent ->hasErrors (), $ parent ->getName () . ' should not have an error, but has one ' );
166
+ $ this ->assertFalse ($ child ->hasErrors (), $ child ->getName () . ' should not have an error, but has one ' );
167
+ $ this ->assertFalse ($ grandChild ->hasErrors (), $ grandChild ->getName () . ' should not have an error, but has one ' );
168
+ }
169
+
170
+ public function testAbortVirtualFormMappingIfNotSynchronized ()
171
+ {
172
+ $ violation = $ this ->getConstraintViolation ('children[address].children[street].data.foo ' );
173
+ $ parent = $ this ->getForm ('parent ' );
174
+ $ child = $ this ->getForm ('address ' , 'address ' , null , array (), true , false );
175
+ // even though "street" is synchronized, it should not have any errors
176
+ // due to its parent not being synchronized
177
+ $ grandChild = $ this ->getForm ('street ' , 'street ' , null , array (), true );
178
+
179
+ $ parent ->add ($ child );
180
+ $ child ->add ($ grandChild );
181
+
182
+ // bind to invoke the transformer and mark the form unsynchronized
183
+ $ parent ->bind (array ());
184
+
185
+ $ this ->mapper ->mapViolation ($ violation , $ parent );
186
+
187
+ $ this ->assertFalse ($ parent ->hasErrors (), $ parent ->getName () . ' should not have an error, but has one ' );
188
+ $ this ->assertFalse ($ child ->hasErrors (), $ child ->getName () . ' should not have an error, but has one ' );
189
+ $ this ->assertFalse ($ grandChild ->hasErrors (), $ grandChild ->getName () . ' should not have an error, but has one ' );
190
+ }
191
+
192
+ public function testAbortDotRuleMappingIfNotSynchronized ()
193
+ {
194
+ $ violation = $ this ->getConstraintViolation ('data.address ' );
195
+ $ parent = $ this ->getForm ('parent ' );
196
+ $ child = $ this ->getForm ('address ' , 'address ' , null , array (
197
+ '. ' => 'street ' ,
198
+ ), false , false );
199
+ // even though "street" is synchronized, it should not have any errors
200
+ // due to its parent not being synchronized
201
+ $ grandChild = $ this ->getForm ('street ' );
202
+
203
+ $ parent ->add ($ child );
204
+ $ child ->add ($ grandChild );
205
+
206
+ // bind to invoke the transformer and mark the form unsynchronized
207
+ $ parent ->bind (array ());
208
+
209
+ $ this ->mapper ->mapViolation ($ violation , $ parent );
210
+
211
+ $ this ->assertFalse ($ parent ->hasErrors (), $ parent ->getName () . ' should not have an error, but has one ' );
212
+ $ this ->assertFalse ($ child ->hasErrors (), $ child ->getName () . ' should not have an error, but has one ' );
213
+ $ this ->assertFalse ($ grandChild ->hasErrors (), $ grandChild ->getName () . ' should not have an error, but has one ' );
214
+ }
215
+
105
216
public function provideDefaultTests ()
106
217
{
107
218
// The mapping must be deterministic! If a child has the property path "[street]",
@@ -1337,47 +1448,4 @@ public function testVirtualFormErrorMapping($target, $childName, $childPath, $gr
1337
1448
$ this ->assertEquals (array ($ this ->getFormError ()), $ grandChild ->getErrors (), $ grandChildName . ' should have an error, but has none ' );
1338
1449
}
1339
1450
}
1340
-
1341
- public function testDontMapToUnsynchronizedForms ()
1342
- {
1343
- $ violation = $ this ->getConstraintViolation ('children[address].data.street ' );
1344
- $ parent = $ this ->getForm ('parent ' );
1345
- $ child = $ this ->getForm ('address ' , 'address ' , null , array (), false , false );
1346
-
1347
- $ parent ->add ($ child );
1348
-
1349
- // bind to invoke the transformer and mark the form unsynchronized
1350
- $ parent ->bind (array ());
1351
-
1352
- $ this ->mapper ->mapViolation ($ violation , $ parent );
1353
-
1354
- $ this ->assertFalse ($ parent ->hasErrors (), $ parent ->getName () . ' should not have an error, but has one ' );
1355
- $ this ->assertFalse ($ child ->hasErrors (), $ child ->getName () . ' should not have an error, but has one ' );
1356
- }
1357
-
1358
- public function testFollowDotRules ()
1359
- {
1360
- $ violation = $ this ->getConstraintViolation ('data.foo ' );
1361
- $ parent = $ this ->getForm ('parent ' , null , null , array (
1362
- 'foo ' => 'address ' ,
1363
- ));
1364
- $ child = $ this ->getForm ('address ' , null , null , array (
1365
- '. ' => 'street ' ,
1366
- ));
1367
- $ grandChild = $ this ->getForm ('street ' , null , null , array (
1368
- '. ' => 'name ' ,
1369
- ));
1370
- $ grandGrandChild = $ this ->getForm ('name ' );
1371
-
1372
- $ parent ->add ($ child );
1373
- $ child ->add ($ grandChild );
1374
- $ grandChild ->add ($ grandGrandChild );
1375
-
1376
- $ this ->mapper ->mapViolation ($ violation , $ parent );
1377
-
1378
- $ this ->assertFalse ($ parent ->hasErrors (), $ parent ->getName
53C6
() . ' should not have an error, but has one ' );
1379
- $ this ->assertFalse ($ child ->hasErrors (), $ child ->getName () . ' should not have an error, but has one ' );
1380
- $ this ->assertFalse ($ grandChild ->hasErrors (), $ grandChild ->getName () . ' should not have an error, but has one ' );
1381
- $ this ->assertEquals (array ($ this ->getFormError ()), $ grandGrandChild ->getErrors (), $ grandGrandChild ->getName () . ' should have an error, but has none ' );
1382
- }
1383
1451
}
0 commit comments