Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Tests Flat Comments.
<?php
namespace Drupal\comment\Tests;
use Drupal\comment\CommentManagerInterface;
/**
* Tests to make sure the comment number increments properly.
*
* @group comment
*/
class CommentFlatTest extends CommentTestBase {
/**
* Tests the comment threading.
*/
public function testCommentFlatDelete() {
// Set comments to have a subject with preview disabled.
$this->drupalLogin($this->adminUser);
$this->setCommentPreview(DRUPAL_DISABLED);
$this->setCommentForm(TRUE);
$this->setCommentSubject(TRUE);
$this->setCommentSettings('default_mode', CommentManagerInterface::COMMENT_MODE_FLAT, 'Comment paging changed.');
// Create a node.
$this->node = $this->drupalCreateNode(['type' => 'article', 'promote' => 1, 'uid' => $this->adminUser->id()]);
// Post comment #1.
$subject_text = $this->randomMachineName();
$comment_text = $this->randomMachineName();
$comment1 = $this->postComment($this->node, $comment_text, $subject_text, TRUE);
// Confirm that the comment was created and has the correct threading.
$this->assertTrue($this->commentExists($comment1), 'Comment #1. Comment found.');
// Reply to comment #1 creating comment #1_2.
$this->drupalGet('comment/reply/node/' . $this->node->id() . '/comment/' . $comment1->id());
$comment1_2 = $this->postComment(NULL, $this->randomMachineName(), '', TRUE);
// Confirm that the comment was created and is not in a thread.
$this->assertTrue($this->commentExists($comment1_2, FALSE), 'Comment #1_2. Reply found.');
// Reply to comment #1_2 creating comment #1_2_3.
$this->drupalGet('comment/reply/node/' . $this->node->id() . '/comment/' . $comment1_2->id());
$comment1_2_3 = $this->postComment(NULL, $this->randomMachineName(), $this->randomMachineName(), TRUE);
// Confirm that the comment was created and is not in a thread.
$this->assertTrue($this->commentExists($comment1_2_3, FALSE), 'Comment #1_2_3. Second reply found.');
// Delete the first comment.
$this->deleteComment($comment1);
// Confirm that the rest of the comments are still there.
$this->assertTrue($this->commentExists($comment1_2_3, FALSE), 'Comment #1_2_3. Second reply found.');
$this->assertTrue($this->commentExists($comment1_2, FALSE), 'Comment #1_3. Reply found.');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment