You are here

function ContentAccessModuleTestCase::testEditAccess in Content Access 6

Same name and namespace in other branches
  1. 5 tests/content_access.test \ContentAccessModuleTestCase::testEditAccess()
  2. 7 tests/content_access.test \ContentAccessModuleTestCase::testEditAccess()

Test for editing nodes

File

tests/content_access.test, line 120

Class

ContentAccessModuleTestCase

Code

function testEditAccess() {

  // Logout admin and try to edit the node anonymously
  $this
    ->drupalLogout();
  $this
    ->drupalGet('node/' . $this->node1->nid . '/edit');
  $this
    ->assertText(t('Access denied'), 'edit access denied for anonymous');

  // Login test user, edit node, access must be denied
  $this
    ->drupalLogin($this->test_user);
  $this
    ->drupalGet('node/' . $this->node1->nid . '/edit');
  $this
    ->assertText(t('Access denied'), 'edit access denied for test user');

  // Login admin and grant access for editing to the test user
  $this
    ->drupalLogin($this->admin_user);
  $this
    ->changeAccessContentTypeKeyword('update');

  // Logout admin and try to edit the node anonymously
  // access must be denied again
  $this
    ->drupalLogout();
  $this
    ->drupalGet('node/' . $this->node1->nid . '/edit');
  $this
    ->assertText(t('Access denied'), 'edit access denied for anonymous');

  // Login test user, edit node, access must be granted
  $this
    ->drupalLogin($this->test_user);
  $this
    ->drupalGet('node/' . $this->node1->nid . '/edit');
  $this
    ->assertNoText(t('Access denied'), 'node1 is editable');

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

  // Restrict access for this content type for the test user
  $this
    ->changeAccessContentTypeKeyword('update', FALSE);

  // Allow acces for node1 only
  $this
    ->changeAccessNodeKeyword($this->node1, 'update');

  // Logout admin and try to edit both nodes anonymously
  $this
    ->drupalLogout();
  $this
    ->drupalGet('node/' . $this->node1->nid . '/edit');
  $this
    ->assertText(t('Access denied'), 'node1 is not editable');
  $this
    ->drupalGet('node/' . $this->node2->nid . '/edit');
  $this
    ->assertText(t('Access denied'), 'node2 is not editable');

  // Login test user, edit node1, access must be granted
  $this
    ->drupalLogin($this->test_user);
  $this
    ->drupalGet('node/' . $this->node1->nid . '/edit');
  $this
    ->assertNoText(t('Access denied'), 'node1 is editable');

  // Edit node2, access must be denied
  $this
    ->drupalGet('node/' . $this->node2->nid . '/edit');
  $this
    ->assertText(t('Access denied'), 'node2 is not editable');

  // Login admin, swap permissions between node1 and node2
  $this
    ->drupalLogin($this->admin_user);

  // Grant edit access to node2
  $this
    ->changeAccessNodeKeyword($this->node2, 'update');

  // Restrict edit acces to node1
  $this
    ->changeAccessNodeKeyword($this->node1, 'update', FALSE);

  // Logout admin and try to edit both nodes anonymously
  $this
    ->drupalLogout();
  $this
    ->drupalGet('node/' . $this->node1->nid . '/edit');
  $this
    ->assertText(t('Access denied'), 'node1 is not editable');
  $this
    ->drupalGet('node/' . $this->node2->nid . '/edit');
  $this
    ->assertText(t('Access denied'), 'node2 is not editable');

  // Login test user, edit node1, access must be denied
  $this
    ->drupalLogin($this->test_user);
  $this
    ->drupalGet('node/' . $this->node1->nid . '/edit');
  $this
    ->assertText(t('Access denied'), 'node1 is not editable');

  // Edit node2, access must be granted
  $this
    ->drupalGet('node/' . $this->node2->nid . '/edit');
  $this
    ->assertNoText(t('Access denied'), 'node2 is editable');
}