class ForumAccessBaseTestCase in Forum Access 7
Base test class for the Forum Access module.
Hierarchy
- class \DrupalTestCase
- class \DrupalWebTestCase
- class \ForumTestCase
- class \ForumAccessBaseTestCase
- class \ForumTestCase
- class \DrupalWebTestCase
Expanded class hierarchy of ForumAccessBaseTestCase
File
- tests/
forum_access_test_base.php, line 11 - Base class with auxiliary functions for forum access module tests.
View source
class ForumAccessBaseTestCase extends ForumTestCase {
protected $admin_rid;
protected $webmaster_rid;
protected $forum_admin_rid;
protected $edndel_any_content_rid;
protected $edndel_own_content_rid;
protected $edit_any_content_rid;
protected $edit_own_content_rid;
protected $delete_any_content_rid;
protected $delete_own_content_rid;
protected $create_content_rid;
protected $anon_rid;
protected $auth_rid;
protected $user1;
protected $webmaster_user;
protected $forum_admin_user;
protected $edndel_any_content_user;
protected $edndel_own_content_user;
protected $edit_any_content_user;
protected $edit_own_content_user;
protected $delete_any_content_user;
protected $delete_own_content_user;
protected $create_content_user;
protected $auth_user;
protected $moderator;
protected $time;
protected $accounts;
protected $rids;
protected $accesses;
/**
* Implements setUp().
*/
function setUp($modules = array()) {
if (!isset($this->time)) {
$this->time = time();
}
$this->timeLimit = 2345;
$this
->pass("timeLimit set to {$this->timeLimit}.");
parent::setUp();
if (!module_exists('forum_access')) {
module_enable(array(
'acl',
'chain_menu_access',
'forum_access',
), FALSE);
}
$this
->assertTrue(module_exists('acl'), t('Module %module enabled!', array(
'%module' => 'acl',
)), 'Setup');
$this
->assertTrue(module_exists('chain_menu_access'), t('Module %module enabled!', array(
'%module' => 'chain_menu_access',
)), 'Setup');
$this
->assertTrue(module_exists('forum_access'), t('Module %module enabled!', array(
'%module' => 'forum_access',
)), 'Setup');
$modules = array(
'devel',
'devel_node_access',
) + $modules;
$files = system_rebuild_module_data();
$available_modules = array();
foreach ($modules as $module) {
if (!empty($files[$module]) && !module_exists($module)) {
$available_modules[] = $module;
}
}
if (!empty($available_modules)) {
module_enable($available_modules);
}
parent::resetAll();
$this->accesses = array(
'view',
'create',
'update',
'delete',
);
}
/*
* Implements additional set-up tasks.
*
* We cannot keep the test driver from calling setUp() for the inherited
* tests, so keep setUp() as short as possible and manually call setUp2()
* at the start of each test.
*/
function setUp2() {
$this->user1 = user_load(1);
// Update uid 1's name and password so we know it.
$password = user_password();
require_once DRUPAL_ROOT . '/' . variable_get('password_inc', 'includes/password.inc');
$account = array(
'name' => 'user1',
'pass' => user_hash_password(trim($password)),
);
// We cannot use user_save() here or the password would be hashed again.
db_update('users')
->fields($account)
->condition('uid', 1)
->execute();
// Reload and log in uid 1.
$this->user1 = user_load(1, TRUE);
$this->user1->pass_raw = $password;
// Rebuild content access permissions
$this
->drupalLogin($this->user1);
$this
->drupalPost('admin/reports/status/rebuild', array(), t('Rebuild permissions'));
if (module_exists('devel_node_access')) {
// Enable Devel Node Access.
$this
->drupalGet('admin/config/development/devel');
$this
->assertResponse(200);
$this
->drupalPost('admin/config/development/devel', array(
'devel_node_access_debug_mode' => '1',
), t('Save configuration'));
$this
->assertResponse(200, 'Devel Node Access configuration saved.');
// Enable the second DNA block, too.
$this
->drupalPost('admin/structure/block/list', array(
'blocks[devel_node_access_dna_user][region]' => 'footer',
), t('Save blocks'));
}
if (module_exists('devel')) {
$this
->drupalPost('admin/config/development/devel', array(
'devel_error_handlers[]' => array(
1,
2,
4,
),
), t('Save configuration'));
$this
->assertResponse(200, 'Devel configuration saved.');
$this
->drupalPost('admin/people/permissions/list', array(
'1[access devel information]' => 'access devel information',
'2[access devel information]' => 'access devel information',
), t('Save permissions'));
$this
->assertResponse(200, 'Devel permissions saved.');
}
/*
The base class creates the following users:
$this->user1 = user 1
$this->admin_user = array('administer blocks', 'administer forums', 'administer menu', 'administer taxonomy', 'create forum content')); // 'access administration pages')
$this->edit_any_topics_user = array('create forum content', 'edit any forum content', 'delete any forum content', 'access administration pages')
$this->edit_own_topics_user = array('create forum content', 'edit own forum content', 'delete own forum content')
$this->web_user = array()
Remove these users and roles and create the ones we need.
*/
user_role_delete((int) reset($this->admin_user->roles));
user_role_delete((int) reset($this->edit_any_topics_user->roles));
user_role_delete((int) reset($this->edit_own_topics_user->roles));
user_delete($this->admin_user->uid);
user_delete($this->edit_any_topics_user->uid);
user_delete($this->edit_own_topics_user->uid);
user_delete($this->web_user->uid);
unset($this->web_user);
// Get rids and uids up to 10/9.
for ($i = 0; $i < 3; ++$i) {
$dummy_rid = (int) $this
->drupalCreateRole(array(), 'dummy');
$dummy_user = $this
->drupalCreateNamedUser('Dummy', array(
$dummy_rid,
));
user_role_delete($dummy_rid);
user_delete($dummy_user->uid);
}
// Create our roles.
$this->admin_rid = 3;
$this->webmaster_rid = (int) $this
->drupalCreateRole(array(
'administer blocks',
'administer forums',
'administer nodes',
'administer comments',
'administer menu',
'administer taxonomy',
'create forum content',
'access content overview',
'access administration pages',
'view revisions',
'revert revisions',
'delete revisions',
), '11 webmaster');
$this->forum_admin_rid = (int) $this
->drupalCreateRole(array(
'administer forums',
'create forum content',
'edit any forum content',
'delete any forum content',
), '12 forum admin');
$this->edndel_any_content_rid = (int) $this
->drupalCreateRole(array(
'create forum content',
'edit any forum content',
'delete any forum content',
'view own unpublished content',
), '13 edndel any content');
$this->edndel_own_content_rid = (int) $this
->drupalCreateRole(array(
'create forum content',
'edit own forum content',
'delete own forum content',
), '14 edndel own content');
$this->edit_any_content_rid = (int) $this
->drupalCreateRole(array(
'create forum content',
'edit any forum content',
'view own unpublished content',
), '15 edit any content');
$this->edit_own_content_rid = (int) $this
->drupalCreateRole(array(
'create forum content',
'edit own forum content',
'edit own comments',
), '16 edit own content');
$this->delete_any_content_rid = (int) $this
->drupalCreateRole(array(
'create forum content',
'delete any forum content',
'view own unpublished content',
), '17 delete any content');
$this->delete_own_content_rid = (int) $this
->drupalCreateRole(array(
'create forum content',
'delete own forum content',
'edit own comments',
), '18 delete own content');
// EOC should not make any difference!
$this->create_content_rid = (int) $this
->drupalCreateRole(array(
'create forum content',
), '19 create content');
$this->anon_rid = DRUPAL_ANONYMOUS_RID;
$this->auth_rid = DRUPAL_AUTHENTICATED_RID;
// Create our users.
$this->admin_user = $this
->drupalCreateNamedUser('10_Administrator', array(
$this->admin_rid,
));
$this->webmaster_user = $this
->drupalCreateNamedUser('11_Webmaster', array(
$this->webmaster_rid,
));
$this->forum_admin_user = $this
->drupalCreateNamedUser('12_Forum_admin', array(
$this->forum_admin_rid,
));
$this->edndel_any_content_user = $this
->drupalCreateNamedUser('13_EdNDel_any_content', array(
$this->edndel_any_content_rid,
));
$this->edndel_own_content_user = $this
->drupalCreateNamedUser('14_EdNDel_own_content', array(
$this->edndel_own_content_rid,
));
$this->edit_any_content_user = $this
->drupalCreateNamedUser('15_Edit_any_content', array(
$this->edit_any_content_rid,
));
$this->edit_own_content_user = $this
->drupalCreateNamedUser('16_Edit_own_content', array(
$this->edit_own_content_rid,
));
$this->delete_any_content_user = $this
->drupalCreateNamedUser('17_Delete_any_content', array(
$this->delete_any_content_rid,
));
$this->delete_own_content_user = $this
->drupalCreateNamedUser('18_Delete_own_content', array(
$this->delete_own_content_rid,
));
$this->create_content_user = $this
->drupalCreateNamedUser('19_Create_content', array(
$this->create_content_rid,
));
$this->auth_user = $this
->drupalCreateNamedUser('20_Auth_only', array());
$this->moderator = $this
->drupalCreateNamedUser('21_Moderator', array(
$this->create_content_rid,
));
$anon = drupal_anonymous_user();
$anon->name = check_plain(format_username($anon));
$this->accounts = array(
$this->user1,
$this->admin_user,
$this->webmaster_user,
$this->forum_admin_user,
$this->edndel_any_content_user,
$this->edndel_own_content_user,
$this->edit_any_content_user,
$this->edit_own_content_user,
$this->delete_any_content_user,
$this->delete_own_content_user,
$this->create_content_user,
$this->auth_user,
$this->moderator,
);
$this->rids = array(
$this->anon_rid,
$this->auth_rid,
$this->admin_rid,
$this->webmaster_rid,
$this->forum_admin_rid,
$this->edndel_any_content_rid,
$this->edndel_own_content_rid,
$this->edit_any_content_rid,
$this->edit_own_content_rid,
$this->delete_any_content_rid,
$this->delete_own_content_rid,
$this->create_content_rid,
);
// Show settings for reference.
$this
->drupalGet('admin/people/permissions/list');
$this
->assertResponse(200, '^^^ Permissions');
$this
->drupalGet('admin/people', array(
'query' => array(
'sort' => 'asc',
'order' => drupal_encode_path(t('Username')),
),
));
$this
->assertResponse(200, '^^^ Users');
}
function testForum() {
// Skip test in the base class; too bad we can't skip the unnecessary setUp() call...
$this
->pass('==========================<br />Empty testForum() @' . (time() - $this->time));
}
function testAddOrphanTopic() {
// Skip test in the base class; too bad we can't skip the unnecessary setUp() call...
$this
->pass('==========================<br />Empty testAddOrphanTopic() @' . (time() - $this->time));
}
function testEnableForumField() {
// Skip test in the base class; too bad we can't skip the unnecessary setUp() call...
$this
->pass('==========================<br />Empty testEnableForumField() @' . (time() - $this->time));
}
/**
* Asserts that a field in the current page is enabled.
*
* @param $id
* Id of field to assert.
* @param $message
* Message to display.
* @return
* TRUE on pass, FALSE on fail.
*/
protected function assertFieldEnabled($id, $message = '') {
$elements = $this
->xpath('//input[@id=:id]', array(
':id' => $id,
));
return $this
->assertTrue(isset($elements[0]) && empty($elements[0]['disabled']), $message ? $message : t('Field @id is enabled.', array(
'@id' => $id,
)), t('Browser'));
}
/**
* Asserts that a field in the current page is disabled.
*
* @param $id
* Id of field to assert.
* @param $message
* Message to display.
* @return
* TRUE on pass, FALSE on fail.
*/
protected function assertFieldDisabled($id, $message = '') {
$elements = $this
->xpath('//input[@id=:id]', array(
':id' => $id,
));
return $this
->assertTrue(isset($elements[0]) && !empty($elements[0]['disabled']), $message ? $message : t('Field @id is disabled.', array(
'@id' => $id,
)), t('Browser'));
}
/**
* Pass if a button with the specified label is found, and optional with the
* specified index.
*
* @param $label
* Text in the value attribute.
* @param $index
* Link position counting from zero.
* @param $message
* Message to display.
* @param $group
* The group this message belongs to, defaults to 'Other'.
* @return
* TRUE if the assertion succeeded, FALSE otherwise.
*/
protected function assertButton($label, $index = 0, $message = '', $group = 'Other') {
$links = $this
->xpath('//input[contains(@type, submit)][contains(@value, :label)]', array(
':label' => $label,
));
$message = $message ? $message : t('Button with label %label found.', array(
'%label' => $label,
));
return $this
->assert(isset($links[$index]), $message, $group);
}
/**
* Pass if a button with the specified label is not found.
*
* @param $label
* Text in the value attribute.
* @param $message
* Message to display.
* @param $group
* The group this message belongs to, defaults to 'Other'.
* @return
* TRUE if the assertion succeeded, FALSE otherwise.
*/
protected function assertNoButton($label, $message = '', $group = 'Other') {
$links = $this
->xpath('//input[contains(@type, submit)][contains(@value, :label)]', array(
':label' => $label,
));
$message = $message ? $message : t('Button with label %label found.', array(
'%label' => $label,
));
return $this
->assert(empty($links), $message, $group);
}
/**
* Extend drupalCreateUser() base method to accept a name as well as
* multiple roles (rather than permissions).
*
* @param $name
* Name to assign to the user
* @param $rids
* Array of Role IDs to assign to user.
* @return
* A fully loaded user object with pass_raw property, or FALSE if account
* creation fails.
*/
protected function drupalCreateNamedUser($name, $rids = array()) {
// Create a user.
$rids2 = array();
foreach ($rids as $rid) {
$rids2[$rid] = $rid;
}
$edit = array();
$edit['name'] = $name;
$edit['mail'] = $edit['name'] . '@example.com';
$edit['roles'] = $rids2;
$edit['pass'] = user_password();
$edit['status'] = 1;
$account = user_save(drupal_anonymous_user(), $edit);
$this
->assertTrue(!empty($account->uid), t('User %name created, uid=%uid.', array(
'%name' => $edit['name'],
'%uid' => $account->uid,
)), t('User login'));
if (empty($account->uid)) {
return FALSE;
}
// Add the raw password so that we can log in as this user.
$account->pass_raw = $edit['pass'];
return $account;
}
protected function createForumTopicWithTitle($forum, $title) {
$node = $this
->createForumTopic((array) $forum);
$node = node_load($node->nid);
$node->title = $title;
$node->shadow = FALSE;
node_save($node);
return $node;
}
protected function createForumCommentWithText($node, $text) {
static $cid = 0;
$this
->drupalPost("node/{$node->nid}", array(
'comment_body[' . LANGUAGE_NONE . '][0][value]' => $text,
), t('Save'));
$this
->assertResponse(200);
$this
->assertText($text, "Comment '{$text}' found, too.");
return comment_load(++$cid);
}
protected function isFieldChecked($id) {
$elements = $this
->xpath('//input[@id=:id]', array(
':id' => $id,
));
return isset($elements[0]) && !empty($elements[0]['checked']);
}
/**
* Check the set of permissions in one forum.
*
* @param $forum
* An associative array describing the forum.
* @param $is_default
* Set to TRUE if this is the default forum (without any moderator).
*/
function checkForum($forum, $is_default = FALSE) {
$this
->drupalLogin($this->user1);
$this
->drupalGet("admin/structure/forum/edit/forum/{$forum->tid}");
$this
->assertResponse(200, "^^^ '{$forum->name}' exists.");
foreach ($this->accounts as $key => $account) {
// Retrieve the access settings for this account.
$account->access = array();
foreach ($account->roles as $rid => $role_name) {
foreach ($this->accesses as $access) {
if ($this
->isFieldChecked("edit-forum-access-grants-checkboxes-{$access}-{$rid}")) {
$account->access[$access] = $access;
}
}
}
}
foreach ($this->accounts as $key => $account) {
// Create a topic and a comment for this account to experiment with.
$account->node = $this
->createForumTopicWithTitle($forum, "Topic for {$account->name}");
$account->comment = $this
->createForumCommentWithText($account->node, "Comment for {$account->name}");
}
// Show the topic list.
$this
->drupalGet("forum/{$forum->tid}");
$this
->assertResponse(200, "^^^ '{$forum->name}' initial topics.");
foreach ($this->accounts as $key => $account) {
$is_super_user = user_access('bypass node access', $account) || $account->uid == $this->moderator->uid && !$is_default;
if (!empty($account->uid)) {
$this
->drupalLogin($account);
}
else {
$this
->drupalLogout();
}
// Check whether we have an 'Add new Forum topic' link.
$this
->drupalGet('forum');
if (empty($account->access['view']) && !$is_super_user) {
$this
->assertResponse(403, "^^^ {$account->name} cannot see the Forum Overview");
}
elseif ((empty($account->access['create']) || !user_access('create forum content', $account)) && !$is_super_user) {
$this
->assertResponse(200, 'Forum Overview');
$this
->assertNoLink(t('Add new Forum topic'), "^^^ {$account->name} cannot post in the '{$forum->name}'.");
}
else {
$this
->assertResponse(200, 'Forum Overview');
$this
->assertLink($forum->name, 0, "^^^ {$account->name} can see the '{$forum->name}'.");
$this
->assertLink(t('Add new Forum topic'), 0, "^^^ {$account->name} can post in the '{$forum->name}'.");
}
foreach (array(
'any',
'own',
) as $test_type) {
// Check whether we can View our topic.
$comment =& $account->comment;
$node =& $account->node;
if ((empty($account->access['view']) || !user_access('access content', $account)) && !$is_super_user) {
$this
->drupalGet("forum/{$forum->tid}");
$this
->assertResponse(404, "^^^ {$account->name} cannot access '{$forum->name}'.");
$this
->drupalGet("node/{$node->nid}");
$this
->assertResponse(403, "^^^ {$account->name} cannot access {$test_type} topic.");
$this
->drupalGet("node/{$node->nid}/edit");
$this
->assertResponse(403, "{$account->name} cannot edit {$test_type} topic (not accessible).");
$this
->drupalGet("comment/{$comment->cid}");
$this
->assertResponse(403, "^^^ {$account->name} cannot access comment '{$comment->subject}'.");
}
else {
$this
->drupalGet("forum/{$forum->tid}");
$this
->assertResponse(200, "^^^ '{$forum->name}' as {$account->name}.");
$this
->assertLink($node->title);
$this
->clickLink($node->title);
$this
->assertResponse(200, "^^^ {$account->name} can access {$test_type} topic.");
$this
->assertText($comment->subject, "Comment '{$comment->subject}' found, too.");
// Check comment visibility.
if (!$is_super_user && (!user_access('access comments', $account) || empty($account->access['view'])) && !user_access('administer comments', $account)) {
$this
->assertNoLinkByHref("/comment/{$comment->cid}#comment-{$comment->cid}");
$this
->drupalGet("comment/{$comment->cid}");
$this
->assertResponse(403, "^^^ {$account->name} cannot see comment '{$comment->subject}'.");
}
else {
$this
->assertLinkByHref(url("comment/{$comment->cid}", array(
'fragment' => "comment-{$comment->cid}",
)));
// Check post comment / reply link.
if ((!user_access('post comments', $account) && !user_access('post comments without approval', $account) || empty($account->access['create'])) && !$is_super_user) {
if (!$account->uid) {
$this
->assertLinkByHref("/user/login?destination=node/{$node->nid}#comment-form");
}
$this
->assertNoLink(t('Add new comment'));
$this
->assertNoText(t('Add new comment'));
$this
->assertNoLink(t('reply'));
$this
->drupalGet("comment/{$comment->cid}");
$this
->assertResponse(200, '^^^ ' . "Comment '{$comment->subject}' is visible to {$account->name}'.");
$this
->drupalGet("comment/reply/{$node->nid}");
$this
->assertResponse(403);
$this
->drupalGet("comment/reply/{$node->nid}/{$comment->cid}");
$this
->assertResponse(403);
}
else {
$this
->assertText(t('Add new comment'));
$this
->assertLink(t('reply'));
$this
->assertLinkByHref("comment/reply/{$node->nid}/{$comment->cid}");
$this
->drupalGet("comment/reply/{$node->nid}/{$comment->cid}");
$this
->assertResponse(200);
}
// Check comment edit links.
global $user;
drupal_save_session(FALSE);
$user_save = $user;
$user = $account;
// We ignore the 'edit own comments' permission!
$comment_access_edit = FALSE;
// comment_access('edit', $comment);
$user = $user_save;
drupal_save_session(TRUE);
$this
->drupalGet("comment/{$comment->cid}");
$this
->assertResponse(200);
if (empty($account->access['update']) && !$is_super_user && !$comment_access_edit && !user_access('administer comments', $account) && !user_access('edit any forum content', $account) && !($account->uid == $comment->uid && user_access('edit own forum content', $account))) {
$this
->assertNoLink(t('edit'));
$this
->drupalGet("comment/{$comment->cid}/edit");
$this
->assertResponse(403);
}
else {
$this
->assertLink(t('edit'));
$this
->clickLink(t('edit'));
$this
->assertResponse(200);
$this
->drupalGet("comment/{$comment->cid}/edit");
$this
->assertResponse(200);
$this
->assertText($comment->subject);
$comment->subject .= ' (updated)';
$this
->drupalPost("comment/{$comment->cid}/edit", array(
'subject' => $comment->subject,
), t('Save'));
$this
->assertText(t("Your comment has been posted."));
// It ought to say 'updated'!
}
// Check comment delete links.
$this
->drupalGet("comment/{$comment->cid}");
if (empty($account->access['delete']) && !$is_super_user && !user_access('administer comments', $account) && !user_access('delete any forum content', $account) && !($account->uid == $comment->uid && user_access('delete own forum content', $account))) {
$this
->assertNoLink(t('delete'));
$this
->drupalGet("comment/{$comment->cid}/delete");
$this
->assertResponse(403);
}
else {
$this
->assertText($comment->subject);
$this
->assertLink(t('delete'));
$this
->clickLink(t('delete'));
$this
->assertResponse(200);
$this
->drupalGet("comment/{$comment->cid}/delete");
$this
->assertResponse(200);
$this
->drupalPost("comment/{$comment->cid}/delete", array(), t('Delete'));
$this
->assertText(t('The comment and all its replies have been deleted.'));
$this
->assertNoText($comment->subject);
unset($account->comment);
}
}
// Check whether we can Edit our topic.
$this
->drupalGet("node/{$node->nid}");
$this
->assertResponse(200);
if (empty($account->access['update']) && !user_access('edit any forum content', $account) && !(user_access('edit own forum content', $account) && $node->uid == $account->uid) && !$is_super_user) {
$this
->assertNoLink(t('Edit'));
$this
->drupalGet("node/{$node->nid}/edit");
$this
->assertResponse(403, "{$account->name} cannot edit {$test_type} topic.");
}
else {
$this
->assertLink(t('Edit'));
$this
->clickLink(t('Edit'));
$this
->assertResponse(200, "^^^ {$account->name} can edit {$test_type} topic.");
// Check that moderator gets administrator properties.
if ($is_super_user || user_access('administer nodes', $account)) {
$this
->assertText(t('Revision information'), "{$account->name} sees Revision information.");
$this
->assertText(t('Comment settings'), "{$account->name} sees Comment settings.");
$this
->assertText(t('Publishing options'), "{$account->name} sees Publishing options.");
if (user_access('administer nodes', $account)) {
$this
->assertText(t('Menu settings'), "{$account->name} sees Menu settings.");
$this
->assertText(t('Authoring information'), "{$account->name} sees Authoring information.");
}
else {
$this
->assertNoText(t('Menu settings'), "{$account->name} does not see Menu settings.");
$this
->assertNoText(t('Authoring information'), "{$account->name} does not see Authoring information.");
}
}
else {
$this
->assertNoText(t('Revision information'), "{$account->name} does not see Revision information.");
$this
->assertNoText(t('Comment settings'), "{$account->name} does not see Comment settings.");
$this
->assertNoText(t('Publishing options'), "{$account->name} does not see Publishing options.");
$this
->assertNoText(t('Menu settings'), "{$account->name} does not see Menu settings.");
$this
->assertNoText(t('Authoring information'), "{$account->name} does not see Authoring information.");
}
// Check whether we can Delete our topic.
if (empty($account->access['delete']) && !user_access('delete any forum content', $account) && !(user_access('delete own forum content', $account) && $node->uid == $account->uid) && !$is_super_user) {
$this
->assertNoButton(t('Delete'), 0, $account->name . ' has no Delete button.');
}
else {
$this
->assertButton(t('Delete'), 0, $account->name . ' has a Delete button.');
}
// Change the title.
$node->title = $node->title . ' (changed)';
$this
->drupalPost("node/{$node->nid}/edit", array(
'title' => $node->title,
), t('Save'));
$this
->assertText(t('Forum topic !title has been updated.', array(
'!title' => $node->title,
)));
}
// Check whether we can delete the topic.
if (empty($account->access['delete']) && !user_access('delete any forum content', $account) && !(user_access('delete own forum content', $account) && $node->uid == $account->uid) && !$is_super_user) {
$this
->drupalGet("node/{$node->nid}/delete");
$this
->assertResponse(403, "{$account->name} cannot delete {$test_type} topic.");
}
else {
$this
->drupalPost("node/{$node->nid}/delete", array(), t('Delete'));
$this
->assertText(t('Forum topic !title has been deleted.', array(
'!title' => $node->title,
)));
}
}
if ($test_type == 'any' && (!empty($account->access['view']) || $is_super_user)) {
// Check whether we can create a topic.
if ((empty($account->access['create']) || !user_access('create forum content', $account)) && !$is_super_user) {
$this
->drupalGet('forum');
if (empty($account->uid)) {
$this
->assertLinkByHref('/user/login?destination=forum');
}
else {
$this
->assertResponse(200, "^^^ {$account->name} can see the Forum Overview, but...");
$this
->assertText(t('You are not allowed to post new content in the forum.'));
}
$this
->drupalGet("node/add/forum/{$forum->tid}");
$this
->assertResponse(403, "^^^ {$account->name} cannot create a forum topic in '{$forum->name}'.");
break;
}
else {
$this
->drupalGet('forum');
$this
->assertNoText(t('You are not allowed to post new content in the forum.'));
$this
->assertLink(t('Add new Forum topic'));
$this
->clickLink(t('Add new Forum topic'));
$this
->assertResponse(200, "^^^ {$account->name} can create a forum topic.");
$this
->drupalGet("node/add/forum/{$forum->tid}");
$this
->assertResponse(200, "^^^ {$account->name} can create a forum topic in '{$forum->name}'.");
$this
->drupalGet('forum');
$this
->assertLink(t('Add new Forum topic'));
$this
->drupalPost("node/add/forum/{$forum->tid}", array(
'title' => "Topic 1 by {$account->name}",
), t('Save'));
$node = $account->node = $this
->createForumTopicWithTitle($forum, "Topic 2 by {$account->name}");
$this
->drupalGet('node/' . $node->nid);
$account->comment = $this
->createForumCommentWithText($node, "Comment by {$account->name}");
$this
->drupalGet("forum/{$forum->tid}");
$this
->assertResponse(200, "^^^ '{$forum->name}' as {$account->name} (own topic).");
}
}
}
}
$this
->drupalLogin($this->user1);
$this
->drupalGet("forum/{$forum->tid}");
$this
->assertResponse(200, "^^^ '{$forum->name}' remaining topics.");
}
function createFAForum($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;
}
function createAndCheckForum($id, $tag, $description, array $accesses) {
$this
->setUp2();
taxonomy_term_delete(1);
$this
->pass("#########################<br />#{$id} - {$tag} Configuration test @" . (time() - $this->time), '<a id="jump1" href="#jump2">/\\<br />######<br />\\/</a>');
$forum = $this
->createFAForum($id, $tag, $description, $accesses);
$this
->checkForum($forum);
$this
->pass("#########################<br />#{$id} - END {$tag} Configuration test @" . (time() - $this->time), '<a id="jump2" href="#jump3">/\\<br />######<br />\\/</a>');
}
/**
* Makes Devel's dpm() work inside this test, if Devel is installed.
*/
function dpm($input, $name = NULL) {
if (module_exists('devel') && user_access('access devel information')) {
$export = kprint_r($input, TRUE, $name);
$trigger_error = 'trigger_error';
$trigger_error($export);
}
}
/**
* Writes a krumo entry into the watchdog log, if Devel is installed.
*/
function wpm($input, $name = NULL) {
if (module_exists('devel') && user_access('access devel information')) {
$export = kprint_r($input, TRUE, $name);
watchdog('debug', $export);
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DrupalTestCase:: |
protected | property | Assertions thrown in that test case. | |
DrupalTestCase:: |
protected | property | The database prefix of this test run. | |
DrupalTestCase:: |
protected | property | The original file directory, before it was changed for testing purposes. | |
DrupalTestCase:: |
public | property | Current results of this test case. | |
DrupalTestCase:: |
protected | property | Flag to indicate whether the test has been set up. | |
DrupalTestCase:: |
protected | property | ||
DrupalTestCase:: |
protected | property | ||
DrupalTestCase:: |
protected | property | This class is skipped when looking for the source of an assertion. | |
DrupalTestCase:: |
protected | property | The test run ID. | |
DrupalTestCase:: |
protected | property | Time limit for the test. | |
DrupalTestCase:: |
public | property | Whether to cache the installation part of the setUp() method. | |
DrupalTestCase:: |
public | property | Whether to cache the modules installation part of the setUp() method. | |
DrupalTestCase:: |
protected | property | URL to the verbose output file directory. | |
DrupalTestCase:: |
protected | function | Internal helper: stores the assert. | |
DrupalTestCase:: |
protected | function | Check to see if two values are equal. | |
DrupalTestCase:: |
protected | function | Check to see if a value is false (an empty string, 0, NULL, or FALSE). | |
DrupalTestCase:: |
protected | function | Check to see if two values are identical. | |
DrupalTestCase:: |
protected | function | Check to see if two values are not equal. | |
DrupalTestCase:: |
protected | function | Check to see if two values are not identical. | |
DrupalTestCase:: |
protected | function | Check to see if a value is not NULL. | |
DrupalTestCase:: |
protected | function | Check to see if a value is NULL. | |
DrupalTestCase:: |
protected | function | Check to see if a value is not false (not an empty string, 0, NULL, or FALSE). | |
DrupalTestCase:: |
public static | function | Delete an assertion record by message ID. | |
DrupalTestCase:: |
protected | function | Fire an error assertion. | 1 |
DrupalTestCase:: |
public | function | Handle errors during test runs. | 1 |
DrupalTestCase:: |
protected | function | Handle exceptions. | |
DrupalTestCase:: |
protected | function | Fire an assertion that is always negative. | |
DrupalTestCase:: |
public static | function | Converts a list of possible parameters into a stack of permutations. | |
DrupalTestCase:: |
protected | function | Cycles through backtrace until the first non-assertion method is found. | |
DrupalTestCase:: |
public static | function | Returns the database connection to the site running Simpletest. | |
DrupalTestCase:: |
public static | function | Store an assertion from outside the testing context. | |
DrupalTestCase:: |
protected | function | Fire an assertion that is always positive. | |
DrupalTestCase:: |
public static | function | Generates a random string containing letters and numbers. | |
DrupalTestCase:: |
public static | function | Generates a random string of ASCII characters of codes 32 to 126. | |
DrupalTestCase:: |
public | function | Run all tests in this class. | |
DrupalTestCase:: |
protected | function | Logs a verbose message in a text file. | |
DrupalWebTestCase:: |
protected | property | Additional cURL options. | |
DrupalWebTestCase:: |
protected | property | The content of the page currently loaded in the internal browser. | |
DrupalWebTestCase:: |
protected | property | The current cookie file used by cURL. | |
DrupalWebTestCase:: |
protected | property | The cookies of the page currently loaded in the internal browser. | |
DrupalWebTestCase:: |
protected | property | The handle of the current cURL connection. | |
DrupalWebTestCase:: |
protected | property | The value of the Drupal.settings JavaScript variable for the page currently loaded in the internal browser. | |
DrupalWebTestCase:: |
protected | property | The parsed version of the page. | |
DrupalWebTestCase:: |
protected | property | Whether the files were copied to the test files directory. | |
DrupalWebTestCase:: |
protected | property | The headers of the page currently loaded in the internal browser. | |
DrupalWebTestCase:: |
protected | property | HTTP authentication credentials (<username>:<password>). | |
DrupalWebTestCase:: |
protected | property | HTTP authentication method | |
DrupalWebTestCase:: |
protected | property | The current user logged in using the internal browser. | |
DrupalWebTestCase:: |
protected | property | The original shutdown handlers array, before it was cleaned for testing purposes. | |
DrupalWebTestCase:: |
protected | property | The original user, before it was changed to a clean uid = 1 for testing purposes. | |
DrupalWebTestCase:: |
protected | property | The content of the page currently loaded in the internal browser (plain text version). | |
DrupalWebTestCase:: |
protected | property | The profile to install as a basis for testing. | 20 |
DrupalWebTestCase:: |
protected | property | The number of redirects followed during the handling of a request. | |
DrupalWebTestCase:: |
protected | property | The current session ID, if available. | |
DrupalWebTestCase:: |
protected | property | The current session name, if available. | |
DrupalWebTestCase:: |
protected | property | The URL currently loaded in the internal browser. | |
DrupalWebTestCase:: |
protected | function | Asserts that a field exists with the given name or ID. | |
DrupalWebTestCase:: |
protected | function | Asserts that a field exists in the current page with the given ID and value. | |
DrupalWebTestCase:: |
protected | function | Asserts that a field exists in the current page with the given name and value. | |
DrupalWebTestCase:: |
protected | function | Asserts that a field exists in the current page by the given XPath. | |
DrupalWebTestCase:: |
protected | function | Asserts that a checkbox field in the current page is checked. | |
DrupalWebTestCase:: |
protected | function | Pass if a link with the specified label is found, and optional with the specified index. | |
DrupalWebTestCase:: |
protected | function | Pass if a link containing a given href (part) is found. | |
DrupalWebTestCase:: |
protected | function | Asserts that the most recently sent e-mail message has the given value. | |
DrupalWebTestCase:: |
protected | function | Asserts that the most recently sent e-mail message has the pattern in it. | |
DrupalWebTestCase:: |
protected | function | Asserts that the most recently sent e-mail message has the string in it. | |
DrupalWebTestCase:: |
protected | function | Asserts that each HTML ID is used for just a single element. | |
DrupalWebTestCase:: |
protected | function | Asserts that a field does not exist with the given name or ID. | |
DrupalWebTestCase:: |
protected | function | Asserts that a field does not exist with the given ID and value. | |
DrupalWebTestCase:: |
protected | function | Asserts that a field does not exist with the given name and value. | |
DrupalWebTestCase:: |
protected | function | Asserts that a field doesn't exist or its value doesn't match, by XPath. | |
DrupalWebTestCase:: |
protected | function | Asserts that a checkbox field in the current page is not checked. | |
DrupalWebTestCase:: |
protected | function | Pass if a link with the specified label is not found. | |
DrupalWebTestCase:: |
protected | function | Pass if a link containing a given href (part) is not found. | |
DrupalWebTestCase:: |
protected | function | Asserts that a select option in the current page is not checked. | |
DrupalWebTestCase:: |
protected | function | Will trigger a pass if the perl regex pattern is not present in raw content. | |
DrupalWebTestCase:: |
protected | function | Pass if the raw text is NOT found on the loaded page, fail otherwise. Raw text refers to the raw HTML that the page generated. | |
DrupalWebTestCase:: |
protected | function | Asserts the page did not return the specified response code. | |
DrupalWebTestCase:: |
protected | function | Pass if the text is NOT found on the text version of the page. The text version is the equivalent of what a user would see when viewing through a web browser. In other words the HTML has been filtered out of the contents. | |
DrupalWebTestCase:: |
protected | function | Pass if the page title is not the given string. | |
DrupalWebTestCase:: |
protected | function | Pass if the text is found MORE THAN ONCE on the text version of the page. | |
DrupalWebTestCase:: |
protected | function | Asserts that a select option in the current page is checked. | |
DrupalWebTestCase:: |
protected | function | Will trigger a pass if the Perl regex pattern is found in the raw content. | |
DrupalWebTestCase:: |
protected | function | Pass if the raw text IS found on the loaded page, fail otherwise. Raw text refers to the raw HTML that the page generated. | |
DrupalWebTestCase:: |
protected | function | Asserts the page responds with the specified response code. | |
DrupalWebTestCase:: |
protected | function | Pass if the text IS found on the text version of the page. The text version is the equivalent of what a user would see when viewing through a web browser. In other words the HTML has been filtered out of the contents. | |
DrupalWebTestCase:: |
protected | function | Helper for assertText and assertNoText. | |
DrupalWebTestCase:: |
protected | function | Asserts themed output. | |
DrupalWebTestCase:: |
protected | function | Pass if the page title is the given string. | |
DrupalWebTestCase:: |
protected | function | Pass if the text is found ONLY ONCE on the text version of the page. | |
DrupalWebTestCase:: |
protected | function | Helper for assertUniqueText and assertNoUniqueText. | |
DrupalWebTestCase:: |
protected | function | Pass if the internal browser's URL matches the given path. | |
DrupalWebTestCase:: |
protected | function | Builds an XPath query. | |
DrupalWebTestCase:: |
protected | function | Changes the database connection to the prefixed one. | |
DrupalWebTestCase:: |
protected | function | Check for meta refresh tag and if found call drupalGet() recursively. This function looks for the http-equiv attribute to be set to "Refresh" and is case-sensitive. | |
DrupalWebTestCase:: |
protected | function | Check to make sure that the array of permissions are valid. | |
DrupalWebTestCase:: |
protected | function | Follows a link by name. | |
DrupalWebTestCase:: |
protected | function | Helper function: construct an XPath for the given set of attributes and value. | |
DrupalWebTestCase:: |
protected | function | Copy the setup cache from/to another table and files directory. | |
DrupalWebTestCase:: |
protected | function | Runs cron in the Drupal installed by Simpletest. | |
DrupalWebTestCase:: |
protected | function | Close the cURL handler and unset the handler. | |
DrupalWebTestCase:: |
protected | function | Initializes and executes a cURL request. | |
DrupalWebTestCase:: |
protected | function | Reads headers and registers errors received from the tested site. | |
DrupalWebTestCase:: |
protected | function | Initializes the cURL connection. | |
DrupalWebTestCase:: |
protected | function | Compare two files based on size and file name. | |
DrupalWebTestCase:: |
protected | function | Creates a custom content type based on default settings. | |
DrupalWebTestCase:: |
protected | function | Creates a node based on default settings. | |
DrupalWebTestCase:: |
protected | function | Creates a role with specified permissions. | |
DrupalWebTestCase:: |
protected | function | Create a user with a given set of permissions. | |
DrupalWebTestCase:: |
protected | function | Retrieves a Drupal path or an absolute path. | |
DrupalWebTestCase:: |
protected | function | Retrieve a Drupal path or an absolute path and JSON decode the result. | |
DrupalWebTestCase:: |
protected | function | Gets the current raw HTML of requested page. | |
DrupalWebTestCase:: |
protected | function | Gets the value of an HTTP response header. If multiple requests were required to retrieve the page, only the headers from the last request will be checked by default. However, if TRUE is passed as the second argument, all requests will be processed… | |
DrupalWebTestCase:: |
protected | function | Gets the HTTP response headers of the requested page. Normally we are only interested in the headers returned by the last request. However, if a page is redirected or HTTP authentication is in use, multiple requests will be required to retrieve the… | |
DrupalWebTestCase:: |
protected | function | Gets an array containing all e-mails sent during this test case. | |
DrupalWebTestCase:: |
function | Get a node from the database based on its title. | ||
DrupalWebTestCase:: |
protected | function | Gets the value of the Drupal.settings JavaScript variable for the currently loaded page. | |
DrupalWebTestCase:: |
protected | function | Get a list files that can be used in tests. | |
DrupalWebTestCase:: |
protected | function | Generate a token for the currently logged in user. | |
DrupalWebTestCase:: |
protected | function | Retrieves only the headers for a Drupal path or an absolute path. | |
DrupalWebTestCase:: |
protected | function | Log in a user with the internal browser. | |
DrupalWebTestCase:: |
protected | function | ||
DrupalWebTestCase:: |
protected | function | Execute a POST request on a Drupal page. It will be done as usual POST request with SimpleBrowser. | |
DrupalWebTestCase:: |
protected | function | Execute an Ajax submission. | |
DrupalWebTestCase:: |
protected | function | Sets the raw HTML content. This can be useful when a page has been fetched outside of the internal browser and assertions need to be made on the returned page. | |
DrupalWebTestCase:: |
protected | function | Sets the value of the Drupal.settings JavaScript variable for the currently loaded page. | |
DrupalWebTestCase:: |
protected | function | Takes a path and returns an absolute path. | |
DrupalWebTestCase:: |
protected | function | Get all option elements, including nested options, in a select. | |
DrupalWebTestCase:: |
protected | function | Get the selected value from a select field. | |
DrupalWebTestCase:: |
protected | function | Returns the cache key used for the setup caching. | |
DrupalWebTestCase:: |
protected | function | Get the current URL from the cURL handler. | |
DrupalWebTestCase:: |
protected | function | Handle form input related to drupalPost(). Ensure that the specified fields exist and attempt to create POST data in the correct manner for the particular field type. | |
DrupalWebTestCase:: |
protected | function | Copies the cached tables and files for a cached installation setup. | |
DrupalWebTestCase:: |
protected | function | Parse content returned from curlExec using DOM and SimpleXML. | |
DrupalWebTestCase:: |
protected | function | Preload the registry from the testing site. | |
DrupalWebTestCase:: |
protected | function | Generates a database prefix for running tests. | |
DrupalWebTestCase:: |
protected | function | Prepares the current environment for running the test. | |
DrupalWebTestCase:: |
protected | function | Recursively copy one directory to another. | |
DrupalWebTestCase:: |
protected | function | Refresh the in-memory set of variables. Useful after a page request is made that changes a variable in a different thread. | 1 |
DrupalWebTestCase:: |
protected | function | Reset all data structures after having enabled new modules. | |
DrupalWebTestCase:: |
protected | function | Store the installation setup to a cache. | |
DrupalWebTestCase:: |
protected | function | Delete created files and temporary files directory, delete the tables created by setUp(), and reset the database prefix. | 6 |
DrupalWebTestCase:: |
protected | function | Outputs to verbose the most recent $count emails sent. | |
DrupalWebTestCase:: |
protected | function | Perform an xpath search on the contents of the internal browser. The search is relative to the root element (HTML tag normally) of the page. | |
DrupalWebTestCase:: |
function |
Constructor for DrupalWebTestCase. Overrides DrupalTestCase:: |
1 | |
ForumAccessBaseTestCase:: |
protected | property | ||
ForumAccessBaseTestCase:: |
protected | property | ||
ForumAccessBaseTestCase:: |
protected | property | ||
ForumAccessBaseTestCase:: |
protected | property | ||
ForumAccessBaseTestCase:: |
protected | property | ||
ForumAccessBaseTestCase:: |
protected | property | ||
ForumAccessBaseTestCase:: |
protected | property | ||
ForumAccessBaseTestCase:: |
protected | property | ||
ForumAccessBaseTestCase:: |
protected | property | ||
ForumAccessBaseTestCase:: |
protected | property | ||
ForumAccessBaseTestCase:: |
protected | property | ||
ForumAccessBaseTestCase:: |
protected | property | ||
ForumAccessBaseTestCase:: |
protected | property | ||
ForumAccessBaseTestCase:: |
protected | property | ||
ForumAccessBaseTestCase:: |
protected | property | ||
ForumAccessBaseTestCase:: |
protected | property | ||
ForumAccessBaseTestCase:: |
protected | property | ||
ForumAccessBaseTestCase:: |
protected | property | ||
ForumAccessBaseTestCase:: |
protected | property | ||
ForumAccessBaseTestCase:: |
protected | property | ||
ForumAccessBaseTestCase:: |
protected | property | ||
ForumAccessBaseTestCase:: |
protected | property | ||
ForumAccessBaseTestCase:: |
protected | property | ||
ForumAccessBaseTestCase:: |
protected | property | ||
ForumAccessBaseTestCase:: |
protected | property | ||
ForumAccessBaseTestCase:: |
protected | property | ||
ForumAccessBaseTestCase:: |
protected | property | ||
ForumAccessBaseTestCase:: |
protected | property | ||
ForumAccessBaseTestCase:: |
protected | function | Pass if a button with the specified label is found, and optional with the specified index. | |
ForumAccessBaseTestCase:: |
protected | function | Asserts that a field in the current page is disabled. | |
ForumAccessBaseTestCase:: |
protected | function | Asserts that a field in the current page is enabled. | |
ForumAccessBaseTestCase:: |
protected | function | Pass if a button with the specified label is not found. | |
ForumAccessBaseTestCase:: |
function | Check the set of permissions in one forum. | ||
ForumAccessBaseTestCase:: |
function | |||
ForumAccessBaseTestCase:: |
function | |||
ForumAccessBaseTestCase:: |
protected | function | ||
ForumAccessBaseTestCase:: |
protected | function | ||
ForumAccessBaseTestCase:: |
function | Makes Devel's dpm() work inside this test, if Devel is installed. | ||
ForumAccessBaseTestCase:: |
protected | function | Extend drupalCreateUser() base method to accept a name as well as multiple roles (rather than permissions). | |
ForumAccessBaseTestCase:: |
protected | function | ||
ForumAccessBaseTestCase:: |
function |
Implements setUp(). Overrides ForumTestCase:: |
||
ForumAccessBaseTestCase:: |
function | |||
ForumAccessBaseTestCase:: |
function |
Tests that forum nodes can't be added without a parent. Overrides ForumTestCase:: |
||
ForumAccessBaseTestCase:: |
function |
Tests disabling and re-enabling the Forum module. Overrides ForumTestCase:: |
||
ForumAccessBaseTestCase:: |
function |
Tests forum functionality through the admin and user interfaces. Overrides ForumTestCase:: |
||
ForumAccessBaseTestCase:: |
function | Writes a krumo entry into the watchdog log, if Devel is installed. | ||
ForumTestCase:: |
protected | property | A user with various administrative privileges. | |
ForumTestCase:: |
protected | property | An array representing a container. | |
ForumTestCase:: |
protected | property | A user that can create, edit, and delete forum topics. | |
ForumTestCase:: |
protected | property | A user that can create forum topics and edit its own topics. | |
ForumTestCase:: |
protected | property | An array representing a forum. | |
ForumTestCase:: |
protected | property | An array of forum topic node IDs. | |
ForumTestCase:: |
protected | property | An array representing a root forum. | |
ForumTestCase:: |
protected | property | A user with no special privileges. | |
ForumTestCase:: |
function | Creates a forum container or a forum. | ||
ForumTestCase:: |
function | Creates forum topic. | ||
ForumTestCase:: |
function | Deletes a forum. | ||
ForumTestCase:: |
private | function | Runs admin tests on the admin user. | |
ForumTestCase:: |
private | function | Runs basic tests on the indicated user. | |
ForumTestCase:: |
function | Edits the forum taxonomy. | ||
ForumTestCase:: |
private | function | Generates forum topics to test the display of an active forum block. | |
ForumTestCase:: |
public static | function | ||
ForumTestCase:: |
private | function | Verifies that the logged in user has access to a forum nodes. | |
ForumTestCase:: |
private | function | Verifies display of forum page. | |
ForumTestCase:: |
private | function | Views forum topics to test the display of an active forum block. |