From 53f597b6d0867ab15ae3a4dc5dbc56f633ff9633 Mon Sep 17 00:00:00 2001 From: Oliver Schramm Date: Thu, 17 Jul 2014 15:45:17 +0200 Subject: [PATCH 01/13] [ticket/10729] Update post_edit_user when user being deleted PHPBB3-10729 --- phpBB/includes/functions_user.php | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/phpBB/includes/functions_user.php b/phpBB/includes/functions_user.php index ea8b0a4640..db98b8e7ca 100644 --- a/phpBB/includes/functions_user.php +++ b/phpBB/includes/functions_user.php @@ -439,11 +439,6 @@ function user_delete($mode, $user_id, $post_username = false) WHERE poster_id = $user_id"; $db->sql_query($sql); - $sql = 'UPDATE ' . POSTS_TABLE . ' - SET post_edit_user = ' . ANONYMOUS . " - WHERE post_edit_user = $user_id"; - $db->sql_query($sql); - $sql = 'UPDATE ' . TOPICS_TABLE . ' SET topic_poster = ' . ANONYMOUS . ", topic_first_poster_name = '" . $db->sql_escape($post_username) . "', topic_first_poster_colour = '' WHERE topic_poster = $user_id"; @@ -501,6 +496,12 @@ function user_delete($mode, $user_id, $post_username = false) $cache->destroy('sql', MODERATOR_CACHE_TABLE); + // Change user_id to anonymous for posts edited by this user + $sql = 'UPDATE ' . POSTS_TABLE . ' + SET post_edit_user = ' . ANONYMOUS . ' + WHERE post_edit_user = ' . $user_id; + $db->sql_query($sql); + // Delete user log entries about this user $sql = 'DELETE FROM ' . LOG_TABLE . ' WHERE reportee_id = ' . $user_id; From da6b378e64d2457ddbcd299d769ecf0167ffb9c8 Mon Sep 17 00:00:00 2001 From: Oliver Schramm Date: Thu, 17 Jul 2014 16:30:22 +0200 Subject: [PATCH 02/13] [ticket/10729] Update message_edit_user when user being deleted PHPBB3-10729 --- phpBB/includes/functions_user.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/phpBB/includes/functions_user.php b/phpBB/includes/functions_user.php index db98b8e7ca..20c371f8e5 100644 --- a/phpBB/includes/functions_user.php +++ b/phpBB/includes/functions_user.php @@ -502,6 +502,12 @@ function user_delete($mode, $user_id, $post_username = false) WHERE post_edit_user = ' . $user_id; $db->sql_query($sql); + // Change user_id to anonymous for pms edited by this user + $sql = 'UPDATE ' . PRIVMSGS_TABLE . ' + SET message_edit_user = ' . ANONYMOUS . ' + WHERE message_edit_user = ' . $user_id; + $db->sql_query($sql); + // Delete user log entries about this user $sql = 'DELETE FROM ' . LOG_TABLE . ' WHERE reportee_id = ' . $user_id; From bef207e9b747539fdd1d1961e431e10b77b31ab6 Mon Sep 17 00:00:00 2001 From: Oliver Schramm Date: Fri, 18 Jul 2014 00:19:21 +0200 Subject: [PATCH 03/13] [ticket/10729] Update *_delete_user when user being deleted PHPBB3-10729 --- phpBB/includes/functions_user.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/phpBB/includes/functions_user.php b/phpBB/includes/functions_user.php index c767816d30..ac3dcd02ff 100644 --- a/phpBB/includes/functions_user.php +++ b/phpBB/includes/functions_user.php @@ -596,6 +596,18 @@ function user_delete($mode, $user_ids, $retain_username = true) WHERE ' . $db->sql_in_set('message_edit_user', $user_ids); $db->sql_query($sql); + // Change user_id to anonymous for posts deleted by this user + $sql = 'UPDATE ' . POSTS_TABLE . ' + SET post_delete_user = ' . ANONYMOUS . ' + WHERE ' . $db->sql_in_set('post_delete_user', $user_ids); + $db->sql_query($sql); + + // Change user_id to anonymous for topics deleted by this user + $sql = 'UPDATE ' . TOPICS_TABLE . ' + SET topic_delete_user = ' . ANONYMOUS . ' + WHERE ' . $db->sql_in_set('topic_delete_user', $user_ids); + $db->sql_query($sql); + // Delete user log entries about this user $sql = 'DELETE FROM ' . LOG_TABLE . ' WHERE ' . $db->sql_in_set('reportee_id', $user_ids); From d48e4b680e55ef9b4eb6ea0bd9748ad501f80b30 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Mon, 22 Sep 2014 00:55:08 +0200 Subject: [PATCH 04/13] [ticket/10729] Fix doc block for user_delete PHPBB3-10729 --- phpBB/includes/functions_user.php | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/phpBB/includes/functions_user.php b/phpBB/includes/functions_user.php index 20c371f8e5..abb057df5b 100644 --- a/phpBB/includes/functions_user.php +++ b/phpBB/includes/functions_user.php @@ -329,11 +329,16 @@ function user_add($user_row, $cp_data = false) } /** -* Remove User -*/ + * Remove User + * + * @param string $mode 'retain' or 'remove' + * @param int $user_id + * @param mixed $post_username + * @return bool + */ function user_delete($mode, $user_id, $post_username = false) { - global $cache, $config, $db, $user, $auth; + global $cache, $config, $db, $user; global $phpbb_root_path, $phpEx; $sql = 'SELECT * From 74854ac65d6d98a30cc34cbbcf6fdddb0c8f7cf0 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Mon, 22 Sep 2014 00:55:34 +0200 Subject: [PATCH 05/13] [ticket/10729] Add tests for user posts, reports and attachments PHPBB3-10729 --- tests/functions_user/delete_user_test.php | 401 ++++++++++++++++++ tests/functions_user/fixtures/delete_user.xml | 244 +++++++++++ 2 files changed, 645 insertions(+) create mode 100644 tests/functions_user/delete_user_test.php create mode 100644 tests/functions_user/fixtures/delete_user.xml diff --git a/tests/functions_user/delete_user_test.php b/tests/functions_user/delete_user_test.php new file mode 100644 index 0000000000..23ba7e9a40 --- /dev/null +++ b/tests/functions_user/delete_user_test.php @@ -0,0 +1,401 @@ +createXMLDataSet(dirname(__FILE__).'/fixtures/delete_user.xml'); + } + + protected function setUp() + { + parent::setUp(); + + global $cache, $config, $db; + + $db = $this->db = $this->new_dbal(); + $config = array( + 'load_online_time' => 5, + 'search_type' => 'fulltext_mysql', + ); + $cache = $this->getMock('cache'); + } + + public function first_last_post_data() + { + return array( + array( + 'retain', + 2, + false, + 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', + 2, + false, + 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', + 2, + 'Bertie', + false, + array( + array('post_id' => 1, 'poster_id' => ANONYMOUS, 'post_username' => 'Bertie'), + array('post_id' => 2, 'poster_id' => ANONYMOUS, 'post_username' => 'Other'), + array('post_id' => 3, 'poster_id' => ANONYMOUS, 'post_username' => 'Bertie'), + array('post_id' => 4, 'poster_id' => ANONYMOUS, 'post_username' => 'Other'), + ), + array( + array( + 'topic_id' => 1, + 'topic_poster' => ANONYMOUS, 'topic_first_poster_name' => 'Bertie', 'topic_first_poster_colour' => '', + 'topic_last_poster_id' => ANONYMOUS, 'topic_last_poster_name' => 'Bertie', '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' => 'Bertie', 'topic_first_poster_colour' => '', + 'topic_last_poster_id' => ANONYMOUS, 'topic_last_poster_name' => 'Bertie', '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' => 'Bertie', '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' => 'Bertie', 'forum_last_poster_colour' => ''), + array('forum_id' => 4, 'forum_last_poster_id' => ANONYMOUS, 'forum_last_poster_name' => 'Other', 'forum_last_poster_colour' => ''), + ), + ), + array( + 'remove', + 2, + 'Bertie', + 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' => ''), + ), + ), + ); + } + + /** + * @dataProvider first_last_post_data + */ + public function test_first_last_post_info($mode, $user_id, $post_username, $expected, $expected_posts, $expected_topics, $expected_forums) + { + $this->assertEquals($expected, user_delete($mode, $user_id, $post_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)); + $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)); + $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)); + $this->db->sql_freeresult($result); + } + + public function report_attachment_data() + { + return array( + array( + 'retain', + 2, + false, + false, + array( + array('post_id' => 1, 'post_reported' => 1, 'post_edit_user' => 1), + array('post_id' => 2, 'post_reported' => 1, 'post_edit_user' => 1), + array('post_id' => 3, 'post_reported' => 0, 'post_edit_user' => 1), + array('post_id' => 4, 'post_reported' => 0, 'post_edit_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), + array('topic_id' => 2, 'topic_reported' => 1), + array('topic_id' => 3, 'topic_reported' => 0), + array('topic_id' => 4, 'topic_reported' => 0), + ), + array( + array('attach_id' => 1, 'post_msg_id' => 1, 'poster_id' => 1), + array('attach_id' => 2, 'post_msg_id' => 2, 'poster_id' => 1), + ), + ), + array( + 'remove', + 2, + false, + false, + array( + array('post_id' => 2, 'post_reported' => 1, 'post_edit_user' => 1), + array('post_id' => 4, 'post_reported' => 0, 'post_edit_user' => 1), + ), + array( + array('report_id' => 3, 'post_id' => 2, 'user_id' => 1), + ), + array( + array('topic_id' => 2, 'topic_reported' => 1), + array('topic_id' => 4, 'topic_reported' => 0), + ), + array( + array('attach_id' => 1, 'post_msg_id' => 1, 'poster_id' => 2), // TODO should be deleted: PHPBB3-13089 + array('attach_id' => 2, 'post_msg_id' => 2, 'poster_id' => 1), + ), + ), + array( + 'retain', + 2, + 'Bertie', + false, + array( + array('post_id' => 1, 'post_reported' => 1, 'post_edit_user' => 1), + array('post_id' => 2, 'post_reported' => 1, 'post_edit_user' => 1), + array('post_id' => 3, 'post_reported' => 0, 'post_edit_user' => 1), + array('post_id' => 4, 'post_reported' => 0, 'post_edit_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), + array('topic_id' => 2, 'topic_reported' => 1), + array('topic_id' => 3, 'topic_reported' => 0), + array('topic_id' => 4, 'topic_reported' => 0), + ), + array( + array('attach_id' => 1, 'post_msg_id' => 1, 'poster_id' => 1), + array('attach_id' => 2, 'post_msg_id' => 2, 'poster_id' => 1), + ), + ), + array( + 'remove', + 2, + 'Bertie', + false, + array( + array('post_id' => 2, 'post_reported' => 1, 'post_edit_user' => 1), + array('post_id' => 4, 'post_reported' => 0, 'post_edit_user' => 1), + ), + array( + array('report_id' => 3, 'post_id' => 2, 'user_id' => 1), + ), + array( + array('topic_id' => 2, 'topic_reported' => 1), + array('topic_id' => 4, 'topic_reported' => 0), + ), + array( + array('attach_id' => 1, 'post_msg_id' => 1, 'poster_id' => 2), // TODO should be deleted: PHPBB3-13089 + array('attach_id' => 2, 'post_msg_id' => 2, 'poster_id' => 1), + ), + ), + ); + } + + /** + * @dataProvider report_attachment_data + */ + public function test_report_attachment_info($mode, $user_id, $post_username, $expected, $expected_posts, $expected_reports, $expected_topics, $expected_attach) + { + $this->assertEquals($expected, user_delete($mode, $user_id, $post_username)); + + $sql = 'SELECT post_id, post_reported, post_edit_user + FROM ' . POSTS_TABLE . ' + ORDER BY post_id ASC'; + $result = $this->db->sql_query($sql); + $this->assertEquals($expected_posts, $this->db->sql_fetchrowset($result)); + $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)); + $this->db->sql_freeresult($result); + + $sql = 'SELECT topic_id, topic_reported + FROM ' . TOPICS_TABLE . ' + ORDER BY topic_id ASC'; + $result = $this->db->sql_query($sql); + $this->assertEquals($expected_topics, $this->db->sql_fetchrowset($result)); + $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)); + $this->db->sql_freeresult($result); + } + + public function delete_data() + { + return array( + array( + 'retain', + 2, + false, + false, + array( + array('user_id' => 1, 'user_posts' => 4), + ), + ), + array( + 'remove', + 2, + false, + false, + array( + array('user_id' => 1, 'user_posts' => 2), + ), + ), + array( + 'retain', + 2, + 'Bertie', + false, + array( + array('user_id' => 1, 'user_posts' => 4), + ), + ), + array( + 'remove', + 2, + 'Bertie', + false, + array( + array('user_id' => 1, 'user_posts' => 2), + ), + ), + ); + } + + /** + * @dataProvider delete_data + */ + public function test_delete_data($mode, $user_id, $post_username, $expected, $expected_users) + { + $this->assertEquals($expected, user_delete($mode, $user_id, $post_username)); + + $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)); + $this->db->sql_freeresult($result); + } +} diff --git a/tests/functions_user/fixtures/delete_user.xml b/tests/functions_user/fixtures/delete_user.xml new file mode 100644 index 0000000000..36e634229f --- /dev/null +++ b/tests/functions_user/fixtures/delete_user.xml @@ -0,0 +1,244 @@ + + + + attach_id + post_msg_id + topic_id + in_message + poster_id + attach_comment + + 1 + 1 + 1 + 1 + 2 + + + + 2 + 2 + 2 + 1 + 1 + + +
+ + forum_id + forum_last_poster_id + forum_last_poster_name + forum_last_poster_colour + forum_parents + forum_desc + forum_rules + + 1 + 2 + + 00AA00 + + + + + + 2 + 1 + Other + + + + + + + 3 + 2 + + 00AA00 + + + + + + 4 + 1 + Other + + + + + +
+ + post_id + poster_id + post_edit_user + post_username + topic_id + forum_id + post_approved + post_time + post_text + post_reported + + 1 + 2 + 2 + + 1 + 1 + 1 + 1 + + 1 + + + 2 + 1 + 1 + Other + 2 + 2 + 1 + 1 + + 1 + + + 3 + 2 + 2 + + 3 + 3 + 1 + 1 + + 1 + + + 4 + 1 + 1 + Other + 4 + 4 + 1 + 1 + + 1 + +
+ + report_id + post_id + user_id + report_text + + 1 + 1 + 1 + Post Removed? + + + 2 + 3 + 2 + Post Removed? + + + 3 + 2 + 1 + Keep + + + 4 + 4 + 2 + Remove Report + +
+ + topic_id + forum_id + topic_reported + topic_poster + topic_first_poster_name + topic_first_poster_colour + topic_last_poster_id + topic_last_poster_name + topic_last_poster_colour + + 1 + 1 + 1 + 2 + + 00AA00 + 2 + + 00AA00 + + + 2 + 2 + 1 + 1 + Other + + 1 + Other + + + + 3 + 3 + 1 + 2 + + 00AA00 + 2 + + 00AA00 + + + 4 + 4 + 1 + 1 + Other + + 1 + Other + + +
+ + user_id + username_clean + user_permissions + user_sig + user_occ + user_interests + user_posts + + 1 + Anonymous + + + + + 2 + + + 2 + Foobar + + + + + 2 + +
+
From d7c12ccd6067a74ca24fe9cec872c29b94ce13b2 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Mon, 22 Sep 2014 01:42:36 +0200 Subject: [PATCH 06/13] [ticket/10729] Add tests for some special tables with unique conditions PHPBB3-10729 --- tests/functions_user/delete_user_test.php | 173 +++++++----------- tests/functions_user/fixtures/delete_user.xml | 157 +++++++++++++++- 2 files changed, 225 insertions(+), 105 deletions(-) diff --git a/tests/functions_user/delete_user_test.php b/tests/functions_user/delete_user_test.php index 23ba7e9a40..3cd575457d 100644 --- a/tests/functions_user/delete_user_test.php +++ b/tests/functions_user/delete_user_test.php @@ -39,10 +39,7 @@ class phpbb_functions_user_delete_user_test extends phpbb_database_test_case { return array( array( - 'retain', - 2, - false, - false, + 'retain', 2, false, array( array('post_id' => 1, 'poster_id' => ANONYMOUS, 'post_username' => ''), array('post_id' => 2, 'poster_id' => ANONYMOUS, 'post_username' => 'Other'), @@ -79,10 +76,7 @@ class phpbb_functions_user_delete_user_test extends phpbb_database_test_case ), ), array( - 'remove', - 2, - false, - false, + 'remove', 2, false, array( array('post_id' => 2, 'poster_id' => ANONYMOUS, 'post_username' => 'Other'), array('post_id' => 4, 'poster_id' => ANONYMOUS, 'post_username' => 'Other'), @@ -107,10 +101,7 @@ class phpbb_functions_user_delete_user_test extends phpbb_database_test_case ), ), array( - 'retain', - 2, - 'Bertie', - false, + 'retain', 2, 'Bertie', array( array('post_id' => 1, 'poster_id' => ANONYMOUS, 'post_username' => 'Bertie'), array('post_id' => 2, 'poster_id' => ANONYMOUS, 'post_username' => 'Other'), @@ -147,10 +138,7 @@ class phpbb_functions_user_delete_user_test extends phpbb_database_test_case ), ), array( - 'remove', - 2, - 'Bertie', - false, + 'remove', 2, 'Bertie', array( array('post_id' => 2, 'poster_id' => ANONYMOUS, 'post_username' => 'Other'), array('post_id' => 4, 'poster_id' => ANONYMOUS, 'post_username' => 'Other'), @@ -180,9 +168,9 @@ class phpbb_functions_user_delete_user_test extends phpbb_database_test_case /** * @dataProvider first_last_post_data */ - public function test_first_last_post_info($mode, $user_id, $post_username, $expected, $expected_posts, $expected_topics, $expected_forums) + public function test_first_last_post_info($mode, $user_id, $post_username, $expected_posts, $expected_topics, $expected_forums) { - $this->assertEquals($expected, user_delete($mode, $user_id, $post_username)); + $this->assertFalse(user_delete($mode, $user_id, $post_username)); $sql = 'SELECT post_id, poster_id, post_username FROM ' . POSTS_TABLE . ' @@ -210,10 +198,7 @@ class phpbb_functions_user_delete_user_test extends phpbb_database_test_case { return array( array( - 'retain', - 2, - false, - false, + 'retain', 2, array( array('post_id' => 1, 'post_reported' => 1, 'post_edit_user' => 1), array('post_id' => 2, 'post_reported' => 1, 'post_edit_user' => 1), @@ -233,13 +218,11 @@ class phpbb_functions_user_delete_user_test extends phpbb_database_test_case 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', - 2, - false, - false, + 'remove', 2, array( array('post_id' => 2, 'post_reported' => 1, 'post_edit_user' => 1), array('post_id' => 4, 'post_reported' => 0, 'post_edit_user' => 1), @@ -252,55 +235,8 @@ class phpbb_functions_user_delete_user_test extends phpbb_database_test_case array('topic_id' => 4, 'topic_reported' => 0), ), array( - array('attach_id' => 1, 'post_msg_id' => 1, 'poster_id' => 2), // TODO should be deleted: PHPBB3-13089 - array('attach_id' => 2, 'post_msg_id' => 2, 'poster_id' => 1), - ), - ), - array( - 'retain', - 2, - 'Bertie', - false, - array( - array('post_id' => 1, 'post_reported' => 1, 'post_edit_user' => 1), - array('post_id' => 2, 'post_reported' => 1, 'post_edit_user' => 1), - array('post_id' => 3, 'post_reported' => 0, 'post_edit_user' => 1), - array('post_id' => 4, 'post_reported' => 0, 'post_edit_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), - array('topic_id' => 2, 'topic_reported' => 1), - array('topic_id' => 3, 'topic_reported' => 0), - array('topic_id' => 4, 'topic_reported' => 0), - ), - array( - array('attach_id' => 1, 'post_msg_id' => 1, 'poster_id' => 1), - array('attach_id' => 2, 'post_msg_id' => 2, 'poster_id' => 1), - ), - ), - array( - 'remove', - 2, - 'Bertie', - false, - array( - array('post_id' => 2, 'post_reported' => 1, 'post_edit_user' => 1), - array('post_id' => 4, 'post_reported' => 0, 'post_edit_user' => 1), - ), - array( - array('report_id' => 3, 'post_id' => 2, 'user_id' => 1), - ), - array( - array('topic_id' => 2, 'topic_reported' => 1), - array('topic_id' => 4, 'topic_reported' => 0), - ), - array( - array('attach_id' => 1, 'post_msg_id' => 1, 'poster_id' => 2), // TODO should be deleted: PHPBB3-13089 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 ), ), ); @@ -309,9 +245,9 @@ class phpbb_functions_user_delete_user_test extends phpbb_database_test_case /** * @dataProvider report_attachment_data */ - public function test_report_attachment_info($mode, $user_id, $post_username, $expected, $expected_posts, $expected_reports, $expected_topics, $expected_attach) + public function test_report_attachment_info($mode, $user_id, $expected_posts, $expected_reports, $expected_topics, $expected_attach) { - $this->assertEquals($expected, user_delete($mode, $user_id, $post_username)); + $this->assertFalse(user_delete($mode, $user_id)); $sql = 'SELECT post_id, post_reported, post_edit_user FROM ' . POSTS_TABLE . ' @@ -346,39 +282,33 @@ class phpbb_functions_user_delete_user_test extends phpbb_database_test_case { return array( array( - 'retain', - 2, - false, - false, + 'retain', 2, + 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('user_id' => 1, 'user_posts' => 4), + 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', - 2, - false, - false, + 'remove', 2, + 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('user_id' => 1, 'user_posts' => 2), + array('log_id' => 2, 'user_id' => 1, 'reportee_id' => 1), + array('log_id' => 3, 'user_id' => 1, 'reportee_id' => 1), ), - ), - array( - 'retain', - 2, - 'Bertie', - false, array( - array('user_id' => 1, 'user_posts' => 4), - ), - ), - array( - 'remove', - 2, - 'Bertie', - false, - array( - array('user_id' => 1, 'user_posts' => 2), + array('msg_id' => 1, 'author_id' => 3, 'message_edit_user' => 3), + array('msg_id' => 2, 'author_id' => 1, 'message_edit_user' => 1), ), ), ); @@ -387,9 +317,9 @@ class phpbb_functions_user_delete_user_test extends phpbb_database_test_case /** * @dataProvider delete_data */ - public function test_delete_data($mode, $user_id, $post_username, $expected, $expected_users) + public function test_delete_data($mode, $user_id, $expected_users, $expected_zebra, $expected_ban, $expected_sessions, $expected_logs, $expected_pms) { - $this->assertEquals($expected, user_delete($mode, $user_id, $post_username)); + $this->assertFalse(user_delete($mode, $user_id)); $sql = 'SELECT user_id, user_posts FROM ' . USERS_TABLE . ' @@ -397,5 +327,40 @@ class phpbb_functions_user_delete_user_test extends phpbb_database_test_case $result = $this->db->sql_query($sql); $this->assertEquals($expected_users, $this->db->sql_fetchrowset($result)); $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)); + $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)); + $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)); + $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)); + $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)); + $this->db->sql_freeresult($result); } } diff --git a/tests/functions_user/fixtures/delete_user.xml b/tests/functions_user/fixtures/delete_user.xml index 36e634229f..8efa05f467 100644 --- a/tests/functions_user/fixtures/delete_user.xml +++ b/tests/functions_user/fixtures/delete_user.xml @@ -6,24 +6,64 @@ topic_id in_message poster_id + is_orphan attach_comment 1 1 1 - 1 + 0 2 + 0 2 2 2 + 0 1 + 0 + + + + 3 + 0 + 0 + 0 + 2 1 + + ban_id + ban_userid + ban_email + ban_reason + ban_give_reason + + 1 + 2 + + + + + + 2 + 3 + + + + + + 3 + 0 + + + + +
forum_idforum_last_poster_id @@ -69,6 +109,41 @@
+ + log_id + user_id + reportee_id + log_operation + log_data + + 1 + 1 + 2 + + + + + 2 + 2 + 1 + + + + + 3 + 1 + 1 + + + + + 4 + 2 + 2 + + + +
post_idposter_id @@ -129,6 +204,55 @@ 1
+ + msg_id + author_id + message_edit_user + message_text + to_address + bcc_address + + 1 + 3 + 3 + + + + + + 2 + 2 + 2 + + + + +
+ + msg_id + user_id + author_id + + 1 + 3 + 3 + + + 1 + 2 + 3 + + + 2 + 3 + 2 + + + 2 + 2 + 2 + +
report_idpost_id @@ -159,6 +283,21 @@ Remove Report
+ + session_id + session_user_id + session_page + + 12345678901234567890123456789012 + 2 + + + + 12345678901234567890123456789013 + 3 + + +
topic_idforum_id @@ -241,4 +380,20 @@ 2
+ + user_id + zebra_id + + 1 + 2 + + + 1 + 3 + + + 2 + 1 + +
From 7fca351e05fd47bb1aaef3611ee9b7d7c946b0b3 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Mon, 22 Sep 2014 02:01:54 +0200 Subject: [PATCH 07/13] [ticket/10729] Add assert messages and finish up tests PHPBB3-10729 --- tests/functions_user/delete_user_test.php | 123 ++++++++++++---- tests/functions_user/fixtures/delete_user.xml | 132 ++++++++++++++++++ 2 files changed, 228 insertions(+), 27 deletions(-) diff --git a/tests/functions_user/delete_user_test.php b/tests/functions_user/delete_user_test.php index 3cd575457d..1d7c843058 100644 --- a/tests/functions_user/delete_user_test.php +++ b/tests/functions_user/delete_user_test.php @@ -39,7 +39,7 @@ class phpbb_functions_user_delete_user_test extends phpbb_database_test_case { return array( array( - 'retain', 2, false, + 'retain', false, array( array('post_id' => 1, 'poster_id' => ANONYMOUS, 'post_username' => ''), array('post_id' => 2, 'poster_id' => ANONYMOUS, 'post_username' => 'Other'), @@ -76,7 +76,7 @@ class phpbb_functions_user_delete_user_test extends phpbb_database_test_case ), ), array( - 'remove', 2, false, + 'remove', false, array( array('post_id' => 2, 'poster_id' => ANONYMOUS, 'post_username' => 'Other'), array('post_id' => 4, 'poster_id' => ANONYMOUS, 'post_username' => 'Other'), @@ -101,7 +101,7 @@ class phpbb_functions_user_delete_user_test extends phpbb_database_test_case ), ), array( - 'retain', 2, 'Bertie', + 'retain', 'Bertie', array( array('post_id' => 1, 'poster_id' => ANONYMOUS, 'post_username' => 'Bertie'), array('post_id' => 2, 'poster_id' => ANONYMOUS, 'post_username' => 'Other'), @@ -138,7 +138,7 @@ class phpbb_functions_user_delete_user_test extends phpbb_database_test_case ), ), array( - 'remove', 2, 'Bertie', + 'remove', 'Bertie', array( array('post_id' => 2, 'poster_id' => ANONYMOUS, 'post_username' => 'Other'), array('post_id' => 4, 'poster_id' => ANONYMOUS, 'post_username' => 'Other'), @@ -168,29 +168,29 @@ class phpbb_functions_user_delete_user_test extends phpbb_database_test_case /** * @dataProvider first_last_post_data */ - public function test_first_last_post_info($mode, $user_id, $post_username, $expected_posts, $expected_topics, $expected_forums) + public function test_first_last_post_info($mode, $post_username, $expected_posts, $expected_topics, $expected_forums) { - $this->assertFalse(user_delete($mode, $user_id, $post_username)); + $this->assertFalse(user_delete($mode, 2, $post_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)); + $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)); + $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)); + $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); } @@ -198,7 +198,7 @@ class phpbb_functions_user_delete_user_test extends phpbb_database_test_case { return array( array( - 'retain', 2, + 'retain', array( array('post_id' => 1, 'post_reported' => 1, 'post_edit_user' => 1), array('post_id' => 2, 'post_reported' => 1, 'post_edit_user' => 1), @@ -222,7 +222,7 @@ class phpbb_functions_user_delete_user_test extends phpbb_database_test_case ), ), array( - 'remove', 2, + 'remove', array( array('post_id' => 2, 'post_reported' => 1, 'post_edit_user' => 1), array('post_id' => 4, 'post_reported' => 0, 'post_edit_user' => 1), @@ -245,36 +245,36 @@ class phpbb_functions_user_delete_user_test extends phpbb_database_test_case /** * @dataProvider report_attachment_data */ - public function test_report_attachment_info($mode, $user_id, $expected_posts, $expected_reports, $expected_topics, $expected_attach) + public function test_report_attachment_info($mode, $expected_posts, $expected_reports, $expected_topics, $expected_attach) { - $this->assertFalse(user_delete($mode, $user_id)); + $this->assertFalse(user_delete($mode, 2)); $sql = 'SELECT post_id, post_reported, post_edit_user FROM ' . POSTS_TABLE . ' ORDER BY post_id ASC'; $result = $this->db->sql_query($sql); - $this->assertEquals($expected_posts, $this->db->sql_fetchrowset($result)); + $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)); + $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 FROM ' . TOPICS_TABLE . ' ORDER BY topic_id ASC'; $result = $this->db->sql_query($sql); - $this->assertEquals($expected_topics, $this->db->sql_fetchrowset($result)); + $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)); + $this->assertEquals($expected_attach, $this->db->sql_fetchrowset($result), 'Attachment table content is mismatching after deleting a user.'); $this->db->sql_freeresult($result); } @@ -282,7 +282,7 @@ class phpbb_functions_user_delete_user_test extends phpbb_database_test_case { return array( array( - 'retain', 2, + '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)), @@ -297,7 +297,7 @@ class phpbb_functions_user_delete_user_test extends phpbb_database_test_case ), ), array( - 'remove', 2, + '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)), @@ -317,50 +317,119 @@ class phpbb_functions_user_delete_user_test extends phpbb_database_test_case /** * @dataProvider delete_data */ - public function test_delete_data($mode, $user_id, $expected_users, $expected_zebra, $expected_ban, $expected_sessions, $expected_logs, $expected_pms) + public function test_delete_data($mode, $expected_users, $expected_zebra, $expected_ban, $expected_sessions, $expected_logs, $expected_pms) { - $this->assertFalse(user_delete($mode, $user_id)); + $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)); + $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)); + $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)); + $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)); + $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)); + $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)); + $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); + } + } } diff --git a/tests/functions_user/fixtures/delete_user.xml b/tests/functions_user/fixtures/delete_user.xml index 8efa05f467..07591389d2 100644 --- a/tests/functions_user/fixtures/delete_user.xml +++ b/tests/functions_user/fixtures/delete_user.xml @@ -396,4 +396,136 @@ 1 + + user_id + + 2 + + + 3 + +
+ + user_id + + 2 + + + 3 + +
+ + user_id + + 2 + + + 3 + +
+ + user_id + + 2 + + + 3 + +
+ + user_id + + 2 + + + 3 + +
+ + user_id + + 2 + + + 3 + +
+ + user_id + + 2 + + + 3 + +
+ + user_id + + 2 + + + 3 + +
+ + user_id + + 2 + + + 3 + +
+ + user_id + + 2 + + + 3 + +
+ + user_id + + 2 + + + 3 + +
+ + user_id + + 2 + + + 3 + +
+ + user_id + rule_string + + 2 + + + + 3 + + +
+ + user_id + draft_message + + 2 + + + + 3 + + +
From e28b93e0cc3d5bceb803b73c646cf51c153e7a5a Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Mon, 22 Sep 2014 23:55:56 +0200 Subject: [PATCH 08/13] [ticket/10729] Ensure that no bans exist before testing create_session PHPBB3-10729 --- tests/session/fixtures/sessions_empty.xml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/session/fixtures/sessions_empty.xml b/tests/session/fixtures/sessions_empty.xml index 0e6ddccd88..c592e0a6c8 100644 --- a/tests/session/fixtures/sessions_empty.xml +++ b/tests/session/fixtures/sessions_empty.xml @@ -38,4 +38,11 @@ session_ip session_browser + + ban_id + ban_userid + ban_email + ban_reason + ban_give_reason +
From bea5f94de654df6b009d6058816ad500836469b3 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 23 Sep 2014 09:03:44 +0200 Subject: [PATCH 09/13] [ticket/10729] Use mocked null cache for phpunit 3.6 on travis with php 5.2 PHPBB3-10729 --- tests/functions_user/delete_user_test.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/functions_user/delete_user_test.php b/tests/functions_user/delete_user_test.php index 1d7c843058..9a7805a819 100644 --- a/tests/functions_user/delete_user_test.php +++ b/tests/functions_user/delete_user_test.php @@ -10,6 +10,7 @@ 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'; +require_once dirname(__FILE__) . '/../mock/null_cache.php'; class phpbb_functions_user_delete_user_test extends phpbb_database_test_case { @@ -32,7 +33,7 @@ class phpbb_functions_user_delete_user_test extends phpbb_database_test_case 'load_online_time' => 5, 'search_type' => 'fulltext_mysql', ); - $cache = $this->getMock('cache'); + $cache = new phpbb_mock_null_cache(); } public function first_last_post_data() From eeeb62b43381e087e09ab75cd5c6b4764d8338fb Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 23 Sep 2014 09:31:33 +0200 Subject: [PATCH 10/13] [ticket/10729] Update fixture to 3.1 database structure PHPBB3-10729 --- tests/functions_user/fixtures/delete_user.xml | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/tests/functions_user/fixtures/delete_user.xml b/tests/functions_user/fixtures/delete_user.xml index 07591389d2..6c6d7ea9cc 100644 --- a/tests/functions_user/fixtures/delete_user.xml +++ b/tests/functions_user/fixtures/delete_user.xml @@ -151,7 +151,7 @@ post_username topic_id forum_id - post_approved + post_visibility post_time post_text post_reported @@ -258,29 +258,34 @@ post_id user_id report_text + reported_post_text 1 1 1 Post Removed? + 2 3 2 Post Removed? + 3 2 1 Keep + 4 4 2 Remove Report + @@ -358,16 +363,12 @@ username_cleanuser_permissionsuser_sig - user_occ - user_interestsuser_posts 1 Anonymous - - 2 @@ -375,8 +376,6 @@ Foobar - - 2
@@ -461,11 +460,17 @@ user_id + pf_phpbb_interests + pf_phpbb_occupation 2 + + 3 + +
From 10b6399d300b05fb0a1f66ccbdb6fc8a2889ebbc Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 23 Sep 2014 09:38:35 +0200 Subject: [PATCH 11/13] [ticket/10729] Fix setup of the tests for 3.1 PHPBB3-10729 --- tests/functions_user/delete_user_test.php | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/tests/functions_user/delete_user_test.php b/tests/functions_user/delete_user_test.php index 9a7805a819..c728e6c122 100644 --- a/tests/functions_user/delete_user_test.php +++ b/tests/functions_user/delete_user_test.php @@ -10,30 +10,34 @@ 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'; -require_once dirname(__FILE__) . '/../mock/null_cache.php'; class phpbb_functions_user_delete_user_test extends phpbb_database_test_case { - /** @var \dbal */ + /** @var \phpbb\db\driver\driver_interface */ protected $db; public function getDataSet() { - return $this->createXMLDataSet(dirname(__FILE__).'/fixtures/delete_user.xml'); + return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/delete_user.xml'); } protected function setUp() { parent::setUp(); - global $cache, $config, $db; + global $cache, $config, $db, $phpbb_dispatcher, $phpbb_container; $db = $this->db = $this->new_dbal(); - $config = array( + $config = new \phpbb\config\config(array( 'load_online_time' => 5, - 'search_type' => 'fulltext_mysql', - ); + 'search_type' => '\phpbb\search\fulltext_mysql', + )); + set_config(false, false, false, $config); + set_config_count(false, false, false, $config); $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()); } public function first_last_post_data() From d6008e896acde7bec567d3ec1b3d6270918e48f5 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 23 Sep 2014 09:42:30 +0200 Subject: [PATCH 12/13] [ticket/10729] Fix handling of third parameter in 3.1 PHPBB3-10729 --- tests/functions_user/delete_user_test.php | 24 +++++++++---------- tests/functions_user/fixtures/delete_user.xml | 3 +++ 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/tests/functions_user/delete_user_test.php b/tests/functions_user/delete_user_test.php index c728e6c122..399dc6a064 100644 --- a/tests/functions_user/delete_user_test.php +++ b/tests/functions_user/delete_user_test.php @@ -106,18 +106,18 @@ class phpbb_functions_user_delete_user_test extends phpbb_database_test_case ), ), array( - 'retain', 'Bertie', + 'retain', true, array( - array('post_id' => 1, 'poster_id' => ANONYMOUS, 'post_username' => 'Bertie'), + 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' => 'Bertie'), + 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' => 'Bertie', 'topic_first_poster_colour' => '', - 'topic_last_poster_id' => ANONYMOUS, 'topic_last_poster_name' => 'Bertie', 'topic_last_poster_colour' => '', + '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, @@ -126,8 +126,8 @@ class phpbb_functions_user_delete_user_test extends phpbb_database_test_case ), array( 'topic_id' => 3, - 'topic_poster' => ANONYMOUS, 'topic_first_poster_name' => 'Bertie', 'topic_first_poster_colour' => '', - 'topic_last_poster_id' => ANONYMOUS, 'topic_last_poster_name' => 'Bertie', 'topic_last_poster_colour' => '', + '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, @@ -136,14 +136,14 @@ class phpbb_functions_user_delete_user_test extends phpbb_database_test_case ), ), array( - array('forum_id' => 1, 'forum_last_poster_id' => ANONYMOUS, 'forum_last_poster_name' => 'Bertie', 'forum_last_poster_colour' => ''), + 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' => 'Bertie', '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', 'Bertie', + 'remove', true, array( array('post_id' => 2, 'poster_id' => ANONYMOUS, 'post_username' => 'Other'), array('post_id' => 4, 'poster_id' => ANONYMOUS, 'post_username' => 'Other'), @@ -173,9 +173,9 @@ class phpbb_functions_user_delete_user_test extends phpbb_database_test_case /** * @dataProvider first_last_post_data */ - public function test_first_last_post_info($mode, $post_username, $expected_posts, $expected_topics, $expected_forums) + public function test_first_last_post_info($mode, $retain_username, $expected_posts, $expected_topics, $expected_forums) { - $this->assertFalse(user_delete($mode, 2, $post_username)); + $this->assertFalse(user_delete($mode, 2, $retain_username)); $sql = 'SELECT post_id, poster_id, post_username FROM ' . POSTS_TABLE . ' diff --git a/tests/functions_user/fixtures/delete_user.xml b/tests/functions_user/fixtures/delete_user.xml index 6c6d7ea9cc..2e09182780 100644 --- a/tests/functions_user/fixtures/delete_user.xml +++ b/tests/functions_user/fixtures/delete_user.xml @@ -360,6 +360,7 @@
user_id + usernameusername_cleanuser_permissionsuser_sig @@ -367,6 +368,7 @@ 1 Anonymous + anonymous 2 @@ -374,6 +376,7 @@ 2 Foobar + foobar 2 From 96024e88e9894ce6215805ad389813659259d871 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 23 Sep 2014 09:51:26 +0200 Subject: [PATCH 13/13] [ticket/10729] Also test *delete_user on posts and topics PHPBB3-10729 --- tests/functions_user/delete_user_test.php | 28 +++++++++---------- tests/functions_user/fixtures/delete_user.xml | 10 +++++++ 2 files changed, 24 insertions(+), 14 deletions(-) diff --git a/tests/functions_user/delete_user_test.php b/tests/functions_user/delete_user_test.php index 399dc6a064..d5c78c64ad 100644 --- a/tests/functions_user/delete_user_test.php +++ b/tests/functions_user/delete_user_test.php @@ -205,20 +205,20 @@ class phpbb_functions_user_delete_user_test extends phpbb_database_test_case array( 'retain', array( - array('post_id' => 1, 'post_reported' => 1, 'post_edit_user' => 1), - array('post_id' => 2, 'post_reported' => 1, 'post_edit_user' => 1), - array('post_id' => 3, 'post_reported' => 0, 'post_edit_user' => 1), - array('post_id' => 4, 'post_reported' => 0, 'post_edit_user' => 1), + 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), - array('topic_id' => 2, 'topic_reported' => 1), - array('topic_id' => 3, 'topic_reported' => 0), - array('topic_id' => 4, 'topic_reported' => 0), + 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), @@ -229,15 +229,15 @@ class phpbb_functions_user_delete_user_test extends phpbb_database_test_case array( 'remove', array( - array('post_id' => 2, 'post_reported' => 1, 'post_edit_user' => 1), - array('post_id' => 4, 'post_reported' => 0, 'post_edit_user' => 1), + 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), - array('topic_id' => 4, 'topic_reported' => 0), + 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), @@ -254,7 +254,7 @@ class phpbb_functions_user_delete_user_test extends phpbb_database_test_case { $this->assertFalse(user_delete($mode, 2)); - $sql = 'SELECT post_id, post_reported, post_edit_user + $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); @@ -268,7 +268,7 @@ class phpbb_functions_user_delete_user_test extends phpbb_database_test_case $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 + $sql = 'SELECT topic_id, topic_reported, topic_delete_user FROM ' . TOPICS_TABLE . ' ORDER BY topic_id ASC'; $result = $this->db->sql_query($sql); diff --git a/tests/functions_user/fixtures/delete_user.xml b/tests/functions_user/fixtures/delete_user.xml index 2e09182780..56014b35d1 100644 --- a/tests/functions_user/fixtures/delete_user.xml +++ b/tests/functions_user/fixtures/delete_user.xml @@ -148,6 +148,7 @@ post_id poster_id post_edit_user + post_delete_user post_username topic_id forum_id @@ -159,6 +160,7 @@ 1 2 2 + 2 1 1 @@ -171,6 +173,7 @@ 2 1 1 + 1 Other 2 2 @@ -183,6 +186,7 @@ 3 2 2 + 2 3 3 @@ -195,6 +199,7 @@ 4 1 1 + 1 Other 4 4 @@ -308,6 +313,7 @@ forum_id topic_reported topic_poster + topic_delete_user topic_first_poster_name topic_first_poster_colour topic_last_poster_id @@ -318,6 +324,7 @@ 1 1 2 + 2 00AA00 2 @@ -329,6 +336,7 @@ 2 1 1 + 1 Other 1 @@ -340,6 +348,7 @@ 3 1 2 + 2 00AA00 2 @@ -351,6 +360,7 @@ 4 1 1 + 1 Other 1