You are here

public function GNodeViewAccessTests::testAnonymousPermissionBuildUp in Group 7

Test the anonymous user does not receive access until their role has access even when higher roles do have access.

File

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

Class

GNodeViewAccessTests
Test for view access control.

Code

public function testAnonymousPermissionBuildUp() {
  $role = user_role_load_by_name('anonymous user');
  user_role_grant_permissions($role->rid, array(
    'access content',
  ));
  $group_type = $this
    ->createGroupType('example');
  $group = $this
    ->createGroup('example', 'example');
  $group_global_role = $this
    ->createRole('example_global_role');
  $group_local_role = $this
    ->createRole('example_local_role', 'example');
  $node = $this
    ->createNodeInGroup($group->gid);
  $this
    ->assertNodeOperationAccess($node->nid, 'view', 403, 'Group node is not accessible by anonymous without view permissions.');
  $this
    ->assertNodesOnListingPage(array(), 'Group node is not visible on listing pages to anonymous without view permissions.');
  $group_global_role
    ->grantPermissions(array(
    'view page node',
  ));
  $this
    ->assertNodeOperationAccess($node->nid, 'view', 403, 'Group node is still not accessible by anonymous though group global role has permission.');
  $this
    ->assertNodesOnListingPage(array(), 'Group node is still not visible on listing pages to anonymous though group global role has permission.');
  $group_local_role
    ->grantPermissions(array(
    'view page node',
  ));
  $this
    ->assertNodeOperationAccess($node->nid, 'view', 403, 'Group node is still not accessible by anonymous though group local role has permission.');
  $this
    ->assertNodesOnListingPage(array(), 'Group node is still not visible on listing pages to anonymous though group local role has permission.');
  $group_type->member_permissions = array(
    'view page node',
  );
  $group_type
    ->save();
  $this
    ->assertNodeOperationAccess($node->nid, 'view', 403, 'Group node is still not accessible by anonymous though member role has permission.');
  $this
    ->assertNodesOnListingPage(array(), 'Group node is still not visible on listing pages to anonymous though member role has permission.');
  $group_type->outsider_permissions = array(
    'view page node',
  );
  $group_type
    ->save();
  $this
    ->assertNodeOperationAccess($node->nid, 'view', 403, 'Group node is still not accessible by anonymous though outsider role has permission.');
  $this
    ->assertNodesOnListingPage(array(), 'Group node is still not visible on listing pages by anonymous though outsider role has permission.');
  $group_type->anonymous_permissions = array(
    'view page node',
  );
  $group_type
    ->save();
  $this
    ->assertNodeOperationAccess($node->nid, 'view', 200, 'Group node is finally accessible by anonymous with view permissions.');
  $this
    ->assertNodesOnListingPage(array(
    $node->nid,
  ), 'Group node is finally visible on listing pages by anonymous with view permissions.');
}