You are here

function ContentAccessACLTestCase::testEditAccess in Content Access 5

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

Test Editing accessibility with permissions for single users

File

tests/content_access_acl.test, line 94

Class

ContentAccessACLTestCase

Code

function testEditAccess() {

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

  // Enable per node access control
  $this
    ->changeAccessPerNode();

  // Allow edit access for test user
  $edit = array(
    'acl[update][add]' => $this->test_user->name,
  );
  $this
    ->drupalPostRequest('node/' . $this->node->nid . '/access', $edit, 'acl[update][add_button]');
  $this
    ->postToCurrentPage(array(), 'Submit');

  // Logout admin, try to edit the node anonymously
  $this
    ->drupalGet(url('logout'));
  $this
    ->drupalGet(url('node/' . $this->node->nid . '/edit'));
  $this
    ->assertText(t('Access denied'), 'node is not editable');

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

  // Login admin and disable per node access
  $this
    ->drupalGet(url('logout'));
  $this
    ->drupalLoginUser($this->admin_user);
  $this
    ->changeAccessPerNode(FALSE);

  // Logout admin, try to edit the node anonymously
  $this
    ->drupalGet(url('logout'));
  $this
    ->drupalGet(url('node/' . $this->node->nid . '/edit'));
  $this
    ->assertText(t('Access denied'), 'node is not editable');

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