You are here

public function RoleDelegationOperationsTestCase::testOperationsWork in Role Delegation 7

Check that Add and Remove role operations work as intended.

File

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

Class

RoleDelegationOperationsTestCase
Functional tests for operations.

Code

public function testOperationsWork() {
  $uids_to_test = array(
    $this->user_high->uid,
    $this->user_low->uid,
  );
  $edit = array();
  foreach ($uids_to_test as $uid) {
    $edit["accounts[{$uid}]"] = TRUE;
  }
  $this
    ->drupalLogin($this->user_high);
  $this
    ->drupalGet('admin/people');

  // Add low role
  $edit['operation'] = "role_delegation_add_role-{$this->rid_low}";
  $this
    ->drupalPost(NULL, $edit, t('Update'));
  foreach ($uids_to_test as $uid) {
    $this
      ->assertFieldByXPath("//tbody/tr[{$uid}]/td[4]//li", 'low', t('!user user assigned !role role to user !uid.', array(
      '!user' => 'High',
      '!role' => 'low',
      '!uid' => $uid,
    )), t('Role Delegation'));
  }

  // Remove low role
  $edit['operation'] = "role_delegation_remove_role-{$this->rid_low}";
  $this
    ->drupalPost(NULL, $edit, t('Update'));
  foreach ($uids_to_test as $uid) {
    $this
      ->assertNoFieldByXPath("//tbody/tr[{$uid}]/td[4]//li", 'low', t('!user user removed !role role from user !uid.', array(
      '!user' => 'High',
      '!role' => 'low',
      '!uid' => $uid,
    )), t('Role Delegation'));
  }
}