You are here

function OgUiAdminPermissionsTestCase::testOgUiAdminTabAccess in Organic groups 7.2

Check access permissions to the group admin tab.

File

og_ui/og_ui.test, line 80

Class

OgUiAdminPermissionsTestCase

Code

function testOgUiAdminTabAccess() {
  $user1 = $this
    ->drupalCreateUser();
  $user2 = $this
    ->drupalCreateUser();
  $settings = array();
  $settings['uid'] = $user1->uid;
  $settings['type'] = 'article';
  $settings[OG_GROUP_FIELD][LANGUAGE_NONE][0]['value'] = 1;
  $node = $this
    ->drupalCreateNode($settings);
  $this
    ->drupalLogin($user2);

  // User does not have any access permissions.
  $this
    ->drupalGet('node/' . $node->nid . '/group');
  $this
    ->assertResponse(403, t('User without privileges can not access group admin tabs.'));
  $perms = array(
    'add user',
    'manage members',
    'manage roles',
    'manage permissions',
  );
  $roles = og_roles('node', 'article');
  $auth_rid = array_search(OG_ANONYMOUS_ROLE, $roles);
  foreach ($perms as $perm) {

    // Add an admin permission to allow the user to access to the admin tabs.
    og_role_grant_permissions($auth_rid, array(
      $perm,
    ));
    $this
      ->drupalGet('node/' . $node->nid . '/group');
    $this
      ->assertResponse(200, t('User with "@perm" privilege can access group admin tabs.', array(
      '@perm' => $perm,
    )));

    // Remove the admin permission to restrict user access to the admin tabs.
    // User is left without admin permissions for the next loop.
    og_role_revoke_permissions($auth_rid, array(
      $perm,
    ));
  }
}