You are here

public function OpenAtriumAccessTestCase::testTeamAccess in Open Atrium Core 7.2

File

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

Class

OpenAtriumAccessTestCase
Functional tests for the Open Atrium Access module.

Code

public function testTeamAccess() {

  // 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);
  $team_b = $this
    ->oaCreateTeamWithUser(array(
    'title' => 'Team B',
  ), array(
    'access content',
  ), $space1);
  $not_in_team = $this
    ->oaCreateUser(array(
    'access content',
  ), $space1);
  $not_in_group = $this
    ->oaCreateUser(array(
    'access content',
  ));
  $group_permissions = array(
    $team_a['team']->nid => array(
      'oa_access_test' => array(
        'access oa_access_test',
        'administer oa_access_test',
      ),
    ),
    $team_b['team']->nid => array(
      'oa_access_test' => array(
        'access oa_access_test',
      ),
    ),
  );
  oa_access_set_group_permissions($group_permissions);

  // Make sure that each user has the permissions that they should.
  $this
    ->assertFalse(oa_access($space1, 'access oa_access_test', $not_in_team));
  $this
    ->assertFalse(oa_access($space1, 'administer oa_access_test', $not_in_team));
  $this
    ->assertFalse(oa_access($space1, 'access oa_access_test', $not_in_group));
  $this
    ->assertFalse(oa_access($space1, 'administer oa_access_test', $not_in_group));
  $this
    ->assertTrue(oa_access($space1, 'access oa_access_test', $team_a['user']));
  $this
    ->assertTrue(oa_access($space1, 'administer oa_access_test', $team_a['user']));
  $this
    ->assertTrue(oa_access($space1, 'access oa_access_test', $team_b['user']));
  $this
    ->assertFalse(oa_access($space1, 'administer oa_access_test', $team_b['user']));

  // Now, create a new Space which our users don't belong to and verify that
  // they don't get any permissions there.
  $space2 = $this
    ->oaCreateNode(array(
    'title' => 'Space B',
    'type' => 'oa_space',
    'uid' => $account->uid,
  ));
  $this
    ->assertFalse(oa_access($space2, 'access oa_access_test', $team_a['user']));
  $this
    ->assertFalse(oa_access($space2, 'administer oa_access_test', $team_a['user']));
  $this
    ->assertFalse(oa_access($space2, 'access oa_access_test', $team_b['user']));
  $this
    ->assertFalse(oa_access($space2, 'administer oa_access_test', $team_b['user']));

  // And, just for good measure, make sure they don't have these permissions
  // when we aren't in any Space context.
  $this
    ->assertFalse(oa_access(NULL, 'access oa_access_test', $team_a['user']));
  $this
    ->assertFalse(oa_access(NULL, 'administer oa_access_test', $team_a['user']));
  $this
    ->assertFalse(oa_access(NULL, 'access oa_access_test', $team_b['user']));
  $this
    ->assertFalse(oa_access(NULL, 'administer oa_access_test', $team_b['user']));

  // Assert that setting the 'All' team permission will give it to everyone
  // including even the user who is not in any team (but not the user who
  // isn't in the group).
  $this
    ->assertFalse(oa_access($space1, 'permission with all option for oa_access_test', $not_in_team));
  $this
    ->assertFalse(oa_access($space1, 'permission with all option for oa_access_test', $not_in_group));
  $this
    ->assertFalse(oa_access($space1, 'permission with all option for oa_access_test', $team_a['user']));
  $this
    ->assertFalse(oa_access($space1, 'permission with all option for oa_access_test', $team_b['user']));
  oa_access_set_group_permissions(array(
    $space1->nid => array(
      'oa_access_test' => array(
        'permission with all option for oa_access_test',
      ),
    ),
  ));
  drupal_static_reset('oa_access');
  $this
    ->assertTrue(oa_access($space1, 'permission with all option for oa_access_test', $not_in_team));
  $this
    ->assertFalse(oa_access($space1, 'permission with all option for oa_access_test', $not_in_group));
  $this
    ->assertTrue(oa_access($space1, 'permission with all option for oa_access_test', $team_a['user']));
  $this
    ->assertTrue(oa_access($space1, 'permission with all option for oa_access_test', $team_b['user']));
}