From 5bc03c961023e01dfb74eff296b12b6169d705e4 Mon Sep 17 00:00:00 2001 From: brunoais Date: Sun, 15 Mar 2015 17:16:53 +0000 Subject: [feature/sql-bool-builder] Prepare testing class PHPBB3-13652 --- tests/dbal/boolean_processor_test.php | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 tests/dbal/boolean_processor_test.php (limited to 'tests/dbal/boolean_processor_test.php') diff --git a/tests/dbal/boolean_processor_test.php b/tests/dbal/boolean_processor_test.php new file mode 100644 index 0000000000..f80e12ad4f --- /dev/null +++ b/tests/dbal/boolean_processor_test.php @@ -0,0 +1,24 @@ + +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ + +require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php'; +require_once dirname(__FILE__) . '/../../phpBB/includes/utf/utf_tools.php'; + +class phpbb_boolean_processor_test extends phpbb_database_test_case +{ + public function getDataSet() + { + return $this->createXMLDataSet(dirname(__FILE__).'/fixtures/boolean_processor.xml'); + } + +} -- cgit v1.2.1 From d10a0ca1ca48d8d348922a806f14f63360179d50 Mon Sep 17 00:00:00 2001 From: brunoais Date: Sun, 15 Mar 2015 20:25:55 +0000 Subject: [feature/sql-bool-builder] test_triple_and_with_is_null PHPBB3-13652 --- tests/dbal/boolean_processor_test.php | 37 +++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'tests/dbal/boolean_processor_test.php') diff --git a/tests/dbal/boolean_processor_test.php b/tests/dbal/boolean_processor_test.php index f80e12ad4f..652cb1164b 100644 --- a/tests/dbal/boolean_processor_test.php +++ b/tests/dbal/boolean_processor_test.php @@ -21,4 +21,41 @@ class phpbb_boolean_processor_test extends phpbb_database_test_case return $this->createXMLDataSet(dirname(__FILE__).'/fixtures/boolean_processor.xml'); } + public function test_triple_and_with_is_null() + { + $db = $this->new_dbal(); + + $db->sql_return_on_error(true); + + $sql_ary = array( + 'SELECT' => 'u.username', + 'FROM' => array( + 'phpbb_users' => 'u', + 'phpbb_user_group' => 'ug', + ), + 'LEFT_JOIN' => array( + array( + 'FROM' => array( + 'phpbb_banlist' => 'b', + ), + 'ON' => 'u.user_id = b.ban_userid', + ), + ), + 'WHERE' => array('AND', + array('ug.group_id', '=', 1), + array('u.user_id', '=', 'ug.user_id'), + array('b.ban_id', 'IS', NULL), + ), + 'ORDER_BY' => 'u.username', + ); + $sql = $db->sql_build_query('SELECT', $sql_ary); + $result = $db->sql_query($sql); + + $db->sql_return_on_error(false); + + $this->assertEquals(array( + array('username' => 'helper'), + array('username' => 'mass email'), + ), $db->sql_fetchrowset($result)); + } } -- cgit v1.2.1 From 5d3b22c21e2c31dce80d3a4c84fd5a0a326f944f Mon Sep 17 00:00:00 2001 From: brunoais Date: Sun, 15 Mar 2015 20:26:24 +0000 Subject: [feature/sql-bool-builder] test_double_and_with_not_of_and PHPBB3-13652 --- tests/dbal/boolean_processor_test.php | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'tests/dbal/boolean_processor_test.php') diff --git a/tests/dbal/boolean_processor_test.php b/tests/dbal/boolean_processor_test.php index 652cb1164b..40efbe8d5a 100644 --- a/tests/dbal/boolean_processor_test.php +++ b/tests/dbal/boolean_processor_test.php @@ -21,6 +21,37 @@ class phpbb_boolean_processor_test extends phpbb_database_test_case return $this->createXMLDataSet(dirname(__FILE__).'/fixtures/boolean_processor.xml'); } + public function test_double_and_with_not_of_or() + { + $db = $this->new_dbal(); + + $db->sql_return_on_error(true); + + $sql_ary = array( + 'SELECT' => 'u.user_id', + 'FROM' => array( + 'phpbb_users' => 'u', + 'phpbb_user_group' => 'ug', + ), + 'WHERE' => array('AND', + array('NOT', + array('OR', + array('ug.group_id', '=', 1), + array('ug.group_id', '=', 2), + ), + ), + array('u.user_id', '=', 'ug.user_id'), + ), + 'ORDER_BY' => 'u.user_id', + ); + $sql = $db->sql_build_query('SELECT', $sql_ary); + $result = $db->sql_query($sql); + + $db->sql_return_on_error(false); + + $this->assertEquals(array(), $db->sql_fetchrowset($result)); + } + public function test_triple_and_with_is_null() { $db = $this->new_dbal(); -- cgit v1.2.1 From e6eab35a641b8795f8a277e28d3eab0937d64b6d Mon Sep 17 00:00:00 2001 From: brunoais Date: Sun, 15 Mar 2015 20:29:48 +0000 Subject: [feature/sql-bool-builder] test_triple_and_with_in PHPBB3-13652 --- tests/dbal/boolean_processor_test.php | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'tests/dbal/boolean_processor_test.php') diff --git a/tests/dbal/boolean_processor_test.php b/tests/dbal/boolean_processor_test.php index 40efbe8d5a..081a5ac64d 100644 --- a/tests/dbal/boolean_processor_test.php +++ b/tests/dbal/boolean_processor_test.php @@ -21,6 +21,37 @@ class phpbb_boolean_processor_test extends phpbb_database_test_case return $this->createXMLDataSet(dirname(__FILE__).'/fixtures/boolean_processor.xml'); } + public function test_triple_and_with_in() + { + $db = $this->new_dbal(); + + $db->sql_return_on_error(true); + + $sql_ary = array( + 'SELECT' => 'u.user_id', + 'FROM' => array( + 'phpbb_users' => 'u', + 'phpbb_user_group' => 'ug', + ), + 'WHERE' => array('AND', + array('ug.user_id', 'IN', array(1, 2, 3, 4)), + array('ug.group_id', '=', 1), + array('u.user_id', '=', 'ug.user_id'), + ), + 'ORDER_BY' => 'u.user_id', + ); + $sql = $db->sql_build_query('SELECT', $sql_ary); + $result = $db->sql_query($sql); + + $db->sql_return_on_error(false); + + $this->assertEquals(array( + array('user_id' => '1'), + array('user_id' => '2'), + array('user_id' => '3'), + ), $db->sql_fetchrowset($result), + } + public function test_double_and_with_not_of_or() { $db = $this->new_dbal(); -- cgit v1.2.1 From 5f63d685f6b0235badd7723e477754833595d045 Mon Sep 17 00:00:00 2001 From: brunoais Date: Sun, 15 Mar 2015 20:30:04 +0000 Subject: [feature/sql-bool-builder] test_and_of_or_of_and PHPBB3-13652 --- tests/dbal/boolean_processor_test.php | 46 +++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) (limited to 'tests/dbal/boolean_processor_test.php') diff --git a/tests/dbal/boolean_processor_test.php b/tests/dbal/boolean_processor_test.php index 081a5ac64d..716e524e9b 100644 --- a/tests/dbal/boolean_processor_test.php +++ b/tests/dbal/boolean_processor_test.php @@ -21,6 +21,52 @@ class phpbb_boolean_processor_test extends phpbb_database_test_case return $this->createXMLDataSet(dirname(__FILE__).'/fixtures/boolean_processor.xml'); } + public function test_and_of_or_of_and() + { + $db = $this->new_dbal(); + + $db->sql_return_on_error(true); + + $sql_ary = array( + 'SELECT' => 'u.user_id', + 'FROM' => array( + 'phpbb_users' => 'u', + 'phpbb_user_group' => 'ug', + ), + 'LEFT_JOIN' => array( + array( + 'FROM' => array( + 'phpbb_banlist' => 'b', + ), + 'ON' => 'u.user_id = b.ban_userid', + ), + ), + 'WHERE' => array('AND', + array('OR', + array('AND', + array('ug.user_id', 'IN', array(1, 2, 3, 4)), + array('ug.group_id', '=', 2), + ), + array('AND', + array('ug.group_id', '=', 1), + array('b.ban_id', 'IS NOT', NULL), + ), + ), + array('u.user_id', '=', 'ug.user_id'), + ), + 'ORDER_BY' => 'u.user_id', + ); + $sql = $db->sql_build_query('SELECT', $sql_ary); + $result = $db->sql_query($sql); + + $db->sql_return_on_error(false); + + $this->assertEquals(array( + array('user_id' => '2'), + array('user_id' => '4'), + ), $db->sql_fetchrowset($result)); + } + public function test_triple_and_with_in() { $db = $this->new_dbal(); -- cgit v1.2.1 From 1754f1832d563074e767f236cbc315eb41c7b7b9 Mon Sep 17 00:00:00 2001 From: brunoais Date: Sun, 15 Mar 2015 20:30:35 +0000 Subject: [feature/sql-bool-builder] test_single_in PHPBB3-13652 --- tests/dbal/boolean_processor_test.php | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'tests/dbal/boolean_processor_test.php') diff --git a/tests/dbal/boolean_processor_test.php b/tests/dbal/boolean_processor_test.php index 716e524e9b..e615edbdcd 100644 --- a/tests/dbal/boolean_processor_test.php +++ b/tests/dbal/boolean_processor_test.php @@ -21,6 +21,32 @@ class phpbb_boolean_processor_test extends phpbb_database_test_case return $this->createXMLDataSet(dirname(__FILE__).'/fixtures/boolean_processor.xml'); } + public function test_single_in() + { + $db = $this->new_dbal(); + + $db->sql_return_on_error(true); + + $sql_ary = array( + 'SELECT' => 'u.user_id', + 'FROM' => array( + 'phpbb_users' => 'u', + ), + 'WHERE' => array('u.user_id', 'IN', array(3,4,5)), + 'ORDER_BY' => 'u.user_id', + ); + $sql = $db->sql_build_query('SELECT', $sql_ary); + $result = $db->sql_query($sql); + + $db->sql_return_on_error(false); + + $this->assertEquals(array( + array('user_id' => '3'), + array('user_id' => '4'), + array('user_id' => '5'), + ), $db->sql_fetchrowset($result)); + } + public function test_and_of_or_of_and() { $db = $this->new_dbal(); -- cgit v1.2.1 From d60d596f25b0c31526f469cf56c4cdb1e3698bda Mon Sep 17 00:00:00 2001 From: brunoais Date: Sun, 15 Mar 2015 20:31:19 +0000 Subject: [feature/sql-bool-builder] test_single_not_in PHPBB3-13652 --- tests/dbal/boolean_processor_test.php | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'tests/dbal/boolean_processor_test.php') diff --git a/tests/dbal/boolean_processor_test.php b/tests/dbal/boolean_processor_test.php index e615edbdcd..a94085b77d 100644 --- a/tests/dbal/boolean_processor_test.php +++ b/tests/dbal/boolean_processor_test.php @@ -21,6 +21,32 @@ class phpbb_boolean_processor_test extends phpbb_database_test_case return $this->createXMLDataSet(dirname(__FILE__).'/fixtures/boolean_processor.xml'); } + public function test_single_not_in() + { + $db = $this->new_dbal(); + + $db->sql_return_on_error(true); + + $sql_ary = array( + 'SELECT' => 'u.user_id', + 'FROM' => array( + 'phpbb_users' => 'u', + ), + 'WHERE' => array('u.user_id', 'NOT_IN', array(3,4,5)), + 'ORDER_BY' => 'u.user_id', + ); + $sql = $db->sql_build_query('SELECT', $sql_ary); + $result = $db->sql_query($sql); + + $db->sql_return_on_error(false); + + $this->assertEquals(array( + array('user_id' => '1'), + array('user_id' => '2'), + array('user_id' => '6'), + ), $db->sql_fetchrowset($result)); + } + public function test_single_in() { $db = $this->new_dbal(); -- cgit v1.2.1 From c342531872938797f52f3e6bdfa966d81e3253ce Mon Sep 17 00:00:00 2001 From: brunoais Date: Sun, 15 Mar 2015 20:31:32 +0000 Subject: [feature/sql-bool-builder] test_single_like PHPBB3-13652 --- tests/dbal/boolean_processor_test.php | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'tests/dbal/boolean_processor_test.php') diff --git a/tests/dbal/boolean_processor_test.php b/tests/dbal/boolean_processor_test.php index a94085b77d..8f57a8e452 100644 --- a/tests/dbal/boolean_processor_test.php +++ b/tests/dbal/boolean_processor_test.php @@ -21,6 +21,31 @@ class phpbb_boolean_processor_test extends phpbb_database_test_case return $this->createXMLDataSet(dirname(__FILE__).'/fixtures/boolean_processor.xml'); } + public function test_single_like() + { + $db = $this->new_dbal(); + + $db->sql_return_on_error(true); + + $sql_ary = array( + 'SELECT' => 'u.user_id', + 'FROM' => array( + 'phpbb_users' => 'u', + ), + 'WHERE' => array('u.username_clean', 'LIKE', 'gr' . $db->get_any_char()), + 'ORDER_BY' => 'u.user_id', + ); + $sql = $db->sql_build_query('SELECT', $sql_ary); + $result = $db->sql_query($sql); + + $db->sql_return_on_error(false); + + $this->assertEquals(array( + array('user_id' => '4'), + array('user_id' => '5'), + ), $db->sql_fetchrowset($result)); + } + public function test_single_not_in() { $db = $this->new_dbal(); -- cgit v1.2.1 From bc6ea5796dcdabd57ff9e6f7640d724df67254c5 Mon Sep 17 00:00:00 2001 From: brunoais Date: Sun, 15 Mar 2015 20:31:46 +0000 Subject: [feature/sql-bool-builder] test_single_not_like PHPBB3-13652 --- tests/dbal/boolean_processor_test.php | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'tests/dbal/boolean_processor_test.php') diff --git a/tests/dbal/boolean_processor_test.php b/tests/dbal/boolean_processor_test.php index 8f57a8e452..2ba3f6ff22 100644 --- a/tests/dbal/boolean_processor_test.php +++ b/tests/dbal/boolean_processor_test.php @@ -21,6 +21,33 @@ class phpbb_boolean_processor_test extends phpbb_database_test_case return $this->createXMLDataSet(dirname(__FILE__).'/fixtures/boolean_processor.xml'); } + public function test_single_not_like() + { + $db = $this->new_dbal(); + + $db->sql_return_on_error(true); + + $sql_ary = array( + 'SELECT' => 'u.user_id', + 'FROM' => array( + 'phpbb_users' => 'u', + ), + 'WHERE' => array('u.username_clean', 'NOT_LIKE', 'gr' . $db->get_any_char()), + 'ORDER_BY' => 'u.user_id', + ); + $sql = $db->sql_build_query('SELECT', $sql_ary); + $result = $db->sql_query($sql); + + $db->sql_return_on_error(false); + + $this->assertEquals(array( + array('user_id' => '1'), + array('user_id' => '2'), + array('user_id' => '3'), + array('user_id' => '6'), + ), $db->sql_fetchrowset($result)); + } + public function test_single_like() { $db = $this->new_dbal(); -- cgit v1.2.1 From 576eaa0cff7a5e051aa672034e596e90f65fc1a9 Mon Sep 17 00:00:00 2001 From: brunoais Date: Mon, 16 Mar 2015 11:31:51 +0000 Subject: [feature/sql-bool-builder] Adding the IS operator to predicted operators PHPBB3-13652 --- tests/dbal/boolean_processor_test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests/dbal/boolean_processor_test.php') diff --git a/tests/dbal/boolean_processor_test.php b/tests/dbal/boolean_processor_test.php index 2ba3f6ff22..5e044797f8 100644 --- a/tests/dbal/boolean_processor_test.php +++ b/tests/dbal/boolean_processor_test.php @@ -153,7 +153,7 @@ class phpbb_boolean_processor_test extends phpbb_database_test_case ), array('AND', array('ug.group_id', '=', 1), - array('b.ban_id', 'IS NOT', NULL), + array('b.ban_id', 'IS_NOT', NULL), ), ), array('u.user_id', '=', 'ug.user_id'), -- cgit v1.2.1 From fe132f19e8d5c821fff936d208fbb981aa6ac92d Mon Sep 17 00:00:00 2001 From: brunoais Date: Sun, 15 Mar 2015 21:01:00 +0000 Subject: [feature/sql-bool-builder] Improved tests output to show the SQL error. PHPBB3-13652 --- tests/dbal/boolean_processor_test.php | 47 +++++++++++++++++++++++++++++------ 1 file changed, 40 insertions(+), 7 deletions(-) (limited to 'tests/dbal/boolean_processor_test.php') diff --git a/tests/dbal/boolean_processor_test.php b/tests/dbal/boolean_processor_test.php index 5e044797f8..8662485ac8 100644 --- a/tests/dbal/boolean_processor_test.php +++ b/tests/dbal/boolean_processor_test.php @@ -45,7 +45,11 @@ class phpbb_boolean_processor_test extends phpbb_database_test_case array('user_id' => '2'), array('user_id' => '3'), array('user_id' => '6'), - ), $db->sql_fetchrowset($result)); + ), $db->sql_fetchrowset($result), + ($result === false) ? + "SQL ERROR:
" . var_export($sql, true) . "
" . $db->sql_error() : + var_export($sql, true) . ' ' . var_export($result, true) + ); } public function test_single_like() @@ -70,7 +74,11 @@ class phpbb_boolean_processor_test extends phpbb_database_test_case $this->assertEquals(array( array('user_id' => '4'), array('user_id' => '5'), - ), $db->sql_fetchrowset($result)); + ), $db->sql_fetchrowset($result), + ($result === false) ? + "SQL ERROR:
" . var_export($sql, true) . "
" . $db->sql_error() : + var_export($sql, true) . ' ' . var_export($result, true) + ); } public function test_single_not_in() @@ -96,7 +104,11 @@ class phpbb_boolean_processor_test extends phpbb_database_test_case array('user_id' => '1'), array('user_id' => '2'), array('user_id' => '6'), - ), $db->sql_fetchrowset($result)); + ), $db->sql_fetchrowset($result), + ($result === false) ? + "SQL ERROR:
" . var_export($sql, true) . "
" . $db->sql_error() : + var_export($sql, true) . ' ' . var_export($result, true) + ); } public function test_single_in() @@ -122,7 +134,11 @@ class phpbb_boolean_processor_test extends phpbb_database_test_case array('user_id' => '3'), array('user_id' => '4'), array('user_id' => '5'), - ), $db->sql_fetchrowset($result)); + ), $db->sql_fetchrowset($result), + ($result === false) ? + "SQL ERROR:
" . var_export($sql, true) . "
" . $db->sql_error() : + var_export($sql, true) . ' ' . var_export($result, true) + ); } public function test_and_of_or_of_and() @@ -168,7 +184,11 @@ class phpbb_boolean_processor_test extends phpbb_database_test_case $this->assertEquals(array( array('user_id' => '2'), array('user_id' => '4'), - ), $db->sql_fetchrowset($result)); + ), $db->sql_fetchrowset($result), + ($result === false) ? + "SQL ERROR:
" . var_export($sql, true) . "
" . $db->sql_error() : + var_export($sql, true) . ' ' . var_export($result, true) + ); } public function test_triple_and_with_in() @@ -200,6 +220,11 @@ class phpbb_boolean_processor_test extends phpbb_database_test_case array('user_id' => '2'), array('user_id' => '3'), ), $db->sql_fetchrowset($result), + ($result === false) ? + "SQL ERROR:
" . var_export($sql, true) . "
" . $db->sql_error() : + var_export($sql, true) . ' ' . var_export($result, true) + ); + } public function test_double_and_with_not_of_or() @@ -230,7 +255,11 @@ class phpbb_boolean_processor_test extends phpbb_database_test_case $db->sql_return_on_error(false); - $this->assertEquals(array(), $db->sql_fetchrowset($result)); + $this->assertEquals(array(), $db->sql_fetchrowset($result), + ($result === false) ? + "SQL ERROR:
" . var_export($sql, true) . "
" . $db->sql_error() : + var_export($sql, true) . ' ' . var_export($result, true) + ); } public function test_triple_and_with_is_null() @@ -268,6 +297,10 @@ class phpbb_boolean_processor_test extends phpbb_database_test_case $this->assertEquals(array( array('username' => 'helper'), array('username' => 'mass email'), - ), $db->sql_fetchrowset($result)); + ), $db->sql_fetchrowset($result), + ($result === false) ? + "SQL ERROR:
" . var_export($sql, true) . "
" . $db->sql_error() : + var_export($sql, true) . ' ' . var_export($result, true) + ); } } -- cgit v1.2.1