Merge branch 'ticket/17422' into ticket/17422-master

This commit is contained in:
rxu 2024-10-31 15:08:08 +07:00
commit 43de83b339
No known key found for this signature in database
GPG key ID: 8117904FEDEFDD17
3 changed files with 41 additions and 18 deletions

View file

@ -112,17 +112,10 @@ abstract class base implements search_backend_interface
}
}
// change the start to the actual end of the current request if the sort direction differs
// from the direction 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 self::SEARCH_RESULT_NOT_IN_CACHE;
}
$stored_ids = array_reverse($stored_ids);
}
for ($i = $start, $n = $start + $per_page; ($i < $n) && ($i < $result_count); $i++)
@ -138,11 +131,6 @@ abstract class base implements search_backend_interface
}
unset($stored_ids);
if ($reverse_ids)
{
$id_ary = array_reverse($id_ary);
}
if (!$complete)
{
return self::SEARCH_RESULT_INCOMPLETE;

View file

@ -51,6 +51,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();
@ -95,10 +119,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');
@ -180,6 +208,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');

View file

@ -1567,9 +1567,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;
@ -1584,6 +1584,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;
}
}