Index: modules/comment/comment.test
===================================================================
RCS file: /cvs/drupal/drupal/modules/comment/comment.test,v
retrieving revision 1.26
diff -u -p -r1.26 comment.test
--- modules/comment/comment.test	17 Mar 2009 12:41:54 -0000	1.26
+++ modules/comment/comment.test	25 Mar 2009 15:51:18 -0000
@@ -71,11 +71,21 @@ class CommentHelperCase extends DrupalWe
    */
   function commentExists($comment, $reply = FALSE) {
     if ($comment && is_object($comment)) {
-      $regex = '/' . ($reply ? '<div class="indented">(.*?)' : '');
+      // Default thread setting for comments is threaded, expanded.
+      $thread_setting = $this->getCommentSettings('comment_default_mode',
+                            COMMENT_MODE_THREADED_EXPANDED);
+      $threaded = $thread_setting == COMMENT_MODE_THREADED_EXPANDED || 
+                  $thread_setting == COMMENT_MODE_THREADED_COLLAPSED;
+      // Replies are only indented if we're in threaded mode.
+      $regex = '/' . ($reply && $threaded ? '<div class="indented">(.*?)' : '');
       $regex .= '<a id="comment-' . $comment->id . '"(.*?)'; // Comment anchor.
       $regex .= '<div(.*?)'; // Begin in comment div.
       $regex .= $comment->subject . '(.*?)'; // Match subject.
-      $regex .= $comment->comment . '(.*?)'; // Match comment.
+      // Comment body only shows up if we're in expanded mode.
+      if($thread_setting == COMMENT_MODE_THREADED_EXPANDED
+        || $thread_setting == COMMENT_MODE_FLAT_EXPANDED) {
+          $regex .= $comment->comment . '(.*?)'; // Match comment.
+      }
       $regex .= '<\/div>/s'; // Dot matches newlines and ensure that match doesn't bleed outside comment div.
 
       return (boolean)preg_match($regex, $this->drupalGetContent());
@@ -123,7 +133,9 @@ class CommentHelperCase extends DrupalWe
    *   Form value.
    */
   function setCommentForm($enabled) {
-    $this->setCommentSettings('comment_form_location', ($enabled ? '1' : '3'), 'Comment controls ' . ($enabled ? 'enabled' : 'disabled') . '.');
+    $this->setCommentSettings('comment_form_location', 
+      ($enabled ? COMMENT_FORM_BELOW : COMMENT_FORM_SEPARATE_PAGE), 
+      'Comment controls ' . ($enabled ? 'enabled' : 'disabled') . '.');
   }
 
   /**
@@ -143,7 +155,7 @@ class CommentHelperCase extends DrupalWe
    *   Comments per page value.
    */
   function setCommentsPerPage($number) {
-    $this->setCommentSettings('comment_default_per_page_article', $number, 'Number of comments per page set to ' . $number .'.');
+    $this->setCommentSettings('comment_default_per_page', $number, 'Number of comments per page set to ' . $number . '.');
   }
 
   /**
@@ -160,6 +172,20 @@ class CommentHelperCase extends DrupalWe
     variable_set($name . '_article', $value);
     $this->assertTrue(TRUE, t($message)); // Display status message.
   }
+  
+  /**
+   * Get comment setting for article content type
+   *
+   * @param string $name 
+   *   Name of variable
+   * @param string $default 
+   *   Default value to return if $name variable is not set
+   * @return mixed 
+   *   Value of $name variable or $default if $name variable is not set
+  **/
+  function getCommentSettings($name, $default) {
+    return variable_get($name . '_article', $default);
+  }
 
   /**
    * Set anonymous comment setting.
@@ -244,7 +270,9 @@ class CommentInterfaceTest extends Comme
     // Set comments to not have subject.
     $this->drupalLogin($this->admin_user);
     $this->setCommentPreview(TRUE);
+    $this->setCommentForm(TRUE);
     $this->setCommentSubject(FALSE);
+    $this->setCommentSettings('comment_default_mode', COMMENT_MODE_THREADED_EXPANDED, t('Comment paging changed.'));
     $this->drupalLogout();
 
     // Post comment without subject.
@@ -280,33 +308,35 @@ class CommentInterfaceTest extends Comme
     $reply_loaded = comment_load($reply->id);
     $this->assertTrue($this->commentExists($reply, TRUE), t('Reply found.'));
     $this->assertEqual($comment->id, $reply_loaded->pid, t('Pid of a reply to a comment is set correctly.'));
-    $this->assertEqual(rtrim($comment_loaded->thread,'/').'.00/', $reply_loaded->thread, t('Thread of reply grows correctly.'));
+    $this->assertEqual(rtrim($comment_loaded->thread,'/') . '.00/', $reply_loaded->thread, t('Thread of reply grows correctly.'));
 
-    // Second reply to comment
+    // Second reply to comment.
     $this->drupalGet('comment/reply/' . $this->node->nid . '/' . $comment->id);
     $this->assertText($subject_text, t('Individual comment-reply subject found.'));
     $this->assertText($comment_text, t('Individual comment-reply body found.'));
     $reply = $this->postComment(NULL, $this->randomName(), $this->randomName());
     $reply_loaded = comment_load($reply->id);
     $this->assertTrue($this->commentExists($reply, TRUE), t('Second reply found.'));
-    $this->assertEqual(rtrim($comment_loaded->thread,'/').'.01/', $reply_loaded->thread, t('Thread of second reply grows correctly.'));
+    $this->assertEqual(rtrim($comment_loaded->thread,'/') . '.01/', $reply_loaded->thread, t('Thread of second reply grows correctly.'));
 
     // Edit reply.
     $this->drupalGet('comment/edit/' . $reply->id);
     $reply = $this->postComment(NULL, $this->randomName(), $this->randomName());
     $this->assertTrue($this->commentExists($reply, TRUE), t('Modified reply found.'));
 
-    // Correct link count
+    // Verify correct link count.
     $this->drupalGet('node');
     $this->assertRaw('3 comments', t('Link to the 3 comments exist.'));
 
-    // Pager
-    $this->setCommentsPerPage(2);
+    // Test paging.
+    $this->drupalGet('node/' . $this->node->nid);
     $comment_new_page = $this->postComment($this->node, $this->randomName(), $this->randomName());
+    $this->setCommentsPerPage(2);
     $this->drupalGet('node/' . $this->node->nid);
-    $this->assertTrue($this->commentExists($comment) && $this->commentExists($comment_new_page), t('Page one exists. %s'));
+    $this->assertTrue($this->commentExists($comment), t('Comment on page one exists. %s'));
+    $this->assertFalse($this->commentExists($comment_new_page), t('New comment on page one doesn\'t exist. %s'));
     $this->drupalGet('node/' . $this->node->nid, array('query' => 'page=1'));
-    $this->assertTrue($this->commentExists($reply, TRUE), t('Page two exists. %s'));
+    $this->assertTrue($this->commentExists($reply, TRUE), t('New comment exists on page two. %s'));
     $this->setCommentsPerPage(50);
 
     // Attempt to post to node with comments disabled.
@@ -524,16 +554,150 @@ class CommentApprovalTest extends Commen
 
     // Approve comment.
     $this->drupalLogin($this->admin_user);
-    $this->drupalGet('node/'. $this->node->nid);
+    $this->drupalGet('node/' . $this->node->nid);
     $this->clickLink(t('approve'));
     $this->drupalLogout();
 
-    $this->drupalGet('node/'. $this->node->nid);
+    $this->drupalGet('node/' . $this->node->nid);
     $this->assertTrue($this->commentExists($anonymous_comment4), t('Anonymous comment visible.'));
   }
 }
 
 /**
+ * Threading tests for comments.
+**/
+class CommentThreadingTest extends CommentHelperCase {
+  function getInfo() {
+    return array(
+      'name' => t('Comment thread settings'),
+      'description' => t('Test threading of comments and their settings.'),
+      'group' => t('Comment'),
+    );
+  }
+  
+  /**
+   * Test the four collapsed / expanded modes:
+   * COMMENT_MODE_FLAT_COLLAPSED
+   * COMMENT_MODE_THREADED_COLLAPSED
+   * COMMENT_MODE_FLAT_EXPANDED
+   * COMMENT_MODE_THREADED_EXPANDED
+   * 
+   * We don't need special tests in this function for collapsed vs. expanded
+   * with respect to showing or hiding comment body. Those tests are built 
+   * into CommentHelperCase::commentExists .
+  **/
+  function testExpandedCollapsed() {
+    $this->drupalLogin($this->admin_user);
+    $this->setCommentForm(TRUE);
+    $this->setCommentSubject(TRUE);
+    $this->setCommentPreview(FALSE);
+
+    $node = $this->drupalCreateNode(array('type' => 'article', 'promote' => 1));
+    $comment1 = $this->postComment($node, $this->randomName(), $this->randomName(), FALSE, TRUE);
+    $comment2 = $this->postComment($node, $this->randomName(), $this->randomName(), FALSE, TRUE);
+
+    // Post a reply to test threading.
+    $this->drupalGet('comment/reply/' . $node->nid . '/' . $comment1->id);
+    $reply1 = $this->postComment(null, $this->randomName(), $this->randomName(), FALSE, TRUE);
+
+    // Post a reply to the reply to further test threading.
+    $this->drupalGet('comment/reply/' . $node->nid . '/' . $reply1->id);
+    $reply2 = $this->postComment(null, $this->randomName(), $this->randomName(), FALSE, TRUE);
+
+
+    $pattern = '/<div class="indented">(<a id="new">)?<a id="comment-' . $reply1->id . '">/';
+    $xpath = '//div[@class="indented"]/div[@class="indented"]/a[@id="comment-' . $reply2->id . '"]';
+
+    $this->setCommentsPerPage(2);
+
+    // In flat view, the replies should not be on the first page, even though
+    // they're replies to the oldest comment. This is not a paging test, but 
+    // it's easier than checking the DOM.
+    // ==================================
+    // = TESTS FOR FLAT, COLLAPSED MODE =
+    // ==================================
+    $this->setCommentSettings('comment_default_mode', COMMENT_MODE_FLAT_COLLAPSED, 
+      t('Switched to flat, collapsed mode.'));
+    $this->drupalGet('node/' . $node->nid, array('query' => 'page=0'));
+    $this->assertFalse($this->commentExists($reply1, TRUE), 
+      t('Flat, collapsed mode is flattened on page 1 (1).'), 'Comment');
+    $this->assertFalse($this->commentExists($reply2, TRUE), 
+      t('Flat, expanded mode is flattened on page 1 (2).'), 'Comment');
+
+    // And where they exist, they should not be indented
+    $this->drupalGet('node/' . $node->nid, array('query' => 'page=1'));
+    $this->assertTrue($this->commentExists($reply1, TRUE), 
+      t('Flat, collapsed mode is flattened on page 2.'), 'Comment');
+    $this->assertNoPattern($pattern, t('Flat, collapsed reply is not indented'), 'Comment');
+    $this->assertFalse($this->xpath($xpath));
+
+    // =================================
+    // = TESTS FOR FLAT, EXPANDED MODE =
+    // =================================
+    $this->setCommentSettings('comment_default_mode', COMMENT_MODE_FLAT_EXPANDED, 
+      t('Switched to flat, expanded mode.'));
+    $this->drupalGet('node/' . $node->nid, array('query' => 'page=0'));
+    $this->assertFalse($this->commentExists($reply1, TRUE), 
+      t('Flat, expanded mode reply 1 is flattened on page 1.'), 'Comment');
+    $this->assertFalse($this->commentExists($reply2, TRUE), 
+      t('Flat, expanded mode reply 2 is flattened on page 1.'), 'Comment');
+
+    // Replies should not be indented in flat mode.
+    $this->drupalGet('node/' . $node->nid, array('query' => 'page=1'));
+    $this->assertTrue($this->commentExists($reply1, TRUE),
+      t('Flat, expanded mode reply 1 is flattened on page 2.'), 'Comment');
+    $this->assertTrue($this->commentExists($reply2, TRUE),
+      t('Flat, expanded mode reply 2 is flattened on page 2.'), 'Comment');
+    $this->assertNoPattern($pattern, t('Flat, expanded reply is not indented.'), 'Comment');
+    $this->assertFalse($this->xpath($xpath), t('Flat, expanded reply 2 is not indented.'), 'Comment');
+
+
+    // In threaded mode, the replies on the oldest comment should appear 
+    // on the first page, while comment 2 should be bumped to the second.
+    // This is not a paging test, but it's easier than checking the DOM.
+    // ======================================
+    // = TESTS FOR THREADED, COLLAPSED MODE =
+    // ======================================
+    $this->setCommentsPerPage(3);
+    $this->setCommentSettings('comment_default_mode', COMMENT_MODE_THREADED_COLLAPSED, 
+      t('Switched to threaded, collapsed mode.'));
+    $this->drupalGet('node/' . $node->nid, array('query' => 'page=0'));
+    $this->assertTrue($this->commentExists($reply1, TRUE), 
+      t('Threaded, collapsed mode is threaded on page 1 (1).'), 'Comment');
+    $this->assertTrue($this->commentExists($reply2, TRUE), 
+      t('Threaded, collapsed mode is threaded on page 1 (2).'), 'Comment');
+    $this->assertFalse($this->commentExists($comment2, TRUE), 
+      t('Threaded, collapsed mode is threaded on page 1 (3).'), 'Comment');
+
+    // Replies should be indented in threaded, expanded mode.
+    $this->assertPattern($pattern, t('Threaded, collapsed reply is indented'), 'Comment');
+    $this->assertTrue($this->xpath($xpath),
+      t('Threaded, collapsed reply to a reply is double-indented'), 'Comment');
+
+    // =====================================
+    // = TESTS FOR THREADED, EXPANDED MODE =
+    // =====================================
+    $this->setCommentSettings('comment_default_mode', COMMENT_MODE_THREADED_EXPANDED, 
+      t('Switched to threaded, expanded mode.'));
+    $this->drupalGet('node/' . $node->nid, array('query' => 'page=0'));
+    $this->assertTrue($this->commentExists($reply1, TRUE), 
+      t('Threaded, expanded mode is threaded on page 1 (1).'), 'Comment');
+    $this->assertTrue($this->commentExists($reply2, TRUE), 
+      t('Threaded, expanded mode is threaded on page 1 (2).'), 'Comment');
+    $this->assertFalse($this->commentExists($comment2, TRUE), 
+      t('Threaded, expanded mode is threaded on page 1 (3).'), 'Comment');
+
+    // Replies should be indented in threaded, expanded mode.
+    $this->assertPattern($pattern, t('Threaded, expanded reply is indented'), 'Comment');
+    $this->assertTrue($this->xpath($xpath),
+      t('Threaded, expanded reply to a reply is double-indented'), 'Comment');
+
+
+  }
+  
+}
+
+/**
  * Functional tests for the comment module blocks.
  */
 class CommentBlockFunctionalTest extends CommentHelperCase {
