diff --git a/core/modules/comment/comment.module b/core/modules/comment/comment.module index 9ad7cfc..9c7f843 100644 --- a/core/modules/comment/comment.module +++ b/core/modules/comment/comment.module @@ -755,10 +755,12 @@ function comment_node_page_additions($node) { $comments_per_page = variable_get('comment_default_per_page_' . $node->type, 50); if ($cids = comment_get_thread($node, $mode, $comments_per_page)) { $comments = comment_load_multiple($cids); - comment_prepare_thread($comments); - $build = comment_view_multiple($comments, $node); - $build['pager']['#theme'] = 'pager'; - $additions['comments'] = $build; + if ($comments) { + comment_prepare_thread($comments); + $build = comment_view_multiple($comments, $node); + $build['pager']['#theme'] = 'pager'; + $additions['comments'] = $build; + } } } @@ -1375,9 +1377,11 @@ function comment_node_update_index($node) { $comments_per_page = variable_get('comment_default_per_page_' . $node->type, 50); if ($node->comment && $cids = comment_get_thread($node, $mode, $comments_per_page)) { $comments = comment_load_multiple($cids); - comment_prepare_thread($comments); - $build = comment_view_multiple($comments, $node); - return drupal_render($build); + if ($comments) { + comment_prepare_thread($comments); + $build = comment_view_multiple($comments, $node); + return drupal_render($build); + } } } return ''; diff --git a/core/modules/comment/comment.test b/core/modules/comment/comment.test index 74f735d..b6e2615 100644 --- a/core/modules/comment/comment.test +++ b/core/modules/comment/comment.test @@ -2117,3 +2117,57 @@ class CommentFieldsTest extends CommentHelperCase { $this->drupalPost('node/' . $this->node->nid, $edit, t('Save')); } } + +/** + * Tests the behavior of comments when the comment author is deleted. + */ +class CommentAuthorDeletionTestCase extends CommentHelperCase { + public static function getInfo() { + return array( + 'name' => 'Comment author deletion', + 'description' => 'Test the behavior of comments when the comment author is deleted.', + 'group' => 'Comment', + ); + } + + /** + * Tests that comments are correctly deleted when their author is deleted. + */ + function testAuthorDeletion() { + // Create a comment as the admin user. + $this->drupalLogin($this->admin_user); + $comment = $this->postComment($this->node, $this->randomName()); + $this->assertTrue($this->commentExists($comment), t('Comment is displayed initially.')); + $this->drupalLogout(); + + // Delete the admin user, and check that the node which displays the + // comment can still be viewed, but the comment itself does not appear + // there. + user_delete($this->admin_user->uid); + $this->drupalGet('node/' . $this->node->nid); + $this->assertResponse(200, t('Node page is accessible after the comment author is deleted.')); + $this->assertFalse($this->commentExists($comment), t('Comment is not displayed after the comment author is deleted.')); + } + + /** + * Test comment author deletion while the comment module is disabled. + */ + function testAuthorDeletionCommentModuleDisabled() { + // Create a comment as the admin user. + $this->drupalLogin($this->admin_user); + $comment = $this->postComment($this->node, $this->randomName()); + $this->assertTrue($this->commentExists($comment), t('Comment is displayed initially.')); + $this->drupalLogout(); + + // Delete the admin user while the comment module is disabled, and ensure + // that the missing comment author is still handled correctly (the node + // itself should be displayed, but the comment should not be displayed on + // it). + module_disable(array('comment')); + user_delete($this->admin_user->uid); + module_enable(array('comment')); + $this->drupalGet('node/' . $this->node->nid); + $this->assertResponse(200, t('Node page is accessible after the comment author is deleted.')); + $this->assertFalse($this->commentExists($comment), t('Comment is not displayed after the comment author is deleted.')); + } +}