You are here

function SpamSpanBasicTestCase::testSpamSpanEmail in SpamSpan filter 6

Check that emails in odd places are properly converted

Each sub-test is run several times, using a different type of email address each time.

File

./spamspan.test, line 65
Tests for the SpamSpan module

Class

SpamSpanBasicTestCase
@file Tests for the SpamSpan module

Code

function testSpamSpanEmail() {

  // a list of address, together with what they should look like
  $emails = array(
    'user@example.com' => '<span class="spamspan"><span class="u">user</span> [at] <span class="d">example [dot] com</span></span>',
    'user@example.co.uk' => '<span class="spamspan"><span class="u">user</span> [at] <span class="d">example [dot] co [dot] uk</span></span>',
    'user@example.museum' => '<span class="spamspan"><span class="u">user</span> [at] <span class="d">example [dot] museum</span></span>',
    'user.user@example.com' => '<span class="spamspan"><span class="u">user [dot] user</span> [at] <span class="d">example [dot] com</span></span>',
    'user\'user@example.com' => '<span class="spamspan"><span class="u">user\'user</span> [at] <span class="d">example [dot] com</span></span>',
    'user-user@example.com' => '<span class="spamspan"><span class="u">user-user</span> [at] <span class="d">example [dot] com</span></span>',
    'user_user@example.com' => '<span class="spamspan"><span class="u">user_user</span> [at] <span class="d">example [dot] com</span></span>',
    'user+user@example.com' => '<span class="spamspan"><span class="u">user+user</span> [at] <span class="d">example [dot] com</span></span>',
    'user!#$%*+-/=?^_`{|}~user@example.com' => '<span class="spamspan"><span class="u">user!#$%*+-/=?^_`{|}~user</span> [at] <span class="d">example [dot] com</span></span>',
  );
  foreach ($emails as $original => $shouldbe) {
    $this
      ->_checkEmail("", "", $original, $shouldbe, "Test for bare email");
  }

  // Test for email with text at the start
  foreach ($emails as $original => $shouldbe) {
    $this
      ->_checkEmail("some text here ", "", $original, $shouldbe, "Test for email with text at the start");
  }

  // Test for email with text at the end
  foreach ($emails as $original => $shouldbe) {
    $this
      ->_checkEmail("", " some text here", $original, $shouldbe, "Test for email with text at the end");
  }

  // Test for email with text at the start and end
  foreach ($emails as $original => $shouldbe) {
    $this
      ->_checkEmail("some text here ", " some text here", $original, $shouldbe, "Test for email with text at the start and end");
  }

  // Test for email with tags at the start and end
  foreach ($emails as $original => $shouldbe) {
    $this
      ->_checkEmail("<p>", "</p>", $original, $shouldbe, "Test for email with tags at the start and end");
  }

  // Test for email with trailing commas
  foreach ($emails as $original => $shouldbe) {
    $this
      ->_checkEmail("some text here. ", ", Next sentence", $original, $shouldbe, "Test for email with trailing commas");
  }

  // Test for email with trailing full stop
  foreach ($emails as $original => $shouldbe) {
    $this
      ->_checkEmail("some text here. ", ". Next sentence", $original, $shouldbe, "Test for email with trailing full stop");
  }

  // Test for email with preceding tag
  foreach ($emails as $original => $shouldbe) {
    $this
      ->_checkEmail("<p>", "</p>", $original, $shouldbe, "Test for email with preceding tag");
  }

  // Test for email with preceding tag,  and no closing tag
  foreach ($emails as $original => $shouldbe) {
    $this
      ->_checkEmail("<dt>", ". no tag here", $original, $shouldbe, "Test for email with preceding tag,  and no closing tag");
  }

  // Test for brackets
  foreach ($emails as $original => $shouldbe) {
    $this
      ->_checkEmail("(", ")", $original, $shouldbe, "Test for brackets");
  }

  // Test for angle brackets;
  foreach ($emails as $original => $shouldbe) {
    $this
      ->_checkEmail("<", ">", $original, $shouldbe, "Test for angle brackets");
  }

  // Test for newlines
  foreach ($emails as $original => $shouldbe) {
    $this
      ->_checkEmail("\n", "\n", $original, $shouldbe, "Test for newlines");
  }

  // Test for spaces
  foreach ($emails as $original => $shouldbe) {
    $this
      ->_checkEmail(" ", " ", $original, $shouldbe, "Test for spaces");
  }
}