diff -u -r1.1.2.6 troll.test
--- troll.test	24 Apr 2009 18:30:40 -0000	1.1.2.6
+++ troll.test	14 Dec 2009 02:01:10 -0000
@@ -181,3 +181,74 @@
   }
 
 }
+
+/**
+ * Verify blocked IP address are redirected to blocked.html and request is
+ * logged.
+ */
+class TrollBlockWebTestCase extends DrupalWebTestCase {
+
+  public static function getInfo() {
+    return array(
+      'name'        => 'Troll IP address blocking',
+      'description' => "Test the Troll blocking functionality.",
+      'group'       => 'Troll'
+    );
+  }
+
+  function setUp() {
+    parent::setUp('troll', 'dblog');
+  }
+
+  function tearDown() {
+    parent::tearDown();
+  }
+
+  /**
+   * Make a regular blocking test.
+   */
+  function testTrollBlocking() {
+    $this->dotestTrollBlocking();
+  }
+
+  /**
+   * Enable dblog on bootstrap and do blocking test again.
+   */
+  function testTrickyTrollBlocking() {
+    db_query("UPDATE {system} SET  bootstrap =  '1' WHERE  filename = 'modules/dblog/dblog.module' LIMIT 1");
+    $this->dotestTrollBlocking();
+  }
+
+  /**
+   * Add a ban for 127.0.0.1 ip address and request a page. Verify Access denied
+   * content and url
+   */
+  function dotestTrollBlocking() {
+    // Create and log in a troll admin user.
+    $permissions = array(
+      'administer troll',
+      'administer site configuration'
+    );
+    $priv_user = $this->drupalCreateUser($permissions);
+    $this->drupalLogin($priv_user);
+
+    // Submit a ban request for localhost.
+    $ban = array(
+      'ip_address' => '127.0.0.1'
+    );
+    $result = $this->drupalPost('admin/user/troll/ip_ban', $ban, t('Ban IP'));
+
+    // Perform a page request now that we are banned, verify we get block page.
+    $result = $this->drupalGet('');
+    $this->assertTrue(strpos($this->getUrl(), 'blocked.html'), t('Found troll blocked page.'));
+
+    // Get last entry from dblog and check it is a troll message.
+    $result = db_fetch_object(db_query("SELECT * FROM {watchdog} WHERE type = 'troll' ORDER BY wid DESC LIMIT 1"));
+    if (isset($result->message)) {
+      $this->assertEqual($result->message, t('IP Ban: @addr Domain: @domain'), t("Watchdog message found."));
+    } else {
+      $this->fail(t('Troll watchdog message was not found.'));
+    }
+  }
+
+}

