You are here

function ContentAccessACLTestCase::testViewAccess in Content Access 7

Same name and namespace in other branches
  1. 5 tests/content_access_acl.test \ContentAccessACLTestCase::testViewAccess()
  2. 6 tests/content_access_acl.test \ContentAccessACLTestCase::testViewAccess()

Test Viewing accessibility with permissions for single users

File

tests/content_access_acl.test, line 46

Class

ContentAccessACLTestCase

Code

function testViewAccess() {

  // Exit test if ACL module could not be enabled
  if (!module_exists('acl')) {
    $this
      ->pass('No ACL module present, skipping test');
    return;
  }

  // Restrict access to this content type (access is only allowed for the author)
  // Enable per node access control
  $access_permissions = array(
    'view[1]' => FALSE,
    'view[2]' => FALSE,
    'per_node' => TRUE,
  );
  $this
    ->changeAccessContentType($access_permissions);

  // Allow access for test user
  $edit = array(
    'acl[view][add]' => $this->test_user->name,
  );
  $this
    ->drupalPost('node/' . $this->node->nid . '/access', $edit, t('Add User'));
  $this
    ->drupalPost(NULL, array(), t('Submit'));

  // Logout admin, try to access the node anonymously
  $this
    ->drupalLogout();
  $this
    ->drupalGet('node/' . $this->node->nid);
  $this
    ->assertText(t('Access denied'), 'node is not viewable');

  // Login test user, view access should be allowed now
  $this
    ->drupalLogin($this->test_user);
  $this
    ->drupalGet('node/' . $this->node->nid);
  $this
    ->assertNoText(t('Access denied'), 'node is viewable');

  // Login admin and disable per node access
  $this
    ->drupalLogin($this->admin_user);
  $this
    ->changeAccessPerNode(FALSE);

  // Logout admin, try to access the node anonymously
  $this
    ->drupalLogout();
  $this
    ->drupalGet('node/' . $this->node->nid);
  $this
    ->assertText(t('Access denied'), 'node is not viewable');

  // Login test user, view access should be denied now
  $this
    ->drupalLogin($this->test_user);
  $this
    ->drupalGet('node/' . $this->node->nid);
  $this
    ->assertText(t('Access denied'), 'node is not viewable');
}