mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-10 05:18:52 +00:00
[ticket/11174] Delete more copy pasting.
PHPBB3-11174
This commit is contained in:
parent
cb2d029abf
commit
7dcb03faf1
3 changed files with 110 additions and 190 deletions
106
tests/search/common_test_case.php
Normal file
106
tests/search/common_test_case.php
Normal file
|
@ -0,0 +1,106 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @package testing
|
||||||
|
* @copyright (c) 2012 phpBB Group
|
||||||
|
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
require_once dirname(__FILE__) . '/../test_framework/phpbb_search_test_case.php';
|
||||||
|
|
||||||
|
abstract class phpbb_search_common_test_case extends phpbb_search_test_case
|
||||||
|
{
|
||||||
|
public function keywords()
|
||||||
|
{
|
||||||
|
return array(
|
||||||
|
// keywords
|
||||||
|
// terms
|
||||||
|
// ok
|
||||||
|
// split words
|
||||||
|
// common words
|
||||||
|
array(
|
||||||
|
'fooo',
|
||||||
|
'all',
|
||||||
|
true,
|
||||||
|
array('fooo'),
|
||||||
|
array(),
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'fooo baar',
|
||||||
|
'all',
|
||||||
|
true,
|
||||||
|
array('fooo', 'baar'),
|
||||||
|
array(),
|
||||||
|
),
|
||||||
|
// leading, trailing and multiple spaces
|
||||||
|
array(
|
||||||
|
' fooo baar ',
|
||||||
|
'all',
|
||||||
|
true,
|
||||||
|
array('fooo', 'baar'),
|
||||||
|
array(),
|
||||||
|
),
|
||||||
|
// words too short
|
||||||
|
array(
|
||||||
|
'f',
|
||||||
|
'all',
|
||||||
|
false,
|
||||||
|
null,
|
||||||
|
// short words count as "common" words
|
||||||
|
array('f'),
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'f o o',
|
||||||
|
'all',
|
||||||
|
false,
|
||||||
|
null,
|
||||||
|
array('f', 'o', 'o'),
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'f -o -o',
|
||||||
|
'all',
|
||||||
|
false,
|
||||||
|
null,
|
||||||
|
array('f', '-o', '-o'),
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'fooo -baar',
|
||||||
|
'all',
|
||||||
|
true,
|
||||||
|
array('-baar', 'fooo'),
|
||||||
|
array(),
|
||||||
|
),
|
||||||
|
// all negative
|
||||||
|
array(
|
||||||
|
'-fooo',
|
||||||
|
'all',
|
||||||
|
true,
|
||||||
|
array('-fooo'),
|
||||||
|
array(),
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'-fooo -baar',
|
||||||
|
'all',
|
||||||
|
true,
|
||||||
|
array('-fooo', '-baar'),
|
||||||
|
array(),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dataProvider keywords
|
||||||
|
*/
|
||||||
|
public function test_split_keywords($keywords, $terms, $ok, $split_words, $common)
|
||||||
|
{
|
||||||
|
$rv = $this->search->split_keywords($keywords, $terms);
|
||||||
|
$this->assertEquals($ok, $rv);
|
||||||
|
if ($ok)
|
||||||
|
{
|
||||||
|
// only check criteria if the search is going to be performed
|
||||||
|
$this->assert_array_content_equals($split_words, $this->search->get_split_words());
|
||||||
|
}
|
||||||
|
$this->assert_array_content_equals($common, $this->search->get_common_words());
|
||||||
|
}
|
||||||
|
}
|
|
@ -7,9 +7,9 @@
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
require_once dirname(__FILE__) . '/../test_framework/phpbb_search_test_case.php';
|
require_once dirname(__FILE__) . '/common_test_case.php';
|
||||||
|
|
||||||
class phpbb_search_mysql_test extends phpbb_search_test_case
|
class phpbb_search_mysql_test extends phpbb_search_common_test_case
|
||||||
{
|
{
|
||||||
protected $db;
|
protected $db;
|
||||||
protected $search;
|
protected $search;
|
||||||
|
@ -37,97 +37,4 @@ class phpbb_search_mysql_test extends phpbb_search_test_case
|
||||||
$class = self::get_search_wrapper('phpbb_search_fulltext_mysql');
|
$class = self::get_search_wrapper('phpbb_search_fulltext_mysql');
|
||||||
$this->search = new $class($error, $phpbb_root_path, $phpEx, null, $config, $this->db, $user);
|
$this->search = new $class($error, $phpbb_root_path, $phpEx, null, $config, $this->db, $user);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function keywords()
|
|
||||||
{
|
|
||||||
return array(
|
|
||||||
// keywords
|
|
||||||
// terms
|
|
||||||
// ok
|
|
||||||
// split words
|
|
||||||
// common words
|
|
||||||
array(
|
|
||||||
'fooo',
|
|
||||||
'all',
|
|
||||||
true,
|
|
||||||
array('fooo'),
|
|
||||||
array(),
|
|
||||||
),
|
|
||||||
array(
|
|
||||||
'fooo baar',
|
|
||||||
'all',
|
|
||||||
true,
|
|
||||||
array('fooo', 'baar'),
|
|
||||||
array(),
|
|
||||||
),
|
|
||||||
// leading, trailing and multiple spaces
|
|
||||||
array(
|
|
||||||
' fooo baar ',
|
|
||||||
'all',
|
|
||||||
true,
|
|
||||||
array('fooo', 'baar'),
|
|
||||||
array(),
|
|
||||||
),
|
|
||||||
// words too short
|
|
||||||
array(
|
|
||||||
'f',
|
|
||||||
'all',
|
|
||||||
false,
|
|
||||||
null,
|
|
||||||
// short words count as "common" words
|
|
||||||
array('f'),
|
|
||||||
),
|
|
||||||
array(
|
|
||||||
'f o o',
|
|
||||||
'all',
|
|
||||||
false,
|
|
||||||
null,
|
|
||||||
array('f', 'o', 'o'),
|
|
||||||
),
|
|
||||||
array(
|
|
||||||
'f -o -o',
|
|
||||||
'all',
|
|
||||||
false,
|
|
||||||
null,
|
|
||||||
array('f', '-o', '-o'),
|
|
||||||
),
|
|
||||||
array(
|
|
||||||
'fooo -baar',
|
|
||||||
'all',
|
|
||||||
true,
|
|
||||||
array('-baar', 'fooo'),
|
|
||||||
array(),
|
|
||||||
),
|
|
||||||
// all negative
|
|
||||||
array(
|
|
||||||
'-fooo',
|
|
||||||
'all',
|
|
||||||
true,
|
|
||||||
array('-fooo'),
|
|
||||||
array(),
|
|
||||||
),
|
|
||||||
array(
|
|
||||||
'-fooo -baar',
|
|
||||||
'all',
|
|
||||||
true,
|
|
||||||
array('-fooo', '-baar'),
|
|
||||||
array(),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @dataProvider keywords
|
|
||||||
*/
|
|
||||||
public function test_split_keywords($keywords, $terms, $ok, $split_words, $common)
|
|
||||||
{
|
|
||||||
$rv = $this->search->split_keywords($keywords, $terms);
|
|
||||||
$this->assertEquals($ok, $rv);
|
|
||||||
if ($ok)
|
|
||||||
{
|
|
||||||
// only check criteria if the search is going to be performed
|
|
||||||
$this->assert_array_content_equals($split_words, $this->search->get_split_words());
|
|
||||||
}
|
|
||||||
$this->assert_array_content_equals($common, $this->search->get_common_words());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,9 +7,9 @@
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
require_once dirname(__FILE__) . '/../test_framework/phpbb_search_test_case.php';
|
require_once dirname(__FILE__) . '/common_test_case.php';
|
||||||
|
|
||||||
class phpbb_search_postgres_test extends phpbb_search_test_case
|
class phpbb_search_postgres_test extends phpbb_search_common_test_case
|
||||||
{
|
{
|
||||||
protected $db;
|
protected $db;
|
||||||
protected $search;
|
protected $search;
|
||||||
|
@ -37,97 +37,4 @@ class phpbb_search_postgres_test extends phpbb_search_test_case
|
||||||
$class = self::get_search_wrapper('phpbb_search_fulltext_postgres');
|
$class = self::get_search_wrapper('phpbb_search_fulltext_postgres');
|
||||||
$this->search = new $class($error, $phpbb_root_path, $phpEx, null, $config, $this->db, $user);
|
$this->search = new $class($error, $phpbb_root_path, $phpEx, null, $config, $this->db, $user);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function keywords()
|
|
||||||
{
|
|
||||||
return array(
|
|
||||||
// keywords
|
|
||||||
// terms
|
|
||||||
// ok
|
|
||||||
// split words
|
|
||||||
// common words
|
|
||||||
array(
|
|
||||||
'fooo',
|
|
||||||
'all',
|
|
||||||
true,
|
|
||||||
array('fooo'),
|
|
||||||
array(),
|
|
||||||
),
|
|
||||||
array(
|
|
||||||
'fooo baar',
|
|
||||||
'all',
|
|
||||||
true,
|
|
||||||
array('fooo', 'baar'),
|
|
||||||
array(),
|
|
||||||
),
|
|
||||||
// leading, trailing and multiple spaces
|
|
||||||
array(
|
|
||||||
' fooo baar ',
|
|
||||||
'all',
|
|
||||||
true,
|
|
||||||
array('fooo', 'baar'),
|
|
||||||
array(),
|
|
||||||
),
|
|
||||||
// words too short
|
|
||||||
array(
|
|
||||||
'f',
|
|
||||||
'all',
|
|
||||||
false,
|
|
||||||
null,
|
|
||||||
// short words count as "common" words
|
|
||||||
array('f'),
|
|
||||||
),
|
|
||||||
array(
|
|
||||||
'f o o',
|
|
||||||
'all',
|
|
||||||
false,
|
|
||||||
null,
|
|
||||||
array('f', 'o', 'o'),
|
|
||||||
),
|
|
||||||
array(
|
|
||||||
'f -o -o',
|
|
||||||
'all',
|
|
||||||
false,
|
|
||||||
null,
|
|
||||||
array('f', '-o', '-o'),
|
|
||||||
),
|
|
||||||
array(
|
|
||||||
'fooo -baar',
|
|
||||||
'all',
|
|
||||||
true,
|
|
||||||
array('-baar', 'fooo'),
|
|
||||||
array(),
|
|
||||||
),
|
|
||||||
// all negative
|
|
||||||
array(
|
|
||||||
'-fooo',
|
|
||||||
'all',
|
|
||||||
true,
|
|
||||||
array('-fooo'),
|
|
||||||
array(),
|
|
||||||
),
|
|
||||||
array(
|
|
||||||
'-fooo -baar',
|
|
||||||
'all',
|
|
||||||
true,
|
|
||||||
array('-fooo', '-baar'),
|
|
||||||
array(),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @dataProvider keywords
|
|
||||||
*/
|
|
||||||
public function test_split_keywords($keywords, $terms, $ok, $split_words, $common)
|
|
||||||
{
|
|
||||||
$rv = $this->search->split_keywords($keywords, $terms);
|
|
||||||
$this->assertEquals($ok, $rv);
|
|
||||||
if ($ok)
|
|
||||||
{
|
|
||||||
// only check criteria if the search is going to be performed
|
|
||||||
$this->assert_array_content_equals($split_words, $this->search->get_split_words());
|
|
||||||
}
|
|
||||||
$this->assert_array_content_equals($common, $this->search->get_common_words());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue