private function UserRolesAssignmentTest::userLoadAndCheckRoleAssigned in Drupal 10
Same name and namespace in other branches
- 8 core/modules/user/tests/src/Functional/UserRolesAssignmentTest.php \Drupal\Tests\user\Functional\UserRolesAssignmentTest::userLoadAndCheckRoleAssigned()
- 9 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.
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());
}
}