/**
  * Includes acl_add_user, acl_remove_user, acl_has_users,
  * acl_get_id_by_name, acl_has_user, acl_get_uids
  */
 function testNodeAclSingleUserAddRemove()
 {
     // Add a node.
     $node1 = $this->drupalCreateNode(array('type' => 'page', 'promote' => 0));
     $this->assertTrue(Node::load($node1->id()), t('Page node created.'));
     acl_create_acl('test2', $node1->getTitle());
     // Check to see if grants added by node_test_node_access_records()
     // made it in.
     $acl_id = acl_get_id_by_name('test2', $node1->getTitle());
     $this->assertNotNull($acl_id, t('ACL ID was successfully 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->id());
     $records = db_query('SELECT acl_id, uid FROM {acl_user} WHERE uid = :uid', array(':uid' => $web_user_1->id()))->fetchAll();
     // Verify user is added.
     $this->assertEqual(count($records), 1, t('User was successfully added.'), $group = 'ACL');
     // Remove user.
     acl_remove_user($acl_id, $web_user_1->id());
     $records = db_query('SELECT acl_id, uid FROM {acl_user} WHERE uid = :uid', array(':uid' => $web_user_1->id()))->fetchAll();
     // Verify user is removed.
     $this->assertEqual(count($records), 0, t('User was successfully removed.'), $group = 'ACL');
 }
 function createForum($id, $tag, $description, array $accesses)
 {
     $edit = array('name' => "Forum {$id} {$tag}", 'description' => $description, 'parent[0]' => 0, 'weight' => '0');
     $forum = (object) ($edit + array('tid' => 2));
     $edit["forum_access[grants][checkboxes][view][1]"] = FALSE;
     $edit["forum_access[grants][checkboxes][view][2]"] = FALSE;
     $edit["forum_access[grants][checkboxes][create][2]"] = FALSE;
     foreach (array($this->webmaster_rid, $this->forum_admin_rid, $this->edit_any_content_rid, $this->edit_own_content_rid, $this->create_content_rid, $this->admin_rid, $this->anon_rid, $this->auth_rid) as $rid) {
         foreach ($accesses as $access) {
             $key = "{$access}-{$rid}";
             if (array_search($key, array('update-3', 'delete-3')) === FALSE) {
                 $edit["forum_access[grants][checkboxes][{$access}][{$rid}]"] = TRUE;
             }
         }
     }
     $this->drupalPost('admin/structure/forum/add/forum', $edit, t('Save'));
     $this->assertResponse(200, "'{$forum->name}' added.");
     // Set moderator.
     $acl_id = _forum_access_get_acl($forum->tid);
     $this->assertNotNull($acl_id);
     acl_add_user($acl_id, $this->moderator->uid);
     $this->assertTrue(acl_has_user($acl_id, $this->moderator->uid), t('User %moderator is moderator.', array('%user' => $this->moderator->uid)));
     // Show the result.
     $this->drupalGet("admin/structure/forum/edit/forum/{$forum->tid}");
     $this->assertResponse(200, "^^^ '{$forum->name}' exists, with these settings.");
     $this->drupalGet('forum');
     $this->assertResponse(200, 'Forum Overview');
     return $forum;
 }