You are here

public function AccessAPITest::testHandlerMethods in Access Control Kit 7

Test access arbitration through our dummy handler.

File

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

Class

AccessAPITest
Tests the access control kit API.

Code

public function testHandlerMethods() {
  $dummy_object = new stdClass();

  // Attach the test "meow" handler for dummy "cat" and "dog" object types.
  entity_get_controller('access_scheme')
    ->attachHandler($this->scheme, 'cat', 'ACKTestMeowHandler');
  entity_get_controller('access_scheme')
    ->attachHandler($this->scheme, 'dog', 'ACKTestMeowHandler');
  access_scheme_save($this->scheme);

  // Reset the scheme cache.
  $this->scheme = access_scheme_load($this->scheme->sid, TRUE);

  // Create an access grant in the scheme for a test user.
  $grant = $this
    ->createGrant($this->scheme, $this->ackRole);

  // Assign access in the TRUE realm.
  $fieldname = $this->scheme->realm_field_name;
  $grant->{$fieldname} = array(
    LANGUAGE_NONE => array(
      array(
        'value' => TRUE,
      ),
    ),
  );
  access_grant_save($grant);

  // Reset grant cache.
  access_grant_load($grant->gid, TRUE);

  // Get the test user.
  $test_user = user_load($grant->uid, TRUE);

  // Check access.
  $this
    ->assertTrue(access_user_object_access('meow', 'cat', $dummy_object, $test_user), 'User has access to an object in an assigned realm.');
  $this
    ->assertFalse(access_user_object_access('meow', 'dog', $dummy_object, $test_user), 'User does not have access to an object in an unassigned realm.');
}