You are here

public function AccessGrantFunctionTest::testGrantStaticReset in Access Control Kit 7

Ensure that the access grant static reset works correctly.

File

./access.test, line 1236
Tests for the access control kit module.

Class

AccessGrantFunctionTest
Tests for access grant functions.

Code

public function testGrantStaticReset() {

  // Set the grant's realm value.
  $field_name = $this->scheme->realm_field['field_name'];
  $this->grants[0]->{$field_name} = array(
    'und' => array(
      array(
        'value' => 0,
      ),
    ),
  );
  access_grant_save($this->grants[0]);

  // Load the grant.
  $original_grant = access_grant_load($this->grants[0]->gid);
  $this
    ->assertTrue(is_object($original_grant) && $original_grant->gid == $this->grants[0]->gid, 'Grant loaded successfully.');
  $this_grant_field = $this->grants[0]->{$field_name};
  $original_grant_field = $original_grant->{$field_name};
  $this
    ->assertEqual($original_grant_field['und'][0]['value'], $this_grant_field['und'][0]['value']);

  // Change the grant's realm value.
  $grant = $original_grant;
  $grant->{$field_name} = array(
    'und' => array(
      array(
        'value' => 1,
      ),
    ),
  );
  access_grant_save($grant);

  // Reload the grant.
  $new_grant = access_grant_load($original_grant->gid);
  $grant_field = $grant->{$field_name};
  $new_grant_field = $new_grant->{$field_name};
  $this
    ->assertEqual($new_grant_field['und'][0]['value'], $grant_field['und'][0]['value']);

  // Delete the grant.
  $grants = access_grant_load_multiple(FALSE);
  $this
    ->assertTrue(isset($grants[$this->grants[0]->gid]), 'The grant exists.');
  access_grant_delete($this->grants[0]->gid);
  $grants = access_grant_load_multiple(FALSE);
  $this
    ->assertTrue(!isset($grants[$this->grants[0]->gid]), 'The grant was deleted.');
}