[ticket/11174] Check common words, fix array equality assertion.

PHPBB3-11174
This commit is contained in:
Oleg Pudeyev 2012-11-08 11:15:46 -05:00
parent e523517e03
commit a5f7f99478

View file

@ -62,12 +62,14 @@ class phpbb_search_native_test extends phpbb_database_test_case
// ok // ok
// must contain ids // must contain ids
// must not contain ids // must not contain ids
// common words
array( array(
'foo', 'foo',
'all', 'all',
true, true,
array(1), array(1),
array(), array(),
array(),
), ),
array( array(
'foo bar', 'foo bar',
@ -75,6 +77,7 @@ class phpbb_search_native_test extends phpbb_database_test_case
true, true,
array(1, 2), array(1, 2),
array(), array(),
array(),
), ),
// leading, trailing and multiple spaces // leading, trailing and multiple spaces
array( array(
@ -83,21 +86,25 @@ class phpbb_search_native_test extends phpbb_database_test_case
true, true,
array(1, 2), array(1, 2),
array(), array(),
array(),
), ),
// words too short // words too short
array( array(
'f', 'f',
'all', 'all',
false, false,
array(), null,
array(), null,
// short words count as "common" words
array('f'),
), ),
array( array(
'f o o', 'f o o',
'all', 'all',
false, false,
array(), null,
array(), null,
array('f', 'o', 'o'),
), ),
array( array(
'foo -bar', 'foo -bar',
@ -105,20 +112,23 @@ class phpbb_search_native_test extends phpbb_database_test_case
true, true,
array(1), array(1),
array(2), array(2),
array(),
), ),
// all negative // all negative
array( array(
'-foo', '-foo',
'all', 'all',
false, false,
array(), null,
null,
array(), array(),
), ),
array( array(
'-foo -bar', '-foo -bar',
'all', 'all',
false, false,
array(), null,
null,
array(), array(),
), ),
// all common // all common
@ -126,8 +136,9 @@ class phpbb_search_native_test extends phpbb_database_test_case
'commonword', 'commonword',
'all', 'all',
false, false,
array(), null,
array(), null,
array('commonword'),
), ),
// some common // some common
array( array(
@ -136,6 +147,7 @@ class phpbb_search_native_test extends phpbb_database_test_case
true, true,
array(1), array(1),
array(), array(),
array('commonword'),
), ),
); );
} }
@ -143,12 +155,32 @@ class phpbb_search_native_test extends phpbb_database_test_case
/** /**
* @dataProvider keywords * @dataProvider keywords
*/ */
public function test_split_keywords($keywords, $terms, $ok, $must_contain, $must_not_contain) public function test_split_keywords($keywords, $terms, $ok, $must_contain, $must_not_contain, $common)
{ {
$rv = $this->search->split_keywords($keywords, $terms); $rv = $this->search->split_keywords($keywords, $terms);
$this->assertEquals($ok, $rv); $this->assertEquals($ok, $rv);
if ($ok)
{
// only check criteria if the search is going to be performed
$this->assert_array_content_equals($must_contain, $this->search->get_must_contain_ids());
$this->assert_array_content_equals($must_not_contain, $this->search->get_must_not_contain_ids());
}
$this->assert_array_content_equals($common, $this->search->get_common_words());
}
public function assert_array_content_equals($one, $two)
{
// http://stackoverflow.com/questions/3838288/phpunit-assert-two-arrays-are-equal-but-order-of-elements-not-important // http://stackoverflow.com/questions/3838288/phpunit-assert-two-arrays-are-equal-but-order-of-elements-not-important
$this->assertEmpty(array_diff($must_contain, $this->search->get_must_contain_ids())); // but one array_diff is not enough!
$this->assertEmpty(array_diff($must_not_contain, $this->search->get_must_not_contain_ids())); if (sizeof(array_diff($one, $two)) || sizeof(array_diff($two, $one)))
{
// get a nice error message
$this->assertEquals($one, $two);
}
else
{
// increase assertion count
$this->assertTrue(true);
}
} }
} }