Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
12.93% |
41 / 317 |
|
66.67% |
2 / 3 |
CRAP | |
0.00% |
0 / 1 |
| phpbb_log_function_view_log_test | |
12.93% |
41 / 317 |
|
66.67% |
2 / 3 |
21.50 | |
0.00% |
0 / 1 |
| getDataSet | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| view_log_function_data | |
0.00% |
0 / 276 |
|
0.00% |
0 / 1 |
12 | |||
| test_view_log_function | |
100.00% |
40 / 40 |
|
100.00% |
1 / 1 |
1 | |||
| 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 | require_once __DIR__ . '/../../phpBB/includes/functions_admin.php'; |
| 15 | require_once __DIR__ . '/../mock/user.php'; |
| 16 | require_once __DIR__ . '/../mock/cache.php'; |
| 17 | |
| 18 | class phpbb_log_function_view_log_test extends phpbb_database_test_case |
| 19 | { |
| 20 | public function getDataSet() |
| 21 | { |
| 22 | return $this->createXMLDataSet(__DIR__ . '/fixtures/full_log.xml'); |
| 23 | } |
| 24 | |
| 25 | public static function view_log_function_data() |
| 26 | { |
| 27 | global $phpEx, $phpbb_dispatcher; |
| 28 | $phpbb_dispatcher = new phpbb_mock_event_dispatcher(); |
| 29 | |
| 30 | $expected_data_sets = array( |
| 31 | 1 => array( |
| 32 | 'id' => 1, |
| 33 | |
| 34 | 'reportee_id' => 0, |
| 35 | 'reportee_username' => '', |
| 36 | 'reportee_username_full'=> '', |
| 37 | |
| 38 | 'user_id' => 1, |
| 39 | 'username' => 'Anonymous', |
| 40 | 'username_full' => '<span class="username">Anonymous</span>', |
| 41 | |
| 42 | 'ip' => '127.0.0.1', |
| 43 | 'time' => 1, |
| 44 | 'forum_id' => 0, |
| 45 | 'topic_id' => 0, |
| 46 | 'post_id' => 0, |
| 47 | |
| 48 | 'viewforum' => '', |
| 49 | 'action' => 'LOG_INSTALL_INSTALLED 3.1.0-dev', |
| 50 | ), |
| 51 | 2 => array( |
| 52 | 'id' => 2, |
| 53 | |
| 54 | 'reportee_id' => 0, |
| 55 | 'reportee_username' => '', |
| 56 | 'reportee_username_full'=> '', |
| 57 | |
| 58 | 'user_id' => 1, |
| 59 | 'username' => 'Anonymous', |
| 60 | 'username_full' => '<span class="username">Anonymous</span>', |
| 61 | |
| 62 | 'ip' => '127.0.0.1', |
| 63 | 'time' => 1, |
| 64 | 'forum_id' => 0, |
| 65 | 'topic_id' => 0, |
| 66 | 'post_id' => 0, |
| 67 | |
| 68 | 'viewforum' => '', |
| 69 | 'action' => '{LOG KEY NOT EXISTS}<br />additional_data', |
| 70 | ), |
| 71 | 3 => array( |
| 72 | 'id' => 3, |
| 73 | |
| 74 | 'reportee_id' => 0, |
| 75 | 'reportee_username' => '', |
| 76 | 'reportee_username_full'=> '', |
| 77 | |
| 78 | 'user_id' => 1, |
| 79 | 'username' => 'Anonymous', |
| 80 | 'username_full' => '<span class="username">Anonymous</span>', |
| 81 | |
| 82 | 'ip' => '127.0.0.1', |
| 83 | 'time' => 1, |
| 84 | 'forum_id' => 0, |
| 85 | 'topic_id' => 0, |
| 86 | 'post_id' => 0, |
| 87 | |
| 88 | 'viewforum' => '', |
| 89 | 'action' => '{LOG CRITICAL}<br />critical data', |
| 90 | ), |
| 91 | 4 => array( |
| 92 | 'id' => 4, |
| 93 | |
| 94 | 'reportee_id' => 0, |
| 95 | 'reportee_username' => '', |
| 96 | 'reportee_username_full'=> '', |
| 97 | |
| 98 | 'user_id' => 1, |
| 99 | 'username' => 'Anonymous', |
| 100 | 'username_full' => '<span class="username">Anonymous</span>', |
| 101 | |
| 102 | 'ip' => '127.0.0.1', |
| 103 | 'time' => 1, |
| 104 | 'forum_id' => 12, |
| 105 | 'topic_id' => 34, |
| 106 | 'post_id' => 0, |
| 107 | |
| 108 | 'viewforum' => '', |
| 109 | 'action' => '{LOG MOD}', |
| 110 | 'viewtopic' => '', |
| 111 | 'viewpost' => '', |
| 112 | 'viewlogs' => '', |
| 113 | ), |
| 114 | 5 => array( |
| 115 | 'id' => 5, |
| 116 | |
| 117 | 'reportee_id' => 0, |
| 118 | 'reportee_username' => '', |
| 119 | 'reportee_username_full'=> '', |
| 120 | |
| 121 | 'user_id' => 1, |
| 122 | 'username' => 'Anonymous', |
| 123 | 'username_full' => '<span class="username">Anonymous</span>', |
| 124 | |
| 125 | 'ip' => '127.0.0.1', |
| 126 | 'time' => 1, |
| 127 | 'forum_id' => 12, |
| 128 | 'topic_id' => 45, |
| 129 | 'post_id' => 0, |
| 130 | |
| 131 | 'viewforum' => '', |
| 132 | 'action' => '{LOG MOD}', |
| 133 | 'viewtopic' => '', |
| 134 | 'viewpost' => '', |
| 135 | 'viewlogs' => '', |
| 136 | ), |
| 137 | 6 => array( |
| 138 | 'id' => 6, |
| 139 | |
| 140 | 'reportee_id' => 0, |
| 141 | 'reportee_username' => '', |
| 142 | 'reportee_username_full'=> '', |
| 143 | |
| 144 | 'user_id' => 1, |
| 145 | 'username' => 'Anonymous', |
| 146 | 'username_full' => '<span class="username">Anonymous</span>', |
| 147 | |
| 148 | 'ip' => '127.0.0.1', |
| 149 | 'time' => 1, |
| 150 | 'forum_id' => 23, |
| 151 | 'topic_id' => 56, |
| 152 | 'post_id' => 0, |
| 153 | |
| 154 | 'viewforum' => append_sid("phpBB/viewforum.$phpEx", 'f=23'), |
| 155 | 'action' => '{LOG MOD}', |
| 156 | 'viewtopic' => append_sid("phpBB/viewtopic.$phpEx", 't=56'), |
| 157 | 'viewpost' => '', |
| 158 | 'viewlogs' => append_sid("phpBB/mcp.$phpEx", 'i=logs&mode=topic_logs&t=56'), |
| 159 | ), |
| 160 | 7 => array( |
| 161 | 'id' => 7, |
| 162 | |
| 163 | 'reportee_id' => 0, |
| 164 | 'reportee_username' => '', |
| 165 | 'reportee_username_full'=> '', |
| 166 | |
| 167 | 'user_id' => 1, |
| 168 | 'username' => 'Anonymous', |
| 169 | 'username_full' => '<span class="username">Anonymous</span>', |
| 170 | |
| 171 | 'ip' => '127.0.0.1', |
| 172 | 'time' => 1, |
| 173 | 'forum_id' => 12, |
| 174 | 'topic_id' => 45, |
| 175 | 'post_id' => 0, |
| 176 | |
| 177 | 'viewforum' => '', |
| 178 | 'action' => 'LOG_MOD2', |
| 179 | 'viewtopic' => '', |
| 180 | 'viewpost' => '', |
| 181 | 'viewlogs' => '', |
| 182 | ), |
| 183 | 8 => array( |
| 184 | 'id' => 8, |
| 185 | |
| 186 | 'reportee_id' => 2, |
| 187 | 'reportee_username' => 'admin', |
| 188 | 'reportee_username_full'=> '<span class="username">admin</span>', |
| 189 | |
| 190 | 'user_id' => 1, |
| 191 | 'username' => 'Anonymous', |
| 192 | 'username_full' => '<span class="username">Anonymous</span>', |
| 193 | |
| 194 | 'ip' => '127.0.0.1', |
| 195 | 'time' => 1, |
| 196 | 'forum_id' => 0, |
| 197 | 'topic_id' => 0, |
| 198 | 'post_id' => 0, |
| 199 | |
| 200 | 'viewforum' => '', |
| 201 | 'action' => 'LOG_USER admin', |
| 202 | ), |
| 203 | 9 => array( |
| 204 | 'id' => 9, |
| 205 | |
| 206 | 'reportee_id' => 1, |
| 207 | 'reportee_username' => 'Anonymous', |
| 208 | 'reportee_username_full'=> '<span class="username">Anonymous</span>', |
| 209 | |
| 210 | 'user_id' => 1, |
| 211 | 'username' => 'Anonymous', |
| 212 | 'username_full' => '<span class="username">Anonymous</span>', |
| 213 | |
| 214 | 'ip' => '127.0.0.1', |
| 215 | 'time' => 1, |
| 216 | 'forum_id' => 0, |
| 217 | 'topic_id' => 0, |
| 218 | 'post_id' => 0, |
| 219 | |
| 220 | 'viewforum' => '', |
| 221 | 'action' => 'LOG_USER guest', |
| 222 | ), |
| 223 | 10 => array( |
| 224 | 'id' => 10, |
| 225 | |
| 226 | 'reportee_id' => 0, |
| 227 | 'reportee_username' => '', |
| 228 | 'reportee_username_full'=> '', |
| 229 | |
| 230 | 'user_id' => 1, |
| 231 | 'username' => 'Anonymous', |
| 232 | 'username_full' => '<span class="username">Anonymous</span>', |
| 233 | |
| 234 | 'ip' => '127.0.0.1', |
| 235 | 'time' => 1, |
| 236 | 'forum_id' => 0, |
| 237 | 'topic_id' => 0, |
| 238 | 'post_id' => 0, |
| 239 | |
| 240 | 'viewforum' => '', |
| 241 | 'action' => 'LOG_SINGULAR_PLURAL 2', |
| 242 | ), |
| 243 | 11 => array( |
| 244 | 'id' => 11, |
| 245 | |
| 246 | 'reportee_id' => 0, |
| 247 | 'reportee_username' => '', |
| 248 | 'reportee_username_full'=> '', |
| 249 | |
| 250 | 'user_id' => 1, |
| 251 | 'username' => 'Anonymous', |
| 252 | 'username_full' => '<span class="username">Anonymous</span>', |
| 253 | |
| 254 | 'ip' => '127.0.0.1', |
| 255 | 'time' => 1, |
| 256 | 'forum_id' => 15, |
| 257 | 'topic_id' => 3, |
| 258 | 'post_id' => 0, |
| 259 | |
| 260 | 'viewforum' => '', |
| 261 | 'action' => 'LOG_MOD3 guest ', |
| 262 | 'viewtopic' => '', |
| 263 | 'viewpost' => '', |
| 264 | 'viewlogs' => '', |
| 265 | ), |
| 266 | ); |
| 267 | |
| 268 | $test_cases = array( |
| 269 | /** |
| 270 | * Case documentation |
| 271 | array( |
| 272 | // Array of datasets that should be in $log after running the function |
| 273 | 'expected' => array(5, 7), |
| 274 | // Offset that will be returned from the function |
| 275 | 'expected_returned' => 0, |
| 276 | // view_log parameters (see includes/functions_admin.php for docblock) |
| 277 | // $log is omitted! |
| 278 | 'mod', 5, 0, 12, 45, |
| 279 | ), |
| 280 | */ |
| 281 | array( |
| 282 | 'expected' => array(1, 2), |
| 283 | 'expected_returned' => 0, |
| 284 | 'admin', false, |
| 285 | ), |
| 286 | array( |
| 287 | 'expected' => array(1), |
| 288 | 'expected_returned' => 0, |
| 289 | 'admin', false, 1, |
| 290 | ), |
| 291 | array( |
| 292 | 'expected' => array(2), |
| 293 | 'expected_returned' => 1, |
| 294 | 'admin', false, 1, 1, |
| 295 | ), |
| 296 | array( |
| 297 | 'expected' => array(2), |
| 298 | 'expected_returned' => 1, |
| 299 | 'admin', 0, 1, 1, |
| 300 | ), |
| 301 | array( |
| 302 | 'expected' => array(2), |
| 303 | 'expected_returned' => 1, |
| 304 | 'admin', 0, 1, 5, |
| 305 | ), |
| 306 | array( |
| 307 | 'expected' => array(3), |
| 308 | 'expected_returned' => 0, |
| 309 | 'critical', false, |
| 310 | ), |
| 311 | array( |
| 312 | 'expected' => array(), |
| 313 | 'expected_returned' => null, |
| 314 | 'mode_does_not_exist', false, |
| 315 | ), |
| 316 | array( |
| 317 | 'expected' => array(4, 5, 7), |
| 318 | 'expected_returned' => 0, |
| 319 | 'mod', 0, 5, 0, 12, |
| 320 | ), |
| 321 | array( |
| 322 | 'expected' => array(5, 7), |
| 323 | 'expected_returned' => 0, |
| 324 | 'mod', 0, 5, 0, 12, 45, |
| 325 | ), |
| 326 | array( |
| 327 | 'expected' => array(6), |
| 328 | 'expected_returned' => 0, |
| 329 | 'mod', 0, 5, 0, 23, |
| 330 | ), |
| 331 | array( |
| 332 | 'expected' => array(8), |
| 333 | 'expected_returned' => 0, |
| 334 | 'user', 0, 5, 0, 0, 0, 2, |
| 335 | ), |
| 336 | array( |
| 337 | 'expected' => array(8, 9, 10), |
| 338 | 'expected_returned' => 0, |
| 339 | 'users', 0, |
| 340 | ), |
| 341 | array( |
| 342 | 'expected' => array(1), |
| 343 | 'expected_returned' => 0, |
| 344 | 'admin', false, 5, 0, 0, 0, 0, 0, 'l.log_id ASC', 'install', |
| 345 | ), |
| 346 | array( |
| 347 | 'expected' => array(10), |
| 348 | 'expected_returned' => 0, |
| 349 | 'user', false, 5, 0, 0, 0, 0, 0, 'l.log_id ASC', 'plural', |
| 350 | ), |
| 351 | array( |
| 352 | 'expected' => array(11), |
| 353 | 'expected_returned' => 0, |
| 354 | 'mod', 0, 5, 0, 15, 3, |
| 355 | ), |
| 356 | ); |
| 357 | |
| 358 | foreach ($test_cases as $case => $case_data) |
| 359 | { |
| 360 | foreach ($case_data['expected'] as $data_set => $expected) |
| 361 | { |
| 362 | $test_cases[$case]['expected'][$data_set] = $expected_data_sets[$expected]; |
| 363 | } |
| 364 | } |
| 365 | |
| 366 | return $test_cases; |
| 367 | } |
| 368 | |
| 369 | /** |
| 370 | * @dataProvider view_log_function_data |
| 371 | */ |
| 372 | public function test_view_log_function($expected, $expected_returned, $mode, $log_count, $limit = 5, $offset = 0, $forum_id = 0, $topic_id = 0, $user_id = 0, $limit_days = 0, $sort_by = 'l.log_id ASC', $keywords = '') |
| 373 | { |
| 374 | global $cache, $db, $user, $auth, $phpbb_log, $phpbb_dispatcher, $phpbb_root_path, $phpEx; |
| 375 | |
| 376 | $db = $this->new_dbal(); |
| 377 | $cache = new phpbb_mock_cache; |
| 378 | $phpbb_dispatcher = new phpbb_mock_event_dispatcher(); |
| 379 | |
| 380 | // Create auth mock |
| 381 | $auth = $this->createMock('\phpbb\auth\auth'); |
| 382 | $acl_get_map = array( |
| 383 | array('f_read', 23, true), |
| 384 | array('m_', 23, true), |
| 385 | ); |
| 386 | $acl_gets_map = array( |
| 387 | array('a_', 'm_', 23, true), |
| 388 | ); |
| 389 | |
| 390 | $auth->expects($this->any()) |
| 391 | ->method('acl_get') |
| 392 | ->with($this->stringContains('_'), |
| 393 | $this->anything()) |
| 394 | ->will($this->returnValueMap($acl_get_map)); |
| 395 | $auth->expects($this->any()) |
| 396 | ->method('acl_gets') |
| 397 | ->with($this->stringContains('_'), |
| 398 | $this->anything()) |
| 399 | ->will($this->returnValueMap($acl_gets_map)); |
| 400 | |
| 401 | $user = new phpbb_mock_user; |
| 402 | $user->optionset('viewcensors', false); |
| 403 | // Test sprintf() of the data into the action |
| 404 | $user->lang = array( |
| 405 | 'LOG_INSTALL_INSTALLED' => 'installed: %s', |
| 406 | 'LOG_USER' => 'User<br /> %s', |
| 407 | 'LOG_MOD2' => 'Mod2', |
| 408 | 'LOG_MOD3' => 'Mod3: %1$s, %2$s', |
| 409 | 'LOG_SINGULAR_PLURAL' => array( |
| 410 | 1 => 'singular', |
| 411 | 2 => 'plural (%d)', |
| 412 | ), |
| 413 | ); |
| 414 | $user->session_id = false; |
| 415 | $user->data['user_id'] = 10; |
| 416 | |
| 417 | $phpbb_log = new \phpbb\log\log($db, $user, $auth, $phpbb_dispatcher, $phpbb_root_path, 'adm/', $phpEx, LOG_TABLE); |
| 418 | |
| 419 | $log = array(); |
| 420 | $this->assertEquals($expected_returned, view_log($mode, $log, $log_count, $limit, $offset, $forum_id, $topic_id, $user_id, $limit_days, $sort_by, $keywords)); |
| 421 | |
| 422 | $this->assertEquals($expected, $log); |
| 423 | } |
| 424 | } |