You are here

public function OpenAtriumAccessTestCase::testCleanupPermissions in Open Atrium Core 7.2

File

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

Class

OpenAtriumAccessTestCase
Functional tests for the Open Atrium Access module.

Code

public function testCleanupPermissions() {
  $group_a = $this
    ->oaCreateGroupWithUser(array(
    'title' => 'Group A',
  ), array(
    'access content',
  ));
  $group_b = $this
    ->oaCreateGroupWithUser(array(
    'title' => 'Group B',
  ), array(
    'access content',
  ));

  // Add some groups with a permission available, that we're going to remove
  // and then cleanup.
  $group_permissions = array(
    $group_a['group']->nid => array(
      'oa_access_test' => array(
        'a permission for oa_access_test that is only conditionally available',
        'access oa_access_test',
      ),
    ),
    $group_b['group']->nid => array(
      'oa_access_test' => array(
        'a permission for oa_access_test that is only conditionally available',
      ),
    ),
  );
  oa_access_set_group_permissions($group_permissions);

  // Now, we remove the permission.
  variable_set('oa_access_test_remove_permission', TRUE);
  drupal_static_reset('oa_access_get_permissions');
  $valid_permissions = oa_access_get_permissions();
  $this
    ->assertFalse(isset($valid_permissions['a permission for oa_access_test that is only conditionally available']));

  // Before we do the clean-up, the removed permission will still be set for
  // $group_a and $group_b. Clear the static cache to make sure we're getting
  // the database version.
  drupal_static_reset('oa_access_get_group_permissions');
  $this
    ->assertEqual(oa_access_get_group_permissions(array_keys($group_permissions)), $group_permissions);

  // Perform the clean-up.
  oa_access_cleanup_permissions();

  // And now verify that the permissions have been removed.
  drupal_static_reset('oa_access_get_group_permissions');
  $this
    ->assertEqual(oa_access_get_group_permissions(array_keys($group_permissions)), array(
    $group_a['group']->nid => array(
      'oa_access_test' => array(
        'access oa_access_test',
      ),
    ),
    $group_b['group']->nid => array(),
  ));
}