Skip to content
Snippets Groups Projects
Commit 3f052180 authored by Dries Buytaert's avatar Dries Buytaert
Browse files

- Patch #66264 by boombatower: comment approval displayed on node view of...

- Patch #66264 by boombatower: comment approval displayed on node view of comment.  Comes with tests and everything.
parent cccf98aa
No related branches found
No related tags found
No related merge requests found
......@@ -212,6 +212,13 @@ function comment_menu() {
'access arguments' => array('view', 2),
'type' => MENU_CALLBACK,
);
$items['comment/approve'] = array(
'title' => 'Approve to comment',
'page callback' => 'comment_approve',
'page arguments' => array(2),
'access arguments' => array('administer comments'),
'type' => MENU_CALLBACK,
);
return $items;
}
......@@ -808,6 +815,12 @@ function comment_links($comment, $return = 1) {
'title' => t('reply'),
'href' => "comment/reply/$comment->nid/$comment->cid"
);
if ($comment->status == COMMENT_NOT_PUBLISHED) {
$links['comment_approve'] = array(
'title' => t('approve'),
'href' => "comment/approve/$comment->cid"
);
}
}
elseif (user_access('post comments')) {
if (comment_access('edit', $comment)) {
......
......@@ -113,3 +113,23 @@ function comment_reply($node, $pid = NULL) {
return $output;
}
/**
* Publish specified comment.
*
* @param $cid ID of comment to be published.
*/
function comment_approve($cid) {
// Load the comment whose cid = $cid
if ($comment = comment_load($cid)) {
$operations = comment_operations('publish');
db_query($operations['publish'][1], $cid);
drupal_set_message(t('Comment approved.'));
drupal_goto("node/$comment->nid");
}
else {
drupal_set_message(t('The comment you are approving does not exist.'), 'error');
drupal_goto();
}
}
......@@ -162,6 +162,17 @@ class CommentTestCase extends DrupalWebTestCase {
$this->drupalGet('admin/content/comment');
$this->assertNoRaw('comments[' . $anonymous_comment3->id . ']', t('Comment was deleted.'));
// Reset.
$this->drupalLogin($this->admin_user);
$this->setAnonymousUserComment(FALSE, FALSE);
}
/**
* Test comment approval functionality through admin/content/comment.
*/
function testApprovalAdminInterface() {
$this->drupalLogin($this->admin_user);
// Set anonymouse comments to require approval.
$this->setAnonymousUserComment(TRUE, FALSE);
$this->setCommentAnonymous('0'); // Ensure that doesn't require contact info.
......@@ -188,10 +199,41 @@ class CommentTestCase extends DrupalWebTestCase {
$this->drupalGet('node/' . $this->node->nid);
$this->assertTrue($this->commentExists($anonymous_comment4), t('Anonymous comment visible.'));
}
// Reset.
/**
* Test comment approval functionality through node interface.
*/
function testApprovalNodeInterface() {
$this->drupalLogin($this->admin_user);
$this->setAnonymousUserComment(FALSE, FALSE);
// Set anonymouse comments to require approval.
$this->setAnonymousUserComment(TRUE, FALSE);
$this->setCommentAnonymous('0'); // Ensure that doesn't require contact info.
$this->drupalLogout();
// Post anonymous comment without contact info.
$subject = $this->randomName();
$body = $this->randomName();
$this->postComment($this->node, $subject, $body, TRUE, TRUE); // Set $contact to true so that it won't check for id and message.
$this->assertText(t('Your comment has been queued for moderation by site administrators and will be published after approval.'), t('Comment requires approval.'));
// Get unaproved comment id.
$this->drupalLogin($this->admin_user);
$anonymous_comment4 = $this->getUnaprovedComment($subject);
$anonymous_comment4 = (object) array('id' => $anonymous_comment4, 'subject' => $subject, 'comment' => $body);
$this->drupalLogout();
$this->assertFalse($this->commentExists($anonymous_comment4), t('Anonymous comment was not published.'));
// Approve comment.
$this->drupalLogin($this->admin_user);
$this->drupalGet('node/'. $this->node->nid);
$this->clickLink(t('approve'));
$this->drupalLogout();
$this->drupalGet('node/'. $this->node->nid);
$this->assertTrue($this->commentExists($anonymous_comment4), t('Anonymous comment visible.'));
}
/**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment