2013-06-12 00:29:04 +05:30
|
|
|
<?php
|
|
|
|
/**
|
2013-09-01 20:03:02 +05:30
|
|
|
*
|
2014-05-27 20:18:06 +02:00
|
|
|
* This file is part of the phpBB Forum Software package.
|
|
|
|
*
|
|
|
|
* @copyright (c) phpBB Limited <https://www.phpbb.com>
|
|
|
|
* @license GNU General Public License, version 2 (GPL-2.0)
|
|
|
|
*
|
|
|
|
* For full copyright and license information, please see
|
|
|
|
* the docs/CREDITS.txt file.
|
2013-09-01 20:03:02 +05:30
|
|
|
*
|
|
|
|
*/
|
2013-06-12 00:29:04 +05:30
|
|
|
|
|
|
|
/**
|
2013-09-01 20:03:02 +05:30
|
|
|
* @group functional
|
|
|
|
*/
|
|
|
|
abstract class phpbb_functional_search_base extends phpbb_functional_test_case
|
2013-06-12 00:29:04 +05:30
|
|
|
{
|
2013-11-08 18:35:49 +05:30
|
|
|
protected function assert_search_found($keywords, $posts_found, $words_highlighted)
|
2013-06-12 00:29:04 +05:30
|
|
|
{
|
2013-07-03 23:25:19 +05:30
|
|
|
$crawler = self::request('GET', 'search.php?keywords=' . $keywords);
|
2013-11-08 18:35:49 +05:30
|
|
|
$this->assertEquals($posts_found, $crawler->filter('.postbody')->count());
|
|
|
|
$this->assertEquals($words_highlighted, $crawler->filter('.posthilit')->count());
|
2013-06-12 00:29:04 +05:30
|
|
|
}
|
|
|
|
|
2013-07-06 14:38:42 +05:30
|
|
|
protected function assert_search_not_found($keywords)
|
2013-06-12 00:29:04 +05:30
|
|
|
{
|
2013-07-03 23:25:19 +05:30
|
|
|
$crawler = self::request('GET', 'search.php?keywords=' . $keywords);
|
2013-06-19 02:23:14 +05:30
|
|
|
$this->assertEquals(0, $crawler->filter('.postbody')->count());
|
2013-07-03 23:25:19 +05:30
|
|
|
$split_keywords_string = str_replace(array('+', '-'), ' ', $keywords);
|
|
|
|
$this->assertEquals($split_keywords_string, $crawler->filter('#keywords')->attr('value'));
|
2013-06-12 00:29:04 +05:30
|
|
|
}
|
|
|
|
|
2013-06-19 02:13:32 +05:30
|
|
|
public function test_search_backend()
|
2013-06-12 00:29:04 +05:30
|
|
|
{
|
|
|
|
$this->login();
|
|
|
|
$this->admin_login();
|
|
|
|
|
2014-03-10 01:02:57 +05:30
|
|
|
$post = $this->create_topic(2, 'Test Topic 1 foosubject', 'This is a test topic posted by the barsearch testing framework.');
|
2013-11-08 18:35:49 +05:30
|
|
|
|
2013-06-12 00:29:04 +05:30
|
|
|
$crawler = self::request('GET', 'adm/index.php?i=acp_search&mode=settings&sid=' . $this->sid);
|
|
|
|
$form = $crawler->selectButton('Submit')->form();
|
|
|
|
$values = $form->getValues();
|
|
|
|
|
2013-06-19 02:13:32 +05:30
|
|
|
if ($values["config[search_type]"] != $this->search_backend)
|
2013-06-12 00:29:04 +05:30
|
|
|
{
|
2013-06-19 02:13:32 +05:30
|
|
|
$values["config[search_type]"] = $this->search_backend;
|
2013-06-12 00:29:04 +05:30
|
|
|
$form->setValues($values);
|
|
|
|
$crawler = self::submit($form);
|
|
|
|
|
|
|
|
$form = $crawler->selectButton('Yes')->form();
|
|
|
|
$values = $form->getValues();
|
|
|
|
$crawler = self::submit($form);
|
|
|
|
|
2013-07-06 14:38:42 +05:30
|
|
|
// check if search backend is not supported
|
2013-07-06 20:36:41 +05:30
|
|
|
if ($crawler->filter('.errorbox')->count() > 0)
|
2013-06-14 00:27:09 +05:30
|
|
|
{
|
2014-03-10 02:20:29 +05:30
|
|
|
$this->delete_topic($post['topic_id']);
|
2013-07-03 23:25:19 +05:30
|
|
|
$this->markTestSkipped("Search backend is not supported/running");
|
2013-06-14 00:27:09 +05:30
|
|
|
}
|
2013-06-19 02:13:32 +05:30
|
|
|
$this->create_search_index();
|
2013-06-12 00:29:04 +05:30
|
|
|
}
|
|
|
|
|
2013-06-14 02:30:43 +05:30
|
|
|
$this->logout();
|
2013-11-08 18:35:49 +05:30
|
|
|
$this->assert_search_found('phpbb3+installation', 1, 3);
|
2014-03-10 01:02:57 +05:30
|
|
|
$this->assert_search_found('foosubject+barsearch', 1, 2);
|
2013-07-06 14:38:42 +05:30
|
|
|
$this->assert_search_not_found('loremipsumdedo');
|
2013-06-14 02:30:43 +05:30
|
|
|
|
|
|
|
$this->login();
|
|
|
|
$this->admin_login();
|
2013-06-19 02:13:32 +05:30
|
|
|
$this->delete_search_index();
|
2013-11-08 23:12:06 +05:30
|
|
|
$this->delete_topic($post['topic_id']);
|
2013-06-14 01:24:24 +05:30
|
|
|
}
|
|
|
|
|
2013-06-19 02:13:32 +05:30
|
|
|
protected function create_search_index()
|
2013-06-14 01:24:24 +05:30
|
|
|
{
|
2013-06-14 01:46:51 +05:30
|
|
|
$this->add_lang('acp/search');
|
2013-06-14 01:24:24 +05:30
|
|
|
$crawler = self::request(
|
|
|
|
'POST',
|
|
|
|
'adm/index.php?i=acp_search&mode=index&sid=' . $this->sid,
|
|
|
|
array(
|
2013-06-19 02:13:32 +05:30
|
|
|
'search_type' => $this->search_backend,
|
2013-06-14 01:24:24 +05:30
|
|
|
'action' => 'create',
|
|
|
|
'submit' => true,
|
|
|
|
)
|
|
|
|
);
|
2013-06-19 02:20:24 +05:30
|
|
|
$this->assertContainsLang('SEARCH_INDEX_CREATED', $crawler->text());
|
2013-06-12 00:29:04 +05:30
|
|
|
}
|
|
|
|
|
2013-06-19 02:13:32 +05:30
|
|
|
protected function delete_search_index()
|
2013-06-12 00:29:04 +05:30
|
|
|
{
|
2013-06-14 01:46:51 +05:30
|
|
|
$this->add_lang('acp/search');
|
2013-06-14 01:24:24 +05:30
|
|
|
$crawler = self::request(
|
|
|
|
'POST',
|
|
|
|
'adm/index.php?i=acp_search&mode=index&sid=' . $this->sid,
|
|
|
|
array(
|
2013-06-19 02:13:32 +05:30
|
|
|
'search_type' => $this->search_backend,
|
2013-06-14 01:24:24 +05:30
|
|
|
'action' => 'delete',
|
|
|
|
'submit' => true,
|
|
|
|
)
|
|
|
|
);
|
2013-06-19 02:20:24 +05:30
|
|
|
$this->assertContainsLang('SEARCH_INDEX_REMOVED', $crawler->text());
|
2013-06-12 00:29:04 +05:30
|
|
|
}
|
|
|
|
}
|