You are here

public function GNodeBypassAccessTests::testAnonymousBypassGroupAccess in Group 7

Test anonymous user's access to nodes in a group when granted bypass group access.

File

modules/gnode/tests/gnode.test, line 965
Tests for the gnode module.

Class

GNodeBypassAccessTests
Test for bypass access control.

Code

public function testAnonymousBypassGroupAccess() {
  $role = user_role_load_by_name('anonymous user');
  user_role_grant_permissions($role->rid, array(
    'access content',
    'bypass group access',
  ));
  $group_type = $this
    ->createGroupType('example');
  $group = $this
    ->createGroup('example', 'example');
  $node = $this
    ->createNodeInGroup($group->gid);
  $group_type->anonymous_permissions = array();
  $group_type
    ->save();
  $this
    ->assertNodeOperationAccess($node->nid, 'view', 200, 'Group node is accessible by anonymous with bypass group access user permissions');
  $this
    ->assertNodeOperationAccess($node->nid, 'edit', 200, 'Group node is editable by anonymous with bypass group access user permissions');
  $this
    ->assertNodeOperationAccess($node->nid, 'delete', 200, 'Group node is deletable by anonymous with bypass group access user permissions');
  $this
    ->removeNodeFromGroup($node);
  $this
    ->assertNodeOperationAccess($node->nid, 'view', 200, 'Node not in group is accessible by anonymous with bypass group access permission');
  $this
    ->assertNodeOperationAccess($node->nid, 'edit', 403, 'Node not in group is not editable by anonymous with bypass group access permission');
  $this
    ->assertNodeOperationAccess($node->nid, 'delete', 403, 'Node not in group is not deletable by anonymous with bypass group access permission');
}