You are here

public function GNodeViewAccessTests::testOutsiderPermissionBuildUp in Group 7

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

File

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

Class

GNodeViewAccessTests
Test for view access control.

Code

public function testOutsiderPermissionBuildUp() {
  $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);
  $web_user = $this
    ->drupalCreateUser(array(
    'access content',
  ));
  $this
    ->drupalLogin($web_user);
  $this
    ->assertNodeOperationAccess($node->nid, 'view', 403, 'Group node is not accessible by outsider without view permissions');
  $this
    ->assertNodesOnListingPage(array(), 'Group node is not visible on listing pages to outsider without view permissions.');
  $group_global_role
    ->grantPermissions(array(
    'view page node',
  ));
  $this
    ->assertNodeOperationAccess($node->nid, 'view', 403, 'Group node is still not accessible by outsider 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 outsider though group local role has permission.');
  $this
    ->assertNodesOnListingPage(array(), 'Group node is still not visible on listing pages to outsider 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 outsider though member role has permission.');
  $this
    ->assertNodesOnListingPage(array(), 'Group node is still not visible on listing pages to outsider though member role has permission.');
  $group_type->outsider_permissions = array(
    'view page node',
  );
  $group_type
    ->save();
  $this
    ->assertNodeOperationAccess($node->nid, 'view', 200, 'Group node is now accessible by outsider with view permissions.');
  $this
    ->assertNodesOnListingPage(array(
    $node->nid,
  ), 'Group node is now visible on listing pages to outsider with view permission.');
  $group_type->anonymous_permissions = array(
    'view page node',
  );
  $group_type
    ->save();
  $this
    ->assertNodeOperationAccess($node->nid, 'view', 200, 'Group node is still accessible by outsider now anonymous has view permissions.');
  $this
    ->assertNodesOnListingPage(array(
    $node->nid,
  ), 'Group node is still visible on listing pages to outsider now anonymous has view permissions.');
}