aboutsummaryrefslogtreecommitdiffstats
path: root/tests/privmsgs
diff options
context:
space:
mode:
authorJoas Schilling <nickvergessen@gmx.de>2012-06-23 16:02:16 +0200
committerJoas Schilling <nickvergessen@gmx.de>2012-06-23 16:02:16 +0200
commitd30dc11f3e1ade19fd8643bdded6f11625da1bb3 (patch)
treeea0157b14917c89be7493ff8c9b32204677b4ab6 /tests/privmsgs
parent49afc1f2dc3a3ee17c6abff1e94c25a8ba8b3604 (diff)
downloadforums-d30dc11f3e1ade19fd8643bdded6f11625da1bb3.tar
forums-d30dc11f3e1ade19fd8643bdded6f11625da1bb3.tar.gz
forums-d30dc11f3e1ade19fd8643bdded6f11625da1bb3.tar.bz2
forums-d30dc11f3e1ade19fd8643bdded6f11625da1bb3.tar.xz
forums-d30dc11f3e1ade19fd8643bdded6f11625da1bb3.zip
[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
Diffstat (limited to 'tests/privmsgs')
-rw-r--r--tests/privmsgs/delete_user_pms_test.php95
-rw-r--r--tests/privmsgs/fixtures/delete_user_pms.xml127
2 files changed, 222 insertions, 0 deletions
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 @@
+<?php
+/**
+*
+* @package testing
+* @copyright (c) 2011 phpBB Group
+* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+*
+*/
+
+require_once dirname(__FILE__) . '/../../phpBB/includes/functions_privmsgs.php';
+
+class phpbb_privmsgs_delete_user_pms_test extends phpbb_database_test_case
+{
+ public function getDataSet()
+ {
+ return $this->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 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<dataset>
+ <table name="phpbb_users">
+ <column>user_id</column>
+ <column>username</column>
+ <column>username_clean</column>
+ <column>user_new_privmsg</column>
+ <column>user_unread_privmsg</column>
+ <column>user_permissions</column>
+ <column>user_sig</column>
+ <column>user_occ</column>
+ <column>user_interests</column>
+ <row>
+ <value>2</value>
+ <value>sender</value>
+ <value>sender</value>
+ <value>0</value>
+ <value>0</value>
+ <value></value>
+ <value></value>
+ <value></value>
+ <value></value>
+ </row>
+ <row>
+ <value>3</value>
+ <value>pm in inbox</value>
+ <value>pm in inbox</value>
+ <value>0</value>
+ <value>0</value>
+ <value></value>
+ <value></value>
+ <value></value>
+ <value></value>
+ </row>
+ <row>
+ <value>4</value>
+ <value>pm in no box</value>
+ <value>pm in no box</value>
+ <value>2</value>
+ <value>2</value>
+ <value></value>
+ <value></value>
+ <value></value>
+ <value></value>
+ </row>
+ <row>
+ <value>5</value>
+ <value>no pms</value>
+ <value>no pms</value>
+ <value>0</value>
+ <value>0</value>
+ <value></value>
+ <value></value>
+ <value></value>
+ <value></value>
+ </row>
+ </table>
+ <table name="phpbb_privmsgs">
+ <column>msg_id</column>
+ <column>root_level</column>
+ <column>author_id</column>
+ <column>message_subject</column>
+ <column>message_text</column>
+ <row>
+ <value>1</value>
+ <value>0</value>
+ <value>2</value>
+ <value>#1</value>
+ <value>#1</value>
+ </row>
+ <row>
+ <value>2</value>
+ <value>0</value>
+ <value>2</value>
+ <value>#2</value>
+ <value>#2</value>
+ </row>
+ </table>
+ <table name="phpbb_privmsgs_to">
+ <column>msg_id</column>
+ <column>user_id</column>
+ <column>author_id</column>
+ <column>pm_new</column>
+ <column>pm_unread</column>
+ <column>folder_id</column>
+ <row>
+ <value>1</value>
+ <value>2</value>
+ <value>2</value>
+ <value>0</value>
+ <value>0</value>
+ <value>-2</value>
+ </row>
+ <row>
+ <value>1</value>
+ <value>3</value>
+ <value>2</value>
+ <value>0</value>
+ <value>0</value>
+ <value>0</value>
+ </row>
+ <row>
+ <value>1</value>
+ <value>4</value>
+ <value>2</value>
+ <value>0</value>
+ <value>0</value>
+ <value>-3</value>
+ </row>
+ <row>
+ <value>2</value>
+ <value>2</value>
+ <value>2</value>
+ <value>0</value>
+ <value>0</value>
+ <value>-2</value>
+ </row>
+ <row>
+ <value>2</value>
+ <value>4</value>
+ <value>2</value>
+ <value>0</value>
+ <value>0</value>
+ <value>-3</value>
+ </row>
+ </table>
+</dataset>