Blog

SimpleTest 6.x gets e-mail capture!

Written by Metal Toad Staff | Nov 3, 2009 12:00:00 AM


The latest 6.x-2.9 release of SimpleTest includes a backport of the e-mail capture feature from D7. This means you can finally unit test e-mail sending functionality! There is still one bug to be ironed out, but a patch is available.

Here's a simple demo of how it works:

class UserTestCase extends DrupalWebTestCase {
  public static function getInfo() {
    return array(
      'name' => t('User functionality'),
      'description' => t('Test user creation.'),
      'group' => t('User'),
    );
  }
 
  /**
   * Test receiving user welcome e-mail.
   */
  function testUserWelcome() {
    $name = $this->randomName();
    $edit = array(
      'name' => $name,
      'mail' => "$name@example.com",
    );
    $this->drupalPost('user/register', $edit, t('Create new account'));
    $this->assertMail('to', $edit['mail']);
  }
}