private function UserRolesAssignmentTest::userLoadAndCheckRoleAssigned in Drupal 9
Same name and namespace in other branches
- 8 core/modules/user/tests/src/Functional/UserRolesAssignmentTest.php \Drupal\Tests\user\Functional\UserRolesAssignmentTest::userLoadAndCheckRoleAssigned()
Check role on user object.
Parameters
object $account: The user account to check.
string $rid: The role ID to search for.
bool $is_assigned: (optional) Whether to assert that $rid exists (TRUE) or not (FALSE). Defaults to TRUE.
2 calls to UserRolesAssignmentTest::userLoadAndCheckRoleAssigned()
- UserRolesAssignmentTest::testAssignAndRemoveRole in core/
modules/ user/ tests/ src/ Functional/ UserRolesAssignmentTest.php - Tests that a user can be assigned a role and that the role can be removed again.
- UserRolesAssignmentTest::testCreateUserWithRole in core/
modules/ user/ tests/ src/ Functional/ UserRolesAssignmentTest.php - Tests that when creating a user the role can be assigned. And that it can be removed again.
File
- core/
modules/ user/ tests/ src/ Functional/ UserRolesAssignmentTest.php, line 94
Class
- UserRolesAssignmentTest
- Tests that users can be assigned and unassigned roles.
Namespace
Drupal\Tests\user\FunctionalCode
private function userLoadAndCheckRoleAssigned($account, $rid, $is_assigned = TRUE) {
$user_storage = $this->container
->get('entity_type.manager')
->getStorage('user');
$user_storage
->resetCache([
$account
->id(),
]);
$account = $user_storage
->load($account
->id());
if ($is_assigned) {
$this
->assertContains($rid, $account
->getRoles());
}
else {
$this
->assertNotContains($rid, $account
->getRoles());
}
}