function UserMailRequiredValidatorTest::testValidate
Same name in other branches
- 9 core/modules/user/tests/src/Unit/Plugin/Validation/Constraint/UserMailRequiredValidatorTest.php \Drupal\Tests\user\Unit\Plugin\Validation\Constraint\UserMailRequiredValidatorTest::testValidate()
- 10 core/modules/user/tests/src/Unit/Plugin/Validation/Constraint/UserMailRequiredValidatorTest.php \Drupal\Tests\user\Unit\Plugin\Validation\Constraint\UserMailRequiredValidatorTest::testValidate()
- 11.x core/modules/user/tests/src/Unit/Plugin/Validation/Constraint/UserMailRequiredValidatorTest.php \Drupal\Tests\user\Unit\Plugin\Validation\Constraint\UserMailRequiredValidatorTest::testValidate()
@covers ::validate
@dataProvider providerTestValidate
File
-
core/
modules/ user/ tests/ src/ Unit/ Plugin/ Validation/ Constraint/ UserMailRequiredValidatorTest.php, line 58
Class
- UserMailRequiredValidatorTest
- @coversDefaultClass \Drupal\user\Plugin\Validation\Constraint\UserMailRequiredValidator @group user
Namespace
Drupal\Tests\user\Unit\Plugin\Validation\ConstraintCode
public function testValidate($items, $expected_violation, $is_admin = FALSE) {
$constraint = new UserMailRequired();
// If a violation is expected, then the context's addViolation method will
// be called, otherwise it should not be called.
$context = $this->prophesize(ExecutionContextInterface::class);
if ($expected_violation) {
$context->addViolation('@name field is required.', [
'@name' => 'Email',
])
->shouldBeCalledTimes(1);
}
else {
$context->addViolation()
->shouldNotBeCalled();
}
$validator = $this->createValidator($is_admin);
$validator->initialize($context->reveal());
$validator->validate($items, $constraint);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.