You are here

function Main::testEmail in SpamSpan filter 5

File

test/spamspan_test.inc, line 33

Class

Main

Code

function testEmail() {

  // check that emails in odd places are properly converted
  // 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>',
  );
  print "Test for bare email\n";
  foreach ($emails as $original => $shouldbe) {
    $this
      ->checkEmail("", "", $original, $shouldbe);
  }
  print "Test for email with text at the start\n";
  foreach ($emails as $original => $shouldbe) {
    $this
      ->checkEmail("some text here ", "", $original, $shouldbe);
  }
  print "Test for email with text at the end\n";
  foreach ($emails as $original => $shouldbe) {
    $this
      ->checkEmail("", " some text here", $original, $shouldbe);
  }
  print "Test for email with text at the start and end\n";
  foreach ($emails as $original => $shouldbe) {
    $this
      ->checkEmail("some text here ", " some text here", $original, $shouldbe);
  }
  print "Test for email with tags at the start and end\n";
  foreach ($emails as $original => $shouldbe) {
    $this
      ->checkEmail("<p>", "</p>", $original, $shouldbe);
  }
  print "Test for email with trailing commas\n";
  foreach ($emails as $original => $shouldbe) {
    $this
      ->checkEmail("some text here. ", ", Next sentence", $original, $shouldbe);
  }
  print "Test for email with trailing full stop\n";
  foreach ($emails as $original => $shouldbe) {
    $this
      ->checkEmail("some text here. ", ". Next sentence", $original, $shouldbe);
  }
  print "Test for email with preceding tag\n";
  foreach ($emails as $original => $shouldbe) {
    $this
      ->checkEmail("<p>", "</p>", $original, $shouldbe);
  }
  print "Test for email with preceding tag, and no closing tag\n";
  foreach ($emails as $original => $shouldbe) {
    $this
      ->checkEmail("<dt>", ". no tag here", $original, $shouldbe);
  }
  print "Test for brackets\n";
  foreach ($emails as $original => $shouldbe) {
    $this
      ->checkEmail("(", ")", $original, $shouldbe);
  }
  print "Test for angle brackets\n";
  foreach ($emails as $original => $shouldbe) {
    $this
      ->checkEmail("<", ">", $original, $shouldbe);
  }
  print "Test for newlines\n";
  foreach ($emails as $original => $shouldbe) {
    $this
      ->checkEmail("\n", "\n", $original, $shouldbe);
  }
  print "Test for spaces\n";
  foreach ($emails as $original => $shouldbe) {
    $this
      ->checkEmail(" ", " ", $original, $shouldbe);
  }
}