Index: tests/mollom.test
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/mollom/tests/mollom.test,v
retrieving revision 1.3
diff -u -r1.3 mollom.test
--- tests/mollom.test	21 Dec 2009 20:24:22 -0000	1.3
+++ tests/mollom.test	22 Dec 2009 11:43:36 -0000
@@ -680,6 +680,106 @@
   }
 }
 
+class MollomBlackListTestCase extends MollomWebTestCase {
+  public static function getInfo() {
+    return array(
+      'name' => 'Blacklisting',
+      'description' => 'Check that the URL and text blacklist functionality works.',
+      'group' => 'Mollom',
+    );
+  }
+
+  /**
+   * Test the URL blacklist functionality at the API level without using a web interface.
+   */
+  function testUrlBlackListAPI() {
+	// Blacklist an URL:
+    mollom('mollom.addBlacklistURL', array(
+	  'url' => 'http://unicorn.com'));
+
+    // Check whether posts containing the blacklisted URL are properly blocked.  
+    $result = mollom('mollom.checkContent', array(
+      'post_body' => "When the exact URL is present, the post should get blocked: http://unicorn.com"));
+    $this->assertEqual($result['spam'], MOLLOM_ANALYSIS_SPAM, t('The message was blocked.'));
+
+    $result = mollom('mollom.checkContent', array(
+      'post_body' => "When the URL is expanded in the back, the post should get blocked: http://unicorn.com/oh-my"));
+    $this->assertEqual($result['spam'], MOLLOM_ANALYSIS_SPAM, t('The message was blocked.'));
+
+    $result = mollom('mollom.checkContent', array(
+      'post_body' => "When the URL is expanded in the front, the post should get blocked: http://www.unicorn.com"));
+    $this->assertEqual($result['spam'], MOLLOM_ANALYSIS_SPAM, t('The message was blocked.'));
+
+    $result = mollom('mollom.checkContent', array(
+      'post_body' => "When the URL has a different schema, the post should get blocked: ftp://www.unicorn.com"));
+    $this->assertEqual($result['spam'], MOLLOM_ANALYSIS_SPAM, t('The message was blocked.'));
+
+    // Validate that there is one entry.
+    $blacklist = mollom('mollom.listBlacklistURL');
+    $this->assertEqual(count($blacklist), 1, t('The server-side blacklist has one entry.'));
+
+    // Although we only one element, we're using a loop because we want to 
+    // reset the blacklist in case it got somehow polluted.
+    foreach ($blacklist as $entry) {
+      $result = mollom('mollom.removeBlacklistURL', array('url' => $entry['url']));
+      $this->assertTrue($result, t('The blacklisted URL was removed.'));
+    }
+
+    // Retrieve the blacklist again, and make sure it is empty.
+    $blacklist = mollom('mollom.listBlacklistURL');
+    $this->assertEqual(count($blacklist), 0, t('The server-side blacklist is empty.'));
+  }
+
+  /**
+   * Test the text blacklist functionality at the API level without using a web interface.
+   */
+  function testTextBlackListAPI() {
+	// Blacklist a word:
+    mollom('mollom.addBlacklistText', array(
+	  'text' => 'unicorn',
+	  'match' => 'contains',
+	  'reason' => 'spam',
+	  'language' => 'en'));
+
+    // Check whether posts containing the blacklisted URL are properly 
+    // blocked. 
+    $result = mollom('mollom.checkContent', array(
+      'post_body' => "When the text is present, the post should get blocked: unicorn"));
+    $this->assertEqual($result['spam'], MOLLOM_ANALYSIS_SPAM, t('The message was blocked.'));
+
+    $result = mollom('mollom.checkContent', array(
+      'post_body' => "When match is 'contains', the word can be surrounded by other text: abcunicorndef"));
+    $this->assertEqual($result['spam'], MOLLOM_ANALYSIS_SPAM, t('The message was blocked.'));
+
+	// To update the work (i.e. to change the 'match' property), we simply 
+	// overwrite it.
+    mollom('mollom.addBlacklistText', array(
+	  'text' => 'unicorn',
+	  'match' => 'exact',
+	  'reason' => 'spam',
+	  'language' => 'en'));
+
+    $result = mollom('mollom.checkContent', array(
+      'post_body' => "When match is 'exact', it has to be exact: abcunicorndef"));
+    $this->assertNotEqual($result['spam'], MOLLOM_ANALYSIS_SPAM, t('The message was not blocked.'));
+	
+    // Validate that there is one entry.
+    $blacklist = mollom('mollom.listBlacklistText');
+    $this->assertEqual(count($blacklist), 1, t('The server-side blacklist has one entry.'));
+
+    // Although we only one element, we're using a loop because we want to 
+    // reset the blacklist in case it got somehow polluted.
+    foreach ($blacklist as $entry) {
+      $result = mollom('mollom.removeBlacklistText', array('text' => $entry['text']));
+      $this->assertTrue($result, t('The blacklisted text was removed.'));
+    }
+
+    // Retrieve the blacklist again, and make sure it is empty.
+    $blacklist = mollom('mollom.listBlacklistText');
+    $this->assertEqual(count($blacklist), 0, t('The server-side blacklist is empty.'));
+  }
+}
+
 /**
  * Tests Mollom form configuration functionality.
  */
