1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-08-12 03:34:04 +02:00

[ticket/16902] Extend test

PHPBB3-16902
This commit is contained in:
rxu
2021-10-31 18:50:35 +07:00
parent e7c81cd1a6
commit 015c9313a7
2 changed files with 166 additions and 16 deletions

View File

@@ -16,25 +16,37 @@
*/
abstract class phpbb_functional_search_base extends phpbb_functional_test_case
{
protected function assert_search_found($keywords, $posts_found, $words_highlighted)
protected function assert_search_found($keywords, $posts_found, $words_highlighted, $sort_key = '')
{
$this->purge_cache();
$crawler = self::request('GET', 'search.php?keywords=' . $keywords);
$crawler = self::request('GET', 'search.php?keywords=' . $keywords . ($sort_key ? "&sk=$sort_key" : ''));
$this->assertEquals($posts_found, $crawler->filter('.postbody')->count(), $this->search_backend);
$this->assertEquals($words_highlighted, $crawler->filter('.posthilit')->count(), $this->search_backend);
$this->assertStringContainsString("Search found $posts_found match", $crawler->filter('.searchresults-title')->text(), $this->search_backend);
}
protected function assert_search_found_topics($keywords, $topics_found)
protected function assert_search_found_topics($keywords, $topics_found, $sort_key = '')
{
$this->purge_cache();
$crawler = self::request('GET', 'search.php?sr=topics&keywords=' . $keywords);
$html = '';
foreach ($crawler as $domElement) {
$html .= $domElement->ownerDocument->saveHTML($domElement);
}
$this->assertEquals($topics_found, $crawler->filter('.row')->count(), $html);
$this->assertStringContainsString("Search found $topics_found match", $crawler->filter('.searchresults-title')->text(), $html);
$crawler = self::request('GET', 'search.php?sr=topics&keywords=' . $keywords . ($sort_key ? "&sk=$sort_key" : ''));
$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_posts_by_author($author, $posts_found, $sort_key = '')
{
$this->purge_cache();
$crawler = self::request('GET', 'search.php?author=' . $author . ($sort_key ? "&sk=$sort_key" : ''));
$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($author, $topics_found, $sort_key = '')
{
$this->purge_cache();
$crawler = self::request('GET', 'search.php?sr=topics&author=' . $author . ($sort_key ? "&sk=$sort_key" : ''));
$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_not_found($keywords)
@@ -45,8 +57,27 @@ abstract class phpbb_functional_search_base extends phpbb_functional_test_case
$this->assertEquals($split_keywords_string, $crawler->filter('#keywords')->attr('value'), $this->search_backend);
}
protected function assert_search_for_author_not_found($author)
{
$this->add_lang('search');
$crawler = self::request('GET', 'search.php?author=' . $author);
$this->assertContainsLang('NO_SEARCH_RESULTS', $crawler->text(), $this->search_backend);
}
public function test_search_backend()
{
// Create a new standard user if needed, topic and post to test searh for author
if (!$this->user_exists('searchforauthoruser'))
{
$searchforauthoruser_id = $this->create_user('searchforauthoruser');
}
$this->remove_user_group('NEWLY_REGISTERED', ['searchforauthoruser']);
$this->disable_flood_interval();
$this->login('searchforauthoruser');
$topic_by_author = $this->create_topic(2, 'Test Topic from searchforauthoruser', 'This is a test topic posted by searchforauthoruser to test searching by author.');
$this->create_post(2, $topic_by_author['topic_id'], 'Re: Test Topic from searchforauthoruser', 'This is a test post posted by searchforauthoruser');
$this->logout();
$this->login();
$this->admin_login();
@@ -54,6 +85,7 @@ abstract class phpbb_functional_search_base extends phpbb_functional_test_case
$post = $this->create_topic(2, 'Test Topic 1 foosubject', 'This is a test topic posted by the barsearch testing framework.');
$crawler = self::request('GET', 'adm/index.php?i=acp_search&mode=settings&sid=' . $this->sid);
$form = $crawler->selectButton('Submit')->form();
$values = $form->getValues();
@@ -72,6 +104,7 @@ abstract class phpbb_functional_search_base extends phpbb_functional_test_case
if ($crawler->filter('.errorbox')->count() > 0)
{
$this->delete_topic($post['topic_id']);
$this->delete_topic($topic_by_author['topic_id']);
$this->markTestSkipped("Search backend is not supported/running");
}
@@ -79,20 +112,29 @@ abstract class phpbb_functional_search_base extends phpbb_functional_test_case
}
$this->logout();
$this->assert_search_found('phpbb3+installation', 1, 3);
$this->assert_search_found('foosubject+barsearch', 1, 2);
$this->assert_search_found_topics('phpbb3+installation', 1);
$this->assert_search_found_topics('foosubject+barsearch', 1);
foreach (['', 'a', 't', 'f', 'i', 's'] as $sort_key)
{
$this->assert_search_found('phpbb3+installation', 1, 3, $sort_key);
$this->assert_search_found('foosubject+barsearch', 1, 2, $sort_key);
$this->assert_search_found('barsearch-testing', 1, 2, $sort_key); // test hyphen ignored
$this->assert_search_found('barsearch+-+testing', 1, 2, $sort_key); // test hyphen wrapped with space ignored
$this->assert_search_found_topics('phpbb3+installation', 1, $sort_key);
$this->assert_search_found_topics('foosubject+barsearch', 1, $sort_key);
$this->assert_search_posts_by_author('searchforauthoruser', 2, $sort_key);
$this->assert_search_topics_by_author('searchforauthoruser', 1, $sort_key);
}
$this->assert_search_not_found('loremipsumdedo');
$this->assert_search_found('barsearch-testing', 1, 2); // test hyphen ignored
$this->assert_search_found('barsearch+-+testing', 1, 2); // test hyphen wrapped with space ignored
$this->assert_search_not_found('barsearch+-testing'); // test excluding keyword
$this->assert_search_for_author_not_found('authornotexists');
$this->login();
$this->admin_login();
$this->delete_search_index();
$this->delete_topic($post['topic_id']);
$this->delete_topic($topic_by_author['topic_id']);
}
protected function create_search_index($backend = null)