Chris@0: drupalLogin($this->adminUser); Chris@0: $this->setCommentPreview(DRUPAL_DISABLED); Chris@0: $this->setCommentForm(TRUE); Chris@0: $this->setCommentSubject(TRUE); Chris@0: $this->setCommentSettings('default_mode', CommentManagerInterface::COMMENT_MODE_THREADED, 'Comment paging changed.'); Chris@0: $this->drupalLogout(); Chris@0: Chris@0: // Create a node. Chris@0: $this->drupalLogin($this->webUser); Chris@0: $this->node = $this->drupalCreateNode(['type' => 'article', 'promote' => 1, 'uid' => $this->webUser->id()]); Chris@0: Chris@0: // Post comment #1. Chris@0: $this->drupalLogin($this->webUser); Chris@0: $subject_text = $this->randomMachineName(); Chris@0: $comment_text = $this->randomMachineName(); Chris@0: Chris@0: $comment1 = $this->postComment($this->node, $comment_text, $subject_text, TRUE); Chris@0: // Confirm that the comment was created and has the correct threading. Chris@0: $this->assertTrue($this->commentExists($comment1), 'Comment #1. Comment found.'); Chris@0: $this->assertEqual($comment1->getThread(), '01/'); Chris@0: // Confirm that there is no reference to a parent comment. Chris@0: $this->assertNoParentLink($comment1->id()); Chris@0: Chris@0: // Post comment #2 following the comment #1 to test if it correctly jumps Chris@0: // out the indentation in case there is a thread above. Chris@0: $subject_text = $this->randomMachineName(); Chris@0: $comment_text = $this->randomMachineName(); Chris@0: $this->postComment($this->node, $comment_text, $subject_text, TRUE); Chris@0: Chris@0: // Reply to comment #1 creating comment #1_3. Chris@0: $this->drupalGet('comment/reply/node/' . $this->node->id() . '/comment/' . $comment1->id()); Chris@0: $comment1_3 = $this->postComment(NULL, $this->randomMachineName(), '', TRUE); Chris@0: Chris@0: // Confirm that the comment was created and has the correct threading. Chris@0: $this->assertTrue($this->commentExists($comment1_3, TRUE), 'Comment #1_3. Reply found.'); Chris@0: $this->assertEqual($comment1_3->getThread(), '01.00/'); Chris@0: // Confirm that there is a link to the parent comment. Chris@0: $this->assertParentLink($comment1_3->id(), $comment1->id()); Chris@0: Chris@0: // Reply to comment #1_3 creating comment #1_3_4. Chris@0: $this->drupalGet('comment/reply/node/' . $this->node->id() . '/comment/' . $comment1_3->id()); Chris@0: $comment1_3_4 = $this->postComment(NULL, $this->randomMachineName(), $this->randomMachineName(), TRUE); Chris@0: Chris@0: // Confirm that the comment was created and has the correct threading. Chris@0: $this->assertTrue($this->commentExists($comment1_3_4, TRUE), 'Comment #1_3_4. Second reply found.'); Chris@0: $this->assertEqual($comment1_3_4->getThread(), '01.00.00/'); Chris@0: // Confirm that there is a link to the parent comment. Chris@0: $this->assertParentLink($comment1_3_4->id(), $comment1_3->id()); Chris@0: Chris@0: // Reply to comment #1 creating comment #1_5. Chris@0: $this->drupalGet('comment/reply/node/' . $this->node->id() . '/comment/' . $comment1->id()); Chris@0: Chris@0: $comment1_5 = $this->postComment(NULL, $this->randomMachineName(), '', TRUE); Chris@0: Chris@0: // Confirm that the comment was created and has the correct threading. Chris@0: $this->assertTrue($this->commentExists($comment1_5), 'Comment #1_5. Third reply found.'); Chris@0: $this->assertEqual($comment1_5->getThread(), '01.01/'); Chris@0: // Confirm that there is a link to the parent comment. Chris@0: $this->assertParentLink($comment1_5->id(), $comment1->id()); Chris@0: Chris@0: // Post comment #3 overall comment #5. Chris@0: $this->drupalLogin($this->webUser); Chris@0: $subject_text = $this->randomMachineName(); Chris@0: $comment_text = $this->randomMachineName(); Chris@0: Chris@0: $comment5 = $this->postComment($this->node, $comment_text, $subject_text, TRUE); Chris@0: // Confirm that the comment was created and has the correct threading. Chris@0: $this->assertTrue($this->commentExists($comment5), 'Comment #5. Second comment found.'); Chris@0: $this->assertEqual($comment5->getThread(), '03/'); Chris@0: // Confirm that there is no link to a parent comment. Chris@0: $this->assertNoParentLink($comment5->id()); Chris@0: Chris@0: // Reply to comment #5 creating comment #5_6. Chris@0: $this->drupalGet('comment/reply/node/' . $this->node->id() . '/comment/' . $comment5->id()); Chris@0: $comment5_6 = $this->postComment(NULL, $this->randomMachineName(), '', TRUE); Chris@0: Chris@0: // Confirm that the comment was created and has the correct threading. Chris@0: $this->assertTrue($this->commentExists($comment5_6, TRUE), 'Comment #6. Reply found.'); Chris@0: $this->assertEqual($comment5_6->getThread(), '03.00/'); Chris@0: // Confirm that there is a link to the parent comment. Chris@0: $this->assertParentLink($comment5_6->id(), $comment5->id()); Chris@0: Chris@0: // Reply to comment #5_6 creating comment #5_6_7. Chris@0: $this->drupalGet('comment/reply/node/' . $this->node->id() . '/comment/' . $comment5_6->id()); Chris@0: $comment5_6_7 = $this->postComment(NULL, $this->randomMachineName(), $this->randomMachineName(), TRUE); Chris@0: Chris@0: // Confirm that the comment was created and has the correct threading. Chris@0: $this->assertTrue($this->commentExists($comment5_6_7, TRUE), 'Comment #5_6_7. Second reply found.'); Chris@0: $this->assertEqual($comment5_6_7->getThread(), '03.00.00/'); Chris@0: // Confirm that there is a link to the parent comment. Chris@0: $this->assertParentLink($comment5_6_7->id(), $comment5_6->id()); Chris@0: Chris@0: // Reply to comment #5 creating comment #5_8. Chris@0: $this->drupalGet('comment/reply/node/' . $this->node->id() . '/comment/' . $comment5->id()); Chris@0: $comment5_8 = $this->postComment(NULL, $this->randomMachineName(), '', TRUE); Chris@0: Chris@0: // Confirm that the comment was created and has the correct threading. Chris@0: $this->assertTrue($this->commentExists($comment5_8), 'Comment #5_8. Third reply found.'); Chris@0: $this->assertEqual($comment5_8->getThread(), '03.01/'); Chris@0: // Confirm that there is a link to the parent comment. Chris@0: $this->assertParentLink($comment5_8->id(), $comment5->id()); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Asserts that the link to the specified parent comment is present. Chris@0: * Chris@0: * @param int $cid Chris@0: * The comment ID to check. Chris@0: * @param int $pid Chris@0: * The expected parent comment ID. Chris@0: */ Chris@0: protected function assertParentLink($cid, $pid) { Chris@0: // This pattern matches a markup structure like: Chris@0: // Chris@0: //
Chris@0: //

Chris@0: // Chris@0: //

Chris@0: //
Chris@18: $pattern = "//article[@id='comment-$cid']//p[contains(@class, 'parent')]//a[contains(@href, 'comment-$pid')]"; Chris@0: Chris@0: $this->assertFieldByXpath($pattern, NULL, format_string( Chris@0: 'Comment %cid has a link to parent %pid.', Chris@0: [ Chris@0: '%cid' => $cid, Chris@0: '%pid' => $pid, Chris@0: ] Chris@0: )); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Asserts that the specified comment does not have a link to a parent. Chris@0: * Chris@0: * @param int $cid Chris@0: * The comment ID to check. Chris@0: */ Chris@0: protected function assertNoParentLink($cid) { Chris@0: // This pattern matches a markup structure like: Chris@0: // Chris@0: //
Chris@0: //

Chris@0: //
Chris@0: Chris@18: $pattern = "//article[@id='comment-$cid']//p[contains(@class, 'parent')]"; Chris@0: $this->assertNoFieldByXpath($pattern, NULL, format_string( Chris@0: 'Comment %cid does not have a link to a parent.', Chris@0: [ Chris@0: '%cid' => $cid, Chris@0: ] Chris@0: )); Chris@0: } Chris@0: Chris@0: }