You are here

public function OpenAtriumAccessTestCase::testTeamOverride in Open Atrium Core 7.2

File

modules/oa_access/tests/oa_access.test, line 627
Functional tests for the Open Atrium Access module.

Class

OpenAtriumAccessTestCase
Functional tests for the Open Atrium Access module.

Code

public function testTeamOverride() {

  // Create an admin user and login.
  $account = $this
    ->oaCreateUser(array(
    'create oa_space content',
  ));
  $this
    ->drupalLogin($account);

  // Create a Space that all our users are going to belong to.
  $space1 = $this
    ->oaCreateNode(array(
    'title' => 'Space A',
    'type' => 'oa_space',
    'uid' => $account->uid,
  ));
  $team_a = $this
    ->oaCreateTeamWithUser(array(
    'title' => 'Team A',
  ), array(
    'access content',
  ), $space1);
  $not_in_team = $this
    ->oaCreateUser(array(
    'access content',
  ), $space1);
  $not_in_space = $this
    ->oaCreateUser(array(
    'access content',
  ));
  $group_permissions = array(
    // Say (via Groups permissions) that 'All site users' have access to this
    // permission.
    0 => array(
      'oa_access_test' => array(
        'access oa_access_test team override',
      ),
    ),
    $team_a['team']->nid => array(
      'oa_access_test' => array(
        'access oa_access_test team override',
      ),
    ),
  );
  oa_access_set_group_permissions($group_permissions);

  // So, in this case, only members of $team_a should have this permission
  // even though 'All site users' have it, the Team permissions have further
  // reduced access.
  $this
    ->assertTrue(oa_access($space1, 'access oa_access_test team override', $team_a['user']));
  $this
    ->assertFalse(oa_access($space1, 'access oa_access_test team override', $not_in_team));
  $this
    ->assertFalse(oa_access($space1, 'access oa_access_test team override', $not_in_space));

  // However, if we are operating outside of a Space context, then all users
  // should get it, ie. there are no Teams to restrict access further.
  $this
    ->assertTrue(oa_access(NULL, 'access oa_access_test team override', $team_a['user']));
  $this
    ->assertTrue(oa_access(NULL, 'access oa_access_test team override', $not_in_team));
  $this
    ->assertTrue(oa_access(NULL, 'access oa_access_test team override', $not_in_space));
}