1 comment.test CommentPagerTest::testCommentOrderingThreading()

Tests comment ordering and threading.

File

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

Class

CommentPagerTest
Verifies pagination of comments.

Code

function testCommentOrderingThreading() {
  $this->backdropLogin($this->admin_user);

  // Set comment config.
  $this->setCommentForm(TRUE);
  $this->setCommentSubject(COMMENT_TITLE_CUSTOM);
  $this->setCommentPreview(BACKDROP_DISABLED);

  // Display all the comments on the same page.
  $this->setCommentsPerPage(1000);

  // Create a node and three comments.
  $node = $this->backdropCreateNode(array('type' => 'post', 'promote' => 1));
  $comments = array();
  $comments[] = $this->postComment($node, $this->randomName(), $this->randomName(), TRUE);
  $comments[] = $this->postComment($node, $this->randomName(), $this->randomName(), TRUE);
  $comments[] = $this->postComment($node, $this->randomName(), $this->randomName(), TRUE);

  // Post a reply to the second comment.
  $this->backdropGet('comment/reply/' . $node->nid . '/' . $comments[1]->id);
  $comments[] = $this->postComment(NULL, $this->randomName(), $this->randomName(), TRUE);

  // Post a reply to the first comment.
  $this->backdropGet('comment/reply/' . $node->nid . '/' . $comments[0]->id);
  $comments[] = $this->postComment(NULL, $this->randomName(), $this->randomName(), TRUE);

  // Post a reply to the last comment.
  $this->backdropGet('comment/reply/' . $node->nid . '/' . $comments[2]->id);
  $comments[] = $this->postComment(NULL, $this->randomName(), $this->randomName(), TRUE);

  // Post a reply to the second comment.
  $this->backdropGet('comment/reply/' . $node->nid . '/' . $comments[3]->id);
  $comments[] = $this->postComment(NULL, $this->randomName(), $this->randomName(), TRUE);

  // At this point, the comment tree is:
  // - 0
  //   - 4
  // - 1
  //   - 3
  //     - 6
  // - 2
  //   - 5

  $this->setCommentSettings('comment_mode', COMMENT_MODE_FLAT, 'Comment paging changed.');

  $expected_order = array(
    0,
    1,
    2,
    3,
    4,
    5,
    6,
  );
  $this->backdropGet('node/' . $node->nid);
  $this->assertCommentOrder($comments, $expected_order);

  $this->setCommentSettings('comment_mode', COMMENT_MODE_THREADED, 'Switched to threaded mode.');

  $expected_order = array(
    0,
    4,
    1,
    3,
    6,
    2,
    5,
  );
  $this->backdropGet('node/' . $node->nid);
  $this->assertCommentOrder($comments, $expected_order);
}