You are here

public function CdnStreamWrapperConstraintValidatorTest::testValidate in CDN 8.3

@covers ::validate

@dataProvider provideTestValidate

File

tests/src/Kernel/CdnStreamWrapperConstraintValidatorTest.php, line 28

Class

CdnStreamWrapperConstraintValidatorTest
@coversDefaultClass \Drupal\cdn\Plugin\Validation\Constraint\CdnStreamWrapperConstraintValidator @group cdn

Namespace

Drupal\Tests\cdn\Kernel

Code

public function testValidate($value, $valid) {
  $constraint_violation_builder = $this
    ->prophesize(ConstraintViolationBuilderInterface::class);
  $constraint_violation_builder
    ->setParameter('%stream_wrapper', $value)
    ->willReturn($constraint_violation_builder
    ->reveal());
  $constraint_violation_builder
    ->setInvalidValue($value)
    ->willReturn($constraint_violation_builder
    ->reveal());
  $constraint_violation_builder
    ->addViolation()
    ->willReturn($constraint_violation_builder
    ->reveal());
  if ($valid) {
    $constraint_violation_builder
      ->addViolation()
      ->shouldNotBeCalled();
  }
  else {
    $constraint_violation_builder
      ->addViolation()
      ->shouldBeCalled();
  }
  $context = $this
    ->prophesize(ExecutionContextInterface::class);
  $context
    ->buildViolation(Argument::type('string'))
    ->willReturn($constraint_violation_builder
    ->reveal());
  $constraint = new CdnStreamWrapperConstraint();
  $validate = new CdnStreamWrapperConstraintValidator();
  $validate
    ->initialize($context
    ->reveal());
  $validate
    ->validate($value, $constraint);
}