diff options
Diffstat (limited to 'tests/tree')
-rw-r--r-- | tests/tree/fixtures/phpbb_forums.xml | 13 | ||||
-rw-r--r-- | tests/tree/nestedset_forum_add_remove_test.php | 196 | ||||
-rw-r--r-- | tests/tree/nestedset_forum_base.php | 86 | ||||
-rw-r--r-- | tests/tree/nestedset_forum_get_data_test.php | 117 | ||||
-rw-r--r-- | tests/tree/nestedset_forum_move_test.php | 569 | ||||
-rw-r--r-- | tests/tree/nestedset_forum_regenerate_test.php | 72 | ||||
-rw-r--r-- | tests/tree/nestedset_forum_test.php | 116 |
7 files changed, 1169 insertions, 0 deletions
diff --git a/tests/tree/fixtures/phpbb_forums.xml b/tests/tree/fixtures/phpbb_forums.xml new file mode 100644 index 0000000000..8f133078a9 --- /dev/null +++ b/tests/tree/fixtures/phpbb_forums.xml @@ -0,0 +1,13 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<dataset> + <table name="phpbb_forums"> + <column>forum_id</column> + <column>parent_id</column> + <column>left_id</column> + <column>right_id</column> + <column>forum_parents</column> + <column>forum_name</column> + <column>forum_desc</column> + <column>forum_rules</column> + </table> +</dataset> diff --git a/tests/tree/nestedset_forum_add_remove_test.php b/tests/tree/nestedset_forum_add_remove_test.php new file mode 100644 index 0000000000..623cb2bbf3 --- /dev/null +++ b/tests/tree/nestedset_forum_add_remove_test.php @@ -0,0 +1,196 @@ +<?php +/** +* +* @package Nested Set Forum +* @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_tree_nestedset_forum_add_remove_test extends phpbb_tests_tree_nestedset_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)); + } +} diff --git a/tests/tree/nestedset_forum_base.php b/tests/tree/nestedset_forum_base.php new file mode 100644 index 0000000000..1e79df2c0d --- /dev/null +++ b/tests/tree/nestedset_forum_base.php @@ -0,0 +1,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); + } +} diff --git a/tests/tree/nestedset_forum_get_data_test.php b/tests/tree/nestedset_forum_get_data_test.php new file mode 100644 index 0000000000..4ce679f05d --- /dev/null +++ b/tests/tree/nestedset_forum_get_data_test.php @@ -0,0 +1,117 @@ +<?php +/** +* +* @package Nested Set Forum +* @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_tree_nestedset_forum_get_data_test extends phpbb_tests_tree_nestedset_forum_base +{ + public function get_full_branch_data_data() + { + return array( + array(1, true, true, array(1, 2, 3)), + array(1, true, false, array(2, 3)), + array(1, false, true, array(3, 2, 1)), + array(1, false, false, array(3, 2)), + + array(2, true, true, array(1, 2)), + array(2, true, false, array(1)), + array(2, false, true, array(2, 1)), + array(2, false, false, array(1)), + + array(5, true, true, array(4, 5, 6)), + array(5, true, false, array(4, 6)), + array(5, false, true, array(6, 5, 4)), + array(5, false, false, array(6, 4)), + ); + } + + /** + * @dataProvider get_full_branch_data_data + */ + public function test_get_full_branch_data($forum_id, $order_desc, $include_item, $expected) + { + $this->assertEquals($expected, array_keys($this->set->get_full_branch_data($forum_id, $order_desc, $include_item))); + } + + public function get_parent_branch_data_data() + { + return array( + array(1, true, true, array(1)), + array(1, true, false, array()), + array(1, false, true, array(1)), + array(1, false, false, array()), + + array(2, true, true, array(1, 2)), + array(2, true, false, array(1)), + array(2, false, true, array(2, 1)), + array(2, false, false, array(1)), + + array(5, true, true, array(4, 5)), + array(5, true, false, array(4)), + array(5, false, true, array(5, 4)), + array(5, false, false, array(4)), + ); + } + + /** + * @dataProvider get_parent_branch_data_data + */ + public function test_get_parent_branch_data($forum_id, $order_desc, $include_item, $expected) + { + $this->assertEquals($expected, array_keys($this->set->get_parent_branch_data($forum_id, $order_desc, $include_item))); + } + + public function get_children_branch_data_data() + { + return array( + array(1, true, true, array(1, 2, 3)), + array(1, true, false, array(2, 3)), + array(1, false, true, array(3, 2, 1)), + array(1, false, false, array(3, 2)), + + array(2, true, true, array(2)), + array(2, true, false, array()), + array(2, false, true, array(2)), + array(2, false, false, array()), + + array(5, true, true, array(5, 6)), + array(5, true, false, array(6)), + array(5, false, true, array(6, 5)), + array(5, false, false, array(6)), + ); + } + + /** + * @dataProvider get_children_branch_data_data + */ + public function test_get_children_branch_data($forum_id, $order_desc, $include_item, $expected) + { + $this->assertEquals($expected, array_keys($this->set->get_children_branch_data($forum_id, $order_desc, $include_item))); + } + + public function get_parent_data_data() + { + return array( + array(1, array(), array()), + array(1, array('forum_parents' => serialize(array())), array()), + array(2, array(), array(1)), + array(2, array('forum_parents' => serialize(array(1 => array()))), array(1)), + array(10, array(), array(7, 9)), + array(10, array('forum_parents' => serialize(array(7 => array(), 9 => array()))), array(7, 9)), + ); + } + + /** + * @dataProvider get_parent_data_data + */ + public function test_get_parent_data($forum_id, $forum_data, $expected) + { + $this->assertEquals($expected, array_keys($this->set->get_parent_data(array_merge($this->forum_data[$forum_id], $forum_data)))); + } +} diff --git a/tests/tree/nestedset_forum_move_test.php b/tests/tree/nestedset_forum_move_test.php new file mode 100644 index 0000000000..29af693374 --- /dev/null +++ b/tests/tree/nestedset_forum_move_test.php @@ -0,0 +1,569 @@ +<?php +/** +* +* @package Nested Set Forum +* @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_tree_nestedset_forum_move_test extends phpbb_tests_tree_nestedset_forum_base +{ + public function move_data() + { + return array( + array('Move first item up', + 1, 1, false, 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('Move last item down', + 7, -1, false, 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('Move first item down', + 1, -1, true, 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' => 1, 'parent_id' => 0, 'left_id' => 7, 'right_id' => 12, 'forum_parents' => ''), + array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 8, 'right_id' => 9, 'forum_parents' => ''), + array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 10, 'right_id' => 11, '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('Move second item up', + 4, 1, true, 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' => 1, 'parent_id' => 0, 'left_id' => 7, 'right_id' => 12, 'forum_parents' => ''), + array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 8, 'right_id' => 9, 'forum_parents' => ''), + array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 10, 'right_id' => 11, '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('Move last item up', + 7, 1, true, 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' => 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' => 4, 'parent_id' => 0, 'left_id' => 17, 'right_id' => 22, 'forum_parents' => ''), + array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 18, 'right_id' => 21, 'forum_parents' => ''), + array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 19, 'right_id' => 20, 'forum_parents' => ''), + )), + array('Move last item up by 2', + 7, 2, true, array( + array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 10, 'forum_parents' => ''), + array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 2, 'right_id' => 3, 'forum_parents' => ''), + array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 4, 'right_id' => 7, 'forum_parents' => ''), + array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 5, 'right_id' => 6, 'forum_parents' => ''), + array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 8, 'right_id' => 9, 'forum_parents' => ''), + array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 11, 'right_id' => 16, 'forum_parents' => ''), + array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 12, 'right_id' => 13, 'forum_parents' => ''), + array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 14, 'right_id' => 15, 'forum_parents' => ''), + array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 17, 'right_id' => 22, 'forum_parents' => ''), + array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 18, 'right_id' => 21, 'forum_parents' => ''), + array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 19, 'right_id' => 20, 'forum_parents' => ''), + )), + array('Move last item up by 100', + 7, 100, true, array( + array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 10, 'forum_parents' => ''), + array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 2, 'right_id' => 3, 'forum_parents' => ''), + array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 4, 'right_id' => 7, 'forum_parents' => ''), + array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 5, 'right_id' => 6, 'forum_parents' => ''), + array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 8, 'right_id' => 9, 'forum_parents' => ''), + array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 11, 'right_id' => 16, 'forum_parents' => ''), + array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 12, 'right_id' => 13, 'forum_parents' => ''), + array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 14, 'right_id' => 15, 'forum_parents' => ''), + array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 17, 'right_id' => 22, 'forum_parents' => ''), + array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 18, 'right_id' => 21, 'forum_parents' => ''), + array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 19, 'right_id' => 20, 'forum_parents' => ''), + )), + ); + } + + /** + * @dataProvider move_data + */ + public function test_move($explain, $forum_id, $delta, $expected_moved, $expected) + { + $this->assertEquals($expected_moved, $this->set->move($forum_id, $delta)); + + $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 move_down_data() + { + return array( + array('Move last item down', + 7, false, 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('Move first item down', + 1, true, 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' => 1, 'parent_id' => 0, 'left_id' => 7, 'right_id' => 12, 'forum_parents' => ''), + array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 8, 'right_id' => 9, 'forum_parents' => ''), + array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 10, 'right_id' => 11, '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' => ''), + )), + ); + } + + /** + * @dataProvider move_down_data + */ + public function test_move_down($explain, $forum_id, $expected_moved, $expected) + { + $this->assertEquals($expected_moved, $this->set->move_down($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 move_up_data() + { + return array( + array('Move first item up', + 1, false, 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('Move second item up', + 4, true, 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' => 1, 'parent_id' => 0, 'left_id' => 7, 'right_id' => 12, 'forum_parents' => ''), + array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 8, 'right_id' => 9, 'forum_parents' => ''), + array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 10, 'right_id' => 11, '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' => ''), + )), + ); + } + + /** + * @dataProvider move_up_data + */ + public function test_move_up($explain, $forum_id, $expected_moved, $expected) + { + $this->assertEquals($expected_moved, $this->set->move_up($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 move_children_data() + { + return array( + array('Item has no children', + 2, 1, false, 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('Move to same parent', + 4, 4, false, 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('Move single child up', + 5, 1, true, array( + array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 8, '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' => 6, 'parent_id' => 1, 'left_id' => 6, 'right_id' => 7, 'forum_parents' => ''), + + array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 9, 'right_id' => 12, 'forum_parents' => ''), + array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 10, 'right_id' => 11, '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('Move nested children up', + 4, 1, true, array( + array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 10, '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' => 5, 'parent_id' => 1, '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' => 4, 'parent_id' => 0, 'left_id' => 11, 'right_id' => 12, '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('Move single child down', + 5, 7, true, 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' => 10, 'forum_parents' => ''), + array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 8, 'right_id' => 9, 'forum_parents' => ''), + + array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 11, 'right_id' => 22, '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' => 6, 'parent_id' => 7, 'left_id' => 20, 'right_id' => 21, 'forum_parents' => ''), + + )), + array('Move nested children down', + 4, 7, true, 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' => 8, 'forum_parents' => ''), + + array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 9, 'right_id' => 22, 'forum_parents' => ''), + array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 10, 'right_id' => 11, 'forum_parents' => ''), + array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 12, 'right_id' => 15, 'forum_parents' => ''), + array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 13, 'right_id' => 14, 'forum_parents' => ''), + array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 16, 'right_id' => 17, 'forum_parents' => ''), + array('forum_id' => 5, 'parent_id' => 7, 'left_id' => 18, 'right_id' => 21, 'forum_parents' => ''), + array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 19, 'right_id' => 20, 'forum_parents' => ''), + )), + array('Move single child to parent 0', + 5, 0, true, 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' => 10, 'forum_parents' => ''), + array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 8, 'right_id' => 9, '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' => 6, 'parent_id' => 0, 'left_id' => 21, 'right_id' => 22, 'forum_parents' => ''), + )), + array('Move nested children to parent 0', + 4, 0, true, 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' => 8, 'forum_parents' => ''), + + array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 9, 'right_id' => 18, 'forum_parents' => ''), + array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 10, 'right_id' => 11, 'forum_parents' => ''), + array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 12, 'right_id' => 15, 'forum_parents' => ''), + array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 13, 'right_id' => 14, 'forum_parents' => ''), + array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 16, 'right_id' => 17, 'forum_parents' => ''), + + array('forum_id' => 5, 'parent_id' => 0, 'left_id' => 19, 'right_id' => 22, 'forum_parents' => ''), + array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 20, 'right_id' => 21, 'forum_parents' => ''), + )), + ); + } + + /** + * @dataProvider move_children_data + */ + public function test_move_children($explain, $forum_id, $target_id, $expected_moved, $expected) + { + $this->assertEquals($expected_moved, $this->set->move_children($forum_id, $target_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 move_children_throws_item_data() + { + return array( + array('Item 0 does not exist', 0, 5), + array('Item does not exist', 200, 5), + ); + } + + /** + * @dataProvider move_children_throws_item_data + * + * @expectedException OutOfBoundsException + * @expectedExceptionMessage FORUM_NESTEDSET_INVALID_ITEM + */ + public function test_move_children_throws_item($explain, $forum_id, $target_id) + { + $this->set->move_children($forum_id, $target_id); + } + + public function move_children_throws_parent_data() + { + return array( + array('New parent is child', 4, 5), + array('New parent is child 2', 7, 9), + array('New parent does not exist', 1, 200), + ); + } + + /** + * @dataProvider move_children_throws_parent_data + * + * @expectedException OutOfBoundsException + * @expectedExceptionMessage FORUM_NESTEDSET_INVALID_PARENT + */ + public function test_move_children_throws_parent($explain, $forum_id, $target_id) + { + $this->set->move_children($forum_id, $target_id); + } + + public function change_parent_data() + { + return array( + array('Move single child up', + 6, 1, true, array( + array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 8, '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' => 6, 'parent_id' => 1, 'left_id' => 6, 'right_id' => 7, 'forum_parents' => ''), + + array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 9, 'right_id' => 12, 'forum_parents' => ''), + array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 10, 'right_id' => 11, '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('Move nested children up', + 5, 1, true, array( + array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 10, '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' => 5, 'parent_id' => 1, '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' => 4, 'parent_id' => 0, 'left_id' => 11, 'right_id' => 12, '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('Move single child down', + 6, 7, true, 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' => 10, 'forum_parents' => ''), + array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 8, 'right_id' => 9, 'forum_parents' => ''), + + array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 11, 'right_id' => 22, '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' => 6, 'parent_id' => 7, 'left_id' => 20, 'right_id' => 21, 'forum_parents' => ''), + )), + array('Move nested children down', + 5, 7, true, 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' => 8, 'forum_parents' => ''), + + array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 9, 'right_id' => 22, 'forum_parents' => ''), + array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 10, 'right_id' => 11, 'forum_parents' => ''), + array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 12, 'right_id' => 15, 'forum_parents' => ''), + array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 13, 'right_id' => 14, 'forum_parents' => ''), + array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 16, 'right_id' => 17, 'forum_parents' => ''), + array('forum_id' => 5, 'parent_id' => 7, 'left_id' => 18, 'right_id' => 21, 'forum_parents' => ''), + array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 19, 'right_id' => 20, 'forum_parents' => ''), + )), + array('Move single child to parent 0', + 6, 0, true, 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' => 10, 'forum_parents' => ''), + array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 8, 'right_id' => 9, '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' => 6, 'parent_id' => 0, 'left_id' => 21, 'right_id' => 22, 'forum_parents' => ''), + )), + array('Move nested children to parent 0', + 5, 0, true, 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' => 8, 'forum_parents' => ''), + + array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 9, 'right_id' => 18, 'forum_parents' => ''), + array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 10, 'right_id' => 11, 'forum_parents' => ''), + array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 12, 'right_id' => 15, 'forum_parents' => ''), + array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 13, 'right_id' => 14, 'forum_parents' => ''), + array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 16, 'right_id' => 17, 'forum_parents' => ''), + + array('forum_id' => 5, 'parent_id' => 0, 'left_id' => 19, 'right_id' => 22, 'forum_parents' => ''), + array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 20, 'right_id' => 21, 'forum_parents' => ''), + )), + ); + } + + /** + * @dataProvider change_parent_data + */ + public function test_change_parent($explain, $forum_id, $target_id, $expected_moved, $expected) + { + $this->assertEquals($expected_moved, $this->set->change_parent($forum_id, $target_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 change_parent_throws_item_data() + { + return array( + array('Item 0 does not exist', 0, 5), + array('Item does not exist', 200, 5), + ); + } + + /** + * @dataProvider change_parent_throws_item_data + * + * @expectedException OutOfBoundsException + * @expectedExceptionMessage FORUM_NESTEDSET_INVALID_ITEM + */ + public function test_change_parent_throws_item($explain, $forum_id, $target_id) + { + $this->set->change_parent($forum_id, $target_id); + } + + public function change_parent_throws_parent_data() + { + return array( + array('New parent is child', 4, 5), + array('New parent is child 2', 7, 9), + array('New parent does not exist', 1, 200), + ); + } + + /** + * @dataProvider change_parent_throws_parent_data + * + * @expectedException OutOfBoundsException + * @expectedExceptionMessage FORUM_NESTEDSET_INVALID_PARENT + */ + public function test_change_parent_throws_parent($explain, $forum_id, $target_id) + { + $this->set->change_parent($forum_id, $target_id); + } +} diff --git a/tests/tree/nestedset_forum_regenerate_test.php b/tests/tree/nestedset_forum_regenerate_test.php new file mode 100644 index 0000000000..3bd272370a --- /dev/null +++ b/tests/tree/nestedset_forum_regenerate_test.php @@ -0,0 +1,72 @@ +<?php +/** +* +* @package Nested Set Forum +* @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_tree_nestedset_forum_regenerate_test extends phpbb_tests_tree_nestedset_forum_base +{ + protected $fixed_set = 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' => ''), + ); + + public function regenerate_left_right_ids_data() + { + return array( + array('UPDATE phpbb_forums + SET left_id = 0, + right_id = 0', false), + array('UPDATE phpbb_forums + SET left_id = 28, + right_id = 28 + WHERE left_id > 12', false), + array('UPDATE phpbb_forums + SET left_id = left_id * 2, + right_id = right_id * 2', false), + array('UPDATE phpbb_forums + SET left_id = left_id * 2, + right_id = right_id * 2 + WHERE left_id > 12', false), + array('UPDATE phpbb_forums + SET left_id = left_id - 4, + right_id = right_id * 4 + WHERE left_id > 4', false), + array('UPDATE phpbb_forums + SET left_id = 0, + right_id = 0 + WHERE left_id > 12', true), + ); + } + + /** + * @dataProvider regenerate_left_right_ids_data + */ + public function test_regenerate_left_right_ids($breaking_query, $reset_ids) + { + $result = $this->db->sql_query($breaking_query); + + $this->assertEquals(23, $this->set->regenerate_left_right_ids(1, 0, $reset_ids)); + + $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($this->fixed_set, $this->db->sql_fetchrowset($result)); + } +} diff --git a/tests/tree/nestedset_forum_test.php b/tests/tree/nestedset_forum_test.php new file mode 100644 index 0000000000..ac02886e95 --- /dev/null +++ b/tests/tree/nestedset_forum_test.php @@ -0,0 +1,116 @@ +<?php +/** +* +* @package Nested Set Forum +* @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 pphpbb_tests_tree_nestedset_forum_test extends phpbb_tests_tree_nestedset_forum_base +{ + public function forum_constructor_data() + { + return array( + array(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' => ''), + )), + ); + } + + /** + * @dataProvider forum_constructor_data + */ + public function test_forum_constructor($expected) + { + $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 get_sql_where_data() + { + return array( + array('SELECT forum_id, parent_id, left_id, right_id, forum_parents + FROM phpbb_forums + %s + ORDER BY left_id, forum_id ASC', + 'WHERE', '', 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('SELECT f.forum_id, f.parent_id, f.left_id, f.right_id, f.forum_parents + FROM phpbb_forums f + %s + ORDER BY f.left_id, f.forum_id ASC', + 'WHERE', 'f.', 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('SELECT forum_id, parent_id, left_id, right_id, forum_parents + FROM phpbb_forums + WHERE forum_id < 4 %s + ORDER BY left_id, forum_id ASC', + 'AND', '', 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('SELECT f.forum_id, f.parent_id, f.left_id, f.right_id, f.forum_parents + FROM phpbb_forums f + WHERE f.forum_id < 4 %s + ORDER BY f.left_id, f.forum_id ASC', + 'AND', 'f.', 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' => ''), + )), + ); + } + + /** + * @dataProvider get_sql_where_data + */ + public function test_get_sql_where($sql_query, $operator, $column_prefix, $expected) + { + $result = $this->db->sql_query(sprintf($sql_query, $this->set->get_sql_where($operator, $column_prefix))); + $this->assertEquals($expected, $this->db->sql_fetchrowset($result)); + } +} |