Index: tests/mollom.test
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/mollom/tests/mollom.test,v
retrieving revision 1.72
diff -u -p -r1.72 mollom.test
--- tests/mollom.test	18 Oct 2010 14:06:08 -0000	1.72
+++ tests/mollom.test	18 Oct 2010 14:26:22 -0000
@@ -142,16 +142,18 @@ class MollomWebTestCase extends DrupalWe
    *
    * This function can be (repeatedly) invoked to assert new watchdog messages.
    * All watchdog messages with a higher severity than WATCHDOG_NOTICE are
-   * considered as fails.
+   * considered as "severe".
    *
-   * @param $no_fail_expected
-   *   (optional) Boolean whether a failing watchdog message is expected.
-   *   Defaults to TRUE (no fail expected). If FALSE is passed, the logic for
-   *   assertion messages is flipped.
+   * @param $max_severity
+   *   (optional) A maximum watchdog severity level message constant that log
+   *   messages must have to pass the assertion. All messages with a higher
+   *   severity will fail. Defaults to WATCHDOG_NOTICE. If a severity level
+   *   higher than WATCHDOG_NOTICE is passed, then at least one severe message
+   *   is expected.
    *
-   * @todo Add this to D7 core.
+   * @todo Add this to Drupal core.
    */
-  protected function assertMollomWatchdogMessages($no_fail_expected = TRUE) {
+  protected function assertMollomWatchdogMessages($max_severity = WATCHDOG_NOTICE) {
     module_load_include('inc', 'dblog', 'dblog.admin');
 
     $this->messages = array();
@@ -159,23 +161,34 @@ class MollomWebTestCase extends DrupalWe
       ->fields('w')
       ->condition('w.type', 'mollom')
       ->orderBy('w.timestamp', 'ASC');
+
+    // The comparison logic applied in this function is a bit confusing, since
+    // the values of the watchdog severity level constants in Drupal core are
+    // negated to their actual "severity level" meaning:
+    // WATCHDOG_EMERGENCY is 0, WATCHDOG_NOTICE is 5, WATCHDOG_DEBUG is 7.
+
+    $fail_expected = ($max_severity < WATCHDOG_NOTICE);
+    $had_severe_message = FALSE;
     foreach ($query->execute() as $row) {
-      // In case no fail is expected, only log messages with a severity of
-      // WATCHDOG_NOTICE or less severe messages must pass. More severe messages
-      // need to fail. The comparison logic applied here is a bit confusing,
-      // since the values of watchdog severity level constants are negated to
-      // their actual "severity level" meaning:
-      // WATCHDOG_EMERGENCY is 0, WATCHDOG_NOTICE is 5, WATCHDOG_DEBUG is 7.
-      // In case a fail is expected, all messages always pass, since we would
-      // otherwise trigger a false positive test failure if there are additional
-      // non-severe log messages.
-      if (!$no_fail_expected || $row->severity >= WATCHDOG_NOTICE) {
+      $this->messages[$row->wid] = $row;
+      // Only messages with a maximum severity of $max_severity or less severe
+      // messages must pass. More severe messages need to fail. See note about
+      // severity level constant values above.
+      if ($row->severity >= $max_severity) {
         $this->pass(theme_dblog_message(array('event' => $row, 'link' => FALSE)), t('Watchdog'));
       }
       else {
         $this->fail(theme_dblog_message(array('event' => $row, 'link' => FALSE)), t('Watchdog'));
       }
-      $this->messages[$row->wid] = $row;
+      // In case a severe message is expected, non-severe messages always pass,
+      // since we would trigger a false positive test failure otherwise.
+      // However, in order to actually assert the expectation, there must have
+      // been at least one severe log message.
+      $had_severe_message = ($had_severe_message || $row->severity < WATCHDOG_NOTICE);
+    }
+    // Assert that there was a severe message, in case we expected one.
+    if ($fail_expected && !$had_severe_message) {
+      $this->fail(t('Severe log message not found.'), t('Watchdog'));
     }
     // Delete processed watchdog messages.
     if (!empty($this->messages)) {
@@ -625,7 +638,7 @@ class MollomWebTestCase extends DrupalWe
    */
   protected function drupalGet($path, array $options = array(), array $headers = array()) {
     $output = parent::drupalGet($path, $options, $headers);
-    $options += array('watchdog' => TRUE);
+    $options += array('watchdog' => WATCHDOG_NOTICE);
     $this->assertMollomWatchdogMessages($options['watchdog']);
     return $output;
   }
@@ -645,7 +658,7 @@ class MollomWebTestCase extends DrupalWe
    */
   protected function drupalPost($path, $edit, $submit, array $options = array(), array $headers = array(), $form_html_id = NULL, $extra_post = NULL) {
     $output = parent::drupalPost($path, $edit, $submit, $options, $headers, $form_html_id, $extra_post);
-    $options += array('watchdog' => TRUE);
+    $options += array('watchdog' => WATCHDOG_NOTICE);
     $this->assertMollomWatchdogMessages($options['watchdog']);
     return $output;
   }
@@ -796,7 +809,8 @@ class MollomInstallationTestCase extends
       'mollom_public_key' => 'foo',
       'mollom_private_key' => 'bar',
     );
-    $this->drupalPost('admin/config/content/mollom/settings', $edit, t('Save configuration'), array('watchdog' => FALSE));
+    $this->drupalGet('admin/config/content/mollom/settings');
+    $this->drupalPost(NULL, $edit, t('Save configuration'), array('watchdog' => WATCHDOG_EMERGENCY));
     $this->assertText(t('The configuration options have been saved.'));
     $this->assertNoText($this->fallback_message, t('Fallback message not found.'));
 
@@ -806,26 +820,26 @@ class MollomInstallationTestCase extends
     $this->assertNoText(t('The Mollom servers could not be contacted. Please make sure that your web server can make outgoing HTTP requests.'));
 
     // Verify requirements error about invalid API keys.
-    $this->drupalGet('admin/reports/status', array('watchdog' => FALSE));
+    $this->drupalGet('admin/reports/status', array('watchdog' => WATCHDOG_EMERGENCY));
     $this->assertText('The configured Mollom API keys are invalid.');
 
     // Ensure unreachable servers.
     variable_set('mollom_servers', array('http://fake-host'));
 
     // Verify presence of 'network error' message.
-    $this->drupalGet('admin/config/content/mollom/settings', array('watchdog' => FALSE));
+    $this->drupalGet('admin/config/content/mollom/settings', array('watchdog' => WATCHDOG_EMERGENCY));
     $this->assertText(t('The Mollom servers could not be contacted. Please make sure that your web server can make outgoing HTTP requests.'));
 
     // Ensure unreachable servers.
     variable_set('mollom_servers', array('http://fake-host'));
 
     // Verify requirements error about network error.
-    $this->drupalGet('admin/reports/status', array('watchdog' => FALSE));
+    $this->drupalGet('admin/reports/status', array('watchdog' => WATCHDOG_EMERGENCY));
     $this->assertText(t('The Mollom servers could not be contacted. Please make sure that your web server can make outgoing HTTP requests.'));
     $this->assertNoText($this->fallback_message, t('Fallback message not found.'));
 
     // Verify that valid keys work.
-    $this->drupalGet('admin/config/content/mollom/settings', array('watchdog' => FALSE));
+    $this->drupalGet('admin/config/content/mollom/settings', array('watchdog' => WATCHDOG_EMERGENCY));
     $edit = array(
       'mollom_public_key' => MOLLOM_TEST_PUBLIC_KEY,
       'mollom_private_key' => MOLLOM_TEST_PRIVATE_KEY,
@@ -1054,7 +1068,7 @@ class MollomAccessTestCase extends Mollo
       'mollom_public_key' => 'invalid-public-key',
       'mollom_private_key' => 'invalid-private-key',
     );
-    $this->drupalPost(NULL, $edit, t('Save configuration'), array('watchdog' => FALSE));
+    $this->drupalPost(NULL, $edit, t('Save configuration'), array('watchdog' => WATCHDOG_EMERGENCY));
     $this->assertText(t('The configuration options have been saved.'));
     $this->assertText('The configured Mollom API keys are invalid.');
   }
@@ -1166,7 +1180,7 @@ class MollomFallbackTestCase extends Mol
 
     // Check the password request form.
     // @todo Test mail sending with assertMail() now that it is available.
-    $this->drupalGet('user/password', array('watchdog' => FALSE));
+    $this->drupalGet('user/password', array('watchdog' => WATCHDOG_EMERGENCY));
     $this->assertNoCaptchaField();
     $this->assertText($this->fallback_message);
   }
@@ -1189,7 +1203,7 @@ class MollomFallbackTestCase extends Mol
     variable_set('mollom_servers', array('http://fake-host'));
 
     // Check the password request form.
-    $this->drupalGet('user/password', array('watchdog' => FALSE));
+    $this->drupalGet('user/password', array('watchdog' => WATCHDOG_EMERGENCY));
     $this->assertNoCaptchaField();
     $this->assertNoText($this->fallback_message);
   }
@@ -1263,7 +1277,7 @@ class MollomServerListRecoveryTestCase e
 
       $key_is_valid = mollom('mollom.verifyKey');
       $this->assertIdentical($key_is_valid, NETWORK_ERROR, t('The Mollom servers could not be contacted.'));
-      $this->assertMollomWatchdogMessages(FALSE);
+      $this->assertMollomWatchdogMessages(WATCHDOG_EMERGENCY);
 
       $key_is_valid = mollom('mollom.verifyKey');
       $this->assertIdentical($key_is_valid, TRUE, t('The Mollom servers could be contacted.'));
@@ -1457,7 +1471,7 @@ class MollomBlacklistTestCase extends Mo
       'context' => 'everything',
       'reason' => 'spam',
     ));
-    $this->assertMollomWatchdogMessages(FALSE);
+    $this->assertMollomWatchdogMessages(WATCHDOG_EMERGENCY);
     $this->assertNotIdentical($result, TRUE, t('Error response for a non-existing blacklist text found.'));
   }
 
@@ -2423,7 +2437,7 @@ class MollomResellerTestCase extends Mol
     // Retrieve information about a non-existing site:
     $details = mollom('mollom.getSite', array('client_key' => 'bogus'));
     $this->assertEqual(xmlrpc_errno(), TRUE, t('Retrieving information from a non-existing site returned an XML-RPC error.'));
-    $this->assertMollomWatchdogMessages(FALSE);
+    $this->assertMollomWatchdogMessages(WATCHDOG_EMERGENCY);
 
     // Verify that all sites have been deleted:
     $sites = mollom('mollom.listSites');
