You are here

function ContentAccessModuleTestCase::testDeleteAccess in Content Access 6

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

Test for deleting nodes

File

tests/content_access.test, line 201

Class

ContentAccessModuleTestCase

Code

function testDeleteAccess() {

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

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

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

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

  // Login test user, delete node, access must be granted
  $this
    ->drupalLogin($this->test_user);
  $this
    ->drupalPost('node/' . $this->node1->nid . '/delete', array(), 'Delete');
  $this
    ->assertRaw(t('%node has been deleted', array(
    '%node' => $this->node1->title,
  )), 'Test node was deleted successfully by test user');

  // Login admin and recreate test node1
  $this
    ->drupalLogin($this->admin_user);
  $this->node1 = $this
    ->drupalCreateNode(array(
    'type' => $this->content_type_name,
  ));

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

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

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

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

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

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

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

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

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

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

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

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