aboutsummaryrefslogtreecommitdiffstats
path: root/tests/dbal/migrator_tool_permission_test.php
blob: 1090b4726a2c24223093edc1df748bb798da140b (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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
<?php
/**
*
* @package testing
* @copyright (c) 2011 phpBB Group
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*
*/

require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php';

class phpbb_dbal_migrator_tool_permission_test extends phpbb_database_test_case
{
	public function getDataSet()
	{
		return $this->createXMLDataSet(dirname(__FILE__).'/fixtures/migrator_permission.xml');
	}

	public function setup()
	{
		// Global $db and $cache are needed in acp/auth.php constructor
		global $phpbb_root_path, $phpEx, $db, $cache;

		parent::setup();

		$db = $this->db = $this->new_dbal();
		$cache = $this->cache = new \phpbb\cache\service(new \phpbb\cache\driver\null(), new \phpbb\config\config(array()), $this->db, $phpbb_root_path, $phpEx);
		$this->auth = new \phpbb\auth\auth();

		$this->tool = new \phpbb\db\migration\tool\permission($this->db, $this->cache, $this->auth, $phpbb_root_path, $phpEx);
	}

	public function exists_data()
	{
		return array(
			array(
				'global',
				true,
				true,
			),
			array(
				'local',
				false,
				true,
			),
			array(
				'both',
				true,
				true,
			),
			array(
				'both',
				false,
				true,
			),
			array(
				'does_not_exist',
				true,
				false,
			),
		);
	}

	/**
	* @dataProvider exists_data
	*/
	public function test_exists($auth_option, $global, $expected)
	{
		$this->assertEquals($expected, $this->tool->exists($auth_option, $global));
	}

	public function test_add()
	{
		try
		{
			$this->tool->add('new', true);
		}
		catch (Exception $e)
		{
			$this->fail($e);
		}
		$this->assertEquals(true, $this->tool->exists('new', true));
		$this->assertEquals(false, $this->tool->exists('new', false));

		try
		{
			$this->tool->add('new', false);
		}
		catch (Exception $e)
		{
			$this->fail($e);
		}
		$this->assertEquals(true, $this->tool->exists('new', false));

		// Should fail (duplicate)
		try
		{
			$this->tool->add('new', true);
			$this->fail('Did not throw exception on duplicate');
		}
		catch (Exception $e) {}
	}

	public function test_remove()
	{
		try
		{
			$this->tool->remove('global', true);
		}
		catch (Exception $e)
		{
			$this->fail($e);
		}
		$this->assertEquals(false, $this->tool->exists('global', true));

		try
		{
			$this->tool->remove('both', false);
		}
		catch (Exception $e)
		{
			$this->fail($e);
		}
		$this->assertEquals(false, $this->tool->exists('both', false));

		// Should fail (does not exist)
		try
		{
			$this->tool->remove('new', true);
			$this->fail('Did not throw exception on duplicate');
		}
		catch (Exception $e) {}
	}

	public function test_reverse()
	{
		try
		{
			$this->tool->reverse('remove', 'global_test', true);
		}
		catch (Exception $e)
		{
			$this->fail($e);
		}
		$this->assertTrue($this->tool->exists('global_test', true));

		try
		{
			$this->tool->reverse('add', 'global_test', true);
		}
		catch (Exception $e)
		{
			$this->fail($e);
		}
		$this->assertFalse($this->tool->exists('global_test', true));
	}
}