Index: modules/comment/comment.test
===================================================================
RCS file: /cvs/drupal/drupal/modules/comment/comment.test,v
retrieving revision 1.16
diff -u -p -r1.16 comment.test
--- modules/comment/comment.test	14 Oct 2008 20:34:56 -0000	1.16
+++ modules/comment/comment.test	16 Oct 2008 16:08:38 -0000
@@ -10,7 +10,7 @@ class CommentHelperCase extends DrupalWe
    * Implementation of setUp().
    */
   function setUp() {
-    parent::setUp('comment');
+    parent::setUp('comment', 'comment_test');
     // 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 article content'));
@@ -18,6 +18,9 @@ class CommentHelperCase extends DrupalWe
     $this->drupalLogin($this->web_user);
     $this->node = $this->drupalCreateNode(array('type' => 'article', 'promote' => 1));
     $this->drupalLogout();
+
+    // Reset hook call tracking.
+    comment_test_reset();
   }
 
   /**
@@ -61,6 +64,9 @@ class CommentHelperCase extends DrupalWe
     if (isset($match[1])) {
       return (object) array('id' => $match[1], 'subject' => $subject, 'comment' => $comment);
     }
+
+    $this->assertCommentHookCalled('insert');
+    $this->assertCommentHookCalled('validate');
   }
 
   /**
@@ -95,6 +101,7 @@ class CommentHelperCase extends DrupalWe
   function deleteComment($comment) {
     $this->drupalPost('comment/delete/' . $comment->id, array(), t('Delete'));
     $this->assertText(t('The comment and all its replies have been deleted.'), t('Comment deleted.'));
+    $this->assertCommentHookCalled('delete');
   }
 
   /**
@@ -210,7 +217,10 @@ class CommentHelperCase extends DrupalWe
     }
     else {
       $this->assertText(t('The update has been performed.'), t('Operation "' . $operation . '" was performed on comment.'));
+      $this->assertCommentHookCalled('update');
     }
+    // Verify that hook_comment() was called.
+    $this->assertCommentHookCalled($operation);
   }
 
   /**
@@ -227,6 +237,34 @@ class CommentHelperCase extends DrupalWe
 
     return $match[2];
   }
+
+  /**
+   * Assert that hook_comment() is called.
+   *
+   * @param $op
+   *   String with the $op name, e.g. 'insert', 'update', 'view', etc.
+   * @param $expected_count
+   *   Optional integer count.
+   * @param $message
+   *   Optional translated string message.
+   */
+  function assertCommentHookCalled($op, $expected_count = 1, $message = NULL) {
+    $actual_count = count(comment_test_get_calls($op));
+
+    if (is_null($message)) {
+      if ($actual_count == $expected_count) {
+        $message = t('hook_comment() was called correctly for the %op operation.', array('%op' => $op));
+      }
+      else {
+        $message = t('hook_comment($a1, %op) was expected to be called %expected times but was called %actual times.', array('%op' => $op, '%expected' => $expected_count, '%actual' => $actual_count));
+      }
+    }
+    $this->assertEqual($actual_count, $expected_count, $message);
+
+    // Reset operation
+    comment_test_reset_op($op);
+  }
+
 }
 
 class CommentInterfaceTest extends CommentHelperCase {
@@ -270,6 +308,7 @@ class CommentInterfaceTest extends Comme
     $comment_text = $this->randomName();
     $comment = $this->postComment($this->node, $subject_text, $comment_text);
     $comment_loaded = comment_load($comment->id);
+    $this->assertCommentHookCalled('view');
     $this->assertTrue($this->commentExists($comment), t('Comment found.'));
 
     // Check comment display.
@@ -283,6 +322,7 @@ class CommentInterfaceTest extends Comme
     $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->assertCommentHookCalled('view');
     $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.'));
@@ -293,6 +333,7 @@ class CommentInterfaceTest extends Comme
     $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->assertCommentHookCalled('view');
     $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.'));
 
Index: modules/simpletest/tests/comment_test.info
===================================================================
RCS file: modules/simpletest/tests/comment_test.info
diff -N modules/simpletest/tests/comment_test.info
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ modules/simpletest/tests/comment_test.info	16 Oct 2008 16:08:38 -0000
@@ -0,0 +1,8 @@
+; $Id$
+name = "Comment test"
+description = "Support module for testing hook_comment()."
+package = Testing
+version = VERSION
+core = 7.x
+files[] = comment_test.module
+hidden = TRUE
Index: modules/simpletest/tests/comment_test.module
===================================================================
RCS file: modules/simpletest/tests/comment_test.module
diff -N modules/simpletest/tests/comment_test.module
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ modules/simpletest/tests/comment_test.module	16 Oct 2008 16:08:38 -0000
@@ -0,0 +1,51 @@
+<?php
+
+// $Id$
+
+/**
+ * Implementation of hook_comment().
+ */
+function comment_test_comment($a1, $op) {
+  $count = variable_get('comment_test_hook_count_' . $op);
+  $count ++;
+  variable_set('comment_test_hook_count_' . $op, $count);
+}
+
+/**
+ * Reset/initialize the history of calls to hook_comment().
+ */
+function comment_test_reset() {
+  $operations = array(
+    'insert' => array(),
+    'update' => array(),
+    'view' => array(),
+    'validate' => array(),
+    'publish' => array(),
+    'unpublish' => array(),
+    'delete' => array(),
+  );
+  foreach ($operations as $op) {
+    comment_test_reset_op($op);
+  }
+}
+
+/**
+ * Get the values passed to hook_comment() for a given operation.
+ *
+ * @param $op
+ *   One of the hook_comment() operations.
+ * @return
+ *   Array of the parameters passed to each call.
+ */
+function comment_test_get_calls($op) {
+  return variable_get('comment_test_hook_count_' . $op, 0);
+}
+
+/**
+ * Reset specified operation count to 0.
+ * @param $op
+ *   hook_comment operation
+ */
+function comment_test_reset_op($op) {
+  variable_set('comment_test_hook_count_' . $op, 0);
+}
