1 comment.test CommentThreadingTestCase::testCommentThreading()

Tests the comment threading.

File

core/modules/comment/tests/comment.test, line 2191
Tests for the Comment module.

Class

CommentThreadingTestCase
Tests comment threading.

Code

function testCommentThreading() {
  $langcode = LANGUAGE_NONE;
  // Set comments to have a title with preview disabled.
  $this->backdropLogin($this->admin_user);
  $this->setCommentPreview(BACKDROP_DISABLED);
  $this->setCommentForm(TRUE);
  $this->setCommentSubject(COMMENT_TITLE_CUSTOM);
  $this->setCommentSettings('comment_mode', COMMENT_MODE_THREADED, 'Comment paging changed.');
  $this->backdropLogout();

  // Create a node.
  $this->backdropLogin($this->web_user);
  $this->node = $this->backdropCreateNode(array('type' => 'post', 'promote' => 1, 'uid' => $this->web_user->uid));

  // Post comment #1.
  $this->backdropLogin($this->web_user);
  $title_text = $this->randomName();
  $comment_text = $this->randomName();
  $comment = $this->postComment($this->node, $comment_text, $title_text, TRUE);
  $comment_loaded = comment_load($comment->id);
  $this->assertTrue($this->commentExists($comment), 'Comment #1. Comment found.');
  $this->assertEqual($comment_loaded->thread, '01/');

  // Reply to comment #1 creating comment #2.
  $this->backdropLogin($this->web_user);
  $this->backdropGet('comment/reply/' . $this->node->nid . '/' . $comment->id);
  $reply = $this->postComment(NULL, $this->randomName(), '', TRUE);
  $reply_loaded = comment_load($reply->id);
  $this->assertTrue($this->commentExists($reply, TRUE), 'Comment #2. Reply found.');
  $this->assertEqual($reply_loaded->thread, '01.00/');

  // Reply to comment #2 creating comment #3.
  $this->backdropGet('comment/reply/' . $this->node->nid . '/' . $reply->id);
  $reply = $this->postComment(NULL, $this->randomName(), $this->randomName(), TRUE);
  $reply_loaded = comment_load($reply->id);
  $this->assertTrue($this->commentExists($reply, TRUE), 'Comment #3. Second reply found.');
  $this->assertEqual($reply_loaded->thread, '01.00.00/');

  // Reply to comment #1 creating comment #4.
  $this->backdropLogin($this->web_user);
  $this->backdropGet('comment/reply/' . $this->node->nid . '/' . $comment->id);
  $reply = $this->postComment(NULL, $this->randomName(), '', TRUE);
  $reply_loaded = comment_load($reply->id);
  $this->assertTrue($this->commentExists($comment), 'Comment #4. Third reply found.');
  $this->assertEqual($reply_loaded->thread, '01.01/');

  // Post comment #2 overall comment #5.
  $this->backdropLogin($this->web_user);
  $title_text = $this->randomName();
  $comment_text = $this->randomName();
  $comment = $this->postComment($this->node, $comment_text, $title_text, TRUE);
  $comment_loaded = comment_load($comment->id);
  $this->assertTrue($this->commentExists($comment), 'Comment #5. Second comment found.');
  $this->assertEqual($comment_loaded->thread, '02/');

  // Reply to comment #5 creating comment #6.
  $this->backdropLogin($this->web_user);
  $this->backdropGet('comment/reply/' . $this->node->nid . '/' . $comment->id);
  $reply = $this->postComment(NULL, $this->randomName(), '', TRUE);
  $reply_loaded = comment_load($reply->id);
  $this->assertTrue($this->commentExists($reply, TRUE), 'Comment #6. Reply found.');
  $this->assertEqual($reply_loaded->thread, '02.00/');

  // Reply to comment #6 creating comment #7.
  $this->backdropGet('comment/reply/' . $this->node->nid . '/' . $reply->id);
  $reply = $this->postComment(NULL, $this->randomName(), $this->randomName(), TRUE);
  $reply_loaded = comment_load($reply->id);
  $this->assertTrue($this->commentExists($reply, TRUE), 'Comment #7. Second reply found.');
  $this->assertEqual($reply_loaded->thread, '02.00.00/');

  // Reply to comment #5 creating comment #8.
  $this->backdropLogin($this->web_user);
  $this->backdropGet('comment/reply/' . $this->node->nid . '/' . $comment->id);
  $reply = $this->postComment(NULL, $this->randomName(), '', TRUE);
  $reply_loaded = comment_load($reply->id);
  $this->assertTrue($this->commentExists($comment), 'Comment #8. Third reply found.');
  $this->assertEqual($reply_loaded->thread, '02.01/');
}