diff --git a/phpBB/phpbb/search/base.php b/phpBB/phpbb/search/base.php index e7d0774b6c..e33dfc8f75 100644 --- a/phpBB/phpbb/search/base.php +++ b/phpBB/phpbb/search/base.php @@ -76,17 +76,10 @@ class base } } - // change the start to the actual end of the current request if the sort direction differs - // from the dirction in the cache and reverse the ids later + // If the sort direction differs from the direction in the cache, then reverse the ids array if ($reverse_ids) { - $start = $result_count - $start - $per_page; - - // the user requested a page past the last index - if ($start < 0) - { - return SEARCH_RESULT_NOT_IN_CACHE; - } + $stored_ids = array_reverse($stored_ids); } for ($i = $start, $n = $start + $per_page; ($i < $n) && ($i < $result_count); $i++) @@ -102,11 +95,6 @@ class base } unset($stored_ids); - if ($reverse_ids) - { - $id_ary = array_reverse($id_ary); - } - if (!$complete) { return SEARCH_RESULT_INCOMPLETE; diff --git a/tests/functional/search/base.php b/tests/functional/search/base.php index 0e3aa80fa3..e5ee1feee3 100644 --- a/tests/functional/search/base.php +++ b/tests/functional/search/base.php @@ -49,6 +49,30 @@ abstract class phpbb_functional_search_base extends phpbb_functional_test_case $this->assertStringContainsString("Search found $topics_found match", $crawler->filter('.searchresults-title')->text(), $this->search_backend); } + protected function assert_search_posts_by_author_id($author_id, $posts_found, $sort_key = '', $sort_dir = '') + { + // Test obtaining data from cache if sorting direction is set + if (!$sort_dir) + { + $this->purge_cache(); + } + $crawler = self::request('GET', 'search.php?author_id=' . $author_id . ($sort_key ? "&sk=$sort_key" : '') . ($sort_dir ? "&sk=$sort_dir" : '')); + $this->assertEquals($posts_found, $crawler->filter('.postbody')->count(), $this->search_backend); + $this->assertStringContainsString("Search found $posts_found match", $crawler->filter('.searchresults-title')->text(), $this->search_backend); + } + + protected function assert_search_topics_by_author_id($author_id, $topics_found, $sort_key = '', $sort_dir = '') + { + // Test obtaining data from cache if sorting direction is set + if (!$sort_dir) + { + $this->purge_cache(); + } + $crawler = self::request('GET', 'search.php?sr=topics&author_id=' . $author_id . ($sort_key ? "&sk=$sort_key" : '') . ($sort_dir ? "&sk=$sort_dir" : '')); + $this->assertEquals($topics_found, $crawler->filter('.row')->count(), $this->search_backend); + $this->assertStringContainsString("Search found $topics_found match", $crawler->filter('.searchresults-title')->text(), $this->search_backend); + } + protected function assert_search_in_topic($topic_id, $keywords, $posts_found, $sort_key = '') { $this->purge_cache(); @@ -93,10 +117,14 @@ abstract class phpbb_functional_search_base extends phpbb_functional_test_case $this->add_lang('common'); // Create a new standard user if needed, topic and post to test searh for author - if (!$this->user_exists('searchforauthoruser')) + if (!$searchforauthoruser_id = $this->user_exists('searchforauthoruser')) { $searchforauthoruser_id = $this->create_user('searchforauthoruser'); } + else + { + $searchforauthoruser_id = key($searchforauthoruser_id); + } $this->remove_user_group('NEWLY_REGISTERED', ['searchforauthoruser']); $this->set_flood_interval(0); $this->login('searchforauthoruser'); @@ -161,6 +189,11 @@ abstract class phpbb_functional_search_base extends phpbb_functional_test_case $this->assert_search_posts_by_author('searchforauthoruser', 2, $sort_key); $this->assert_search_topics_by_author('searchforauthoruser', 1, $sort_key); + + $this->assert_search_posts_by_author_id($searchforauthoruser_id, 2, $sort_key); + $this->assert_search_topics_by_author_id($searchforauthoruser_id, 1, $sort_key); + $this->assert_search_posts_by_author_id($searchforauthoruser_id, 2, $sort_key, 'a'); //search asc order + $this->assert_search_topics_by_author_id($searchforauthoruser_id, 1, $sort_key, 'a'); // search asc order } $this->assert_search_not_found('loremipsumdedo'); diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index 9e4cb364d0..6f8bc2d013 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -1523,9 +1523,9 @@ class phpbb_functional_test_case extends phpbb_test_case * @param string $username The username to check or empty if user_id is used * @param int $user_id The user id to check or empty if username is used * - * @return bool Returns true if a user exists, false otherwise + * @return array Returns user_id => username array or empty array if user does not exist */ - protected function user_exists($username, $user_id = null) + protected function user_exists($username = '', $user_id = '') { global $db; @@ -1540,6 +1540,8 @@ class phpbb_functional_test_case extends phpbb_test_case require_once(__DIR__ . '/../../phpBB/includes/functions_user.php'); } - return user_get_id_name($user_id, $username) ? false : true; + user_get_id_name($user_id, $username, false, true); + + return $username; } }