public function ValidationVisitorTest::testValidateCascadedPropertyValidatesReferences

File

drupal/core/vendor/symfony/validator/Symfony/Component/Validator/Tests/ValidationVisitorTest.php, line 233

Class

ValidationVisitorTest
@author Bernhard Schussek <bschussek@gmail.com>

Namespace

Symfony\Component\Validator\Tests

Code

public function testValidateCascadedPropertyValidatesReferences() {
  $entity = new Entity();
  $entity->reference = new Entity();

  // add a constraint for the entity that always fails
  $this->metadata
    ->addConstraint(new FailingConstraint());

  // validate entity when validating the property "reference"
  $this->metadata
    ->addPropertyConstraint('reference', new Valid());

  // invoke validation on an object
  $this->visitor
    ->validate($entity, 'Default', '');
  $violations = new ConstraintViolationList(array(
    // generated by the root object
    new ConstraintViolation('Failed', 'Failed', array(), 'Root', '', $entity),
    // generated by the reference
    new ConstraintViolation('Failed', 'Failed', array(), 'Root', 'reference', $entity->reference),
  ));
  $this
    ->assertEquals($violations, $this->visitor
    ->getViolations());
}