You are here

function AclWebTestCase::testNodeAclSingleUserAddRemove in ACL 7

Includes acl_add_user, acl_remove_user, acl_has_users, acl_get_id_by_name, acl_has_user, acl_get_uids

File

tests/acl.test, line 59
Tests for the ACL module.

Class

AclWebTestCase
Test case for ACL module.

Code

function testNodeAclSingleUserAddRemove() {

  // Add a node.
  $node1 = $this
    ->drupalCreateNode(array(
    'type' => 'page',
    'promote' => 0,
  ));
  $this
    ->assertTrue(node_load($node1->nid), t('Page node created.'));
  acl_create_acl('test2', $node1->title);

  // Check to see if grants added by node_test_node_access_records()
  // made it in.
  $acl_id = acl_get_id_by_name('test2', $node1->title);
  $this
    ->assertNotNull($acl_id, t('ACL ID was succesfully found.'), $group = 'ACL');
  $records = db_query('SELECT acl_id, name FROM {acl} WHERE acl_id = :acl_id', array(
    ':acl_id' => $acl_id,
  ))
    ->fetchAll();
  $this
    ->assertEqual(count($records), 1, t('ACL was succesfully created.'), $group = 'ACL');

  // Add user (can't we use the user created in setup?).
  $web_user_1 = $this
    ->drupalCreateUser();

  //$this->drupalLogin($web_user);
  acl_add_user($acl_id, $web_user_1->uid);
  $records = db_query('SELECT acl_id, uid FROM {acl_user} WHERE uid = :uid', array(
    ':uid' => $web_user_1->uid,
  ))
    ->fetchAll();

  // Verify user is added.
  $this
    ->assertEqual(count($records), 1, t('User was succesfully added.'), $group = 'ACL');

  // Remove user.
  acl_remove_user($acl_id, $web_user_1->uid);
  $records = db_query('SELECT acl_id, uid FROM {acl_user} WHERE uid = :uid', array(
    ':uid' => $web_user_1->uid,
  ))
    ->fetchAll();

  // Verify user is removed.
  $this
    ->assertEqual(count($records), 0, t('User was succesfully removed.'), $group = 'ACL');
}