21
21
use Symfony \Component \Validator \Context \ExecutionContextInterface ;
22
22
use Symfony \Component \Validator \Constraints \NotNull ;
23
23
use Symfony \Component \Validator \Constraints \NotBlank ;
24
+ use Symfony \Component \Validator \Constraints \Valid ;
24
25
use Symfony \Component \Validator \Tests \Constraints \AbstractConstraintValidatorTest ;
25
26
use Symfony \Component \Validator \Validation ;
26
27
@@ -109,6 +110,52 @@ public function testValidateConstraints()
109
110
$ this ->assertNoViolation ();
110
111
}
111
112
113
+ public function testValidateIfParentWithCascadeValidation ()
114
+ {
115
+ $ object = $ this ->getMock ('\stdClass ' );
116
+
117
+ $ parent = $ this ->getBuilder ('parent ' , null , array ('cascade_validation ' => true ))
118
+ ->setCompound (true )
119
+ ->setDataMapper ($ this ->getDataMapper ())
120
+ ->getForm ();
121
+ $ options = array ('validation_groups ' => array ('group1 ' , 'group2 ' ));
122
+ $ form = $ this ->getBuilder ('name ' , '\stdClass ' , $ options )->getForm ();
123
+ $ parent ->add ($ form );
124
+
125
+ $ form ->setData ($ object );
126
+
127
+ $ this ->expectValidateAt (0 , 'data ' , $ object , 'group1 ' );
128
+ $ this ->expectValidateAt (1 , 'data ' , $ object , 'group2 ' );
129
+
130
+ $ this ->validator ->validate ($ form , new Form ());
131
+
132
+ $ this ->assertNoViolation ();
133
+ }
134
+
135
+ public function testValidateIfChildWithValidConstraint ()
136
+ {
137
+ $ object = $ this ->getMock ('\stdClass ' );
138
+
139
+ $ parent = $ this ->getBuilder ('parent ' )
140
+ ->setCompound (true )
141
+ ->setDataMapper ($ this ->getDataMapper ())
142
+ ->getForm ();
143
+ $ options = array (
144
+ 'validation_groups ' => array ('group1 ' , 'group2 ' ),
145
+ 'constraints ' => array (new Valid ()),
146
+ );
147
+ $ form = $ this ->getBuilder ('name ' , '\stdClass ' , $ options )->getForm ();
148
+ $ parent ->add ($ form );
149
+
150
+ $ form ->setData ($ object );
151
+
152
+ $ this ->expectValidateAt (0 , 'data ' , $ object , array ('group1 ' , 'group2 ' ));
153
+
154
+ $ this ->validator ->validate ($ form , new Form ());
155
+
156
+ $ this ->assertNoViolation ();
157
+ }
158
+
112
159
public function testDontValidateIfParentWithoutCascadeValidation ()
113
160
{
114
161
$ object = $ this ->getMock ('\stdClass ' );
@@ -387,12 +434,13 @@ public function testUseValidationGroupOfClickedButton()
387
434
{
388
435
$ object = $ this ->getMock ('\stdClass ' );
389
436
390
- $ parent = $ this ->getBuilder ('parent ' , null , array ( ' cascade_validation ' => true ) )
437
+ $ parent = $ this ->getBuilder ('parent ' )
391
438
->setCompound (true )
392
439
->setDataMapper ($ this ->getDataMapper ())
393
440
->getForm ();
394
441
$ form = $ this ->getForm ('name ' , '\stdClass ' , array (
395
442
'validation_groups ' => 'form_group ' ,
443
+ 'constraints ' => array (new Valid ()),
396
444
));
397
445
398
446
$ parent ->add ($ form );
@@ -402,7 +450,7 @@ public function testUseValidationGroupOfClickedButton()
402
450
403
451
$ parent ->submit (array ('name ' => $ object , 'submit ' => '' ));
404
452
405
- $ this ->expectValidateAt (0 , 'data ' , $ object , 'button_group ' );
453
+ $ this ->expectValidateAt (0 , 'data ' , $ object , array ( 'button_group ' ) );
406
454
407
455
$ this ->validator ->validate ($ form , new Form ());
408
456
@@ -413,12 +461,13 @@ public function testDontUseValidationGroupOfUnclickedButton()
413
461
{
414
462
$ object = $ this ->getMock ('\stdClass ' );
415
463
416
- $ parent = $ this ->getBuilder ('parent ' , null , array ( ' cascade_validation ' => true ) )
464
+ $ parent = $ this ->getBuilder ('parent ' )
417
465
->setCompound (true )
418
466
->setDataMapper ($ this ->getDataMapper ())
419
467
->getForm ();
420
468
$ form = $ this ->getForm ('name ' , '\stdClass ' , array (
421
469
'validation_groups ' => 'form_group ' ,
470
+ 'constraints ' => array (new Valid ()),
422
471
));
423
472
424
473
$ parent ->add ($ form );
@@ -428,7 +477,7 @@ public function testDontUseValidationGroupOfUnclickedButton()
428
477
429
478
$ form ->setData ($ object );
430
479
431
- $ this ->expectValidateAt (0 , 'data ' , $ object , 'form_group ' );
480
+ $ this ->expectValidateAt (0 , 'data ' , $ object , array ( 'form_group ' ) );
432
481
433
482
$ this ->validator ->validate ($ form , new Form ());
434
483
@@ -439,20 +488,18 @@ public function testUseInheritedValidationGroup()
439
488
{
440
489
$ object = $ this ->getMock ('\stdClass ' );
441
490
442
- $ parentOptions = array (
443
- 'validation_groups ' => 'group ' ,
444
- 'cascade_validation ' => true ,
445
- );
491
+ $ parentOptions = array ('validation_groups ' => 'group ' );
446
492
$ parent = $ this ->getBuilder ('parent ' , null , $ parentOptions )
447
493
->setCompound (true )
448
494
->setDataMapper ($ this ->getDataMapper ())
449
495
->getForm ();
450
- $ form = $ this ->getBuilder ('name ' , '\stdClass ' )->getForm ();
496
+ $ formOptions = array ('constraints ' => array (new Valid ()));
497
+ $ form = $ this ->getBuilder ('name ' , '\stdClass ' , $ formOptions )->getForm ();
451
498
$ parent ->add ($ form );
452
499
453
500
$ form ->setData ($ object );
454
501
455
- $ this ->expectValidateAt (0 , 'data ' , $ object , 'group ' );
502
+ $ this ->expectValidateAt (0 , 'data ' , $ object , array ( 'group ' ) );
456
503
457
504
$ this ->validator ->validate ($ form , new Form ());
458
505
@@ -463,21 +510,18 @@ public function testUseInheritedCallbackValidationGroup()
463
510
{
464
511
$ object = $ this ->getMock ('\stdClass ' );
465
512
466
- $ parentOptions = array (
467
- 'validation_groups ' => array ($ this , 'getValidationGroups ' ),
468
- 'cascade_validation ' => true ,
469
- );
513
+ $ parentOptions = array ('validation_groups ' => array ($ this , 'getValidationGroups ' ));
470
514
$ parent = $ this ->getBuilder ('parent ' , null , $ parentOptions )
471
515
->setCompound (true )
472
516
->setDataMapper ($ this ->getDataMapper ())
473
517
->getForm ();
474
- $ form = $ this ->getBuilder ('name ' , '\stdClass ' )->getForm ();
518
+ $ formOptions = array ('constraints ' => array (new Valid ()));
519
+ $ form = $ this ->getBuilder ('name ' , '\stdClass ' , $ formOptions )->getForm ();
475
520
$ parent ->add ($ form );
476
521
477
522
$ form ->setData ($ object );
478
523
479
- $ this ->expectValidateAt (0 , 'data ' , $ object , 'group1 ' );
480
- $ this ->expectValidateAt (1 , 'data ' , $ object , 'group2 ' );
524
+ $ this ->expectValidateAt (0 , 'data ' , $ object , array ('group1 ' , 'group2 ' ));
481
525
482
526
$ this ->validator ->validate ($ form , new Form ());
483
527
@@ -492,19 +536,18 @@ public function testUseInheritedClosureValidationGroup()
492
536
'validation_groups ' => function (FormInterface $ form ) {
493
537
return array ('group1 ' , 'group2 ' );
494
538
},
495
- 'cascade_validation ' => true ,
496
539
);
497
540
$ parent = $ this ->getBuilder ('parent ' , null , $ parentOptions )
498
541
->setCompound (true )
499
542
->setDataMapper ($ this ->getDataMapper ())
500
543
->getForm ();
501
- $ form = $ this ->getBuilder ('name ' , '\stdClass ' )->getForm ();
544
+ $ formOptions = array ('constraints ' => array (new Valid ()));
545
+ $ form = $ this ->getBuilder ('name ' , '\stdClass ' , $ formOptions )->getForm ();
502
546
$ parent ->add ($ form );
503
547
504
548
$ form ->setData ($ object );
505
549
506
- $ this ->expectValidateAt (0 , 'data ' , $ object , 'group1 ' );
507
- $ this ->expectValidateAt (1 , 'data ' , $ object , 'group2 ' );
550
+ $ this ->expectValidateAt (0 , 'data ' , $ object , array ('group1 ' , 'group2 ' ));
508
551
509
552
$ this ->validator ->validate ($ form , new Form ());
510
553
0 commit comments