From 764da977729aef331241d0cf0df77bd2e29d6256 Mon Sep 17 00:00:00 2001 From: Dhruv Date: Mon, 12 Nov 2012 13:41:58 +0100 Subject: [PATCH 01/18] [ticket/11174] include utf_tools in mysql backend when running tests include utf_tools file in the mysql search backend PHPBB3-11174 --- phpBB/includes/search/fulltext_mysql.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/phpBB/includes/search/fulltext_mysql.php b/phpBB/includes/search/fulltext_mysql.php index 58a4dd7d6a..cd5f0cef67 100644 --- a/phpBB/includes/search/fulltext_mysql.php +++ b/phpBB/includes/search/fulltext_mysql.php @@ -86,6 +86,14 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base $this->word_length = array('min' => $this->config['fulltext_mysql_min_word_len'], 'max' => $this->config['fulltext_mysql_max_word_len']); + /** + * Load the UTF tools + */ + if (!function_exists('utf8_strlen')) + { + include($phpbb_root_path . 'includes/utf/utf_tools.' . $phpEx); + } + $error = false; } From 6e8f142d3994f4568e40447d7cfd60cb5b082824 Mon Sep 17 00:00:00 2001 From: Dhruv Date: Mon, 12 Nov 2012 13:43:13 +0100 Subject: [PATCH 02/18] [ticket/11174] removes unnecessary space from word PHPBB3-11174 --- phpBB/includes/search/fulltext_mysql.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpBB/includes/search/fulltext_mysql.php b/phpBB/includes/search/fulltext_mysql.php index cd5f0cef67..ff2e24aa05 100644 --- a/phpBB/includes/search/fulltext_mysql.php +++ b/phpBB/includes/search/fulltext_mysql.php @@ -238,7 +238,7 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base } else { - $tmp_split_words[] = $word . ' '; + $tmp_split_words[] = $word; } } if ($phrase) From 6a76b85cbc741ef15c219c2c02c318bc43f29a59 Mon Sep 17 00:00:00 2001 From: Dhruv Date: Mon, 12 Nov 2012 13:46:15 +0100 Subject: [PATCH 03/18] [ticket/11174] add mysql unit tests PHPBB3-11174 --- tests/search/mysql_test.php | 155 ++++++++++++++++++++++++++++++++++++ 1 file changed, 155 insertions(+) create mode 100644 tests/search/mysql_test.php diff --git a/tests/search/mysql_test.php b/tests/search/mysql_test.php new file mode 100644 index 0000000000..d9da2dfb2d --- /dev/null +++ b/tests/search/mysql_test.php @@ -0,0 +1,155 @@ +split_words; } +} + "; + eval($code); + } + return $wrapped; +} + +class phpbb_search_mysql_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_mysql'); + $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 + // 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( + ' foo bar ', + 'all', + true, + array('foo', 'bar'), + 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( + 'foo -bar', + 'all', + true, + array('-bar', 'foo'), + array(), + ), + // all negative + array( + '-foo', + 'all', + false, + null, + array(), + ), + array( + '-foo -bar', + 'all', + false, + array('-foo', '-bar'), + 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()); + } + + public function assert_array_content_equals($one, $two) + { + 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); + } + } +} From 615582f0dffc8d50604e3cc567e01e807a397bec Mon Sep 17 00:00:00 2001 From: Dhruv Date: Mon, 12 Nov 2012 13:47:33 +0100 Subject: [PATCH 04/18] [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(-) 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); } From 2d1ac34de60a15e0b9e00a30140a08b4e329099d Mon Sep 17 00:00:00 2001 From: Dhruv Date: Mon, 12 Nov 2012 14:19:32 +0100 Subject: [PATCH 05/18] [ticket/11174] add test case for native test PHPBB3-11174 --- tests/search/native_test.php | 8 ++++++++ 1 file changed, 8 insertions(+) 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', From 9d597dc2ee152f448139dc708663f9a81e5cb209 Mon Sep 17 00:00:00 2001 From: Dhruv Date: Mon, 12 Nov 2012 16:22:10 +0100 Subject: [PATCH 06/18] [ticket/11174] set config values set config values and use min length as 4 for wordss in test cases PHPBB3-11174 --- tests/search/mysql_test.php | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/tests/search/mysql_test.php b/tests/search/mysql_test.php index d9da2dfb2d..44043da40d 100644 --- a/tests/search/mysql_test.php +++ b/tests/search/mysql_test.php @@ -42,6 +42,10 @@ class phpbb_search_mysql_test extends phpbb_database_test_case // dbal uses cache $cache = new phpbb_cache_driver_null; + // set config values + $config['fulltext_mysql_min_word_len'] = 4; + $config['fulltext_mysql_max_word_len'] = 254; + $this->db = $this->new_dbal(); $error = null; $class = phpbb_search_wrapper('phpbb_search_fulltext_mysql'); @@ -77,10 +81,10 @@ class phpbb_search_mysql_test extends phpbb_database_test_case ), // leading, trailing and multiple spaces array( - ' foo bar ', + ' fooo baar ', 'all', true, - array('foo', 'bar'), + array('fooo', 'baar'), array(), ), // words too short @@ -100,25 +104,32 @@ class phpbb_search_mysql_test extends phpbb_database_test_case array('f', 'o', 'o'), ), array( - 'foo -bar', + 'f -o -o', + 'all', + false, + null, + array('f', '-o', '-o'), + ), + array( + 'fooo -baar', 'all', true, - array('-bar', 'foo'), + array('-baar', 'fooo'), array(), ), // all negative array( - '-foo', + '-fooo', 'all', false, null, array(), ), array( - '-foo -bar', + '-fooo -baar', 'all', false, - array('-foo', '-bar'), + array('-fooo', '-baar'), array(), ), ); From db2297827d92f09e52cd2dd6f6b4613e0c210fe7 Mon Sep 17 00:00:00 2001 From: Dhruv Date: Mon, 12 Nov 2012 16:25:44 +0100 Subject: [PATCH 07/18] [ticket/11174] negation queries do not return false negation queries are split into words too and returns false in mysql search backend PHPBB3-11174 --- tests/search/mysql_test.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/search/mysql_test.php b/tests/search/mysql_test.php index 44043da40d..56cce24c09 100644 --- a/tests/search/mysql_test.php +++ b/tests/search/mysql_test.php @@ -121,14 +121,14 @@ class phpbb_search_mysql_test extends phpbb_database_test_case array( '-fooo', 'all', - false, - null, + true, + array('-fooo'), array(), ), array( '-fooo -baar', 'all', - false, + true, array('-fooo', '-baar'), array(), ), From c725b02df8a6d8838f6e0b7d82eaa8ec8f1839d1 Mon Sep 17 00:00:00 2001 From: Dhruv Date: Mon, 12 Nov 2012 17:05:07 +0100 Subject: [PATCH 08/18] [ticket/11174] include utf_tools in postgres search backend PHPBB3-11174 --- phpBB/includes/search/fulltext_postgres.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/phpBB/includes/search/fulltext_postgres.php b/phpBB/includes/search/fulltext_postgres.php index 08f64735b6..2880610655 100644 --- a/phpBB/includes/search/fulltext_postgres.php +++ b/phpBB/includes/search/fulltext_postgres.php @@ -121,6 +121,14 @@ class phpbb_search_fulltext_postgres extends phpbb_search_base } } + /** + * Load the UTF tools + */ + if (!function_exists('utf8_strlen')) + { + include($phpbb_root_path . 'includes/utf/utf_tools.' . $phpEx); + } + $error = false; } From d308ee8a25ec6dc7b6e23cb78e14bd1d75f05a91 Mon Sep 17 00:00:00 2001 From: Dhruv Date: Mon, 12 Nov 2012 17:06:05 +0100 Subject: [PATCH 09/18] [ticket/11174] add unit tests for postgres search backend PHPBB3-11174 --- tests/search/postgres_test.php | 155 +++++++++++++++++++++++++++++++++ 1 file changed, 155 insertions(+) create mode 100644 tests/search/postgres_test.php diff --git a/tests/search/postgres_test.php b/tests/search/postgres_test.php new file mode 100644 index 0000000000..e20e6789b7 --- /dev/null +++ b/tests/search/postgres_test.php @@ -0,0 +1,155 @@ +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; + + // set config values + $config['fulltext_postgres_min_word_len'] = 4; + $config['fulltext_postgres_max_word_len'] = 254; + + if(!function_exists('phpbb_search_wrapper')) + { + include('mysql_test.' . $phpEx); + } + + $this->db = $this->new_dbal(); + $error = null; + $class = phpbb_search_wrapper('phpbb_search_fulltext_postgres'); + $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 + // 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()); + } + + public function assert_array_content_equals($one, $two) + { + 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); + } + } +} From 3ed4fc437e2a88638d705b8f4cab23eacf39fe3c Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Tue, 27 Nov 2012 08:08:34 -0500 Subject: [PATCH 10/18] [ticket/11174] Move assertion definition to base class. PHPBB3-11174 --- tests/search/native_test.php | 16 ---------------- .../test_framework/phpbb_database_test_case.php | 16 ++++++++++++++++ 2 files changed, 16 insertions(+), 16 deletions(-) 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); - } - } } diff --git a/tests/test_framework/phpbb_database_test_case.php b/tests/test_framework/phpbb_database_test_case.php index 75a3c0944b..514619687a 100644 --- a/tests/test_framework/phpbb_database_test_case.php +++ b/tests/test_framework/phpbb_database_test_case.php @@ -141,4 +141,20 @@ abstract class phpbb_database_test_case extends PHPUnit_Extensions_Database_Test { return $matches[1] . strtoupper($matches[2]) . $matches[3]; } + + 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); + } + } } From 04480ec4ae8435db37072cd976e7591a3abaafb9 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Tue, 27 Nov 2012 08:09:35 -0500 Subject: [PATCH 11/18] [ticket/11174] Delete copy pasting. PHPBB3-11174 --- tests/search/mysql_test.php | 14 -------------- tests/search/postgres_test.php | 14 -------------- 2 files changed, 28 deletions(-) diff --git a/tests/search/mysql_test.php b/tests/search/mysql_test.php index 56cce24c09..5e5d5c9846 100644 --- a/tests/search/mysql_test.php +++ b/tests/search/mysql_test.php @@ -149,18 +149,4 @@ class phpbb_search_mysql_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) - { - 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); - } - } } diff --git a/tests/search/postgres_test.php b/tests/search/postgres_test.php index e20e6789b7..d3172c6457 100644 --- a/tests/search/postgres_test.php +++ b/tests/search/postgres_test.php @@ -138,18 +138,4 @@ class phpbb_search_postgres_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) - { - 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); - } - } } From a5900a6b1120a3d062e6d51579872bf940b13dcb Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Tue, 27 Nov 2012 08:18:39 -0500 Subject: [PATCH 12/18] [ticket/11174] Extract phpbb_search_test_case. PHPBB3-11174 --- tests/search/native_test.php | 21 ++------------ .../test_framework/phpbb_search_test_case.php | 28 +++++++++++++++++++ 2 files changed, 31 insertions(+), 18 deletions(-) create mode 100644 tests/test_framework/phpbb_search_test_case.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); } diff --git a/tests/test_framework/phpbb_search_test_case.php b/tests/test_framework/phpbb_search_test_case.php new file mode 100644 index 0000000000..8b378186df --- /dev/null +++ b/tests/test_framework/phpbb_search_test_case.php @@ -0,0 +1,28 @@ +must_contain_ids; } + public function get_must_not_contain_ids() { return \$this->must_not_contain_ids; } +} + "; + eval($code); + } + return $wrapped; + } +} From 4d1486b08cd2f1e75527ed3b54664361934258a7 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Tue, 27 Nov 2012 08:22:43 -0500 Subject: [PATCH 13/18] [ticket/11174] Eliminate search wrapper copy pasting. PHPBB3-11174 --- tests/search/mysql_test.php | 20 +++---------------- tests/search/postgres_test.php | 11 ++++------ .../test_framework/phpbb_search_test_case.php | 1 + 3 files changed, 8 insertions(+), 24 deletions(-) diff --git a/tests/search/mysql_test.php b/tests/search/mysql_test.php index 5e5d5c9846..cf89facc83 100644 --- a/tests/search/mysql_test.php +++ b/tests/search/mysql_test.php @@ -7,23 +7,9 @@ * */ -function phpbb_search_wrapper($class) -{ - $wrapped = $class . '_wrapper'; - if (!class_exists($wrapped)) - { - $code = " -class $wrapped extends $class -{ - public function get_split_words() { return \$this->split_words; } -} - "; - eval($code); - } - return $wrapped; -} +require_once dirname(__FILE__) . '/../test_framework/phpbb_search_test_case.php'; -class phpbb_search_mysql_test extends phpbb_database_test_case +class phpbb_search_mysql_test extends phpbb_search_test_case { protected $db; protected $search; @@ -48,7 +34,7 @@ class phpbb_search_mysql_test extends phpbb_database_test_case $this->db = $this->new_dbal(); $error = null; - $class = phpbb_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); } diff --git a/tests/search/postgres_test.php b/tests/search/postgres_test.php index d3172c6457..211755c7db 100644 --- a/tests/search/postgres_test.php +++ b/tests/search/postgres_test.php @@ -7,7 +7,9 @@ * */ -class phpbb_search_postgres_test extends phpbb_database_test_case +require_once dirname(__FILE__) . '/../test_framework/phpbb_search_test_case.php'; + +class phpbb_search_postgres_test extends phpbb_search_test_case { protected $db; protected $search; @@ -30,14 +32,9 @@ class phpbb_search_postgres_test extends phpbb_database_test_case $config['fulltext_postgres_min_word_len'] = 4; $config['fulltext_postgres_max_word_len'] = 254; - if(!function_exists('phpbb_search_wrapper')) - { - include('mysql_test.' . $phpEx); - } - $this->db = $this->new_dbal(); $error = null; - $class = phpbb_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); } diff --git a/tests/test_framework/phpbb_search_test_case.php b/tests/test_framework/phpbb_search_test_case.php index 8b378186df..418d352c17 100644 --- a/tests/test_framework/phpbb_search_test_case.php +++ b/tests/test_framework/phpbb_search_test_case.php @@ -19,6 +19,7 @@ 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; } + public function get_split_words() { return \$this->split_words; } } "; eval($code); From 4b5e90a2bd7380d67a0aba053b2788ce7d9abd89 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Tue, 27 Nov 2012 08:45:48 -0500 Subject: [PATCH 14/18] [ticket/11174] Empty fixture for when we don't need any data. PHPBB3-11174 --- tests/fixtures/empty.xml | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 tests/fixtures/empty.xml diff --git a/tests/fixtures/empty.xml b/tests/fixtures/empty.xml new file mode 100644 index 0000000000..96eb1ab483 --- /dev/null +++ b/tests/fixtures/empty.xml @@ -0,0 +1,5 @@ + + + +
+
From 0c430a1f9365260502b7b293b32a34f97edeada4 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Tue, 27 Nov 2012 08:46:15 -0500 Subject: [PATCH 15/18] [ticket/11174] These tests do not need posts fixtures. PHPBB3-11174 --- tests/search/mysql_test.php | 2 +- tests/search/postgres_test.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/search/mysql_test.php b/tests/search/mysql_test.php index cf89facc83..097e46d855 100644 --- a/tests/search/mysql_test.php +++ b/tests/search/mysql_test.php @@ -16,7 +16,7 @@ class phpbb_search_mysql_test extends phpbb_search_test_case public function getDataSet() { - return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/posts.xml'); + return $this->createXMLDataSet(dirname(__FILE__) . '/../fixtures/empty.xml'); } protected function setUp() diff --git a/tests/search/postgres_test.php b/tests/search/postgres_test.php index 211755c7db..b6dc5ef1a3 100644 --- a/tests/search/postgres_test.php +++ b/tests/search/postgres_test.php @@ -16,7 +16,7 @@ class phpbb_search_postgres_test extends phpbb_search_test_case public function getDataSet() { - return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/posts.xml'); + return $this->createXMLDataSet(dirname(__FILE__) . '/../fixtures/empty.xml'); } protected function setUp() From cb2d029abf2d4857fa462f46af21728afde3cd28 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Tue, 27 Nov 2012 08:56:32 -0500 Subject: [PATCH 16/18] [ticket/11174] Drop needless teardown functions. PHPBB3-11174 --- tests/search/mysql_test.php | 5 ----- tests/search/native_test.php | 5 ----- tests/search/postgres_test.php | 5 ----- 3 files changed, 15 deletions(-) diff --git a/tests/search/mysql_test.php b/tests/search/mysql_test.php index 097e46d855..9f38ef2ef6 100644 --- a/tests/search/mysql_test.php +++ b/tests/search/mysql_test.php @@ -38,11 +38,6 @@ class phpbb_search_mysql_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( 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( diff --git a/tests/search/postgres_test.php b/tests/search/postgres_test.php index b6dc5ef1a3..b8c9bcfbe9 100644 --- a/tests/search/postgres_test.php +++ b/tests/search/postgres_test.php @@ -38,11 +38,6 @@ class phpbb_search_postgres_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( From 7dcb03faf1e9c2374f5d5fd36e3b01e8f0315d73 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Tue, 27 Nov 2012 09:06:56 -0500 Subject: [PATCH 17/18] [ticket/11174] Delete more copy pasting. PHPBB3-11174 --- tests/search/common_test_case.php | 106 ++++++++++++++++++++++++++++++ tests/search/mysql_test.php | 97 +-------------------------- tests/search/postgres_test.php | 97 +-------------------------- 3 files changed, 110 insertions(+), 190 deletions(-) create mode 100644 tests/search/common_test_case.php diff --git a/tests/search/common_test_case.php b/tests/search/common_test_case.php new file mode 100644 index 0000000000..dd04f7048c --- /dev/null +++ b/tests/search/common_test_case.php @@ -0,0 +1,106 @@ +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()); + } +} diff --git a/tests/search/mysql_test.php b/tests/search/mysql_test.php index 9f38ef2ef6..e1538bc81c 100644 --- a/tests/search/mysql_test.php +++ b/tests/search/mysql_test.php @@ -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 $search; @@ -37,97 +37,4 @@ class phpbb_search_mysql_test extends phpbb_search_test_case $class = self::get_search_wrapper('phpbb_search_fulltext_mysql'); $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()); - } } diff --git a/tests/search/postgres_test.php b/tests/search/postgres_test.php index b8c9bcfbe9..6a65e6bf8f 100644 --- a/tests/search/postgres_test.php +++ b/tests/search/postgres_test.php @@ -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 $search; @@ -37,97 +37,4 @@ class phpbb_search_postgres_test extends phpbb_search_test_case $class = self::get_search_wrapper('phpbb_search_fulltext_postgres'); $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()); - } } From 79237b60b6b234e10f14cbcb00691b5e4374fd04 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Tue, 27 Nov 2012 10:24:31 -0500 Subject: [PATCH 18/18] [ticket/11174] Global $cache is a cache service instance. PHPBB3-11174 --- tests/search/mysql_test.php | 2 +- tests/search/native_test.php | 2 +- tests/search/postgres_test.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/search/mysql_test.php b/tests/search/mysql_test.php index e1538bc81c..3ba3915714 100644 --- a/tests/search/mysql_test.php +++ b/tests/search/mysql_test.php @@ -26,7 +26,7 @@ class phpbb_search_mysql_test extends phpbb_search_common_test_case parent::setUp(); // dbal uses cache - $cache = new phpbb_cache_driver_null; + $cache = new phpbb_cache_service(new phpbb_cache_driver_null); // set config values $config['fulltext_mysql_min_word_len'] = 4; 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; diff --git a/tests/search/postgres_test.php b/tests/search/postgres_test.php index 6a65e6bf8f..9c77e0c09e 100644 --- a/tests/search/postgres_test.php +++ b/tests/search/postgres_test.php @@ -26,7 +26,7 @@ class phpbb_search_postgres_test extends phpbb_search_common_test_case parent::setUp(); // dbal uses cache - $cache = new phpbb_cache_driver_null; + $cache = new phpbb_cache_service(new phpbb_cache_driver_null); // set config values $config['fulltext_postgres_min_word_len'] = 4;