|
14 | 14 | use Symfony\Component\Validator\Constraints\Callback;
|
15 | 15 | use Symfony\Component\Validator\Constraints\Collection;
|
16 | 16 | use Symfony\Component\Validator\Constraints\GroupSequence;
|
| 17 | +use Symfony\Component\Validator\Constraints\NotBlank; |
17 | 18 | use Symfony\Component\Validator\Constraints\NotNull;
|
18 | 19 | use Symfony\Component\Validator\Constraints\Traverse;
|
19 | 20 | use Symfony\Component\Validator\Constraints\Valid;
|
@@ -670,4 +671,38 @@ public function testCollectionConstraitViolationHasCorrectContext()
|
670 | 671 | $this->assertCount(1, $violations);
|
671 | 672 | $this->assertSame($constraint, $violations[0]->getConstraint());
|
672 | 673 | }
|
| 674 | + |
| 675 | + public function testNestedObjectIsNotValidatedIfGroupInValidConstraintIsNotValidated() |
| 676 | + { |
| 677 | + $entity = new Entity(); |
| 678 | + $entity->firstName = ''; |
| 679 | + $reference = new Reference(); |
| 680 | + $reference->value = ''; |
| 681 | + $entity->childA = $reference; |
| 682 | + |
| 683 | + $this->metadata->addPropertyConstraint('firstName', new NotBlank(array('groups' => 'group1'))); |
| 684 | + $this->metadata->addPropertyConstraint('childA', new Valid(array('groups' => 'group1'))); |
| 685 | + $this->referenceMetadata->addPropertyConstraint('value', new NotBlank()); |
| 686 | + |
| 687 | + $violations = $this->validator->validate($entity, null, array()); |
| 688 | + |
| 689 | + $this->assertCount(0, $violations); |
| 690 | + } |
| 691 | + |
| 692 | + public function testNestedObjectIsValidatedIfGroupInValidConstraintIsValidated() |
| 693 | + { |
| 694 | + $entity = new Entity(); |
| 695 | + $entity->firstName = ''; |
| 696 | + $reference = new Reference(); |
| 697 | + $reference->value = ''; |
| 698 | + $entity->childA = $reference; |
| 699 | + |
| 700 | + $this->metadata->addPropertyConstraint('firstName', new NotBlank(array('groups' => 'group1'))); |
| 701 | + $this->metadata->addPropertyConstraint('childA', new Valid(array('groups' => 'group1'))); |
| 702 | + $this->referenceMetadata->addPropertyConstraint('value', new NotBlank(array('groups' => 'group1'))); |
| 703 | + |
| 704 | + $violations = $this->validator->validate($entity, null, array('Default', 'group1')); |
| 705 | + |
| 706 | + $this->assertCount(2, $violations); |
| 707 | + } |
673 | 708 | }
|
0 commit comments