private function 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 drupal/core/modules/user/lib/Drupal/user/Tests/UserRolesAssignmentTest.php
Tests that a user can be assigned a role and that the role can be removed again.
UserRolesAssignmentTest::testCreateUserWithRole in drupal/core/modules/user/lib/Drupal/user/Tests/UserRolesAssignmentTest.php
Tests that when creating a user the role can be assigned. And that it can be removed again.

File

drupal/core/modules/user/lib/Drupal/user/Tests/UserRolesAssignmentTest.php, line 94
Definition of Drupal\user\Tests\UserRolesAssignmentTest.

Class

UserRolesAssignmentTest
Test role assignment.

Namespace

Drupal\user\Tests

Code

private function userLoadAndCheckRoleAssigned($account, $rid, $is_assigned = TRUE) {
  $account = user_load($account->uid, TRUE);
  if ($is_assigned) {
    $this
      ->assertTrue(array_search($rid, $account->roles), 'The role is present in the user object.');
  }
  else {
    $this
      ->assertFalse(array_search($rid, $account->roles), 'The role is not present in the user object.');
  }
}