--- comment.test	2009-02-07 15:10:40.000000000 -0500
+++ modules/comment/comment.test	2009-03-07 18:02:42.000000000 -0500
@@ -123,7 +122,7 @@ 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 ? '1' : '0'), 'Comment controls ' . ($enabled ? 'enabled' : 'disabled') . '.');
   }
 
   /**
@@ -143,7 +142,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 .'.');
   }
 
   /**
@@ -244,7 +243,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 +302,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.
@@ -533,6 +536,138 @@ class CommentApprovalTest extends Commen
   }
 }
 
+class CommentFormTest extends CommentHelperCase {
+	function getInfo() {
+		return array(
+			'name' => t('Comment form settings'),
+			'description' => t('Test comment form settings and comment form visibility'),
+			'group' => t('Comment')
+			);
+	}
+	
+	function testFormVisibility() {
+		$content_types = node_get_types();
+	    $this->drupalLogin($this->admin_user);
+		foreach($content_types as $type) {
+			$content_type = $type->type;
+		    variable_set('comment_preview_'.$content_type, 0);
+		    variable_set('comment_subject_field_'.$content_type, 1);
+		    variable_set('comment_form_location_'.$content_type, 1);
+
+			$node = $this->drupalCreateNode(array('type' => $content_type));
+			$this->drupalGet('node/' . $node->nid);
+			$this->assertField('edit-comment', t('Comment form appears on the node page.'));
+
+		    variable_set('comment_form_location_'.$content_type, 0);
+			$this->drupalGet('node/' . $node->nid);
+			$this->assertRaw(t('Add new comment'), t('Link to comment form appears on the node page.'));
+			$this->assertNoField('edit-comment', t('Comment form does not appear on the node page.'));
+		}
+		$this->drupalLogout();
+	}
+}
+
+/**
+ * verify pagination of comments
+ *
+ */
+class CommentPagerTest extends CommentHelperCase {
+
+  function getInfo() {
+    return array(
+      'name' => t('Comment paging settings'),
+      'description' => t('Test paging of comments and their settings.'),
+      'group' => t('Comment'),
+    );
+  }
+
+  function testCommentPaging() {
+    $this->drupalLogin($this->admin_user);
+	$this->setCommentForm(TRUE);
+   $this->setCommentSubject(TRUE);
+   $this->setCommentPreview(FALSE);
+	$node = $this->drupalCreateNode(array('type' => 'article', 'promote' => 1));
+	$comments = array();
+    foreach (range(0, 24) as $i) {
+      $comments[] = $this->postComment($node, $this->randomName(), $this->randomName(), FALSE, TRUE);
+    }
+
+    $this->setCommentSettings('comment_default_mode', COMMENT_MODE_FLAT_EXPANDED, t('Comment paging changed.'));
+    $this->setCommentsPerPage(10);
+    $this->drupalGet('node/' . $node->nid);
+	error_log(print_r($comments, 1));
+	error_log($this->drupalGetContent());
+	exit;
+    $this->assertRaw(t('next ›'), t('Paging links found.'));
+    //exhaustive tests for comments
+    foreach (range(0, 9) as $i) {
+      $this->assertTrue($this->commentExists($comments[$i]), t('Comment ' . $i . ' appears on page 1.'));
+    }
+    foreach (range(10, 24) as $i) {
+      $this->assertFalse($this->commentExists($comments[$i]), t('Comment ' . $i . ' does not appear on page 1.'));
+    }
+    
+    $this->drupalGet('node/' . $node->nid, array('query' => 'page=1'));
+	error_log($this->drupalGetContent());
+    foreach (range(10, 19) as $i) {
+      $this->assertTrue($this->commentExists($comments[$i]), t('Comment ' . $i . ' appears on page 2.'));
+    }
+    foreach (array_merge(range(0, 9), range(20, 24)) as $i) {
+      $this->assertFalse($this->commentExists($comments[$i]), t('Comment ' . $i . ' does not appear on page 2.'));
+    }
+    
+    $this->drupalGet('node/' . $node->nid, array('query' => 'page=2'));
+	error_log($this->drupalGetContent());
+    foreach (range(20, 24) as $i) {
+      $this->assertTrue($this->commentExists($comments[$i]), t('Comment ' . $i . ' appears on page 3.'));
+    }
+    foreach (range(0, 19) as $i) {
+      $this->assertFalse($this->commentExists($comments[$i]), t('Comment ' . $i . ' does not appear on page 3.'));
+    }
+
+	// Post four replies to the oldest comment and test again - there are 30 comments total now
+	$replies = array();
+	$oldest_comment = reset($comments);
+	foreach (range(0, 4) as $i) {
+	    $this->drupalGet('comment/reply/' . $node->nid . '/' . $oldest_comment->id);
+		$reply = $this->postComment(null, $this->randomName(), $this->randomName(), FALSE, TRUE);
+		$replies[] = $reply;
+	}
+
+	// We're still in flat view - the replies should not be on the first, 
+	// even though they're replies to the oldest comment
+	$this->drupalGet('node/' . $node->nid, array('query' => 'page=0'));
+	error_log('******** NODE THREADED EXPANDED VIEW PAGE 0 -- 4 REPLIES, FLAT MODE *********');
+	error_log($this->drupalGetContent());
+    foreach (range(0, 4) as $i) {
+		$this->assertFalse($this->commentExists($replies[$i], TRUE), t('In flat mode, reply ' . $i . ' does not appear on page 1.'));
+	}
+	
+	// If we switch to threaded mode, the replies on the oldest comment should be bumped to the first page
+	// and comment 6 should be bumped to the second page
+	$this->setCommentSettings('comment_default_mode', COMMENT_MODE_THREADED_EXPANDED, t('Switched to threaded mode.'));
+	$this->drupalGet('node/' . $node->nid, array('query' => 'page=0'));
+	error_log('******** NODE THREADED EXPANDED VIEW PAGE 0 -- 4 REPLIES, THREADED MODE *********');
+	error_log($this->drupalGetContent());
+    foreach (range(0, 4) as $i) {
+		$this->assertTrue($this->commentExists($replies[$i], TRUE), t('In threaded mode, reply ' . $i . ' appears on page 1.'));
+	}
+	$this->assertFalse($this->commentExists($comments[5]), t('In threaded mode, comment 6 has been bumped off of page 1.'));
+
+	// If (# replies > # comments per page) in threaded expanded view, the overage should be bumped
+	foreach (range(0, 5) as $i) {
+    	$this->drupalGet('comment/reply/' . $node->nid . '/' . $oldest_comment->id);
+		$reply = $this->postComment(NULL, $this->randomName(), $this->randomName(), FALSE, TRUE);
+		$replies[] = $reply;
+	}
+	$this->drupalGet('node/' . $node->nid, array('query' => 'page=0'));
+	$this->assertFalse($this->commentExists(end($replies), TRUE), t('In threaded mode where # replies > # comments per page, the newest reply does not appear on page 1.'));
+
+    $this->drupalLogout();
+  }
+}
+
+
 /**
  * Functional tests for the comment module blocks.
  */
