assertEqual($prefix.$shouldbe.$suffix, spamspan($prefix.$original.$suffix, "") ); } function testNoEmail() { // test that strings without emails a passed unchanged $noemails = array( 'no email here', 'oneword', '', 'notan@email', 'notan@email either', 'some text and notan.email@something here', ); while ($text = each($noemails)) { $this->assertEqual(spamspan($text, ""), $text); } } 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' => 'user [at] example [dot] com', 'user@example.co.uk' => 'user [at] example [dot] co [dot] uk', 'user@example.museum' => 'user [at] example [dot] museum', 'user.user@example.com' => 'user [dot] user [at] example [dot] com', 'user\'user@example.com' => 'user\'user [at] example [dot] com', 'user-user@example.com' => 'user-user [at] example [dot] com', 'user_user@example.com' => 'user_user [at] example [dot] com', 'user+user@example.com' => 'user+user [at] example [dot] com', ); 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("

","

",$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("

","

",$original,$shouldbe); } print "Test for email with preceding tag, and no closing tag\n"; foreach ($emails as $original => $shouldbe) { $this->checkEmail("
",". 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); } } function testMailto() { $this->assertEqual(spamspan_convertmailto(""), "email@example.com"); $this->assertEqual(spamspan_convertmailto(""), ""); $this->assertEqual(spamspan_convertmailto("some texttext"), "email@example.comtext"); $this->assertEqual(spamspan_convertmailto(""), "email@example.com"); $this->assertEqual(spamspan_convertmailto(""), "email@example.com"); $this->assertEqual(spamspan_convertmailto('some text'), "email@example.com"); // ignore parameters $this->assertEqual(spamspan_convertmailto('some text'), "email@example.com"); // allow nested tags $this->assertEqual(spamspan_convertmailto('some text'), "email@example.com"); } } // set up a dummy function, because variable_get is not available outside drupal function variable_get($one, $two) { return $two; } $test = &new Main(); $test->run(new TextReporter()); ?>