aboutsummaryrefslogtreecommitdiffstats
path: root/tests/privmsgs/delete_user_pms_test.php
blob: 7345721d8bcfd6adb5d4b7121fc1983a97f86e74 (plain)
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
<?php
/**
*
* This file is part of the phpBB Forum Software package.
*
* @copyright (c) phpBB Limited <https://www.phpbb.com>
* @license GNU General Public License, version 2 (GPL-2.0)
*
* For full copyright and license information, please see
* the docs/CREDITS.txt file.
*
*/

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');
	}

	static public 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(
					array('msg_id' => 1, 'user_id' => 3),
				),
			),
			array(
				3,
				array(
					array('msg_id' => 1),
					array('msg_id' => 2),
					array('msg_id' => 3),
					array('msg_id' => 5),
				),
				array(
					array('msg_id' => 1, 'user_id' => 2),
					array('msg_id' => 1, 'user_id' => 4),
					array('msg_id' => 2, 'user_id' => 2),
					array('msg_id' => 2, 'user_id' => 4),
					array('msg_id' => 3, 'user_id' => 2),
					array('msg_id' => 5, 'user_id' => 2),
					array('msg_id' => 5, 'user_id' => 4),
				),
			),
			array(
				5,
				array(
					array('msg_id' => 1),
					array('msg_id' => 2),
					array('msg_id' => 3),
					array('msg_id' => 4),
					array('msg_id' => 5),
				),
				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('msg_id' => 3, 'user_id' => 2),
					array('msg_id' => 4, 'user_id' => 3),
					array('msg_id' => 5, 'user_id' => 2),
					array('msg_id' => 5, 'user_id' => 3),
					array('msg_id' => 5, 'user_id' => 4),
				),
			),
		);
	}

	/**
	* @dataProvider delete_user_pms_data
	*/
	public function test_delete_user_pms($delete_user, $remaining_privmsgs, $remaining_privmsgs_to)
	{
		global $db, $phpbb_container;

		$db = $this->new_dbal();

		$phpbb_container = new phpbb_mock_container_builder();
		$phpbb_container->set('notification_manager', new phpbb_mock_notification_manager());
		$phpbb_container->set('attachment.delete', new \phpbb\attachment\delete(new \phpbb\config\config(array()), $db, new \phpbb\attachment\resync($db)));

		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));
	}
}