From 151c05e92eb5814d492f4739ccf636e7bca4701f Mon Sep 17 00:00:00 2001 From: Cesar G Date: Mon, 3 Feb 2014 12:28:58 -0800 Subject: [PATCH 1/2] [ticket/12158] The pagination start value should be 0 when there are no items. PHPBB3-12158 --- phpBB/phpbb/pagination.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpBB/phpbb/pagination.php b/phpBB/phpbb/pagination.php index 467dc2157f..276351d6a7 100644 --- a/phpBB/phpbb/pagination.php +++ b/phpBB/phpbb/pagination.php @@ -262,7 +262,7 @@ class pagination { if ($start < 0 || $start >= $num_items) { - return ($start < 0) ? 0 : floor(($num_items - 1) / $per_page) * $per_page; + return ($start < 0 || $num_items <= 0) ? 0 : floor(($num_items - 1) / $per_page) * $per_page; } return $start; From 5e1db72532aa58991a9c1d7ddba6bc5dd45ae93c Mon Sep 17 00:00:00 2001 From: Cesar G Date: Mon, 3 Feb 2014 12:29:40 -0800 Subject: [PATCH 2/2] [ticket/12158] Add test data for 0 items to validate_start() test. PHPBB3-12158 --- tests/pagination/pagination_test.php | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/tests/pagination/pagination_test.php b/tests/pagination/pagination_test.php index 4e8083b47f..a96466347c 100644 --- a/tests/pagination/pagination_test.php +++ b/tests/pagination/pagination_test.php @@ -155,24 +155,39 @@ class phpbb_pagination_pagination_test extends phpbb_template_template_test_case public function validate_start_data() { return array( + array( + 0, + 0, + 0, + ), array( -1, + 20, + 0, + ), + array( + 20, + -30, 0, ), array( 0, + 20, 0, ), array( 10, + 20, 10, ), array( + 20, 20, 10, ), array( 30, + 20, 10, ), ); @@ -181,9 +196,9 @@ class phpbb_pagination_pagination_test extends phpbb_template_template_test_case /** * @dataProvider validate_start_data */ - public function test_validate_start($start, $expect) + public function test_validate_start($start, $num_items, $expect) { - $this->assertEquals($expect, $this->pagination->validate_start($start, 10, 20)); + $this->assertEquals($expect, $this->pagination->validate_start($start, 10, $num_items)); } public function reverse_start_data()