You are here

public function RangeBothValuesRequiredConstraintValidatorTest::testValidate in Range 8

Tests the RangeBothValuesRequiredConstraintValidator::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/RangeBothValuesRequiredConstraintValidatorTest.php, line 31

Class

RangeBothValuesRequiredConstraintValidatorTest
Tests the RangeBothValuesRequiredConstraintValidator 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 RangeBothValuesRequiredConstraint();
  $validate = new RangeBothValuesRequiredConstraintValidator();
  $validate
    ->initialize($context);
  $validate
    ->validate($value, $constraint);
}