diff options
author | Joel Uckelman <uckelman@nomic.net> | 2012-02-27 03:07:24 +0100 |
---|---|---|
committer | Joel Uckelman <uckelman@nomic.net> | 2012-02-27 03:07:24 +0100 |
commit | a6c7607d5882fb0de7d23791b11c69f2fca04aa4 (patch) | |
tree | 85eff25d4a110e7d9a0d8b2d64a903970ffc6127 | |
parent | a814b48061ffc23701ca56ecfbaebf2f8ca61468 (diff) |
build_email_subject passes tests now.
-rw-r--r-- | src/build_email.php | 15 | ||||
-rw-r--r-- | test/build_email_test.php | 19 |
2 files changed, 32 insertions, 2 deletions
diff --git a/src/build_email.php b/src/build_email.php index 41344ca..cad2968 100644 --- a/src/build_email.php +++ b/src/build_email.php @@ -97,6 +97,21 @@ function build_from($name, $email) { return sprintf('%s <%s>', $qname, $email); } +function build_email_subject($forumtag, $reply, $subject) { + $subject = trim($subject); + if ($subject == '') { + $subject = '(no subject)'; + } + + $subject = $forumtag . ' ' . $subject; + + if ($reply) { + $subject = 'Re: ' . $subject; + } + + return utf8_quote_non_ascii($subject); +} + function build_headers($userName, $userEmail, $to, $sender, $subject, $edit, $time, $messageId, $forumURL, $inReplyTo, $references) { diff --git a/test/build_email_test.php b/test/build_email_test.php index d441627..ae88388 100644 --- a/test/build_email_test.php +++ b/test/build_email_test.php @@ -1,7 +1,5 @@ <?php -require_once('PHPUnit/Framework.php'); - require_once(__DIR__ . '/../src/build_email.php'); class build_email_test extends PHPUnit_Framework_TestCase { @@ -53,6 +51,23 @@ http://www.example.com/viewtopic.php?p=42#p42", ); } + /** @dataProvider build_email_subject_data */ + public function test_build_email_subject($ftag, $re, $subject, $expected) { + $this->assertEquals( + $expected, + build_email_subject($ftag, $re, $subject) + ); + } + + public function build_email_subject_data() { + return array( + array('[f]', false, '', '[f] (no subject)'), + array('[f]', true, '', 'Re: [f] (no subject)'), + array('[f]', false, 'Subject', '[f] Subject'), + array('[f]', true, 'Subject', 'Re: [f] Subject'), + ); + } + protected $default_headers = array( 'To' => 'messages@vassalengine.org', 'From' => 'Joel Uckelman <uckelman@nomic.net>', |