[ticket/17422] Add author_id search tests

PHPBB-17422
This commit is contained in:
rxu 2024-10-31 00:51:05 +07:00
parent be52902541
commit eeede1ab6c
No known key found for this signature in database
GPG key ID: 955F0567380E586A
2 changed files with 37 additions and 2 deletions

View file

@ -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,16 @@ 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'))
$searchforauthoruser_name = 'searchforauthoruser';
$searchforauthoruser_id = null; // if the user exists, array with user_id will be returned
if (!$this->user_exists($searchforauthoruser_name, $searchforauthoruser_id))
{
$searchforauthoruser_id = $this->create_user('searchforauthoruser');
}
else
{
$searchforauthoruser_id = (int) $searchforauthoruser_id[0];
}
$this->remove_user_group('NEWLY_REGISTERED', ['searchforauthoruser']);
$this->set_flood_interval(0);
$this->login('searchforauthoruser');
@ -161,6 +191,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

@ -1525,7 +1525,7 @@ class phpbb_functional_test_case extends phpbb_test_case
*
* @return bool Returns true if a user exists, false otherwise
*/
protected function user_exists($username, $user_id = null)
protected function user_exists(&$username, &$user_id = null)
{
global $db;