You are here

public function ProtectedUserFieldConstraintValidatorTest::testValidate in Lightweight Directory Access Protocol (LDAP) 8.4

Test validation.

@dataProvider providerTestValidate

File

ldap_user/tests/src/Unit/ProtectedUserFieldConstraintValidatorTest.php, line 65

Class

ProtectedUserFieldConstraintValidatorTest
Extended from core tests.

Namespace

Drupal\Tests\ldap_user\Unit

Code

public function testValidate($items, $expected_violation, $name = FALSE) : void {
  $constraint = new LdapProtectedUserFieldConstraint();

  // If a violation is expected, then the context's addViolation method will
  // be called, otherwise it should not be called.
  $context = $this
    ->createMock(ExecutionContextInterface::class);
  if ($expected_violation) {
    $context
      ->expects($this
      ->once())
      ->method('addViolation')
      ->with($constraint->message, [
      '%name' => $name,
    ]);
  }
  else {
    $context
      ->expects($this
      ->never())
      ->method('addViolation');
  }
  $validator = $this
    ->createValidator();
  $validator
    ->initialize($context);
  $validator
    ->validate($items, $constraint);
}