aboutsummaryrefslogtreecommitdiffstats
path: root/tests/nestedset/set_forum_add_remove_test.php
blob: 97b6348d6704fa3c0d343b321b3c11a1c6df2247 (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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
<?php
/**
*
* @package Nested Set
* @copyright (c) 2013 phpBB Group
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/

require_once dirname(__FILE__) . '/set_forum_base.php';

class phpbb_tests_nestedset_set_forum_add_remove_test extends phpbb_tests_nestedset_set_forum_base
{
	public function remove_add_data()
	{
		return array(
			array(1, array(1, 2, 3), array(
				array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 0, 'right_id' => 0, 'forum_parents' => ''),
				array('forum_id' => 2, 'parent_id' => 0, 'left_id' => 0, 'right_id' => 0, 'forum_parents' => ''),
				array('forum_id' => 3, 'parent_id' => 0, 'left_id' => 0, 'right_id' => 0, 'forum_parents' => ''),
				array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 6, 'forum_parents' => ''),
				array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 2, 'right_id' => 5, 'forum_parents' => ''),
				array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 3, 'right_id' => 4, 'forum_parents' => ''),
				array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 7, 'right_id' => 16, 'forum_parents' => ''),
				array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 8, 'right_id' => 9, 'forum_parents' => ''),
				array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 10, 'right_id' => 13, 'forum_parents' => ''),
				array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 11, 'right_id' => 12, 'forum_parents' => ''),
				array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 15, 'forum_parents' => ''),
			), array(
				1	=> array('parent_id' => 0, 'left_id' => 17, 'right_id' => 18, 'forum_parents' => ''),
				2	=> array('parent_id' => 0, 'left_id' => 19, 'right_id' => 20, 'forum_parents' => ''),
				3	=> array('parent_id' => 0, 'left_id' => 21, 'right_id' => 22, 'forum_parents' => ''),
			), array(
				array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 6, 'forum_parents' => ''),
				array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 2, 'right_id' => 5, 'forum_parents' => ''),
				array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 3, 'right_id' => 4, 'forum_parents' => ''),
				array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 7, 'right_id' => 16, 'forum_parents' => ''),
				array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 8, 'right_id' => 9, 'forum_parents' => ''),
				array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 10, 'right_id' => 13, 'forum_parents' => ''),
				array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 11, 'right_id' => 12, 'forum_parents' => ''),
				array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 15, 'forum_parents' => ''),
				array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 17, 'right_id' => 18, 'forum_parents' => ''),
				array('forum_id' => 2, 'parent_id' => 0, 'left_id' => 19, 'right_id' => 20, 'forum_parents' => ''),
				array('forum_id' => 3, 'parent_id' => 0, 'left_id' => 21, 'right_id' => 22, 'forum_parents' => ''),
			)),
			array(2, array(2), array(
				array('forum_id' => 2, 'parent_id' => 0, 'left_id' => 0, 'right_id' => 0, 'forum_parents' => ''),
				array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 4, 'forum_parents' => ''),
				array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 2, 'right_id' => 3, 'forum_parents' => ''),
				array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 5, 'right_id' => 10, 'forum_parents' => ''),
				array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 6, 'right_id' => 9, 'forum_parents' => ''),
				array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 7, 'right_id' => 8, 'forum_parents' => ''),
				array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 11, 'right_id' => 20, 'forum_parents' => ''),
				array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 12, 'right_id' => 13, 'forum_parents' => ''),
				array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 17, 'forum_parents' => ''),
				array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 15, 'right_id' => 16, 'forum_parents' => ''),
				array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 18, 'right_id' => 19, 'forum_parents' => ''),
			), array(
				2	=> array('parent_id' => 0, 'left_id' => 21, 'right_id' => 22, 'forum_parents' => '')
			), array(
				array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 4, 'forum_parents' => ''),
				array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 2, 'right_id' => 3, 'forum_parents' => ''),
				array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 5, 'right_id' => 10, 'forum_parents' => ''),
				array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 6, 'right_id' => 9, 'forum_parents' => ''),
				array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 7, 'right_id' => 8, 'forum_parents' => ''),
				array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 11, 'right_id' => 20, 'forum_parents' => ''),
				array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 12, 'right_id' => 13, 'forum_parents' => ''),
				array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 17, 'forum_parents' => ''),
				array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 15, 'right_id' => 16, 'forum_parents' => ''),
				array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 18, 'right_id' => 19, 'forum_parents' => ''),
				array('forum_id' => 2, 'parent_id' => 0, 'left_id' => 21, 'right_id' => 22, 'forum_parents' => ''),
			)),
		);
	}

	/**
	* @dataProvider remove_add_data
	*/
	public function test_remove_add($forum_id, $expected_removed, $expected_remove_table, $expected_added, $expected_add_table)
	{
		$removed_items = $this->set->remove($forum_id);

		$this->assertEquals($expected_removed, $removed_items);

		$result = $this->db->sql_query("SELECT forum_id, parent_id, left_id, right_id, forum_parents
			FROM phpbb_forums
			ORDER BY left_id, forum_id ASC");
		$this->assertEquals($expected_remove_table, $this->db->sql_fetchrowset($result));

		$added_items = array();
		foreach ($removed_items as $item_id)
		{
			$added_items[$item_id] = $this->set->add(array_merge($this->forum_data[$item_id], array(
				'forum_rules'	=> '',
				'forum_desc'	=> '',
				'parent_id'	=> 0,
				'left_id'	=> 0,
				'right_id'	=> 0,
			)));
		}
		$this->assertEquals($expected_added, $added_items);

		$result = $this->db->sql_query("SELECT forum_id, parent_id, left_id, right_id, forum_parents
			FROM phpbb_forums
			ORDER BY left_id, forum_id ASC");
		$this->assertEquals($expected_add_table, $this->db->sql_fetchrowset($result));
	}

	public function delete_data()
	{
		return array(
			array(1, array(1, 2, 3), array(
				array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 6, 'forum_parents' => ''),
				array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 2, 'right_id' => 5, 'forum_parents' => ''),
				array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 3, 'right_id' => 4, 'forum_parents' => ''),
				array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 7, 'right_id' => 16, 'forum_parents' => ''),
				array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 8, 'right_id' => 9, 'forum_parents' => ''),
				array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 10, 'right_id' => 13, 'forum_parents' => ''),
				array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 11, 'right_id' => 12, 'forum_parents' => ''),
				array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 15, 'forum_parents' => ''),
			)),
			array(2, array(2), array(
				array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 4, 'forum_parents' => ''),
				array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 2, 'right_id' => 3, 'forum_parents' => ''),
				array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 5, 'right_id' => 10, 'forum_parents' => ''),
				array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 6, 'right_id' => 9, 'forum_parents' => ''),
				array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 7, 'right_id' => 8, 'forum_parents' => ''),
				array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 11, 'right_id' => 20, 'forum_parents' => ''),
				array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 12, 'right_id' => 13, 'forum_parents' => ''),
				array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 17, 'forum_parents' => ''),
				array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 15, 'right_id' => 16, 'forum_parents' => ''),
				array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 18, 'right_id' => 19, 'forum_parents' => ''),
			)),
		);
	}

	/**
	* @dataProvider delete_data
	*/
	public function test_delete($forum_id, $expected_deleted, $expected)
	{
		$this->assertEquals($expected_deleted, $this->set->delete($forum_id));

		$result = $this->db->sql_query("SELECT forum_id, parent_id, left_id, right_id, forum_parents
			FROM phpbb_forums
			ORDER BY left_id, forum_id ASC");
		$this->assertEquals($expected, $this->db->sql_fetchrowset($result));
	}

	public function insert_data()
	{
		return array(
			array(array(
				'forum_desc'	=> '',
				'forum_rules'	=> '',
				'forum_id'		=> 12,
				'parent_id'		=> 0,
				'left_id'		=> 23,
				'right_id'		=> 24,
				'forum_parents'	=> '',
			), array(
				array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 6, 'forum_parents' => ''),
				array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 2, 'right_id' => 3, 'forum_parents' => ''),
				array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 4, 'right_id' => 5, 'forum_parents' => ''),

				array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 7, 'right_id' => 12, 'forum_parents' => ''),
				array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 8, 'right_id' => 11, 'forum_parents' => ''),
				array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 9, 'right_id' => 10, 'forum_parents' => ''),

				array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 13, 'right_id' => 22, 'forum_parents' => ''),
				array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 15, 'forum_parents' => ''),
				array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 16, 'right_id' => 19, 'forum_parents' => ''),
				array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 17, 'right_id' => 18, 'forum_parents' => ''),
				array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 20, 'right_id' => 21, 'forum_parents' => ''),

				array('forum_id' => 12, 'parent_id' => 0, 'left_id' => 23, 'right_id' => 24, 'forum_parents' => ''),
			)),
		);
	}

	/**
	* @dataProvider insert_data
	*/
	public function test_insert($expected_data, $expected)
	{
		$this->assertEquals($expected_data, $this->set->insert(array(
			'forum_desc'	=> '',
			'forum_rules'	=> '',
		)));

		$result = $this->db->sql_query('SELECT forum_id, parent_id, left_id, right_id, forum_parents
			FROM phpbb_forums
			ORDER BY left_id, forum_id ASC');
		$this->assertEquals($expected, $this->db->sql_fetchrowset($result));
	}
}