diff --git a/portal/fetch_posts.php b/portal/fetch_posts.php index fd22bbf9..b5d5d24e 100644 --- a/portal/fetch_posts.php +++ b/portal/fetch_posts.php @@ -321,8 +321,8 @@ class fetch_posts 'icon_id' => $row['icon_id'], 'topic_status' => $row['topic_status'], 'forum_id' => $row['forum_id'], - 'topic_replies' => $row['topic_posts_approved'] + $row['topic_posts_unapproved'] + $row['topic_posts_softdeleted'], - 'topic_replies_real' => $row['topic_posts_approved'], + 'topic_replies' => $row['topic_posts_approved'] + $row['topic_posts_unapproved'] + $row['topic_posts_softdeleted'] - 1, + 'topic_replies_real' => $row['topic_posts_approved'] - 1, 'topic_time' => $this->user->format_date($row['post_time']), 'topic_last_post_time' => $row['topic_last_post_time'], 'topic_title' => $row['topic_title'], diff --git a/tests/unit/functions/fetch_news_test.php b/tests/unit/functions/fetch_news_test.php index 30cc04ba..434a267b 100644 --- a/tests/unit/functions/fetch_news_test.php +++ b/tests/unit/functions/fetch_news_test.php @@ -264,4 +264,12 @@ class phpbb_functions_fetch_news_test extends \board3\portal\tests\testframework $fetch_posts = phpbb_fetch_posts(5, '2', true, 5, 150, time(), 'announcements'); $this->assertSame(array(), $fetch_posts); } + + public function test_number_replies() + { + $fetch_posts = phpbb_fetch_posts(5, '', false, 5, 150, time(), 'news'); + // Topic has 2 posts which means there is only one reply + $this->assertEquals(1, $fetch_posts[0]['topic_replies']); + $this->assertEquals(1, $fetch_posts[0]['topic_replies_real']); + } } diff --git a/tests/unit/portal/fetch_posts_test.php b/tests/unit/portal/fetch_posts_test.php index 48ec0ce1..ef04a258 100644 --- a/tests/unit/portal/fetch_posts_test.php +++ b/tests/unit/portal/fetch_posts_test.php @@ -266,4 +266,13 @@ class phpbb_portal_fetch_posts_test extends \board3\portal\tests\testframework\d $fetch_posts = $this->fetch_posts->get_posts('2', true, 5, 150, time(), 'announcements'); $this->assertSame(array(), $fetch_posts); } + + public function test_number_replies() + { + $this->fetch_posts->set_module_id(5); + $fetch_posts = $this->fetch_posts->get_posts('', false, 5, 150, time(), 'news'); + // Topic has 2 posts which means there is only one reply + $this->assertEquals(1, $fetch_posts[0]['topic_replies']); + $this->assertEquals(1, $fetch_posts[0]['topic_replies_real']); + } }