diff options
-rw-r--r-- | src/PhpBB3Impl.php | 2 | ||||
-rw-r--r-- | src/build_post.php | 6 | ||||
-rw-r--r-- | test/build_postTest.php | 70 |
3 files changed, 52 insertions, 26 deletions
diff --git a/src/PhpBB3Impl.php b/src/PhpBB3Impl.php index 59f052f..7e8595a 100644 --- a/src/PhpBB3Impl.php +++ b/src/PhpBB3Impl.php @@ -206,7 +206,7 @@ class PhpBB3Impl implements PhpBB3 { $listTag = '[messages]'; $forumName = $this->getForumName($forumId); $forumTag = '[' . html_entity_decode($forumName, ENT_QUOTES) . ']'; - $subject = build_post_subject($listTag, $forumTag, $subject); + $subject = build_post_subject($listTag, $forumTag, $subject, $postType == 'reply'); list($message, $attachments) = $msg->getFlattenedParts(); diff --git a/src/build_post.php b/src/build_post.php index 9039dcb..d889b92 100644 --- a/src/build_post.php +++ b/src/build_post.php @@ -1,6 +1,6 @@ <?php -function build_post_subject($listtag, $forumtag, $subject) { +function build_post_subject($listtag, $forumtag, $subject, $reply) { // strip the '[list]' and '[forum]' tags $tagpat = '/(' . preg_quote($listtag, '/') . '|' . preg_quote($forumtag, '/') . ')\\s*/'; @@ -18,6 +18,10 @@ function build_post_subject($listtag, $forumtag, $subject) { $subject = '(no subject)'; } + if ($reply) { + $subject = 'Re: ' . $subject; + } + return $subject; } diff --git a/test/build_postTest.php b/test/build_postTest.php index be542dd..5e8017e 100644 --- a/test/build_postTest.php +++ b/test/build_postTest.php @@ -5,37 +5,59 @@ require_once(__DIR__ . '/../src/build_post.php'); class build_post_test extends PHPUnit_Framework_TestCase { /** @dataProvider build_post_subject_data */ - public function test_build_post_subject($ltag, $ftag, $subject, $expected) { + public function test_build_post_subject($ltag, $ftag, $subject, $reply, $expected) { $this->assertEquals( $expected, - build_post_subject($ltag, $ftag, $subject) + build_post_subject($ltag, $ftag, $subject, $reply) ); } public function build_post_subject_data() { return array( - array('[l]', '[f]', '', '(no subject)'), - array('[l]', '[f]', 'Re:', '(no subject)'), - array('[l]', '[f]', 'Subject', 'Subject'), - array('[l]', '[f]', 'Re: Subject', 'Subject'), - array('[l]', '[f]', 'Re: Re: Re: Subject', 'Subject'), - array('[l]', '[f]', '[f] Subject', 'Subject'), - array('[l]', '[f]', '[f] [f] Subject', 'Subject'), - array('[l]', '[f]', '[f] [f] Subject [f]', 'Subject'), - array('[l]', '[f]', '[l] [f] Re: Subject', 'Subject'), - array('[l]', '[f]', 'Re: [l] [f] Subject', 'Subject'), - array('[l]', '[f]', 'Re: Subject [l][f] Subject', 'Subject Subject'), - array('[l]', '[f]', 'Edit:', '(no subject)'), - array('[l]', '[f]', 'Edit: Re:', '(no subject)'), - array('[l]', '[f]', 'Edit: Subject', 'Subject'), - array('[l]', '[f]', 'Edit: Re: Subject', 'Subject'), - array('[l]', '[f]', 'Edit: Re: Re: Re: Subject', 'Subject'), - array('[l]', '[f]', 'Edit: [f] Subject', 'Subject'), - array('[l]', '[f]', 'Edit: [f] [f] Subject', 'Subject'), - array('[l]', '[f]', 'Edit: [f] [f] Subject [f]', 'Subject'), - array('[l]', '[f]', '[l] [f] Edit: Re: Subject', 'Subject'), - array('[l]', '[f]', 'Edit: Re: [l] [f] Subject', 'Subject'), - array('[l]', '[f]', 'Edit: Re: Subject [l][f] Subject', 'Subject Subject') + array('[l]', '[f]', '', false, '(no subject)'), + array('[l]', '[f]', 'Re:', false, '(no subject)'), + array('[l]', '[f]', 'Subject', false, 'Subject'), + array('[l]', '[f]', 'Re: Subject', false, 'Subject'), + array('[l]', '[f]', 'Re: Re: Re: Subject', false, 'Subject'), + array('[l]', '[f]', '[f] Subject', false, 'Subject'), + array('[l]', '[f]', '[f] [f] Subject', false, 'Subject'), + array('[l]', '[f]', '[f] [f] Subject [f]', false, 'Subject'), + array('[l]', '[f]', '[l] [f] Re: Subject', false, 'Subject'), + array('[l]', '[f]', 'Re: [l] [f] Subject', false, 'Subject'), + array('[l]', '[f]', 'Re: Subject [l][f] Subject', false, 'Subject Subject'), + array('[l]', '[f]', 'Edit:', false, '(no subject)'), + array('[l]', '[f]', 'Edit: Re:', false, '(no subject)'), + array('[l]', '[f]', 'Edit: Subject', false, 'Subject'), + array('[l]', '[f]', 'Edit: Re: Subject', false, 'Subject'), + array('[l]', '[f]', 'Edit: Re: Re: Re: Subject', false, 'Subject'), + array('[l]', '[f]', 'Edit: [f] Subject', false, 'Subject'), + array('[l]', '[f]', 'Edit: [f] [f] Subject', false, 'Subject'), + array('[l]', '[f]', 'Edit: [f] [f] Subject [f]', false, 'Subject'), + array('[l]', '[f]', '[l] [f] Edit: Re: Subject', false, 'Subject'), + array('[l]', '[f]', 'Edit: Re: [l] [f] Subject', false, 'Subject'), + array('[l]', '[f]', 'Edit: Re: Subject [l][f] Subject', false, 'Subject Subject'), + array('[l]', '[f]', '', true, 'Re: (no subject)'), + array('[l]', '[f]', 'Re:', true, 'Re: (no subject)'), + array('[l]', '[f]', 'Subject', true, 'Re: Subject'), + array('[l]', '[f]', 'Re: Subject', true, 'Re: Subject'), + array('[l]', '[f]', 'Re: Re: Re: Subject', true, 'Re: Subject'), + array('[l]', '[f]', '[f] Subject', true, 'Re: Subject'), + array('[l]', '[f]', '[f] [f] Subject', true, 'Re: Subject'), + array('[l]', '[f]', '[f] [f] Subject [f]', true, 'Re: Subject'), + array('[l]', '[f]', '[l] [f] Re: Subject', true, 'Re: Subject'), + array('[l]', '[f]', 'Re: [l] [f] Subject', true, 'Re: Subject'), + array('[l]', '[f]', 'Re: Subject [l][f] Subject', true, 'Re: Subject Subject'), + array('[l]', '[f]', 'Edit:', true, 'Re: (no subject)'), + array('[l]', '[f]', 'Edit: Re:', true, 'Re: (no subject)'), + array('[l]', '[f]', 'Edit: Subject', true, 'Re: Subject'), + array('[l]', '[f]', 'Edit: Re: Subject', true, 'Re: Subject'), + array('[l]', '[f]', 'Edit: Re: Re: Re: Subject', true, 'Re: Subject'), + array('[l]', '[f]', 'Edit: [f] Subject', true, 'Re: Subject'), + array('[l]', '[f]', 'Edit: [f] [f] Subject', true, 'Re: Subject'), + array('[l]', '[f]', 'Edit: [f] [f] Subject [f]', true, 'Re: Subject'), + array('[l]', '[f]', '[l] [f] Edit: Re: Subject', true, 'Re: Subject'), + array('[l]', '[f]', 'Edit: Re: [l] [f] Subject', true, 'Re: Subject'), + array('[l]', '[f]', 'Edit: Re: Subject [l][f] Subject', true, 'Re: Subject Subject') ); } } |