@@ -170,6 +170,51 @@ public function testValidateConstraintsEvenIfNoCascadeValidation()
170
170
$ this ->validator ->validate ($ form , new Form ());
171
171
}
172
172
173
+ public function testDontValidateIfNoValidationGroups ()
174
+ {
175
+ $ context = $ this ->getMockExecutionContext ();
176
+ $ object = $ this ->getMock ('\stdClass ' );
177
+
178
+ $ form = $ this ->getBuilder ('name ' , '\stdClass ' , array (
179
+ 'validation_groups ' => array (),
180
+ ))
181
+ ->setData ($ object )
182
+ ->getForm ();
183
+
184
+ $ form ->setData ($ object );
185
+
186
+ $ context ->expects ($ this ->never ())
187
+ ->method ('validate ' );
188
+
189
+ $ this ->validator ->initialize ($ context );
190
+ $ this ->validator ->validate ($ form , new Form ());
191
+ }
192
+
193
+ public function testDontValidateConstraintsIfNoValidationGroups ()
194
+ {
195
+ $ context = $ this ->getMockExecutionContext ();
196
+ $ object = $ this ->getMock ('\stdClass ' );
197
+ $ constraint1 = $ this ->getMock ('Symfony\Component\Validator\Constraint ' );
198
+ $ constraint2 = $ this ->getMock ('Symfony\Component\Validator\Constraint ' );
199
+
200
+ $ options = array (
201
+ 'validation_groups ' => array (),
202
+ 'constraints ' => array ($ constraint1 , $ constraint2 ),
203
+ );
204
+ $ form = $ this ->getBuilder ('name ' , '\stdClass ' , $ options )
205
+ ->setData ($ object )
206
+ ->getForm ();
207
+
208
+ // Launch transformer
209
+ $ form ->bind (array ());
210
+
211
+ $ context ->expects ($ this ->never ())
212
+ ->method ('validate ' );
213
+
214
+ $ this ->validator ->initialize ($ context );
215
+ $ this ->validator ->validate ($ form , new Form ());
216
+ }
217
+
173
218
public function testDontValidateIfNotSynchronized ()
174
219
{
175
220
$ context = $ this ->getMockExecutionContext ();
@@ -209,6 +254,46 @@ function () { throw new TransformationFailedException(); }
209
254
$ this ->validator ->validate ($ form , new Form ());
210
255
}
211
256
257
+ public function testAddInvalidErrorEvenIfNoValidationGroups ()
258
+ {
259
+ $ context = $ this ->getMockExecutionContext ();
260
+ $ object = $ this ->getMock ('\stdClass ' );
261
+
262
+ $ form = $ this ->getBuilder ('name ' , '\stdClass ' , array (
263
+ 'invalid_message ' => 'invalid_message_key ' ,
264
+ // Invalid message parameters must be supported, because the
265
+ // invalid message can be a translation key
266
+ // see https://github.com/symfony/symfony/issues/5144
267
+ 'invalid_message_parameters ' => array ('{{ foo }} ' => 'bar ' ),
268
+ 'validation_groups ' => array (),
269
+ ))
270
+ ->setData ($ object )
271
+ ->addViewTransformer (new CallbackTransformer (
272
+ function ($ data ) { return $ data ; },
273
+ function () { throw new TransformationFailedException (); }
274
+ ))
275
+ ->getForm ();
276
+
277
+ // Launch transformer
278
+ $ form ->bind ('foo ' );
279
+
280
+ $ context ->expects ($ this ->never ())
281
+ ->method ('validate ' );
282
+
283
+ $ context ->expects ($ this ->once ())
284
+ ->method ('addViolation ' )
285
+ ->with (
286
+ 'invalid_message_key ' ,
287
+ array ('{{ value }} ' => 'foo ' , '{{ foo }} ' => 'bar ' ),
288
+ 'foo '
289
+ );
290
+ $ context ->expects ($ this ->never ())
291
+ ->method ('addViolationAt ' );
292
+
293
+ $ this ->validator ->initialize ($ context );
294
+ $ this ->validator ->validate ($ form , new Form ());
295
+ }
296
+
212
297
public function testDontValidateConstraintsIfNotSynchronized ()
213
298
{
214
299
$ context = $ this ->getMockExecutionContext ();
0 commit comments