You are here

public function RangeFromGreaterToConstraintValidatorTest::testValidate in Range 8

Tests the RangeFromGreaterToConstraintValidator::validate() method.

@covers ::validate @dataProvider providerValidate

Parameters

\Drupal\range\RangeItemInterface $value: Range item.

bool $valid: A boolean indicating if the combination is expected to be valid.

File

tests/src/Unit/Plugin/Validation/Constraint/RangeFromGreaterToConstraintValidatorTest.php, line 31

Class

RangeFromGreaterToConstraintValidatorTest
Tests the RangeFromGreaterToConstraintValidator validator.

Namespace

Drupal\Tests\range\Unit\Plugin\Validation\Constraint

Code

public function testValidate(RangeItemInterface $value, $valid) {
  $context = $this
    ->createMock(ExecutionContextInterface::class);
  if ($valid) {
    $context
      ->expects($this
      ->never())
      ->method('addViolation');
  }
  else {
    $context
      ->expects($this
      ->once())
      ->method('addViolation');
  }
  $constraint = new RangeFromGreaterToConstraint();
  $validate = new RangeFromGreaterToConstraintValidator();
  $validate
    ->initialize($context);
  $validate
    ->validate($value, $constraint);
}