@@ -386,4 +386,115 @@ public function testObjectShouldBeLeftUnchanged()
386
386
'foo ' => 3 ,
387
387
), (array ) $ value );
388
388
}
389
+
390
+ /**
391
+ * @expectedException \Symfony\Component\Validator\Exception\ConstraintDefinitionException
392
+ */
393
+ public function testGroupShouldBePassedToTheContainingConstraint ()
394
+ {
395
+ $ value = array ('baz ' => 2 );
396
+
397
+ $ constraint = new Collection (
398
+ array (
399
+ 'fields ' => array (
400
+ 'baz ' => array (
401
+ new Range (array (
402
+ 'min ' => 1 ,
403
+ 'groups ' => 'bar ' ,
404
+ )),
405
+ ),
406
+ ),
407
+ 'groups ' => 'foo ' ,
408
+ )
409
+ );
410
+
411
+ $ this ->validator ->validate ($ this ->prepareTestData ($ value ), $ constraint );
412
+ }
413
+
414
+ /**
415
+ * @dataProvider multipleGroupsForCollectionProvider
416
+ * @param array $fooGroups
417
+ * @param array $barGroups
418
+ * @param array $collectionGroups
419
+ * @param array $expectedGroups
420
+ */
421
+ public function testValidateMultipleGroupsForCollectionConstraint (
422
+ array $ fooGroups ,
423
+ array $ barGroups ,
424
+ array $ collectionGroups ,
425
+ array $ expectedGroups
426
+ ) {
427
+ $ value = array ('baz ' => 2 );
428
+
429
+ $ fooConstraint = new Range (array (
430
+ 'min ' => 3 ,
431
+ 'minMessage ' => 'Group foo ' ,
432
+ 'groups ' => $ fooGroups ,
433
+ ));
434
+ $ barConstraint = new Range (array (
435
+ 'min ' => 5 ,
436
+ 'minMessage ' => 'Group bar ' ,
437
+ 'groups ' => $ barGroups ,
438
+ ));
439
+
440
+ $ constraint = new Collection (
441
+ array (
442
+ 'fields ' => array (
443
+ 'baz ' => array (
444
+ $ fooConstraint ,
445
+ $ barConstraint ,
446
+ ),
447
+ ),
448
+ 'groups ' => $ collectionGroups ,
449
+ )
450
+ );
451
+
452
+ $ data = $ this ->prepareTestData ($ value );
453
+
454
+ $ this ->expectValidateValueAt (0 , '[baz] ' , $ value ['baz ' ], array ($ fooConstraint , $ barConstraint ), $ expectedGroups );
455
+
456
+ $ this ->validator ->validate ($ data , $ constraint );
457
+ }
458
+
459
+ public static function multipleGroupsForCollectionProvider ()
460
+ {
461
+ return array (
462
+ array (
463
+ array ('foo ' , 'bar ' ),
464
+ array ('foo ' , 'bar ' ),
465
+ array ('foo ' , 'bar ' ),
466
+ array ('foo ' , 'bar ' )
467
+ ),
468
+ array (
469
+ array ('foo ' , 'bar ' ),
470
+ array ('bar ' ),
471
+ array ('foo ' , 'bar ' ),
472
+ array ('foo ' , 'bar ' )
473
+ ),
474
+ array (
475
+ array ('foo ' ),
476
+ array ('foo ' , 'bar ' ),
477
+ array ('foo ' , 'bar ' ),
478
+ array ('foo ' , 'bar ' )
479
+ ),
480
+ array (
481
+ array ('foo ' ),
482
+ array ('bar ' ),
483
+ array ('foo ' , 'bar ' ),
484
+ array ('foo ' , 'bar ' )
485
+ ),
486
+ array (
487
+ array ('foo ' ),
488
+ array ('foo ' ),
489
+ array ('foo ' , 'bar ' ),
490
+ array ('foo ' )
491
+ ),
492
+ array (
493
+ array ('foo ' ),
494
+ array ('foo ' ),
495
+ array ('foo ' ),
496
+ array ('foo ' )
497
+ ),
498
+ );
499
+ }
389
500
}
0 commit comments