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