function ForumAccessBaseTestCase::checkForum in Forum Access 7
Check the set of permissions in one forum.
Parameters
$forum: An associative array describing the forum.
$is_default: Set to TRUE if this is the default forum (without any moderator).
2 calls to ForumAccessBaseTestCase::checkForum()
File
- tests/
forum_access_test_base.php, line 359 - Base class with auxiliary functions for forum access module tests.
Class
- ForumAccessBaseTestCase
- Base test class for the Forum Access module.
Code
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.");
}