function ProtectedUserFieldConstraintValidatorTest::validate

Same name and namespace in other branches
  1. 11.x core/modules/user/tests/src/Unit/Plugin/Validation/Constraint/ProtectedUserFieldConstraintValidatorTest.php \Drupal\Tests\user\Unit\Plugin\Validation\Constraint\ProtectedUserFieldConstraintValidatorTest::validate()

Perform the validation.

1 call to ProtectedUserFieldConstraintValidatorTest::validate()
ProtectedUserFieldConstraintValidatorTest::testValidate in core/modules/user/tests/src/Unit/Plugin/Validation/Constraint/ProtectedUserFieldConstraintValidatorTest.php
@covers ::validate[[api-linebreak]]

File

core/modules/user/tests/src/Unit/Plugin/Validation/Constraint/ProtectedUserFieldConstraintValidatorTest.php, line 47

Class

ProtectedUserFieldConstraintValidatorTest
@coversDefaultClass \Drupal\user\Plugin\Validation\Constraint\ProtectedUserFieldConstraintValidator[[api-linebreak]] @group user

Namespace

Drupal\Tests\user\Unit\Plugin\Validation\Constraint

Code

protected function validate($items, ?string $name = NULL) : void {
  $constraint = new ProtectedUserFieldConstraint();
  // 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 ($name) {
    $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);
}

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