diff options
-rw-r--r-- | modules/comment/comment.module | 13 | ||||
-rw-r--r-- | modules/comment/comment.pages.inc | 20 | ||||
-rw-r--r-- | modules/comment/comment.test | 46 |
3 files changed, 77 insertions, 2 deletions
diff --git a/modules/comment/comment.module b/modules/comment/comment.module index 80c69f9a9..6dc45017f 100644 --- a/modules/comment/comment.module +++ b/modules/comment/comment.module @@ -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)) { diff --git a/modules/comment/comment.pages.inc b/modules/comment/comment.pages.inc index b9cb35d9d..8e4944402 100644 --- a/modules/comment/comment.pages.inc +++ b/modules/comment/comment.pages.inc @@ -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(); + } +} diff --git a/modules/comment/comment.test b/modules/comment/comment.test index f8933b820..82b204767 100644 --- a/modules/comment/comment.test +++ b/modules/comment/comment.test @@ -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.')); } /** |