function LinkAccessConstraintValidatorTest::testValidate

Same name in other branches
  1. 9 core/modules/link/tests/src/Unit/Plugin/Validation/Constraint/LinkAccessConstraintValidatorTest.php \Drupal\Tests\link\Unit\Plugin\Validation\Constraint\LinkAccessConstraintValidatorTest::testValidate()
  2. 10 core/modules/link/tests/src/Unit/Plugin/Validation/Constraint/LinkAccessConstraintValidatorTest.php \Drupal\Tests\link\Unit\Plugin\Validation\Constraint\LinkAccessConstraintValidatorTest::testValidate()
  3. 11.x 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 32

Class

LinkAccessConstraintValidatorTest
Tests the LinkAccessConstraintValidator validator.

Namespace

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

Code

public function testValidate($value, $user, $valid) {
    $context = $this->createMock(ExecutionContextInterface::class);
    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);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.