Updated to Drupal 8.5. Core Media not yet in use.
[yaffs-website] / vendor / symfony / validator / Tests / Validator / AbstractTest.php
index 77a7cc6c2bdc6815d8208ac32aabc9b00278301d..6587dae139550671125f7653c1eed16068421d8d 100644 (file)
@@ -13,7 +13,9 @@ namespace Symfony\Component\Validator\Tests\Validator;
 
 use Symfony\Component\Validator\Constraints\Callback;
 use Symfony\Component\Validator\Constraints\Collection;
+use Symfony\Component\Validator\Constraints\Expression;
 use Symfony\Component\Validator\Constraints\GroupSequence;
+use Symfony\Component\Validator\Constraints\NotBlank;
 use Symfony\Component\Validator\Constraints\NotNull;
 use Symfony\Component\Validator\Constraints\Traverse;
 use Symfony\Component\Validator\Constraints\Valid;
@@ -37,9 +39,6 @@ abstract class AbstractTest extends AbstractValidatorTest
     protected $validator;
 
     /**
-     * @param MetadataFactoryInterface $metadataFactory
-     * @param array                    $objectInitializers
-     *
      * @return ValidatorInterface
      */
     abstract protected function createValidator(MetadataFactoryInterface $metadataFactory, array $objectInitializers = array());
@@ -583,6 +582,7 @@ abstract class AbstractTest extends AbstractValidatorTest
         $called = false;
         $entity = new Entity();
         $entity->firstName = 'Bernhard';
+        $entity->data = array('firstName' => 'Bernhard');
 
         $callback = function ($value, ExecutionContextInterface $context) use ($entity, &$called) {
             $called = true;
@@ -591,6 +591,7 @@ abstract class AbstractTest extends AbstractValidatorTest
 
         $this->metadata->addConstraint(new Callback($callback));
         $this->metadata->addPropertyConstraint('firstName', new Callback($callback));
+        $this->metadata->addPropertyConstraint('data', new Collection(array('firstName' => new Expression('value == this.firstName'))));
 
         $this->validator->validate($entity);
 
@@ -670,4 +671,38 @@ abstract class AbstractTest extends AbstractValidatorTest
         $this->assertCount(1, $violations);
         $this->assertSame($constraint, $violations[0]->getConstraint());
     }
+
+    public function testNestedObjectIsNotValidatedIfGroupInValidConstraintIsNotValidated()
+    {
+        $entity = new Entity();
+        $entity->firstName = '';
+        $reference = new Reference();
+        $reference->value = '';
+        $entity->childA = $reference;
+
+        $this->metadata->addPropertyConstraint('firstName', new NotBlank(array('groups' => 'group1')));
+        $this->metadata->addPropertyConstraint('childA', new Valid(array('groups' => 'group1')));
+        $this->referenceMetadata->addPropertyConstraint('value', new NotBlank());
+
+        $violations = $this->validator->validate($entity, null, array());
+
+        $this->assertCount(0, $violations);
+    }
+
+    public function testNestedObjectIsValidatedIfGroupInValidConstraintIsValidated()
+    {
+        $entity = new Entity();
+        $entity->firstName = '';
+        $reference = new Reference();
+        $reference->value = '';
+        $entity->childA = $reference;
+
+        $this->metadata->addPropertyConstraint('firstName', new NotBlank(array('groups' => 'group1')));
+        $this->metadata->addPropertyConstraint('childA', new Valid(array('groups' => 'group1')));
+        $this->referenceMetadata->addPropertyConstraint('value', new NotBlank(array('groups' => 'group1')));
+
+        $violations = $this->validator->validate($entity, null, array('Default', 'group1'));
+
+        $this->assertCount(2, $violations);
+    }
 }