From 74854ac65d6d98a30cc34cbbcf6fdddb0c8f7cf0 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Mon, 22 Sep 2014 00:55:34 +0200 Subject: [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 (limited to 'tests/functions_user') 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 + +
+
-- cgit v1.2.1