1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
|
<?php
/**
*
* @package testing
* @copyright (c) 2014 phpBB Group
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/
require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php';
require_once dirname(__FILE__) . '/../../phpBB/includes/functions_user.php';
require_once dirname(__FILE__) . '/../../phpBB/includes/utf/utf_tools.php';
class phpbb_functions_user_delete_user_test extends phpbb_database_test_case
{
/** @var \phpbb\db\driver\driver_interface */
protected $db;
public function getDataSet()
{
return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/delete_user.xml');
}
protected function setUp()
{
parent::setUp();
global $cache, $config, $db, $phpbb_dispatcher, $phpbb_container;
$db = $this->db = $this->new_dbal();
$config = new \phpbb\config\config(array(
'load_online_time' => 5,
'search_type' => '\phpbb\search\fulltext_mysql',
));
$cache = new phpbb_mock_null_cache();
$phpbb_dispatcher = new phpbb_mock_event_dispatcher();
$phpbb_container = new phpbb_mock_container_builder();
$phpbb_container->set('notification_manager', new phpbb_mock_notification_manager());
$phpbb_container->set(
'auth.provider.db',
new phpbb_mock_auth_provider()
);
$provider_collection = new \phpbb\auth\provider_collection($phpbb_container, $config);
$provider_collection->add('auth.provider.db');
$phpbb_container->set(
'auth.provider_collection',
$provider_collection
);
}
public function first_last_post_data()
{
return array(
array(
'retain', false,
array(
array('post_id' => 1, 'poster_id' => ANONYMOUS, 'post_username' => ''),
array('post_id' => 2, 'poster_id' => ANONYMOUS, 'post_username' => 'Other'),
array('post_id' => 3, 'poster_id' => ANONYMOUS, 'post_username' => ''),
array('post_id' => 4, 'poster_id' => ANONYMOUS, 'post_username' => 'Other'),
),
array(
array(
'topic_id' => 1,
'topic_poster' => ANONYMOUS, 'topic_first_poster_name' => '', 'topic_first_poster_colour' => '',
'topic_last_poster_id' => ANONYMOUS, 'topic_last_poster_name' => '', 'topic_last_poster_colour' => '',
),
array(
'topic_id' => 2,
'topic_poster' => ANONYMOUS, 'topic_first_poster_name' => 'Other', 'topic_first_poster_colour' => '',
'topic_last_poster_id' => ANONYMOUS, 'topic_last_poster_name' => 'Other', 'topic_last_poster_colour' => '',
),
array(
'topic_id' => 3,
'topic_poster' => ANONYMOUS, 'topic_first_poster_name' => '', 'topic_first_poster_colour' => '',
'topic_last_poster_id' => ANONYMOUS, 'topic_last_poster_name' => '', 'topic_last_poster_colour' => '',
),
array(
'topic_id' => 4,
'topic_poster' => ANONYMOUS, 'topic_first_poster_name' => 'Other', 'topic_first_poster_colour' => '',
'topic_last_poster_id' => ANONYMOUS, 'topic_last_poster_name' => 'Other', 'topic_last_poster_colour' => '',
),
),
array(
array('forum_id' => 1, 'forum_last_poster_id' => ANONYMOUS, 'forum_last_poster_name' => '', 'forum_last_poster_colour' => ''),
array('forum_id' => 2, 'forum_last_poster_id' => ANONYMOUS, 'forum_last_poster_name' => 'Other', 'forum_last_poster_colour' => ''),
array('forum_id' => 3, 'forum_last_poster_id' => ANONYMOUS, 'forum_last_poster_name' => '', 'forum_last_poster_colour' => ''),
array('forum_id' => 4, 'forum_last_poster_id' => ANONYMOUS, 'forum_last_poster_name' => 'Other', 'forum_last_poster_colour' => ''),
),
),
array(
'remove', false,
array(
array('post_id' => 2, 'poster_id' => ANONYMOUS, 'post_username' => 'Other'),
array('post_id' => 4, 'poster_id' => ANONYMOUS, 'post_username' => 'Other'),
),
array(
array(
'topic_id' => 2,
'topic_poster' => ANONYMOUS, 'topic_first_poster_name' => 'Other', 'topic_first_poster_colour' => '',
'topic_last_poster_id' => ANONYMOUS, 'topic_last_poster_name' => 'Other', 'topic_last_poster_colour' => '',
),
array(
'topic_id' => 4,
'topic_poster' => ANONYMOUS, 'topic_first_poster_name' => 'Other', 'topic_first_poster_colour' => '',
'topic_last_poster_id' => ANONYMOUS, 'topic_last_poster_name' => 'Other', 'topic_last_poster_colour' => '',
),
),
array(
array('forum_id' => 1, 'forum_last_poster_id' => 0, 'forum_last_poster_name' => '', 'forum_last_poster_colour' => ''),
array('forum_id' => 2, 'forum_last_poster_id' => ANONYMOUS, 'forum_last_poster_name' => 'Other', 'forum_last_poster_colour' => ''),
array('forum_id' => 3, 'forum_last_poster_id' => 0, 'forum_last_poster_name' => '', 'forum_last_poster_colour' => ''),
array('forum_id' => 4, 'forum_last_poster_id' => ANONYMOUS, 'forum_last_poster_name' => 'Other', 'forum_last_poster_colour' => ''),
),
),
array(
'retain', true,
array(
array('post_id' => 1, 'poster_id' => ANONYMOUS, 'post_username' => 'Foobar'),
array('post_id' => 2, 'poster_id' => ANONYMOUS, 'post_username' => 'Other'),
array('post_id' => 3, 'poster_id' => ANONYMOUS, 'post_username' => 'Foobar'),
array('post_id' => 4, 'poster_id' => ANONYMOUS, 'post_username' => 'Other'),
),
array(
array(
'topic_id' => 1,
'topic_poster' => ANONYMOUS, 'topic_first_poster_name' => 'Foobar', 'topic_first_poster_colour' => '',
'topic_last_poster_id' => ANONYMOUS, 'topic_last_poster_name' => 'Foobar', 'topic_last_poster_colour' => '',
),
array(
'topic_id' => 2,
'topic_poster' => ANONYMOUS, 'topic_first_poster_name' => 'Other', 'topic_first_poster_colour' => '',
'topic_last_poster_id' => ANONYMOUS, 'topic_last_poster_name' => 'Other', 'topic_last_poster_colour' => '',
),
array(
'topic_id' => 3,
'topic_poster' => ANONYMOUS, 'topic_first_poster_name' => 'Foobar', 'topic_first_poster_colour' => '',
'topic_last_poster_id' => ANONYMOUS, 'topic_last_poster_name' => 'Foobar', 'topic_last_poster_colour' => '',
),
array(
'topic_id' => 4,
'topic_poster' => ANONYMOUS, 'topic_first_poster_name' => 'Other', 'topic_first_poster_colour' => '',
'topic_last_poster_id' => ANONYMOUS, 'topic_last_poster_name' => 'Other', 'topic_last_poster_colour' => '',
),
),
array(
array('forum_id' => 1, 'forum_last_poster_id' => ANONYMOUS, 'forum_last_poster_name' => 'Foobar', 'forum_last_poster_colour' => ''),
array('forum_id' => 2, 'forum_last_poster_id' => ANONYMOUS, 'forum_last_poster_name' => 'Other', 'forum_last_poster_colour' => ''),
array('forum_id' => 3, 'forum_last_poster_id' => ANONYMOUS, 'forum_last_poster_name' => 'Foobar', 'forum_last_poster_colour' => ''),
array('forum_id' => 4, 'forum_last_poster_id' => ANONYMOUS, 'forum_last_poster_name' => 'Other', 'forum_last_poster_colour' => ''),
),
),
array(
'remove', true,
array(
array('post_id' => 2, 'poster_id' => ANONYMOUS, 'post_username' => 'Other'),
array('post_id' => 4, 'poster_id' => ANONYMOUS, 'post_username' => 'Other'),
),
array(
array(
'topic_id' => 2,
'topic_poster' => ANONYMOUS, 'topic_first_poster_name' => 'Other', 'topic_first_poster_colour' => '',
'topic_last_poster_id' => ANONYMOUS, 'topic_last_poster_name' => 'Other', 'topic_last_poster_colour' => '',
),
array(
'topic_id' => 4,
'topic_poster' => ANONYMOUS, 'topic_first_poster_name' => 'Other', 'topic_first_poster_colour' => '',
'topic_last_poster_id' => ANONYMOUS, 'topic_last_poster_name' => 'Other', 'topic_last_poster_colour' => '',
),
),
array(
array('forum_id' => 1, 'forum_last_poster_id' => 0, 'forum_last_poster_name' => '', 'forum_last_poster_colour' => ''),
array('forum_id' => 2, 'forum_last_poster_id' => ANONYMOUS, 'forum_last_poster_name' => 'Other', 'forum_last_poster_colour' => ''),
array('forum_id' => 3, 'forum_last_poster_id' => 0, 'forum_last_poster_name' => '', 'forum_last_poster_colour' => ''),
array('forum_id' => 4, 'forum_last_poster_id' => ANONYMOUS, 'forum_last_poster_name' => 'Other', 'forum_last_poster_colour' => ''),
),
),
);
}
/**
* @dataProvider first_last_post_data
*/
public function test_first_last_post_info($mode, $retain_username, $expected_posts, $expected_topics, $expected_forums)
{
$this->assertFalse(user_delete($mode, 2, $retain_username));
$sql = 'SELECT post_id, poster_id, post_username
FROM ' . POSTS_TABLE . '
ORDER BY post_id ASC';
$result = $this->db->sql_query($sql);
$this->assertEquals($expected_posts, $this->db->sql_fetchrowset($result), 'Post table poster info is mismatching after deleting a user.');
$this->db->sql_freeresult($result);
$sql = 'SELECT topic_id, topic_poster, topic_first_poster_name, topic_first_poster_colour, topic_last_poster_id, topic_last_poster_name, topic_last_poster_colour
FROM ' . TOPICS_TABLE . '
ORDER BY topic_id ASC';
$result = $this->db->sql_query($sql);
$this->assertEquals($expected_topics, $this->db->sql_fetchrowset($result), 'Topic table first/last poster info is mismatching after deleting a user.');
$this->db->sql_freeresult($result);
$sql = 'SELECT forum_id, forum_last_poster_id, forum_last_poster_name, forum_last_poster_colour
FROM ' . FORUMS_TABLE . '
ORDER BY forum_id ASC';
$result = $this->db->sql_query($sql);
$this->assertEquals($expected_forums, $this->db->sql_fetchrowset($result), 'Forum table last poster info is mismatching after deleting a user.');
$this->db->sql_freeresult($result);
}
public function report_attachment_data()
{
return array(
array(
'retain',
array(
array('post_id' => 1, 'post_reported' => 1, 'post_edit_user' => 1, 'post_delete_user' => 1),
array('post_id' => 2, 'post_reported' => 1, 'post_edit_user' => 1, 'post_delete_user' => 1),
array('post_id' => 3, 'post_reported' => 0, 'post_edit_user' => 1, 'post_delete_user' => 1),
array('post_id' => 4, 'post_reported' => 0, 'post_edit_user' => 1, 'post_delete_user' => 1),
),
array(
array('report_id' => 1, 'post_id' => 1, 'user_id' => 1),
array('report_id' => 3, 'post_id' => 2, 'user_id' => 1),
),
array(
array('topic_id' => 1, 'topic_reported' => 1, 'topic_delete_user' => 1),
array('topic_id' => 2, 'topic_reported' => 1, 'topic_delete_user' => 1),
array('topic_id' => 3, 'topic_reported' => 0, 'topic_delete_user' => 1),
array('topic_id' => 4, 'topic_reported' => 0, 'topic_delete_user' => 1),
),
array(
array('attach_id' => 1, 'post_msg_id' => 1, 'poster_id' => 1),
array('attach_id' => 2, 'post_msg_id' => 2, 'poster_id' => 1),
array('attach_id' => 3, 'post_msg_id' => 0, 'poster_id' => 1), // TODO should be deleted: PHPBB3-13089
),
),
array(
'remove',
array(
array('post_id' => 2, 'post_reported' => 1, 'post_edit_user' => 1, 'post_delete_user' => 1),
array('post_id' => 4, 'post_reported' => 0, 'post_edit_user' => 1, 'post_delete_user' => 1),
),
array(
array('report_id' => 3, 'post_id' => 2, 'user_id' => 1),
),
array(
array('topic_id' => 2, 'topic_reported' => 1, 'topic_delete_user' => 1),
array('topic_id' => 4, 'topic_reported' => 0, 'topic_delete_user' => 1),
),
array(
array('attach_id' => 2, 'post_msg_id' => 2, 'poster_id' => 1),
array('attach_id' => 3, 'post_msg_id' => 0, 'poster_id' => 2), // TODO should be deleted: PHPBB3-13089
),
),
);
}
/**
* @dataProvider report_attachment_data
*/
public function test_report_attachment_info($mode, $expected_posts, $expected_reports, $expected_topics, $expected_attach)
{
$this->assertFalse(user_delete($mode, 2));
$sql = 'SELECT post_id, post_reported, post_edit_user, post_delete_user
FROM ' . POSTS_TABLE . '
ORDER BY post_id ASC';
$result = $this->db->sql_query($sql);
$this->assertEquals($expected_posts, $this->db->sql_fetchrowset($result), 'Post report status content is mismatching after deleting a user.');
$this->db->sql_freeresult($result);
$sql = 'SELECT report_id, post_id, user_id
FROM ' . REPORTS_TABLE . '
ORDER BY report_id ASC';
$result = $this->db->sql_query($sql);
$this->assertEquals($expected_reports, $this->db->sql_fetchrowset($result), 'Report table content is mismatching after deleting a user.');
$this->db->sql_freeresult($result);
$sql = 'SELECT topic_id, topic_reported, topic_delete_user
FROM ' . TOPICS_TABLE . '
ORDER BY topic_id ASC';
$result = $this->db->sql_query($sql);
$this->assertEquals($expected_topics, $this->db->sql_fetchrowset($result), 'Topic report status is mismatching after deleting a user.');
$this->db->sql_freeresult($result);
$sql = 'SELECT attach_id, post_msg_id, poster_id
FROM ' . ATTACHMENTS_TABLE . '
ORDER BY attach_id ASC';
$result = $this->db->sql_query($sql);
$this->assertEquals($expected_attach, $this->db->sql_fetchrowset($result), 'Attachment table content is mismatching after deleting a user.');
$this->db->sql_freeresult($result);
}
public function delete_data()
{
return array(
array(
'retain',
array(array('user_id' => 1, 'user_posts' => 4)),
array(array('user_id' => 1, 'zebra_id' => 3)),
array(array('ban_id' => 2), array('ban_id' => 3)),
array(array('session_id' => '12345678901234567890123456789013')),
array(
array('log_id' => 2, 'user_id' => 1, 'reportee_id' => 1),
array('log_id' => 3, 'user_id' => 1, 'reportee_id' => 1),
),
array(
array('msg_id' => 1, 'author_id' => 3, 'message_edit_user' => 3),
array('msg_id' => 2, 'author_id' => 1, 'message_edit_user' => 1),
),
),
array(
'remove',
array(array('user_id' => 1, 'user_posts' => 2)),
array(array('user_id' => 1, 'zebra_id' => 3)),
array(array('ban_id' => 2), array('ban_id' => 3)),
array(array('session_id' => '12345678901234567890123456789013')),
array(
array('log_id' => 2, 'user_id' => 1, 'reportee_id' => 1),
array('log_id' => 3, 'user_id' => 1, 'reportee_id' => 1),
),
array(
array('msg_id' => 1, 'author_id' => 3, 'message_edit_user' => 3),
array('msg_id' => 2, 'author_id' => 1, 'message_edit_user' => 1),
),
),
);
}
/**
* @dataProvider delete_data
*/
public function test_delete_data($mode, $expected_users, $expected_zebra, $expected_ban, $expected_sessions, $expected_logs, $expected_pms)
{
$this->assertFalse(user_delete($mode, 2));
$sql = 'SELECT user_id, user_posts
FROM ' . USERS_TABLE . '
ORDER BY user_id ASC';
$result = $this->db->sql_query($sql);
$this->assertEquals($expected_users, $this->db->sql_fetchrowset($result), 'User table content is mismatching after deleting a user.');
$this->db->sql_freeresult($result);
$sql = 'SELECT user_id, zebra_id
FROM ' . ZEBRA_TABLE . '
ORDER BY user_id ASC, zebra_id ASC';
$result = $this->db->sql_query($sql);
$this->assertEquals($expected_zebra, $this->db->sql_fetchrowset($result), 'Zebra table content is mismatching after deleting a user.');
$this->db->sql_freeresult($result);
$sql = 'SELECT ban_id
FROM ' . BANLIST_TABLE . '
ORDER BY ban_id ASC';
$result = $this->db->sql_query($sql);
$this->assertEquals($expected_ban, $this->db->sql_fetchrowset($result), 'Ban table content is mismatching after deleting a user.');
$this->db->sql_freeresult($result);
$sql = 'SELECT session_id
FROM ' . SESSIONS_TABLE . '
ORDER BY session_id ASC';
$result = $this->db->sql_query($sql);
$this->assertEquals($expected_sessions, $this->db->sql_fetchrowset($result), 'Session table content is mismatching after deleting a user.');
$this->db->sql_freeresult($result);
$sql = 'SELECT log_id, user_id, reportee_id
FROM ' . LOG_TABLE . '
ORDER BY log_id ASC';
$result = $this->db->sql_query($sql);
$this->assertEquals($expected_logs, $this->db->sql_fetchrowset($result), 'Log table content is mismatching after deleting a user.');
$this->db->sql_freeresult($result);
$sql = 'SELECT msg_id, author_id, message_edit_user
FROM ' . PRIVMSGS_TABLE . '
ORDER BY msg_id ASC';
$result = $this->db->sql_query($sql);
$this->assertEquals($expected_pms, $this->db->sql_fetchrowset($result), 'Private messages table content is mismatching after deleting a user.');
$this->db->sql_freeresult($result);
}
public function delete_user_id_data()
{
return array(
array(
'retain',
array(
USER_GROUP_TABLE,
TOPICS_WATCH_TABLE,
FORUMS_WATCH_TABLE,
ACL_USERS_TABLE,
TOPICS_TRACK_TABLE,
TOPICS_POSTED_TABLE,
FORUMS_TRACK_TABLE,
PROFILE_FIELDS_DATA_TABLE,
MODERATOR_CACHE_TABLE,
DRAFTS_TABLE,
BOOKMARKS_TABLE,
SESSIONS_KEYS_TABLE,
PRIVMSGS_FOLDER_TABLE,
PRIVMSGS_RULES_TABLE,
),
),
array(
'remove',
array(
USER_GROUP_TABLE,
TOPICS_WATCH_TABLE,
FORUMS_WATCH_TABLE,
ACL_USERS_TABLE,
TOPICS_TRACK_TABLE,
TOPICS_POSTED_TABLE,
FORUMS_TRACK_TABLE,
PROFILE_FIELDS_DATA_TABLE,
MODERATOR_CACHE_TABLE,
DRAFTS_TABLE,
BOOKMARKS_TABLE,
SESSIONS_KEYS_TABLE,
PRIVMSGS_FOLDER_TABLE,
PRIVMSGS_RULES_TABLE,
),
),
);
}
/**
* @dataProvider delete_user_id_data
*/
public function test_delete_user_id_data($mode, $cleaned_tables)
{
$this->assertFalse(user_delete($mode, 2));
foreach ($cleaned_tables as $table)
{
$sql = 'SELECT user_id
FROM ' . $table . '
WHERE user_id = 2';
$result = $this->db->sql_query($sql);
$this->assertFalse($this->db->sql_fetchfield('user_id'), 'Found data for deleted user in table: ' . $table);
$this->db->sql_freeresult($result);
$sql = 'SELECT user_id
FROM ' . $table . '
WHERE user_id = 3';
$result = $this->db->sql_query($sql);
$this->assertEquals(3, $this->db->sql_fetchfield('user_id'), 'Missing data for user in table: ' . $table);
$this->db->sql_freeresult($result);
}
}
}
|