|
12 | 12 | namespace Symfony\Component\Validator\Tests\Validator;
|
13 | 13 |
|
14 | 14 | use Symfony\Component\Translation\IdentityTranslator;
|
| 15 | +use Symfony\Component\Validator\Constraints\All; |
| 16 | +use Symfony\Component\Validator\Constraints\Collection; |
| 17 | +use Symfony\Component\Validator\Constraints\Length; |
| 18 | +use Symfony\Component\Validator\Constraints\NotBlank; |
15 | 19 | use Symfony\Component\Validator\ConstraintValidatorFactory;
|
16 | 20 | use Symfony\Component\Validator\Context\ExecutionContextFactory;
|
17 | 21 | use Symfony\Component\Validator\Mapping\Factory\MetadataFactoryInterface;
|
@@ -95,4 +99,38 @@ public function testRelationBetweenChildAAndChildB()
|
95 | 99 |
|
96 | 100 | $validator->validate($entity, null, array());
|
97 | 101 | }
|
| 102 | + |
| 103 | + public function testCollectionConstraintValidateAllGroupsForNestedConstraints() |
| 104 | + { |
| 105 | + $this->metadata->addPropertyConstraint('data', new Collection(array('fields' => array( |
| 106 | + 'one' => array(new NotBlank(array('groups' => 'one')), new Length(array('min' => 2, 'groups' => 'two'))), |
| 107 | + 'two' => array(new NotBlank(array('groups' => 'two'))), |
| 108 | + )))); |
| 109 | + |
| 110 | + $entity = new Entity(); |
| 111 | + $entity->data = array('one' => 't', 'two' => ''); |
| 112 | + |
| 113 | + $violations = $this->validator->validate($entity, null, array('one', 'two')); |
| 114 | + |
| 115 | + $this->assertCount(2, $violations); |
| 116 | + $this->assertInstanceOf(Length::class, $violations->get(0)->getConstraint()); |
| 117 | + $this->assertInstanceOf(NotBlank::class, $violations->get(1)->getConstraint()); |
| 118 | + } |
| 119 | + |
| 120 | + public function testAllConstraintValidateAllGroupsForNestedConstraints() |
| 121 | + { |
| 122 | + $this->metadata->addPropertyConstraint('data', new All(array('constraints' => array( |
| 123 | + new NotBlank(array('groups' => 'one')), |
| 124 | + new Length(array('min' => 2, 'groups' => 'two')), |
| 125 | + )))); |
| 126 | + |
| 127 | + $entity = new Entity(); |
| 128 | + $entity->data = array('one' => 't', 'two' => ''); |
| 129 | + |
| 130 | + $violations = $this->validator->validate($entity, null, array('one', 'two')); |
| 131 | + |
| 132 | + $this->assertCount(2, $violations); |
| 133 | + $this->assertInstanceOf(NotBlank::class, $violations->get(0)->getConstraint()); |
| 134 | + $this->assertInstanceOf(Length::class, $violations->get(1)->getConstraint()); |
| 135 | + } |
98 | 136 | }
|
0 commit comments