=== modified file 'modules/comment/comment.test'
--- modules/comment/comment.test	2008-04-20 18:23:21 +0000
+++ modules/comment/comment.test	2008-04-27 15:24:10 +0000
@@ -5,16 +5,24 @@ class CommentTestCase extends DrupalWebT
   protected $admin_user;
   protected $web_user;
   protected $node;
+  protected $contactPattern = '/(input).*?(name="name").*?(input).*?(name="mail").*?(input).*?(name="homepage")/s';
 
   /**
-   * Implementation of getInfo().
+   * Set comment preview setting.
+   *
+   * @param boolean $required Preview value.
    */
-  function getInfo() {
-    return array(
-      'name' => t('Comment functionality'),
-      'description' => t('Thoroughly test comment administration and user interfaces.'),
-      'group' => t('Comment'),
-    );
+  function setCommentPreview($required) {
+    $this->setCommentSettings('comment_preview', ($required ? '1' : '0'), 'Comment preview '. ($required ? 'required' : 'optional') .'.');
+  }
+
+  /**
+   * Set comment form setting.
+   *
+   * @param boolean $enabled Form value.
+   */
+  function setCommentForm($enabled) {
+    $this->setCommentSettings('comment_form_location', ($enabled ? '1' : '3'), 'Comment controls '. ($enabled ? 'enabled' : 'disabled') .'.');
   }
 
   /**
@@ -25,173 +33,6 @@ class CommentTestCase extends DrupalWebT
     // Create users.
     $this->admin_user = $this->drupalCreateUser(array('administer content types', 'administer comments', 'administer permissions'));
     $this->web_user = $this->drupalCreateUser(array('access comments', 'post comments', 'create story content'));
-
-    $this->drupalLogin($this->web_user);
-    $this->node = $this->drupalCreateNode(array('type' => 'story'));
-    $this->assertTrue($this->node, t('Story node created.'));
-    $this->drupalLogout();
-  }
-
-  /**
-   * Test comment interface.
-   */
-  function testCommentInterface() {
-    // Set comments to not have subject.
-    $this->drupalLogin($this->admin_user);
-    $this->setCommentPreview(TRUE);
-    $this->setCommentSubject(FALSE);
-    $this->drupalLogout();
-
-    // Post comment without subject.
-    $this->drupalLogin($this->web_user);
-    $this->drupalGet('comment/reply/'. $this->node->nid);
-    $this->assertNoFieldByName('subject', '', t('Subject field not found.'));
-
-    // Set comments to have subject and preview to required.
-    $this->drupalLogout();
-    $this->drupalLogin($this->admin_user);
-    $this->setCommentSubject(TRUE);
-    $this->setCommentPreview(TRUE);
-    $this->drupalLogout();
-
-    // Create comment that requires preview.
-    $this->drupalLogin($this->web_user);
-    $comment = $this->postComment($this->node, $this->randomName(), $this->randomName());
-    $this->assertTrue($this->commentExists($comment), t('Comment found.'));
-
-    // Reply to comment.
-    $this->drupalGet('comment/reply/'. $this->node->nid .'/'. $comment->id);
-    $reply = $this->postComment(NULL, $this->randomName(), $this->randomName());
-    $this->assertTrue($this->commentExists($reply, TRUE), t('Reply found.'));
-
-    // 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.'));
-
-    // Delete comment and make sure that reply is also removed.
-    $this->drupalLogout();
-    $this->drupalLogin($this->admin_user);
-    $this->deleteComment($comment);
-
-    $this->drupalGet('node/'. $this->node->nid);
-    $this->assertFalse($this->commentExists($comment), t('Comment not found.'));
-    $this->assertFalse($this->commentExists($reply, TRUE), t('Reply not found.'));
-  }
-
-  /**
-   * Test comment form on node page.
-   */
-  function testFormOnPage() {
-    // Enabled comment form on node page.
-    $this->drupalLogin($this->admin_user);
-    $this->setCommentForm(TRUE);
-    $this->drupalLogout();
-
-    // Submit comment through node form.
-    $this->drupalLogin($this->web_user);
-    $this->drupalGet('node/'. $this->node->nid);
-    $form_comment = $this->postComment(NULL, $this->randomName(), $this->randomName());
-    $this->assertTrue($this->commentExists($form_comment), t('Form comment found.'));
-
-    // Disable comment form on node page.
-    $this->drupalLogout();
-    $this->drupalLogin($this->admin_user);
-    $this->setCommentForm(FALSE);
-  }
-
-  /**
-   * Test anonymous comment functionality.
-   */
-  function testAnonymous() {
-    $this->drupalLogin($this->admin_user);
-    // Enabled anonymous user comments.
-    $this->setAnonymousUserComment(TRUE, TRUE);
-    $this->setCommentAnonymous('0'); // Ensure that doesn't require contact info.
-    $this->drupalLogout();
-
-    // Post anonymous comment without contact info.
-    $anonymous_comment1 = $this->postComment($this->node, $this->randomName(), $this->randomName());
-    $this->assertTrue($this->commentExists($anonymous_comment1), t('Anonymous comment without contact info found.'));
-
-    // Allow contact info.
-    $this->drupalLogin($this->admin_user);
-    $this->setCommentAnonymous('1');
-    $this->drupalLogout();
-
-    // Post anonymous comment with contact info (optional).
-    $this->drupalGet('comment/reply/'. $this->node->nid);
-    $this->assertTrue($this->commentContactInfoAvailable(), t('Contact information available.'));
-
-    $anonymous_comment2 = $this->postComment($this->node, $this->randomName(), $this->randomName());
-    $this->assertTrue($this->commentExists($anonymous_comment2), t('Anonymous comment with contact info (optional) found.'));
-
-    // Require contact info.
-    $this->drupalLogin($this->admin_user);
-    $this->setCommentAnonymous('2');
-    $this->drupalLogout();
-
-    // Try to post comment with contact info (required).
-    $this->drupalGet('comment/reply/'. $this->node->nid);
-    $this->assertTrue($this->commentContactInfoAvailable(), t('Contact information available.'));
-
-    $anonymous_comment3 = $this->postComment($this->node, $this->randomName(), $this->randomName(), TRUE, TRUE);
-    $this->assertText(t('E-mail field is required.'), t('E-mail required.')); // Name should have 'Anonymous' for value by default.
-    $this->assertFalse($this->commentExists($anonymous_comment3), t('Anonymous comment with contact info (required) not found.'));
-
-    // Post comment with contact info (required).
-    $anonymous_comment3 = $this->postComment($this->node, $this->randomName(), $this->randomName(), FALSE, array('mail' => 'tester@simpletest.org'));
-    $this->assertTrue($this->commentExists($anonymous_comment3), t('Anonymous comment with contact info (required) found.'));
-
-    // Unpublish comment.
-    $this->drupalLogin($this->admin_user);
-    $this->performCommentOperation($anonymous_comment3, 'unpublish');
-
-    $this->drupalGet('admin/content/comment/approval');
-    $this->assertRaw('comments['. $anonymous_comment3->id .']', t('Comment was unpublished.'));
-
-    // Publish comment.
-    $this->performCommentOperation($anonymous_comment3, 'publish', TRUE);
-
-    $this->drupalGet('admin/content/comment');
-    $this->assertRaw('comments['. $anonymous_comment3->id .']', t('Comment was published.'));
-
-    // Delete comment.
-    $this->performCommentOperation($anonymous_comment3, 'delete');
-
-    $this->drupalGet('admin/content/comment');
-    $this->assertNoRaw('comments['. $anonymous_comment3->id .']', t('Comment was deleted.'));
-
-    // Set anonymouse comments to require approval.
-    $this->setAnonymousUserComment(TRUE, FALSE);
-    $this->setCommentAnonymous('0'); // Ensure that doesn't require contact info.
-    $this->drupalLogout();
-
-    // Post anonymous comment without contact info.
-    $subject = $this->randomName();
-    $body = $this->randomName();
-    $this->postComment($this->node, $subject, $body, TRUE, TRUE); // Set $contact to true so that it won't check for id and message.
-    $this->assertText(t('Your comment has been queued for moderation by site administrators and will be published after approval.'), t('Comment requires approval.'));
-
-    // Get unaproved comment id.
-    $this->drupalLogin($this->admin_user);
-    $anonymous_comment4 = $this->getUnaprovedComment($subject);
-    $anonymous_comment4 = (object) array('id' => $anonymous_comment4, 'subject' => $subject, 'comment' => $body);
-    $this->drupalLogout();
-
-    $this->assertFalse($this->commentExists($anonymous_comment4), t('Anonymous comment was not published.'));
-
-    // Approve comment.
-    $this->drupalLogin($this->admin_user);
-    $this->performCommentOperation($anonymous_comment4, 'publish', TRUE);
-    $this->drupalLogout();
-
-    $this->drupalGet('node/'. $this->node->nid);
-    $this->assertTrue($this->commentExists($anonymous_comment4), t('Anonymous comment visible.'));
-
-    // Reset.
-    $this->drupalLogin($this->admin_user);
-    $this->setAnonymousUserComment(FALSE, FALSE);
   }
 
   /**
@@ -274,24 +115,6 @@ class CommentTestCase extends DrupalWebT
   }
 
   /**
-   * Set comment preview setting.
-   *
-   * @param boolean $required Preview value.
-   */
-  function setCommentPreview($required) {
-    $this->setCommentSettings('comment_preview', ($required ? '1' : '0'), 'Comment preview '. ($required ? 'required' : 'optional') .'.');
-  }
-
-  /**
-   * Set comment form setting.
-   *
-   * @param boolean $enabled Form value.
-   */
-  function setCommentForm($enabled) {
-    $this->setCommentSettings('comment_form_location', ($enabled ? '1' : '3'), 'Comment controls '. ($enabled ? 'enabled' : 'disabled') .'.');
-  }
-
-  /**
    * Set comment anonymous level setting.
    *
    * @param integer $level Anonymous level.
@@ -328,15 +151,6 @@ class CommentTestCase extends DrupalWebT
   }
 
   /**
-   * Check for contact info.
-   *
-   * @return boolean Contact info is avialable.
-   */
-  function commentContactInfoAvailable() {
-    return preg_match('/(input).*?(name="name").*?(input).*?(name="mail").*?(input).*?(name="homepage")/s', $this->drupalGetContent());
-  }
-
-  /**
    * Perform the specified operation on the specified comment.
    *
    * @param object $comment Comment to perform operation on.
@@ -370,3 +184,225 @@ class CommentTestCase extends DrupalWebT
     return $match[2];
   }
 }
+
+class CommentTestInterface extends CommentTestCase {
+  function getInfo() {
+    return array(
+      'name' => t('Comment interface.'),
+      'description' => t('Post comments with various settings.'),
+      'group' => t('Comment'),
+    );
+  }
+
+  /**
+   * Test comment interface.
+   */
+  function testCommentInterface() {
+    // Set comments to not have subject.
+    $this->drupalLogin($this->admin_user);
+    $this->setCommentPreview(TRUE);
+    $this->setCommentSubject(FALSE);
+    $this->drupalLogout();
+
+    // Post comment without subject.
+    $this->drupalLogin($this->web_user);
+    $this->node = $this->drupalCreateNode(array('type' => 'story'));
+    $this->drupalGet('comment/reply/'. $this->node->nid);
+    $this->assertNoFieldByName('subject', '', t('Subject field not found.'));
+
+    // Set comments to have subject and preview to required.
+    $this->drupalLogout();
+    $this->drupalLogin($this->admin_user);
+    $this->setCommentSubject(TRUE);
+    $this->setCommentPreview(TRUE);
+    $this->drupalLogout();
+
+    // Create comment that requires preview.
+    $this->drupalLogin($this->web_user);
+    $comment = $this->postComment($this->node, $this->randomName(), $this->randomName());
+    $this->assertTrue($this->commentExists($comment), t('Comment found.'));
+
+    // Reply to comment.
+    $this->drupalGet('comment/reply/'. $this->node->nid .'/'. $comment->id);
+    $reply = $this->postComment(NULL, $this->randomName(), $this->randomName());
+    $this->assertTrue($this->commentExists($reply, TRUE), t('Reply found.'));
+
+    // 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.'));
+
+    // Delete comment and make sure that reply is also removed.
+    $this->drupalLogout();
+    $this->drupalLogin($this->admin_user);
+    $this->deleteComment($comment);
+
+    $this->drupalGet('node/'. $this->node->nid);
+    $this->assertFalse($this->commentExists($comment), t('Comment not found.'));
+    $this->assertFalse($this->commentExists($reply, TRUE), t('Reply not found.'));
+  }
+}
+
+class CommentNodePage extends CommentTestCase {
+  function getInfo() {
+    return array(
+      'name' => t('Comment node page.'),
+      'description' => t('Test comment form on node page.'),
+      'group' => t('Comment'),
+    );
+  }
+
+  /**
+   * Test comment form on node page.
+   */
+  function testFormOnPage() {
+    // Enabled comment form on node page.
+    $this->drupalLogin($this->admin_user);
+    $this->setCommentForm(TRUE);
+    $this->drupalLogout();
+
+    // Submit comment through node form.
+    $this->drupalLogin($this->web_user);
+    $this->node = $this->drupalCreateNode(array('type' => 'story'));
+    $this->drupalGet('node/'. $this->node->nid);
+    $form_comment = $this->postComment(NULL, $this->randomName(), $this->randomName());
+    $this->assertTrue($this->commentExists($form_comment), t('Form comment found.'));
+
+    // Disable comment form on node page.
+    $this->drupalLogout();
+    $this->drupalLogin($this->admin_user);
+    $this->setCommentForm(FALSE);
+  }
+}
+
+class CommentAnonymousTestCase extends CommentTestCase {
+  function getInfo() {
+    return array(
+      'name' => t('Comment anonymously, contact info optional.'),
+      'description' => t('Test anonymous comments, contact info optional.'),
+      'group' => t('Comment'),
+    );
+  }
+
+  /**
+   * Test anonymous comment functionality.
+   */
+  function testAnonymousTestCase() {
+    $this->drupalLogin($this->admin_user);
+    // Enabled anonymous user comments.
+    $this->setAnonymousUserComment(TRUE, TRUE);
+    $this->setCommentAnonymous('0'); // Ensure that doesn't require contact info.
+    $this->node = $this->drupalCreateNode(array('type' => 'story'));
+    $this->drupalLogout();
+
+    // Post anonymous comment without contact info.
+    $anonymous_comment = $this->postComment($this->node, $this->randomName(), $this->randomName());
+    $this->assertTrue($this->commentExists($anonymous_comment), t('Anonymous comment without contact info found.'));
+
+    // Allow contact info.
+    $this->drupalLogin($this->admin_user);
+    $this->setCommentAnonymous('1');
+    $this->drupalLogout();
+
+    // Post anonymous comment with contact info (optional).
+    $this->drupalGet('comment/reply/'. $this->node->nid);
+    $this->assertPattern($this->contactPattern, t('Contact information available.'));
+    $anonymous_comment = $this->postComment($this->node, $this->randomName(), $this->randomName());
+    $this->assertTrue($this->commentExists($anonymous_comment), t('Anonymous comment with contact info (optional) found.'));
+  }
+}
+
+class CommentAnonymousWithContactInfoTestCase extends CommentTestCase {
+  function getInfo() {
+    return array(
+      'name' => t('Comment anonymously, contact info required.'),
+      'description' => t('Test anonymous comments, contact info required.'),
+      'group' => t('Comment'),
+    );
+  }
+
+
+  function testAnonymousWithContactInfoTestCase() {
+    // Require contact info.
+    $this->drupalLogin($this->admin_user);
+    $this->setAnonymousUserComment(TRUE, TRUE);
+    $this->setCommentAnonymous('2');
+    $this->node = $this->drupalCreateNode(array('type' => 'story'));
+    $this->drupalLogout();
+
+    // Try to post comment with contact info (required).
+    $this->drupalGet('comment/reply/'. $this->node->nid);
+    $this->assertPattern($this->contactPattern, t('Contact information available.'));
+
+    $anonymous_comment = $this->postComment($this->node, $this->randomName(), $this->randomName(), TRUE, TRUE);
+    $this->assertText(t('E-mail field is required.'), t('E-mail required.')); // Name should have 'Anonymous' for value by default.
+    $this->assertFalse($this->commentExists($anonymous_comment), t('Anonymous comment with contact info (required) not found.'));
+
+    // Post comment with contact info (required).
+    $anonymous_comment = $this->postComment($this->node, $this->randomName(), $this->randomName(), TRUE, array('mail' => 'tester@simpletest.org'));
+    $this->assertTrue($this->commentExists($anonymous_comment), t('Anonymous comment with contact info (required) found.'));
+
+    // Unpublish comment.
+    $this->drupalLogin($this->admin_user);
+    $this->performCommentOperation($anonymous_comment, 'unpublish');
+
+    $this->drupalGet('admin/content/comment/approval');
+    $this->assertRaw('comments['. $anonymous_comment->id .']', t('Comment was unpublished.'));
+
+    // Publish comment.
+    $this->performCommentOperation($anonymous_comment, 'publish', TRUE);
+
+    $this->drupalGet('admin/content/comment');
+    $this->assertRaw('comments['. $anonymous_comment->id .']', t('Comment was published.'));
+
+    // Delete comment.
+    $this->performCommentOperation($anonymous_comment, 'delete');
+    $this->drupalGet('admin/content/comment');
+    $this->assertNoRaw('comments['. $anonymous_comment->id .']', t('Comment was deleted.'));
+
+  }
+}
+class CommentAnonymousApprovalTestCase extends CommentTestCase {
+  function getInfo() {
+    return array(
+      'name' => t('Comment anonymously w/ approval.'),
+      'description' => t('Test anonymous comments, approval required.'),
+      'group' => t('Comment'),
+    );
+  }
+
+  function testAnonymousApprovalTestCase() {
+    $this->drupalLogin($this->admin_user);
+    // Set anonymouse comments to require approval.
+    $this->setAnonymousUserComment(TRUE, FALSE);
+    $this->setCommentAnonymous('0'); // Ensure that doesn't require contact info.
+    $this->node = $this->drupalCreateNode(array('type' => 'story'));
+    $this->drupalLogout();
+
+    // Post anonymous comment without contact info.
+    $subject = $this->randomName();
+    $body = $this->randomName();
+    $this->postComment($this->node, $subject, $body, TRUE, TRUE); // Set $contact to true so that it won't check for id and message.
+    $this->assertText(t('Your comment has been queued for moderation by site administrators and will be published after approval.'), t('Comment requires approval.'));
+
+    // Get unaproved comment id.
+    $this->drupalLogin($this->admin_user);
+    $anonymous_comment = $this->getUnaprovedComment($subject);
+    $anonymous_comment = (object) array('id' => $anonymous_comment, 'subject' => $subject, 'comment' => $body);
+    $this->drupalLogout();
+
+    $this->assertFalse($this->commentExists($anonymous_comment), t('Anonymous comment was not published.'));
+
+    // Approve comment.
+    $this->drupalLogin($this->admin_user);
+    $this->performCommentOperation($anonymous_comment, 'publish', TRUE);
+    $this->drupalLogout();
+
+    $this->drupalGet('node/'. $this->node->nid);
+    $this->assertTrue($this->commentExists($anonymous_comment), t('Anonymous comment visible.'));
+
+    // Reset.
+    $this->drupalLogin($this->admin_user);
+    $this->setAnonymousUserComment(FALSE, FALSE);
+  }
+}

