public function ProtectedUserFieldConstraintValidatorTest::testValidate in Drupal 10
Same name and namespace in other branches
- 8 core/modules/user/tests/src/Unit/Plugin/Validation/Constraint/ProtectedUserFieldConstraintValidatorTest.php \Drupal\Tests\user\Unit\Plugin\Validation\Constraint\ProtectedUserFieldConstraintValidatorTest::testValidate()
- 9 core/modules/user/tests/src/Unit/Plugin/Validation/Constraint/ProtectedUserFieldConstraintValidatorTest.php \Drupal\Tests\user\Unit\Plugin\Validation\Constraint\ProtectedUserFieldConstraintValidatorTest::testValidate()
@covers ::validate
@dataProvider providerTestValidate
File
- core/
modules/ user/ tests/ src/ Unit/ Plugin/ Validation/ Constraint/ ProtectedUserFieldConstraintValidatorTest.php, line 47
Class
- ProtectedUserFieldConstraintValidatorTest
- @coversDefaultClass \Drupal\user\Plugin\Validation\Constraint\ProtectedUserFieldConstraintValidator @group user
Namespace
Drupal\Tests\user\Unit\Plugin\Validation\ConstraintCode
public function testValidate($items, $expected_violation, $name = FALSE) {
$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 ($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);
}