? .DS_Store
? .htaccess
? sites/all/modules/devel
? sites/default/files
? sites/default/settings.php
Index: modules/forum/forum.test
===================================================================
RCS file: /cvs/drupal/drupal/modules/forum/forum.test,v
retrieving revision 1.56
diff -u -p -r1.56 forum.test
--- modules/forum/forum.test	28 Apr 2010 05:54:55 -0000	1.56
+++ modules/forum/forum.test	9 May 2010 04:07:29 -0000
@@ -10,6 +10,7 @@ class ForumTestCase extends DrupalWebTes
   protected $forum;
   protected $root_forum;
   protected $nids;
+  protected $post_count;
 
   public static function getInfo() {
     return array(
@@ -45,6 +46,12 @@ class ForumTestCase extends DrupalWebTes
     // Generate topics to populate the active forum block.
     $this->generateForumTopics($this->forum);
 
+    // Generate topics posts to populate the active forum block.
+    foreach ($this->nids as $nid) {
+      $node = node_load($nid);
+      $this->generateForumPosts($node);
+    }
+
     // Login an unprivileged user to view the forum topics and generate an
     // active forum topics list.
     $this->drupalLogin($this->web_user);
@@ -72,7 +79,8 @@ class ForumTestCase extends DrupalWebTes
     // Verify the topic and post counts on the forum page.
     $this->drupalGet('forum');
     $this->assertRaw("<td class=\"topics\">\n          6                  </td>");
-    $this->assertRaw('<td class="posts">6</td>');
+    $this->post_count += 4;
+    $this->assertRaw('<td class="posts">'. $this->post_count .'</td>');
 
     // Test loading multiple forum nodes on the front page.
     $this->drupalLogin($this->drupalCreateUser(array('administer content types', 'create forum content')));
@@ -286,6 +294,8 @@ class ForumTestCase extends DrupalWebTes
     $this->createForumTopic($this->container, TRUE);
     // Create forum node.
     $node = $this->createForumTopic($this->forum, FALSE);
+    // Create response
+    $this->createForumPost($node);
     // Verify the user has access to all the forum nodes.
     $this->verifyForums($user, $node, $admin);
   }
@@ -341,6 +351,78 @@ class ForumTestCase extends DrupalWebTes
   }
 
   /**
+   * Create Forum Post (comment).
+   *
+   * @param $node
+   *   Node to post comment on.
+   * @param $contact
+   *   Set to NULL for no contact info, TRUE to ignore success checking, and
+   *   array of values to set contact info.
+   */
+  function createForumPost($node, $contact = NULL) {
+    $subject = $this->randomName(20);
+    $comment = $this->randomName(200);
+    $langcode = LANGUAGE_NONE;
+    $edit = array();
+    $edit['comment_body[' . $langcode . '][0][value]'] = $comment;
+
+    $preview_mode = variable_get('comment_preview_article', DRUPAL_OPTIONAL);
+    $subject_mode = variable_get('comment_subject_field_article', 1);
+
+    // Must get the page before we test for fields.
+    if ($node !== NULL) {
+      $this->drupalGet('comment/reply/' . $node->nid);
+    }
+
+    if ($subject_mode == TRUE) {
+      $edit['subject'] = $subject;
+    }
+    else {
+      $this->assertNoFieldByName('subject', '', t('Subject field not found.'));
+    }
+
+    if ($contact !== NULL && is_array($contact)) {
+      $edit += $contact;
+    }
+    switch ($preview_mode) {
+      case DRUPAL_REQUIRED:
+        // Preview required so no save button should be found.
+        $this->assertNoFieldByName('op', t('Save'), t('Save button not found.'));
+        $this->drupalPost(NULL, $edit, t('Preview'));
+        // Don't break here so that we can test post-preview field presence and
+        // function below.
+      case DRUPAL_OPTIONAL:
+        $this->assertFieldByName('op', t('Preview'), t('Preview button found.'));
+        $this->assertFieldByName('op', t('Save'), t('Save button found.'));
+        $this->drupalPost(NULL, $edit, t('Save'));
+        break;
+
+      case DRUPAL_DISABLED:
+        $this->assertNoFieldByName('op', t('Preview'), t('Preview button not found.'));
+        $this->assertFieldByName('op', t('Save'), t('Save button found.'));
+        $this->drupalPost(NULL, $edit, t('Save'));
+        break;
+    }
+    $this->post_count++;
+    $match = array();
+    // Get comment ID
+    preg_match('/#comment-([0-9]+)/', $this->getURL(), $match);
+
+    // Get comment.
+    if ($contact !== TRUE) { // If true then attempting to find error message.
+      if ($subject) {
+        $this->assertText($subject, 'Comment subject posted.');
+      }
+      $this->assertText($comment, 'Comment body posted.');
+      $this->assertTrue((!empty($match) && !empty($match[1])), t('Comment id found.'));
+    }
+
+    if (isset($match[1])) {
+      return (object) array('id' => $match[1], 'subject' => $subject, 'comment' => $comment);
+    }
+  }
+
+  /**
    * Verify the logged in user has access to a forum nodes.
    *
    * @param $node_user
@@ -367,9 +449,36 @@ class ForumTestCase extends DrupalWebTes
     }
 
     // Verify the forum blocks were displayed.
+    drupal_flush_all_caches();
     $this->drupalGet('');
     $this->assertResponse(200);
     $this->assertText(t('New forum topics'), t('[New forum topics] Forum block was displayed'));
+    $this->assertText(t('Active forum topics'), t('[Active forum topics] Forum block was displayed'));
+    
+    // Verify top topics are listed on blocks first
+    $topics = array();
+    $result = db_query("SELECT nid FROM {node} WHERE type = 'forum'");
+    while ($nid = $result->fetchField()) {
+      $topics[] = node_load($nid);
+    }
+    $newest_topic = array('nid' => 0, 'title' => '', 'created' => 0, 'comment_count' => 0);
+    $active_topic = array('nid' => 0, 'title' => '', 'created' => 0, 'comment_count' => 0);
+    foreach ($topics as $topic) {
+      $comment_count = db_query("SELECT COUNT(cid) count FROM {comment} WHERE nid = :nid", array(':nid' => $topic->nid))->fetchField();
+      $newest_topic = $topic->created > $newest_topic['created'] ? array('nid' => $topic->nid, 'title' => $topic->title, 'created' => $topic->created, 'comment_count' => $comment_count) : $newest_topic;
+      $active_topic = $topic->created > $active_topic['created'] ? array('nid' => $topic->nid, 'title' => $topic->title, 'created' => $topic->created, 'comment_count' => $comment_count) : $active_topic;
+      $active_topic = $topic->last_comment_timestamp > $active_topic['created'] ? array('nid' => $topic->nid, 'title' => $topic->title, 'created' => $topic->last_comment_timestamp, 'comment_count' => $comment_count) : $active_topic;
+    }
+    if ($newest_topic['nid']) {
+      $s = $newest_topic['comment_count'] > 1 ? 's' : '';
+      $title = $newest_topic['comment_count'] ? ' title="'. $newest_topic['comment_count'] .' comment'. $s .'"' : '';
+      $this->assertRaw('<ul><li class="first"><a href="/node/'. $newest_topic['nid'] .'"'. $title .'>'. $newest_topic['title'] .'</a></li>');
+    }
+    if ($active_topic['nid']) {
+      $s = $active_topic['comment_count'] > 1 ? 's' : '';
+      $title = $active_topic['comment_count'] ? ' title="'. $active_topic['comment_count'] .' comment'. $s .'"' : '';
+      $this->assertRaw('<ul><li class="first"><a href="/node/'. $active_topic['nid'] .'"'. $title .'>'. $active_topic['title'] .'</a></li>');
+    }
 
     // View forum container page.
     $this->verifyForumView($this->container);
@@ -452,6 +561,18 @@ class ForumTestCase extends DrupalWebTes
   }
 
   /**
+   * Generate forum posts to test display of active forum block.
+   *
+   * @param array $node Forum array (a row from taxonomy_term_data table).
+   */
+  private function generateForumPosts($node) {
+    $max = rand(0,20);
+    for ($i = 0; $i < $max; $i++) {
+      $this->createForumPost($node);
+    }
+  }
+
+  /**
    * View forum topics to test display of active forum block.
    *
    * @todo The logic here is completely incorrect, since the active
@@ -472,4 +593,5 @@ class ForumTestCase extends DrupalWebTes
       }
     }
   }
+  
 }
