You are here

public function RoleExpireWebTestCase::testAssignAndRemoveRole in Role Expire 7

File

tests/role_expire.test, line 156

Class

RoleExpireWebTestCase
@package RoleExpireWebTestCase

Code

public function testAssignAndRemoveRole() {

  // Create and log in the operating user.
  $admin_user = $this
    ->drupalCreateUser(array(
    'administer users',
    'administer role expire',
  ));
  $this
    ->drupalLogin($admin_user);

  // Create the victim (with a randomly assigned role).
  $victim_user = $this
    ->drupalCreateUser();

  // Get the victim's highest rid.
  $all_rids = array_keys($victim_user->roles);
  sort($all_rids);
  $rid = array_pop($all_rids);

  // Assign the role to the user.
  $this
    ->drupalPost('user/' . $victim_user->uid . '/edit', array(
    "roles[{$rid}]" => $rid,
  ), t('Save'));
  $this
    ->assertText(t('The changes have been saved.'));
  $this
    ->assertFieldChecked('edit-roles-' . $rid, t('Role is assigned.'));

  // Remove the role from the user.
  $this
    ->drupalPost('user/' . $victim_user->uid . '/edit', array(
    "roles[{$rid}]" => FALSE,
  ), t('Save'));
  $this
    ->assertText(t('The changes have been saved.'));
  $this
    ->assertNoFieldChecked('edit-roles-' . $rid, t('Role is removed from user.'));
}