function UserMailRequiredValidatorTest::createValidator
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::createValidator()
- 8.9.x core/modules/user/tests/src/Unit/Plugin/Validation/Constraint/UserMailRequiredValidatorTest.php \Drupal\Tests\user\Unit\Plugin\Validation\Constraint\UserMailRequiredValidatorTest::createValidator()
- 10 core/modules/user/tests/src/Unit/Plugin/Validation/Constraint/UserMailRequiredValidatorTest.php \Drupal\Tests\user\Unit\Plugin\Validation\Constraint\UserMailRequiredValidatorTest::createValidator()
Creates a validator instance.
Parameters
bool $is_admin: Whether or not the current user is an administrator.
Return value
\Drupal\user\Plugin\Validation\Constraint\UserMailRequiredValidator The validator instance.
1 call to UserMailRequiredValidatorTest::createValidator()
- UserMailRequiredValidatorTest::testValidate in core/
modules/ user/ tests/ src/ Unit/ Plugin/ Validation/ Constraint/ UserMailRequiredValidatorTest.php - @covers ::validate
File
-
core/
modules/ user/ tests/ src/ Unit/ Plugin/ Validation/ Constraint/ UserMailRequiredValidatorTest.php, line 35
Class
- UserMailRequiredValidatorTest
- @coversDefaultClass \Drupal\user\Plugin\Validation\Constraint\UserMailRequiredValidator @group user
Namespace
Drupal\Tests\user\Unit\Plugin\Validation\ConstraintCode
protected function createValidator($is_admin) {
// Setup mocks that don't need to change.
$unchanged_account = $this->prophesize(UserInterface::class);
$unchanged_account->getEmail()
->willReturn(NULL);
$user_storage = $this->prophesize(UserStorageInterface::class);
$user_storage->loadUnchanged(3)
->willReturn($unchanged_account->reveal());
$entity_type_manager = $this->prophesize(EntityTypeManagerInterface::class);
$entity_type_manager->getStorage('user')
->willReturn($user_storage->reveal());
$current_user = $this->prophesize(AccountInterface::class);
$current_user->id()
->willReturn(3);
$current_user->hasPermission("administer users")
->willReturn($is_admin);
$container = new ContainerBuilder();
$container->set('entity_type.manager', $entity_type_manager->reveal());
$container->set('current_user', $current_user->reveal());
\Drupal::setContainer($container);
return new UserMailRequiredValidator();
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.