mirror of
https://github.com/phpbb/phpbb.git
synced 2025-07-30 13:30:25 +02:00
[ticket/16941] Add sphinx tests to 3.3.x
Also adjust Sphinx keywords splitting to be consistent with other search backends when it comes to handling hyphen (like ignoring hyphen when it hasn't NOT meaning and ignoring hyphen wrapped with "plus" signs) PHPBB3-16941
This commit is contained in:
@@ -150,8 +150,19 @@ abstract class phpbb_functional_search_base extends phpbb_functional_test_case
|
||||
if ($values["config[search_type]"] != $this->search_backend)
|
||||
{
|
||||
$values["config[search_type]"] = $this->search_backend;
|
||||
|
||||
if (strpos($this->search_backend, 'fulltext_sphinx'))
|
||||
{
|
||||
// Set board Sphinx id in according to respective setup-sphinx.sh $ID value
|
||||
$sql = 'UPDATE ' . CONFIG_TABLE . "
|
||||
SET config_value = '" . $this->db->sql_escape('gokw5rvjvvxp8kgj') . "'
|
||||
WHERE config_name = '" . $this->db->sql_escape('fulltext_sphinx_id') . "'";
|
||||
$this->db->sql_query($sql);
|
||||
}
|
||||
|
||||
$form->setValues($values);
|
||||
$crawler = self::submit($form);
|
||||
$this->purge_cache();
|
||||
|
||||
$form = $crawler->selectButton($this->lang('YES'))->form();
|
||||
$values = $form->getValues();
|
||||
@@ -244,7 +255,12 @@ abstract class phpbb_functional_search_base extends phpbb_functional_test_case
|
||||
|
||||
// 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();
|
||||
$posts_indexed = (int) $crawler->filter('#acp_search_index_' . $search_type . ' td')->reduce(
|
||||
function ($node, $i) {
|
||||
// Find the value of total posts indexed
|
||||
return (strpos($node->text(), $this->lang('FULLTEXT_MYSQL_TOTAL_POSTS')) !== false || strpos($node->text(), $this->lang('TOTAL_WORDS')) !== false);
|
||||
})
|
||||
->nextAll()->eq(0)->text();
|
||||
$this->assertTrue($posts_indexed > 0);
|
||||
}
|
||||
|
||||
@@ -281,7 +297,12 @@ abstract class phpbb_functional_search_base extends phpbb_functional_test_case
|
||||
|
||||
// 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();
|
||||
$posts_indexed = (int) $crawler->filter('#acp_search_index_' . $this->search_backend . ' td')->reduce(
|
||||
function ($node, $i) {
|
||||
// Find the value of total posts indexed
|
||||
return (strpos($node->text(), $this->lang('FULLTEXT_MYSQL_TOTAL_POSTS')) !== false || strpos($node->text(), $this->lang('TOTAL_WORDS')) !== false);
|
||||
})
|
||||
->nextAll()->eq(0)->text();
|
||||
$this->assertEquals(0, $posts_indexed);
|
||||
}
|
||||
}
|
||||
|
@@ -20,8 +20,31 @@ class phpbb_functional_search_sphinx_test extends phpbb_functional_search_base
|
||||
{
|
||||
protected $search_backend = '\phpbb\search\fulltext_sphinx';
|
||||
|
||||
protected function create_search_index($backend = null)
|
||||
{
|
||||
parent::create_search_index($backend);
|
||||
$this->purge_cache();
|
||||
|
||||
if (!$backend || $this->search_backend == $backend)
|
||||
{
|
||||
$output = $retval = null;
|
||||
|
||||
// After creating phpBB search index, build Sphinx index
|
||||
exec('sudo -S service sphinxsearch stop', $output, $retval); // Attempt to stop sphinxsearch service in case it's running
|
||||
exec('sudo -S indexer --all', $output, $retval); // Run sphinxsearch indexer
|
||||
exec('sudo -S service sphinxsearch start', $output, $retval); // Attempt to start sphinxsearch service again
|
||||
}
|
||||
}
|
||||
|
||||
public function test_search_backend()
|
||||
{
|
||||
$this->markTestIncomplete('Sphinx Tests are not supported');
|
||||
if ($this->db->sql_layer != 'mysqli') // Sphinx test runs on MySQL/MariaDB only so far
|
||||
{
|
||||
$this->markTestIncomplete('Sphinx Tests are not supported');
|
||||
}
|
||||
else
|
||||
{
|
||||
parent::test_search_backend();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -601,7 +601,16 @@ class phpbb_functional_visibility_softdelete_test extends phpbb_functional_test_
|
||||
// Assert new topic title is indexed as well
|
||||
$this->add_lang('search');
|
||||
self::request('GET', "search.php?keywords=bang&sid={$this->sid}");
|
||||
$this->assertStringContainsString(sprintf($this->lang['FOUND_SEARCH_MATCHES'][1], 1), self::get_content());
|
||||
|
||||
// Sphinx search doesn't apply to unapproved or softdeleted posts
|
||||
if (strpos($this->get_search_type(), 'fulltext_sphinx'))
|
||||
{
|
||||
$this->assertStringContainsString(sprintf($this->lang['FOUND_SEARCH_MATCHES'][2], 0), self::get_content());
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->assertStringContainsString(sprintf($this->lang['FOUND_SEARCH_MATCHES'][1], 1), self::get_content());
|
||||
}
|
||||
}
|
||||
|
||||
public function test_move_topic_back()
|
||||
|
@@ -735,6 +735,24 @@ class phpbb_functional_test_case extends phpbb_test_case
|
||||
return $group_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get current board's search type
|
||||
*
|
||||
* @return string Current search type setting
|
||||
*/
|
||||
protected function get_search_type()
|
||||
{
|
||||
$db = $this->get_db();
|
||||
$sql = 'SELECT config_value as search_type
|
||||
FROM ' . CONFIG_TABLE . "
|
||||
WHERE config_name = '" . $db->sql_escape('search_type') . "'";
|
||||
$result = $db->sql_query($sql);
|
||||
$search_type = $db->sql_fetchfield('search_type');
|
||||
$db->sql_freeresult($result);
|
||||
|
||||
return $search_type;
|
||||
}
|
||||
|
||||
protected function remove_user_group($group_name, $usernames)
|
||||
{
|
||||
global $db, $cache, $auth, $config, $phpbb_dispatcher, $phpbb_log, $phpbb_container, $user, $phpbb_root_path, $phpEx;
|
||||
|
Reference in New Issue
Block a user