From d30dc11f3e1ade19fd8643bdded6f11625da1bb3 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sat, 23 Jun 2012 16:02:16 +0200 Subject: [ticket/10950] Add some first and simple unit tests for phpbb_delete_user_pms() Todo: Add cases to in which the msg is also deleted. PHPBB3-10950 --- tests/privmsgs/delete_user_pms_test.php | 95 +++++++++++++++++++++ tests/privmsgs/fixtures/delete_user_pms.xml | 127 ++++++++++++++++++++++++++++ 2 files changed, 222 insertions(+) create mode 100644 tests/privmsgs/delete_user_pms_test.php create mode 100644 tests/privmsgs/fixtures/delete_user_pms.xml (limited to 'tests/privmsgs') diff --git a/tests/privmsgs/delete_user_pms_test.php b/tests/privmsgs/delete_user_pms_test.php new file mode 100644 index 0000000000..b399d94c6d --- /dev/null +++ b/tests/privmsgs/delete_user_pms_test.php @@ -0,0 +1,95 @@ +createXMLDataSet(dirname(__FILE__).'/fixtures/delete_user_pms.xml'); + } + + public static function delete_user_pms_data() + { + return array( + // array( + // (user we delete), + // array(remaining privmsgs ids), + // array(remaining privmsgs_to), + // ), + array( + 2, + array( + array('msg_id' => 1), + array('msg_id' => 2), + ), + array( + //array('msg_id' => 1, 'user_id' => 2), + array('msg_id' => 1, 'user_id' => 3), + array('msg_id' => 1, 'user_id' => 4), + //array('msg_id' => 2, 'user_id' => 2), + array('msg_id' => 2, 'user_id' => 4), + ), + ), + array( + 3, + array( + array('msg_id' => 1), + array('msg_id' => 2), + ), + array( + array('msg_id' => 1, 'user_id' => 2), + //array('msg_id' => 1, 'user_id' => 3), + array('msg_id' => 1, 'user_id' => 4), + array('msg_id' => 2, 'user_id' => 2), + array('msg_id' => 2, 'user_id' => 4), + ), + ), + array( + 5, + array( + array('msg_id' => 1), + array('msg_id' => 2), + ), + array( + array('msg_id' => 1, 'user_id' => 2), + array('msg_id' => 1, 'user_id' => 3), + array('msg_id' => 1, 'user_id' => 4), + array('msg_id' => 2, 'user_id' => 2), + array('msg_id' => 2, 'user_id' => 4), + ), + ), + ); + } + + /** + * @dataProvider delete_user_pms_data + */ + public function test_delete_user_pms($delete_user, $remaining_privmsgs, $remaining_privmsgs_to) + { + global $db; + + $db = $this->new_dbal(); + + phpbb_delete_user_pms($delete_user); + + $sql = 'SELECT msg_id + FROM ' . PRIVMSGS_TABLE; + $result = $db->sql_query($sql); + + $this->assertEquals($remaining_privmsgs, $db->sql_fetchrowset($result)); + + $sql = 'SELECT msg_id, user_id + FROM ' . PRIVMSGS_TO_TABLE; + $result = $db->sql_query($sql); + + $this->assertEquals($remaining_privmsgs_to, $db->sql_fetchrowset($result)); + } +} diff --git a/tests/privmsgs/fixtures/delete_user_pms.xml b/tests/privmsgs/fixtures/delete_user_pms.xml new file mode 100644 index 0000000000..848164080c --- /dev/null +++ b/tests/privmsgs/fixtures/delete_user_pms.xml @@ -0,0 +1,127 @@ + + + + user_id + username + username_clean + user_new_privmsg + user_unread_privmsg + user_permissions + user_sig + user_occ + user_interests + + 2 + sender + sender + 0 + 0 + + + + + + + 3 + pm in inbox + pm in inbox + 0 + 0 + + + + + + + 4 + pm in no box + pm in no box + 2 + 2 + + + + + + + 5 + no pms + no pms + 0 + 0 + + + + + +
+ + msg_id + root_level + author_id + message_subject + message_text + + 1 + 0 + 2 + #1 + #1 + + + 2 + 0 + 2 + #2 + #2 + +
+ + msg_id + user_id + author_id + pm_new + pm_unread + folder_id + + 1 + 2 + 2 + 0 + 0 + -2 + + + 1 + 3 + 2 + 0 + 0 + 0 + + + 1 + 4 + 2 + 0 + 0 + -3 + + + 2 + 2 + 2 + 0 + 0 + -2 + + + 2 + 4 + 2 + 0 + 0 + -3 + +
+
-- cgit v1.2.1