aboutsummaryrefslogtreecommitdiffstats
path: root/tests/tree/nestedset_forum_base.php
blob: 1e79df2c0d8a86a21d5782ea71e6e396477a9ae4 (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
<?php
/**
*
* @package Nested Set Forum
* @copyright (c) 2013 phpBB Group
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/

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

	protected $forum_data = array(
		// \__/
		1	=> array('forum_id' => 1, 'parent_id' => 0, 'user_id' => 0, 'left_id' => 1, 'right_id' => 6, 'forum_parents' => ''),
		2	=> array('forum_id' => 2, 'parent_id' => 1, 'user_id' => 0, 'left_id' => 2, 'right_id' => 3, 'forum_parents' => ''),
		3	=> array('forum_id' => 3, 'parent_id' => 1, 'user_id' => 0, 'left_id' => 4, 'right_id' => 5, 'forum_parents' => ''),

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

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

		// Unexisting forums
		0	=> array('forum_id' => 0, 'parent_id' => 0, 'user_id' => 0, 'left_id' => 0, 'right_id' => 0, 'forum_parents' => ''),
		200	=> array('forum_id' => 200, 'parent_id' => 0, 'user_id' => 0, 'left_id' => 0, 'right_id' => 0, 'forum_parents' => ''),
	);

	protected $set,
		$config,
		$lock,
		$db;

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

		$this->db = $this->new_dbal();

		global $config;

		$config = $this->config = new phpbb_config(array('nestedset_forum_lock' => 0));
		set_config(null, null, null, $this->config);

		$this->lock = new phpbb_lock_db('nestedset_forum_lock', $this->config, $this->db);
		$this->set = new phpbb_tree_nestedset_forum($this->db, $this->lock, 'phpbb_forums');

		$this->set_up_forums();
	}

	protected function set_up_forums()
	{
		$this->create_forum('Parent with two flat children');
		$this->create_forum('Flat child #1', 1);
		$this->create_forum('Flat child #2', 1);

		$this->create_forum('Parent with two nested children');
		$this->create_forum('Nested child #1', 4);
		$this->create_forum('Nested child #2', 5);

		$this->create_forum('Parent with flat and nested children');
		$this->create_forum('Mixed child #1', 7);
		$this->create_forum('Mixed child #2', 7);
		$this->create_forum('Nested child #1 of Mixed child #2', 9);
		$this->create_forum('Mixed child #3', 7);
	}

	protected function create_forum($name, $parent_id = 0)
	{
		$forum = $this->set->insert(array('forum_name' => $name, 'forum_desc' => '', 'forum_rules' => ''));
		$this->set->change_parent($forum['forum_id'], $parent_id);
	}
}