You are here

public function AdministerUsersByRoleTestCase::testPermissions in Administer Users by Role 6

Same name and namespace in other branches
  1. 7.2 administerusersbyrole.test \AdministerUsersByRoleTestCase::testPermissions()
  2. 7 administerusersbyrole.test \AdministerUsersByRoleTestCase::testPermissions()

File

./administerusersbyrole.test, line 143
Test Administer Users by Role.

Class

AdministerUsersByRoleTestCase
@file Test Administer Users by Role.

Code

public function testPermissions() {
  $expectations = array(
    // When I'm logged in as...
    'nobody' => array(
      // ...I can perform these actions on this other user...
      'noroles' => array(
        'edit' => FALSE,
        'delete' => FALSE,
      ),
      'alpha' => array(
        'edit' => FALSE,
        'delete' => FALSE,
      ),
      'alpha_editor' => array(
        'edit' => FALSE,
        'delete' => FALSE,
      ),
      'alpha_o_ed' => array(
        'edit' => FALSE,
        'delete' => FALSE,
      ),
      'alpha_o_del' => array(
        'edit' => FALSE,
        'delete' => FALSE,
      ),
      'beta' => array(
        'edit' => FALSE,
        'delete' => FALSE,
      ),
      'beta_editor' => array(
        'edit' => FALSE,
        'delete' => FALSE,
      ),
      'beta_o_ed' => array(
        'edit' => FALSE,
        'delete' => FALSE,
      ),
      'alphabeta' => array(
        'edit' => FALSE,
        'delete' => FALSE,
      ),
      'creator' => array(
        'edit' => FALSE,
        'delete' => FALSE,
      ),
      'all_editor' => array(
        'edit' => FALSE,
        'delete' => FALSE,
      ),
      'all_deletor' => array(
        'edit' => FALSE,
        'delete' => FALSE,
      ),
      'create users' => FALSE,
    ),
    'noroles' => array(
      'noroles' => array(
        'edit' => TRUE,
        'delete' => FALSE,
      ),
      'alpha' => array(
        'edit' => FALSE,
        'delete' => FALSE,
      ),
      'alpha_editor' => array(
        'edit' => FALSE,
        'delete' => FALSE,
      ),
      'alpha_o_ed' => array(
        'edit' => FALSE,
        'delete' => FALSE,
      ),
      'alpha_o_del' => array(
        'edit' => FALSE,
        'delete' => FALSE,
      ),
      'beta' => array(
        'edit' => FALSE,
        'delete' => FALSE,
      ),
      'beta_editor' => array(
        'edit' => FALSE,
        'delete' => FALSE,
      ),
      'beta_o_ed' => array(
        'edit' => FALSE,
        'delete' => FALSE,
      ),
      'alphabeta' => array(
        'edit' => FALSE,
        'delete' => FALSE,
      ),
      'creator' => array(
        'edit' => FALSE,
        'delete' => FALSE,
      ),
      'all_editor' => array(
        'edit' => FALSE,
        'delete' => FALSE,
      ),
      'all_deletor' => array(
        'edit' => FALSE,
        'delete' => FALSE,
      ),
      'create users' => FALSE,
    ),
    'alpha' => array(
      'noroles' => array(
        'edit' => FALSE,
        'delete' => FALSE,
      ),
      'alpha' => array(
        'edit' => TRUE,
        'delete' => FALSE,
      ),
      'alpha_editor' => array(
        'edit' => FALSE,
        'delete' => FALSE,
      ),
      'alpha_o_ed' => array(
        'edit' => FALSE,
        'delete' => FALSE,
      ),
      'alpha_o_del' => array(
        'edit' => FALSE,
        'delete' => FALSE,
      ),
      'beta' => array(
        'edit' => FALSE,
        'delete' => FALSE,
      ),
      'beta_editor' => array(
        'edit' => FALSE,
        'delete' => FALSE,
      ),
      'beta_o_ed' => array(
        'edit' => FALSE,
        'delete' => FALSE,
      ),
      'alphabeta' => array(
        'edit' => FALSE,
        'delete' => FALSE,
      ),
      'creator' => array(
        'edit' => FALSE,
        'delete' => FALSE,
      ),
      'all_editor' => array(
        'edit' => FALSE,
        'delete' => FALSE,
      ),
      'all_deletor' => array(
        'edit' => FALSE,
        'delete' => FALSE,
      ),
      'create users' => FALSE,
    ),
    'alpha_editor' => array(
      'noroles' => array(
        'edit' => FALSE,
        'delete' => FALSE,
      ),
      'alpha' => array(
        'edit' => TRUE,
        'delete' => FALSE,
      ),
      'alpha_editor' => array(
        'edit' => TRUE,
        'delete' => FALSE,
      ),
      'alpha_o_ed' => array(
        'edit' => FALSE,
        'delete' => FALSE,
      ),
      'alpha_o_del' => array(
        'edit' => FALSE,
        'delete' => FALSE,
      ),
      'beta' => array(
        'edit' => FALSE,
        'delete' => FALSE,
      ),
      'beta_editor' => array(
        'edit' => FALSE,
        'delete' => FALSE,
      ),
      'beta_o_ed' => array(
        'edit' => FALSE,
        'delete' => FALSE,
      ),
      'alphabeta' => array(
        'edit' => FALSE,
        'delete' => FALSE,
      ),
      'creator' => array(
        'edit' => FALSE,
        'delete' => FALSE,
      ),
      'all_editor' => array(
        'edit' => FALSE,
        'delete' => FALSE,
      ),
      'all_deletor' => array(
        'edit' => FALSE,
        'delete' => FALSE,
      ),
      'create users' => FALSE,
    ),
    'alpha_o_ed' => array(
      'noroles' => array(
        'edit' => FALSE,
        'delete' => FALSE,
      ),
      'alpha' => array(
        'edit' => TRUE,
        'delete' => FALSE,
      ),
      'alpha_editor' => array(
        'edit' => FALSE,
        'delete' => FALSE,
      ),
      'alpha_o_ed' => array(
        'edit' => TRUE,
        'delete' => FALSE,
      ),
      'alpha_o_del' => array(
        'edit' => FALSE,
        'delete' => FALSE,
      ),
      'beta' => array(
        'edit' => FALSE,
        'delete' => FALSE,
      ),
      'beta_editor' => array(
        'edit' => FALSE,
        'delete' => FALSE,
      ),
      'beta_o_ed' => array(
        'edit' => FALSE,
        'delete' => FALSE,
      ),
      'alphabeta' => array(
        'edit' => TRUE,
        'delete' => FALSE,
      ),
      'creator' => array(
        'edit' => FALSE,
        'delete' => FALSE,
      ),
      'all_editor' => array(
        'edit' => FALSE,
        'delete' => FALSE,
      ),
      'all_deletor' => array(
        'edit' => FALSE,
        'delete' => FALSE,
      ),
      'create users' => FALSE,
    ),
    'alpha_o_del' => array(
      'noroles' => array(
        'edit' => FALSE,
        'delete' => FALSE,
      ),
      'alpha' => array(
        'edit' => FALSE,
        'delete' => TRUE,
      ),
      'alpha_editor' => array(
        'edit' => FALSE,
        'delete' => FALSE,
      ),
      'alpha_o_ed' => array(
        'edit' => FALSE,
        'delete' => FALSE,
      ),
      'alpha_o_del' => array(
        'edit' => TRUE,
        'delete' => FALSE,
      ),
      'beta' => array(
        'edit' => FALSE,
        'delete' => FALSE,
      ),
      'beta_editor' => array(
        'edit' => FALSE,
        'delete' => FALSE,
      ),
      'beta_o_ed' => array(
        'edit' => FALSE,
        'delete' => FALSE,
      ),
      'alphabeta' => array(
        'edit' => FALSE,
        'delete' => TRUE,
      ),
      'creator' => array(
        'edit' => FALSE,
        'delete' => FALSE,
      ),
      'all_editor' => array(
        'edit' => FALSE,
        'delete' => FALSE,
      ),
      'all_deletor' => array(
        'edit' => FALSE,
        'delete' => FALSE,
      ),
      'create users' => FALSE,
    ),
    'beta' => array(
      'noroles' => array(
        'edit' => FALSE,
        'delete' => FALSE,
      ),
      'alpha' => array(
        'edit' => FALSE,
        'delete' => FALSE,
      ),
      'alpha_editor' => array(
        'edit' => FALSE,
        'delete' => FALSE,
      ),
      'alpha_o_ed' => array(
        'edit' => FALSE,
        'delete' => FALSE,
      ),
      'alpha_o_del' => array(
        'edit' => FALSE,
        'delete' => FALSE,
      ),
      'beta' => array(
        'edit' => TRUE,
        'delete' => FALSE,
      ),
      'beta_editor' => array(
        'edit' => FALSE,
        'delete' => FALSE,
      ),
      'beta_o_ed' => array(
        'edit' => FALSE,
        'delete' => FALSE,
      ),
      'alphabeta' => array(
        'edit' => FALSE,
        'delete' => FALSE,
      ),
      'creator' => array(
        'edit' => FALSE,
        'delete' => FALSE,
      ),
      'all_editor' => array(
        'edit' => FALSE,
        'delete' => FALSE,
      ),
      'all_deletor' => array(
        'edit' => FALSE,
        'delete' => FALSE,
      ),
      'create users' => FALSE,
    ),
    'beta_editor' => array(
      'noroles' => array(
        'edit' => FALSE,
        'delete' => FALSE,
      ),
      'alpha' => array(
        'edit' => FALSE,
        'delete' => FALSE,
      ),
      'alpha_editor' => array(
        'edit' => FALSE,
        'delete' => FALSE,
      ),
      'alpha_o_ed' => array(
        'edit' => FALSE,
        'delete' => FALSE,
      ),
      'alpha_o_del' => array(
        'edit' => FALSE,
        'delete' => FALSE,
      ),
      'beta' => array(
        'edit' => TRUE,
        'delete' => TRUE,
      ),
      'beta_editor' => array(
        'edit' => TRUE,
        'delete' => FALSE,
      ),
      'beta_o_ed' => array(
        'edit' => FALSE,
        'delete' => FALSE,
      ),
      'alphabeta' => array(
        'edit' => FALSE,
        'delete' => FALSE,
      ),
      'creator' => array(
        'edit' => FALSE,
        'delete' => FALSE,
      ),
      'all_editor' => array(
        'edit' => FALSE,
        'delete' => FALSE,
      ),
      'all_deletor' => array(
        'edit' => FALSE,
        'delete' => FALSE,
      ),
      'create users' => FALSE,
    ),
    'beta_o_ed' => array(
      'noroles' => array(
        'edit' => FALSE,
        'delete' => FALSE,
      ),
      'alpha' => array(
        'edit' => FALSE,
        'delete' => FALSE,
      ),
      'alpha_editor' => array(
        'edit' => FALSE,
        'delete' => FALSE,
      ),
      'alpha_o_ed' => array(
        'edit' => FALSE,
        'delete' => FALSE,
      ),
      'alpha_o_del' => array(
        'edit' => FALSE,
        'delete' => FALSE,
      ),
      'beta' => array(
        'edit' => TRUE,
        'delete' => FALSE,
      ),
      'beta_editor' => array(
        'edit' => FALSE,
        'delete' => FALSE,
      ),
      'beta_o_ed' => array(
        'edit' => TRUE,
        'delete' => FALSE,
      ),
      'alphabeta' => array(
        'edit' => TRUE,
        'delete' => FALSE,
      ),
      'creator' => array(
        'edit' => FALSE,
        'delete' => FALSE,
      ),
      'all_editor' => array(
        'edit' => FALSE,
        'delete' => FALSE,
      ),
      'all_deletor' => array(
        'edit' => FALSE,
        'delete' => FALSE,
      ),
      'create users' => FALSE,
    ),
    'alphabeta' => array(
      'noroles' => array(
        'edit' => FALSE,
        'delete' => FALSE,
      ),
      'alpha' => array(
        'edit' => FALSE,
        'delete' => FALSE,
      ),
      'alpha_editor' => array(
        'edit' => FALSE,
        'delete' => FALSE,
      ),
      'alpha_o_ed' => array(
        'edit' => FALSE,
        'delete' => FALSE,
      ),
      'alpha_o_del' => array(
        'edit' => FALSE,
        'delete' => FALSE,
      ),
      'beta' => array(
        'edit' => FALSE,
        'delete' => FALSE,
      ),
      'beta_editor' => array(
        'edit' => FALSE,
        'delete' => FALSE,
      ),
      'beta_o_ed' => array(
        'edit' => FALSE,
        'delete' => FALSE,
      ),
      'alphabeta' => array(
        'edit' => TRUE,
        'delete' => FALSE,
      ),
      'creator' => array(
        'edit' => FALSE,
        'delete' => FALSE,
      ),
      'all_editor' => array(
        'edit' => FALSE,
        'delete' => FALSE,
      ),
      'all_deletor' => array(
        'edit' => FALSE,
        'delete' => FALSE,
      ),
      'create users' => FALSE,
    ),
    'all_editor' => array(
      'noroles' => array(
        'edit' => TRUE,
        'delete' => FALSE,
      ),
      'alpha' => array(
        'edit' => TRUE,
        'delete' => FALSE,
      ),
      'alpha_editor' => array(
        'edit' => TRUE,
        'delete' => FALSE,
      ),
      'alpha_o_ed' => array(
        'edit' => TRUE,
        'delete' => FALSE,
      ),
      'alpha_o_del' => array(
        'edit' => TRUE,
        'delete' => FALSE,
      ),
      'beta' => array(
        'edit' => TRUE,
        'delete' => FALSE,
      ),
      'beta_editor' => array(
        'edit' => TRUE,
        'delete' => FALSE,
      ),
      'beta_o_ed' => array(
        'edit' => TRUE,
        'delete' => FALSE,
      ),
      'alphabeta' => array(
        'edit' => TRUE,
        'delete' => FALSE,
      ),
      'creator' => array(
        'edit' => FALSE,
        'delete' => FALSE,
      ),
      'all_editor' => array(
        'edit' => TRUE,
        'delete' => FALSE,
      ),
      'all_deletor' => array(
        'edit' => FALSE,
        'delete' => FALSE,
      ),
      'create users' => FALSE,
    ),
    'all_deletor' => array(
      'noroles' => array(
        'edit' => FALSE,
        'delete' => TRUE,
      ),
      'alpha' => array(
        'edit' => FALSE,
        'delete' => TRUE,
      ),
      'alpha_editor' => array(
        'edit' => FALSE,
        'delete' => TRUE,
      ),
      'alpha_o_ed' => array(
        'edit' => FALSE,
        'delete' => TRUE,
      ),
      'alpha_o_del' => array(
        'edit' => FALSE,
        'delete' => TRUE,
      ),
      'beta' => array(
        'edit' => FALSE,
        'delete' => TRUE,
      ),
      'beta_editor' => array(
        'edit' => FALSE,
        'delete' => TRUE,
      ),
      'beta_o_ed' => array(
        'edit' => FALSE,
        'delete' => TRUE,
      ),
      'alphabeta' => array(
        'edit' => FALSE,
        'delete' => TRUE,
      ),
      'creator' => array(
        'edit' => FALSE,
        'delete' => FALSE,
      ),
      'all_editor' => array(
        'edit' => FALSE,
        'delete' => TRUE,
      ),
      'all_deletor' => array(
        'edit' => TRUE,
        'delete' => FALSE,
      ),
      'create users' => FALSE,
    ),
    'creator' => array(
      'noroles' => array(
        'edit' => FALSE,
        'delete' => FALSE,
      ),
      'alpha' => array(
        'edit' => FALSE,
        'delete' => FALSE,
      ),
      'alpha_editor' => array(
        'edit' => FALSE,
        'delete' => FALSE,
      ),
      'alpha_o_ed' => array(
        'edit' => FALSE,
        'delete' => FALSE,
      ),
      'alpha_o_del' => array(
        'edit' => FALSE,
        'delete' => FALSE,
      ),
      'beta' => array(
        'edit' => FALSE,
        'delete' => FALSE,
      ),
      'beta_editor' => array(
        'edit' => FALSE,
        'delete' => FALSE,
      ),
      'beta_o_ed' => array(
        'edit' => FALSE,
        'delete' => FALSE,
      ),
      'alphabeta' => array(
        'edit' => FALSE,
        'delete' => FALSE,
      ),
      'creator' => array(
        'edit' => TRUE,
        'delete' => FALSE,
      ),
      'all_editor' => array(
        'edit' => FALSE,
        'delete' => FALSE,
      ),
      'all_deletor' => array(
        'edit' => FALSE,
        'delete' => FALSE,
      ),
      'create users' => TRUE,
    ),
  );
  foreach ($expectations as $loginUsername => $editUsernames) {
    if ($loginUsername !== 'nobody') {
      $this
        ->drupalLogin($this->users[$loginUsername]);
    }
    foreach ($editUsernames as $k => $v) {
      if ($k === 'create users') {
        $this
          ->drupalGet("admin/user/user/create");
        $expectedResult = $v;
        if ($expectedResult) {
          $this
            ->assertRaw('This web page allows administrators to register new users.', "My expectation is that {$loginUsername} should be able to create users, but it can't.");
        }
        else {
          $this
            ->assertRaw('You do not have permission to create users.', "My expectation is that {$loginUsername} shouldn't be able to create users, but it can.");
        }
      }
      else {
        $editUsername = $k;
        $operations = $v;
        $editUid = $this->users[$editUsername]->uid;
        foreach ($operations as $operation => $expectedResult) {
          $this
            ->drupalGet("user/{$editUid}/{$operation}");
          if ($expectedResult) {
            if ($operation === 'edit') {
              $this
                ->assertRaw("All e-mails from the system will be sent to this address.", "My expectation is that {$loginUsername} should be able to {$operation} {$editUsername}, but it can't.");
            }
            elseif ($operation === 'delete') {
              $this
                ->assertRaw("Are you sure you want to delete the account <em>{$editUsername}</em>?", "My expectation is that {$loginUsername} should be able to {$operation} {$editUsername}, but it can't.");
            }
          }
          else {
            $this
              ->assertTrue(strstr($this
              ->drupalGetContent(), "You do not have permission to {$operation} <em>{$editUsername}</em>.") || strstr($this
              ->drupalGetContent(), 'You are not authorized to access this page.'), "My expectation is that {$loginUsername} shouldn't be able to {$operation} {$editUsername}, but it can.");
          }
        }
      }
    }
    if ($loginUsername !== 'nobody') {
      $this
        ->drupalLogout();
    }
  }
}