You are here

protected function RoleDelegationTestCase::assignRoleToUser in Role Delegation 7

Assign or remove one role to/from one user.

The logged in user must have the "administer users" permission in order for this function to succeed.

Parameters

$rid: The role id of the role to assign or remove.

$user: The user object of the user to assign/remove the role to.

$assign: TRUE (the default) to assign the role, or FALSE to remove it.

Return value

TRUE or FALSE depending on whether the role was successfully assigned or removed.

3 calls to RoleDelegationTestCase::assignRoleToUser()
RoleDelegationPermissionsTestCase::testHighHigh in ./role_delegation.test
Check that high role can't assign high role.
RoleDelegationPermissionsTestCase::testHighLow in ./role_delegation.test
Check that high role can assign low role.
RoleDelegationTestCase::setUp in ./role_delegation.test
Sets up a Drupal site for running functional and integration tests.

File

./role_delegation.test, line 33
Tests for the Role Delegation module.

Class

RoleDelegationTestCase
Base class for Role Delegation tests.

Code

protected function assignRoleToUser($rid, $user, $assign = TRUE) {
  $this
    ->drupalGet("user/{$user->uid}/edit");
  if (count($this
    ->xpath("//input[@name='roles[{$rid}]']"))) {
    $name = "roles[{$rid}]";
  }
  elseif (count($this
    ->xpath("//input[@name='roles_change[{$rid}]']"))) {
    $name = "roles_change[{$rid}]";
  }
  else {
    return FALSE;
  }
  $this
    ->drupalPost(NULL, array(
    $name => $assign,
  ), t('Save'));
  $elements = $this
    ->xpath("//input[@name='{$name}']");
  return isset($elements[0]) && ($assign xor empty($elements[0]['checked']));
}