Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
96.64% |
230 / 238 |
|
11.11% |
1 / 9 |
CRAP | |
0.00% |
0 / 1 |
| phpbb_boolean_processor_test | |
96.64% |
230 / 238 |
|
11.11% |
1 / 9 |
17 | |
0.00% |
0 / 1 |
| getDataSet | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| test_single_not_like | |
95.65% |
22 / 23 |
|
0.00% |
0 / 1 |
2 | |||
| test_single_like | |
95.24% |
20 / 21 |
|
0.00% |
0 / 1 |
2 | |||
| test_single_not_in | |
95.45% |
21 / 22 |
|
0.00% |
0 / 1 |
2 | |||
| test_single_in | |
95.45% |
21 / 22 |
|
0.00% |
0 / 1 |
2 | |||
| test_and_of_or_of_and | |
98.04% |
50 / 51 |
|
0.00% |
0 / 1 |
2 | |||
| test_triple_and_with_in | |
96.55% |
28 / 29 |
|
0.00% |
0 / 1 |
2 | |||
| test_double_and_with_not_of_or | |
96.97% |
32 / 33 |
|
0.00% |
0 / 1 |
2 | |||
| test_triple_and_with_is_null | |
97.22% |
35 / 36 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * |
| 4 | * This file is part of the phpBB Forum Software package. |
| 5 | * |
| 6 | * @copyright (c) phpBB Limited <https://www.phpbb.com> |
| 7 | * @license GNU General Public License, version 2 (GPL-2.0) |
| 8 | * |
| 9 | * For full copyright and license information, please see |
| 10 | * the docs/CREDITS.txt file. |
| 11 | * |
| 12 | */ |
| 13 | |
| 14 | class phpbb_boolean_processor_test extends phpbb_database_test_case |
| 15 | { |
| 16 | public function getDataSet() |
| 17 | { |
| 18 | return $this->createXMLDataSet(__DIR__.'/fixtures/boolean_processor.xml'); |
| 19 | } |
| 20 | |
| 21 | public function test_single_not_like() |
| 22 | { |
| 23 | $db = $this->new_dbal(); |
| 24 | |
| 25 | $db->sql_return_on_error(true); |
| 26 | |
| 27 | $sql_ary = array( |
| 28 | 'SELECT' => 'u.user_id', |
| 29 | 'FROM' => array( |
| 30 | 'phpbb_users' => 'u', |
| 31 | ), |
| 32 | 'WHERE' => array('u.username_clean', 'NOT_LIKE', 'gr' . $db->get_any_char()), |
| 33 | 'ORDER_BY' => 'u.user_id', |
| 34 | ); |
| 35 | $sql = $db->sql_build_query('SELECT', $sql_ary); |
| 36 | $result = $db->sql_query($sql); |
| 37 | |
| 38 | $db->sql_return_on_error(false); |
| 39 | |
| 40 | $this->assertEquals(array( |
| 41 | array('user_id' => '1'), |
| 42 | array('user_id' => '2'), |
| 43 | array('user_id' => '3'), |
| 44 | array('user_id' => '6'), |
| 45 | ), $db->sql_fetchrowset($result), |
| 46 | ($result === false) ? |
| 47 | "SQL ERROR:<br>" . var_export($sql, true) . "<br>" . $db->sql_error() : |
| 48 | var_export($sql, true) . ' ' . var_export($result, true) |
| 49 | ); |
| 50 | } |
| 51 | |
| 52 | public function test_single_like() |
| 53 | { |
| 54 | $db = $this->new_dbal(); |
| 55 | |
| 56 | $db->sql_return_on_error(true); |
| 57 | |
| 58 | $sql_ary = array( |
| 59 | 'SELECT' => 'u.user_id', |
| 60 | 'FROM' => array( |
| 61 | 'phpbb_users' => 'u', |
| 62 | ), |
| 63 | 'WHERE' => array('u.username_clean', 'LIKE', 'gr' . $db->get_any_char()), |
| 64 | 'ORDER_BY' => 'u.user_id', |
| 65 | ); |
| 66 | $sql = $db->sql_build_query('SELECT', $sql_ary); |
| 67 | $result = $db->sql_query($sql); |
| 68 | |
| 69 | $db->sql_return_on_error(false); |
| 70 | |
| 71 | $this->assertEquals(array( |
| 72 | array('user_id' => '4'), |
| 73 | array('user_id' => '5'), |
| 74 | ), $db->sql_fetchrowset($result), |
| 75 | ($result === false) ? |
| 76 | "SQL ERROR:<br>" . var_export($sql, true) . "<br>" . $db->sql_error() : |
| 77 | var_export($sql, true) . ' ' . var_export($result, true) |
| 78 | ); |
| 79 | } |
| 80 | |
| 81 | public function test_single_not_in() |
| 82 | { |
| 83 | $db = $this->new_dbal(); |
| 84 | |
| 85 | $db->sql_return_on_error(true); |
| 86 | |
| 87 | $sql_ary = array( |
| 88 | 'SELECT' => 'u.user_id', |
| 89 | 'FROM' => array( |
| 90 | 'phpbb_users' => 'u', |
| 91 | ), |
| 92 | 'WHERE' => array('u.user_id', 'NOT_IN', array(3,4,5)), |
| 93 | 'ORDER_BY' => 'u.user_id', |
| 94 | ); |
| 95 | $sql = $db->sql_build_query('SELECT', $sql_ary); |
| 96 | $result = $db->sql_query($sql); |
| 97 | |
| 98 | $db->sql_return_on_error(false); |
| 99 | |
| 100 | $this->assertEquals(array( |
| 101 | array('user_id' => '1'), |
| 102 | array('user_id' => '2'), |
| 103 | array('user_id' => '6'), |
| 104 | ), $db->sql_fetchrowset($result), |
| 105 | ($result === false) ? |
| 106 | "SQL ERROR:<br>" . var_export($sql, true) . "<br>" . $db->sql_error() : |
| 107 | var_export($sql, true) . ' ' . var_export($result, true) |
| 108 | ); |
| 109 | } |
| 110 | |
| 111 | public function test_single_in() |
| 112 | { |
| 113 | $db = $this->new_dbal(); |
| 114 | |
| 115 | $db->sql_return_on_error(true); |
| 116 | |
| 117 | $sql_ary = array( |
| 118 | 'SELECT' => 'u.user_id', |
| 119 | 'FROM' => array( |
| 120 | 'phpbb_users' => 'u', |
| 121 | ), |
| 122 | 'WHERE' => array('u.user_id', 'IN', array(3,4,5)), |
| 123 | 'ORDER_BY' => 'u.user_id', |
| 124 | ); |
| 125 | $sql = $db->sql_build_query('SELECT', $sql_ary); |
| 126 | $result = $db->sql_query($sql); |
| 127 | |
| 128 | $db->sql_return_on_error(false); |
| 129 | |
| 130 | $this->assertEquals(array( |
| 131 | array('user_id' => '3'), |
| 132 | array('user_id' => '4'), |
| 133 | array('user_id' => '5'), |
| 134 | ), $db->sql_fetchrowset($result), |
| 135 | ($result === false) ? |
| 136 | "SQL ERROR:<br>" . var_export($sql, true) . "<br>" . $db->sql_error() : |
| 137 | var_export($sql, true) . ' ' . var_export($result, true) |
| 138 | ); |
| 139 | } |
| 140 | |
| 141 | public function test_and_of_or_of_and() |
| 142 | { |
| 143 | $db = $this->new_dbal(); |
| 144 | |
| 145 | $db->sql_return_on_error(true); |
| 146 | |
| 147 | $sql_ary = array( |
| 148 | 'SELECT' => 'u.user_id', |
| 149 | 'FROM' => array( |
| 150 | 'phpbb_users' => 'u', |
| 151 | 'phpbb_user_group' => 'ug', |
| 152 | ), |
| 153 | 'LEFT_JOIN' => array( |
| 154 | array( |
| 155 | 'FROM' => array( |
| 156 | 'phpbb_bans' => 'b', |
| 157 | ), |
| 158 | 'ON' => 'b.ban_item = ' . $db->cast_expr_to_string('u.user_id'), |
| 159 | ), |
| 160 | ), |
| 161 | 'WHERE' => array('AND', |
| 162 | array( |
| 163 | array('OR', |
| 164 | array( |
| 165 | array('AND', |
| 166 | array( |
| 167 | array('ug.user_id', 'IN', array(1, 2, 3, 4)), |
| 168 | array('ug.group_id', '=', 2), |
| 169 | ), |
| 170 | ), |
| 171 | array('AND', |
| 172 | array( |
| 173 | array('ug.group_id', '=', 1), |
| 174 | array('b.ban_id', 'IS_NOT', NULL), |
| 175 | array('b.ban_mode', '=', "'user'"), |
| 176 | ), |
| 177 | ), |
| 178 | ), |
| 179 | ), |
| 180 | array('u.user_id', '=', 'ug.user_id'), |
| 181 | ), |
| 182 | ), |
| 183 | 'ORDER_BY' => 'u.user_id', |
| 184 | ); |
| 185 | $sql = $db->sql_build_query('SELECT', $sql_ary); |
| 186 | $result = $db->sql_query($sql); |
| 187 | |
| 188 | $db->sql_return_on_error(false); |
| 189 | |
| 190 | $this->assertEquals(array( |
| 191 | array('user_id' => '2'), |
| 192 | array('user_id' => '4'), |
| 193 | ), $db->sql_fetchrowset($result), |
| 194 | ($result === false) ? |
| 195 | "SQL ERROR:<br>" . var_export($sql, true) . "<br>" . $db->sql_error() : |
| 196 | var_export($sql, true) . ' ' . var_export($result, true) |
| 197 | ); |
| 198 | } |
| 199 | |
| 200 | public function test_triple_and_with_in() |
| 201 | { |
| 202 | $db = $this->new_dbal(); |
| 203 | |
| 204 | $db->sql_return_on_error(true); |
| 205 | |
| 206 | $sql_ary = array( |
| 207 | 'SELECT' => 'u.user_id', |
| 208 | 'FROM' => array( |
| 209 | 'phpbb_users' => 'u', |
| 210 | 'phpbb_user_group' => 'ug', |
| 211 | ), |
| 212 | 'WHERE' => array('AND', |
| 213 | array( |
| 214 | array('ug.user_id', 'IN', array(1, 2, 3, 4)), |
| 215 | array('ug.group_id', '=', 1), |
| 216 | array('u.user_id', '=', 'ug.user_id'), |
| 217 | ), |
| 218 | ), |
| 219 | 'ORDER_BY' => 'u.user_id', |
| 220 | ); |
| 221 | $sql = $db->sql_build_query('SELECT', $sql_ary); |
| 222 | $result = $db->sql_query($sql); |
| 223 | |
| 224 | $db->sql_return_on_error(false); |
| 225 | |
| 226 | $this->assertEquals(array( |
| 227 | array('user_id' => '1'), |
| 228 | array('user_id' => '2'), |
| 229 | array('user_id' => '3'), |
| 230 | ), $db->sql_fetchrowset($result), |
| 231 | ($result === false) ? |
| 232 | "SQL ERROR:<br>" . var_export($sql, true) . "<br>" . $db->sql_error() : |
| 233 | var_export($sql, true) . ' ' . var_export($result, true) |
| 234 | ); |
| 235 | |
| 236 | } |
| 237 | |
| 238 | public function test_double_and_with_not_of_or() |
| 239 | { |
| 240 | $db = $this->new_dbal(); |
| 241 | |
| 242 | $db->sql_return_on_error(true); |
| 243 | |
| 244 | $sql_ary = array( |
| 245 | 'SELECT' => 'u.user_id', |
| 246 | 'FROM' => array( |
| 247 | 'phpbb_users' => 'u', |
| 248 | 'phpbb_user_group' => 'ug', |
| 249 | ), |
| 250 | 'WHERE' => array('AND', |
| 251 | array( |
| 252 | array('NOT', |
| 253 | array( |
| 254 | array('OR', |
| 255 | array( |
| 256 | array('ug.group_id', '=', 1), |
| 257 | array('ug.group_id', '=', 2), |
| 258 | ), |
| 259 | ), |
| 260 | ), |
| 261 | ), |
| 262 | array('u.user_id', '=', 'ug.user_id'), |
| 263 | ), |
| 264 | ), |
| 265 | 'ORDER_BY' => 'u.user_id', |
| 266 | ); |
| 267 | $sql = $db->sql_build_query('SELECT', $sql_ary); |
| 268 | $result = $db->sql_query($sql); |
| 269 | |
| 270 | $db->sql_return_on_error(false); |
| 271 | |
| 272 | $this->assertEquals(array(), $db->sql_fetchrowset($result), |
| 273 | ($result === false) ? |
| 274 | "SQL ERROR:<br>" . var_export($sql, true) . "<br>" . $db->sql_error() : |
| 275 | var_export($sql, true) . ' ' . var_export($result, true) |
| 276 | ); |
| 277 | } |
| 278 | |
| 279 | public function test_triple_and_with_is_null() |
| 280 | { |
| 281 | $db = $this->new_dbal(); |
| 282 | |
| 283 | $db->sql_return_on_error(true); |
| 284 | |
| 285 | $sql_ary = array( |
| 286 | 'SELECT' => 'u.username', |
| 287 | 'FROM' => array( |
| 288 | 'phpbb_users' => 'u', |
| 289 | 'phpbb_user_group' => 'ug', |
| 290 | ), |
| 291 | 'LEFT_JOIN' => array( |
| 292 | array( |
| 293 | 'FROM' => array( |
| 294 | 'phpbb_bans' => 'b', |
| 295 | ), |
| 296 | 'ON' => 'b.ban_item = ' . $db->cast_expr_to_string('u.user_id'), |
| 297 | ), |
| 298 | ), |
| 299 | 'WHERE' => array('AND', |
| 300 | array( |
| 301 | array('ug.group_id', '=', 1), |
| 302 | array('u.user_id', '=', 'ug.user_id'), |
| 303 | array('b.ban_id', 'IS', NULL), |
| 304 | ), |
| 305 | ), |
| 306 | 'ORDER_BY' => 'u.username', |
| 307 | ); |
| 308 | $sql = $db->sql_build_query('SELECT', $sql_ary); |
| 309 | $result = $db->sql_query($sql); |
| 310 | |
| 311 | $db->sql_return_on_error(false); |
| 312 | |
| 313 | $this->assertEquals(array( |
| 314 | array('username' => 'helper'), |
| 315 | array('username' => 'mass email'), |
| 316 | ), $db->sql_fetchrowset($result), |
| 317 | ($result === false) ? |
| 318 | "SQL ERROR:<br>" . var_export($sql, true) . "<br>" . $db->sql_error() : |
| 319 | var_export($sql, true) . ' ' . var_export($result, true) |
| 320 | ); |
| 321 | } |
| 322 | } |