Updated to Drupal 8.5. Core Media not yet in use.
[yaffs-website] / vendor / symfony / validator / Tests / Constraints / AbstractComparisonValidatorTestCase.php
index a613d18ead3fb38394ddf551a922d62d24ed1820..93898bc6ec89f7c258b75b88f1ee2274f3888aa1 100644 (file)
@@ -13,6 +13,7 @@ namespace Symfony\Component\Validator\Tests\Constraints;
 
 use Symfony\Component\Intl\Util\IntlTestHelper;
 use Symfony\Component\Validator\Constraint;
+use Symfony\Component\Validator\Exception\ConstraintDefinitionException;
 use Symfony\Component\Validator\Test\ConstraintValidatorTestCase;
 
 class ComparisonTest_Class
@@ -28,6 +29,11 @@ class ComparisonTest_Class
     {
         return (string) $this->value;
     }
+
+    public function getValue()
+    {
+        return $this->value;
+    }
 }
 
 /**
@@ -76,12 +82,25 @@ abstract class AbstractComparisonValidatorTestCase extends ConstraintValidatorTe
     /**
      * @dataProvider provideInvalidConstraintOptions
      * @expectedException \Symfony\Component\Validator\Exception\ConstraintDefinitionException
+     * @expectedExceptionMessage requires either the "value" or "propertyPath" option to be set.
      */
-    public function testThrowsConstraintExceptionIfNoValueOrProperty($options)
+    public function testThrowsConstraintExceptionIfNoValueOrPropertyPath($options)
     {
         $this->createConstraint($options);
     }
 
+    /**
+     * @expectedException \Symfony\Component\Validator\Exception\ConstraintDefinitionException
+     * @expectedExceptionMessage requires only one of the "value" or "propertyPath" options to be set, not both.
+     */
+    public function testThrowsConstraintExceptionIfBothValueAndPropertyPath()
+    {
+        $this->createConstraint((array(
+            'value' => 'value',
+            'propertyPath' => 'propertyPath',
+        )));
+    }
+
     /**
      * @dataProvider provideAllValidComparisons
      *
@@ -113,11 +132,75 @@ abstract class AbstractComparisonValidatorTestCase extends ConstraintValidatorTe
         return $comparisons;
     }
 
+    /**
+     * @dataProvider provideValidComparisonsToPropertyPath
+     */
+    public function testValidComparisonToPropertyPath($comparedValue)
+    {
+        $constraint = $this->createConstraint(array('propertyPath' => 'value'));
+
+        $object = new ComparisonTest_Class(5);
+
+        $this->setObject($object);
+
+        $this->validator->validate($comparedValue, $constraint);
+
+        $this->assertNoViolation();
+    }
+
+    /**
+     * @dataProvider provideValidComparisonsToPropertyPath
+     */
+    public function testValidComparisonToPropertyPathOnArray($comparedValue)
+    {
+        $constraint = $this->createConstraint(array('propertyPath' => '[root][value]'));
+
+        $this->setObject(array('root' => array('value' => 5)));
+
+        $this->validator->validate($comparedValue, $constraint);
+
+        $this->assertNoViolation();
+    }
+
+    public function testNoViolationOnNullObjectWithPropertyPath()
+    {
+        $constraint = $this->createConstraint(array('propertyPath' => 'propertyPath'));
+
+        $this->setObject(null);
+
+        $this->validator->validate('some data', $constraint);
+
+        $this->assertNoViolation();
+    }
+
+    public function testInvalidValuePath()
+    {
+        $constraint = $this->createConstraint(array('propertyPath' => 'foo'));
+
+        if (method_exists($this, 'expectException')) {
+            $this->expectException(ConstraintDefinitionException::class);
+            $this->expectExceptionMessage(sprintf('Invalid property path "foo" provided to "%s" constraint', get_class($constraint)));
+        } else {
+            $this->setExpectedException(ConstraintDefinitionException::class, sprintf('Invalid property path "foo" provided to "%s" constraint', get_class($constraint)));
+        }
+
+        $object = new ComparisonTest_Class(5);
+
+        $this->setObject($object);
+
+        $this->validator->validate(5, $constraint);
+    }
+
     /**
      * @return array
      */
     abstract public function provideValidComparisons();
 
+    /**
+     * @return array
+     */
+    abstract public function provideValidComparisonsToPropertyPath();
+
     /**
      * @dataProvider provideAllInvalidComparisons
      *