1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-07-31 14:00:31 +02:00

Merge pull request #6352 from rxu/ticket/16902-master

[ticket/16902] Improve search results count - master
This commit is contained in:
Marc Alexander
2022-01-19 20:34:29 +01:00
10 changed files with 199 additions and 119 deletions

View File

@@ -868,24 +868,6 @@ class phpbb_functional_feed_test extends phpbb_functional_test_case
$this->set_flood_interval(15);
}
protected function set_flood_interval($flood_interval)
{
$this->login();
$this->admin_login();
$crawler = self::request('GET', 'adm/index.php?sid=' . $this->sid . '&i=acp_board&mode=post');
$form = $crawler->selectButton('Submit')->form();
$values = $form->getValues();
$values['config[flood_interval]'] = $flood_interval;
$form->setValues($values);
$crawler = self::submit($form);
self::assertGreaterThan(0, $crawler->filter('.successbox')->count());
$this->logout();
}
public function test_feeds_unapproved_topic_admin()
{
$this->load_ids(array(

View File

@@ -22,13 +22,7 @@ class phpbb_functional_mcp_main_test extends phpbb_functional_test_case
$this->login();
$this->admin_login();
// Disable flood interval to post >1 of topics
$crawler = self::request('GET', "adm/index.php?i=acp_board&mode=post&sid={$this->sid}");
$form = $crawler->selectButton($this->lang('SUBMIT'))->form([
'config[flood_interval]' => 0,
]);
$crawler = self::submit($form);
$this->assertContainsLang('CONFIG_UPDATED', $crawler->text());
$this->set_flood_interval(0);
// Create a forum to move topics around
$forum_name = 'MCP Test #1';
@@ -54,6 +48,8 @@ class phpbb_functional_mcp_main_test extends phpbb_functional_test_case
$crawler = self::request('GET', "viewtopic.php?t={$post[1]['topic_id']}&sid={$this->sid}");
$this->assertStringContainsString('Testing merge topics moderation actions from MCP/View forum page.', $crawler->filter('html')->text());
$this->set_flood_interval(15);
return $post;
}

View File

@@ -18,32 +18,80 @@ abstract class phpbb_functional_search_base extends phpbb_functional_test_case
{
protected $search_backend;
protected function assert_search_found($keywords, $posts_found, $words_highlighted)
protected function assert_search_found($keywords, $posts_found, $words_highlighted, $sort_key = '')
{
$crawler = self::request('GET', 'search.php?keywords=' . $keywords);
$this->assertEquals($posts_found, $crawler->filter('.postbody')->count());
$this->assertEquals($words_highlighted, $crawler->filter('.posthilit')->count());
$this->purge_cache();
$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, $sort_key = '')
{
$this->purge_cache();
$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)
{
$crawler = self::request('GET', 'search.php?keywords=' . $keywords);
$this->assertEquals(0, $crawler->filter('.postbody')->count());
$this->assertEquals(0, $crawler->filter('.postbody')->count(), $this->search_backend);
$split_keywords_string = str_replace('+', ' ', $keywords);
$this->assertEquals($split_keywords_string, $crawler->filter('#keywords')->attr('value'));
$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()
{
$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_id = $this->create_user('searchforauthoruser');
}
$this->remove_user_group('NEWLY_REGISTERED', ['searchforauthoruser']);
$this->set_flood_interval(0);
$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();
$this->create_search_index('phpbb\\search\\backend\\fulltext_native');
$post = $this->create_topic(2, 'Test Topic 1 foosubject', 'This is a test topic posted by the barsearch testing framework.');
$this->set_flood_interval(15);
$crawler = self::request('GET', 'adm/index.php?i=acp_search&mode=settings&sid=' . $this->sid);
$form = $crawler->selectButton('Submit')->form();
$form = $crawler->selectButton($this->lang('SUBMIT'))->form();
$values = $form->getValues();
if ($values["config[search_type]"] != $this->search_backend)
@@ -58,12 +106,13 @@ abstract class phpbb_functional_search_base extends phpbb_functional_test_case
{
// Search backed is not supported because don't appear in the select
$this->delete_topic($post['topic_id']);
$this->delete_topic($topic_by_author['topic_id']);
$this->markTestSkipped("Search backend is not supported/running");
}
$crawler = self::submit($form);
$form = $crawler->selectButton('Yes')->form();
$form = $crawler->selectButton($this->lang('YES'))->form();
$values = $form->getValues();
$crawler = self::submit($form);
@@ -77,50 +126,73 @@ 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);
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)
{
$this->add_lang('acp/search');
$search_type = $backend ?? $this->search_backend;
$crawler = self::request('GET', 'adm/index.php?i=acp_search&mode=index&sid=' . $this->sid);
$form = $crawler->selectButton('Create index')->form();
$form = $crawler->selectButton($this->lang('CREATE_INDEX'))->form();
$form_values = $form->getValues();
$form_values = array_merge($form_values,
array(
'search_type' => ( ($backend === null) ? $this->search_backend : $backend ),
[
'search_type' => $search_type,
'action' => 'create',
)
]
);
$form->setValues($form_values);
$crawler = self::submit($form);
$this->assertContainsLang('SEARCH_INDEX_CREATED', $crawler->text());
// Ensure search index has been actually created
$crawler = self::request('GET', 'adm/index.php?i=acp_search&mode=index&sid=' . $this->sid);
$posts_indexed = (int) $crawler->filter('#acp_search_index_' . $search_type . ' td')->eq(1)->text();
$this->assertTrue($posts_indexed > 0);
}
protected function delete_search_index()
{
$this->add_lang('acp/search');
$crawler = self::request('GET', 'adm/index.php?i=acp_search&mode=index&sid=' . $this->sid);
$form = $crawler->selectButton('Delete index')->form();
$form = $crawler->selectButton($this->lang('DELETE_INDEX'))->form();
$form_values = $form->getValues();
$form_values = array_merge($form_values,
array(
[
'search_type' => $this->search_backend,
'action' => 'delete',
)
]
);
$form->setValues($form_values);
$crawler = self::submit($form);
$this->assertContainsLang('SEARCH_INDEX_REMOVED', $crawler->text());
// Ensure search index has been actually removed
$crawler = self::request('GET', 'adm/index.php?i=acp_search&mode=index&sid=' . $this->sid);
$posts_indexed = (int) $crawler->filter('#acp_search_index_' . $this->search_backend . ' td')->eq(1)->text();
$this->assertEquals(0, $posts_indexed);
}
}

View File

@@ -255,19 +255,6 @@ class phpbb_functional_visibility_disapprove_test extends phpbb_functional_test_
$this->assertEquals($details, $data, "Forum {$forum_id} does not match expected {$additional_error_message}");
}
protected function set_flood_interval($flood_interval)
{
$crawler = self::request('GET', 'adm/index.php?sid=' . $this->sid . '&i=acp_board&mode=post');
$form = $crawler->selectButton('Submit')->form();
$values = $form->getValues();
$values["config[flood_interval]"] = $flood_interval;
$form->setValues($values);
$crawler = self::submit($form);
$this->assertGreaterThan(0, $crawler->filter('.successbox')->count());
}
protected function load_ids($data)
{
$this->db = $this->get_db();

View File

@@ -351,19 +351,6 @@ class phpbb_functional_visibility_reapprove_test extends phpbb_functional_test_c
$this->assertEquals($details, $data, "Forum {$forum_id} does not match expected {$additional_error_message}");
}
protected function set_flood_interval($flood_interval)
{
$crawler = self::request('GET', 'adm/index.php?sid=' . $this->sid . '&i=acp_board&mode=post');
$form = $crawler->selectButton('Submit')->form();
$values = $form->getValues();
$values["config[flood_interval]"] = $flood_interval;
$form->setValues($values);
$crawler = self::submit($form);
$this->assertGreaterThan(0, $crawler->filter('.successbox')->count());
}
protected function load_ids($data)
{
$this->db = $this->get_db();

View File

@@ -268,19 +268,6 @@ class phpbb_functional_visibility_unapproved_test extends phpbb_functional_test_
$this->assertEquals($details, $data, "Forum {$forum_id} does not match expected {$additional_error_message}");
}
protected function set_flood_interval($flood_interval)
{
$crawler = self::request('GET', "adm/index.php?sid={$this->sid}&i=acp_board&mode=post");
$form = $crawler->selectButton('Submit')->form();
$values = $form->getValues();
$values['config[flood_interval]'] = $flood_interval;
$form->setValues($values);
$crawler = self::submit($form);
$this->assertGreaterThan(0, $crawler->filter('.successbox')->count());
}
protected function load_ids($data)
{
$this->db = $this->get_db();