Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
16.36% |
18 / 110 |
|
80.00% |
4 / 5 |
CRAP | |
0.00% |
0 / 1 |
| phpbb_log_delete_test | |
16.36% |
18 / 110 |
|
80.00% |
4 / 5 |
27.06 | |
0.00% |
0 / 1 |
| getDataSet | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| setUp | |
100.00% |
10 / 10 |
|
100.00% |
1 / 1 |
1 | |||
| log_delete_data | |
0.00% |
0 / 92 |
|
0.00% |
0 / 1 |
2 | |||
| test_log_delete | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
| get_ids | |
100.00% |
4 / 4 |
|
100.00% |
1 / 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_log_delete_test extends phpbb_database_test_case |
| 15 | { |
| 16 | protected $log; |
| 17 | |
| 18 | public function getDataSet() |
| 19 | { |
| 20 | return $this->createXMLDataSet(__DIR__ . '/fixtures/delete_log.xml'); |
| 21 | } |
| 22 | |
| 23 | protected function setUp(): void |
| 24 | { |
| 25 | global $phpbb_root_path, $phpEx, $db, $phpbb_dispatcher, $auth, $user; |
| 26 | |
| 27 | $db = $this->new_dbal(); |
| 28 | $phpbb_dispatcher = new phpbb_mock_event_dispatcher(); |
| 29 | $lang_loader = new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx); |
| 30 | $lang = new \phpbb\language\language($lang_loader); |
| 31 | $user = new \phpbb\user($lang, '\phpbb\datetime'); |
| 32 | $user->data['user_id'] = 1; |
| 33 | $auth = $this->createMock('\phpbb\auth\auth'); |
| 34 | |
| 35 | $this->log = new \phpbb\log\log($db, $user, $auth, $phpbb_dispatcher, $phpbb_root_path, 'adm/', $phpEx, LOG_TABLE); |
| 36 | |
| 37 | parent::setUp(); |
| 38 | } |
| 39 | |
| 40 | public static function log_delete_data() |
| 41 | { |
| 42 | return array( |
| 43 | array( |
| 44 | array(1, 2), |
| 45 | array(16), |
| 46 | array(), |
| 47 | 'admin', |
| 48 | false, |
| 49 | 0, |
| 50 | 0, |
| 51 | 0, |
| 52 | 0, |
| 53 | 0, |
| 54 | 0, |
| 55 | 'l.log_id ASC', |
| 56 | '', |
| 57 | ), |
| 58 | array( |
| 59 | array(11), |
| 60 | array(), |
| 61 | array('keywords' => 'guest'), |
| 62 | 'mod', |
| 63 | false, |
| 64 | 0, |
| 65 | 0, |
| 66 | 0, |
| 67 | 0, |
| 68 | 0, |
| 69 | 0, |
| 70 | 'l.log_id ASC', |
| 71 | 'guest', |
| 72 | ), |
| 73 | array( |
| 74 | array(4, 5, 7), |
| 75 | array(), |
| 76 | array('forum_id' => 12, 'user_id' => 1), |
| 77 | 'mod', |
| 78 | false, |
| 79 | 0, |
| 80 | 0, |
| 81 | 12, |
| 82 | 0, |
| 83 | 1, |
| 84 | 0, |
| 85 | 'l.log_id ASC', |
| 86 | '', |
| 87 | ), |
| 88 | array( |
| 89 | array(12, 13), |
| 90 | array(), |
| 91 | array('forum_id' => array('IN' => array(14, 13))), |
| 92 | 'mod', |
| 93 | false, |
| 94 | 0, |
| 95 | 0, |
| 96 | array(13, 14), |
| 97 | 0, |
| 98 | 0, |
| 99 | 0, |
| 100 | 'l.log_id ASC', |
| 101 | '', |
| 102 | ), |
| 103 | array( |
| 104 | array(3, 14, 15), |
| 105 | array(3), |
| 106 | array('user_id' => array('>', 1)), |
| 107 | 'critical', |
| 108 | false, |
| 109 | 0, |
| 110 | 0, |
| 111 | 0, |
| 112 | 0, |
| 113 | 0, |
| 114 | 0, |
| 115 | 'l.log_id ASC', |
| 116 | '', |
| 117 | ), |
| 118 | array( |
| 119 | array(3, 14, 15), |
| 120 | array(), |
| 121 | array('keywords' => ''), |
| 122 | 'critical', |
| 123 | false, |
| 124 | 0, |
| 125 | 0, |
| 126 | 0, |
| 127 | 0, |
| 128 | 0, |
| 129 | 0, |
| 130 | 'l.log_id ASC', |
| 131 | '', |
| 132 | ), |
| 133 | ); |
| 134 | } |
| 135 | |
| 136 | /** |
| 137 | * @dataProvider log_delete_data |
| 138 | */ |
| 139 | public function test_log_delete($expected_before, $expected_after, $delete_conditions, $mode, $count_logs, $limit, $offset, $forum_id, $topic_id, $user_id, $log_time, $sort_by, $keywords) |
| 140 | { |
| 141 | $this->assertSame($expected_before, $this->get_ids($this->log->get_logs($mode, $count_logs, $limit, $offset, $forum_id, $topic_id, $user_id, $log_time, $sort_by, $keywords)), 'before'); |
| 142 | $this->log->delete($mode, $delete_conditions); |
| 143 | $this->assertSame($expected_after, $this->get_ids($this->log->get_logs($mode, $count_logs, $limit, $offset, $forum_id, $topic_id, $user_id, $log_time, $sort_by, $keywords)), 'after'); |
| 144 | } |
| 145 | |
| 146 | public function get_ids($logs) |
| 147 | { |
| 148 | $ids = array(); |
| 149 | foreach ($logs as $log_entry) |
| 150 | { |
| 151 | $ids[] = (int) $log_entry['id']; |
| 152 | } |
| 153 | return $ids; |
| 154 | } |
| 155 | } |