From 18a922c036f196e934fec1a1daab7cfaa98001ce Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Thu, 8 Nov 2012 10:14:29 -0500 Subject: [ticket/11174] Started on search tests - keyword splitting. PHPBB3-11174 --- tests/search/native_test.php | 113 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 113 insertions(+) create mode 100644 tests/search/native_test.php (limited to 'tests/search/native_test.php') diff --git a/tests/search/native_test.php b/tests/search/native_test.php new file mode 100644 index 0000000000..bcde11faf1 --- /dev/null +++ b/tests/search/native_test.php @@ -0,0 +1,113 @@ +must_contain_ids; } + public function get_must_not_contain_ids() { return \$this->must_not_contain_ids; } +} + "; + eval($code); + } + return $wrapped; +} + +class phpbb_search_native_test extends phpbb_database_test_case +{ + protected $db; + protected $search; + + public function getDataSet() + { + return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/posts.xml'); + } + + protected function setUp() + { + global $phpbb_root_path, $phpEx, $config, $user, $cache; + + parent::setUp(); + + // dbal uses cache + $cache = new phpbb_cache_driver_null; + + $this->db = $this->new_dbal(); + $error = null; + $class = phpbb_search_wrapper('phpbb_search_fulltext_native'); + $this->search = new $class($error, $phpbb_root_path, $phpEx, null, $config, $this->db, $user); + } + + protected function tearDown() + { + parent::tearDown(); + } + + public function keywords() + { + return array( + // keywords + // terms + // ok + // must contain ids + // must not contain ids + array( + 'foo', + 'all', + true, + array(1), + array(), + ), + array( + 'foo bar', + 'all', + true, + array(1, 2), + array(), + ), + array( + 'foo -bar', + 'all', + true, + array(1), + array(2), + ), + array( + '-foo', + 'all', + false, + array(), + array(), + ), + array( + '-foo -bar', + 'all', + false, + array(), + array(), + ), + ); + } + + /** + * @dataProvider keywords + */ + public function test_split_keywords($keywords, $terms, $ok, $must_contain, $must_not_contain) + { + $rv = $this->search->split_keywords($keywords, $terms); + $this->assertEquals($ok, $rv); + $this->assertEmpty(array_diff($must_contain, $this->search->get_must_contain_ids())); + $this->assertEmpty(array_diff($must_not_contain, $this->search->get_must_not_contain_ids())); + } +} -- cgit v1.2.1 From ed37141f512f857311b64bb283943634eba84525 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Thu, 8 Nov 2012 10:19:15 -0500 Subject: [ticket/11174] Clarify why that is the way it is. PHPBB3-11174 --- tests/search/native_test.php | 1 + 1 file changed, 1 insertion(+) (limited to 'tests/search/native_test.php') diff --git a/tests/search/native_test.php b/tests/search/native_test.php index bcde11faf1..15b4644498 100644 --- a/tests/search/native_test.php +++ b/tests/search/native_test.php @@ -107,6 +107,7 @@ class phpbb_search_native_test extends phpbb_database_test_case { $rv = $this->search->split_keywords($keywords, $terms); $this->assertEquals($ok, $rv); + // 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())); $this->assertEmpty(array_diff($must_not_contain, $this->search->get_must_not_contain_ids())); } -- cgit v1.2.1 From 1aa0b4567fc1849712471e129b868927f400f773 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Thu, 8 Nov 2012 10:23:28 -0500 Subject: [ticket/11174] More tests. PHPBB3-11174 --- tests/search/native_test.php | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'tests/search/native_test.php') diff --git a/tests/search/native_test.php b/tests/search/native_test.php index 15b4644498..8638a914ba 100644 --- a/tests/search/native_test.php +++ b/tests/search/native_test.php @@ -76,6 +76,29 @@ class phpbb_search_native_test extends phpbb_database_test_case array(1, 2), array(), ), + // leading, trailing and multiple spaces + array( + ' foo bar ', + 'all', + true, + array(1, 2), + array(), + ), + // words too short + array( + 'f', + 'all', + false, + array(), + array(), + ), + array( + 'f o o', + 'all', + false, + array(), + array(), + ), array( 'foo -bar', 'all', @@ -83,6 +106,7 @@ class phpbb_search_native_test extends phpbb_database_test_case array(1), array(2), ), + // all negative array( '-foo', 'all', -- cgit v1.2.1 From e523517e03d3f54daaa33b4e48743a0f065fba0f Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Thu, 8 Nov 2012 11:01:34 -0500 Subject: [ticket/11174] Test for common words. PHPBB3-11174 --- tests/search/native_test.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'tests/search/native_test.php') diff --git a/tests/search/native_test.php b/tests/search/native_test.php index 8638a914ba..3726b96a82 100644 --- a/tests/search/native_test.php +++ b/tests/search/native_test.php @@ -121,6 +121,22 @@ class phpbb_search_native_test extends phpbb_database_test_case array(), array(), ), + // all common + array( + 'commonword', + 'all', + false, + array(), + array(), + ), + // some common + array( + 'commonword foo', + 'all', + true, + array(1), + array(), + ), ); } -- cgit v1.2.1 From a5f7f99478a43206ab6021a80828dddf66f92e9f Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Thu, 8 Nov 2012 11:15:46 -0500 Subject: [ticket/11174] Check common words, fix array equality assertion. PHPBB3-11174 --- tests/search/native_test.php | 54 +++++++++++++++++++++++++++++++++++--------- 1 file changed, 43 insertions(+), 11 deletions(-) (limited to 'tests/search/native_test.php') diff --git a/tests/search/native_test.php b/tests/search/native_test.php index 3726b96a82..66972079cf 100644 --- a/tests/search/native_test.php +++ b/tests/search/native_test.php @@ -62,12 +62,14 @@ class phpbb_search_native_test extends phpbb_database_test_case // ok // must contain ids // must not contain ids + // common words array( 'foo', 'all', true, array(1), array(), + array(), ), array( 'foo bar', @@ -75,6 +77,7 @@ class phpbb_search_native_test extends phpbb_database_test_case true, array(1, 2), array(), + array(), ), // leading, trailing and multiple spaces array( @@ -83,21 +86,25 @@ class phpbb_search_native_test extends phpbb_database_test_case true, array(1, 2), array(), + array(), ), // words too short array( 'f', 'all', false, - array(), - array(), + null, + null, + // short words count as "common" words + array('f'), ), array( 'f o o', 'all', false, - array(), - array(), + null, + null, + array('f', 'o', 'o'), ), array( 'foo -bar', @@ -105,20 +112,23 @@ class phpbb_search_native_test extends phpbb_database_test_case true, array(1), array(2), + array(), ), // all negative array( '-foo', 'all', false, - array(), + null, + null, array(), ), array( '-foo -bar', 'all', false, - array(), + null, + null, array(), ), // all common @@ -126,8 +136,9 @@ class phpbb_search_native_test extends phpbb_database_test_case 'commonword', 'all', false, - array(), - array(), + null, + null, + array('commonword'), ), // some common array( @@ -136,6 +147,7 @@ class phpbb_search_native_test extends phpbb_database_test_case true, array(1), array(), + array('commonword'), ), ); } @@ -143,12 +155,32 @@ class phpbb_search_native_test extends phpbb_database_test_case /** * @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); $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 - $this->assertEmpty(array_diff($must_contain, $this->search->get_must_contain_ids())); - $this->assertEmpty(array_diff($must_not_contain, $this->search->get_must_not_contain_ids())); + // but one array_diff is not enough! + 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); + } } } -- cgit v1.2.1 From 615582f0dffc8d50604e3cc567e01e807a397bec Mon Sep 17 00:00:00 2001 From: Dhruv Date: Mon, 12 Nov 2012 13:47:33 +0100 Subject: [ticket/11174] rename native wrapper class native wrapper class is limited to the native search backend hence renamed. the one used with mysql can be used with pgsql too. PHPBB3-11174 --- tests/search/native_test.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'tests/search/native_test.php') diff --git a/tests/search/native_test.php b/tests/search/native_test.php index 66972079cf..722da9eb59 100644 --- a/tests/search/native_test.php +++ b/tests/search/native_test.php @@ -7,7 +7,7 @@ * */ -function phpbb_search_wrapper($class) +function phpbb_native_search_wrapper($class) { $wrapped = $class . '_wrapper'; if (!class_exists($wrapped)) @@ -45,7 +45,7 @@ class phpbb_search_native_test extends phpbb_database_test_case $this->db = $this->new_dbal(); $error = null; - $class = phpbb_search_wrapper('phpbb_search_fulltext_native'); + $class = phpbb_native_search_wrapper('phpbb_search_fulltext_native'); $this->search = new $class($error, $phpbb_root_path, $phpEx, null, $config, $this->db, $user); } -- cgit v1.2.1 From 2d1ac34de60a15e0b9e00a30140a08b4e329099d Mon Sep 17 00:00:00 2001 From: Dhruv Date: Mon, 12 Nov 2012 14:19:32 +0100 Subject: [ticket/11174] add test case for native test PHPBB3-11174 --- tests/search/native_test.php | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'tests/search/native_test.php') diff --git a/tests/search/native_test.php b/tests/search/native_test.php index 722da9eb59..5f6d49c26c 100644 --- a/tests/search/native_test.php +++ b/tests/search/native_test.php @@ -106,6 +106,14 @@ class phpbb_search_native_test extends phpbb_database_test_case null, array('f', 'o', 'o'), ), + array( + 'f -o -o', + 'all', + false, + null, + null, + array('f', 'o', 'o'), + ), array( 'foo -bar', 'all', -- cgit v1.2.1 From 3ed4fc437e2a88638d705b8f4cab23eacf39fe3c Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Tue, 27 Nov 2012 08:08:34 -0500 Subject: [ticket/11174] Move assertion definition to base class. PHPBB3-11174 --- tests/search/native_test.php | 16 ---------------- 1 file changed, 16 deletions(-) (limited to 'tests/search/native_test.php') diff --git a/tests/search/native_test.php b/tests/search/native_test.php index 5f6d49c26c..21cbde496a 100644 --- a/tests/search/native_test.php +++ b/tests/search/native_test.php @@ -175,20 +175,4 @@ class phpbb_search_native_test extends phpbb_database_test_case } $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 - // but one array_diff is not enough! - 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); - } - } } -- cgit v1.2.1 From a5900a6b1120a3d062e6d51579872bf940b13dcb Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Tue, 27 Nov 2012 08:18:39 -0500 Subject: [ticket/11174] Extract phpbb_search_test_case. PHPBB3-11174 --- tests/search/native_test.php | 21 +++------------------ 1 file changed, 3 insertions(+), 18 deletions(-) (limited to 'tests/search/native_test.php') diff --git a/tests/search/native_test.php b/tests/search/native_test.php index 21cbde496a..544ab7ca17 100644 --- a/tests/search/native_test.php +++ b/tests/search/native_test.php @@ -7,24 +7,9 @@ * */ -function phpbb_native_search_wrapper($class) -{ - $wrapped = $class . '_wrapper'; - if (!class_exists($wrapped)) - { - $code = " -class $wrapped extends $class -{ - public function get_must_contain_ids() { return \$this->must_contain_ids; } - public function get_must_not_contain_ids() { return \$this->must_not_contain_ids; } -} - "; - eval($code); - } - return $wrapped; -} +require_once dirname(__FILE__) . '/../test_framework/phpbb_search_test_case.php'; -class phpbb_search_native_test extends phpbb_database_test_case +class phpbb_search_native_test extends phpbb_search_test_case { protected $db; protected $search; @@ -45,7 +30,7 @@ class phpbb_search_native_test extends phpbb_database_test_case $this->db = $this->new_dbal(); $error = null; - $class = phpbb_native_search_wrapper('phpbb_search_fulltext_native'); + $class = self::get_search_wrapper('phpbb_search_fulltext_native'); $this->search = new $class($error, $phpbb_root_path, $phpEx, null, $config, $this->db, $user); } -- cgit v1.2.1 From cb2d029abf2d4857fa462f46af21728afde3cd28 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Tue, 27 Nov 2012 08:56:32 -0500 Subject: [ticket/11174] Drop needless teardown functions. PHPBB3-11174 --- tests/search/native_test.php | 5 ----- 1 file changed, 5 deletions(-) (limited to 'tests/search/native_test.php') diff --git a/tests/search/native_test.php b/tests/search/native_test.php index 544ab7ca17..53d7a1fe78 100644 --- a/tests/search/native_test.php +++ b/tests/search/native_test.php @@ -34,11 +34,6 @@ class phpbb_search_native_test extends phpbb_search_test_case $this->search = new $class($error, $phpbb_root_path, $phpEx, null, $config, $this->db, $user); } - protected function tearDown() - { - parent::tearDown(); - } - public function keywords() { return array( -- cgit v1.2.1 From 79237b60b6b234e10f14cbcb00691b5e4374fd04 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Tue, 27 Nov 2012 10:24:31 -0500 Subject: [ticket/11174] Global $cache is a cache service instance. PHPBB3-11174 --- tests/search/native_test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests/search/native_test.php') diff --git a/tests/search/native_test.php b/tests/search/native_test.php index 53d7a1fe78..eeee3a44f3 100644 --- a/tests/search/native_test.php +++ b/tests/search/native_test.php @@ -26,7 +26,7 @@ class phpbb_search_native_test extends phpbb_search_test_case parent::setUp(); // dbal uses cache - $cache = new phpbb_cache_driver_null; + $cache = new phpbb_cache_service(new phpbb_cache_driver_null); $this->db = $this->new_dbal(); $error = null; -- cgit v1.2.1