diff options
author | Joas Schilling <nickvergessen@gmx.de> | 2012-11-13 11:22:30 +0100 |
---|---|---|
committer | Joas Schilling <nickvergessen@gmx.de> | 2012-11-13 11:22:30 +0100 |
commit | ff7465e75f129d23a0f9f4fd6a1c556ec2b7bb13 (patch) | |
tree | 5c50b290a4d8c5f7186aa9df32125a478a3ae0ec /tests/groupposition | |
parent | 69845585a2bc6720e6c512227f436782c7bf5d29 (diff) | |
download | forums-ff7465e75f129d23a0f9f4fd6a1c556ec2b7bb13.tar forums-ff7465e75f129d23a0f9f4fd6a1c556ec2b7bb13.tar.gz forums-ff7465e75f129d23a0f9f4fd6a1c556ec2b7bb13.tar.bz2 forums-ff7465e75f129d23a0f9f4fd6a1c556ec2b7bb13.tar.xz forums-ff7465e75f129d23a0f9f4fd6a1c556ec2b7bb13.zip |
[ticket/10411] New class interface and unit tests for legend and teampage
PHPBB3-10411
Diffstat (limited to 'tests/groupposition')
-rw-r--r-- | tests/groupposition/fixtures/legend.xml | 23 | ||||
-rw-r--r-- | tests/groupposition/fixtures/teampage.xml | 102 | ||||
-rw-r--r-- | tests/groupposition/legend_test.php | 300 | ||||
-rw-r--r-- | tests/groupposition/teampage_test.php | 479 |
4 files changed, 904 insertions, 0 deletions
diff --git a/tests/groupposition/fixtures/legend.xml b/tests/groupposition/fixtures/legend.xml new file mode 100644 index 0000000000..a9209309bd --- /dev/null +++ b/tests/groupposition/fixtures/legend.xml @@ -0,0 +1,23 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<dataset> + <table name="phpbb_groups"> + <column>group_id</column> + <column>group_legend</column> + <column>group_desc</column> + <row> + <value>1</value> + <value>0</value> + <value></value> + </row> + <row> + <value>2</value> + <value>1</value> + <value></value> + </row> + <row> + <value>3</value> + <value>2</value> + <value></value> + </row> + </table> +</dataset> diff --git a/tests/groupposition/fixtures/teampage.xml b/tests/groupposition/fixtures/teampage.xml new file mode 100644 index 0000000000..b6c39045e3 --- /dev/null +++ b/tests/groupposition/fixtures/teampage.xml @@ -0,0 +1,102 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<dataset> + <table name="phpbb_groups"> + <column>group_id</column> + <column>group_desc</column> + <row> + <value>1</value> + <value></value> + </row> + <row> + <value>2</value> + <value></value> + </row> + <row> + <value>3</value> + <value></value> + </row> + <row> + <value>4</value> + <value></value> + </row> + <row> + <value>5</value> + <value></value> + </row> + <row> + <value>6</value> + <value></value> + </row> + <row> + <value>7</value> + <value></value> + </row> + <row> + <value>8</value> + <value></value> + </row> + </table> + <table name="phpbb_teampage"> + <column>teampage_id</column> + <column>group_id</column> + <column>teampage_name</column> + <column>teampage_position</column> + <column>teampage_parent</column> + <row> + <value>1</value> + <value>1</value> + <value></value> + <value>1</value> + <value>0</value> + </row> + <row> + <value>2</value> + <value>0</value> + <value>category - 2 children</value> + <value>2</value> + <value>0</value> + </row> + <row> + <value>3</value> + <value>2</value> + <value></value> + <value>3</value> + <value>2</value> + </row> + <row> + <value>4</value> + <value>3</value> + <value></value> + <value>4</value> + <value>2</value> + </row> + <row> + <value>5</value> + <value>0</value> + <value>category2 - 2 children</value> + <value>5</value> + <value>0</value> + </row> + <row> + <value>6</value> + <value>4</value> + <value></value> + <value>6</value> + <value>5</value> + </row> + <row> + <value>7</value> + <value>5</value> + <value></value> + <value>7</value> + <value>5</value> + </row> + <row> + <value>8</value> + <value>6</value> + <value></value> + <value>8</value> + <value>0</value> + </row> + </table> +</dataset> diff --git a/tests/groupposition/legend_test.php b/tests/groupposition/legend_test.php new file mode 100644 index 0000000000..a2a16e06ad --- /dev/null +++ b/tests/groupposition/legend_test.php @@ -0,0 +1,300 @@ +<?php +/** +* +* @package testing +* @copyright (c) 2012 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ + + +class phpbb_groupposition_legend_test extends phpbb_database_test_case +{ + public function getDataSet() + { + return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/legend.xml'); + } + + public function get_group_value_data() + { + return array( + array(1, 0), + array(3, 2), + ); + } + + /** + * @dataProvider get_group_value_data + */ + public function test_get_group_value($group_id, $expected) + { + global $cache; + + $cache = new phpbb_mock_cache; + $db = $this->new_dbal(); + $user = new phpbb_user; + $user->lang = array(); + + $test_class = new phpbb_groupposition_legend($db, $user, ''); + $this->assertEquals($expected, $test_class->get_group_value($group_id)); + } + + public function test_get_group_count() + { + global $cache; + + $cache = new phpbb_mock_cache; + $db = $this->new_dbal(); + $user = new phpbb_user; + $user->lang = array(); + + $test_class = new phpbb_groupposition_legend($db, $user, ''); + $this->assertEquals(2, $test_class->get_group_count()); + } + + public function add_group_data() + { + return array( + array(1, array( + array('group_id' => 1, 'group_legend' => 3), + array('group_id' => 2, 'group_legend' => 1), + array('group_id' => 3, 'group_legend' => 2), + )), + array(2, array( + array('group_id' => 1, 'group_legend' => 0), + array('group_id' => 2, 'group_legend' => 1), + array('group_id' => 3, 'group_legend' => 2), + )), + ); + } + + /** + * @dataProvider add_group_data + */ + public function test_add_group($group_id, $expected) + { + global $cache; + + $cache = new phpbb_mock_cache; + $db = $this->new_dbal(); + $user = new phpbb_user; + $user->lang = array(); + + $test_class = new phpbb_groupposition_legend($db, $user, ''); + $test_class->add_group($group_id); + + $result = $db->sql_query('SELECT group_id, group_legend + FROM ' . GROUPS_TABLE . ' + ORDER BY group_id ASC'); + + $this->assertEquals($expected, $db->sql_fetchrowset($result)); + } + + public function delete_group_data() + { + return array( + array(1, false, array( + array('group_id' => 1, 'group_legend' => 0), + array('group_id' => 2, 'group_legend' => 1), + array('group_id' => 3, 'group_legend' =>2), + )), + array(2, false, array( + array('group_id' => 1, 'group_legend' => 0), + array('group_id' => 2, 'group_legend' => 0), + array('group_id' => 3, 'group_legend' => 1), + )), + array(3, false, array( + array('group_id' => 1, 'group_legend' => 0), + array('group_id' => 2, 'group_legend' => 1), + array('group_id' => 3, 'group_legend' => 0), + )), + array(1, true, array( + array('group_id' => 1, 'group_legend' => 0), + array('group_id' => 2, 'group_legend' => 1), + array('group_id' => 3, 'group_legend' => 2), + )), + array(2, true, array( + array('group_id' => 1, 'group_legend' => 0), + array('group_id' => 2, 'group_legend' => 1), + array('group_id' => 3, 'group_legend' => 1), + )), + array(3, true, array( + array('group_id' => 1, 'group_legend' => 0), + array('group_id' => 2, 'group_legend' => 1), + array('group_id' => 3, 'group_legend' => 2), + )), + ); + } + + /** + * @dataProvider delete_group_data + */ + public function test_delete_group($group_id, $skip_group, $expected) + { + global $cache; + + $cache = new phpbb_mock_cache; + $db = $this->new_dbal(); + $user = new phpbb_user; + $user->lang = array(); + + $test_class = new phpbb_groupposition_legend($db, $user, ''); + $test_class->delete_group($group_id, $skip_group); + + $result = $db->sql_query('SELECT group_id, group_legend + FROM ' . GROUPS_TABLE . ' + ORDER BY group_id ASC'); + + $this->assertEquals($expected, $db->sql_fetchrowset($result)); + } + + public function move_up_data() + { + return array( + array(1, array( + array('group_id' => 1, 'group_legend' => 0), + array('group_id' => 2, 'group_legend' => 1), + array('group_id' => 3, 'group_legend' => 2), + )), + array(2, array( + array('group_id' => 1, 'group_legend' => 0), + array('group_id' => 2, 'group_legend' => 1), + array('group_id' => 3, 'group_legend' => 2), + )), + array(3, array( + array('group_id' => 1, 'group_legend' => 0), + array('group_id' => 2, 'group_legend' => 2), + array('group_id' => 3, 'group_legend' => 1), + )), + ); + } + + /** + * @dataProvider move_up_data + */ + public function test_move_up($group_id, $expected) + { + global $cache; + + $cache = new phpbb_mock_cache; + $db = $this->new_dbal(); + $user = new phpbb_user; + $user->lang = array(); + + $test_class = new phpbb_groupposition_legend($db, $user, ''); + $test_class->move_up($group_id); + + $result = $db->sql_query('SELECT group_id, group_legend + FROM ' . GROUPS_TABLE . ' + ORDER BY group_id ASC'); + + $this->assertEquals($expected, $db->sql_fetchrowset($result)); + } + + public function move_down_data() + { + return array( + array(1, array( + array('group_id' => 1, 'group_legend' => 0), + array('group_id' => 2, 'group_legend' => 1), + array('group_id' => 3, 'group_legend' => 2), + )), + array(2, array( + array('group_id' => 1, 'group_legend' => 0), + array('group_id' => 2, 'group_legend' => 2), + array('group_id' => 3, 'group_legend' => 1), + )), + array(3, array( + array('group_id' => 1, 'group_legend' => 0), + array('group_id' => 2, 'group_legend' => 1), + array('group_id' => 3, 'group_legend' => 2), + )), + ); + } + + /** + * @dataProvider move_down_data + */ + public function test_move_down($group_id, $expected) + { + global $cache; + + $cache = new phpbb_mock_cache; + $db = $this->new_dbal(); + $user = new phpbb_user; + $user->lang = array(); + + $test_class = new phpbb_groupposition_legend($db, $user, ''); + $test_class->move_down($group_id); + + $result = $db->sql_query('SELECT group_id, group_legend + FROM ' . GROUPS_TABLE . ' + ORDER BY group_id ASC'); + + $this->assertEquals($expected, $db->sql_fetchrowset($result)); + } + + public function move_data() + { + return array( + array(1, 1, array( + array('group_id' => 1, 'group_legend' => 0), + array('group_id' => 2, 'group_legend' => 1), + array('group_id' => 3, 'group_legend' => 2), + )), + array(1, -1, array( + array('group_id' => 1, 'group_legend' => 0), + array('group_id' => 2, 'group_legend' => 1), + array('group_id' => 3, 'group_legend' => 2), + )), + array(3, 3, array( + array('group_id' => 1, 'group_legend' => 0), + array('group_id' => 2, 'group_legend' => 2), + array('group_id' => 3, 'group_legend' => 1), + )), + array(2, 0, array( + array('group_id' => 1, 'group_legend' => 0), + array('group_id' => 2, 'group_legend' => 1), + array('group_id' => 3, 'group_legend' => 2), + )), + array(2, -1, array( + array('group_id' => 1, 'group_legend' => 0), + array('group_id' => 2, 'group_legend' => 2), + array('group_id' => 3, 'group_legend' => 1), + )), + array(2, -3, array( + array('group_id' => 1, 'group_legend' => 0), + array('group_id' => 2, 'group_legend' => 2), + array('group_id' => 3, 'group_legend' => 1), + )), + array(3, -1, array( + array('group_id' => 1, 'group_legend' => 0), + array('group_id' => 2, 'group_legend' => 1), + array('group_id' => 3, 'group_legend' => 2), + )), + ); + } + + /** + * @dataProvider move_data + */ + public function test_move($group_id, $increment, $expected) + { + global $cache; + + $cache = new phpbb_mock_cache; + $db = $this->new_dbal(); + $user = new phpbb_user; + $user->lang = array(); + + $test_class = new phpbb_groupposition_legend($db, $user, ''); + $test_class->move($group_id, $increment); + + $result = $db->sql_query('SELECT group_id, group_legend + FROM ' . GROUPS_TABLE . ' + ORDER BY group_id ASC'); + + $this->assertEquals($expected, $db->sql_fetchrowset($result)); + } +} + diff --git a/tests/groupposition/teampage_test.php b/tests/groupposition/teampage_test.php new file mode 100644 index 0000000000..fd85548eb3 --- /dev/null +++ b/tests/groupposition/teampage_test.php @@ -0,0 +1,479 @@ +<?php +/** +* +* @package testing +* @copyright (c) 2012 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ + + +class phpbb_groupposition_teampage_test extends phpbb_database_test_case +{ + public function getDataSet() + { + return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/teampage.xml'); + } + + public function get_group_value_data() + { + return array( + array(2, 3), + array(6, 8), + ); + } + + /** + * @dataProvider get_group_value_data + */ + public function test_get_group_value($group_id, $expected) + { + global $cache; + + $cache = new phpbb_mock_cache; + $db = $this->new_dbal(); + $user = new phpbb_user; + $user->lang = array(); + + $test_class = new phpbb_groupposition_teampage($db, $user, ''); + $this->assertEquals($expected, $test_class->get_group_value($group_id)); + } + + public function test_get_group_count() + { + global $cache; + + $cache = new phpbb_mock_cache; + $db = $this->new_dbal(); + $user = new phpbb_user; + $user->lang = array(); + + $test_class = new phpbb_groupposition_teampage($db, $user, ''); + $this->assertEquals(8, $test_class->get_group_count()); + } + + public function add_group_teampage_data() + { + return array( + array(1, 2, array( + array('teampage_position' => 1, 'group_id' => 1, 'teampage_parent' => 0, 'teampage_name' => ''), + array('teampage_position' => 2, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category - 2 children'), + array('teampage_position' => 3, 'group_id' => 2, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 4, 'group_id' => 3, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 5, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'), + array('teampage_position' => 6, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 7, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 8, 'group_id' => 6, 'teampage_parent' => 0, 'teampage_name' => ''), + )), + array(6, 2, array( + array('teampage_position' => 1, 'group_id' => 1, 'teampage_parent' => 0, 'teampage_name' => ''), + array('teampage_position' => 2, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category - 2 children'), + array('teampage_position' => 3, 'group_id' => 2, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 4, 'group_id' => 3, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 5, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'), + array('teampage_position' => 6, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 7, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 8, 'group_id' => 6, 'teampage_parent' => 0, 'teampage_name' => ''), + )), + array(7, 2, array( + array('teampage_position' => 1, 'group_id' => 1, 'teampage_parent' => 0, 'teampage_name' => ''), + array('teampage_position' => 2, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category - 2 children'), + array('teampage_position' => 3, 'group_id' => 2, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 4, 'group_id' => 3, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 5, 'group_id' => 7, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 6, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'), + array('teampage_position' => 7, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 8, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 9, 'group_id' => 6, 'teampage_parent' => 0, 'teampage_name' => ''), + )), + array(7, 0, array( + array('teampage_position' => 1, 'group_id' => 1, 'teampage_parent' => 0, 'teampage_name' => ''), + array('teampage_position' => 2, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category - 2 children'), + array('teampage_position' => 3, 'group_id' => 2, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 4, 'group_id' => 3, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 5, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'), + array('teampage_position' => 6, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 7, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 8, 'group_id' => 6, 'teampage_parent' => 0, 'teampage_name' => ''), + array('teampage_position' => 9, 'group_id' => 7, 'teampage_parent' => 0, 'teampage_name' => ''), + )), + ); + } + + /** + * @dataProvider add_group_teampage_data + */ + public function test_add_group_teampage($group_id, $parent_id, $expected) + { + global $cache; + + $cache = new phpbb_mock_cache; + $db = $this->new_dbal(); + $user = new phpbb_user; + $user->lang = array(); + + $test_class = new phpbb_groupposition_teampage($db, $user, ''); + $test_class->add_group_teampage($group_id, $parent_id); + + $result = $db->sql_query('SELECT teampage_position, group_id, teampage_parent, teampage_name + FROM ' . TEAMPAGE_TABLE . ' + ORDER BY teampage_position ASC'); + + $this->assertEquals($expected, $db->sql_fetchrowset($result)); + } + + public function add_category_teampage_data() + { + return array( + array('new', array( + array('teampage_position' => 1, 'group_id' => 1, 'teampage_parent' => 0, 'teampage_name' => ''), + array('teampage_position' => 2, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category - 2 children'), + array('teampage_position' => 3, 'group_id' => 2, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 4, 'group_id' => 3, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 5, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'), + array('teampage_position' => 6, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 7, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 8, 'group_id' => 6, 'teampage_parent' => 0, 'teampage_name' => ''), + array('teampage_position' => 9, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'new'), + )), + ); + } + + /** + * @dataProvider add_category_teampage_data + */ + public function test_add_category_teampage($group_name, $expected) + { + global $cache; + + $cache = new phpbb_mock_cache; + $db = $this->new_dbal(); + $user = new phpbb_user; + $user->lang = array(); + + $test_class = new phpbb_groupposition_teampage($db, $user, ''); + $test_class->add_category_teampage($group_name); + + $result = $db->sql_query('SELECT teampage_position, group_id, teampage_parent, teampage_name + FROM ' . TEAMPAGE_TABLE . ' + ORDER BY teampage_position ASC'); + + $this->assertEquals($expected, $db->sql_fetchrowset($result)); + } + + public function delete_group_data() + { + return array( + array(1, array( + array('teampage_position' => 1, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category - 2 children'), + array('teampage_position' => 2, 'group_id' => 2, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 3, 'group_id' => 3, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 4, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'), + array('teampage_position' => 5, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 6, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 7, 'group_id' => 6, 'teampage_parent' => 0, 'teampage_name' => ''), + )), + array(2, array( + array('teampage_position' => 1, 'group_id' => 1, 'teampage_parent' => 0, 'teampage_name' => ''), + array('teampage_position' => 2, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category - 2 children'), + array('teampage_position' => 3, 'group_id' => 3, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 4, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'), + array('teampage_position' => 5, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 6, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 7, 'group_id' => 6, 'teampage_parent' => 0, 'teampage_name' => ''), + )), + array(6, array( + array('teampage_position' => 1, 'group_id' => 1, 'teampage_parent' => 0, 'teampage_name' => ''), + array('teampage_position' => 2, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category - 2 children'), + array('teampage_position' => 3, 'group_id' => 2, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 4, 'group_id' => 3, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 5, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'), + array('teampage_position' => 6, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 7, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''), + )), + ); + } + + /** + * @dataProvider delete_group_data + */ + public function test_delete_group($group_id, $expected) + { + global $cache; + + $cache = new phpbb_mock_cache; + $db = $this->new_dbal(); + $user = new phpbb_user; + $user->lang = array(); + + $test_class = new phpbb_groupposition_teampage($db, $user, ''); + $test_class->delete_group($group_id, false); + + $result = $db->sql_query('SELECT teampage_position, group_id, teampage_parent, teampage_name + FROM ' . TEAMPAGE_TABLE . ' + ORDER BY teampage_position ASC'); + + $this->assertEquals($expected, $db->sql_fetchrowset($result)); + } + + public function delete_teampage_data() + { + return array( + array(1, array( + array('teampage_position' => 1, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category - 2 children'), + array('teampage_position' => 2, 'group_id' => 2, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 3, 'group_id' => 3, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 4, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'), + array('teampage_position' => 5, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 6, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 7, 'group_id' => 6, 'teampage_parent' => 0, 'teampage_name' => ''), + )), + array(2, array( + array('teampage_position' => 1, 'group_id' => 1, 'teampage_parent' => 0, 'teampage_name' => ''), + array('teampage_position' => 2, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'), + array('teampage_position' => 3, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 4, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 5, 'group_id' => 6, 'teampage_parent' => 0, 'teampage_name' => ''), + )), + ); + } + + /** + * @dataProvider delete_teampage_data + */ + public function test_delete_teampage($teampage_id, $expected) + { + global $cache; + + $cache = new phpbb_mock_cache; + $db = $this->new_dbal(); + $user = new phpbb_user; + $user->lang = array(); + + $test_class = new phpbb_groupposition_teampage($db, $user, ''); + $test_class->delete_teampage($teampage_id, false); + + $result = $db->sql_query('SELECT teampage_position, group_id, teampage_parent, teampage_name + FROM ' . TEAMPAGE_TABLE . ' + ORDER BY teampage_position ASC'); + + $this->assertEquals($expected, $db->sql_fetchrowset($result)); + } + + public function move_data() + { + return array( + array(1, 1, array( + array('teampage_position' => 1, 'group_id' => 1, 'teampage_parent' => 0, 'teampage_name' => ''), + array('teampage_position' => 2, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category - 2 children'), + array('teampage_position' => 3, 'group_id' => 2, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 4, 'group_id' => 3, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 5, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'), + array('teampage_position' => 6, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 7, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 8, 'group_id' => 6, 'teampage_parent' => 0, 'teampage_name' => ''), + )), + array(2, 1, array( + array('teampage_position' => 1, 'group_id' => 1, 'teampage_parent' => 0, 'teampage_name' => ''), + array('teampage_position' => 2, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category - 2 children'), + array('teampage_position' => 3, 'group_id' => 2, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 4, 'group_id' => 3, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 5, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'), + array('teampage_position' => 6, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 7, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 8, 'group_id' => 6, 'teampage_parent' => 0, 'teampage_name' => ''), + )), + array(5, 1, array( + array('teampage_position' => 1, 'group_id' => 1, 'teampage_parent' => 0, 'teampage_name' => ''), + array('teampage_position' => 2, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category - 2 children'), + array('teampage_position' => 3, 'group_id' => 2, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 4, 'group_id' => 3, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 5, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'), + array('teampage_position' => 6, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 7, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 8, 'group_id' => 6, 'teampage_parent' => 0, 'teampage_name' => ''), + )), + array(6, 1, array( + array('teampage_position' => 1, 'group_id' => 1, 'teampage_parent' => 0, 'teampage_name' => ''), + array('teampage_position' => 2, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category - 2 children'), + array('teampage_position' => 3, 'group_id' => 2, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 4, 'group_id' => 3, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 5, 'group_id' => 6, 'teampage_parent' => 0, 'teampage_name' => ''), + array('teampage_position' => 6, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'), + array('teampage_position' => 7, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 8, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''), + )), + array(1, -1, array( + array('teampage_position' => 1, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category - 2 children'), + array('teampage_position' => 2, 'group_id' => 2, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 3, 'group_id' => 3, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 4, 'group_id' => 1, 'teampage_parent' => 0, 'teampage_name' => ''), + array('teampage_position' => 5, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'), + array('teampage_position' => 6, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 7, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 8, 'group_id' => 6, 'teampage_parent' => 0, 'teampage_name' => ''), + )), + array(2, -1, array( + array('teampage_position' => 1, 'group_id' => 1, 'teampage_parent' => 0, 'teampage_name' => ''), + array('teampage_position' => 2, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category - 2 children'), + array('teampage_position' => 3, 'group_id' => 3, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 4, 'group_id' => 2, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 5, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'), + array('teampage_position' => 6, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 7, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 8, 'group_id' => 6, 'teampage_parent' => 0, 'teampage_name' => ''), + )), + array(5, -1, array( + array('teampage_position' => 1, 'group_id' => 1, 'teampage_parent' => 0, 'teampage_name' => ''), + array('teampage_position' => 2, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category - 2 children'), + array('teampage_position' => 3, 'group_id' => 2, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 4, 'group_id' => 3, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 5, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'), + array('teampage_position' => 6, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 7, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 8, 'group_id' => 6, 'teampage_parent' => 0, 'teampage_name' => ''), + )), + array(6, -1, array( + array('teampage_position' => 1, 'group_id' => 1, 'teampage_parent' => 0, 'teampage_name' => ''), + array('teampage_position' => 2, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category - 2 children'), + array('teampage_position' => 3, 'group_id' => 2, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 4, 'group_id' => 3, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 5, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'), + array('teampage_position' => 6, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 7, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 8, 'group_id' => 6, 'teampage_parent' => 0, 'teampage_name' => ''), + )), + ); + } + + /** + * @dataProvider move_data + */ + public function test_move($group_id, $move_delta, $expected) + { + global $cache; + + $cache = new phpbb_mock_cache; + $db = $this->new_dbal(); + $user = new phpbb_user; + $user->lang = array(); + + $test_class = new phpbb_groupposition_teampage($db, $user, ''); + $test_class->move($group_id, $move_delta); + + $result = $db->sql_query('SELECT teampage_position, group_id, teampage_parent, teampage_name + FROM ' . TEAMPAGE_TABLE . ' + ORDER BY teampage_position ASC'); + + $this->assertEquals($expected, $db->sql_fetchrowset($result)); + } + + public function move_teampage_data() + { + return array( + array(1, 1, array( + array('teampage_position' => 1, 'group_id' => 1, 'teampage_parent' => 0, 'teampage_name' => ''), + array('teampage_position' => 2, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category - 2 children'), + array('teampage_position' => 3, 'group_id' => 2, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 4, 'group_id' => 3, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 5, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'), + array('teampage_position' => 6, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 7, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 8, 'group_id' => 6, 'teampage_parent' => 0, 'teampage_name' => ''), + )), + array(2, 1, array( + array('teampage_position' => 1, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category - 2 children'), + array('teampage_position' => 2, 'group_id' => 2, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 3, 'group_id' => 3, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 4, 'group_id' => 1, 'teampage_parent' => 0, 'teampage_name' => ''), + array('teampage_position' => 5, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'), + array('teampage_position' => 6, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 7, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 8, 'group_id' => 6, 'teampage_parent' => 0, 'teampage_name' => ''), + )), + array(5, 1, array( + array('teampage_position' => 1, 'group_id' => 1, 'teampage_parent' => 0, 'teampage_name' => ''), + array('teampage_position' => 2, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'), + array('teampage_position' => 3, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 4, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 5, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category - 2 children'), + array('teampage_position' => 6, 'group_id' => 2, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 7, 'group_id' => 3, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 8, 'group_id' => 6, 'teampage_parent' => 0, 'teampage_name' => ''), + )), + array(6, 1, array( + array('teampage_position' => 1, 'group_id' => 1, 'teampage_parent' => 0, 'teampage_name' => ''), + array('teampage_position' => 2, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category - 2 children'), + array('teampage_position' => 3, 'group_id' => 2, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 4, 'group_id' => 3, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 5, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'), + array('teampage_position' => 6, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 7, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 8, 'group_id' => 6, 'teampage_parent' => 0, 'teampage_name' => ''), + )), + array(1, -1, array( + array('teampage_position' => 1, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category - 2 children'), + array('teampage_position' => 2, 'group_id' => 2, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 3, 'group_id' => 3, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 4, 'group_id' => 1, 'teampage_parent' => 0, 'teampage_name' => ''), + array('teampage_position' => 5, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'), + array('teampage_position' => 6, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 7, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 8, 'group_id' => 6, 'teampage_parent' => 0, 'teampage_name' => ''), + )), + array(2, -1, array( + array('teampage_position' => 1, 'group_id' => 1, 'teampage_parent' => 0, 'teampage_name' => ''), + array('teampage_position' => 2, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'), + array('teampage_position' => 3, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 4, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 5, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category - 2 children'), + array('teampage_position' => 6, 'group_id' => 2, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 7, 'group_id' => 3, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 8, 'group_id' => 6, 'teampage_parent' => 0, 'teampage_name' => ''), + )), + array(5, -1, array( + array('teampage_position' => 1, 'group_id' => 1, 'teampage_parent' => 0, 'teampage_name' => ''), + array('teampage_position' => 2, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category - 2 children'), + array('teampage_position' => 3, 'group_id' => 2, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 4, 'group_id' => 3, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 5, 'group_id' => 6, 'teampage_parent' => 0, 'teampage_name' => ''), + array('teampage_position' => 6, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'), + array('teampage_position' => 7, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 8, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''), + )), + array(6, -1, array( + array('teampage_position' => 1, 'group_id' => 1, 'teampage_parent' => 0, 'teampage_name' => ''), + array('teampage_position' => 2, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category - 2 children'), + array('teampage_position' => 3, 'group_id' => 2, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 4, 'group_id' => 3, 'teampage_parent' => 2, 'teampage_name' => ''), + array('teampage_position' => 5, 'group_id' => 0, 'teampage_parent' => 0, 'teampage_name' => 'category2 - 2 children'), + array('teampage_position' => 6, 'group_id' => 5, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 7, 'group_id' => 4, 'teampage_parent' => 5, 'teampage_name' => ''), + array('teampage_position' => 8, 'group_id' => 6, 'teampage_parent' => 0, 'teampage_name' => ''), + )), + ); + } + + /** + * @dataProvider move_teampage_data + */ + public function test_move_teampage($teampage_id, $move_delta, $expected) + { + global $cache; + + $cache = new phpbb_mock_cache; + $db = $this->new_dbal(); + $user = new phpbb_user; + $user->lang = array(); + + $test_class = new phpbb_groupposition_teampage($db, $user, ''); + $test_class->move_teampage($teampage_id, $move_delta); + + $result = $db->sql_query('SELECT teampage_position, group_id, teampage_parent, teampage_name + FROM ' . TEAMPAGE_TABLE . ' + ORDER BY teampage_position ASC'); + + $this->assertEquals($expected, $db->sql_fetchrowset($result)); + } +} + |