mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-07 20:08:53 +00:00
Merge pull request #6744 from rxu/ticket/17422
[ticket/17422] Fix search results sorting - 3.3.x
This commit is contained in:
commit
c7e68fb572
3 changed files with 41 additions and 18 deletions
|
@ -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;
|
||||
|
|
|
@ -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');
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue