aboutsummaryrefslogtreecommitdiffstats
path: root/tests/functional/ucp_allow_pm_test.php
blob: 2d41296ddf05b1e7d1e1015c9a1d606da8ffe507 (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
<?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.
*
*/

/**
* @group functional
*/
class phpbb_functional_ucp_allow_pm_test extends phpbb_functional_test_case
{
	static protected $data = array();

	public function __construct()
	{
		parent::__construct();

		$this->backupStaticAttributesBlacklist += array(
			'phpbb_functional_ucp_allow_pm_test' => array('data'),
		);
	}

	// user A sends a PM to user B where B accepts PM
	public function test_enabled_pm_user_to_user()
	{
		// setup
		$this->create_user('test_ucp_allow_pm_sender');
		$this->login('test_ucp_allow_pm_sender');
		self::$data['recipient_id'] = $this->create_user('test_ucp_allow_pm_recipient');
		self::$data['pm_url'] = "ucp.php?i=pm&mode=compose&u=" . (int) self::$data['recipient_id'] . "&sid={$this->sid}";

		// the actual test
		$this->set_user_allow_pm(self::$data['recipient_id'], 1);
		$crawler = self::request('GET', self::$data['pm_url']);
		$this->assertNotContainsLang('PM_USERS_REMOVED_NO_PM', $crawler->filter('html')->text());
	}

	// user A sends a PM to user B where B does not accept PM
	public function test_disabled_pm_user_to_user()
	{
		$this->login('test_ucp_allow_pm_sender');
		$this->set_user_allow_pm(self::$data['recipient_id'], 0);
		$crawler = self::request('GET', self::$data['pm_url']);
		$this->assertContainsLang('PM_USERS_REMOVED_NO_PM', $crawler->filter('.error')->text());
	}


	// An admin sends a PM to user B where B does not accept PM, but cannot
	// ignore a PM from an admin
	public function test_disabled_pm_admin_to_user()
	{
		$this->login();
		$crawler = self::request('GET', self::$data['pm_url']);
		$this->assertNotContainsLang('PM_USERS_REMOVED_NO_PM', $crawler->filter('html')->text());
	}

	// enable or disable PM for a user, like from ucp
	protected function set_user_allow_pm($user_id, $allow)
	{
		$db = $this->get_db();
		$sql = 'UPDATE ' . USERS_TABLE . "
			SET user_allow_pm = " . $allow . "
			WHERE user_id = " . $user_id;
		$result = $db->sql_query($sql);
		$db->sql_freeresult($result);
	}
}