You are here

public function OpenAtriumAccessTestCase::testGroupAccess in Open Atrium Core 7.2

File

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

Class

OpenAtriumAccessTestCase
Functional tests for the Open Atrium Access module.

Code

public function testGroupAccess() {
  $group_a = $this
    ->oaCreateGroupWithUser(array(
    'title' => 'Group A',
  ), array(
    'access content',
  ));
  $group_b = $this
    ->oaCreateGroupWithUser(array(
    'title' => 'Group B',
  ), array(
    'access content',
  ));
  $not_in_group = $this
    ->oaCreateUser(array(
    'access content',
  ));
  $group_permissions = array(
    $group_a['group']->nid => array(
      'oa_access_test' => array(
        'access oa_access_test',
        'administer oa_access_test',
      ),
    ),
    $group_b['group']->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(NULL, 'access oa_access_test', $not_in_group));
  $this
    ->assertFalse(oa_access(NULL, 'administer oa_access_test', $not_in_group));
  $this
    ->assertTrue(oa_access(NULL, 'access oa_access_test', $group_a['user']));
  $this
    ->assertTrue(oa_access(NULL, 'administer oa_access_test', $group_a['user']));
  $this
    ->assertTrue(oa_access(NULL, 'access oa_access_test', $group_b['user']));
  $this
    ->assertFalse(oa_access(NULL, 'administer oa_access_test', $group_b['user']));

  // Assert that setting the 'All' group permission will give it to everyone
  // including even the user who is not in any group.
  $this
    ->assertFalse(oa_access(NULL, 'permission with all option for oa_access_test', $not_in_group));
  $this
    ->assertFalse(oa_access(NULL, 'permission with all option for oa_access_test', $group_a['user']));
  $this
    ->assertFalse(oa_access(NULL, 'permission with all option for oa_access_test', $group_b['user']));
  oa_access_set_group_permissions(array(
    0 => array(
      'oa_access_test' => array(
        'permission with all option for oa_access_test',
      ),
    ),
  ));
  drupal_static_reset('oa_access');
  $this
    ->assertTrue(oa_access(NULL, 'permission with all option for oa_access_test', $not_in_group));
  $this
    ->assertTrue(oa_access(NULL, 'permission with all option for oa_access_test', $group_a['user']));
  $this
    ->assertTrue(oa_access(NULL, 'permission with all option for oa_access_test', $group_b['user']));
}