Index: comment.test
===================================================================
RCS file: /cvs/drupal/drupal/modules/comment/comment.test,v
retrieving revision 1.26
diff -u -p -r1.26 comment.test
--- comment.test	17 Mar 2009 12:41:54 -0000	1.26
+++ comment.test	18 Mar 2009 16:39:28 -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 .'.');
   }
 
   /**
@@ -157,9 +169,23 @@ class CommentHelperCase extends DrupalWe
    *   Status message to display.
    */
   function setCommentSettings($name, $value, $message) {
-    variable_set($name . '_article', $value);
+    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.
@@ -301,12 +329,14 @@ class CommentInterfaceTest extends Comme
     $this->assertRaw('3 comments', t('Link to the 3 comments exist.'));
 
     // Pager
-    $this->setCommentsPerPage(2);
+  //$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.
@@ -534,6 +564,142 @@ class CommentApprovalTest extends Commen
 }
 
 /**
+ * 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.
+    // We're not checking paging, but it's easier to see if comments are threaded by paging
+    //  rather than checking the actual order of comments on the same page.
+    // ==================================
+    // = 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');
+
+    // 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, 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 be bumped to the first page.
+    // And comment 2 should be bumped to the second page.
+    // Again, we're not testing paging, 
+    //  but this way's easier than checking the order of DOM elements.
+    // ======================================
+    // = 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
+    $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
+    $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 {
