You are here

public function LinkAccessConstraintValidatorTest::testValidate in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/link/tests/src/Unit/Plugin/Validation/Constraint/LinkAccessConstraintValidatorTest.php \Drupal\Tests\link\Unit\Plugin\Validation\Constraint\LinkAccessConstraintValidatorTest::testValidate()

Tests the \Drupal\link\Plugin\Validation\Constraint\LinkAccessConstraintValidator::validate() method.

@covers ::validate @dataProvider providerValidate

Parameters

\Drupal\link\LinkItemInterface $value: The link item.

\Drupal\Core\Session\AccountProxyInterface $user: The user account.

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

File

core/modules/link/tests/src/Unit/Plugin/Validation/Constraint/LinkAccessConstraintValidatorTest.php, line 36
Contains \Drupal\Tests\link\Unit\Plugin\Validation\Constraint\LinkAccessConstraintValidatorTest.

Class

LinkAccessConstraintValidatorTest
Tests the LinkAccessConstraintValidator validator.

Namespace

Drupal\Tests\link\Unit\Plugin\Validation\Constraint

Code

public function testValidate($value, $user, $valid) {
  $context = $this
    ->getMock('Symfony\\Component\\Validator\\ExecutionContextInterface');
  if ($valid) {
    $context
      ->expects($this
      ->never())
      ->method('addViolation');
  }
  else {
    $context
      ->expects($this
      ->once())
      ->method('addViolation');
  }
  $constraint = new LinkAccessConstraint();
  $validate = new LinkAccessConstraintValidator($user);
  $validate
    ->initialize($context);
  $validate
    ->validate($value, $constraint);
}