You are here

public function GNodeViewAccessTests::testAnonymousViewAccess in Group 7

Test anonymous user's view access to nodes in a group.

File

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

Class

GNodeViewAccessTests
Test for view access control.

Code

public function testAnonymousViewAccess() {
  $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');
  $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_type->anonymous_permissions = array(
    'view page node',
  );
  $group_type
    ->save();
  $this
    ->assertNodeOperationAccess($node->nid, 'view', 200, 'Group node is accessible by anonymous with view permissions');
  $this
    ->assertNodesOnListingPage(array(
    $node->nid,
  ), 'Group node is visible on listing pages to anonymous with view permissions.');
  $group_type->anonymous_permissions = array(
    'administer group',
  );
  $group_type
    ->save();
  $this
    ->assertNodeOperationAccess($node->nid, 'view', 200, 'Group node is accessible by anonymous with administer group permissions');
  $this
    ->assertNodesOnListingPage(array(
    $node->nid,
  ), 'Group node is visible on listing pages to anonymous with administer group permissions.');
  $this
    ->removeNodeFromGroup($node);
  $this
    ->assertNodeOperationAccess($node->nid, 'view', 200, 'Node not in group is accessible by anonymous with standard access content permission');
  $this
    ->assertNodesOnListingPage(array(
    $node->nid,
  ), 'Node not in group is visible on listing pages to anonymous with administer group permissions.');
}