You are here

public function AckNodeAccessTest::testStickyAccess in Access Control Kit 7

Test controlling access by stickiness.

File

ack_node/ack_node.test, line 362
Tests for the ACK node module.

Class

AckNodeAccessTest
Tests the node access functions.

Code

public function testStickyAccess() {

  // Prepare the access scheme.
  $name = $this
    ->randomName();
  $edit = array(
    'name' => $name,
    'machine_name' => 'test_sticky_access',
    'roles[' . $this->ackRoleAny->rid . ']' => TRUE,
  );
  $this
    ->drupalPost('admin/structure/access/add/boolean', $edit, 'Save access scheme and continue');
  $edit = array(
    'handlers[node][handler]' => 'ACKNodeSticky',
  );
  $this
    ->drupalPost(NULL, $edit, 'Save access scheme');
  $this
    ->assertText('Updated access scheme ' . $name, 'Access scheme configured.');

  // Test node access without any grants.
  drupal_static_reset();
  $this
    ->assertFalse(node_access('update', $this->node, $this->ackUser), 'User does not have access to edit the test node.');
  $this
    ->assertFalse(node_access('delete', $this->node, $this->ackUser), 'User does not have access to delete the test node.');

  // Grant access and retest.
  $edit = array(
    'user' => $this->ackUser->name,
    'role' => $this->ackRoleAny->rid,
    'ack_test_sticky_access[und][0]' => TRUE,
  );
  $this
    ->drupalPost('admin/access/add/test-sticky-access', $edit, 'Save');
  drupal_static_reset();
  $this
    ->assertTrue(node_access('update', $this->node, $this->ackUser), 'User has access to edit the test node.');
  $this
    ->assertTrue(node_access('delete', $this->node, $this->ackUser), 'User has access to delete the test node.');

  // Change access and retest.
  $edit = array(
    'ack_test_sticky_access[und][0]' => FALSE,
    'ack_test_sticky_access[und][1]' => TRUE,
  );
  $this
    ->drupalPost('admin/access/grant/1/edit', $edit, 'Save');
  drupal_static_reset();
  $this
    ->assertFalse(node_access('update', $this->node, $this->ackUser), 'User does not have access to edit the test node.');
  $this
    ->assertFalse(node_access('delete', $this->node, $this->ackUser), 'User does not have access to delete the test node.');

  // Change node properties and retest.
  $this->node->sticky = TRUE;
  node_save($this->node);
  drupal_static_reset();
  $this
    ->assertTrue(node_access('update', $this->node, $this->ackUser), 'User has access to edit the test node.');
  $this
    ->assertTrue(node_access('delete', $this->node, $this->ackUser), 'User has access to delete the test node.');

  // Revoke access and retest.
  $edit = array();
  $this
    ->drupalPost('admin/access/grant/1/delete', $edit, 'Delete');
  drupal_static_reset();
  $this
    ->assertFalse(node_access('update', $this->node, $this->ackUser), 'User does not have access to edit the test node.');
  $this
    ->assertFalse(node_access('delete', $this->node, $this->ackUser), 'User does not have access to delete the test node.');
}