aboutsummaryrefslogtreecommitdiffstats
path: root/tests/mock/user.php
blob: 9888337a9eda8d55284d6b7a1c2fdd03dd36723d (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
<?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.
*
*/

/**
* Mock user class.
* This class is used when tests invoke phpBB code expecting to have a global
* user object, to avoid instantiating the actual user object.
* It has a minimum amount of functionality, just to make tests work.
*/
class phpbb_mock_user
{
	public $host = "testhost";
	public $page = array('root_script_path' => '/');
	
	private $options = array();
	public function optionget($item)
	{
		if (!isset($this->options[$item]))
		{
			throw new Exception(sprintf("You didn't set the option '%s' on the mock user using optionset.", $item));
		}
		
		return $this->options[$item];
	}
	
	public function optionset($item, $value)
	{
		$this->options[$item] = $value;
	}

	public function check_ban($user_id = false, $user_ips = false, $user_email = false, $return = false)
	{
		$banned_users = $this->optionget('banned_users');
		foreach ($banned_users as $banned)
		{
			if ($banned == $user_id || $banned == $user_ips || $banned == $user_email)
			{
				return true;
			}
		}
		return false;
	}

	public function lang()
	{
		return implode(' ', func_get_args());
	}
}