From dfe10a92744410a612f93526a774710775d24a4b Mon Sep 17 00:00:00 2001
From: Kelly <mushroomhead52e@gmail.com>
Date: Mon, 27 Feb 2012 20:37:59 -0500
Subject: [PATCH] comment-test

---
 core/modules/comment/comment.test |   99 ++++++++++++++++++++++++++++++++++++-
 1 files changed, 97 insertions(+), 2 deletions(-)

diff --git a/core/modules/comment/comment.test b/core/modules/comment/comment.test
index dd74d13..3198618 100644
--- a/core/modules/comment/comment.test
+++ b/core/modules/comment/comment.test
@@ -1042,10 +1042,9 @@ class CommentPreviewTest extends CommentHelperCase {
     $this->assertEqual($comment_loaded->comment_body[$langcode][0]['value'], $edit['comment_body[' . $langcode . '][0][value]'], t('Comment body loaded.'));
     $this->assertEqual($comment_loaded->name, $edit['name'], t('Name loaded.'));
     $this->assertEqual($comment_loaded->created, $raw_date, t('Date loaded.'));
-
   }
-
 }
+
 /**
  * Tests anonymous commenting.
  */
@@ -1533,6 +1532,7 @@ class CommentNodeAccessTest extends CommentHelperCase {
     $this->assertText($reply_subject);
   }
 }
+
 /**
  * Tests comment approval functionality.
  */
@@ -2096,3 +2096,98 @@ class CommentFieldsTest extends CommentHelperCase {
     $this->drupalPost('node/' . $this->node->nid, $edit, t('Save'));
   }
 }
+
+/**
+ * Tests comment threading.
+ */
+class CommentThreadingTestCase extends CommentHelperCase {
+  public static function getInfo() {
+    return array(
+      'name' => 'Comment Threading',
+      'description' => 'Test to make sure the comment number increments properly.',
+      'group' => 'Comment',
+    );
+  }
+
+  /**
+   * Tests the comment threading.
+   */
+  function testCommentThreading() {
+    $langcode = LANGUAGE_NONE;
+    // Set comments to have a subject with preview disabled.
+    $this->drupalLogin($this->admin_user);
+    $this->setCommentPreview(DRUPAL_DISABLED);
+    $this->setCommentForm(TRUE);
+    $this->setCommentSubject(TRUE);
+    $this->setCommentSettings('comment_default_mode', COMMENT_MODE_THREADED, t('Comment paging changed.'));
+    $this->drupalLogout();
+
+    // Create a node.
+    $this->drupalLogin($this->web_user);
+    $this->node = $this->drupalCreateNode(array('type' => 'article', 'promote' => 1, 'uid' => $this->web_user->uid));
+
+    // Post comment #1.
+    $this->drupalLogin($this->web_user);
+    $subject_text = $this->randomName();
+    $comment_text = $this->randomName();
+    $comment = $this->postComment($this->node, $comment_text, $subject_text, TRUE);
+    $comment_loaded = comment_load($comment->id);
+    $this->assertTrue($this->commentExists($comment), t('Comment #1. Comment found. Thread 01/'));
+    $this->assertEqual($comment_loaded->thread, '01/', t('Thread of reply grows correctly.'));
+
+    // Reply to comment #1 creating comment #2.
+    $this->drupalLogin($this->web_user);
+    $this->drupalGet('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), t('Comment #2. Reply found. Thread 01.00/'));
+    $this->assertEqual($reply_loaded->thread, '01.00/', t('Thread of reply grows correctly.'));
+
+    // Reply to comment #2 creating comment #3.
+    $this->drupalGet('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), t('Comment #3. Second reply found. Thread 01.00.00/'));
+    $this->assertEqual($reply_loaded->thread, '01.00.00/', t('Thread of second reply grows correctly.'));
+
+    // Reply to comment #1 creating comment #4.
+    $this->drupalLogin($this->web_user);
+    $this->drupalGet('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), t('Comment #4. Third reply found. Thread 01.01/'));
+    $this->assertEqual($reply_loaded->thread, '01.01/', t('Thread of reply grows correctly.'));
+
+    // Post comment #2 overall comment #5.
+    $this->drupalLogin($this->web_user);
+    $subject_text = $this->randomName();
+    $comment_text = $this->randomName();
+    $comment = $this->postComment($this->node, $comment_text, $subject_text, TRUE);
+    $comment_loaded = comment_load($comment->id);
+    $this->assertTrue($this->commentExists($comment), t('Comment #5. Second comment found. Thread 02/'));
+    $this->assertEqual($comment_loaded->thread, '02/', t('Thread of reply grows correctly.'));
+
+    // Reply to comment #5 creating comment #6.
+    $this->drupalLogin($this->web_user);
+    $this->drupalGet('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), t('Comment #6. Reply found. Thread 02.00/'));
+    $this->assertEqual($reply_loaded->thread, '02.00/', t('Thread of reply grows correctly.'));
+
+    // Reply to comment #6 creating comment #7.
+    $this->drupalGet('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), t('Comment #7. Second reply found. Thread 02.00.00/'));
+    $this->assertEqual($reply_loaded->thread, '02.00.00/', t('Thread of second reply grows correctly.'));
+
+    // Reply to comment #5 creating comment #8.
+    $this->drupalLogin($this->web_user);
+    $this->drupalGet('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), t('Comment #8. Third reply found. Thread 02.01/'));
+    $this->assertEqual($reply_loaded->thread, '02.01/', t('Thread of reply grows correctly.'));
+  }
+}
-- 
1.7.7.GIT

