From dd5963eabb17b29fc4abc98ea0cb95357fe253bb Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Tue, 19 Feb 2013 15:59:15 +0100 Subject: [ticket/11323] Enable tests for inclusion of defined variables PHPBB3-11323 --- tests/template/template_test.php | 3 --- 1 file changed, 3 deletions(-) (limited to 'tests') diff --git a/tests/template/template_test.php b/tests/template/template_test.php index f43157775a..56cc7a9de5 100644 --- a/tests/template/template_test.php +++ b/tests/template/template_test.php @@ -197,8 +197,6 @@ class phpbb_template_template_test extends phpbb_template_template_test_case array('loop'), '', ), - /* Currently fail on develop: - http://tracker.phpbb.com/browse/PHPBB3-11323 array( 'include_define_variable.html', array('VARIABLE' => 'variable.html'), @@ -213,7 +211,6 @@ class phpbb_template_template_test extends phpbb_template_template_test_case array(), 'value', ), - */ /* no top level nested loops array( 'loop_vars.html', -- cgit v1.2.1 From 2ec0dc5b34e88c737e0737e73a46e1edd1573f10 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Mon, 11 Mar 2013 10:32:08 +0100 Subject: [ticket/11404] Convert manager_test to UNIX line endings PHPBB3-11404 --- tests/avatar/manager_test.php | 180 +++++++++++++++++++++--------------------- 1 file changed, 90 insertions(+), 90 deletions(-) (limited to 'tests') diff --git a/tests/avatar/manager_test.php b/tests/avatar/manager_test.php index f01ea47c25..7ea3cc6a0f 100644 --- a/tests/avatar/manager_test.php +++ b/tests/avatar/manager_test.php @@ -1,90 +1,90 @@ -phpbb_container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface'); - $this->phpbb_container->expects($this->any()) - ->method('get') - ->with('avatar.driver.foobar')->will($this->returnValue('avatar.driver.foobar')); - - // Prepare dependencies for avatar manager and driver - $config = new phpbb_config(array()); - $request = $this->getMock('phpbb_request'); - $cache = $this->getMock('phpbb_cache_driver_interface'); - - $this->avatar_foobar = $this->getMock('phpbb_avatar_driver_foobar', array('get_name'), array($config, $phpbb_root_path, $phpEx, $cache)); - $this->avatar_foobar->expects($this->any()) - ->method('get_name') - ->will($this->returnValue('avatar.driver.foobar')); - $this->avatar_barfoo = $this->getMock('phpbb_avatar_driver_barfoo', array('get_name')); - $this->avatar_barfoo->expects($this->any()) - ->method('get_name') - ->will($this->returnValue('avatar.driver.barfoo')); - - $avatar_drivers = array($this->avatar_foobar, $this->avatar_barfoo); - - $config['allow_avatar_' . get_class($this->avatar_foobar)] = true; - $config['allow_avatar_' . get_class($this->avatar_barfoo)] = false; - - // Set up avatar manager - $this->manager = new phpbb_avatar_manager($config, $avatar_drivers, $this->phpbb_container); - } - - public function test_get_driver() - { - $driver = $this->manager->get_driver('avatar.driver.foobar', false); - $this->assertEquals('avatar.driver.foobar', $driver); - - $driver = $this->manager->get_driver('avatar.driver.foo_wrong', false); - $this->assertNull($driver); - - $driver = $this->manager->get_driver('avatar.driver.foobar'); - $this->assertEquals('avatar.driver.foobar', $driver); - - $driver = $this->manager->get_driver('avatar.driver.foo_wrong'); - $this->assertNull($driver); - } - - public function test_get_all_drivers() - { - $drivers = $this->manager->get_all_drivers(); - $this->assertArrayHasKey('avatar.driver.foobar', $drivers); - $this->assertArrayHasKey('avatar.driver.barfoo', $drivers); - $this->assertEquals('avatar.driver.foobar', $drivers['avatar.driver.foobar']); - $this->assertEquals('avatar.driver.barfoo', $drivers['avatar.driver.barfoo']); - } - - public function test_get_enabled_drivers() - { - $drivers = $this->manager->get_enabled_drivers(); - $this->assertArrayHasKey('avatar.driver.foobar', $drivers); - $this->assertArrayNotHasKey('avatar.driver.barfoo', $drivers); - $this->assertEquals('avatar.driver.foobar', $drivers['avatar.driver.foobar']); - } - - public function test_get_avatar_settings() - { - $avatar_settings = $this->manager->get_avatar_settings($this->avatar_foobar); - - $expected_settings = array( - 'allow_avatar_' . get_class($this->avatar_foobar) => array('lang' => 'ALLOW_' . strtoupper(get_class($this->avatar_foobar)), 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => false), - ); - - $this->assertEquals($expected_settings, $avatar_settings); - } -} +phpbb_container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface'); + $this->phpbb_container->expects($this->any()) + ->method('get') + ->with('avatar.driver.foobar')->will($this->returnValue('avatar.driver.foobar')); + + // Prepare dependencies for avatar manager and driver + $config = new phpbb_config(array()); + $request = $this->getMock('phpbb_request'); + $cache = $this->getMock('phpbb_cache_driver_interface'); + + $this->avatar_foobar = $this->getMock('phpbb_avatar_driver_foobar', array('get_name'), array($config, $phpbb_root_path, $phpEx, $cache)); + $this->avatar_foobar->expects($this->any()) + ->method('get_name') + ->will($this->returnValue('avatar.driver.foobar')); + $this->avatar_barfoo = $this->getMock('phpbb_avatar_driver_barfoo', array('get_name')); + $this->avatar_barfoo->expects($this->any()) + ->method('get_name') + ->will($this->returnValue('avatar.driver.barfoo')); + + $avatar_drivers = array($this->avatar_foobar, $this->avatar_barfoo); + + $config['allow_avatar_' . get_class($this->avatar_foobar)] = true; + $config['allow_avatar_' . get_class($this->avatar_barfoo)] = false; + + // Set up avatar manager + $this->manager = new phpbb_avatar_manager($config, $avatar_drivers, $this->phpbb_container); + } + + public function test_get_driver() + { + $driver = $this->manager->get_driver('avatar.driver.foobar', false); + $this->assertEquals('avatar.driver.foobar', $driver); + + $driver = $this->manager->get_driver('avatar.driver.foo_wrong', false); + $this->assertNull($driver); + + $driver = $this->manager->get_driver('avatar.driver.foobar'); + $this->assertEquals('avatar.driver.foobar', $driver); + + $driver = $this->manager->get_driver('avatar.driver.foo_wrong'); + $this->assertNull($driver); + } + + public function test_get_all_drivers() + { + $drivers = $this->manager->get_all_drivers(); + $this->assertArrayHasKey('avatar.driver.foobar', $drivers); + $this->assertArrayHasKey('avatar.driver.barfoo', $drivers); + $this->assertEquals('avatar.driver.foobar', $drivers['avatar.driver.foobar']); + $this->assertEquals('avatar.driver.barfoo', $drivers['avatar.driver.barfoo']); + } + + public function test_get_enabled_drivers() + { + $drivers = $this->manager->get_enabled_drivers(); + $this->assertArrayHasKey('avatar.driver.foobar', $drivers); + $this->assertArrayNotHasKey('avatar.driver.barfoo', $drivers); + $this->assertEquals('avatar.driver.foobar', $drivers['avatar.driver.foobar']); + } + + public function test_get_avatar_settings() + { + $avatar_settings = $this->manager->get_avatar_settings($this->avatar_foobar); + + $expected_settings = array( + 'allow_avatar_' . get_class($this->avatar_foobar) => array('lang' => 'ALLOW_' . strtoupper(get_class($this->avatar_foobar)), 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => false), + ); + + $this->assertEquals($expected_settings, $avatar_settings); + } +} -- cgit v1.2.1 From fb1984dadb2ef4ec679f3a66e1a98e75bbe38dec Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Mon, 11 Mar 2013 10:33:16 +0100 Subject: [ticket/11404] Add tests for phpbb_avatar_manager::clean_row() PHPBB3-11404 --- tests/avatar/manager_test.php | 71 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) (limited to 'tests') diff --git a/tests/avatar/manager_test.php b/tests/avatar/manager_test.php index 7ea3cc6a0f..ffcfe2ce11 100644 --- a/tests/avatar/manager_test.php +++ b/tests/avatar/manager_test.php @@ -87,4 +87,75 @@ class phpbb_avatar_manager_test extends PHPUnit_Framework_TestCase $this->assertEquals($expected_settings, $avatar_settings); } + + public function database_row_data() + { + return array( + array( + array( + 'user_avatar' => '', + 'user_avatar_type' => '', + 'user_avatar_width' => '', + 'user_avatar_height' => '', + ), + array( + 'avatar' => '', + 'avatar_type' => '', + 'avatar_width' => '', + 'avatar_height' => '', + ), + ), + array( + array( + 'group_avatar' => '', + 'group_avatar_type' => '', + 'group_avatar_width' => '', + 'group_avatar_height' => '', + ), + array( + 'avatar' => '', + 'avatar_type' => '', + 'avatar_width' => '', + 'avatar_height' => '', + ), + ), + array( + array(), + array( + 'avatar' => '', + 'avatar_type' => '', + 'avatar_width' => '', + 'avatar_height' => '', + ), + ), + array( + array( + 'foobar_avatar' => '', + 'foobar_avatar_type' => '', + 'foobar_avatar_width' => '', + 'foobar_avatar_height' => '', + ), + array( + 'foobar_avatar' => '', + 'foobar_avatar_type' => '', + 'foobar_avatar_width' => '', + 'foobar_avatar_height' => '', + ), + ), + ); + } + + /** + * @dataProvider database_row_data + */ + public function test_clean_row(array $input, array $output) + { + $cleaned_row = array(); + + $cleaned_row = phpbb_avatar_manager::clean_row($input); + foreach ($output as $key => $null) + { + $this->assertArrayHasKey($key, $cleaned_row); + } + } } -- cgit v1.2.1 From 4ad8fcbd58aeb72b659db6ebc18ff38b0725f006 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Mon, 11 Mar 2013 10:35:18 +0100 Subject: [ticket/11404] Remove version ID from manager_test.php file header PHPBB3-11404 --- tests/avatar/manager_test.php | 1 - 1 file changed, 1 deletion(-) (limited to 'tests') diff --git a/tests/avatar/manager_test.php b/tests/avatar/manager_test.php index ffcfe2ce11..cb895b521a 100644 --- a/tests/avatar/manager_test.php +++ b/tests/avatar/manager_test.php @@ -2,7 +2,6 @@ /** * * @package testing -* @version $Id$ * @copyright (c) 2012 phpBB Group * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 * -- cgit v1.2.1 From 1fd5be859e3fe85e67fe7f5632e4630b96ca3634 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 12 Mar 2013 22:45:44 +0100 Subject: [ticket/11362] Add unit test for ../ in directory paths PHPBB3-11362 --- tests/extension/finder_test.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'tests') diff --git a/tests/extension/finder_test.php b/tests/extension/finder_test.php index c96b11a73c..3781591b19 100644 --- a/tests/extension/finder_test.php +++ b/tests/extension/finder_test.php @@ -6,6 +6,7 @@ * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 * */ +require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php'; class phpbb_extension_finder_test extends phpbb_test_case { @@ -142,6 +143,21 @@ class phpbb_extension_finder_test extends phpbb_test_case ); } + public function test_uncleansub_directory_get_classes() + { + $classes = $this->finder + ->directory('/sub/../sub/type') + ->get_classes(); + + sort($classes); + $this->assertEquals( + array( + 'phpbb_ext_foo_sub_type_alternative', + ), + $classes + ); + } + /** * These do not work because of changes with PHPBB3-11386 * They do not seem neccessary to me, so I am commenting them out for now -- cgit v1.2.1 From eabcbb9baf7d69cfae6d23f05b062002d054424c Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Fri, 15 Mar 2013 01:25:10 +0100 Subject: [ticket/11441] Add _test prefix to user loader test filename. PHPBB3-11441 --- tests/user/user_loader.php | 49 ----------------------------------------- tests/user/user_loader_test.php | 49 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 49 deletions(-) delete mode 100644 tests/user/user_loader.php create mode 100644 tests/user/user_loader_test.php (limited to 'tests') diff --git a/tests/user/user_loader.php b/tests/user/user_loader.php deleted file mode 100644 index 0beb804729..0000000000 --- a/tests/user/user_loader.php +++ /dev/null @@ -1,49 +0,0 @@ -createXMLDataSet(dirname(__FILE__) . '/fixtures/user_loader.xml'); - } - - public function test_user_loader() - { - $db = $this->new_dbal(); - - $user_loader = new phpbb_user_loader($db, __DIR__ . '/../../phpBB/', 'php', 'phpbb_users'); - - $user_loader->load_users(array(2)); - - $user = $user_loader->get_user(1); - $this->assertEquals(1, $user['user_id']); - $this->assertEquals('Guest', $user['username']); - - $user = $user_loader->get_user(2); - $this->assertEquals(2, $user['user_id']); - $this->assertEquals('Admin', $user['username']); - - // Not loaded - $user = $user_loader->get_user(3); - $this->assertEquals(1, $user['user_id']); - $this->assertEquals('Guest', $user['username']); - - $user = $user_loader->get_user(3, true); - $this->assertEquals(3, $user['user_id']); - $this->assertEquals('Test', $user['username']); - - $user_id = $user_loader->load_user_by_username('Test'); - $user = $user_loader->get_user($user_id); - $this->assertEquals(3, $user['user_id']); - $this->assertEquals('Test', $user['username']); - } -} diff --git a/tests/user/user_loader_test.php b/tests/user/user_loader_test.php new file mode 100644 index 0000000000..0beb804729 --- /dev/null +++ b/tests/user/user_loader_test.php @@ -0,0 +1,49 @@ +createXMLDataSet(dirname(__FILE__) . '/fixtures/user_loader.xml'); + } + + public function test_user_loader() + { + $db = $this->new_dbal(); + + $user_loader = new phpbb_user_loader($db, __DIR__ . '/../../phpBB/', 'php', 'phpbb_users'); + + $user_loader->load_users(array(2)); + + $user = $user_loader->get_user(1); + $this->assertEquals(1, $user['user_id']); + $this->assertEquals('Guest', $user['username']); + + $user = $user_loader->get_user(2); + $this->assertEquals(2, $user['user_id']); + $this->assertEquals('Admin', $user['username']); + + // Not loaded + $user = $user_loader->get_user(3); + $this->assertEquals(1, $user['user_id']); + $this->assertEquals('Guest', $user['username']); + + $user = $user_loader->get_user(3, true); + $this->assertEquals(3, $user['user_id']); + $this->assertEquals('Test', $user['username']); + + $user_id = $user_loader->load_user_by_username('Test'); + $user = $user_loader->get_user($user_id); + $this->assertEquals(3, $user['user_id']); + $this->assertEquals('Test', $user['username']); + } +} -- cgit v1.2.1 From 3c09612d36acf821d4d8576f165dda2e7d69d04e Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Fri, 15 Mar 2013 01:26:26 +0100 Subject: [ticket/11441] Correct/fix class name of user loader test. PHPBB3-11441 --- tests/user/user_loader_test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/user/user_loader_test.php b/tests/user/user_loader_test.php index 0beb804729..57a86d8729 100644 --- a/tests/user/user_loader_test.php +++ b/tests/user/user_loader_test.php @@ -9,7 +9,7 @@ include_once(__DIR__ . '/../../phpBB/includes/utf/utf_tools.php'); -class phpbb_user_lang_test extends phpbb_database_test_case +class phpbb_user_loader_test extends phpbb_database_test_case { public function getDataSet() { -- cgit v1.2.1 From e1e9138c3b706d686dc176f7ccb3dfc95cbf0bb4 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Fri, 15 Mar 2013 01:28:27 +0100 Subject: [ticket/11441] Update/correct copyright year of user loader test. PHPBB3-11441 --- tests/user/user_loader_test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/user/user_loader_test.php b/tests/user/user_loader_test.php index 57a86d8729..c030e7ff97 100644 --- a/tests/user/user_loader_test.php +++ b/tests/user/user_loader_test.php @@ -2,7 +2,7 @@ /** * * @package testing -* @copyright (c) 2011 phpBB Group +* @copyright (c) 2012 phpBB Group * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 * */ -- cgit v1.2.1 From ef1caf69332bed24a12fdeda98711f5012c85ebd Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Fri, 15 Mar 2013 01:32:33 +0100 Subject: [ticket/11441] Use setUp() in phpbb_user_loader_test. PHPBB3-11441 --- tests/user/user_loader_test.php | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) (limited to 'tests') diff --git a/tests/user/user_loader_test.php b/tests/user/user_loader_test.php index c030e7ff97..89659256f8 100644 --- a/tests/user/user_loader_test.php +++ b/tests/user/user_loader_test.php @@ -11,38 +11,45 @@ include_once(__DIR__ . '/../../phpBB/includes/utf/utf_tools.php'); class phpbb_user_loader_test extends phpbb_database_test_case { + protected $db; + protected $user_loader; + public function getDataSet() { return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/user_loader.xml'); } - public function test_user_loader() + public function setUp() { - $db = $this->new_dbal(); + parent::setUp(); - $user_loader = new phpbb_user_loader($db, __DIR__ . '/../../phpBB/', 'php', 'phpbb_users'); + $this->db = $this->new_dbal(); + $this->user_loader = new phpbb_user_loader($this->db, __DIR__ . '/../../phpBB/', 'php', 'phpbb_users'); + } - $user_loader->load_users(array(2)); + public function test_user_loader() + { + $this->user_loader->load_users(array(2)); - $user = $user_loader->get_user(1); + $user = $this->user_loader->get_user(1); $this->assertEquals(1, $user['user_id']); $this->assertEquals('Guest', $user['username']); - $user = $user_loader->get_user(2); + $user = $this->user_loader->get_user(2); $this->assertEquals(2, $user['user_id']); $this->assertEquals('Admin', $user['username']); // Not loaded - $user = $user_loader->get_user(3); + $user = $this->user_loader->get_user(3); $this->assertEquals(1, $user['user_id']); $this->assertEquals('Guest', $user['username']); - $user = $user_loader->get_user(3, true); + $user = $this->user_loader->get_user(3, true); $this->assertEquals(3, $user['user_id']); $this->assertEquals('Test', $user['username']); - $user_id = $user_loader->load_user_by_username('Test'); - $user = $user_loader->get_user($user_id); + $user_id = $this->user_loader->load_user_by_username('Test'); + $user = $this->user_loader->get_user($user_id); $this->assertEquals(3, $user['user_id']); $this->assertEquals('Test', $user['username']); } -- cgit v1.2.1 From ba460d98f1fb78da1f996ae7fcc5cc28e574d3ba Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Fri, 15 Mar 2013 01:36:05 +0100 Subject: [ticket/11441] Split user loader tests into multiple test methods. PHPBB3-11441 --- tests/user/user_loader_test.php | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/user/user_loader_test.php b/tests/user/user_loader_test.php index 89659256f8..5cdb654b18 100644 --- a/tests/user/user_loader_test.php +++ b/tests/user/user_loader_test.php @@ -27,7 +27,7 @@ class phpbb_user_loader_test extends phpbb_database_test_case $this->user_loader = new phpbb_user_loader($this->db, __DIR__ . '/../../phpBB/', 'php', 'phpbb_users'); } - public function test_user_loader() + public function test_load_get() { $this->user_loader->load_users(array(2)); @@ -38,8 +38,12 @@ class phpbb_user_loader_test extends phpbb_database_test_case $user = $this->user_loader->get_user(2); $this->assertEquals(2, $user['user_id']); $this->assertEquals('Admin', $user['username']); + } + + public function test_load_get_unloaded() + { + $this->user_loader->load_users(array(2)); - // Not loaded $user = $this->user_loader->get_user(3); $this->assertEquals(1, $user['user_id']); $this->assertEquals('Guest', $user['username']); @@ -47,7 +51,10 @@ class phpbb_user_loader_test extends phpbb_database_test_case $user = $this->user_loader->get_user(3, true); $this->assertEquals(3, $user['user_id']); $this->assertEquals('Test', $user['username']); + } + public function test_load_user_by_username() + { $user_id = $this->user_loader->load_user_by_username('Test'); $user = $this->user_loader->get_user($user_id); $this->assertEquals(3, $user['user_id']); -- cgit v1.2.1 From 15cade3dc56f8850c1468982814ec658d7856522 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Fri, 15 Mar 2013 00:12:02 +0100 Subject: [ticket/11439] Add _test suffix to notification test filename. PHPBB3-11439 --- tests/notification/notification.php | 385 ------------------------------- tests/notification/notification_test.php | 385 +++++++++++++++++++++++++++++++ 2 files changed, 385 insertions(+), 385 deletions(-) delete mode 100644 tests/notification/notification.php create mode 100644 tests/notification/notification_test.php (limited to 'tests') diff --git a/tests/notification/notification.php b/tests/notification/notification.php deleted file mode 100644 index 13c868a0c7..0000000000 --- a/tests/notification/notification.php +++ /dev/null @@ -1,385 +0,0 @@ -createXMLDataSet(dirname(__FILE__) . '/fixtures/notification.xml'); - } - - protected function setUp() - { - parent::setUp(); - - global $phpbb_root_path, $phpEx; - - if (!function_exists('set_var')) - { - include($phpbb_root_path . 'includes/functions.' . $phpEx); - } - - include_once(__DIR__ . '/ext/test/notification/type/test.' . $phpEx); - - $this->db = $this->new_dbal(); - $this->config = new phpbb_config(array( - 'allow_privmsg' => true, - 'allow_bookmarks' => true, - 'allow_topic_notify' => true, - 'allow_forum_notify' => true, - )); - $this->user = new phpbb_mock_user(); - $this->user_loader = new phpbb_user_loader($this->db, $phpbb_root_path, $phpEx, 'phpbb_users'); - $this->auth = new phpbb_mock_notifications_auth(); - $this->cache = new phpbb_mock_cache(); - - $this->container = new phpbb_mock_container_builder(); - - $this->notifications = new phpbb_mock_notifications_notification_manager( - array(), - array(), - $this->container, - $this->user_loader, - $this->db, - $this->user, - $phpbb_root_path, - $phpEx, - 'phpbb_notification_types', - 'phpbb_notifications', - 'phpbb_user_notifications' - ); - - $this->notifications->setDependencies($this->auth, $this->cache, $this->config); - - $types = array(); - foreach (array( - 'test', - 'approve_post', - 'approve_topic', - 'bookmark', - 'disapprove_post', - 'disapprove_topic', - 'pm', - 'post', - 'post_in_queue', - 'quote', - 'report_pm', - 'report_pm_closed', - 'report_post', - 'report_post_closed', - 'topic', - 'topic_in_queue', - ) as $type) - { - $class = $this->build_type('phpbb_notification_type_' . $type); - - $types[$type] = $class; - $this->container->set('notification.type.' . $type, $class); - } - - $this->notifications->set_var('notification_types', $types); - } - - protected function build_type($type) - { - global $phpbb_root_path, $phpEx; - - return new $type($this->user_loader, $this->db, $this->cache, $this->user, $this->auth, $this->config, $phpbb_root_path, $phpEx, 'phpbb_notification_types', 'phpbb_notifications', 'phpbb_user_notifications'); - } - - public function test_get_subscription_types() - { - $subscription_types = $this->notifications->get_subscription_types(); - - $this->assertArrayHasKey('NOTIFICATION_GROUP_MISCELLANEOUS', $subscription_types); - $this->assertArrayHasKey('NOTIFICATION_GROUP_POSTING', $subscription_types); - - $this->assertArrayHasKey('bookmark', $subscription_types['NOTIFICATION_GROUP_POSTING']); - $this->assertArrayHasKey('post', $subscription_types['NOTIFICATION_GROUP_POSTING']); - $this->assertArrayHasKey('quote', $subscription_types['NOTIFICATION_GROUP_POSTING']); - $this->assertArrayHasKey('topic', $subscription_types['NOTIFICATION_GROUP_POSTING']); - - $this->assertArrayHasKey('pm', $subscription_types['NOTIFICATION_GROUP_MISCELLANEOUS']); - - //get_subscription_types - //get_subscription_methods - } - - public function test_subscriptions() - { - $this->notifications->delete_subscription('post', 0, '', 2); - - $this->assertArrayNotHasKey('post', $this->notifications->get_global_subscriptions(2)); - - $this->notifications->add_subscription('post', 0, '', 2); - - $this->assertArrayHasKey('post', $this->notifications->get_global_subscriptions(2)); - } - - public function test_notifications() - { - // Used to test post notifications later - $this->db->sql_query('INSERT INTO ' . TOPICS_WATCH_TABLE . ' ' . $this->db->sql_build_array('INSERT', array( - 'topic_id' => 2, - 'notify_status' => NOTIFY_YES, - 'user_id' => 0, - ))); - - $this->assertEquals(array( - 'notifications' => array(), - 'unread_count' => 0, - 'total_count' => 0, - ), $this->notifications->load_notifications(array( - 'count_unread' => true, - ))); - - $this->notifications->add_notifications('test', array( - 'post_id' => '1', - 'topic_id' => '1', - 'post_time' => 1349413321, - )); - - $this->notifications->add_notifications('test', array( - 'post_id' => '2', - 'topic_id' => '2', - 'post_time' => 1349413322, - )); - - $this->notifications->add_notifications('test', array( - 'post_id' => '3', - 'topic_id' => '2', - 'post_time' => 1349413323, - )); - - $this->notifications->add_notifications(array('quote', 'bookmark', 'post', 'test'), array( - 'post_id' => '4', - 'topic_id' => '2', - 'post_time' => 1349413324, - 'poster_id' => 2, - 'topic_title' => 'test-title', - 'post_subject' => 'Re: test-title', - 'forum_id' => 2, - 'forum_name' => 'Your first forum', - )); - - $this->db->sql_query('INSERT INTO ' . BOOKMARKS_TABLE . ' ' . $this->db->sql_build_array('INSERT', array( - 'topic_id' => 2, - 'user_id' => 0, - ))); - - $this->notifications->add_notifications(array('quote', 'bookmark', 'post', 'test'), array( - 'post_id' => '5', - 'topic_id' => '2', - 'post_time' => 1349413325, - 'poster_id' => 2, - 'topic_title' => 'test-title', - 'post_subject' => 'Re: test-title', - 'forum_id' => 2, - 'forum_name' => 'Your first forum', - )); - - $this->notifications->delete_subscription('test'); - - $this->notifications->add_notifications('test', array( - 'post_id' => '6', - 'topic_id' => '2', - 'post_time' => 1349413326, - )); - - $notifications = $this->notifications->load_notifications(array( - 'count_unread' => true, - )); - - $expected = array( - 1 => array( - 'item_type' => 'test', - 'item_id' => 1, - 'item_parent_id' => 1, - 'user_id' => 0, - 'notification_read' => 0, - 'notification_time' => 1349413321, - 'notification_data' => array(), - ), - 2 => array( - 'item_type' => 'test', - 'item_id' => 2, - 'item_parent_id' => 2, - 'user_id' => 0, - 'notification_read' => 0, - 'notification_time' => 1349413322, - 'notification_data' => array(), - ), - 3 => array( - 'item_type' => 'test', - 'item_id' => 3, - 'item_parent_id' => 2, - 'user_id' => 0, - 'notification_read' => 0, - 'notification_time' => 1349413323, - 'notification_data' => array(), - ), - 4 => array( - 'item_type' => 'post', - 'item_id' => 4, - 'item_parent_id' => 2, - 'user_id' => 0, - 'notification_read' => 0, - 'notification_time' => 1349413324, - 'notification_data' => array( - 'poster_id' => 2, - 'topic_title' => 'test-title', - 'post_subject' => 'Re: test-title', - 'post_username' => '', - 'forum_id' => 2, - 'forum_name' => 'Your first forum', - ), - ), - 5 => array( - 'item_type' => 'bookmark', - 'item_id' => 5, - 'item_parent_id' => 2, - 'user_id' => 0, - 'notification_read' => 0, - 'notification_time' => 1349413325, - 'notification_data' => array( - 'poster_id' => 2, - 'topic_title' => 'test-title', - 'post_subject' => 'Re: test-title', - 'post_username' => '', - 'forum_id' => 2, - 'forum_name' => 'Your first forum', - ), - ), - ); - - $this->assertEquals(sizeof($expected), $notifications['unread_count']); - - $notifications = $notifications['notifications']; - - foreach ($expected as $notification_id => $notification_data) - { - //echo $notifications[$notification_id]; - - $this->assertEquals($notification_id, $notifications[$notification_id]->notification_id, 'notification_id'); - - foreach ($notification_data as $key => $value) - { - $this->assertEquals($value, $notifications[$notification_id]->$key, $key . ' ' . $notification_id); - } - } - - // Now test updating ------------------------------- - - $this->notifications->update_notifications('test', array( - 'post_id' => '1', - 'topic_id' => '2', // change parent_id - 'post_time' => 1349413321, - )); - - $this->notifications->update_notifications('test', array( - 'post_id' => '3', - 'topic_id' => '2', - 'post_time' => 1234, // change time - )); - - $this->notifications->update_notifications(array('quote', 'bookmark', 'post', 'test'), array( - 'post_id' => '5', - 'topic_id' => '2', - 'poster_id' => 2, - 'topic_title' => 'test-title2', // change topic_title - 'post_subject' => 'Re: test-title2', // change post_subject - 'forum_id' => 3, // change forum_id - 'forum_name' => 'Your second forum', // change forum_name - )); - - $notifications = $this->notifications->load_notifications(array( - 'count_unread' => true, - )); - - $expected = array( - 1 => array( - 'item_type' => 'test', - 'item_id' => 1, - 'item_parent_id' => 2, - 'user_id' => 0, - 'notification_read' => 0, - 'notification_time' => 1349413321, - 'notification_data' => array(), - ), - 2 => array( - 'item_type' => 'test', - 'item_id' => 2, - 'item_parent_id' => 2, - 'user_id' => 0, - 'notification_read' => 0, - 'notification_time' => 1349413322, - 'notification_data' => array(), - ), - 3 => array( - 'item_type' => 'test', - 'item_id' => 3, - 'item_parent_id' => 2, - 'user_id' => 0, - 'notification_read' => 0, - 'notification_time' => 1234, - 'notification_data' => array(), - ), - 4 => array( - 'item_type' => 'post', - 'item_id' => 4, - 'item_parent_id' => 2, - 'user_id' => 0, - 'notification_read' => 0, - 'notification_time' => 1349413324, - 'notification_data' => array( - 'poster_id' => 2, - 'topic_title' => 'test-title', - 'post_subject' => 'Re: test-title', - 'post_username' => '', - 'forum_id' => 2, - 'forum_name' => 'Your first forum', - ), - ), - 5 => array( - 'item_type' => 'bookmark', - 'item_id' => 5, - 'item_parent_id' => 2, - 'user_id' => 0, - 'notification_read' => 0, - 'notification_time' => 1349413325, - 'notification_data' => array( - 'poster_id' => 2, - 'topic_title' => 'test-title2', - 'post_subject' => 'Re: test-title2', - 'post_username' => '', - 'forum_id' => 3, - 'forum_name' => 'Your second forum', - ), - ), - ); - - $this->assertEquals(sizeof($expected), $notifications['unread_count']); - - $notifications = $notifications['notifications']; - - foreach ($expected as $notification_id => $notification_data) - { - //echo $notifications[$notification_id]; - - $this->assertEquals($notification_id, $notifications[$notification_id]->notification_id, 'notification_id'); - - foreach ($notification_data as $key => $value) - { - $this->assertEquals($value, $notifications[$notification_id]->$key, $key . ' ' . $notification_id); - } - } - } -} diff --git a/tests/notification/notification_test.php b/tests/notification/notification_test.php new file mode 100644 index 0000000000..13c868a0c7 --- /dev/null +++ b/tests/notification/notification_test.php @@ -0,0 +1,385 @@ +createXMLDataSet(dirname(__FILE__) . '/fixtures/notification.xml'); + } + + protected function setUp() + { + parent::setUp(); + + global $phpbb_root_path, $phpEx; + + if (!function_exists('set_var')) + { + include($phpbb_root_path . 'includes/functions.' . $phpEx); + } + + include_once(__DIR__ . '/ext/test/notification/type/test.' . $phpEx); + + $this->db = $this->new_dbal(); + $this->config = new phpbb_config(array( + 'allow_privmsg' => true, + 'allow_bookmarks' => true, + 'allow_topic_notify' => true, + 'allow_forum_notify' => true, + )); + $this->user = new phpbb_mock_user(); + $this->user_loader = new phpbb_user_loader($this->db, $phpbb_root_path, $phpEx, 'phpbb_users'); + $this->auth = new phpbb_mock_notifications_auth(); + $this->cache = new phpbb_mock_cache(); + + $this->container = new phpbb_mock_container_builder(); + + $this->notifications = new phpbb_mock_notifications_notification_manager( + array(), + array(), + $this->container, + $this->user_loader, + $this->db, + $this->user, + $phpbb_root_path, + $phpEx, + 'phpbb_notification_types', + 'phpbb_notifications', + 'phpbb_user_notifications' + ); + + $this->notifications->setDependencies($this->auth, $this->cache, $this->config); + + $types = array(); + foreach (array( + 'test', + 'approve_post', + 'approve_topic', + 'bookmark', + 'disapprove_post', + 'disapprove_topic', + 'pm', + 'post', + 'post_in_queue', + 'quote', + 'report_pm', + 'report_pm_closed', + 'report_post', + 'report_post_closed', + 'topic', + 'topic_in_queue', + ) as $type) + { + $class = $this->build_type('phpbb_notification_type_' . $type); + + $types[$type] = $class; + $this->container->set('notification.type.' . $type, $class); + } + + $this->notifications->set_var('notification_types', $types); + } + + protected function build_type($type) + { + global $phpbb_root_path, $phpEx; + + return new $type($this->user_loader, $this->db, $this->cache, $this->user, $this->auth, $this->config, $phpbb_root_path, $phpEx, 'phpbb_notification_types', 'phpbb_notifications', 'phpbb_user_notifications'); + } + + public function test_get_subscription_types() + { + $subscription_types = $this->notifications->get_subscription_types(); + + $this->assertArrayHasKey('NOTIFICATION_GROUP_MISCELLANEOUS', $subscription_types); + $this->assertArrayHasKey('NOTIFICATION_GROUP_POSTING', $subscription_types); + + $this->assertArrayHasKey('bookmark', $subscription_types['NOTIFICATION_GROUP_POSTING']); + $this->assertArrayHasKey('post', $subscription_types['NOTIFICATION_GROUP_POSTING']); + $this->assertArrayHasKey('quote', $subscription_types['NOTIFICATION_GROUP_POSTING']); + $this->assertArrayHasKey('topic', $subscription_types['NOTIFICATION_GROUP_POSTING']); + + $this->assertArrayHasKey('pm', $subscription_types['NOTIFICATION_GROUP_MISCELLANEOUS']); + + //get_subscription_types + //get_subscription_methods + } + + public function test_subscriptions() + { + $this->notifications->delete_subscription('post', 0, '', 2); + + $this->assertArrayNotHasKey('post', $this->notifications->get_global_subscriptions(2)); + + $this->notifications->add_subscription('post', 0, '', 2); + + $this->assertArrayHasKey('post', $this->notifications->get_global_subscriptions(2)); + } + + public function test_notifications() + { + // Used to test post notifications later + $this->db->sql_query('INSERT INTO ' . TOPICS_WATCH_TABLE . ' ' . $this->db->sql_build_array('INSERT', array( + 'topic_id' => 2, + 'notify_status' => NOTIFY_YES, + 'user_id' => 0, + ))); + + $this->assertEquals(array( + 'notifications' => array(), + 'unread_count' => 0, + 'total_count' => 0, + ), $this->notifications->load_notifications(array( + 'count_unread' => true, + ))); + + $this->notifications->add_notifications('test', array( + 'post_id' => '1', + 'topic_id' => '1', + 'post_time' => 1349413321, + )); + + $this->notifications->add_notifications('test', array( + 'post_id' => '2', + 'topic_id' => '2', + 'post_time' => 1349413322, + )); + + $this->notifications->add_notifications('test', array( + 'post_id' => '3', + 'topic_id' => '2', + 'post_time' => 1349413323, + )); + + $this->notifications->add_notifications(array('quote', 'bookmark', 'post', 'test'), array( + 'post_id' => '4', + 'topic_id' => '2', + 'post_time' => 1349413324, + 'poster_id' => 2, + 'topic_title' => 'test-title', + 'post_subject' => 'Re: test-title', + 'forum_id' => 2, + 'forum_name' => 'Your first forum', + )); + + $this->db->sql_query('INSERT INTO ' . BOOKMARKS_TABLE . ' ' . $this->db->sql_build_array('INSERT', array( + 'topic_id' => 2, + 'user_id' => 0, + ))); + + $this->notifications->add_notifications(array('quote', 'bookmark', 'post', 'test'), array( + 'post_id' => '5', + 'topic_id' => '2', + 'post_time' => 1349413325, + 'poster_id' => 2, + 'topic_title' => 'test-title', + 'post_subject' => 'Re: test-title', + 'forum_id' => 2, + 'forum_name' => 'Your first forum', + )); + + $this->notifications->delete_subscription('test'); + + $this->notifications->add_notifications('test', array( + 'post_id' => '6', + 'topic_id' => '2', + 'post_time' => 1349413326, + )); + + $notifications = $this->notifications->load_notifications(array( + 'count_unread' => true, + )); + + $expected = array( + 1 => array( + 'item_type' => 'test', + 'item_id' => 1, + 'item_parent_id' => 1, + 'user_id' => 0, + 'notification_read' => 0, + 'notification_time' => 1349413321, + 'notification_data' => array(), + ), + 2 => array( + 'item_type' => 'test', + 'item_id' => 2, + 'item_parent_id' => 2, + 'user_id' => 0, + 'notification_read' => 0, + 'notification_time' => 1349413322, + 'notification_data' => array(), + ), + 3 => array( + 'item_type' => 'test', + 'item_id' => 3, + 'item_parent_id' => 2, + 'user_id' => 0, + 'notification_read' => 0, + 'notification_time' => 1349413323, + 'notification_data' => array(), + ), + 4 => array( + 'item_type' => 'post', + 'item_id' => 4, + 'item_parent_id' => 2, + 'user_id' => 0, + 'notification_read' => 0, + 'notification_time' => 1349413324, + 'notification_data' => array( + 'poster_id' => 2, + 'topic_title' => 'test-title', + 'post_subject' => 'Re: test-title', + 'post_username' => '', + 'forum_id' => 2, + 'forum_name' => 'Your first forum', + ), + ), + 5 => array( + 'item_type' => 'bookmark', + 'item_id' => 5, + 'item_parent_id' => 2, + 'user_id' => 0, + 'notification_read' => 0, + 'notification_time' => 1349413325, + 'notification_data' => array( + 'poster_id' => 2, + 'topic_title' => 'test-title', + 'post_subject' => 'Re: test-title', + 'post_username' => '', + 'forum_id' => 2, + 'forum_name' => 'Your first forum', + ), + ), + ); + + $this->assertEquals(sizeof($expected), $notifications['unread_count']); + + $notifications = $notifications['notifications']; + + foreach ($expected as $notification_id => $notification_data) + { + //echo $notifications[$notification_id]; + + $this->assertEquals($notification_id, $notifications[$notification_id]->notification_id, 'notification_id'); + + foreach ($notification_data as $key => $value) + { + $this->assertEquals($value, $notifications[$notification_id]->$key, $key . ' ' . $notification_id); + } + } + + // Now test updating ------------------------------- + + $this->notifications->update_notifications('test', array( + 'post_id' => '1', + 'topic_id' => '2', // change parent_id + 'post_time' => 1349413321, + )); + + $this->notifications->update_notifications('test', array( + 'post_id' => '3', + 'topic_id' => '2', + 'post_time' => 1234, // change time + )); + + $this->notifications->update_notifications(array('quote', 'bookmark', 'post', 'test'), array( + 'post_id' => '5', + 'topic_id' => '2', + 'poster_id' => 2, + 'topic_title' => 'test-title2', // change topic_title + 'post_subject' => 'Re: test-title2', // change post_subject + 'forum_id' => 3, // change forum_id + 'forum_name' => 'Your second forum', // change forum_name + )); + + $notifications = $this->notifications->load_notifications(array( + 'count_unread' => true, + )); + + $expected = array( + 1 => array( + 'item_type' => 'test', + 'item_id' => 1, + 'item_parent_id' => 2, + 'user_id' => 0, + 'notification_read' => 0, + 'notification_time' => 1349413321, + 'notification_data' => array(), + ), + 2 => array( + 'item_type' => 'test', + 'item_id' => 2, + 'item_parent_id' => 2, + 'user_id' => 0, + 'notification_read' => 0, + 'notification_time' => 1349413322, + 'notification_data' => array(), + ), + 3 => array( + 'item_type' => 'test', + 'item_id' => 3, + 'item_parent_id' => 2, + 'user_id' => 0, + 'notification_read' => 0, + 'notification_time' => 1234, + 'notification_data' => array(), + ), + 4 => array( + 'item_type' => 'post', + 'item_id' => 4, + 'item_parent_id' => 2, + 'user_id' => 0, + 'notification_read' => 0, + 'notification_time' => 1349413324, + 'notification_data' => array( + 'poster_id' => 2, + 'topic_title' => 'test-title', + 'post_subject' => 'Re: test-title', + 'post_username' => '', + 'forum_id' => 2, + 'forum_name' => 'Your first forum', + ), + ), + 5 => array( + 'item_type' => 'bookmark', + 'item_id' => 5, + 'item_parent_id' => 2, + 'user_id' => 0, + 'notification_read' => 0, + 'notification_time' => 1349413325, + 'notification_data' => array( + 'poster_id' => 2, + 'topic_title' => 'test-title2', + 'post_subject' => 'Re: test-title2', + 'post_username' => '', + 'forum_id' => 3, + 'forum_name' => 'Your second forum', + ), + ), + ); + + $this->assertEquals(sizeof($expected), $notifications['unread_count']); + + $notifications = $notifications['notifications']; + + foreach ($expected as $notification_id => $notification_data) + { + //echo $notifications[$notification_id]; + + $this->assertEquals($notification_id, $notifications[$notification_id]->notification_id, 'notification_id'); + + foreach ($notification_data as $key => $value) + { + $this->assertEquals($value, $notifications[$notification_id]->$key, $key . ' ' . $notification_id); + } + } + } +} -- cgit v1.2.1 From 2cd1c62403c290df13752579258b08ebf007e3fb Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 15 Mar 2013 10:19:28 +0100 Subject: [ticket/11443] Add _test suffix to migration test filenames PHPBB3-11443 --- tests/dbal/migrator_tool_module.php | 150 ------------------------- tests/dbal/migrator_tool_module_test.php | 150 +++++++++++++++++++++++++ tests/dbal/migrator_tool_permission.php | 159 --------------------------- tests/dbal/migrator_tool_permission_test.php | 159 +++++++++++++++++++++++++++ 4 files changed, 309 insertions(+), 309 deletions(-) delete mode 100644 tests/dbal/migrator_tool_module.php create mode 100644 tests/dbal/migrator_tool_module_test.php delete mode 100644 tests/dbal/migrator_tool_permission.php create mode 100644 tests/dbal/migrator_tool_permission_test.php (limited to 'tests') diff --git a/tests/dbal/migrator_tool_module.php b/tests/dbal/migrator_tool_module.php deleted file mode 100644 index 6937b6f8c5..0000000000 --- a/tests/dbal/migrator_tool_module.php +++ /dev/null @@ -1,150 +0,0 @@ -createXMLDataSet(dirname(__FILE__).'/fixtures/migrator_module.xml'); - } - - public function setup() - { - // Need global $db, $user for delete_module function in acp_modules - global $phpbb_root_path, $phpEx, $skip_add_log, $db, $user; - - parent::setup(); - - // Force add_log function to not be used - $skip_add_log = true; - - $db = $this->db = $this->new_dbal(); - $this->cache = new phpbb_cache_service(new phpbb_cache_driver_null(), new phpbb_config(array()), $this->db, $phpbb_root_path, $phpEx); - $user = $this->user = new phpbb_user(); - - $this->tool = new phpbb_db_migration_tool_module($this->db, $this->cache, $this->user, $phpbb_root_path, $phpEx, 'phpbb_modules'); - } - - public function exists_data() - { - return array( - // Test the category - array( - '', - 'ACP_CAT', - true, - ), - array( - 0, - 'ACP_CAT', - true, - ), - - // Test the module - array( - '', - 'ACP_MODULE', - false, - ), - array( - false, - 'ACP_MODULE', - true, - ), - array( - 'ACP_CAT', - 'ACP_MODULE', - true, - ), - ); - } - - /** - * @dataProvider exists_data - */ - public function test_exists($parent, $module, $expected) - { - $this->assertEquals($expected, $this->tool->exists('acp', $parent, $module)); - } - - public function test_add() - { - try - { - $this->tool->add('acp', 0, 'ACP_NEW_CAT'); - } - catch (Exception $e) - { - $this->fail($e); - } - $this->assertEquals(true, $this->tool->exists('acp', 0, 'ACP_NEW_CAT')); - - // Should throw an exception when trying to add a module that already exists - try - { - $this->tool->add('acp', 0, 'ACP_NEW_CAT'); - $this->fail('Exception not thrown'); - } - catch (Exception $e) {} - - try - { - $this->tool->add('acp', 'ACP_NEW_CAT', array( - 'module_basename' => 'acp_new_module', - 'module_langname' => 'ACP_NEW_MODULE', - 'module_mode' => 'test', - 'module_auth' => '', - )); - } - catch (Exception $e) - { - $this->fail($e); - } - $this->assertEquals(true, $this->tool->exists('acp', 'ACP_NEW_CAT', 'ACP_NEW_MODULE')); - } - - public function test_remove() - { - try - { - $this->tool->remove('acp', 'ACP_CAT', 'ACP_MODULE'); - } - catch (Exception $e) - { - $this->fail($e); - } - $this->assertEquals(false, $this->tool->exists('acp', 'ACP_CAT', 'ACP_MODULE')); - } - - public function test_reverse() - { - try - { - $this->tool->add('acp', 0, 'ACP_NEW_CAT'); - } - catch (Exception $e) - { - $this->fail($e); - } - - try - { - $this->tool->reverse('add', 'acp', 0, 'ACP_NEW_CAT'); - } - catch (Exception $e) - { - $this->fail($e); - } - $this->assertFalse($this->tool->exists('acp', 0, 'ACP_NEW_CAT')); - } -} diff --git a/tests/dbal/migrator_tool_module_test.php b/tests/dbal/migrator_tool_module_test.php new file mode 100644 index 0000000000..6937b6f8c5 --- /dev/null +++ b/tests/dbal/migrator_tool_module_test.php @@ -0,0 +1,150 @@ +createXMLDataSet(dirname(__FILE__).'/fixtures/migrator_module.xml'); + } + + public function setup() + { + // Need global $db, $user for delete_module function in acp_modules + global $phpbb_root_path, $phpEx, $skip_add_log, $db, $user; + + parent::setup(); + + // Force add_log function to not be used + $skip_add_log = true; + + $db = $this->db = $this->new_dbal(); + $this->cache = new phpbb_cache_service(new phpbb_cache_driver_null(), new phpbb_config(array()), $this->db, $phpbb_root_path, $phpEx); + $user = $this->user = new phpbb_user(); + + $this->tool = new phpbb_db_migration_tool_module($this->db, $this->cache, $this->user, $phpbb_root_path, $phpEx, 'phpbb_modules'); + } + + public function exists_data() + { + return array( + // Test the category + array( + '', + 'ACP_CAT', + true, + ), + array( + 0, + 'ACP_CAT', + true, + ), + + // Test the module + array( + '', + 'ACP_MODULE', + false, + ), + array( + false, + 'ACP_MODULE', + true, + ), + array( + 'ACP_CAT', + 'ACP_MODULE', + true, + ), + ); + } + + /** + * @dataProvider exists_data + */ + public function test_exists($parent, $module, $expected) + { + $this->assertEquals($expected, $this->tool->exists('acp', $parent, $module)); + } + + public function test_add() + { + try + { + $this->tool->add('acp', 0, 'ACP_NEW_CAT'); + } + catch (Exception $e) + { + $this->fail($e); + } + $this->assertEquals(true, $this->tool->exists('acp', 0, 'ACP_NEW_CAT')); + + // Should throw an exception when trying to add a module that already exists + try + { + $this->tool->add('acp', 0, 'ACP_NEW_CAT'); + $this->fail('Exception not thrown'); + } + catch (Exception $e) {} + + try + { + $this->tool->add('acp', 'ACP_NEW_CAT', array( + 'module_basename' => 'acp_new_module', + 'module_langname' => 'ACP_NEW_MODULE', + 'module_mode' => 'test', + 'module_auth' => '', + )); + } + catch (Exception $e) + { + $this->fail($e); + } + $this->assertEquals(true, $this->tool->exists('acp', 'ACP_NEW_CAT', 'ACP_NEW_MODULE')); + } + + public function test_remove() + { + try + { + $this->tool->remove('acp', 'ACP_CAT', 'ACP_MODULE'); + } + catch (Exception $e) + { + $this->fail($e); + } + $this->assertEquals(false, $this->tool->exists('acp', 'ACP_CAT', 'ACP_MODULE')); + } + + public function test_reverse() + { + try + { + $this->tool->add('acp', 0, 'ACP_NEW_CAT'); + } + catch (Exception $e) + { + $this->fail($e); + } + + try + { + $this->tool->reverse('add', 'acp', 0, 'ACP_NEW_CAT'); + } + catch (Exception $e) + { + $this->fail($e); + } + $this->assertFalse($this->tool->exists('acp', 0, 'ACP_NEW_CAT')); + } +} diff --git a/tests/dbal/migrator_tool_permission.php b/tests/dbal/migrator_tool_permission.php deleted file mode 100644 index 438ab2b28e..0000000000 --- a/tests/dbal/migrator_tool_permission.php +++ /dev/null @@ -1,159 +0,0 @@ -createXMLDataSet(dirname(__FILE__).'/fixtures/migrator_permission.xml'); - } - - public function setup() - { - // Global $db and $cache are needed in acp/auth.php constructor - global $phpbb_root_path, $phpEx, $db, $cache; - - parent::setup(); - - $db = $this->db = $this->new_dbal(); - $cache = $this->cache = new phpbb_cache_service(new phpbb_cache_driver_null(), new phpbb_config(array()), $this->db, $phpbb_root_path, $phpEx); - $this->auth = new phpbb_auth(); - - $this->tool = new phpbb_db_migration_tool_permission($this->db, $this->cache, $this->auth, $phpbb_root_path, $phpEx); - } - - public function exists_data() - { - return array( - array( - 'global', - true, - true, - ), - array( - 'local', - false, - true, - ), - array( - 'both', - true, - true, - ), - array( - 'both', - false, - true, - ), - array( - 'does_not_exist', - true, - false, - ), - ); - } - - /** - * @dataProvider exists_data - */ - public function test_exists($auth_option, $global, $expected) - { - $this->assertEquals($expected, $this->tool->exists($auth_option, $global)); - } - - public function test_add() - { - try - { - $this->tool->add('new', true); - } - catch (Exception $e) - { - $this->fail($e); - } - $this->assertEquals(true, $this->tool->exists('new', true)); - $this->assertEquals(false, $this->tool->exists('new', false)); - - try - { - $this->tool->add('new', false); - } - catch (Exception $e) - { - $this->fail($e); - } - $this->assertEquals(true, $this->tool->exists('new', false)); - - // Should fail (duplicate) - try - { - $this->tool->add('new', true); - $this->fail('Did not throw exception on duplicate'); - } - catch (Exception $e) {} - } - - public function test_remove() - { - try - { - $this->tool->remove('global', true); - } - catch (Exception $e) - { - $this->fail($e); - } - $this->assertEquals(false, $this->tool->exists('global', true)); - - try - { - $this->tool->remove('both', false); - } - catch (Exception $e) - { - $this->fail($e); - } - $this->assertEquals(false, $this->tool->exists('both', false)); - - // Should fail (does not exist) - try - { - $this->tool->remove('new', true); - $this->fail('Did not throw exception on duplicate'); - } - catch (Exception $e) {} - } - - public function test_reverse() - { - try - { - $this->tool->reverse('remove', 'global_test', true); - } - catch (Exception $e) - { - $this->fail($e); - } - $this->assertTrue($this->tool->exists('global_test', true)); - - try - { - $this->tool->reverse('add', 'global_test', true); - } - catch (Exception $e) - { - $this->fail($e); - } - $this->assertFalse($this->tool->exists('global_test', true)); - } -} diff --git a/tests/dbal/migrator_tool_permission_test.php b/tests/dbal/migrator_tool_permission_test.php new file mode 100644 index 0000000000..438ab2b28e --- /dev/null +++ b/tests/dbal/migrator_tool_permission_test.php @@ -0,0 +1,159 @@ +createXMLDataSet(dirname(__FILE__).'/fixtures/migrator_permission.xml'); + } + + public function setup() + { + // Global $db and $cache are needed in acp/auth.php constructor + global $phpbb_root_path, $phpEx, $db, $cache; + + parent::setup(); + + $db = $this->db = $this->new_dbal(); + $cache = $this->cache = new phpbb_cache_service(new phpbb_cache_driver_null(), new phpbb_config(array()), $this->db, $phpbb_root_path, $phpEx); + $this->auth = new phpbb_auth(); + + $this->tool = new phpbb_db_migration_tool_permission($this->db, $this->cache, $this->auth, $phpbb_root_path, $phpEx); + } + + public function exists_data() + { + return array( + array( + 'global', + true, + true, + ), + array( + 'local', + false, + true, + ), + array( + 'both', + true, + true, + ), + array( + 'both', + false, + true, + ), + array( + 'does_not_exist', + true, + false, + ), + ); + } + + /** + * @dataProvider exists_data + */ + public function test_exists($auth_option, $global, $expected) + { + $this->assertEquals($expected, $this->tool->exists($auth_option, $global)); + } + + public function test_add() + { + try + { + $this->tool->add('new', true); + } + catch (Exception $e) + { + $this->fail($e); + } + $this->assertEquals(true, $this->tool->exists('new', true)); + $this->assertEquals(false, $this->tool->exists('new', false)); + + try + { + $this->tool->add('new', false); + } + catch (Exception $e) + { + $this->fail($e); + } + $this->assertEquals(true, $this->tool->exists('new', false)); + + // Should fail (duplicate) + try + { + $this->tool->add('new', true); + $this->fail('Did not throw exception on duplicate'); + } + catch (Exception $e) {} + } + + public function test_remove() + { + try + { + $this->tool->remove('global', true); + } + catch (Exception $e) + { + $this->fail($e); + } + $this->assertEquals(false, $this->tool->exists('global', true)); + + try + { + $this->tool->remove('both', false); + } + catch (Exception $e) + { + $this->fail($e); + } + $this->assertEquals(false, $this->tool->exists('both', false)); + + // Should fail (does not exist) + try + { + $this->tool->remove('new', true); + $this->fail('Did not throw exception on duplicate'); + } + catch (Exception $e) {} + } + + public function test_reverse() + { + try + { + $this->tool->reverse('remove', 'global_test', true); + } + catch (Exception $e) + { + $this->fail($e); + } + $this->assertTrue($this->tool->exists('global_test', true)); + + try + { + $this->tool->reverse('add', 'global_test', true); + } + catch (Exception $e) + { + $this->fail($e); + } + $this->assertFalse($this->tool->exists('global_test', true)); + } +} -- cgit v1.2.1 From d3e2fae66d74f79ef7dcfe2e24f47efaa5c106e2 Mon Sep 17 00:00:00 2001 From: David King Date: Fri, 15 Feb 2013 16:48:43 -0500 Subject: [ticket/11334] Add a test for the controller helper URL method PHPBB3-11334 --- tests/controller/controller_test.php | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'tests') diff --git a/tests/controller/controller_test.php b/tests/controller/controller_test.php index 198fb3c6dd..97f6d6152a 100644 --- a/tests/controller/controller_test.php +++ b/tests/controller/controller_test.php @@ -40,6 +40,12 @@ class phpbb_controller_test extends phpbb_test_case $this->assertEquals(2, sizeof($routes)); } + public function test_controller_url_helper() + { + $helper = new phpbb_controller_helper; + $this->assertEquals($helper->url('foo/bar'),'./app.php?controller=foo/bar'); + } + public function test_controller_resolver() { $container = new ContainerBuilder(); -- cgit v1.2.1 From 48aefb13b0f66dd84f5e7a2f18ca485fabe4833b Mon Sep 17 00:00:00 2001 From: David King Date: Sat, 16 Feb 2013 19:18:16 -0500 Subject: [ticket/11334] Make $phpbb_dispatcher global, as done in append_sid test PHPBB3-11334 --- tests/controller/controller_test.php | 3 +++ 1 file changed, 3 insertions(+) (limited to 'tests') diff --git a/tests/controller/controller_test.php b/tests/controller/controller_test.php index 97f6d6152a..c4818dbd6a 100644 --- a/tests/controller/controller_test.php +++ b/tests/controller/controller_test.php @@ -42,6 +42,9 @@ class phpbb_controller_test extends phpbb_test_case public function test_controller_url_helper() { + global $phpbb_dispatcher; + + $phpbb_dispatcher = new phpbb_mock_event_dispatcher; $helper = new phpbb_controller_helper; $this->assertEquals($helper->url('foo/bar'),'./app.php?controller=foo/bar'); } -- cgit v1.2.1 From cd697e68129868dc811c141660652360e0f0f983 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 15 Mar 2013 13:35:00 +0100 Subject: [ticket/11334] Include functions.php and fix class name in tests PHPBB3-11334 --- tests/controller/controller_test.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/controller/controller_test.php b/tests/controller/controller_test.php index c4818dbd6a..8cdedb27e2 100644 --- a/tests/controller/controller_test.php +++ b/tests/controller/controller_test.php @@ -7,6 +7,8 @@ * */ +require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php'; + use Symfony\Component\HttpFoundation\Request; use Symfony\Component\Routing\Route; use Symfony\Component\Routing\RouteCollection; @@ -14,7 +16,7 @@ use Symfony\Component\Config\FileLocator; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Loader\YamlFileLoader; -class phpbb_controller_test extends phpbb_test_case +class phpbb_controller_controller_test extends phpbb_test_case { public function setUp() { -- cgit v1.2.1 From 9259e635cacce34699115b909f256f9302ec3aaa Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 15 Mar 2013 14:01:15 +0100 Subject: [ticket/11334] Move unit tests for helper->url() into own file PHPBB3-11334 --- tests/controller/controller_test.php | 11 -------- tests/controller/helper_url_test.php | 55 ++++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+), 11 deletions(-) create mode 100644 tests/controller/helper_url_test.php (limited to 'tests') diff --git a/tests/controller/controller_test.php b/tests/controller/controller_test.php index 8cdedb27e2..c06bf7d548 100644 --- a/tests/controller/controller_test.php +++ b/tests/controller/controller_test.php @@ -7,8 +7,6 @@ * */ -require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php'; - use Symfony\Component\HttpFoundation\Request; use Symfony\Component\Routing\Route; use Symfony\Component\Routing\RouteCollection; @@ -42,15 +40,6 @@ class phpbb_controller_controller_test extends phpbb_test_case $this->assertEquals(2, sizeof($routes)); } - public function test_controller_url_helper() - { - global $phpbb_dispatcher; - - $phpbb_dispatcher = new phpbb_mock_event_dispatcher; - $helper = new phpbb_controller_helper; - $this->assertEquals($helper->url('foo/bar'),'./app.php?controller=foo/bar'); - } - public function test_controller_resolver() { $container = new ContainerBuilder(); diff --git a/tests/controller/helper_url_test.php b/tests/controller/helper_url_test.php new file mode 100644 index 0000000000..6e3f535cf3 --- /dev/null +++ b/tests/controller/helper_url_test.php @@ -0,0 +1,55 @@ + 1, 'f' => 2), true, false, 'app.php?controller=foo/bar&t=1&f=2', 'parameters in params-argument as array'), + + // Custom sid parameter + array('foo/bar', 't=1&f=2', true, 'custom-sid', 'app.php?controller=foo/bar&t=1&f=2&sid=custom-sid', 'using session_id'), + + // Testing anchors + // Unsupported: array('foo/bar?t=1&f=2#anchor', false, true, false, 'app.php?controller=foo/bar&t=1&f=2#anchor', 'anchor in url-argument'), + array('foo/bar', 't=1&f=2#anchor', true, false, 'app.php?controller=foo/bar&t=1&f=2#anchor', 'anchor in params-argument'), + array('foo/bar', array('t' => 1, 'f' => 2, '#' => 'anchor'), true, false, 'app.php?controller=foo/bar&t=1&f=2#anchor', 'anchor in params-argument (array)'), + + // Anchors and custom sid + // Unsupported: array('foo/bar?t=1&f=2#anchor', false, true, 'custom-sid', 'app.php?controller=foo/bar&t=1&f=2&sid=custom-sid#anchor', 'anchor in url-argument using session_id'), + array('foo/bar', 't=1&f=2#anchor', true, 'custom-sid', 'app.php?controller=foo/bar&t=1&f=2&sid=custom-sid#anchor', 'anchor in params-argument using session_id'), + array('foo/bar', array('t' => 1, 'f' => 2, '#' => 'anchor'), true, 'custom-sid', 'app.php?controller=foo/bar&t=1&f=2&sid=custom-sid#anchor', 'anchor in params-argument (array) using session_id'), + + // Empty parameters should not append the & + array('foo/bar', false, true, false, 'app.php?controller=foo/bar', 'no params using bool false'), + array('foo/bar', '', true, false, 'app.php?controller=foo/bar', 'no params using empty string'), + array('foo/bar', array(), true, false, 'app.php?controller=foo/bar', 'no params using empty array'), + ); + } + + /** + * @dataProvider helper_url_data + */ + public function test_helper_url($route, $params, $is_amp, $session_id, $expected, $description) + { + global $phpbb_dispatcher; + + $phpbb_dispatcher = new phpbb_mock_event_dispatcher; + $helper = new phpbb_controller_helper; + $this->assertEquals($helper->url($route, $params, $is_amp, $session_id), $expected); + } +} + -- cgit v1.2.1 From 076711d9a95e05083143b7ac4a589914a2e2b2ad Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 15 Mar 2013 14:02:46 +0100 Subject: [ticket/11334] Use mocks instead of making parameters optional PHPBB3-11334 --- tests/controller/helper_url_test.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/controller/helper_url_test.php b/tests/controller/helper_url_test.php index 6e3f535cf3..7754278219 100644 --- a/tests/controller/helper_url_test.php +++ b/tests/controller/helper_url_test.php @@ -48,7 +48,11 @@ class phpbb_controller_helper_url_test extends phpbb_test_case global $phpbb_dispatcher; $phpbb_dispatcher = new phpbb_mock_event_dispatcher; - $helper = new phpbb_controller_helper; + $this->style_resource_locator = new phpbb_style_resource_locator(); + $this->user = $this->getMock('phpbb_user'); + $this->template = new phpbb_template($phpbb_root_path, $phpEx, $config, $this->user, $this->style_resource_locator, new phpbb_template_context()); + + $helper = new phpbb_controller_helper($this->template, $this->user, '', '.php'); $this->assertEquals($helper->url($route, $params, $is_amp, $session_id), $expected); } } -- cgit v1.2.1 From 9157095cdabe629765ab0583f2850c2d4771c1d1 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 15 Mar 2013 14:06:56 +0100 Subject: [ticket/11334] Fix copyright year in test file PHPBB3-11334 --- tests/controller/helper_url_test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/controller/helper_url_test.php b/tests/controller/helper_url_test.php index 7754278219..f27c03501d 100644 --- a/tests/controller/helper_url_test.php +++ b/tests/controller/helper_url_test.php @@ -2,7 +2,7 @@ /** * * @package testing -* @copyright (c) 2011 phpBB Group +* @copyright (c) 2013 phpBB Group * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 * */ -- cgit v1.2.1 From 3b0cdc53629c3a852762ae9b96b809cf4b1af2c4 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 15 Mar 2013 15:21:15 +0100 Subject: [ticket/11334] Allow parameters to be specified in the route PHPBB3-11334 --- tests/controller/helper_url_test.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'tests') diff --git a/tests/controller/helper_url_test.php b/tests/controller/helper_url_test.php index f27c03501d..195f48d8a9 100644 --- a/tests/controller/helper_url_test.php +++ b/tests/controller/helper_url_test.php @@ -15,7 +15,7 @@ class phpbb_controller_helper_url_test extends phpbb_test_case public function helper_url_data() { return array( - // Unsupported: array('foo/bar?t=1&f=2', false, true, false, 'app.php?controller=foo/bar&t=1&f=2', 'parameters in url-argument'), + array('foo/bar?t=1&f=2', false, true, false, 'app.php?t=1&f=2&controller=foo/bar', 'parameters in url-argument'), array('foo/bar', 't=1&f=2', true, false, 'app.php?controller=foo/bar&t=1&f=2', 'parameters in params-argument using amp'), array('foo/bar', 't=1&f=2', false, false, 'app.php?controller=foo/bar&t=1&f=2', 'parameters in params-argument using &'), array('foo/bar', array('t' => 1, 'f' => 2), true, false, 'app.php?controller=foo/bar&t=1&f=2', 'parameters in params-argument as array'), @@ -24,12 +24,12 @@ class phpbb_controller_helper_url_test extends phpbb_test_case array('foo/bar', 't=1&f=2', true, 'custom-sid', 'app.php?controller=foo/bar&t=1&f=2&sid=custom-sid', 'using session_id'), // Testing anchors - // Unsupported: array('foo/bar?t=1&f=2#anchor', false, true, false, 'app.php?controller=foo/bar&t=1&f=2#anchor', 'anchor in url-argument'), + array('foo/bar?t=1&f=2#anchor', false, true, false, 'app.php?t=1&f=2&controller=foo/bar#anchor', 'anchor in url-argument'), array('foo/bar', 't=1&f=2#anchor', true, false, 'app.php?controller=foo/bar&t=1&f=2#anchor', 'anchor in params-argument'), array('foo/bar', array('t' => 1, 'f' => 2, '#' => 'anchor'), true, false, 'app.php?controller=foo/bar&t=1&f=2#anchor', 'anchor in params-argument (array)'), // Anchors and custom sid - // Unsupported: array('foo/bar?t=1&f=2#anchor', false, true, 'custom-sid', 'app.php?controller=foo/bar&t=1&f=2&sid=custom-sid#anchor', 'anchor in url-argument using session_id'), + array('foo/bar?t=1&f=2#anchor', false, true, 'custom-sid', 'app.php?t=1&f=2&controller=foo/bar&sid=custom-sid#anchor', 'anchor in url-argument using session_id'), array('foo/bar', 't=1&f=2#anchor', true, 'custom-sid', 'app.php?controller=foo/bar&t=1&f=2&sid=custom-sid#anchor', 'anchor in params-argument using session_id'), array('foo/bar', array('t' => 1, 'f' => 2, '#' => 'anchor'), true, 'custom-sid', 'app.php?controller=foo/bar&t=1&f=2&sid=custom-sid#anchor', 'anchor in params-argument (array) using session_id'), -- cgit v1.2.1 From 4168cfd7e6ae6a6bd2c6e16b330b9ea27c9cf4af Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sat, 16 Mar 2013 01:24:50 +0100 Subject: [ticket/11443] Fix Migrator Modules Tool by creating a phpbb_log object PHPBB3-11443 --- tests/dbal/migrator_tool_module_test.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/dbal/migrator_tool_module_test.php b/tests/dbal/migrator_tool_module_test.php index 6937b6f8c5..3303086b26 100644 --- a/tests/dbal/migrator_tool_module_test.php +++ b/tests/dbal/migrator_tool_module_test.php @@ -21,7 +21,7 @@ class phpbb_dbal_migrator_tool_module_test extends phpbb_database_test_case public function setup() { // Need global $db, $user for delete_module function in acp_modules - global $phpbb_root_path, $phpEx, $skip_add_log, $db, $user; + global $phpbb_root_path, $phpEx, $skip_add_log, $db, $user, $phpbb_log; parent::setup(); @@ -32,6 +32,11 @@ class phpbb_dbal_migrator_tool_module_test extends phpbb_database_test_case $this->cache = new phpbb_cache_service(new phpbb_cache_driver_null(), new phpbb_config(array()), $this->db, $phpbb_root_path, $phpEx); $user = $this->user = new phpbb_user(); + $cache = new phpbb_mock_cache; + $phpbb_dispatcher = new phpbb_mock_event_dispatcher(); + $auth = $this->getMock('phpbb_auth'); + $phpbb_log = new phpbb_log($db, $user, $auth, $phpbb_dispatcher, $phpbb_root_path, 'adm/', $phpEx, LOG_TABLE); + $this->tool = new phpbb_db_migration_tool_module($this->db, $this->cache, $this->user, $phpbb_root_path, $phpEx, 'phpbb_modules'); } -- cgit v1.2.1 From 3c99a33e878063e96c4c57bb64d03cff35621fa6 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Sun, 17 Mar 2013 18:58:43 +0100 Subject: [ticket/11457] Remove check and include for set_var function. It's not used. PHPBB3-11457 --- tests/notification/notification_test.php | 5 ----- 1 file changed, 5 deletions(-) (limited to 'tests') diff --git a/tests/notification/notification_test.php b/tests/notification/notification_test.php index 13c868a0c7..beccf55371 100644 --- a/tests/notification/notification_test.php +++ b/tests/notification/notification_test.php @@ -22,11 +22,6 @@ class phpbb_notification_test extends phpbb_database_test_case global $phpbb_root_path, $phpEx; - if (!function_exists('set_var')) - { - include($phpbb_root_path . 'includes/functions.' . $phpEx); - } - include_once(__DIR__ . '/ext/test/notification/type/test.' . $phpEx); $this->db = $this->new_dbal(); -- cgit v1.2.1 From 15aec0bbb24be10da850f78d85a3d10880c6f28a Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Thu, 21 Mar 2013 03:07:50 +0100 Subject: [ticket/11460] Add methods for checkbox handling to phpbb_functional_test_case. PHPBB3-11460 --- .../test_framework/phpbb_functional_test_case.php | 64 ++++++++++++++++++++++ 1 file changed, 64 insertions(+) (limited to 'tests') diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index 887dfea3b5..a62f5341ca 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -463,4 +463,68 @@ class phpbb_functional_test_case extends phpbb_test_case $this->assertGreaterThan(0, count($nodes), $msg); return $nodes; } + + /** + * Asserts that exactly one checkbox with name $name exists within the scope + * of $crawler and that the checkbox is checked. + * + * @param Symfony\Component\DomCrawler\Crawler $crawler + * @param string $name + * @param string $message + * + * @return null + */ + public function assert_checkbox_is_checked($crawler, $name, $message = '') + { + $this->assertSame( + 'checked', + $this->assert_find_one_checkbox($crawler, $name)->attr('checked'), + $message ?: "Failed asserting that checkbox $name is checked." + ); + } + + /** + * Asserts that exactly one checkbox with name $name exists within the scope + * of $crawler and that the checkbox is unchecked. + * + * @param Symfony\Component\DomCrawler\Crawler $crawler + * @param string $name + * @param string $message + * + * @return null + */ + public function assert_checkbox_is_unchecked($crawler, $name, $message = '') + { + $this->assertSame( + '', + $this->assert_find_one_checkbox($crawler, $name)->attr('checked'), + $message ?: "Failed asserting that checkbox $name is unchecked." + ); + } + + /** + * Searches for an input element of type checkbox with the name $name using + * $crawler. Contains an assertion that only one such checkbox exists within + * the scope of $crawler. + * + * @param Symfony\Component\DomCrawler\Crawler $crawler + * @param string $name + * @param string $message + * + * @return Symfony\Component\DomCrawler\Crawler + */ + public function assert_find_one_checkbox($crawler, $name, $message = '') + { + $query = sprintf('//input[@type="checkbox" and @name="%s"]', $name); + $result = $crawler->filterXPath($query); + + $this->assertEquals( + 1, + sizeof($result), + $message ?: 'Failed asserting that exactly one checkbox with name' . + " $name exists in crawler scope." + ); + + return $result; + } } -- cgit v1.2.1 From fadcee77b9ac652655f1dffb07979ac59b78b140 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Fri, 22 Mar 2013 10:12:39 +0100 Subject: [ticket/11465] Add unit tests for acp_modules::get_module_infos() The tests add 3 different modules. One acp module that should be found (acp/a_module), one acp module that should not be found (acp/fail_module), and one mcp module that should work again (mcp/a_module). The modules' info files had to be included as they were not auto-loaded for some reason. There are several test stages. First of, it is tested if the correct mcp and acp module is returned. Afterwards, the proper loading of specified modules is tested. One with an existing module and one with a not existing module. Finally, the test concludes with trying to get the module info of not existing ucp modules. Other classes like foobar would have also worked for that check but I decided to use the ucp type of class as that is the one type missing from the added test modules. PHPBB3-11465 --- tests/extension/ext/foo/acp/a_info.php | 16 +++++ tests/extension/ext/foo/acp/a_module.php | 5 ++ tests/extension/ext/foo/acp/fail_info.php | 16 +++++ tests/extension/ext/foo/acp/fail_module.php | 5 ++ tests/extension/ext/foo/mcp/a_info.php | 16 +++++ tests/extension/ext/foo/mcp/a_module.php | 5 ++ tests/extension/modules_test.php | 95 +++++++++++++++++++++++++++++ 7 files changed, 158 insertions(+) create mode 100644 tests/extension/ext/foo/acp/a_info.php create mode 100644 tests/extension/ext/foo/acp/a_module.php create mode 100644 tests/extension/ext/foo/acp/fail_info.php create mode 100644 tests/extension/ext/foo/acp/fail_module.php create mode 100644 tests/extension/ext/foo/mcp/a_info.php create mode 100644 tests/extension/ext/foo/mcp/a_module.php create mode 100644 tests/extension/modules_test.php (limited to 'tests') diff --git a/tests/extension/ext/foo/acp/a_info.php b/tests/extension/ext/foo/acp/a_info.php new file mode 100644 index 0000000000..3e9bbffaca --- /dev/null +++ b/tests/extension/ext/foo/acp/a_info.php @@ -0,0 +1,16 @@ + 'phpbb_ext_foo_acp_a_module', + 'title' => 'Foobar', + 'version' => '3.1.0-dev', + 'modes' => array( + 'config' => array('title' => 'Config', 'auth' => '', 'cat' => array('ACP_MODS')), + ), + ); + } +} diff --git a/tests/extension/ext/foo/acp/a_module.php b/tests/extension/ext/foo/acp/a_module.php new file mode 100644 index 0000000000..093b4b1ad7 --- /dev/null +++ b/tests/extension/ext/foo/acp/a_module.php @@ -0,0 +1,5 @@ + 'phpbb_ext_foo_acp_fail_module', + 'title' => 'Foobar', + 'version' => '3.1.0-dev', + 'modes' => array( + 'config' => array('title' => 'Config', 'auth' => '', 'cat' => array('ACP_MODS')), + ), + ); + } +} diff --git a/tests/extension/ext/foo/acp/fail_module.php b/tests/extension/ext/foo/acp/fail_module.php new file mode 100644 index 0000000000..dd16955418 --- /dev/null +++ b/tests/extension/ext/foo/acp/fail_module.php @@ -0,0 +1,5 @@ + 'phpbb_ext_foo_mcp_a_module', + 'title' => 'Foobar', + 'version' => '3.1.0-dev', + 'modes' => array( + 'config' => array('title' => 'Config', 'auth' => '', 'cat' => array('MCP_MAIN')), + ), + ); + } +} diff --git a/tests/extension/ext/foo/mcp/a_module.php b/tests/extension/ext/foo/mcp/a_module.php new file mode 100644 index 0000000000..59d9f8cc6f --- /dev/null +++ b/tests/extension/ext/foo/mcp/a_module.php @@ -0,0 +1,5 @@ +extension_manager = new phpbb_mock_extension_manager( + dirname(__FILE__) . '/', + array( + 'foo' => array( + 'ext_name' => 'foo', + 'ext_active' => '1', + 'ext_path' => 'ext/foo/', + ), + 'bar' => array( + 'ext_name' => 'bar', + 'ext_active' => '1', + 'ext_path' => 'ext/bar/', + ), + )); + $phpbb_extension_manager = $this->extension_manager; + + $this->acp_modules = new acp_modules(); + } + + public function test_get_module_infos() + { + // the modules' info files needs to be included before the test for + // some reason ... + require_once dirname(__FILE__) . '/ext/foo/acp/a_info.php'; + require_once dirname(__FILE__) . '/ext/foo/mcp/a_info.php'; + require_once dirname(__FILE__) . '/ext/foo/acp/fail_info.php'; + + $this->acp_modules->module_class = 'acp'; + $acp_modules = $this->acp_modules->get_module_infos(); + $this->assertEquals(array( + 'phpbb_ext_foo_acp_a_module' => array( + 'filename' => 'phpbb_ext_foo_acp_a_module', + 'title' => 'Foobar', + 'version' => '3.1.0-dev', + 'modes' => array( + 'config' => array('title' => 'Config', 'auth' => '', 'cat' => array('ACP_MODS')), + ), + ), + ), $acp_modules); + + $this->acp_modules->module_class = 'mcp'; + $acp_modules = $this->acp_modules->get_module_infos(); + $this->assertEquals(array( + 'phpbb_ext_foo_mcp_a_module' => array( + 'filename' => 'phpbb_ext_foo_mcp_a_module', + 'title' => 'Foobar', + 'version' => '3.1.0-dev', + 'modes' => array( + 'config' => array('title' => 'Config', 'auth' => '', 'cat' => array('MCP_MAIN')), + ), + ), + ), $acp_modules); + + $this->acp_modules->module_class = 'mcp'; + $acp_modules = $this->acp_modules->get_module_infos('mcp_a_module'); + $this->assertEquals(array( + 'phpbb_ext_foo_mcp_a_module' => array( + 'filename' => 'phpbb_ext_foo_mcp_a_module', + 'title' => 'Foobar', + 'version' => '3.1.0-dev', + 'modes' => array( + 'config' => array('title' => 'Config', 'auth' => '', 'cat' => array('MCP_MAIN')), + ), + ), + ), $acp_modules); + + $this->acp_modules->module_class = 'mcp'; + $acp_modules = $this->acp_modules->get_module_infos('mcp_a_fail'); + $this->assertEquals(array(), $acp_modules); + + $this->acp_modules->module_class = 'ucp'; + $acp_modules = $this->acp_modules->get_module_infos(); + $this->assertEquals(array(), $acp_modules); + } +} -- cgit v1.2.1 From 11477a3f18078625d79205e4ab488a25ead7d15d Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Fri, 22 Mar 2013 13:29:30 +0100 Subject: [ticket/11465] Move require_once() in unit test to the top of the file PHPBB3-11465 --- tests/extension/modules_test.php | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) (limited to 'tests') diff --git a/tests/extension/modules_test.php b/tests/extension/modules_test.php index 52ec3503e7..36f54fde32 100644 --- a/tests/extension/modules_test.php +++ b/tests/extension/modules_test.php @@ -7,7 +7,10 @@ * */ -require_once dirname(__FILE__) . './../../phpBB/includes/acp/acp_modules.php'; +require_once dirname(__FILE__) . '/ext/foo/acp/a_info.php'; +require_once dirname(__FILE__) . '/ext/foo/mcp/a_info.php'; +require_once dirname(__FILE__) . '/ext/foo/acp/fail_info.php'; +require_once dirname(__FILE__) . '/../../phpBB/includes/acp/acp_modules.php'; class phpbb_extension_modules_test extends phpbb_test_case { @@ -39,12 +42,6 @@ class phpbb_extension_modules_test extends phpbb_test_case public function test_get_module_infos() { - // the modules' info files needs to be included before the test for - // some reason ... - require_once dirname(__FILE__) . '/ext/foo/acp/a_info.php'; - require_once dirname(__FILE__) . '/ext/foo/mcp/a_info.php'; - require_once dirname(__FILE__) . '/ext/foo/acp/fail_info.php'; - $this->acp_modules->module_class = 'acp'; $acp_modules = $this->acp_modules->get_module_infos(); $this->assertEquals(array( -- cgit v1.2.1 From 69df6b49db73d1a475d0b410f38fb4efb56d7451 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Thu, 21 Mar 2013 03:08:15 +0100 Subject: [ticket/11460] Add test for whether post_email and topic_email are checked. PHPBB3-11460 --- tests/functional/notification_test.php | 46 ++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 tests/functional/notification_test.php (limited to 'tests') diff --git a/tests/functional/notification_test.php b/tests/functional/notification_test.php new file mode 100644 index 0000000000..519fb8152b --- /dev/null +++ b/tests/functional/notification_test.php @@ -0,0 +1,46 @@ +login(); + $crawler = $this->request('GET', 'ucp.php?i=ucp_notifications&mode=notification_options'); + $this->assert_response_success(); + + $cplist = $crawler->filter('.cplist'); + if ($expected_status) + { + $this->assert_checkbox_is_checked($cplist, $checkbox_name); + } + else + { + $this->assert_checkbox_is_unchecked($cplist, $checkbox_name); + } + } +} -- cgit v1.2.1 From 02817158fc4209b57893eaba107f732274835fa7 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Fri, 22 Mar 2013 22:42:05 +0100 Subject: [ticket/11460] Configure functional test board email using dummy SMTP data. PHPBB3-11460 --- tests/test_framework/phpbb_functional_test_case.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'tests') diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index a62f5341ca..a411d9c98a 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -196,12 +196,12 @@ class phpbb_functional_test_case extends phpbb_test_case $parseURL = parse_url(self::$config['phpbb_functional_url']); $data = array_merge($data, array( - 'email_enable' => false, - 'smtp_delivery' => false, - 'smtp_host' => '', - 'smtp_auth' => '', - 'smtp_user' => '', - 'smtp_pass' => '', + 'email_enable' => true, + 'smtp_delivery' => true, + 'smtp_host' => 'nxdomain.phpbb.com', + 'smtp_auth' => '', + 'smtp_user' => 'nxuser', + 'smtp_pass' => 'nxpass', 'cookie_secure' => false, 'force_server_vars' => false, 'server_protocol' => $parseURL['scheme'] . '://', -- cgit v1.2.1 From bc5f8e30d09be1ded463b7d7a0e0d9b001de6b3b Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sat, 23 Mar 2013 13:20:32 +0100 Subject: [ticket/11405] Add some basic tests for notifications in submit_post() Poster, should NOT receive a notification Topic subscribed, should receive a notification Topic subscribed, but unauthed to read, should NOT receive a notification Topic subscribed, but already notified, should NOT receive a new notification Topic and forum subscribed, should receive ONE notification Forum subscribed, should receive a notification Forum subscribed, but already notified, should NOT receive a new notification PHPBB3-11405 --- .../fixtures/submit_post_notification.xml | 132 ++++++++++++++ .../submit_post_notifications_test.php | 195 +++++++++++++++++++++ 2 files changed, 327 insertions(+) create mode 100644 tests/notification/fixtures/submit_post_notification.xml create mode 100644 tests/notification/submit_post_notifications_test.php (limited to 'tests') diff --git a/tests/notification/fixtures/submit_post_notification.xml b/tests/notification/fixtures/submit_post_notification.xml new file mode 100644 index 0000000000..c082402056 --- /dev/null +++ b/tests/notification/fixtures/submit_post_notification.xml @@ -0,0 +1,132 @@ + + + + forum_id + user_id + notify_status + + 1 + 6 + 0 + + + 1 + 7 + 0 + + + 1 + 8 + 0 + +
+ + item_type + user_id + item_id + item_parent_id + notification_data + + post + 5 + 1 + 1 + + + + post + 8 + 1 + 1 + + +
+ +
+ + topic_id + user_id + notify_status + + 1 + 2 + 0 + + + 1 + 3 + 0 + + + 1 + 4 + 0 + + + 1 + 5 + 0 + + + 1 + 6 + 0 + +
+ + item_type + item_id + user_id + method + notify + + post + 0 + 2 + + 1 + + + post + 0 + 3 + + 1 + + + post + 0 + 4 + + 1 + + + post + 0 + 5 + + 1 + + + post + 0 + 6 + + 1 + + + post + 0 + 7 + + 1 + + + post + 0 + 8 + + 1 + +
+
diff --git a/tests/notification/submit_post_notifications_test.php b/tests/notification/submit_post_notifications_test.php new file mode 100644 index 0000000000..e08d7a439a --- /dev/null +++ b/tests/notification/submit_post_notifications_test.php @@ -0,0 +1,195 @@ +createXMLDataSet(dirname(__FILE__) . '/fixtures/submit_post_notification.xml'); + } + + public function setUp() + { + parent::setUp(); + + global $auth, $cache, $config, $db, $phpbb_container, $phpbb_dispatcher, $user, $request, $phpEx, $phpbb_root_path; + + // Database + $this->db = $this->new_dbal(); + $db = $this->db; + + // Cache + $cache = new phpbb_mock_cache(); + + // Auth + $auth = $this->getMock('phpbb_auth'); + $auth->expects($this->any()) + ->method('acl_get') + ->with($this->stringContains('_'), + $this->anything()) + ->will($this->returnValueMap(array( + array('f_noapprove', 1, true), + array('f_postcount', 1, true), + array('m_edit', 1, false), + ))); + + $auth->expects($this->any()) + ->method('acl_get_list') + ->with($this->anything(), + $this->stringContains('_'), + $this->greaterThan(0)) + ->will($this->returnValueMap(array( + array( + array( + 0 => '3', + 1 => '4', + 2 => '5', + 3 => '6', + 5 => '7', + 6 => '8', + ), + 'f_read', + 1, + array( + 1 => array( + 'f_read' => array(3, 5, 6, 7, 8,), + ), + ), + ), + array( + array( + 0 => '3', + 1 => '4', + 2 => '5', + 3 => '6', + ), + 'f_read', + 1, + array( + 1 => array( + 'f_read' => array(3, 5, 6,), + ), + ), + ), + ))); + + // Config + $config = new phpbb_config(array('num_topics' => 1,'num_posts' => 1,)); + set_config(null, null, null, $config); + set_config_count(null, null, null, $config); + + // Event dispatcher + $phpbb_dispatcher = new phpbb_mock_event_dispatcher(); + + // User + $user = $this->getMock('phpbb_user'); + $user->ip = ''; + $user->data = array( + 'user_id' => 2, + 'username' => 'user-name', + 'is_registered' => true, + 'user_colour' => '', + ); + + // Request + $type_cast_helper = $this->getMock('phpbb_request_type_cast_helper_interface'); + $request = $this->getMock('phpbb_request'); + + // Container + $phpbb_container = new phpbb_mock_container_builder(); + + $user_loader = new phpbb_user_loader($db, $phpbb_root_path, '.' . $phpEx, USERS_TABLE); + + // Notification Manager + $phpbb_notifications = new phpbb_notification_manager(array(), array(), + $phpbb_container, $user_loader, $db, $user, + $phpbb_root_path, '.' . $phpEx, + NOTIFICATION_TYPES_TABLE, NOTIFICATIONS_TABLE, USER_NOTIFICATIONS_TABLE); + $phpbb_container->set('notification_manager', $phpbb_notifications); + + // Notification Types + $notification_types = array('quote', 'bookmark', 'post'); + foreach ($notification_types as $type) + { + $class_name = 'phpbb_notification_type_' . $type; + $phpbb_container->set('notification.type.' . $type, new $class_name( + $user_loader, $db, $cache, $user, $auth, $config, + $phpbb_root_path, '.' . $phpEx, + NOTIFICATION_TYPES_TABLE, NOTIFICATIONS_TABLE, USER_NOTIFICATIONS_TABLE)); + } + } + + /** + * submit_post() Notifications test + * + * User => State description + * 2 => Poster, should NOT receive a notification + * 3 => Topic subscribed, should receive a notification + * 4 => Topic subscribed, but unauthed to read, should NOT receive a notification + * 5 => Topic subscribed, but already notified, should NOT receive a new notification + * 6 => Topic and forum subscribed, should receive ONE notification + * 7 => Forum subscribed, should receive a notification + * 8 => Forum subscribed, but already notified, should NOT receive a new notification + */ + public function test_type_post() + { + $sql = 'SELECT user_id, item_id, item_parent_id + FROM ' . NOTIFICATIONS_TABLE . " + WHERE item_type = 'post' + ORDER BY user_id, item_id ASC"; + $result = $this->db->sql_query($sql); + $this->assertEquals(array( + array('user_id' => 5, 'item_id' => 1, 'item_parent_id' => 1), + array('user_id' => 8, 'item_id' => 1, 'item_parent_id' => 1), + ), $this->db->sql_fetchrowset($result)); + $this->db->sql_freeresult($result); + + $poll = array(); + $data = array( + 'forum_id' => 1, + 'topic_id' => 1, + 'topic_title' => 'topic_title', + 'icon_id' => 0, + 'enable_bbcode' => 0, + 'enable_smilies' => 0, + 'enable_urls' => 0, + 'enable_sig' => 0, + 'message' => '', + 'message_md5' => '', + 'attachment_data' => array(), + 'bbcode_bitfield' => '', + 'bbcode_uid' => '', + 'post_edit_locked' => false, + //'force_approved_state' => 1, + ); + + submit_post('reply', '', 'poster-name', POST_NORMAL, $poll, $data, false, false); + + $sql = 'SELECT user_id, item_id, item_parent_id + FROM ' . NOTIFICATIONS_TABLE . " + WHERE item_type = 'post' + ORDER BY user_id ASC, item_id ASC"; + $result = $this->db->sql_query($sql); + $this->assertEquals(array( + array('user_id' => 3, 'item_id' => 1, 'item_parent_id' => 1,), + array('user_id' => 5, 'item_id' => 1, 'item_parent_id' => 1,), + array('user_id' => 6, 'item_id' => 1, 'item_parent_id' => 1,), + array('user_id' => 7, 'item_id' => 1, 'item_parent_id' => 1,), + array('user_id' => 8, 'item_id' => 1, 'item_parent_id' => 1,), + ), $this->db->sql_fetchrowset($result)); + $this->db->sql_freeresult($result); + } +} -- cgit v1.2.1 From d3decaeedff926f2945285b713e85c09c3de9daf Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Sun, 24 Mar 2013 23:42:13 +0100 Subject: [ticket/11460] Add default behaviour tests for notification and email types. PHPBB3-11460 --- tests/functional/notification_test.php | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/functional/notification_test.php b/tests/functional/notification_test.php index 519fb8152b..ec495da602 100644 --- a/tests/functional/notification_test.php +++ b/tests/functional/notification_test.php @@ -15,12 +15,22 @@ class phpbb_functional_notification_test extends phpbb_functional_test_case static public function user_subscription_data() { return array( + // Rows inserted by phpBB/install/schemas/schema_data.sql + // Also see PHPBB3-11460 array('post_notification', true), array('topic_notification', true), - - // PHPBB3-11460 array('post_email', true), array('topic_email', true), + + // Default behaviour for in-board notifications: + // If user did not opt-out, in-board notifications are on. + array('bookmark_notification', true), + array('quote_notification', true), + + // Default behaviour for email notifications: + // If user did not opt-in, email notifications are off. + array('bookmark_email', false), + array('quote_email', false), ); } -- cgit v1.2.1 From a91ffe06c79dd067162fe3d659be44382a20df0e Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sat, 23 Mar 2013 13:25:01 +0100 Subject: [ticket/11405] Send post notifications to forum subscribers Like in 3.0 we should also send notifications about new posts to users that subscribed to the forum. (Subscriptions are verbose) PHPBB3-11405 --- .../submit_post_notifications_test.php | 24 +--------------------- 1 file changed, 1 insertion(+), 23 deletions(-) (limited to 'tests') diff --git a/tests/notification/submit_post_notifications_test.php b/tests/notification/submit_post_notifications_test.php index e08d7a439a..3dfb948ca9 100644 --- a/tests/notification/submit_post_notifications_test.php +++ b/tests/notification/submit_post_notifications_test.php @@ -53,14 +53,7 @@ class phpbb_notification_submit_post_notifications_test extends phpbb_database_t $this->greaterThan(0)) ->will($this->returnValueMap(array( array( - array( - 0 => '3', - 1 => '4', - 2 => '5', - 3 => '6', - 5 => '7', - 6 => '8', - ), + array('3', '4', '5', '6', '7', '8',), 'f_read', 1, array( @@ -69,21 +62,6 @@ class phpbb_notification_submit_post_notifications_test extends phpbb_database_t ), ), ), - array( - array( - 0 => '3', - 1 => '4', - 2 => '5', - 3 => '6', - ), - 'f_read', - 1, - array( - 1 => array( - 'f_read' => array(3, 5, 6,), - ), - ), - ), ))); // Config -- cgit v1.2.1 From 7d5949ae3d2faba5dc76c3d355e73b5abaa8e6c1 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Mon, 25 Mar 2013 14:37:22 +0100 Subject: [ticket/11405] Fix some coding style issues PHPBB3-11405 --- tests/notification/submit_post_notifications_test.php | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) (limited to 'tests') diff --git a/tests/notification/submit_post_notifications_test.php b/tests/notification/submit_post_notifications_test.php index 3dfb948ca9..6b61624481 100644 --- a/tests/notification/submit_post_notifications_test.php +++ b/tests/notification/submit_post_notifications_test.php @@ -53,12 +53,12 @@ class phpbb_notification_submit_post_notifications_test extends phpbb_database_t $this->greaterThan(0)) ->will($this->returnValueMap(array( array( - array('3', '4', '5', '6', '7', '8',), + array('3', '4', '5', '6', '7', '8'), 'f_read', 1, array( 1 => array( - 'f_read' => array(3, 5, 6, 7, 8,), + 'f_read' => array(3, 5, 6, 7, 8), ), ), ), @@ -113,6 +113,9 @@ class phpbb_notification_submit_post_notifications_test extends phpbb_database_t /** * submit_post() Notifications test * + * submit_post() $mode = 'reply' + * Notification item_type = 'post' + * * User => State description * 2 => Poster, should NOT receive a notification * 3 => Topic subscribed, should receive a notification @@ -162,11 +165,11 @@ class phpbb_notification_submit_post_notifications_test extends phpbb_database_t ORDER BY user_id ASC, item_id ASC"; $result = $this->db->sql_query($sql); $this->assertEquals(array( - array('user_id' => 3, 'item_id' => 1, 'item_parent_id' => 1,), - array('user_id' => 5, 'item_id' => 1, 'item_parent_id' => 1,), - array('user_id' => 6, 'item_id' => 1, 'item_parent_id' => 1,), - array('user_id' => 7, 'item_id' => 1, 'item_parent_id' => 1,), - array('user_id' => 8, 'item_id' => 1, 'item_parent_id' => 1,), + array('user_id' => 3, 'item_id' => 1, 'item_parent_id' => 1), + array('user_id' => 5, 'item_id' => 1, 'item_parent_id' => 1), + array('user_id' => 6, 'item_id' => 1, 'item_parent_id' => 1), + array('user_id' => 7, 'item_id' => 1, 'item_parent_id' => 1), + array('user_id' => 8, 'item_id' => 1, 'item_parent_id' => 1), ), $this->db->sql_fetchrowset($result)); $this->db->sql_freeresult($result); } -- cgit v1.2.1 From 499eded88004f0bbae554090939b38e6158c8271 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Mon, 25 Mar 2013 14:40:53 +0100 Subject: [ticket/11405] Add unit tests for quoted users notifications PHPBB3-11405 --- .../fixtures/submit_post_notification.xml | 98 +++++++++++ .../submit_post_notifications_test.php | 176 -------------------- tests/notification/submit_post_type_post_test.php | 176 ++++++++++++++++++++ tests/notification/submit_post_type_quote_test.php | 180 +++++++++++++++++++++ 4 files changed, 454 insertions(+), 176 deletions(-) delete mode 100644 tests/notification/submit_post_notifications_test.php create mode 100644 tests/notification/submit_post_type_post_test.php create mode 100644 tests/notification/submit_post_type_quote_test.php (limited to 'tests') diff --git a/tests/notification/fixtures/submit_post_notification.xml b/tests/notification/fixtures/submit_post_notification.xml index c082402056..5c59edf073 100644 --- a/tests/notification/fixtures/submit_post_notification.xml +++ b/tests/notification/fixtures/submit_post_notification.xml @@ -33,6 +33,13 @@ 1 + + quote + 5 + 1 + 1 + + post 8 @@ -73,6 +80,62 @@ 0 + + user_id + username_clean + user_permissions + user_sig + user_occ + user_interests + + 2 + poster + + + + + + + 3 + test + + + + + + + 4 + unauthorized + + + + + + + 5 + notified + + + + + + + 6 + disabled + + + + + + + 7 + default + + + + + +
item_typeitem_id @@ -86,6 +149,13 @@ 1 + + quote + 0 + 2 + + 1 + post 0 @@ -93,6 +163,13 @@ 1 + + quote + 0 + 3 + + 1 + post 0 @@ -100,6 +177,13 @@ 1 + + quote + 0 + 4 + + 1 + post 0 @@ -107,6 +191,13 @@ 1 + + quote + 0 + 5 + + 1 + post 0 @@ -114,6 +205,13 @@ 1 + + quote + 0 + 6 + + 0 + post 0 diff --git a/tests/notification/submit_post_notifications_test.php b/tests/notification/submit_post_notifications_test.php deleted file mode 100644 index 6b61624481..0000000000 --- a/tests/notification/submit_post_notifications_test.php +++ /dev/null @@ -1,176 +0,0 @@ -createXMLDataSet(dirname(__FILE__) . '/fixtures/submit_post_notification.xml'); - } - - public function setUp() - { - parent::setUp(); - - global $auth, $cache, $config, $db, $phpbb_container, $phpbb_dispatcher, $user, $request, $phpEx, $phpbb_root_path; - - // Database - $this->db = $this->new_dbal(); - $db = $this->db; - - // Cache - $cache = new phpbb_mock_cache(); - - // Auth - $auth = $this->getMock('phpbb_auth'); - $auth->expects($this->any()) - ->method('acl_get') - ->with($this->stringContains('_'), - $this->anything()) - ->will($this->returnValueMap(array( - array('f_noapprove', 1, true), - array('f_postcount', 1, true), - array('m_edit', 1, false), - ))); - - $auth->expects($this->any()) - ->method('acl_get_list') - ->with($this->anything(), - $this->stringContains('_'), - $this->greaterThan(0)) - ->will($this->returnValueMap(array( - array( - array('3', '4', '5', '6', '7', '8'), - 'f_read', - 1, - array( - 1 => array( - 'f_read' => array(3, 5, 6, 7, 8), - ), - ), - ), - ))); - - // Config - $config = new phpbb_config(array('num_topics' => 1,'num_posts' => 1,)); - set_config(null, null, null, $config); - set_config_count(null, null, null, $config); - - // Event dispatcher - $phpbb_dispatcher = new phpbb_mock_event_dispatcher(); - - // User - $user = $this->getMock('phpbb_user'); - $user->ip = ''; - $user->data = array( - 'user_id' => 2, - 'username' => 'user-name', - 'is_registered' => true, - 'user_colour' => '', - ); - - // Request - $type_cast_helper = $this->getMock('phpbb_request_type_cast_helper_interface'); - $request = $this->getMock('phpbb_request'); - - // Container - $phpbb_container = new phpbb_mock_container_builder(); - - $user_loader = new phpbb_user_loader($db, $phpbb_root_path, '.' . $phpEx, USERS_TABLE); - - // Notification Manager - $phpbb_notifications = new phpbb_notification_manager(array(), array(), - $phpbb_container, $user_loader, $db, $user, - $phpbb_root_path, '.' . $phpEx, - NOTIFICATION_TYPES_TABLE, NOTIFICATIONS_TABLE, USER_NOTIFICATIONS_TABLE); - $phpbb_container->set('notification_manager', $phpbb_notifications); - - // Notification Types - $notification_types = array('quote', 'bookmark', 'post'); - foreach ($notification_types as $type) - { - $class_name = 'phpbb_notification_type_' . $type; - $phpbb_container->set('notification.type.' . $type, new $class_name( - $user_loader, $db, $cache, $user, $auth, $config, - $phpbb_root_path, '.' . $phpEx, - NOTIFICATION_TYPES_TABLE, NOTIFICATIONS_TABLE, USER_NOTIFICATIONS_TABLE)); - } - } - - /** - * submit_post() Notifications test - * - * submit_post() $mode = 'reply' - * Notification item_type = 'post' - * - * User => State description - * 2 => Poster, should NOT receive a notification - * 3 => Topic subscribed, should receive a notification - * 4 => Topic subscribed, but unauthed to read, should NOT receive a notification - * 5 => Topic subscribed, but already notified, should NOT receive a new notification - * 6 => Topic and forum subscribed, should receive ONE notification - * 7 => Forum subscribed, should receive a notification - * 8 => Forum subscribed, but already notified, should NOT receive a new notification - */ - public function test_type_post() - { - $sql = 'SELECT user_id, item_id, item_parent_id - FROM ' . NOTIFICATIONS_TABLE . " - WHERE item_type = 'post' - ORDER BY user_id, item_id ASC"; - $result = $this->db->sql_query($sql); - $this->assertEquals(array( - array('user_id' => 5, 'item_id' => 1, 'item_parent_id' => 1), - array('user_id' => 8, 'item_id' => 1, 'item_parent_id' => 1), - ), $this->db->sql_fetchrowset($result)); - $this->db->sql_freeresult($result); - - $poll = array(); - $data = array( - 'forum_id' => 1, - 'topic_id' => 1, - 'topic_title' => 'topic_title', - 'icon_id' => 0, - 'enable_bbcode' => 0, - 'enable_smilies' => 0, - 'enable_urls' => 0, - 'enable_sig' => 0, - 'message' => '', - 'message_md5' => '', - 'attachment_data' => array(), - 'bbcode_bitfield' => '', - 'bbcode_uid' => '', - 'post_edit_locked' => false, - //'force_approved_state' => 1, - ); - - submit_post('reply', '', 'poster-name', POST_NORMAL, $poll, $data, false, false); - - $sql = 'SELECT user_id, item_id, item_parent_id - FROM ' . NOTIFICATIONS_TABLE . " - WHERE item_type = 'post' - ORDER BY user_id ASC, item_id ASC"; - $result = $this->db->sql_query($sql); - $this->assertEquals(array( - array('user_id' => 3, 'item_id' => 1, 'item_parent_id' => 1), - array('user_id' => 5, 'item_id' => 1, 'item_parent_id' => 1), - array('user_id' => 6, 'item_id' => 1, 'item_parent_id' => 1), - array('user_id' => 7, 'item_id' => 1, 'item_parent_id' => 1), - array('user_id' => 8, 'item_id' => 1, 'item_parent_id' => 1), - ), $this->db->sql_fetchrowset($result)); - $this->db->sql_freeresult($result); - } -} diff --git a/tests/notification/submit_post_type_post_test.php b/tests/notification/submit_post_type_post_test.php new file mode 100644 index 0000000000..b1e4b86b15 --- /dev/null +++ b/tests/notification/submit_post_type_post_test.php @@ -0,0 +1,176 @@ +createXMLDataSet(dirname(__FILE__) . '/fixtures/submit_post_notification.xml'); + } + + public function setUp() + { + parent::setUp(); + + global $auth, $cache, $config, $db, $phpbb_container, $phpbb_dispatcher, $user, $request, $phpEx, $phpbb_root_path; + + // Database + $this->db = $this->new_dbal(); + $db = $this->db; + + // Cache + $cache = new phpbb_mock_cache(); + + // Auth + $auth = $this->getMock('phpbb_auth'); + $auth->expects($this->any()) + ->method('acl_get') + ->with($this->stringContains('_'), + $this->anything()) + ->will($this->returnValueMap(array( + array('f_noapprove', 1, true), + array('f_postcount', 1, true), + array('m_edit', 1, false), + ))); + + $auth->expects($this->any()) + ->method('acl_get_list') + ->with($this->anything(), + $this->stringContains('_'), + $this->greaterThan(0)) + ->will($this->returnValueMap(array( + array( + array('3', '4', '5', '6', '7', '8'), + 'f_read', + 1, + array( + 1 => array( + 'f_read' => array(3, 5, 6, 7, 8), + ), + ), + ), + ))); + + // Config + $config = new phpbb_config(array('num_topics' => 1,'num_posts' => 1,)); + set_config(null, null, null, $config); + set_config_count(null, null, null, $config); + + // Event dispatcher + $phpbb_dispatcher = new phpbb_mock_event_dispatcher(); + + // User + $user = $this->getMock('phpbb_user'); + $user->ip = ''; + $user->data = array( + 'user_id' => 2, + 'username' => 'user-name', + 'is_registered' => true, + 'user_colour' => '', + ); + + // Request + $type_cast_helper = $this->getMock('phpbb_request_type_cast_helper_interface'); + $request = $this->getMock('phpbb_request'); + + // Container + $phpbb_container = new phpbb_mock_container_builder(); + + $user_loader = new phpbb_user_loader($db, $phpbb_root_path, '.' . $phpEx, USERS_TABLE); + + // Notification Manager + $phpbb_notifications = new phpbb_notification_manager(array(), array(), + $phpbb_container, $user_loader, $db, $user, + $phpbb_root_path, '.' . $phpEx, + NOTIFICATION_TYPES_TABLE, NOTIFICATIONS_TABLE, USER_NOTIFICATIONS_TABLE); + $phpbb_container->set('notification_manager', $phpbb_notifications); + + // Notification Types + $notification_types = array('quote', 'bookmark', 'post'); + foreach ($notification_types as $type) + { + $class_name = 'phpbb_notification_type_' . $type; + $phpbb_container->set('notification.type.' . $type, new $class_name( + $user_loader, $db, $cache, $user, $auth, $config, + $phpbb_root_path, '.' . $phpEx, + NOTIFICATION_TYPES_TABLE, NOTIFICATIONS_TABLE, USER_NOTIFICATIONS_TABLE)); + } + } + + /** + * submit_post() Notifications test + * + * submit_post() $mode = 'reply' + * Notification item_type = 'post' + * + * User => State description + * 2 => Poster, should NOT receive a notification + * 3 => Topic subscribed, should receive a notification + * 4 => Topic subscribed, but unauthed to read, should NOT receive a notification + * 5 => Topic subscribed, but already notified, should NOT receive a new notification + * 6 => Topic and forum subscribed, should receive ONE notification + * 7 => Forum subscribed, should receive a notification + * 8 => Forum subscribed, but already notified, should NOT receive a new notification + */ + public function test_type_post() + { + $sql = 'SELECT user_id, item_id, item_parent_id + FROM ' . NOTIFICATIONS_TABLE . " + WHERE item_type = 'post' + ORDER BY user_id, item_id ASC"; + $result = $this->db->sql_query($sql); + $this->assertEquals(array( + array('user_id' => 5, 'item_id' => 1, 'item_parent_id' => 1), + array('user_id' => 8, 'item_id' => 1, 'item_parent_id' => 1), + ), $this->db->sql_fetchrowset($result)); + $this->db->sql_freeresult($result); + + $poll = array(); + $data = array( + 'forum_id' => 1, + 'topic_id' => 1, + 'topic_title' => 'topic_title', + 'icon_id' => 0, + 'enable_bbcode' => 0, + 'enable_smilies' => 0, + 'enable_urls' => 0, + 'enable_sig' => 0, + 'message' => '', + 'message_md5' => '', + 'attachment_data' => array(), + 'bbcode_bitfield' => '', + 'bbcode_uid' => '', + 'post_edit_locked' => false, + //'force_approved_state' => 1, + ); + + submit_post('reply', '', 'poster-name', POST_NORMAL, $poll, $data, false, false); + + $sql = 'SELECT user_id, item_id, item_parent_id + FROM ' . NOTIFICATIONS_TABLE . " + WHERE item_type = 'post' + ORDER BY user_id ASC, item_id ASC"; + $result = $this->db->sql_query($sql); + $this->assertEquals(array( + array('user_id' => 3, 'item_id' => 1, 'item_parent_id' => 1), + array('user_id' => 5, 'item_id' => 1, 'item_parent_id' => 1), + array('user_id' => 6, 'item_id' => 1, 'item_parent_id' => 1), + array('user_id' => 7, 'item_id' => 1, 'item_parent_id' => 1), + array('user_id' => 8, 'item_id' => 1, 'item_parent_id' => 1), + ), $this->db->sql_fetchrowset($result)); + $this->db->sql_freeresult($result); + } +} diff --git a/tests/notification/submit_post_type_quote_test.php b/tests/notification/submit_post_type_quote_test.php new file mode 100644 index 0000000000..82f4eaf189 --- /dev/null +++ b/tests/notification/submit_post_type_quote_test.php @@ -0,0 +1,180 @@ +createXMLDataSet(dirname(__FILE__) . '/fixtures/submit_post_notification.xml'); + } + + public function setUp() + { + parent::setUp(); + + global $auth, $cache, $config, $db, $phpbb_container, $phpbb_dispatcher, $user, $request, $phpEx, $phpbb_root_path; + + // Database + $this->db = $this->new_dbal(); + $db = $this->db; + + // Cache + $cache = new phpbb_mock_cache(); + + // Auth + $auth = $this->getMock('phpbb_auth'); + $auth->expects($this->any()) + ->method('acl_get') + ->with($this->stringContains('_'), + $this->anything()) + ->will($this->returnValueMap(array( + array('f_noapprove', 1, true), + array('f_postcount', 1, true), + array('m_edit', 1, false), + ))); + + $auth->expects($this->any()) + ->method('acl_get_list') + ->with($this->anything(), + $this->stringContains('_'), + $this->greaterThan(0)) + ->will($this->returnValueMap(array( + array( + array('3', '4', '5', '6', '7'), + 'f_read', + 1, + array( + 1 => array( + 'f_read' => array(3, 5, 6, 7), + ), + ), + ), + ))); + + // Config + $config = new phpbb_config(array('num_topics' => 1,'num_posts' => 1,)); + set_config(null, null, null, $config); + set_config_count(null, null, null, $config); + + // Event dispatcher + $phpbb_dispatcher = new phpbb_mock_event_dispatcher(); + + // User + $user = $this->getMock('phpbb_user'); + $user->ip = ''; + $user->data = array( + 'user_id' => 2, + 'username' => 'user-name', + 'is_registered' => true, + 'user_colour' => '', + ); + + // Request + $type_cast_helper = $this->getMock('phpbb_request_type_cast_helper_interface'); + $request = $this->getMock('phpbb_request'); + + // Container + $phpbb_container = new phpbb_mock_container_builder(); + + $user_loader = new phpbb_user_loader($db, $phpbb_root_path, '.' . $phpEx, USERS_TABLE); + + // Notification Manager + $phpbb_notifications = new phpbb_notification_manager(array(), array(), + $phpbb_container, $user_loader, $db, $user, + $phpbb_root_path, '.' . $phpEx, + NOTIFICATION_TYPES_TABLE, NOTIFICATIONS_TABLE, USER_NOTIFICATIONS_TABLE); + $phpbb_container->set('notification_manager', $phpbb_notifications); + + // Notification Types + $notification_types = array('quote', 'bookmark', 'post'); + foreach ($notification_types as $type) + { + $class_name = 'phpbb_notification_type_' . $type; + $phpbb_container->set('notification.type.' . $type, new $class_name( + $user_loader, $db, $cache, $user, $auth, $config, + $phpbb_root_path, '.' . $phpEx, + NOTIFICATION_TYPES_TABLE, NOTIFICATIONS_TABLE, USER_NOTIFICATIONS_TABLE)); + } + } + + /** + * submit_post() Notifications test + * + * submit_post() $mode = 'reply' + * Notification item_type = 'quote' + * + * User => State description + * 2 => Poster, should NOT receive a notification + * 3 => Quoted, should receive a notification + * 4 => Quoted, but unauthed to read, should NOT receive a notification + * 5 => Quoted, but already notified, should NOT receive a new notification + * 6 => Quoted, but option disabled, should NOT receive a notification + * 7 => Quoted, option set to default, should receive a notification + */ + public function test_type_quote() + { + $sql = 'SELECT user_id, item_id, item_parent_id + FROM ' . NOTIFICATIONS_TABLE . " + WHERE item_type = 'quote' + ORDER BY user_id, item_id ASC"; + $result = $this->db->sql_query($sql); + $this->assertEquals(array( + array('user_id' => 5, 'item_id' => 1, 'item_parent_id' => 1), + ), $this->db->sql_fetchrowset($result)); + $this->db->sql_freeresult($result); + + $poll = array(); + $data = array( + 'forum_id' => 1, + 'topic_id' => 1, + 'topic_title' => 'topic_title', + 'icon_id' => 0, + 'enable_bbcode' => 0, + 'enable_smilies' => 0, + 'enable_urls' => 0, + 'enable_sig' => 0, + 'message' => implode(' ', array( + '[quote="poster":uid]poster should not be notified[/quote:uid]', + '[quote="test":uid]test should be notified[/quote:uid]', + '[quote="unauthorized":uid]unauthorized to read, should not receive a notification[/quote:uid]', + '[quote="notified":uid]already notified, should not receive a new notification[/quote:uid]', + '[quote="disabled":uid]option disabled, should not receive a notification[/quote:uid]', + '[quote="default":uid]option set to default, should receive a notification[/quote:uid]', + '[quote="doesn\'t exist":uid]user does not exist, should not receive a notification[/quote:uid]', + )), + 'message_md5' => '', + 'attachment_data' => array(), + 'bbcode_bitfield' => '', + 'bbcode_uid' => 'uid', + 'post_edit_locked' => false, + //'force_approved_state' => 1, + ); + + submit_post('reply', '', 'poster-name', POST_NORMAL, $poll, $data, false, false); + + $sql = 'SELECT user_id, item_id, item_parent_id + FROM ' . NOTIFICATIONS_TABLE . " + WHERE item_type = 'quote' + ORDER BY user_id ASC, item_id ASC"; + $result = $this->db->sql_query($sql); + $this->assertEquals(array( + array('user_id' => 3, 'item_id' => 1, 'item_parent_id' => 1), + array('user_id' => 5, 'item_id' => 1, 'item_parent_id' => 1), + array('user_id' => 7, 'item_id' => 1, 'item_parent_id' => 1), + ), $this->db->sql_fetchrowset($result)); + $this->db->sql_freeresult($result); + } +} -- cgit v1.2.1 From 060876e627db127c72a953d37e83f5176a085e5d Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Mon, 25 Mar 2013 15:16:29 +0100 Subject: [ticket/11405] Add a base class to avoid duplicated setUp() code PHPBB3-11405 --- tests/notification/submit_post_base.php | 94 ++++++++++++++++++++++ tests/notification/submit_post_type_post_test.php | 81 +------------------ tests/notification/submit_post_type_quote_test.php | 81 +------------------ 3 files changed, 102 insertions(+), 154 deletions(-) create mode 100644 tests/notification/submit_post_base.php (limited to 'tests') diff --git a/tests/notification/submit_post_base.php b/tests/notification/submit_post_base.php new file mode 100644 index 0000000000..60d0e798cb --- /dev/null +++ b/tests/notification/submit_post_base.php @@ -0,0 +1,94 @@ +createXMLDataSet(dirname(__FILE__) . '/fixtures/submit_post_notification.xml'); + } + + public function setUp() + { + parent::setUp(); + + global $auth, $cache, $config, $db, $phpbb_container, $phpbb_dispatcher, $user, $request, $phpEx, $phpbb_root_path; + + // Database + $this->db = $this->new_dbal(); + $db = $this->db; + + // Cache + $cache = new phpbb_mock_cache(); + + // Auth + $auth = $this->getMock('phpbb_auth'); + $auth->expects($this->any()) + ->method('acl_get') + ->with($this->stringContains('_'), + $this->anything()) + ->will($this->returnValueMap(array( + array('f_noapprove', 1, true), + array('f_postcount', 1, true), + array('m_edit', 1, false), + ))); + + // Config + $config = new phpbb_config(array('num_topics' => 1,'num_posts' => 1,)); + set_config(null, null, null, $config); + set_config_count(null, null, null, $config); + + // Event dispatcher + $phpbb_dispatcher = new phpbb_mock_event_dispatcher(); + + // User + $user = $this->getMock('phpbb_user'); + $user->ip = ''; + $user->data = array( + 'user_id' => 2, + 'username' => 'user-name', + 'is_registered' => true, + 'user_colour' => '', + ); + + // Request + $type_cast_helper = $this->getMock('phpbb_request_type_cast_helper_interface'); + $request = $this->getMock('phpbb_request'); + + // Container + $phpbb_container = new phpbb_mock_container_builder(); + + $user_loader = new phpbb_user_loader($db, $phpbb_root_path, '.' . $phpEx, USERS_TABLE); + + // Notification Manager + $phpbb_notifications = new phpbb_notification_manager(array(), array(), + $phpbb_container, $user_loader, $db, $user, + $phpbb_root_path, '.' . $phpEx, + NOTIFICATION_TYPES_TABLE, NOTIFICATIONS_TABLE, USER_NOTIFICATIONS_TABLE); + $phpbb_container->set('notification_manager', $phpbb_notifications); + + // Notification Types + $notification_types = array('quote', 'bookmark', 'post'); + foreach ($notification_types as $type) + { + $class_name = 'phpbb_notification_type_' . $type; + $phpbb_container->set('notification.type.' . $type, new $class_name( + $user_loader, $db, $cache, $user, $auth, $config, + $phpbb_root_path, '.' . $phpEx, + NOTIFICATION_TYPES_TABLE, NOTIFICATIONS_TABLE, USER_NOTIFICATIONS_TABLE)); + } + } +} diff --git a/tests/notification/submit_post_type_post_test.php b/tests/notification/submit_post_type_post_test.php index b1e4b86b15..2e269ff080 100644 --- a/tests/notification/submit_post_type_post_test.php +++ b/tests/notification/submit_post_type_post_test.php @@ -7,45 +7,17 @@ * */ -require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php'; -require_once dirname(__FILE__) . '/../../phpBB/includes/functions_content.php'; -require_once dirname(__FILE__) . '/../../phpBB/includes/functions_posting.php'; -require_once dirname(__FILE__) . '/../../phpBB/includes/utf/utf_tools.php'; +require_once dirname(__FILE__) . '/submit_post_base.php'; -class phpbb_notification_submit_post_type_post_test extends phpbb_database_test_case +class phpbb_notification_submit_post_type_post_test extends phpbb_notification_submit_post_base { - protected $notifications, $db, $container, $user, $config, $auth, $cache; - - public function getDataSet() - { - return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/submit_post_notification.xml'); - } - public function setUp() { parent::setUp(); - global $auth, $cache, $config, $db, $phpbb_container, $phpbb_dispatcher, $user, $request, $phpEx, $phpbb_root_path; - - // Database - $this->db = $this->new_dbal(); - $db = $this->db; - - // Cache - $cache = new phpbb_mock_cache(); - - // Auth - $auth = $this->getMock('phpbb_auth'); - $auth->expects($this->any()) - ->method('acl_get') - ->with($this->stringContains('_'), - $this->anything()) - ->will($this->returnValueMap(array( - array('f_noapprove', 1, true), - array('f_postcount', 1, true), - array('m_edit', 1, false), - ))); + global $auth; + // Add additional permissions $auth->expects($this->any()) ->method('acl_get_list') ->with($this->anything(), @@ -63,51 +35,6 @@ class phpbb_notification_submit_post_type_post_test extends phpbb_database_test_ ), ), ))); - - // Config - $config = new phpbb_config(array('num_topics' => 1,'num_posts' => 1,)); - set_config(null, null, null, $config); - set_config_count(null, null, null, $config); - - // Event dispatcher - $phpbb_dispatcher = new phpbb_mock_event_dispatcher(); - - // User - $user = $this->getMock('phpbb_user'); - $user->ip = ''; - $user->data = array( - 'user_id' => 2, - 'username' => 'user-name', - 'is_registered' => true, - 'user_colour' => '', - ); - - // Request - $type_cast_helper = $this->getMock('phpbb_request_type_cast_helper_interface'); - $request = $this->getMock('phpbb_request'); - - // Container - $phpbb_container = new phpbb_mock_container_builder(); - - $user_loader = new phpbb_user_loader($db, $phpbb_root_path, '.' . $phpEx, USERS_TABLE); - - // Notification Manager - $phpbb_notifications = new phpbb_notification_manager(array(), array(), - $phpbb_container, $user_loader, $db, $user, - $phpbb_root_path, '.' . $phpEx, - NOTIFICATION_TYPES_TABLE, NOTIFICATIONS_TABLE, USER_NOTIFICATIONS_TABLE); - $phpbb_container->set('notification_manager', $phpbb_notifications); - - // Notification Types - $notification_types = array('quote', 'bookmark', 'post'); - foreach ($notification_types as $type) - { - $class_name = 'phpbb_notification_type_' . $type; - $phpbb_container->set('notification.type.' . $type, new $class_name( - $user_loader, $db, $cache, $user, $auth, $config, - $phpbb_root_path, '.' . $phpEx, - NOTIFICATION_TYPES_TABLE, NOTIFICATIONS_TABLE, USER_NOTIFICATIONS_TABLE)); - } } /** diff --git a/tests/notification/submit_post_type_quote_test.php b/tests/notification/submit_post_type_quote_test.php index 82f4eaf189..603f7b2020 100644 --- a/tests/notification/submit_post_type_quote_test.php +++ b/tests/notification/submit_post_type_quote_test.php @@ -7,45 +7,17 @@ * */ -require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php'; -require_once dirname(__FILE__) . '/../../phpBB/includes/functions_content.php'; -require_once dirname(__FILE__) . '/../../phpBB/includes/functions_posting.php'; -require_once dirname(__FILE__) . '/../../phpBB/includes/utf/utf_tools.php'; +require_once dirname(__FILE__) . '/submit_post_base.php'; -class phpbb_notification_submit_post_type_quote_test extends phpbb_database_test_case +class phpbb_notification_submit_post_type_quote_test extends phpbb_notification_submit_post_base { - protected $notifications, $db, $container, $user, $config, $auth, $cache; - - public function getDataSet() - { - return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/submit_post_notification.xml'); - } - public function setUp() { parent::setUp(); - global $auth, $cache, $config, $db, $phpbb_container, $phpbb_dispatcher, $user, $request, $phpEx, $phpbb_root_path; - - // Database - $this->db = $this->new_dbal(); - $db = $this->db; - - // Cache - $cache = new phpbb_mock_cache(); - - // Auth - $auth = $this->getMock('phpbb_auth'); - $auth->expects($this->any()) - ->method('acl_get') - ->with($this->stringContains('_'), - $this->anything()) - ->will($this->returnValueMap(array( - array('f_noapprove', 1, true), - array('f_postcount', 1, true), - array('m_edit', 1, false), - ))); + global $auth; + // Add additional permissions $auth->expects($this->any()) ->method('acl_get_list') ->with($this->anything(), @@ -63,51 +35,6 @@ class phpbb_notification_submit_post_type_quote_test extends phpbb_database_test ), ), ))); - - // Config - $config = new phpbb_config(array('num_topics' => 1,'num_posts' => 1,)); - set_config(null, null, null, $config); - set_config_count(null, null, null, $config); - - // Event dispatcher - $phpbb_dispatcher = new phpbb_mock_event_dispatcher(); - - // User - $user = $this->getMock('phpbb_user'); - $user->ip = ''; - $user->data = array( - 'user_id' => 2, - 'username' => 'user-name', - 'is_registered' => true, - 'user_colour' => '', - ); - - // Request - $type_cast_helper = $this->getMock('phpbb_request_type_cast_helper_interface'); - $request = $this->getMock('phpbb_request'); - - // Container - $phpbb_container = new phpbb_mock_container_builder(); - - $user_loader = new phpbb_user_loader($db, $phpbb_root_path, '.' . $phpEx, USERS_TABLE); - - // Notification Manager - $phpbb_notifications = new phpbb_notification_manager(array(), array(), - $phpbb_container, $user_loader, $db, $user, - $phpbb_root_path, '.' . $phpEx, - NOTIFICATION_TYPES_TABLE, NOTIFICATIONS_TABLE, USER_NOTIFICATIONS_TABLE); - $phpbb_container->set('notification_manager', $phpbb_notifications); - - // Notification Types - $notification_types = array('quote', 'bookmark', 'post'); - foreach ($notification_types as $type) - { - $class_name = 'phpbb_notification_type_' . $type; - $phpbb_container->set('notification.type.' . $type, new $class_name( - $user_loader, $db, $cache, $user, $auth, $config, - $phpbb_root_path, '.' . $phpEx, - NOTIFICATION_TYPES_TABLE, NOTIFICATIONS_TABLE, USER_NOTIFICATIONS_TABLE)); - } } /** -- cgit v1.2.1 From 053c75543de4c8e5d787a2e344b837f867842f8d Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Mon, 25 Mar 2013 15:34:18 +0100 Subject: [ticket/11405] Correctly prefill the tables (missed the posts and not-types) PHPBB3-11405 --- .../fixtures/submit_post_notification.xml | 34 ++++++++++++++++++++++ tests/notification/submit_post_type_post_test.php | 6 ++-- tests/notification/submit_post_type_quote_test.php | 4 +-- 3 files changed, 39 insertions(+), 5 deletions(-) (limited to 'tests') diff --git a/tests/notification/fixtures/submit_post_notification.xml b/tests/notification/fixtures/submit_post_notification.xml index 5c59edf073..51dd2f8dbd 100644 --- a/tests/notification/fixtures/submit_post_notification.xml +++ b/tests/notification/fixtures/submit_post_notification.xml @@ -25,12 +25,14 @@ user_id item_id item_parent_id + notification_read notification_data post 5 1 1 + 0 @@ -38,6 +40,7 @@ 5 1 1 + 0 @@ -45,10 +48,41 @@ 8 1 1 + 0
+ + notification_type + notification_type_enabled + + post + 1 + + + quote + 1 + +
+ post_id + topic_id + forum_id + post_text + + 1 + 1 + 1 + + +
+ + topic_id + forum_id + + 1 + 1 +
topic_id diff --git a/tests/notification/submit_post_type_post_test.php b/tests/notification/submit_post_type_post_test.php index 2e269ff080..f439c49167 100644 --- a/tests/notification/submit_post_type_post_test.php +++ b/tests/notification/submit_post_type_post_test.php @@ -92,10 +92,10 @@ class phpbb_notification_submit_post_type_post_test extends phpbb_notification_s ORDER BY user_id ASC, item_id ASC"; $result = $this->db->sql_query($sql); $this->assertEquals(array( - array('user_id' => 3, 'item_id' => 1, 'item_parent_id' => 1), + array('user_id' => 3, 'item_id' => 2, 'item_parent_id' => 1), array('user_id' => 5, 'item_id' => 1, 'item_parent_id' => 1), - array('user_id' => 6, 'item_id' => 1, 'item_parent_id' => 1), - array('user_id' => 7, 'item_id' => 1, 'item_parent_id' => 1), + array('user_id' => 6, 'item_id' => 2, 'item_parent_id' => 1), + array('user_id' => 7, 'item_id' => 2, 'item_parent_id' => 1), array('user_id' => 8, 'item_id' => 1, 'item_parent_id' => 1), ), $this->db->sql_fetchrowset($result)); $this->db->sql_freeresult($result); diff --git a/tests/notification/submit_post_type_quote_test.php b/tests/notification/submit_post_type_quote_test.php index 603f7b2020..9b2323f770 100644 --- a/tests/notification/submit_post_type_quote_test.php +++ b/tests/notification/submit_post_type_quote_test.php @@ -98,9 +98,9 @@ class phpbb_notification_submit_post_type_quote_test extends phpbb_notification_ ORDER BY user_id ASC, item_id ASC"; $result = $this->db->sql_query($sql); $this->assertEquals(array( - array('user_id' => 3, 'item_id' => 1, 'item_parent_id' => 1), + array('user_id' => 3, 'item_id' => 2, 'item_parent_id' => 1), array('user_id' => 5, 'item_id' => 1, 'item_parent_id' => 1), - array('user_id' => 7, 'item_id' => 1, 'item_parent_id' => 1), + array('user_id' => 7, 'item_id' => 2, 'item_parent_id' => 1), ), $this->db->sql_fetchrowset($result)); $this->db->sql_freeresult($result); } -- cgit v1.2.1 From cdd45cb8ba4d420bfc44a9bb7a4c43662ec78156 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 26 Mar 2013 12:58:14 +0100 Subject: [ticket/11405] Move test to submit_post_base.php and use data sets for testing PHPBB3-11405 --- tests/notification/submit_post_base.php | 47 +++++++- tests/notification/submit_post_type_post_test.php | 99 ++++++++--------- tests/notification/submit_post_type_quote_test.php | 120 +++++++++++---------- 3 files changed, 155 insertions(+), 111 deletions(-) (limited to 'tests') diff --git a/tests/notification/submit_post_base.php b/tests/notification/submit_post_base.php index 60d0e798cb..f458a4896a 100644 --- a/tests/notification/submit_post_base.php +++ b/tests/notification/submit_post_base.php @@ -16,6 +16,27 @@ class phpbb_notification_submit_post_base extends phpbb_database_test_case { protected $notifications, $db, $container, $user, $config, $auth, $cache; + protected $item_type = ''; + + protected $poll_data = array(); + protected $post_data = array( + 'forum_id' => 1, + 'topic_id' => 1, + 'topic_title' => 'topic_title', + 'icon_id' => 0, + 'enable_bbcode' => 0, + 'enable_smilies' => 0, + 'enable_urls' => 0, + 'enable_sig' => 0, + 'message' => '', + 'message_md5' => '', + 'attachment_data' => array(), + 'bbcode_bitfield' => '', + 'bbcode_uid' => '', + 'post_edit_locked' => false, + //'force_approved_state' => 1, + ); + public function getDataSet() { return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/submit_post_notification.xml'); @@ -81,7 +102,7 @@ class phpbb_notification_submit_post_base extends phpbb_database_test_case $phpbb_container->set('notification_manager', $phpbb_notifications); // Notification Types - $notification_types = array('quote', 'bookmark', 'post'); + $notification_types = array('quote', 'bookmark', 'post', 'post_in_queue'); foreach ($notification_types as $type) { $class_name = 'phpbb_notification_type_' . $type; @@ -91,4 +112,28 @@ class phpbb_notification_submit_post_base extends phpbb_database_test_case NOTIFICATION_TYPES_TABLE, NOTIFICATIONS_TABLE, USER_NOTIFICATIONS_TABLE)); } } + + /** + * @dataProvider submit_post_data + */ + public function test_submit_post($additional_post_data, $expected_before, $expected_after) + { + $sql = 'SELECT user_id, item_id, item_parent_id + FROM ' . NOTIFICATIONS_TABLE . " + WHERE item_type = '" . $this->item_type . "' + ORDER BY user_id, item_id ASC"; + $result = $this->db->sql_query($sql); + $this->assertEquals($expected_before, $this->db->sql_fetchrowset($result)); + $this->db->sql_freeresult($result); + + submit_post('reply', '', 'poster-name', POST_NORMAL, $this->poll_data, array_merge($this->post_data, $additional_post_data), false, false); + + $sql = 'SELECT user_id, item_id, item_parent_id + FROM ' . NOTIFICATIONS_TABLE . " + WHERE item_type = '" . $this->item_type . "' + ORDER BY user_id ASC, item_id ASC"; + $result = $this->db->sql_query($sql); + $this->assertEquals($expected_after, $this->db->sql_fetchrowset($result)); + $this->db->sql_freeresult($result); + } } diff --git a/tests/notification/submit_post_type_post_test.php b/tests/notification/submit_post_type_post_test.php index f439c49167..473247a764 100644 --- a/tests/notification/submit_post_type_post_test.php +++ b/tests/notification/submit_post_type_post_test.php @@ -11,6 +11,8 @@ require_once dirname(__FILE__) . '/submit_post_base.php'; class phpbb_notification_submit_post_type_post_test extends phpbb_notification_submit_post_base { + protected $item_type = 'post'; + public function setUp() { parent::setUp(); @@ -42,62 +44,53 @@ class phpbb_notification_submit_post_type_post_test extends phpbb_notification_s * * submit_post() $mode = 'reply' * Notification item_type = 'post' - * - * User => State description - * 2 => Poster, should NOT receive a notification - * 3 => Topic subscribed, should receive a notification - * 4 => Topic subscribed, but unauthed to read, should NOT receive a notification - * 5 => Topic subscribed, but already notified, should NOT receive a new notification - * 6 => Topic and forum subscribed, should receive ONE notification - * 7 => Forum subscribed, should receive a notification - * 8 => Forum subscribed, but already notified, should NOT receive a new notification */ - public function test_type_post() + public function submit_post_data() { - $sql = 'SELECT user_id, item_id, item_parent_id - FROM ' . NOTIFICATIONS_TABLE . " - WHERE item_type = 'post' - ORDER BY user_id, item_id ASC"; - $result = $this->db->sql_query($sql); - $this->assertEquals(array( - array('user_id' => 5, 'item_id' => 1, 'item_parent_id' => 1), - array('user_id' => 8, 'item_id' => 1, 'item_parent_id' => 1), - ), $this->db->sql_fetchrowset($result)); - $this->db->sql_freeresult($result); + return array( + /** + * Normal post + * + * User => State description + * 2 => Poster, should NOT receive a notification + * 3 => Topic subscribed, should receive a notification + * 4 => Topic subscribed, but unauthed to read, should NOT receive a notification + * 5 => Topic subscribed, but already notified, should NOT receive a new notification + * 6 => Topic and forum subscribed, should receive ONE notification + * 7 => Forum subscribed, should receive a notification + * 8 => Forum subscribed, but already notified, should NOT receive a new notification + */ + array( + array(), + array( + array('user_id' => 5, 'item_id' => 1, 'item_parent_id' => 1), + array('user_id' => 8, 'item_id' => 1, 'item_parent_id' => 1), + ), + array( + array('user_id' => 3, 'item_id' => 2, 'item_parent_id' => 1), + array('user_id' => 5, 'item_id' => 1, 'item_parent_id' => 1), + array('user_id' => 6, 'item_id' => 2, 'item_parent_id' => 1), + array('user_id' => 7, 'item_id' => 2, 'item_parent_id' => 1), + array('user_id' => 8, 'item_id' => 1, 'item_parent_id' => 1), + ), + ), - $poll = array(); - $data = array( - 'forum_id' => 1, - 'topic_id' => 1, - 'topic_title' => 'topic_title', - 'icon_id' => 0, - 'enable_bbcode' => 0, - 'enable_smilies' => 0, - 'enable_urls' => 0, - 'enable_sig' => 0, - 'message' => '', - 'message_md5' => '', - 'attachment_data' => array(), - 'bbcode_bitfield' => '', - 'bbcode_uid' => '', - 'post_edit_locked' => false, - //'force_approved_state' => 1, + /** + * Unapproved post + * + * No new notifications + */ + array( + array('force_approved_state' => false), + array( + array('user_id' => 5, 'item_id' => 1, 'item_parent_id' => 1), + array('user_id' => 8, 'item_id' => 1, 'item_parent_id' => 1), + ), + array( + array('user_id' => 5, 'item_id' => 1, 'item_parent_id' => 1), + array('user_id' => 8, 'item_id' => 1, 'item_parent_id' => 1), + ), + ), ); - - submit_post('reply', '', 'poster-name', POST_NORMAL, $poll, $data, false, false); - - $sql = 'SELECT user_id, item_id, item_parent_id - FROM ' . NOTIFICATIONS_TABLE . " - WHERE item_type = 'post' - ORDER BY user_id ASC, item_id ASC"; - $result = $this->db->sql_query($sql); - $this->assertEquals(array( - array('user_id' => 3, 'item_id' => 2, 'item_parent_id' => 1), - array('user_id' => 5, 'item_id' => 1, 'item_parent_id' => 1), - array('user_id' => 6, 'item_id' => 2, 'item_parent_id' => 1), - array('user_id' => 7, 'item_id' => 2, 'item_parent_id' => 1), - array('user_id' => 8, 'item_id' => 1, 'item_parent_id' => 1), - ), $this->db->sql_fetchrowset($result)); - $this->db->sql_freeresult($result); } } diff --git a/tests/notification/submit_post_type_quote_test.php b/tests/notification/submit_post_type_quote_test.php index 9b2323f770..2b66d9c6a1 100644 --- a/tests/notification/submit_post_type_quote_test.php +++ b/tests/notification/submit_post_type_quote_test.php @@ -11,6 +11,8 @@ require_once dirname(__FILE__) . '/submit_post_base.php'; class phpbb_notification_submit_post_type_quote_test extends phpbb_notification_submit_post_base { + protected $item_type = 'quote'; + public function setUp() { parent::setUp(); @@ -42,66 +44,70 @@ class phpbb_notification_submit_post_type_quote_test extends phpbb_notification_ * * submit_post() $mode = 'reply' * Notification item_type = 'quote' - * - * User => State description - * 2 => Poster, should NOT receive a notification - * 3 => Quoted, should receive a notification - * 4 => Quoted, but unauthed to read, should NOT receive a notification - * 5 => Quoted, but already notified, should NOT receive a new notification - * 6 => Quoted, but option disabled, should NOT receive a notification - * 7 => Quoted, option set to default, should receive a notification */ - public function test_type_quote() + public function submit_post_data() { - $sql = 'SELECT user_id, item_id, item_parent_id - FROM ' . NOTIFICATIONS_TABLE . " - WHERE item_type = 'quote' - ORDER BY user_id, item_id ASC"; - $result = $this->db->sql_query($sql); - $this->assertEquals(array( - array('user_id' => 5, 'item_id' => 1, 'item_parent_id' => 1), - ), $this->db->sql_fetchrowset($result)); - $this->db->sql_freeresult($result); + return array( + /** + * Normal post + * + * User => State description + * 2 => Poster, should NOT receive a notification + * 3 => Quoted, should receive a notification + * 4 => Quoted, but unauthed to read, should NOT receive a notification + * 5 => Quoted, but already notified, should NOT receive a new notification + * 6 => Quoted, but option disabled, should NOT receive a notification + * 7 => Quoted, option set to default, should receive a notification + */ + array( + array( + 'message' => implode(' ', array( + '[quote="poster":uid]poster should not be notified[/quote:uid]', + '[quote="test":uid]test should be notified[/quote:uid]', + '[quote="unauthorized":uid]unauthorized to read, should not receive a notification[/quote:uid]', + '[quote="notified":uid]already notified, should not receive a new notification[/quote:uid]', + '[quote="disabled":uid]option disabled, should not receive a notification[/quote:uid]', + '[quote="default":uid]option set to default, should receive a notification[/quote:uid]', + '[quote="doesn\'t exist":uid]user does not exist, should not receive a notification[/quote:uid]', + )), + 'bbcode_uid' => 'uid', + ), + array( + array('user_id' => 5, 'item_id' => 1, 'item_parent_id' => 1), + ), + array( + array('user_id' => 3, 'item_id' => 2, 'item_parent_id' => 1), + array('user_id' => 5, 'item_id' => 1, 'item_parent_id' => 1), + array('user_id' => 7, 'item_id' => 2, 'item_parent_id' => 1), + ), + ), - $poll = array(); - $data = array( - 'forum_id' => 1, - 'topic_id' => 1, - 'topic_title' => 'topic_title', - 'icon_id' => 0, - 'enable_bbcode' => 0, - 'enable_smilies' => 0, - 'enable_urls' => 0, - 'enable_sig' => 0, - 'message' => implode(' ', array( - '[quote="poster":uid]poster should not be notified[/quote:uid]', - '[quote="test":uid]test should be notified[/quote:uid]', - '[quote="unauthorized":uid]unauthorized to read, should not receive a notification[/quote:uid]', - '[quote="notified":uid]already notified, should not receive a new notification[/quote:uid]', - '[quote="disabled":uid]option disabled, should not receive a notification[/quote:uid]', - '[quote="default":uid]option set to default, should receive a notification[/quote:uid]', - '[quote="doesn\'t exist":uid]user does not exist, should not receive a notification[/quote:uid]', - )), - 'message_md5' => '', - 'attachment_data' => array(), - 'bbcode_bitfield' => '', - 'bbcode_uid' => 'uid', - 'post_edit_locked' => false, - //'force_approved_state' => 1, + /** + * Unapproved post + * + * No new notifications + */ + array( + array( + 'message' => implode(' ', array( + '[quote="poster":uid]poster should not be notified[/quote:uid]', + '[quote="test":uid]test should be notified[/quote:uid]', + '[quote="unauthorized":uid]unauthorized to read, should not receive a notification[/quote:uid]', + '[quote="notified":uid]already notified, should not receive a new notification[/quote:uid]', + '[quote="disabled":uid]option disabled, should not receive a notification[/quote:uid]', + '[quote="default":uid]option set to default, should receive a notification[/quote:uid]', + '[quote="doesn\'t exist":uid]user does not exist, should not receive a notification[/quote:uid]', + )), + 'bbcode_uid' => 'uid', + 'force_approved_state' => false, + ), + array( + array('user_id' => 5, 'item_id' => 1, 'item_parent_id' => 1), + ), + array( + array('user_id' => 5, 'item_id' => 1, 'item_parent_id' => 1), + ), + ), ); - - submit_post('reply', '', 'poster-name', POST_NORMAL, $poll, $data, false, false); - - $sql = 'SELECT user_id, item_id, item_parent_id - FROM ' . NOTIFICATIONS_TABLE . " - WHERE item_type = 'quote' - ORDER BY user_id ASC, item_id ASC"; - $result = $this->db->sql_query($sql); - $this->assertEquals(array( - array('user_id' => 3, 'item_id' => 2, 'item_parent_id' => 1), - array('user_id' => 5, 'item_id' => 1, 'item_parent_id' => 1), - array('user_id' => 7, 'item_id' => 2, 'item_parent_id' => 1), - ), $this->db->sql_fetchrowset($result)); - $this->db->sql_freeresult($result); } } -- cgit v1.2.1 From 7e2f80ec0ab69c512383602c42b84db1c767180e Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 26 Mar 2013 12:59:35 +0100 Subject: [ticket/11405] Add unit tests for bookmarking PHPBB3-11405 --- .../fixtures/submit_post_notification.xml | 75 ++++++++++++++++++ .../submit_post_type_bookmark_test.php | 90 ++++++++++++++++++++++ 2 files changed, 165 insertions(+) create mode 100644 tests/notification/submit_post_type_bookmark_test.php (limited to 'tests') diff --git a/tests/notification/fixtures/submit_post_notification.xml b/tests/notification/fixtures/submit_post_notification.xml index 51dd2f8dbd..3f46bc2962 100644 --- a/tests/notification/fixtures/submit_post_notification.xml +++ b/tests/notification/fixtures/submit_post_notification.xml @@ -1,5 +1,33 @@ +
+ topic_id + user_id + + 1 + 2 + + + 1 + 3 + + + 1 + 4 + + + 1 + 5 + + + 1 + 6 + + + 1 + 7 + +
forum_iduser_id @@ -43,6 +71,14 @@ 0 + + bookmark + 5 + 1 + 1 + 0 + + post 8 @@ -63,6 +99,10 @@ quote 1 + + bookmark + 1 +
post_id @@ -190,6 +230,13 @@ 1 + + bookmark + 0 + 2 + + 1 + post 0 @@ -204,6 +251,13 @@ 1 + + bookmark + 0 + 3 + + 1 + post 0 @@ -218,6 +272,13 @@ 1 + + bookmark + 0 + 4 + + 1 + post 0 @@ -232,6 +293,13 @@ 1 + + bookmark + 0 + 5 + + 1 + post 0 @@ -246,6 +314,13 @@ 0 + + bookmark + 0 + 6 + + 0 + post 0 diff --git a/tests/notification/submit_post_type_bookmark_test.php b/tests/notification/submit_post_type_bookmark_test.php new file mode 100644 index 0000000000..861017ff5f --- /dev/null +++ b/tests/notification/submit_post_type_bookmark_test.php @@ -0,0 +1,90 @@ +expects($this->any()) + ->method('acl_get_list') + ->with($this->anything(), + $this->stringContains('_'), + $this->greaterThan(0)) + ->will($this->returnValueMap(array( + array( + array('3', '4', '5', '6', '7'), + 'f_read', + 1, + array( + 1 => array( + 'f_read' => array(3, 5, 6, 7), + ), + ), + ), + ))); + } + + /** + * submit_post() Notifications test + * + * submit_post() $mode = 'reply' + * Notification item_type = 'bookmark' + */ + public function submit_post_data() + { + return array( + /** + * Normal post + * + * User => State description + * 2 => Poster, should NOT receive a notification + * 3 => Bookmarked, should receive a notification + * 4 => Bookmarked, but unauthed to read, should NOT receive a notification + * 5 => Bookmarked, but already notified, should NOT receive a new notification + * 6 => Bookmarked, but option disabled, should NOT receive a notification + * 7 => Bookmarked, option set to default, should receive a notification + */ + array( + array(), + array( + array('user_id' => 5, 'item_id' => 1, 'item_parent_id' => 1), + ), + array( + array('user_id' => 3, 'item_id' => 2, 'item_parent_id' => 1), + array('user_id' => 5, 'item_id' => 1, 'item_parent_id' => 1), + array('user_id' => 7, 'item_id' => 2, 'item_parent_id' => 1), + ), + ), + + /** + * Unapproved post + * + * No new notifications + */ + array( + array('force_approved_state' => false), + array( + array('user_id' => 5, 'item_id' => 1, 'item_parent_id' => 1), + ), + array( + array('user_id' => 5, 'item_id' => 1, 'item_parent_id' => 1), + ), + ), + ); + } +} -- cgit v1.2.1 From e20b0a423474eb6f4dce362283ae2ebb3d3e0f8d Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 26 Mar 2013 13:06:04 +0100 Subject: [ticket/11405] Use different fixtures so it's not a total mess PHPBB3-11405 --- .../notification/fixtures/submit_post_bookmark.xml | 173 +++++++++++ .../fixtures/submit_post_notification.xml | 339 --------------------- tests/notification/fixtures/submit_post_post.xml | 217 +++++++++++++ tests/notification/fixtures/submit_post_quote.xml | 145 +++++++++ tests/notification/submit_post_base.php | 2 +- 5 files changed, 536 insertions(+), 340 deletions(-) create mode 100644 tests/notification/fixtures/submit_post_bookmark.xml delete mode 100644 tests/notification/fixtures/submit_post_notification.xml create mode 100644 tests/notification/fixtures/submit_post_post.xml create mode 100644 tests/notification/fixtures/submit_post_quote.xml (limited to 'tests') diff --git a/tests/notification/fixtures/submit_post_bookmark.xml b/tests/notification/fixtures/submit_post_bookmark.xml new file mode 100644 index 0000000000..b669d4c1b6 --- /dev/null +++ b/tests/notification/fixtures/submit_post_bookmark.xml @@ -0,0 +1,173 @@ + + +
+ topic_id + user_id + + 1 + 2 + + + 1 + 3 + + + 1 + 4 + + + 1 + 5 + + + 1 + 6 + + + 1 + 7 + +
+ + item_type + user_id + item_id + item_parent_id + notification_read + notification_data + + bookmark + 5 + 1 + 1 + 0 + + +
+ + notification_type + notification_type_enabled + + bookmark + 1 + +
+ + post_id + topic_id + forum_id + post_text + + 1 + 1 + 1 + + +
+ + topic_id + forum_id + + 1 + 1 + +
+ + user_id + username_clean + user_permissions + user_sig + user_occ + user_interests + + 2 + poster + + + + + + + 3 + test + + + + + + + 4 + unauthorized + + + + + + + 5 + notified + + + + + + + 6 + disabled + + + + + + + 7 + default + + + + + +
+ + item_type + item_id + user_id + method + notify + + bookmark + 0 + 2 + + 1 + + + bookmark + 0 + 3 + + 1 + + + bookmark + 0 + 4 + + 1 + + + bookmark + 0 + 5 + + 1 + + + bookmark + 0 + 6 + + 0 + +
+ diff --git a/tests/notification/fixtures/submit_post_notification.xml b/tests/notification/fixtures/submit_post_notification.xml deleted file mode 100644 index 3f46bc2962..0000000000 --- a/tests/notification/fixtures/submit_post_notification.xml +++ /dev/null @@ -1,339 +0,0 @@ - - - - topic_id - user_id - - 1 - 2 - - - 1 - 3 - - - 1 - 4 - - - 1 - 5 - - - 1 - 6 - - - 1 - 7 - -
- - forum_id - user_id - notify_status - - 1 - 6 - 0 - - - 1 - 7 - 0 - - - 1 - 8 - 0 - -
- - item_type - user_id - item_id - item_parent_id - notification_read - notification_data - - post - 5 - 1 - 1 - 0 - - - - quote - 5 - 1 - 1 - 0 - - - - bookmark - 5 - 1 - 1 - 0 - - - - post - 8 - 1 - 1 - 0 - - -
- - notification_type - notification_type_enabled - - post - 1 - - - quote - 1 - - - bookmark - 1 - -
- - post_id - topic_id - forum_id - post_text - - 1 - 1 - 1 - - -
- - topic_id - forum_id - - 1 - 1 - -
- - topic_id - user_id - notify_status - - 1 - 2 - 0 - - - 1 - 3 - 0 - - - 1 - 4 - 0 - - - 1 - 5 - 0 - - - 1 - 6 - 0 - -
- - user_id - username_clean - user_permissions - user_sig - user_occ - user_interests - - 2 - poster - - - - - - - 3 - test - - - - - - - 4 - unauthorized - - - - - - - 5 - notified - - - - - - - 6 - disabled - - - - - - - 7 - default - - - - - -
- - item_type - item_id - user_id - method - notify - - post - 0 - 2 - - 1 - - - quote - 0 - 2 - - 1 - - - bookmark - 0 - 2 - - 1 - - - post - 0 - 3 - - 1 - - - quote - 0 - 3 - - 1 - - - bookmark - 0 - 3 - - 1 - - - post - 0 - 4 - - 1 - - - quote - 0 - 4 - - 1 - - - bookmark - 0 - 4 - - 1 - - - post - 0 - 5 - - 1 - - - quote - 0 - 5 - - 1 - - - bookmark - 0 - 5 - - 1 - - - post - 0 - 6 - - 1 - - - quote - 0 - 6 - - 0 - - - bookmark - 0 - 6 - - 0 - - - post - 0 - 7 - - 1 - - - post - 0 - 8 - - 1 - -
-
diff --git a/tests/notification/fixtures/submit_post_post.xml b/tests/notification/fixtures/submit_post_post.xml new file mode 100644 index 0000000000..cead4f7c26 --- /dev/null +++ b/tests/notification/fixtures/submit_post_post.xml @@ -0,0 +1,217 @@ + + + + forum_id + user_id + notify_status + + 1 + 6 + 0 + + + 1 + 7 + 0 + + + 1 + 8 + 0 + +
+ + item_type + user_id + item_id + item_parent_id + notification_read + notification_data + + post + 5 + 1 + 1 + 0 + + + + post + 8 + 1 + 1 + 0 + + +
+ + notification_type + notification_type_enabled + + post + 1 + +
+ + post_id + topic_id + forum_id + post_text + + 1 + 1 + 1 + + +
+ + topic_id + forum_id + + 1 + 1 + +
+ + topic_id + user_id + notify_status + + 1 + 2 + 0 + + + 1 + 3 + 0 + + + 1 + 4 + 0 + + + 1 + 5 + 0 + + + 1 + 6 + 0 + +
+ + user_id + username_clean + user_permissions + user_sig + user_occ + user_interests + + 2 + poster + + + + + + + 3 + test + + + + + + + 4 + unauthorized + + + + + + + 5 + notified + + + + + + + 6 + disabled + + + + + + + 7 + default + + + + + +
+ + item_type + item_id + user_id + method + notify + + post + 0 + 2 + + 1 + + + post + 0 + 3 + + 1 + + + post + 0 + 4 + + 1 + + + post + 0 + 5 + + 1 + + + post + 0 + 6 + + 1 + + + post + 0 + 7 + + 1 + + + post + 0 + 8 + + 1 + +
+
diff --git a/tests/notification/fixtures/submit_post_quote.xml b/tests/notification/fixtures/submit_post_quote.xml new file mode 100644 index 0000000000..884a84af4a --- /dev/null +++ b/tests/notification/fixtures/submit_post_quote.xml @@ -0,0 +1,145 @@ + + + + item_type + user_id + item_id + item_parent_id + notification_read + notification_data + + quote + 5 + 1 + 1 + 0 + + +
+ + notification_type + notification_type_enabled + + quote + 1 + +
+ + post_id + topic_id + forum_id + post_text + + 1 + 1 + 1 + + +
+ + topic_id + forum_id + + 1 + 1 + +
+ + user_id + username_clean + user_permissions + user_sig + user_occ + user_interests + + 2 + poster + + + + + + + 3 + test + + + + + + + 4 + unauthorized + + + + + + + 5 + notified + + + + + + + 6 + disabled + + + + + + + 7 + default + + + + + +
+ + item_type + item_id + user_id + method + notify + + quote + 0 + 2 + + 1 + + + quote + 0 + 3 + + 1 + + + quote + 0 + 4 + + 1 + + + quote + 0 + 5 + + 1 + + + quote + 0 + 6 + + 0 + +
+
diff --git a/tests/notification/submit_post_base.php b/tests/notification/submit_post_base.php index f458a4896a..d306e3f381 100644 --- a/tests/notification/submit_post_base.php +++ b/tests/notification/submit_post_base.php @@ -39,7 +39,7 @@ class phpbb_notification_submit_post_base extends phpbb_database_test_case public function getDataSet() { - return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/submit_post_notification.xml'); + return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/submit_post_' . $this->item_type . '.xml'); } public function setUp() -- cgit v1.2.1 From 0f204595d9b69c29716e8cf0ccf5033e66f5294f Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 26 Mar 2013 14:09:35 +0100 Subject: [ticket/11405] Fix "only variables should be passed by reference" PHPBB3-11405 --- tests/notification/submit_post_base.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/notification/submit_post_base.php b/tests/notification/submit_post_base.php index d306e3f381..c5b2450e1c 100644 --- a/tests/notification/submit_post_base.php +++ b/tests/notification/submit_post_base.php @@ -126,7 +126,9 @@ class phpbb_notification_submit_post_base extends phpbb_database_test_case $this->assertEquals($expected_before, $this->db->sql_fetchrowset($result)); $this->db->sql_freeresult($result); - submit_post('reply', '', 'poster-name', POST_NORMAL, $this->poll_data, array_merge($this->post_data, $additional_post_data), false, false); + $poll_data = $this->poll_data; + $post_data = array_merge($this->post_data, $additional_post_data); + submit_post('reply', '', 'poster-name', POST_NORMAL, $poll_data, $post_data, false, false); $sql = 'SELECT user_id, item_id, item_parent_id FROM ' . NOTIFICATIONS_TABLE . " -- cgit v1.2.1 From 8a94e08e3009fece3f9de2d28c8f873dc4471b52 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 26 Mar 2013 13:33:32 +0100 Subject: [ticket/11405] Add unit tests for post_in_queue PHPBB3-11405 --- .../fixtures/submit_post_post_in_queue.xml | 160 +++++++++++++++++++++ .../submit_post_type_post_in_queue_test.php | 102 +++++++++++++ 2 files changed, 262 insertions(+) create mode 100644 tests/notification/fixtures/submit_post_post_in_queue.xml create mode 100644 tests/notification/submit_post_type_post_in_queue_test.php (limited to 'tests') diff --git a/tests/notification/fixtures/submit_post_post_in_queue.xml b/tests/notification/fixtures/submit_post_post_in_queue.xml new file mode 100644 index 0000000000..4162d01d7f --- /dev/null +++ b/tests/notification/fixtures/submit_post_post_in_queue.xml @@ -0,0 +1,160 @@ + + + + item_type + user_id + item_id + item_parent_id + notification_read + notification_data + + post_in_queue + 6 + 1 + 1 + 0 + + +
+ + notification_type + notification_type_enabled + + post_in_queue + 1 + +
+ + post_id + topic_id + forum_id + post_text + + 1 + 1 + 1 + + +
+ + topic_id + forum_id + + 1 + 1 + +
+ + user_id + username_clean + user_permissions + user_sig + user_occ + user_interests + + 2 + poster + + + + + + + 3 + test + + + + + + + 4 + unauthorized-mod + + + + + + + 5 + unauthorized-read + + + + + + + 6 + notified + + + + + + + 7 + disabled + + + + + + + 8 + default + + + + + +
+ + item_type + item_id + user_id + method + notify + + needs_approval + 0 + 2 + + 1 + + + needs_approval + 0 + 3 + + 1 + + + needs_approval + 0 + 4 + + 1 + + + needs_approval + 0 + 5 + + 1 + + + needs_approval + 0 + 6 + + 1 + + + needs_approval + 0 + 7 + + 0 + +
+
diff --git a/tests/notification/submit_post_type_post_in_queue_test.php b/tests/notification/submit_post_type_post_in_queue_test.php new file mode 100644 index 0000000000..375ee3fbef --- /dev/null +++ b/tests/notification/submit_post_type_post_in_queue_test.php @@ -0,0 +1,102 @@ +expects($this->any()) + ->method('acl_get_list') + ->with($this->anything(), + $this->stringContains('_'), + $this->greaterThan(0)) + ->will($this->returnValueMap(array( + array( + false, + 'm_approve', + array(1, 0), + array( + 1 => array( + 'm_approve' => array(3, 4, 6, 7, 8), + ), + ), + ), + array( + array(3, 4, 6, 7, 8), + 'f_read', + 1, + array( + 1 => array( + 'f_read' => array(3, 6, 7, 8), + ), + ), + ), + ))); + } + + /** + * submit_post() Notifications test + * + * submit_post() $mode = 'reply' + * Notification item_type = 'post_in_queue' + */ + public function submit_post_data() + { + return array( + /** + * Normal post + * + * No new notifications + */ + array( + array(), + array( + array('user_id' => 6, 'item_id' => 1, 'item_parent_id' => 1), + ), + array( + array('user_id' => 6, 'item_id' => 1, 'item_parent_id' => 1), + ), + ), + + /** + * Unapproved post + * + * User => State description + * 2 => Poster, should NOT receive a notification + * 3 => Moderator, should receive a notification + * 4 => Moderator, but unauthed to read, should NOT receive a notification + * 5 => Moderator, but unauthed to approve, should NOT receive a notification + * 6 => Moderator, but already notified, should STILL receive a new notification + * 7 => Moderator, but option disabled, should NOT receive a notification + * 8 => Moderator, option set to default, should receive a notification + */ + array( + array('force_approved_state' => false), + array( + array('user_id' => 6, 'item_id' => 1, 'item_parent_id' => 1), + ), + array( + array('user_id' => 3, 'item_id' => 2, 'item_parent_id' => 1), + array('user_id' => 6, 'item_id' => 1, 'item_parent_id' => 1), + array('user_id' => 6, 'item_id' => 2, 'item_parent_id' => 1), + array('user_id' => 8, 'item_id' => 2, 'item_parent_id' => 1), + ), + ), + ); + } +} -- cgit v1.2.1 From bdd2062a667fdf9acde75946c7a9d5d84e84b092 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 27 Mar 2013 11:12:33 +0100 Subject: [ticket/11474] Add test user with only global m_approve permissions PHPBB3-11405 PHPBB3-11474 --- tests/notification/fixtures/submit_post_post_in_queue.xml | 15 +++++++++++++++ .../notification/submit_post_type_post_in_queue_test.php | 9 +++++++-- 2 files changed, 22 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/notification/fixtures/submit_post_post_in_queue.xml b/tests/notification/fixtures/submit_post_post_in_queue.xml index 4162d01d7f..eedcebf71d 100644 --- a/tests/notification/fixtures/submit_post_post_in_queue.xml +++ b/tests/notification/fixtures/submit_post_post_in_queue.xml @@ -107,6 +107,14 @@ + + 9 + test glboal-permissions + + + + + item_type @@ -156,5 +164,12 @@ 0 + + needs_approval + 0 + 9 + + 1 +
diff --git a/tests/notification/submit_post_type_post_in_queue_test.php b/tests/notification/submit_post_type_post_in_queue_test.php index 375ee3fbef..6a7ac44e39 100644 --- a/tests/notification/submit_post_type_post_in_queue_test.php +++ b/tests/notification/submit_post_type_post_in_queue_test.php @@ -31,18 +31,21 @@ class phpbb_notification_submit_post_type_post_in_queue_test extends phpbb_notif 'm_approve', array(1, 0), array( + 0 => array( + 'm_approve' => array(9), + ), 1 => array( 'm_approve' => array(3, 4, 6, 7, 8), ), ), ), array( - array(3, 4, 6, 7, 8), + array(3, 4, 6, 7, 8, 9), 'f_read', 1, array( 1 => array( - 'f_read' => array(3, 6, 7, 8), + 'f_read' => array(3, 6, 7, 8, 9), ), ), ), @@ -84,6 +87,7 @@ class phpbb_notification_submit_post_type_post_in_queue_test extends phpbb_notif * 6 => Moderator, but already notified, should STILL receive a new notification * 7 => Moderator, but option disabled, should NOT receive a notification * 8 => Moderator, option set to default, should receive a notification + * 9 => Moderator, has only global mod permissions, should receive a notification */ array( array('force_approved_state' => false), @@ -95,6 +99,7 @@ class phpbb_notification_submit_post_type_post_in_queue_test extends phpbb_notif array('user_id' => 6, 'item_id' => 1, 'item_parent_id' => 1), array('user_id' => 6, 'item_id' => 2, 'item_parent_id' => 1), array('user_id' => 8, 'item_id' => 2, 'item_parent_id' => 1), + array('user_id' => 9, 'item_id' => 2, 'item_parent_id' => 1), ), ), ); -- cgit v1.2.1 From 8dd26dee8349a14abac00db6ad5039d7517bda57 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 27 Mar 2013 11:45:45 +0100 Subject: [ticket/11469] Add some basic unit tests for phpbb_db_sql_insert_buffer PHPBB3-11469 --- tests/dbal/sql_insert_buffer_test.php | 176 ++++++++++++++++++++++++++++++++++ 1 file changed, 176 insertions(+) create mode 100644 tests/dbal/sql_insert_buffer_test.php (limited to 'tests') diff --git a/tests/dbal/sql_insert_buffer_test.php b/tests/dbal/sql_insert_buffer_test.php new file mode 100644 index 0000000000..a67ccbe89f --- /dev/null +++ b/tests/dbal/sql_insert_buffer_test.php @@ -0,0 +1,176 @@ +createXMLDataSet(dirname(__FILE__).'/fixtures/config.xml'); + } + + public function insert_buffer_data() + { + $db = $this->new_dbal(); + + if ($db->multi_insert) + { + // Test with enabled and disabled multi_insert + return array( + array(true), + array(false), + ); + } + else + { + // Only test with disabled multi_insert, the DB doesn't support it + return array( + array(false), + ); + } + } + + /** + * @dataProvider insert_buffer_data + */ + public function test_insert_and_flush($force_multi_insert) + { + $db = $this->new_dbal(); + $db->multi_insert = $force_multi_insert; + + $buffer = new phpbb_db_sql_insert_buffer($db, 'phpbb_config', 2); + + $sql = 'SELECT COUNT(*) AS num_configs + FROM phpbb_config'; + $result = $db->sql_query_limit($sql, 1); + $this->assertEquals(2, $db->sql_fetchfield('num_configs')); + $db->sql_freeresult($result); + + // This call can be buffered + $buffer->insert(array( + 'config_name' => 'name1', + 'config_value' => 'value1', + 'is_dynamic' => '0', + )); + + if ($db->multi_insert) + { + $sql = 'SELECT COUNT(*) AS num_configs + FROM phpbb_config'; + $result = $db->sql_query_limit($sql, 1); + $this->assertEquals(2, $db->sql_fetchfield('num_configs')); + $db->sql_freeresult($result); + } + else + { + $sql = 'SELECT COUNT(*) AS num_configs + FROM phpbb_config'; + $result = $db->sql_query_limit($sql, 1); + $this->assertEquals(3, $db->sql_fetchfield('num_configs')); + $db->sql_freeresult($result); + } + + // Manually flush + $buffer->flush(); + + $sql = 'SELECT COUNT(*) AS num_configs + FROM phpbb_config'; + $result = $db->sql_query_limit($sql, 1); + $this->assertEquals(3, $db->sql_fetchfield('num_configs')); + $db->sql_freeresult($result); + } + + /** + * @dataProvider insert_buffer_data + */ + public function test_insert_with_flush($force_multi_insert) + { + $db = $this->new_dbal(); + $db->multi_insert = $force_multi_insert; + + $buffer = new phpbb_db_sql_insert_buffer($db, 'phpbb_config', 2); + + $sql = 'SELECT COUNT(*) AS num_configs + FROM phpbb_config'; + $result = $db->sql_query_limit($sql, 1); + $this->assertEquals(2, $db->sql_fetchfield('num_configs')); + $db->sql_freeresult($result); + + $buffer->insert(array( + 'config_name' => 'name1', + 'config_value' => 'value1', + 'is_dynamic' => '0', + )); + + // This call flushes the values + $buffer->insert(array( + 'config_name' => 'name2', + 'config_value' => 'value2', + 'is_dynamic' => '0', + )); + + $sql = 'SELECT COUNT(*) AS num_configs + FROM phpbb_config'; + $result = $db->sql_query_limit($sql, 1); + $this->assertEquals(4, $db->sql_fetchfield('num_configs')); + $db->sql_freeresult($result); + } + + /** + * @dataProvider insert_buffer_data + */ + public function test_insert_all_and_flush($force_multi_insert) + { + $db = $this->new_dbal(); + $db->multi_insert = $force_multi_insert; + + $buffer = new phpbb_db_sql_insert_buffer($db, 'phpbb_config', 2); + + $sql = 'SELECT COUNT(*) AS num_configs + FROM phpbb_config'; + $result = $db->sql_query_limit($sql, 1); + $this->assertEquals(2, $db->sql_fetchfield('num_configs')); + $db->sql_freeresult($result); + + $buffer->insert_all(array( + array( + 'config_name' => 'name1', + 'config_value' => 'value1', + 'is_dynamic' => '0', + ), + array( + 'config_name' => 'name2', + 'config_value' => 'value2', + 'is_dynamic' => '0', + ), + array( + 'config_name' => 'name3', + 'config_value' => 'value3', + 'is_dynamic' => '0', + ), + )); + + if ($db->multi_insert) + { + $sql = 'SELECT COUNT(*) AS num_configs + FROM phpbb_config'; + $result = $db->sql_query_limit($sql, 1); + $this->assertEquals(4, $db->sql_fetchfield('num_configs')); + $db->sql_freeresult($result); + + // Manually flush + $buffer->flush(); + } + + $sql = 'SELECT COUNT(*) AS num_configs + FROM phpbb_config'; + $result = $db->sql_query_limit($sql, 1); + $this->assertEquals(5, $db->sql_fetchfield('num_configs')); + $db->sql_freeresult($result); + } +} -- cgit v1.2.1 From af9f30cd52fd7b53b17b946a0c646fd72c4a6f4f Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 27 Mar 2013 14:09:04 +0100 Subject: [ticket/11469] Use method to check config count, instead of repeating it PHPBB3-11469 --- tests/dbal/sql_insert_buffer_test.php | 63 ++++++++++------------------------- 1 file changed, 18 insertions(+), 45 deletions(-) (limited to 'tests') diff --git a/tests/dbal/sql_insert_buffer_test.php b/tests/dbal/sql_insert_buffer_test.php index a67ccbe89f..e3ee767937 100644 --- a/tests/dbal/sql_insert_buffer_test.php +++ b/tests/dbal/sql_insert_buffer_test.php @@ -14,6 +14,15 @@ class phpbb_dbal_sql_insert_buffer_test extends phpbb_database_test_case return $this->createXMLDataSet(dirname(__FILE__).'/fixtures/config.xml'); } + protected function assert_config_count($db, $num_configs) + { + $sql = 'SELECT COUNT(*) AS num_configs + FROM phpbb_config'; + $result = $db->sql_query($sql); + $this->assertEquals($num_configs, $db->sql_fetchfield('num_configs')); + $db->sql_freeresult($result); + } + public function insert_buffer_data() { $db = $this->new_dbal(); @@ -45,11 +54,7 @@ class phpbb_dbal_sql_insert_buffer_test extends phpbb_database_test_case $buffer = new phpbb_db_sql_insert_buffer($db, 'phpbb_config', 2); - $sql = 'SELECT COUNT(*) AS num_configs - FROM phpbb_config'; - $result = $db->sql_query_limit($sql, 1); - $this->assertEquals(2, $db->sql_fetchfield('num_configs')); - $db->sql_freeresult($result); + $this->assert_config_count($db, 2); // This call can be buffered $buffer->insert(array( @@ -60,29 +65,17 @@ class phpbb_dbal_sql_insert_buffer_test extends phpbb_database_test_case if ($db->multi_insert) { - $sql = 'SELECT COUNT(*) AS num_configs - FROM phpbb_config'; - $result = $db->sql_query_limit($sql, 1); - $this->assertEquals(2, $db->sql_fetchfield('num_configs')); - $db->sql_freeresult($result); + $this->assert_config_count($db, 2); } else { - $sql = 'SELECT COUNT(*) AS num_configs - FROM phpbb_config'; - $result = $db->sql_query_limit($sql, 1); - $this->assertEquals(3, $db->sql_fetchfield('num_configs')); - $db->sql_freeresult($result); + $this->assert_config_count($db, 3); } // Manually flush $buffer->flush(); - $sql = 'SELECT COUNT(*) AS num_configs - FROM phpbb_config'; - $result = $db->sql_query_limit($sql, 1); - $this->assertEquals(3, $db->sql_fetchfield('num_configs')); - $db->sql_freeresult($result); + $this->assert_config_count($db, 3); } /** @@ -95,11 +88,7 @@ class phpbb_dbal_sql_insert_buffer_test extends phpbb_database_test_case $buffer = new phpbb_db_sql_insert_buffer($db, 'phpbb_config', 2); - $sql = 'SELECT COUNT(*) AS num_configs - FROM phpbb_config'; - $result = $db->sql_query_limit($sql, 1); - $this->assertEquals(2, $db->sql_fetchfield('num_configs')); - $db->sql_freeresult($result); + $this->assert_config_count($db, 2); $buffer->insert(array( 'config_name' => 'name1', @@ -114,11 +103,7 @@ class phpbb_dbal_sql_insert_buffer_test extends phpbb_database_test_case 'is_dynamic' => '0', )); - $sql = 'SELECT COUNT(*) AS num_configs - FROM phpbb_config'; - $result = $db->sql_query_limit($sql, 1); - $this->assertEquals(4, $db->sql_fetchfield('num_configs')); - $db->sql_freeresult($result); + $this->assert_config_count($db, 4); } /** @@ -131,11 +116,7 @@ class phpbb_dbal_sql_insert_buffer_test extends phpbb_database_test_case $buffer = new phpbb_db_sql_insert_buffer($db, 'phpbb_config', 2); - $sql = 'SELECT COUNT(*) AS num_configs - FROM phpbb_config'; - $result = $db->sql_query_limit($sql, 1); - $this->assertEquals(2, $db->sql_fetchfield('num_configs')); - $db->sql_freeresult($result); + $this->assert_config_count($db, 2); $buffer->insert_all(array( array( @@ -157,20 +138,12 @@ class phpbb_dbal_sql_insert_buffer_test extends phpbb_database_test_case if ($db->multi_insert) { - $sql = 'SELECT COUNT(*) AS num_configs - FROM phpbb_config'; - $result = $db->sql_query_limit($sql, 1); - $this->assertEquals(4, $db->sql_fetchfield('num_configs')); - $db->sql_freeresult($result); + $this->assert_config_count($db, 4); // Manually flush $buffer->flush(); } - $sql = 'SELECT COUNT(*) AS num_configs - FROM phpbb_config'; - $result = $db->sql_query_limit($sql, 1); - $this->assertEquals(5, $db->sql_fetchfield('num_configs')); - $db->sql_freeresult($result); + $this->assert_config_count($db, 5); } } -- cgit v1.2.1 From 9606ccc2021e7e169473d92306e28680e4b9f966 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 27 Mar 2013 20:54:20 +0100 Subject: [ticket/11469] Split tests and skip multi_insert if unavailable PHPBB3-11469 --- tests/dbal/sql_insert_buffer_test.php | 139 +++++++++++++++++++++++----------- 1 file changed, 95 insertions(+), 44 deletions(-) (limited to 'tests') diff --git a/tests/dbal/sql_insert_buffer_test.php b/tests/dbal/sql_insert_buffer_test.php index e3ee767937..bdf3544bbc 100644 --- a/tests/dbal/sql_insert_buffer_test.php +++ b/tests/dbal/sql_insert_buffer_test.php @@ -23,34 +23,38 @@ class phpbb_dbal_sql_insert_buffer_test extends phpbb_database_test_case $db->sql_freeresult($result); } - public function insert_buffer_data() + public function test_multi_insert_disabled_insert_and_flush() { $db = $this->new_dbal(); + $db->multi_insert = false; - if ($db->multi_insert) - { - // Test with enabled and disabled multi_insert - return array( - array(true), - array(false), - ); - } - else - { - // Only test with disabled multi_insert, the DB doesn't support it - return array( - array(false), - ); - } + $buffer = new phpbb_db_sql_insert_buffer($db, 'phpbb_config', 2); + + $this->assert_config_count($db, 2); + + // This call can be buffered + $buffer->insert(array( + 'config_name' => 'name1', + 'config_value' => 'value1', + 'is_dynamic' => '0', + )); + + $this->assert_config_count($db, 3); + + // Manually flush + $buffer->flush(); + + $this->assert_config_count($db, 3); } - /** - * @dataProvider insert_buffer_data - */ - public function test_insert_and_flush($force_multi_insert) + public function test_multi_insert_enabled_insert_and_flush() { $db = $this->new_dbal(); - $db->multi_insert = $force_multi_insert; + + if (!$db->multi_insert) + { + $this->markTestSkipped('Database does not support multi_insert'); + } $buffer = new phpbb_db_sql_insert_buffer($db, 'phpbb_config', 2); @@ -63,14 +67,7 @@ class phpbb_dbal_sql_insert_buffer_test extends phpbb_database_test_case 'is_dynamic' => '0', )); - if ($db->multi_insert) - { - $this->assert_config_count($db, 2); - } - else - { - $this->assert_config_count($db, 3); - } + $this->assert_config_count($db, 2); // Manually flush $buffer->flush(); @@ -78,13 +75,10 @@ class phpbb_dbal_sql_insert_buffer_test extends phpbb_database_test_case $this->assert_config_count($db, 3); } - /** - * @dataProvider insert_buffer_data - */ - public function test_insert_with_flush($force_multi_insert) + public function test_multi_insert_disabled_insert_with_flush() { $db = $this->new_dbal(); - $db->multi_insert = $force_multi_insert; + $db->multi_insert = false; $buffer = new phpbb_db_sql_insert_buffer($db, 'phpbb_config', 2); @@ -106,13 +100,39 @@ class phpbb_dbal_sql_insert_buffer_test extends phpbb_database_test_case $this->assert_config_count($db, 4); } - /** - * @dataProvider insert_buffer_data - */ - public function test_insert_all_and_flush($force_multi_insert) + public function test_multi_insert_enabled_insert_with_flush() { $db = $this->new_dbal(); - $db->multi_insert = $force_multi_insert; + + if (!$db->multi_insert) + { + $this->markTestSkipped('Database does not support multi_insert'); + } + + $buffer = new phpbb_db_sql_insert_buffer($db, 'phpbb_config', 2); + + $this->assert_config_count($db, 2); + + $buffer->insert(array( + 'config_name' => 'name1', + 'config_value' => 'value1', + 'is_dynamic' => '0', + )); + + // This call flushes the values + $buffer->insert(array( + 'config_name' => 'name2', + 'config_value' => 'value2', + 'is_dynamic' => '0', + )); + + $this->assert_config_count($db, 4); + } + + public function test_multi_insert_disabled_insert_all_and_flush() + { + $db = $this->new_dbal(); + $db->multi_insert = false; $buffer = new phpbb_db_sql_insert_buffer($db, 'phpbb_config', 2); @@ -136,14 +156,45 @@ class phpbb_dbal_sql_insert_buffer_test extends phpbb_database_test_case ), )); - if ($db->multi_insert) - { - $this->assert_config_count($db, 4); + $this->assert_config_count($db, 5); + } + + public function test_multi_insert_enabled_insert_all_and_flush() + { + $db = $this->new_dbal(); - // Manually flush - $buffer->flush(); + if (!$db->multi_insert) + { + $this->markTestSkipped('Database does not support multi_insert'); } + $buffer = new phpbb_db_sql_insert_buffer($db, 'phpbb_config', 2); + + $this->assert_config_count($db, 2); + + $buffer->insert_all(array( + array( + 'config_name' => 'name1', + 'config_value' => 'value1', + 'is_dynamic' => '0', + ), + array( + 'config_name' => 'name2', + 'config_value' => 'value2', + 'is_dynamic' => '0', + ), + array( + 'config_name' => 'name3', + 'config_value' => 'value3', + 'is_dynamic' => '0', + ), + )); + + $this->assert_config_count($db, 4); + + // Manually flush + $buffer->flush(); + $this->assert_config_count($db, 5); } } -- cgit v1.2.1 From 69ad4aab787db4c80c431c412a76d731a1abdf63 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 27 Mar 2013 20:55:08 +0100 Subject: [ticket/11469] Check return values of the functions PHPBB3-11469 --- tests/dbal/sql_insert_buffer_test.php | 38 +++++++++++++++++------------------ 1 file changed, 19 insertions(+), 19 deletions(-) (limited to 'tests') diff --git a/tests/dbal/sql_insert_buffer_test.php b/tests/dbal/sql_insert_buffer_test.php index bdf3544bbc..fd92ca9bba 100644 --- a/tests/dbal/sql_insert_buffer_test.php +++ b/tests/dbal/sql_insert_buffer_test.php @@ -33,16 +33,16 @@ class phpbb_dbal_sql_insert_buffer_test extends phpbb_database_test_case $this->assert_config_count($db, 2); // This call can be buffered - $buffer->insert(array( + $this->assertTrue($buffer->insert(array( 'config_name' => 'name1', 'config_value' => 'value1', 'is_dynamic' => '0', - )); + ))); $this->assert_config_count($db, 3); // Manually flush - $buffer->flush(); + $this->assertFalse($buffer->flush()); $this->assert_config_count($db, 3); } @@ -61,16 +61,16 @@ class phpbb_dbal_sql_insert_buffer_test extends phpbb_database_test_case $this->assert_config_count($db, 2); // This call can be buffered - $buffer->insert(array( + $this->assertFalse($buffer->insert(array( 'config_name' => 'name1', 'config_value' => 'value1', 'is_dynamic' => '0', - )); + ))); $this->assert_config_count($db, 2); // Manually flush - $buffer->flush(); + $this->assertTrue($buffer->flush()); $this->assert_config_count($db, 3); } @@ -84,18 +84,18 @@ class phpbb_dbal_sql_insert_buffer_test extends phpbb_database_test_case $this->assert_config_count($db, 2); - $buffer->insert(array( + $this->assertTrue($buffer->insert(array( 'config_name' => 'name1', 'config_value' => 'value1', 'is_dynamic' => '0', - )); + ))); // This call flushes the values - $buffer->insert(array( + $this->assertTrue($buffer->insert(array( 'config_name' => 'name2', 'config_value' => 'value2', 'is_dynamic' => '0', - )); + ))); $this->assert_config_count($db, 4); } @@ -113,18 +113,18 @@ class phpbb_dbal_sql_insert_buffer_test extends phpbb_database_test_case $this->assert_config_count($db, 2); - $buffer->insert(array( + $this->assertFalse($buffer->insert(array( 'config_name' => 'name1', 'config_value' => 'value1', 'is_dynamic' => '0', - )); + ))); // This call flushes the values - $buffer->insert(array( + $this->assertTrue($buffer->insert(array( 'config_name' => 'name2', 'config_value' => 'value2', 'is_dynamic' => '0', - )); + ))); $this->assert_config_count($db, 4); } @@ -138,7 +138,7 @@ class phpbb_dbal_sql_insert_buffer_test extends phpbb_database_test_case $this->assert_config_count($db, 2); - $buffer->insert_all(array( + $this->assertTrue($buffer->insert_all(array( array( 'config_name' => 'name1', 'config_value' => 'value1', @@ -154,7 +154,7 @@ class phpbb_dbal_sql_insert_buffer_test extends phpbb_database_test_case 'config_value' => 'value3', 'is_dynamic' => '0', ), - )); + ))); $this->assert_config_count($db, 5); } @@ -172,7 +172,7 @@ class phpbb_dbal_sql_insert_buffer_test extends phpbb_database_test_case $this->assert_config_count($db, 2); - $buffer->insert_all(array( + $this->assertTrue($buffer->insert_all(array( array( 'config_name' => 'name1', 'config_value' => 'value1', @@ -188,12 +188,12 @@ class phpbb_dbal_sql_insert_buffer_test extends phpbb_database_test_case 'config_value' => 'value3', 'is_dynamic' => '0', ), - )); + ))); $this->assert_config_count($db, 4); // Manually flush - $buffer->flush(); + $this->assertTrue($buffer->flush()); $this->assert_config_count($db, 5); } -- cgit v1.2.1 From a534497d82cb9febaa18ee6c858ef68217bc2d14 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Wed, 27 Mar 2013 23:21:29 +0100 Subject: [ticket/11469] Move protected method to end of test file. PHPBB3-11469 --- tests/dbal/sql_insert_buffer_test.php | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'tests') diff --git a/tests/dbal/sql_insert_buffer_test.php b/tests/dbal/sql_insert_buffer_test.php index fd92ca9bba..0cf476b14a 100644 --- a/tests/dbal/sql_insert_buffer_test.php +++ b/tests/dbal/sql_insert_buffer_test.php @@ -14,15 +14,6 @@ class phpbb_dbal_sql_insert_buffer_test extends phpbb_database_test_case return $this->createXMLDataSet(dirname(__FILE__).'/fixtures/config.xml'); } - protected function assert_config_count($db, $num_configs) - { - $sql = 'SELECT COUNT(*) AS num_configs - FROM phpbb_config'; - $result = $db->sql_query($sql); - $this->assertEquals($num_configs, $db->sql_fetchfield('num_configs')); - $db->sql_freeresult($result); - } - public function test_multi_insert_disabled_insert_and_flush() { $db = $this->new_dbal(); @@ -197,4 +188,13 @@ class phpbb_dbal_sql_insert_buffer_test extends phpbb_database_test_case $this->assert_config_count($db, 5); } + + protected function assert_config_count($db, $num_configs) + { + $sql = 'SELECT COUNT(*) AS num_configs + FROM phpbb_config'; + $result = $db->sql_query($sql); + $this->assertEquals($num_configs, $db->sql_fetchfield('num_configs')); + $db->sql_freeresult($result); + } } -- cgit v1.2.1 From 873f098b6ccc108dc293054f2cf7cb7231684caa Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Wed, 27 Mar 2013 23:30:23 +0100 Subject: [ticket/11469] Do not repeat array with three rows. PHPBB3-11469 --- tests/dbal/sql_insert_buffer_test.php | 57 ++++++++++++++--------------------- 1 file changed, 23 insertions(+), 34 deletions(-) (limited to 'tests') diff --git a/tests/dbal/sql_insert_buffer_test.php b/tests/dbal/sql_insert_buffer_test.php index 0cf476b14a..59bfb73d0f 100644 --- a/tests/dbal/sql_insert_buffer_test.php +++ b/tests/dbal/sql_insert_buffer_test.php @@ -129,23 +129,7 @@ class phpbb_dbal_sql_insert_buffer_test extends phpbb_database_test_case $this->assert_config_count($db, 2); - $this->assertTrue($buffer->insert_all(array( - array( - 'config_name' => 'name1', - 'config_value' => 'value1', - 'is_dynamic' => '0', - ), - array( - 'config_name' => 'name2', - 'config_value' => 'value2', - 'is_dynamic' => '0', - ), - array( - 'config_name' => 'name3', - 'config_value' => 'value3', - 'is_dynamic' => '0', - ), - ))); + $this->assertTrue($buffer->insert_all($this->get_three_rows())); $this->assert_config_count($db, 5); } @@ -163,23 +147,7 @@ class phpbb_dbal_sql_insert_buffer_test extends phpbb_database_test_case $this->assert_config_count($db, 2); - $this->assertTrue($buffer->insert_all(array( - array( - 'config_name' => 'name1', - 'config_value' => 'value1', - 'is_dynamic' => '0', - ), - array( - 'config_name' => 'name2', - 'config_value' => 'value2', - 'is_dynamic' => '0', - ), - array( - 'config_name' => 'name3', - 'config_value' => 'value3', - 'is_dynamic' => '0', - ), - ))); + $this->assertTrue($buffer->insert_all($this->get_three_rows())); $this->assert_config_count($db, 4); @@ -197,4 +165,25 @@ class phpbb_dbal_sql_insert_buffer_test extends phpbb_database_test_case $this->assertEquals($num_configs, $db->sql_fetchfield('num_configs')); $db->sql_freeresult($result); } + + protected function get_three_rows() + { + return array( + array( + 'config_name' => 'name1', + 'config_value' => 'value1', + 'is_dynamic' => '0', + ), + array( + 'config_name' => 'name2', + 'config_value' => 'value2', + 'is_dynamic' => '0', + ), + array( + 'config_name' => 'name3', + 'config_value' => 'value3', + 'is_dynamic' => '0', + ), + ); + } } -- cgit v1.2.1 From b88eb3c8e099e1a0634ab84e9e1c215c00410264 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Wed, 27 Mar 2013 23:33:13 +0100 Subject: [ticket/11469] Do not repeat row generation. PHPBB3-11469 --- tests/dbal/sql_insert_buffer_test.php | 63 ++++++++++------------------------- 1 file changed, 18 insertions(+), 45 deletions(-) (limited to 'tests') diff --git a/tests/dbal/sql_insert_buffer_test.php b/tests/dbal/sql_insert_buffer_test.php index 59bfb73d0f..650a42c36d 100644 --- a/tests/dbal/sql_insert_buffer_test.php +++ b/tests/dbal/sql_insert_buffer_test.php @@ -24,11 +24,7 @@ class phpbb_dbal_sql_insert_buffer_test extends phpbb_database_test_case $this->assert_config_count($db, 2); // This call can be buffered - $this->assertTrue($buffer->insert(array( - 'config_name' => 'name1', - 'config_value' => 'value1', - 'is_dynamic' => '0', - ))); + $this->assertTrue($buffer->insert($this->get_row(1))); $this->assert_config_count($db, 3); @@ -52,11 +48,7 @@ class phpbb_dbal_sql_insert_buffer_test extends phpbb_database_test_case $this->assert_config_count($db, 2); // This call can be buffered - $this->assertFalse($buffer->insert(array( - 'config_name' => 'name1', - 'config_value' => 'value1', - 'is_dynamic' => '0', - ))); + $this->assertFalse($buffer->insert($this->get_row(1))); $this->assert_config_count($db, 2); @@ -75,18 +67,10 @@ class phpbb_dbal_sql_insert_buffer_test extends phpbb_database_test_case $this->assert_config_count($db, 2); - $this->assertTrue($buffer->insert(array( - 'config_name' => 'name1', - 'config_value' => 'value1', - 'is_dynamic' => '0', - ))); + $this->assertTrue($buffer->insert($this->get_row(1))); // This call flushes the values - $this->assertTrue($buffer->insert(array( - 'config_name' => 'name2', - 'config_value' => 'value2', - 'is_dynamic' => '0', - ))); + $this->assertTrue($buffer->insert($this->get_row(2))); $this->assert_config_count($db, 4); } @@ -104,18 +88,10 @@ class phpbb_dbal_sql_insert_buffer_test extends phpbb_database_test_case $this->assert_config_count($db, 2); - $this->assertFalse($buffer->insert(array( - 'config_name' => 'name1', - 'config_value' => 'value1', - 'is_dynamic' => '0', - ))); + $this->assertFalse($buffer->insert($this->get_row(1))); // This call flushes the values - $this->assertTrue($buffer->insert(array( - 'config_name' => 'name2', - 'config_value' => 'value2', - 'is_dynamic' => '0', - ))); + $this->assertTrue($buffer->insert($this->get_row(2))); $this->assert_config_count($db, 4); } @@ -166,24 +142,21 @@ class phpbb_dbal_sql_insert_buffer_test extends phpbb_database_test_case $db->sql_freeresult($result); } + protected function get_row($rownum) + { + return array( + 'config_name' => "name$rownum", + 'config_value' => "value$rownum", + 'is_dynamic' => '0', + ); + } + protected function get_three_rows() { return array( - array( - 'config_name' => 'name1', - 'config_value' => 'value1', - 'is_dynamic' => '0', - ), - array( - 'config_name' => 'name2', - 'config_value' => 'value2', - 'is_dynamic' => '0', - ), - array( - 'config_name' => 'name3', - 'config_value' => 'value3', - 'is_dynamic' => '0', - ), + $this->get_row(1), + $this->get_row(2), + $this->get_row(3), ); } } -- cgit v1.2.1 From b48c4d9549acaff8bbe7846b2390267ccd36d39a Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Wed, 27 Mar 2013 23:45:10 +0100 Subject: [ticket/11469] Use setUp() to setup DB and a buffer with size 2. PHPBB3-11469 --- tests/dbal/sql_insert_buffer_test.php | 104 +++++++++++++++------------------- 1 file changed, 47 insertions(+), 57 deletions(-) (limited to 'tests') diff --git a/tests/dbal/sql_insert_buffer_test.php b/tests/dbal/sql_insert_buffer_test.php index 650a42c36d..bc6508b30a 100644 --- a/tests/dbal/sql_insert_buffer_test.php +++ b/tests/dbal/sql_insert_buffer_test.php @@ -9,6 +9,17 @@ class phpbb_dbal_sql_insert_buffer_test extends phpbb_database_test_case { + protected $db; + protected $buffer; + + public function setUp() + { + parent::setUp(); + + $this->db = $this->new_dbal(); + $this->buffer = new phpbb_db_sql_insert_buffer($this->db, 'phpbb_config', 2); + } + public function getDataSet() { return $this->createXMLDataSet(dirname(__FILE__).'/fixtures/config.xml'); @@ -16,130 +27,109 @@ class phpbb_dbal_sql_insert_buffer_test extends phpbb_database_test_case public function test_multi_insert_disabled_insert_and_flush() { - $db = $this->new_dbal(); - $db->multi_insert = false; - - $buffer = new phpbb_db_sql_insert_buffer($db, 'phpbb_config', 2); + $this->db->multi_insert = false; - $this->assert_config_count($db, 2); + $this->assert_config_count(2); // This call can be buffered - $this->assertTrue($buffer->insert($this->get_row(1))); + $this->assertTrue($this->buffer->insert($this->get_row(1))); - $this->assert_config_count($db, 3); + $this->assert_config_count(3); // Manually flush - $this->assertFalse($buffer->flush()); + $this->assertFalse($this->buffer->flush()); - $this->assert_config_count($db, 3); + $this->assert_config_count(3); } public function test_multi_insert_enabled_insert_and_flush() { - $db = $this->new_dbal(); - - if (!$db->multi_insert) + if (!$this->db->multi_insert) { $this->markTestSkipped('Database does not support multi_insert'); } - $buffer = new phpbb_db_sql_insert_buffer($db, 'phpbb_config', 2); - - $this->assert_config_count($db, 2); + $this->assert_config_count(2); // This call can be buffered - $this->assertFalse($buffer->insert($this->get_row(1))); + $this->assertFalse($this->buffer->insert($this->get_row(1))); - $this->assert_config_count($db, 2); + $this->assert_config_count(2); // Manually flush - $this->assertTrue($buffer->flush()); + $this->assertTrue($this->buffer->flush()); - $this->assert_config_count($db, 3); + $this->assert_config_count(3); } public function test_multi_insert_disabled_insert_with_flush() { - $db = $this->new_dbal(); - $db->multi_insert = false; - - $buffer = new phpbb_db_sql_insert_buffer($db, 'phpbb_config', 2); + $this->db->multi_insert = false; - $this->assert_config_count($db, 2); + $this->assert_config_count(2); - $this->assertTrue($buffer->insert($this->get_row(1))); + $this->assertTrue($this->buffer->insert($this->get_row(1))); // This call flushes the values - $this->assertTrue($buffer->insert($this->get_row(2))); + $this->assertTrue($this->buffer->insert($this->get_row(2))); - $this->assert_config_count($db, 4); + $this->assert_config_count(4); } public function test_multi_insert_enabled_insert_with_flush() { - $db = $this->new_dbal(); - - if (!$db->multi_insert) + if (!$this->db->multi_insert) { $this->markTestSkipped('Database does not support multi_insert'); } - $buffer = new phpbb_db_sql_insert_buffer($db, 'phpbb_config', 2); - - $this->assert_config_count($db, 2); + $this->assert_config_count(2); - $this->assertFalse($buffer->insert($this->get_row(1))); + $this->assertFalse($this->buffer->insert($this->get_row(1))); // This call flushes the values - $this->assertTrue($buffer->insert($this->get_row(2))); + $this->assertTrue($this->buffer->insert($this->get_row(2))); - $this->assert_config_count($db, 4); + $this->assert_config_count(4); } public function test_multi_insert_disabled_insert_all_and_flush() { - $db = $this->new_dbal(); - $db->multi_insert = false; + $this->db->multi_insert = false; - $buffer = new phpbb_db_sql_insert_buffer($db, 'phpbb_config', 2); + $this->assert_config_count(2); - $this->assert_config_count($db, 2); + $this->assertTrue($this->buffer->insert_all($this->get_three_rows())); - $this->assertTrue($buffer->insert_all($this->get_three_rows())); - - $this->assert_config_count($db, 5); + $this->assert_config_count(5); } public function test_multi_insert_enabled_insert_all_and_flush() { - $db = $this->new_dbal(); - - if (!$db->multi_insert) + if (!$this->db->multi_insert) { $this->markTestSkipped('Database does not support multi_insert'); } - $buffer = new phpbb_db_sql_insert_buffer($db, 'phpbb_config', 2); - - $this->assert_config_count($db, 2); + $this->assert_config_count(2); - $this->assertTrue($buffer->insert_all($this->get_three_rows())); + $this->assertTrue($this->buffer->insert_all($this->get_three_rows())); - $this->assert_config_count($db, 4); + $this->assert_config_count(4); // Manually flush - $this->assertTrue($buffer->flush()); + $this->assertTrue($this->buffer->flush()); - $this->assert_config_count($db, 5); + $this->assert_config_count(5); } - protected function assert_config_count($db, $num_configs) + protected function assert_config_count($num_configs) { $sql = 'SELECT COUNT(*) AS num_configs FROM phpbb_config'; - $result = $db->sql_query($sql); - $this->assertEquals($num_configs, $db->sql_fetchfield('num_configs')); - $db->sql_freeresult($result); + $result = $this->db->sql_query($sql); + $this->assertEquals($num_configs, $this->db->sql_fetchfield('num_configs')); + $this->db->sql_freeresult($result); } protected function get_row($rownum) -- cgit v1.2.1 From c909d9602b8a8d91d9c6cd72e01c1ddf21dcf593 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Wed, 27 Mar 2013 23:46:39 +0100 Subject: [ticket/11469] Do not repeat assert_config_count(2). Also move to setUp(). PHPBB3-11469 --- tests/dbal/sql_insert_buffer_test.php | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) (limited to 'tests') diff --git a/tests/dbal/sql_insert_buffer_test.php b/tests/dbal/sql_insert_buffer_test.php index bc6508b30a..4aad852149 100644 --- a/tests/dbal/sql_insert_buffer_test.php +++ b/tests/dbal/sql_insert_buffer_test.php @@ -18,6 +18,7 @@ class phpbb_dbal_sql_insert_buffer_test extends phpbb_database_test_case $this->db = $this->new_dbal(); $this->buffer = new phpbb_db_sql_insert_buffer($this->db, 'phpbb_config', 2); + $this->assert_config_count(2); } public function getDataSet() @@ -29,8 +30,6 @@ class phpbb_dbal_sql_insert_buffer_test extends phpbb_database_test_case { $this->db->multi_insert = false; - $this->assert_config_count(2); - // This call can be buffered $this->assertTrue($this->buffer->insert($this->get_row(1))); @@ -49,8 +48,6 @@ class phpbb_dbal_sql_insert_buffer_test extends phpbb_database_test_case $this->markTestSkipped('Database does not support multi_insert'); } - $this->assert_config_count(2); - // This call can be buffered $this->assertFalse($this->buffer->insert($this->get_row(1))); @@ -66,8 +63,6 @@ class phpbb_dbal_sql_insert_buffer_test extends phpbb_database_test_case { $this->db->multi_insert = false; - $this->assert_config_count(2); - $this->assertTrue($this->buffer->insert($this->get_row(1))); // This call flushes the values @@ -83,8 +78,6 @@ class phpbb_dbal_sql_insert_buffer_test extends phpbb_database_test_case $this->markTestSkipped('Database does not support multi_insert'); } - $this->assert_config_count(2); - $this->assertFalse($this->buffer->insert($this->get_row(1))); // This call flushes the values @@ -97,8 +90,6 @@ class phpbb_dbal_sql_insert_buffer_test extends phpbb_database_test_case { $this->db->multi_insert = false; - $this->assert_config_count(2); - $this->assertTrue($this->buffer->insert_all($this->get_three_rows())); $this->assert_config_count(5); @@ -111,8 +102,6 @@ class phpbb_dbal_sql_insert_buffer_test extends phpbb_database_test_case $this->markTestSkipped('Database does not support multi_insert'); } - $this->assert_config_count(2); - $this->assertTrue($this->buffer->insert_all($this->get_three_rows())); $this->assert_config_count(4); -- cgit v1.2.1 From eacd0f3e7d200924a1d98d1ce34a454eda707dd4 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Wed, 27 Mar 2013 23:48:48 +0100 Subject: [ticket/11469] Fix spacing in getDataSet(). PHPBB3-11469 --- tests/dbal/sql_insert_buffer_test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/dbal/sql_insert_buffer_test.php b/tests/dbal/sql_insert_buffer_test.php index 4aad852149..bd03fb9c05 100644 --- a/tests/dbal/sql_insert_buffer_test.php +++ b/tests/dbal/sql_insert_buffer_test.php @@ -23,7 +23,7 @@ class phpbb_dbal_sql_insert_buffer_test extends phpbb_database_test_case public function getDataSet() { - return $this->createXMLDataSet(dirname(__FILE__).'/fixtures/config.xml'); + return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/config.xml'); } public function test_multi_insert_disabled_insert_and_flush() -- cgit v1.2.1 From 6f946e2188d08bdc939e56143bff9e663c0b6931 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Wed, 27 Mar 2013 23:53:03 +0100 Subject: [ticket/11469] Refactor get_three_rows() into get_rows($n). PHPBB3-11469 --- tests/dbal/sql_insert_buffer_test.php | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) (limited to 'tests') diff --git a/tests/dbal/sql_insert_buffer_test.php b/tests/dbal/sql_insert_buffer_test.php index bd03fb9c05..f06df26b0c 100644 --- a/tests/dbal/sql_insert_buffer_test.php +++ b/tests/dbal/sql_insert_buffer_test.php @@ -90,7 +90,7 @@ class phpbb_dbal_sql_insert_buffer_test extends phpbb_database_test_case { $this->db->multi_insert = false; - $this->assertTrue($this->buffer->insert_all($this->get_three_rows())); + $this->assertTrue($this->buffer->insert_all($this->get_rows(3))); $this->assert_config_count(5); } @@ -102,7 +102,7 @@ class phpbb_dbal_sql_insert_buffer_test extends phpbb_database_test_case $this->markTestSkipped('Database does not support multi_insert'); } - $this->assertTrue($this->buffer->insert_all($this->get_three_rows())); + $this->assertTrue($this->buffer->insert_all($this->get_rows(3))); $this->assert_config_count(4); @@ -130,12 +130,13 @@ class phpbb_dbal_sql_insert_buffer_test extends phpbb_database_test_case ); } - protected function get_three_rows() + protected function get_rows($n) { - return array( - $this->get_row(1), - $this->get_row(2), - $this->get_row(3), - ); + $result = array(); + for ($i = 0; $i < $n; ++$i) + { + $result[] = $this->get_row($i); + } + return $result; } } -- cgit v1.2.1 From a04fe625a86c0b1fcc037687afec39c659fbd830 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Wed, 27 Mar 2013 23:55:26 +0100 Subject: [ticket/11469] Do not repeat markTestSkipped() message. PHPBB3-11469 --- tests/dbal/sql_insert_buffer_test.php | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) (limited to 'tests') diff --git a/tests/dbal/sql_insert_buffer_test.php b/tests/dbal/sql_insert_buffer_test.php index f06df26b0c..9357278a62 100644 --- a/tests/dbal/sql_insert_buffer_test.php +++ b/tests/dbal/sql_insert_buffer_test.php @@ -43,10 +43,7 @@ class phpbb_dbal_sql_insert_buffer_test extends phpbb_database_test_case public function test_multi_insert_enabled_insert_and_flush() { - if (!$this->db->multi_insert) - { - $this->markTestSkipped('Database does not support multi_insert'); - } + $this->check_multi_insert_support(); // This call can be buffered $this->assertFalse($this->buffer->insert($this->get_row(1))); @@ -73,10 +70,7 @@ class phpbb_dbal_sql_insert_buffer_test extends phpbb_database_test_case public function test_multi_insert_enabled_insert_with_flush() { - if (!$this->db->multi_insert) - { - $this->markTestSkipped('Database does not support multi_insert'); - } + $this->check_multi_insert_support(); $this->assertFalse($this->buffer->insert($this->get_row(1))); @@ -97,10 +91,7 @@ class phpbb_dbal_sql_insert_buffer_test extends phpbb_database_test_case public function test_multi_insert_enabled_insert_all_and_flush() { - if (!$this->db->multi_insert) - { - $this->markTestSkipped('Database does not support multi_insert'); - } + $this->check_multi_insert_support(); $this->assertTrue($this->buffer->insert_all($this->get_rows(3))); @@ -121,6 +112,14 @@ class phpbb_dbal_sql_insert_buffer_test extends phpbb_database_test_case $this->db->sql_freeresult($result); } + protected function check_multi_insert_support() + { + if (!$this->db->multi_insert) + { + $this->markTestSkipped('Database does not support multi_insert'); + } + } + protected function get_row($rownum) { return array( -- cgit v1.2.1 From e022a7e8f602de67472e4ea5b6ecb6280f4054e4 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Thu, 28 Mar 2013 00:03:48 +0100 Subject: [ticket/11469] Remove comments. Method names should be good enough now. PHPBB3-11469 --- tests/dbal/sql_insert_buffer_test.php | 27 --------------------------- 1 file changed, 27 deletions(-) (limited to 'tests') diff --git a/tests/dbal/sql_insert_buffer_test.php b/tests/dbal/sql_insert_buffer_test.php index 9357278a62..04ef6a3d52 100644 --- a/tests/dbal/sql_insert_buffer_test.php +++ b/tests/dbal/sql_insert_buffer_test.php @@ -29,77 +29,50 @@ class phpbb_dbal_sql_insert_buffer_test extends phpbb_database_test_case public function test_multi_insert_disabled_insert_and_flush() { $this->db->multi_insert = false; - - // This call can be buffered $this->assertTrue($this->buffer->insert($this->get_row(1))); - $this->assert_config_count(3); - - // Manually flush $this->assertFalse($this->buffer->flush()); - $this->assert_config_count(3); } public function test_multi_insert_enabled_insert_and_flush() { $this->check_multi_insert_support(); - - // This call can be buffered $this->assertFalse($this->buffer->insert($this->get_row(1))); - $this->assert_config_count(2); - - // Manually flush $this->assertTrue($this->buffer->flush()); - $this->assert_config_count(3); } public function test_multi_insert_disabled_insert_with_flush() { $this->db->multi_insert = false; - $this->assertTrue($this->buffer->insert($this->get_row(1))); - - // This call flushes the values $this->assertTrue($this->buffer->insert($this->get_row(2))); - $this->assert_config_count(4); } public function test_multi_insert_enabled_insert_with_flush() { $this->check_multi_insert_support(); - $this->assertFalse($this->buffer->insert($this->get_row(1))); - - // This call flushes the values $this->assertTrue($this->buffer->insert($this->get_row(2))); - $this->assert_config_count(4); } public function test_multi_insert_disabled_insert_all_and_flush() { $this->db->multi_insert = false; - $this->assertTrue($this->buffer->insert_all($this->get_rows(3))); - $this->assert_config_count(5); } public function test_multi_insert_enabled_insert_all_and_flush() { $this->check_multi_insert_support(); - $this->assertTrue($this->buffer->insert_all($this->get_rows(3))); - $this->assert_config_count(4); - - // Manually flush $this->assertTrue($this->buffer->flush()); - $this->assert_config_count(5); } -- cgit v1.2.1 From e3a6935de6185bde189e53452fca024ef9474c1b Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Thu, 28 Mar 2013 00:20:24 +0100 Subject: [ticket/11469] Add more table status assertions. PHPBB3-11469 --- tests/dbal/sql_insert_buffer_test.php | 2 ++ 1 file changed, 2 insertions(+) (limited to 'tests') diff --git a/tests/dbal/sql_insert_buffer_test.php b/tests/dbal/sql_insert_buffer_test.php index 04ef6a3d52..45339a6b50 100644 --- a/tests/dbal/sql_insert_buffer_test.php +++ b/tests/dbal/sql_insert_buffer_test.php @@ -48,6 +48,7 @@ class phpbb_dbal_sql_insert_buffer_test extends phpbb_database_test_case { $this->db->multi_insert = false; $this->assertTrue($this->buffer->insert($this->get_row(1))); + $this->assert_config_count(3); $this->assertTrue($this->buffer->insert($this->get_row(2))); $this->assert_config_count(4); } @@ -56,6 +57,7 @@ class phpbb_dbal_sql_insert_buffer_test extends phpbb_database_test_case { $this->check_multi_insert_support(); $this->assertFalse($this->buffer->insert($this->get_row(1))); + $this->assert_config_count(2); $this->assertTrue($this->buffer->insert($this->get_row(2))); $this->assert_config_count(4); } -- cgit v1.2.1 From 5e8d92b0a84cf6ffbaefe1af5f2efd947e25aa1a Mon Sep 17 00:00:00 2001 From: Vjacheslav Trushkin Date: Wed, 10 Apr 2013 09:00:34 +0300 Subject: [ticket/11482] Unit tests for advanced DEFINE Unit tests for advanced DEFINE and ENDDEFINE PHPBB3-11482 --- tests/template/template_test.php | 14 ++++++++++++++ tests/template/templates/define.html | 2 -- tests/template/templates/define_advanced.html | 12 ++++++++++++ tests/template/templates/define_include2.html | 11 +++++++++++ tests/template/templates/define_unclosed.html | 2 ++ 5 files changed, 39 insertions(+), 2 deletions(-) create mode 100644 tests/template/templates/define_advanced.html create mode 100644 tests/template/templates/define_include2.html create mode 100644 tests/template/templates/define_unclosed.html (limited to 'tests') diff --git a/tests/template/template_test.php b/tests/template/template_test.php index 56cc7a9de5..a3c0b69123 100644 --- a/tests/template/template_test.php +++ b/tests/template/template_test.php @@ -132,6 +132,20 @@ class phpbb_template_template_test extends phpbb_template_template_test_case array(), "xyz\nabc\nabc\nbar\nbar\nabc", ), + array( + 'define_advanced.html', + array(), + array('loop' => array(array(), array(), array(), array(), array(), array(), array()), 'test' => array(array()), 'test.deep' => array(array()), 'test.deep.defines' => array(array())), + array(), + "abc\nzxc\ncde\nbcd", + ), + array( + 'define_unclosed.html', + array(), + array(), + array(), + "test", + ), array( 'expressions.html', array(), diff --git a/tests/template/templates/define.html b/tests/template/templates/define.html index 4459fffbe0..4e6d0ee793 100644 --- a/tests/template/templates/define.html +++ b/tests/template/templates/define.html @@ -7,5 +7,3 @@ {$VALUE} {$VALUE} - - diff --git a/tests/template/templates/define_advanced.html b/tests/template/templates/define_advanced.html new file mode 100644 index 0000000000..83467a5b4b --- /dev/null +++ b/tests/template/templates/define_advanced.html @@ -0,0 +1,12 @@ + +abc + +{$VALUE} + +bcd + + +cde + + +{$INCLUDED_VALUE3} diff --git a/tests/template/templates/define_include2.html b/tests/template/templates/define_include2.html new file mode 100644 index 0000000000..874f3e1852 --- /dev/null +++ b/tests/template/templates/define_include2.html @@ -0,0 +1,11 @@ + +zxc + + +qwe + +{$INCLUDED_VALUE1} + +{$VALUE2} +{$VALUE1} + diff --git a/tests/template/templates/define_unclosed.html b/tests/template/templates/define_unclosed.html new file mode 100644 index 0000000000..1c975eab2b --- /dev/null +++ b/tests/template/templates/define_unclosed.html @@ -0,0 +1,2 @@ + +test -- cgit v1.2.1 From 6110380a35ec2bca1dc953e8dfd67b1131bb1e59 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 10 Apr 2013 13:07:25 +0200 Subject: [ticket/11465] Add phpBB module to test PHPBB3-11465 --- tests/extension/includes/acp/acp_foobar.php | 28 ++++++++++++++++++++++++ tests/extension/includes/acp/info/acp_foobar.php | 26 ++++++++++++++++++++++ tests/extension/modules_test.php | 8 +++++++ 3 files changed, 62 insertions(+) create mode 100644 tests/extension/includes/acp/acp_foobar.php create mode 100644 tests/extension/includes/acp/info/acp_foobar.php (limited to 'tests') diff --git a/tests/extension/includes/acp/acp_foobar.php b/tests/extension/includes/acp/acp_foobar.php new file mode 100644 index 0000000000..c256a432e2 --- /dev/null +++ b/tests/extension/includes/acp/acp_foobar.php @@ -0,0 +1,28 @@ + 'acp_foobar', + 'title' => 'ACP Foobar', + 'version' => '3.1.0-dev', + 'modes' => array( + 'test' => array('title' => 'Test', 'auth' => '', 'cat' => array('ACP_GENERAL')), + ), + ); + } +} diff --git a/tests/extension/modules_test.php b/tests/extension/modules_test.php index 36f54fde32..9849ad2ca4 100644 --- a/tests/extension/modules_test.php +++ b/tests/extension/modules_test.php @@ -53,6 +53,14 @@ class phpbb_extension_modules_test extends phpbb_test_case 'config' => array('title' => 'Config', 'auth' => '', 'cat' => array('ACP_MODS')), ), ), + 'acp_foobar' => array( + 'filename' => 'acp_foobar', + 'title' => 'ACP Foobar', + 'version' => '3.1.0-dev', + 'modes' => array( + 'test' => array('title' => 'Test', 'auth' => '', 'cat' => array('ACP_GENERAL')), + ), + ), ), $acp_modules); $this->acp_modules->module_class = 'mcp'; -- cgit v1.2.1 From bc423f0d97e1cc531aa78505317e85604e57b88d Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 10 Apr 2013 13:11:13 +0200 Subject: [ticket/11465] Correctly set the root path for the test PHPBB3-11465 --- tests/extension/modules_test.php | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'tests') diff --git a/tests/extension/modules_test.php b/tests/extension/modules_test.php index 9849ad2ca4..675fb1f4a0 100644 --- a/tests/extension/modules_test.php +++ b/tests/extension/modules_test.php @@ -42,6 +42,11 @@ class phpbb_extension_modules_test extends phpbb_test_case public function test_get_module_infos() { + global $phpbb_root_path; + + // Correctly set the root path for this test to this directory, so the classes can be found + $phpbb_root_path = dirname(__FILE__) . '/'; + $this->acp_modules->module_class = 'acp'; $acp_modules = $this->acp_modules->get_module_infos(); $this->assertEquals(array( -- cgit v1.2.1 From 60713c8a203b4d92db016f38cf8d78165d72b30a Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 11 Apr 2013 14:06:08 +0200 Subject: [ticket/11492] Add functional test for empty teampage PHPBB3-11492 --- tests/functional/memberlist_test.php | 9 +++++ .../test_framework/phpbb_functional_test_case.php | 40 ++++++++++++++++++++++ 2 files changed, 49 insertions(+) (limited to 'tests') diff --git a/tests/functional/memberlist_test.php b/tests/functional/memberlist_test.php index 879bee2f0e..5c5d96d777 100644 --- a/tests/functional/memberlist_test.php +++ b/tests/functional/memberlist_test.php @@ -40,4 +40,13 @@ class phpbb_functional_memberlist_test extends phpbb_functional_test_case $this->assert_response_success(); $this->assertContains('admin', $crawler->filter('h2')->text()); } + + public function test_leaders() + { + $this->login(); + $this->remove_user_group('ADMINISTRATORS', array('admin')); + + $crawler = $this->request('GET', 'memberlist.php?mode=leaders&sid=' . $this->sid); + $this->assert_response_success(); + } } diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index a411d9c98a..283110a104 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -316,6 +316,46 @@ class phpbb_functional_test_case extends phpbb_test_case return user_add($user_row); } + protected function remove_user_group($group_name, $usernames) + { + global $db, $cache, $auth, $config, $phpbb_dispatcher, $phpbb_container; + + $config = new phpbb_config(array()); + $config['coppa_enable'] = 0; + + $db = $this->get_db(); + + $cache = new phpbb_mock_null_cache; + + $cache_driver = new phpbb_cache_driver_null(); + $phpbb_container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface'); + $phpbb_container + ->expects($this->any()) + ->method('get') + ->with('cache.driver') + ->will($this->returnValue($cache_driver)); + + if (!function_exists('utf_clean_string')) + { + require_once(__DIR__ . '/../../phpBB/includes/utf/utf_tools.php'); + } + if (!function_exists('group_user_del')) + { + require_once(__DIR__ . '/../../phpBB/includes/functions_user.php'); + } + $phpbb_dispatcher = new phpbb_mock_event_dispatcher(); + $auth = $this->getMock('Observer', array('acl_clear_prefetch')); + + $sql = 'SELECT group_id + FROM ' . GROUPS_TABLE . " + WHERE group_name = '" . $db->sql_escape($group_name) . "'"; + $result = $db->sql_query($sql); + $group_id = (int) $db->sql_fetchfield('group_id'); + $db->sql_freeresult($result); + + return group_user_del($group_id, false, $usernames, $group_name); + } + protected function login($username = 'admin') { $this->add_lang('ucp'); -- cgit v1.2.1 From 59ad90b25c50f0a4062ae5e190b27811c4c0279b Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 11 Apr 2013 15:18:47 +0200 Subject: [ticket/11492] Add tests for removing/adding users PHPBB3-11492 --- tests/functional/memberlist_test.php | 23 ++++++++++ .../test_framework/phpbb_functional_test_case.php | 52 +++++++++++++++++++++- 2 files changed, 74 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/functional/memberlist_test.php b/tests/functional/memberlist_test.php index 5c5d96d777..f27092aa36 100644 --- a/tests/functional/memberlist_test.php +++ b/tests/functional/memberlist_test.php @@ -44,9 +44,32 @@ class phpbb_functional_memberlist_test extends phpbb_functional_test_case public function test_leaders() { $this->login(); + $this->create_user('memberlist-test-user'); + $this->create_user('memberlist-test-moderator'); + + // Admin should be listed, user not + $crawler = $this->request('GET', 'memberlist.php?mode=leaders&sid=' . $this->sid); + $this->assert_response_success(); + $this->assertContains('admin', $crawler->filter('tr')->text()); + $this->assertNotContains('memberlist-test-user', $crawler->filter('tr')->text()); + $this->assertNotContains('memberlist-test-moderator', $crawler->filter('tr')->text()); + + // Remove admin from admins, still a moderator $this->remove_user_group('ADMINISTRATORS', array('admin')); + $crawler = $this->request('GET', 'memberlist.php?mode=leaders&sid=' . $this->sid); + $this->assert_response_success(); + $this->assertContains('admin', $crawler->filter('tr')->text()); + + // Remove admin from moderators + $this->remove_user_group('GLOBAL_MODERATORS', array('admin')); + $crawler = $this->request('GET', 'memberlist.php?mode=leaders&sid=' . $this->sid); + $this->assert_response_success(); + $this->assertNotContains('admin', $crawler->filter('tr')->text()); + // Add mod to moderators + $this->add_user_group('GLOBAL_MODERATORS', array('memberlist-test-moderator')); $crawler = $this->request('GET', 'memberlist.php?mode=leaders&sid=' . $this->sid); $this->assert_response_success(); + $this->assertContains('memberlist-test-moderator', $crawler->filter('tr')->text()); } } diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index 283110a104..3eba57caa7 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -318,13 +318,18 @@ class phpbb_functional_test_case extends phpbb_test_case protected function remove_user_group($group_name, $usernames) { - global $db, $cache, $auth, $config, $phpbb_dispatcher, $phpbb_container; + global $db, $cache, $auth, $config, $phpbb_dispatcher, $phpbb_log, $phpbb_container; $config = new phpbb_config(array()); $config['coppa_enable'] = 0; $db = $this->get_db(); + $phpbb_log = $this->getMock('phpbb_log'); + $phpbb_log + ->expects($this->any()) + ->method('add') + ->will($this->returnValue(true)); $cache = new phpbb_mock_null_cache; $cache_driver = new phpbb_cache_driver_null(); @@ -356,6 +361,51 @@ class phpbb_functional_test_case extends phpbb_test_case return group_user_del($group_id, false, $usernames, $group_name); } + protected function add_user_group($group_name, $usernames) + { + global $db, $cache, $auth, $config, $phpbb_dispatcher, $phpbb_log, $phpbb_container; + + $config = new phpbb_config(array()); + $config['coppa_enable'] = 0; + + $db = $this->get_db(); + + $phpbb_log = $this->getMock('phpbb_log'); + $phpbb_log + ->expects($this->any()) + ->method('add') + ->will($this->returnValue(true)); + $cache = new phpbb_mock_null_cache; + + $cache_driver = new phpbb_cache_driver_null(); + $phpbb_container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface'); + $phpbb_container + ->expects($this->any()) + ->method('get') + ->with('cache.driver') + ->will($this->returnValue($cache_driver)); + + if (!function_exists('utf_clean_string')) + { + require_once(__DIR__ . '/../../phpBB/includes/utf/utf_tools.php'); + } + if (!function_exists('group_user_del')) + { + require_once(__DIR__ . '/../../phpBB/includes/functions_user.php'); + } + $phpbb_dispatcher = new phpbb_mock_event_dispatcher(); + $auth = $this->getMock('Observer', array('acl_clear_prefetch')); + + $sql = 'SELECT group_id + FROM ' . GROUPS_TABLE . " + WHERE group_name = '" . $db->sql_escape($group_name) . "'"; + $result = $db->sql_query($sql); + $group_id = (int) $db->sql_fetchfield('group_id'); + $db->sql_freeresult($result); + + return group_user_add($group_id, false, $usernames, $group_name); + } + protected function login($username = 'admin') { $this->add_lang('ucp'); -- cgit v1.2.1 From e5503e20d84c94c66de33500324afb9a4c774c77 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 11 Apr 2013 15:28:55 +0200 Subject: [ticket/11492] Do not add the user again PHPBB3-11492 --- tests/functional/memberlist_test.php | 1 - 1 file changed, 1 deletion(-) (limited to 'tests') diff --git a/tests/functional/memberlist_test.php b/tests/functional/memberlist_test.php index f27092aa36..c822c06263 100644 --- a/tests/functional/memberlist_test.php +++ b/tests/functional/memberlist_test.php @@ -44,7 +44,6 @@ class phpbb_functional_memberlist_test extends phpbb_functional_test_case public function test_leaders() { $this->login(); - $this->create_user('memberlist-test-user'); $this->create_user('memberlist-test-moderator'); // Admin should be listed, user not -- cgit v1.2.1 From f920c69ad5cbe9d435a2235180dfd5e7dc9905d4 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 11 Apr 2013 15:44:54 +0200 Subject: [ticket/11492] Split into mutliple tests PHPBB3-11492 --- tests/functional/memberlist_test.php | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) (limited to 'tests') diff --git a/tests/functional/memberlist_test.php b/tests/functional/memberlist_test.php index c822c06263..46d7976230 100644 --- a/tests/functional/memberlist_test.php +++ b/tests/functional/memberlist_test.php @@ -49,26 +49,36 @@ class phpbb_functional_memberlist_test extends phpbb_functional_test_case // Admin should be listed, user not $crawler = $this->request('GET', 'memberlist.php?mode=leaders&sid=' . $this->sid); $this->assert_response_success(); - $this->assertContains('admin', $crawler->filter('tr')->text()); - $this->assertNotContains('memberlist-test-user', $crawler->filter('tr')->text()); - $this->assertNotContains('memberlist-test-moderator', $crawler->filter('tr')->text()); + $this->assertContains('admin', $crawler->text()); + $this->assertNotContains('memberlist-test-user', $crawler->text()); + $this->assertNotContains('memberlist-test-moderator', $crawler->text()); + } + + public function test_leaders_remove_users() + { + $this->login(); // Remove admin from admins, still a moderator $this->remove_user_group('ADMINISTRATORS', array('admin')); $crawler = $this->request('GET', 'memberlist.php?mode=leaders&sid=' . $this->sid); $this->assert_response_success(); - $this->assertContains('admin', $crawler->filter('tr')->text()); + $this->assertContains('admin', $crawler->text()); // Remove admin from moderators $this->remove_user_group('GLOBAL_MODERATORS', array('admin')); $crawler = $this->request('GET', 'memberlist.php?mode=leaders&sid=' . $this->sid); $this->assert_response_success(); - $this->assertNotContains('admin', $crawler->filter('tr')->text()); + $this->assertNotContains('admin', $crawler->text()); + } + + public function test_leaders_add_users() + { + $this->login(); // Add mod to moderators $this->add_user_group('GLOBAL_MODERATORS', array('memberlist-test-moderator')); $crawler = $this->request('GET', 'memberlist.php?mode=leaders&sid=' . $this->sid); $this->assert_response_success(); - $this->assertContains('memberlist-test-moderator', $crawler->filter('tr')->text()); + $this->assertContains('memberlist-test-moderator', $crawler->text()); } } -- cgit v1.2.1 From 7f527e801221bf5638acf0d46a94c0e28ec03331 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 11 Apr 2013 15:59:31 +0200 Subject: [ticket/11492] Fix issues with log object PHPBB3-11492 --- .../test_framework/phpbb_functional_test_case.php | 26 +++++++++------------- 1 file changed, 10 insertions(+), 16 deletions(-) (limited to 'tests') diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index 3eba57caa7..db6a6066e4 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -318,18 +318,17 @@ class phpbb_functional_test_case extends phpbb_test_case protected function remove_user_group($group_name, $usernames) { - global $db, $cache, $auth, $config, $phpbb_dispatcher, $phpbb_log, $phpbb_container; + global $db, $cache, $auth, $config, $phpbb_dispatcher, $phpbb_log, $phpbb_container, $phpbb_root_path, $phpEx; $config = new phpbb_config(array()); $config['coppa_enable'] = 0; $db = $this->get_db(); + $phpbb_dispatcher = new phpbb_mock_event_dispatcher(); + $user = $this->getMock('phpbb_user'); + $auth = $this->getMock('phpbb_auth'); - $phpbb_log = $this->getMock('phpbb_log'); - $phpbb_log - ->expects($this->any()) - ->method('add') - ->will($this->returnValue(true)); + $phpbb_log = new phpbb_log($db, $user, $auth, $phpbb_dispatcher, $phpbb_root_path, 'adm/', $phpEx, LOG_TABLE); $cache = new phpbb_mock_null_cache; $cache_driver = new phpbb_cache_driver_null(); @@ -348,8 +347,6 @@ class phpbb_functional_test_case extends phpbb_test_case { require_once(__DIR__ . '/../../phpBB/includes/functions_user.php'); } - $phpbb_dispatcher = new phpbb_mock_event_dispatcher(); - $auth = $this->getMock('Observer', array('acl_clear_prefetch')); $sql = 'SELECT group_id FROM ' . GROUPS_TABLE . " @@ -363,18 +360,17 @@ class phpbb_functional_test_case extends phpbb_test_case protected function add_user_group($group_name, $usernames) { - global $db, $cache, $auth, $config, $phpbb_dispatcher, $phpbb_log, $phpbb_container; + global $db, $cache, $auth, $config, $phpbb_dispatcher, $phpbb_log, $phpbb_container, $phpbb_root_path, $phpEx; $config = new phpbb_config(array()); $config['coppa_enable'] = 0; $db = $this->get_db(); + $phpbb_dispatcher = new phpbb_mock_event_dispatcher(); + $user = $this->getMock('phpbb_user'); + $auth = $this->getMock('phpbb_auth'); - $phpbb_log = $this->getMock('phpbb_log'); - $phpbb_log - ->expects($this->any()) - ->method('add') - ->will($this->returnValue(true)); + $phpbb_log = new phpbb_log($db, $user, $auth, $phpbb_dispatcher, $phpbb_root_path, 'adm/', $phpEx, LOG_TABLE); $cache = new phpbb_mock_null_cache; $cache_driver = new phpbb_cache_driver_null(); @@ -393,8 +389,6 @@ class phpbb_functional_test_case extends phpbb_test_case { require_once(__DIR__ . '/../../phpBB/includes/functions_user.php'); } - $phpbb_dispatcher = new phpbb_mock_event_dispatcher(); - $auth = $this->getMock('Observer', array('acl_clear_prefetch')); $sql = 'SELECT group_id FROM ' . GROUPS_TABLE . " -- cgit v1.2.1 From 4d4cf25edddac7de305f0d291550189ba8a5492e Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 11 Apr 2013 16:28:10 +0200 Subject: [ticket/11492] Fix the test once more PHPBB3-11492 --- tests/functional/memberlist_test.php | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) (limited to 'tests') diff --git a/tests/functional/memberlist_test.php b/tests/functional/memberlist_test.php index 46d7976230..66e3591f21 100644 --- a/tests/functional/memberlist_test.php +++ b/tests/functional/memberlist_test.php @@ -58,17 +58,11 @@ class phpbb_functional_memberlist_test extends phpbb_functional_test_case { $this->login(); - // Remove admin from admins, still a moderator + // Remove admin from admins $this->remove_user_group('ADMINISTRATORS', array('admin')); $crawler = $this->request('GET', 'memberlist.php?mode=leaders&sid=' . $this->sid); $this->assert_response_success(); $this->assertContains('admin', $crawler->text()); - - // Remove admin from moderators - $this->remove_user_group('GLOBAL_MODERATORS', array('admin')); - $crawler = $this->request('GET', 'memberlist.php?mode=leaders&sid=' . $this->sid); - $this->assert_response_success(); - $this->assertNotContains('admin', $crawler->text()); } public function test_leaders_add_users() -- cgit v1.2.1 From 5c24474c2a85d159d2b76d4483c62ab1e9861222 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 11 Apr 2013 22:11:52 +0200 Subject: [ticket/11494] Fix memberlist leaders functional tests The scope of the crawler should be reduced to the specific table PHPBB3-11494 --- tests/functional/memberlist_test.php | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) (limited to 'tests') diff --git a/tests/functional/memberlist_test.php b/tests/functional/memberlist_test.php index 66e3591f21..2e3d7907bf 100644 --- a/tests/functional/memberlist_test.php +++ b/tests/functional/memberlist_test.php @@ -46,33 +46,49 @@ class phpbb_functional_memberlist_test extends phpbb_functional_test_case $this->login(); $this->create_user('memberlist-test-moderator'); - // Admin should be listed, user not $crawler = $this->request('GET', 'memberlist.php?mode=leaders&sid=' . $this->sid); $this->assert_response_success(); - $this->assertContains('admin', $crawler->text()); - $this->assertNotContains('memberlist-test-user', $crawler->text()); - $this->assertNotContains('memberlist-test-moderator', $crawler->text()); + + // Admin in admin group, but not in moderators + $this->assertContains('admin', $crawler->filter('.forumbg-table')->eq(0)->text()); + $this->assertNotContains('admin', $crawler->filter('.forumbg-table')->eq(1)->text()); + + // memberlist-test-user in neither group + $this->assertNotContains('memberlist-test-user', $crawler->filter('.forumbg-table')->eq(0)->text()); + $this->assertNotContains('memberlist-test-user', $crawler->filter('.forumbg-table')->eq(1)->text()); + + // memberlist-test-moderator in neither group + $this->assertNotContains('memberlist-test-moderator', $crawler->filter('.forumbg-table')->eq(0)->text()); + $this->assertNotContains('memberlist-test-moderator', $crawler->filter('.forumbg-table')->eq(1)->text()); } public function test_leaders_remove_users() { $this->login(); - // Remove admin from admins + // Remove admin from admins, but is now in moderators $this->remove_user_group('ADMINISTRATORS', array('admin')); $crawler = $this->request('GET', 'memberlist.php?mode=leaders&sid=' . $this->sid); $this->assert_response_success(); - $this->assertContains('admin', $crawler->text()); + $this->assertNotContains('admin', $crawler->filter('.forumbg-table')->eq(0)->text()); + $this->assertContains('admin', $crawler->filter('.forumbg-table')->eq(1)->text()); + + // Remove admin from moderators, should not be visible anymore + $this->remove_user_group('GLOBAL_MODERATORS', array('admin')); + $crawler = $this->request('GET', 'memberlist.php?mode=leaders&sid=' . $this->sid); + $this->assertNotContains('admin', $crawler->filter('.forumbg-table')->eq(0)->text()); + $this->assertNotContains('admin', $crawler->filter('.forumbg-table')->eq(1)->text()); } public function test_leaders_add_users() { $this->login(); - // Add mod to moderators + // Add memberlist-test-moderator to moderators $this->add_user_group('GLOBAL_MODERATORS', array('memberlist-test-moderator')); $crawler = $this->request('GET', 'memberlist.php?mode=leaders&sid=' . $this->sid); $this->assert_response_success(); - $this->assertContains('memberlist-test-moderator', $crawler->text()); + $this->assertNotContains('memberlist-test-moderator', $crawler->filter('.forumbg-table')->eq(0)->text()); + $this->assertContains('memberlist-test-moderator', $crawler->filter('.forumbg-table')->eq(1)->text()); } } -- cgit v1.2.1 From b2b8b62fad58e1c53545212074894a07d7aca6a9 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 12 Apr 2013 01:08:09 +0200 Subject: [ticket/11491] Move file to correct directory PHPBB3-11491 --- tests/extension/acp.php | 205 -------------------------------- tests/functional/extension_acp_test.php | 205 ++++++++++++++++++++++++++++++++ 2 files changed, 205 insertions(+), 205 deletions(-) delete mode 100644 tests/extension/acp.php create mode 100644 tests/functional/extension_acp_test.php (limited to 'tests') diff --git a/tests/extension/acp.php b/tests/extension/acp.php deleted file mode 100644 index 790df77c0d..0000000000 --- a/tests/extension/acp.php +++ /dev/null @@ -1,205 +0,0 @@ -copy_dir($phpbb_root_path . 'ext/', $phpbb_root_path . 'store/temp_ext/'); - - // Then empty the ext/ directory on the board (for accurate test cases) - self::$helper->empty_dir($phpbb_root_path . 'ext/'); - - // Copy our ext/ files from the test case to the board - self::$copied_files = array_merge(self::$copied_files, self::$helper->copy_dir(dirname(__FILE__) . '/ext/', $phpbb_root_path . 'ext/')); - } - - public function setUp() - { - parent::setUp(); - - $this->get_db(); - - // Clear the phpbb_ext table - $this->db->sql_query('DELETE FROM phpbb_ext'); - - // Insert our base data - $insert_rows = array( - array( - 'ext_name' => 'foo', - 'ext_active' => true, - 'ext_state' => 'b:0;', - ), - array( - 'ext_name' => 'vendor/moo', - 'ext_active' => false, - 'ext_state' => 'b:0;', - ), - - // do not exist - array( - 'ext_name' => 'test2', - 'ext_active' => true, - 'ext_state' => 'b:0;', - ), - array( - 'ext_name' => 'test3', - 'ext_active' => false, - 'ext_state' => 'b:0;', - ), - ); - $this->db->sql_multi_insert('phpbb_ext', $insert_rows); - - $this->login(); - $this->admin_login(); - - $this->add_lang('acp/extensions'); - } - - /** - * This should only be called once after the tests are run. - * This is used to remove the files copied to the phpBB install - */ - static public function tearDownAfterClass() - { - global $phpbb_root_path; - - // Copy back the board installed extensions from the temp directory - self::$helper->copy_dir($phpbb_root_path . 'store/temp_ext/', $phpbb_root_path . 'ext/'); - - self::$copied_files[] = $phpbb_root_path . 'store/temp_ext/'; - - // Remove all of the files we copied around (from board ext -> temp_ext, from test ext -> board ext) - self::$helper->remove_files(self::$copied_files); - } - - public function test_list() - { - $crawler = $this->request('GET', 'adm/index.php?i=acp_extensions&mode=main&sid=' . $this->sid); - - $this->assertCount(1, $crawler->filter('.ext_enabled')); - $this->assertCount(4, $crawler->filter('.ext_disabled')); - - $this->assertContains('phpBB Foo Extension', $crawler->filter('.ext_enabled')->eq(0)->text()); - $this->assertContainsLang('PURGE', $crawler->filter('.ext_enabled')->eq(0)->text()); - - $this->assertContains('The "test2" extension is not valid.', $crawler->filter('.ext_disabled')->eq(0)->text()); - - $this->assertContains('The "test3" extension is not valid.', $crawler->filter('.ext_disabled')->eq(1)->text()); - - $this->assertContains('phpBB Moo Extension', $crawler->filter('.ext_disabled')->eq(2)->text()); - $this->assertContainsLang('DETAILS', $crawler->filter('.ext_disabled')->eq(2)->text()); - $this->assertContainsLang('ENABLE', $crawler->filter('.ext_disabled')->eq(2)->text()); - $this->assertContainsLang('PURGE', $crawler->filter('.ext_disabled')->eq(2)->text()); - - $this->assertContains('The "bar" extension is not valid.', $crawler->filter('.ext_disabled')->eq(3)->text()); - } - - public function test_details() - { - $crawler = $this->request('GET', 'adm/index.php?i=acp_extensions&mode=main&action=details&ext_name=foo&sid=' . $this->sid); - - $validation = array( - 'DISPLAY_NAME' => 'phpBB Foo Extension', - 'CLEAN_NAME' => 'foo/example', - 'DESCRIPTION' => 'An example/sample extension to be used for testing purposes in phpBB Development.', - 'VERSION' => '1.0.0', - 'TIME' => '2012-02-15 01:01:01', - 'LICENCE' => 'GPL-2.0', - 'PHPBB_VERSION' => '3.1.0-dev', - 'PHP_VERSION' => '>=5.3', - 'AUTHOR_NAME' => 'Nathan Guse', - 'AUTHOR_EMAIL' => 'email@phpbb.com', - 'AUTHOR_HOMEPAGE' => 'http://lithiumstudios.org', - 'AUTHOR_ROLE' => 'N/A', - ); - - for ($i = 0; $i < $crawler->filter('dl')->count(); $i++) - { - $text = $crawler->filter('dl')->eq($i)->text(); - - $match = false; - - foreach ($validation as $language_key => $expected) - { - if (strpos($text, $this->lang($language_key)) === 0) - { - $match = true; - - $this->assertContains($expected, $text); - } - } - - if (!$match) - { - $this->fail('Unexpected field: "' . $text . '"'); - } - } - } - - public function test_enable_pre() - { - // Foo is already enabled (redirect to list) - $crawler = $this->request('GET', 'adm/index.php?i=acp_extensions&mode=main&action=enable_pre&ext_name=foo&sid=' . $this->sid); - $this->assertContainsLang('EXTENSION_NAME', $crawler->filter('html')->text()); - $this->assertContainsLang('EXTENSION_OPTIONS', $crawler->filter('html')->text()); - $this->assertContainsLang('EXTENSION_ACTIONS', $crawler->filter('html')->text()); - - $crawler = $this->request('GET', 'adm/index.php?i=acp_extensions&mode=main&action=enable_pre&ext_name=vendor%2Fmoo&sid=' . $this->sid); - $this->assertContainsLang('ENABLE_CONFIRM', $crawler->filter('html')->text()); - } - - public function test_disable_pre() - { - // Moo is not enabled (redirect to list) - $crawler = $this->request('GET', 'adm/index.php?i=acp_extensions&mode=main&action=disable_pre&ext_name=vendor%2Fmoo&sid=' . $this->sid); - $this->assertContainsLang('EXTENSION_NAME', $crawler->filter('html')->text()); - $this->assertContainsLang('EXTENSION_OPTIONS', $crawler->filter('html')->text()); - $this->assertContainsLang('EXTENSION_ACTIONS', $crawler->filter('html')->text()); - - $crawler = $this->request('GET', 'adm/index.php?i=acp_extensions&mode=main&action=disable_pre&ext_name=foo&sid=' . $this->sid); - $this->assertContainsLang('DISABLE_CONFIRM', $crawler->filter('html')->text()); - } - - public function test_purge_pre() - { - // test2 is not available (error) - $crawler = $this->request('GET', 'adm/index.php?i=acp_extensions&mode=main&action=purge_pre&ext_name=test2&sid=' . $this->sid); - $this->assertContains('The required file does not exist', $crawler->filter('html')->text()); - - $crawler = $this->request('GET', 'adm/index.php?i=acp_extensions&mode=main&action=purge_pre&ext_name=foo&sid=' . $this->sid); - $this->assertContainsLang('PURGE_CONFIRM', $crawler->filter('html')->text()); - } - - public function test_actions() - { - $crawler = $this->request('GET', 'adm/index.php?i=acp_extensions&mode=main&action=enable&ext_name=vendor%2Fmoo&sid=' . $this->sid); - $this->assertContainsLang('ENABLE_SUCCESS', $crawler->filter('html')->text()); - - $crawler = $this->request('GET', 'adm/index.php?i=acp_extensions&mode=main&action=disable&ext_name=vendor%2Fmoo&sid=' . $this->sid); - $this->assertContainsLang('DISABLE_SUCCESS', $crawler->filter('html')->text()); - - $crawler = $this->request('GET', 'adm/index.php?i=acp_extensions&mode=main&action=purge&ext_name=vendor%2Fmoo&sid=' . $this->sid); - $this->assertContainsLang('PURGE_SUCCESS', $crawler->filter('html')->text()); - } -} \ No newline at end of file diff --git a/tests/functional/extension_acp_test.php b/tests/functional/extension_acp_test.php new file mode 100644 index 0000000000..790df77c0d --- /dev/null +++ b/tests/functional/extension_acp_test.php @@ -0,0 +1,205 @@ +copy_dir($phpbb_root_path . 'ext/', $phpbb_root_path . 'store/temp_ext/'); + + // Then empty the ext/ directory on the board (for accurate test cases) + self::$helper->empty_dir($phpbb_root_path . 'ext/'); + + // Copy our ext/ files from the test case to the board + self::$copied_files = array_merge(self::$copied_files, self::$helper->copy_dir(dirname(__FILE__) . '/ext/', $phpbb_root_path . 'ext/')); + } + + public function setUp() + { + parent::setUp(); + + $this->get_db(); + + // Clear the phpbb_ext table + $this->db->sql_query('DELETE FROM phpbb_ext'); + + // Insert our base data + $insert_rows = array( + array( + 'ext_name' => 'foo', + 'ext_active' => true, + 'ext_state' => 'b:0;', + ), + array( + 'ext_name' => 'vendor/moo', + 'ext_active' => false, + 'ext_state' => 'b:0;', + ), + + // do not exist + array( + 'ext_name' => 'test2', + 'ext_active' => true, + 'ext_state' => 'b:0;', + ), + array( + 'ext_name' => 'test3', + 'ext_active' => false, + 'ext_state' => 'b:0;', + ), + ); + $this->db->sql_multi_insert('phpbb_ext', $insert_rows); + + $this->login(); + $this->admin_login(); + + $this->add_lang('acp/extensions'); + } + + /** + * This should only be called once after the tests are run. + * This is used to remove the files copied to the phpBB install + */ + static public function tearDownAfterClass() + { + global $phpbb_root_path; + + // Copy back the board installed extensions from the temp directory + self::$helper->copy_dir($phpbb_root_path . 'store/temp_ext/', $phpbb_root_path . 'ext/'); + + self::$copied_files[] = $phpbb_root_path . 'store/temp_ext/'; + + // Remove all of the files we copied around (from board ext -> temp_ext, from test ext -> board ext) + self::$helper->remove_files(self::$copied_files); + } + + public function test_list() + { + $crawler = $this->request('GET', 'adm/index.php?i=acp_extensions&mode=main&sid=' . $this->sid); + + $this->assertCount(1, $crawler->filter('.ext_enabled')); + $this->assertCount(4, $crawler->filter('.ext_disabled')); + + $this->assertContains('phpBB Foo Extension', $crawler->filter('.ext_enabled')->eq(0)->text()); + $this->assertContainsLang('PURGE', $crawler->filter('.ext_enabled')->eq(0)->text()); + + $this->assertContains('The "test2" extension is not valid.', $crawler->filter('.ext_disabled')->eq(0)->text()); + + $this->assertContains('The "test3" extension is not valid.', $crawler->filter('.ext_disabled')->eq(1)->text()); + + $this->assertContains('phpBB Moo Extension', $crawler->filter('.ext_disabled')->eq(2)->text()); + $this->assertContainsLang('DETAILS', $crawler->filter('.ext_disabled')->eq(2)->text()); + $this->assertContainsLang('ENABLE', $crawler->filter('.ext_disabled')->eq(2)->text()); + $this->assertContainsLang('PURGE', $crawler->filter('.ext_disabled')->eq(2)->text()); + + $this->assertContains('The "bar" extension is not valid.', $crawler->filter('.ext_disabled')->eq(3)->text()); + } + + public function test_details() + { + $crawler = $this->request('GET', 'adm/index.php?i=acp_extensions&mode=main&action=details&ext_name=foo&sid=' . $this->sid); + + $validation = array( + 'DISPLAY_NAME' => 'phpBB Foo Extension', + 'CLEAN_NAME' => 'foo/example', + 'DESCRIPTION' => 'An example/sample extension to be used for testing purposes in phpBB Development.', + 'VERSION' => '1.0.0', + 'TIME' => '2012-02-15 01:01:01', + 'LICENCE' => 'GPL-2.0', + 'PHPBB_VERSION' => '3.1.0-dev', + 'PHP_VERSION' => '>=5.3', + 'AUTHOR_NAME' => 'Nathan Guse', + 'AUTHOR_EMAIL' => 'email@phpbb.com', + 'AUTHOR_HOMEPAGE' => 'http://lithiumstudios.org', + 'AUTHOR_ROLE' => 'N/A', + ); + + for ($i = 0; $i < $crawler->filter('dl')->count(); $i++) + { + $text = $crawler->filter('dl')->eq($i)->text(); + + $match = false; + + foreach ($validation as $language_key => $expected) + { + if (strpos($text, $this->lang($language_key)) === 0) + { + $match = true; + + $this->assertContains($expected, $text); + } + } + + if (!$match) + { + $this->fail('Unexpected field: "' . $text . '"'); + } + } + } + + public function test_enable_pre() + { + // Foo is already enabled (redirect to list) + $crawler = $this->request('GET', 'adm/index.php?i=acp_extensions&mode=main&action=enable_pre&ext_name=foo&sid=' . $this->sid); + $this->assertContainsLang('EXTENSION_NAME', $crawler->filter('html')->text()); + $this->assertContainsLang('EXTENSION_OPTIONS', $crawler->filter('html')->text()); + $this->assertContainsLang('EXTENSION_ACTIONS', $crawler->filter('html')->text()); + + $crawler = $this->request('GET', 'adm/index.php?i=acp_extensions&mode=main&action=enable_pre&ext_name=vendor%2Fmoo&sid=' . $this->sid); + $this->assertContainsLang('ENABLE_CONFIRM', $crawler->filter('html')->text()); + } + + public function test_disable_pre() + { + // Moo is not enabled (redirect to list) + $crawler = $this->request('GET', 'adm/index.php?i=acp_extensions&mode=main&action=disable_pre&ext_name=vendor%2Fmoo&sid=' . $this->sid); + $this->assertContainsLang('EXTENSION_NAME', $crawler->filter('html')->text()); + $this->assertContainsLang('EXTENSION_OPTIONS', $crawler->filter('html')->text()); + $this->assertContainsLang('EXTENSION_ACTIONS', $crawler->filter('html')->text()); + + $crawler = $this->request('GET', 'adm/index.php?i=acp_extensions&mode=main&action=disable_pre&ext_name=foo&sid=' . $this->sid); + $this->assertContainsLang('DISABLE_CONFIRM', $crawler->filter('html')->text()); + } + + public function test_purge_pre() + { + // test2 is not available (error) + $crawler = $this->request('GET', 'adm/index.php?i=acp_extensions&mode=main&action=purge_pre&ext_name=test2&sid=' . $this->sid); + $this->assertContains('The required file does not exist', $crawler->filter('html')->text()); + + $crawler = $this->request('GET', 'adm/index.php?i=acp_extensions&mode=main&action=purge_pre&ext_name=foo&sid=' . $this->sid); + $this->assertContainsLang('PURGE_CONFIRM', $crawler->filter('html')->text()); + } + + public function test_actions() + { + $crawler = $this->request('GET', 'adm/index.php?i=acp_extensions&mode=main&action=enable&ext_name=vendor%2Fmoo&sid=' . $this->sid); + $this->assertContainsLang('ENABLE_SUCCESS', $crawler->filter('html')->text()); + + $crawler = $this->request('GET', 'adm/index.php?i=acp_extensions&mode=main&action=disable&ext_name=vendor%2Fmoo&sid=' . $this->sid); + $this->assertContainsLang('DISABLE_SUCCESS', $crawler->filter('html')->text()); + + $crawler = $this->request('GET', 'adm/index.php?i=acp_extensions&mode=main&action=purge&ext_name=vendor%2Fmoo&sid=' . $this->sid); + $this->assertContainsLang('PURGE_SUCCESS', $crawler->filter('html')->text()); + } +} \ No newline at end of file -- cgit v1.2.1 From 4c99229be81332b6c2bce11b98ae6538e07d141f Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 12 Apr 2013 01:08:40 +0200 Subject: [ticket/11491] Fix class name of functional test PHPBB3-11491 --- tests/functional/extension_acp_test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/functional/extension_acp_test.php b/tests/functional/extension_acp_test.php index 790df77c0d..1ecff49353 100644 --- a/tests/functional/extension_acp_test.php +++ b/tests/functional/extension_acp_test.php @@ -7,7 +7,7 @@ * */ -class acp_test extends phpbb_functional_test_case +class phpbb_functional_extension_acp_test extends phpbb_functional_test_case { static private $copied_files = array(); static private $helper; -- cgit v1.2.1 From 08e7bd6166f28b106be28d6eb947ed950bedeaa1 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 12 Apr 2013 01:09:09 +0200 Subject: [ticket/11491] Add extension_acp_test.php to functional group PHPBB3-11491 --- tests/functional/extension_acp_test.php | 3 +++ 1 file changed, 3 insertions(+) (limited to 'tests') diff --git a/tests/functional/extension_acp_test.php b/tests/functional/extension_acp_test.php index 1ecff49353..399af2b452 100644 --- a/tests/functional/extension_acp_test.php +++ b/tests/functional/extension_acp_test.php @@ -7,6 +7,9 @@ * */ +/** +* @group functional +*/ class phpbb_functional_extension_acp_test extends phpbb_functional_test_case { static private $copied_files = array(); -- cgit v1.2.1 From 56bcf7497e6b866d67d8c7e2f8b679d2190639a7 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 12 Apr 2013 01:10:09 +0200 Subject: [ticket/11491] Fix path to the ext/ folder PHPBB3-11491 --- tests/functional/extension_acp_test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/functional/extension_acp_test.php b/tests/functional/extension_acp_test.php index 399af2b452..4dab5ecf82 100644 --- a/tests/functional/extension_acp_test.php +++ b/tests/functional/extension_acp_test.php @@ -34,7 +34,7 @@ class phpbb_functional_extension_acp_test extends phpbb_functional_test_case self::$helper->empty_dir($phpbb_root_path . 'ext/'); // Copy our ext/ files from the test case to the board - self::$copied_files = array_merge(self::$copied_files, self::$helper->copy_dir(dirname(__FILE__) . '/ext/', $phpbb_root_path . 'ext/')); + self::$copied_files = array_merge(self::$copied_files, self::$helper->copy_dir(dirname(__FILE__) . '/../extension/ext/', $phpbb_root_path . 'ext/')); } public function setUp() -- cgit v1.2.1 From 0b64db275bae14649e09031483b03ccc1943310b Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 12 Apr 2013 01:40:45 +0200 Subject: [ticket/11491] Correctly remove the store/temp_ext/ directory after use PHPBB3-11491 --- tests/functional/extension_acp_test.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/functional/extension_acp_test.php b/tests/functional/extension_acp_test.php index 4dab5ecf82..e829e4582e 100644 --- a/tests/functional/extension_acp_test.php +++ b/tests/functional/extension_acp_test.php @@ -90,10 +90,10 @@ class phpbb_functional_extension_acp_test extends phpbb_functional_test_case // Copy back the board installed extensions from the temp directory self::$helper->copy_dir($phpbb_root_path . 'store/temp_ext/', $phpbb_root_path . 'ext/'); - self::$copied_files[] = $phpbb_root_path . 'store/temp_ext/'; - // Remove all of the files we copied around (from board ext -> temp_ext, from test ext -> board ext) self::$helper->remove_files(self::$copied_files); + + self::$helper->empty_dir($phpbb_root_path . 'store/temp_ext/'); } public function test_list() -- cgit v1.2.1 From 3436e3f1020cce0a7d78edb7517335dfa6645024 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 12 Apr 2013 02:03:58 +0200 Subject: [ticket/11491] Only copy files from phpBB/ext/ the directory exists PHPBB3-11491 --- tests/functional/extension_acp_test.php | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'tests') diff --git a/tests/functional/extension_acp_test.php b/tests/functional/extension_acp_test.php index e829e4582e..cb908e0f98 100644 --- a/tests/functional/extension_acp_test.php +++ b/tests/functional/extension_acp_test.php @@ -27,11 +27,16 @@ class phpbb_functional_extension_acp_test extends phpbb_functional_test_case self::$helper = new phpbb_test_case_helpers(self); - // First, move any extensions setup on the board to a temp directory - self::$copied_files = self::$helper->copy_dir($phpbb_root_path . 'ext/', $phpbb_root_path . 'store/temp_ext/'); + self::$copied_files = array(); - // Then empty the ext/ directory on the board (for accurate test cases) - self::$helper->empty_dir($phpbb_root_path . 'ext/'); + if (file_exists($phpbb_root_path . 'ext/')) + { + // First, move any extensions setup on the board to a temp directory + self::$copied_files = self::$helper->copy_dir($phpbb_root_path . 'ext/', $phpbb_root_path . 'store/temp_ext/'); + + // Then empty the ext/ directory on the board (for accurate test cases) + self::$helper->empty_dir($phpbb_root_path . 'ext/'); + } // Copy our ext/ files from the test case to the board self::$copied_files = array_merge(self::$copied_files, self::$helper->copy_dir(dirname(__FILE__) . '/../extension/ext/', $phpbb_root_path . 'ext/')); -- cgit v1.2.1 From 13ca1f55985b4e481876e78f84f8957aa94e21f3 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 12 Apr 2013 02:15:37 +0200 Subject: [ticket/11491] Copy files back only if we saved them previously PHPBB3-11491 --- tests/functional/extension_acp_test.php | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'tests') diff --git a/tests/functional/extension_acp_test.php b/tests/functional/extension_acp_test.php index cb908e0f98..1879cbd62c 100644 --- a/tests/functional/extension_acp_test.php +++ b/tests/functional/extension_acp_test.php @@ -92,13 +92,19 @@ class phpbb_functional_extension_acp_test extends phpbb_functional_test_case { global $phpbb_root_path; - // Copy back the board installed extensions from the temp directory - self::$helper->copy_dir($phpbb_root_path . 'store/temp_ext/', $phpbb_root_path . 'ext/'); + if (file_exists($phpbb_root_path . 'store/temp_ext/')) + { + // Copy back the board installed extensions from the temp directory + self::$helper->copy_dir($phpbb_root_path . 'store/temp_ext/', $phpbb_root_path . 'ext/'); + } // Remove all of the files we copied around (from board ext -> temp_ext, from test ext -> board ext) self::$helper->remove_files(self::$copied_files); - self::$helper->empty_dir($phpbb_root_path . 'store/temp_ext/'); + if (file_exists($phpbb_root_path . 'store/temp_ext/')) + { + self::$helper->empty_dir($phpbb_root_path . 'store/temp_ext/'); + } } public function test_list() -- cgit v1.2.1 From 06e32e36dff55dffcb60c19e768656db237ee836 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 12 Apr 2013 21:20:34 +0200 Subject: [ticket/10844] Add unit tests for different root_paths PHPBB3-10844 --- tests/extension/style_path_provider_test.php | 50 ++++++++++++++++++++++ .../extension/subdir/style_path_provider_test.php | 18 ++++++++ 2 files changed, 68 insertions(+) create mode 100644 tests/extension/style_path_provider_test.php create mode 100644 tests/extension/subdir/style_path_provider_test.php (limited to 'tests') diff --git a/tests/extension/style_path_provider_test.php b/tests/extension/style_path_provider_test.php new file mode 100644 index 0000000000..e1021c20ac --- /dev/null +++ b/tests/extension/style_path_provider_test.php @@ -0,0 +1,50 @@ +relative_root_path = './'; + $this->root_path = dirname(__FILE__) . '/'; + } + + public function test_find() + { + $phpbb_style_path_provider = new phpbb_style_path_provider(); + $phpbb_style_path_provider->set_styles(array($this->relative_root_path . 'styles/prosilver')); + $phpbb_style_extension_path_provider = new phpbb_style_extension_path_provider(new phpbb_mock_extension_manager( + $this->root_path, + array( + 'foo' => array( + 'ext_name' => 'foo', + 'ext_active' => '1', + 'ext_path' => 'ext/foo/', + ), + 'bar' => array( + 'ext_name' => 'bar', + 'ext_active' => '1', + 'ext_path' => 'ext/bar/', + ), + )), $phpbb_style_path_provider, $this->relative_root_path); + + $this->assertEquals(array( + 'style' => array( + $this->relative_root_path . 'styles/prosilver', + ), + 'bar' => array( + $this->root_path . 'ext/bar/styles/prosilver', + ), + ), $phpbb_style_extension_path_provider->find()); + } +} diff --git a/tests/extension/subdir/style_path_provider_test.php b/tests/extension/subdir/style_path_provider_test.php new file mode 100644 index 0000000000..1b5ce62e5f --- /dev/null +++ b/tests/extension/subdir/style_path_provider_test.php @@ -0,0 +1,18 @@ +relative_root_path = '../'; + $this->root_path = dirname(__FILE__) . '/../'; + } +} -- cgit v1.2.1 From 84c815a12e7c2c816035e3b05e8ea7c88f0f4534 Mon Sep 17 00:00:00 2001 From: OpenShift guest Date: Sat, 13 Apr 2013 11:24:47 -0400 Subject: [ticket/11458] Add functional test Since there is no test method to include extension language files, a functional test seems more appropriate. We add a permission mask 'acl_u_foo' with translation found in extenion 'bar' and confirm that the permission language file 'permissions_foo.php' from 'bar' was added by asserting that 'Can view foo' exists when viewing user permissions in acp PHPBB3-11458 --- .../functional/extension_permission_lang_test.php | 59 ++++++++++++++++++++++ .../ext/foo/bar/language/en/permissions_foo.php | 6 +++ 2 files changed, 65 insertions(+) create mode 100644 tests/functional/extension_permission_lang_test.php create mode 100644 tests/functional/fixtures/ext/foo/bar/language/en/permissions_foo.php (limited to 'tests') diff --git a/tests/functional/extension_permission_lang_test.php b/tests/functional/extension_permission_lang_test.php new file mode 100644 index 0000000000..c3d136de49 --- /dev/null +++ b/tests/functional/extension_permission_lang_test.php @@ -0,0 +1,59 @@ +phpbb_extension_manager = $this->get_extension_manager(); + + $this->purge_cache(); + + $this->login(); + $this->admin_login(); + $this->add_lang('acp/permissions'); + } + + public function test_auto_include_permission_lang_from_extensions() + { + $this->phpbb_extension_manager->enable('foo/bar'); + + // User permissions + $crawler = $this->request('GET', 'adm/index.php?i=acp_permissions&icat=16&mode=setting_user_global&sid=' . $this->sid); + $this->assert_response_success(); + $this->assertContains('Can view foo', $this->client->getResponse()->getContent()); + } + + public function permissions_data() + { + return array( + // description + // permission type + // permission name + // mode + // object name + // object id + array( + 'user permission', + 'u_', + 'acl_u_foo', + 'setting_user_global', + 'user_id', + 2, + ), + ); + } +} diff --git a/tests/functional/fixtures/ext/foo/bar/language/en/permissions_foo.php b/tests/functional/fixtures/ext/foo/bar/language/en/permissions_foo.php new file mode 100644 index 0000000000..cd4b9a32d1 --- /dev/null +++ b/tests/functional/fixtures/ext/foo/bar/language/en/permissions_foo.php @@ -0,0 +1,6 @@ + array('lang' => 'Can view foo', 'cat' => 'misc'), +)); -- cgit v1.2.1 From cbfe866eba5b2a7bb9f141e5145292dbef135e78 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sat, 13 Apr 2013 18:03:02 +0200 Subject: [ticket/11494] Use functions instead of repeating PHPBB3-11494 --- tests/functional/memberlist_test.php | 48 ++++++++++++++++++++++-------------- 1 file changed, 29 insertions(+), 19 deletions(-) (limited to 'tests') diff --git a/tests/functional/memberlist_test.php b/tests/functional/memberlist_test.php index 2e3d7907bf..0065147d11 100644 --- a/tests/functional/memberlist_test.php +++ b/tests/functional/memberlist_test.php @@ -41,25 +41,37 @@ class phpbb_functional_memberlist_test extends phpbb_functional_test_case $this->assertContains('admin', $crawler->filter('h2')->text()); } + protected function get_memberlist_leaders_crawler() + { + $crawler = $this->request('GET', 'memberlist.php?mode=leaders&sid=' . $this->sid); + $this->assert_response_success(); + + return $crawler; + } + + protected function get_crawler_table_text($crawler, $table) + { + return $crawler->filter('.forumbg-table')->eq($table)->text(); + } + public function test_leaders() { $this->login(); $this->create_user('memberlist-test-moderator'); - $crawler = $this->request('GET', 'memberlist.php?mode=leaders&sid=' . $this->sid); - $this->assert_response_success(); + $crawler = $this->get_memberlist_leaders_crawler(); // Admin in admin group, but not in moderators - $this->assertContains('admin', $crawler->filter('.forumbg-table')->eq(0)->text()); - $this->assertNotContains('admin', $crawler->filter('.forumbg-table')->eq(1)->text()); + $this->assertContains('admin', $this->get_crawler_table_text($crawler, 0)); + $this->assertNotContains('admin', $this->get_crawler_table_text($crawler, 1)); // memberlist-test-user in neither group - $this->assertNotContains('memberlist-test-user', $crawler->filter('.forumbg-table')->eq(0)->text()); - $this->assertNotContains('memberlist-test-user', $crawler->filter('.forumbg-table')->eq(1)->text()); + $this->assertNotContains('memberlist-test-user', $this->get_crawler_table_text($crawler, 0)); + $this->assertNotContains('memberlist-test-user', $this->get_crawler_table_text($crawler, 1)); // memberlist-test-moderator in neither group - $this->assertNotContains('memberlist-test-moderator', $crawler->filter('.forumbg-table')->eq(0)->text()); - $this->assertNotContains('memberlist-test-moderator', $crawler->filter('.forumbg-table')->eq(1)->text()); + $this->assertNotContains('memberlist-test-moderator', $this->get_crawler_table_text($crawler, 0)); + $this->assertNotContains('memberlist-test-moderator', $this->get_crawler_table_text($crawler, 1)); } public function test_leaders_remove_users() @@ -68,16 +80,15 @@ class phpbb_functional_memberlist_test extends phpbb_functional_test_case // Remove admin from admins, but is now in moderators $this->remove_user_group('ADMINISTRATORS', array('admin')); - $crawler = $this->request('GET', 'memberlist.php?mode=leaders&sid=' . $this->sid); - $this->assert_response_success(); - $this->assertNotContains('admin', $crawler->filter('.forumbg-table')->eq(0)->text()); - $this->assertContains('admin', $crawler->filter('.forumbg-table')->eq(1)->text()); + $crawler = $this->get_memberlist_leaders_crawler(); + $this->assertNotContains('admin', $this->get_crawler_table_text($crawler, 0)); + $this->assertContains('admin', $this->get_crawler_table_text($crawler, 1)); // Remove admin from moderators, should not be visible anymore $this->remove_user_group('GLOBAL_MODERATORS', array('admin')); - $crawler = $this->request('GET', 'memberlist.php?mode=leaders&sid=' . $this->sid); - $this->assertNotContains('admin', $crawler->filter('.forumbg-table')->eq(0)->text()); - $this->assertNotContains('admin', $crawler->filter('.forumbg-table')->eq(1)->text()); + $crawler = $this->get_memberlist_leaders_crawler(); + $this->assertNotContains('admin', $this->get_crawler_table_text($crawler, 0)); + $this->assertNotContains('admin', $this->get_crawler_table_text($crawler, 1)); } public function test_leaders_add_users() @@ -86,9 +97,8 @@ class phpbb_functional_memberlist_test extends phpbb_functional_test_case // Add memberlist-test-moderator to moderators $this->add_user_group('GLOBAL_MODERATORS', array('memberlist-test-moderator')); - $crawler = $this->request('GET', 'memberlist.php?mode=leaders&sid=' . $this->sid); - $this->assert_response_success(); - $this->assertNotContains('memberlist-test-moderator', $crawler->filter('.forumbg-table')->eq(0)->text()); - $this->assertContains('memberlist-test-moderator', $crawler->filter('.forumbg-table')->eq(1)->text()); + $crawler = $this->get_memberlist_leaders_crawler(); + $this->assertNotContains('memberlist-test-moderator', $this->get_crawler_table_text($crawler, 0)); + $this->assertContains('memberlist-test-moderator', $this->get_crawler_table_text($crawler, 1)); } } -- cgit v1.2.1 From 2c910999b090502cf6a3ac2add68de763ea897ca Mon Sep 17 00:00:00 2001 From: OpenShift guest Date: Sat, 13 Apr 2013 13:56:02 -0400 Subject: [ticket/11458] Fix test PHPBB-11458 --- tests/functional/extension_permission_lang_test.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/functional/extension_permission_lang_test.php b/tests/functional/extension_permission_lang_test.php index c3d136de49..1368a628d8 100644 --- a/tests/functional/extension_permission_lang_test.php +++ b/tests/functional/extension_permission_lang_test.php @@ -34,7 +34,14 @@ class phpbb_functional_extension_permission_lang_test extends phpbb_functional_t // User permissions $crawler = $this->request('GET', 'adm/index.php?i=acp_permissions&icat=16&mode=setting_user_global&sid=' . $this->sid); $this->assert_response_success(); - $this->assertContains('Can view foo', $this->client->getResponse()->getContent()); + + // Select admin + $form = $crawler->selectButton($this->lang('SUBMIT'))->form(); + $data = array('username[0]' => 'admin'); + $form->setValues($data); + $crawler = $this->client->submit($form); + $this->assert_response_success(); + $this->assertContains('Can view foo', $crawler->filter('body')->text()); } public function permissions_data() -- cgit v1.2.1 From 9e2acdab9aea7762761e81b3306a950ab627434d Mon Sep 17 00:00:00 2001 From: OpenShift guest Date: Sun, 14 Apr 2013 17:53:38 -0400 Subject: [ticket/11458] Fix functional test again Add 'u_foo' to phpbb_acl_options Make sure extension and fixtures are added before running test PHPBB3-11458 --- .../functional/extension_permission_lang_test.php | 84 ++++++++++++++++------ 1 file changed, 64 insertions(+), 20 deletions(-) (limited to 'tests') diff --git a/tests/functional/extension_permission_lang_test.php b/tests/functional/extension_permission_lang_test.php index 1368a628d8..234cbbbaf2 100644 --- a/tests/functional/extension_permission_lang_test.php +++ b/tests/functional/extension_permission_lang_test.php @@ -14,9 +14,73 @@ class phpbb_functional_extension_permission_lang_test extends phpbb_functional_t { protected $phpbb_extension_manager; + static protected $fixtures = array( + 'foo/bar/language/en/permissions_foo.php', + ); + + /** + * This should only be called once before the tests are run. + * This is used to copy the fixtures to the phpBB install + */ + static public function setUpBeforeClass() + { + global $phpbb_root_path; + parent::setUpBeforeClass(); + + $directories = array( + $phpbb_root_path . 'ext/foo/bar/', + $phpbb_root_path . 'ext/foo/bar/language/', + $phpbb_root_path . 'ext/foo/bar/language/en/', + ); + + foreach ($directories as $dir) + { + if (!is_dir($dir)) + { + mkdir($dir, 0777, true); + } + } + + foreach (self::$fixtures as $fixture) + { + copy( + "tests/functional/fixtures/ext/$fixture", + "{$phpbb_root_path}ext/$fixture"); + } + } + + /** + * This should only be called once after the tests are run. + * This is used to remove the fixtures from the phpBB install + */ + static public function tearDownAfterClass() + { + global $phpbb_root_path; + + foreach (self::$fixtures as $fixture) + { + unlink("{$phpbb_root_path}ext/$fixture"); + } + + rmdir("{$phpbb_root_path}ext/foo/bar/language/en"); + rmdir("{$phpbb_root_path}ext/foo/bar/language"); + rmdir("{$phpbb_root_path}ext/foo/bar"); + rmdir("{$phpbb_root_path}ext/foo"); + } + public function setUp() { parent::setUp(); + + $this->get_db(); + + $acl_ary = array( + 'auth_option' => 'u_foo', + 'is_global' => 1, + ); + + $sql = 'INSERT INTO phpbb_acl_options ' . $this->db->sql_build_array('INSERT', $acl_ary); + $this->db->sql_query($sql); $this->phpbb_extension_manager = $this->get_extension_manager(); @@ -43,24 +107,4 @@ class phpbb_functional_extension_permission_lang_test extends phpbb_functional_t $this->assert_response_success(); $this->assertContains('Can view foo', $crawler->filter('body')->text()); } - - public function permissions_data() - { - return array( - // description - // permission type - // permission name - // mode - // object name - // object id - array( - 'user permission', - 'u_', - 'acl_u_foo', - 'setting_user_global', - 'user_id', - 2, - ), - ); - } } -- cgit v1.2.1 From 6bcc220df3499e2e58735c9f3a586521784c4edf Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Mon, 15 Apr 2013 03:30:07 +0200 Subject: [ticket/11494] Filter crawler in first place PHPBB3-11494 --- tests/functional/memberlist_test.php | 41 ++++++++++++++++-------------------- 1 file changed, 18 insertions(+), 23 deletions(-) (limited to 'tests') diff --git a/tests/functional/memberlist_test.php b/tests/functional/memberlist_test.php index 0065147d11..92ede8bd04 100644 --- a/tests/functional/memberlist_test.php +++ b/tests/functional/memberlist_test.php @@ -41,17 +41,12 @@ class phpbb_functional_memberlist_test extends phpbb_functional_test_case $this->assertContains('admin', $crawler->filter('h2')->text()); } - protected function get_memberlist_leaders_crawler() + protected function get_memberlist_leaders_table_crawler() { $crawler = $this->request('GET', 'memberlist.php?mode=leaders&sid=' . $this->sid); $this->assert_response_success(); - return $crawler; - } - - protected function get_crawler_table_text($crawler, $table) - { - return $crawler->filter('.forumbg-table')->eq($table)->text(); + return $crawler->filter('.forumbg-table'); } public function test_leaders() @@ -59,19 +54,19 @@ class phpbb_functional_memberlist_test extends phpbb_functional_test_case $this->login(); $this->create_user('memberlist-test-moderator'); - $crawler = $this->get_memberlist_leaders_crawler(); + $crawler = $this->get_memberlist_leaders_table_crawler(); // Admin in admin group, but not in moderators - $this->assertContains('admin', $this->get_crawler_table_text($crawler, 0)); - $this->assertNotContains('admin', $this->get_crawler_table_text($crawler, 1)); + $this->assertContains('admin', $crawler->eq(0)->text()); + $this->assertNotContains('admin', $crawler->eq(1)->text()); // memberlist-test-user in neither group - $this->assertNotContains('memberlist-test-user', $this->get_crawler_table_text($crawler, 0)); - $this->assertNotContains('memberlist-test-user', $this->get_crawler_table_text($crawler, 1)); + $this->assertNotContains('memberlist-test-user', $crawler->eq(0)->text()); + $this->assertNotContains('memberlist-test-user', $crawler->eq(1)->text()); // memberlist-test-moderator in neither group - $this->assertNotContains('memberlist-test-moderator', $this->get_crawler_table_text($crawler, 0)); - $this->assertNotContains('memberlist-test-moderator', $this->get_crawler_table_text($crawler, 1)); + $this->assertNotContains('memberlist-test-moderator', $crawler->eq(0)->text()); + $this->assertNotContains('memberlist-test-moderator', $crawler->eq(1)->text()); } public function test_leaders_remove_users() @@ -80,15 +75,15 @@ class phpbb_functional_memberlist_test extends phpbb_functional_test_case // Remove admin from admins, but is now in moderators $this->remove_user_group('ADMINISTRATORS', array('admin')); - $crawler = $this->get_memberlist_leaders_crawler(); - $this->assertNotContains('admin', $this->get_crawler_table_text($crawler, 0)); - $this->assertContains('admin', $this->get_crawler_table_text($crawler, 1)); + $crawler = $this->get_memberlist_leaders_table_crawler(); + $this->assertNotContains('admin', $crawler->eq(0)->text()); + $this->assertContains('admin', $crawler->eq(1)->text()); // Remove admin from moderators, should not be visible anymore $this->remove_user_group('GLOBAL_MODERATORS', array('admin')); - $crawler = $this->get_memberlist_leaders_crawler(); - $this->assertNotContains('admin', $this->get_crawler_table_text($crawler, 0)); - $this->assertNotContains('admin', $this->get_crawler_table_text($crawler, 1)); + $crawler = $this->get_memberlist_leaders_table_crawler(); + $this->assertNotContains('admin', $crawler->eq(0)->text()); + $this->assertNotContains('admin', $crawler->eq(1)->text()); } public function test_leaders_add_users() @@ -97,8 +92,8 @@ class phpbb_functional_memberlist_test extends phpbb_functional_test_case // Add memberlist-test-moderator to moderators $this->add_user_group('GLOBAL_MODERATORS', array('memberlist-test-moderator')); - $crawler = $this->get_memberlist_leaders_crawler(); - $this->assertNotContains('memberlist-test-moderator', $this->get_crawler_table_text($crawler, 0)); - $this->assertContains('memberlist-test-moderator', $this->get_crawler_table_text($crawler, 1)); + $crawler = $this->get_memberlist_leaders_table_crawler(); + $this->assertNotContains('memberlist-test-moderator', $crawler->eq(0)->text()); + $this->assertContains('memberlist-test-moderator', $crawler->eq(1)->text()); } } -- cgit v1.2.1 From 82a630cd648b193079cd147144ad5b035450d824 Mon Sep 17 00:00:00 2001 From: Dhruv Date: Mon, 15 Apr 2013 20:41:05 +0530 Subject: [ticket/11493] add check for phpBB Debug in functional tests PHPBB3-11493 --- tests/test_framework/phpbb_functional_test_case.php | 1 + 1 file changed, 1 insertion(+) (limited to 'tests') diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index 8ab6469e9a..c600cba5f8 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -349,5 +349,6 @@ class phpbb_functional_test_case extends phpbb_test_case $this->assertEquals(200, $this->client->getResponse()->getStatus()); $content = $this->client->getResponse()->getContent(); $this->assertNotContains('Fatal error:', $content); + $this->assertNotContains('[phpBB Debug]', $content); } } -- cgit v1.2.1 From 14071e6085d55f459728ade117ff93b3957045d2 Mon Sep 17 00:00:00 2001 From: Dhruv Date: Mon, 15 Apr 2013 22:02:21 +0530 Subject: [ticket/11493] add checks for Notice and Warning PHPBB3-11493 --- tests/test_framework/phpbb_functional_test_case.php | 2 ++ 1 file changed, 2 insertions(+) (limited to 'tests') diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index c600cba5f8..83c931f924 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -349,6 +349,8 @@ class phpbb_functional_test_case extends phpbb_test_case $this->assertEquals(200, $this->client->getResponse()->getStatus()); $content = $this->client->getResponse()->getContent(); $this->assertNotContains('Fatal error:', $content); + $this->assertNotContains('Notice:', $content); + $this->assertNotContains('Warning:', $content); $this->assertNotContains('[phpBB Debug]', $content); } } -- cgit v1.2.1 From dcee7961e80a0d188d887a13cc6409623bc1ff6e Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 16 Apr 2013 23:09:56 +0200 Subject: [ticket/11495] Add unit tests for the implemented functions PHPBB3-11495 --- tests/nestedset/fixtures/phpbb_forums.xml | 123 ++++++ tests/nestedset/item_forum_test.php | 31 ++ tests/nestedset/set_forum_add_remove_test.php | 195 +++++++++ tests/nestedset/set_forum_base.php | 61 +++ tests/nestedset/set_forum_get_data_test.php | 96 +++++ tests/nestedset/set_forum_move_test.php | 565 +++++++++++++++++++++++++ tests/nestedset/set_forum_recalculate_test.php | 72 ++++ tests/nestedset/set_forum_test.php | 116 +++++ 8 files changed, 1259 insertions(+) create mode 100644 tests/nestedset/fixtures/phpbb_forums.xml create mode 100644 tests/nestedset/item_forum_test.php create mode 100644 tests/nestedset/set_forum_add_remove_test.php create mode 100644 tests/nestedset/set_forum_base.php create mode 100644 tests/nestedset/set_forum_get_data_test.php create mode 100644 tests/nestedset/set_forum_move_test.php create mode 100644 tests/nestedset/set_forum_recalculate_test.php create mode 100644 tests/nestedset/set_forum_test.php (limited to 'tests') diff --git a/tests/nestedset/fixtures/phpbb_forums.xml b/tests/nestedset/fixtures/phpbb_forums.xml new file mode 100644 index 0000000000..016c8ea7c5 --- /dev/null +++ b/tests/nestedset/fixtures/phpbb_forums.xml @@ -0,0 +1,123 @@ + + + + forum_id + parent_id + left_id + right_id + forum_parents + forum_name + forum_desc + forum_rules + + 1 + 0 + 1 + 6 + + Parent with two flat children + + + + + 2 + 1 + 2 + 3 + + Flat child #1 + + + + + 3 + 1 + 4 + 5 + + Flat child #2 + + + + + 4 + 0 + 7 + 12 + + Parent with two nested children + + + + + 5 + 4 + 8 + 11 + + Nested child #1 + + + + + 6 + 5 + 9 + 10 + + Nested child #2 + + + + + 7 + 0 + 13 + 22 + + Parent with flat and nested children + + + + + 8 + 7 + 14 + 15 + + Mixed child #1 + + + + + 9 + 7 + 16 + 19 + + Mixed child #2 + + + + + 10 + 9 + 17 + 18 + + Nested child #1 of Mixed child #2 + + + + + 11 + 7 + 20 + 21 + + Mixed child #3 + + + +
+
diff --git a/tests/nestedset/item_forum_test.php b/tests/nestedset/item_forum_test.php new file mode 100644 index 0000000000..1ca89ebd2f --- /dev/null +++ b/tests/nestedset/item_forum_test.php @@ -0,0 +1,31 @@ + 1, + 'forum_id' => 5, + 'user_id' => 32, + 'left_id' => 2, + 'right_id' => 3, + 'forum_parents' => '', + ); + + $forum = new phpbb_nestedset_item_forum($forum_data); + + $this->assertEquals($forum->get_item_id(), $forum_data['forum_id']); + $this->assertEquals($forum->get_left_id(), $forum_data['left_id']); + $this->assertEquals($forum->get_right_id(), $forum_data['right_id']); + $this->assertEquals($forum->get_parent_id(), $forum_data['parent_id']); + $this->assertEquals($forum->get_item_parents_data(), $forum_data['forum_parents']); + } +} diff --git a/tests/nestedset/set_forum_add_remove_test.php b/tests/nestedset/set_forum_add_remove_test.php new file mode 100644 index 0000000000..f7d4980292 --- /dev/null +++ b/tests/nestedset/set_forum_add_remove_test.php @@ -0,0 +1,195 @@ + 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) + { + $forum = new phpbb_nestedset_item_forum($this->forum_data[$forum_id]); + + $removed_items = $this->set->remove($forum); + + $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) + { + $forum = new phpbb_nestedset_item_forum($this->forum_data[$item_id]); + $added_items[$item_id] = $this->set->add($forum); + } + $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) + { + $forum = new phpbb_nestedset_item_forum($this->forum_data[$forum_id]); + + $this->assertEquals($expected_deleted, $this->set->delete($forum)); + + $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/nestedset/set_forum_base.php b/tests/nestedset/set_forum_base.php new file mode 100644 index 0000000000..4523f12897 --- /dev/null +++ b/tests/nestedset/set_forum_base.php @@ -0,0 +1,61 @@ +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_nestedset_forum($this->db, $this->lock, 'phpbb_forums'); + } +} diff --git a/tests/nestedset/set_forum_get_data_test.php b/tests/nestedset/set_forum_get_data_test.php new file mode 100644 index 0000000000..b7314efd15 --- /dev/null +++ b/tests/nestedset/set_forum_get_data_test.php @@ -0,0 +1,96 @@ +forum_data[$forum_id]); + + $this->assertEquals($expected, array_keys($this->set->get_branch_data($forum, $type, $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) + { + $data = array_merge($this->forum_data[$forum_id], $forum_data); + $forum = new phpbb_nestedset_item_forum($data); + + $this->assertEquals($expected, array_keys($this->set->get_parent_data($forum))); + } +} diff --git a/tests/nestedset/set_forum_move_test.php b/tests/nestedset/set_forum_move_test.php new file mode 100644 index 0000000000..7e1c03e60f --- /dev/null +++ b/tests/nestedset/set_forum_move_test.php @@ -0,0 +1,565 @@ + 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) + { + $forum = new phpbb_nestedset_item_forum($this->forum_data[$forum_id]); + + $this->assertEquals($expected_moved, $this->set->move($forum, $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) + { + $forum = new phpbb_nestedset_item_forum($this->forum_data[$forum_id]); + + $this->assertEquals($expected_moved, $this->set->move_down($forum)); + + $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) + { + $forum = new phpbb_nestedset_item_forum($this->forum_data[$forum_id]); + + $this->assertEquals($expected_moved, $this->set->move_up($forum)); + + $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('Parent is 0', + 0, 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 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) + { + $forum = new phpbb_nestedset_item_forum($this->forum_data[$forum_id]); + $target = new phpbb_nestedset_item_forum($this->forum_data[$target_id]); + + $this->assertEquals($expected_moved, $this->set->move_children($forum, $target)); + + $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_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_data + * + * @expectedException phpbb_nestedset_exception + * @expectedExceptionMessage FORUM_NESTEDSET_INVALID_PARENT + */ + public function test_move_children_throws($explain, $forum_id, $target_id) + { + $forum = new phpbb_nestedset_item_forum($this->forum_data[$forum_id]); + $target = new phpbb_nestedset_item_forum($this->forum_data[$target_id]); + + $this->set->move_children($forum, $target); + } + + public function set_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 set_parent_data + */ + public function test_set_parent($explain, $forum_id, $target_id, $expected_moved, $expected) + { + $forum = new phpbb_nestedset_item_forum($this->forum_data[$forum_id]); + $target = new phpbb_nestedset_item_forum($this->forum_data[$target_id]); + + $this->assertEquals($expected_moved, $this->set->set_parent($forum, $target)); + + $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 set_parent_throws_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 set_parent_throws_data + * + * @expectedException phpbb_nestedset_exception + * @expectedExceptionMessage FORUM_NESTEDSET_INVALID_PARENT + */ + public function test_set_parent_throws($explain, $forum_id, $target_id) + { + $forum = new phpbb_nestedset_item_forum($this->forum_data[$forum_id]); + $target = new phpbb_nestedset_item_forum($this->forum_data[$target_id]); + + $this->set->set_parent($forum, $target); + } +} diff --git a/tests/nestedset/set_forum_recalculate_test.php b/tests/nestedset/set_forum_recalculate_test.php new file mode 100644 index 0000000000..6ff7a372a4 --- /dev/null +++ b/tests/nestedset/set_forum_recalculate_test.php @@ -0,0 +1,72 @@ + 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 recalculate_nested_set_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 recalculate_nested_set_data + */ + public function test_recalculate_nested_set($breaking_query, $reset_ids) + { + $result = $this->db->sql_query($breaking_query); + + $this->assertEquals(23, $this->set->recalculate_nested_set(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/nestedset/set_forum_test.php b/tests/nestedset/set_forum_test.php new file mode 100644 index 0000000000..ab4da1ff1e --- /dev/null +++ b/tests/nestedset/set_forum_test.php @@ -0,0 +1,116 @@ + 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)); + } +} -- cgit v1.2.1 From 869e00a23b0400b9ad81c1130227cc4c29d6a38d Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 17 Apr 2013 17:45:49 +0200 Subject: [ticket/11362] Move phpbb_clean_path into a simple filesystem service PHPBB3-11362 --- tests/filesystem/clean_path_test.php | 48 ++++++++++++++++++++++++++++++++++++ tests/functions/clean_path_test.php | 44 --------------------------------- 2 files changed, 48 insertions(+), 44 deletions(-) create mode 100644 tests/filesystem/clean_path_test.php delete mode 100644 tests/functions/clean_path_test.php (limited to 'tests') diff --git a/tests/filesystem/clean_path_test.php b/tests/filesystem/clean_path_test.php new file mode 100644 index 0000000000..50951fc88c --- /dev/null +++ b/tests/filesystem/clean_path_test.php @@ -0,0 +1,48 @@ +filesystem = new phpbb_filesystem(); + } + + public function clean_path_data() + { + return array( + array('foo', 'foo'), + array('foo/bar', 'foo/bar'), + array('foo/bar/', 'foo/bar/'), + array('foo/./bar', 'foo/bar'), + array('foo/./././bar', 'foo/bar'), + array('foo/bar/.', 'foo/bar'), + array('./foo/bar', './foo/bar'), + array('../foo/bar', '../foo/bar'), + array('one/two/three', 'one/two/three'), + array('one/two/../three', 'one/three'), + array('one/../two/three', 'two/three'), + array('one/two/..', 'one'), + array('one/two/../', 'one/'), + array('one/two/../three/../four', 'one/four'), + array('one/two/three/../../four', 'one/four'), + ); + } + + /** + * @dataProvider clean_path_data + */ + public function test_clean_path($input, $expected) + { + $this->assertEquals($expected, $this->filesystem->clean_path($input)); + } +} diff --git a/tests/functions/clean_path_test.php b/tests/functions/clean_path_test.php deleted file mode 100644 index bcbe9838d9..0000000000 --- a/tests/functions/clean_path_test.php +++ /dev/null @@ -1,44 +0,0 @@ -assertEquals($expected, $output); - } -} -- cgit v1.2.1 From 423b310e2acbbc72814a4278a4cccf2900114f85 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 17 Apr 2013 18:43:19 +0200 Subject: [ticket/11362] Extension manager depends on filesystem PHPBB3-11362 --- tests/dbal/migrator_test.php | 1 + tests/extension/finder_test.php | 3 ++- tests/extension/manager_test.php | 1 + tests/extension/metadata_manager_test.php | 1 + tests/mock/extension_manager.php | 1 + tests/test_framework/phpbb_functional_test_case.php | 1 + 6 files changed, 7 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/dbal/migrator_test.php b/tests/dbal/migrator_test.php index 89669b85ec..745d260b38 100644 --- a/tests/dbal/migrator_test.php +++ b/tests/dbal/migrator_test.php @@ -60,6 +60,7 @@ class phpbb_dbal_migrator_test extends phpbb_database_test_case $this->db, $this->config, $this->migrator, + new phpbb_filesystem(), 'phpbb_ext', dirname(__FILE__) . '/../../phpBB/', '.php', diff --git a/tests/extension/finder_test.php b/tests/extension/finder_test.php index 3781591b19..73c07ef79a 100644 --- a/tests/extension/finder_test.php +++ b/tests/extension/finder_test.php @@ -164,7 +164,7 @@ class phpbb_extension_finder_test extends phpbb_test_case public function test_get_classes_create_cache() { $cache = new phpbb_mock_cache; - $finder = new phpbb_extension_finder($this->extension_manager, dirname(__FILE__) . '/', $cache, '.php', '_custom_cache_name'); + $finder = new phpbb_extension_finder($this->extension_manager, new phpbb_filesystem(), dirname(__FILE__) . '/', $cache, '.php', '_custom_cache_name'); $files = $finder->suffix('_class.php')->get_files(); $expected_files = array( @@ -204,6 +204,7 @@ class phpbb_extension_finder_test extends phpbb_test_case $finder = new phpbb_extension_finder( $this->extension_manager, + new phpbb_filesystem(), dirname(__FILE__) . '/', new phpbb_mock_cache(array( '_ext_finder' => array( diff --git a/tests/extension/manager_test.php b/tests/extension/manager_test.php index 1f311116f4..d6bcb97586 100644 --- a/tests/extension/manager_test.php +++ b/tests/extension/manager_test.php @@ -112,6 +112,7 @@ class phpbb_extension_manager_test extends phpbb_database_test_case $db, $config, $migrator, + new phpbb_filesystem(), 'phpbb_ext', dirname(__FILE__) . '/', '.' . $php_ext, diff --git a/tests/extension/metadata_manager_test.php b/tests/extension/metadata_manager_test.php index 081a32e277..df7817b479 100644 --- a/tests/extension/metadata_manager_test.php +++ b/tests/extension/metadata_manager_test.php @@ -64,6 +64,7 @@ class metadata_manager_test extends phpbb_database_test_case $this->db, $this->config, $this->migrator, + new phpbb_filesystem(), 'phpbb_ext', $this->phpbb_root_path, $this->phpEx, diff --git a/tests/mock/extension_manager.php b/tests/mock/extension_manager.php index fdda4cbadc..954f2bf1c4 100644 --- a/tests/mock/extension_manager.php +++ b/tests/mock/extension_manager.php @@ -14,5 +14,6 @@ class phpbb_mock_extension_manager extends phpbb_extension_manager $this->phpbb_root_path = $phpbb_root_path; $this->php_ext = '.php'; $this->extensions = $extensions; + $this->filesystem = new phpbb_filesystem(); } } diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index 887dfea3b5..891fe237b3 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -153,6 +153,7 @@ class phpbb_functional_test_case extends phpbb_test_case $db, $config, $migrator, + new phpbb_filesystem(), self::$config['table_prefix'] . 'ext', dirname(__FILE__) . '/', '.' . $php_ext, -- cgit v1.2.1 From d11fed65da00297084c6f5e9799e5a544ad76e9b Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 18 Apr 2013 00:33:48 +0200 Subject: [ticket/11495] Remove item class from unit tests PHPBB3-11495 --- tests/nestedset/item_forum_test.php | 31 -------------------------- tests/nestedset/set_forum_add_remove_test.php | 17 +++++++------- tests/nestedset/set_forum_get_data_test.php | 9 ++------ tests/nestedset/set_forum_move_test.php | 32 ++++++--------------------- 4 files changed, 18 insertions(+), 71 deletions(-) delete mode 100644 tests/nestedset/item_forum_test.php (limited to 'tests') diff --git a/tests/nestedset/item_forum_test.php b/tests/nestedset/item_forum_test.php deleted file mode 100644 index 1ca89ebd2f..0000000000 --- a/tests/nestedset/item_forum_test.php +++ /dev/null @@ -1,31 +0,0 @@ - 1, - 'forum_id' => 5, - 'user_id' => 32, - 'left_id' => 2, - 'right_id' => 3, - 'forum_parents' => '', - ); - - $forum = new phpbb_nestedset_item_forum($forum_data); - - $this->assertEquals($forum->get_item_id(), $forum_data['forum_id']); - $this->assertEquals($forum->get_left_id(), $forum_data['left_id']); - $this->assertEquals($forum->get_right_id(), $forum_data['right_id']); - $this->assertEquals($forum->get_parent_id(), $forum_data['parent_id']); - $this->assertEquals($forum->get_item_parents_data(), $forum_data['forum_parents']); - } -} diff --git a/tests/nestedset/set_forum_add_remove_test.php b/tests/nestedset/set_forum_add_remove_test.php index f7d4980292..53fc23594a 100644 --- a/tests/nestedset/set_forum_add_remove_test.php +++ b/tests/nestedset/set_forum_add_remove_test.php @@ -78,9 +78,7 @@ class phpbb_tests_nestedset_set_forum_add_remove_test extends phpbb_tests_nested */ public function test_remove_add($forum_id, $expected_removed, $expected_remove_table, $expected_added, $expected_add_table) { - $forum = new phpbb_nestedset_item_forum($this->forum_data[$forum_id]); - - $removed_items = $this->set->remove($forum); + $removed_items = $this->set->remove($this->forum_data[$forum_id]); $this->assertEquals($expected_removed, $removed_items); @@ -92,8 +90,13 @@ class phpbb_tests_nestedset_set_forum_add_remove_test extends phpbb_tests_nested $added_items = array(); foreach ($removed_items as $item_id) { - $forum = new phpbb_nestedset_item_forum($this->forum_data[$item_id]); - $added_items[$item_id] = $this->set->add($forum); + $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); @@ -136,9 +139,7 @@ class phpbb_tests_nestedset_set_forum_add_remove_test extends phpbb_tests_nested */ public function test_delete($forum_id, $expected_deleted, $expected) { - $forum = new phpbb_nestedset_item_forum($this->forum_data[$forum_id]); - - $this->assertEquals($expected_deleted, $this->set->delete($forum)); + $this->assertEquals($expected_deleted, $this->set->delete($this->forum_data[$forum_id])); $result = $this->db->sql_query("SELECT forum_id, parent_id, left_id, right_id, forum_parents FROM phpbb_forums diff --git a/tests/nestedset/set_forum_get_data_test.php b/tests/nestedset/set_forum_get_data_test.php index b7314efd15..b537d0a062 100644 --- a/tests/nestedset/set_forum_get_data_test.php +++ b/tests/nestedset/set_forum_get_data_test.php @@ -66,9 +66,7 @@ class phpbb_tests_nestedset_set_forum_get_data_test extends phpbb_tests_nestedse */ public function test_get_branch_data($forum_id, $type, $order_desc, $include_item, $expected) { - $forum = new phpbb_nestedset_item_forum($this->forum_data[$forum_id]); - - $this->assertEquals($expected, array_keys($this->set->get_branch_data($forum, $type, $order_desc, $include_item))); + $this->assertEquals($expected, array_keys($this->set->get_branch_data($this->forum_data[$forum_id], $type, $order_desc, $include_item))); } public function get_parent_data_data() @@ -88,9 +86,6 @@ class phpbb_tests_nestedset_set_forum_get_data_test extends phpbb_tests_nestedse */ public function test_get_parent_data($forum_id, $forum_data, $expected) { - $data = array_merge($this->forum_data[$forum_id], $forum_data); - $forum = new phpbb_nestedset_item_forum($data); - - $this->assertEquals($expected, array_keys($this->set->get_parent_data($forum))); + $this->assertEquals($expected, array_keys($this->set->get_parent_data(array_merge($this->forum_data[$forum_id], $forum_data)))); } } diff --git a/tests/nestedset/set_forum_move_test.php b/tests/nestedset/set_forum_move_test.php index 7e1c03e60f..b90eaa12ad 100644 --- a/tests/nestedset/set_forum_move_test.php +++ b/tests/nestedset/set_forum_move_test.php @@ -120,9 +120,7 @@ class phpbb_tests_nestedset_set_forum_move_test extends phpbb_tests_nestedset_se */ public function test_move($explain, $forum_id, $delta, $expected_moved, $expected) { - $forum = new phpbb_nestedset_item_forum($this->forum_data[$forum_id]); - - $this->assertEquals($expected_moved, $this->set->move($forum, $delta)); + $this->assertEquals($expected_moved, $this->set->move($this->forum_data[$forum_id], $delta)); $result = $this->db->sql_query("SELECT forum_id, parent_id, left_id, right_id, forum_parents FROM phpbb_forums @@ -169,9 +167,7 @@ class phpbb_tests_nestedset_set_forum_move_test extends phpbb_tests_nestedset_se */ public function test_move_down($explain, $forum_id, $expected_moved, $expected) { - $forum = new phpbb_nestedset_item_forum($this->forum_data[$forum_id]); - - $this->assertEquals($expected_moved, $this->set->move_down($forum)); + $this->assertEquals($expected_moved, $this->set->move_down($this->forum_data[$forum_id])); $result = $this->db->sql_query("SELECT forum_id, parent_id, left_id, right_id, forum_parents FROM phpbb_forums @@ -218,9 +214,7 @@ class phpbb_tests_nestedset_set_forum_move_test extends phpbb_tests_nestedset_se */ public function test_move_up($explain, $forum_id, $expected_moved, $expected) { - $forum = new phpbb_nestedset_item_forum($this->forum_data[$forum_id]); - - $this->assertEquals($expected_moved, $this->set->move_up($forum)); + $this->assertEquals($expected_moved, $this->set->move_up($this->forum_data[$forum_id])); $result = $this->db->sql_query("SELECT forum_id, parent_id, left_id, right_id, forum_parents FROM phpbb_forums @@ -386,10 +380,7 @@ class phpbb_tests_nestedset_set_forum_move_test extends phpbb_tests_nestedset_se */ public function test_move_children($explain, $forum_id, $target_id, $expected_moved, $expected) { - $forum = new phpbb_nestedset_item_forum($this->forum_data[$forum_id]); - $target = new phpbb_nestedset_item_forum($this->forum_data[$target_id]); - - $this->assertEquals($expected_moved, $this->set->move_children($forum, $target)); + $this->assertEquals($expected_moved, $this->set->move_children($this->forum_data[$forum_id], $this->forum_data[$target_id])); $result = $this->db->sql_query("SELECT forum_id, parent_id, left_id, right_id, forum_parents FROM phpbb_forums @@ -414,10 +405,7 @@ class phpbb_tests_nestedset_set_forum_move_test extends phpbb_tests_nestedset_se */ public function test_move_children_throws($explain, $forum_id, $target_id) { - $forum = new phpbb_nestedset_item_forum($this->forum_data[$forum_id]); - $target = new phpbb_nestedset_item_forum($this->forum_data[$target_id]); - - $this->set->move_children($forum, $target); + $this->set->move_children($this->forum_data[$forum_id], $this->forum_data[$target_id]); } public function set_parent_data() @@ -529,10 +517,7 @@ class phpbb_tests_nestedset_set_forum_move_test extends phpbb_tests_nestedset_se */ public function test_set_parent($explain, $forum_id, $target_id, $expected_moved, $expected) { - $forum = new phpbb_nestedset_item_forum($this->forum_data[$forum_id]); - $target = new phpbb_nestedset_item_forum($this->forum_data[$target_id]); - - $this->assertEquals($expected_moved, $this->set->set_parent($forum, $target)); + $this->assertEquals($expected_moved, $this->set->set_parent($this->forum_data[$forum_id], $this->forum_data[$target_id])); $result = $this->db->sql_query("SELECT forum_id, parent_id, left_id, right_id, forum_parents FROM phpbb_forums @@ -557,9 +542,6 @@ class phpbb_tests_nestedset_set_forum_move_test extends phpbb_tests_nestedset_se */ public function test_set_parent_throws($explain, $forum_id, $target_id) { - $forum = new phpbb_nestedset_item_forum($this->forum_data[$forum_id]); - $target = new phpbb_nestedset_item_forum($this->forum_data[$target_id]); - - $this->set->set_parent($forum, $target); + $this->set->set_parent($this->forum_data[$forum_id], $this->forum_data[$target_id]); } } -- cgit v1.2.1 From 845832820ba89a0f33e264a34639a05045783397 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 19 Apr 2013 01:48:31 +0200 Subject: [ticket/11501] Assert the variables instead of fail() with the condition PHPBB3-11501 --- tests/dbal/migrator_test.php | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) (limited to 'tests') diff --git a/tests/dbal/migrator_test.php b/tests/dbal/migrator_test.php index 89669b85ec..0d7fc2f839 100644 --- a/tests/dbal/migrator_test.php +++ b/tests/dbal/migrator_test.php @@ -144,15 +144,8 @@ class phpbb_dbal_migrator_test extends phpbb_database_test_case $this->migrator->update(); } - if ($migrator_test_if_true_failed) - { - $this->fail('True test failed'); - } - - if ($migrator_test_if_false_failed) - { - $this->fail('False test failed'); - } + $this->assertFalse($migrator_test_if_true_failed, 'True test failed'); + $this->assertFalse($migrator_test_if_false_failed, 'False test failed'); } public function test_recall() -- cgit v1.2.1 From 1431a027563b717183937751970f52cc0a4c94fe Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 19 Apr 2013 01:49:35 +0200 Subject: [ticket/11501] Remove test_ prefix from data provider methods PHPBB3-11501 --- tests/log/function_add_log_test.php | 4 ++-- tests/log/function_view_log_test.php | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'tests') diff --git a/tests/log/function_add_log_test.php b/tests/log/function_add_log_test.php index 864b364862..7aa42be6df 100644 --- a/tests/log/function_add_log_test.php +++ b/tests/log/function_add_log_test.php @@ -16,7 +16,7 @@ class phpbb_log_function_add_log_test extends phpbb_database_test_case return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/empty_log.xml'); } - public static function test_add_log_function_data() + public static function add_log_function_data() { return array( /** @@ -138,7 +138,7 @@ class phpbb_log_function_add_log_test extends phpbb_database_test_case } /** - * @dataProvider test_add_log_function_data + * @dataProvider add_log_function_data */ public function test_add_log_function($expected, $user_id, $mode, $required1, $additional1 = null, $additional2 = null, $additional3 = null) { diff --git a/tests/log/function_view_log_test.php b/tests/log/function_view_log_test.php index 2ecf77aeb8..1ab9488568 100644 --- a/tests/log/function_view_log_test.php +++ b/tests/log/function_view_log_test.php @@ -22,7 +22,7 @@ class phpbb_log_function_view_log_test extends phpbb_database_test_case return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/full_log.xml'); } - public static function test_view_log_function_data() + public static function view_log_function_data() { global $phpEx, $phpbb_dispatcher; $phpbb_dispatcher = new phpbb_mock_event_dispatcher(); @@ -296,7 +296,7 @@ class phpbb_log_function_view_log_test extends phpbb_database_test_case } /** - * @dataProvider test_view_log_function_data + * @dataProvider view_log_function_data */ public function test_view_log_function($expected, $expected_returned, $mode, $log_count, $limit = 5, $offset = 0, $forum_id = 0, $topic_id = 0, $user_id = 0, $limit_days = 0, $sort_by = 'l.log_id ASC', $keywords = '') { -- cgit v1.2.1 From d24ff2329fe145864712cb37ec19183bd4e21a42 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 19 Apr 2013 16:18:03 +0200 Subject: [ticket/11495] Use item_id only as parameter for get_branch_data() PHPBB3-11495 --- tests/nestedset/set_forum_get_data_test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/nestedset/set_forum_get_data_test.php b/tests/nestedset/set_forum_get_data_test.php index b537d0a062..2c8889d1a5 100644 --- a/tests/nestedset/set_forum_get_data_test.php +++ b/tests/nestedset/set_forum_get_data_test.php @@ -66,7 +66,7 @@ class phpbb_tests_nestedset_set_forum_get_data_test extends phpbb_tests_nestedse */ public function test_get_branch_data($forum_id, $type, $order_desc, $include_item, $expected) { - $this->assertEquals($expected, array_keys($this->set->get_branch_data($this->forum_data[$forum_id], $type, $order_desc, $include_item))); + $this->assertEquals($expected, array_keys($this->set->get_branch_data($forum_id, $type, $order_desc, $include_item))); } public function get_parent_data_data() -- cgit v1.2.1 From 3d54a81ed9394f13aff4c40d524ed7cff0546604 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 19 Apr 2013 16:19:01 +0200 Subject: [ticket/11495] Use item_id only as parameter for delete() and remove() The data is acquired again anyway PHPBB3-11495 --- tests/nestedset/set_forum_add_remove_test.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/nestedset/set_forum_add_remove_test.php b/tests/nestedset/set_forum_add_remove_test.php index 53fc23594a..97b6348d67 100644 --- a/tests/nestedset/set_forum_add_remove_test.php +++ b/tests/nestedset/set_forum_add_remove_test.php @@ -78,7 +78,7 @@ class phpbb_tests_nestedset_set_forum_add_remove_test extends phpbb_tests_nested */ public function test_remove_add($forum_id, $expected_removed, $expected_remove_table, $expected_added, $expected_add_table) { - $removed_items = $this->set->remove($this->forum_data[$forum_id]); + $removed_items = $this->set->remove($forum_id); $this->assertEquals($expected_removed, $removed_items); @@ -139,7 +139,7 @@ class phpbb_tests_nestedset_set_forum_add_remove_test extends phpbb_tests_nested */ public function test_delete($forum_id, $expected_deleted, $expected) { - $this->assertEquals($expected_deleted, $this->set->delete($this->forum_data[$forum_id])); + $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 -- cgit v1.2.1 From 87dc3b1e55bcfcade98eedfaa07e77c454dd7d4f Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 19 Apr 2013 21:07:42 +0200 Subject: [ticket/11495] Use item ids instead of requiring all data The data is grabbed again in most cases anyway, so it just makes the system easier to use. PHPBB3-11495 --- tests/nestedset/set_forum_move_test.php | 80 +++++++++++++++++++++------------ 1 file changed, 51 insertions(+), 29 deletions(-) (limited to 'tests') diff --git a/tests/nestedset/set_forum_move_test.php b/tests/nestedset/set_forum_move_test.php index b90eaa12ad..9a19d18476 100644 --- a/tests/nestedset/set_forum_move_test.php +++ b/tests/nestedset/set_forum_move_test.php @@ -120,7 +120,7 @@ class phpbb_tests_nestedset_set_forum_move_test extends phpbb_tests_nestedset_se */ public function test_move($explain, $forum_id, $delta, $expected_moved, $expected) { - $this->assertEquals($expected_moved, $this->set->move($this->forum_data[$forum_id], $delta)); + $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 @@ -167,7 +167,7 @@ class phpbb_tests_nestedset_set_forum_move_test extends phpbb_tests_nestedset_se */ public function test_move_down($explain, $forum_id, $expected_moved, $expected) { - $this->assertEquals($expected_moved, $this->set->move_down($this->forum_data[$forum_id])); + $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 @@ -214,7 +214,7 @@ class phpbb_tests_nestedset_set_forum_move_test extends phpbb_tests_nestedset_se */ public function test_move_up($explain, $forum_id, $expected_moved, $expected) { - $this->assertEquals($expected_moved, $this->set->move_up($this->forum_data[$forum_id])); + $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 @@ -257,22 +257,6 @@ class phpbb_tests_nestedset_set_forum_move_test extends phpbb_tests_nestedset_se 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('Parent is 0', - 0, 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 single child up', 5, 1, true, array( array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 8, 'forum_parents' => ''), @@ -380,7 +364,7 @@ class phpbb_tests_nestedset_set_forum_move_test extends phpbb_tests_nestedset_se */ public function test_move_children($explain, $forum_id, $target_id, $expected_moved, $expected) { - $this->assertEquals($expected_moved, $this->set->move_children($this->forum_data[$forum_id], $this->forum_data[$target_id])); + $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 @@ -388,7 +372,26 @@ class phpbb_tests_nestedset_set_forum_move_test extends phpbb_tests_nestedset_se $this->assertEquals($expected, $this->db->sql_fetchrowset($result)); } - public function move_children_throws_data() + 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 phpbb_nestedset_exception + * @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), @@ -398,14 +401,14 @@ class phpbb_tests_nestedset_set_forum_move_test extends phpbb_tests_nestedset_se } /** - * @dataProvider move_children_throws_data + * @dataProvider move_children_throws_parent_data * * @expectedException phpbb_nestedset_exception * @expectedExceptionMessage FORUM_NESTEDSET_INVALID_PARENT */ - public function test_move_children_throws($explain, $forum_id, $target_id) + public function test_move_children_throws_parent($explain, $forum_id, $target_id) { - $this->set->move_children($this->forum_data[$forum_id], $this->forum_data[$target_id]); + $this->set->move_children($forum_id, $target_id); } public function set_parent_data() @@ -517,7 +520,7 @@ class phpbb_tests_nestedset_set_forum_move_test extends phpbb_tests_nestedset_se */ public function test_set_parent($explain, $forum_id, $target_id, $expected_moved, $expected) { - $this->assertEquals($expected_moved, $this->set->set_parent($this->forum_data[$forum_id], $this->forum_data[$target_id])); + $this->assertEquals($expected_moved, $this->set->set_parent($forum_id, $target_id)); $result = $this->db->sql_query("SELECT forum_id, parent_id, left_id, right_id, forum_parents FROM phpbb_forums @@ -525,7 +528,26 @@ class phpbb_tests_nestedset_set_forum_move_test extends phpbb_tests_nestedset_se $this->assertEquals($expected, $this->db->sql_fetchrowset($result)); } - public function set_parent_throws_data() + public function set_parent_throws_item_data() + { + return array( + array('Item 0 does not exist', 0, 5), + array('Item does not exist', 200, 5), + ); + } + + /** + * @dataProvider set_parent_throws_item_data + * + * @expectedException phpbb_nestedset_exception + * @expectedExceptionMessage FORUM_NESTEDSET_INVALID_ITEM + */ + public function test_set_parent_throws_item($explain, $forum_id, $target_id) + { + $this->set->set_parent($forum_id, $target_id); + } + + public function set_parent_throws_parent_data() { return array( array('New parent is child', 4, 5), @@ -535,13 +557,13 @@ class phpbb_tests_nestedset_set_forum_move_test extends phpbb_tests_nestedset_se } /** - * @dataProvider set_parent_throws_data + * @dataProvider set_parent_throws_parent_data * * @expectedException phpbb_nestedset_exception * @expectedExceptionMessage FORUM_NESTEDSET_INVALID_PARENT */ - public function test_set_parent_throws($explain, $forum_id, $target_id) + public function test_set_parent_throws_parent($explain, $forum_id, $target_id) { - $this->set->set_parent($this->forum_data[$forum_id], $this->forum_data[$target_id]); + $this->set->set_parent($forum_id, $target_id); } } -- cgit v1.2.1 From 12c432c5230db49b659498ea4fc3ff8766a0e87f Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Mon, 22 Apr 2013 00:23:49 +0200 Subject: [ticket/10844] Add extension template file to locate PHPBB3-10844 --- tests/extension/ext/bar/styles/prosilver/template/foobar_body.html | 1 + 1 file changed, 1 insertion(+) create mode 100644 tests/extension/ext/bar/styles/prosilver/template/foobar_body.html (limited to 'tests') diff --git a/tests/extension/ext/bar/styles/prosilver/template/foobar_body.html b/tests/extension/ext/bar/styles/prosilver/template/foobar_body.html new file mode 100644 index 0000000000..00c2a84a18 --- /dev/null +++ b/tests/extension/ext/bar/styles/prosilver/template/foobar_body.html @@ -0,0 +1 @@ +bertie rules! -- cgit v1.2.1 From 10781ce9ae74efd4f04063c78235f4be031b414a Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Mon, 22 Apr 2013 00:24:30 +0200 Subject: [ticket/10844] Increase prefix to not match template/ in finder test PHPBB3-10844 --- tests/extension/finder_test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/extension/finder_test.php b/tests/extension/finder_test.php index c96b11a73c..c2ac88a76a 100644 --- a/tests/extension/finder_test.php +++ b/tests/extension/finder_test.php @@ -66,7 +66,7 @@ class phpbb_extension_finder_test extends phpbb_test_case public function test_prefix_get_directories() { $dirs = $this->finder - ->prefix('t') + ->prefix('ty') ->get_directories(); sort($dirs); -- cgit v1.2.1 From 9f545a7f6ba7ddd54fae083563b5b582e05f5c1c Mon Sep 17 00:00:00 2001 From: asperous Date: Tue, 23 Apr 2013 09:55:36 -0700 Subject: [ticket/9975] Moved a few E_USER_ERROR errors to /language There were a few error messages that a user could experience that would, previously, be without any the ability to be localized. There are some more E_USER_ERRORs that I did not change to a constant, for example the error message that is displayed if there aren't any folders in /language. PHPBB3-9975 --- tests/security/redirect_test.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'tests') diff --git a/tests/security/redirect_test.php b/tests/security/redirect_test.php index 1325466137..8e36780ca4 100644 --- a/tests/security/redirect_test.php +++ b/tests/security/redirect_test.php @@ -18,11 +18,11 @@ class phpbb_security_redirect_test extends phpbb_security_test_base // array(Input -> redirect(), expected triggered error (else false), expected returned result url (else false)) return array( array('data://x', false, 'http://localhost/phpBB'), - array('bad://localhost/phpBB/index.php', 'Tried to redirect to potentially insecure url.', false), + array('bad://localhost/phpBB/index.php', 'INSECURE_REDIRECT', false), array('http://www.otherdomain.com/somescript.php', false, 'http://localhost/phpBB'), - array("http://localhost/phpBB/memberlist.php\n\rConnection: close", 'Tried to redirect to potentially insecure url.', false), + array("http://localhost/phpBB/memberlist.php\n\rConnection: close", 'INSECURE_REDIRECT', false), array('javascript:test', false, 'http://localhost/phpBB/../javascript:test'), - array('http://localhost/phpBB/index.php;url=', 'Tried to redirect to potentially insecure url.', false), + array('http://localhost/phpBB/index.php;url=', 'INSECURE_REDIRECT', false), ); } -- cgit v1.2.1 From df518ac131bb022aa14c207e0c1408751dd9e1ef Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Wed, 24 Apr 2013 17:27:24 -0500 Subject: [ticket/11335] (tests) Make php_ext 'php' not '.php' PHPBB3-11335 --- tests/class_loader/class_loader_test.php | 4 ++-- tests/controller/helper_url_test.php | 2 +- tests/dbal/migrator_test.php | 2 +- tests/extension/finder_test.php | 2 +- tests/extension/metadata_manager_test.php | 2 +- tests/mock/extension_manager.php | 2 +- 6 files changed, 7 insertions(+), 7 deletions(-) (limited to 'tests') diff --git a/tests/class_loader/class_loader_test.php b/tests/class_loader/class_loader_test.php index 76af4dde37..bf27c7c217 100644 --- a/tests/class_loader/class_loader_test.php +++ b/tests/class_loader/class_loader_test.php @@ -71,8 +71,8 @@ class phpbb_class_loader_test extends PHPUnit_Framework_TestCase $cache = new phpbb_mock_cache($cache_map); $prefix = dirname(__FILE__) . '/'; - $class_loader = new phpbb_class_loader('phpbb_', $prefix . 'includes/', '.php', $cache); - $class_loader_ext = new phpbb_class_loader('phpbb_ext_', $prefix . 'includes/', '.php', $cache); + $class_loader = new phpbb_class_loader('phpbb_', $prefix . 'includes/', 'php', $cache); + $class_loader_ext = new phpbb_class_loader('phpbb_ext_', $prefix . 'includes/', 'php', $cache); $prefix .= 'includes/'; diff --git a/tests/controller/helper_url_test.php b/tests/controller/helper_url_test.php index 195f48d8a9..2c22700ca6 100644 --- a/tests/controller/helper_url_test.php +++ b/tests/controller/helper_url_test.php @@ -52,7 +52,7 @@ class phpbb_controller_helper_url_test extends phpbb_test_case $this->user = $this->getMock('phpbb_user'); $this->template = new phpbb_template($phpbb_root_path, $phpEx, $config, $this->user, $this->style_resource_locator, new phpbb_template_context()); - $helper = new phpbb_controller_helper($this->template, $this->user, '', '.php'); + $helper = new phpbb_controller_helper($this->template, $this->user, '', 'php'); $this->assertEquals($helper->url($route, $params, $is_amp, $session_id), $expected); } } diff --git a/tests/dbal/migrator_test.php b/tests/dbal/migrator_test.php index ae4099e6f8..6390d6a715 100644 --- a/tests/dbal/migrator_test.php +++ b/tests/dbal/migrator_test.php @@ -63,7 +63,7 @@ class phpbb_dbal_migrator_test extends phpbb_database_test_case new phpbb_filesystem(), 'phpbb_ext', dirname(__FILE__) . '/../../phpBB/', - '.php', + 'php', null ); } diff --git a/tests/extension/finder_test.php b/tests/extension/finder_test.php index 4c99ba6343..dc3e26be02 100644 --- a/tests/extension/finder_test.php +++ b/tests/extension/finder_test.php @@ -164,7 +164,7 @@ class phpbb_extension_finder_test extends phpbb_test_case public function test_get_classes_create_cache() { $cache = new phpbb_mock_cache; - $finder = new phpbb_extension_finder($this->extension_manager, new phpbb_filesystem(), dirname(__FILE__) . '/', $cache, '.php', '_custom_cache_name'); + $finder = new phpbb_extension_finder($this->extension_manager, new phpbb_filesystem(), dirname(__FILE__) . '/', $cache, 'php', '_custom_cache_name'); $files = $finder->suffix('_class.php')->get_files(); $expected_files = array( diff --git a/tests/extension/metadata_manager_test.php b/tests/extension/metadata_manager_test.php index df7817b479..05d1cbccc3 100644 --- a/tests/extension/metadata_manager_test.php +++ b/tests/extension/metadata_manager_test.php @@ -36,7 +36,7 @@ class metadata_manager_test extends phpbb_database_test_case $this->db = $this->new_dbal(); $this->db_tools = new phpbb_db_tools($this->db); $this->phpbb_root_path = dirname(__FILE__) . '/'; - $this->phpEx = '.php'; + $this->phpEx = 'php'; $this->user = new phpbb_user(); $this->table_prefix = 'phpbb_'; diff --git a/tests/mock/extension_manager.php b/tests/mock/extension_manager.php index 954f2bf1c4..10b3595206 100644 --- a/tests/mock/extension_manager.php +++ b/tests/mock/extension_manager.php @@ -12,7 +12,7 @@ class phpbb_mock_extension_manager extends phpbb_extension_manager public function __construct($phpbb_root_path, $extensions = array()) { $this->phpbb_root_path = $phpbb_root_path; - $this->php_ext = '.php'; + $this->php_ext = 'php'; $this->extensions = $extensions; $this->filesystem = new phpbb_filesystem(); } -- cgit v1.2.1 From e5d032ca2112ba2c6156718b3fe42128e444a6fd Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Wed, 24 Apr 2013 17:37:05 -0500 Subject: [ticket/11335] (more class loader) Make php_ext 'php' not '.php' PHPBB3-11335 --- tests/bootstrap.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'tests') diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 1017e0c72f..a38740c82d 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -16,11 +16,11 @@ $table_prefix = 'phpbb_'; require_once $phpbb_root_path . 'includes/constants.php'; require_once $phpbb_root_path . 'includes/class_loader.' . $phpEx; -$phpbb_class_loader_mock = new phpbb_class_loader('phpbb_mock_', $phpbb_root_path . '../tests/mock/', ".php"); +$phpbb_class_loader_mock = new phpbb_class_loader('phpbb_mock_', $phpbb_root_path . '../tests/mock/', "php"); $phpbb_class_loader_mock->register(); -$phpbb_class_loader_ext = new phpbb_class_loader('phpbb_ext_', $phpbb_root_path . 'ext/', ".php"); +$phpbb_class_loader_ext = new phpbb_class_loader('phpbb_ext_', $phpbb_root_path . 'ext/', "php"); $phpbb_class_loader_ext->register(); -$phpbb_class_loader = new phpbb_class_loader('phpbb_', $phpbb_root_path . 'includes/', ".php"); +$phpbb_class_loader = new phpbb_class_loader('phpbb_', $phpbb_root_path . 'includes/', "php"); $phpbb_class_loader->register(); require_once 'test_framework/phpbb_test_case_helpers.php'; -- cgit v1.2.1 From c870b9f43be073a766e4380857415e011b5ed7ef Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Wed, 24 Apr 2013 17:37:25 -0500 Subject: [ticket/11335] (more tests) Make php_ext 'php' not '.php' PHPBB3-11335 --- tests/notification/submit_post_base.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'tests') diff --git a/tests/notification/submit_post_base.php b/tests/notification/submit_post_base.php index c5b2450e1c..953bedac80 100644 --- a/tests/notification/submit_post_base.php +++ b/tests/notification/submit_post_base.php @@ -92,12 +92,12 @@ class phpbb_notification_submit_post_base extends phpbb_database_test_case // Container $phpbb_container = new phpbb_mock_container_builder(); - $user_loader = new phpbb_user_loader($db, $phpbb_root_path, '.' . $phpEx, USERS_TABLE); + $user_loader = new phpbb_user_loader($db, $phpbb_root_path, $phpEx, USERS_TABLE); // Notification Manager $phpbb_notifications = new phpbb_notification_manager(array(), array(), $phpbb_container, $user_loader, $db, $user, - $phpbb_root_path, '.' . $phpEx, + $phpbb_root_path, $phpEx, NOTIFICATION_TYPES_TABLE, NOTIFICATIONS_TABLE, USER_NOTIFICATIONS_TABLE); $phpbb_container->set('notification_manager', $phpbb_notifications); @@ -108,7 +108,7 @@ class phpbb_notification_submit_post_base extends phpbb_database_test_case $class_name = 'phpbb_notification_type_' . $type; $phpbb_container->set('notification.type.' . $type, new $class_name( $user_loader, $db, $cache, $user, $auth, $config, - $phpbb_root_path, '.' . $phpEx, + $phpbb_root_path, $phpEx, NOTIFICATION_TYPES_TABLE, NOTIFICATIONS_TABLE, USER_NOTIFICATIONS_TABLE)); } } -- cgit v1.2.1 From f49993766e2bcf4efe346e29972f3721b1b1438a Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Wed, 24 Apr 2013 17:41:27 -0500 Subject: [ticket/11335] (more) Make php_ext 'php' not '.php' PHPBB3-11335 --- tests/extension/manager_test.php | 2 +- tests/test_framework/phpbb_functional_test_case.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/extension/manager_test.php b/tests/extension/manager_test.php index d6bcb97586..106f078691 100644 --- a/tests/extension/manager_test.php +++ b/tests/extension/manager_test.php @@ -115,7 +115,7 @@ class phpbb_extension_manager_test extends phpbb_database_test_case new phpbb_filesystem(), 'phpbb_ext', dirname(__FILE__) . '/', - '.' . $php_ext, + $php_ext, ($with_cache) ? new phpbb_mock_cache() : null ); } diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index b9647e4742..5534de89c9 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -156,7 +156,7 @@ class phpbb_functional_test_case extends phpbb_test_case new phpbb_filesystem(), self::$config['table_prefix'] . 'ext', dirname(__FILE__) . '/', - '.' . $php_ext, + $php_ext, $this->get_cache_driver() ); -- cgit v1.2.1 From 4bff28a0eeaf44eae9e99725ead6ff2cf770b857 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 25 Apr 2013 13:40:25 +0200 Subject: [ticket/11495] Rename fix function to regenerate_left_right_ids() This method regenerates the left/right ids for the nested set based on the parent/child relations. This function executes three queries per item, so it should only be called, when the set has one of the following problems: - The set has a duplicated value inside the left/right id chain - The set has a missing value inside the left/right id chain - The set has items that do not have a left/right is set When regenerating the items, the items are sorted by parent id and their current left id, so the current child/parent relationships are kept and running the function on a working set will not change any orders. PHPBB3-11495 --- tests/nestedset/set_forum_recalculate_test.php | 72 -------------------------- tests/nestedset/set_forum_regenerate_test.php | 72 ++++++++++++++++++++++++++ 2 files changed, 72 insertions(+), 72 deletions(-) delete mode 100644 tests/nestedset/set_forum_recalculate_test.php create mode 100644 tests/nestedset/set_forum_regenerate_test.php (limited to 'tests') diff --git a/tests/nestedset/set_forum_recalculate_test.php b/tests/nestedset/set_forum_recalculate_test.php deleted file mode 100644 index 6ff7a372a4..0000000000 --- a/tests/nestedset/set_forum_recalculate_test.php +++ /dev/null @@ -1,72 +0,0 @@ - 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 recalculate_nested_set_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 recalculate_nested_set_data - */ - public function test_recalculate_nested_set($breaking_query, $reset_ids) - { - $result = $this->db->sql_query($breaking_query); - - $this->assertEquals(23, $this->set->recalculate_nested_set(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/nestedset/set_forum_regenerate_test.php b/tests/nestedset/set_forum_regenerate_test.php new file mode 100644 index 0000000000..0e3a2123a0 --- /dev/null +++ b/tests/nestedset/set_forum_regenerate_test.php @@ -0,0 +1,72 @@ + 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)); + } +} -- cgit v1.2.1 From ab7054445fbf397ae5bf4c13eb44a2019d71cc2d Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 25 Apr 2013 13:48:19 +0200 Subject: [ticket/11495] Rename set_parent to change_parent() PHPBB3-11495 --- tests/nestedset/set_forum_move_test.php | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'tests') diff --git a/tests/nestedset/set_forum_move_test.php b/tests/nestedset/set_forum_move_test.php index 9a19d18476..166fe666f2 100644 --- a/tests/nestedset/set_forum_move_test.php +++ b/tests/nestedset/set_forum_move_test.php @@ -411,7 +411,7 @@ class phpbb_tests_nestedset_set_forum_move_test extends phpbb_tests_nestedset_se $this->set->move_children($forum_id, $target_id); } - public function set_parent_data() + public function change_parent_data() { return array( array('Move single child up', @@ -516,11 +516,11 @@ class phpbb_tests_nestedset_set_forum_move_test extends phpbb_tests_nestedset_se } /** - * @dataProvider set_parent_data + * @dataProvider change_parent_data */ - public function test_set_parent($explain, $forum_id, $target_id, $expected_moved, $expected) + public function test_change_parent($explain, $forum_id, $target_id, $expected_moved, $expected) { - $this->assertEquals($expected_moved, $this->set->set_parent($forum_id, $target_id)); + $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 @@ -528,7 +528,7 @@ class phpbb_tests_nestedset_set_forum_move_test extends phpbb_tests_nestedset_se $this->assertEquals($expected, $this->db->sql_fetchrowset($result)); } - public function set_parent_throws_item_data() + public function change_parent_throws_item_data() { return array( array('Item 0 does not exist', 0, 5), @@ -537,17 +537,17 @@ class phpbb_tests_nestedset_set_forum_move_test extends phpbb_tests_nestedset_se } /** - * @dataProvider set_parent_throws_item_data + * @dataProvider change_parent_throws_item_data * * @expectedException phpbb_nestedset_exception * @expectedExceptionMessage FORUM_NESTEDSET_INVALID_ITEM */ - public function test_set_parent_throws_item($explain, $forum_id, $target_id) + public function test_change_parent_throws_item($explain, $forum_id, $target_id) { - $this->set->set_parent($forum_id, $target_id); + $this->set->change_parent($forum_id, $target_id); } - public function set_parent_throws_parent_data() + public function change_parent_throws_parent_data() { return array( array('New parent is child', 4, 5), @@ -557,13 +557,13 @@ class phpbb_tests_nestedset_set_forum_move_test extends phpbb_tests_nestedset_se } /** - * @dataProvider set_parent_throws_parent_data + * @dataProvider change_parent_throws_parent_data * * @expectedException phpbb_nestedset_exception * @expectedExceptionMessage FORUM_NESTEDSET_INVALID_PARENT */ - public function test_set_parent_throws_parent($explain, $forum_id, $target_id) + public function test_change_parent_throws_parent($explain, $forum_id, $target_id) { - $this->set->set_parent($forum_id, $target_id); + $this->set->change_parent($forum_id, $target_id); } } -- cgit v1.2.1 From fe97915fc91e4fbfb211e3eb6038dd1b482553dd Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 25 Apr 2013 14:05:41 +0200 Subject: [ticket/11495] Split get_branch_data into multiple methods PHPBB3-11495 --- tests/nestedset/set_forum_get_data_test.php | 106 +++++++++++++++++----------- 1 file changed, 66 insertions(+), 40 deletions(-) (limited to 'tests') diff --git a/tests/nestedset/set_forum_get_data_test.php b/tests/nestedset/set_forum_get_data_test.php index 2c8889d1a5..a0e255b9b8 100644 --- a/tests/nestedset/set_forum_get_data_test.php +++ b/tests/nestedset/set_forum_get_data_test.php @@ -11,62 +11,88 @@ require_once dirname(__FILE__) . '/set_forum_base.php'; class phpbb_tests_nestedset_set_forum_get_data_test extends phpbb_tests_nestedset_set_forum_base { - public function get_branch_data_data() + public function get_full_branch_data_data() { return array( - array(1, 'all', true, true, array(1, 2, 3)), - array(1, 'all', true, false, array(2, 3)), - array(1, 'all', false, true, array(3, 2, 1)), - array(1, 'all', false, false, array(3, 2)), + 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(1, 'parents', true, true, array(1)), - array(1, 'parents', true, false, array()), - array(1, 'parents', false, true, array(1)), - array(1, 'parents', 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(1, 'children', true, true, array(1, 2, 3)), - array(1, 'children', true, false, array(2, 3)), - array(1, 'children', false, true, array(3, 2, 1)), - array(1, 'children', false, false, array(3, 2)), + 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, 'all', true, true, array(1, 2)), - array(2, 'all', true, false, array(1)), - array(2, 'all', false, true, array(2, 1)), - array(2, 'all', false, false, array(1)), + 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(2, 'parents', true, true, array(1, 2)), - array(2, 'parents', true, false, array(1)), - array(2, 'parents', false, true, array(2, 1)), - array(2, 'parents', 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)), + ); + } - array(2, 'children', true, true, array(2)), - array(2, 'children', true, false, array()), - array(2, 'children', false, true, array(2)), - array(2, 'children', false, false, array()), + /** + * @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))); + } - array(5, 'all', true, true, array(4, 5, 6)), - array(5, 'all', true, false, array(4, 6)), - array(5, 'all', false, true, array(6, 5, 4)), - array(5, 'all', false, false, array(6, 4)), + 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(5, 'parents', true, true, array(4, 5)), - array(5, 'parents', true, false, array(4)), - array(5, 'parents', false, true, array(5, 4)), - array(5, 'parents', false, false, array(4)), + array(2, true, true, array(2)), + array(2, true, false, array()), + array(2, false, true, array(2)), + array(2, false, false, array()), - array(5, 'children', true, true, array(5, 6)), - array(5, 'children', true, false, array(6)), - array(5, 'children', false, true, array(6, 5)), - array(5, 'children', false, false, array(6)), + 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_branch_data_data + * @dataProvider get_children_branch_data_data */ - public function test_get_branch_data($forum_id, $type, $order_desc, $include_item, $expected) + public function test_get_children_branch_data($forum_id, $order_desc, $include_item, $expected) { - $this->assertEquals($expected, array_keys($this->set->get_branch_data($forum_id, $type, $order_desc, $include_item))); + $this->assertEquals($expected, array_keys($this->set->get_children_branch_data($forum_id, $order_desc, $include_item))); } public function get_parent_data_data() -- cgit v1.2.1 From 804f139be0534691fc1c8f6ddaf7ebc68a7d0a1c Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 25 Apr 2013 16:17:58 +0200 Subject: [ticket/11495] Use default exceptions PHPBB3-11495 --- tests/nestedset/set_forum_move_test.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'tests') diff --git a/tests/nestedset/set_forum_move_test.php b/tests/nestedset/set_forum_move_test.php index 166fe666f2..90fc1c5468 100644 --- a/tests/nestedset/set_forum_move_test.php +++ b/tests/nestedset/set_forum_move_test.php @@ -383,7 +383,7 @@ class phpbb_tests_nestedset_set_forum_move_test extends phpbb_tests_nestedset_se /** * @dataProvider move_children_throws_item_data * - * @expectedException phpbb_nestedset_exception + * @expectedException OutOfBoundsException * @expectedExceptionMessage FORUM_NESTEDSET_INVALID_ITEM */ public function test_move_children_throws_item($explain, $forum_id, $target_id) @@ -403,7 +403,7 @@ class phpbb_tests_nestedset_set_forum_move_test extends phpbb_tests_nestedset_se /** * @dataProvider move_children_throws_parent_data * - * @expectedException phpbb_nestedset_exception + * @expectedException OutOfBoundsException * @expectedExceptionMessage FORUM_NESTEDSET_INVALID_PARENT */ public function test_move_children_throws_parent($explain, $forum_id, $target_id) @@ -539,7 +539,7 @@ class phpbb_tests_nestedset_set_forum_move_test extends phpbb_tests_nestedset_se /** * @dataProvider change_parent_throws_item_data * - * @expectedException phpbb_nestedset_exception + * @expectedException OutOfBoundsException * @expectedExceptionMessage FORUM_NESTEDSET_INVALID_ITEM */ public function test_change_parent_throws_item($explain, $forum_id, $target_id) @@ -559,7 +559,7 @@ class phpbb_tests_nestedset_set_forum_move_test extends phpbb_tests_nestedset_se /** * @dataProvider change_parent_throws_parent_data * - * @expectedException phpbb_nestedset_exception + * @expectedException OutOfBoundsException * @expectedExceptionMessage FORUM_NESTEDSET_INVALID_PARENT */ public function test_change_parent_throws_parent($explain, $forum_id, $target_id) -- cgit v1.2.1 From 94dee77647a7ae1a263632a156b5afc14722ad6a Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 25 Apr 2013 16:50:11 +0200 Subject: [ticket/11495] Replace fixtures content with manual calls Should be easier to maintain PHPBB3-11495 --- tests/nestedset/fixtures/phpbb_forums.xml | 110 ------------------------------ tests/nestedset/set_forum_base.php | 25 +++++++ 2 files changed, 25 insertions(+), 110 deletions(-) (limited to 'tests') diff --git a/tests/nestedset/fixtures/phpbb_forums.xml b/tests/nestedset/fixtures/phpbb_forums.xml index 016c8ea7c5..8f133078a9 100644 --- a/tests/nestedset/fixtures/phpbb_forums.xml +++ b/tests/nestedset/fixtures/phpbb_forums.xml @@ -9,115 +9,5 @@ forum_name forum_desc forum_rules - - 1 - 0 - 1 - 6 - - Parent with two flat children - - - - - 2 - 1 - 2 - 3 - - Flat child #1 - - - - - 3 - 1 - 4 - 5 - - Flat child #2 - - - - - 4 - 0 - 7 - 12 - - Parent with two nested children - - - - - 5 - 4 - 8 - 11 - - Nested child #1 - - - - - 6 - 5 - 9 - 10 - - Nested child #2 - - - - - 7 - 0 - 13 - 22 - - Parent with flat and nested children - - - - - 8 - 7 - 14 - 15 - - Mixed child #1 - - - - - 9 - 7 - 16 - 19 - - Mixed child #2 - - - - - 10 - 9 - 17 - 18 - - Nested child #1 of Mixed child #2 - - - - - 11 - 7 - 20 - 21 - - Mixed child #3 - - - diff --git a/tests/nestedset/set_forum_base.php b/tests/nestedset/set_forum_base.php index 4523f12897..93d4dc3522 100644 --- a/tests/nestedset/set_forum_base.php +++ b/tests/nestedset/set_forum_base.php @@ -57,5 +57,30 @@ class phpbb_tests_nestedset_set_forum_base extends phpbb_database_test_case $this->lock = new phpbb_lock_db('nestedset_forum_lock', $this->config, $this->db); $this->set = new phpbb_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); } } -- cgit v1.2.1 From b334a2ce0fe3ae196da9686028667c430eb411d1 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 25 Apr 2013 17:04:37 +0200 Subject: [ticket/11495] Move classes to tree/ as they all implement a tree PHPBB3-11495 --- tests/nestedset/set_forum_base.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/nestedset/set_forum_base.php b/tests/nestedset/set_forum_base.php index 93d4dc3522..0d1cb1f881 100644 --- a/tests/nestedset/set_forum_base.php +++ b/tests/nestedset/set_forum_base.php @@ -56,7 +56,7 @@ class phpbb_tests_nestedset_set_forum_base extends phpbb_database_test_case set_config(null, null, null, $this->config); $this->lock = new phpbb_lock_db('nestedset_forum_lock', $this->config, $this->db); - $this->set = new phpbb_nestedset_forum($this->db, $this->lock, 'phpbb_forums'); + $this->set = new phpbb_tree_nestedset_forum($this->db, $this->lock, 'phpbb_forums'); $this->set_up_forums(); } -- cgit v1.2.1 From 499dd3a833912d07fe677ae721e99678708bddcd Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 25 Apr 2013 17:13:21 +0200 Subject: [ticket/11495] Move tests to tree/ directory PHPBB3-11495 --- tests/nestedset/fixtures/phpbb_forums.xml | 13 - tests/nestedset/set_forum_add_remove_test.php | 196 --------- tests/nestedset/set_forum_base.php | 86 ---- tests/nestedset/set_forum_get_data_test.php | 117 ----- tests/nestedset/set_forum_move_test.php | 569 ------------------------- tests/nestedset/set_forum_regenerate_test.php | 72 ---- tests/nestedset/set_forum_test.php | 116 ----- tests/tree/fixtures/phpbb_forums.xml | 13 + tests/tree/nestedset_forum_add_remove_test.php | 196 +++++++++ tests/tree/nestedset_forum_base.php | 86 ++++ tests/tree/nestedset_forum_get_data_test.php | 117 +++++ tests/tree/nestedset_forum_move_test.php | 569 +++++++++++++++++++++++++ tests/tree/nestedset_forum_regenerate_test.php | 72 ++++ tests/tree/nestedset_forum_test.php | 116 +++++ 14 files changed, 1169 insertions(+), 1169 deletions(-) delete mode 100644 tests/nestedset/fixtures/phpbb_forums.xml delete mode 100644 tests/nestedset/set_forum_add_remove_test.php delete mode 100644 tests/nestedset/set_forum_base.php delete mode 100644 tests/nestedset/set_forum_get_data_test.php delete mode 100644 tests/nestedset/set_forum_move_test.php delete mode 100644 tests/nestedset/set_forum_regenerate_test.php delete mode 100644 tests/nestedset/set_forum_test.php create mode 100644 tests/tree/fixtures/phpbb_forums.xml create mode 100644 tests/tree/nestedset_forum_add_remove_test.php create mode 100644 tests/tree/nestedset_forum_base.php create mode 100644 tests/tree/nestedset_forum_get_data_test.php create mode 100644 tests/tree/nestedset_forum_move_test.php create mode 100644 tests/tree/nestedset_forum_regenerate_test.php create mode 100644 tests/tree/nestedset_forum_test.php (limited to 'tests') diff --git a/tests/nestedset/fixtures/phpbb_forums.xml b/tests/nestedset/fixtures/phpbb_forums.xml deleted file mode 100644 index 8f133078a9..0000000000 --- a/tests/nestedset/fixtures/phpbb_forums.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - forum_id - parent_id - left_id - right_id - forum_parents - forum_name - forum_desc - forum_rules -
-
diff --git a/tests/nestedset/set_forum_add_remove_test.php b/tests/nestedset/set_forum_add_remove_test.php deleted file mode 100644 index 97b6348d67..0000000000 --- a/tests/nestedset/set_forum_add_remove_test.php +++ /dev/null @@ -1,196 +0,0 @@ - 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/nestedset/set_forum_base.php b/tests/nestedset/set_forum_base.php deleted file mode 100644 index 0d1cb1f881..0000000000 --- a/tests/nestedset/set_forum_base.php +++ /dev/null @@ -1,86 +0,0 @@ -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/nestedset/set_forum_get_data_test.php b/tests/nestedset/set_forum_get_data_test.php deleted file mode 100644 index a0e255b9b8..0000000000 --- a/tests/nestedset/set_forum_get_data_test.php +++ /dev/null @@ -1,117 +0,0 @@ -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/nestedset/set_forum_move_test.php b/tests/nestedset/set_forum_move_test.php deleted file mode 100644 index 90fc1c5468..0000000000 --- a/tests/nestedset/set_forum_move_test.php +++ /dev/null @@ -1,569 +0,0 @@ - 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/nestedset/set_forum_regenerate_test.php b/tests/nestedset/set_forum_regenerate_test.php deleted file mode 100644 index 0e3a2123a0..0000000000 --- a/tests/nestedset/set_forum_regenerate_test.php +++ /dev/null @@ -1,72 +0,0 @@ - 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/nestedset/set_forum_test.php b/tests/nestedset/set_forum_test.php deleted file mode 100644 index ab4da1ff1e..0000000000 --- a/tests/nestedset/set_forum_test.php +++ /dev/null @@ -1,116 +0,0 @@ - 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)); - } -} 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 @@ + + + + forum_id + parent_id + left_id + right_id + forum_parents + forum_name + forum_desc + forum_rules +
+
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 @@ + 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 @@ +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 @@ +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 @@ + 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 @@ + 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 @@ + 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)); + } +} -- cgit v1.2.1 From d4b7708d4b1f6d83caae52794dc3f602b7fe96a1 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 25 Apr 2013 17:19:21 +0200 Subject: [ticket/11495] Remove tests for add/remove we make them protected later PHPBB3-11495 --- tests/tree/nestedset_forum_add_remove_test.php | 196 ---------------------- tests/tree/nestedset_forum_insert_delete_test.php | 101 +++++++++++ 2 files changed, 101 insertions(+), 196 deletions(-) delete mode 100644 tests/tree/nestedset_forum_add_remove_test.php create mode 100644 tests/tree/nestedset_forum_insert_delete_test.php (limited to 'tests') diff --git a/tests/tree/nestedset_forum_add_remove_test.php b/tests/tree/nestedset_forum_add_remove_test.php deleted file mode 100644 index 623cb2bbf3..0000000000 --- a/tests/tree/nestedset_forum_add_remove_test.php +++ /dev/null @@ -1,196 +0,0 @@ - 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_insert_delete_test.php b/tests/tree/nestedset_forum_insert_delete_test.php new file mode 100644 index 0000000000..02259f9091 --- /dev/null +++ b/tests/tree/nestedset_forum_insert_delete_test.php @@ -0,0 +1,101 @@ + 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)); + } +} -- cgit v1.2.1 From ce07b2776577d1ed3987b38e231a367cfef21db6 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 25 Apr 2013 17:27:33 +0200 Subject: [ticket/11495] Fix failing unit tests PHPBB3-11495 --- tests/tree/nestedset_forum_get_data_test.php | 2 +- tests/tree/nestedset_forum_insert_delete_test.php | 2 +- tests/tree/nestedset_forum_move_test.php | 2 +- tests/tree/nestedset_forum_regenerate_test.php | 2 +- tests/tree/nestedset_forum_test.php | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) (limited to 'tests') diff --git a/tests/tree/nestedset_forum_get_data_test.php b/tests/tree/nestedset_forum_get_data_test.php index 4ce679f05d..24ada93409 100644 --- a/tests/tree/nestedset_forum_get_data_test.php +++ b/tests/tree/nestedset_forum_get_data_test.php @@ -7,7 +7,7 @@ * */ -require_once dirname(__FILE__) . '/set_forum_base.php'; +require_once dirname(__FILE__) . '/nestedset_forum_base.php'; class phpbb_tests_tree_nestedset_forum_get_data_test extends phpbb_tests_tree_nestedset_forum_base { diff --git a/tests/tree/nestedset_forum_insert_delete_test.php b/tests/tree/nestedset_forum_insert_delete_test.php index 02259f9091..67692d2b7e 100644 --- a/tests/tree/nestedset_forum_insert_delete_test.php +++ b/tests/tree/nestedset_forum_insert_delete_test.php @@ -7,7 +7,7 @@ * */ -require_once dirname(__FILE__) . '/set_forum_base.php'; +require_once dirname(__FILE__) . '/nestedset_forum_base.php'; class phpbb_tests_tree_nestedset_forum_add_remove_test extends phpbb_tests_tree_nestedset_forum_base { diff --git a/tests/tree/nestedset_forum_move_test.php b/tests/tree/nestedset_forum_move_test.php index 29af693374..9561089378 100644 --- a/tests/tree/nestedset_forum_move_test.php +++ b/tests/tree/nestedset_forum_move_test.php @@ -7,7 +7,7 @@ * */ -require_once dirname(__FILE__) . '/set_forum_base.php'; +require_once dirname(__FILE__) . '/nestedset_forum_base.php'; class phpbb_tests_tree_nestedset_forum_move_test extends phpbb_tests_tree_nestedset_forum_base { diff --git a/tests/tree/nestedset_forum_regenerate_test.php b/tests/tree/nestedset_forum_regenerate_test.php index 3bd272370a..6b1759d1cc 100644 --- a/tests/tree/nestedset_forum_regenerate_test.php +++ b/tests/tree/nestedset_forum_regenerate_test.php @@ -7,7 +7,7 @@ * */ -require_once dirname(__FILE__) . '/set_forum_base.php'; +require_once dirname(__FILE__) . '/nestedset_forum_base.php'; class phpbb_tests_tree_nestedset_forum_regenerate_test extends phpbb_tests_tree_nestedset_forum_base { diff --git a/tests/tree/nestedset_forum_test.php b/tests/tree/nestedset_forum_test.php index ac02886e95..5e6d912596 100644 --- a/tests/tree/nestedset_forum_test.php +++ b/tests/tree/nestedset_forum_test.php @@ -7,7 +7,7 @@ * */ -require_once dirname(__FILE__) . '/set_forum_base.php'; +require_once dirname(__FILE__) . '/nestedset_forum_base.php'; class pphpbb_tests_tree_nestedset_forum_test extends phpbb_tests_tree_nestedset_forum_base { -- cgit v1.2.1 From 2fa5f9591e06e82ca76e7ac7e653d8ad4494eb67 Mon Sep 17 00:00:00 2001 From: Dhruv Date: Thu, 25 Apr 2013 22:52:40 +0530 Subject: [ticket/10325] add logout function in functional_test_case PHPBB3-10325 --- tests/test_framework/phpbb_functional_test_case.php | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'tests') diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index 5534de89c9..dae37f336d 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -425,6 +425,17 @@ class phpbb_functional_test_case extends phpbb_test_case } } + protected function logout() + { + $this->add_lang('ucp'); + + $crawler = $this->request('GET', 'ucp.php?sid=' . $this->sid . '&mode=logout'); + $this->assert_response_success(); + $this->assertContains($this->lang('LOGOUT_REDIRECT'), $crawler->filter('#message')->text()); + unset($this->sid); + + } + /** * Login to the ACP * You must run login() before calling this. -- cgit v1.2.1 From 27aa5e7b713b58eb0afb8d92e684a6868eb080ce Mon Sep 17 00:00:00 2001 From: Dhruv Date: Thu, 25 Apr 2013 22:58:03 +0530 Subject: [ticket/10325] functional tests for forgot password functionality PHPBB3-10325 --- tests/functional/forgot_password_test.php | 45 +++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 tests/functional/forgot_password_test.php (limited to 'tests') diff --git a/tests/functional/forgot_password_test.php b/tests/functional/forgot_password_test.php new file mode 100644 index 0000000000..3ae74ed1e9 --- /dev/null +++ b/tests/functional/forgot_password_test.php @@ -0,0 +1,45 @@ +add_lang('ucp'); + $crawler = $this->request('GET', 'ucp.php?mode=sendpassword'); + $this->assertEquals($this->lang('SEND_PASSWORD'), $crawler->filter('h2')->text()); + } + + public function test_forgot_password_disabled() + { + $this->login(); + $this->admin_login(); + $this->add_lang('ucp'); + $crawler = $this->request('GET', 'adm/index.php?sid=' . $this->sid . '&i=acp_board&mode=security'); + + $form = $crawler->selectButton('Submit')->form(); + $values = $form->getValues(); + + $values["config[allow_password_reset]"] = 0; + $form->setValues($values); + $crawler = $this->client->submit($form); + + $this->logout(); + + $crawler = $this->request('GET', 'ucp.php?mode=sendpassword'); + + $this->assertContains($this->lang('UCP_PASSWORD_RESET_DISABLED', '', ''), $crawler->text()); + + } + +} -- cgit v1.2.1 From 6801e36defcd9628a7feeebd01c6f34366b70542 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Thu, 25 Apr 2013 14:13:21 -0500 Subject: [ticket/11435] Fix comments in events test PHPBB3-11435 --- tests/template/template_events_test.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/template/template_events_test.php b/tests/template/template_events_test.php index 6cea9b92e3..0ac50c7f2b 100644 --- a/tests/template/template_events_test.php +++ b/tests/template/template_events_test.php @@ -16,9 +16,10 @@ class phpbb_template_template_events_test extends phpbb_template_template_test_c return array( /* array( - '', // file + '', // Description '', // dataset array(), // style names + '', // file array(), // vars array(), // block vars array(), // destroy -- cgit v1.2.1 From ab87fe7982b185e9c08a3fd7248214004b23a58b Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Thu, 25 Apr 2013 14:15:04 -0500 Subject: [ticket/11435] Create test to make sure template/event output is equal PHPBB3-11435 --- .../styles/all/template/variable_spacing.html | 6 ++ .../styles/silver/template/variable_spacing.html | 1 + tests/template/template_spacing_test.php | 87 ++++++++++++++++++++++ tests/template/templates/variable_spacing.html | 6 ++ 4 files changed, 100 insertions(+) create mode 100644 tests/template/datasets/ext_trivial/ext/trivial/styles/all/template/variable_spacing.html create mode 100644 tests/template/datasets/ext_trivial/styles/silver/template/variable_spacing.html create mode 100644 tests/template/template_spacing_test.php create mode 100644 tests/template/templates/variable_spacing.html (limited to 'tests') diff --git a/tests/template/datasets/ext_trivial/ext/trivial/styles/all/template/variable_spacing.html b/tests/template/datasets/ext_trivial/ext/trivial/styles/all/template/variable_spacing.html new file mode 100644 index 0000000000..2909e1c136 --- /dev/null +++ b/tests/template/datasets/ext_trivial/ext/trivial/styles/all/template/variable_spacing.html @@ -0,0 +1,6 @@ +|{VARIABLE}| +{VARIABLE}|{VARIABLE}| + +|{VARIABLE} + +
test
\ No newline at end of file diff --git a/tests/template/datasets/ext_trivial/styles/silver/template/variable_spacing.html b/tests/template/datasets/ext_trivial/styles/silver/template/variable_spacing.html new file mode 100644 index 0000000000..c11ae9cb40 --- /dev/null +++ b/tests/template/datasets/ext_trivial/styles/silver/template/variable_spacing.html @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/tests/template/template_spacing_test.php b/tests/template/template_spacing_test.php new file mode 100644 index 0000000000..83f8711b38 --- /dev/null +++ b/tests/template/template_spacing_test.php @@ -0,0 +1,87 @@ + '{}', + ), + array(), + array(), + '|{}| +{}|{}| +|{} +
test
', + ), + ); + } + + /** + * @dataProvider template_data + */ + public function test_template($desc, $dataset, $style_names, $file, array $vars, array $block_vars, array $destroy, $expected) + { + // Run test + $cache_file = $this->template->cachepath . str_replace('/', '.', $file) . '.php'; + $this->run_template($file, $vars, $block_vars, $destroy, $expected, $cache_file); + } + + /** + * @dataProvider template_data + */ + public function test_event($desc, $dataset, $style_names, $file, array $vars, array $block_vars, array $destroy, $expected) + { + // Reset the engine state + $this->setup_engine_for_events($dataset, $style_names); + + // Run test + $cache_file = $this->template->cachepath . str_replace('/', '.', $file) . '.php'; + $this->run_template($file, $vars, $block_vars, $destroy, $expected, $cache_file); + } + + protected function setup_engine_for_events($dataset, $style_names, array $new_config = array()) + { + global $phpbb_root_path, $phpEx, $user; + + $defaults = $this->config_defaults(); + $config = new phpbb_config(array_merge($defaults, $new_config)); + + $this->template_path = dirname(__FILE__) . "/datasets/$dataset/styles/silver/template"; + $this->style_resource_locator = new phpbb_style_resource_locator(); + $this->extension_manager = new phpbb_mock_filesystem_extension_manager( + dirname(__FILE__) . "/datasets/$dataset/" + ); + $this->template = new phpbb_template($phpbb_root_path, $phpEx, $config, $user, $this->style_resource_locator, new phpbb_template_context, $this->extension_manager); + $this->style_provider = new phpbb_style_path_provider(); + $this->style = new phpbb_style($phpbb_root_path, $phpEx, $config, $user, $this->style_resource_locator, $this->style_provider, $this->template); + $this->style->set_custom_style('silver', array($this->template_path), $style_names, ''); + } +} diff --git a/tests/template/templates/variable_spacing.html b/tests/template/templates/variable_spacing.html new file mode 100644 index 0000000000..2909e1c136 --- /dev/null +++ b/tests/template/templates/variable_spacing.html @@ -0,0 +1,6 @@ +|{VARIABLE}| +{VARIABLE}|{VARIABLE}| + +|{VARIABLE} + +
test
\ No newline at end of file -- cgit v1.2.1 From baff4287e5a7142b7af41e56c29b064bb56fd7fb Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 25 Apr 2013 22:39:24 +0200 Subject: [ticket/11495] Fix comments and package docs PHPBB3-11495 --- tests/tree/nestedset_forum_base.php | 2 +- tests/tree/nestedset_forum_get_data_test.php | 2 +- tests/tree/nestedset_forum_insert_delete_test.php | 2 +- tests/tree/nestedset_forum_move_test.php | 2 +- tests/tree/nestedset_forum_regenerate_test.php | 2 +- tests/tree/nestedset_forum_test.php | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) (limited to 'tests') diff --git a/tests/tree/nestedset_forum_base.php b/tests/tree/nestedset_forum_base.php index 1e79df2c0d..bfb97ba63e 100644 --- a/tests/tree/nestedset_forum_base.php +++ b/tests/tree/nestedset_forum_base.php @@ -1,7 +1,7 @@ Date: Mon, 29 Apr 2013 02:25:22 +0530 Subject: [ticket/10820] add unit tests for phpbb_is_greater_ie7 PHPBB3-10820 --- tests/download/http_user_agent_test.php | 65 +++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 tests/download/http_user_agent_test.php (limited to 'tests') diff --git a/tests/download/http_user_agent_test.php b/tests/download/http_user_agent_test.php new file mode 100644 index 0000000000..601561f44e --- /dev/null +++ b/tests/download/http_user_agent_test.php @@ -0,0 +1,65 @@ +assertEquals($expected, phpbb_is_greater_ie7($user_agent)); + } +} -- cgit v1.2.1 From 4cd0914f8976913de0ec46cc78c8ac5731415838 Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Mon, 29 Apr 2013 22:16:46 -0500 Subject: [ticket/11413] Fix notification tests Send types/methods the cache service, not the driver (not sure why the driver was sent before) PHPBB3-11413 --- tests/mock/notifications_notification_manager.php | 69 ----------------------- tests/notification/manager_helper.php | 69 +++++++++++++++++++++++ tests/notification/notification_test.php | 47 +++++++++++---- 3 files changed, 104 insertions(+), 81 deletions(-) delete mode 100644 tests/mock/notifications_notification_manager.php create mode 100644 tests/notification/manager_helper.php (limited to 'tests') diff --git a/tests/mock/notifications_notification_manager.php b/tests/mock/notifications_notification_manager.php deleted file mode 100644 index c995afb9ab..0000000000 --- a/tests/mock/notifications_notification_manager.php +++ /dev/null @@ -1,69 +0,0 @@ -$name = $value; - } - - // Extra dependencies for get_*_class functions - protected $auth = null; - protected $cache = null; - protected $config = null; - public function setDependencies($auth, $cache, $config) - { - $this->auth = $auth; - $this->cache = $cache; - $this->config = $config; - } - - /** - * Helper to get the notifications item type class and set it up - */ - public function get_item_type_class($item_type, $data = array()) - { - $item_type = 'phpbb_notification_type_' . $item_type; - - $item = new $item_type($this->user_loader, $this->db, $this->cache, $this->user, $this->auth, $this->config, $this->phpbb_root_path, $this->php_ext, $this->notification_types_table, $this->notifications_table, $this->user_notifications_table); - - $item->set_notification_manager($this); - - $item->set_initial_data($data); - - return $item; - } - - /** - * Helper to get the notifications method class and set it up - */ - public function get_method_class($method_name) - { - $method_name = 'phpbb_notification_method_' . $method_name; - - $method = new $method_name($this->user_loader, $this->db, $this->cache, $this->user, $this->auth, $this->config, $this->phpbb_root_path, $this->php_ext, $this->notification_types_table, $this->notifications_table, $this->user_notifications_table); - - $method->set_notification_manager($this); - - return $method; - } -} diff --git a/tests/notification/manager_helper.php b/tests/notification/manager_helper.php new file mode 100644 index 0000000000..8d2ce5e002 --- /dev/null +++ b/tests/notification/manager_helper.php @@ -0,0 +1,69 @@ +$name = $value; + } + + // Extra dependencies for get_*_class functions + protected $auth = null; + protected $cache = null; + protected $config = null; + public function setDependencies($auth, $cache, $config) + { + $this->auth = $auth; + $this->cache = $cache; + $this->config = $config; + } + + /** + * Helper to get the notifications item type class and set it up + */ + public function get_item_type_class($item_type, $data = array()) + { + $item_type = 'phpbb_notification_type_' . $item_type; + + $item = new $item_type($this->user_loader, $this->db, $this->cache, $this->user, $this->auth, $this->config, $this->phpbb_root_path, $this->php_ext, $this->notification_types_table, $this->notifications_table, $this->user_notifications_table); + + $item->set_notification_manager($this); + + $item->set_initial_data($data); + + return $item; + } + + /** + * Helper to get the notifications method class and set it up + */ + public function get_method_class($method_name) + { + $method_name = 'phpbb_notification_method_' . $method_name; + + $method = new $method_name($this->user_loader, $this->db, $this->cache, $this->user, $this->auth, $this->config, $this->phpbb_root_path, $this->php_ext, $this->notification_types_table, $this->notifications_table, $this->user_notifications_table); + + $method->set_notification_manager($this); + + return $method; + } +} diff --git a/tests/notification/notification_test.php b/tests/notification/notification_test.php index beccf55371..5746d0090e 100644 --- a/tests/notification/notification_test.php +++ b/tests/notification/notification_test.php @@ -7,6 +7,8 @@ * */ +require_once dirname(__FILE__) . '/manager_helper.php'; + class phpbb_notification_test extends phpbb_database_test_case { protected $notifications, $db, $container, $user, $config, $auth, $cache; @@ -34,16 +36,23 @@ class phpbb_notification_test extends phpbb_database_test_case $this->user = new phpbb_mock_user(); $this->user_loader = new phpbb_user_loader($this->db, $phpbb_root_path, $phpEx, 'phpbb_users'); $this->auth = new phpbb_mock_notifications_auth(); - $this->cache = new phpbb_mock_cache(); + $this->cache = new phpbb_cache_service( + new phpbb_cache_driver_null(), + $this->config, + $this->db, + $phpbb_root_path, + $phpEx + ); $this->container = new phpbb_mock_container_builder(); - $this->notifications = new phpbb_mock_notifications_notification_manager( + $this->notifications = new phpbb_notification_manager_helper( array(), array(), $this->container, $this->user_loader, $this->db, + $this->cache, $this->user, $phpbb_root_path, $phpEx, @@ -121,6 +130,20 @@ class phpbb_notification_test extends phpbb_database_test_case public function test_notifications() { + $this->db->sql_query('DELETE FROM phpbb_notification_types'); + + $types = array('quote', 'bookmark', 'post', 'test'); + foreach ($types as $id => $type) + { + $this->db->sql_query('INSERT INTO phpbb_notification_types ' . + $this->db->sql_build_array('INSERT', array( + 'notification_type_id' => ($id + 1), + 'notification_type_name' => $type, + 'notification_type_enabled' => 1, + )) + ); + } + // Used to test post notifications later $this->db->sql_query('INSERT INTO ' . TOPICS_WATCH_TABLE . ' ' . $this->db->sql_build_array('INSERT', array( 'topic_id' => 2, @@ -195,7 +218,7 @@ class phpbb_notification_test extends phpbb_database_test_case $expected = array( 1 => array( - 'item_type' => 'test', + 'notification_type_id' => 4, 'item_id' => 1, 'item_parent_id' => 1, 'user_id' => 0, @@ -204,7 +227,7 @@ class phpbb_notification_test extends phpbb_database_test_case 'notification_data' => array(), ), 2 => array( - 'item_type' => 'test', + 'notification_type_id' => 4, 'item_id' => 2, 'item_parent_id' => 2, 'user_id' => 0, @@ -213,7 +236,7 @@ class phpbb_notification_test extends phpbb_database_test_case 'notification_data' => array(), ), 3 => array( - 'item_type' => 'test', + 'notification_type_id' => 4, 'item_id' => 3, 'item_parent_id' => 2, 'user_id' => 0, @@ -222,7 +245,7 @@ class phpbb_notification_test extends phpbb_database_test_case 'notification_data' => array(), ), 4 => array( - 'item_type' => 'post', + 'notification_type_id' => 3, 'item_id' => 4, 'item_parent_id' => 2, 'user_id' => 0, @@ -238,7 +261,7 @@ class phpbb_notification_test extends phpbb_database_test_case ), ), 5 => array( - 'item_type' => 'bookmark', + 'notification_type_id' => 2, 'item_id' => 5, 'item_parent_id' => 2, 'user_id' => 0, @@ -301,7 +324,7 @@ class phpbb_notification_test extends phpbb_database_test_case $expected = array( 1 => array( - 'item_type' => 'test', + 'notification_type_id' => 4, 'item_id' => 1, 'item_parent_id' => 2, 'user_id' => 0, @@ -310,7 +333,7 @@ class phpbb_notification_test extends phpbb_database_test_case 'notification_data' => array(), ), 2 => array( - 'item_type' => 'test', + 'notification_type_id' => 4, 'item_id' => 2, 'item_parent_id' => 2, 'user_id' => 0, @@ -319,7 +342,7 @@ class phpbb_notification_test extends phpbb_database_test_case 'notification_data' => array(), ), 3 => array( - 'item_type' => 'test', + 'notification_type_id' => 4, 'item_id' => 3, 'item_parent_id' => 2, 'user_id' => 0, @@ -328,7 +351,7 @@ class phpbb_notification_test extends phpbb_database_test_case 'notification_data' => array(), ), 4 => array( - 'item_type' => 'post', + 'notification_type_id' => 3, 'item_id' => 4, 'item_parent_id' => 2, 'user_id' => 0, @@ -344,7 +367,7 @@ class phpbb_notification_test extends phpbb_database_test_case ), ), 5 => array( - 'item_type' => 'bookmark', + 'notification_type_id' => 2, 'item_id' => 5, 'item_parent_id' => 2, 'user_id' => 0, -- cgit v1.2.1 From 78c22248fa35dd01c0e30d1ea896379890cefe66 Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Mon, 29 Apr 2013 22:41:08 -0500 Subject: [ticket/11413] Fix some more tests PHPBB3-11413 --- tests/notification/submit_post_base.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'tests') diff --git a/tests/notification/submit_post_base.php b/tests/notification/submit_post_base.php index 953bedac80..5fbcfc8776 100644 --- a/tests/notification/submit_post_base.php +++ b/tests/notification/submit_post_base.php @@ -119,8 +119,9 @@ class phpbb_notification_submit_post_base extends phpbb_database_test_case public function test_submit_post($additional_post_data, $expected_before, $expected_after) { $sql = 'SELECT user_id, item_id, item_parent_id - FROM ' . NOTIFICATIONS_TABLE . " - WHERE item_type = '" . $this->item_type . "' + FROM ' . NOTIFICATIONS_TABLE . ' n, ' . NOTIFICATIONS_TYPES_TABLE . " nt + WHERE nt.notification_type_name = '" . $this->item_type . "' + AND n.notification_type_id = nt.notification_type_id ORDER BY user_id, item_id ASC"; $result = $this->db->sql_query($sql); $this->assertEquals($expected_before, $this->db->sql_fetchrowset($result)); @@ -131,8 +132,9 @@ class phpbb_notification_submit_post_base extends phpbb_database_test_case submit_post('reply', '', 'poster-name', POST_NORMAL, $poll_data, $post_data, false, false); $sql = 'SELECT user_id, item_id, item_parent_id - FROM ' . NOTIFICATIONS_TABLE . " - WHERE item_type = '" . $this->item_type . "' + FROM ' . NOTIFICATIONS_TABLE . ' n, ' . NOTIFICATIONS_TYPES_TABLE . " nt + WHERE nt.notification_type_name = '" . $this->item_type . "' + AND n.notification_type_id = nt.notification_type_id ORDER BY user_id ASC, item_id ASC"; $result = $this->db->sql_query($sql); $this->assertEquals($expected_after, $this->db->sql_fetchrowset($result)); -- cgit v1.2.1 From 878df5f280878b465e6e42c8257ddbdb66327a92 Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Mon, 29 Apr 2013 22:52:52 -0500 Subject: [ticket/11413] Fix test fixtures and tests PHPBB3-11413 --- .../notification/fixtures/submit_post_bookmark.xml | 8 +++-- tests/notification/fixtures/submit_post_post.xml | 10 +++--- .../fixtures/submit_post_post_in_queue.xml | 8 +++-- tests/notification/fixtures/submit_post_quote.xml | 8 +++-- tests/notification/submit_post_base.php | 40 ++++++++++++++-------- 5 files changed, 46 insertions(+), 28 deletions(-) (limited to 'tests') diff --git a/tests/notification/fixtures/submit_post_bookmark.xml b/tests/notification/fixtures/submit_post_bookmark.xml index b669d4c1b6..d4bf8df73f 100644 --- a/tests/notification/fixtures/submit_post_bookmark.xml +++ b/tests/notification/fixtures/submit_post_bookmark.xml @@ -29,14 +29,14 @@ - item_type + notification_type_iduser_iditem_iditem_parent_idnotification_readnotification_data - bookmark + 1 5 1 1 @@ -45,9 +45,11 @@
- notification_type + notification_type_id + notification_type_namenotification_type_enabled + 1 bookmark 1 diff --git a/tests/notification/fixtures/submit_post_post.xml b/tests/notification/fixtures/submit_post_post.xml index cead4f7c26..b0ffa042c5 100644 --- a/tests/notification/fixtures/submit_post_post.xml +++ b/tests/notification/fixtures/submit_post_post.xml @@ -21,14 +21,14 @@
- item_type + notification_type_iduser_iditem_iditem_parent_idnotification_readnotification_data - post + 1 5 1 1 @@ -36,7 +36,7 @@ - post + 1 8 1 1 @@ -45,9 +45,11 @@
- notification_type + notification_type_id + notification_type_namenotification_type_enabled + 1 post 1 diff --git a/tests/notification/fixtures/submit_post_post_in_queue.xml b/tests/notification/fixtures/submit_post_post_in_queue.xml index eedcebf71d..090e90ea49 100644 --- a/tests/notification/fixtures/submit_post_post_in_queue.xml +++ b/tests/notification/fixtures/submit_post_post_in_queue.xml @@ -1,14 +1,14 @@
- item_type + notification_type_iduser_iditem_iditem_parent_idnotification_readnotification_data - post_in_queue + 1 6 1 1 @@ -17,9 +17,11 @@
- notification_type + notification_type_id + notification_type_namenotification_type_enabled + 1 post_in_queue 1 diff --git a/tests/notification/fixtures/submit_post_quote.xml b/tests/notification/fixtures/submit_post_quote.xml index 884a84af4a..f22ed97d91 100644 --- a/tests/notification/fixtures/submit_post_quote.xml +++ b/tests/notification/fixtures/submit_post_quote.xml @@ -1,14 +1,14 @@
- item_type + notification_type_iduser_iditem_iditem_parent_idnotification_readnotification_data - quote + 1 5 1 1 @@ -17,9 +17,11 @@
- notification_type + notification_type_id + notification_type_namenotification_type_enabled + 1 quote 1 diff --git a/tests/notification/submit_post_base.php b/tests/notification/submit_post_base.php index 5fbcfc8776..c3dbfc2535 100644 --- a/tests/notification/submit_post_base.php +++ b/tests/notification/submit_post_base.php @@ -52,9 +52,6 @@ class phpbb_notification_submit_post_base extends phpbb_database_test_case $this->db = $this->new_dbal(); $db = $this->db; - // Cache - $cache = new phpbb_mock_cache(); - // Auth $auth = $this->getMock('phpbb_auth'); $auth->expects($this->any()) @@ -72,6 +69,14 @@ class phpbb_notification_submit_post_base extends phpbb_database_test_case set_config(null, null, null, $config); set_config_count(null, null, null, $config); + $cache = new phpbb_cache_service( + new phpbb_cache_driver_null(), + $config, + $db, + $phpbb_root_path, + $phpEx + ); + // Event dispatcher $phpbb_dispatcher = new phpbb_mock_event_dispatcher(); @@ -94,23 +99,28 @@ class phpbb_notification_submit_post_base extends phpbb_database_test_case $user_loader = new phpbb_user_loader($db, $phpbb_root_path, $phpEx, USERS_TABLE); - // Notification Manager - $phpbb_notifications = new phpbb_notification_manager(array(), array(), - $phpbb_container, $user_loader, $db, $user, - $phpbb_root_path, $phpEx, - NOTIFICATION_TYPES_TABLE, NOTIFICATIONS_TABLE, USER_NOTIFICATIONS_TABLE); - $phpbb_container->set('notification_manager', $phpbb_notifications); - // Notification Types - $notification_types = array('quote', 'bookmark', 'post', 'post_in_queue'); + $notification_types = array('quote', 'bookmark', 'post', 'post_in_queue', 'topic', 'approve_topic', 'approve_post'); + $notification_types_array = array(); foreach ($notification_types as $type) { $class_name = 'phpbb_notification_type_' . $type; - $phpbb_container->set('notification.type.' . $type, new $class_name( + $class = new $class_name( $user_loader, $db, $cache, $user, $auth, $config, $phpbb_root_path, $phpEx, - NOTIFICATION_TYPES_TABLE, NOTIFICATIONS_TABLE, USER_NOTIFICATIONS_TABLE)); + NOTIFICATION_TYPES_TABLE, NOTIFICATIONS_TABLE, USER_NOTIFICATIONS_TABLE); + + $phpbb_container->set('notification.type.' . $type, $class); + + $notification_types_array['notification.type.' . $type] = $class; } + + // Notification Manager + $phpbb_notifications = new phpbb_notification_manager($notification_types_array, array(), + $phpbb_container, $user_loader, $db, $cache, $user, + $phpbb_root_path, $phpEx, + NOTIFICATION_TYPES_TABLE, NOTIFICATIONS_TABLE, USER_NOTIFICATIONS_TABLE); + $phpbb_container->set('notification_manager', $phpbb_notifications); } /** @@ -119,7 +129,7 @@ class phpbb_notification_submit_post_base extends phpbb_database_test_case public function test_submit_post($additional_post_data, $expected_before, $expected_after) { $sql = 'SELECT user_id, item_id, item_parent_id - FROM ' . NOTIFICATIONS_TABLE . ' n, ' . NOTIFICATIONS_TYPES_TABLE . " nt + FROM ' . NOTIFICATIONS_TABLE . ' n, ' . NOTIFICATION_TYPES_TABLE . " nt WHERE nt.notification_type_name = '" . $this->item_type . "' AND n.notification_type_id = nt.notification_type_id ORDER BY user_id, item_id ASC"; @@ -132,7 +142,7 @@ class phpbb_notification_submit_post_base extends phpbb_database_test_case submit_post('reply', '', 'poster-name', POST_NORMAL, $poll_data, $post_data, false, false); $sql = 'SELECT user_id, item_id, item_parent_id - FROM ' . NOTIFICATIONS_TABLE . ' n, ' . NOTIFICATIONS_TYPES_TABLE . " nt + FROM ' . NOTIFICATIONS_TABLE . ' n, ' . NOTIFICATION_TYPES_TABLE . " nt WHERE nt.notification_type_name = '" . $this->item_type . "' AND n.notification_type_id = nt.notification_type_id ORDER BY user_id ASC, item_id ASC"; -- cgit v1.2.1 From 8a4260703fa76bb92f144b527b3d55289568db74 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 30 Apr 2013 10:32:01 +0200 Subject: [ticket/11495] Fix some docs and replace branch with other terms PHPBB3-11495 --- tests/tree/nestedset_forum_get_data_test.php | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'tests') diff --git a/tests/tree/nestedset_forum_get_data_test.php b/tests/tree/nestedset_forum_get_data_test.php index 71c1d8bf8a..300bbc6bfa 100644 --- a/tests/tree/nestedset_forum_get_data_test.php +++ b/tests/tree/nestedset_forum_get_data_test.php @@ -11,7 +11,7 @@ require_once dirname(__FILE__) . '/nestedset_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() + public function get_path_and_subtree_data_data() { return array( array(1, true, true, array(1, 2, 3)), @@ -32,14 +32,14 @@ class phpbb_tests_tree_nestedset_forum_get_data_test extends phpbb_tests_tree_ne } /** - * @dataProvider get_full_branch_data_data + * @dataProvider get_path_and_subtree_data_data */ - public function test_get_full_branch_data($forum_id, $order_desc, $include_item, $expected) + public function test_get_path_and_subtree_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))); + $this->assertEquals($expected, array_keys($this->set->get_path_and_subtree_data($forum_id, $order_desc, $include_item))); } - public function get_parent_branch_data_data() + public function get_path_data_data() { return array( array(1, true, true, array(1)), @@ -60,14 +60,14 @@ class phpbb_tests_tree_nestedset_forum_get_data_test extends phpbb_tests_tree_ne } /** - * @dataProvider get_parent_branch_data_data + * @dataProvider get_path_data_data */ - public function test_get_parent_branch_data($forum_id, $order_desc, $include_item, $expected) + public function test_get_path_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))); + $this->assertEquals($expected, array_keys($this->set->get_path_data($forum_id, $order_desc, $include_item))); } - public function get_children_branch_data_data() + public function get_subtree_data_data() { return array( array(1, true, true, array(1, 2, 3)), @@ -88,11 +88,11 @@ class phpbb_tests_tree_nestedset_forum_get_data_test extends phpbb_tests_tree_ne } /** - * @dataProvider get_children_branch_data_data + * @dataProvider get_subtree_data_data */ - public function test_get_children_branch_data($forum_id, $order_desc, $include_item, $expected) + public function test_get_subtree_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))); + $this->assertEquals($expected, array_keys($this->set->get_subtree_data($forum_id, $order_desc, $include_item))); } public function get_parent_data_data() -- cgit v1.2.1 From 4810c61fd7b912ea2914b99f7db502b6f503068f Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 30 Apr 2013 10:37:59 +0200 Subject: [ticket/11495] Remove get_parent_data from interface and rename it The method is implementation specific and has no use, apart from cache, that is not covered by get_path_data(). PHPBB3-11495 --- tests/tree/nestedset_forum_get_data_test.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'tests') diff --git a/tests/tree/nestedset_forum_get_data_test.php b/tests/tree/nestedset_forum_get_data_test.php index 300bbc6bfa..7a4fada880 100644 --- a/tests/tree/nestedset_forum_get_data_test.php +++ b/tests/tree/nestedset_forum_get_data_test.php @@ -95,7 +95,7 @@ class phpbb_tests_tree_nestedset_forum_get_data_test extends phpbb_tests_tree_ne $this->assertEquals($expected, array_keys($this->set->get_subtree_data($forum_id, $order_desc, $include_item))); } - public function get_parent_data_data() + public function get_path_basic_data_data() { return array( array(1, array(), array()), @@ -108,10 +108,10 @@ class phpbb_tests_tree_nestedset_forum_get_data_test extends phpbb_tests_tree_ne } /** - * @dataProvider get_parent_data_data + * @dataProvider get_path_basic_data_data */ - public function test_get_parent_data($forum_id, $forum_data, $expected) + public function test_get_path_basic_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)))); + $this->assertEquals($expected, array_keys($this->set->get_path_basic_data(array_merge($this->forum_data[$forum_id], $forum_data)))); } } -- cgit v1.2.1 From 67f2edae170576104e619ffb38672cabf44e20fa Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 30 Apr 2013 13:54:50 +0200 Subject: [ticket/11495] Use descendants and ancestors instead of parents/children PHPBB3-11495 --- tests/tree/nestedset_forum_get_data_test.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'tests') diff --git a/tests/tree/nestedset_forum_get_data_test.php b/tests/tree/nestedset_forum_get_data_test.php index 7a4fada880..49586fbade 100644 --- a/tests/tree/nestedset_forum_get_data_test.php +++ b/tests/tree/nestedset_forum_get_data_test.php @@ -34,9 +34,9 @@ class phpbb_tests_tree_nestedset_forum_get_data_test extends phpbb_tests_tree_ne /** * @dataProvider get_path_and_subtree_data_data */ - public function test_get_path_and_subtree_data($forum_id, $order_desc, $include_item, $expected) + public function test_get_path_and_subtree_data($forum_id, $order_asc, $include_item, $expected) { - $this->assertEquals($expected, array_keys($this->set->get_path_and_subtree_data($forum_id, $order_desc, $include_item))); + $this->assertEquals($expected, array_keys($this->set->get_path_and_subtree_data($forum_id, $order_asc, $include_item))); } public function get_path_data_data() @@ -62,9 +62,9 @@ class phpbb_tests_tree_nestedset_forum_get_data_test extends phpbb_tests_tree_ne /** * @dataProvider get_path_data_data */ - public function test_get_path_data($forum_id, $order_desc, $include_item, $expected) + public function test_get_path_data($forum_id, $order_asc, $include_item, $expected) { - $this->assertEquals($expected, array_keys($this->set->get_path_data($forum_id, $order_desc, $include_item))); + $this->assertEquals($expected, array_keys($this->set->get_path_data($forum_id, $order_asc, $include_item))); } public function get_subtree_data_data() @@ -90,9 +90,9 @@ class phpbb_tests_tree_nestedset_forum_get_data_test extends phpbb_tests_tree_ne /** * @dataProvider get_subtree_data_data */ - public function test_get_subtree_data($forum_id, $order_desc, $include_item, $expected) + public function test_get_subtree_data($forum_id, $order_asc, $include_item, $expected) { - $this->assertEquals($expected, array_keys($this->set->get_subtree_data($forum_id, $order_desc, $include_item))); + $this->assertEquals($expected, array_keys($this->set->get_subtree_data($forum_id, $order_asc, $include_item))); } public function get_path_basic_data_data() -- cgit v1.2.1 From 863d0c7687cc926dfda0ddd20b34e7942748fb2e Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 30 Apr 2013 14:36:26 +0200 Subject: [ticket/11495] Fix some more comments and the package tag PHPBB3-11495 --- tests/tree/nestedset_forum_base.php | 2 +- tests/tree/nestedset_forum_get_data_test.php | 2 +- tests/tree/nestedset_forum_insert_delete_test.php | 2 +- tests/tree/nestedset_forum_move_test.php | 2 +- tests/tree/nestedset_forum_regenerate_test.php | 2 +- tests/tree/nestedset_forum_test.php | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) (limited to 'tests') diff --git a/tests/tree/nestedset_forum_base.php b/tests/tree/nestedset_forum_base.php index bfb97ba63e..2b617fcc53 100644 --- a/tests/tree/nestedset_forum_base.php +++ b/tests/tree/nestedset_forum_base.php @@ -1,7 +1,7 @@ Date: Tue, 30 Apr 2013 15:48:29 +0200 Subject: [ticket/11495] Add owns_lock() method to lock classes PHPBB3-11495 --- tests/lock/db_test.php | 14 ++++++++++++++ tests/lock/flock_test.php | 11 +++++++++++ 2 files changed, 25 insertions(+) (limited to 'tests') diff --git a/tests/lock/db_test.php b/tests/lock/db_test.php index f7b1557a0c..de7a23fd05 100644 --- a/tests/lock/db_test.php +++ b/tests/lock/db_test.php @@ -32,13 +32,18 @@ class phpbb_lock_db_test extends phpbb_database_test_case public function test_new_lock() { + $this->assertFalse($this->lock->owns_lock()); + $this->assertTrue($this->lock->acquire()); + $this->assertTrue($this->lock->owns_lock()); $this->assertTrue(isset($this->config['test_lock']), 'Lock was created'); $lock2 = new phpbb_lock_db('test_lock', $this->config, $this->db); $this->assertFalse($lock2->acquire()); + $this->assertFalse($lock2->owns_lock()); $this->lock->release(); + $this->assertFalse($this->lock->owns_lock()); $this->assertEquals('0', $this->config['test_lock'], 'Lock was released'); } @@ -50,31 +55,40 @@ class phpbb_lock_db_test extends phpbb_database_test_case public function test_double_lock() { + $this->assertFalse($this->lock->owns_lock()); + $this->assertTrue($this->lock->acquire()); + $this->assertTrue($this->lock->owns_lock()); $this->assertTrue(isset($this->config['test_lock']), 'Lock was created'); $value = $this->config['test_lock']; $this->assertFalse($this->lock->acquire()); + $this->assertTrue($this->lock->owns_lock()); $this->assertEquals($value, $this->config['test_lock'], 'Second lock failed'); $this->lock->release(); + $this->assertFalse($this->lock->owns_lock()); $this->assertEquals('0', $this->config['test_lock'], 'Lock was released'); } public function test_double_unlock() { $this->assertTrue($this->lock->acquire()); + $this->assertTrue($this->lock->owns_lock()); $this->assertFalse(empty($this->config['test_lock']), 'First lock is acquired'); $this->lock->release(); + $this->assertFalse($this->lock->owns_lock()); $this->assertEquals('0', $this->config['test_lock'], 'First lock is released'); $lock2 = new phpbb_lock_db('test_lock', $this->config, $this->db); $this->assertTrue($lock2->acquire()); + $this->assertTrue($lock2->owns_lock()); $this->assertFalse(empty($this->config['test_lock']), 'Second lock is acquired'); $this->lock->release(); + $this->assertTrue($lock2->owns_lock()); $this->assertFalse(empty($this->config['test_lock']), 'Double release of first lock is ignored'); $lock2->release(); diff --git a/tests/lock/flock_test.php b/tests/lock/flock_test.php index 1edc96b3a4..8f0b866ab3 100644 --- a/tests/lock/flock_test.php +++ b/tests/lock/flock_test.php @@ -26,15 +26,21 @@ class phpbb_lock_flock_test extends phpbb_test_case $lock = new phpbb_lock_flock($path); $ok = $lock->acquire(); $this->assertTrue($ok); + $this->assertTrue($lock->owns_lock()); $lock->release(); + $this->assertFalse($lock->owns_lock()); $ok = $lock->acquire(); $this->assertTrue($ok); + $this->assertTrue($lock->owns_lock()); $lock->release(); + $this->assertFalse($lock->owns_lock()); $ok = $lock->acquire(); $this->assertTrue($ok); + $this->assertTrue($lock->owns_lock()); $lock->release(); + $this->assertFalse($lock->owns_lock()); } /* This hangs the process. @@ -77,15 +83,18 @@ class phpbb_lock_flock_test extends phpbb_test_case $ok = $lock->acquire(); $delta = time() - $start; $this->assertTrue($ok); + $this->assertTrue($lock->owns_lock()); $this->assertGreaterThan(0.5, $delta, 'First lock acquired too soon'); $lock->release(); + $this->assertFalse($lock->owns_lock()); // acquire again, this should be instantaneous $start = time(); $ok = $lock->acquire(); $delta = time() - $start; $this->assertTrue($ok); + $this->assertTrue($lock->owns_lock()); $this->assertLessThan(0.1, $delta, 'Second lock not acquired instantaneously'); // reap the child @@ -99,8 +108,10 @@ class phpbb_lock_flock_test extends phpbb_test_case $lock = new phpbb_lock_flock($path); $ok = $lock->acquire(); $this->assertTrue($ok); + $this->assertTrue($lock->owns_lock()); sleep(2); $lock->release(); + $this->assertFalse($lock->owns_lock()); // and go away silently pcntl_exec('/usr/bin/env', array('true')); -- cgit v1.2.1 From 39ff3ed15fc77215153a47a870e8cde5436674ae Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 30 Apr 2013 18:05:44 +0200 Subject: [ticket/11495] Add proper testing of item_parent to tests PHPBB3-11495 --- tests/tree/nestedset_forum_base.php | 30 +- tests/tree/nestedset_forum_get_data_test.php | 18 +- tests/tree/nestedset_forum_insert_delete_test.php | 58 +-- tests/tree/nestedset_forum_move_test.php | 530 +++++++++++----------- tests/tree/nestedset_forum_test.php | 78 ++-- 5 files changed, 360 insertions(+), 354 deletions(-) (limited to 'tests') diff --git a/tests/tree/nestedset_forum_base.php b/tests/tree/nestedset_forum_base.php index 2b617fcc53..b9d42fb51d 100644 --- a/tests/tree/nestedset_forum_base.php +++ b/tests/tree/nestedset_forum_base.php @@ -16,27 +16,27 @@ class phpbb_tests_tree_nestedset_forum_base extends phpbb_database_test_case 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' => ''), + 1 => array('forum_id' => 1, 'parent_id' => 0, 'user_id' => 0, 'left_id' => 1, 'right_id' => 6, 'forum_parents' => 'a:0:{}'), + 2 => array('forum_id' => 2, 'parent_id' => 1, 'user_id' => 0, 'left_id' => 2, 'right_id' => 3, 'forum_parents' => 'a:0:{}'), + 3 => array('forum_id' => 3, 'parent_id' => 1, 'user_id' => 0, 'left_id' => 4, 'right_id' => 5, 'forum_parents' => 'a:0:{}'), // \ / // \/ - 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' => ''), + 4 => array('forum_id' => 4, 'parent_id' => 0, 'user_id' => 0, 'left_id' => 7, 'right_id' => 12, 'forum_parents' => 'a:0:{}'), + 5 => array('forum_id' => 5, 'parent_id' => 4, 'user_id' => 0, 'left_id' => 8, 'right_id' => 11, 'forum_parents' => 'a:0:{}'), + 6 => array('forum_id' => 6, 'parent_id' => 5, 'user_id' => 0, 'left_id' => 9, 'right_id' => 10, 'forum_parents' => 'a:0:{}'), // \_ _/ // \/ - 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' => ''), + 7 => array('forum_id' => 7, 'parent_id' => 0, 'user_id' => 0, 'left_id' => 13, 'right_id' => 22, 'forum_parents' => 'a:0:{}'), + 8 => array('forum_id' => 8, 'parent_id' => 7, 'user_id' => 0, 'left_id' => 14, 'right_id' => 15, 'forum_parents' => 'a:0:{}'), + 9 => array('forum_id' => 9, 'parent_id' => 7, 'user_id' => 0, 'left_id' => 16, 'right_id' => 19, 'forum_parents' => 'a:0:{}'), + 10 => array('forum_id' => 10, 'parent_id' => 9, 'user_id' => 0, 'left_id' => 17, 'right_id' => 18, 'forum_parents' => 'a:0:{}'), + 11 => array('forum_id' => 11, 'parent_id' => 7, 'user_id' => 0, 'left_id' => 20, 'right_id' => 21, 'forum_parents' => 'a:0:{}'), // 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' => ''), + 0 => array('forum_id' => 0, 'parent_id' => 0, 'user_id' => 0, 'left_id' => 0, 'right_id' => 0, 'forum_parents' => 'a:0:{}'), + 200 => array('forum_id' => 200, 'parent_id' => 0, 'user_id' => 0, 'left_id' => 0, 'right_id' => 0, 'forum_parents' => 'a:0:{}'), ); protected $set, @@ -59,6 +59,10 @@ class phpbb_tests_tree_nestedset_forum_base extends phpbb_database_test_case $this->set = new phpbb_tree_nestedset_forum($this->db, $this->lock, 'phpbb_forums'); $this->set_up_forums(); + + $sql = "UPDATE phpbb_forums + SET forum_parents = 'a:0:{}'"; + $this->db->sql_query($sql); } protected function set_up_forums() diff --git a/tests/tree/nestedset_forum_get_data_test.php b/tests/tree/nestedset_forum_get_data_test.php index 76c99650aa..ca1863e55e 100644 --- a/tests/tree/nestedset_forum_get_data_test.php +++ b/tests/tree/nestedset_forum_get_data_test.php @@ -98,20 +98,22 @@ class phpbb_tests_tree_nestedset_forum_get_data_test extends phpbb_tests_tree_ne public function get_path_basic_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)), + array(1, '', array()), + array(1, serialize(array()), array()), + array(2, '', array(1)), + array(2, serialize(array(1 => array())), array(1)), + array(10, '', array(7, 9)), + array(10, serialize(array(7 => array(), 9 => array())), array(7, 9)), ); } /** * @dataProvider get_path_basic_data_data */ - public function test_get_path_basic_data($forum_id, $forum_data, $expected) + public function test_get_path_basic_data($forum_id, $forum_parents, $expected) { - $this->assertEquals($expected, array_keys($this->set->get_path_basic_data(array_merge($this->forum_data[$forum_id], $forum_data)))); + $forum_data = $this->forum_data[$forum_id]; + $forum_data['forum_parents'] = $forum_parents; + $this->assertEquals($expected, array_keys($this->set->get_path_basic_data($forum_data))); } } diff --git a/tests/tree/nestedset_forum_insert_delete_test.php b/tests/tree/nestedset_forum_insert_delete_test.php index d11180ca78..34aac19270 100644 --- a/tests/tree/nestedset_forum_insert_delete_test.php +++ b/tests/tree/nestedset_forum_insert_delete_test.php @@ -15,26 +15,26 @@ class phpbb_tests_tree_nestedset_forum_add_remove_test extends phpbb_tests_tree_ { 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('forum_id' => 4, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 6, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 2, 'right_id' => 5, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 3, 'right_id' => 4, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 7, 'right_id' => 16, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 8, 'right_id' => 9, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 10, 'right_id' => 13, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 11, 'right_id' => 12, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 15, 'forum_parents' => 'a:0:{}'), )), 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' => ''), + array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 4, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 2, 'right_id' => 3, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 5, 'right_id' => 10, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 6, 'right_id' => 9, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 7, 'right_id' => 8, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 11, 'right_id' => 20, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 12, 'right_id' => 13, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 17, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 15, 'right_id' => 16, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 18, 'right_id' => 19, 'forum_parents' => 'a:0:{}'), )), ); } @@ -64,19 +64,19 @@ class phpbb_tests_tree_nestedset_forum_add_remove_test extends phpbb_tests_tree_ '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' => 1, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 6, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 2, 'right_id' => 3, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 4, 'right_id' => 5, 'forum_parents' => 'a:0:{}'), - 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' => 4, 'parent_id' => 0, 'left_id' => 7, 'right_id' => 12, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 8, 'right_id' => 11, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 9, 'right_id' => 10, 'forum_parents' => 'a:0:{}'), - 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' => 7, 'parent_id' => 0, 'left_id' => 13, 'right_id' => 22, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 15, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 16, 'right_id' => 19, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 17, 'right_id' => 18, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 20, 'right_id' => 21, 'forum_parents' => 'a:0:{}'), array('forum_id' => 12, 'parent_id' => 0, 'left_id' => 23, 'right_id' => 24, 'forum_parents' => ''), )), diff --git a/tests/tree/nestedset_forum_move_test.php b/tests/tree/nestedset_forum_move_test.php index 2407a43ab6..0901082926 100644 --- a/tests/tree/nestedset_forum_move_test.php +++ b/tests/tree/nestedset_forum_move_test.php @@ -16,101 +16,101 @@ class phpbb_tests_tree_nestedset_forum_move_test extends phpbb_tests_tree_nested 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('forum_id' => 1, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 6, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 2, 'right_id' => 3, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 4, 'right_id' => 5, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 7, 'right_id' => 12, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 8, 'right_id' => 11, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 9, 'right_id' => 10, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 13, 'right_id' => 22, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 15, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 16, 'right_id' => 19, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 17, 'right_id' => 18, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 20, 'right_id' => 21, 'forum_parents' => 'a:0:{}'), )), 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('forum_id' => 1, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 6, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 2, 'right_id' => 3, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 4, 'right_id' => 5, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 7, 'right_id' => 12, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 8, 'right_id' => 11, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 9, 'right_id' => 10, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 13, 'right_id' => 22, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 15, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 16, 'right_id' => 19, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 17, 'right_id' => 18, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 20, 'right_id' => 21, 'forum_parents' => 'a:0:{}'), )), 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('forum_id' => 4, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 6, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 2, 'right_id' => 5, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 3, 'right_id' => 4, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 7, 'right_id' => 12, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 8, 'right_id' => 9, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 10, 'right_id' => 11, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 13, 'right_id' => 22, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 15, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 16, 'right_id' => 19, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 17, 'right_id' => 18, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 20, 'right_id' => 21, 'forum_parents' => 'a:0:{}'), )), 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('forum_id' => 4, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 6, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 2, 'right_id' => 5, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 3, 'right_id' => 4, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 7, 'right_id' => 12, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 8, 'right_id' => 9, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 10, 'right_id' => 11, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 13, 'right_id' => 22, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 15, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 16, 'right_id' => 19, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 17, 'right_id' => 18, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 20, 'right_id' => 21, 'forum_parents' => 'a:0:{}'), )), 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('forum_id' => 1, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 6, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 2, 'right_id' => 3, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 4, 'right_id' => 5, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 7, 'right_id' => 16, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 8, 'right_id' => 9, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 10, 'right_id' => 13, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 11, 'right_id' => 12, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 15, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 17, 'right_id' => 22, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 18, 'right_id' => 21, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 19, 'right_id' => 20, 'forum_parents' => 'a:0:{}'), )), 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('forum_id' => 7, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 10, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 2, 'right_id' => 3, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 4, 'right_id' => 7, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 5, 'right_id' => 6, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 8, 'right_id' => 9, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 11, 'right_id' => 16, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 12, 'right_id' => 13, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 14, 'right_id' => 15, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 17, 'right_id' => 22, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 18, 'right_id' => 21, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 19, 'right_id' => 20, 'forum_parents' => 'a:0:{}'), )), 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' => ''), + array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 10, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 2, 'right_id' => 3, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 4, 'right_id' => 7, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 5, 'right_id' => 6, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 8, 'right_id' => 9, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 11, 'right_id' => 16, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 12, 'right_id' => 13, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 14, 'right_id' => 15, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 17, 'right_id' => 22, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 18, 'right_id' => 21, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 19, 'right_id' => 20, 'forum_parents' => 'a:0:{}'), )), ); } @@ -133,31 +133,31 @@ class phpbb_tests_tree_nestedset_forum_move_test extends phpbb_tests_tree_nested 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('forum_id' => 1, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 6, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 2, 'right_id' => 3, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 4, 'right_id' => 5, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 7, 'right_id' => 12, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 8, 'right_id' => 11, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 9, 'right_id' => 10, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 13, 'right_id' => 22, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 15, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 16, 'right_id' => 19, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 17, 'right_id' => 18, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 20, 'right_id' => 21, 'forum_parents' => 'a:0:{}'), )), 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' => ''), + array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 6, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 2, 'right_id' => 5, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 3, 'right_id' => 4, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 7, 'right_id' => 12, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 8, 'right_id' => 9, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 10, 'right_id' => 11, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 13, 'right_id' => 22, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 15, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 16, 'right_id' => 19, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 17, 'right_id' => 18, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 20, 'right_id' => 21, 'forum_parents' => 'a:0:{}'), )), ); } @@ -180,31 +180,31 @@ class phpbb_tests_tree_nestedset_forum_move_test extends phpbb_tests_tree_nested 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('forum_id' => 1, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 6, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 2, 'right_id' => 3, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 4, 'right_id' => 5, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 7, 'right_id' => 12, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 8, 'right_id' => 11, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 9, 'right_id' => 10, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 13, 'right_id' => 22, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 15, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 16, 'right_id' => 19, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 17, 'right_id' => 18, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 20, 'right_id' => 21, 'forum_parents' => 'a:0:{}'), )), 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' => ''), + array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 6, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 2, 'right_id' => 5, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 3, 'right_id' => 4, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 7, 'right_id' => 12, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 8, 'right_id' => 9, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 10, 'right_id' => 11, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 13, 'right_id' => 22, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 15, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 16, 'right_id' => 19, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 17, 'right_id' => 18, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 20, 'right_id' => 21, 'forum_parents' => 'a:0:{}'), )), ); } @@ -227,131 +227,131 @@ class phpbb_tests_tree_nestedset_forum_move_test extends phpbb_tests_tree_nested 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('forum_id' => 1, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 6, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 2, 'right_id' => 3, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 4, 'right_id' => 5, 'forum_parents' => 'a:0:{}'), + + array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 7, 'right_id' => 12, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 8, 'right_id' => 11, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 9, 'right_id' => 10, 'forum_parents' => 'a:0:{}'), + + array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 13, 'right_id' => 22, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 15, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 16, 'right_id' => 19, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 17, 'right_id' => 18, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 20, 'right_id' => 21, 'forum_parents' => 'a:0:{}'), )), 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('forum_id' => 1, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 6, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 2, 'right_id' => 3, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 4, 'right_id' => 5, 'forum_parents' => 'a:0:{}'), + + array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 7, 'right_id' => 12, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 8, 'right_id' => 11, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 9, 'right_id' => 10, 'forum_parents' => 'a:0:{}'), + + array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 13, 'right_id' => 22, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 15, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 16, 'right_id' => 19, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 17, 'right_id' => 18, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 20, 'right_id' => 21, 'forum_parents' => 'a:0:{}'), )), 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' => 1, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 8, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 2, 'right_id' => 3, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 4, 'right_id' => 5, 'forum_parents' => 'a:0:{}'), 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' => 4, 'parent_id' => 0, 'left_id' => 9, 'right_id' => 12, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 10, 'right_id' => 11, 'forum_parents' => 'a:0:{}'), - 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' => 7, 'parent_id' => 0, 'left_id' => 13, 'right_id' => 22, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 15, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 16, 'right_id' => 19, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 17, 'right_id' => 18, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 20, 'right_id' => 21, 'forum_parents' => 'a:0:{}'), )), 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' => 1, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 10, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 2, 'right_id' => 3, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 4, 'right_id' => 5, 'forum_parents' => 'a:0:{}'), 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' => 4, 'parent_id' => 0, 'left_id' => 11, 'right_id' => 12, 'forum_parents' => 'a:0:{}'), - 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' => 7, 'parent_id' => 0, 'left_id' => 13, 'right_id' => 22, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 15, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 16, 'right_id' => 19, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 17, 'right_id' => 18, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 20, 'right_id' => 21, 'forum_parents' => 'a:0:{}'), )), 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' => 1, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 6, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 2, 'right_id' => 3, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 4, 'right_id' => 5, 'forum_parents' => 'a:0:{}'), + + array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 7, 'right_id' => 10, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 8, 'right_id' => 9, 'forum_parents' => 'a:0:{}'), + + array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 11, 'right_id' => 22, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 12, 'right_id' => 13, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 17, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 15, 'right_id' => 16, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 18, 'right_id' => 19, 'forum_parents' => 'a:0:{}'), 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' => 1, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 6, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 2, 'right_id' => 3, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 4, 'right_id' => 5, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 7, 'right_id' => 8, 'forum_parents' => ''), + array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 7, 'right_id' => 8, 'forum_parents' => 'a:0:{}'), - 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' => 7, 'parent_id' => 0, 'left_id' => 9, 'right_id' => 22, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 10, 'right_id' => 11, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 12, 'right_id' => 15, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 13, 'right_id' => 14, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 16, 'right_id' => 17, 'forum_parents' => 'a:0:{}'), 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' => 1, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 6, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 2, 'right_id' => 3, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 4, 'right_id' => 5, 'forum_parents' => 'a:0:{}'), - 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' => 4, 'parent_id' => 0, 'left_id' => 7, 'right_id' => 10, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 8, 'right_id' => 9, 'forum_parents' => 'a:0:{}'), - 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' => 7, 'parent_id' => 0, 'left_id' => 11, 'right_id' => 20, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 12, 'right_id' => 13, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 17, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 15, 'right_id' => 16, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 18, 'right_id' => 19, 'forum_parents' => 'a:0:{}'), 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' => 1, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 6, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 2, 'right_id' => 3, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 4, 'right_id' => 5, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 7, 'right_id' => 8, 'forum_parents' => ''), + array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 7, 'right_id' => 8, 'forum_parents' => 'a:0:{}'), - 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' => 7, 'parent_id' => 0, 'left_id' => 9, 'right_id' => 18, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 10, 'right_id' => 11, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 12, 'right_id' => 15, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 13, 'right_id' => 14, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 16, 'right_id' => 17, 'forum_parents' => 'a:0:{}'), 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' => ''), @@ -416,98 +416,98 @@ class phpbb_tests_tree_nestedset_forum_move_test extends phpbb_tests_tree_nested 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' => 1, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 8, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 2, 'right_id' => 3, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 4, 'right_id' => 5, 'forum_parents' => 'a:0:{}'), 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' => 4, 'parent_id' => 0, 'left_id' => 9, 'right_id' => 12, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 10, 'right_id' => 11, 'forum_parents' => 'a:0:{}'), - 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' => 7, 'parent_id' => 0, 'left_id' => 13, 'right_id' => 22, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 15, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 16, 'right_id' => 19, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 17, 'right_id' => 18, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 20, 'right_id' => 21, 'forum_parents' => 'a:0:{}'), )), 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' => 1, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 10, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 2, 'right_id' => 3, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 4, 'right_id' => 5, 'forum_parents' => 'a:0:{}'), 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' => 4, 'parent_id' => 0, 'left_id' => 11, 'right_id' => 12, 'forum_parents' => 'a:0:{}'), - 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' => 7, 'parent_id' => 0, 'left_id' => 13, 'right_id' => 22, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 15, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 16, 'right_id' => 19, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 17, 'right_id' => 18, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 20, 'right_id' => 21, 'forum_parents' => 'a:0:{}'), )), 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' => 1, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 6, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 2, 'right_id' => 3, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 4, 'right_id' => 5, 'forum_parents' => 'a:0:{}'), + + array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 7, 'right_id' => 10, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 8, 'right_id' => 9, 'forum_parents' => 'a:0:{}'), + + array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 11, 'right_id' => 22, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 12, 'right_id' => 13, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 17, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 15, 'right_id' => 16, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 18, 'right_id' => 19, 'forum_parents' => 'a:0:{}'), 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' => 1, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 6, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 2, 'right_id' => 3, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 4, 'right_id' => 5, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 7, 'right_id' => 8, 'forum_parents' => ''), + array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 7, 'right_id' => 8, 'forum_parents' => 'a:0:{}'), - 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' => 7, 'parent_id' => 0, 'left_id' => 9, 'right_id' => 22, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 10, 'right_id' => 11, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 12, 'right_id' => 15, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 13, 'right_id' => 14, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 16, 'right_id' => 17, 'forum_parents' => 'a:0:{}'), 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' => 1, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 6, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 2, 'right_id' => 3, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 4, 'right_id' => 5, 'forum_parents' => 'a:0:{}'), - 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' => 4, 'parent_id' => 0, 'left_id' => 7, 'right_id' => 10, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 8, 'right_id' => 9, 'forum_parents' => 'a:0:{}'), - 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' => 7, 'parent_id' => 0, 'left_id' => 11, 'right_id' => 20, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 12, 'right_id' => 13, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 17, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 15, 'right_id' => 16, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 18, 'right_id' => 19, 'forum_parents' => 'a:0:{}'), 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' => 1, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 6, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 2, 'right_id' => 3, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 4, 'right_id' => 5, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 7, 'right_id' => 8, 'forum_parents' => ''), + array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 7, 'right_id' => 8, 'forum_parents' => 'a:0:{}'), - 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' => 7, 'parent_id' => 0, 'left_id' => 9, 'right_id' => 18, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 10, 'right_id' => 11, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 12, 'right_id' => 15, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 13, 'right_id' => 14, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 16, 'right_id' => 17, 'forum_parents' => 'a:0:{}'), 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' => ''), diff --git a/tests/tree/nestedset_forum_test.php b/tests/tree/nestedset_forum_test.php index 4e335f9d35..631ec2c4bc 100644 --- a/tests/tree/nestedset_forum_test.php +++ b/tests/tree/nestedset_forum_test.php @@ -15,19 +15,19 @@ class pphpbb_tests_tree_nestedset_forum_test extends phpbb_tests_tree_nestedset_ { 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' => 1, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 6, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 2, 'right_id' => 3, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 4, 'right_id' => 5, 'forum_parents' => 'a:0:{}'), - 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' => 4, 'parent_id' => 0, 'left_id' => 7, 'right_id' => 12, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 8, 'right_id' => 11, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 9, 'right_id' => 10, 'forum_parents' => 'a:0:{}'), - 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' => 7, 'parent_id' => 0, 'left_id' => 13, 'right_id' => 22, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 15, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 16, 'right_id' => 19, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 17, 'right_id' => 18, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 20, 'right_id' => 21, 'forum_parents' => 'a:0:{}'), )), ); } @@ -51,56 +51,56 @@ class pphpbb_tests_tree_nestedset_forum_test extends phpbb_tests_tree_nestedset_ %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' => 1, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 6, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 2, 'right_id' => 3, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 4, 'right_id' => 5, 'forum_parents' => 'a:0:{}'), - 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' => 4, 'parent_id' => 0, 'left_id' => 7, 'right_id' => 12, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 8, 'right_id' => 11, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 9, 'right_id' => 10, 'forum_parents' => 'a:0:{}'), - 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' => 7, 'parent_id' => 0, 'left_id' => 13, 'right_id' => 22, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 15, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 16, 'right_id' => 19, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 17, 'right_id' => 18, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 20, 'right_id' => 21, 'forum_parents' => 'a:0:{}'), )), 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' => 1, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 6, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 2, 'right_id' => 3, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 4, 'right_id' => 5, 'forum_parents' => 'a:0:{}'), - 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' => 4, 'parent_id' => 0, 'left_id' => 7, 'right_id' => 12, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 8, 'right_id' => 11, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 9, 'right_id' => 10, 'forum_parents' => 'a:0:{}'), - 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' => 7, 'parent_id' => 0, 'left_id' => 13, 'right_id' => 22, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 15, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 16, 'right_id' => 19, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 17, 'right_id' => 18, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 20, 'right_id' => 21, 'forum_parents' => 'a:0:{}'), )), 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('forum_id' => 1, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 6, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 2, 'right_id' => 3, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 4, 'right_id' => 5, 'forum_parents' => 'a:0:{}'), )), 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' => ''), + array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 6, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 2, 'right_id' => 3, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 4, 'right_id' => 5, 'forum_parents' => 'a:0:{}'), )), ); } -- cgit v1.2.1 From fe02218a2d2f5634e22e494f7b85f9701fa57623 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 30 Apr 2013 18:11:24 +0200 Subject: [ticket/11495] Remove forum_parents from tests where it is not required PHPBB3-11495 --- tests/tree/nestedset_forum_insert_delete_test.php | 64 +++--- tests/tree/nestedset_forum_move_test.php | 248 +++++++++++----------- tests/tree/nestedset_forum_test.php | 88 ++++---- 3 files changed, 200 insertions(+), 200 deletions(-) (limited to 'tests') diff --git a/tests/tree/nestedset_forum_insert_delete_test.php b/tests/tree/nestedset_forum_insert_delete_test.php index 34aac19270..1f901c7422 100644 --- a/tests/tree/nestedset_forum_insert_delete_test.php +++ b/tests/tree/nestedset_forum_insert_delete_test.php @@ -15,26 +15,26 @@ class phpbb_tests_tree_nestedset_forum_add_remove_test extends phpbb_tests_tree_ { return array( array(1, array(1, 2, 3), array( - array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 6, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 2, 'right_id' => 5, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 3, 'right_id' => 4, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 7, 'right_id' => 16, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 8, 'right_id' => 9, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 10, 'right_id' => 13, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 11, 'right_id' => 12, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 15, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 6), + array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 2, 'right_id' => 5), + array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 3, 'right_id' => 4), + array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 7, 'right_id' => 16), + array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 8, 'right_id' => 9), + array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 10, 'right_id' => 13), + array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 11, 'right_id' => 12), + array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 15), )), array(2, array(2), array( - array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 4, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 2, 'right_id' => 3, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 5, 'right_id' => 10, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 6, 'right_id' => 9, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 7, 'right_id' => 8, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 11, 'right_id' => 20, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 12, 'right_id' => 13, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 17, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 15, 'right_id' => 16, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 18, 'right_id' => 19, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 4), + array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 2, 'right_id' => 3), + array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 5, 'right_id' => 10), + array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 6, 'right_id' => 9), + array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 7, 'right_id' => 8), + array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 11, 'right_id' => 20), + array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 12, 'right_id' => 13), + array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 17), + array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 15, 'right_id' => 16), + array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 18, 'right_id' => 19), )), ); } @@ -46,7 +46,7 @@ class phpbb_tests_tree_nestedset_forum_add_remove_test extends phpbb_tests_tree_ { $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 + $result = $this->db->sql_query("SELECT forum_id, parent_id, left_id, right_id FROM phpbb_forums ORDER BY left_id, forum_id ASC"); $this->assertEquals($expected, $this->db->sql_fetchrowset($result)); @@ -64,21 +64,21 @@ class phpbb_tests_tree_nestedset_forum_add_remove_test extends phpbb_tests_tree_ 'right_id' => 24, 'forum_parents' => '', ), array( - array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 6, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 2, 'right_id' => 3, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 4, 'right_id' => 5, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 6), + array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 2, 'right_id' => 3), + array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 4, 'right_id' => 5), - array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 7, 'right_id' => 12, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 8, 'right_id' => 11, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 9, 'right_id' => 10, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 7, 'right_id' => 12), + array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 8, 'right_id' => 11), + array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 9, 'right_id' => 10), - array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 13, 'right_id' => 22, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 15, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 16, 'right_id' => 19, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 17, 'right_id' => 18, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 20, 'right_id' => 21, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 13, 'right_id' => 22), + array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 15), + array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 16, 'right_id' => 19), + array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 17, 'right_id' => 18), + array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 20, 'right_id' => 21), - array('forum_id' => 12, 'parent_id' => 0, 'left_id' => 23, 'right_id' => 24, 'forum_parents' => ''), + array('forum_id' => 12, 'parent_id' => 0, 'left_id' => 23, 'right_id' => 24), )), ); } @@ -93,7 +93,7 @@ class phpbb_tests_tree_nestedset_forum_add_remove_test extends phpbb_tests_tree_ 'forum_rules' => '', ))); - $result = $this->db->sql_query('SELECT forum_id, parent_id, left_id, right_id, forum_parents + $result = $this->db->sql_query('SELECT forum_id, parent_id, left_id, right_id 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_move_test.php b/tests/tree/nestedset_forum_move_test.php index 0901082926..fe506c8278 100644 --- a/tests/tree/nestedset_forum_move_test.php +++ b/tests/tree/nestedset_forum_move_test.php @@ -16,101 +16,101 @@ class phpbb_tests_tree_nestedset_forum_move_test extends phpbb_tests_tree_nested 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' => 'a:0:{}'), - array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 2, 'right_id' => 3, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 4, 'right_id' => 5, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 7, 'right_id' => 12, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 8, 'right_id' => 11, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 9, 'right_id' => 10, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 13, 'right_id' => 22, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 15, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 16, 'right_id' => 19, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 17, 'right_id' => 18, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 20, 'right_id' => 21, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 6), + array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 2, 'right_id' => 3), + array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 4, 'right_id' => 5), + array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 7, 'right_id' => 12), + array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 8, 'right_id' => 11), + array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 9, 'right_id' => 10), + array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 13, 'right_id' => 22), + array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 15), + array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 16, 'right_id' => 19), + array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 17, 'right_id' => 18), + array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 20, 'right_id' => 21), )), array('Move last item down', 7, -1, false, array( - array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 6, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 2, 'right_id' => 3, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 4, 'right_id' => 5, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 7, 'right_id' => 12, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 8, 'right_id' => 11, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 9, 'right_id' => 10, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 13, 'right_id' => 22, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 15, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 16, 'right_id' => 19, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 17, 'right_id' => 18, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 20, 'right_id' => 21, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 6), + array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 2, 'right_id' => 3), + array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 4, 'right_id' => 5), + array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 7, 'right_id' => 12), + array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 8, 'right_id' => 11), + array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 9, 'right_id' => 10), + array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 13, 'right_id' => 22), + array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 15), + array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 16, 'right_id' => 19), + array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 17, 'right_id' => 18), + array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 20, 'right_id' => 21), )), array('Move first item down', 1, -1, true, array( - array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 6, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 2, 'right_id' => 5, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 3, 'right_id' => 4, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 7, 'right_id' => 12, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 8, 'right_id' => 9, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 10, 'right_id' => 11, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 13, 'right_id' => 22, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 15, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 16, 'right_id' => 19, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 17, 'right_id' => 18, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 20, 'right_id' => 21, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 6), + array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 2, 'right_id' => 5), + array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 3, 'right_id' => 4), + array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 7, 'right_id' => 12), + array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 8, 'right_id' => 9), + array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 10, 'right_id' => 11), + array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 13, 'right_id' => 22), + array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 15), + array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 16, 'right_id' => 19), + array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 17, 'right_id' => 18), + array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 20, 'right_id' => 21), )), array('Move second item up', 4, 1, true, array( - array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 6, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 2, 'right_id' => 5, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 3, 'right_id' => 4, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 7, 'right_id' => 12, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 8, 'right_id' => 9, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 10, 'right_id' => 11, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 13, 'right_id' => 22, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 15, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 16, 'right_id' => 19, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 17, 'right_id' => 18, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 20, 'right_id' => 21, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 6), + array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 2, 'right_id' => 5), + array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 3, 'right_id' => 4), + array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 7, 'right_id' => 12), + array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 8, 'right_id' => 9), + array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 10, 'right_id' => 11), + array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 13, 'right_id' => 22), + array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 15), + array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 16, 'right_id' => 19), + array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 17, 'right_id' => 18), + array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 20, 'right_id' => 21), )), array('Move last item up', 7, 1, true, array( - array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 6, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 2, 'right_id' => 3, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 4, 'right_id' => 5, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 7, 'right_id' => 16, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 8, 'right_id' => 9, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 10, 'right_id' => 13, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 11, 'right_id' => 12, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 15, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 17, 'right_id' => 22, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 18, 'right_id' => 21, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 19, 'right_id' => 20, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 6), + array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 2, 'right_id' => 3), + array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 4, 'right_id' => 5), + array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 7, 'right_id' => 16), + array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 8, 'right_id' => 9), + array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 10, 'right_id' => 13), + array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 11, 'right_id' => 12), + array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 15), + array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 17, 'right_id' => 22), + array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 18, 'right_id' => 21), + array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 19, 'right_id' => 20), )), 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' => 'a:0:{}'), - array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 2, 'right_id' => 3, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 4, 'right_id' => 7, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 5, 'right_id' => 6, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 8, 'right_id' => 9, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 11, 'right_id' => 16, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 12, 'right_id' => 13, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 14, 'right_id' => 15, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 17, 'right_id' => 22, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 18, 'right_id' => 21, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 19, 'right_id' => 20, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 10), + array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 2, 'right_id' => 3), + array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 4, 'right_id' => 7), + array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 5, 'right_id' => 6), + array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 8, 'right_id' => 9), + array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 11, 'right_id' => 16), + array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 12, 'right_id' => 13), + array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 14, 'right_id' => 15), + array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 17, 'right_id' => 22), + array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 18, 'right_id' => 21), + array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 19, 'right_id' => 20), )), 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' => 'a:0:{}'), - array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 2, 'right_id' => 3, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 4, 'right_id' => 7, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 5, 'right_id' => 6, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 8, 'right_id' => 9, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 11, 'right_id' => 16, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 12, 'right_id' => 13, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 14, 'right_id' => 15, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 17, 'right_id' => 22, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 18, 'right_id' => 21, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 19, 'right_id' => 20, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 10), + array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 2, 'right_id' => 3), + array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 4, 'right_id' => 7), + array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 5, 'right_id' => 6), + array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 8, 'right_id' => 9), + array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 11, 'right_id' => 16), + array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 12, 'right_id' => 13), + array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 14, 'right_id' => 15), + array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 17, 'right_id' => 22), + array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 18, 'right_id' => 21), + array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 19, 'right_id' => 20), )), ); } @@ -122,7 +122,7 @@ class phpbb_tests_tree_nestedset_forum_move_test extends phpbb_tests_tree_nested { $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 + $result = $this->db->sql_query("SELECT forum_id, parent_id, left_id, right_id FROM phpbb_forums ORDER BY left_id, forum_id ASC"); $this->assertEquals($expected, $this->db->sql_fetchrowset($result)); @@ -133,31 +133,31 @@ class phpbb_tests_tree_nestedset_forum_move_test extends phpbb_tests_tree_nested 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' => 'a:0:{}'), - array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 2, 'right_id' => 3, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 4, 'right_id' => 5, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 7, 'right_id' => 12, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 8, 'right_id' => 11, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 9, 'right_id' => 10, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 13, 'right_id' => 22, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 15, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 16, 'right_id' => 19, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 17, 'right_id' => 18, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 20, 'right_id' => 21, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 6), + array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 2, 'right_id' => 3), + array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 4, 'right_id' => 5), + array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 7, 'right_id' => 12), + array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 8, 'right_id' => 11), + array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 9, 'right_id' => 10), + array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 13, 'right_id' => 22), + array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 15), + array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 16, 'right_id' => 19), + array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 17, 'right_id' => 18), + array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 20, 'right_id' => 21), )), array('Move first item down', 1, true, array( - array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 6, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 2, 'right_id' => 5, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 3, 'right_id' => 4, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 7, 'right_id' => 12, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 8, 'right_id' => 9, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 10, 'right_id' => 11, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 13, 'right_id' => 22, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 15, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 16, 'right_id' => 19, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 17, 'right_id' => 18, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 20, 'right_id' => 21, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 6), + array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 2, 'right_id' => 5), + array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 3, 'right_id' => 4), + array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 7, 'right_id' => 12), + array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 8, 'right_id' => 9), + array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 10, 'right_id' => 11), + array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 13, 'right_id' => 22), + array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 15), + array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 16, 'right_id' => 19), + array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 17, 'right_id' => 18), + array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 20, 'right_id' => 21), )), ); } @@ -169,7 +169,7 @@ class phpbb_tests_tree_nestedset_forum_move_test extends phpbb_tests_tree_nested { $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 + $result = $this->db->sql_query("SELECT forum_id, parent_id, left_id, right_id FROM phpbb_forums ORDER BY left_id, forum_id ASC"); $this->assertEquals($expected, $this->db->sql_fetchrowset($result)); @@ -180,31 +180,31 @@ class phpbb_tests_tree_nestedset_forum_move_test extends phpbb_tests_tree_nested 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' => 'a:0:{}'), - array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 2, 'right_id' => 3, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 4, 'right_id' => 5, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 7, 'right_id' => 12, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 8, 'right_id' => 11, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 9, 'right_id' => 10, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 13, 'right_id' => 22, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 15, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 16, 'right_id' => 19, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 17, 'right_id' => 18, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 20, 'right_id' => 21, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 6), + array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 2, 'right_id' => 3), + array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 4, 'right_id' => 5), + array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 7, 'right_id' => 12), + array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 8, 'right_id' => 11), + array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 9, 'right_id' => 10), + array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 13, 'right_id' => 22), + array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 15), + array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 16, 'right_id' => 19), + array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 17, 'right_id' => 18), + array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 20, 'right_id' => 21), )), array('Move second item up', 4, true, array( - array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 6, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 2, 'right_id' => 5, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 3, 'right_id' => 4, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 7, 'right_id' => 12, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 8, 'right_id' => 9, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 10, 'right_id' => 11, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 13, 'right_id' => 22, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 15, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 16, 'right_id' => 19, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 17, 'right_id' => 18, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 20, 'right_id' => 21, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 6), + array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 2, 'right_id' => 5), + array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 3, 'right_id' => 4), + array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 7, 'right_id' => 12), + array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 8, 'right_id' => 9), + array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 10, 'right_id' => 11), + array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 13, 'right_id' => 22), + array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 15), + array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 16, 'right_id' => 19), + array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 17, 'right_id' => 18), + array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 20, 'right_id' => 21), )), ); } @@ -216,7 +216,7 @@ class phpbb_tests_tree_nestedset_forum_move_test extends phpbb_tests_tree_nested { $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 + $result = $this->db->sql_query("SELECT forum_id, parent_id, left_id, right_id 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_test.php b/tests/tree/nestedset_forum_test.php index 631ec2c4bc..28c6b048b0 100644 --- a/tests/tree/nestedset_forum_test.php +++ b/tests/tree/nestedset_forum_test.php @@ -15,19 +15,19 @@ class pphpbb_tests_tree_nestedset_forum_test extends phpbb_tests_tree_nestedset_ { return array( array(array( - array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 6, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 2, 'right_id' => 3, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 4, 'right_id' => 5, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 6), + array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 2, 'right_id' => 3), + array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 4, 'right_id' => 5), - array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 7, 'right_id' => 12, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 8, 'right_id' => 11, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 9, 'right_id' => 10, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 7, 'right_id' => 12), + array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 8, 'right_id' => 11), + array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 9, 'right_id' => 10), - array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 13, 'right_id' => 22, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 15, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 16, 'right_id' => 19, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 17, 'right_id' => 18, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 20, 'right_id' => 21, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 13, 'right_id' => 22), + array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 15), + array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 16, 'right_id' => 19), + array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 17, 'right_id' => 18), + array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 20, 'right_id' => 21), )), ); } @@ -37,7 +37,7 @@ class pphpbb_tests_tree_nestedset_forum_test extends phpbb_tests_tree_nestedset_ */ public function test_forum_constructor($expected) { - $result = $this->db->sql_query('SELECT forum_id, parent_id, left_id, right_id, forum_parents + $result = $this->db->sql_query('SELECT forum_id, parent_id, left_id, right_id FROM phpbb_forums ORDER BY left_id, forum_id ASC'); $this->assertEquals($expected, $this->db->sql_fetchrowset($result)); @@ -46,61 +46,61 @@ class pphpbb_tests_tree_nestedset_forum_test extends phpbb_tests_tree_nestedset_ public function get_sql_where_data() { return array( - array('SELECT forum_id, parent_id, left_id, right_id, forum_parents + array('SELECT forum_id, parent_id, left_id, right_id 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' => 'a:0:{}'), - array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 2, 'right_id' => 3, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 4, 'right_id' => 5, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 6), + array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 2, 'right_id' => 3), + array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 4, 'right_id' => 5), - array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 7, 'right_id' => 12, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 8, 'right_id' => 11, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 9, 'right_id' => 10, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 7, 'right_id' => 12), + array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 8, 'right_id' => 11), + array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 9, 'right_id' => 10), - array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 13, 'right_id' => 22, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 15, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 16, 'right_id' => 19, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 17, 'right_id' => 18, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 20, 'right_id' => 21, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 13, 'right_id' => 22), + array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 15), + array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 16, 'right_id' => 19), + array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 17, 'right_id' => 18), + array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 20, 'right_id' => 21), )), - array('SELECT f.forum_id, f.parent_id, f.left_id, f.right_id, f.forum_parents + array('SELECT f.forum_id, f.parent_id, f.left_id, f.right_id 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' => 'a:0:{}'), - array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 2, 'right_id' => 3, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 4, 'right_id' => 5, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 6), + array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 2, 'right_id' => 3), + array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 4, 'right_id' => 5), - array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 7, 'right_id' => 12, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 8, 'right_id' => 11, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 9, 'right_id' => 10, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 7, 'right_id' => 12), + array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 8, 'right_id' => 11), + array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 9, 'right_id' => 10), - array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 13, 'right_id' => 22, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 15, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 16, 'right_id' => 19, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 17, 'right_id' => 18, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 20, 'right_id' => 21, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 13, 'right_id' => 22), + array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 15), + array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 16, 'right_id' => 19), + array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 17, 'right_id' => 18), + array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 20, 'right_id' => 21), )), - array('SELECT forum_id, parent_id, left_id, right_id, forum_parents + array('SELECT forum_id, parent_id, left_id, right_id 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' => 'a:0:{}'), - array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 2, 'right_id' => 3, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 4, 'right_id' => 5, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 6), + array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 2, 'right_id' => 3), + array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 4, 'right_id' => 5), )), - array('SELECT f.forum_id, f.parent_id, f.left_id, f.right_id, f.forum_parents + array('SELECT f.forum_id, f.parent_id, f.left_id, f.right_id 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' => 'a:0:{}'), - array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 2, 'right_id' => 3, 'forum_parents' => 'a:0:{}'), - array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 4, 'right_id' => 5, 'forum_parents' => 'a:0:{}'), + array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 6), + array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 2, 'right_id' => 3), + array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 4, 'right_id' => 5), )), ); } -- cgit v1.2.1 From 2f54a63b0fb998c84730e21a3af4150281c22cab Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 30 Apr 2013 18:24:54 +0200 Subject: [ticket/11495] Fix more grammar issues in doc blocks PHPBB3-11495 --- tests/tree/nestedset_forum_base.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/tree/nestedset_forum_base.php b/tests/tree/nestedset_forum_base.php index b9d42fb51d..776e822280 100644 --- a/tests/tree/nestedset_forum_base.php +++ b/tests/tree/nestedset_forum_base.php @@ -34,7 +34,7 @@ class phpbb_tests_tree_nestedset_forum_base extends phpbb_database_test_case 10 => array('forum_id' => 10, 'parent_id' => 9, 'user_id' => 0, 'left_id' => 17, 'right_id' => 18, 'forum_parents' => 'a:0:{}'), 11 => array('forum_id' => 11, 'parent_id' => 7, 'user_id' => 0, 'left_id' => 20, 'right_id' => 21, 'forum_parents' => 'a:0:{}'), - // Unexisting forums + // Non-existent forums 0 => array('forum_id' => 0, 'parent_id' => 0, 'user_id' => 0, 'left_id' => 0, 'right_id' => 0, 'forum_parents' => 'a:0:{}'), 200 => array('forum_id' => 200, 'parent_id' => 0, 'user_id' => 0, 'left_id' => 0, 'right_id' => 0, 'forum_parents' => 'a:0:{}'), ); -- cgit v1.2.1 From d1d59dc5cc3ca779c5e7a971659c8aca5e28215d Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 30 Apr 2013 18:33:28 +0200 Subject: [ticket/11495] Remove unneccessary values from tests PHPBB3-11495 --- tests/tree/nestedset_forum_test.php | 72 ++++++++++++++++++------------------- 1 file changed, 36 insertions(+), 36 deletions(-) (limited to 'tests') diff --git a/tests/tree/nestedset_forum_test.php b/tests/tree/nestedset_forum_test.php index 28c6b048b0..516c794ffc 100644 --- a/tests/tree/nestedset_forum_test.php +++ b/tests/tree/nestedset_forum_test.php @@ -46,61 +46,61 @@ class pphpbb_tests_tree_nestedset_forum_test extends phpbb_tests_tree_nestedset_ public function get_sql_where_data() { return array( - array('SELECT forum_id, parent_id, left_id, right_id + array('SELECT forum_id FROM phpbb_forums %s - ORDER BY left_id, forum_id ASC', + ORDER BY forum_id ASC', 'WHERE', '', array( - array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 6), - array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 2, 'right_id' => 3), - array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 4, 'right_id' => 5), + array('forum_id' => 1), + array('forum_id' => 2), + array('forum_id' => 3), - array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 7, 'right_id' => 12), - array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 8, 'right_id' => 11), - array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 9, 'right_id' => 10), + array('forum_id' => 4), + array('forum_id' => 5), + array('forum_id' => 6), - array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 13, 'right_id' => 22), - array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 15), - array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 16, 'right_id' => 19), - array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 17, 'right_id' => 18), - array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 20, 'right_id' => 21), + array('forum_id' => 7), + array('forum_id' => 8), + array('forum_id' => 9), + array('forum_id' => 10), + array('forum_id' => 11), )), - array('SELECT f.forum_id, f.parent_id, f.left_id, f.right_id + array('SELECT f.forum_id FROM phpbb_forums f %s - ORDER BY f.left_id, f.forum_id ASC', + ORDER BY f.forum_id ASC', 'WHERE', 'f.', array( - array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 6), - array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 2, 'right_id' => 3), - array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 4, 'right_id' => 5), + array('forum_id' => 1), + array('forum_id' => 2), + array('forum_id' => 3), - array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 7, 'right_id' => 12), - array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 8, 'right_id' => 11), - array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 9, 'right_id' => 10), + array('forum_id' => 4), + array('forum_id' => 5), + array('forum_id' => 6), - array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 13, 'right_id' => 22), - array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 15), - array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 16, 'right_id' => 19), - array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 17, 'right_id' => 18), - array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 20, 'right_id' => 21), + array('forum_id' => 7), + array('forum_id' => 8), + array('forum_id' => 9), + array('forum_id' => 10), + array('forum_id' => 11), )), - array('SELECT forum_id, parent_id, left_id, right_id + array('SELECT forum_id FROM phpbb_forums WHERE forum_id < 4 %s - ORDER BY left_id, forum_id ASC', + ORDER BY forum_id ASC', 'AND', '', array( - array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 6), - array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 2, 'right_id' => 3), - array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 4, 'right_id' => 5), + array('forum_id' => 1), + array('forum_id' => 2), + array('forum_id' => 3), )), - array('SELECT f.forum_id, f.parent_id, f.left_id, f.right_id + array('SELECT f.forum_id FROM phpbb_forums f WHERE f.forum_id < 4 %s - ORDER BY f.left_id, f.forum_id ASC', + ORDER BY f.forum_id ASC', 'AND', 'f.', array( - array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 6), - array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 2, 'right_id' => 3), - array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 4, 'right_id' => 5), + array('forum_id' => 1), + array('forum_id' => 2), + array('forum_id' => 3), )), ); } -- cgit v1.2.1 From a5b5e4b31da6f91e73b09b3c2a50d1a79e8c108d Mon Sep 17 00:00:00 2001 From: Dhruv Date: Tue, 30 Apr 2013 22:29:20 +0530 Subject: [ticket/10325] add assert_response_success in test PHPBB3-10325 --- tests/functional/forgot_password_test.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/functional/forgot_password_test.php b/tests/functional/forgot_password_test.php index 3ae74ed1e9..14dfae3d7c 100644 --- a/tests/functional/forgot_password_test.php +++ b/tests/functional/forgot_password_test.php @@ -17,6 +17,7 @@ class phpbb_functional_forgot_password_test extends phpbb_functional_test_case global $config; $this->add_lang('ucp'); $crawler = $this->request('GET', 'ucp.php?mode=sendpassword'); + $this->assert_response_success(); $this->assertEquals($this->lang('SEND_PASSWORD'), $crawler->filter('h2')->text()); } @@ -26,6 +27,7 @@ class phpbb_functional_forgot_password_test extends phpbb_functional_test_case $this->admin_login(); $this->add_lang('ucp'); $crawler = $this->request('GET', 'adm/index.php?sid=' . $this->sid . '&i=acp_board&mode=security'); + //$this->assert_response_success(); $form = $crawler->selectButton('Submit')->form(); $values = $form->getValues(); @@ -37,7 +39,7 @@ class phpbb_functional_forgot_password_test extends phpbb_functional_test_case $this->logout(); $crawler = $this->request('GET', 'ucp.php?mode=sendpassword'); - + $this->assert_response_success(); $this->assertContains($this->lang('UCP_PASSWORD_RESET_DISABLED', '', ''), $crawler->text()); } -- cgit v1.2.1 From 1d0c8a1fe86b65174ae27c2353d52b69fda2a16d Mon Sep 17 00:00:00 2001 From: Dhruv Date: Tue, 30 Apr 2013 23:09:28 +0530 Subject: [ticket/10325] use assert_response_success parts PHPBB3-10325 --- tests/functional/forgot_password_test.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/functional/forgot_password_test.php b/tests/functional/forgot_password_test.php index 14dfae3d7c..bfb4616d64 100644 --- a/tests/functional/forgot_password_test.php +++ b/tests/functional/forgot_password_test.php @@ -27,7 +27,11 @@ class phpbb_functional_forgot_password_test extends phpbb_functional_test_case $this->admin_login(); $this->add_lang('ucp'); $crawler = $this->request('GET', 'adm/index.php?sid=' . $this->sid . '&i=acp_board&mode=security'); - //$this->assert_response_success(); + $this->assertEquals(200, $this->client->getResponse()->getStatus()); + $content = $this->client->getResponse()->getContent(); + $this->assertNotContains('Fatal error:', $content); + $this->assertNotContains('Notice:', $content); + $this->assertNotContains('[phpBB Debug]', $content); $form = $crawler->selectButton('Submit')->form(); $values = $form->getValues(); -- cgit v1.2.1 From d7787682df0474b7bb78434339f8edde3727c580 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 30 Apr 2013 22:19:35 +0200 Subject: [ticket/11495] Throw exception when item that should be deleted does not exist PHPBB3-11495 --- tests/tree/nestedset_forum_insert_delete_test.php | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'tests') diff --git a/tests/tree/nestedset_forum_insert_delete_test.php b/tests/tree/nestedset_forum_insert_delete_test.php index 1f901c7422..d0e9e02c2e 100644 --- a/tests/tree/nestedset_forum_insert_delete_test.php +++ b/tests/tree/nestedset_forum_insert_delete_test.php @@ -52,6 +52,25 @@ class phpbb_tests_tree_nestedset_forum_add_remove_test extends phpbb_tests_tree_ $this->assertEquals($expected, $this->db->sql_fetchrowset($result)); } + public function delete_throws_data() + { + return array( + array('Not an item', 0), + array('Item does not exist', 200), + ); + } + + /** + * @dataProvider delete_throws_data + * + * @expectedException OutOfBoundsException + * @expectedExceptionMessage FORUM_NESTEDSET_INVALID_ITEM + */ + public function test_delete_throws($explain, $forum_id) + { + $this->set->delete($forum_id); + } + public function insert_data() { return array( -- cgit v1.2.1 From 00ea297b614a10ad045075cad6f69f2c431c2757 Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Tue, 30 Apr 2013 20:54:01 -0500 Subject: [ticket/11413] Create test for notification conversion PHPBB3-11413 --- tests/notification/convert_test.php | 114 ++++++++++++++++++++++++++++++++ tests/notification/fixtures/convert.xml | 52 +++++++++++++++ 2 files changed, 166 insertions(+) create mode 100644 tests/notification/convert_test.php create mode 100644 tests/notification/fixtures/convert.xml (limited to 'tests') diff --git a/tests/notification/convert_test.php b/tests/notification/convert_test.php new file mode 100644 index 0000000000..9fa7fc6a42 --- /dev/null +++ b/tests/notification/convert_test.php @@ -0,0 +1,114 @@ +createXMLDataSet(dirname(__FILE__) . '/fixtures/convert.xml'); + } + + protected function setUp() + { + parent::setUp(); + + global $phpbb_root_path, $phpEx; + + $this->db = $this->new_dbal(); + + $this->migration = new phpbb_db_migration_data_310_notifications2( + new phpbb_config(array()), + $this->db, + new phpbb_db_tools($this->db), + $phpbb_root_path, + $phpEx, + 'phpbb_' + ); + } + + public function test_convert() + { + $this->migration->convert_notifications(); + + $expected = array_merge( + $this->create_expected('post', 1, 'email'), + $this->create_expected('topic', 1, 'email'), + + $this->create_expected('pm', 2, 'email'), + $this->create_expected('post', 2, 'email'), + $this->create_expected('topic', 2, 'email'), + + $this->create_expected('post', 3, 'jabber'), + $this->create_expected('topic', 3, 'jabber'), + + $this->create_expected('pm', 4, 'jabber'), + $this->create_expected('post', 4, 'jabber'), + $this->create_expected('topic', 4, 'jabber'), + + $this->create_expected('post', 5, 'both'), + $this->create_expected('topic', 5, 'both'), + + $this->create_expected('pm', 6, 'both'), + $this->create_expected('post', 6, 'both'), + $this->create_expected('topic', 6, 'both') + ); + + $sql = 'SELECT * FROM phpbb_user_notifications + ORDER BY user_id ASC, item_type ASC'; + $result = $this->db->sql_query($sql); + $rowset = $this->db->sql_fetchrowset($result); + $this->db->sql_freeresult($result); + + $this->assertEquals($expected, $rowset); + } + + protected function create_expected($type, $user_id, $method = '') + { + $return = array(); + + if ($method != '') + { + $return[] = array( + 'item_type' => $type, + 'item_id' => '0', + 'user_id' => (string) $user_id, + 'method' => '', + 'notify' => '1', + ); + } + + if ($method == 'email' || $method == 'both') + { + $return[] = array( + 'item_type' => $type, + 'item_id' => '0', + 'user_id' => (string) $user_id, + 'method' => 'email', + 'notify' => '1', + ); + } + + if ($method == 'jabber' || $method == 'both') + { + $return[] = array( + 'item_type' => $type, + 'item_id' => '0', + 'user_id' => (string) $user_id, + 'method' => 'jabber', + 'notify' => '1', + ); + } + + return $return; + } +} diff --git a/tests/notification/fixtures/convert.xml b/tests/notification/fixtures/convert.xml new file mode 100644 index 0000000000..a244070a95 --- /dev/null +++ b/tests/notification/fixtures/convert.xml @@ -0,0 +1,52 @@ + + +
+ user_id + username + username_clean + user_notify_type + user_notify_pm + + 1 + 1 + 1 + 0 + 0 + + + 2 + 2 + 2 + 0 + 1 + + + 3 + 3 + 3 + 1 + 0 + + + 4 + 4 + 4 + 1 + 1 + + + 5 + 5 + 5 + 2 + 0 + + + 6 + 6 + 6 + 2 + 1 + +
+ -- cgit v1.2.1 From f2e618a05de5f406477363cb9236aca46569afe1 Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Tue, 30 Apr 2013 21:10:04 -0500 Subject: [ticket/11413] Test get_notification_type_id and _ids functions PHPBB3-11413 --- tests/notification/notification_test.php | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'tests') diff --git a/tests/notification/notification_test.php b/tests/notification/notification_test.php index 5746d0090e..4ffd3587f1 100644 --- a/tests/notification/notification_test.php +++ b/tests/notification/notification_test.php @@ -99,6 +99,35 @@ class phpbb_notification_test extends phpbb_database_test_case return new $type($this->user_loader, $this->db, $this->cache, $this->user, $this->auth, $this->config, $phpbb_root_path, $phpEx, 'phpbb_notification_types', 'phpbb_notifications', 'phpbb_user_notifications'); } + public function test_get_notification_type_id() + { + // They should be inserted the first time + $this->assertEquals(1, $this->notifications->get_notification_type_id('post')); + $this->assertEquals(2, $this->notifications->get_notification_type_id('quote')); + $this->assertEquals(3, $this->notifications->get_notification_type_id('test')); + + $this->assertEquals(array( + 'test' => 3, + 'quote' => 2, + 'post' => 1, + ), + $this->notifications->get_notification_type_ids(array( + 'test', + 'quote', + 'post', + ) + )); + $this->assertEquals(2, $this->notifications->get_notification_type_id('quote')); + + try + { + $this->assertEquals(3, $this->notifications->get_notification_type_id('fail')); + + $this->fail('Non-existant type should throw exception'); + } + catch (Exception $e) {} + } + public function test_get_subscription_types() { $subscription_types = $this->notifications->get_subscription_types(); -- cgit v1.2.1 From 2f2feaa4e8ad9a18fd9ddcb7d65ae958c544dbcb Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Tue, 30 Apr 2013 21:38:40 -0500 Subject: [ticket/11413] Don't use the database for the convert test Different databases seem to work slightly differently here and are causing errors PHPBB3-11413 --- tests/notification/convert_test.php | 37 ++++++++++++++++--------------------- 1 file changed, 16 insertions(+), 21 deletions(-) (limited to 'tests') diff --git a/tests/notification/convert_test.php b/tests/notification/convert_test.php index 9fa7fc6a42..529b2935e1 100644 --- a/tests/notification/convert_test.php +++ b/tests/notification/convert_test.php @@ -38,38 +38,33 @@ class phpbb_notification_convert_test extends phpbb_database_test_case public function test_convert() { - $this->migration->convert_notifications(); + $buffer = new phpbb_mock_sql_insert_buffer($this->db, 'phpbb_user_notifications'); + $this->migration->perform_conversion($buffer, 'phpbb_user_notifications'); $expected = array_merge( $this->create_expected('post', 1, 'email'), $this->create_expected('topic', 1, 'email'), - $this->create_expected('pm', 2, 'email'), $this->create_expected('post', 2, 'email'), $this->create_expected('topic', 2, 'email'), + $this->create_expected('pm', 2, 'email'), $this->create_expected('post', 3, 'jabber'), $this->create_expected('topic', 3, 'jabber'), - $this->create_expected('pm', 4, 'jabber'), $this->create_expected('post', 4, 'jabber'), $this->create_expected('topic', 4, 'jabber'), + $this->create_expected('pm', 4, 'jabber'), $this->create_expected('post', 5, 'both'), $this->create_expected('topic', 5, 'both'), - $this->create_expected('pm', 6, 'both'), $this->create_expected('post', 6, 'both'), - $this->create_expected('topic', 6, 'both') + $this->create_expected('topic', 6, 'both'), + $this->create_expected('pm', 6, 'both') ); - $sql = 'SELECT * FROM phpbb_user_notifications - ORDER BY user_id ASC, item_type ASC'; - $result = $this->db->sql_query($sql); - $rowset = $this->db->sql_fetchrowset($result); - $this->db->sql_freeresult($result); - - $this->assertEquals($expected, $rowset); + $this->assertEquals($expected, $buffer->get_buffer()); } protected function create_expected($type, $user_id, $method = '') @@ -80,10 +75,10 @@ class phpbb_notification_convert_test extends phpbb_database_test_case { $return[] = array( 'item_type' => $type, - 'item_id' => '0', - 'user_id' => (string) $user_id, + 'item_id' => 0, + 'user_id' => $user_id, 'method' => '', - 'notify' => '1', + 'notify' => 1, ); } @@ -91,10 +86,10 @@ class phpbb_notification_convert_test extends phpbb_database_test_case { $return[] = array( 'item_type' => $type, - 'item_id' => '0', - 'user_id' => (string) $user_id, + 'item_id' => 0, + 'user_id' => $user_id, 'method' => 'email', - 'notify' => '1', + 'notify' => 1, ); } @@ -102,10 +97,10 @@ class phpbb_notification_convert_test extends phpbb_database_test_case { $return[] = array( 'item_type' => $type, - 'item_id' => '0', - 'user_id' => (string) $user_id, + 'item_id' => 0, + 'user_id' => $user_id, 'method' => 'jabber', - 'notify' => '1', + 'notify' => 1, ); } -- cgit v1.2.1 From 900467681077b7c4cd48529b53f083c8ea0334f6 Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Tue, 30 Apr 2013 21:53:16 -0500 Subject: [ticket/11413] Include mock class PHPBB3-11413 --- tests/mock/sql_insert_buffer.php | 21 +++++++++++++++++++++ tests/notification/convert_test.php | 1 + 2 files changed, 22 insertions(+) create mode 100644 tests/mock/sql_insert_buffer.php (limited to 'tests') diff --git a/tests/mock/sql_insert_buffer.php b/tests/mock/sql_insert_buffer.php new file mode 100644 index 0000000000..ba09aa8d7f --- /dev/null +++ b/tests/mock/sql_insert_buffer.php @@ -0,0 +1,21 @@ +buffer)) ? true : false; + } + + public function get_buffer() + { + return $this->buffer; + } +} diff --git a/tests/notification/convert_test.php b/tests/notification/convert_test.php index 529b2935e1..ba586b681d 100644 --- a/tests/notification/convert_test.php +++ b/tests/notification/convert_test.php @@ -8,6 +8,7 @@ */ require_once dirname(__FILE__) . '/../../phpBB/includes/db/db_tools.php'; +require_once dirname(__FILE__) . '/../mock/sql_insert_buffer.php'; class phpbb_notification_convert_test extends phpbb_database_test_case { -- cgit v1.2.1 From 356bc00a293300a777304a3c2d442868d4491344 Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Tue, 30 Apr 2013 23:21:50 -0500 Subject: [ticket/11435] Mark extension spacing test as incomplete This test fails until 11435 is fixed Add newlines at EOF PHPBB3-11435 --- .../ext_trivial/ext/trivial/styles/all/template/variable_spacing.html | 2 +- .../datasets/ext_trivial/styles/silver/template/variable_spacing.html | 2 +- tests/template/template_spacing_test.php | 4 ++++ tests/template/templates/variable_spacing.html | 2 +- 4 files changed, 7 insertions(+), 3 deletions(-) (limited to 'tests') diff --git a/tests/template/datasets/ext_trivial/ext/trivial/styles/all/template/variable_spacing.html b/tests/template/datasets/ext_trivial/ext/trivial/styles/all/template/variable_spacing.html index 2909e1c136..028f8aa0d1 100644 --- a/tests/template/datasets/ext_trivial/ext/trivial/styles/all/template/variable_spacing.html +++ b/tests/template/datasets/ext_trivial/ext/trivial/styles/all/template/variable_spacing.html @@ -3,4 +3,4 @@ |{VARIABLE} -
test
\ No newline at end of file +
test
diff --git a/tests/template/datasets/ext_trivial/styles/silver/template/variable_spacing.html b/tests/template/datasets/ext_trivial/styles/silver/template/variable_spacing.html index c11ae9cb40..ad05e6f661 100644 --- a/tests/template/datasets/ext_trivial/styles/silver/template/variable_spacing.html +++ b/tests/template/datasets/ext_trivial/styles/silver/template/variable_spacing.html @@ -1 +1 @@ - \ No newline at end of file + diff --git a/tests/template/template_spacing_test.php b/tests/template/template_spacing_test.php index 83f8711b38..fb4161066a 100644 --- a/tests/template/template_spacing_test.php +++ b/tests/template/template_spacing_test.php @@ -59,6 +59,10 @@ class phpbb_template_template_spacing_test extends phpbb_template_template_test_ */ public function test_event($desc, $dataset, $style_names, $file, array $vars, array $block_vars, array $destroy, $expected) { + $this->markTestIncomplete( + 'This test will fail until PHPBB3-11435 is fixed' + ); + // Reset the engine state $this->setup_engine_for_events($dataset, $style_names); diff --git a/tests/template/templates/variable_spacing.html b/tests/template/templates/variable_spacing.html index 2909e1c136..028f8aa0d1 100644 --- a/tests/template/templates/variable_spacing.html +++ b/tests/template/templates/variable_spacing.html @@ -3,4 +3,4 @@ |{VARIABLE} -
test
\ No newline at end of file +
test
-- cgit v1.2.1 From 60e32728393d4258f92f7893f8275889278a995f Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Wed, 1 May 2013 14:09:08 -0500 Subject: [ticket/11415] Remove migrator dependency from extension manager PHPBB3-11415 --- tests/dbal/migrator_test.php | 6 +++++- tests/extension/manager_test.php | 6 ++++-- tests/extension/metadata_manager_test.php | 5 ++++- tests/test_framework/phpbb_functional_test_case.php | 5 ++++- 4 files changed, 17 insertions(+), 5 deletions(-) (limited to 'tests') diff --git a/tests/dbal/migrator_test.php b/tests/dbal/migrator_test.php index 6390d6a715..5fc05f2119 100644 --- a/tests/dbal/migrator_test.php +++ b/tests/dbal/migrator_test.php @@ -55,8 +55,12 @@ class phpbb_dbal_migrator_test extends phpbb_database_test_case 'phpbb_', $tools ); + + $container = new phpbb_mock_container_builder(); + $container->set('migrator', $migrator); + $this->extension_manager = new phpbb_extension_manager( - new phpbb_mock_container_builder(), + $container, $this->db, $this->config, $this->migrator, diff --git a/tests/extension/manager_test.php b/tests/extension/manager_test.php index 106f078691..43b7410654 100644 --- a/tests/extension/manager_test.php +++ b/tests/extension/manager_test.php @@ -107,11 +107,13 @@ class phpbb_extension_manager_test extends phpbb_database_test_case $table_prefix, array() ); + $container = new phpbb_mock_container_builder(); + $container->set('migrator', $migrator); + return new phpbb_extension_manager( - new phpbb_mock_container_builder(), + $container, $db, $config, - $migrator, new phpbb_filesystem(), 'phpbb_ext', dirname(__FILE__) . '/', diff --git a/tests/extension/metadata_manager_test.php b/tests/extension/metadata_manager_test.php index 05d1cbccc3..92a0ff126c 100644 --- a/tests/extension/metadata_manager_test.php +++ b/tests/extension/metadata_manager_test.php @@ -59,8 +59,11 @@ class metadata_manager_test extends phpbb_database_test_case $this->table_prefix, array() ); + $container = new phpbb_mock_container_builder(); + $container->set('migrator', $migrator); + $this->extension_manager = new phpbb_extension_manager( - new phpbb_mock_container_builder(), + $container, $this->db, $this->config, $this->migrator, diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index 5534de89c9..a11c0f72ca 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -148,8 +148,11 @@ class phpbb_functional_test_case extends phpbb_test_case self::$config['table_prefix'], array() ); + $container = new phpbb_mock_container_builder(); + $container->set('migrator', $migrator); + $extension_manager = new phpbb_extension_manager( - new phpbb_mock_container_builder(), + $container, $db, $config, $migrator, -- cgit v1.2.1 From 07c972f5d71f7aa56d6623774e977ea7958a906e Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Thu, 2 May 2013 15:39:26 -0500 Subject: [ticket/11413] Remove changes for ticket 11420 from this branch PHPBB3-11413 --- tests/notification/convert_test.php | 110 -------------------------------- tests/notification/fixtures/convert.xml | 52 --------------- 2 files changed, 162 deletions(-) delete mode 100644 tests/notification/convert_test.php delete mode 100644 tests/notification/fixtures/convert.xml (limited to 'tests') diff --git a/tests/notification/convert_test.php b/tests/notification/convert_test.php deleted file mode 100644 index ba586b681d..0000000000 --- a/tests/notification/convert_test.php +++ /dev/null @@ -1,110 +0,0 @@ -createXMLDataSet(dirname(__FILE__) . '/fixtures/convert.xml'); - } - - protected function setUp() - { - parent::setUp(); - - global $phpbb_root_path, $phpEx; - - $this->db = $this->new_dbal(); - - $this->migration = new phpbb_db_migration_data_310_notifications2( - new phpbb_config(array()), - $this->db, - new phpbb_db_tools($this->db), - $phpbb_root_path, - $phpEx, - 'phpbb_' - ); - } - - public function test_convert() - { - $buffer = new phpbb_mock_sql_insert_buffer($this->db, 'phpbb_user_notifications'); - $this->migration->perform_conversion($buffer, 'phpbb_user_notifications'); - - $expected = array_merge( - $this->create_expected('post', 1, 'email'), - $this->create_expected('topic', 1, 'email'), - - $this->create_expected('post', 2, 'email'), - $this->create_expected('topic', 2, 'email'), - $this->create_expected('pm', 2, 'email'), - - $this->create_expected('post', 3, 'jabber'), - $this->create_expected('topic', 3, 'jabber'), - - $this->create_expected('post', 4, 'jabber'), - $this->create_expected('topic', 4, 'jabber'), - $this->create_expected('pm', 4, 'jabber'), - - $this->create_expected('post', 5, 'both'), - $this->create_expected('topic', 5, 'both'), - - $this->create_expected('post', 6, 'both'), - $this->create_expected('topic', 6, 'both'), - $this->create_expected('pm', 6, 'both') - ); - - $this->assertEquals($expected, $buffer->get_buffer()); - } - - protected function create_expected($type, $user_id, $method = '') - { - $return = array(); - - if ($method != '') - { - $return[] = array( - 'item_type' => $type, - 'item_id' => 0, - 'user_id' => $user_id, - 'method' => '', - 'notify' => 1, - ); - } - - if ($method == 'email' || $method == 'both') - { - $return[] = array( - 'item_type' => $type, - 'item_id' => 0, - 'user_id' => $user_id, - 'method' => 'email', - 'notify' => 1, - ); - } - - if ($method == 'jabber' || $method == 'both') - { - $return[] = array( - 'item_type' => $type, - 'item_id' => 0, - 'user_id' => $user_id, - 'method' => 'jabber', - 'notify' => 1, - ); - } - - return $return; - } -} diff --git a/tests/notification/fixtures/convert.xml b/tests/notification/fixtures/convert.xml deleted file mode 100644 index a244070a95..0000000000 --- a/tests/notification/fixtures/convert.xml +++ /dev/null @@ -1,52 +0,0 @@ - - - - user_id - username - username_clean - user_notify_type - user_notify_pm - - 1 - 1 - 1 - 0 - 0 - - - 2 - 2 - 2 - 0 - 1 - - - 3 - 3 - 3 - 1 - 0 - - - 4 - 4 - 4 - 1 - 1 - - - 5 - 5 - 5 - 2 - 0 - - - 6 - 6 - 6 - 2 - 1 - -
-
-- cgit v1.2.1 From 77147b53c119706f5fb6ea6036056aed554adf8c Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Fri, 3 May 2013 08:38:00 -0500 Subject: [ticket/11413] Remove mock sql_insert_buffer.php (not relevant to PR) PHPBB3-11413 --- tests/mock/sql_insert_buffer.php | 21 --------------------- 1 file changed, 21 deletions(-) delete mode 100644 tests/mock/sql_insert_buffer.php (limited to 'tests') diff --git a/tests/mock/sql_insert_buffer.php b/tests/mock/sql_insert_buffer.php deleted file mode 100644 index ba09aa8d7f..0000000000 --- a/tests/mock/sql_insert_buffer.php +++ /dev/null @@ -1,21 +0,0 @@ -buffer)) ? true : false; - } - - public function get_buffer() - { - return $this->buffer; - } -} -- cgit v1.2.1 From 3c76cdeb6701a4aded7a7c39b8c9b44c00b5848a Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Fri, 3 May 2013 08:50:27 -0500 Subject: [ticket/11413] Remove remaining irrelevant code to this PR PHPBB3-11413 --- tests/notification/manager_helper.php | 8 +++----- tests/notification/notification_test.php | 4 ++-- tests/notification/submit_post_base.php | 2 +- 3 files changed, 6 insertions(+), 8 deletions(-) (limited to 'tests') diff --git a/tests/notification/manager_helper.php b/tests/notification/manager_helper.php index 8d2ce5e002..7a794f922f 100644 --- a/tests/notification/manager_helper.php +++ b/tests/notification/manager_helper.php @@ -28,12 +28,10 @@ class phpbb_notification_manager_helper extends phpbb_notification_manager // Extra dependencies for get_*_class functions protected $auth = null; - protected $cache = null; protected $config = null; - public function setDependencies($auth, $cache, $config) + public function setDependencies($auth, $config) { $this->auth = $auth; - $this->cache = $cache; $this->config = $config; } @@ -44,7 +42,7 @@ class phpbb_notification_manager_helper extends phpbb_notification_manager { $item_type = 'phpbb_notification_type_' . $item_type; - $item = new $item_type($this->user_loader, $this->db, $this->cache, $this->user, $this->auth, $this->config, $this->phpbb_root_path, $this->php_ext, $this->notification_types_table, $this->notifications_table, $this->user_notifications_table); + $item = new $item_type($this->user_loader, $this->db, $this->cache->get_driver(), $this->user, $this->auth, $this->config, $this->phpbb_root_path, $this->php_ext, $this->notification_types_table, $this->notifications_table, $this->user_notifications_table); $item->set_notification_manager($this); @@ -60,7 +58,7 @@ class phpbb_notification_manager_helper extends phpbb_notification_manager { $method_name = 'phpbb_notification_method_' . $method_name; - $method = new $method_name($this->user_loader, $this->db, $this->cache, $this->user, $this->auth, $this->config, $this->phpbb_root_path, $this->php_ext, $this->notification_types_table, $this->notifications_table, $this->user_notifications_table); + $method = new $method_name($this->user_loader, $this->db, $this->cache->get_driver(), $this->user, $this->auth, $this->config, $this->phpbb_root_path, $this->php_ext, $this->notification_types_table, $this->notifications_table, $this->user_notifications_table); $method->set_notification_manager($this); diff --git a/tests/notification/notification_test.php b/tests/notification/notification_test.php index 4ffd3587f1..c342b10a7f 100644 --- a/tests/notification/notification_test.php +++ b/tests/notification/notification_test.php @@ -61,7 +61,7 @@ class phpbb_notification_test extends phpbb_database_test_case 'phpbb_user_notifications' ); - $this->notifications->setDependencies($this->auth, $this->cache, $this->config); + $this->notifications->setDependencies($this->auth, $this->config); $types = array(); foreach (array( @@ -123,7 +123,7 @@ class phpbb_notification_test extends phpbb_database_test_case { $this->assertEquals(3, $this->notifications->get_notification_type_id('fail')); - $this->fail('Non-existant type should throw exception'); + $this->fail('Non-existent type should throw an exception'); } catch (Exception $e) {} } diff --git a/tests/notification/submit_post_base.php b/tests/notification/submit_post_base.php index c3dbfc2535..59daf6c9cb 100644 --- a/tests/notification/submit_post_base.php +++ b/tests/notification/submit_post_base.php @@ -106,7 +106,7 @@ class phpbb_notification_submit_post_base extends phpbb_database_test_case { $class_name = 'phpbb_notification_type_' . $type; $class = new $class_name( - $user_loader, $db, $cache, $user, $auth, $config, + $user_loader, $db, $cache->get_driver(), $user, $auth, $config, $phpbb_root_path, $phpEx, NOTIFICATION_TYPES_TABLE, NOTIFICATIONS_TABLE, USER_NOTIFICATIONS_TABLE); -- cgit v1.2.1 From 1b34ddb330d1a666185947ec2325732466f9ce4e Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Fri, 3 May 2013 09:02:50 -0500 Subject: [ticket/11415] Fix ext.manager constructor in tests PHPBB3-11415 --- tests/dbal/migrator_test.php | 1 - tests/extension/metadata_manager_test.php | 1 - tests/test_framework/phpbb_functional_test_case.php | 1 - 3 files changed, 3 deletions(-) (limited to 'tests') diff --git a/tests/dbal/migrator_test.php b/tests/dbal/migrator_test.php index 5fc05f2119..1e40c9c6d6 100644 --- a/tests/dbal/migrator_test.php +++ b/tests/dbal/migrator_test.php @@ -63,7 +63,6 @@ class phpbb_dbal_migrator_test extends phpbb_database_test_case $container, $this->db, $this->config, - $this->migrator, new phpbb_filesystem(), 'phpbb_ext', dirname(__FILE__) . '/../../phpBB/', diff --git a/tests/extension/metadata_manager_test.php b/tests/extension/metadata_manager_test.php index 92a0ff126c..059b7148da 100644 --- a/tests/extension/metadata_manager_test.php +++ b/tests/extension/metadata_manager_test.php @@ -66,7 +66,6 @@ class metadata_manager_test extends phpbb_database_test_case $container, $this->db, $this->config, - $this->migrator, new phpbb_filesystem(), 'phpbb_ext', $this->phpbb_root_path, diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index a11c0f72ca..0157706b12 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -155,7 +155,6 @@ class phpbb_functional_test_case extends phpbb_test_case $container, $db, $config, - $migrator, new phpbb_filesystem(), self::$config['table_prefix'] . 'ext', dirname(__FILE__) . '/', -- cgit v1.2.1 From 3a30bd2753ab56dd5035ebba8cf42850e41c3728 Mon Sep 17 00:00:00 2001 From: Dhruv Date: Sat, 4 May 2013 18:25:43 +0530 Subject: [ticket/11288] add search tests cases PHPBB3-11288 --- tests/search/common_test_case.php | 98 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 98 insertions(+) (limited to 'tests') diff --git a/tests/search/common_test_case.php b/tests/search/common_test_case.php index dd04f7048c..029637b00b 100644 --- a/tests/search/common_test_case.php +++ b/tests/search/common_test_case.php @@ -86,6 +86,104 @@ abstract class phpbb_search_common_test_case extends phpbb_search_test_case array('-fooo', '-baar'), array(), ), + array( + 'fooo -fooo', + 'all', + true, + array('fooo', '-fooo'), + array(), + ), + array( + 'fooo fooo-', + 'all', + true, + array('fooo', 'fooo'), + array(), + ), + array( + '-fooo fooo', + 'all', + true, + array('-fooo', 'fooo'), + array(), + ), + array( + 'fooo- fooo', + 'all', + true, + array('fooo', 'fooo'), + array(), + ), + array( + 'fooo-baar fooo', + 'all', + true, + array('fooo', 'baar', 'fooo'), + array(), + ), + array( + 'fooo-baar -fooo', + 'all', + true, + array('fooo', 'baar', '-fooo'), + array(), + ), + array( + 'fooo-baar fooo-', + 'all', + true, + array('fooo', 'baar', 'fooo'), + array(), + ), + array( + 'fooo-baar baar', + 'all', + true, + array('fooo', 'baar', 'baar'), + array(), + ), + array( + 'fooo-baar -baar', + 'all', + true, + array('fooo', 'baar', '-baar'), + array(), + ), + array( + 'fooo-baar baar-', + 'all', + true, + array('fooo', 'baar', 'baar'), + array(), + ), + array( + 'fooo-baar fooo-baar', + 'all', + true, + array('fooo', 'baar', 'fooo', 'baar'), + array(), + ), + array( + 'fooo-baar -fooo-baar', + 'all', + true, + array('fooo', 'baar', '-fooo', 'baar'), + array(), + ), + array( + 'fooo-baar fooo-baar-', + 'all', + true, + array('fooo', 'baar', 'fooo', 'baar'), + array(), + ), + array( + 'fooo-baar-baaz', + 'all', + true, + array('fooo', 'baar', 'baaz'), + array(), + ), ); } -- cgit v1.2.1 From 9608d9bf1e4ed23c36496612a6ffb63072c32371 Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Sat, 4 May 2013 11:45:49 -0500 Subject: [ticket/11519] Rename test event template file As requested by Oleg https://github.com/phpbb/phpbb3/pull/1340#issuecomment-17306967 PHPBB3-11519 --- .../ext/trivial/styles/all/template/event_variable_spacing.html | 6 ++++++ .../ext/trivial/styles/all/template/variable_spacing.html | 6 ------ .../ext_trivial/styles/silver/template/variable_spacing.html | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) create mode 100644 tests/template/datasets/ext_trivial/ext/trivial/styles/all/template/event_variable_spacing.html delete mode 100644 tests/template/datasets/ext_trivial/ext/trivial/styles/all/template/variable_spacing.html (limited to 'tests') diff --git a/tests/template/datasets/ext_trivial/ext/trivial/styles/all/template/event_variable_spacing.html b/tests/template/datasets/ext_trivial/ext/trivial/styles/all/template/event_variable_spacing.html new file mode 100644 index 0000000000..028f8aa0d1 --- /dev/null +++ b/tests/template/datasets/ext_trivial/ext/trivial/styles/all/template/event_variable_spacing.html @@ -0,0 +1,6 @@ +|{VARIABLE}| +{VARIABLE}|{VARIABLE}| + +|{VARIABLE} + +
test
diff --git a/tests/template/datasets/ext_trivial/ext/trivial/styles/all/template/variable_spacing.html b/tests/template/datasets/ext_trivial/ext/trivial/styles/all/template/variable_spacing.html deleted file mode 100644 index 028f8aa0d1..0000000000 --- a/tests/template/datasets/ext_trivial/ext/trivial/styles/all/template/variable_spacing.html +++ /dev/null @@ -1,6 +0,0 @@ -|{VARIABLE}| -{VARIABLE}|{VARIABLE}| - -|{VARIABLE} - -
test
diff --git a/tests/template/datasets/ext_trivial/styles/silver/template/variable_spacing.html b/tests/template/datasets/ext_trivial/styles/silver/template/variable_spacing.html index ad05e6f661..49d8a6b873 100644 --- a/tests/template/datasets/ext_trivial/styles/silver/template/variable_spacing.html +++ b/tests/template/datasets/ext_trivial/styles/silver/template/variable_spacing.html @@ -1 +1 @@ - + -- cgit v1.2.1 From 62f35121d948bd177004628a4be2b4e8810a50bd Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Mon, 18 Mar 2013 23:15:27 +0100 Subject: [ticket/11450] Fix all instances of phpbb_extension_metadata_manager PHPBB3-11450 --- tests/extension/metadata_manager_test.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'tests') diff --git a/tests/extension/metadata_manager_test.php b/tests/extension/metadata_manager_test.php index 05d1cbccc3..8873d25c9c 100644 --- a/tests/extension/metadata_manager_test.php +++ b/tests/extension/metadata_manager_test.php @@ -422,12 +422,10 @@ class metadata_manager_test extends phpbb_database_test_case { return new phpbb_extension_metadata_manager_test( $ext_name, - $this->db, + $this->config, $this->extension_manager, - $this->phpbb_root_path, - $this->phpEx, $this->template, - $this->config + $this->phpbb_root_path ); } } -- cgit v1.2.1 From 269c2ce98de5b55a713e998aacdaa5500d32b617 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 21 Mar 2013 15:19:26 +0100 Subject: [ticket/11450] Test the extensions details page in ACP Customise Tab PHPBB3-11450 --- .../functional/fixtures/ext/foo/bar/composer.json | 23 +++++ tests/functional/metadata_manager_test.php | 104 +++++++++++++++++++++ 2 files changed, 127 insertions(+) create mode 100644 tests/functional/fixtures/ext/foo/bar/composer.json create mode 100644 tests/functional/metadata_manager_test.php (limited to 'tests') diff --git a/tests/functional/fixtures/ext/foo/bar/composer.json b/tests/functional/fixtures/ext/foo/bar/composer.json new file mode 100644 index 0000000000..50a8a7358a --- /dev/null +++ b/tests/functional/fixtures/ext/foo/bar/composer.json @@ -0,0 +1,23 @@ +{ + "name": "foo/bar", + "type": "phpbb3-extension", + "description": "Testing extensions", + "homepage": "", + "version": "1.0.0", + "time": "2013-03-21 01:01:01", + "licence": "GPL-2.0", + "authors": [{ + "name": "Joas Schilling", + "username": "nickvergessen", + "email": "nickvergessen@phpbb.com", + "homepage": "http://www.phpbb.com", + "role": "Developer" + }], + "require": { + "php": ">=5.3", + "phpbb": ">=3.1.0-dev" + }, + "extra": { + "display-name": "phpBB 3.1 Extension Testing" + } +} \ No newline at end of file diff --git a/tests/functional/metadata_manager_test.php b/tests/functional/metadata_manager_test.php new file mode 100644 index 0000000000..0f5b49f01e --- /dev/null +++ b/tests/functional/metadata_manager_test.php @@ -0,0 +1,104 @@ +phpbb_extension_manager = $this->get_extension_manager(); + + $this->purge_cache(); + $this->phpbb_extension_manager->enable('foo/bar'); + + $this->login(); + $this->admin_login(); + $this->add_lang('acp/extensions'); + } + + public function test_extensions_list() + { + $crawler = $this->request('GET', 'adm/index.php?i=acp_extensions&mode=main&sid=' . $this->sid); + $this->assert_response_success(); + + $this->assertContains($this->lang('EXTENSIONS_EXPLAIN'), $this->client->getResponse()->getContent()); + $this->assertContains('phpBB 3.1 Extension Testing', $this->client->getResponse()->getContent()); + $this->assertContains('Details', $this->client->getResponse()->getContent()); + } + + public function test_permissions_tab() + { + $crawler = $this->request('GET', 'adm/index.php?i=acp_extensions&mode=main&action=details&ext_name=foo%2Fbar&sid=' . $this->sid); + $this->assert_response_success(); + + // Test whether the details are displayed + $this->assertContains($this->lang('CLEAN_NAME'), $this->client->getResponse()->getContent()); + $this->assertContains('foo/bar', $this->client->getResponse()->getContent()); + + // Details should be html escaped + $this->assertContains($this->lang('PHP_VERSION'), $this->client->getResponse()->getContent()); + $this->assertContains('>=5.3', $this->client->getResponse()->getContent()); + } +} -- cgit v1.2.1 From 0de153d9034720745eb3589b95953de9a185360d Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 21 Mar 2013 15:27:15 +0100 Subject: [ticket/11450] Add test for unexisting composer.json PHPBB3-11450 --- tests/functional/metadata_manager_test.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/functional/metadata_manager_test.php b/tests/functional/metadata_manager_test.php index 0f5b49f01e..deb8af7707 100644 --- a/tests/functional/metadata_manager_test.php +++ b/tests/functional/metadata_manager_test.php @@ -88,7 +88,7 @@ class phpbb_functional_metadata_manager_test extends phpbb_functional_test_case $this->assertContains('Details', $this->client->getResponse()->getContent()); } - public function test_permissions_tab() + public function test_extensions_details() { $crawler = $this->request('GET', 'adm/index.php?i=acp_extensions&mode=main&action=details&ext_name=foo%2Fbar&sid=' . $this->sid); $this->assert_response_success(); @@ -101,4 +101,13 @@ class phpbb_functional_metadata_manager_test extends phpbb_functional_test_case $this->assertContains($this->lang('PHP_VERSION'), $this->client->getResponse()->getContent()); $this->assertContains('>=5.3', $this->client->getResponse()->getContent()); } + + public function test_extensions_details_notexists() + { + $crawler = $this->request('GET', 'adm/index.php?i=acp_extensions&mode=main&action=details&ext_name=not%2Fexists&sid=' . $this->sid); + $this->assert_response_success(); + + // Error message because the files do not exist + $this->assertContains('The required file does not exist:', $this->client->getResponse()->getContent()); + } } -- cgit v1.2.1 From a44a35926f9535c8d0d6afaeef6eeaf64a7f470e Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Mon, 1 Apr 2013 11:17:05 +0200 Subject: [ticket/11450] Require db_tools file to be included PHPBB3-11450 --- tests/extension/metadata_manager_test.php | 2 ++ 1 file changed, 2 insertions(+) (limited to 'tests') diff --git a/tests/extension/metadata_manager_test.php b/tests/extension/metadata_manager_test.php index 8873d25c9c..24b2861079 100644 --- a/tests/extension/metadata_manager_test.php +++ b/tests/extension/metadata_manager_test.php @@ -7,6 +7,8 @@ * */ +require_once dirname(__FILE__) . '/../../phpBB/includes/db/db_tools.php'; + class metadata_manager_test extends phpbb_database_test_case { protected $class_loader; -- cgit v1.2.1 From 74f3161b4b555f5ef5482c95a919aae468312142 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Mon, 1 Apr 2013 11:18:46 +0200 Subject: [ticket/11450] Fix tests class name PHPBB3-11450 --- tests/extension/metadata_manager_test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/extension/metadata_manager_test.php b/tests/extension/metadata_manager_test.php index 24b2861079..7b51f2d50f 100644 --- a/tests/extension/metadata_manager_test.php +++ b/tests/extension/metadata_manager_test.php @@ -9,7 +9,7 @@ require_once dirname(__FILE__) . '/../../phpBB/includes/db/db_tools.php'; -class metadata_manager_test extends phpbb_database_test_case +class phpbb_extension_metadata_manager_test extends phpbb_database_test_case { protected $class_loader; protected $extension_manager; -- cgit v1.2.1 From d75af4109ff4a2323e1561f3376b4ef0515977cc Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Mon, 1 Apr 2013 11:20:34 +0200 Subject: [ticket/11450] Add new line at end of file PHPBB3-11450 --- tests/functional/fixtures/ext/foo/bar/composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/functional/fixtures/ext/foo/bar/composer.json b/tests/functional/fixtures/ext/foo/bar/composer.json index 50a8a7358a..067a9d38eb 100644 --- a/tests/functional/fixtures/ext/foo/bar/composer.json +++ b/tests/functional/fixtures/ext/foo/bar/composer.json @@ -20,4 +20,4 @@ "extra": { "display-name": "phpBB 3.1 Extension Testing" } -} \ No newline at end of file +} -- cgit v1.2.1 From 65c407044e77568ddcd80648830b8caf8fb3dd4a Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 4 Apr 2013 21:36:32 +0200 Subject: [ticket/11450] Move mocked class into mock/metadata_manager.php PHPBB3-11450 --- tests/extension/metadata_manager_test.php | 17 ++--------------- tests/mock/metadata_manager.php | 21 +++++++++++++++++++++ 2 files changed, 23 insertions(+), 15 deletions(-) create mode 100644 tests/mock/metadata_manager.php (limited to 'tests') diff --git a/tests/extension/metadata_manager_test.php b/tests/extension/metadata_manager_test.php index 7b51f2d50f..2f38a26217 100644 --- a/tests/extension/metadata_manager_test.php +++ b/tests/extension/metadata_manager_test.php @@ -418,11 +418,11 @@ class phpbb_extension_metadata_manager_test extends phpbb_database_test_case * Get an instance of the metadata manager * * @param string $ext_name - * @return phpbb_extension_metadata_manager_test + * @return phpbb_mock_metadata_manager */ private function get_metadata_manager($ext_name) { - return new phpbb_extension_metadata_manager_test( + return new phpbb_mock_metadata_manager( $ext_name, $this->config, $this->extension_manager, @@ -431,16 +431,3 @@ class phpbb_extension_metadata_manager_test extends phpbb_database_test_case ); } } - -class phpbb_extension_metadata_manager_test extends phpbb_extension_metadata_manager -{ - public function set_metadata($metadata) - { - $this->metadata = $metadata; - } - - public function merge_metadata($metadata) - { - $this->metadata = array_merge($this->metadata, $metadata); - } -} \ No newline at end of file diff --git a/tests/mock/metadata_manager.php b/tests/mock/metadata_manager.php new file mode 100644 index 0000000000..a7fbf0681c --- /dev/null +++ b/tests/mock/metadata_manager.php @@ -0,0 +1,21 @@ +metadata = $metadata; + } + + public function merge_metadata($metadata) + { + $this->metadata = array_merge($this->metadata, $metadata); + } +} -- cgit v1.2.1 From 4c9c1d8c02142315d88bb7aaee2f64015c5033b7 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 12 Apr 2013 16:29:59 +0200 Subject: [ticket/11450] Use helpers to copy/remove files PHPBB3-11450 --- tests/functional/metadata_manager_test.php | 44 ++++++++++++++---------------- 1 file changed, 21 insertions(+), 23 deletions(-) (limited to 'tests') diff --git a/tests/functional/metadata_manager_test.php b/tests/functional/metadata_manager_test.php index deb8af7707..c639cad809 100644 --- a/tests/functional/metadata_manager_test.php +++ b/tests/functional/metadata_manager_test.php @@ -7,6 +7,8 @@ * */ +require_once dirname(__FILE__) . '/../../phpBB/includes/db/db_tools.php'; + /** * @group functional */ @@ -14,8 +16,10 @@ class phpbb_functional_metadata_manager_test extends phpbb_functional_test_case { protected $phpbb_extension_manager; + static private $helpers; + static protected $fixtures = array( - 'foo/bar/composer.json', + 'foo/bar/', ); /** @@ -27,23 +31,16 @@ class phpbb_functional_metadata_manager_test extends phpbb_functional_test_case global $phpbb_root_path; parent::setUpBeforeClass(); - $directories = array( - $phpbb_root_path . 'ext/foo/bar/', - ); + self::$helpers = new phpbb_test_case_helpers(self); - foreach ($directories as $dir) + if (!file_exists($phpbb_root_path . 'ext/foo/bar/')) { - if (!is_dir($dir)) - { - mkdir($dir, 0777, true); - } + self::$helpers->makedirs($phpbb_root_path . 'ext/foo/bar/'); } foreach (self::$fixtures as $fixture) { - copy( - "tests/functional/fixtures/ext/$fixture", - "{$phpbb_root_path}ext/$fixture"); + self::$helpers->copy_dir(dirname(__FILE__) . '/fixtures/ext/' . $fixture, $phpbb_root_path . 'ext/' . $fixture); } } @@ -57,11 +54,9 @@ class phpbb_functional_metadata_manager_test extends phpbb_functional_test_case foreach (self::$fixtures as $fixture) { - unlink("{$phpbb_root_path}ext/$fixture"); + self::$helpers->empty_dir($phpbb_root_path . 'ext/' . $fixture); } - - rmdir("{$phpbb_root_path}ext/foo/bar"); - rmdir("{$phpbb_root_path}ext/foo"); + self::$helpers->empty_dir($phpbb_root_path . 'ext/foo/'); } public function setUp() @@ -83,9 +78,9 @@ class phpbb_functional_metadata_manager_test extends phpbb_functional_test_case $crawler = $this->request('GET', 'adm/index.php?i=acp_extensions&mode=main&sid=' . $this->sid); $this->assert_response_success(); - $this->assertContains($this->lang('EXTENSIONS_EXPLAIN'), $this->client->getResponse()->getContent()); - $this->assertContains('phpBB 3.1 Extension Testing', $this->client->getResponse()->getContent()); - $this->assertContains('Details', $this->client->getResponse()->getContent()); + $this->assertContains($this->lang('EXTENSIONS_EXPLAIN'), $crawler->filter('#page-body')->text()); + $this->assertContains('phpBB 3.1 Extension Testing', $crawler->filter('#page-body')->text()); + $this->assertContains('Details', $crawler->filter('#page-body')->text()); } public function test_extensions_details() @@ -94,11 +89,14 @@ class phpbb_functional_metadata_manager_test extends phpbb_functional_test_case $this->assert_response_success(); // Test whether the details are displayed - $this->assertContains($this->lang('CLEAN_NAME'), $this->client->getResponse()->getContent()); - $this->assertContains('foo/bar', $this->client->getResponse()->getContent()); + $this->assertContains($this->lang('CLEAN_NAME'), $crawler->filter('#page-body')->text()); + $this->assertContains('foo/bar', $crawler->filter('#page-body')->text()); // Details should be html escaped - $this->assertContains($this->lang('PHP_VERSION'), $this->client->getResponse()->getContent()); + $this->assertContains($this->lang('PHP_VERSION'), $crawler->filter('#page-body')->text()); + // The Crawler parses the text, so we can not see whether it was escaped anymore + // To test this, we grab the content of the response directly + // $this->assertContains('>=5.3', $$crawler->filter('#page-body')->text()); $this->assertContains('>=5.3', $this->client->getResponse()->getContent()); } @@ -108,6 +106,6 @@ class phpbb_functional_metadata_manager_test extends phpbb_functional_test_case $this->assert_response_success(); // Error message because the files do not exist - $this->assertContains('The required file does not exist:', $this->client->getResponse()->getContent()); + $this->assertContains('The required file does not exist:', $crawler->filter('#page-body')->text()); } } -- cgit v1.2.1 From 54680b9709ab2288408cbb0ddc7737e93d41de18 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 3 May 2013 15:52:16 +0200 Subject: [ticket/11450] Limit scopes of filters and add better docs PHPBB3-11450 --- tests/functional/metadata_manager_test.php | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'tests') diff --git a/tests/functional/metadata_manager_test.php b/tests/functional/metadata_manager_test.php index c639cad809..0125886e04 100644 --- a/tests/functional/metadata_manager_test.php +++ b/tests/functional/metadata_manager_test.php @@ -78,9 +78,9 @@ class phpbb_functional_metadata_manager_test extends phpbb_functional_test_case $crawler = $this->request('GET', 'adm/index.php?i=acp_extensions&mode=main&sid=' . $this->sid); $this->assert_response_success(); - $this->assertContains($this->lang('EXTENSIONS_EXPLAIN'), $crawler->filter('#page-body')->text()); - $this->assertContains('phpBB 3.1 Extension Testing', $crawler->filter('#page-body')->text()); - $this->assertContains('Details', $crawler->filter('#page-body')->text()); + $this->assertContains($this->lang('EXTENSIONS_EXPLAIN'), $crawler->filter('#main')->text()); + $this->assertContains('phpBB 3.1 Extension Testing', $crawler->filter('#main')->text()); + $this->assertContains('Details', $crawler->filter('#main')->text()); } public function test_extensions_details() @@ -89,15 +89,15 @@ class phpbb_functional_metadata_manager_test extends phpbb_functional_test_case $this->assert_response_success(); // Test whether the details are displayed - $this->assertContains($this->lang('CLEAN_NAME'), $crawler->filter('#page-body')->text()); - $this->assertContains('foo/bar', $crawler->filter('#page-body')->text()); + $this->assertContains($this->lang('CLEAN_NAME'), $crawler->filter('#main')->text()); + $this->assertContains('foo/bar', $crawler->filter('#meta_name')->text()); + $this->assertContains($this->lang('PHP_VERSION'), $crawler->filter('#main')->text()); + $this->assertContains('>=5.3', $crawler->filter('#require_php')->text()); // Details should be html escaped - $this->assertContains($this->lang('PHP_VERSION'), $crawler->filter('#page-body')->text()); - // The Crawler parses the text, so we can not see whether it was escaped anymore - // To test this, we grab the content of the response directly - // $this->assertContains('>=5.3', $$crawler->filter('#page-body')->text()); - $this->assertContains('>=5.3', $this->client->getResponse()->getContent()); + // However, text() only returns the displayed text, so HTML Special Chars are decoded. + // So we test this directly on the content of the response. + $this->assertContains('

>=5.3

', $this->client->getResponse()->getContent()); } public function test_extensions_details_notexists() @@ -106,6 +106,6 @@ class phpbb_functional_metadata_manager_test extends phpbb_functional_test_case $this->assert_response_success(); // Error message because the files do not exist - $this->assertContains('The required file does not exist:', $crawler->filter('#page-body')->text()); + $this->assertContains('The required file does not exist:', $crawler->filter('#main')->text()); } } -- cgit v1.2.1 From f2f97dd5e06be645f830e0467737d9f23544d631 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Thu, 9 May 2013 18:58:31 +0200 Subject: [ticket/11513] Update all CLI calls to phpunit to use vendor/bin. PHPBB3-11513 --- tests/RUNNING_TESTS.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/RUNNING_TESTS.txt b/tests/RUNNING_TESTS.txt index de9c751238..f33fa59dc2 100644 --- a/tests/RUNNING_TESTS.txt +++ b/tests/RUNNING_TESTS.txt @@ -95,7 +95,7 @@ Running Once the prerequisites are installed, run the tests from the project root directory (above phpBB): - $ phpunit + $ phpBB/vendor/bin/phpunit Slow tests -------------- @@ -105,7 +105,7 @@ Thus these tests are in the `slow` group, which is excluded by default. You can enable slow tests by copying the phpunit.xml.all file to phpunit.xml. If you only want the slow tests, run: - $ phpunit --group slow + $ phpBB/vendor/bin/phpunit --group slow More Information ================ -- cgit v1.2.1 From c31123e8a4f3350cd33be80a8178a0c94617d9c7 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Thu, 9 May 2013 19:14:31 +0200 Subject: [ticket/11513] Update RUNNING_TESTS.txt to no longer refer to PEAR. PHPBB3-11513 --- tests/RUNNING_TESTS.txt | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'tests') diff --git a/tests/RUNNING_TESTS.txt b/tests/RUNNING_TESTS.txt index f33fa59dc2..0fa45e7bc4 100644 --- a/tests/RUNNING_TESTS.txt +++ b/tests/RUNNING_TESTS.txt @@ -7,9 +7,14 @@ Prerequisites PHPUnit ------- -phpBB unit tests use PHPUnit framework. Version 3.5 or better is required -to run the tests. PHPUnit prefers to be installed via PEAR; refer to -http://www.phpunit.de/ for more information. +phpBB unit tests use the PHPUnit framework (see http://www.phpunit.de for more +information). Version 3.5 or higher is required to run the tests. PHPUnit can +be installed via Composer together with other development dependencies as +follows. + + $ cd phpBB + $ php ../composer.phar install --dev + $ cd .. PHP extensions -------------- -- cgit v1.2.1 From 1c9d36615a60dfbe96da5e9866480313415f262d Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Thu, 9 May 2013 19:59:34 +0200 Subject: [ticket/11529] Rename RUNNING_TESTS.txt to RUNNING_TESTS.md PHPBB3-11529 --- tests/RUNNING_TESTS.md | 119 ++++++++++++++++++++++++++++++++++++++++++++++++ tests/RUNNING_TESTS.txt | 119 ------------------------------------------------ 2 files changed, 119 insertions(+), 119 deletions(-) create mode 100644 tests/RUNNING_TESTS.md delete mode 100644 tests/RUNNING_TESTS.txt (limited to 'tests') diff --git a/tests/RUNNING_TESTS.md b/tests/RUNNING_TESTS.md new file mode 100644 index 0000000000..0fa45e7bc4 --- /dev/null +++ b/tests/RUNNING_TESTS.md @@ -0,0 +1,119 @@ +Running Tests +============= + +Prerequisites +============= + +PHPUnit +------- + +phpBB unit tests use the PHPUnit framework (see http://www.phpunit.de for more +information). Version 3.5 or higher is required to run the tests. PHPUnit can +be installed via Composer together with other development dependencies as +follows. + + $ cd phpBB + $ php ../composer.phar install --dev + $ cd .. + +PHP extensions +-------------- + +Unit tests use several PHP extensions that board code does not use. Currently +the following PHP extensions must be installed and enabled to run unit tests: + +- ctype (also a PHPUnit dependency) +- dom (PHPUnit dependency) + +Some of the functionality in phpBB and/or the test suite uses additional +PHP extensions. If these extensions are not loaded, respective tests +will be skipped: + +- apc (APC cache driver) +- bz2 (compress tests) +- interbase, pdo_firebird (Firebird database driver) +- mysql, pdo_mysql (MySQL database driver) +- mysqli, pdo_mysql (MySQLi database driver) +- pdo (any database tests) +- pgsql, pdo_pgsql (PostgreSQL database driver) +- simplexml (any database tests) +- sqlite, pdo_sqlite (SQLite database driver, requires SQLite 2.x support + in pdo_sqlite) +- zlib (compress tests) + +Database Tests +-------------- + +By default all tests requiring a database connection will use sqlite. If you +do not have sqlite installed the tests will be skipped. If you wish to run the +tests on a different database you have to create a test_config.php file within +your tests directory following the same format as phpBB's config.php. An +example for mysqli can be found below. More information on configuration +options can be found on the wiki (see below). + + Date: Thu, 9 May 2013 20:06:12 +0200 Subject: [ticket/11529] Format markdown code correctly PHPBB3-11529 --- tests/RUNNING_TESTS.md | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'tests') diff --git a/tests/RUNNING_TESTS.md b/tests/RUNNING_TESTS.md index 0fa45e7bc4..26a93f0430 100644 --- a/tests/RUNNING_TESTS.md +++ b/tests/RUNNING_TESTS.md @@ -79,14 +79,16 @@ In order to run tests on some of the databases that we support, it will be necessary to provide a custom DSN string in test_config.php. This is only needed for MSSQL 2000+ (PHP module), MSSQL via ODBC, and Firebird when PDO_Firebird does not work on your system -(https://bugs.php.net/bug.php?id=61183). The variable must be named $custom_dsn. +(https://bugs.php.net/bug.php?id=61183). The variable must be named `$custom_dsn`. Examples: Firebird using http://www.firebirdsql.org/en/odbc-driver/ -$custom_dsn = "Driver={Firebird/InterBase(r) driver};dbname=$dbhost:$dbname"; + + $custom_dsn = "Driver={Firebird/InterBase(r) driver};dbname=$dbhost:$dbname"; MSSQL -$custom_dsn = "Driver={SQL Server Native Client 10.0};Server=$dbhost;Database=$dbname"; + + $custom_dsn = "Driver={SQL Server Native Client 10.0};Server=$dbhost;Database=$dbname"; The other fields in test_config.php should be filled out as you would normally to connect to that database in phpBB. -- cgit v1.2.1 From 109b1a3a952f8a590f6613c8d940e6d01b755af7 Mon Sep 17 00:00:00 2001 From: OpenShift guest Date: Thu, 9 May 2013 23:12:19 -0400 Subject: [ticket/11458] Use helper to create/move/delete directories/files PHPBB3-11458 --- .../functional/extension_permission_lang_test.php | 51 ++++++++++++---------- 1 file changed, 27 insertions(+), 24 deletions(-) (limited to 'tests') diff --git a/tests/functional/extension_permission_lang_test.php b/tests/functional/extension_permission_lang_test.php index 234cbbbaf2..6f1048279a 100644 --- a/tests/functional/extension_permission_lang_test.php +++ b/tests/functional/extension_permission_lang_test.php @@ -14,8 +14,12 @@ class phpbb_functional_extension_permission_lang_test extends phpbb_functional_t { protected $phpbb_extension_manager; + static private $helper; + + static private $copied_files = array(); + static protected $fixtures = array( - 'foo/bar/language/en/permissions_foo.php', + 'foo/bar/language/en/', ); /** @@ -27,26 +31,21 @@ class phpbb_functional_extension_permission_lang_test extends phpbb_functional_t global $phpbb_root_path; parent::setUpBeforeClass(); - $directories = array( - $phpbb_root_path . 'ext/foo/bar/', - $phpbb_root_path . 'ext/foo/bar/language/', - $phpbb_root_path . 'ext/foo/bar/language/en/', - ); + self::$helper = new phpbb_test_case_helpers(self); - foreach ($directories as $dir) - { - if (!is_dir($dir)) - { - mkdir($dir, 0777, true); - } - } + self::$copied_files = array(); - foreach (self::$fixtures as $fixture) + if (file_exists($phpbb_root_path . 'ext/')) { - copy( - "tests/functional/fixtures/ext/$fixture", - "{$phpbb_root_path}ext/$fixture"); + // First, move any extensions setup on the board to a temp directory + self::$copied_files = self::$helper->copy_dir($phpbb_root_path . 'ext/', $phpbb_root_path . 'store/temp_ext/'); + + // Then empty the ext/ directory on the board (for accurate test cases) + self::$helper->empty_dir($phpbb_root_path . 'ext/'); } + + // Copy our ext/ files from the test case to the board + self::$copied_files = array_merge(self::$copied_files, self::$helper->copy_dir(dirname(__FILE__) . '/fixtures/ext/' . $fixture, $phpbb_root_path . 'ext/' . $fixture)); } /** @@ -56,16 +55,20 @@ class phpbb_functional_extension_permission_lang_test extends phpbb_functional_t static public function tearDownAfterClass() { global $phpbb_root_path; - - foreach (self::$fixtures as $fixture) + + if (file_exists($phpbb_root_path . 'store/temp_ext/')) { - unlink("{$phpbb_root_path}ext/$fixture"); + // Copy back the board installed extensions from the temp directory + self::$helper->copy_dir($phpbb_root_path . 'store/temp_ext/', $phpbb_root_path . 'ext/'); } - rmdir("{$phpbb_root_path}ext/foo/bar/language/en"); - rmdir("{$phpbb_root_path}ext/foo/bar/language"); - rmdir("{$phpbb_root_path}ext/foo/bar"); - rmdir("{$phpbb_root_path}ext/foo"); + // Remove all of the files we copied around (from board ext -> temp_ext, from test ext -> board ext) + self::$helper->remove_files(self::$copied_files); + + if (file_exists($phpbb_root_path . 'store/temp_ext/')) + { + self::$helper->empty_dir($phpbb_root_path . 'store/temp_ext/'); + } } public function setUp() -- cgit v1.2.1 From 6a1fa3e0f40d1ce63ff8686b47bd131417d9fc04 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Fri, 10 May 2013 11:53:26 +0200 Subject: [ticket/11465] Add comments explaining the tests PHPBB3-11465 --- tests/extension/ext/foo/acp/fail_info.php | 5 ++++- tests/extension/ext/foo/acp/fail_module.php | 5 ++++- tests/extension/modules_test.php | 5 +++++ 3 files changed, 13 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/extension/ext/foo/acp/fail_info.php b/tests/extension/ext/foo/acp/fail_info.php index 98b0eb9529..99aa09551e 100644 --- a/tests/extension/ext/foo/acp/fail_info.php +++ b/tests/extension/ext/foo/acp/fail_info.php @@ -1,5 +1,8 @@ acp_modules->module_class = 'acp'; $acp_modules = $this->acp_modules->get_module_infos(); $this->assertEquals(array( @@ -68,6 +69,7 @@ class phpbb_extension_modules_test extends phpbb_test_case ), ), $acp_modules); + // Find mcp module info files $this->acp_modules->module_class = 'mcp'; $acp_modules = $this->acp_modules->get_module_infos(); $this->assertEquals(array( @@ -81,6 +83,7 @@ class phpbb_extension_modules_test extends phpbb_test_case ), ), $acp_modules); + // Find a specific module info file (mcp_a_module) $this->acp_modules->module_class = 'mcp'; $acp_modules = $this->acp_modules->get_module_infos('mcp_a_module'); $this->assertEquals(array( @@ -94,10 +97,12 @@ class phpbb_extension_modules_test extends phpbb_test_case ), ), $acp_modules); + // The mcp module info file we're looking for shouldn't exist $this->acp_modules->module_class = 'mcp'; $acp_modules = $this->acp_modules->get_module_infos('mcp_a_fail'); $this->assertEquals(array(), $acp_modules); + // As there are no ucp modules we shouldn't find any $this->acp_modules->module_class = 'ucp'; $acp_modules = $this->acp_modules->get_module_infos(); $this->assertEquals(array(), $acp_modules); -- cgit v1.2.1 From 48e1be58db26ba09f7421082038f1f6353a38e91 Mon Sep 17 00:00:00 2001 From: OpenShift guest Date: Sat, 11 May 2013 02:38:40 -0400 Subject: [ticket/11458] Update functional test Show that the phpbb permission lanuage file is being included PHPBB3-11458 --- tests/functional/extension_permission_lang_test.php | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'tests') diff --git a/tests/functional/extension_permission_lang_test.php b/tests/functional/extension_permission_lang_test.php index 6f1048279a..26ec4d28a1 100644 --- a/tests/functional/extension_permission_lang_test.php +++ b/tests/functional/extension_permission_lang_test.php @@ -108,6 +108,11 @@ class phpbb_functional_extension_permission_lang_test extends phpbb_functional_t $form->setValues($data); $crawler = $this->client->submit($form); $this->assert_response_success(); + + // language from language/en/acp/permissions_phpbb.php + $this->assertContains('Can attach files', $crawler->filter('body')->text()); + + // language from ext/foo/bar/language/en/permissions_foo.php $this->assertContains('Can view foo', $crawler->filter('body')->text()); } } -- cgit v1.2.1 From f17e67364dca55c9ccd8416f41547fa4097cdcd4 Mon Sep 17 00:00:00 2001 From: Vjacheslav Trushkin Date: Sat, 11 May 2013 23:33:40 +0300 Subject: [ticket/11533] Update unit tests Update notification settings functional unit test for new layout PHPBB3-11533 --- tests/functional/notification_test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/functional/notification_test.php b/tests/functional/notification_test.php index ec495da602..fa6513a0ba 100644 --- a/tests/functional/notification_test.php +++ b/tests/functional/notification_test.php @@ -43,7 +43,7 @@ class phpbb_functional_notification_test extends phpbb_functional_test_case $crawler = $this->request('GET', 'ucp.php?i=ucp_notifications&mode=notification_options'); $this->assert_response_success(); - $cplist = $crawler->filter('.cplist'); + $cplist = $crawler->filter('.table1'); if ($expected_status) { $this->assert_checkbox_is_checked($cplist, $checkbox_name); -- cgit v1.2.1 From bcd6f79d5c3e3db5ae60098526d93b477cc9eed9 Mon Sep 17 00:00:00 2001 From: Dhruv Date: Sun, 12 May 2013 15:57:13 +0530 Subject: [ticket/10820] Add test cases PHPBB3-10325 --- tests/download/http_user_agent_test.php | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'tests') diff --git a/tests/download/http_user_agent_test.php b/tests/download/http_user_agent_test.php index 601561f44e..e08fb7a3f1 100644 --- a/tests/download/http_user_agent_test.php +++ b/tests/download/http_user_agent_test.php @@ -52,6 +52,38 @@ class phpbb_download_http_user_agent_test extends phpbb_test_case 'Mozilla/5.0 (Windows NT 6.2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1464.0 Safari/537.36', false, ), + array( + 'Googlebot-Image/1.0', + false, + ), + array( + 'Googlebot/2.1 ( http://www.google.com/bot.html)', + false, + ), + array( + 'Lynx/2.8.3dev.9 libwww-FM/2.14 SSL-MM/1.4.1 OpenSSL/0.9.6', + false, + ), + array( + 'Links (0.9x; Linux 2.4.7-10 i686)', + false, + ), + array( + 'Opera/9.60 (Windows NT 5.1; U; de) Presto/2.1.1', + false, + ), + array( + 'Mozilla/4.0 (compatible; MSIE 5.0; Windows NT;)', + false, + ), + array( + 'Mozilla/4.0 (compatible; MSIE 5.0; Windows NT 4.0) Opera 6.01 [en]', + false, + ), + array( + 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; en) Opera 9.24', + false, + ), ); } -- cgit v1.2.1 From 7327f9326f739f9b602fd8896e8a4731caa93ee8 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Sun, 12 May 2013 16:49:49 +0200 Subject: [ticket/11465] Add tests for optional arguments of get_module_infos() The possibilities of the first argument have already been covered previously. The second argument will be covered with an entry that should exist, an incorrect entry, and the default false entry that should use the previously set module class. Unfortunately, the third argument doesn't have an effect in the tests, as the mocked extension manager will not properly handle enabled/disabled extensions. PHPBB3-11465 --- tests/extension/modules_test.php | 60 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) (limited to 'tests') diff --git a/tests/extension/modules_test.php b/tests/extension/modules_test.php index f0acd6f2eb..d24a3ec52f 100644 --- a/tests/extension/modules_test.php +++ b/tests/extension/modules_test.php @@ -97,6 +97,20 @@ class phpbb_extension_modules_test extends phpbb_test_case ), ), $acp_modules); + // Find a specific module info file (mcp_a_module) with passing the module_class + $this->acp_modules->module_class = ''; + $acp_modules = $this->acp_modules->get_module_infos('mcp_a_module', 'mcp'); + $this->assertEquals(array( + 'phpbb_ext_foo_mcp_a_module' => array( + 'filename' => 'phpbb_ext_foo_mcp_a_module', + 'title' => 'Foobar', + 'version' => '3.1.0-dev', + 'modes' => array( + 'config' => array('title' => 'Config', 'auth' => '', 'cat' => array('MCP_MAIN')), + ), + ), + ), $acp_modules); + // The mcp module info file we're looking for shouldn't exist $this->acp_modules->module_class = 'mcp'; $acp_modules = $this->acp_modules->get_module_infos('mcp_a_fail'); @@ -106,5 +120,51 @@ class phpbb_extension_modules_test extends phpbb_test_case $this->acp_modules->module_class = 'ucp'; $acp_modules = $this->acp_modules->get_module_infos(); $this->assertEquals(array(), $acp_modules); + + // Get module info of specified extension module + $this->acp_modules->module_class = 'acp'; + $acp_modules = $this->acp_modules->get_module_infos('phpbb_ext_foo_acp_a_module'); + $this->assertEquals(array( + 'phpbb_ext_foo_acp_a_module' => array ( + 'filename' => 'phpbb_ext_foo_acp_a_module', + 'title' => 'Foobar', + 'version' => '3.1.0-dev', + 'modes' => array ( + 'config' => array ('title' => 'Config', 'auth' => '', 'cat' => array ('ACP_MODS')), + ), + ), + ), $acp_modules); + + // No specific module and module class set to an incorrect name + $acp_modules = $this->acp_modules->get_module_infos('', 'wcp', true); + $this->assertEquals(array(), $acp_modules); + + // No specific module, no module_class set in the function parameter, and an incorrect module class + $this->acp_modules->module_class = 'wcp'; + $acp_modules = $this->acp_modules->get_module_infos(); + $this->assertEquals(array(), $acp_modules); + + // No specific module, module class set to false (will default to the above acp) + // Setting $use_all_available will have no effect here as the ext manager is just mocked + $this->acp_modules->module_class = 'acp'; + $acp_modules = $this->acp_modules->get_module_infos('', false, true); + $this->assertEquals(array( + 'phpbb_ext_foo_acp_a_module' => array( + 'filename' => 'phpbb_ext_foo_acp_a_module', + 'title' => 'Foobar', + 'version' => '3.1.0-dev', + 'modes' => array( + 'config' => array('title' => 'Config', 'auth' => '', 'cat' => array('ACP_MODS')), + ), + ), + 'acp_foobar' => array( + 'filename' => 'acp_foobar', + 'title' => 'ACP Foobar', + 'version' => '3.1.0-dev', + 'modes' => array( + 'test' => array('title' => 'Test', 'auth' => '', 'cat' => array('ACP_GENERAL')), + ), + ), + ), $acp_modules); } } -- cgit v1.2.1 From f90ed6c3cb9e1b8baeb352a07b81608fa7c067b5 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Sun, 12 May 2013 22:21:16 +0200 Subject: [ticket/11465] Add disabled ext to allow proper testing of get_module_infos() This will now also enable us to test the $use_all_available parameter of get_module_infos(), which will not only return the module infos for enabled extensions but also those from disabled extensions. PHPBB3-11465 --- tests/extension/ext/barfoo/acp/a_info.php | 16 ++++++++++++++++ tests/extension/ext/barfoo/acp/a_module.php | 5 +++++ tests/extension/ext/barfoo/ext.php | 5 +++++ tests/extension/manager_test.php | 2 +- tests/extension/modules_test.php | 24 +++++++++++++++++++++++- 5 files changed, 50 insertions(+), 2 deletions(-) create mode 100644 tests/extension/ext/barfoo/acp/a_info.php create mode 100644 tests/extension/ext/barfoo/acp/a_module.php create mode 100644 tests/extension/ext/barfoo/ext.php (limited to 'tests') diff --git a/tests/extension/ext/barfoo/acp/a_info.php b/tests/extension/ext/barfoo/acp/a_info.php new file mode 100644 index 0000000000..cd7e4e574b --- /dev/null +++ b/tests/extension/ext/barfoo/acp/a_info.php @@ -0,0 +1,16 @@ + 'phpbb_ext_barfoo_acp_a_module', + 'title' => 'Barfoo', + 'version' => '3.1.0-dev', + 'modes' => array( + 'config' => array('title' => 'Config', 'auth' => '', 'cat' => array('ACP_MODS')), + ), + ); + } +} diff --git a/tests/extension/ext/barfoo/acp/a_module.php b/tests/extension/ext/barfoo/acp/a_module.php new file mode 100644 index 0000000000..5bedb49645 --- /dev/null +++ b/tests/extension/ext/barfoo/acp/a_module.php @@ -0,0 +1,5 @@ +assertEquals(array('bar', 'foo', 'vendor/moo'), array_keys($this->extension_manager->all_available())); + $this->assertEquals(array('bar', 'barfoo', 'foo', 'vendor/moo'), array_keys($this->extension_manager->all_available())); } public function test_enabled() diff --git a/tests/extension/modules_test.php b/tests/extension/modules_test.php index d24a3ec52f..fe71747c5d 100644 --- a/tests/extension/modules_test.php +++ b/tests/extension/modules_test.php @@ -10,6 +10,7 @@ require_once dirname(__FILE__) . '/ext/foo/acp/a_info.php'; require_once dirname(__FILE__) . '/ext/foo/mcp/a_info.php'; require_once dirname(__FILE__) . '/ext/foo/acp/fail_info.php'; +require_once dirname(__FILE__) . '/ext/barfoo/acp/a_info.php'; require_once dirname(__FILE__) . '/../../phpBB/includes/acp/acp_modules.php'; class phpbb_extension_modules_test extends phpbb_test_case @@ -145,7 +146,7 @@ class phpbb_extension_modules_test extends phpbb_test_case $this->assertEquals(array(), $acp_modules); // No specific module, module class set to false (will default to the above acp) - // Setting $use_all_available will have no effect here as the ext manager is just mocked + // Setting $use_all_available will cause get_module_infos() to also load not enabled extensions (barfoo) $this->acp_modules->module_class = 'acp'; $acp_modules = $this->acp_modules->get_module_infos('', false, true); $this->assertEquals(array( @@ -165,6 +166,27 @@ class phpbb_extension_modules_test extends phpbb_test_case 'test' => array('title' => 'Test', 'auth' => '', 'cat' => array('ACP_GENERAL')), ), ), + 'phpbb_ext_barfoo_acp_a_module' => array( + 'filename' => 'phpbb_ext_barfoo_acp_a_module', + 'title' => 'Barfoo', + 'version' => '3.1.0-dev', + 'modes' => array( + 'config' => array('title' => 'Config', 'auth' => '', 'cat' => array('ACP_MODS')), + ), + ) + ), $acp_modules); + + // Specific module set to disabled extension + $acp_modules = $this->acp_modules->get_module_infos('phpbb_ext_barfoo_acp_a_module', 'acp', true); + $this->assertEquals(array( + 'phpbb_ext_barfoo_acp_a_module' => array( + 'filename' => 'phpbb_ext_barfoo_acp_a_module', + 'title' => 'Barfoo', + 'version' => '3.1.0-dev', + 'modes' => array( + 'config' => array('title' => 'Config', 'auth' => '', 'cat' => array('ACP_MODS')), + ), + ) ), $acp_modules); } } -- cgit v1.2.1 From bd6cebfe3882d5df810eb1725a10cd64f5473240 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Sun, 12 May 2013 22:44:59 +0200 Subject: [ticket/11465] Increase count of disabled extensions to 5 in functional test The ACP function test checks the amount of disabled extensions. Due to the added disabled extension for the tests of the acp_modules method get_module_infos(), this needed to be increased from 4 to 5. PHPBB3-11465 --- tests/functional/extension_acp_test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/functional/extension_acp_test.php b/tests/functional/extension_acp_test.php index 1879cbd62c..1b406e5042 100644 --- a/tests/functional/extension_acp_test.php +++ b/tests/functional/extension_acp_test.php @@ -112,7 +112,7 @@ class phpbb_functional_extension_acp_test extends phpbb_functional_test_case $crawler = $this->request('GET', 'adm/index.php?i=acp_extensions&mode=main&sid=' . $this->sid); $this->assertCount(1, $crawler->filter('.ext_enabled')); - $this->assertCount(4, $crawler->filter('.ext_disabled')); + $this->assertCount(5, $crawler->filter('.ext_disabled')); $this->assertContains('phpBB Foo Extension', $crawler->filter('.ext_enabled')->eq(0)->text()); $this->assertContainsLang('PURGE', $crawler->filter('.ext_enabled')->eq(0)->text()); -- cgit v1.2.1 From a4d6486d8061049f5c40e971463b171f4ee33708 Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Mon, 13 May 2013 00:35:01 -0500 Subject: [ticket/11413] Fix unit tests PHPBB3-11413 --- tests/notification/notification_test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/notification/notification_test.php b/tests/notification/notification_test.php index c342b10a7f..ff168516e3 100644 --- a/tests/notification/notification_test.php +++ b/tests/notification/notification_test.php @@ -96,7 +96,7 @@ class phpbb_notification_test extends phpbb_database_test_case { global $phpbb_root_path, $phpEx; - return new $type($this->user_loader, $this->db, $this->cache, $this->user, $this->auth, $this->config, $phpbb_root_path, $phpEx, 'phpbb_notification_types', 'phpbb_notifications', 'phpbb_user_notifications'); + return new $type($this->user_loader, $this->db, $this->cache->get_driver(), $this->user, $this->auth, $this->config, $phpbb_root_path, $phpEx, 'phpbb_notification_types', 'phpbb_notifications', 'phpbb_user_notifications'); } public function test_get_notification_type_id() -- cgit v1.2.1 From bae42c6f0a7872d73518b7c3a221b6e23093e0a6 Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Mon, 13 May 2013 00:48:27 -0500 Subject: [ticket/11413] Use phpbb_user in test PHPBB3-11413 --- tests/notification/notification_test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/notification/notification_test.php b/tests/notification/notification_test.php index ff168516e3..8f7eb3b8a8 100644 --- a/tests/notification/notification_test.php +++ b/tests/notification/notification_test.php @@ -33,7 +33,7 @@ class phpbb_notification_test extends phpbb_database_test_case 'allow_topic_notify' => true, 'allow_forum_notify' => true, )); - $this->user = new phpbb_mock_user(); + $this->user = new phpbb_user(); $this->user_loader = new phpbb_user_loader($this->db, $phpbb_root_path, $phpEx, 'phpbb_users'); $this->auth = new phpbb_mock_notifications_auth(); $this->cache = new phpbb_cache_service( -- cgit v1.2.1 From b7b0b0ccc3fbf92324948e8c5e616a3e06343600 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Tue, 14 May 2013 13:43:53 +0200 Subject: [ticket/11538] Make sure group color can't exceed maximum of 6 characters In order to prevent future issues with this, a basic set of functional tests for the UCP groups manage page have been added. PHPBB3-11538 --- tests/functional/ucp_groups_test.php | 61 ++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 tests/functional/ucp_groups_test.php (limited to 'tests') diff --git a/tests/functional/ucp_groups_test.php b/tests/functional/ucp_groups_test.php new file mode 100644 index 0000000000..010727cb55 --- /dev/null +++ b/tests/functional/ucp_groups_test.php @@ -0,0 +1,61 @@ +login(); + $this->add_lang(array('ucp', 'acp/groups')); + + $crawler = $this->request('GET', 'ucp.php?i=groups&mode=manage&action=edit&g=5&sid=' . $this->sid); + $this->assert_response_success(); + $form = $crawler->selectButton($this->lang('SUBMIT'))->form(); + $form['group_colour']->setValue('#AA0000'); + $crawler = $this->client->submit($form); + $this->assertContains($this->lang('GROUP_UPDATED'), $crawler->text()); + + $crawler = $this->request('GET', 'ucp.php?i=groups&mode=manage&action=edit&g=5&sid=' . $this->sid); + $this->assert_response_success(); + $form = $crawler->selectButton($this->lang('SUBMIT'))->form(); + $values = $form->getValues(); + $this->assertContains('AA0000', $values['group_colour']); + $form['group_colour']->setValue('AA0000'); + $crawler = $this->client->submit($form); + $this->assertContains($this->lang('GROUP_UPDATED'), $crawler->text()); + + $crawler = $this->request('GET', 'ucp.php?i=groups&mode=manage&action=edit&g=5&sid=' . $this->sid); + $this->assert_response_success(); + $form = $crawler->selectButton($this->lang('SUBMIT'))->form(); + $values = $form->getValues(); + $this->assertContains('AA0000', $values['group_colour']); + $form['group_colour']->setValue('AA0000v'); + $crawler = $this->client->submit($form); + $this->assertContains($this->lang('GROUP_UPDATED'), $crawler->text()); + + $crawler = $this->request('GET', 'ucp.php?i=groups&mode=manage&action=edit&g=5&sid=' . $this->sid); + $this->assert_response_success(); + $form = $crawler->selectButton($this->lang('SUBMIT'))->form(); + $values = $form->getValues(); + $this->assertContains('AA0000', $values['group_colour']); + $form['group_colour']->setValue('vAA0000'); + $crawler = $this->client->submit($form); + $this->assertContains($this->lang('GROUP_UPDATED'), $crawler->text()); + + $crawler = $this->request('GET', 'ucp.php?i=groups&mode=manage&action=edit&g=5&sid=' . $this->sid); + $this->assert_response_success(); + $form = $crawler->selectButton($this->lang('SUBMIT'))->form(); + $values = $form->getValues(); + $this->assertContains('vAA000', $values['group_colour']); + } +} -- cgit v1.2.1 From 3f75534258144dc0cdafd0e56c712b2b620b9e38 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 14 May 2013 15:54:40 +0200 Subject: [ticket/11540] Add unit tests for is_absolute() PHPBB3-11540 --- tests/functions/is_absolute_test.php | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 tests/functions/is_absolute_test.php (limited to 'tests') diff --git a/tests/functions/is_absolute_test.php b/tests/functions/is_absolute_test.php new file mode 100644 index 0000000000..26425d2a36 --- /dev/null +++ b/tests/functions/is_absolute_test.php @@ -0,0 +1,34 @@ +assertEquals($expected, is_absolute($path)); + } +} -- cgit v1.2.1 From a547ba3f9d569410107574a151af9a2f301bb68e Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Tue, 14 May 2013 19:44:55 +0200 Subject: [ticket/11538] Use regex for testing color value and improve tests We are now using a regex with preg_match() in order to properly check if the entered color value is in hex color format or not. A proper error message is triggered if an incorrect color value is entered and the prepended '#' is removed if necessary. PHPBB3-11538 --- tests/functional/ucp_groups_test.php | 57 +++++++++++++----------------------- 1 file changed, 20 insertions(+), 37 deletions(-) (limited to 'tests') diff --git a/tests/functional/ucp_groups_test.php b/tests/functional/ucp_groups_test.php index 010727cb55..f570c6af8d 100644 --- a/tests/functional/ucp_groups_test.php +++ b/tests/functional/ucp_groups_test.php @@ -12,50 +12,33 @@ */ class phpbb_functional_ucp_groups_test extends phpbb_functional_test_case { - public function test_groups_manage() + public function groups_manage_test_data() + { + return array( + array('#AA0000', 'GROUP_UPDATED'), + array('AA0000', 'GROUP_UPDATED'), + array('AA0000v', 'COLOUR_INVALID'), + array('vAA0000', 'COLOUR_INVALID'), + array('AAG000', 'COLOUR_INVALID'), + array('#a00', 'GROUP_UPDATED'), + array('ag0', 'COLOUR_INVALID'), + array('#ag0', 'COLOUR_INVALID'), + ); + } + + /** + * @dataProvider groups_manage_test_data + */ + public function test_groups_manage($input, $expected) { - $values = array(); $this->login(); $this->add_lang(array('ucp', 'acp/groups')); $crawler = $this->request('GET', 'ucp.php?i=groups&mode=manage&action=edit&g=5&sid=' . $this->sid); $this->assert_response_success(); $form = $crawler->selectButton($this->lang('SUBMIT'))->form(); - $form['group_colour']->setValue('#AA0000'); - $crawler = $this->client->submit($form); - $this->assertContains($this->lang('GROUP_UPDATED'), $crawler->text()); - - $crawler = $this->request('GET', 'ucp.php?i=groups&mode=manage&action=edit&g=5&sid=' . $this->sid); - $this->assert_response_success(); - $form = $crawler->selectButton($this->lang('SUBMIT'))->form(); - $values = $form->getValues(); - $this->assertContains('AA0000', $values['group_colour']); - $form['group_colour']->setValue('AA0000'); - $crawler = $this->client->submit($form); - $this->assertContains($this->lang('GROUP_UPDATED'), $crawler->text()); - - $crawler = $this->request('GET', 'ucp.php?i=groups&mode=manage&action=edit&g=5&sid=' . $this->sid); - $this->assert_response_success(); - $form = $crawler->selectButton($this->lang('SUBMIT'))->form(); - $values = $form->getValues(); - $this->assertContains('AA0000', $values['group_colour']); - $form['group_colour']->setValue('AA0000v'); + $form['group_colour']->setValue($input); $crawler = $this->client->submit($form); - $this->assertContains($this->lang('GROUP_UPDATED'), $crawler->text()); - - $crawler = $this->request('GET', 'ucp.php?i=groups&mode=manage&action=edit&g=5&sid=' . $this->sid); - $this->assert_response_success(); - $form = $crawler->selectButton($this->lang('SUBMIT'))->form(); - $values = $form->getValues(); - $this->assertContains('AA0000', $values['group_colour']); - $form['group_colour']->setValue('vAA0000'); - $crawler = $this->client->submit($form); - $this->assertContains($this->lang('GROUP_UPDATED'), $crawler->text()); - - $crawler = $this->request('GET', 'ucp.php?i=groups&mode=manage&action=edit&g=5&sid=' . $this->sid); - $this->assert_response_success(); - $form = $crawler->selectButton($this->lang('SUBMIT'))->form(); - $values = $form->getValues(); - $this->assertContains('vAA000', $values['group_colour']); + $this->assertContains($this->lang($expected), $crawler->text()); } } -- cgit v1.2.1 From 25be16748dc39b2e30bd55472d8e5d6ef60f1c39 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 14 May 2013 15:55:21 +0200 Subject: [ticket/11541] Add unit tests for style_select() PHPBB3-11541 --- tests/functions/fixtures/style_select.xml | 23 +++++++++++++++++ tests/functions/style_select_test.php | 41 +++++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+) create mode 100644 tests/functions/fixtures/style_select.xml create mode 100644 tests/functions/style_select_test.php (limited to 'tests') diff --git a/tests/functions/fixtures/style_select.xml b/tests/functions/fixtures/style_select.xml new file mode 100644 index 0000000000..12d6392ab5 --- /dev/null +++ b/tests/functions/fixtures/style_select.xml @@ -0,0 +1,23 @@ + + + + style_id + style_name + style_active + + 1 + prosilver + 1 + + + 2 + subsilver2 + 1 + + + 3 + zoo + 0 + +
+
diff --git a/tests/functions/style_select_test.php b/tests/functions/style_select_test.php new file mode 100644 index 0000000000..1e44f3c2cb --- /dev/null +++ b/tests/functions/style_select_test.php @@ -0,0 +1,41 @@ +createXMLDataSet(dirname(__FILE__).'/fixtures/style_select.xml'); + } + + static public function style_select_data() + { + return array( + array('', false, ''), + array('', true, ''), + array('1', false, ''), + array('1', true, ''), + array('3', false, ''), + array('3', true, ''), + ); + } + + /** + * @dataProvider style_select_data + */ + public function test_style_select($default, $all, $expected) + { + global $db; + $db = $this->new_dbal(); + + $this->assertEquals($expected, style_select($default, $all)); + } +} -- cgit v1.2.1 From 6900e8dae08b4a8c1af3529a418f5156b0cfd157 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 14 May 2013 15:55:05 +0200 Subject: [ticket/11542] Add unit tests for language_select() PHPBB3-11542 --- tests/functions/fixtures/language_select.xml | 18 +++++++++++++ tests/functions/language_select_test.php | 38 ++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 tests/functions/fixtures/language_select.xml create mode 100644 tests/functions/language_select_test.php (limited to 'tests') diff --git a/tests/functions/fixtures/language_select.xml b/tests/functions/fixtures/language_select.xml new file mode 100644 index 0000000000..02fdee093e --- /dev/null +++ b/tests/functions/fixtures/language_select.xml @@ -0,0 +1,18 @@ + + + + lang_id + lang_iso + lang_local_name + + 1 + en + English + + + 2 + de + Deutsch + +
+
diff --git a/tests/functions/language_select_test.php b/tests/functions/language_select_test.php new file mode 100644 index 0000000000..3e7ed45bbf --- /dev/null +++ b/tests/functions/language_select_test.php @@ -0,0 +1,38 @@ +createXMLDataSet(dirname(__FILE__).'/fixtures/language_select.xml'); + } + + static public function language_select_data() + { + return array( + array('', ''), + array('en', ''), + array('de', ''), + ); + } + + /** + * @dataProvider language_select_data + */ + public function test_language_select($default, $expected) + { + global $db; + $db = $this->new_dbal(); + + $this->assertEquals($expected, language_select($default)); + } +} -- cgit v1.2.1 From 1fae7720e43c8ff853225e16d0de54395d9ab051 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Tue, 14 May 2013 21:27:25 +0200 Subject: [ticket/11538] Fix incorrect regex and test for duplicate # in color string PHPBB3-11538 --- tests/functional/ucp_groups_test.php | 1 + 1 file changed, 1 insertion(+) (limited to 'tests') diff --git a/tests/functional/ucp_groups_test.php b/tests/functional/ucp_groups_test.php index f570c6af8d..d5ac6f697e 100644 --- a/tests/functional/ucp_groups_test.php +++ b/tests/functional/ucp_groups_test.php @@ -23,6 +23,7 @@ class phpbb_functional_ucp_groups_test extends phpbb_functional_test_case array('#a00', 'GROUP_UPDATED'), array('ag0', 'COLOUR_INVALID'), array('#ag0', 'COLOUR_INVALID'), + array('##bcc', 'COLOUR_INVALID'), ); } -- cgit v1.2.1 From deefe5c0e48534cea1327cf685255d109d9d7e2c Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Tue, 14 May 2013 22:39:33 +0200 Subject: [ticket/11538] Simplify colour value check and remove support for '#' The input length for the hex color is now limited to 6 characters and the support for colors starting with a '#' has been dropped. The allowed input length of 7 in prosilver seems to have been a relict from old ages of phpBB3. In order to have proper support for correct checking of the colour value, the new code was also ported to the ACP groups manage page. The tests have been modified to reflect the changes to the behavior of the color check. Tests for the ACP will follow. PHPBB3-11538 --- tests/functional/ucp_groups_test.php | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) (limited to 'tests') diff --git a/tests/functional/ucp_groups_test.php b/tests/functional/ucp_groups_test.php index d5ac6f697e..7a315c2018 100644 --- a/tests/functional/ucp_groups_test.php +++ b/tests/functional/ucp_groups_test.php @@ -15,15 +15,14 @@ class phpbb_functional_ucp_groups_test extends phpbb_functional_test_case public function groups_manage_test_data() { return array( - array('#AA0000', 'GROUP_UPDATED'), + array('#AA0000', 'WRONG_DATA_COLOUR'), array('AA0000', 'GROUP_UPDATED'), - array('AA0000v', 'COLOUR_INVALID'), - array('vAA0000', 'COLOUR_INVALID'), - array('AAG000', 'COLOUR_INVALID'), - array('#a00', 'GROUP_UPDATED'), - array('ag0', 'COLOUR_INVALID'), - array('#ag0', 'COLOUR_INVALID'), - array('##bcc', 'COLOUR_INVALID'), + array('AA0000v', 'WRONG_DATA_COLOUR'), + array('vAA0000', 'WRONG_DATA_COLOUR'), + array('AAG000','WRONG_DATA_COLOUR'), + array('a00', 'GROUP_UPDATED'), + array('ag0', 'WRONG_DATA_COLOUR'), + array('#aa0', 'WRONG_DATA_COLOUR'), ); } -- cgit v1.2.1 From cbe4a3c3b6a2b21aeff179ee8452fb705d05369b Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Tue, 14 May 2013 22:50:17 +0200 Subject: [ticket/11538] Add tests for acp group manage page This will currently test if the colour check properly works. PHPBB3-11538 --- tests/functional/acp_groups_test.php | 45 ++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 tests/functional/acp_groups_test.php (limited to 'tests') diff --git a/tests/functional/acp_groups_test.php b/tests/functional/acp_groups_test.php new file mode 100644 index 0000000000..152f05c7a7 --- /dev/null +++ b/tests/functional/acp_groups_test.php @@ -0,0 +1,45 @@ +login(); + $this->admin_login(); + $this->add_lang(array('ucp', 'acp/groups')); + + $crawler = $this->request('GET', 'adm/index.php?i=groups&mode=manage&action=edit&g=5&sid=' . $this->sid); + $this->assert_response_success(); + $form = $crawler->selectButton($this->lang('SUBMIT'))->form(); + $form['group_colour']->setValue($input); + $crawler = $this->client->submit($form); + $this->assertContains($this->lang($expected), $crawler->text()); + } +} -- cgit v1.2.1 From ac8e8a156a771cabcd73859f1c2235c89257e76b Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Tue, 14 May 2013 22:51:10 +0200 Subject: [ticket/11544] Add admin_login() method to 3.0 functional test case This method is needed in order to be able to properly test acp functions. PHPBB3-11544 --- .../test_framework/phpbb_functional_test_case.php | 44 ++++++++++++++++++++++ 1 file changed, 44 insertions(+) (limited to 'tests') diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index 83c931f924..b1352b247e 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -299,6 +299,50 @@ class phpbb_functional_test_case extends phpbb_test_case } } + /** + * Login to the ACP + * You must run login() before calling this. + */ + protected function admin_login($username = 'admin') + { + $this->add_lang('acp/common'); + + // Requires login first! + if (empty($this->sid)) + { + $this->fail('$this->sid is empty. Make sure you call login() before admin_login()'); + return; + } + + $crawler = $this->request('GET', 'adm/index.php?sid=' . $this->sid); + $this->assertContains($this->lang('LOGIN_ADMIN_CONFIRM'), $crawler->filter('html')->text()); + + $form = $crawler->selectButton($this->lang('LOGIN'))->form(); + + foreach ($form->getValues() as $field => $value) + { + if (strpos($field, 'password_') === 0) + { + $crawler = $this->client->submit($form, array('username' => $username, $field => $username)); + $this->assert_response_success(); + $this->assertContains($this->lang('LOGIN_ADMIN_SUCCESS'), $crawler->filter('html')->text()); + + $cookies = $this->cookieJar->all(); + + // The session id is stored in a cookie that ends with _sid - we assume there is only one such cookie + foreach ($cookies as $cookie); + { + if (substr($cookie->getName(), -4) == '_sid') + { + $this->sid = $cookie->getValue(); + } + } + + break; + } + } + } + protected function add_lang($lang_file) { if (is_array($lang_file)) -- cgit v1.2.1 From 20815ed5a2032dbad628304d31a0c29b6eef3d4f Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Tue, 14 May 2013 18:56:16 -0500 Subject: [ticket/11415] Add test for find_from_extension() PHPBB3-11415 --- tests/extension/finder_test.php | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'tests') diff --git a/tests/extension/finder_test.php b/tests/extension/finder_test.php index dc3e26be02..6f3cebbd7c 100644 --- a/tests/extension/finder_test.php +++ b/tests/extension/finder_test.php @@ -158,6 +158,23 @@ class phpbb_extension_finder_test extends phpbb_test_case ); } + public function test_find_from_extension() + { + $files = $this->finder + ->extension_directory('/type') + ->find_from_extension('foo', dirname(__FILE__) . '/ext/foo/'); + $classes = $this->finder->get_classes_from_files($files); + + sort($classes); + $this->assertEquals( + array( + 'phpbb_ext_foo_type_alternative', + 'phpbb_ext_foo_type_dummy_empty', + ), + $classes + ); + } + /** * These do not work because of changes with PHPBB3-11386 * They do not seem neccessary to me, so I am commenting them out for now -- cgit v1.2.1 From 204cdb21640aead9f7560034bb8e686c17707476 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Wed, 15 May 2013 12:30:05 +0200 Subject: [ticket/11538] Make sure regex doesn't allow multiple color values This will now make sure that 'AAFF00' will be matched but strings like 'AAFF00 AABB00' will not. PHPBB3-11538 --- tests/functional/acp_groups_test.php | 3 +++ tests/functional/ucp_groups_test.php | 3 +++ 2 files changed, 6 insertions(+) (limited to 'tests') diff --git a/tests/functional/acp_groups_test.php b/tests/functional/acp_groups_test.php index 152f05c7a7..9a85e9ec67 100644 --- a/tests/functional/acp_groups_test.php +++ b/tests/functional/acp_groups_test.php @@ -23,6 +23,9 @@ class phpbb_functional_acp_groups_test extends phpbb_functional_test_case array('a00', 'GROUP_UPDATED'), array('ag0', 'WRONG_DATA_COLOUR'), array('#aa0', 'WRONG_DATA_COLOUR'), + array('AA0000 ', 'GROUP_UPDATED'), + array('AA0000 abf', 'WRONG_DATA_COLOUR'), + array('AA0000 AA0000', 'WRONG_DATA_COLOUR'), ); } diff --git a/tests/functional/ucp_groups_test.php b/tests/functional/ucp_groups_test.php index 7a315c2018..ae568e8182 100644 --- a/tests/functional/ucp_groups_test.php +++ b/tests/functional/ucp_groups_test.php @@ -23,6 +23,9 @@ class phpbb_functional_ucp_groups_test extends phpbb_functional_test_case array('a00', 'GROUP_UPDATED'), array('ag0', 'WRONG_DATA_COLOUR'), array('#aa0', 'WRONG_DATA_COLOUR'), + array('AA0000 ', 'GROUP_UPDATED'), + array('AA0000 abf', 'WRONG_DATA_COLOUR'), + array('AA0000 AA0000', 'WRONG_DATA_COLOUR'), ); } -- cgit v1.2.1 From fd3b257468042fe546916370c4610dc8238c2483 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Wed, 15 May 2013 13:52:02 +0200 Subject: [ticket/11540] Add phpbb_ prefix in is_absolute_test from olympus. PHPBB3-11540 --- tests/functions/is_absolute_test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/functions/is_absolute_test.php b/tests/functions/is_absolute_test.php index 26425d2a36..64a7a81b4a 100644 --- a/tests/functions/is_absolute_test.php +++ b/tests/functions/is_absolute_test.php @@ -29,6 +29,6 @@ class phpbb_functions_is_absolute_test extends phpbb_test_case */ public function test_is_absolute($path, $expected) { - $this->assertEquals($expected, is_absolute($path)); + $this->assertEquals($expected, phpbb_is_absolute($path)); } } -- cgit v1.2.1 From 06edf15ac3e63350b7973b04f07578de1c4565d0 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 15 May 2013 13:55:35 +0200 Subject: [ticket/11546] Fix is_absolute() throws E_NOTICE for empty string PHPBB3-11546 --- tests/functions/is_absolute_test.php | 1 + 1 file changed, 1 insertion(+) (limited to 'tests') diff --git a/tests/functions/is_absolute_test.php b/tests/functions/is_absolute_test.php index 26425d2a36..5d70b6c2a3 100644 --- a/tests/functions/is_absolute_test.php +++ b/tests/functions/is_absolute_test.php @@ -14,6 +14,7 @@ class phpbb_functions_is_absolute_test extends phpbb_test_case static public function is_absolute_data() { return array( + array('', false), array('/etc/phpbb', true), array('etc/phpbb', false), -- cgit v1.2.1 From 14ab0ba594c1b78176452c012965fa4ec723f37f Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 15 May 2013 15:18:28 +0200 Subject: [ticket/11542] Add lang_english_name to fixture PHPBB3-11542 --- tests/functions/fixtures/language_select.xml | 3 +++ 1 file changed, 3 insertions(+) (limited to 'tests') diff --git a/tests/functions/fixtures/language_select.xml b/tests/functions/fixtures/language_select.xml index 02fdee093e..921f2c0a3a 100644 --- a/tests/functions/fixtures/language_select.xml +++ b/tests/functions/fixtures/language_select.xml @@ -4,15 +4,18 @@ lang_id lang_iso lang_local_name + lang_english_name 1 en English + English 2 de Deutsch + German -- cgit v1.2.1 From 38dbfc17a782f72737451103b8e4067f152bd0b7 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 16 May 2013 17:30:23 +0200 Subject: [ticket/11545] Remove DIRECTORY_SEPARATOR dependency from is_absolute The given path is an absolute path in general, just not on our current system. PHPBB3-11545 --- tests/functions/is_absolute_test.php | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) (limited to 'tests') diff --git a/tests/functions/is_absolute_test.php b/tests/functions/is_absolute_test.php index 5d70b6c2a3..7630b7c58c 100644 --- a/tests/functions/is_absolute_test.php +++ b/tests/functions/is_absolute_test.php @@ -14,14 +14,35 @@ class phpbb_functions_is_absolute_test extends phpbb_test_case static public function is_absolute_data() { return array( + // Empty array('', false), + + // Absolute unix style array('/etc/phpbb', true), + // Unix does not support \ so that is not an absolute path + array('\etc\phpbb', false), + + // Absolute windows style + array('c:\windows', true), + array('C:\Windows', true), + array('c:/windows', true), + array('C:/Windows', true), + + // Executable array('etc/phpbb', false), + array('explorer.exe', false), + + // Relative subdir + array('Windows\System32', false), + array('Windows\System32\explorer.exe', false), + array('Windows/System32', false), + array('Windows/System32/explorer.exe', false), - // Until we got DIRECTORY_SEPARATOR replaced in that function, - // test results vary on OS. - array('c:\windows', DIRECTORY_SEPARATOR == '\\'), - array('C:\Windows', DIRECTORY_SEPARATOR == '\\'), + // Relative updir + array('..\Windows\System32', false), + array('..\Windows\System32\explorer.exe', false), + array('../Windows/System32', false), + array('../Windows/System32/explorer.exe', false), ); } -- cgit v1.2.1 From 92e1e86e5c75879c2b538cbf738de947eadb08d3 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 16 May 2013 00:14:40 +0200 Subject: [ticket/11542] Add non-existing default value for language select PHPBB3-11542 --- tests/functions/language_select_test.php | 1 + 1 file changed, 1 insertion(+) (limited to 'tests') diff --git a/tests/functions/language_select_test.php b/tests/functions/language_select_test.php index 3e7ed45bbf..3ec2bd4bc3 100644 --- a/tests/functions/language_select_test.php +++ b/tests/functions/language_select_test.php @@ -22,6 +22,7 @@ class phpbb_functions_language_select_test extends phpbb_database_test_case array('', ''), array('en', ''), array('de', ''), + array('cs', ''), ); } -- cgit v1.2.1 From 225aba976e0603c24d4808ad71d6b00e86326400 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Fri, 17 May 2013 01:22:22 +0200 Subject: [ticket/11547] Set MySQL charset to UTF8 in database_test_connection_manager. PHPBB3-11547 --- tests/test_framework/phpbb_database_test_connection_manager.php | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'tests') diff --git a/tests/test_framework/phpbb_database_test_connection_manager.php b/tests/test_framework/phpbb_database_test_connection_manager.php index 3b8c2e99ae..af7e6b1144 100644 --- a/tests/test_framework/phpbb_database_test_connection_manager.php +++ b/tests/test_framework/phpbb_database_test_connection_manager.php @@ -142,6 +142,14 @@ class phpbb_database_test_connection_manager } $this->pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); + + switch ($this->config['dbms']) + { + case 'mysql': + case 'mysqli': + $this->pdo->exec('SET NAMES utf8'); + default: + } } /** -- cgit v1.2.1 From 1ee2543309245d627c000bcd1b3d680ae7498123 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 17 May 2013 02:13:51 +0200 Subject: [ticket/11542] Use Czech as example as it contains non-latin characters PHPBB3-11542 --- tests/functions/fixtures/language_select.xml | 6 +++--- tests/functions/language_select_test.php | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) (limited to 'tests') diff --git a/tests/functions/fixtures/language_select.xml b/tests/functions/fixtures/language_select.xml index 921f2c0a3a..d7232a3d28 100644 --- a/tests/functions/fixtures/language_select.xml +++ b/tests/functions/fixtures/language_select.xml @@ -13,9 +13,9 @@ 2 - de - Deutsch - German + cs + Čeština + Czech diff --git a/tests/functions/language_select_test.php b/tests/functions/language_select_test.php index 3ec2bd4bc3..3341e2a256 100644 --- a/tests/functions/language_select_test.php +++ b/tests/functions/language_select_test.php @@ -19,10 +19,10 @@ class phpbb_functions_language_select_test extends phpbb_database_test_case static public function language_select_data() { return array( - array('', ''), - array('en', ''), - array('de', ''), - array('cs', ''), + array('', ''), + array('en', ''), + array('cs', ''), + array('de', ''), ); } -- cgit v1.2.1 From 0a1ca4d3eafda2e9c3baa30e55d825d934f5aed4 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Fri, 17 May 2013 02:31:25 +0200 Subject: [ticket/11547] Add phpbb_db_driver_ prefix to DBMS names. PHPBB3-11547 --- tests/test_framework/phpbb_database_test_connection_manager.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/test_framework/phpbb_database_test_connection_manager.php b/tests/test_framework/phpbb_database_test_connection_manager.php index 237fbd9af2..a192d2922f 100644 --- a/tests/test_framework/phpbb_database_test_connection_manager.php +++ b/tests/test_framework/phpbb_database_test_connection_manager.php @@ -145,8 +145,8 @@ class phpbb_database_test_connection_manager switch ($this->config['dbms']) { - case 'mysql': - case 'mysqli': + case 'phpbb_db_driver_mysql': + case 'phpbb_db_driver_mysqli': $this->pdo->exec('SET NAMES utf8'); default: } -- cgit v1.2.1 From 0a5988ec1f3d72afb17b87d6cd74f60b646bae42 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Fri, 17 May 2013 12:32:09 +0200 Subject: [ticket/11538] Use abstract class for functional test cases for group colour PHPBB3-11538 --- tests/functional/acp_groups_test.php | 37 ++++-------------------- tests/functional/common_groups_test.php | 50 +++++++++++++++++++++++++++++++++ tests/functional/ucp_groups_test.php | 36 ++++-------------------- 3 files changed, 60 insertions(+), 63 deletions(-) create mode 100644 tests/functional/common_groups_test.php (limited to 'tests') diff --git a/tests/functional/acp_groups_test.php b/tests/functional/acp_groups_test.php index 9a85e9ec67..8b45bea7a6 100644 --- a/tests/functional/acp_groups_test.php +++ b/tests/functional/acp_groups_test.php @@ -7,42 +7,15 @@ * */ +require_once dirname(__FILE__) . '/common_groups_test.php'; + /** * @group functional */ -class phpbb_functional_acp_groups_test extends phpbb_functional_test_case +class phpbb_functional_acp_groups_test extends phpbb_functional_common_groups_test { - public function groups_manage_test_data() + protected function get_url() { - return array( - array('#AA0000', 'WRONG_DATA_COLOUR'), - array('AA0000', 'GROUP_UPDATED'), - array('AA0000v', 'WRONG_DATA_COLOUR'), - array('vAA0000', 'WRONG_DATA_COLOUR'), - array('AAG000','WRONG_DATA_COLOUR'), - array('a00', 'GROUP_UPDATED'), - array('ag0', 'WRONG_DATA_COLOUR'), - array('#aa0', 'WRONG_DATA_COLOUR'), - array('AA0000 ', 'GROUP_UPDATED'), - array('AA0000 abf', 'WRONG_DATA_COLOUR'), - array('AA0000 AA0000', 'WRONG_DATA_COLOUR'), - ); - } - - /** - * @dataProvider groups_manage_test_data - */ - public function test_groups_manage($input, $expected) - { - $this->login(); - $this->admin_login(); - $this->add_lang(array('ucp', 'acp/groups')); - - $crawler = $this->request('GET', 'adm/index.php?i=groups&mode=manage&action=edit&g=5&sid=' . $this->sid); - $this->assert_response_success(); - $form = $crawler->selectButton($this->lang('SUBMIT'))->form(); - $form['group_colour']->setValue($input); - $crawler = $this->client->submit($form); - $this->assertContains($this->lang($expected), $crawler->text()); + return 'adm/index.php?i=groups&mode=manage&action=edit&g=5'; } } diff --git a/tests/functional/common_groups_test.php b/tests/functional/common_groups_test.php new file mode 100644 index 0000000000..3061bf7510 --- /dev/null +++ b/tests/functional/common_groups_test.php @@ -0,0 +1,50 @@ +login(); + $this->admin_login(); + $this->add_lang(array('ucp', 'acp/groups')); + + $crawler = $this->request('GET', $this->get_url() . '&sid=' . $this->sid); + $this->assert_response_success(); + $form = $crawler->selectButton($this->lang('SUBMIT'))->form(); + $form['group_colour']->setValue($input); + $crawler = $this->client->submit($form); + $this->assertContains($this->lang($expected), $crawler->text()); + } +} diff --git a/tests/functional/ucp_groups_test.php b/tests/functional/ucp_groups_test.php index ae568e8182..8401cfdb09 100644 --- a/tests/functional/ucp_groups_test.php +++ b/tests/functional/ucp_groups_test.php @@ -7,41 +7,15 @@ * */ +require_once dirname(__FILE__) . '/common_groups_test.php'; + /** * @group functional */ -class phpbb_functional_ucp_groups_test extends phpbb_functional_test_case +class phpbb_functional_ucp_groups_test extends phpbb_functional_common_groups_test { - public function groups_manage_test_data() + protected function get_url() { - return array( - array('#AA0000', 'WRONG_DATA_COLOUR'), - array('AA0000', 'GROUP_UPDATED'), - array('AA0000v', 'WRONG_DATA_COLOUR'), - array('vAA0000', 'WRONG_DATA_COLOUR'), - array('AAG000','WRONG_DATA_COLOUR'), - array('a00', 'GROUP_UPDATED'), - array('ag0', 'WRONG_DATA_COLOUR'), - array('#aa0', 'WRONG_DATA_COLOUR'), - array('AA0000 ', 'GROUP_UPDATED'), - array('AA0000 abf', 'WRONG_DATA_COLOUR'), - array('AA0000 AA0000', 'WRONG_DATA_COLOUR'), - ); - } - - /** - * @dataProvider groups_manage_test_data - */ - public function test_groups_manage($input, $expected) - { - $this->login(); - $this->add_lang(array('ucp', 'acp/groups')); - - $crawler = $this->request('GET', 'ucp.php?i=groups&mode=manage&action=edit&g=5&sid=' . $this->sid); - $this->assert_response_success(); - $form = $crawler->selectButton($this->lang('SUBMIT'))->form(); - $form['group_colour']->setValue($input); - $crawler = $this->client->submit($form); - $this->assertContains($this->lang($expected), $crawler->text()); + return 'ucp.php?i=groups&mode=manage&action=edit&g=5'; } } -- cgit v1.2.1 From 8aea2b382dcb57f67704dec5194378d9a76c127e Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Sun, 19 May 2013 11:44:26 +0200 Subject: [ticket/11538] Move group ID into abstract test class and add more test cases The group ID is defined in the abstract class now and additional test cases for hex colour values have been added. PHPBB3-11538 --- tests/functional/acp_groups_test.php | 2 +- tests/functional/common_groups_test.php | 6 +++++- tests/functional/ucp_groups_test.php | 2 +- 3 files changed, 7 insertions(+), 3 deletions(-) (limited to 'tests') diff --git a/tests/functional/acp_groups_test.php b/tests/functional/acp_groups_test.php index 8b45bea7a6..3d8cabb086 100644 --- a/tests/functional/acp_groups_test.php +++ b/tests/functional/acp_groups_test.php @@ -16,6 +16,6 @@ class phpbb_functional_acp_groups_test extends phpbb_functional_common_groups_te { protected function get_url() { - return 'adm/index.php?i=groups&mode=manage&action=edit&g=5'; + return 'adm/index.php?i=groups&mode=manage&action=edit'; } } diff --git a/tests/functional/common_groups_test.php b/tests/functional/common_groups_test.php index 3061bf7510..985dbc9220 100644 --- a/tests/functional/common_groups_test.php +++ b/tests/functional/common_groups_test.php @@ -20,6 +20,7 @@ abstract class phpbb_functional_common_groups_test extends phpbb_functional_test array('#AA0000', 'WRONG_DATA_COLOUR'), array('AA0000', 'GROUP_UPDATED'), array('AA0000v', 'WRONG_DATA_COLOUR'), + array('AA00000', 'WRONG_DATA_COLOUR'), array('vAA0000', 'WRONG_DATA_COLOUR'), array('AAG000','WRONG_DATA_COLOUR'), array('a00', 'GROUP_UPDATED'), @@ -28,6 +29,8 @@ abstract class phpbb_functional_common_groups_test extends phpbb_functional_test array('AA0000 ', 'GROUP_UPDATED'), array('AA0000 abf', 'WRONG_DATA_COLOUR'), array('AA0000 AA0000', 'WRONG_DATA_COLOUR'), + array('000 ', 'GROUP_UPDATED'), + array('000000 ', 'GROUP_UPDATED'), ); } @@ -40,7 +43,8 @@ abstract class phpbb_functional_common_groups_test extends phpbb_functional_test $this->admin_login(); $this->add_lang(array('ucp', 'acp/groups')); - $crawler = $this->request('GET', $this->get_url() . '&sid=' . $this->sid); + // Manage Administrators group + $crawler = $this->request('GET', $this->get_url() . '&g=5&sid=' . $this->sid); $this->assert_response_success(); $form = $crawler->selectButton($this->lang('SUBMIT'))->form(); $form['group_colour']->setValue($input); diff --git a/tests/functional/ucp_groups_test.php b/tests/functional/ucp_groups_test.php index 8401cfdb09..9c6b1edc5e 100644 --- a/tests/functional/ucp_groups_test.php +++ b/tests/functional/ucp_groups_test.php @@ -16,6 +16,6 @@ class phpbb_functional_ucp_groups_test extends phpbb_functional_common_groups_te { protected function get_url() { - return 'ucp.php?i=groups&mode=manage&action=edit&g=5'; + return 'ucp.php?i=groups&mode=manage&action=edit'; } } -- cgit v1.2.1 From e49b4543de7c18df7e9b5c70ef5064cc4de9934a Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Sun, 19 May 2013 15:17:47 +0200 Subject: [ticket/11538] Modify test colour values PHPBB3-11538 --- tests/functional/common_groups_test.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/functional/common_groups_test.php b/tests/functional/common_groups_test.php index 985dbc9220..02a538d46e 100644 --- a/tests/functional/common_groups_test.php +++ b/tests/functional/common_groups_test.php @@ -29,8 +29,9 @@ abstract class phpbb_functional_common_groups_test extends phpbb_functional_test array('AA0000 ', 'GROUP_UPDATED'), array('AA0000 abf', 'WRONG_DATA_COLOUR'), array('AA0000 AA0000', 'WRONG_DATA_COLOUR'), - array('000 ', 'GROUP_UPDATED'), - array('000000 ', 'GROUP_UPDATED'), + array('', 'GROUP_UPDATED'), + array('000', 'GROUP_UPDATED'), + array('000000', 'GROUP_UPDATED'), ); } -- cgit v1.2.1 From bee2faa560323a7385a3920b2f0c4e45b215da52 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Mon, 29 Oct 2012 07:52:25 -0400 Subject: [ticket/11010] Progress toward fixing the test suite. PHPBB3-11010 --- tests/functions_acp/build_cfg_template_test.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'tests') diff --git a/tests/functions_acp/build_cfg_template_test.php b/tests/functions_acp/build_cfg_template_test.php index bf5330fd88..0a6c922ce1 100644 --- a/tests/functions_acp/build_cfg_template_test.php +++ b/tests/functions_acp/build_cfg_template_test.php @@ -58,20 +58,20 @@ class phpbb_functions_acp_build_cfg_template_test extends phpbb_test_case { return array( array( - array('dimension', 20, 255), - 'key_name', + array('dimension', 20, 15), + 'number_key_name', array('config_key_name_width' => 10, 'config_key_name_height' => 20), 'config_key_name', array(), - ' x ', + ' x ', ), array( - array('dimension', 0, 255), - 'key_name', + array('dimension', 0, 15), + 'number_key_name', array('config_key_name_width' => 10, 'config_key_name_height' => 20), 'config_key_name', array(), - ' x ', + ' x ', ), ); } -- cgit v1.2.1 From 84fb8fc4f08cd1b35ab0813ac61101b479c577ec Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Mon, 7 Jan 2013 06:49:21 -0500 Subject: [ticket/11010] Mock user in order for the test to run standalone. PHPBB3-11010 --- tests/functions_acp/build_cfg_template_test.php | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'tests') diff --git a/tests/functions_acp/build_cfg_template_test.php b/tests/functions_acp/build_cfg_template_test.php index 0a6c922ce1..3b304362a0 100644 --- a/tests/functions_acp/build_cfg_template_test.php +++ b/tests/functions_acp/build_cfg_template_test.php @@ -49,6 +49,7 @@ class phpbb_functions_acp_build_cfg_template_test extends phpbb_test_case global $user, $phpbb_dispatcher; $phpbb_dispatcher = new phpbb_mock_event_dispatcher(); + $user = new phpbb_mock_user(); $user->lang = new phpbb_mock_lang(); $this->assertEquals($expected, build_cfg_template($tpl_type, $key, $new, $config_key, $vars)); @@ -84,6 +85,7 @@ class phpbb_functions_acp_build_cfg_template_test extends phpbb_test_case global $user, $phpbb_dispatcher; $phpbb_dispatcher = new phpbb_mock_event_dispatcher(); + $user = new phpbb_mock_user(); $user->lang = new phpbb_mock_lang(); $this->assertEquals($expected, build_cfg_template($tpl_type, $key, $new, $config_key, $vars)); @@ -111,6 +113,7 @@ class phpbb_functions_acp_build_cfg_template_test extends phpbb_test_case global $user, $phpbb_dispatcher; $phpbb_dispatcher = new phpbb_mock_event_dispatcher(); + $user = new phpbb_mock_user(); $user->lang = new phpbb_mock_lang(); $this->assertEquals($expected, build_cfg_template($tpl_type, $key, $new, $config_key, $vars)); @@ -162,6 +165,7 @@ class phpbb_functions_acp_build_cfg_template_test extends phpbb_test_case global $user, $phpbb_dispatcher; $phpbb_dispatcher = new phpbb_mock_event_dispatcher(); + $user = new phpbb_mock_user(); $user->lang = new phpbb_mock_lang(); $this->assertEquals($expected, build_cfg_template($tpl_type, $key, $new, $config_key, $vars)); @@ -189,6 +193,7 @@ class phpbb_functions_acp_build_cfg_template_test extends phpbb_test_case global $user, $phpbb_dispatcher; $phpbb_dispatcher = new phpbb_mock_event_dispatcher(); + $user = new phpbb_mock_user(); $user->lang = new phpbb_mock_lang(); $this->assertEquals($expected, build_cfg_template($tpl_type, $key, $new, $config_key, $vars)); -- cgit v1.2.1 From 4bb7a69afa90636a473005467828bfecf0e31b29 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Mon, 7 Jan 2013 06:56:48 -0500 Subject: [ticket/11010] Try to keep min < max. PHPBB3-11010 --- tests/functions_acp/build_cfg_template_test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/functions_acp/build_cfg_template_test.php b/tests/functions_acp/build_cfg_template_test.php index 3b304362a0..32980d97ce 100644 --- a/tests/functions_acp/build_cfg_template_test.php +++ b/tests/functions_acp/build_cfg_template_test.php @@ -59,7 +59,7 @@ class phpbb_functions_acp_build_cfg_template_test extends phpbb_test_case { return array( array( - array('dimension', 20, 15), + array('dimension', 5, 15), 'number_key_name', array('config_key_name_width' => 10, 'config_key_name_height' => 20), 'config_key_name', -- cgit v1.2.1 From 77ae733918d47b12f65a13fb58df03e2c8a3e621 Mon Sep 17 00:00:00 2001 From: Senky Date: Wed, 6 Feb 2013 23:02:53 +0100 Subject: [ticket/11010] fixing tests PHPBB3-11010 --- tests/functions_acp/build_cfg_template_test.php | 40 +++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/functions_acp/build_cfg_template_test.php b/tests/functions_acp/build_cfg_template_test.php index 32980d97ce..3159aabaa1 100644 --- a/tests/functions_acp/build_cfg_template_test.php +++ b/tests/functions_acp/build_cfg_template_test.php @@ -64,7 +64,7 @@ class phpbb_functions_acp_build_cfg_template_test extends phpbb_test_case array('config_key_name_width' => 10, 'config_key_name_height' => 20), 'config_key_name', array(), - ' x ', + ' x ', ), array( array('dimension', 0, 15), @@ -72,7 +72,7 @@ class phpbb_functions_acp_build_cfg_template_test extends phpbb_test_case array('config_key_name_width' => 10, 'config_key_name_height' => 20), 'config_key_name', array(), - ' x ', + ' x ', ), ); } @@ -91,6 +91,42 @@ class phpbb_functions_acp_build_cfg_template_test extends phpbb_test_case $this->assertEquals($expected, build_cfg_template($tpl_type, $key, $new, $config_key, $vars)); } + public function build_cfg_template_number_data() + { + return array( + array( + array('number', 5, 15), + 'number_key_name', + array('config_key_name' => 10), + 'config_key_name', + array(), + '', + ), + array( + array('number', -1, 9999), + 'number_key_name', + array('config_key_name' => 10), + 'config_key_name', + array(), + '', + ), + ); + } + + /** + * @dataProvider build_cfg_template_number_data + */ + public function test_build_cfg_template_number($tpl_type, $key, $new, $config_key, $vars, $expected) + { + global $user, $phpbb_dispatcher; + + $phpbb_dispatcher = new phpbb_mock_event_dispatcher(); + $user = new phpbb_mock_user(); + $user->lang = new phpbb_mock_lang(); + + $this->assertEquals($expected, build_cfg_template($tpl_type, $key, $new, $config_key, $vars)); + } + public function build_cfg_template_textarea_data() { return array( -- cgit v1.2.1 From ae2700eef29a0cda1ff9abecb9bdc6beaf199982 Mon Sep 17 00:00:00 2001 From: Senky Date: Sun, 12 May 2013 15:01:43 +0200 Subject: [ticket/11010] updating tests PHPBB3-11010 --- tests/functions_acp/build_cfg_template_test.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/functions_acp/build_cfg_template_test.php b/tests/functions_acp/build_cfg_template_test.php index 3159aabaa1..acf4da1bd6 100644 --- a/tests/functions_acp/build_cfg_template_test.php +++ b/tests/functions_acp/build_cfg_template_test.php @@ -64,7 +64,7 @@ class phpbb_functions_acp_build_cfg_template_test extends phpbb_test_case array('config_key_name_width' => 10, 'config_key_name_height' => 20), 'config_key_name', array(), - ' x ', + ' x ', ), array( array('dimension', 0, 15), @@ -72,7 +72,7 @@ class phpbb_functions_acp_build_cfg_template_test extends phpbb_test_case array('config_key_name_width' => 10, 'config_key_name_height' => 20), 'config_key_name', array(), - ' x ', + ' x ', ), ); } -- cgit v1.2.1 From 06720fb0d795423331372c73304ba923e47f7135 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Mon, 20 May 2013 11:46:08 -0500 Subject: [ticket/11435] Enable spacing test as it should now pass PHPBB3-11435 --- tests/template/template_spacing_test.php | 4 ---- 1 file changed, 4 deletions(-) (limited to 'tests') diff --git a/tests/template/template_spacing_test.php b/tests/template/template_spacing_test.php index fb4161066a..83f8711b38 100644 --- a/tests/template/template_spacing_test.php +++ b/tests/template/template_spacing_test.php @@ -59,10 +59,6 @@ class phpbb_template_template_spacing_test extends phpbb_template_template_test_ */ public function test_event($desc, $dataset, $style_names, $file, array $vars, array $block_vars, array $destroy, $expected) { - $this->markTestIncomplete( - 'This test will fail until PHPBB3-11435 is fixed' - ); - // Reset the engine state $this->setup_engine_for_events($dataset, $style_names); -- cgit v1.2.1 From e84f5db4f5f24a2cfb06dc89fc371685e95380fb Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Sun, 26 May 2013 17:24:03 +0200 Subject: [ticket/11538] Add unit tests for phpbb_validate_hex_colour(). PHPBB3-11538 --- tests/functions/validate_hex_colour_test.php | 121 +++++++++++++++++++++++++++ 1 file changed, 121 insertions(+) create mode 100644 tests/functions/validate_hex_colour_test.php (limited to 'tests') diff --git a/tests/functions/validate_hex_colour_test.php b/tests/functions/validate_hex_colour_test.php new file mode 100644 index 0000000000..812ebe5eeb --- /dev/null +++ b/tests/functions/validate_hex_colour_test.php @@ -0,0 +1,121 @@ +negative_match_data(), + $this->optional_only_data() + ); + } + + public function nonstrict_positive_match_data() + { + return array_merge( + $this->positive_match_data(), + $this->optional_only_data() + ); + } + + /** + * @dataProvider positive_match_data + */ + public function test_strict_positive_match($input) + { + $this->assertFalse( + phpbb_validate_hex_colour($input, false), + "Failed asserting that $input passes as a valid hex colour." + ); + } + + /** + * @dataProvider strict_negative_match_data + */ + public function test_strict_negative_match($input) + { + $this->assertSame( + 'WRONG_DATA', + phpbb_validate_hex_colour($input, false), + "Failed asserting that $input does not pass as a valid hex colour." + ); + } + + /** + * @dataProvider nonstrict_positive_match_data + */ + public function test_nonstrict_positive_match($input) + { + $this->assertFalse( + phpbb_validate_hex_colour($input, true), + "Failed asserting that $input passes as a valid or optional hex colour." + ); + } + + /** + * @dataProvider negative_match_data + */ + public function test_nonstrict_negative_match($input) + { + $this->assertSame( + 'WRONG_DATA', + phpbb_validate_hex_colour($input, true), + "Failed asserting that $input does not pass as a valid or optional hex colour." + ); + } +} -- cgit v1.2.1 From 3faae5c98cfe9d3b6245a892808aee19bc9c1fcc Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Sun, 26 May 2013 17:55:23 +0200 Subject: [ticket/11538] Cut functional tests down a bit as these are more expensive. PHPBB3-11538 --- tests/functional/common_groups_test.php | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) (limited to 'tests') diff --git a/tests/functional/common_groups_test.php b/tests/functional/common_groups_test.php index 02a538d46e..7ccd78421e 100644 --- a/tests/functional/common_groups_test.php +++ b/tests/functional/common_groups_test.php @@ -17,21 +17,11 @@ abstract class phpbb_functional_common_groups_test extends phpbb_functional_test public function groups_manage_test_data() { return array( - array('#AA0000', 'WRONG_DATA_COLOUR'), - array('AA0000', 'GROUP_UPDATED'), - array('AA0000v', 'WRONG_DATA_COLOUR'), - array('AA00000', 'WRONG_DATA_COLOUR'), - array('vAA0000', 'WRONG_DATA_COLOUR'), - array('AAG000','WRONG_DATA_COLOUR'), - array('a00', 'GROUP_UPDATED'), - array('ag0', 'WRONG_DATA_COLOUR'), - array('#aa0', 'WRONG_DATA_COLOUR'), - array('AA0000 ', 'GROUP_UPDATED'), - array('AA0000 abf', 'WRONG_DATA_COLOUR'), - array('AA0000 AA0000', 'WRONG_DATA_COLOUR'), array('', 'GROUP_UPDATED'), - array('000', 'GROUP_UPDATED'), - array('000000', 'GROUP_UPDATED'), + array('aa0000', 'GROUP_UPDATED'), + + array('AAG000','WRONG_DATA_COLOUR'), + array('#AA0000', 'WRONG_DATA_COLOUR'), ); } -- cgit v1.2.1 From 8a13fff2aa16c656e3a39be374dded2211c37b38 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Mon, 27 May 2013 12:56:03 +0200 Subject: [ticket/11575] Correct test_cross_join() to test_order_lower(). This test does not do any cross joining, it only tests ORDER BY LOWER(...). PHPBB3-11575 --- tests/dbal/order_lower_test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/dbal/order_lower_test.php b/tests/dbal/order_lower_test.php index b50494d506..b07f1baa91 100644 --- a/tests/dbal/order_lower_test.php +++ b/tests/dbal/order_lower_test.php @@ -14,7 +14,7 @@ class phpbb_dbal_order_lower_test extends phpbb_database_test_case return $this->createXMLDataSet(dirname(__FILE__).'/fixtures/styles.xml'); } - public function test_cross_join() + public function test_order_lower() { $db = $this->new_dbal(); -- cgit v1.2.1 From 38022a6999c58b310bdad43021fa66195db7bf32 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Mon, 27 May 2013 15:25:48 +0200 Subject: [ticket/11576] MySQL unit tests: Enable STRICT_TRANS_TABLES and others. PHPBB3-11576 --- .../phpbb_database_test_connection_manager.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'tests') diff --git a/tests/test_framework/phpbb_database_test_connection_manager.php b/tests/test_framework/phpbb_database_test_connection_manager.php index af7e6b1144..bcd52b1794 100644 --- a/tests/test_framework/phpbb_database_test_connection_manager.php +++ b/tests/test_framework/phpbb_database_test_connection_manager.php @@ -148,6 +148,20 @@ class phpbb_database_test_connection_manager case 'mysql': case 'mysqli': $this->pdo->exec('SET NAMES utf8'); + + /* + * The phpBB MySQL drivers set the STRICT_ALL_TABLES and + * STRICT_TRANS_TABLES flags/modes, so as a minimum requirement + * we want to make sure those are set for the PDO side of the + * test suite. + * + * The TRADITIONAL flag implies STRICT_ALL_TABLES and + * STRICT_TRANS_TABLES as well as other useful strictness flags + * the phpBB MySQL driver does not set. + */ + $this->pdo->exec("SET SESSION sql_mode='TRADITIONAL'"); + break; + default: } } -- cgit v1.2.1 From c338dfcbf2cdd1dc0dce087270b0901cd099c954 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Mon, 27 May 2013 15:45:01 +0200 Subject: [ticket/11573] Honor MySQL STRICT_TRANS_TABLES in test_style_select. PHPBB3-11573 --- tests/functions/fixtures/style_select.xml | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'tests') diff --git a/tests/functions/fixtures/style_select.xml b/tests/functions/fixtures/style_select.xml index 12d6392ab5..ca95f94461 100644 --- a/tests/functions/fixtures/style_select.xml +++ b/tests/functions/fixtures/style_select.xml @@ -4,20 +4,24 @@ style_id style_name style_active + style_parent_tree 1 prosilver 1 + 2 subsilver2 1 + 3 zoo 0 + -- cgit v1.2.1 From 555f0529f2a256545d67208a2bd1af1adfb92c41 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Mon, 27 May 2013 15:47:19 +0200 Subject: [ticket/11573] Honor MySQL STRICT_TRANS_TABLES in phpbb_user_loader_test. PHPBB3-11573 --- tests/user/fixtures/user_loader.xml | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'tests') diff --git a/tests/user/fixtures/user_loader.xml b/tests/user/fixtures/user_loader.xml index 737376f326..1fed8b5838 100644 --- a/tests/user/fixtures/user_loader.xml +++ b/tests/user/fixtures/user_loader.xml @@ -2,22 +2,38 @@ user_id + user_permissionsusernameusername_clean + user_sig + user_occ + user_interests 1 + Guest guest + + + 2 + Admin admin + + + 3 + Test test + + +
-- cgit v1.2.1 From 5dcf028cf0791956be0a8cb5f8ea82d3cd91080a Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sun, 26 May 2013 21:12:32 +0200 Subject: [ticket/11568] Use Goutte Client to install the board for functional tests PHPBB3-11568 --- .../test_framework/phpbb_functional_test_case.php | 144 +++++++++++++++------ 1 file changed, 105 insertions(+), 39 deletions(-) (limited to 'tests') diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index b1352b247e..cd3133f3a0 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -17,6 +17,9 @@ class phpbb_functional_test_case extends phpbb_test_case protected $client; protected $root_url; + static protected $static_client; + static protected $static_root_url; + protected $cache = null; protected $db = null; @@ -77,6 +80,11 @@ class phpbb_functional_test_case extends phpbb_test_case return $this->client->request($method, $this->root_url . $path); } + static public function static_request($method, $path) + { + return self::$static_client->request($method, self::$static_root_url . $path); + } + // bootstrap, called after board is set up // once per test case class // test cases can override this @@ -148,28 +156,78 @@ class phpbb_functional_test_case extends phpbb_test_case } } - // begin data - $data = array(); + $cookieJar = new CookieJar; + self::$static_client = new Goutte\Client(array(), null, $cookieJar); - $data = array_merge($data, self::$config); + // Reset the curl handle because it is 0 at this point and not a valid + // resource + self::$static_client->getClient()->getCurlMulti()->reset(true); + self::$static_root_url = self::$config['phpbb_functional_url']; - $data = array_merge($data, array( + $parseURL = parse_url(self::$config['phpbb_functional_url']); + + $crawler = self::static_request('GET', 'install/index.php?mode=install'); + self::static_assert_response_success(); + self::assertContains('Welcome to Installation', $crawler->filter('#main')->text()); + $form = $crawler->selectButton('submit')->form(); + + $crawler = self::$static_client->submit($form); + self::static_assert_response_success(); + self::assertContains('Installation compatibility', $crawler->filter('#main')->text()); + $form = $crawler->selectButton('submit')->form(); + + $crawler = self::$static_client->submit($form); + self::static_assert_response_success(); + self::assertContains('Database configuration', $crawler->filter('#main')->text()); + $form = $crawler->selectButton('submit')->form(array( + // Installer uses 3.0-style dbms name + 'dbms' => str_replace('phpbb_db_driver_', '', self::$config['dbms']), + 'dbhost' => self::$config['dbhost'], + 'dbport' => self::$config['dbport'], + 'dbname' => self::$config['dbname'], + 'dbuser' => self::$config['dbuser'], + 'dbpasswd' => self::$config['dbpasswd'], + 'table_prefix' => self::$config['table_prefix'], + )); + + $crawler = self::$static_client->submit($form); + self::static_assert_response_success(); + self::assertContains('Successful connection', $crawler->filter('#main')->text()); + $form = $crawler->selectButton('submit')->form(); + + $crawler = self::$static_client->submit($form); + self::static_assert_response_success(); + self::assertContains('Administrator configuration', $crawler->filter('#main')->text()); + $form = $crawler->selectButton('submit')->form(array( 'default_lang' => 'en', 'admin_name' => 'admin', - 'admin_pass1' => 'admin', - 'admin_pass2' => 'admin', - 'board_email' => 'nobody@example.com', + 'admin_pass1' => 'adminadmin', + 'admin_pass2' => 'adminadmin', + 'board_email1' => 'nobody@example.com', + 'board_email2' => 'nobody@example.com', )); - $parseURL = parse_url(self::$config['phpbb_functional_url']); - - $data = array_merge($data, array( - 'email_enable' => false, - 'smtp_delivery' => false, - 'smtp_host' => '', - 'smtp_auth' => '', - 'smtp_user' => '', - 'smtp_pass' => '', + $crawler = self::$static_client->submit($form); + self::static_assert_response_success(); + self::assertContains('Tests passed', $crawler->filter('#main')->text()); + $form = $crawler->selectButton('submit')->form(); + + $crawler = self::$static_client->submit($form); + self::static_assert_response_success(); + self::assertContains('The configuration file has been written.', $crawler->filter('#main')->text()); + file_put_contents($phpbb_root_path . "config.$phpEx", phpbb_create_config_file_data(self::$config, self::$config['dbms'], array(), true, true)); + $form = $crawler->selectButton('submit')->form(); + + $crawler = self::$static_client->submit($form); + self::static_assert_response_success(); + self::assertContains('The settings on this page are only necessary to set if you know that you require something different from the default.', $crawler->filter('#main')->text()); + $form = $crawler->selectButton('submit')->form(array( + 'email_enable' => true, + 'smtp_delivery' => true, + 'smtp_host' => 'nxdomain.phpbb.com', + 'smtp_auth' => 'PLAIN', + 'smtp_user' => 'nxuser', + 'smtp_pass' => 'nxpass', 'cookie_secure' => false, 'force_server_vars' => false, 'server_protocol' => $parseURL['scheme'] . '://', @@ -177,26 +235,16 @@ class phpbb_functional_test_case extends phpbb_test_case 'server_port' => isset($parseURL['port']) ? (int) $parseURL['port'] : 80, 'script_path' => $parseURL['path'], )); - // end data - - $content = self::do_request('install'); - self::assertNotSame(false, $content); - self::assertContains('Welcome to Installation', $content); - - $content = self::do_request('create_table', $data); - self::assertNotSame(false, $content); - self::assertContains('The database tables used by phpBB', $content); - // 3.0 or 3.1 - self::assertContains('have been created and populated with some initial data.', $content); - - $content = self::do_request('config_file', $data); - self::assertNotSame(false, $content); - self::assertContains('Configuration file', $content); - file_put_contents($phpbb_root_path . "config.$phpEx", phpbb_create_config_file_data($data, self::$config['dbms'], array(), true, true)); - - $content = self::do_request('final', $data); - self::assertNotSame(false, $content); - self::assertContains('You have successfully installed', $content); + + $crawler = self::$static_client->submit($form); + self::static_assert_response_success(); + self::assertContains('The database tables used by phpBB', $crawler->filter('#main')->text()); + self::assertContains('have been created and populated with some initial data.', $crawler->filter('#main')->text()); + $form = $crawler->selectButton('submit')->form(); + + $crawler = self::$static_client->submit($form); + self::static_assert_response_success(); + self::assertContains('You have successfully installed', $crawler->text()); copy($phpbb_root_path . "config.$phpEx", $phpbb_root_path . "config_test.$phpEx"); } @@ -270,7 +318,7 @@ class phpbb_functional_test_case extends phpbb_test_case 'user_lang' => 'en', 'user_timezone' => 0, 'user_dateformat' => '', - 'user_password' => phpbb_hash($username), + 'user_password' => phpbb_hash($username . $username), ); return user_add($user_row); } @@ -283,7 +331,7 @@ class phpbb_functional_test_case extends phpbb_test_case $this->assertContains($this->lang('LOGIN_EXPLAIN_UCP'), $crawler->filter('html')->text()); $form = $crawler->selectButton($this->lang('LOGIN'))->form(); - $crawler = $this->client->submit($form, array('username' => $username, 'password' => $username)); + $crawler = $this->client->submit($form, array('username' => $username, 'password' => $username . $username)); $this->assert_response_success(); $this->assertContains($this->lang('LOGIN_REDIRECT'), $crawler->filter('html')->text()); @@ -323,7 +371,7 @@ class phpbb_functional_test_case extends phpbb_test_case { if (strpos($field, 'password_') === 0) { - $crawler = $this->client->submit($form, array('username' => $username, $field => $username)); + $crawler = $this->client->submit($form, array('username' => $username, $field => $username . $username)); $this->assert_response_success(); $this->assertContains($this->lang('LOGIN_ADMIN_SUCCESS'), $crawler->filter('html')->text()); @@ -397,4 +445,22 @@ class phpbb_functional_test_case extends phpbb_test_case $this->assertNotContains('Warning:', $content); $this->assertNotContains('[phpBB Debug]', $content); } + + /** + * Heuristic function to check that the response is success. + * + * When php decides to die with a fatal error, it still sends 200 OK + * status code. This assertion tries to catch that. + * + * @return null + */ + static public function static_assert_response_success() + { + self::assertEquals(200, self::$static_client->getResponse()->getStatus()); + $content = self::$static_client->getResponse()->getContent(); + self::assertNotContains('Fatal error:', $content); + self::assertNotContains('Notice:', $content); + //@todo: self::assertNotContains('Warning:', $content); + self::assertNotContains('[phpBB Debug]', $content); + } } -- cgit v1.2.1 From a3e5efc63483f06c6d66296adbd0538d59a05a21 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sun, 26 May 2013 21:16:49 +0200 Subject: [ticket/11568] Set client manually so we can increase the cURL timeout PHPBB3-11568 --- tests/test_framework/phpbb_functional_test_case.php | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'tests') diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index cd3133f3a0..b622c6e284 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -158,6 +158,13 @@ class phpbb_functional_test_case extends phpbb_test_case $cookieJar = new CookieJar; self::$static_client = new Goutte\Client(array(), null, $cookieJar); + // Set client manually so we can increase the cURL timeout + self::$static_client->setClient(new Guzzle\Http\Client('', array( + Guzzle\Http\Client::DISABLE_REDIRECTS => true, + 'curl.options' => array( + CURLOPT_TIMEOUT => 120 + ), + ))); // Reset the curl handle because it is 0 at this point and not a valid // resource -- cgit v1.2.1 From f25389f94a46bb63d8688be9eef699de9853b4fc Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sun, 26 May 2013 23:57:50 +0200 Subject: [ticket/11568] Any output before the doc type means there was an error Change is needed to allow "Warning:" in the HTML body PHPBB3-11568 --- tests/test_framework/phpbb_functional_test_case.php | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) (limited to 'tests') diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index b622c6e284..8a386d1db7 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -447,10 +447,9 @@ class phpbb_functional_test_case extends phpbb_test_case { $this->assertEquals(200, $this->client->getResponse()->getStatus()); $content = $this->client->getResponse()->getContent(); - $this->assertNotContains('Fatal error:', $content); - $this->assertNotContains('Notice:', $content); - $this->assertNotContains('Warning:', $content); - $this->assertNotContains('[phpBB Debug]', $content); + + // Any output before the doc type means there was an error + $this->assertEquals(0, strpos($content, 'getResponse()->getStatus()); $content = self::$static_client->getResponse()->getContent(); - self::assertNotContains('Fatal error:', $content); - self::assertNotContains('Notice:', $content); - //@todo: self::assertNotContains('Warning:', $content); - self::assertNotContains('[phpBB Debug]', $content); + + // Any output before the doc type means there was an error + self::assertEquals(0, strpos($content, ' Date: Mon, 27 May 2013 22:09:44 +0200 Subject: [ticket/11568] Only use a static version of the client PHPBB3-11568 --- .../test_framework/phpbb_functional_test_case.php | 119 +++++++++++---------- 1 file changed, 60 insertions(+), 59 deletions(-) (limited to 'tests') diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index 8a386d1db7..0d122604fd 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -14,11 +14,8 @@ require_once __DIR__ . '/../../phpBB/includes/cache.php'; class phpbb_functional_test_case extends phpbb_test_case { - protected $client; - protected $root_url; - - static protected $static_client; - static protected $static_root_url; + static protected $client; + static protected $root_url; protected $cache = null; protected $db = null; @@ -43,6 +40,7 @@ class phpbb_functional_test_case extends phpbb_test_case parent::setUpBeforeClass(); self::$config = phpbb_test_case_helpers::get_test_config(); + self::$root_url = self::$config['phpbb_functional_url']; if (!isset(self::$config['phpbb_functional_url'])) { @@ -63,11 +61,11 @@ class phpbb_functional_test_case extends phpbb_test_case $this->bootstrap(); $this->cookieJar = new CookieJar; - $this->client = new Goutte\Client(array(), null, $this->cookieJar); + self::$client = new Goutte\Client(array(), null, $this->cookieJar); // Reset the curl handle because it is 0 at this point and not a valid // resource - $this->client->getClient()->getCurlMulti()->reset(true); - $this->root_url = self::$config['phpbb_functional_url']; + self::$client->getClient()->getCurlMulti()->reset(true); + // Clear the language array so that things // that were added in other tests are gone $this->lang = array(); @@ -75,14 +73,45 @@ class phpbb_functional_test_case extends phpbb_test_case $this->purge_cache(); } - public function request($method, $path) + /** + * Perform a request to page + * + * @param string $method HTTP Method + * @param string $path Page path, relative from phpBB root path + * @param array $form_data An array of form field values + * @param bool $skip_assert_response_success Should we skip the basic response assertions? + * @return Symfony\Component\DomCrawler\Crawler + */ + static public function request($method, $path, $form_data = array(), $skip_assert_response_success = false) { - return $this->client->request($method, $this->root_url . $path); + $crawler = self::$client->request($method, self::$root_url . $path, $form_data); + + if (!$skip_assert_response_success) + { + self::assert_response_success(); + } + + return $crawler; } - static public function static_request($method, $path) + /** + * Submits a form + * + * @param Symfony\Component\DomCrawler\Form $form A Form instance + * @param array $values An array of form field values + * @param bool $skip_assert_response_success Should we skip the basic response assertions? + * @return Symfony\Component\DomCrawler\Crawler + */ + static public function submit(Symfony\Component\DomCrawler\Form $form, array $values = array(), $skip_assert_response_success = false) { - return self::$static_client->request($method, self::$static_root_url . $path); + $crawler = self::$client->submit($form, $values); + + if (!$skip_assert_response_success) + { + self::assert_response_success(); + } + + return $crawler; } // bootstrap, called after board is set up @@ -157,9 +186,9 @@ class phpbb_functional_test_case extends phpbb_test_case } $cookieJar = new CookieJar; - self::$static_client = new Goutte\Client(array(), null, $cookieJar); + self::$client = new Goutte\Client(array(), null, $cookieJar); // Set client manually so we can increase the cURL timeout - self::$static_client->setClient(new Guzzle\Http\Client('', array( + self::$client->setClient(new Guzzle\Http\Client('', array( Guzzle\Http\Client::DISABLE_REDIRECTS => true, 'curl.options' => array( CURLOPT_TIMEOUT => 120 @@ -168,23 +197,19 @@ class phpbb_functional_test_case extends phpbb_test_case // Reset the curl handle because it is 0 at this point and not a valid // resource - self::$static_client->getClient()->getCurlMulti()->reset(true); - self::$static_root_url = self::$config['phpbb_functional_url']; + self::$client->getClient()->getCurlMulti()->reset(true); $parseURL = parse_url(self::$config['phpbb_functional_url']); - $crawler = self::static_request('GET', 'install/index.php?mode=install'); - self::static_assert_response_success(); + $crawler = self::request('GET', 'install/index.php?mode=install'); self::assertContains('Welcome to Installation', $crawler->filter('#main')->text()); $form = $crawler->selectButton('submit')->form(); - $crawler = self::$static_client->submit($form); - self::static_assert_response_success(); + $crawler = self::submit($form); self::assertContains('Installation compatibility', $crawler->filter('#main')->text()); $form = $crawler->selectButton('submit')->form(); - $crawler = self::$static_client->submit($form); - self::static_assert_response_success(); + $crawler = self::submit($form); self::assertContains('Database configuration', $crawler->filter('#main')->text()); $form = $crawler->selectButton('submit')->form(array( // Installer uses 3.0-style dbms name @@ -197,13 +222,11 @@ class phpbb_functional_test_case extends phpbb_test_case 'table_prefix' => self::$config['table_prefix'], )); - $crawler = self::$static_client->submit($form); - self::static_assert_response_success(); + $crawler = self::submit($form); self::assertContains('Successful connection', $crawler->filter('#main')->text()); $form = $crawler->selectButton('submit')->form(); - $crawler = self::$static_client->submit($form); - self::static_assert_response_success(); + $crawler = self::submit($form); self::assertContains('Administrator configuration', $crawler->filter('#main')->text()); $form = $crawler->selectButton('submit')->form(array( 'default_lang' => 'en', @@ -214,19 +237,16 @@ class phpbb_functional_test_case extends phpbb_test_case 'board_email2' => 'nobody@example.com', )); - $crawler = self::$static_client->submit($form); - self::static_assert_response_success(); + $crawler = self::submit($form); self::assertContains('Tests passed', $crawler->filter('#main')->text()); $form = $crawler->selectButton('submit')->form(); - $crawler = self::$static_client->submit($form); - self::static_assert_response_success(); + $crawler = self::submit($form); self::assertContains('The configuration file has been written.', $crawler->filter('#main')->text()); file_put_contents($phpbb_root_path . "config.$phpEx", phpbb_create_config_file_data(self::$config, self::$config['dbms'], array(), true, true)); $form = $crawler->selectButton('submit')->form(); - $crawler = self::$static_client->submit($form); - self::static_assert_response_success(); + $crawler = self::submit($form); self::assertContains('The settings on this page are only necessary to set if you know that you require something different from the default.', $crawler->filter('#main')->text()); $form = $crawler->selectButton('submit')->form(array( 'email_enable' => true, @@ -243,14 +263,12 @@ class phpbb_functional_test_case extends phpbb_test_case 'script_path' => $parseURL['path'], )); - $crawler = self::$static_client->submit($form); - self::static_assert_response_success(); + $crawler = self::submit($form); self::assertContains('The database tables used by phpBB', $crawler->filter('#main')->text()); self::assertContains('have been created and populated with some initial data.', $crawler->filter('#main')->text()); $form = $crawler->selectButton('submit')->form(); - $crawler = self::$static_client->submit($form); - self::static_assert_response_success(); + $crawler = self::submit($form); self::assertContains('You have successfully installed', $crawler->text()); copy($phpbb_root_path . "config.$phpEx", $phpbb_root_path . "config_test.$phpEx"); } @@ -338,7 +356,7 @@ class phpbb_functional_test_case extends phpbb_test_case $this->assertContains($this->lang('LOGIN_EXPLAIN_UCP'), $crawler->filter('html')->text()); $form = $crawler->selectButton($this->lang('LOGIN'))->form(); - $crawler = $this->client->submit($form, array('username' => $username, 'password' => $username . $username)); + $crawler = $this->submit($form, array('username' => $username, 'password' => $username . $username)); $this->assert_response_success(); $this->assertContains($this->lang('LOGIN_REDIRECT'), $crawler->filter('html')->text()); @@ -378,7 +396,7 @@ class phpbb_functional_test_case extends phpbb_test_case { if (strpos($field, 'password_') === 0) { - $crawler = $this->client->submit($form, array('username' => $username, $field => $username . $username)); + $crawler = $this->submit($form, array('username' => $username, $field => $username . $username)); $this->assert_response_success(); $this->assertContains($this->lang('LOGIN_ADMIN_SUCCESS'), $crawler->filter('html')->text()); @@ -443,29 +461,12 @@ class phpbb_functional_test_case extends phpbb_test_case * * @return null */ - public function assert_response_success() - { - $this->assertEquals(200, $this->client->getResponse()->getStatus()); - $content = $this->client->getResponse()->getContent(); - - // Any output before the doc type means there was an error - $this->assertEquals(0, strpos($content, 'getResponse()->getStatus()); - $content = self::$static_client->getResponse()->getContent(); + self::assertEquals(200, self::$client->getResponse()->getStatus()); + $content = self::$client->getResponse()->getContent(); // Any output before the doc type means there was an error - self::assertEquals(0, strpos($content, ' Date: Mon, 27 May 2013 22:12:50 +0200 Subject: [ticket/11568] Remove manual calls to assert_response_success() PHPBB3-11568 --- tests/functional/auth_test.php | 4 ---- tests/functional/browse_test.php | 3 --- tests/functional/posting_test.php | 5 +---- 3 files changed, 1 insertion(+), 11 deletions(-) (limited to 'tests') diff --git a/tests/functional/auth_test.php b/tests/functional/auth_test.php index 662b1bd38b..a0c909e798 100644 --- a/tests/functional/auth_test.php +++ b/tests/functional/auth_test.php @@ -18,7 +18,6 @@ class phpbb_functional_auth_test extends phpbb_functional_test_case // check for logout link $crawler = $this->request('GET', 'index.php'); - $this->assert_response_success(); $this->assertContains($this->lang('LOGOUT_USER', 'admin'), $crawler->filter('.navbar')->text()); } @@ -27,7 +26,6 @@ class phpbb_functional_auth_test extends phpbb_functional_test_case $this->create_user('anothertestuser'); $this->login('anothertestuser'); $crawler = $this->request('GET', 'index.php'); - $this->assert_response_success(); $this->assertContains('anothertestuser', $crawler->filter('.icon-logout')->text()); } @@ -41,12 +39,10 @@ class phpbb_functional_auth_test extends phpbb_functional_test_case // logout $crawler = $this->request('GET', 'ucp.php?sid=' . $this->sid . '&mode=logout'); - $this->assert_response_success(); $this->assertContains($this->lang('LOGOUT_REDIRECT'), $crawler->filter('#message')->text()); // look for a register link, which should be visible only when logged out $crawler = $this->request('GET', 'index.php'); - $this->assert_response_success(); $this->assertContains($this->lang('REGISTER'), $crawler->filter('.navbar')->text()); } } diff --git a/tests/functional/browse_test.php b/tests/functional/browse_test.php index b5748059c6..26c18c4c1f 100644 --- a/tests/functional/browse_test.php +++ b/tests/functional/browse_test.php @@ -15,21 +15,18 @@ class phpbb_functional_browse_test extends phpbb_functional_test_case public function test_index() { $crawler = $this->request('GET', 'index.php'); - $this->assert_response_success(); $this->assertGreaterThan(0, $crawler->filter('.topiclist')->count()); } public function test_viewforum() { $crawler = $this->request('GET', 'viewforum.php?f=2'); - $this->assert_response_success(); $this->assertGreaterThan(0, $crawler->filter('.topiclist')->count()); } public function test_viewtopic() { $crawler = $this->request('GET', 'viewtopic.php?t=1'); - $this->assert_response_success(); $this->assertGreaterThan(0, $crawler->filter('.postbody')->count()); } } diff --git a/tests/functional/posting_test.php b/tests/functional/posting_test.php index d05207edf0..5cf7559245 100644 --- a/tests/functional/posting_test.php +++ b/tests/functional/posting_test.php @@ -30,7 +30,6 @@ class phpbb_functional_posting_test extends phpbb_functional_test_case // Test quoting a message $crawler = $this->request('GET', "posting.php?mode=quote&f=2&t={$post2['topic_id']}&p={$post2['post_id']}&sid={$this->sid}"); - $this->assert_response_success(); $this->assertContains('This is a test post posted by the testing framework.', $crawler->filter('html')->text()); } @@ -95,7 +94,6 @@ class phpbb_functional_posting_test extends phpbb_functional_test_case $this->add_lang('posting'); $crawler = $this->request('GET', $posting_url); - $this->assert_response_success(); $this->assertContains($this->lang($posting_contains), $crawler->filter('html')->text()); $hidden_fields = array( @@ -119,8 +117,7 @@ class phpbb_functional_posting_test extends phpbb_functional_test_case // I use a request because the form submission method does not allow you to send data that is not // contained in one of the actual form fields that the browser sees (i.e. it ignores "hidden" inputs) // Instead, I send it as a request with the submit button "post" set to true. - $crawler = $this->client->request('POST', $posting_url, $form_data); - $this->assert_response_success(); + $crawler = $this->request('POST', $posting_url, $form_data); $this->assertContains($this->lang('POST_STORED'), $crawler->filter('html')->text()); $url = $crawler->selectLink($this->lang('VIEW_MESSAGE', '', ''))->link()->getUri(); -- cgit v1.2.1 From da98866c24572031b2deda4e8a50cac07efdef5d Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Mon, 27 May 2013 22:25:25 +0200 Subject: [ticket/11568] Make CookieJar static aswell PHPBB3-11568 --- tests/test_framework/phpbb_functional_test_case.php | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'tests') diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index 0d122604fd..1725a45e38 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -15,6 +15,7 @@ require_once __DIR__ . '/../../phpBB/includes/cache.php'; class phpbb_functional_test_case extends phpbb_test_case { static protected $client; + static protected $cookieJar; static protected $root_url; protected $cache = null; @@ -60,8 +61,8 @@ class phpbb_functional_test_case extends phpbb_test_case $this->bootstrap(); - $this->cookieJar = new CookieJar; - self::$client = new Goutte\Client(array(), null, $this->cookieJar); + self::$cookieJar = new CookieJar; + self::$client = new Goutte\Client(array(), null, self::$cookieJar); // Reset the curl handle because it is 0 at this point and not a valid // resource self::$client->getClient()->getCurlMulti()->reset(true); @@ -185,8 +186,8 @@ class phpbb_functional_test_case extends phpbb_test_case } } - $cookieJar = new CookieJar; - self::$client = new Goutte\Client(array(), null, $cookieJar); + self::$cookieJar = new CookieJar; + self::$client = new Goutte\Client(array(), null, self::$cookieJar); // Set client manually so we can increase the cURL timeout self::$client->setClient(new Guzzle\Http\Client('', array( Guzzle\Http\Client::DISABLE_REDIRECTS => true, @@ -360,7 +361,7 @@ class phpbb_functional_test_case extends phpbb_test_case $this->assert_response_success(); $this->assertContains($this->lang('LOGIN_REDIRECT'), $crawler->filter('html')->text()); - $cookies = $this->cookieJar->all(); + $cookies = self::$cookieJar->all(); // The session id is stored in a cookie that ends with _sid - we assume there is only one such cookie foreach ($cookies as $cookie); @@ -400,7 +401,7 @@ class phpbb_functional_test_case extends phpbb_test_case $this->assert_response_success(); $this->assertContains($this->lang('LOGIN_ADMIN_SUCCESS'), $crawler->filter('html')->text()); - $cookies = $this->cookieJar->all(); + $cookies = self::$cookieJar->all(); // The session id is stored in a cookie that ends with _sid - we assume there is only one such cookie foreach ($cookies as $cookie); -- cgit v1.2.1 From 9be57ec076eb1c819c6a6a51c4f2ba9f3e3c915d Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Mon, 27 May 2013 22:33:48 +0200 Subject: [ticket/11568] Fix common_groups_test.php form handling PHPBB3-11568 --- tests/functional/common_groups_test.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/functional/common_groups_test.php b/tests/functional/common_groups_test.php index 7ccd78421e..6e1f1afdce 100644 --- a/tests/functional/common_groups_test.php +++ b/tests/functional/common_groups_test.php @@ -36,10 +36,9 @@ abstract class phpbb_functional_common_groups_test extends phpbb_functional_test // Manage Administrators group $crawler = $this->request('GET', $this->get_url() . '&g=5&sid=' . $this->sid); - $this->assert_response_success(); $form = $crawler->selectButton($this->lang('SUBMIT'))->form(); $form['group_colour']->setValue($input); - $crawler = $this->client->submit($form); + $crawler = $this->submit($form); $this->assertContains($this->lang($expected), $crawler->text()); } } -- cgit v1.2.1 From 3d6620f0db5dbbf9b1f59ec865854a1dcd2e3179 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 28 May 2013 14:10:27 +0200 Subject: [ticket/11568] Trim the output to allow Tabs before INCLUDE overall_header PHPBB3-11568 --- tests/test_framework/phpbb_functional_test_case.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index 1725a45e38..4ebe1d2d17 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -468,6 +468,6 @@ class phpbb_functional_test_case extends phpbb_test_case $content = self::$client->getResponse()->getContent(); // Any output before the doc type means there was an error - self::assertStringStartsWith(' Date: Tue, 28 May 2013 14:38:28 +0200 Subject: [ticket/11568] Allow different status codes PHPBB3-11568 --- tests/test_framework/phpbb_functional_test_case.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index 4ebe1d2d17..e87f53caed 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -462,9 +462,9 @@ class phpbb_functional_test_case extends phpbb_test_case * * @return null */ - static public function assert_response_success() + static public function assert_response_success($status_code = 200) { - self::assertEquals(200, self::$client->getResponse()->getStatus()); + self::assertEquals($status_code, self::$client->getResponse()->getStatus()); $content = self::$client->getResponse()->getContent(); // Any output before the doc type means there was an error -- cgit v1.2.1 From e84fb0c6cacdd4da2542bb94e5994d1962930ca4 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 28 May 2013 14:47:24 +0200 Subject: [ticket/11568] Add method to get page content PHPBB3-11568 --- tests/test_framework/phpbb_functional_test_case.php | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'tests') diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index e87f53caed..63cbeb515a 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -115,6 +115,16 @@ class phpbb_functional_test_case extends phpbb_test_case return $crawler; } + /** + * Get Client Content + * + * @return string HTML page + */ + static public function get_content() + { + return self::$client->getResponse()->getContent(); + } + // bootstrap, called after board is set up // once per test case class // test cases can override this -- cgit v1.2.1 From 467c4d62c44a32a1a60bed2e2a2519b10cdebd33 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 28 May 2013 14:55:04 +0200 Subject: [ticket/develop/11568] Do not directly access $client from tests PHPBB3-11568 --- tests/functional/acp_permissions_test.php | 8 ++++---- tests/functional/extension_controller_test.php | 9 +++++---- tests/functional/extension_permission_lang_test.php | 2 +- tests/functional/fileupload_form_test.php | 2 +- tests/functional/forgot_password_test.php | 7 +------ tests/functional/metadata_manager_test.php | 2 +- 6 files changed, 13 insertions(+), 17 deletions(-) (limited to 'tests') diff --git a/tests/functional/acp_permissions_test.php b/tests/functional/acp_permissions_test.php index f7fd44fc89..2f27b68555 100644 --- a/tests/functional/acp_permissions_test.php +++ b/tests/functional/acp_permissions_test.php @@ -28,7 +28,7 @@ class phpbb_functional_acp_permissions_test extends phpbb_functional_test_case $crawler = $this->request('GET', 'adm/index.php?i=16&sid=' . $this->sid); $this->assert_response_success(); // these language strings are html - $this->assertContains($this->lang('ACP_PERMISSIONS_EXPLAIN'), $this->client->getResponse()->getContent()); + $this->assertContains($this->lang('ACP_PERMISSIONS_EXPLAIN'), $this->get_content()); } public function test_select_user() @@ -36,13 +36,13 @@ class phpbb_functional_acp_permissions_test extends phpbb_functional_test_case // User permissions $crawler = $this->request('GET', 'adm/index.php?i=acp_permissions&icat=16&mode=setting_user_global&sid=' . $this->sid); $this->assert_response_success(); - $this->assertContains($this->lang('ACP_USERS_PERMISSIONS_EXPLAIN'), $this->client->getResponse()->getContent()); + $this->assertContains($this->lang('ACP_USERS_PERMISSIONS_EXPLAIN'), $this->get_content()); // Select admin $form = $crawler->selectButton($this->lang('SUBMIT'))->form(); $data = array('username[0]' => 'admin'); $form->setValues($data); - $crawler = $this->client->submit($form); + $crawler = $this->submit($form); $this->assert_response_success(); $this->assertContains($this->lang('ACL_SET'), $crawler->filter('h1')->eq(1)->text()); } @@ -114,7 +114,7 @@ class phpbb_functional_acp_permissions_test extends phpbb_functional_test_case // set to never $data = array("setting[$object_id][0][$permission]" => '0'); $form->setValues($data); - $crawler = $this->client->submit($form); + $crawler = $this->submit($form); $this->assert_response_success(); $this->assertContains($this->lang('AUTH_UPDATED'), $crawler->text()); diff --git a/tests/functional/extension_controller_test.php b/tests/functional/extension_controller_test.php index f28b321942..7f1decd5b5 100644 --- a/tests/functional/extension_controller_test.php +++ b/tests/functional/extension_controller_test.php @@ -115,8 +115,9 @@ class phpbb_functional_extension_controller_test extends phpbb_functional_test_c public function test_missing_argument() { $this->phpbb_extension_manager->enable('foo/bar'); - $crawler = $this->request('GET', 'app.php?controller=foo/baz'); - $this->assertEquals(500, $this->client->getResponse()->getStatus()); + $crawler = $this->request('GET', 'app.php?controller=foo/baz', false); + $this->request('GET', 'app.php?controller=foo/baz', false); + $this->assert_response_success(500); $this->assertContains('Missing value for argument #1: test in class phpbb_ext_foo_bar_controller:baz', $crawler->filter('body')->text()); $this->phpbb_extension_manager->purge('foo/bar'); } @@ -128,7 +129,7 @@ class phpbb_functional_extension_controller_test extends phpbb_functional_test_c { $this->phpbb_extension_manager->enable('foo/bar'); $crawler = $this->request('GET', 'app.php?controller=foo/exception'); - $this->assertEquals(500, $this->client->getResponse()->getStatus()); + $this->assert_response_success(500); $this->assertContains('Exception thrown from foo/exception route', $crawler->filter('body')->text()); $this->phpbb_extension_manager->purge('foo/bar'); } @@ -145,7 +146,7 @@ class phpbb_functional_extension_controller_test extends phpbb_functional_test_c public function test_error_ext_disabled_or_404() { $crawler = $this->request('GET', 'app.php?controller=does/not/exist'); - $this->assertEquals(404, $this->client->getResponse()->getStatus()); + $this->assert_response_success(404); $this->assertContains('No route found for "GET /does/not/exist"', $crawler->filter('body')->text()); } } diff --git a/tests/functional/extension_permission_lang_test.php b/tests/functional/extension_permission_lang_test.php index 26ec4d28a1..4e40b11560 100644 --- a/tests/functional/extension_permission_lang_test.php +++ b/tests/functional/extension_permission_lang_test.php @@ -106,7 +106,7 @@ class phpbb_functional_extension_permission_lang_test extends phpbb_functional_t $form = $crawler->selectButton($this->lang('SUBMIT'))->form(); $data = array('username[0]' => 'admin'); $form->setValues($data); - $crawler = $this->client->submit($form); + $crawler = $this->submit($form); $this->assert_response_success(); // language from language/en/acp/permissions_phpbb.php diff --git a/tests/functional/fileupload_form_test.php b/tests/functional/fileupload_form_test.php index b663c89e95..ec2296d6f2 100644 --- a/tests/functional/fileupload_form_test.php +++ b/tests/functional/fileupload_form_test.php @@ -68,7 +68,7 @@ class phpbb_functional_fileupload_form_test extends phpbb_functional_test_case $crawler = $this->upload_file('valid.jpg', 'image/jpeg'); $this->assert_response_success(); // ensure there was no error message rendered - $this->assertNotContains('

' . $this->lang('INFORMATION') . '

', $this->client->getResponse()->getContent()); + $this->assertNotContains('

' . $this->lang('INFORMATION') . '

', $this->get_content()); $this->assertContains($this->lang('POSTED_ATTACHMENTS'), $crawler->filter('#postform h3')->eq(1)->text()); } } diff --git a/tests/functional/forgot_password_test.php b/tests/functional/forgot_password_test.php index bfb4616d64..7c5f27c07e 100644 --- a/tests/functional/forgot_password_test.php +++ b/tests/functional/forgot_password_test.php @@ -27,18 +27,13 @@ class phpbb_functional_forgot_password_test extends phpbb_functional_test_case $this->admin_login(); $this->add_lang('ucp'); $crawler = $this->request('GET', 'adm/index.php?sid=' . $this->sid . '&i=acp_board&mode=security'); - $this->assertEquals(200, $this->client->getResponse()->getStatus()); - $content = $this->client->getResponse()->getContent(); - $this->assertNotContains('Fatal error:', $content); - $this->assertNotContains('Notice:', $content); - $this->assertNotContains('[phpBB Debug]', $content); $form = $crawler->selectButton('Submit')->form(); $values = $form->getValues(); $values["config[allow_password_reset]"] = 0; $form->setValues($values); - $crawler = $this->client->submit($form); + $crawler = $this->submit($form); $this->logout(); diff --git a/tests/functional/metadata_manager_test.php b/tests/functional/metadata_manager_test.php index 0125886e04..fa668b3cb5 100644 --- a/tests/functional/metadata_manager_test.php +++ b/tests/functional/metadata_manager_test.php @@ -97,7 +97,7 @@ class phpbb_functional_metadata_manager_test extends phpbb_functional_test_case // Details should be html escaped // However, text() only returns the displayed text, so HTML Special Chars are decoded. // So we test this directly on the content of the response. - $this->assertContains('

>=5.3

', $this->client->getResponse()->getContent()); + $this->assertContains('

>=5.3

', $this->get_content()); } public function test_extensions_details_notexists() -- cgit v1.2.1 From f1523944a048e22207d6f200c6d152ecb9fdc136 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 28 May 2013 14:58:40 +0200 Subject: [ticket/develop/11568] Remove unneccessary calls to assert_response_success() PHPBB3-11568 --- tests/functional/acp_permissions_test.php | 5 ----- tests/functional/auth_test.php | 1 - tests/functional/extension_controller_test.php | 6 ++---- tests/functional/extension_permission_lang_test.php | 2 -- tests/functional/fileupload_form_test.php | 1 - tests/functional/forgot_password_test.php | 2 -- tests/functional/memberlist_test.php | 6 ------ tests/functional/metadata_manager_test.php | 4 ---- tests/functional/notification_test.php | 1 - 9 files changed, 2 insertions(+), 26 deletions(-) (limited to 'tests') diff --git a/tests/functional/acp_permissions_test.php b/tests/functional/acp_permissions_test.php index 2f27b68555..3d91242df6 100644 --- a/tests/functional/acp_permissions_test.php +++ b/tests/functional/acp_permissions_test.php @@ -26,7 +26,6 @@ class phpbb_functional_acp_permissions_test extends phpbb_functional_test_case // Permissions tab // XXX hardcoded id $crawler = $this->request('GET', 'adm/index.php?i=16&sid=' . $this->sid); - $this->assert_response_success(); // these language strings are html $this->assertContains($this->lang('ACP_PERMISSIONS_EXPLAIN'), $this->get_content()); } @@ -35,7 +34,6 @@ class phpbb_functional_acp_permissions_test extends phpbb_functional_test_case { // User permissions $crawler = $this->request('GET', 'adm/index.php?i=acp_permissions&icat=16&mode=setting_user_global&sid=' . $this->sid); - $this->assert_response_success(); $this->assertContains($this->lang('ACP_USERS_PERMISSIONS_EXPLAIN'), $this->get_content()); // Select admin @@ -43,7 +41,6 @@ class phpbb_functional_acp_permissions_test extends phpbb_functional_test_case $data = array('username[0]' => 'admin'); $form->setValues($data); $crawler = $this->submit($form); - $this->assert_response_success(); $this->assertContains($this->lang('ACL_SET'), $crawler->filter('h1')->eq(1)->text()); } @@ -92,7 +89,6 @@ class phpbb_functional_acp_permissions_test extends phpbb_functional_test_case { // Get the form $crawler = $this->request('GET', "adm/index.php?i=acp_permissions&icat=16&mode=$mode&${object_name}[0]=$object_id&type=$permission_type&sid=" . $this->sid); - $this->assert_response_success(); $this->assertContains($this->lang('ACL_SET'), $crawler->filter('h1')->eq(1)->text()); // XXX globals for phpbb_auth, refactor it later @@ -115,7 +111,6 @@ class phpbb_functional_acp_permissions_test extends phpbb_functional_test_case $data = array("setting[$object_id][0][$permission]" => '0'); $form->setValues($data); $crawler = $this->submit($form); - $this->assert_response_success(); $this->assertContains($this->lang('AUTH_UPDATED'), $crawler->text()); // check acl again diff --git a/tests/functional/auth_test.php b/tests/functional/auth_test.php index 8359bbe8ea..06dc26dfeb 100644 --- a/tests/functional/auth_test.php +++ b/tests/functional/auth_test.php @@ -53,7 +53,6 @@ class phpbb_functional_auth_test extends phpbb_functional_test_case // check that we are logged in $crawler = $this->request('GET', 'adm/index.php?sid=' . $this->sid); - $this->assert_response_success(); $this->assertContains($this->lang('ADMIN_PANEL'), $crawler->filter('h1')->text()); } } diff --git a/tests/functional/extension_controller_test.php b/tests/functional/extension_controller_test.php index 7f1decd5b5..1755843398 100644 --- a/tests/functional/extension_controller_test.php +++ b/tests/functional/extension_controller_test.php @@ -91,7 +91,6 @@ class phpbb_functional_extension_controller_test extends phpbb_functional_test_c { $this->phpbb_extension_manager->enable('foo/bar'); $crawler = $this->request('GET', 'app.php?controller=foo/bar'); - $this->assert_response_success(); $this->assertContains("foo/bar controller handle() method", $crawler->filter('body')->text()); $this->phpbb_extension_manager->purge('foo/bar'); } @@ -103,7 +102,6 @@ class phpbb_functional_extension_controller_test extends phpbb_functional_test_c { $this->phpbb_extension_manager->enable('foo/bar'); $crawler = $this->request('GET', 'app.php?controller=foo/template'); - $this->assert_response_success(); $this->assertContains("I am a variable", $crawler->filter('#content')->text()); $this->phpbb_extension_manager->purge('foo/bar'); } @@ -128,7 +126,7 @@ class phpbb_functional_extension_controller_test extends phpbb_functional_test_c public function test_exception_should_result_in_500_status_code() { $this->phpbb_extension_manager->enable('foo/bar'); - $crawler = $this->request('GET', 'app.php?controller=foo/exception'); + $crawler = $this->request('GET', 'app.php?controller=foo/exception', false); $this->assert_response_success(500); $this->assertContains('Exception thrown from foo/exception route', $crawler->filter('body')->text()); $this->phpbb_extension_manager->purge('foo/bar'); @@ -145,7 +143,7 @@ class phpbb_functional_extension_controller_test extends phpbb_functional_test_c */ public function test_error_ext_disabled_or_404() { - $crawler = $this->request('GET', 'app.php?controller=does/not/exist'); + $crawler = $this->request('GET', 'app.php?controller=does/not/exist', false); $this->assert_response_success(404); $this->assertContains('No route found for "GET /does/not/exist"', $crawler->filter('body')->text()); } diff --git a/tests/functional/extension_permission_lang_test.php b/tests/functional/extension_permission_lang_test.php index 4e40b11560..c1ceae382d 100644 --- a/tests/functional/extension_permission_lang_test.php +++ b/tests/functional/extension_permission_lang_test.php @@ -100,14 +100,12 @@ class phpbb_functional_extension_permission_lang_test extends phpbb_functional_t // User permissions $crawler = $this->request('GET', 'adm/index.php?i=acp_permissions&icat=16&mode=setting_user_global&sid=' . $this->sid); - $this->assert_response_success(); // Select admin $form = $crawler->selectButton($this->lang('SUBMIT'))->form(); $data = array('username[0]' => 'admin'); $form->setValues($data); $crawler = $this->submit($form); - $this->assert_response_success(); // language from language/en/acp/permissions_phpbb.php $this->assertContains('Can attach files', $crawler->filter('body')->text()); diff --git a/tests/functional/fileupload_form_test.php b/tests/functional/fileupload_form_test.php index ec2296d6f2..2abea86077 100644 --- a/tests/functional/fileupload_form_test.php +++ b/tests/functional/fileupload_form_test.php @@ -66,7 +66,6 @@ class phpbb_functional_fileupload_form_test extends phpbb_functional_test_case { $this->markTestIncomplete('Test fails intermittently.'); $crawler = $this->upload_file('valid.jpg', 'image/jpeg'); - $this->assert_response_success(); // ensure there was no error message rendered $this->assertNotContains('

' . $this->lang('INFORMATION') . '

', $this->get_content()); $this->assertContains($this->lang('POSTED_ATTACHMENTS'), $crawler->filter('#postform h3')->eq(1)->text()); diff --git a/tests/functional/forgot_password_test.php b/tests/functional/forgot_password_test.php index 7c5f27c07e..65d07672cf 100644 --- a/tests/functional/forgot_password_test.php +++ b/tests/functional/forgot_password_test.php @@ -17,7 +17,6 @@ class phpbb_functional_forgot_password_test extends phpbb_functional_test_case global $config; $this->add_lang('ucp'); $crawler = $this->request('GET', 'ucp.php?mode=sendpassword'); - $this->assert_response_success(); $this->assertEquals($this->lang('SEND_PASSWORD'), $crawler->filter('h2')->text()); } @@ -38,7 +37,6 @@ class phpbb_functional_forgot_password_test extends phpbb_functional_test_case $this->logout(); $crawler = $this->request('GET', 'ucp.php?mode=sendpassword'); - $this->assert_response_success(); $this->assertContains($this->lang('UCP_PASSWORD_RESET_DISABLED', '', ''), $crawler->text()); } diff --git a/tests/functional/memberlist_test.php b/tests/functional/memberlist_test.php index 92ede8bd04..ef3c9b3298 100644 --- a/tests/functional/memberlist_test.php +++ b/tests/functional/memberlist_test.php @@ -18,17 +18,14 @@ class phpbb_functional_memberlist_test extends phpbb_functional_test_case // logs in as admin $this->login(); $crawler = $this->request('GET', 'memberlist.php?sid=' . $this->sid); - $this->assert_response_success(); $this->assertContains('memberlist-test-user', $crawler->text()); // restrict by first character $crawler = $this->request('GET', 'memberlist.php?first_char=m&sid=' . $this->sid); - $this->assert_response_success(); $this->assertContains('memberlist-test-user', $crawler->text()); // make sure results for wrong character are not returned $crawler = $this->request('GET', 'memberlist.php?first_char=a&sid=' . $this->sid); - $this->assert_response_success(); $this->assertNotContains('memberlist-test-user', $crawler->text()); } @@ -37,15 +34,12 @@ class phpbb_functional_memberlist_test extends phpbb_functional_test_case $this->login(); // XXX hardcoded user id $crawler = $this->request('GET', 'memberlist.php?mode=viewprofile&u=2&sid=' . $this->sid); - $this->assert_response_success(); $this->assertContains('admin', $crawler->filter('h2')->text()); } protected function get_memberlist_leaders_table_crawler() { $crawler = $this->request('GET', 'memberlist.php?mode=leaders&sid=' . $this->sid); - $this->assert_response_success(); - return $crawler->filter('.forumbg-table'); } diff --git a/tests/functional/metadata_manager_test.php b/tests/functional/metadata_manager_test.php index fa668b3cb5..cbc1c76ef8 100644 --- a/tests/functional/metadata_manager_test.php +++ b/tests/functional/metadata_manager_test.php @@ -76,8 +76,6 @@ class phpbb_functional_metadata_manager_test extends phpbb_functional_test_case public function test_extensions_list() { $crawler = $this->request('GET', 'adm/index.php?i=acp_extensions&mode=main&sid=' . $this->sid); - $this->assert_response_success(); - $this->assertContains($this->lang('EXTENSIONS_EXPLAIN'), $crawler->filter('#main')->text()); $this->assertContains('phpBB 3.1 Extension Testing', $crawler->filter('#main')->text()); $this->assertContains('Details', $crawler->filter('#main')->text()); @@ -86,7 +84,6 @@ class phpbb_functional_metadata_manager_test extends phpbb_functional_test_case public function test_extensions_details() { $crawler = $this->request('GET', 'adm/index.php?i=acp_extensions&mode=main&action=details&ext_name=foo%2Fbar&sid=' . $this->sid); - $this->assert_response_success(); // Test whether the details are displayed $this->assertContains($this->lang('CLEAN_NAME'), $crawler->filter('#main')->text()); @@ -103,7 +100,6 @@ class phpbb_functional_metadata_manager_test extends phpbb_functional_test_case public function test_extensions_details_notexists() { $crawler = $this->request('GET', 'adm/index.php?i=acp_extensions&mode=main&action=details&ext_name=not%2Fexists&sid=' . $this->sid); - $this->assert_response_success(); // Error message because the files do not exist $this->assertContains('The required file does not exist:', $crawler->filter('#main')->text()); diff --git a/tests/functional/notification_test.php b/tests/functional/notification_test.php index fa6513a0ba..ad4f3acdc2 100644 --- a/tests/functional/notification_test.php +++ b/tests/functional/notification_test.php @@ -41,7 +41,6 @@ class phpbb_functional_notification_test extends phpbb_functional_test_case { $this->login(); $crawler = $this->request('GET', 'ucp.php?i=ucp_notifications&mode=notification_options'); - $this->assert_response_success(); $cplist = $crawler->filter('.table1'); if ($expected_status) -- cgit v1.2.1 From 3d625ab0cf9fe8d1869fbdd66a4602553bb744d4 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Wed, 29 May 2013 18:24:54 +0200 Subject: [ticket/11579] Add basic set of unit tests for validate_data() This currently includes tests for the string, num, date, match, and language iso validation functions. PHPBB3-11579 --- tests/functions/validate_data_test.php | 252 +++++++++++++++++++++++++++++++++ 1 file changed, 252 insertions(+) create mode 100644 tests/functions/validate_data_test.php (limited to 'tests') diff --git a/tests/functions/validate_data_test.php b/tests/functions/validate_data_test.php new file mode 100644 index 0000000000..6a429a5529 --- /dev/null +++ b/tests/functions/validate_data_test.php @@ -0,0 +1,252 @@ +createXMLDataSet(dirname(__FILE__) . '/fixtures/language_select.xml'); + } + + /** + * Test provided input data with supplied checks and compare to expected + * results + * + * @param array $input Input data with specific array keys that need to + * be matched by the ones in the other 2 params + * @param array $validate_check Array containing validate_data check + * settings, i.e. array('foobar' => array('string')) + * @param array $expected Array containing the expected results. Either + * an array containing the error message or the an empty + * array if input is correct + */ + public function validate_data_check($input, $validate_check, $expected) + { + foreach ($input as $key => $data) + { + $this->assertEquals($expected[$key], validate_data(array($data), array($validate_check[$key]))); + } + } + + /* + * Types to test + * - string: + * empty + optional = true --> good + * empty + optional = false --> good (min = 0) + * 'foobar' --> good + * 'foobar' + optional = false|true + min = 2 + max = 6 --> good + * 'foobar' + " + min = 7 + max = 9 --> TOO_SHORT + * 'foobar' + " + min = 2 + max = 5 --> TOO_LONG + * '' + optional = false + min = 1 + max = 6 --> TOO_SHORT + * '' + optional = true + min = 1 + max = 6 --> good + */ + public function test_validate_string() + { + $this->validate_data_check(array( + 'empty_opt' => '', + 'empty' => '', + 'foo' => 'foobar', + 'foo_minmax_correct' => 'foobar', + 'foo_minmax_short' => 'foobar', + 'foo_minmax_long' => 'foobar', + 'empty_short' => '', + 'empty_length_opt' => '', + ), + array( + 'empty_opt' => array('string', true), + 'empty' => array('string'), + 'foo' => array('string'), + 'foo_minmax_correct' => array('string', false, 2, 6), + 'foo_minmax_short' => array('string', false, 7, 9), + 'foo_minmax_long' => array('string', false, 2, 5), + 'empty_short' => array('string', false, 1, 6), + 'empty_length_opt' => array('string', true, 1, 6), + ), + array( + 'empty_opt' => array(), + 'empty' => array(), + 'foo' => array(), + 'foo_minmax_correct' => array(), + 'foo_minmax_short' => array('TOO_SHORT'), + 'foo_minmax_long' => array('TOO_LONG'), + 'empty_short' => array('TOO_SHORT'), + 'empty_length_opt' => array(), + )); + } + + /* + * Types to test + * - num + * empty + optional = true|false --> good + * 0 --> good + * 5 + optional = false|true + min = 2 + max = 6 --> good + * 5 + optional = false|true + min = 7 + max = 10 --> TOO_SMALL + * 5 + optional = false|true + min = 2 + max = 3 --> TOO_LARGE + * 'foobar' --> should fail with WRONG_DATA_NUMERIC !!! + */ + public function test_validate_num() + { + $this->validate_data_check(array( + 'empty' => '', + 'zero' => 0, + 'five_minmax_correct' => 5, + 'five_minmax_short' => 5, + 'five_minmax_long' => 5, + 'string' => 'foobar', + ), + array( + 'empty' => array('num'), + 'zero' => array('num'), + 'five_minmax_correct' => array('num', false, 2, 6), + 'five_minmax_short' => array('num', false, 7, 10), + 'five_minmax_long' => array('num', false, 2, 3), + 'string' => array('num'), + ), + array( + 'empty' => array(), + 'zero' => array(), + 'five_minmax_correct' => array(), + 'five_minmax_short' => array('TOO_SMALL'), + 'five_minmax_long' => array('TOO_LARGE'), + 'string' => array(), + )); + } + + /* + * Types to test + * - date + * . '' --> invalid + * . '' + optional = true --> good + * . 17-06-1990 --> good + * . 05-05-1990 --> good + * . 17-12-1990 --> good + * . 01-01-0000 --> good!!! + * . 17-17-1990 --> invalid + * . 00-12-1990 --> invalid + * . 01-00-1990 --> invalid + */ + public function test_validate_date() + { + $this->validate_data_check(array( + 'empty' => '', + 'empty_opt' => '', + 'double_single' => '17-06-1990', + 'single_single' => '05-05-2009', + 'double_double' => '17-12-1990', + // Currently fails + //'zero_year' => '01-01-0000', + 'month_high' => '17-17-1990', + 'month_low' => '01-00-1990', + 'day_high' => '64-01-1990', + 'day_low' => '00-12-1990', + ), + array( + 'empty' => array('date'), + 'empty_opt' => array('date', true), + 'double_single' => array('date'), + 'single_single' => array('date'), + 'double_double' => array('date'), + // Currently fails + //'zero_year' => array('date'), + 'month_high' => array('date'), + 'month_low' => array('date'), + 'day_high' => array('date'), + 'day_low' => array('date'), + ), + array( + 'empty' => array('INVALID'), + 'empty_opt' => array(), + 'double_single' => array(), + 'single_single' => array(), + 'double_double' => array(), + // Currently fails + //'zero_year' => array(), + 'month_high' => array('INVALID'), + 'month_low' => array('INVALID'), + 'day_high' => array('INVALID'), + 'day_low' => array('INVALID'), + )); + } + + /* + * Types to test + * - match + * . empty + optional = true --> good + * . empty + empty match --> good + * . 'test' + optional = true|false + match = '/[a-z]/' --> good + * . 'test123' + optional = true|false + match = '/[a-z]/' --> WRONG_DATA_MATCH + */ + public function test_validate_match() + { + $this->validate_data_check(array( + 'empty_opt' => '', + 'empty_empty_match' => '', + 'foobar' => 'foobar', + 'foobar_fail' => 'foobar123', + ), + array( + 'empty_opt' => array('match', true, '/[a-z]$/'), + 'empty_empty_match' => array('match'), + 'foobar' => array('match', false, '/[a-z]$/'), + 'foobar_fail' => array('match', false, '/[a-z]$/'), + ), + array( + 'empty_opt' => array(), + 'empty_empty_match' => array(), + 'foobar' => array(), + 'foobar_fail' => array('WRONG_DATA'), + )); + } + + /* + * Types to test + * - language_iso_name + * . empty --> WRONG_DATA + * . 'en' --> good + * . 'cs' --> good + * . 'de' --> WRONG_DATA (won't exist) + */ + public function test_validate_lang_iso() + { + global $db; + + $db = $this->new_dbal(); + + $this->validate_data_check(array( + 'empty' => '', + 'en' => 'en', + 'cs' => 'cs', + 'de' => 'de', + ), + array( + 'empty' => array('language_iso_name'), + 'en' => array('language_iso_name'), + 'cs' => array('language_iso_name'), + 'de' => array('language_iso_name'), + ), + array( + 'empty' => array('WRONG_DATA'), + 'en' => array(), + 'cs' => array(), + 'de' => array('WRONG_DATA'), + )); + } +} -- cgit v1.2.1 From 4f6b12ae1d4b9ac681efff0651a0007fed6942b6 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 30 May 2013 10:49:13 +0200 Subject: [ticket/develop/11568] Remove php extension parameter We don't support that in 3.1 anymore PHPBB3-11568 --- tests/test_framework/phpbb_functional_test_case.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index 42d38255f7..e5e08df5fc 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -288,7 +288,7 @@ class phpbb_functional_test_case extends phpbb_test_case $crawler = self::submit($form); self::assertContains('The configuration file has been written.', $crawler->filter('#main')->text()); - file_put_contents($phpbb_root_path . "config.$phpEx", phpbb_create_config_file_data(self::$config, self::$config['dbms'], array(), true, true)); + file_put_contents($phpbb_root_path . "config.$phpEx", phpbb_create_config_file_data(self::$config, self::$config['dbms'], true, true)); $form = $crawler->selectButton('submit')->form(); $crawler = self::submit($form); -- cgit v1.2.1 From a36defb10fd8962d6073bfafd0cab1b7e15fbbda Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 30 May 2013 13:26:16 +0200 Subject: [ticket/develop/11568] Fix some more tests in 3.1 PHPBB3-11568 --- tests/functional/extension_controller_test.php | 6 +++--- tests/functional/fileupload_form_test.php | 2 +- tests/functional/fileupload_remote_test.php | 5 +++-- 3 files changed, 7 insertions(+), 6 deletions(-) (limited to 'tests') diff --git a/tests/functional/extension_controller_test.php b/tests/functional/extension_controller_test.php index 1755843398..3e9428e82c 100644 --- a/tests/functional/extension_controller_test.php +++ b/tests/functional/extension_controller_test.php @@ -113,7 +113,7 @@ class phpbb_functional_extension_controller_test extends phpbb_functional_test_c public function test_missing_argument() { $this->phpbb_extension_manager->enable('foo/bar'); - $crawler = $this->request('GET', 'app.php?controller=foo/baz', false); + $crawler = $this->request('GET', 'app.php?controller=foo/baz', array(), true); $this->request('GET', 'app.php?controller=foo/baz', false); $this->assert_response_success(500); $this->assertContains('Missing value for argument #1: test in class phpbb_ext_foo_bar_controller:baz', $crawler->filter('body')->text()); @@ -126,7 +126,7 @@ class phpbb_functional_extension_controller_test extends phpbb_functional_test_c public function test_exception_should_result_in_500_status_code() { $this->phpbb_extension_manager->enable('foo/bar'); - $crawler = $this->request('GET', 'app.php?controller=foo/exception', false); + $crawler = $this->request('GET', 'app.php?controller=foo/exception', array(), true); $this->assert_response_success(500); $this->assertContains('Exception thrown from foo/exception route', $crawler->filter('body')->text()); $this->phpbb_extension_manager->purge('foo/bar'); @@ -143,7 +143,7 @@ class phpbb_functional_extension_controller_test extends phpbb_functional_test_c */ public function test_error_ext_disabled_or_404() { - $crawler = $this->request('GET', 'app.php?controller=does/not/exist', false); + $crawler = $this->request('GET', 'app.php?controller=does/not/exist', array(), true); $this->assert_response_success(404); $this->assertContains('No route found for "GET /does/not/exist"', $crawler->filter('body')->text()); } diff --git a/tests/functional/fileupload_form_test.php b/tests/functional/fileupload_form_test.php index 2abea86077..998c402fa3 100644 --- a/tests/functional/fileupload_form_test.php +++ b/tests/functional/fileupload_form_test.php @@ -32,7 +32,7 @@ class phpbb_functional_fileupload_form_test extends phpbb_functional_test_case 'error' => UPLOAD_ERR_OK, ); - $crawler = $this->client->request( + $crawler = self::$client->request( 'POST', 'posting.php?mode=reply&f=2&t=1&sid=' . $this->sid, array('add_file' => $this->lang('ADD_FILE')), diff --git a/tests/functional/fileupload_remote_test.php b/tests/functional/fileupload_remote_test.php index 0deb79acf6..8e361ab77b 100644 --- a/tests/functional/fileupload_remote_test.php +++ b/tests/functional/fileupload_remote_test.php @@ -58,7 +58,7 @@ class phpbb_functional_fileupload_remote_test extends phpbb_functional_test_case public function test_successful_upload() { $upload = new fileupload('', array('gif'), 1000); - $file = $upload->remote_upload($this->root_url . 'styles/prosilver/theme/images/forum_read.gif'); + $file = $upload->remote_upload(self::$root_url . 'styles/prosilver/theme/images/forum_read.gif'); $this->assertEquals(0, sizeof($file->error)); $this->assertTrue(file_exists($file->filename)); } @@ -66,7 +66,8 @@ class phpbb_functional_fileupload_remote_test extends phpbb_functional_test_case public function test_too_large() { $upload = new fileupload('', array('gif'), 100); - $file = $upload->remote_upload($this->root_url . 'styles/prosilver/theme/images/forum_read.gif'); + $file = $upload->remote_upload(self::$root_url . 'styles/prosilver/theme/images/forum_read.gif'); + $this->assertEquals(1, sizeof($file->error)); $this->assertEquals('WRONG_FILESIZE', $file->error[0]); } } -- cgit v1.2.1 From 45c91be970f6afc1a5907442cd66e6a3a42a00fc Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 30 May 2013 14:12:08 +0200 Subject: [ticket/11568] Only assert string when doctype is there at all PHPBB3-11568 --- tests/test_framework/phpbb_functional_test_case.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index 63cbeb515a..304220f243 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -478,6 +478,9 @@ class phpbb_functional_test_case extends phpbb_test_case $content = self::$client->getResponse()->getContent(); // Any output before the doc type means there was an error - self::assertStringStartsWith(' Date: Thu, 30 May 2013 14:16:31 +0200 Subject: [ticket/11568] Remove unused method PHPBB3-11568 --- tests/test_framework/phpbb_functional_test_case.php | 19 ------------------- 1 file changed, 19 deletions(-) (limited to 'tests') diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index 304220f243..04a43182ae 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -284,25 +284,6 @@ class phpbb_functional_test_case extends phpbb_test_case copy($phpbb_root_path . "config.$phpEx", $phpbb_root_path . "config_test.$phpEx"); } - static private function do_request($sub, $post_data = null) - { - $context = null; - - if ($post_data) - { - $context = stream_context_create(array( - 'http' => array( - 'method' => 'POST', - 'header' => 'Content-Type: application/x-www-form-urlencoded', - 'content' => http_build_query($post_data), - 'ignore_errors' => true, - ), - )); - } - - return file_get_contents(self::$config['phpbb_functional_url'] . 'install/index.php?mode=install&sub=' . $sub, false, $context); - } - static private function recreate_database($config) { $db_conn_mgr = new phpbb_database_test_connection_manager($config); -- cgit v1.2.1 From 3f657bc63e6649da43d860be1848116c42214a65 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Thu, 30 May 2013 16:05:19 +0200 Subject: [ticket/11579] Add remaining unit tests for validate_data functions This now includes tests for usernames, passwords, emails, and jabber addresses. A few small changes had to be applied to phpbb_mock_cache and phpbb_mock_user in order to incorporate needed methods. PHPBB3-11579 --- tests/functions/fixtures/validate_data.xml | 59 +++++ tests/functions/validate_data_test.php | 350 ++++++++++++++++++++++++----- tests/mock/cache.php | 15 ++ tests/mock/user.php | 13 ++ 4 files changed, 375 insertions(+), 62 deletions(-) create mode 100644 tests/functions/fixtures/validate_data.xml (limited to 'tests') diff --git a/tests/functions/fixtures/validate_data.xml b/tests/functions/fixtures/validate_data.xml new file mode 100644 index 0000000000..38ecae6ad2 --- /dev/null +++ b/tests/functions/fixtures/validate_data.xml @@ -0,0 +1,59 @@ + + + + group_name + group_desc + + foobar_group + test123 + +
+ + lang_id + lang_iso + lang_local_name + lang_english_name + + 1 + en + English + English + + + 2 + cs + Čeština + Czech + +
+ + user_id + username + username_clean + user_permissions + user_sig + user_occ + user_interests + user_email_hash + + 1 + admin + admin + + + + + 143317126117 + + + 2 + moderator + moderator + + + + + 0 + +
+
diff --git a/tests/functions/validate_data_test.php b/tests/functions/validate_data_test.php index 6a429a5529..ed91f782ba 100644 --- a/tests/functions/validate_data_test.php +++ b/tests/functions/validate_data_test.php @@ -7,23 +7,30 @@ * */ +require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php'; require_once dirname(__FILE__) . '/../../phpBB/includes/functions_user.php'; require_once dirname(__FILE__) . '/../../phpBB/includes/utf/utf_tools.php'; +require_once dirname(__FILE__) . '/../mock/cache.php'; +require_once dirname(__FILE__) . '/../mock/user.php'; class phpbb_functions_validate_data_test extends phpbb_database_test_case { - /* - * Types to test - * - username - * . - * - password - * - email - * - jabber - */ + protected $db; + protected $cache; + protected $user; public function getDataSet() { - return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/language_select.xml'); + return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/validate_data.xml'); + } + + protected function setUp() + { + parent::setUp(); + + $this->db = $this->new_dbal(); + $this->cache = new phpbb_mock_cache; + $this->user = new phpbb_mock_user; } /** @@ -42,22 +49,15 @@ class phpbb_functions_validate_data_test extends phpbb_database_test_case { foreach ($input as $key => $data) { - $this->assertEquals($expected[$key], validate_data(array($data), array($validate_check[$key]))); + $test = validate_data(array($data), array($validate_check[$key])); + if ($test != $expected[$key]) + { + var_dump($key, $data, $test, $expected[$key]); + } + $this->assertEquals($expected[$key], $test); } } - /* - * Types to test - * - string: - * empty + optional = true --> good - * empty + optional = false --> good (min = 0) - * 'foobar' --> good - * 'foobar' + optional = false|true + min = 2 + max = 6 --> good - * 'foobar' + " + min = 7 + max = 9 --> TOO_SHORT - * 'foobar' + " + min = 2 + max = 5 --> TOO_LONG - * '' + optional = false + min = 1 + max = 6 --> TOO_SHORT - * '' + optional = true + min = 1 + max = 6 --> good - */ public function test_validate_string() { $this->validate_data_check(array( @@ -92,16 +92,6 @@ class phpbb_functions_validate_data_test extends phpbb_database_test_case )); } - /* - * Types to test - * - num - * empty + optional = true|false --> good - * 0 --> good - * 5 + optional = false|true + min = 2 + max = 6 --> good - * 5 + optional = false|true + min = 7 + max = 10 --> TOO_SMALL - * 5 + optional = false|true + min = 2 + max = 3 --> TOO_LARGE - * 'foobar' --> should fail with WRONG_DATA_NUMERIC !!! - */ public function test_validate_num() { $this->validate_data_check(array( @@ -130,19 +120,6 @@ class phpbb_functions_validate_data_test extends phpbb_database_test_case )); } - /* - * Types to test - * - date - * . '' --> invalid - * . '' + optional = true --> good - * . 17-06-1990 --> good - * . 05-05-1990 --> good - * . 17-12-1990 --> good - * . 01-01-0000 --> good!!! - * . 17-17-1990 --> invalid - * . 00-12-1990 --> invalid - * . 01-00-1990 --> invalid - */ public function test_validate_date() { $this->validate_data_check(array( @@ -186,14 +163,6 @@ class phpbb_functions_validate_data_test extends phpbb_database_test_case )); } - /* - * Types to test - * - match - * . empty + optional = true --> good - * . empty + empty match --> good - * . 'test' + optional = true|false + match = '/[a-z]/' --> good - * . 'test123' + optional = true|false + match = '/[a-z]/' --> WRONG_DATA_MATCH - */ public function test_validate_match() { $this->validate_data_check(array( @@ -216,19 +185,11 @@ class phpbb_functions_validate_data_test extends phpbb_database_test_case )); } - /* - * Types to test - * - language_iso_name - * . empty --> WRONG_DATA - * . 'en' --> good - * . 'cs' --> good - * . 'de' --> WRONG_DATA (won't exist) - */ public function test_validate_lang_iso() { global $db; - $db = $this->new_dbal(); + $db = $this->db; $this->validate_data_check(array( 'empty' => '', @@ -249,4 +210,269 @@ class phpbb_functions_validate_data_test extends phpbb_database_test_case 'de' => array('WRONG_DATA'), )); } + + public function validate_username_data() + { + return array( + array('USERNAME_CHARS_ANY', array( + 'foobar_allow' => array(), + 'foobar_ascii' => array(), + 'foobar_any' => array(), + 'foobar_alpha' => array(), + 'foobar_alpha_spacers' => array(), + 'foobar_letter_num' => array(), + 'foobar_letter_num_sp' => array(), + 'foobar_quot' => array('INVALID_CHARS'), + 'barfoo_disallow' => array('USERNAME_DISALLOWED'), + 'admin_taken' => array('USERNAME_TAKEN'), + 'group_taken' => array('USERNAME_TAKEN') + )), + array('USERNAME_ALPHA_ONLY', array( + 'foobar_allow' => array(), + 'foobar_ascii' => array(), + 'foobar_any' => array('INVALID_CHARS'), + 'foobar_alpha' => array(), + 'foobar_alpha_spacers' => array('INVALID_CHARS'), + 'foobar_letter_num' => array(), + 'foobar_letter_num_sp' => array('INVALID_CHARS'), + 'foobar_quot' => array('INVALID_CHARS'), + 'barfoo_disallow' => array('USERNAME_DISALLOWED'), + 'admin_taken' => array('USERNAME_TAKEN'), + 'group_taken' => array('INVALID_CHARS') + )), + array('USERNAME_ALPHA_SPACERS', array( + 'foobar_allow' => array(), + 'foobar_ascii' => array(), + 'foobar_any' => array('INVALID_CHARS'), + 'foobar_alpha' => array(), + 'foobar_alpha_spacers' => array(), + 'foobar_letter_num' => array(), + 'foobar_letter_num_sp' => array('INVALID_CHARS'), + 'foobar_quot' => array('INVALID_CHARS'), + 'barfoo_disallow' => array('USERNAME_DISALLOWED'), + 'admin_taken' => array('USERNAME_TAKEN'), + 'group_taken' => array('USERNAME_TAKEN') + )), + array('USERNAME_LETTER_NUM', array( + 'foobar_allow' => array(), + 'foobar_ascii' => array(), + 'foobar_any' => array('INVALID_CHARS'), + 'foobar_alpha' => array(), + 'foobar_alpha_spacers' => array('INVALID_CHARS'), + 'foobar_letter_num' => array(), + 'foobar_letter_num_sp' => array('INVALID_CHARS'), + 'foobar_quot' => array('INVALID_CHARS'), + 'barfoo_disallow' => array('USERNAME_DISALLOWED'), + 'admin_taken' => array('USERNAME_TAKEN'), + 'group_taken' => array('INVALID_CHARS') + )), + array('USERNAME_LETTER_NUM_SPACERS', array( + 'foobar_allow' => array(), + 'foobar_ascii' => array(), + 'foobar_any' => array('INVALID_CHARS'), + 'foobar_alpha' => array(), + 'foobar_alpha_spacers' => array(), + 'foobar_letter_num' => array(), + 'foobar_letter_num_sp' => array(), + 'foobar_quot' => array('INVALID_CHARS'), + 'barfoo_disallow' => array('USERNAME_DISALLOWED'), + 'admin_taken' => array('USERNAME_TAKEN'), + 'group_taken' => array('USERNAME_TAKEN') + )), + array('USERNAME_ASCII', array( + 'foobar_allow' => array(), + 'foobar_ascii' => array(), + 'foobar_any' => array(), + 'foobar_alpha' => array(), + 'foobar_alpha_spacers' => array(), + 'foobar_letter_num' => array(), + 'foobar_letter_num_sp' => array('INVALID_CHARS'), + 'foobar_quot' => array('INVALID_CHARS'), + 'barfoo_disallow' => array('USERNAME_DISALLOWED'), + 'admin_taken' => array('USERNAME_TAKEN'), + 'group_taken' => array('USERNAME_TAKEN') + )), + ); + } + + /** + * @dataProvider validate_username_data + */ + public function test_validate_username($allow_name_chars, $expected) + { + global $cache, $config, $db; + + $db = $this->db; + $cache = $this->cache; + $cache->put('_disallowed_usernames', array('barfoo')); + + $config['allow_name_chars'] = $allow_name_chars; + + $this->validate_data_check(array( + 'foobar_allow' => 'foobar', + 'foobar_ascii' => 'foobar', + 'foobar_any' => 'f*~*^=oo_bar1', + 'foobar_alpha' => 'fo0Bar', + 'foobar_alpha_spacers' => 'Fo0-[B]_a+ R', + 'foobar_letter_num' => 'fo0Bar0', + 'foobar_letter_num_sp' => 'Fö0-[B]_a+ R', + 'foobar_quot' => '"foobar"', + 'barfoo_disallow' => 'barfoo', + 'admin_taken' => 'admin', + 'group_taken' => 'foobar_group', + ), + array( + 'foobar_allow' => array('username', 'foobar'), + 'foobar_ascii' => array('username'), + 'foobar_any' => array('username'), + 'foobar_alpha' => array('username'), + 'foobar_alpha_spacers' => array('username'), + 'foobar_letter_num' => array('username'), + 'foobar_letter_num_sp' => array('username'), + 'foobar_quot' => array('username'), + 'barfoo_disallow' => array('username'), + 'admin_taken' => array('username'), + 'group_taken' => array('username'), + ), + $expected); + } + + public function validate_password_data() + { + return array( + array('PASS_TYPE_ANY', array( + 'empty' => array(), + 'foobar_any' => array(), + 'foobar_mixed' => array(), + 'foobar_alpha' => array(), + 'foobar_symbol' => array(), + )), + array('PASS_TYPE_CASE', array( + 'empty' => array(), + 'foobar_any' => array('INVALID_CHARS'), + 'foobar_mixed' => array(), + 'foobar_alpha' => array(), + 'foobar_symbol' => array(), + )), + array('PASS_TYPE_ALPHA', array( + 'empty' => array(), + 'foobar_any' => array('INVALID_CHARS'), + 'foobar_mixed' => array('INVALID_CHARS'), + 'foobar_alpha' => array(), + 'foobar_symbol' => array(), + )), + array('PASS_TYPE_SYMBOL', array( + 'empty' => array(), + 'foobar_any' => array('INVALID_CHARS'), + 'foobar_mixed' => array('INVALID_CHARS'), + 'foobar_alpha' => array('INVALID_CHARS'), + 'foobar_symbol' => array(), + )), + ); + } + + /** + * @dataProvider validate_password_data + */ + public function test_validate_password($pass_complexity, $expected) + { + global $config; + + // Set complexity to mixed case letters, numbers and symbols + $config['pass_complex'] = $pass_complexity; + + $this->validate_data_check(array( + 'empty' => '', + 'foobar_any' => 'foobar', + 'foobar_mixed' => 'FooBar', + 'foobar_alpha' => 'F00bar', + 'foobar_symbol' => 'fooBar123*', + ), + array( + 'empty' => array('password'), + 'foobar_any' => array('password'), + 'foobar_mixed' => array('password'), + 'foobar_alpha' => array('password'), + 'foobar_symbol' => array('password'), + ), + $expected); + } + + public function test_validate_email() + { + global $config, $db, $user; + + $config['email_check_mx'] = true; + $db = $this->db; + $user = $this->user; + $user->optionset('banned_users', array('banned@example.com')); + + $this->validate_data_check(array( + 'empty' => '', + 'allowed' => 'foobar@example.com', + 'invalid' => 'fööbar@example.com', + 'valid_complex' => "'%$~test@example.com", + 'taken' => 'admin@example.com', + 'banned' => 'banned@example.com', + 'no_mx' => 'test@wwrrrhhghgghgh.ttv', + ), + array( + 'empty' => array('email'), + 'allowed' => array('email', 'foobar@example.com'), + 'invalid' => array('email'), + 'valid_complex' => array('email'), + 'taken' => array('email'), + 'banned' => array('email'), + 'no_mx' => array('email'), + ), + array( + 'empty' => array(), + 'allowed' => array(), + 'invalid' => array('EMAIL_INVALID'), + 'valid_complex' => array(), + 'taken' => array('EMAIL_TAKEN'), + 'banned' => array('EMAIL_BANNED'), + 'no_mx' => array('DOMAIN_NO_MX_RECORD'), + )); + } + + public function test_validate_jabber() + { + $this->validate_data_check(array( + 'empty' => '', + 'no_seperator' => 'testjabber.ccc', + 'no_user' => '@jabber.ccc', + 'no_realm' => 'user@', + 'dot_realm' => 'user@.....', + '-realm' => 'user@-jabber.ccc', + 'realm-' => 'user@jabber.ccc-', + 'correct' => 'user@jabber.09A-z.org', + 'prohibited' => 'u@ser@jabber.ccc.org', + 'prohibited_char' => 'uer@jabber.ccc.org', + ), + array( + 'empty' => array('jabber'), + 'no_seperator' => array('jabber'), + 'no_user' => array('jabber'), + 'no_realm' => array('jabber'), + 'dot_realm' => array('jabber'), + '-realm' => array('jabber'), + 'realm-' => array('jabber'), + 'correct' => array('jabber'), + 'prohibited' => array('jabber'), + 'prohibited_char' => array('jabber'), + ), + array( + 'empty' => array(), + 'no_seperator' => array('WRONG_DATA'), + 'no_user' => array('WRONG_DATA'), + 'no_realm' => array('WRONG_DATA'), + 'dot_realm' => array('WRONG_DATA'), + '-realm' => array('WRONG_DATA'), + 'realm-' => array('WRONG_DATA'), + 'correct' => array(), + 'prohibited' => array('WRONG_DATA'), + 'prohibited_char' => array('WRONG_DATA'), + )); + } } diff --git a/tests/mock/cache.php b/tests/mock/cache.php index aa0db5ab20..acf4288319 100644 --- a/tests/mock/cache.php +++ b/tests/mock/cache.php @@ -74,6 +74,21 @@ class phpbb_mock_cache ); } + /** + * Obtain disallowed usernames. Input data via standard put method. + */ + public function obtain_disallowed_usernames() + { + if (($usernames = $this->get('_disallowed_usernames')) !== false) + { + return $usernames; + } + else + { + return array(); + } + } + public function set_bots($bots) { $this->data['_bots'] = $bots; diff --git a/tests/mock/user.php b/tests/mock/user.php index ec14ce430e..bd547b3973 100644 --- a/tests/mock/user.php +++ b/tests/mock/user.php @@ -33,4 +33,17 @@ class phpbb_mock_user { $this->options[$item] = $value; } + + public function check_ban($user_id = false, $user_ips = false, $user_email = false, $return = false) + { + $banned_users = $this->optionget('banned_users'); + foreach ($banned_users as $banned) + { + if ($banned == $user_id || $banned == $user_ips || $banned == $user_email) + { + return true; + } + } + return false; + } } -- cgit v1.2.1 From 5c046b9493d05981264c18b304d217fc75eda9e2 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 30 May 2013 16:16:49 +0200 Subject: [ticket/develop/11568] Remove unneccessary second call with wrong arguments PHPBB3-11568 --- tests/functional/extension_controller_test.php | 1 - 1 file changed, 1 deletion(-) (limited to 'tests') diff --git a/tests/functional/extension_controller_test.php b/tests/functional/extension_controller_test.php index 3e9428e82c..28805e7b5d 100644 --- a/tests/functional/extension_controller_test.php +++ b/tests/functional/extension_controller_test.php @@ -114,7 +114,6 @@ class phpbb_functional_extension_controller_test extends phpbb_functional_test_c { $this->phpbb_extension_manager->enable('foo/bar'); $crawler = $this->request('GET', 'app.php?controller=foo/baz', array(), true); - $this->request('GET', 'app.php?controller=foo/baz', false); $this->assert_response_success(500); $this->assertContains('Missing value for argument #1: test in class phpbb_ext_foo_bar_controller:baz', $crawler->filter('body')->text()); $this->phpbb_extension_manager->purge('foo/bar'); -- cgit v1.2.1 From 33a0859f4ac3454c12dda651f708e16fc6c45adb Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Thu, 30 May 2013 20:34:21 +0200 Subject: [ticket/11579] Move tests into seperate files depending on needed fixture PHPBB3-11579 --- tests/functions/common_validate_data.php | 31 ++ tests/functions/fixtures/validate_data.xml | 59 --- tests/functions/fixtures/validate_email.xml | 23 ++ tests/functions/fixtures/validate_username.xml | 38 ++ tests/functions/validate_data_simple_test.php | 252 +++++++++++++ tests/functions/validate_data_test.php | 478 ------------------------- tests/functions/validate_email_test.php | 72 ++++ tests/functions/validate_lang_iso_test.php | 56 +++ tests/functions/validate_username_test.php | 160 +++++++++ 9 files changed, 632 insertions(+), 537 deletions(-) create mode 100644 tests/functions/common_validate_data.php delete mode 100644 tests/functions/fixtures/validate_data.xml create mode 100644 tests/functions/fixtures/validate_email.xml create mode 100644 tests/functions/fixtures/validate_username.xml create mode 100644 tests/functions/validate_data_simple_test.php delete mode 100644 tests/functions/validate_data_test.php create mode 100644 tests/functions/validate_email_test.php create mode 100644 tests/functions/validate_lang_iso_test.php create mode 100644 tests/functions/validate_username_test.php (limited to 'tests') diff --git a/tests/functions/common_validate_data.php b/tests/functions/common_validate_data.php new file mode 100644 index 0000000000..64c9499ac3 --- /dev/null +++ b/tests/functions/common_validate_data.php @@ -0,0 +1,31 @@ + array('string')) + * @param array $expected Array containing the expected results. Either + * an array containing the error message or the an empty + * array if input is correct + */ + public function validate_data_check($input, $validate_check, $expected) + { + foreach ($input as $key => $data) + { + $this->assertEquals($expected[$key], validate_data(array($data), array($validate_check[$key]))); + } + } +} diff --git a/tests/functions/fixtures/validate_data.xml b/tests/functions/fixtures/validate_data.xml deleted file mode 100644 index 38ecae6ad2..0000000000 --- a/tests/functions/fixtures/validate_data.xml +++ /dev/null @@ -1,59 +0,0 @@ - - - - group_name - group_desc - - foobar_group - test123 - -
- - lang_id - lang_iso - lang_local_name - lang_english_name - - 1 - en - English - English - - - 2 - cs - Čeština - Czech - -
- - user_id - username - username_clean - user_permissions - user_sig - user_occ - user_interests - user_email_hash - - 1 - admin - admin - - - - - 143317126117 - - - 2 - moderator - moderator - - - - - 0 - -
-
diff --git a/tests/functions/fixtures/validate_email.xml b/tests/functions/fixtures/validate_email.xml new file mode 100644 index 0000000000..de7fce8a08 --- /dev/null +++ b/tests/functions/fixtures/validate_email.xml @@ -0,0 +1,23 @@ + + + + user_id + username + username_clean + user_permissions + user_sig + user_occ + user_interests + user_email_hash + + 1 + admin + admin + + + + + 143317126117 + +
+
diff --git a/tests/functions/fixtures/validate_username.xml b/tests/functions/fixtures/validate_username.xml new file mode 100644 index 0000000000..fbe398469c --- /dev/null +++ b/tests/functions/fixtures/validate_username.xml @@ -0,0 +1,38 @@ + + + + group_name + group_desc + + foobar_group + test123 + +
+ + user_id + username + username_clean + user_permissions + user_sig + user_occ + user_interests + + 1 + admin + admin + + + + + + + 2 + moderator + moderator + + + + + +
+
diff --git a/tests/functions/validate_data_simple_test.php b/tests/functions/validate_data_simple_test.php new file mode 100644 index 0000000000..002b1f2298 --- /dev/null +++ b/tests/functions/validate_data_simple_test.php @@ -0,0 +1,252 @@ +common = new phpbb_functions_common_validate_data; + } + + public function test_validate_string() + { + $this->common->validate_data_check(array( + 'empty_opt' => '', + 'empty' => '', + 'foo' => 'foobar', + 'foo_minmax_correct' => 'foobar', + 'foo_minmax_short' => 'foobar', + 'foo_minmax_long' => 'foobar', + 'empty_short' => '', + 'empty_length_opt' => '', + ), + array( + 'empty_opt' => array('string', true), + 'empty' => array('string'), + 'foo' => array('string'), + 'foo_minmax_correct' => array('string', false, 2, 6), + 'foo_minmax_short' => array('string', false, 7, 9), + 'foo_minmax_long' => array('string', false, 2, 5), + 'empty_short' => array('string', false, 1, 6), + 'empty_length_opt' => array('string', true, 1, 6), + ), + array( + 'empty_opt' => array(), + 'empty' => array(), + 'foo' => array(), + 'foo_minmax_correct' => array(), + 'foo_minmax_short' => array('TOO_SHORT'), + 'foo_minmax_long' => array('TOO_LONG'), + 'empty_short' => array('TOO_SHORT'), + 'empty_length_opt' => array(), + )); + } + + public function test_validate_num() + { + $this->common->validate_data_check(array( + 'empty' => '', + 'zero' => 0, + 'five_minmax_correct' => 5, + 'five_minmax_short' => 5, + 'five_minmax_long' => 5, + 'string' => 'foobar', + ), + array( + 'empty' => array('num'), + 'zero' => array('num'), + 'five_minmax_correct' => array('num', false, 2, 6), + 'five_minmax_short' => array('num', false, 7, 10), + 'five_minmax_long' => array('num', false, 2, 3), + 'string' => array('num'), + ), + array( + 'empty' => array(), + 'zero' => array(), + 'five_minmax_correct' => array(), + 'five_minmax_short' => array('TOO_SMALL'), + 'five_minmax_long' => array('TOO_LARGE'), + 'string' => array(), + )); + } + + public function test_validate_date() + { + $this->common->validate_data_check(array( + 'empty' => '', + 'empty_opt' => '', + 'double_single' => '17-06-1990', + 'single_single' => '05-05-2009', + 'double_double' => '17-12-1990', + // Currently fails + //'zero_year' => '01-01-0000', + 'month_high' => '17-17-1990', + 'month_low' => '01-00-1990', + 'day_high' => '64-01-1990', + 'day_low' => '00-12-1990', + ), + array( + 'empty' => array('date'), + 'empty_opt' => array('date', true), + 'double_single' => array('date'), + 'single_single' => array('date'), + 'double_double' => array('date'), + // Currently fails + //'zero_year' => array('date'), + 'month_high' => array('date'), + 'month_low' => array('date'), + 'day_high' => array('date'), + 'day_low' => array('date'), + ), + array( + 'empty' => array('INVALID'), + 'empty_opt' => array(), + 'double_single' => array(), + 'single_single' => array(), + 'double_double' => array(), + // Currently fails + //'zero_year' => array(), + 'month_high' => array('INVALID'), + 'month_low' => array('INVALID'), + 'day_high' => array('INVALID'), + 'day_low' => array('INVALID'), + )); + } + + public function test_validate_match() + { + $this->common->validate_data_check(array( + 'empty_opt' => '', + 'empty_empty_match' => '', + 'foobar' => 'foobar', + 'foobar_fail' => 'foobar123', + ), + array( + 'empty_opt' => array('match', true, '/[a-z]$/'), + 'empty_empty_match' => array('match'), + 'foobar' => array('match', false, '/[a-z]$/'), + 'foobar_fail' => array('match', false, '/[a-z]$/'), + ), + array( + 'empty_opt' => array(), + 'empty_empty_match' => array(), + 'foobar' => array(), + 'foobar_fail' => array('WRONG_DATA'), + )); + } + + public function validate_password_data() + { + return array( + array('PASS_TYPE_ANY', array( + 'empty' => array(), + 'foobar_any' => array(), + 'foobar_mixed' => array(), + 'foobar_alpha' => array(), + 'foobar_symbol' => array(), + )), + array('PASS_TYPE_CASE', array( + 'empty' => array(), + 'foobar_any' => array('INVALID_CHARS'), + 'foobar_mixed' => array(), + 'foobar_alpha' => array(), + 'foobar_symbol' => array(), + )), + array('PASS_TYPE_ALPHA', array( + 'empty' => array(), + 'foobar_any' => array('INVALID_CHARS'), + 'foobar_mixed' => array('INVALID_CHARS'), + 'foobar_alpha' => array(), + 'foobar_symbol' => array(), + )), + array('PASS_TYPE_SYMBOL', array( + 'empty' => array(), + 'foobar_any' => array('INVALID_CHARS'), + 'foobar_mixed' => array('INVALID_CHARS'), + 'foobar_alpha' => array('INVALID_CHARS'), + 'foobar_symbol' => array(), + )), + ); + } + + /** + * @dataProvider validate_password_data + */ + public function test_validate_password($pass_complexity, $expected) + { + global $config; + + // Set complexity to mixed case letters, numbers and symbols + $config['pass_complex'] = $pass_complexity; + + $this->common->validate_data_check(array( + 'empty' => '', + 'foobar_any' => 'foobar', + 'foobar_mixed' => 'FooBar', + 'foobar_alpha' => 'F00bar', + 'foobar_symbol' => 'fooBar123*', + ), + array( + 'empty' => array('password'), + 'foobar_any' => array('password'), + 'foobar_mixed' => array('password'), + 'foobar_alpha' => array('password'), + 'foobar_symbol' => array('password'), + ), + $expected); + } + + public function test_validate_jabber() + { + $this->common->validate_data_check(array( + 'empty' => '', + 'no_seperator' => 'testjabber.ccc', + 'no_user' => '@jabber.ccc', + 'no_realm' => 'user@', + 'dot_realm' => 'user@.....', + '-realm' => 'user@-jabber.ccc', + 'realm-' => 'user@jabber.ccc-', + 'correct' => 'user@jabber.09A-z.org', + 'prohibited' => 'u@ser@jabber.ccc.org', + 'prohibited_char' => 'uer@jabber.ccc.org', + ), + array( + 'empty' => array('jabber'), + 'no_seperator' => array('jabber'), + 'no_user' => array('jabber'), + 'no_realm' => array('jabber'), + 'dot_realm' => array('jabber'), + '-realm' => array('jabber'), + 'realm-' => array('jabber'), + 'correct' => array('jabber'), + 'prohibited' => array('jabber'), + 'prohibited_char' => array('jabber'), + ), + array( + 'empty' => array(), + 'no_seperator' => array('WRONG_DATA'), + 'no_user' => array('WRONG_DATA'), + 'no_realm' => array('WRONG_DATA'), + 'dot_realm' => array('WRONG_DATA'), + '-realm' => array('WRONG_DATA'), + 'realm-' => array('WRONG_DATA'), + 'correct' => array(), + 'prohibited' => array('WRONG_DATA'), + 'prohibited_char' => array('WRONG_DATA'), + )); + } +} diff --git a/tests/functions/validate_data_test.php b/tests/functions/validate_data_test.php deleted file mode 100644 index ed91f782ba..0000000000 --- a/tests/functions/validate_data_test.php +++ /dev/null @@ -1,478 +0,0 @@ -createXMLDataSet(dirname(__FILE__) . '/fixtures/validate_data.xml'); - } - - protected function setUp() - { - parent::setUp(); - - $this->db = $this->new_dbal(); - $this->cache = new phpbb_mock_cache; - $this->user = new phpbb_mock_user; - } - - /** - * Test provided input data with supplied checks and compare to expected - * results - * - * @param array $input Input data with specific array keys that need to - * be matched by the ones in the other 2 params - * @param array $validate_check Array containing validate_data check - * settings, i.e. array('foobar' => array('string')) - * @param array $expected Array containing the expected results. Either - * an array containing the error message or the an empty - * array if input is correct - */ - public function validate_data_check($input, $validate_check, $expected) - { - foreach ($input as $key => $data) - { - $test = validate_data(array($data), array($validate_check[$key])); - if ($test != $expected[$key]) - { - var_dump($key, $data, $test, $expected[$key]); - } - $this->assertEquals($expected[$key], $test); - } - } - - public function test_validate_string() - { - $this->validate_data_check(array( - 'empty_opt' => '', - 'empty' => '', - 'foo' => 'foobar', - 'foo_minmax_correct' => 'foobar', - 'foo_minmax_short' => 'foobar', - 'foo_minmax_long' => 'foobar', - 'empty_short' => '', - 'empty_length_opt' => '', - ), - array( - 'empty_opt' => array('string', true), - 'empty' => array('string'), - 'foo' => array('string'), - 'foo_minmax_correct' => array('string', false, 2, 6), - 'foo_minmax_short' => array('string', false, 7, 9), - 'foo_minmax_long' => array('string', false, 2, 5), - 'empty_short' => array('string', false, 1, 6), - 'empty_length_opt' => array('string', true, 1, 6), - ), - array( - 'empty_opt' => array(), - 'empty' => array(), - 'foo' => array(), - 'foo_minmax_correct' => array(), - 'foo_minmax_short' => array('TOO_SHORT'), - 'foo_minmax_long' => array('TOO_LONG'), - 'empty_short' => array('TOO_SHORT'), - 'empty_length_opt' => array(), - )); - } - - public function test_validate_num() - { - $this->validate_data_check(array( - 'empty' => '', - 'zero' => 0, - 'five_minmax_correct' => 5, - 'five_minmax_short' => 5, - 'five_minmax_long' => 5, - 'string' => 'foobar', - ), - array( - 'empty' => array('num'), - 'zero' => array('num'), - 'five_minmax_correct' => array('num', false, 2, 6), - 'five_minmax_short' => array('num', false, 7, 10), - 'five_minmax_long' => array('num', false, 2, 3), - 'string' => array('num'), - ), - array( - 'empty' => array(), - 'zero' => array(), - 'five_minmax_correct' => array(), - 'five_minmax_short' => array('TOO_SMALL'), - 'five_minmax_long' => array('TOO_LARGE'), - 'string' => array(), - )); - } - - public function test_validate_date() - { - $this->validate_data_check(array( - 'empty' => '', - 'empty_opt' => '', - 'double_single' => '17-06-1990', - 'single_single' => '05-05-2009', - 'double_double' => '17-12-1990', - // Currently fails - //'zero_year' => '01-01-0000', - 'month_high' => '17-17-1990', - 'month_low' => '01-00-1990', - 'day_high' => '64-01-1990', - 'day_low' => '00-12-1990', - ), - array( - 'empty' => array('date'), - 'empty_opt' => array('date', true), - 'double_single' => array('date'), - 'single_single' => array('date'), - 'double_double' => array('date'), - // Currently fails - //'zero_year' => array('date'), - 'month_high' => array('date'), - 'month_low' => array('date'), - 'day_high' => array('date'), - 'day_low' => array('date'), - ), - array( - 'empty' => array('INVALID'), - 'empty_opt' => array(), - 'double_single' => array(), - 'single_single' => array(), - 'double_double' => array(), - // Currently fails - //'zero_year' => array(), - 'month_high' => array('INVALID'), - 'month_low' => array('INVALID'), - 'day_high' => array('INVALID'), - 'day_low' => array('INVALID'), - )); - } - - public function test_validate_match() - { - $this->validate_data_check(array( - 'empty_opt' => '', - 'empty_empty_match' => '', - 'foobar' => 'foobar', - 'foobar_fail' => 'foobar123', - ), - array( - 'empty_opt' => array('match', true, '/[a-z]$/'), - 'empty_empty_match' => array('match'), - 'foobar' => array('match', false, '/[a-z]$/'), - 'foobar_fail' => array('match', false, '/[a-z]$/'), - ), - array( - 'empty_opt' => array(), - 'empty_empty_match' => array(), - 'foobar' => array(), - 'foobar_fail' => array('WRONG_DATA'), - )); - } - - public function test_validate_lang_iso() - { - global $db; - - $db = $this->db; - - $this->validate_data_check(array( - 'empty' => '', - 'en' => 'en', - 'cs' => 'cs', - 'de' => 'de', - ), - array( - 'empty' => array('language_iso_name'), - 'en' => array('language_iso_name'), - 'cs' => array('language_iso_name'), - 'de' => array('language_iso_name'), - ), - array( - 'empty' => array('WRONG_DATA'), - 'en' => array(), - 'cs' => array(), - 'de' => array('WRONG_DATA'), - )); - } - - public function validate_username_data() - { - return array( - array('USERNAME_CHARS_ANY', array( - 'foobar_allow' => array(), - 'foobar_ascii' => array(), - 'foobar_any' => array(), - 'foobar_alpha' => array(), - 'foobar_alpha_spacers' => array(), - 'foobar_letter_num' => array(), - 'foobar_letter_num_sp' => array(), - 'foobar_quot' => array('INVALID_CHARS'), - 'barfoo_disallow' => array('USERNAME_DISALLOWED'), - 'admin_taken' => array('USERNAME_TAKEN'), - 'group_taken' => array('USERNAME_TAKEN') - )), - array('USERNAME_ALPHA_ONLY', array( - 'foobar_allow' => array(), - 'foobar_ascii' => array(), - 'foobar_any' => array('INVALID_CHARS'), - 'foobar_alpha' => array(), - 'foobar_alpha_spacers' => array('INVALID_CHARS'), - 'foobar_letter_num' => array(), - 'foobar_letter_num_sp' => array('INVALID_CHARS'), - 'foobar_quot' => array('INVALID_CHARS'), - 'barfoo_disallow' => array('USERNAME_DISALLOWED'), - 'admin_taken' => array('USERNAME_TAKEN'), - 'group_taken' => array('INVALID_CHARS') - )), - array('USERNAME_ALPHA_SPACERS', array( - 'foobar_allow' => array(), - 'foobar_ascii' => array(), - 'foobar_any' => array('INVALID_CHARS'), - 'foobar_alpha' => array(), - 'foobar_alpha_spacers' => array(), - 'foobar_letter_num' => array(), - 'foobar_letter_num_sp' => array('INVALID_CHARS'), - 'foobar_quot' => array('INVALID_CHARS'), - 'barfoo_disallow' => array('USERNAME_DISALLOWED'), - 'admin_taken' => array('USERNAME_TAKEN'), - 'group_taken' => array('USERNAME_TAKEN') - )), - array('USERNAME_LETTER_NUM', array( - 'foobar_allow' => array(), - 'foobar_ascii' => array(), - 'foobar_any' => array('INVALID_CHARS'), - 'foobar_alpha' => array(), - 'foobar_alpha_spacers' => array('INVALID_CHARS'), - 'foobar_letter_num' => array(), - 'foobar_letter_num_sp' => array('INVALID_CHARS'), - 'foobar_quot' => array('INVALID_CHARS'), - 'barfoo_disallow' => array('USERNAME_DISALLOWED'), - 'admin_taken' => array('USERNAME_TAKEN'), - 'group_taken' => array('INVALID_CHARS') - )), - array('USERNAME_LETTER_NUM_SPACERS', array( - 'foobar_allow' => array(), - 'foobar_ascii' => array(), - 'foobar_any' => array('INVALID_CHARS'), - 'foobar_alpha' => array(), - 'foobar_alpha_spacers' => array(), - 'foobar_letter_num' => array(), - 'foobar_letter_num_sp' => array(), - 'foobar_quot' => array('INVALID_CHARS'), - 'barfoo_disallow' => array('USERNAME_DISALLOWED'), - 'admin_taken' => array('USERNAME_TAKEN'), - 'group_taken' => array('USERNAME_TAKEN') - )), - array('USERNAME_ASCII', array( - 'foobar_allow' => array(), - 'foobar_ascii' => array(), - 'foobar_any' => array(), - 'foobar_alpha' => array(), - 'foobar_alpha_spacers' => array(), - 'foobar_letter_num' => array(), - 'foobar_letter_num_sp' => array('INVALID_CHARS'), - 'foobar_quot' => array('INVALID_CHARS'), - 'barfoo_disallow' => array('USERNAME_DISALLOWED'), - 'admin_taken' => array('USERNAME_TAKEN'), - 'group_taken' => array('USERNAME_TAKEN') - )), - ); - } - - /** - * @dataProvider validate_username_data - */ - public function test_validate_username($allow_name_chars, $expected) - { - global $cache, $config, $db; - - $db = $this->db; - $cache = $this->cache; - $cache->put('_disallowed_usernames', array('barfoo')); - - $config['allow_name_chars'] = $allow_name_chars; - - $this->validate_data_check(array( - 'foobar_allow' => 'foobar', - 'foobar_ascii' => 'foobar', - 'foobar_any' => 'f*~*^=oo_bar1', - 'foobar_alpha' => 'fo0Bar', - 'foobar_alpha_spacers' => 'Fo0-[B]_a+ R', - 'foobar_letter_num' => 'fo0Bar0', - 'foobar_letter_num_sp' => 'Fö0-[B]_a+ R', - 'foobar_quot' => '"foobar"', - 'barfoo_disallow' => 'barfoo', - 'admin_taken' => 'admin', - 'group_taken' => 'foobar_group', - ), - array( - 'foobar_allow' => array('username', 'foobar'), - 'foobar_ascii' => array('username'), - 'foobar_any' => array('username'), - 'foobar_alpha' => array('username'), - 'foobar_alpha_spacers' => array('username'), - 'foobar_letter_num' => array('username'), - 'foobar_letter_num_sp' => array('username'), - 'foobar_quot' => array('username'), - 'barfoo_disallow' => array('username'), - 'admin_taken' => array('username'), - 'group_taken' => array('username'), - ), - $expected); - } - - public function validate_password_data() - { - return array( - array('PASS_TYPE_ANY', array( - 'empty' => array(), - 'foobar_any' => array(), - 'foobar_mixed' => array(), - 'foobar_alpha' => array(), - 'foobar_symbol' => array(), - )), - array('PASS_TYPE_CASE', array( - 'empty' => array(), - 'foobar_any' => array('INVALID_CHARS'), - 'foobar_mixed' => array(), - 'foobar_alpha' => array(), - 'foobar_symbol' => array(), - )), - array('PASS_TYPE_ALPHA', array( - 'empty' => array(), - 'foobar_any' => array('INVALID_CHARS'), - 'foobar_mixed' => array('INVALID_CHARS'), - 'foobar_alpha' => array(), - 'foobar_symbol' => array(), - )), - array('PASS_TYPE_SYMBOL', array( - 'empty' => array(), - 'foobar_any' => array('INVALID_CHARS'), - 'foobar_mixed' => array('INVALID_CHARS'), - 'foobar_alpha' => array('INVALID_CHARS'), - 'foobar_symbol' => array(), - )), - ); - } - - /** - * @dataProvider validate_password_data - */ - public function test_validate_password($pass_complexity, $expected) - { - global $config; - - // Set complexity to mixed case letters, numbers and symbols - $config['pass_complex'] = $pass_complexity; - - $this->validate_data_check(array( - 'empty' => '', - 'foobar_any' => 'foobar', - 'foobar_mixed' => 'FooBar', - 'foobar_alpha' => 'F00bar', - 'foobar_symbol' => 'fooBar123*', - ), - array( - 'empty' => array('password'), - 'foobar_any' => array('password'), - 'foobar_mixed' => array('password'), - 'foobar_alpha' => array('password'), - 'foobar_symbol' => array('password'), - ), - $expected); - } - - public function test_validate_email() - { - global $config, $db, $user; - - $config['email_check_mx'] = true; - $db = $this->db; - $user = $this->user; - $user->optionset('banned_users', array('banned@example.com')); - - $this->validate_data_check(array( - 'empty' => '', - 'allowed' => 'foobar@example.com', - 'invalid' => 'fööbar@example.com', - 'valid_complex' => "'%$~test@example.com", - 'taken' => 'admin@example.com', - 'banned' => 'banned@example.com', - 'no_mx' => 'test@wwrrrhhghgghgh.ttv', - ), - array( - 'empty' => array('email'), - 'allowed' => array('email', 'foobar@example.com'), - 'invalid' => array('email'), - 'valid_complex' => array('email'), - 'taken' => array('email'), - 'banned' => array('email'), - 'no_mx' => array('email'), - ), - array( - 'empty' => array(), - 'allowed' => array(), - 'invalid' => array('EMAIL_INVALID'), - 'valid_complex' => array(), - 'taken' => array('EMAIL_TAKEN'), - 'banned' => array('EMAIL_BANNED'), - 'no_mx' => array('DOMAIN_NO_MX_RECORD'), - )); - } - - public function test_validate_jabber() - { - $this->validate_data_check(array( - 'empty' => '', - 'no_seperator' => 'testjabber.ccc', - 'no_user' => '@jabber.ccc', - 'no_realm' => 'user@', - 'dot_realm' => 'user@.....', - '-realm' => 'user@-jabber.ccc', - 'realm-' => 'user@jabber.ccc-', - 'correct' => 'user@jabber.09A-z.org', - 'prohibited' => 'u@ser@jabber.ccc.org', - 'prohibited_char' => 'uer@jabber.ccc.org', - ), - array( - 'empty' => array('jabber'), - 'no_seperator' => array('jabber'), - 'no_user' => array('jabber'), - 'no_realm' => array('jabber'), - 'dot_realm' => array('jabber'), - '-realm' => array('jabber'), - 'realm-' => array('jabber'), - 'correct' => array('jabber'), - 'prohibited' => array('jabber'), - 'prohibited_char' => array('jabber'), - ), - array( - 'empty' => array(), - 'no_seperator' => array('WRONG_DATA'), - 'no_user' => array('WRONG_DATA'), - 'no_realm' => array('WRONG_DATA'), - 'dot_realm' => array('WRONG_DATA'), - '-realm' => array('WRONG_DATA'), - 'realm-' => array('WRONG_DATA'), - 'correct' => array(), - 'prohibited' => array('WRONG_DATA'), - 'prohibited_char' => array('WRONG_DATA'), - )); - } -} diff --git a/tests/functions/validate_email_test.php b/tests/functions/validate_email_test.php new file mode 100644 index 0000000000..47aa37e11f --- /dev/null +++ b/tests/functions/validate_email_test.php @@ -0,0 +1,72 @@ +createXMLDataSet(dirname(__FILE__) . '/fixtures/validate_email.xml'); + } + + protected function setUp() + { + parent::setUp(); + + $this->db = $this->new_dbal(); + $this->user = new phpbb_mock_user; + $this->common = new phpbb_functions_common_validate_data; + } + + public function test_validate_email() + { + global $config, $db, $user; + + $config['email_check_mx'] = true; + $db = $this->db; + $user = $this->user; + $user->optionset('banned_users', array('banned@example.com')); + + $this->common->validate_data_check(array( + 'empty' => '', + 'allowed' => 'foobar@example.com', + 'invalid' => 'fööbar@example.com', + 'valid_complex' => "'%$~test@example.com", + 'taken' => 'admin@example.com', + 'banned' => 'banned@example.com', + 'no_mx' => 'test@wwrrrhhghgghgh.ttv', + ), + array( + 'empty' => array('email'), + 'allowed' => array('email', 'foobar@example.com'), + 'invalid' => array('email'), + 'valid_complex' => array('email'), + 'taken' => array('email'), + 'banned' => array('email'), + 'no_mx' => array('email'), + ), + array( + 'empty' => array(), + 'allowed' => array(), + 'invalid' => array('EMAIL_INVALID'), + 'valid_complex' => array(), + 'taken' => array('EMAIL_TAKEN'), + 'banned' => array('EMAIL_BANNED'), + 'no_mx' => array('DOMAIN_NO_MX_RECORD'), + )); + } +} diff --git a/tests/functions/validate_lang_iso_test.php b/tests/functions/validate_lang_iso_test.php new file mode 100644 index 0000000000..b8a1827432 --- /dev/null +++ b/tests/functions/validate_lang_iso_test.php @@ -0,0 +1,56 @@ +createXMLDataSet(dirname(__FILE__) . '/fixtures/language_select.xml'); + } + + protected function setUp() + { + parent::setUp(); + + $this->db = $this->new_dbal(); + $this->common = new phpbb_functions_common_validate_data; + } + + public function test_validate_lang_iso() + { + global $db; + + $db = $this->db; + + $this->common->validate_data_check(array( + 'empty' => '', + 'en' => 'en', + 'cs' => 'cs', + 'de' => 'de', + ), + array( + 'empty' => array('language_iso_name'), + 'en' => array('language_iso_name'), + 'cs' => array('language_iso_name'), + 'de' => array('language_iso_name'), + ), + array( + 'empty' => array('WRONG_DATA'), + 'en' => array(), + 'cs' => array(), + 'de' => array('WRONG_DATA'), + )); + } +} diff --git a/tests/functions/validate_username_test.php b/tests/functions/validate_username_test.php new file mode 100644 index 0000000000..656248cec3 --- /dev/null +++ b/tests/functions/validate_username_test.php @@ -0,0 +1,160 @@ +createXMLDataSet(dirname(__FILE__) . '/fixtures/validate_username.xml'); + } + + protected function setUp() + { + parent::setUp(); + + $this->db = $this->new_dbal(); + $this->cache = new phpbb_mock_cache; + $this->common = new phpbb_functions_common_validate_data; + } + + public function validate_username_data() + { + return array( + array('USERNAME_CHARS_ANY', array( + 'foobar_allow' => array(), + 'foobar_ascii' => array(), + 'foobar_any' => array(), + 'foobar_alpha' => array(), + 'foobar_alpha_spacers' => array(), + 'foobar_letter_num' => array(), + 'foobar_letter_num_sp' => array(), + 'foobar_quot' => array('INVALID_CHARS'), + 'barfoo_disallow' => array('USERNAME_DISALLOWED'), + 'admin_taken' => array('USERNAME_TAKEN'), + 'group_taken' => array('USERNAME_TAKEN') + )), + array('USERNAME_ALPHA_ONLY', array( + 'foobar_allow' => array(), + 'foobar_ascii' => array(), + 'foobar_any' => array('INVALID_CHARS'), + 'foobar_alpha' => array(), + 'foobar_alpha_spacers' => array('INVALID_CHARS'), + 'foobar_letter_num' => array(), + 'foobar_letter_num_sp' => array('INVALID_CHARS'), + 'foobar_quot' => array('INVALID_CHARS'), + 'barfoo_disallow' => array('USERNAME_DISALLOWED'), + 'admin_taken' => array('USERNAME_TAKEN'), + 'group_taken' => array('INVALID_CHARS') + )), + array('USERNAME_ALPHA_SPACERS', array( + 'foobar_allow' => array(), + 'foobar_ascii' => array(), + 'foobar_any' => array('INVALID_CHARS'), + 'foobar_alpha' => array(), + 'foobar_alpha_spacers' => array(), + 'foobar_letter_num' => array(), + 'foobar_letter_num_sp' => array('INVALID_CHARS'), + 'foobar_quot' => array('INVALID_CHARS'), + 'barfoo_disallow' => array('USERNAME_DISALLOWED'), + 'admin_taken' => array('USERNAME_TAKEN'), + 'group_taken' => array('USERNAME_TAKEN') + )), + array('USERNAME_LETTER_NUM', array( + 'foobar_allow' => array(), + 'foobar_ascii' => array(), + 'foobar_any' => array('INVALID_CHARS'), + 'foobar_alpha' => array(), + 'foobar_alpha_spacers' => array('INVALID_CHARS'), + 'foobar_letter_num' => array(), + 'foobar_letter_num_sp' => array('INVALID_CHARS'), + 'foobar_quot' => array('INVALID_CHARS'), + 'barfoo_disallow' => array('USERNAME_DISALLOWED'), + 'admin_taken' => array('USERNAME_TAKEN'), + 'group_taken' => array('INVALID_CHARS') + )), + array('USERNAME_LETTER_NUM_SPACERS', array( + 'foobar_allow' => array(), + 'foobar_ascii' => array(), + 'foobar_any' => array('INVALID_CHARS'), + 'foobar_alpha' => array(), + 'foobar_alpha_spacers' => array(), + 'foobar_letter_num' => array(), + 'foobar_letter_num_sp' => array(), + 'foobar_quot' => array('INVALID_CHARS'), + 'barfoo_disallow' => array('USERNAME_DISALLOWED'), + 'admin_taken' => array('USERNAME_TAKEN'), + 'group_taken' => array('USERNAME_TAKEN') + )), + array('USERNAME_ASCII', array( + 'foobar_allow' => array(), + 'foobar_ascii' => array(), + 'foobar_any' => array(), + 'foobar_alpha' => array(), + 'foobar_alpha_spacers' => array(), + 'foobar_letter_num' => array(), + 'foobar_letter_num_sp' => array('INVALID_CHARS'), + 'foobar_quot' => array('INVALID_CHARS'), + 'barfoo_disallow' => array('USERNAME_DISALLOWED'), + 'admin_taken' => array('USERNAME_TAKEN'), + 'group_taken' => array('USERNAME_TAKEN') + )), + ); + } + + /** + * @dataProvider validate_username_data + */ + public function test_validate_username($allow_name_chars, $expected) + { + global $cache, $config, $db; + + $db = $this->db; + $cache = $this->cache; + $cache->put('_disallowed_usernames', array('barfoo')); + + $config['allow_name_chars'] = $allow_name_chars; + + $this->common->validate_data_check(array( + 'foobar_allow' => 'foobar', + 'foobar_ascii' => 'foobar', + 'foobar_any' => 'f*~*^=oo_bar1', + 'foobar_alpha' => 'fo0Bar', + 'foobar_alpha_spacers' => 'Fo0-[B]_a+ R', + 'foobar_letter_num' => 'fo0Bar0', + 'foobar_letter_num_sp' => 'Fö0-[B]_a+ R', + 'foobar_quot' => '"foobar"', + 'barfoo_disallow' => 'barfoo', + 'admin_taken' => 'admin', + 'group_taken' => 'foobar_group', + ), + array( + 'foobar_allow' => array('username', 'foobar'), + 'foobar_ascii' => array('username'), + 'foobar_any' => array('username'), + 'foobar_alpha' => array('username'), + 'foobar_alpha_spacers' => array('username'), + 'foobar_letter_num' => array('username'), + 'foobar_letter_num_sp' => array('username'), + 'foobar_quot' => array('username'), + 'barfoo_disallow' => array('username'), + 'admin_taken' => array('username'), + 'group_taken' => array('username'), + ), + $expected); + } +} -- cgit v1.2.1 From 48036c6edaa778cbeb6cc7ad9018846a659bb0b0 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 17 May 2013 16:05:48 +0200 Subject: [ticket/11549] Add functional test for ACP Extension Module with Template PHPBB3-11549 --- tests/functional/extension_module_test.php | 130 +++++++++++++++++++++ .../fixtures/ext/foo/bar/acp/main_info.php | 32 +++++ .../fixtures/ext/foo/bar/acp/main_module.php | 28 +++++ .../fixtures/ext/foo/bar/adm/style/foobar.html | 3 + 4 files changed, 193 insertions(+) create mode 100644 tests/functional/extension_module_test.php create mode 100644 tests/functional/fixtures/ext/foo/bar/acp/main_info.php create mode 100644 tests/functional/fixtures/ext/foo/bar/acp/main_module.php create mode 100644 tests/functional/fixtures/ext/foo/bar/adm/style/foobar.html (limited to 'tests') diff --git a/tests/functional/extension_module_test.php b/tests/functional/extension_module_test.php new file mode 100644 index 0000000000..cf67675a28 --- /dev/null +++ b/tests/functional/extension_module_test.php @@ -0,0 +1,130 @@ +copy_dir($phpbb_root_path . 'ext/', $phpbb_root_path . 'store/temp_ext/'); + + // Then empty the ext/ directory on the board (for accurate test cases) + self::$helper->empty_dir($phpbb_root_path . 'ext/'); + } + + // Copy our ext/ files from the test case to the board + self::$copied_files = array_merge(self::$copied_files, self::$helper->copy_dir(dirname(__FILE__) . '/fixtures/ext/', $phpbb_root_path . 'ext/')); + } + + /** + * This should only be called once after the tests are run. + * This is used to remove the fixtures from the phpBB install + */ + static public function tearDownAfterClass() + { + global $phpbb_root_path; + + if (file_exists($phpbb_root_path . 'store/temp_ext/')) + { + // Copy back the board installed extensions from the temp directory + self::$helper->copy_dir($phpbb_root_path . 'store/temp_ext/', $phpbb_root_path . 'ext/'); + } + + // Remove all of the files we copied around (from board ext -> temp_ext, from test ext -> board ext) + self::$helper->remove_files(self::$copied_files); + + if (file_exists($phpbb_root_path . 'store/temp_ext/')) + { + self::$helper->empty_dir($phpbb_root_path . 'store/temp_ext/'); + } + } + + public function setUp() + { + global $db; + + parent::setUp(); + + $this->phpbb_extension_manager = $this->get_extension_manager(); + $this->phpbb_extension_manager->enable('foo/bar'); + + $modules = new acp_modules(); + $db = $this->get_db(); + + $sql = 'SELECT module_id + FROM ' . MODULES_TABLE . " + WHERE module_langname = 'acp' + AND module_class = 'ACP_CAT_DOT_MODS'"; + $result = $db->sql_query($sql); + $module_id = (int) $db->sql_fetchfield('module_id'); + $db->sql_freeresult($result); + + $parent_data = array( + 'module_basename' => '', + 'module_enabled' => 1, + 'module_display' => 1, + 'parent_id' => $module_id, + 'module_class' => 'acp', + 'module_langname' => 'ACP_FOOBAR_TITLE', + 'module_mode' => '', + 'module_auth' => '', + ); + $modules->update_module_data($parent_data, true); + + $module_data = array( + 'module_basename' => 'phpbb_ext_foo_bar_acp_main_module', + 'module_enabled' => 1, + 'module_display' => 1, + 'parent_id' => $parent_data['module_id'], + 'module_class' => 'acp', + 'module_langname' => 'ACP_FOOBAR_TITLE', + 'module_mode' => 'mode', + 'module_auth' => '', + ); + $modules->update_module_data($module_data, true); + + $this->purge_cache(); + } + + /** + * Check a controller for extension foo/bar. + */ + public function test_foo_bar() + { + $this->login(); + $this->admin_login(); + $crawler = $this->request('GET', 'adm/index.php?i=phpbb_ext_foo_bar_acp_main_module&mode=mode&sid=' . $this->sid, array(), true); + $this->assert_response_success(); + $this->assertContains("Bertie rulez!", $crawler->filter('#main')->text()); + $this->phpbb_extension_manager->purge('foo/bar'); + } +} diff --git a/tests/functional/fixtures/ext/foo/bar/acp/main_info.php b/tests/functional/fixtures/ext/foo/bar/acp/main_info.php new file mode 100644 index 0000000000..21e38b09b5 --- /dev/null +++ b/tests/functional/fixtures/ext/foo/bar/acp/main_info.php @@ -0,0 +1,32 @@ + 'phpbb_ext_foo_bar_acp_main_module', + 'title' => 'ACP_FOOBAR_TITLE', + 'version' => '1.0.0', + 'modes' => array( + 'mode' => array('title' => 'ACP_FOOBAR_MODE', 'auth' => '', 'cat' => array('ACP_FOOBAR_TITLE')), + ), + ); + } +} diff --git a/tests/functional/fixtures/ext/foo/bar/acp/main_module.php b/tests/functional/fixtures/ext/foo/bar/acp/main_module.php new file mode 100644 index 0000000000..c4ab69fb38 --- /dev/null +++ b/tests/functional/fixtures/ext/foo/bar/acp/main_module.php @@ -0,0 +1,28 @@ +tpl_name = 'foobar'; + $this->page_title = 'Bertie'; + } +} diff --git a/tests/functional/fixtures/ext/foo/bar/adm/style/foobar.html b/tests/functional/fixtures/ext/foo/bar/adm/style/foobar.html new file mode 100644 index 0000000000..3cb45c269c --- /dev/null +++ b/tests/functional/fixtures/ext/foo/bar/adm/style/foobar.html @@ -0,0 +1,3 @@ + +Bertie rulez! + -- cgit v1.2.1 From b7b81f64316a900d6de308d4b65f89b7b4b58e2f Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 31 May 2013 16:16:41 +0200 Subject: [ticket/11568] Use static calls for static methods PHPBB3-11568 --- tests/functional/auth_test.php | 8 ++++---- tests/functional/browse_test.php | 6 +++--- tests/functional/common_groups_test.php | 4 ++-- tests/functional/posting_test.php | 14 +++++++------- tests/test_framework/phpbb_functional_test_case.php | 8 ++++---- 5 files changed, 20 insertions(+), 20 deletions(-) (limited to 'tests') diff --git a/tests/functional/auth_test.php b/tests/functional/auth_test.php index a0c909e798..afb4f15fc2 100644 --- a/tests/functional/auth_test.php +++ b/tests/functional/auth_test.php @@ -17,7 +17,7 @@ class phpbb_functional_auth_test extends phpbb_functional_test_case $this->login(); // check for logout link - $crawler = $this->request('GET', 'index.php'); + $crawler = self::request('GET', 'index.php'); $this->assertContains($this->lang('LOGOUT_USER', 'admin'), $crawler->filter('.navbar')->text()); } @@ -25,7 +25,7 @@ class phpbb_functional_auth_test extends phpbb_functional_test_case { $this->create_user('anothertestuser'); $this->login('anothertestuser'); - $crawler = $this->request('GET', 'index.php'); + $crawler = self::request('GET', 'index.php'); $this->assertContains('anothertestuser', $crawler->filter('.icon-logout')->text()); } @@ -38,11 +38,11 @@ class phpbb_functional_auth_test extends phpbb_functional_test_case $this->add_lang('ucp'); // logout - $crawler = $this->request('GET', 'ucp.php?sid=' . $this->sid . '&mode=logout'); + $crawler = self::request('GET', 'ucp.php?sid=' . $this->sid . '&mode=logout'); $this->assertContains($this->lang('LOGOUT_REDIRECT'), $crawler->filter('#message')->text()); // look for a register link, which should be visible only when logged out - $crawler = $this->request('GET', 'index.php'); + $crawler = self::request('GET', 'index.php'); $this->assertContains($this->lang('REGISTER'), $crawler->filter('.navbar')->text()); } } diff --git a/tests/functional/browse_test.php b/tests/functional/browse_test.php index 26c18c4c1f..18a2ad9464 100644 --- a/tests/functional/browse_test.php +++ b/tests/functional/browse_test.php @@ -14,19 +14,19 @@ class phpbb_functional_browse_test extends phpbb_functional_test_case { public function test_index() { - $crawler = $this->request('GET', 'index.php'); + $crawler = self::request('GET', 'index.php'); $this->assertGreaterThan(0, $crawler->filter('.topiclist')->count()); } public function test_viewforum() { - $crawler = $this->request('GET', 'viewforum.php?f=2'); + $crawler = self::request('GET', 'viewforum.php?f=2'); $this->assertGreaterThan(0, $crawler->filter('.topiclist')->count()); } public function test_viewtopic() { - $crawler = $this->request('GET', 'viewtopic.php?t=1'); + $crawler = self::request('GET', 'viewtopic.php?t=1'); $this->assertGreaterThan(0, $crawler->filter('.postbody')->count()); } } diff --git a/tests/functional/common_groups_test.php b/tests/functional/common_groups_test.php index 6e1f1afdce..7c88ec900d 100644 --- a/tests/functional/common_groups_test.php +++ b/tests/functional/common_groups_test.php @@ -35,10 +35,10 @@ abstract class phpbb_functional_common_groups_test extends phpbb_functional_test $this->add_lang(array('ucp', 'acp/groups')); // Manage Administrators group - $crawler = $this->request('GET', $this->get_url() . '&g=5&sid=' . $this->sid); + $crawler = self::request('GET', $this->get_url() . '&g=5&sid=' . $this->sid); $form = $crawler->selectButton($this->lang('SUBMIT'))->form(); $form['group_colour']->setValue($input); - $crawler = $this->submit($form); + $crawler = self::submit($form); $this->assertContains($this->lang($expected), $crawler->text()); } } diff --git a/tests/functional/posting_test.php b/tests/functional/posting_test.php index 5cf7559245..9bcfcc2fda 100644 --- a/tests/functional/posting_test.php +++ b/tests/functional/posting_test.php @@ -19,17 +19,17 @@ class phpbb_functional_posting_test extends phpbb_functional_test_case // Test creating topic $post = $this->create_topic(2, 'Test Topic 1', 'This is a test topic posted by the testing framework.'); - $crawler = $this->request('GET', "viewtopic.php?t={$post['topic_id']}&sid={$this->sid}"); + $crawler = self::request('GET', "viewtopic.php?t={$post['topic_id']}&sid={$this->sid}"); $this->assertContains('This is a test topic posted by the testing framework.', $crawler->filter('html')->text()); // Test creating a reply $post2 = $this->create_post(2, $post['topic_id'], 'Re: Test Topic 1', 'This is a test post posted by the testing framework.'); - $crawler = $this->request('GET', "viewtopic.php?t={$post2['topic_id']}&sid={$this->sid}"); + $crawler = self::request('GET', "viewtopic.php?t={$post2['topic_id']}&sid={$this->sid}"); $this->assertContains('This is a test post posted by the testing framework.', $crawler->filter('html')->text()); // Test quoting a message - $crawler = $this->request('GET', "posting.php?mode=quote&f=2&t={$post2['topic_id']}&p={$post2['post_id']}&sid={$this->sid}"); + $crawler = self::request('GET', "posting.php?mode=quote&f=2&t={$post2['topic_id']}&p={$post2['post_id']}&sid={$this->sid}"); $this->assertContains('This is a test post posted by the testing framework.', $crawler->filter('html')->text()); } @@ -54,7 +54,7 @@ class phpbb_functional_posting_test extends phpbb_functional_test_case 'post' => true, ), $additional_form_data); - return $this->submit_post($posting_url, 'POST_TOPIC', $form_data); + return self::submit_post($posting_url, 'POST_TOPIC', $form_data); } /** @@ -78,7 +78,7 @@ class phpbb_functional_posting_test extends phpbb_functional_test_case 'post' => true, ), $additional_form_data); - return $this->submit_post($posting_url, 'POST_REPLY', $form_data); + return self::submit_post($posting_url, 'POST_REPLY', $form_data); } /** @@ -93,7 +93,7 @@ class phpbb_functional_posting_test extends phpbb_functional_test_case { $this->add_lang('posting'); - $crawler = $this->request('GET', $posting_url); + $crawler = self::request('GET', $posting_url); $this->assertContains($this->lang($posting_contains), $crawler->filter('html')->text()); $hidden_fields = array( @@ -117,7 +117,7 @@ class phpbb_functional_posting_test extends phpbb_functional_test_case // I use a request because the form submission method does not allow you to send data that is not // contained in one of the actual form fields that the browser sees (i.e. it ignores "hidden" inputs) // Instead, I send it as a request with the submit button "post" set to true. - $crawler = $this->request('POST', $posting_url, $form_data); + $crawler = self::request('POST', $posting_url, $form_data); $this->assertContains($this->lang('POST_STORED'), $crawler->filter('html')->text()); $url = $crawler->selectLink($this->lang('VIEW_MESSAGE', '', ''))->link()->getUri(); diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index 04a43182ae..a0dceb152b 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -344,11 +344,11 @@ class phpbb_functional_test_case extends phpbb_test_case { $this->add_lang('ucp'); - $crawler = $this->request('GET', 'ucp.php'); + $crawler = self::request('GET', 'ucp.php'); $this->assertContains($this->lang('LOGIN_EXPLAIN_UCP'), $crawler->filter('html')->text()); $form = $crawler->selectButton($this->lang('LOGIN'))->form(); - $crawler = $this->submit($form, array('username' => $username, 'password' => $username . $username)); + $crawler = self::submit($form, array('username' => $username, 'password' => $username . $username)); $this->assert_response_success(); $this->assertContains($this->lang('LOGIN_REDIRECT'), $crawler->filter('html')->text()); @@ -379,7 +379,7 @@ class phpbb_functional_test_case extends phpbb_test_case return; } - $crawler = $this->request('GET', 'adm/index.php?sid=' . $this->sid); + $crawler = self::request('GET', 'adm/index.php?sid=' . $this->sid); $this->assertContains($this->lang('LOGIN_ADMIN_CONFIRM'), $crawler->filter('html')->text()); $form = $crawler->selectButton($this->lang('LOGIN'))->form(); @@ -388,7 +388,7 @@ class phpbb_functional_test_case extends phpbb_test_case { if (strpos($field, 'password_') === 0) { - $crawler = $this->submit($form, array('username' => $username, $field => $username . $username)); + $crawler = self::submit($form, array('username' => $username, $field => $username . $username)); $this->assert_response_success(); $this->assertContains($this->lang('LOGIN_ADMIN_SUCCESS'), $crawler->filter('html')->text()); -- cgit v1.2.1 From b2be82cd57fd14e354d9e9c06b0324db74b754cf Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 31 May 2013 16:19:19 +0200 Subject: [ticket/11568] Invert logic for asserting the response PHPBB3-11568 --- tests/test_framework/phpbb_functional_test_case.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'tests') diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index a0dceb152b..f1d282311f 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -83,11 +83,11 @@ class phpbb_functional_test_case extends phpbb_test_case * @param bool $skip_assert_response_success Should we skip the basic response assertions? * @return Symfony\Component\DomCrawler\Crawler */ - static public function request($method, $path, $form_data = array(), $skip_assert_response_success = false) + static public function request($method, $path, $form_data = array(), $assert_response_success = true) { $crawler = self::$client->request($method, self::$root_url . $path, $form_data); - if (!$skip_assert_response_success) + if ($assert_response_success) { self::assert_response_success(); } @@ -103,11 +103,11 @@ class phpbb_functional_test_case extends phpbb_test_case * @param bool $skip_assert_response_success Should we skip the basic response assertions? * @return Symfony\Component\DomCrawler\Crawler */ - static public function submit(Symfony\Component\DomCrawler\Form $form, array $values = array(), $skip_assert_response_success = false) + static public function submit(Symfony\Component\DomCrawler\Form $form, array $values = array(), $assert_response_success = true) { $crawler = self::$client->submit($form, $values); - if (!$skip_assert_response_success) + if ($assert_response_success) { self::assert_response_success(); } -- cgit v1.2.1 From 09a3877ae4c5bda66f22d89408b589ea8b56f380 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 31 May 2013 16:20:20 +0200 Subject: [ticket/11568] Add comma at end of array key-value couple PHPBB3-11568 --- tests/test_framework/phpbb_functional_test_case.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index f1d282311f..5416125f42 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -202,7 +202,7 @@ class phpbb_functional_test_case extends phpbb_test_case self::$client->setClient(new Guzzle\Http\Client('', array( Guzzle\Http\Client::DISABLE_REDIRECTS => true, 'curl.options' => array( - CURLOPT_TIMEOUT => 120 + CURLOPT_TIMEOUT => 120, ), ))); -- cgit v1.2.1 From 6af5262fcccae3f3e651348a20dbbd8a78e191aa Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 31 May 2013 16:27:52 +0200 Subject: [ticket/11568] Split status code and html debug assertion into two methods PHPBB3-11568 --- .../test_framework/phpbb_functional_test_case.php | 48 ++++++++++++++-------- 1 file changed, 30 insertions(+), 18 deletions(-) (limited to 'tests') diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index 5416125f42..651ab013c7 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -80,16 +80,16 @@ class phpbb_functional_test_case extends phpbb_test_case * @param string $method HTTP Method * @param string $path Page path, relative from phpBB root path * @param array $form_data An array of form field values - * @param bool $skip_assert_response_success Should we skip the basic response assertions? + * @param bool $assert_response_html Should we perform standard assertions for a normal html page * @return Symfony\Component\DomCrawler\Crawler */ - static public function request($method, $path, $form_data = array(), $assert_response_success = true) + static public function request($method, $path, $form_data = array(), $assert_response_html = true) { $crawler = self::$client->request($method, self::$root_url . $path, $form_data); - if ($assert_response_success) + if ($assert_response_html) { - self::assert_response_success(); + self::assert_response_html(); } return $crawler; @@ -100,16 +100,16 @@ class phpbb_functional_test_case extends phpbb_test_case * * @param Symfony\Component\DomCrawler\Form $form A Form instance * @param array $values An array of form field values - * @param bool $skip_assert_response_success Should we skip the basic response assertions? + * @param bool $assert_response_html Should we perform standard assertions for a normal html page * @return Symfony\Component\DomCrawler\Crawler */ - static public function submit(Symfony\Component\DomCrawler\Form $form, array $values = array(), $assert_response_success = true) + static public function submit(Symfony\Component\DomCrawler\Form $form, array $values = array(), $assert_response_html = true) { $crawler = self::$client->submit($form, $values); - if ($assert_response_success) + if ($assert_response_html) { - self::assert_response_success(); + self::assert_response_html(); } return $crawler; @@ -349,7 +349,6 @@ class phpbb_functional_test_case extends phpbb_test_case $form = $crawler->selectButton($this->lang('LOGIN'))->form(); $crawler = self::submit($form, array('username' => $username, 'password' => $username . $username)); - $this->assert_response_success(); $this->assertContains($this->lang('LOGIN_REDIRECT'), $crawler->filter('html')->text()); $cookies = self::$cookieJar->all(); @@ -389,7 +388,6 @@ class phpbb_functional_test_case extends phpbb_test_case if (strpos($field, 'password_') === 0) { $crawler = self::submit($form, array('username' => $username, $field => $username . $username)); - $this->assert_response_success(); $this->assertContains($this->lang('LOGIN_ADMIN_SUCCESS'), $crawler->filter('html')->text()); $cookies = self::$cookieJar->all(); @@ -445,23 +443,37 @@ class phpbb_functional_test_case extends phpbb_test_case return call_user_func_array('sprintf', $args); } + /** + * Perform some basic assertions for the page + * + * Checks for debug/error output before the actual page content and the status code + * + * @param mixed $status_code Expected status code, false to disable check + * @return null + */ + static public function assert_response_html($status_code = 200) + { + if ($status_code !== false) + { + self::assert_response_status_code($status_code); + } + + // Any output before the doc type means there was an error + $content = self::$client->getResponse()->getContent(); + self::assertStringStartsWith('getResponse()->getStatus()); - $content = self::$client->getResponse()->getContent(); - - // Any output before the doc type means there was an error - if (strpos($content, ' Date: Mon, 3 Jun 2013 16:06:11 +0200 Subject: [ticket/11579] Use test case helper class and use assert prefix for method PHPBB3-11579 --- tests/functions/common_validate_data.php | 31 ------- tests/functions/validate_data_helper.php | 38 ++++++++ tests/functions/validate_data_simple_test.php | 119 +++++++++++++------------- tests/functions/validate_email_test.php | 26 +++--- tests/functions/validate_lang_iso_test.php | 20 ++--- tests/functions/validate_username_test.php | 11 ++- 6 files changed, 125 insertions(+), 120 deletions(-) delete mode 100644 tests/functions/common_validate_data.php create mode 100644 tests/functions/validate_data_helper.php (limited to 'tests') diff --git a/tests/functions/common_validate_data.php b/tests/functions/common_validate_data.php deleted file mode 100644 index 64c9499ac3..0000000000 --- a/tests/functions/common_validate_data.php +++ /dev/null @@ -1,31 +0,0 @@ - array('string')) - * @param array $expected Array containing the expected results. Either - * an array containing the error message or the an empty - * array if input is correct - */ - public function validate_data_check($input, $validate_check, $expected) - { - foreach ($input as $key => $data) - { - $this->assertEquals($expected[$key], validate_data(array($data), array($validate_check[$key]))); - } - } -} diff --git a/tests/functions/validate_data_helper.php b/tests/functions/validate_data_helper.php new file mode 100644 index 0000000000..b8e8bfded3 --- /dev/null +++ b/tests/functions/validate_data_helper.php @@ -0,0 +1,38 @@ +test_case = $test_case; + } + + /** + * Test provided input data with supplied checks and compare to expected + * results + * + * @param array $expected Array containing the expected results. Either + * an array containing the error message or the an empty + * array if input is correct + * @param array $input Input data with specific array keys that need to + * be matched by the ones in the other 2 params + * @param array $validate_check Array containing validate_data check + * settings, i.e. array('foobar' => array('string')) + */ + public function assert_validate_data($expected, $input, $validate_check) + { + foreach ($input as $key => $data) + { + $this->test_case->assertEquals($expected[$key], validate_data(array($data), array($validate_check[$key]))); + } + } +} diff --git a/tests/functions/validate_data_simple_test.php b/tests/functions/validate_data_simple_test.php index 002b1f2298..db4f218eed 100644 --- a/tests/functions/validate_data_simple_test.php +++ b/tests/functions/validate_data_simple_test.php @@ -9,22 +9,32 @@ require_once dirname(__FILE__) . '/../../phpBB/includes/functions_user.php'; require_once dirname(__FILE__) . '/../../phpBB/includes/utf/utf_tools.php'; -require_once dirname(__FILE__) . '/common_validate_data.php'; +require_once dirname(__FILE__) . '/validate_data_helper.php'; class phpbb_functions_validate_data_simple_test extends phpbb_test_case { - protected $common; + protected $helper; protected function setUp() { parent::setUp(); - $this->common = new phpbb_functions_common_validate_data; + $this->helper = new phpbb_functions_validate_data_helper($this); } public function test_validate_string() { - $this->common->validate_data_check(array( + $this->helper->assert_validate_data(array( + 'empty_opt' => array(), + 'empty' => array(), + 'foo' => array(), + 'foo_minmax_correct' => array(), + 'foo_minmax_short' => array('TOO_SHORT'), + 'foo_minmax_long' => array('TOO_LONG'), + 'empty_short' => array('TOO_SHORT'), + 'empty_length_opt' => array(), + ), + array( 'empty_opt' => '', 'empty' => '', 'foo' => 'foobar', @@ -43,22 +53,20 @@ class phpbb_functions_validate_data_simple_test extends phpbb_test_case 'foo_minmax_long' => array('string', false, 2, 5), 'empty_short' => array('string', false, 1, 6), 'empty_length_opt' => array('string', true, 1, 6), - ), - array( - 'empty_opt' => array(), - 'empty' => array(), - 'foo' => array(), - 'foo_minmax_correct' => array(), - 'foo_minmax_short' => array('TOO_SHORT'), - 'foo_minmax_long' => array('TOO_LONG'), - 'empty_short' => array('TOO_SHORT'), - 'empty_length_opt' => array(), )); } public function test_validate_num() { - $this->common->validate_data_check(array( + $this->helper->assert_validate_data(array( + 'empty' => array(), + 'zero' => array(), + 'five_minmax_correct' => array(), + 'five_minmax_short' => array('TOO_SMALL'), + 'five_minmax_long' => array('TOO_LARGE'), + 'string' => array(), + ), + array( 'empty' => '', 'zero' => 0, 'five_minmax_correct' => 5, @@ -73,20 +81,25 @@ class phpbb_functions_validate_data_simple_test extends phpbb_test_case 'five_minmax_short' => array('num', false, 7, 10), 'five_minmax_long' => array('num', false, 2, 3), 'string' => array('num'), - ), - array( - 'empty' => array(), - 'zero' => array(), - 'five_minmax_correct' => array(), - 'five_minmax_short' => array('TOO_SMALL'), - 'five_minmax_long' => array('TOO_LARGE'), - 'string' => array(), )); } public function test_validate_date() { - $this->common->validate_data_check(array( + $this->helper->assert_validate_data(array( + 'empty' => array('INVALID'), + 'empty_opt' => array(), + 'double_single' => array(), + 'single_single' => array(), + 'double_double' => array(), + // Currently fails + //'zero_year' => array(), + 'month_high' => array('INVALID'), + 'month_low' => array('INVALID'), + 'day_high' => array('INVALID'), + 'day_low' => array('INVALID'), + ), + array( 'empty' => '', 'empty_opt' => '', 'double_single' => '17-06-1990', @@ -111,25 +124,18 @@ class phpbb_functions_validate_data_simple_test extends phpbb_test_case 'month_low' => array('date'), 'day_high' => array('date'), 'day_low' => array('date'), - ), - array( - 'empty' => array('INVALID'), - 'empty_opt' => array(), - 'double_single' => array(), - 'single_single' => array(), - 'double_double' => array(), - // Currently fails - //'zero_year' => array(), - 'month_high' => array('INVALID'), - 'month_low' => array('INVALID'), - 'day_high' => array('INVALID'), - 'day_low' => array('INVALID'), )); } public function test_validate_match() { - $this->common->validate_data_check(array( + $this->helper->assert_validate_data(array( + 'empty_opt' => array(), + 'empty_empty_match' => array(), + 'foobar' => array(), + 'foobar_fail' => array('WRONG_DATA'), + ), + array( 'empty_opt' => '', 'empty_empty_match' => '', 'foobar' => 'foobar', @@ -140,12 +146,6 @@ class phpbb_functions_validate_data_simple_test extends phpbb_test_case 'empty_empty_match' => array('match'), 'foobar' => array('match', false, '/[a-z]$/'), 'foobar_fail' => array('match', false, '/[a-z]$/'), - ), - array( - 'empty_opt' => array(), - 'empty_empty_match' => array(), - 'foobar' => array(), - 'foobar_fail' => array('WRONG_DATA'), )); } @@ -193,7 +193,7 @@ class phpbb_functions_validate_data_simple_test extends phpbb_test_case // Set complexity to mixed case letters, numbers and symbols $config['pass_complex'] = $pass_complexity; - $this->common->validate_data_check(array( + $this->helper->assert_validate_data($expected, array( 'empty' => '', 'foobar_any' => 'foobar', 'foobar_mixed' => 'FooBar', @@ -206,13 +206,24 @@ class phpbb_functions_validate_data_simple_test extends phpbb_test_case 'foobar_mixed' => array('password'), 'foobar_alpha' => array('password'), 'foobar_symbol' => array('password'), - ), - $expected); + )); } public function test_validate_jabber() { - $this->common->validate_data_check(array( + $this->helper->assert_validate_data(array( + 'empty' => array(), + 'no_seperator' => array('WRONG_DATA'), + 'no_user' => array('WRONG_DATA'), + 'no_realm' => array('WRONG_DATA'), + 'dot_realm' => array('WRONG_DATA'), + '-realm' => array('WRONG_DATA'), + 'realm-' => array('WRONG_DATA'), + 'correct' => array(), + 'prohibited' => array('WRONG_DATA'), + 'prohibited_char' => array('WRONG_DATA'), + ), + array( 'empty' => '', 'no_seperator' => 'testjabber.ccc', 'no_user' => '@jabber.ccc', @@ -235,18 +246,6 @@ class phpbb_functions_validate_data_simple_test extends phpbb_test_case 'correct' => array('jabber'), 'prohibited' => array('jabber'), 'prohibited_char' => array('jabber'), - ), - array( - 'empty' => array(), - 'no_seperator' => array('WRONG_DATA'), - 'no_user' => array('WRONG_DATA'), - 'no_realm' => array('WRONG_DATA'), - 'dot_realm' => array('WRONG_DATA'), - '-realm' => array('WRONG_DATA'), - 'realm-' => array('WRONG_DATA'), - 'correct' => array(), - 'prohibited' => array('WRONG_DATA'), - 'prohibited_char' => array('WRONG_DATA'), )); } } diff --git a/tests/functions/validate_email_test.php b/tests/functions/validate_email_test.php index 47aa37e11f..2e81d3277e 100644 --- a/tests/functions/validate_email_test.php +++ b/tests/functions/validate_email_test.php @@ -10,13 +10,13 @@ require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php'; require_once dirname(__FILE__) . '/../../phpBB/includes/functions_user.php'; require_once dirname(__FILE__) . '/../mock/user.php'; -require_once dirname(__FILE__) . '/common_validate_data.php'; +require_once dirname(__FILE__) . '/validate_data_helper.php'; class phpbb_functions_validate_email_test extends phpbb_database_test_case { protected $db; protected $user; - protected $common; + protected $helper; public function getDataSet() { @@ -29,7 +29,7 @@ class phpbb_functions_validate_email_test extends phpbb_database_test_case $this->db = $this->new_dbal(); $this->user = new phpbb_mock_user; - $this->common = new phpbb_functions_common_validate_data; + $this->helper = new phpbb_functions_validate_data_helper($this); } public function test_validate_email() @@ -41,7 +41,16 @@ class phpbb_functions_validate_email_test extends phpbb_database_test_case $user = $this->user; $user->optionset('banned_users', array('banned@example.com')); - $this->common->validate_data_check(array( + $this->helper->assert_validate_data(array( + 'empty' => array(), + 'allowed' => array(), + 'invalid' => array('EMAIL_INVALID'), + 'valid_complex' => array(), + 'taken' => array('EMAIL_TAKEN'), + 'banned' => array('EMAIL_BANNED'), + 'no_mx' => array('DOMAIN_NO_MX_RECORD'), + ), + array( 'empty' => '', 'allowed' => 'foobar@example.com', 'invalid' => 'fööbar@example.com', @@ -58,15 +67,6 @@ class phpbb_functions_validate_email_test extends phpbb_database_test_case 'taken' => array('email'), 'banned' => array('email'), 'no_mx' => array('email'), - ), - array( - 'empty' => array(), - 'allowed' => array(), - 'invalid' => array('EMAIL_INVALID'), - 'valid_complex' => array(), - 'taken' => array('EMAIL_TAKEN'), - 'banned' => array('EMAIL_BANNED'), - 'no_mx' => array('DOMAIN_NO_MX_RECORD'), )); } } diff --git a/tests/functions/validate_lang_iso_test.php b/tests/functions/validate_lang_iso_test.php index b8a1827432..baf75108b7 100644 --- a/tests/functions/validate_lang_iso_test.php +++ b/tests/functions/validate_lang_iso_test.php @@ -8,12 +8,12 @@ */ require_once dirname(__FILE__) . '/../../phpBB/includes/functions_user.php'; -require_once dirname(__FILE__) . '/common_validate_data.php'; +require_once dirname(__FILE__) . '/validate_data_helper.php'; class phpbb_functions_validate_lang_iso_test extends phpbb_database_test_case { protected $db; - protected $common; + protected $helper; public function getDataSet() { @@ -25,7 +25,7 @@ class phpbb_functions_validate_lang_iso_test extends phpbb_database_test_case parent::setUp(); $this->db = $this->new_dbal(); - $this->common = new phpbb_functions_common_validate_data; + $this->helper = new phpbb_functions_validate_data_helper($this); } public function test_validate_lang_iso() @@ -34,7 +34,13 @@ class phpbb_functions_validate_lang_iso_test extends phpbb_database_test_case $db = $this->db; - $this->common->validate_data_check(array( + $this->helper->assert_validate_data(array( + 'empty' => array('WRONG_DATA'), + 'en' => array(), + 'cs' => array(), + 'de' => array('WRONG_DATA'), + ), + array( 'empty' => '', 'en' => 'en', 'cs' => 'cs', @@ -45,12 +51,6 @@ class phpbb_functions_validate_lang_iso_test extends phpbb_database_test_case 'en' => array('language_iso_name'), 'cs' => array('language_iso_name'), 'de' => array('language_iso_name'), - ), - array( - 'empty' => array('WRONG_DATA'), - 'en' => array(), - 'cs' => array(), - 'de' => array('WRONG_DATA'), )); } } diff --git a/tests/functions/validate_username_test.php b/tests/functions/validate_username_test.php index 656248cec3..92c5ba6ee1 100644 --- a/tests/functions/validate_username_test.php +++ b/tests/functions/validate_username_test.php @@ -10,13 +10,13 @@ require_once dirname(__FILE__) . '/../../phpBB/includes/functions_user.php'; require_once dirname(__FILE__) . '/../../phpBB/includes/utf/utf_tools.php'; require_once dirname(__FILE__) . '/../mock/cache.php'; -require_once dirname(__FILE__) . '/common_validate_data.php'; +require_once dirname(__FILE__) . '/validate_data_helper.php'; class phpbb_functions_validate_data_test extends phpbb_database_test_case { protected $db; protected $cache; - protected $common; + protected $helper; public function getDataSet() { @@ -29,7 +29,7 @@ class phpbb_functions_validate_data_test extends phpbb_database_test_case $this->db = $this->new_dbal(); $this->cache = new phpbb_mock_cache; - $this->common = new phpbb_functions_common_validate_data; + $this->helper = new phpbb_functions_validate_data_helper($this); } public function validate_username_data() @@ -129,7 +129,7 @@ class phpbb_functions_validate_data_test extends phpbb_database_test_case $config['allow_name_chars'] = $allow_name_chars; - $this->common->validate_data_check(array( + $this->helper->assert_validate_data($expected, array( 'foobar_allow' => 'foobar', 'foobar_ascii' => 'foobar', 'foobar_any' => 'f*~*^=oo_bar1', @@ -154,7 +154,6 @@ class phpbb_functions_validate_data_test extends phpbb_database_test_case 'barfoo_disallow' => array('username'), 'admin_taken' => array('username'), 'group_taken' => array('username'), - ), - $expected); + )); } } -- cgit v1.2.1 From c2bc82ebfd54cebba03bd04dccaf5a8e317844ae Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Mon, 3 Jun 2013 16:15:08 +0200 Subject: [ticket/11579] Move simple tests into seperate files PHPBB3-11579 --- tests/functions/validate_data_simple_test.php | 251 -------------------------- tests/functions/validate_date_test.php | 66 +++++++ tests/functions/validate_jabber_test.php | 63 +++++++ tests/functions/validate_match_test.php | 45 +++++ tests/functions/validate_num_test.php | 51 ++++++ tests/functions/validate_password_test.php | 83 +++++++++ tests/functions/validate_string_test.php | 58 ++++++ 7 files changed, 366 insertions(+), 251 deletions(-) delete mode 100644 tests/functions/validate_data_simple_test.php create mode 100644 tests/functions/validate_date_test.php create mode 100644 tests/functions/validate_jabber_test.php create mode 100644 tests/functions/validate_match_test.php create mode 100644 tests/functions/validate_num_test.php create mode 100644 tests/functions/validate_password_test.php create mode 100644 tests/functions/validate_string_test.php (limited to 'tests') diff --git a/tests/functions/validate_data_simple_test.php b/tests/functions/validate_data_simple_test.php deleted file mode 100644 index db4f218eed..0000000000 --- a/tests/functions/validate_data_simple_test.php +++ /dev/null @@ -1,251 +0,0 @@ -helper = new phpbb_functions_validate_data_helper($this); - } - - public function test_validate_string() - { - $this->helper->assert_validate_data(array( - 'empty_opt' => array(), - 'empty' => array(), - 'foo' => array(), - 'foo_minmax_correct' => array(), - 'foo_minmax_short' => array('TOO_SHORT'), - 'foo_minmax_long' => array('TOO_LONG'), - 'empty_short' => array('TOO_SHORT'), - 'empty_length_opt' => array(), - ), - array( - 'empty_opt' => '', - 'empty' => '', - 'foo' => 'foobar', - 'foo_minmax_correct' => 'foobar', - 'foo_minmax_short' => 'foobar', - 'foo_minmax_long' => 'foobar', - 'empty_short' => '', - 'empty_length_opt' => '', - ), - array( - 'empty_opt' => array('string', true), - 'empty' => array('string'), - 'foo' => array('string'), - 'foo_minmax_correct' => array('string', false, 2, 6), - 'foo_minmax_short' => array('string', false, 7, 9), - 'foo_minmax_long' => array('string', false, 2, 5), - 'empty_short' => array('string', false, 1, 6), - 'empty_length_opt' => array('string', true, 1, 6), - )); - } - - public function test_validate_num() - { - $this->helper->assert_validate_data(array( - 'empty' => array(), - 'zero' => array(), - 'five_minmax_correct' => array(), - 'five_minmax_short' => array('TOO_SMALL'), - 'five_minmax_long' => array('TOO_LARGE'), - 'string' => array(), - ), - array( - 'empty' => '', - 'zero' => 0, - 'five_minmax_correct' => 5, - 'five_minmax_short' => 5, - 'five_minmax_long' => 5, - 'string' => 'foobar', - ), - array( - 'empty' => array('num'), - 'zero' => array('num'), - 'five_minmax_correct' => array('num', false, 2, 6), - 'five_minmax_short' => array('num', false, 7, 10), - 'five_minmax_long' => array('num', false, 2, 3), - 'string' => array('num'), - )); - } - - public function test_validate_date() - { - $this->helper->assert_validate_data(array( - 'empty' => array('INVALID'), - 'empty_opt' => array(), - 'double_single' => array(), - 'single_single' => array(), - 'double_double' => array(), - // Currently fails - //'zero_year' => array(), - 'month_high' => array('INVALID'), - 'month_low' => array('INVALID'), - 'day_high' => array('INVALID'), - 'day_low' => array('INVALID'), - ), - array( - 'empty' => '', - 'empty_opt' => '', - 'double_single' => '17-06-1990', - 'single_single' => '05-05-2009', - 'double_double' => '17-12-1990', - // Currently fails - //'zero_year' => '01-01-0000', - 'month_high' => '17-17-1990', - 'month_low' => '01-00-1990', - 'day_high' => '64-01-1990', - 'day_low' => '00-12-1990', - ), - array( - 'empty' => array('date'), - 'empty_opt' => array('date', true), - 'double_single' => array('date'), - 'single_single' => array('date'), - 'double_double' => array('date'), - // Currently fails - //'zero_year' => array('date'), - 'month_high' => array('date'), - 'month_low' => array('date'), - 'day_high' => array('date'), - 'day_low' => array('date'), - )); - } - - public function test_validate_match() - { - $this->helper->assert_validate_data(array( - 'empty_opt' => array(), - 'empty_empty_match' => array(), - 'foobar' => array(), - 'foobar_fail' => array('WRONG_DATA'), - ), - array( - 'empty_opt' => '', - 'empty_empty_match' => '', - 'foobar' => 'foobar', - 'foobar_fail' => 'foobar123', - ), - array( - 'empty_opt' => array('match', true, '/[a-z]$/'), - 'empty_empty_match' => array('match'), - 'foobar' => array('match', false, '/[a-z]$/'), - 'foobar_fail' => array('match', false, '/[a-z]$/'), - )); - } - - public function validate_password_data() - { - return array( - array('PASS_TYPE_ANY', array( - 'empty' => array(), - 'foobar_any' => array(), - 'foobar_mixed' => array(), - 'foobar_alpha' => array(), - 'foobar_symbol' => array(), - )), - array('PASS_TYPE_CASE', array( - 'empty' => array(), - 'foobar_any' => array('INVALID_CHARS'), - 'foobar_mixed' => array(), - 'foobar_alpha' => array(), - 'foobar_symbol' => array(), - )), - array('PASS_TYPE_ALPHA', array( - 'empty' => array(), - 'foobar_any' => array('INVALID_CHARS'), - 'foobar_mixed' => array('INVALID_CHARS'), - 'foobar_alpha' => array(), - 'foobar_symbol' => array(), - )), - array('PASS_TYPE_SYMBOL', array( - 'empty' => array(), - 'foobar_any' => array('INVALID_CHARS'), - 'foobar_mixed' => array('INVALID_CHARS'), - 'foobar_alpha' => array('INVALID_CHARS'), - 'foobar_symbol' => array(), - )), - ); - } - - /** - * @dataProvider validate_password_data - */ - public function test_validate_password($pass_complexity, $expected) - { - global $config; - - // Set complexity to mixed case letters, numbers and symbols - $config['pass_complex'] = $pass_complexity; - - $this->helper->assert_validate_data($expected, array( - 'empty' => '', - 'foobar_any' => 'foobar', - 'foobar_mixed' => 'FooBar', - 'foobar_alpha' => 'F00bar', - 'foobar_symbol' => 'fooBar123*', - ), - array( - 'empty' => array('password'), - 'foobar_any' => array('password'), - 'foobar_mixed' => array('password'), - 'foobar_alpha' => array('password'), - 'foobar_symbol' => array('password'), - )); - } - - public function test_validate_jabber() - { - $this->helper->assert_validate_data(array( - 'empty' => array(), - 'no_seperator' => array('WRONG_DATA'), - 'no_user' => array('WRONG_DATA'), - 'no_realm' => array('WRONG_DATA'), - 'dot_realm' => array('WRONG_DATA'), - '-realm' => array('WRONG_DATA'), - 'realm-' => array('WRONG_DATA'), - 'correct' => array(), - 'prohibited' => array('WRONG_DATA'), - 'prohibited_char' => array('WRONG_DATA'), - ), - array( - 'empty' => '', - 'no_seperator' => 'testjabber.ccc', - 'no_user' => '@jabber.ccc', - 'no_realm' => 'user@', - 'dot_realm' => 'user@.....', - '-realm' => 'user@-jabber.ccc', - 'realm-' => 'user@jabber.ccc-', - 'correct' => 'user@jabber.09A-z.org', - 'prohibited' => 'u@ser@jabber.ccc.org', - 'prohibited_char' => 'uer@jabber.ccc.org', - ), - array( - 'empty' => array('jabber'), - 'no_seperator' => array('jabber'), - 'no_user' => array('jabber'), - 'no_realm' => array('jabber'), - 'dot_realm' => array('jabber'), - '-realm' => array('jabber'), - 'realm-' => array('jabber'), - 'correct' => array('jabber'), - 'prohibited' => array('jabber'), - 'prohibited_char' => array('jabber'), - )); - } -} diff --git a/tests/functions/validate_date_test.php b/tests/functions/validate_date_test.php new file mode 100644 index 0000000000..e7a279879c --- /dev/null +++ b/tests/functions/validate_date_test.php @@ -0,0 +1,66 @@ +helper = new phpbb_functions_validate_data_helper($this); + } + + public function test_validate_date() + { + $this->helper->assert_validate_data(array( + 'empty' => array('INVALID'), + 'empty_opt' => array(), + 'double_single' => array(), + 'single_single' => array(), + 'double_double' => array(), + // Currently fails + //'zero_year' => array(), + 'month_high' => array('INVALID'), + 'month_low' => array('INVALID'), + 'day_high' => array('INVALID'), + 'day_low' => array('INVALID'), + ), + array( + 'empty' => '', + 'empty_opt' => '', + 'double_single' => '17-06-1990', + 'single_single' => '05-05-2009', + 'double_double' => '17-12-1990', + // Currently fails + //'zero_year' => '01-01-0000', + 'month_high' => '17-17-1990', + 'month_low' => '01-00-1990', + 'day_high' => '64-01-1990', + 'day_low' => '00-12-1990', + ), + array( + 'empty' => array('date'), + 'empty_opt' => array('date', true), + 'double_single' => array('date'), + 'single_single' => array('date'), + 'double_double' => array('date'), + // Currently fails + //'zero_year' => array('date'), + 'month_high' => array('date'), + 'month_low' => array('date'), + 'day_high' => array('date'), + 'day_low' => array('date'), + )); + } +} diff --git a/tests/functions/validate_jabber_test.php b/tests/functions/validate_jabber_test.php new file mode 100644 index 0000000000..551b243f81 --- /dev/null +++ b/tests/functions/validate_jabber_test.php @@ -0,0 +1,63 @@ +helper = new phpbb_functions_validate_data_helper($this); + } + + public function test_validate_jabber() + { + $this->helper->assert_validate_data(array( + 'empty' => array(), + 'no_seperator' => array('WRONG_DATA'), + 'no_user' => array('WRONG_DATA'), + 'no_realm' => array('WRONG_DATA'), + 'dot_realm' => array('WRONG_DATA'), + '-realm' => array('WRONG_DATA'), + 'realm-' => array('WRONG_DATA'), + 'correct' => array(), + 'prohibited' => array('WRONG_DATA'), + 'prohibited_char' => array('WRONG_DATA'), + ), + array( + 'empty' => '', + 'no_seperator' => 'testjabber.ccc', + 'no_user' => '@jabber.ccc', + 'no_realm' => 'user@', + 'dot_realm' => 'user@.....', + '-realm' => 'user@-jabber.ccc', + 'realm-' => 'user@jabber.ccc-', + 'correct' => 'user@jabber.09A-z.org', + 'prohibited' => 'u@ser@jabber.ccc.org', + 'prohibited_char' => 'uer@jabber.ccc.org', + ), + array( + 'empty' => array('jabber'), + 'no_seperator' => array('jabber'), + 'no_user' => array('jabber'), + 'no_realm' => array('jabber'), + 'dot_realm' => array('jabber'), + '-realm' => array('jabber'), + 'realm-' => array('jabber'), + 'correct' => array('jabber'), + 'prohibited' => array('jabber'), + 'prohibited_char' => array('jabber'), + )); + } +} diff --git a/tests/functions/validate_match_test.php b/tests/functions/validate_match_test.php new file mode 100644 index 0000000000..5d44f1e00b --- /dev/null +++ b/tests/functions/validate_match_test.php @@ -0,0 +1,45 @@ +helper = new phpbb_functions_validate_data_helper($this); + } + + public function test_validate_match() + { + $this->helper->assert_validate_data(array( + 'empty_opt' => array(), + 'empty_empty_match' => array(), + 'foobar' => array(), + 'foobar_fail' => array('WRONG_DATA'), + ), + array( + 'empty_opt' => '', + 'empty_empty_match' => '', + 'foobar' => 'foobar', + 'foobar_fail' => 'foobar123', + ), + array( + 'empty_opt' => array('match', true, '/[a-z]$/'), + 'empty_empty_match' => array('match'), + 'foobar' => array('match', false, '/[a-z]$/'), + 'foobar_fail' => array('match', false, '/[a-z]$/'), + )); + } +} diff --git a/tests/functions/validate_num_test.php b/tests/functions/validate_num_test.php new file mode 100644 index 0000000000..4e210ba29a --- /dev/null +++ b/tests/functions/validate_num_test.php @@ -0,0 +1,51 @@ +helper = new phpbb_functions_validate_data_helper($this); + } + + public function test_validate_num() + { + $this->helper->assert_validate_data(array( + 'empty' => array(), + 'zero' => array(), + 'five_minmax_correct' => array(), + 'five_minmax_short' => array('TOO_SMALL'), + 'five_minmax_long' => array('TOO_LARGE'), + 'string' => array(), + ), + array( + 'empty' => '', + 'zero' => 0, + 'five_minmax_correct' => 5, + 'five_minmax_short' => 5, + 'five_minmax_long' => 5, + 'string' => 'foobar', + ), + array( + 'empty' => array('num'), + 'zero' => array('num'), + 'five_minmax_correct' => array('num', false, 2, 6), + 'five_minmax_short' => array('num', false, 7, 10), + 'five_minmax_long' => array('num', false, 2, 3), + 'string' => array('num'), + )); + } +} diff --git a/tests/functions/validate_password_test.php b/tests/functions/validate_password_test.php new file mode 100644 index 0000000000..e8dc7e0dea --- /dev/null +++ b/tests/functions/validate_password_test.php @@ -0,0 +1,83 @@ +helper = new phpbb_functions_validate_data_helper($this); + } + + public function validate_password_data() + { + return array( + array('PASS_TYPE_ANY', array( + 'empty' => array(), + 'foobar_any' => array(), + 'foobar_mixed' => array(), + 'foobar_alpha' => array(), + 'foobar_symbol' => array(), + )), + array('PASS_TYPE_CASE', array( + 'empty' => array(), + 'foobar_any' => array('INVALID_CHARS'), + 'foobar_mixed' => array(), + 'foobar_alpha' => array(), + 'foobar_symbol' => array(), + )), + array('PASS_TYPE_ALPHA', array( + 'empty' => array(), + 'foobar_any' => array('INVALID_CHARS'), + 'foobar_mixed' => array('INVALID_CHARS'), + 'foobar_alpha' => array(), + 'foobar_symbol' => array(), + )), + array('PASS_TYPE_SYMBOL', array( + 'empty' => array(), + 'foobar_any' => array('INVALID_CHARS'), + 'foobar_mixed' => array('INVALID_CHARS'), + 'foobar_alpha' => array('INVALID_CHARS'), + 'foobar_symbol' => array(), + )), + ); + } + + /** + * @dataProvider validate_password_data + */ + public function test_validate_password($pass_complexity, $expected) + { + global $config; + + // Set complexity to mixed case letters, numbers and symbols + $config['pass_complex'] = $pass_complexity; + + $this->helper->assert_validate_data($expected, array( + 'empty' => '', + 'foobar_any' => 'foobar', + 'foobar_mixed' => 'FooBar', + 'foobar_alpha' => 'F00bar', + 'foobar_symbol' => 'fooBar123*', + ), + array( + 'empty' => array('password'), + 'foobar_any' => array('password'), + 'foobar_mixed' => array('password'), + 'foobar_alpha' => array('password'), + 'foobar_symbol' => array('password'), + )); + } +} diff --git a/tests/functions/validate_string_test.php b/tests/functions/validate_string_test.php new file mode 100644 index 0000000000..2b4f7321a6 --- /dev/null +++ b/tests/functions/validate_string_test.php @@ -0,0 +1,58 @@ +helper = new phpbb_functions_validate_data_helper($this); + } + + public function test_validate_string() + { + $this->helper->assert_validate_data(array( + 'empty_opt' => array(), + 'empty' => array(), + 'foo' => array(), + 'foo_minmax_correct' => array(), + 'foo_minmax_short' => array('TOO_SHORT'), + 'foo_minmax_long' => array('TOO_LONG'), + 'empty_short' => array('TOO_SHORT'), + 'empty_length_opt' => array(), + ), + array( + 'empty_opt' => '', + 'empty' => '', + 'foo' => 'foobar', + 'foo_minmax_correct' => 'foobar', + 'foo_minmax_short' => 'foobar', + 'foo_minmax_long' => 'foobar', + 'empty_short' => '', + 'empty_length_opt' => '', + ), + array( + 'empty_opt' => array('string', true), + 'empty' => array('string'), + 'foo' => array('string'), + 'foo_minmax_correct' => array('string', false, 2, 6), + 'foo_minmax_short' => array('string', false, 7, 9), + 'foo_minmax_long' => array('string', false, 2, 5), + 'empty_short' => array('string', false, 1, 6), + 'empty_length_opt' => array('string', true, 1, 6), + )); + } +} -- cgit v1.2.1 From 11678678b810c26376728166cf334550cbc30124 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Mon, 3 Jun 2013 21:30:13 +0200 Subject: [ticket/11579] Rework calls to validate_data_helper PHPBB3-11579 --- tests/functions/validate_data_helper.php | 18 +++--- tests/functions/validate_date_test.php | 90 ++++++++++++++++++------------ tests/functions/validate_email_test.php | 62 +++++++++++--------- tests/functions/validate_jabber_test.php | 86 ++++++++++++++++------------ tests/functions/validate_lang_iso_test.php | 38 +++++++------ tests/functions/validate_match_test.php | 38 +++++++------ tests/functions/validate_num_test.php | 54 ++++++++++-------- tests/functions/validate_password_test.php | 39 ++++++++----- tests/functions/validate_string_test.php | 70 +++++++++++++---------- tests/functions/validate_username_test.php | 81 ++++++++++++++++++--------- 10 files changed, 344 insertions(+), 232 deletions(-) (limited to 'tests') diff --git a/tests/functions/validate_data_helper.php b/tests/functions/validate_data_helper.php index b8e8bfded3..94ddf60429 100644 --- a/tests/functions/validate_data_helper.php +++ b/tests/functions/validate_data_helper.php @@ -20,19 +20,17 @@ class phpbb_functions_validate_data_helper extends PHPUnit_Framework_TestCase * Test provided input data with supplied checks and compare to expected * results * - * @param array $expected Array containing the expected results. Either - * an array containing the error message or the an empty - * array if input is correct - * @param array $input Input data with specific array keys that need to - * be matched by the ones in the other 2 params - * @param array $validate_check Array containing validate_data check - * settings, i.e. array('foobar' => array('string')) + * @param array $data Array containing one or more subarrays with the + * test data. The first element of a subarray is the + * expected result, the second one is the input, and the + * third is the data that should be passed to the function + * validate_data(). */ - public function assert_validate_data($expected, $input, $validate_check) + public function assert_valid_data($data) { - foreach ($input as $key => $data) + foreach ($data as $key => $test) { - $this->test_case->assertEquals($expected[$key], validate_data(array($data), array($validate_check[$key]))); + $this->test_case->assertEquals($test[0], validate_data(array($test[1]), array($test[2]))); } } } diff --git a/tests/functions/validate_date_test.php b/tests/functions/validate_date_test.php index e7a279879c..1dcd1361a2 100644 --- a/tests/functions/validate_date_test.php +++ b/tests/functions/validate_date_test.php @@ -23,44 +23,60 @@ class phpbb_functions_validate_date_test extends phpbb_test_case public function test_validate_date() { - $this->helper->assert_validate_data(array( - 'empty' => array('INVALID'), - 'empty_opt' => array(), - 'double_single' => array(), - 'single_single' => array(), - 'double_double' => array(), + $this->helper->assert_valid_data(array( + 'empty' => array( + array('INVALID'), + '', + array('date'), + ), + 'empty_opt' => array( + array(), + '', + array('date', true), + ), + 'double_single' => array( + array(), + '17-06-1990', + array('date'), + ), + 'single_single' => array( + array(), + '05-05-2009', + array('date'), + ), + 'double_double' => array( + array(), + '17-12-1990', + array('date'), + ), + 'month_high' => array( + array('INVALID'), + '17-17-1990', + array('date'), + ), + 'month_low' => array( + array('INVALID'), + '01-00-1990', + array('date'), + ), + 'day_high' => array( + array('INVALID'), + '64-01-1990', + array('date'), + ), + 'day_low' => array( + array('INVALID'), + '00-12-1990', + array('date'), + ), // Currently fails - //'zero_year' => array(), - 'month_high' => array('INVALID'), - 'month_low' => array('INVALID'), - 'day_high' => array('INVALID'), - 'day_low' => array('INVALID'), - ), - array( - 'empty' => '', - 'empty_opt' => '', - 'double_single' => '17-06-1990', - 'single_single' => '05-05-2009', - 'double_double' => '17-12-1990', - // Currently fails - //'zero_year' => '01-01-0000', - 'month_high' => '17-17-1990', - 'month_low' => '01-00-1990', - 'day_high' => '64-01-1990', - 'day_low' => '00-12-1990', - ), - array( - 'empty' => array('date'), - 'empty_opt' => array('date', true), - 'double_single' => array('date'), - 'single_single' => array('date'), - 'double_double' => array('date'), - // Currently fails - //'zero_year' => array('date'), - 'month_high' => array('date'), - 'month_low' => array('date'), - 'day_high' => array('date'), - 'day_low' => array('date'), + /* + 'zero_year' => array( + array(), + '01-01-0000', + array('date'), + ), + */ )); } } diff --git a/tests/functions/validate_email_test.php b/tests/functions/validate_email_test.php index 2e81d3277e..93b5ba0896 100644 --- a/tests/functions/validate_email_test.php +++ b/tests/functions/validate_email_test.php @@ -41,32 +41,42 @@ class phpbb_functions_validate_email_test extends phpbb_database_test_case $user = $this->user; $user->optionset('banned_users', array('banned@example.com')); - $this->helper->assert_validate_data(array( - 'empty' => array(), - 'allowed' => array(), - 'invalid' => array('EMAIL_INVALID'), - 'valid_complex' => array(), - 'taken' => array('EMAIL_TAKEN'), - 'banned' => array('EMAIL_BANNED'), - 'no_mx' => array('DOMAIN_NO_MX_RECORD'), - ), - array( - 'empty' => '', - 'allowed' => 'foobar@example.com', - 'invalid' => 'fööbar@example.com', - 'valid_complex' => "'%$~test@example.com", - 'taken' => 'admin@example.com', - 'banned' => 'banned@example.com', - 'no_mx' => 'test@wwrrrhhghgghgh.ttv', - ), - array( - 'empty' => array('email'), - 'allowed' => array('email', 'foobar@example.com'), - 'invalid' => array('email'), - 'valid_complex' => array('email'), - 'taken' => array('email'), - 'banned' => array('email'), - 'no_mx' => array('email'), + $this->helper->assert_valid_data(array( + 'empty' => array( + array(), + '', + array('email'), + ), + 'allowed' => array( + array(), + 'foobar@example.com', + array('email', 'foobar@example.com'), + ), + 'invalid' => array( + array('EMAIL_INVALID'), + 'fööbar@example.com', + array('email'), + ), + 'valid_complex' => array( + array(), + "'%$~test@example.com", + array('email'), + ), + 'taken' => array( + array('EMAIL_TAKEN'), + 'admin@example.com', + array('email'), + ), + 'banned' => array( + array('EMAIL_BANNED'), + 'banned@example.com', + array('email'), + ), + 'no_mx' => array( + array('DOMAIN_NO_MX_RECORD'), + 'test@wwrrrhhghgghgh.ttv', + array('email'), + ), )); } } diff --git a/tests/functions/validate_jabber_test.php b/tests/functions/validate_jabber_test.php index 551b243f81..5a53c963bd 100644 --- a/tests/functions/validate_jabber_test.php +++ b/tests/functions/validate_jabber_test.php @@ -23,41 +23,57 @@ class phpbb_functions_validate_jabber_test extends phpbb_test_case public function test_validate_jabber() { - $this->helper->assert_validate_data(array( - 'empty' => array(), - 'no_seperator' => array('WRONG_DATA'), - 'no_user' => array('WRONG_DATA'), - 'no_realm' => array('WRONG_DATA'), - 'dot_realm' => array('WRONG_DATA'), - '-realm' => array('WRONG_DATA'), - 'realm-' => array('WRONG_DATA'), - 'correct' => array(), - 'prohibited' => array('WRONG_DATA'), - 'prohibited_char' => array('WRONG_DATA'), - ), - array( - 'empty' => '', - 'no_seperator' => 'testjabber.ccc', - 'no_user' => '@jabber.ccc', - 'no_realm' => 'user@', - 'dot_realm' => 'user@.....', - '-realm' => 'user@-jabber.ccc', - 'realm-' => 'user@jabber.ccc-', - 'correct' => 'user@jabber.09A-z.org', - 'prohibited' => 'u@ser@jabber.ccc.org', - 'prohibited_char' => 'uer@jabber.ccc.org', - ), - array( - 'empty' => array('jabber'), - 'no_seperator' => array('jabber'), - 'no_user' => array('jabber'), - 'no_realm' => array('jabber'), - 'dot_realm' => array('jabber'), - '-realm' => array('jabber'), - 'realm-' => array('jabber'), - 'correct' => array('jabber'), - 'prohibited' => array('jabber'), - 'prohibited_char' => array('jabber'), + $this->helper->assert_valid_data(array( + 'empty' => array( + array(), + '', + array('jabber'), + ), + 'no_seperator' => array( + array('WRONG_DATA'), + 'testjabber.ccc', + array('jabber'), + ), + 'no_user' => array( + array('WRONG_DATA'), + '@jabber.ccc', + array('jabber'), + ), + 'no_realm' => array( + array('WRONG_DATA'), + 'user@', + array('jabber'), + ), + 'dot_realm' => array( + array('WRONG_DATA'), + 'user@.....', + array('jabber'), + ), + '-realm' => array( + array('WRONG_DATA'), + 'user@-jabber.ccc', + array('jabber'), + ), + 'realm-' => array( + array('WRONG_DATA'), + 'user@jabber.ccc-', + array('jabber'), + ), + 'correct' => array( + array(), + 'user@jabber.09A-z.org', + array('jabber'), + ), + 'prohibited' => array( + array('WRONG_DATA'), + 'u@ser@jabber.ccc.org', + array('jabber'), + ), + 'prohibited_char' => array( + array('WRONG_DATA'), + 'uer@jabber.ccc.org', + array('jabber'), + ), )); } } diff --git a/tests/functions/validate_lang_iso_test.php b/tests/functions/validate_lang_iso_test.php index baf75108b7..c8a5b71021 100644 --- a/tests/functions/validate_lang_iso_test.php +++ b/tests/functions/validate_lang_iso_test.php @@ -34,23 +34,27 @@ class phpbb_functions_validate_lang_iso_test extends phpbb_database_test_case $db = $this->db; - $this->helper->assert_validate_data(array( - 'empty' => array('WRONG_DATA'), - 'en' => array(), - 'cs' => array(), - 'de' => array('WRONG_DATA'), - ), - array( - 'empty' => '', - 'en' => 'en', - 'cs' => 'cs', - 'de' => 'de', - ), - array( - 'empty' => array('language_iso_name'), - 'en' => array('language_iso_name'), - 'cs' => array('language_iso_name'), - 'de' => array('language_iso_name'), + $this->helper->assert_valid_data(array( + 'empty' => array( + array('WRONG_DATA'), + '', + array('language_iso_name'), + ), + 'en' => array( + array(), + 'en', + array('language_iso_name'), + ), + 'cs' => array( + array(), + 'cs', + array('language_iso_name'), + ), + 'de' => array( + array('WRONG_DATA'), + 'de', + array('language_iso_name'), + ), )); } } diff --git a/tests/functions/validate_match_test.php b/tests/functions/validate_match_test.php index 5d44f1e00b..73a363e003 100644 --- a/tests/functions/validate_match_test.php +++ b/tests/functions/validate_match_test.php @@ -23,23 +23,27 @@ class phpbb_functions_validate_match_test extends phpbb_test_case public function test_validate_match() { - $this->helper->assert_validate_data(array( - 'empty_opt' => array(), - 'empty_empty_match' => array(), - 'foobar' => array(), - 'foobar_fail' => array('WRONG_DATA'), - ), - array( - 'empty_opt' => '', - 'empty_empty_match' => '', - 'foobar' => 'foobar', - 'foobar_fail' => 'foobar123', - ), - array( - 'empty_opt' => array('match', true, '/[a-z]$/'), - 'empty_empty_match' => array('match'), - 'foobar' => array('match', false, '/[a-z]$/'), - 'foobar_fail' => array('match', false, '/[a-z]$/'), + $this->helper->assert_valid_data(array( + 'empty_opt' => array( + array(), + '', + array('match', true, '/[a-z]$/'), + ), + 'empty_empty_match' => array( + array(), + '', + array('match'), + ), + 'foobar' => array( + array(), + 'foobar', + array('match', false, '/[a-z]$/'), + ), + 'foobar_fail' => array( + array('WRONG_DATA'), + 'foobar123', + array('match', false, '/[a-z]$/'), + ), )); } } diff --git a/tests/functions/validate_num_test.php b/tests/functions/validate_num_test.php index 4e210ba29a..4deac02ebc 100644 --- a/tests/functions/validate_num_test.php +++ b/tests/functions/validate_num_test.php @@ -23,29 +23,37 @@ class phpbb_functions_validate_num_test extends phpbb_test_case public function test_validate_num() { - $this->helper->assert_validate_data(array( - 'empty' => array(), - 'zero' => array(), - 'five_minmax_correct' => array(), - 'five_minmax_short' => array('TOO_SMALL'), - 'five_minmax_long' => array('TOO_LARGE'), - 'string' => array(), - ), - array( - 'empty' => '', - 'zero' => 0, - 'five_minmax_correct' => 5, - 'five_minmax_short' => 5, - 'five_minmax_long' => 5, - 'string' => 'foobar', - ), - array( - 'empty' => array('num'), - 'zero' => array('num'), - 'five_minmax_correct' => array('num', false, 2, 6), - 'five_minmax_short' => array('num', false, 7, 10), - 'five_minmax_long' => array('num', false, 2, 3), - 'string' => array('num'), + $this->helper->assert_valid_data(array( + 'empty' => array( + array(), + '', + array('num'), + ), + 'zero' => array( + array(), + '0', + array('num'), + ), + 'five_minmax_correct' => array( + array(), + '5', + array('num', false, 2, 6), + ), + 'five_minmax_short' => array( + array('TOO_SMALL'), + '5', + array('num', false, 7, 10), + ), + 'five_minmax_long' => array( + array('TOO_LARGE'), + '5', + array('num', false, 2, 3), + ), + 'string' => array( + array(), + 'foobar', + array('num'), + ), )); } } diff --git a/tests/functions/validate_password_test.php b/tests/functions/validate_password_test.php index e8dc7e0dea..4639f6cc89 100644 --- a/tests/functions/validate_password_test.php +++ b/tests/functions/validate_password_test.php @@ -65,19 +65,32 @@ class phpbb_functions_validate_password_test extends phpbb_test_case // Set complexity to mixed case letters, numbers and symbols $config['pass_complex'] = $pass_complexity; - $this->helper->assert_validate_data($expected, array( - 'empty' => '', - 'foobar_any' => 'foobar', - 'foobar_mixed' => 'FooBar', - 'foobar_alpha' => 'F00bar', - 'foobar_symbol' => 'fooBar123*', - ), - array( - 'empty' => array('password'), - 'foobar_any' => array('password'), - 'foobar_mixed' => array('password'), - 'foobar_alpha' => array('password'), - 'foobar_symbol' => array('password'), + $this->helper->assert_valid_data(array( + 'empty' => array( + $expected['empty'], + '', + array('password'), + ), + 'foobar_any' => array( + $expected['foobar_any'], + 'foobar', + array('password'), + ), + 'foobar_mixed' => array( + $expected['foobar_mixed'], + 'FooBar', + array('password'), + ), + 'foobar_alpha' => array( + $expected['foobar_alpha'], + 'F00bar', + array('password'), + ), + 'foobar_symbol' => array( + $expected['foobar_symbol'], + 'fooBar123*', + array('password'), + ), )); } } diff --git a/tests/functions/validate_string_test.php b/tests/functions/validate_string_test.php index 2b4f7321a6..ab44c28541 100644 --- a/tests/functions/validate_string_test.php +++ b/tests/functions/validate_string_test.php @@ -24,35 +24,47 @@ class phpbb_functions_validate_string_test extends phpbb_test_case public function test_validate_string() { - $this->helper->assert_validate_data(array( - 'empty_opt' => array(), - 'empty' => array(), - 'foo' => array(), - 'foo_minmax_correct' => array(), - 'foo_minmax_short' => array('TOO_SHORT'), - 'foo_minmax_long' => array('TOO_LONG'), - 'empty_short' => array('TOO_SHORT'), - 'empty_length_opt' => array(), - ), - array( - 'empty_opt' => '', - 'empty' => '', - 'foo' => 'foobar', - 'foo_minmax_correct' => 'foobar', - 'foo_minmax_short' => 'foobar', - 'foo_minmax_long' => 'foobar', - 'empty_short' => '', - 'empty_length_opt' => '', - ), - array( - 'empty_opt' => array('string', true), - 'empty' => array('string'), - 'foo' => array('string'), - 'foo_minmax_correct' => array('string', false, 2, 6), - 'foo_minmax_short' => array('string', false, 7, 9), - 'foo_minmax_long' => array('string', false, 2, 5), - 'empty_short' => array('string', false, 1, 6), - 'empty_length_opt' => array('string', true, 1, 6), + $this->helper->assert_valid_data(array( + 'empty_opt' => array( + array(), + '', + array('string', true), + ), + 'empty' => array( + array(), + '', + array('string'), + ), + 'foo' => array( + array(), + 'foobar', + array('string'), + ), + 'foo_minmax_correct' => array( + array(), + 'foobar', + array('string', false, 2, 6), + ), + 'foo_minmax_short' => array( + array('TOO_SHORT'), + 'foobar', + array('string', false, 7, 9), + ), + 'foo_minmax_long' => array( + array('TOO_LONG'), + 'foobar', + array('string', false, 2, 5), + ), + 'empty_short' => array( + array('TOO_SHORT'), + '', + array('string', false, 1, 6), + ), + 'empty_length_opt' => array( + array(), + '', + array('string', true, 1, 6), + ), )); } } diff --git a/tests/functions/validate_username_test.php b/tests/functions/validate_username_test.php index 92c5ba6ee1..9adfb63812 100644 --- a/tests/functions/validate_username_test.php +++ b/tests/functions/validate_username_test.php @@ -129,31 +129,62 @@ class phpbb_functions_validate_data_test extends phpbb_database_test_case $config['allow_name_chars'] = $allow_name_chars; - $this->helper->assert_validate_data($expected, array( - 'foobar_allow' => 'foobar', - 'foobar_ascii' => 'foobar', - 'foobar_any' => 'f*~*^=oo_bar1', - 'foobar_alpha' => 'fo0Bar', - 'foobar_alpha_spacers' => 'Fo0-[B]_a+ R', - 'foobar_letter_num' => 'fo0Bar0', - 'foobar_letter_num_sp' => 'Fö0-[B]_a+ R', - 'foobar_quot' => '"foobar"', - 'barfoo_disallow' => 'barfoo', - 'admin_taken' => 'admin', - 'group_taken' => 'foobar_group', - ), - array( - 'foobar_allow' => array('username', 'foobar'), - 'foobar_ascii' => array('username'), - 'foobar_any' => array('username'), - 'foobar_alpha' => array('username'), - 'foobar_alpha_spacers' => array('username'), - 'foobar_letter_num' => array('username'), - 'foobar_letter_num_sp' => array('username'), - 'foobar_quot' => array('username'), - 'barfoo_disallow' => array('username'), - 'admin_taken' => array('username'), - 'group_taken' => array('username'), + $this->helper->assert_valid_data(array( + 'foobar_allow' => array( + $expected['foobar_allow'], + 'foobar', + array('username', 'foobar'), + ), + 'foobar_ascii' => array( + $expected['foobar_ascii'], + 'foobar', + array('username'), + ), + 'foobar_any' => array( + $expected['foobar_any'], + 'f*~*^=oo_bar1', + array('username'), + ), + 'foobar_alpha' => array( + $expected['foobar_alpha'], + 'fo0Bar', + array('username'), + ), + 'foobar_alpha_spacers' => array( + $expected['foobar_alpha_spacers'], + 'Fo0-[B]_a+ R', + array('username'), + ), + 'foobar_letter_num' => array( + $expected['foobar_letter_num'], + 'fo0Bar0', + array('username'), + ), + 'foobar_letter_num_sp' => array( + $expected['foobar_letter_num_sp'], + 'Fö0-[B]_a+ R', + array('username'), + ), + 'foobar_quot' => array( + $expected['foobar_quot'], + '"foobar"', + array('username'), + ), + 'barfoo_disallow' => array( + $expected['barfoo_disallow'], + 'barfoo', + array('username'), + ), + 'admin_taken' => array( + $expected['admin_taken'], + 'admin', + array('username'), + ), + 'group_taken' => array( + $expected['group_taken'], + 'foobar_group', + array('username'), + ), )); } } -- cgit v1.2.1 From b288bd441436c8dd3417f67013729732ca87939f Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Mon, 3 Jun 2013 21:33:02 +0200 Subject: [ticket/11579] Add missing commas to validate_username_test PHPBB3-11579 --- tests/functions/validate_username_test.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'tests') diff --git a/tests/functions/validate_username_test.php b/tests/functions/validate_username_test.php index 9adfb63812..0819974e54 100644 --- a/tests/functions/validate_username_test.php +++ b/tests/functions/validate_username_test.php @@ -46,7 +46,7 @@ class phpbb_functions_validate_data_test extends phpbb_database_test_case 'foobar_quot' => array('INVALID_CHARS'), 'barfoo_disallow' => array('USERNAME_DISALLOWED'), 'admin_taken' => array('USERNAME_TAKEN'), - 'group_taken' => array('USERNAME_TAKEN') + 'group_taken' => array('USERNAME_TAKEN'), )), array('USERNAME_ALPHA_ONLY', array( 'foobar_allow' => array(), @@ -59,7 +59,7 @@ class phpbb_functions_validate_data_test extends phpbb_database_test_case 'foobar_quot' => array('INVALID_CHARS'), 'barfoo_disallow' => array('USERNAME_DISALLOWED'), 'admin_taken' => array('USERNAME_TAKEN'), - 'group_taken' => array('INVALID_CHARS') + 'group_taken' => array('INVALID_CHARS'), )), array('USERNAME_ALPHA_SPACERS', array( 'foobar_allow' => array(), @@ -72,7 +72,7 @@ class phpbb_functions_validate_data_test extends phpbb_database_test_case 'foobar_quot' => array('INVALID_CHARS'), 'barfoo_disallow' => array('USERNAME_DISALLOWED'), 'admin_taken' => array('USERNAME_TAKEN'), - 'group_taken' => array('USERNAME_TAKEN') + 'group_taken' => array('USERNAME_TAKEN'), )), array('USERNAME_LETTER_NUM', array( 'foobar_allow' => array(), @@ -85,7 +85,7 @@ class phpbb_functions_validate_data_test extends phpbb_database_test_case 'foobar_quot' => array('INVALID_CHARS'), 'barfoo_disallow' => array('USERNAME_DISALLOWED'), 'admin_taken' => array('USERNAME_TAKEN'), - 'group_taken' => array('INVALID_CHARS') + 'group_taken' => array('INVALID_CHARS'), )), array('USERNAME_LETTER_NUM_SPACERS', array( 'foobar_allow' => array(), @@ -98,7 +98,7 @@ class phpbb_functions_validate_data_test extends phpbb_database_test_case 'foobar_quot' => array('INVALID_CHARS'), 'barfoo_disallow' => array('USERNAME_DISALLOWED'), 'admin_taken' => array('USERNAME_TAKEN'), - 'group_taken' => array('USERNAME_TAKEN') + 'group_taken' => array('USERNAME_TAKEN'), )), array('USERNAME_ASCII', array( 'foobar_allow' => array(), @@ -111,7 +111,7 @@ class phpbb_functions_validate_data_test extends phpbb_database_test_case 'foobar_quot' => array('INVALID_CHARS'), 'barfoo_disallow' => array('USERNAME_DISALLOWED'), 'admin_taken' => array('USERNAME_TAKEN'), - 'group_taken' => array('USERNAME_TAKEN') + 'group_taken' => array('USERNAME_TAKEN'), )), ); } -- cgit v1.2.1 From 71deb4dde7f0d92905c13b79c92b5ccc6beeb3c3 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Tue, 4 Jun 2013 17:16:22 +0200 Subject: [ticket/11538] Add admin as admins leader and moderator in memberlist_test Removing the admin user from the admin and moderator group in memberlist_test potentially breaks other tests, i.e. the ucp groups test. PHPBB3-11538 --- tests/functional/common_groups_test.php | 6 ------ tests/functional/memberlist_test.php | 12 ++++++++++++ tests/test_framework/phpbb_functional_test_case.php | 4 ++-- 3 files changed, 14 insertions(+), 8 deletions(-) (limited to 'tests') diff --git a/tests/functional/common_groups_test.php b/tests/functional/common_groups_test.php index cc6afa54b9..7ccd78421e 100644 --- a/tests/functional/common_groups_test.php +++ b/tests/functional/common_groups_test.php @@ -30,12 +30,6 @@ abstract class phpbb_functional_common_groups_test extends phpbb_functional_test */ public function test_groups_manage($input, $expected) { - $this->markTestIncomplete( - 'Test fails on develop due to another test deleting the Administrators group.' - ); - // See https://github.com/phpbb/phpbb3/pull/1407#issuecomment-18465480 - // and https://gist.github.com/bantu/22dc4f6c6c0b8f9e0fa1 - $this->login(); $this->admin_login(); $this->add_lang(array('ucp', 'acp/groups')); diff --git a/tests/functional/memberlist_test.php b/tests/functional/memberlist_test.php index 92ede8bd04..e9739f5f9a 100644 --- a/tests/functional/memberlist_test.php +++ b/tests/functional/memberlist_test.php @@ -95,5 +95,17 @@ class phpbb_functional_memberlist_test extends phpbb_functional_test_case $crawler = $this->get_memberlist_leaders_table_crawler(); $this->assertNotContains('memberlist-test-moderator', $crawler->eq(0)->text()); $this->assertContains('memberlist-test-moderator', $crawler->eq(1)->text()); + + // Add admin to moderators, should be visible as moderator + $this->add_user_group('GLOBAL_MODERATORS', array('admin'), true); + $crawler = $this->get_memberlist_leaders_table_crawler(); + $this->assertNotContains('admin', $crawler->eq(0)->text()); + $this->assertContains('admin', $crawler->eq(1)->text()); + + // Add admin to admins as leader, should be visible as admin, not moderator + $this->add_user_group('ADMINISTRATORS', array('admin'), true, true); + $crawler = $this->get_memberlist_leaders_table_crawler(); + $this->assertContains('admin', $crawler->eq(0)->text()); + $this->assertNotContains('admin', $crawler->eq(1)->text()); } } diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index 660234f3ed..923cb16d37 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -361,7 +361,7 @@ class phpbb_functional_test_case extends phpbb_test_case return group_user_del($group_id, false, $usernames, $group_name); } - protected function add_user_group($group_name, $usernames) + protected function add_user_group($group_name, $usernames, $default = false, $leader = false) { global $db, $cache, $auth, $config, $phpbb_dispatcher, $phpbb_log, $phpbb_container, $phpbb_root_path, $phpEx; @@ -400,7 +400,7 @@ class phpbb_functional_test_case extends phpbb_test_case $group_id = (int) $db->sql_fetchfield('group_id'); $db->sql_freeresult($result); - return group_user_add($group_id, false, $usernames, $group_name); + return group_user_add($group_id, false, $usernames, $group_name, $default, $leader); } protected function login($username = 'admin') -- cgit v1.2.1 From 495b22632c489f08c46f6712f917e920911e5759 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Tue, 4 Jun 2013 20:26:35 +0200 Subject: [ticket/11587] Add functional tests for group teampage settings The group_legend and group_teampage settings, which are needed for the teampage, are tested with these newly added functional tests. Duplicate code has been reduced as much as possible. PHPBB3-11587 --- tests/functional/acp_groups_test.php | 99 +++++++++++++++++++++++++++++++++ tests/functional/common_groups_test.php | 32 +++++++++-- tests/functional/ucp_groups_test.php | 32 +++++++++++ 3 files changed, 157 insertions(+), 6 deletions(-) (limited to 'tests') diff --git a/tests/functional/acp_groups_test.php b/tests/functional/acp_groups_test.php index 3d8cabb086..56132e24fb 100644 --- a/tests/functional/acp_groups_test.php +++ b/tests/functional/acp_groups_test.php @@ -14,8 +14,107 @@ require_once dirname(__FILE__) . '/common_groups_test.php'; */ class phpbb_functional_acp_groups_test extends phpbb_functional_common_groups_test { + protected $form_data; + protected function get_url() { return 'adm/index.php?i=groups&mode=manage&action=edit'; } + + public function acp_group_test_data() + { + return array( + 'both_yes' => array( + 5, + true, + true, + ), + 'legend_no_teampage' => array( + 5, + true, + false, + ), + 'no_legend_teampage' => array( + 5, + false, + true, + ), + 'both_no' => array( + 5, + false, + false, + ), + 'no_change' => array( + 5, + NULL, + NULL, + ), + 'back_to_default' => array( + 5, + true, + true, + ), + // Remove and add moderators back in order to reset + // group order to default one + 'mods_both_no' => array( + 4, + false, + false, + ), + 'mods_back_to_default' => array( + 4, + true, + true, + ), + ); + } + + /** + * @dataProvider acp_group_test_data + */ + public function test_acp_groups_teampage($group_id, $tick_legend, $tick_teampage) + { + $this->group_manage_login(); + + // Manage Administrators group + $form = $this->get_group_manage_form($group_id); + $this->form_data[0] = $form->getValues(); + + if (isset($tick_legend) && isset($tick_teampage)) + { + if ($tick_legend) + { + $form['group_legend']->tick(); + } + else + { + $form['group_legend']->untick(); + } + + if ($tick_teampage) + { + $form['group_teampage']->tick(); + } + else + { + $form['group_teampage']->untick(); + } + } + $crawler = $this->client->submit($form); + $this->assertContains($this->lang('GROUP_UPDATED'), $crawler->text()); + + $form = $this->get_group_manage_form($group_id); + if (!isset($tick_legend) && !isset($tick_teampage)) + { + $this->form_data[1] = $form->getValues(); + unset($this->form_data[0]['creation_time'], $this->form_data[0]['form_token'], $this->form_data[1]['creation_time'], $this->form_data[1]['form_token']); + $this->assertEquals($this->form_data[0], $this->form_data[1]); + } + else + { + $this->form_data = $form->getValues(); + $this->assertEquals($tick_legend, $this->form_data['group_legend']); + $this->assertEquals($tick_teampage, $this->form_data['group_teampage']); + } + } } diff --git a/tests/functional/common_groups_test.php b/tests/functional/common_groups_test.php index 7ccd78421e..53f7ead29a 100644 --- a/tests/functional/common_groups_test.php +++ b/tests/functional/common_groups_test.php @@ -14,6 +14,30 @@ abstract class phpbb_functional_common_groups_test extends phpbb_functional_test { abstract protected function get_url(); + /** + * Get group_manage form + * @param int $group_id ID of the group that should be managed + */ + protected function get_group_manage_form($group_id = 5) + { + // Manage Administrators group + $crawler = $this->request('GET', $this->get_url() . "&g=$group_id&sid=" . $this->sid); + $this->assert_response_success(); + //var_export($this->client->getResponse()->getContent()); + $form = $crawler->selectButton($this->lang('SUBMIT'))->form(); + return $form; + } + + /** + * Execute login calls and add_lang() calls for tests + */ + protected function group_manage_login() + { + $this->login(); + $this->admin_login(); + $this->add_lang(array('ucp', 'acp/groups')); + } + public function groups_manage_test_data() { return array( @@ -30,14 +54,10 @@ abstract class phpbb_functional_common_groups_test extends phpbb_functional_test */ public function test_groups_manage($input, $expected) { - $this->login(); - $this->admin_login(); - $this->add_lang(array('ucp', 'acp/groups')); + $this->group_manage_login(); // Manage Administrators group - $crawler = $this->request('GET', $this->get_url() . '&g=5&sid=' . $this->sid); - $this->assert_response_success(); - $form = $crawler->selectButton($this->lang('SUBMIT'))->form(); + $form = $this->get_group_manage_form(); $form['group_colour']->setValue($input); $crawler = $this->client->submit($form); $this->assertContains($this->lang($expected), $crawler->text()); diff --git a/tests/functional/ucp_groups_test.php b/tests/functional/ucp_groups_test.php index 9c6b1edc5e..a804d8f601 100644 --- a/tests/functional/ucp_groups_test.php +++ b/tests/functional/ucp_groups_test.php @@ -14,8 +14,40 @@ require_once dirname(__FILE__) . '/common_groups_test.php'; */ class phpbb_functional_ucp_groups_test extends phpbb_functional_common_groups_test { + protected $db; + protected function get_url() { return 'ucp.php?i=groups&mode=manage&action=edit'; } + + protected function get_teampage_settings() + { + if (!isset($this->db)) + { + $this->db = $this->get_db(); + } + $sql = 'SELECT g.group_legend AS group_legend, t.teampage_position AS group_teampage + FROM ' . GROUPS_TABLE . ' g + LEFT JOIN ' . TEAMPAGE_TABLE . ' t + ON (t.group_id = g.group_id) + WHERE g.group_id = 5'; + $result = $this->db->sql_query($sql); + $group_row = $this->db->sql_fetchrow($result); + $this->db->sql_freeresult($result); + return $group_row; + } + + public function test_ucp_groups_teampage() + { + $this->group_manage_login(); + + // Test if group_legend or group_teampage are modified while + // submitting the ucp_group_manage page + $form = $this->get_group_manage_form(); + $teampage_settings = $this->get_teampage_settings(); + $crawler = $this->client->submit($form); + $this->assertContains($this->lang('GROUP_UPDATED'), $crawler->text()); + $this->assertEquals($teampage_settings, $this->get_teampage_settings()); + } } -- cgit v1.2.1 From 7abc85cedac4fdde514f740dfaad24b2414ebce8 Mon Sep 17 00:00:00 2001 From: Dhruv Date: Wed, 5 Jun 2013 00:29:07 +0530 Subject: [ticket/10820] Change function call in tests PHPBB3-10820 --- tests/download/http_user_agent_test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/download/http_user_agent_test.php b/tests/download/http_user_agent_test.php index e08fb7a3f1..d85e7b0d08 100644 --- a/tests/download/http_user_agent_test.php +++ b/tests/download/http_user_agent_test.php @@ -92,6 +92,6 @@ class phpbb_download_http_user_agent_test extends phpbb_test_case */ public function test_is_greater_ie7($user_agent, $expected) { - $this->assertEquals($expected, phpbb_is_greater_ie7($user_agent)); + $this->assertEquals($expected, phpbb_is_greater_ie_version($user_agent, 7)); } } -- cgit v1.2.1 From a8a1c75a70c0c167ea3f6831a9800a27525c7d89 Mon Sep 17 00:00:00 2001 From: Dhruv Date: Wed, 5 Jun 2013 00:29:34 +0530 Subject: [ticket/10820] Fix copyright PHPBB3-10820 --- tests/download/http_user_agent_test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/download/http_user_agent_test.php b/tests/download/http_user_agent_test.php index d85e7b0d08..4e759e990d 100644 --- a/tests/download/http_user_agent_test.php +++ b/tests/download/http_user_agent_test.php @@ -2,7 +2,7 @@ /** * * @package testing -* @copyright (c) 2010 phpBB Group +* @copyright (c) 2013 phpBB Group * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 * */ -- cgit v1.2.1 From a8bb0330959e67e2e7a81bffdedc46d626912f3e Mon Sep 17 00:00:00 2001 From: Dhruv Date: Wed, 5 Jun 2013 00:57:25 +0530 Subject: [ticket/10820] Rename function PHPBB3-10820 --- tests/download/http_user_agent_test.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/download/http_user_agent_test.php b/tests/download/http_user_agent_test.php index 4e759e990d..179477f36a 100644 --- a/tests/download/http_user_agent_test.php +++ b/tests/download/http_user_agent_test.php @@ -11,7 +11,7 @@ require_once dirname(__FILE__) . '/../../phpBB/includes/functions_download.php'; class phpbb_download_http_user_agent_test extends phpbb_test_case { - public function user_agents() + public function user_agents_check_greater_ie7() { return array( // user agent @@ -88,7 +88,7 @@ class phpbb_download_http_user_agent_test extends phpbb_test_case } /** - * @dataProvider user_agents + * @dataProvider user_agents_check_greater_ie7 */ public function test_is_greater_ie7($user_agent, $expected) { -- cgit v1.2.1 From db5bff87157818e424e1717e3047606f53ca3807 Mon Sep 17 00:00:00 2001 From: Dhruv Date: Wed, 5 Jun 2013 02:22:51 +0530 Subject: [ticket/10820] Add test cases More test cases to check against different versions PHPBB3-10820 --- tests/download/http_user_agent_test.php | 41 +++++++++++++++++++++++++++++---- 1 file changed, 37 insertions(+), 4 deletions(-) (limited to 'tests') diff --git a/tests/download/http_user_agent_test.php b/tests/download/http_user_agent_test.php index 179477f36a..166a186913 100644 --- a/tests/download/http_user_agent_test.php +++ b/tests/download/http_user_agent_test.php @@ -11,87 +11,120 @@ require_once dirname(__FILE__) . '/../../phpBB/includes/functions_download.php'; class phpbb_download_http_user_agent_test extends phpbb_test_case { - public function user_agents_check_greater_ie7() + public function user_agents_check_greater_ie_version() { return array( // user agent + // IE version // expected array( 'Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)', + 7, true, ), array( 'Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; WOW64; Trident/6.0)', + 7, true, ), array( 'Mozilla/5.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0; GTB7.4; InfoPath.2; SV1; .NET CLR 3.3.69573; WOW64; en-US)', + 7, true, ), array( 'Mozilla/5.0 (Windows; U; MSIE 7.0; Windows NT 6.0; en-US)', + 7, false, ), array( 'Mozilla/4.0 (compatible; MSIE 6.1; Windows XP; .NET CLR 1.1.4322; .NET CLR 2.0.50727)', + 7, false, ), array( 'Mozilla/4.0 (compatible; MSIE 6.01; Windows NT 6.0)', + 7, false, ), array( 'Mozilla/5.0 (Windows; U; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727)', + 7, false, ), array( 'Mozilla/5.0 (Windows NT 6.2; Win64; x64;) Gecko/20100101 Firefox/20.0', + 7, false, ), array( 'Mozilla/5.0 (Windows NT 6.2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1464.0 Safari/537.36', + 7, false, ), array( 'Googlebot-Image/1.0', + 7, false, ), array( 'Googlebot/2.1 ( http://www.google.com/bot.html)', + 7, false, ), array( 'Lynx/2.8.3dev.9 libwww-FM/2.14 SSL-MM/1.4.1 OpenSSL/0.9.6', + 7, false, ), array( 'Links (0.9x; Linux 2.4.7-10 i686)', + 7, false, ), array( 'Opera/9.60 (Windows NT 5.1; U; de) Presto/2.1.1', + 7, false, ), array( 'Mozilla/4.0 (compatible; MSIE 5.0; Windows NT;)', + 7, false, ), array( 'Mozilla/4.0 (compatible; MSIE 5.0; Windows NT 4.0) Opera 6.01 [en]', + 7, false, ), array( 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; en) Opera 9.24', + 7, + false, + ), + array( + 'Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)', + 8, + true, + ), + array( + 'Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; WOW64; Trident/6.0)', + 9, + true, + ), + array( + 'Mozilla/5.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0; GTB7.4; InfoPath.2; SV1; .NET CLR 3.3.69573; WOW64; en-US)', + 10, false, ), ); } /** - * @dataProvider user_agents_check_greater_ie7 + * @dataProvider user_agents_check_greater_ie_version */ - public function test_is_greater_ie7($user_agent, $expected) + public function test_is_greater_ie_version($user_agent, $version, $expected) { - $this->assertEquals($expected, phpbb_is_greater_ie_version($user_agent, 7)); + $this->assertEquals($expected, phpbb_is_greater_ie_version($user_agent, $version)); } } -- cgit v1.2.1 From 6a77ee1f30961f6363818691f91162fa67618872 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Wed, 5 Jun 2013 17:05:10 +0200 Subject: [ticket/11579] Do not extend validate_data_helper PHPBB3-11579 --- tests/functions/validate_data_helper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/functions/validate_data_helper.php b/tests/functions/validate_data_helper.php index 94ddf60429..b92a3aa5eb 100644 --- a/tests/functions/validate_data_helper.php +++ b/tests/functions/validate_data_helper.php @@ -7,7 +7,7 @@ * */ -class phpbb_functions_validate_data_helper extends PHPUnit_Framework_TestCase +class phpbb_functions_validate_data_helper { protected $test_case; -- cgit v1.2.1 From c6ba894acdfdf5b0800dc3903d01605ddd83e8e9 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Wed, 5 Jun 2013 17:36:20 +0200 Subject: [ticket/11579] Add method for validating emails for valid MX and mark as slow A method for setting up the prerequisities also has been added in order to reduce the amount of necessary code. PHPBB3-11579 --- tests/functions/validate_email_test.php | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) (limited to 'tests') diff --git a/tests/functions/validate_email_test.php b/tests/functions/validate_email_test.php index 93b5ba0896..9a6ce39251 100644 --- a/tests/functions/validate_email_test.php +++ b/tests/functions/validate_email_test.php @@ -32,14 +32,24 @@ class phpbb_functions_validate_email_test extends phpbb_database_test_case $this->helper = new phpbb_functions_validate_data_helper($this); } - public function test_validate_email() + /** + * Get validation prerequesites + * + * @param bool $check_mx Whether mx records should be checked + */ + protected function set_validation_prerequisites($check_mx) { global $config, $db, $user; - $config['email_check_mx'] = true; + $config['email_check_mx'] = $check_mx; $db = $this->db; $user = $this->user; $user->optionset('banned_users', array('banned@example.com')); + } + + public function test_validate_email() + { + $this->set_validation_prerequisites(false); $this->helper->assert_valid_data(array( 'empty' => array( @@ -72,9 +82,25 @@ class phpbb_functions_validate_email_test extends phpbb_database_test_case 'banned@example.com', array('email'), ), + )); + } + + /** + * @group slow + */ + public function test_validate_email_mx() + { + $this->set_validation_prerequisites(true); + + $this->helper->assert_valid_data(array( + 'valid' => array( + array(), + 'foobar@phpbb.com', + array('email'), + ), 'no_mx' => array( array('DOMAIN_NO_MX_RECORD'), - 'test@wwrrrhhghgghgh.ttv', + 'test@does-not-exist.phpbb.com', array('email'), ), )); -- cgit v1.2.1 From 057bbfa2406bf659d85d137c07704f0aaddb4478 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 14 May 2013 15:57:17 +0200 Subject: [ticket/11543] Add unit tests for obtain_guest_count() PHPBB3-11543 --- tests/functions/fixtures/obtain_online.xml | 11 +++++ tests/functions/obtain_online_test.php | 69 ++++++++++++++++++++++++++++++ 2 files changed, 80 insertions(+) create mode 100644 tests/functions/fixtures/obtain_online.xml create mode 100644 tests/functions/obtain_online_test.php (limited to 'tests') diff --git a/tests/functions/fixtures/obtain_online.xml b/tests/functions/fixtures/obtain_online.xml new file mode 100644 index 0000000000..ea4d6f9238 --- /dev/null +++ b/tests/functions/fixtures/obtain_online.xml @@ -0,0 +1,11 @@ + + + + session_id + session_user_id + session_forum_id + session_time + session_ip + session_viewonline +
+
diff --git a/tests/functions/obtain_online_test.php b/tests/functions/obtain_online_test.php new file mode 100644 index 0000000000..1089b42616 --- /dev/null +++ b/tests/functions/obtain_online_test.php @@ -0,0 +1,69 @@ +createXMLDataSet(dirname(__FILE__).'/fixtures/obtain_online.xml'); + } + + protected function setUp() + { + global $config, $db; + + $db = $this->db = $this->new_dbal(); + $config = array( + 'load_online_time' => 5, + ); + } + + static public function obtain_guest_count_data() + { + return array( + array(0, 2), + array(1, 1), + ); + } + + /** + * @dataProvider obtain_guest_count_data + */ + public function test_obtain_guest_count($forum_id, $expected) + { + $this->db->sql_query('DELETE FROM phpbb_sessions'); + + $this->create_guest_sessions(); + $this->assertEquals($expected, obtain_guest_count($forum_id)); + } + + protected function create_guest_sessions() + { + $this->add_session(1, '0001', 0, true, 0); + $this->add_session(1, '0002', 1, true, 0); + $this->add_session(1, '0003', 0, true, 10); + $this->add_session(1, '0004', 1, true, 10); + } + + protected function add_session($user_id, $user_ip, $forum_id, $view_online, $time_delta) + { + $sql_ary = array( + 'session_id' => $user_id . '_' . $forum_id . '_session00000000000000000' . $user_ip, + 'session_user_id' => $user_id, + 'session_ip' => $user_ip, + 'session_forum_id' => $forum_id, + 'session_time' => time() - $time_delta * 60, + 'session_viewonline' => $view_online, + ); + + $this->db->sql_query('INSERT INTO phpbb_sessions ' . $this->db->sql_build_array('INSERT', $sql_ary)); + } +} -- cgit v1.2.1 From 6b3758edd091f09f46b8117df39c4d104e96739b Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 14 May 2013 15:57:57 +0200 Subject: [ticket/11543] Add unit tests for obtain_users_online() PHPBB3-11543 --- tests/functions/obtain_online_test.php | 65 ++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) (limited to 'tests') diff --git a/tests/functions/obtain_online_test.php b/tests/functions/obtain_online_test.php index 1089b42616..efb8e97fc7 100644 --- a/tests/functions/obtain_online_test.php +++ b/tests/functions/obtain_online_test.php @@ -45,6 +45,59 @@ class phpbb_functions_obtain_online_test extends phpbb_database_test_case $this->assertEquals($expected, obtain_guest_count($forum_id)); } + static public function obtain_users_online_data() + { + return array( + array(0, false, array( + 'online_users' => array(2 => 2, 3 => 3, 6 => 6, 7 => 7), + 'hidden_users' => array(6 => 6, 7 => 7), + 'total_online' => 4, + 'visible_online' => 2, + 'hidden_online' => 2, + 'guests_online' => 0, + )), + array(0, true, array( + 'online_users' => array(2 => 2, 3 => 3, 6 => 6, 7 => 7), + 'hidden_users' => array(6 => 6, 7 => 7), + 'total_online' => 6, + 'visible_online' => 2, + 'hidden_online' => 2, + 'guests_online' => 2, + )), + array(1, false, array( + 'online_users' => array(3 => 3, 7 => 7), + 'hidden_users' => array(7 => 7), + 'total_online' => 2, + 'visible_online' => 1, + 'hidden_online' => 1, + 'guests_online' => 0, + )), + array(1, true, array( + 'online_users' => array(3 => 3, 7 => 7), + 'hidden_users' => array(7 => 7), + 'total_online' => 3, + 'visible_online' => 1, + 'hidden_online' => 1, + 'guests_online' => 1, + )), + ); + } + + /** + * @dataProvider obtain_users_online_data + */ + public function test_obtain_users_online($forum_id, $display_guests, $expected) + { + $this->db->sql_query('DELETE FROM phpbb_sessions'); + + global $config; + $config['load_online_guests'] = $display_guests; + + $this->create_guest_sessions(); + $this->create_user_sessions(); + $this->assertEquals($expected, obtain_users_online($forum_id)); + } + protected function create_guest_sessions() { $this->add_session(1, '0001', 0, true, 0); @@ -53,6 +106,18 @@ class phpbb_functions_obtain_online_test extends phpbb_database_test_case $this->add_session(1, '0004', 1, true, 10); } + protected function create_user_sessions() + { + $this->add_session(2, '0005', 0, true, 0); + $this->add_session(3, '0006', 1, true, 0); + $this->add_session(4, '0007', 0, true, 10); + $this->add_session(5, '0008', 1, true, 10); + $this->add_session(6, '0005', 0, false, 0); + $this->add_session(7, '0006', 1, false, 0); + $this->add_session(8, '0007', 0, false, 10); + $this->add_session(9, '0008', 1, false, 10); + } + protected function add_session($user_id, $user_ip, $forum_id, $view_online, $time_delta) { $sql_ary = array( -- cgit v1.2.1 From 3301b01f4c659af15393a58b8221d62a906551be Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 14 May 2013 16:02:30 +0200 Subject: [ticket/11543] Add unit tests for obtain_users_online() with empty forum PHPBB3-11543 --- tests/functions/obtain_online_test.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'tests') diff --git a/tests/functions/obtain_online_test.php b/tests/functions/obtain_online_test.php index efb8e97fc7..8fd7e6a977 100644 --- a/tests/functions/obtain_online_test.php +++ b/tests/functions/obtain_online_test.php @@ -80,6 +80,22 @@ class phpbb_functions_obtain_online_test extends phpbb_database_test_case 'hidden_online' => 1, 'guests_online' => 1, )), + array(2, false, array( + 'online_users' => array(), + 'hidden_users' => array(), + 'total_online' => 0, + 'visible_online' => 0, + 'hidden_online' => 0, + 'guests_online' => 0, + )), + array(2, true, array( + 'online_users' => array(), + 'hidden_users' => array(), + 'total_online' => 0, + 'visible_online' => 0, + 'hidden_online' => 0, + 'guests_online' => 0, + )), ); } -- cgit v1.2.1 From 766be31f95ff5b03cba0273cdfd83fb7f0d93a0b Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 14 May 2013 17:23:17 +0200 Subject: [ticket/11543] Add unit tests for obtain_users_online_string() PHPBB3-11543 --- tests/functions/fixtures/obtain_online.xml | 100 +++++++++++++++++++++++++++++ tests/functions/obtain_online_test.php | 86 ++++++++++++++++++++++++- 2 files changed, 185 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/functions/fixtures/obtain_online.xml b/tests/functions/fixtures/obtain_online.xml index ea4d6f9238..1c5a4454f2 100644 --- a/tests/functions/fixtures/obtain_online.xml +++ b/tests/functions/fixtures/obtain_online.xml @@ -8,4 +8,104 @@ session_ip session_viewonline + + user_id + username_clean + username + user_allow_viewonline + user_permissions + user_sig + user_occ + user_interests + + 1 + anonymous + anonymous + 1 + + + + + + + 2 + 2 + 2 + 1 + + + + + + + 3 + 3 + 3 + 1 + + + + + + + 4 + 4 + 4 + 1 + + + + + + + 5 + 5 + 5 + 1 + + + + + + + 6 + 6 + 6 + 0 + + + + + + + 7 + 7 + 7 + 0 + + + + + + + 8 + 8 + 8 + 0 + + + + + + + 9 + 9 + 9 + 0 + + + + + +
diff --git a/tests/functions/obtain_online_test.php b/tests/functions/obtain_online_test.php index 8fd7e6a977..64f368164c 100644 --- a/tests/functions/obtain_online_test.php +++ b/tests/functions/obtain_online_test.php @@ -8,6 +8,8 @@ */ require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php'; +require_once dirname(__FILE__) . '/../../phpBB/includes/functions_content.php'; +require_once dirname(__FILE__) . '/../../phpBB/includes/auth.php'; class phpbb_functions_obtain_online_test extends phpbb_database_test_case { @@ -18,6 +20,8 @@ class phpbb_functions_obtain_online_test extends phpbb_database_test_case protected function setUp() { + parent::setUp(); + global $config, $db; $db = $this->db = $this->new_dbal(); @@ -114,6 +118,63 @@ class phpbb_functions_obtain_online_test extends phpbb_database_test_case $this->assertEquals($expected, obtain_users_online($forum_id)); } + static public function obtain_users_online_string_data() + { + return array( + array(0, false, array( + 'online_userlist' => 'REGISTERED_USERS 2, 3', + 'l_online_users' => 'ONLINE_USERS_TOTAL 4REG_USERS_TOTAL_AND 2HIDDEN_USERS_TOTAL 2', + )), + array(0, true, array( + 'online_userlist' => 'REGISTERED_USERS 2, 3', + 'l_online_users' => 'ONLINE_USERS_TOTAL 6REG_USERS_TOTAL 2HIDDEN_USERS_TOTAL_AND 2GUEST_USERS_TOTAL 2', + )), + array(1, false, array( + 'online_userlist' => 'BROWSING_FORUM 3', + 'l_online_users' => 'ONLINE_USERS_TOTAL 2REG_USER_TOTAL_AND 1HIDDEN_USER_TOTAL 1', + )), + array(1, true, array( + 'online_userlist' => 'BROWSING_FORUM_GUEST 3 1', + 'l_online_users' => 'ONLINE_USERS_TOTAL 3REG_USER_TOTAL 1HIDDEN_USER_TOTAL_AND 1GUEST_USER_TOTAL 1', + )), + array(2, false, array( + 'online_userlist' => 'BROWSING_FORUM NO_ONLINE_USERS', + 'l_online_users' => 'ONLINE_USERS_ZERO_TOTAL 0REG_USERS_ZERO_TOTAL_AND 0HIDDEN_USERS_ZERO_TOTAL 0', + )), + array(2, true, array( + 'online_userlist' => 'BROWSING_FORUM_GUESTS NO_ONLINE_USERS 0', + 'l_online_users' => 'ONLINE_USERS_ZERO_TOTAL 0REG_USERS_ZERO_TOTAL 0HIDDEN_USERS_ZERO_TOTAL_AND 0GUEST_USERS_ZERO_TOTAL 0', + )), + ); + } + + /** + * @dataProvider obtain_users_online_string_data + */ + public function test_obtain_users_online_string($forum_id, $display_guests, $expected) + { + $this->db->sql_query('DELETE FROM phpbb_sessions'); + + global $config, $user, $auth; + $config['load_online_guests'] = $display_guests; + $user->lang = $this->load_language(); + $auth = $this->getMock('auth'); + $acl_get_map = array( + array('u_viewonline', true), + ); + $auth->expects($this->any()) + ->method('acl_get') + ->with($this->stringContains('_'), + $this->anything()) + ->will($this->returnValueMap($acl_get_map)); + + $this->create_guest_sessions(); + $this->create_user_sessions(); + + $online_users = obtain_users_online($forum_id); + $this->assertEquals($expected, obtain_users_online_string($online_users, $forum_id)); + } + protected function create_guest_sessions() { $this->add_session(1, '0001', 0, true, 0); @@ -144,7 +205,30 @@ class phpbb_functions_obtain_online_test extends phpbb_database_test_case 'session_time' => time() - $time_delta * 60, 'session_viewonline' => $view_online, ); - $this->db->sql_query('INSERT INTO phpbb_sessions ' . $this->db->sql_build_array('INSERT', $sql_ary)); } + + protected function load_language() + { + $lang = array( + 'NO_ONLINE_USERS' => 'NO_ONLINE_USERS', + 'REGISTERED_USERS' => 'REGISTERED_USERS', + 'BROWSING_FORUM' => 'BROWSING_FORUM %s', + 'BROWSING_FORUM_GUEST' => 'BROWSING_FORUM_GUEST %s %d', + 'BROWSING_FORUM_GUESTS' => 'BROWSING_FORUM_GUESTS %s %d', + ); + $vars_online = array('ONLINE', 'REG', 'HIDDEN', 'GUEST'); + foreach ($vars_online as $online) + { + $lang = array_merge($lang, array( + $online . '_USERS_ZERO_TOTAL' => $online . '_USERS_ZERO_TOTAL %d', + $online . '_USER_TOTAL' => $online . '_USER_TOTAL %d', + $online . '_USERS_TOTAL' => $online . '_USERS_TOTAL %d', + $online . '_USERS_ZERO_TOTAL_AND' => $online . '_USERS_ZERO_TOTAL_AND %d', + $online . '_USER_TOTAL_AND' => $online . '_USER_TOTAL_AND %d', + $online . '_USERS_TOTAL_AND' => $online . '_USERS_TOTAL_AND %d', + )); + } + return $lang; + } } -- cgit v1.2.1 From ba665412ea4342da24b70408335e82a8c455f258 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 28 May 2013 17:56:48 +0200 Subject: [ticket/11543] Use correct IP addresses and inject time for correct values PHPBB3-11543 --- tests/functions/obtain_online_test.php | 47 ++++++++++++++++++---------------- 1 file changed, 25 insertions(+), 22 deletions(-) (limited to 'tests') diff --git a/tests/functions/obtain_online_test.php b/tests/functions/obtain_online_test.php index 64f368164c..941c20de92 100644 --- a/tests/functions/obtain_online_test.php +++ b/tests/functions/obtain_online_test.php @@ -45,7 +45,8 @@ class phpbb_functions_obtain_online_test extends phpbb_database_test_case { $this->db->sql_query('DELETE FROM phpbb_sessions'); - $this->create_guest_sessions(); + $time = time(); + $this->create_guest_sessions($time); $this->assertEquals($expected, obtain_guest_count($forum_id)); } @@ -113,8 +114,9 @@ class phpbb_functions_obtain_online_test extends phpbb_database_test_case global $config; $config['load_online_guests'] = $display_guests; - $this->create_guest_sessions(); - $this->create_user_sessions(); + $time = time(); + $this->create_guest_sessions($time); + $this->create_user_sessions($time); $this->assertEquals($expected, obtain_users_online($forum_id)); } @@ -168,41 +170,42 @@ class phpbb_functions_obtain_online_test extends phpbb_database_test_case $this->anything()) ->will($this->returnValueMap($acl_get_map)); - $this->create_guest_sessions(); - $this->create_user_sessions(); + $time = time(); + $this->create_guest_sessions($time); + $this->create_user_sessions($time); $online_users = obtain_users_online($forum_id); $this->assertEquals($expected, obtain_users_online_string($online_users, $forum_id)); } - protected function create_guest_sessions() + protected function create_guest_sessions($time) { - $this->add_session(1, '0001', 0, true, 0); - $this->add_session(1, '0002', 1, true, 0); - $this->add_session(1, '0003', 0, true, 10); - $this->add_session(1, '0004', 1, true, 10); + $this->add_session(1, '0001', '192.168.0.1', 0, true, $time); + $this->add_session(1, '0002', '192.168.0.2', 1, true, $time); + $this->add_session(1, '0003', '192.168.0.3', 0, true, $time, 10); + $this->add_session(1, '0004', '192.168.0.4', 1, true, $time, 10); } - protected function create_user_sessions() + protected function create_user_sessions($time) { - $this->add_session(2, '0005', 0, true, 0); - $this->add_session(3, '0006', 1, true, 0); - $this->add_session(4, '0007', 0, true, 10); - $this->add_session(5, '0008', 1, true, 10); - $this->add_session(6, '0005', 0, false, 0); - $this->add_session(7, '0006', 1, false, 0); - $this->add_session(8, '0007', 0, false, 10); - $this->add_session(9, '0008', 1, false, 10); + $this->add_session(2, '0005', '192.168.0.5', 0, true, $time); + $this->add_session(3, '0006', '192.168.0.6', 1, true, $time); + $this->add_session(4, '0007', '192.168.0.7', 0, true, $time, 10); + $this->add_session(5, '0008', '192.168.0.8', 1, true, $time, 10); + $this->add_session(6, '0005', '192.168.0.9', 0, false, $time); + $this->add_session(7, '0006', '192.168.0.10', 1, false, $time); + $this->add_session(8, '0007', '192.168.0.11', 0, false, $time, 10); + $this->add_session(9, '0008', '192.168.0.12', 1, false, $time, 10); } - protected function add_session($user_id, $user_ip, $forum_id, $view_online, $time_delta) + protected function add_session($user_id, $session_id, $user_ip, $forum_id, $view_online, $time, $time_delta = 0) { $sql_ary = array( - 'session_id' => $user_id . '_' . $forum_id . '_session00000000000000000' . $user_ip, + 'session_id' => $user_id . '_' . $forum_id . '_session00000000000000000' . $session_id, 'session_user_id' => $user_id, 'session_ip' => $user_ip, 'session_forum_id' => $forum_id, - 'session_time' => time() - $time_delta * 60, + 'session_time' => $time - $time_delta * 60, 'session_viewonline' => $view_online, ); $this->db->sql_query('INSERT INTO phpbb_sessions ' . $this->db->sql_build_array('INSERT', $sql_ary)); -- cgit v1.2.1 From d406dd99d84a5c4f2b879859f11b2d10b01d54de Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 6 Jun 2013 23:29:50 +0200 Subject: [ticket/develop/11543] Use plurals in develop PHPBB3-11543 --- tests/functions/obtain_online_test.php | 39 ++++++++++++---------------------- tests/mock/lang.php | 5 +++++ 2 files changed, 19 insertions(+), 25 deletions(-) (limited to 'tests') diff --git a/tests/functions/obtain_online_test.php b/tests/functions/obtain_online_test.php index 941c20de92..30e743cbab 100644 --- a/tests/functions/obtain_online_test.php +++ b/tests/functions/obtain_online_test.php @@ -9,7 +9,6 @@ require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php'; require_once dirname(__FILE__) . '/../../phpBB/includes/functions_content.php'; -require_once dirname(__FILE__) . '/../../phpBB/includes/auth.php'; class phpbb_functions_obtain_online_test extends phpbb_database_test_case { @@ -125,27 +124,27 @@ class phpbb_functions_obtain_online_test extends phpbb_database_test_case return array( array(0, false, array( 'online_userlist' => 'REGISTERED_USERS 2, 3', - 'l_online_users' => 'ONLINE_USERS_TOTAL 4REG_USERS_TOTAL_AND 2HIDDEN_USERS_TOTAL 2', + 'l_online_users' => 'ONLINE_USERS_TOTAL 4 REG_USERS_TOTAL 2 HIDDEN_USERS_TOTAL 2', )), array(0, true, array( 'online_userlist' => 'REGISTERED_USERS 2, 3', - 'l_online_users' => 'ONLINE_USERS_TOTAL 6REG_USERS_TOTAL 2HIDDEN_USERS_TOTAL_AND 2GUEST_USERS_TOTAL 2', + 'l_online_users' => 'ONLINE_USERS_TOTAL_GUESTS 6 REG_USERS_TOTAL 2 HIDDEN_USERS_TOTAL 2 GUEST_USERS_TOTAL 2', )), array(1, false, array( 'online_userlist' => 'BROWSING_FORUM 3', - 'l_online_users' => 'ONLINE_USERS_TOTAL 2REG_USER_TOTAL_AND 1HIDDEN_USER_TOTAL 1', + 'l_online_users' => 'ONLINE_USERS_TOTAL 2 REG_USERS_TOTAL 1 HIDDEN_USERS_TOTAL 1', )), array(1, true, array( - 'online_userlist' => 'BROWSING_FORUM_GUEST 3 1', - 'l_online_users' => 'ONLINE_USERS_TOTAL 3REG_USER_TOTAL 1HIDDEN_USER_TOTAL_AND 1GUEST_USER_TOTAL 1', + 'online_userlist' => 'BROWSING_FORUM_GUESTS 1 3', + 'l_online_users' => 'ONLINE_USERS_TOTAL_GUESTS 3 REG_USERS_TOTAL 1 HIDDEN_USERS_TOTAL 1 GUEST_USERS_TOTAL 1', )), array(2, false, array( 'online_userlist' => 'BROWSING_FORUM NO_ONLINE_USERS', - 'l_online_users' => 'ONLINE_USERS_ZERO_TOTAL 0REG_USERS_ZERO_TOTAL_AND 0HIDDEN_USERS_ZERO_TOTAL 0', + 'l_online_users' => 'ONLINE_USERS_TOTAL 0 REG_USERS_TOTAL 0 HIDDEN_USERS_TOTAL 0', )), array(2, true, array( - 'online_userlist' => 'BROWSING_FORUM_GUESTS NO_ONLINE_USERS 0', - 'l_online_users' => 'ONLINE_USERS_ZERO_TOTAL 0REG_USERS_ZERO_TOTAL 0HIDDEN_USERS_ZERO_TOTAL_AND 0GUEST_USERS_ZERO_TOTAL 0', + 'online_userlist' => 'BROWSING_FORUM_GUESTS 0 NO_ONLINE_USERS', + 'l_online_users' => 'ONLINE_USERS_TOTAL_GUESTS 0 REG_USERS_TOTAL 0 HIDDEN_USERS_TOTAL 0 GUEST_USERS_TOTAL 0', )), ); } @@ -157,18 +156,21 @@ class phpbb_functions_obtain_online_test extends phpbb_database_test_case { $this->db->sql_query('DELETE FROM phpbb_sessions'); - global $config, $user, $auth; + global $config, $user, $auth, $phpbb_dispatcher; $config['load_online_guests'] = $display_guests; + $user = new phpbb_mock_lang(); $user->lang = $this->load_language(); - $auth = $this->getMock('auth'); + $auth = $this->getMock('phpbb_auth'); $acl_get_map = array( array('u_viewonline', true), + array('u_viewprofile', true), ); $auth->expects($this->any()) ->method('acl_get') ->with($this->stringContains('_'), $this->anything()) ->will($this->returnValueMap($acl_get_map)); + $phpbb_dispatcher = new phpbb_mock_event_dispatcher(); $time = time(); $this->create_guest_sessions($time); @@ -213,25 +215,12 @@ class phpbb_functions_obtain_online_test extends phpbb_database_test_case protected function load_language() { - $lang = array( + return array( 'NO_ONLINE_USERS' => 'NO_ONLINE_USERS', 'REGISTERED_USERS' => 'REGISTERED_USERS', 'BROWSING_FORUM' => 'BROWSING_FORUM %s', 'BROWSING_FORUM_GUEST' => 'BROWSING_FORUM_GUEST %s %d', 'BROWSING_FORUM_GUESTS' => 'BROWSING_FORUM_GUESTS %s %d', ); - $vars_online = array('ONLINE', 'REG', 'HIDDEN', 'GUEST'); - foreach ($vars_online as $online) - { - $lang = array_merge($lang, array( - $online . '_USERS_ZERO_TOTAL' => $online . '_USERS_ZERO_TOTAL %d', - $online . '_USER_TOTAL' => $online . '_USER_TOTAL %d', - $online . '_USERS_TOTAL' => $online . '_USERS_TOTAL %d', - $online . '_USERS_ZERO_TOTAL_AND' => $online . '_USERS_ZERO_TOTAL_AND %d', - $online . '_USER_TOTAL_AND' => $online . '_USER_TOTAL_AND %d', - $online . '_USERS_TOTAL_AND' => $online . '_USERS_TOTAL_AND %d', - )); - } - return $lang; } } diff --git a/tests/mock/lang.php b/tests/mock/lang.php index 781b3d060e..ac814b45db 100644 --- a/tests/mock/lang.php +++ b/tests/mock/lang.php @@ -30,4 +30,9 @@ class phpbb_mock_lang implements ArrayAccess public function offsetUnset($offset) { } + + public function lang() + { + return implode(' ', func_get_args()); + } } -- cgit v1.2.1 From 228c1075b765e8d51a997935bf12f973ae02264e Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 7 Jun 2013 01:31:20 +0200 Subject: [ticket/11590] Close database connections when tearDown() is called PHPBB3-11590 --- tests/test_framework/phpbb_database_test_case.php | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'tests') diff --git a/tests/test_framework/phpbb_database_test_case.php b/tests/test_framework/phpbb_database_test_case.php index 429bb92bf1..beddece470 100644 --- a/tests/test_framework/phpbb_database_test_case.php +++ b/tests/test_framework/phpbb_database_test_case.php @@ -11,6 +11,8 @@ abstract class phpbb_database_test_case extends PHPUnit_Extensions_Database_Test { static private $already_connected; + private $db_connections; + protected $test_case_helpers; protected $fixture_xml_data; @@ -28,6 +30,22 @@ abstract class phpbb_database_test_case extends PHPUnit_Extensions_Database_Test 'phpbb_database_test_case' => array('already_connected'), ); + + $this->db_connections = array(); + } + + protected function tearDown() + { + parent::tearDown(); + + // Close all database connections from this test + if (!empty($this->db_connections)) + { + foreach ($this->db_connections as $db) + { + $db->sql_close(); + } + } } protected function setUp() @@ -123,6 +141,8 @@ abstract class phpbb_database_test_case extends PHPUnit_Extensions_Database_Test $db = new $dbal(); $db->sql_connect($config['dbhost'], $config['dbuser'], $config['dbpasswd'], $config['dbname'], $config['dbport']); + $this->db_connections[] = $db; + return $db; } -- cgit v1.2.1 From d39ed5afc13285c1d6d14ea0d04be87dd11f7d38 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 7 Jun 2013 14:48:50 +0200 Subject: [ticket/11543] Add more users so #hidden <> #normal PHPBB3-11543 --- tests/functions/fixtures/obtain_online.xml | 10 ++++++++++ tests/functions/obtain_online_test.php | 21 +++++++++++---------- 2 files changed, 21 insertions(+), 10 deletions(-) (limited to 'tests') diff --git a/tests/functions/fixtures/obtain_online.xml b/tests/functions/fixtures/obtain_online.xml index 1c5a4454f2..05bbe6a05e 100644 --- a/tests/functions/fixtures/obtain_online.xml +++ b/tests/functions/fixtures/obtain_online.xml @@ -107,5 +107,15 @@ + + 10 + 10 + 10 + 0 + + + + + diff --git a/tests/functions/obtain_online_test.php b/tests/functions/obtain_online_test.php index 941c20de92..b3beb55a96 100644 --- a/tests/functions/obtain_online_test.php +++ b/tests/functions/obtain_online_test.php @@ -54,19 +54,19 @@ class phpbb_functions_obtain_online_test extends phpbb_database_test_case { return array( array(0, false, array( - 'online_users' => array(2 => 2, 3 => 3, 6 => 6, 7 => 7), - 'hidden_users' => array(6 => 6, 7 => 7), - 'total_online' => 4, + 'online_users' => array(2 => 2, 3 => 3, 6 => 6, 7 => 7, 10 => 10), + 'hidden_users' => array(6 => 6, 7 => 7, 10 => 10), + 'total_online' => 5, 'visible_online' => 2, - 'hidden_online' => 2, + 'hidden_online' => 3, 'guests_online' => 0, )), array(0, true, array( - 'online_users' => array(2 => 2, 3 => 3, 6 => 6, 7 => 7), - 'hidden_users' => array(6 => 6, 7 => 7), - 'total_online' => 6, + 'online_users' => array(2 => 2, 3 => 3, 6 => 6, 7 => 7, 10 => 10), + 'hidden_users' => array(6 => 6, 7 => 7, 10 => 10), + 'total_online' => 7, 'visible_online' => 2, - 'hidden_online' => 2, + 'hidden_online' => 3, 'guests_online' => 2, )), array(1, false, array( @@ -125,11 +125,11 @@ class phpbb_functions_obtain_online_test extends phpbb_database_test_case return array( array(0, false, array( 'online_userlist' => 'REGISTERED_USERS 2, 3', - 'l_online_users' => 'ONLINE_USERS_TOTAL 4REG_USERS_TOTAL_AND 2HIDDEN_USERS_TOTAL 2', + 'l_online_users' => 'ONLINE_USERS_TOTAL 5REG_USERS_TOTAL_AND 2HIDDEN_USERS_TOTAL 3', )), array(0, true, array( 'online_userlist' => 'REGISTERED_USERS 2, 3', - 'l_online_users' => 'ONLINE_USERS_TOTAL 6REG_USERS_TOTAL 2HIDDEN_USERS_TOTAL_AND 2GUEST_USERS_TOTAL 2', + 'l_online_users' => 'ONLINE_USERS_TOTAL 7REG_USERS_TOTAL 2HIDDEN_USERS_TOTAL_AND 3GUEST_USERS_TOTAL 2', )), array(1, false, array( 'online_userlist' => 'BROWSING_FORUM 3', @@ -196,6 +196,7 @@ class phpbb_functions_obtain_online_test extends phpbb_database_test_case $this->add_session(7, '0006', '192.168.0.10', 1, false, $time); $this->add_session(8, '0007', '192.168.0.11', 0, false, $time, 10); $this->add_session(9, '0008', '192.168.0.12', 1, false, $time, 10); + $this->add_session(10, '009', '192.168.0.13', 0, false, $time); } protected function add_session($user_id, $session_id, $user_ip, $forum_id, $view_online, $time, $time_delta = 0) -- cgit v1.2.1 From 35064086377c3f3334e02ca153b008b0502fbdee Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sat, 8 Jun 2013 15:26:35 +0200 Subject: [ticket/11550] Fix copying the fixtures in extension_permission_lang_test.php PHPBB3-11550 --- tests/functional/extension_permission_lang_test.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/functional/extension_permission_lang_test.php b/tests/functional/extension_permission_lang_test.php index 9a251e8645..04c3a9d497 100644 --- a/tests/functional/extension_permission_lang_test.php +++ b/tests/functional/extension_permission_lang_test.php @@ -45,7 +45,10 @@ class phpbb_functional_extension_permission_lang_test extends phpbb_functional_t } // Copy our ext/ files from the test case to the board - self::$copied_files = array_merge(self::$copied_files, self::$helper->copy_dir(dirname(__FILE__) . '/fixtures/ext/' . $fixture, $phpbb_root_path . 'ext/' . $fixture)); + foreach (self::$fixtures as $fixture) + { + self::$copied_files = array_merge(self::$copied_files, self::$helper->copy_dir(dirname(__FILE__) . '/fixtures/ext/' . $fixture, $phpbb_root_path . 'ext/' . $fixture)); + } } /** -- cgit v1.2.1 From c8ee6cb0c200b7e64ebbae11806f4daddfd8d93d Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sat, 8 Jun 2013 17:00:27 +0200 Subject: [ticket/11550] Move functionality for copying/restoring to test case helpers PHPBB3-11550 --- tests/test_framework/phpbb_test_case_helpers.php | 44 ++++++++++++++++++++++++ 1 file changed, 44 insertions(+) (limited to 'tests') diff --git a/tests/test_framework/phpbb_test_case_helpers.php b/tests/test_framework/phpbb_test_case_helpers.php index 20ae384f21..0e0b5c2a8f 100644 --- a/tests/test_framework/phpbb_test_case_helpers.php +++ b/tests/test_framework/phpbb_test_case_helpers.php @@ -18,6 +18,50 @@ class phpbb_test_case_helpers $this->test_case = $test_case; } + private $copied_files = array(); + + public function copy_ext_fixtures($fixtures_dir, $fixtures) + { + global $phpbb_root_path; + + $this->copied_files = array(); + + if (file_exists($phpbb_root_path . 'ext/')) + { + // First, move any extensions setup on the board to a temp directory + $this->copied_files = $this->copy_dir($phpbb_root_path . 'ext/', $phpbb_root_path . 'store/temp_ext/'); + + // Then empty the ext/ directory on the board (for accurate test cases) + $this->empty_dir($phpbb_root_path . 'ext/'); + } + + // Copy our ext/ files from the test case to the board + foreach ($fixtures as $fixture) + { + $this->copied_files = array_merge($this->copied_files, $this->copy_dir($fixtures_dir . 'ext/' . $fixture, $phpbb_root_path . 'ext/' . $fixture)); + } + } + + public function restore_original_ext_dir() + { + global $phpbb_root_path; + + // Copy back the board installed extensions from the temp directory + if (file_exists($phpbb_root_path . 'store/temp_ext/')) + { + $this->copy_dir($phpbb_root_path . 'store/temp_ext/', $phpbb_root_path . 'ext/'); + } + + // Remove all of the files we copied around (from board ext -> temp_ext, from test ext -> board ext) + $this->remove_files($this->copied_files); + $this->copied_files = array(); + + if (file_exists($phpbb_root_path . 'store/temp_ext/')) + { + $this->empty_dir($phpbb_root_path . 'store/temp_ext/'); + } + } + public function setExpectedTriggerError($errno, $message = '') { $exceptionName = ''; -- cgit v1.2.1 From a61ab1e5e4bbe786d3f500438bb0dd6ca395989e Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sat, 8 Jun 2013 17:02:31 +0200 Subject: [ticket/11550] Use new functionality from the test case helpers Instead of duplicating the extension copy code, it is now in the helpers. So we remove the code from existing tests. PHPBB3-11550 --- tests/functional/extension_acp_test.php | 54 ++++++---------------- tests/functional/extension_controller_test.php | 41 +++------------- tests/functional/extension_module_test.php | 38 ++++----------- .../functional/extension_permission_lang_test.php | 39 ++-------------- tests/functional/metadata_manager_test.php | 24 ++-------- tests/test_framework/phpbb_test_case_helpers.php | 2 +- 6 files changed, 39 insertions(+), 159 deletions(-) (limited to 'tests') diff --git a/tests/functional/extension_acp_test.php b/tests/functional/extension_acp_test.php index 9badab8ced..ada17397d7 100644 --- a/tests/functional/extension_acp_test.php +++ b/tests/functional/extension_acp_test.php @@ -12,34 +12,33 @@ */ class phpbb_functional_extension_acp_test extends phpbb_functional_test_case { - static private $copied_files = array(); static private $helper; + static protected $fixtures = array( + '', + ); + /** * This should only be called once before the tests are run. - * This is used to copy the extensions to the phpBB install + * This is used to copy the fixtures to the phpBB install */ static public function setUpBeforeClass() { - global $phpbb_root_path; - parent::setUpBeforeClass(); self::$helper = new phpbb_test_case_helpers(self); + self::$helper->copy_ext_fixtures(dirname(__FILE__) . '/fixtures/ext/', self::$fixtures); + } - self::$copied_files = array(); - - if (file_exists($phpbb_root_path . 'ext/')) - { - // First, move any extensions setup on the board to a temp directory - self::$copied_files = self::$helper->copy_dir($phpbb_root_path . 'ext/', $phpbb_root_path . 'store/temp_ext/'); - - // Then empty the ext/ directory on the board (for accurate test cases) - self::$helper->empty_dir($phpbb_root_path . 'ext/'); - } + /** + * This should only be called once after the tests are run. + * This is used to remove the fixtures from the phpBB install + */ + static public function tearDownAfterClass() + { + parent::tearDownAfterClass(); - // Copy our ext/ files from the test case to the board - self::$copied_files = array_merge(self::$copied_files, self::$helper->copy_dir(dirname(__FILE__) . '/../extension/ext/', $phpbb_root_path . 'ext/')); + self::$helper->restore_original_ext_dir(); } public function setUp() @@ -84,29 +83,6 @@ class phpbb_functional_extension_acp_test extends phpbb_functional_test_case $this->add_lang('acp/extensions'); } - /** - * This should only be called once after the tests are run. - * This is used to remove the files copied to the phpBB install - */ - static public function tearDownAfterClass() - { - global $phpbb_root_path; - - if (file_exists($phpbb_root_path . 'store/temp_ext/')) - { - // Copy back the board installed extensions from the temp directory - self::$helper->copy_dir($phpbb_root_path . 'store/temp_ext/', $phpbb_root_path . 'ext/'); - } - - // Remove all of the files we copied around (from board ext -> temp_ext, from test ext -> board ext) - self::$helper->remove_files(self::$copied_files); - - if (file_exists($phpbb_root_path . 'store/temp_ext/')) - { - self::$helper->empty_dir($phpbb_root_path . 'store/temp_ext/'); - } - } - public function test_list() { $crawler = self::request('GET', 'adm/index.php?i=acp_extensions&mode=main&sid=' . $this->sid); diff --git a/tests/functional/extension_controller_test.php b/tests/functional/extension_controller_test.php index a09035cb2b..c789ea160d 100644 --- a/tests/functional/extension_controller_test.php +++ b/tests/functional/extension_controller_test.php @@ -15,6 +15,8 @@ class phpbb_functional_extension_controller_test extends phpbb_functional_test_c { protected $phpbb_extension_manager; + static private $helper; + static protected $fixtures = array( 'foo/bar/config/routing.yml', 'foo/bar/config/services.yml', @@ -28,30 +30,10 @@ class phpbb_functional_extension_controller_test extends phpbb_functional_test_c */ static public function setUpBeforeClass() { - global $phpbb_root_path; parent::setUpBeforeClass(); - $directories = array( - $phpbb_root_path . 'ext/foo/bar/', - $phpbb_root_path . 'ext/foo/bar/config/', - $phpbb_root_path . 'ext/foo/bar/controller/', - $phpbb_root_path . 'ext/foo/bar/styles/prosilver/template', - ); - - foreach ($directories as $dir) - { - if (!is_dir($dir)) - { - mkdir($dir, 0777, true); - } - } - - foreach (self::$fixtures as $fixture) - { - copy( - "tests/functional/fixtures/ext/$fixture", - "{$phpbb_root_path}ext/$fixture"); - } + self::$helper = new phpbb_test_case_helpers(self); + self::$helper->copy_ext_fixtures(dirname(__FILE__) . '/fixtures/ext/', self::$fixtures); } /** @@ -60,20 +42,9 @@ class phpbb_functional_extension_controller_test extends phpbb_functional_test_c */ static public function tearDownAfterClass() { - global $phpbb_root_path; - - foreach (self::$fixtures as $fixture) - { - unlink("{$phpbb_root_path}ext/$fixture"); - } + parent::tearDownAfterClass(); - rmdir("{$phpbb_root_path}ext/foo/bar/config"); - rmdir("{$phpbb_root_path}ext/foo/bar/controller"); - rmdir("{$phpbb_root_path}ext/foo/bar/styles/prosilver/template"); - rmdir("{$phpbb_root_path}ext/foo/bar/styles/prosilver"); - rmdir("{$phpbb_root_path}ext/foo/bar/styles"); - rmdir("{$phpbb_root_path}ext/foo/bar"); - rmdir("{$phpbb_root_path}ext/foo"); + self::$helper->restore_original_ext_dir(); } public function setUp() diff --git a/tests/functional/extension_module_test.php b/tests/functional/extension_module_test.php index c8686e0ac6..e95f0b7e3f 100644 --- a/tests/functional/extension_module_test.php +++ b/tests/functional/extension_module_test.php @@ -16,33 +16,23 @@ require_once dirname(__FILE__) . '/../../phpBB/includes/acp/acp_modules.php'; class phpbb_functional_extension_module_test extends phpbb_functional_test_case { protected $phpbb_extension_manager; - static private $copied_files = array(); + static private $helper; + static protected $fixtures = array( + '', + ); + /** * This should only be called once before the tests are run. * This is used to copy the fixtures to the phpBB install */ static public function setUpBeforeClass() { - global $phpbb_root_path; parent::setUpBeforeClass(); self::$helper = new phpbb_test_case_helpers(self); - - self::$copied_files = array(); - - if (file_exists($phpbb_root_path . 'ext/')) - { - // First, move any extensions setup on the board to a temp directory - self::$copied_files = self::$helper->copy_dir($phpbb_root_path . 'ext/', $phpbb_root_path . 'store/temp_ext/'); - - // Then empty the ext/ directory on the board (for accurate test cases) - self::$helper->empty_dir($phpbb_root_path . 'ext/'); - } - - // Copy our ext/ files from the test case to the board - self::$copied_files = array_merge(self::$copied_files, self::$helper->copy_dir(dirname(__FILE__) . '/fixtures/ext/', $phpbb_root_path . 'ext/')); + self::$helper->copy_ext_fixtures(dirname(__FILE__) . '/fixtures/ext/', self::$fixtures); } /** @@ -51,21 +41,9 @@ class phpbb_functional_extension_module_test extends phpbb_functional_test_case */ static public function tearDownAfterClass() { - global $phpbb_root_path; - - if (file_exists($phpbb_root_path . 'store/temp_ext/')) - { - // Copy back the board installed extensions from the temp directory - self::$helper->copy_dir($phpbb_root_path . 'store/temp_ext/', $phpbb_root_path . 'ext/'); - } - - // Remove all of the files we copied around (from board ext -> temp_ext, from test ext -> board ext) - self::$helper->remove_files(self::$copied_files); + parent::tearDownAfterClass(); - if (file_exists($phpbb_root_path . 'store/temp_ext/')) - { - self::$helper->empty_dir($phpbb_root_path . 'store/temp_ext/'); - } + self::$helper->restore_original_ext_dir(); } public function setUp() diff --git a/tests/functional/extension_permission_lang_test.php b/tests/functional/extension_permission_lang_test.php index 04c3a9d497..fe8ea95cf0 100644 --- a/tests/functional/extension_permission_lang_test.php +++ b/tests/functional/extension_permission_lang_test.php @@ -16,8 +16,6 @@ class phpbb_functional_extension_permission_lang_test extends phpbb_functional_t static private $helper; - static private $copied_files = array(); - static protected $fixtures = array( 'foo/bar/language/en/', ); @@ -28,27 +26,10 @@ class phpbb_functional_extension_permission_lang_test extends phpbb_functional_t */ static public function setUpBeforeClass() { - global $phpbb_root_path; parent::setUpBeforeClass(); self::$helper = new phpbb_test_case_helpers(self); - - self::$copied_files = array(); - - if (file_exists($phpbb_root_path . 'ext/')) - { - // First, move any extensions setup on the board to a temp directory - self::$copied_files = self::$helper->copy_dir($phpbb_root_path . 'ext/', $phpbb_root_path . 'store/temp_ext/'); - - // Then empty the ext/ directory on the board (for accurate test cases) - self::$helper->empty_dir($phpbb_root_path . 'ext/'); - } - - // Copy our ext/ files from the test case to the board - foreach (self::$fixtures as $fixture) - { - self::$copied_files = array_merge(self::$copied_files, self::$helper->copy_dir(dirname(__FILE__) . '/fixtures/ext/' . $fixture, $phpbb_root_path . 'ext/' . $fixture)); - } + self::$helper->copy_ext_fixtures(dirname(__FILE__) . '/fixtures/ext/', self::$fixtures); } /** @@ -57,21 +38,9 @@ class phpbb_functional_extension_permission_lang_test extends phpbb_functional_t */ static public function tearDownAfterClass() { - global $phpbb_root_path; - - if (file_exists($phpbb_root_path . 'store/temp_ext/')) - { - // Copy back the board installed extensions from the temp directory - self::$helper->copy_dir($phpbb_root_path . 'store/temp_ext/', $phpbb_root_path . 'ext/'); - } - - // Remove all of the files we copied around (from board ext -> temp_ext, from test ext -> board ext) - self::$helper->remove_files(self::$copied_files); - - if (file_exists($phpbb_root_path . 'store/temp_ext/')) - { - self::$helper->empty_dir($phpbb_root_path . 'store/temp_ext/'); - } + parent::tearDownAfterClass(); + + self::$helper->restore_original_ext_dir(); } public function setUp() diff --git a/tests/functional/metadata_manager_test.php b/tests/functional/metadata_manager_test.php index 7e98b0d025..9d36a41354 100644 --- a/tests/functional/metadata_manager_test.php +++ b/tests/functional/metadata_manager_test.php @@ -16,7 +16,7 @@ class phpbb_functional_metadata_manager_test extends phpbb_functional_test_case { protected $phpbb_extension_manager; - static private $helpers; + static private $helper; static protected $fixtures = array( 'foo/bar/', @@ -28,20 +28,10 @@ class phpbb_functional_metadata_manager_test extends phpbb_functional_test_case */ static public function setUpBeforeClass() { - global $phpbb_root_path; parent::setUpBeforeClass(); - self::$helpers = new phpbb_test_case_helpers(self); - - if (!file_exists($phpbb_root_path . 'ext/foo/bar/')) - { - self::$helpers->makedirs($phpbb_root_path . 'ext/foo/bar/'); - } - - foreach (self::$fixtures as $fixture) - { - self::$helpers->copy_dir(dirname(__FILE__) . '/fixtures/ext/' . $fixture, $phpbb_root_path . 'ext/' . $fixture); - } + self::$helper = new phpbb_test_case_helpers(self); + self::$helper->copy_ext_fixtures(dirname(__FILE__) . '/fixtures/ext/', self::$fixtures); } /** @@ -50,13 +40,9 @@ class phpbb_functional_metadata_manager_test extends phpbb_functional_test_case */ static public function tearDownAfterClass() { - global $phpbb_root_path; + parent::tearDownAfterClass(); - foreach (self::$fixtures as $fixture) - { - self::$helpers->empty_dir($phpbb_root_path . 'ext/' . $fixture); - } - self::$helpers->empty_dir($phpbb_root_path . 'ext/foo/'); + self::$helper->restore_original_ext_dir(); } public function setUp() diff --git a/tests/test_framework/phpbb_test_case_helpers.php b/tests/test_framework/phpbb_test_case_helpers.php index 0e0b5c2a8f..367bd3b142 100644 --- a/tests/test_framework/phpbb_test_case_helpers.php +++ b/tests/test_framework/phpbb_test_case_helpers.php @@ -38,7 +38,7 @@ class phpbb_test_case_helpers // Copy our ext/ files from the test case to the board foreach ($fixtures as $fixture) { - $this->copied_files = array_merge($this->copied_files, $this->copy_dir($fixtures_dir . 'ext/' . $fixture, $phpbb_root_path . 'ext/' . $fixture)); + $this->copied_files = array_merge($this->copied_files, $this->copy_dir($fixtures_dir . $fixture, $phpbb_root_path . 'ext/' . $fixture)); } } -- cgit v1.2.1 From 7546c3a7a76a7293b3c1524097098f3f19c39666 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sat, 8 Jun 2013 17:14:20 +0200 Subject: [ticket/11550] Fixtures should only be directories not files PHPBB3-11550 --- tests/functional/extension_controller_test.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'tests') diff --git a/tests/functional/extension_controller_test.php b/tests/functional/extension_controller_test.php index c789ea160d..ea5a51291d 100644 --- a/tests/functional/extension_controller_test.php +++ b/tests/functional/extension_controller_test.php @@ -18,10 +18,9 @@ class phpbb_functional_extension_controller_test extends phpbb_functional_test_c static private $helper; static protected $fixtures = array( - 'foo/bar/config/routing.yml', - 'foo/bar/config/services.yml', - 'foo/bar/controller/controller.php', - 'foo/bar/styles/prosilver/template/foo_bar_body.html', + 'foo/bar/config/', + 'foo/bar/controller/', + 'foo/bar/styles/prosilver/template/', ); /** -- cgit v1.2.1 From 0b3f18208354aabc5b9c8901c2950e9626c3e5f3 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sun, 9 Jun 2013 17:40:33 +0200 Subject: [ticket/11550] We use a different fixture set for extension_acp_test.php PHPBB3-11550 --- tests/functional/extension_acp_test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/functional/extension_acp_test.php b/tests/functional/extension_acp_test.php index ada17397d7..5f8e3762a6 100644 --- a/tests/functional/extension_acp_test.php +++ b/tests/functional/extension_acp_test.php @@ -27,7 +27,7 @@ class phpbb_functional_extension_acp_test extends phpbb_functional_test_case parent::setUpBeforeClass(); self::$helper = new phpbb_test_case_helpers(self); - self::$helper->copy_ext_fixtures(dirname(__FILE__) . '/fixtures/ext/', self::$fixtures); + self::$helper->copy_ext_fixtures(dirname(__FILE__) . '/../extension/ext/', self::$fixtures); } /** -- cgit v1.2.1 From 68d15f0f14dfdc827e1169a73c194a9e30795605 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 11 Jun 2013 11:14:24 +0200 Subject: [ticket/11550] Move comments to correct function PHPBB3-11550 --- tests/functional/extension_acp_test.php | 8 -------- tests/functional/extension_controller_test.php | 8 -------- tests/functional/extension_module_test.php | 8 -------- tests/functional/extension_permission_lang_test.php | 8 -------- tests/functional/metadata_manager_test.php | 8 -------- tests/test_framework/phpbb_test_case_helpers.php | 8 ++++++++ 6 files changed, 8 insertions(+), 40 deletions(-) (limited to 'tests') diff --git a/tests/functional/extension_acp_test.php b/tests/functional/extension_acp_test.php index 5f8e3762a6..b36f2c6aac 100644 --- a/tests/functional/extension_acp_test.php +++ b/tests/functional/extension_acp_test.php @@ -18,10 +18,6 @@ class phpbb_functional_extension_acp_test extends phpbb_functional_test_case '', ); - /** - * This should only be called once before the tests are run. - * This is used to copy the fixtures to the phpBB install - */ static public function setUpBeforeClass() { parent::setUpBeforeClass(); @@ -30,10 +26,6 @@ class phpbb_functional_extension_acp_test extends phpbb_functional_test_case self::$helper->copy_ext_fixtures(dirname(__FILE__) . '/../extension/ext/', self::$fixtures); } - /** - * This should only be called once after the tests are run. - * This is used to remove the fixtures from the phpBB install - */ static public function tearDownAfterClass() { parent::tearDownAfterClass(); diff --git a/tests/functional/extension_controller_test.php b/tests/functional/extension_controller_test.php index ea5a51291d..9ddf1e3e5c 100644 --- a/tests/functional/extension_controller_test.php +++ b/tests/functional/extension_controller_test.php @@ -23,10 +23,6 @@ class phpbb_functional_extension_controller_test extends phpbb_functional_test_c 'foo/bar/styles/prosilver/template/', ); - /** - * This should only be called once before the tests are run. - * This is used to copy the fixtures to the phpBB install - */ static public function setUpBeforeClass() { parent::setUpBeforeClass(); @@ -35,10 +31,6 @@ class phpbb_functional_extension_controller_test extends phpbb_functional_test_c self::$helper->copy_ext_fixtures(dirname(__FILE__) . '/fixtures/ext/', self::$fixtures); } - /** - * This should only be called once after the tests are run. - * This is used to remove the fixtures from the phpBB install - */ static public function tearDownAfterClass() { parent::tearDownAfterClass(); diff --git a/tests/functional/extension_module_test.php b/tests/functional/extension_module_test.php index e95f0b7e3f..12113bedac 100644 --- a/tests/functional/extension_module_test.php +++ b/tests/functional/extension_module_test.php @@ -23,10 +23,6 @@ class phpbb_functional_extension_module_test extends phpbb_functional_test_case '', ); - /** - * This should only be called once before the tests are run. - * This is used to copy the fixtures to the phpBB install - */ static public function setUpBeforeClass() { parent::setUpBeforeClass(); @@ -35,10 +31,6 @@ class phpbb_functional_extension_module_test extends phpbb_functional_test_case self::$helper->copy_ext_fixtures(dirname(__FILE__) . '/fixtures/ext/', self::$fixtures); } - /** - * This should only be called once after the tests are run. - * This is used to remove the fixtures from the phpBB install - */ static public function tearDownAfterClass() { parent::tearDownAfterClass(); diff --git a/tests/functional/extension_permission_lang_test.php b/tests/functional/extension_permission_lang_test.php index fe8ea95cf0..6c1720735c 100644 --- a/tests/functional/extension_permission_lang_test.php +++ b/tests/functional/extension_permission_lang_test.php @@ -20,10 +20,6 @@ class phpbb_functional_extension_permission_lang_test extends phpbb_functional_t 'foo/bar/language/en/', ); - /** - * This should only be called once before the tests are run. - * This is used to copy the fixtures to the phpBB install - */ static public function setUpBeforeClass() { parent::setUpBeforeClass(); @@ -32,10 +28,6 @@ class phpbb_functional_extension_permission_lang_test extends phpbb_functional_t self::$helper->copy_ext_fixtures(dirname(__FILE__) . '/fixtures/ext/', self::$fixtures); } - /** - * This should only be called once after the tests are run. - * This is used to remove the fixtures from the phpBB install - */ static public function tearDownAfterClass() { parent::tearDownAfterClass(); diff --git a/tests/functional/metadata_manager_test.php b/tests/functional/metadata_manager_test.php index 9d36a41354..c55e7373ea 100644 --- a/tests/functional/metadata_manager_test.php +++ b/tests/functional/metadata_manager_test.php @@ -22,10 +22,6 @@ class phpbb_functional_metadata_manager_test extends phpbb_functional_test_case 'foo/bar/', ); - /** - * This should only be called once before the tests are run. - * This is used to copy the fixtures to the phpBB install - */ static public function setUpBeforeClass() { parent::setUpBeforeClass(); @@ -34,10 +30,6 @@ class phpbb_functional_metadata_manager_test extends phpbb_functional_test_case self::$helper->copy_ext_fixtures(dirname(__FILE__) . '/fixtures/ext/', self::$fixtures); } - /** - * This should only be called once after the tests are run. - * This is used to remove the fixtures from the phpBB install - */ static public function tearDownAfterClass() { parent::tearDownAfterClass(); diff --git a/tests/test_framework/phpbb_test_case_helpers.php b/tests/test_framework/phpbb_test_case_helpers.php index 367bd3b142..1b08f2368f 100644 --- a/tests/test_framework/phpbb_test_case_helpers.php +++ b/tests/test_framework/phpbb_test_case_helpers.php @@ -20,6 +20,10 @@ class phpbb_test_case_helpers private $copied_files = array(); + /** + * This should only be called once before the tests are run. + * This is used to copy the fixtures to the phpBB install + */ public function copy_ext_fixtures($fixtures_dir, $fixtures) { global $phpbb_root_path; @@ -42,6 +46,10 @@ class phpbb_test_case_helpers } } + /** + * This should only be called once after the tests are run. + * This is used to remove the fixtures from the phpBB install + */ public function restore_original_ext_dir() { global $phpbb_root_path; -- cgit v1.2.1 From 007cd6177630c3f70521be130a18f0139b58c184 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 11 Jun 2013 11:37:28 +0200 Subject: [ticket/11550] Specify a valid path so it's clearer that it must be a path PHPBB3-11550 --- tests/functional/extension_acp_test.php | 2 +- tests/functional/extension_module_test.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/functional/extension_acp_test.php b/tests/functional/extension_acp_test.php index b36f2c6aac..8614c0c963 100644 --- a/tests/functional/extension_acp_test.php +++ b/tests/functional/extension_acp_test.php @@ -15,7 +15,7 @@ class phpbb_functional_extension_acp_test extends phpbb_functional_test_case static private $helper; static protected $fixtures = array( - '', + './', ); static public function setUpBeforeClass() diff --git a/tests/functional/extension_module_test.php b/tests/functional/extension_module_test.php index 12113bedac..c573ea5410 100644 --- a/tests/functional/extension_module_test.php +++ b/tests/functional/extension_module_test.php @@ -20,7 +20,7 @@ class phpbb_functional_extension_module_test extends phpbb_functional_test_case static private $helper; static protected $fixtures = array( - '', + './', ); static public function setUpBeforeClass() -- cgit v1.2.1 From 5e8054f04598c449799a594fcb96cfeb8abf925a Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 11 Jun 2013 13:24:55 +0200 Subject: [ticket/11601] Split post_setup_synchronisation logic from xml parsing PHPBB3-11601 --- .../phpbb_database_test_connection_manager.php | 27 +++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) (limited to 'tests') diff --git a/tests/test_framework/phpbb_database_test_connection_manager.php b/tests/test_framework/phpbb_database_test_connection_manager.php index bcd52b1794..30f1fa6589 100644 --- a/tests/test_framework/phpbb_database_test_connection_manager.php +++ b/tests/test_framework/phpbb_database_test_connection_manager.php @@ -480,12 +480,33 @@ class phpbb_database_test_connection_manager * @return null */ public function post_setup_synchronisation($xml_data_set) + { + $table_names = $xml_data_set->getTableNames(); + + $tables = array(); + foreach ($table_names as $table) + { + $tables[$table] = $xml_data_set->getTableMetaData($table)->getColumns(); + } + + $this->database_synchronisation($tables); + } + + /** + * Performs synchronisations on the database after a fixture has been loaded + * + * @param array $table_column_map Array of tables/columns to synchronise + * array(table1 => array(column1, column2)) + * + * @return null + */ + public function database_synchronisation($table_column_map) { $this->ensure_connected(__METHOD__); $queries = array(); - // Get escaped versions of the table names used in the fixture - $table_names = array_map(array($this->pdo, 'PDO::quote'), $xml_data_set->getTableNames()); + // Get escaped versions of the table names to synchronise + $table_names = array_map(array($this->pdo, 'PDO::quote'), array_keys($table_column_map)); switch ($this->config['dbms']) { @@ -542,7 +563,7 @@ class phpbb_database_test_connection_manager while ($row = $result->fetch(PDO::FETCH_ASSOC)) { // Get the columns used in the fixture for this table - $column_names = $xml_data_set->getTableMetaData($row['table_name'])->getColumns(); + $column_names = $table_column_map[$row['table_name']]; // Skip sequences that weren't specified in the fixture if (!in_array($row['column_name'], $column_names)) -- cgit v1.2.1 From 33bce3fac6c29787e121e5d000251353637dd422 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 11 Jun 2013 13:26:17 +0200 Subject: [ticket/11601] Add protected method for database sync and call it PHPBB3-11601 --- tests/test_framework/phpbb_database_test_case.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'tests') diff --git a/tests/test_framework/phpbb_database_test_case.php b/tests/test_framework/phpbb_database_test_case.php index beddece470..28d3a716f0 100644 --- a/tests/test_framework/phpbb_database_test_case.php +++ b/tests/test_framework/phpbb_database_test_case.php @@ -62,6 +62,21 @@ abstract class phpbb_database_test_case extends PHPUnit_Extensions_Database_Test } } + /** + * Performs synchronisations for a given table/column set on the database + * + * @param array $table_column_map Information about the tables/columns to synchronise + * + * @return null + */ + protected function database_synchronisation($table_column_map) + { + $config = $this->get_database_config(); + $manager = $this->create_connection_manager($config); + $manager->connect(); + $manager->database_synchronisation($table_column_map); + } + public function createXMLDataSet($path) { $db_config = $this->get_database_config(); -- cgit v1.2.1 From d02f98c63530454700661fc80354d66207ed8b02 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 11 Jun 2013 16:03:34 +0200 Subject: [ticket/11605] Use empty_dir to better delete files and dirs of extensions PHPBB3-11605 --- tests/test_framework/phpbb_test_case_helpers.php | 29 +++++------------------- 1 file changed, 6 insertions(+), 23 deletions(-) (limited to 'tests') diff --git a/tests/test_framework/phpbb_test_case_helpers.php b/tests/test_framework/phpbb_test_case_helpers.php index 1b08f2368f..8c91d357b8 100644 --- a/tests/test_framework/phpbb_test_case_helpers.php +++ b/tests/test_framework/phpbb_test_case_helpers.php @@ -54,14 +54,18 @@ class phpbb_test_case_helpers { global $phpbb_root_path; + // Remove all of the files we copied from test ext -> board ext + $this->empty_dir($phpbb_root_path . 'ext/'); + // Copy back the board installed extensions from the temp directory if (file_exists($phpbb_root_path . 'store/temp_ext/')) { $this->copy_dir($phpbb_root_path . 'store/temp_ext/', $phpbb_root_path . 'ext/'); + + // Remove all of the files we copied from board ext -> temp_ext + $this->empty_dir($phpbb_root_path . 'store/temp_ext/'); } - // Remove all of the files we copied around (from board ext -> temp_ext, from test ext -> board ext) - $this->remove_files($this->copied_files); $this->copied_files = array(); if (file_exists($phpbb_root_path . 'store/temp_ext/')) @@ -254,27 +258,6 @@ class phpbb_test_case_helpers return $copied_files; } - /** - * Remove files/directories that are listed in an array - * Designed for use with $this->copy_dir() - * - * @param array $file_list - */ - public function remove_files($file_list) - { - foreach ($file_list as $file) - { - if (is_dir($file)) - { - rmdir($file); - } - else - { - unlink($file); - } - } - } - /** * Empty directory (remove any subdirectories/files below) * -- cgit v1.2.1 From fa8d5c7d209b616e9552e072e38242ef4e74aaca Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 11 Jun 2013 16:04:23 +0200 Subject: [ticket/11605] Remove unused copied_files property PHPBB3-11605 --- tests/test_framework/phpbb_test_case_helpers.php | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) (limited to 'tests') diff --git a/tests/test_framework/phpbb_test_case_helpers.php b/tests/test_framework/phpbb_test_case_helpers.php index 8c91d357b8..50b2bf03ec 100644 --- a/tests/test_framework/phpbb_test_case_helpers.php +++ b/tests/test_framework/phpbb_test_case_helpers.php @@ -18,8 +18,6 @@ class phpbb_test_case_helpers $this->test_case = $test_case; } - private $copied_files = array(); - /** * This should only be called once before the tests are run. * This is used to copy the fixtures to the phpBB install @@ -28,12 +26,10 @@ class phpbb_test_case_helpers { global $phpbb_root_path; - $this->copied_files = array(); - if (file_exists($phpbb_root_path . 'ext/')) { // First, move any extensions setup on the board to a temp directory - $this->copied_files = $this->copy_dir($phpbb_root_path . 'ext/', $phpbb_root_path . 'store/temp_ext/'); + $this->copy_dir($phpbb_root_path . 'ext/', $phpbb_root_path . 'store/temp_ext/'); // Then empty the ext/ directory on the board (for accurate test cases) $this->empty_dir($phpbb_root_path . 'ext/'); @@ -42,7 +38,7 @@ class phpbb_test_case_helpers // Copy our ext/ files from the test case to the board foreach ($fixtures as $fixture) { - $this->copied_files = array_merge($this->copied_files, $this->copy_dir($fixtures_dir . $fixture, $phpbb_root_path . 'ext/' . $fixture)); + $this->copy_dir($fixtures_dir . $fixture, $phpbb_root_path . 'ext/' . $fixture); } } @@ -66,8 +62,6 @@ class phpbb_test_case_helpers $this->empty_dir($phpbb_root_path . 'store/temp_ext/'); } - $this->copied_files = array(); - if (file_exists($phpbb_root_path . 'store/temp_ext/')) { $this->empty_dir($phpbb_root_path . 'store/temp_ext/'); -- cgit v1.2.1 From d5f651c51406fb71dd5075be8a33a904aa570450 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 11 Jun 2013 16:16:17 +0200 Subject: [ticket/11599] Copy the forums into a static array for later reuse PHPBB3-11599 --- tests/tree/nestedset_forum_base.php | 59 ++++++++++++++++++++++++++----------- 1 file changed, 42 insertions(+), 17 deletions(-) (limited to 'tests') diff --git a/tests/tree/nestedset_forum_base.php b/tests/tree/nestedset_forum_base.php index 776e822280..43680609f8 100644 --- a/tests/tree/nestedset_forum_base.php +++ b/tests/tree/nestedset_forum_base.php @@ -59,27 +59,52 @@ class phpbb_tests_tree_nestedset_forum_base extends phpbb_database_test_case $this->set = new phpbb_tree_nestedset_forum($this->db, $this->lock, 'phpbb_forums'); $this->set_up_forums(); - - $sql = "UPDATE phpbb_forums - SET forum_parents = 'a:0:{}'"; - $this->db->sql_query($sql); } 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); + static $forums; + + if (empty($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); + + // Updating forum_parents column here so it's not empty + // This is required, so we can see whether the methods + // correctly clear the values. + $sql = "UPDATE phpbb_forums + SET forum_parents = 'a:0:{}'"; + $this->db->sql_query($sql); + + // Copy the forums into a static array, so we can reuse the list later + $sql = 'SELECT * + FROM phpbb_forums'; + $result = $this->db->sql_query($sql); + $forums = $this->db->sql_fetchrowset($result); + $this->db->sql_freeresult($result); + } + else + { + $buffer = new phpbb_db_sql_insert_buffer($this->db, 'phpbb_forums'); + $buffer->insert_all($forums); + $buffer->flush(); + + $this->database_synchronisation(array( + 'phpbb_forums' => array('forum_id'), + )); + } } protected function create_forum($name, $parent_id = 0) -- cgit v1.2.1 From b8678f467824eed9daa97eacca197348c945e3e9 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Mon, 17 Jun 2013 12:47:09 +0200 Subject: [ticket/11561] Specify used tables in notification fixture, so they are emptied PHPBB3-11561 --- tests/notification/fixtures/notification.xml | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'tests') diff --git a/tests/notification/fixtures/notification.xml b/tests/notification/fixtures/notification.xml index 38e5f811dd..c7b2d03ff1 100644 --- a/tests/notification/fixtures/notification.xml +++ b/tests/notification/fixtures/notification.xml @@ -1,5 +1,13 @@ + +
+ +
+ +
+ +
-- cgit v1.2.1 From 516581c41edaa5f565ef90bac14cdbdc054e7914 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Tue, 18 Jun 2013 15:04:48 +0200 Subject: [ticket/11604] Use variables for config.php filesnames. PHPBB3-11604 --- tests/test_framework/phpbb_functional_test_case.php | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'tests') diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index 651ab013c7..1b47cbe125 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -184,15 +184,19 @@ class phpbb_functional_test_case extends phpbb_test_case self::$config['table_prefix'] = 'phpbb_'; self::recreate_database(self::$config); - if (file_exists($phpbb_root_path . "config.$phpEx")) + $config_file = $phpbb_root_path . "config.$phpEx"; + $config_file_dev = $phpbb_root_path . "config_dev.$phpEx"; + $config_file_test = $phpbb_root_path . "config_test.$phpEx"; + + if (file_exists($config_file)) { - if (!file_exists($phpbb_root_path . "config_dev.$phpEx")) + if (!file_exists($config_file_dev)) { - rename($phpbb_root_path . "config.$phpEx", $phpbb_root_path . "config_dev.$phpEx"); + rename($config_file, $config_file_dev); } else { - unlink($phpbb_root_path . "config.$phpEx"); + unlink($config_file); } } @@ -254,7 +258,7 @@ class phpbb_functional_test_case extends phpbb_test_case $crawler = self::submit($form); self::assertContains('The configuration file has been written.', $crawler->filter('#main')->text()); - file_put_contents($phpbb_root_path . "config.$phpEx", phpbb_create_config_file_data(self::$config, self::$config['dbms'], array(), true, true)); + file_put_contents($config_file, phpbb_create_config_file_data(self::$config, self::$config['dbms'], array(), true, true)); $form = $crawler->selectButton('submit')->form(); $crawler = self::submit($form); @@ -281,7 +285,7 @@ class phpbb_functional_test_case extends phpbb_test_case $crawler = self::submit($form); self::assertContains('You have successfully installed', $crawler->text()); - copy($phpbb_root_path . "config.$phpEx", $phpbb_root_path . "config_test.$phpEx"); + copy($config_file, $config_file_test); } static private function recreate_database($config) -- cgit v1.2.1 From 21f839494ddb55d1c4aefeed113b5debe9b2e1b3 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Tue, 18 Jun 2013 15:21:28 +0200 Subject: [ticket/11604] Fix case where config.php is not generated by phpBB. PHPBB3-11604 --- .../test_framework/phpbb_functional_test_case.php | 24 +++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index 1b47cbe125..16ed9f5a1e 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -257,8 +257,30 @@ class phpbb_functional_test_case extends phpbb_test_case $form = $crawler->selectButton('submit')->form(); $crawler = self::submit($form); + $config_writable = strpos($crawler->filter('#main')->text(), 'It was not possible to write the configuration file.') === false; + $config_php_data = phpbb_create_config_file_data(self::$config, self::$config['dbms'], array(), true, true); + + if (!$config_writable) + { + // phpBB could not write to the config.php file, so we have to "Download" it. + self::assertContains('Download config', $crawler->filter('#main')->text()); + + file_put_contents($config_file, $config_php_data); + + $form = $crawler->selectButton('dldone')->form(); + $crawler = self::submit($form); + } + self::assertContains('The configuration file has been written.', $crawler->filter('#main')->text()); - file_put_contents($config_file, phpbb_create_config_file_data(self::$config, self::$config['dbms'], array(), true, true)); + + // Overwrite the config.php file generated by phpBB in order to get the + // DEBUG constants defined if possible. It should be possible when unit + // tests run as the same user as phpBB. + if ($config_writable && is_writable($config_file)) + { + file_put_contents($config_file, $config_php_data); + } + $form = $crawler->selectButton('submit')->form(); $crawler = self::submit($form); -- cgit v1.2.1 From 1af6dc22e2ccb13b610a932a9b043d2d9d4ea17d Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Wed, 19 Jun 2013 17:03:41 +0200 Subject: [ticket/11604] Skip installer step where config.php is created. PHPBB3-11604 --- .../test_framework/phpbb_functional_test_case.php | 47 +++++++++++++--------- 1 file changed, 27 insertions(+), 20 deletions(-) (limited to 'tests') diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index 16ed9f5a1e..6b423b56fd 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -220,10 +220,12 @@ class phpbb_functional_test_case extends phpbb_test_case self::assertContains('Welcome to Installation', $crawler->filter('#main')->text()); $form = $crawler->selectButton('submit')->form(); + // install/index.php?mode=install&sub=requirements $crawler = self::submit($form); self::assertContains('Installation compatibility', $crawler->filter('#main')->text()); $form = $crawler->selectButton('submit')->form(); + // install/index.php?mode=install&sub=database $crawler = self::submit($form); self::assertContains('Database configuration', $crawler->filter('#main')->text()); $form = $crawler->selectButton('submit')->form(array( @@ -237,10 +239,12 @@ class phpbb_functional_test_case extends phpbb_test_case 'table_prefix' => self::$config['table_prefix'], )); + // install/index.php?mode=install&sub=database $crawler = self::submit($form); self::assertContains('Successful connection', $crawler->filter('#main')->text()); $form = $crawler->selectButton('submit')->form(); + // install/index.php?mode=install&sub=administrator $crawler = self::submit($form); self::assertContains('Administrator configuration', $crawler->filter('#main')->text()); $form = $crawler->selectButton('submit')->form(array( @@ -252,38 +256,38 @@ class phpbb_functional_test_case extends phpbb_test_case 'board_email2' => 'nobody@example.com', )); + // install/index.php?mode=install&sub=administrator $crawler = self::submit($form); self::assertContains('Tests passed', $crawler->filter('#main')->text()); $form = $crawler->selectButton('submit')->form(); - $crawler = self::submit($form); - $config_writable = strpos($crawler->filter('#main')->text(), 'It was not possible to write the configuration file.') === false; + // We have to skip install/index.php?mode=install&sub=config_file + // because that step will create a config.php file if phpBB has the + // permission to do so. We have to create the config file on our own + // in order to get the DEBUG constants defined. $config_php_data = phpbb_create_config_file_data(self::$config, self::$config['dbms'], array(), true, true); - - if (!$config_writable) + $config_created = file_put_contents($config_file, $config_php_data) !== false; + if (!$config_created) { - // phpBB could not write to the config.php file, so we have to "Download" it. - self::assertContains('Download config', $crawler->filter('#main')->text()); - - file_put_contents($config_file, $config_php_data); - - $form = $crawler->selectButton('dldone')->form(); - $crawler = self::submit($form); + self::markTestSkipped("Could not write $config_file file."); } - self::assertContains('The configuration file has been written.', $crawler->filter('#main')->text()); - - // Overwrite the config.php file generated by phpBB in order to get the - // DEBUG constants defined if possible. It should be possible when unit - // tests run as the same user as phpBB. - if ($config_writable && is_writable($config_file)) + // We also have to create a install lock that is normally created by + // the installer. The file will be removed by the final step of the + // installer. + $install_lock_file = $phpbb_root_path . 'cache/install_lock'; + $lock_created = file_put_contents($install_lock_file, '') !== false; + if (!$lock_created) { - file_put_contents($config_file, $config_php_data); + self::markTestSkipped("Could not create $lock_created file."); } + @chmod($install_lock_file, 0666); - $form = $crawler->selectButton('submit')->form(); + // install/index.php?mode=install&sub=advanced + $form_data = $form->getValues(); + unset($form_data['submit']); - $crawler = self::submit($form); + $crawler = self::request('POST', 'install/index.php?mode=install&sub=advanced', $form_data); self::assertContains('The settings on this page are only necessary to set if you know that you require something different from the default.', $crawler->filter('#main')->text()); $form = $crawler->selectButton('submit')->form(array( 'email_enable' => true, @@ -300,13 +304,16 @@ class phpbb_functional_test_case extends phpbb_test_case 'script_path' => $parseURL['path'], )); + // install/index.php?mode=install&sub=create_table $crawler = self::submit($form); self::assertContains('The database tables used by phpBB', $crawler->filter('#main')->text()); self::assertContains('have been created and populated with some initial data.', $crawler->filter('#main')->text()); $form = $crawler->selectButton('submit')->form(); + // install/index.php?mode=install&sub=final $crawler = self::submit($form); self::assertContains('You have successfully installed', $crawler->text()); + copy($config_file, $config_file_test); } -- cgit v1.2.1 From 80e2d65399e7dcf9b53dada4929d7194275721ad Mon Sep 17 00:00:00 2001 From: Joseph Warner Date: Mon, 24 Jun 2013 12:05:29 -0400 Subject: [feature/auth-refactor] Initial auth unit test provider_db Initial work on a unit test for the provider_db login function. Does not work currently. PHPBB3-9734 --- tests/auth/fixtures/user.xml | 33 +++++++++++++++++++++++++++++++++ tests/auth/provider_db_test.php | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 73 insertions(+) create mode 100644 tests/auth/fixtures/user.xml create mode 100644 tests/auth/provider_db_test.php (limited to 'tests') diff --git a/tests/auth/fixtures/user.xml b/tests/auth/fixtures/user.xml new file mode 100644 index 0000000000..34584babbf --- /dev/null +++ b/tests/auth/fixtures/user.xml @@ -0,0 +1,33 @@ + + + + user_id + username + username_clean + user_password + user_passchg + user_pass_convert + user_email + user_type + user_login_attempts + user_permissions + user_sig + user_occ + user_interests + + 1 + foobar + foobar + $H$9E45lK6J8nLTSm9oJE5aNCSTFK9wqa/ + 0 + 0 + example@example.com + 0 + 0 + + + + + +
+
diff --git a/tests/auth/provider_db_test.php b/tests/auth/provider_db_test.php new file mode 100644 index 0000000000..c6355ae7f9 --- /dev/null +++ b/tests/auth/provider_db_test.php @@ -0,0 +1,40 @@ +createXMLDataSet(dirname(__FILE__).'/fixtures/user.xml'); + } + + public function test_login() + { + global $phpbb_root_path, $phpEx; + + $db = $this->new_dbal(); + $config = new phpbb_config(array( + 'ip_login_limit_max' => 0, + 'ip_login_limit_use_forwarded' => 0, + 'max_login_attempts' => 0, + )); + $request = $this->getMock('phpbb_request'); + $user = $this->getMock('phpbb_user'); + $provider = new phpbb_auth_provider_db($db, $config, $request, $user, $phpbb_root_path, $phpEx); + + $expected = array( + 'status' => LOGIN_SUCCESS, + 'error_msg' => false, + 'user_row' => '', + ); + $this->assertEquals($expected, $provider->login('example', 'example')); + } +} -- cgit v1.2.1 From 8e1a503f4437eb38de6a349a841db75648a81678 Mon Sep 17 00:00:00 2001 From: Joseph Warner Date: Tue, 25 Jun 2013 13:22:56 -0400 Subject: [feature/auth-refactor] Finish provider_db unit test for login Finishes the provider_db unit test for login. The test currently passes. PHPBB3-9734 --- tests/auth/provider_db_test.php | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/auth/provider_db_test.php b/tests/auth/provider_db_test.php index c6355ae7f9..d876683f84 100644 --- a/tests/auth/provider_db_test.php +++ b/tests/auth/provider_db_test.php @@ -33,8 +33,18 @@ class phpbb_auth_provider_db_test extends phpbb_database_test_case $expected = array( 'status' => LOGIN_SUCCESS, 'error_msg' => false, - 'user_row' => '', + 'user_row' => array( + 'user_id' => '1', + 'username' => 'foobar', + 'user_password' => '$H$9E45lK6J8nLTSm9oJE5aNCSTFK9wqa/', + 'user_passchg' => '0', + 'user_pass_convert' => '0', + 'user_email' => 'example@example.com', + 'user_type' => '0', + 'user_login_attempts' => '0', + ), ); - $this->assertEquals($expected, $provider->login('example', 'example')); + + $this->assertEquals($expected, $provider->login('foobar', 'example')); } } -- cgit v1.2.1 From 91c80dfc8eed6ed3cfa90732087741c8433acabf Mon Sep 17 00:00:00 2001 From: Joseph Warner Date: Tue, 25 Jun 2013 13:34:43 -0400 Subject: [feature/auth-refactor] Skeleton of provider_apache_test Creates a skeleton of the tests for provider_apache. PHPBB3-9734 --- tests/auth/provider_apache_test.php | 49 +++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 tests/auth/provider_apache_test.php (limited to 'tests') diff --git a/tests/auth/provider_apache_test.php b/tests/auth/provider_apache_test.php new file mode 100644 index 0000000000..d552c4131e --- /dev/null +++ b/tests/auth/provider_apache_test.php @@ -0,0 +1,49 @@ +new_dbal(); + $config = new phpbb_config(array()); + $request = $this->getMock('phpbb_request'); + $user = $this->getMock('phpbb_user'); + + $this->provider = new phpbb_auth_provider_apache($db, $config, $request, $user, $phpbb_root_path, $phpEx); + } + + public function getDataSet() + { + return $this->createXMLDataSet(dirname(__FILE__).'/fixtures/user.xml'); + } + + public function test_init() + { + $this->markTestIncomplete(); + } + + public function test_login() + { + $this->markTestIncomplete(); + } + + public function test_validate_session() + { + $this->markTestIncomplete(); + } +} -- cgit v1.2.1 From e5de05d8dbbcf0a38aa5c1c2a872765b163ccb31 Mon Sep 17 00:00:00 2001 From: Joseph Warner Date: Tue, 25 Jun 2013 14:05:40 -0400 Subject: [feature/auth-refactor] Test for init on provider_apache Provides a test for the init() method of provider_apache. Appears to be failing due to an error with the mock request class. PHPBB3-9734 --- tests/auth/provider_apache_test.php | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'tests') diff --git a/tests/auth/provider_apache_test.php b/tests/auth/provider_apache_test.php index d552c4131e..1530dcb746 100644 --- a/tests/auth/provider_apache_test.php +++ b/tests/auth/provider_apache_test.php @@ -12,6 +12,8 @@ require_once dirname(__FILE__).'/../../phpBB/includes/functions.php'; class phpbb_auth_provider_apache_test extends phpbb_database_test_case { protected $provider; + protected $user; + protected $request; protected function setup() { @@ -21,10 +23,10 @@ class phpbb_auth_provider_apache_test extends phpbb_database_test_case $db = $this->new_dbal(); $config = new phpbb_config(array()); - $request = $this->getMock('phpbb_request'); - $user = $this->getMock('phpbb_user'); + $this->request = $this->getMock('phpbb_request'); + $this->user = $this->getMock('phpbb_user'); - $this->provider = new phpbb_auth_provider_apache($db, $config, $request, $user, $phpbb_root_path, $phpEx); + $this->provider = new phpbb_auth_provider_apache($db, $config, $this->request, $this->user, $phpbb_root_path, $phpEx); } public function getDataSet() @@ -32,9 +34,15 @@ class phpbb_auth_provider_apache_test extends phpbb_database_test_case return $this->createXMLDataSet(dirname(__FILE__).'/fixtures/user.xml'); } + /** + * Test to see if a user is identified to Apache. Expects false if they are. + */ public function test_init() { - $this->markTestIncomplete(); + $this->user->data['username'] = 'foobar'; + $this->request->overwrite('PHP_AUTH_USER', 'foobar', phpbb_request_interface::SERVER); + + $this->assertFalse($this->provider->init()); } public function test_login() -- cgit v1.2.1 From 307dd9777b67e8a7628bb74eeba8cc55ab6a8f58 Mon Sep 17 00:00:00 2001 From: Joseph Warner Date: Tue, 25 Jun 2013 14:12:31 -0400 Subject: [feature/auth-refactor] Test login() for provider_apache Provides a test for the login() method for provider_apache. Appears to be failing due to an issue with the mock phpBB request class. PHPBB3-9734 --- tests/auth/provider_apache_test.php | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/auth/provider_apache_test.php b/tests/auth/provider_apache_test.php index 1530dcb746..4773e4fdc3 100644 --- a/tests/auth/provider_apache_test.php +++ b/tests/auth/provider_apache_test.php @@ -47,7 +47,26 @@ class phpbb_auth_provider_apache_test extends phpbb_database_test_case public function test_login() { - $this->markTestIncomplete(); + $username = 'foobar'; + $password = 'example'; + + $this->request->overwrite('PHP_AUTH_USER', $username, phpbb_request_interface::SERVER); + $this->request->overwrite('PHP_AUTH_PW', $password, phpbb_request_interface::SERVER); + + $expected = array( + 'status' => LOGIN_SUCCESS, + 'error_msg' => false, + 'user_row' => array( + 'user_id' => '1', + 'username' => 'foobar', + 'user_password' => '$H$9E45lK6J8nLTSm9oJE5aNCSTFK9wqa/', + 'user_passchg' => '0', + 'user_email' => 'example@example.com', + 'user_type' => '0', + ), + ); + + $this->assertEquals($expected, $this->provider->login($username, $password)); } public function test_validate_session() -- cgit v1.2.1 From 9e04328545c933aa801c52c1567efd3d2e06fcf3 Mon Sep 17 00:00:00 2001 From: Joseph Warner Date: Tue, 25 Jun 2013 14:24:47 -0400 Subject: [feature/auth-refactor] Test autologin() on provider_apache Provides a test for the autologin() method of provider_apache that assumes the user already exists in the database. PHPBB3-9734 --- tests/auth/provider_apache_test.php | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'tests') diff --git a/tests/auth/provider_apache_test.php b/tests/auth/provider_apache_test.php index 4773e4fdc3..6cfd676fc2 100644 --- a/tests/auth/provider_apache_test.php +++ b/tests/auth/provider_apache_test.php @@ -69,6 +69,34 @@ class phpbb_auth_provider_apache_test extends phpbb_database_test_case $this->assertEquals($expected, $this->provider->login($username, $password)); } + public function test_autologin() + { + $this->request->overwrite('PHP_AUTH_USER', 'foobar', phpbb_request_interface::SERVER); + $this->request->overwrite('PHP_AUTH_PW', 'example', phpbb_request_interface::SERVER); + + $expected = array( + 'status' => LOGIN_SUCCESS, + 'error_msg' => false, + 'user_row' => array( + 'user_id' => '1', + 'username' => 'foobar', + 'username_clean' => 'foobar', + 'user_password' => '$H$9E45lK6J8nLTSm9oJE5aNCSTFK9wqa/', + 'user_passchg' => '0', + 'user_pass_convert' => '0', + 'user_email' => 'example@example.com', + 'user_type' => '0', + 'user_login_attempts' => '0', + 'user_permission' => '', + 'user_sig' => '', + 'user_occ' => '', + 'user_interests' => '', + ), + ); + + $this->assertEquals($expected, $this->provider->autologin()); + } + public function test_validate_session() { $this->markTestIncomplete(); -- cgit v1.2.1 From 5444e5b6831d5ce87ff2adaf1f7b0e4788592bc3 Mon Sep 17 00:00:00 2001 From: Joseph Warner Date: Tue, 25 Jun 2013 14:28:16 -0400 Subject: [feature/auth-refactor] Test validate_session on provider_apache Provides a test for the validate_session() method of provider_apache. PHPBB3-9734 --- tests/auth/provider_apache_test.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/auth/provider_apache_test.php b/tests/auth/provider_apache_test.php index 6cfd676fc2..092b90bea3 100644 --- a/tests/auth/provider_apache_test.php +++ b/tests/auth/provider_apache_test.php @@ -99,6 +99,10 @@ class phpbb_auth_provider_apache_test extends phpbb_database_test_case public function test_validate_session() { - $this->markTestIncomplete(); + $user = $this->getMock('phpbb_user'); + $user->data['username'] = 'foobar'; + $this->request->overwrite('PHP_AUTH_USER', 'foobar', phpbb_request_interface::SERVER); + + $this->assertTrue($this->provider->validate_session($user)); } } -- cgit v1.2.1 From 5f3ed197e73550e78b37dd38496210737cf3f39d Mon Sep 17 00:00:00 2001 From: Joseph Warner Date: Tue, 25 Jun 2013 16:25:45 -0400 Subject: [feature/auth-refactor] Fix auth tests to use mock objects correctly PHPBB3-9734 --- tests/auth/provider_apache_test.php | 148 ++++++++++++++++++++++++++++++------ 1 file changed, 123 insertions(+), 25 deletions(-) (limited to 'tests') diff --git a/tests/auth/provider_apache_test.php b/tests/auth/provider_apache_test.php index 092b90bea3..0ca6ef763e 100644 --- a/tests/auth/provider_apache_test.php +++ b/tests/auth/provider_apache_test.php @@ -40,7 +40,15 @@ class phpbb_auth_provider_apache_test extends phpbb_database_test_case public function test_init() { $this->user->data['username'] = 'foobar'; - $this->request->overwrite('PHP_AUTH_USER', 'foobar', phpbb_request_interface::SERVER); + $this->request->expects($this->once()) + ->method('is_set') + ->with('PHP_AUTH_USER', + phpbb_request_interface::SERVER) + ->will($this->returnValue(true)); + $this->request->expects($this->once()) + ->method('server') + ->with('PHP_AUTH_USER') + ->will($this->returnValue('foobar')); $this->assertFalse($this->provider->init()); } @@ -50,8 +58,19 @@ class phpbb_auth_provider_apache_test extends phpbb_database_test_case $username = 'foobar'; $password = 'example'; - $this->request->overwrite('PHP_AUTH_USER', $username, phpbb_request_interface::SERVER); - $this->request->overwrite('PHP_AUTH_PW', $password, phpbb_request_interface::SERVER); + $this->request->expects($this->once()) + ->method('is_set') + ->with('PHP_AUTH_USER', + phpbb_request_interface::SERVER) + ->will($this->returnValue(true)); + $this->request->expects($this->at(1)) + ->method('server') + ->with('PHP_AUTH_USER') + ->will($this->returnValue('foobar')); + $this->request->expects($this->at(2)) + ->method('server') + ->with('PHP_AUTH_PW') + ->will($this->returnValue('example')); $expected = array( 'status' => LOGIN_SUCCESS, @@ -71,27 +90,96 @@ class phpbb_auth_provider_apache_test extends phpbb_database_test_case public function test_autologin() { - $this->request->overwrite('PHP_AUTH_USER', 'foobar', phpbb_request_interface::SERVER); - $this->request->overwrite('PHP_AUTH_PW', 'example', phpbb_request_interface::SERVER); + $this->request->expects($this->once()) + ->method('is_set') + ->with('PHP_AUTH_USER', + phpbb_request_interface::SERVER) + ->will($this->returnValue(true)); + $this->request->expects($this->at(1)) + ->method('server') + ->with('PHP_AUTH_USER') + ->will($this->returnValue('foobar')); + $this->request->expects($this->at(2)) + ->method('server') + ->with('PHP_AUTH_PW') + ->will($this->returnValue('example')); $expected = array( - 'status' => LOGIN_SUCCESS, - 'error_msg' => false, - 'user_row' => array( - 'user_id' => '1', - 'username' => 'foobar', - 'username_clean' => 'foobar', - 'user_password' => '$H$9E45lK6J8nLTSm9oJE5aNCSTFK9wqa/', - 'user_passchg' => '0', - 'user_pass_convert' => '0', - 'user_email' => 'example@example.com', - 'user_type' => '0', - 'user_login_attempts' => '0', - 'user_permission' => '', - 'user_sig' => '', - 'user_occ' => '', - 'user_interests' => '', - ), + 'user_id' => '1', + 'user_type' => '0', + 'group_id' => '3', + 'user_permissions' => '', + 'user_perm_from' => '0', + 'user_ip' => '', + 'user_regdate' => '0', + 'username' => 'foobar', + 'username_clean' => 'foobar', + 'user_password' => '$H$9E45lK6J8nLTSm9oJE5aNCSTFK9wqa/', + 'user_passchg' => '0', + 'user_pass_convert' => '0', + 'user_email' => 'example@example.com', + 'user_email_hash' => '0', + 'user_birthday' => '', + 'user_lastvisit' => '0', + 'user_lastmark' => '0', + 'user_lastpost_time' => '0', + 'user_lastpage' => '', + 'user_last_confirm_key' => '', + 'user_last_search' => '0', + 'user_warnings' => '0', + 'user_last_warning' => '0', + 'user_login_attempts' => '0', + 'user_inactive_reason' => '0', + 'user_inactive_time' => '0', + 'user_posts' => '0', + 'user_lang' => '', + 'user_timezone' => 'UTC', + 'user_dateformat' => 'd M Y H:i', + 'user_style' => '0', + 'user_rank' => '0', + 'user_colour' => '', + 'user_new_privmsg' => '0', + 'user_unread_privmsg' => '0', + 'user_last_privmsg' => '0', + 'user_message_rules' => '0', + 'user_full_folder' => '-3', + 'user_emailtime' => '0', + 'user_topic_show_days' => '0', + 'user_topic_sortby_type' => 't', + 'user_topic_sortby_dir' => 'd', + 'user_post_show_days' => '0', + 'user_post_sortby_type' => 't', + 'user_post_sortby_dir' => 'a', + 'user_notify' => '0', + 'user_notify_pm' => '1', + 'user_notify_type' => '0', + 'user_allow_pm' => '1', + 'user_allow_viewonline' => '1', + 'user_allow_viewemail' => '1', + 'user_allow_massemail' => '1', + 'user_options' => '230271', + 'user_avatar' => '', + 'user_avatar_type' => '', + 'user_avatar_width' => '0', + 'user_avatar_height' => '0', + 'user_sig' => '', + 'user_sig_bbcode_uid' => '', + 'user_sig_bbcode_bitfield' => '', + 'user_from' => '', + 'user_icq' => '', + 'user_aim' => '', + 'user_yim' => '', + 'user_msnm' => '', + 'user_jabber' => '', + 'user_website' => '', + 'user_occ' => '', + 'user_interests' => '', + 'user_actkey' => '', + 'user_newpasswd' => '', + 'user_form_salt' => '', + 'user_new' => '1', + 'user_reminded' => '0', + 'user_reminded_time' => '0', ); $this->assertEquals($expected, $this->provider->autologin()); @@ -99,9 +187,19 @@ class phpbb_auth_provider_apache_test extends phpbb_database_test_case public function test_validate_session() { - $user = $this->getMock('phpbb_user'); - $user->data['username'] = 'foobar'; - $this->request->overwrite('PHP_AUTH_USER', 'foobar', phpbb_request_interface::SERVER); + $user = array( + 'username' => 'foobar', + 'user_type' + ); + $this->request->expects($this->once()) + ->method('is_set') + ->with('PHP_AUTH_USER', + phpbb_request_interface::SERVER) + ->will($this->returnValue(true)); + $this->request->expects($this->once()) + ->method('server') + ->with('PHP_AUTH_USER') + ->will($this->returnValue('foobar')); $this->assertTrue($this->provider->validate_session($user)); } -- cgit v1.2.1 From 19bbf7b7de4a2575405b84c8a253cbf9de315b7c Mon Sep 17 00:00:00 2001 From: Joseph Warner Date: Wed, 26 Jun 2013 11:31:11 -0400 Subject: [feature/auth-refactor] Fix two session tests broken by changes PHPBB3-9734 --- tests/session/continue_test.php | 13 +++++++++++++ tests/session/init_test.php | 13 +++++++++++++ 2 files changed, 26 insertions(+) (limited to 'tests') diff --git a/tests/session/continue_test.php b/tests/session/continue_test.php index ad78d92299..e5a7f7a4a1 100644 --- a/tests/session/continue_test.php +++ b/tests/session/continue_test.php @@ -53,7 +53,20 @@ class phpbb_session_continue_test extends phpbb_database_test_case */ public function test_session_begin_valid_session($session_id, $user_id, $user_agent, $ip, $expected_sessions, $expected_cookies, $message) { + global $phpbb_container, $phpbb_root_path, $phpEx; + $db = $this->new_dbal(); + $config = new phpbb_config(array()); + $request = $this->getMock('phpbb_request'); + $user = $this->getMock('phpbb_user'); + + $auth_provider = new phpbb_auth_provider_db($db, $config, $request, $user, $phpbb_root_path, $phpEx); + $phpbb_container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface'); + $phpbb_container->expects($this->any()) + ->method('get') + ->with('auth.provider.db') + ->will($this->returnValue($auth_provider)); + $session_factory = new phpbb_session_testable_factory; $session_factory->set_cookies(array( '_sid' => $session_id, diff --git a/tests/session/init_test.php b/tests/session/init_test.php index 830de34ed0..43af8c554f 100644 --- a/tests/session/init_test.php +++ b/tests/session/init_test.php @@ -20,7 +20,20 @@ class phpbb_session_init_test extends phpbb_database_test_case public function test_login_session_create() { + global $phpbb_container, $phpbb_root_path, $phpEx; + $db = $this->new_dbal(); + $config = new phpbb_config(array()); + $request = $this->getMock('phpbb_request'); + $user = $this->getMock('phpbb_user'); + + $auth_provider = new phpbb_auth_provider_db($db, $config, $request, $user, $phpbb_root_path, $phpEx); + $phpbb_container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface'); + $phpbb_container->expects($this->any()) + ->method('get') + ->with('auth.provider.db') + ->will($this->returnValue($auth_provider)); + $session_factory = new phpbb_session_testable_factory; $session = $session_factory->get_session($db); -- cgit v1.2.1 From a105a6d7a7140fe94e9b0a166fa515b9e02d9e3e Mon Sep 17 00:00:00 2001 From: Andy Chase Date: Tue, 25 Jun 2013 12:39:43 -0700 Subject: [ticket/11615] Rename init_test to creation_test for clarity PHPBB3-11615 --- tests/session/creation_test.php | 56 +++++++++++++++++++++++++++++++++++++++++ tests/session/init_test.php | 56 ----------------------------------------- 2 files changed, 56 insertions(+), 56 deletions(-) create mode 100644 tests/session/creation_test.php delete mode 100644 tests/session/init_test.php (limited to 'tests') diff --git a/tests/session/creation_test.php b/tests/session/creation_test.php new file mode 100644 index 0000000000..2ce6c4a4ac --- /dev/null +++ b/tests/session/creation_test.php @@ -0,0 +1,56 @@ +createXMLDataSet(dirname(__FILE__).'/fixtures/sessions_empty.xml'); + } + + // also see security/extract_current_page.php + + public function test_login_session_create() + { + $db = $this->new_dbal(); + $session_factory = new phpbb_session_testable_factory; + + $session = $session_factory->get_session($db); + $session->page = array('page' => 'page', 'forum' => 0); + + $session->session_create(3); + + $sql = 'SELECT session_user_id + FROM phpbb_sessions'; + + $this->assertSqlResultEquals( + array(array('session_user_id' => 3)), + $sql, + 'Check if exacly one session for user id 3 was created' + ); + + $cookie_expire = $session->time_now + 31536000; // default is one year + + $session->check_cookies($this, array( + 'u' => array(null, $cookie_expire), + 'k' => array(null, $cookie_expire), + 'sid' => array($session->session_id, $cookie_expire), + )); + + global $SID, $_SID; + $this->assertEquals($session->session_id, $_SID); + $this->assertEquals('?sid=' . $session->session_id, $SID); + + $session_factory->check($this); + } +} + diff --git a/tests/session/init_test.php b/tests/session/init_test.php deleted file mode 100644 index 2ce6c4a4ac..0000000000 --- a/tests/session/init_test.php +++ /dev/null @@ -1,56 +0,0 @@ -createXMLDataSet(dirname(__FILE__).'/fixtures/sessions_empty.xml'); - } - - // also see security/extract_current_page.php - - public function test_login_session_create() - { - $db = $this->new_dbal(); - $session_factory = new phpbb_session_testable_factory; - - $session = $session_factory->get_session($db); - $session->page = array('page' => 'page', 'forum' => 0); - - $session->session_create(3); - - $sql = 'SELECT session_user_id - FROM phpbb_sessions'; - - $this->assertSqlResultEquals( - array(array('session_user_id' => 3)), - $sql, - 'Check if exacly one session for user id 3 was created' - ); - - $cookie_expire = $session->time_now + 31536000; // default is one year - - $session->check_cookies($this, array( - 'u' => array(null, $cookie_expire), - 'k' => array(null, $cookie_expire), - 'sid' => array($session->session_id, $cookie_expire), - )); - - global $SID, $_SID; - $this->assertEquals($session->session_id, $_SID); - $this->assertEquals('?sid=' . $session->session_id, $SID); - - $session_factory->check($this); - } -} - -- cgit v1.2.1 From c29cca1a755461ec2bd63b7cc9292d79ae0508d6 Mon Sep 17 00:00:00 2001 From: Andy Chase Date: Tue, 25 Jun 2013 12:40:31 -0700 Subject: [ticket/11615] Rename class in file to match PHPBB3-11615 --- tests/session/creation_test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/session/creation_test.php b/tests/session/creation_test.php index 2ce6c4a4ac..c5558c1577 100644 --- a/tests/session/creation_test.php +++ b/tests/session/creation_test.php @@ -10,7 +10,7 @@ require_once dirname(__FILE__) . '/../mock/cache.php'; require_once dirname(__FILE__) . '/testable_factory.php'; -class phpbb_session_init_test extends phpbb_database_test_case +class phpbb_session_creation_test extends phpbb_database_test_case { public function getDataSet() { -- cgit v1.2.1 From 4c432fecc75473c5f12a70048973a4139bdf1b22 Mon Sep 17 00:00:00 2001 From: Andy Chase Date: Tue, 25 Jun 2013 12:42:19 -0700 Subject: [ticket/11615] Remove magic number in creation_test Removing this magic number to its own variable with clean multiplication makes it clear what the number represents. PHPBB3-11615 --- tests/session/creation_test.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/session/creation_test.php b/tests/session/creation_test.php index c5558c1577..b9f8b18c63 100644 --- a/tests/session/creation_test.php +++ b/tests/session/creation_test.php @@ -38,7 +38,8 @@ class phpbb_session_creation_test extends phpbb_database_test_case 'Check if exacly one session for user id 3 was created' ); - $cookie_expire = $session->time_now + 31536000; // default is one year + $one_year_in_seconds = 365 * 24 * 60 * 60; + $cookie_expire = $session->time_now + $one_year_in_seconds; $session->check_cookies($this, array( 'u' => array(null, $cookie_expire), -- cgit v1.2.1 From 7ba81a293f014f3c6b161672b8fbc27e2075d239 Mon Sep 17 00:00:00 2001 From: Andy Chase Date: Tue, 25 Jun 2013 12:42:41 -0700 Subject: [ticket/11615] Fix typo in creation_test PHPBB3-11615 --- tests/session/creation_test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/session/creation_test.php b/tests/session/creation_test.php index b9f8b18c63..bef52c6554 100644 --- a/tests/session/creation_test.php +++ b/tests/session/creation_test.php @@ -35,7 +35,7 @@ class phpbb_session_creation_test extends phpbb_database_test_case $this->assertSqlResultEquals( array(array('session_user_id' => 3)), $sql, - 'Check if exacly one session for user id 3 was created' + 'Check if exactly one session for user id 3 was created' ); $one_year_in_seconds = 365 * 24 * 60 * 60; -- cgit v1.2.1 From 1f989c6be774d88ffff8a8d5ac1da58f442f6174 Mon Sep 17 00:00:00 2001 From: Dhruv Date: Thu, 27 Jun 2013 00:57:34 +0530 Subject: [ticket/9341] Move create_topic and post into functional test case create_topic and create_post are moved into functional test case so that they can be used by other tests as well PHPBB3-9341 --- tests/functional/posting_test.php | 101 --------------------- .../test_framework/phpbb_functional_test_case.php | 101 +++++++++++++++++++++ 2 files changed, 101 insertions(+), 101 deletions(-) (limited to 'tests') diff --git a/tests/functional/posting_test.php b/tests/functional/posting_test.php index 9bcfcc2fda..7fd1e4fdcf 100644 --- a/tests/functional/posting_test.php +++ b/tests/functional/posting_test.php @@ -32,105 +32,4 @@ class phpbb_functional_posting_test extends phpbb_functional_test_case $crawler = self::request('GET', "posting.php?mode=quote&f=2&t={$post2['topic_id']}&p={$post2['post_id']}&sid={$this->sid}"); $this->assertContains('This is a test post posted by the testing framework.', $crawler->filter('html')->text()); } - - /** - * Creates a topic - * - * Be sure to login before creating - * - * @param int $forum_id - * @param string $subject - * @param string $message - * @param array $additional_form_data Any additional form data to be sent in the request - * @return array post_id, topic_id - */ - public function create_topic($forum_id, $subject, $message, $additional_form_data = array()) - { - $posting_url = "posting.php?mode=post&f={$forum_id}&sid={$this->sid}"; - - $form_data = array_merge(array( - 'subject' => $subject, - 'message' => $message, - 'post' => true, - ), $additional_form_data); - - return self::submit_post($posting_url, 'POST_TOPIC', $form_data); - } - - /** - * Creates a post - * - * Be sure to login before creating - * - * @param int $forum_id - * @param string $subject - * @param string $message - * @param array $additional_form_data Any additional form data to be sent in the request - * @return array post_id, topic_id - */ - public function create_post($forum_id, $topic_id, $subject, $message, $additional_form_data = array()) - { - $posting_url = "posting.php?mode=reply&f={$forum_id}&t={$topic_id}&sid={$this->sid}"; - - $form_data = array_merge(array( - 'subject' => $subject, - 'message' => $message, - 'post' => true, - ), $additional_form_data); - - return self::submit_post($posting_url, 'POST_REPLY', $form_data); - } - - /** - * Helper for submitting posts - * - * @param string $posting_url - * @param string $posting_contains - * @param array $form_data - * @return array post_id, topic_id - */ - protected function submit_post($posting_url, $posting_contains, $form_data) - { - $this->add_lang('posting'); - - $crawler = self::request('GET', $posting_url); - $this->assertContains($this->lang($posting_contains), $crawler->filter('html')->text()); - - $hidden_fields = array( - $crawler->filter('[type="hidden"]')->each(function ($node, $i) { - return array('name' => $node->getAttribute('name'), 'value' => $node->getAttribute('value')); - }), - ); - - foreach ($hidden_fields as $fields) - { - foreach($fields as $field) - { - $form_data[$field['name']] = $field['value']; - } - } - - // Bypass time restriction that said that if the lastclick time (i.e. time when the form was opened) - // is not at least 2 seconds before submission, cancel the form - $form_data['lastclick'] = 0; - - // I use a request because the form submission method does not allow you to send data that is not - // contained in one of the actual form fields that the browser sees (i.e. it ignores "hidden" inputs) - // Instead, I send it as a request with the submit button "post" set to true. - $crawler = self::request('POST', $posting_url, $form_data); - $this->assertContains($this->lang('POST_STORED'), $crawler->filter('html')->text()); - - $url = $crawler->selectLink($this->lang('VIEW_MESSAGE', '', ''))->link()->getUri(); - - $matches = $topic_id = $post_id = false; - preg_match_all('#&t=([0-9]+)(&p=([0-9]+))?#', $url, $matches); - - $topic_id = (int) (isset($matches[1][0])) ? $matches[1][0] : 0; - $post_id = (int) (isset($matches[3][0])) ? $matches[3][0] : 0; - - return array( - 'topic_id' => $topic_id, - 'post_id' => $post_id, - ); - } } diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index 97fe147d8e..ece42c5fff 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -703,4 +703,105 @@ class phpbb_functional_test_case extends phpbb_test_case return $result; } + + /** + * Creates a topic + * + * Be sure to login before creating + * + * @param int $forum_id + * @param string $subject + * @param string $message + * @param array $additional_form_data Any additional form data to be sent in the request + * @return array post_id, topic_id + */ + public function create_topic($forum_id, $subject, $message, $additional_form_data = array()) + { + $posting_url = "posting.php?mode=post&f={$forum_id}&sid={$this->sid}"; + + $form_data = array_merge(array( + 'subject' => $subject, + 'message' => $message, + 'post' => true, + ), $additional_form_data); + + return self::submit_post($posting_url, 'POST_TOPIC', $form_data); + } + + /** + * Creates a post + * + * Be sure to login before creating + * + * @param int $forum_id + * @param string $subject + * @param string $message + * @param array $additional_form_data Any additional form data to be sent in the request + * @return array post_id, topic_id + */ + public function create_post($forum_id, $topic_id, $subject, $message, $additional_form_data = array()) + { + $posting_url = "posting.php?mode=reply&f={$forum_id}&t={$topic_id}&sid={$this->sid}"; + + $form_data = array_merge(array( + 'subject' => $subject, + 'message' => $message, + 'post' => true, + ), $additional_form_data); + + return self::submit_post($posting_url, 'POST_REPLY', $form_data); + } + + /** + * Helper for submitting posts + * + * @param string $posting_url + * @param string $posting_contains + * @param array $form_data + * @return array post_id, topic_id + */ + protected function submit_post($posting_url, $posting_contains, $form_data) + { + $this->add_lang('posting'); + + $crawler = self::request('GET', $posting_url); + $this->assertContains($this->lang($posting_contains), $crawler->filter('html')->text()); + + $hidden_fields = array( + $crawler->filter('[type="hidden"]')->each(function ($node, $i) { + return array('name' => $node->getAttribute('name'), 'value' => $node->getAttribute('value')); + }), + ); + + foreach ($hidden_fields as $fields) + { + foreach($fields as $field) + { + $form_data[$field['name']] = $field['value']; + } + } + + // Bypass time restriction that said that if the lastclick time (i.e. time when the form was opened) + // is not at least 2 seconds before submission, cancel the form + $form_data['lastclick'] = 0; + + // I use a request because the form submission method does not allow you to send data that is not + // contained in one of the actual form fields that the browser sees (i.e. it ignores "hidden" inputs) + // Instead, I send it as a request with the submit button "post" set to true. + $crawler = self::request('POST', $posting_url, $form_data); + $this->assertContains($this->lang('POST_STORED'), $crawler->filter('html')->text()); + + $url = $crawler->selectLink($this->lang('VIEW_MESSAGE', '', ''))->link()->getUri(); + + $matches = $topic_id = $post_id = false; + preg_match_all('#&t=([0-9]+)(&p=([0-9]+))?#', $url, $matches); + + $topic_id = (int) (isset($matches[1][0])) ? $matches[1][0] : 0; + $post_id = (int) (isset($matches[3][0])) ? $matches[3][0] : 0; + + return array( + 'topic_id' => $topic_id, + 'post_id' => $post_id, + ); + } } -- cgit v1.2.1 From bd9ece7ab678976db58325d740124b309507b5ca Mon Sep 17 00:00:00 2001 From: Dhruv Date: Thu, 27 Jun 2013 00:59:37 +0530 Subject: [ticket/9341] Add tests for checking Next and Previous template vars PHPBB3-9341 --- tests/functional/paging_test.php | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 tests/functional/paging_test.php (limited to 'tests') diff --git a/tests/functional/paging_test.php b/tests/functional/paging_test.php new file mode 100644 index 0000000000..d2e52ccf09 --- /dev/null +++ b/tests/functional/paging_test.php @@ -0,0 +1,33 @@ +login(); + + $post = $this->create_topic(2, 'Test Topic 1', 'This is a test topic posted by the testing framework.'); + for ($post_id = 1; $post_id < 20; $post_id++) + { + $this->create_post(2, $post['topic_id'], 'Re: Test Topic 1', 'This is a test post no' . $post_id . ' posted by the testing framework.'); + } + $crawler = self::request('GET', "viewtopic.php?t={$post['topic_id']}&sid={$this->sid}"); + $link = $crawler->filter('#viewtopic > fieldset > a')->attr('href'); + $crawler = self::request('GET', $link); + + $crawler = self::request('GET', "viewtopic.php?t={$post['topic_id']}&sid={$this->sid}&start=10"); + $link = $crawler->filter('#viewtopic > fieldset > a')->attr('href'); + $crawler = self::request('GET', $link); + } +} -- cgit v1.2.1 From fe4bfd02a3f3b178130c7a8d8bcf66a4ab1c67d4 Mon Sep 17 00:00:00 2001 From: Dhruv Date: Sun, 23 Jun 2013 21:37:54 +0530 Subject: [ticket/10838] Updated RUNNING_TESTS.md PHPBB3-10838 --- tests/RUNNING_TESTS.md | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'tests') diff --git a/tests/RUNNING_TESTS.md b/tests/RUNNING_TESTS.md index 26a93f0430..bde1455855 100644 --- a/tests/RUNNING_TESTS.md +++ b/tests/RUNNING_TESTS.md @@ -114,6 +114,42 @@ only want the slow tests, run: $ phpBB/vendor/bin/phpunit --group slow +Functional tests +----------------- + +Functional tests test software the way a user would. They simulate a user +browsing the website, but they do these steps in an automated way. +phpBB allows you to write such tests. This document will tell you how. + +Running +======= + +Running the tests requires your phpBB3 repository to be accessible through a +local web server. As of PHP 5.4 a builtin webserver is available. If you are +on PHP 5.3 you will also need to supply the URL to a webserver of your own in +the 'tests/test_config.php' file. This is as simple as defining the +'$phpbb_functional_url', which contains the URL for the directory containing +the board. Make sure you include the trailing slash. Testing makes use of a +seperate database defined in this config file and before running the tests +each time this database is deleted. Note that without extensive changes to the +test framework, you cannot use a board outside of the repository on which to +run tests. + + $phpbb_functional_url = 'http://localhost/phpBB3/'; + +On PHP 5.4 you do not need the $phpbb_functional_url parameter but you can +configure the port the builtin webserver runs on using + + $phpbb_functional_port = 8000; + +To then run the tests, you run PHPUnit, but use the phpunit.xml.functional +config file instead of the default one. Specify this through the "-c" option: + + phpunit -c phpunit.xml.functional + +This will change your board's config.php file, but it makes a backup at +config_dev.php, so you can restore it after the test run is complete. + More Information ================ -- cgit v1.2.1 From 8e575487ff73f3b9c05aceba7b71f06c6e0b032a Mon Sep 17 00:00:00 2001 From: Joseph Warner Date: Wed, 26 Jun 2013 19:51:52 -0400 Subject: [ticket/11618] Replace glob() with scandir() and string matching Removes glob from template tests as glob() does not work on all systems according to PHP documentation as has been noticed by users. PHPBB3-11618 --- tests/template/template_test.php | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) (limited to 'tests') diff --git a/tests/template/template_test.php b/tests/template/template_test.php index e532de294c..fd68124c89 100644 --- a/tests/template/template_test.php +++ b/tests/template/template_test.php @@ -69,9 +69,14 @@ class phpbb_template_template_test extends phpbb_test_case $this->markTestSkipped("Template cache directory ({$template_cache_dir}) is not writable."); } - foreach (glob($this->template->cachepath . '*') as $file) + $file_array = scandir($template_cache_dir); + $file_prefix = basename($this->template->cachepath); + foreach ($file_array as $file) { - unlink($file); + if (strpos($file, $file_prefix) === 0) + { + unlink($template_cache_dir . '/' . $file); + } } $GLOBALS['config'] = array( @@ -84,9 +89,15 @@ class phpbb_template_template_test extends phpbb_test_case { if (is_object($this->template)) { - foreach (glob($this->template->cachepath . '*') as $file) + $template_cache_dir = dirname($this->template->cachepath); + $file_array = scandir($template_cache_dir); + $file_prefix = basename($this->template->cachepath); + foreach ($file_array as $file) { - unlink($file); + if (strpos($file, $file_prefix) === 0) + { + unlink($template_cache_dir . '/' . $file); + } } } } -- cgit v1.2.1 From 22998ee5ee2d3cb4b0e3e34083b2876ab1e9bfb1 Mon Sep 17 00:00:00 2001 From: Dhruv Date: Fri, 28 Jun 2013 00:52:36 +0530 Subject: [ticket/9341] Follow the Next/Prev link in tests follow the next/prev link and then assert if the page contains its last post or not PHPBB3-9341 --- tests/functional/paging_test.php | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'tests') diff --git a/tests/functional/paging_test.php b/tests/functional/paging_test.php index d2e52ccf09..d85ce49aa6 100644 --- a/tests/functional/paging_test.php +++ b/tests/functional/paging_test.php @@ -23,11 +23,15 @@ class phpbb_functional_paging_test extends phpbb_functional_test_case $this->create_post(2, $post['topic_id'], 'Re: Test Topic 1', 'This is a test post no' . $post_id . ' posted by the testing framework.'); } $crawler = self::request('GET', "viewtopic.php?t={$post['topic_id']}&sid={$this->sid}"); - $link = $crawler->filter('#viewtopic > fieldset > a')->attr('href'); - $crawler = self::request('GET', $link); + $this->assertContains('post no9', $crawler->text()); - $crawler = self::request('GET', "viewtopic.php?t={$post['topic_id']}&sid={$this->sid}&start=10"); - $link = $crawler->filter('#viewtopic > fieldset > a')->attr('href'); - $crawler = self::request('GET', $link); + $next_link = $crawler->filter('#viewtopic > fieldset > a.arrow-right')->attr('href'); + $crawler = self::request('GET', $next_link); + $this->assertContains('post no19', $crawler->text()); + + + $prev_link = $crawler->filter('#viewtopic > fieldset > a.arrow-left')->attr('href'); + $crawler = self::request('GET', $prev_link); + $this->assertContains('post no9', $crawler->text()); } } -- cgit v1.2.1 From 91e773a79538a8fa26bea1d56384379b8730ac70 Mon Sep 17 00:00:00 2001 From: Dhruv Date: Fri, 28 Jun 2013 01:02:00 +0530 Subject: [ticket/9341] Assert that page doesnt contain next or prev page posts PHPBB3-9341 --- tests/functional/paging_test.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/functional/paging_test.php b/tests/functional/paging_test.php index d85ce49aa6..d5adc6ad0a 100644 --- a/tests/functional/paging_test.php +++ b/tests/functional/paging_test.php @@ -24,14 +24,16 @@ class phpbb_functional_paging_test extends phpbb_functional_test_case } $crawler = self::request('GET', "viewtopic.php?t={$post['topic_id']}&sid={$this->sid}"); $this->assertContains('post no9', $crawler->text()); + $this->assertNotContains('post no19', $crawler->text()); $next_link = $crawler->filter('#viewtopic > fieldset > a.arrow-right')->attr('href'); $crawler = self::request('GET', $next_link); $this->assertContains('post no19', $crawler->text()); - + $this->assertNotContains('post no9', $crawler->text()); $prev_link = $crawler->filter('#viewtopic > fieldset > a.arrow-left')->attr('href'); $crawler = self::request('GET', $prev_link); $this->assertContains('post no9', $crawler->text()); + $this->assertNotContains('post no19', $crawler->text()); } } -- cgit v1.2.1 From 43053c541ac0f998a3925b7277cfb77f1ceafb11 Mon Sep 17 00:00:00 2001 From: Dhruv Date: Wed, 12 Jun 2013 01:45:07 +0530 Subject: [ticket/11566] add tests for reporting post Functional test for reporting post and check if captcha validation is required for guests and not for registerted users PHPBB3-11566 --- tests/functional/report_post_captcha.php | 55 ++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 tests/functional/report_post_captcha.php (limited to 'tests') diff --git a/tests/functional/report_post_captcha.php b/tests/functional/report_post_captcha.php new file mode 100644 index 0000000000..6b112c3538 --- /dev/null +++ b/tests/functional/report_post_captcha.php @@ -0,0 +1,55 @@ +login(); + $crawler = self::request('GET', 'report.php?f=2&p=1'); + $this->assertNotContains($this->lang('CONFIRM_CODE'), $crawler->filter('html')->text()); + } + + public function test_guest_report_post() + { + $this->enable_reporting_guest(); + $crawler = self::request('GET', 'report.php?f=2&p=1'); + $this->assertContains($this->lang('CONFIRM_CODE'), $crawler->filter('html')->text()); + } + + protected function enable_reporting_guest() + { + $this->login(); + $this->admin_login(); + + $crawler = self::request('GET', 'adm/index.php?i=permissions&icat=12&mode=setting_group_local&sid=' . $this->sid); + $form = $crawler->selectButton('Submit')->form(); + $values = $form->getValues(); + $values["group_id[0]"] = 1; + $form->setValues($values); + $crawler = self::submit($form); + + $form = $crawler->selectButton('Submit')->form(); + $values = $form->getValues(); + $values["forum_id"] = 2; + $form->setValues($values); + $crawler = self::submit($form); + + $form = $crawler->selectButton('Apply all permissions')->form(); + $values = $form->getValues(); + $values["setting[1][2][f_report]"] = 1; + $form->setValues($values); + $crawler = self::submit($form); + + $crawler = self::request('GET', 'ucp.php?mode=logout&sid=' . $this->sid); + } +} -- cgit v1.2.1 From 1abc3d91d05919f20b31876dbafbb8edec83d724 Mon Sep 17 00:00:00 2001 From: Dhruv Date: Wed, 12 Jun 2013 02:00:24 +0530 Subject: [ticket/11566] Use language variable instead of hardcode Add language variable in tests PHPBB3-11566 --- tests/functional/report_post_captcha.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/functional/report_post_captcha.php b/tests/functional/report_post_captcha.php index 6b112c3538..e0a67ab6fa 100644 --- a/tests/functional/report_post_captcha.php +++ b/tests/functional/report_post_captcha.php @@ -44,7 +44,8 @@ class phpbb_functional_report_post_captcha_test extends phpbb_functional_test_ca $form->setValues($values); $crawler = self::submit($form); - $form = $crawler->selectButton('Apply all permissions')->form(); + $this->add_lang('acp/permissions'); + $form = $crawler->selectButton($this->lang('APPLY_ALL_PERMISSIONS'))->form(); $values = $form->getValues(); $values["setting[1][2][f_report]"] = 1; $form->setValues($values); -- cgit v1.2.1 From 434d14e1d5c2341584c9d5cfd93840f3eb1a6941 Mon Sep 17 00:00:00 2001 From: Dhruv Date: Wed, 12 Jun 2013 20:00:51 +0530 Subject: [ticket/11566] Revert forum permission changes Revert the f_report permission for guests in the functional tests PHPBB3-11566 --- tests/functional/report_post_captcha.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'tests') diff --git a/tests/functional/report_post_captcha.php b/tests/functional/report_post_captcha.php index e0a67ab6fa..0585be1332 100644 --- a/tests/functional/report_post_captcha.php +++ b/tests/functional/report_post_captcha.php @@ -21,12 +21,13 @@ class phpbb_functional_report_post_captcha_test extends phpbb_functional_test_ca public function test_guest_report_post() { - $this->enable_reporting_guest(); + $this->set_reporting_guest(1); $crawler = self::request('GET', 'report.php?f=2&p=1'); $this->assertContains($this->lang('CONFIRM_CODE'), $crawler->filter('html')->text()); + $this->set_reporting_guest(-1); } - protected function enable_reporting_guest() + protected function set_reporting_guest($report_post_allowed) { $this->login(); $this->admin_login(); @@ -47,7 +48,7 @@ class phpbb_functional_report_post_captcha_test extends phpbb_functional_test_ca $this->add_lang('acp/permissions'); $form = $crawler->selectButton($this->lang('APPLY_ALL_PERMISSIONS'))->form(); $values = $form->getValues(); - $values["setting[1][2][f_report]"] = 1; + $values["setting[1][2][f_report]"] = $report_post_allowed; $form->setValues($values); $crawler = self::submit($form); -- cgit v1.2.1 From 84ec1f542365d38763b099e0cb9dcc78cc341258 Mon Sep 17 00:00:00 2001 From: Dhruv Date: Mon, 1 Jul 2013 01:34:21 +0530 Subject: [ticket/11566] Check that guest doesn't have reporting permission by default PHPBB3-11566 --- tests/functional/report_post_captcha.php | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'tests') diff --git a/tests/functional/report_post_captcha.php b/tests/functional/report_post_captcha.php index 0585be1332..af713775c5 100644 --- a/tests/functional/report_post_captcha.php +++ b/tests/functional/report_post_captcha.php @@ -21,6 +21,10 @@ class phpbb_functional_report_post_captcha_test extends phpbb_functional_test_ca public function test_guest_report_post() { + $crawler = self::request('GET', 'report.php?f=2&p=1'); + $this->add_lang('mcp'); + $this->assertContains($this->lang('USER_CANNOT_REPORT'), $crawler->filter('html')->text()); + $this->set_reporting_guest(1); $crawler = self::request('GET', 'report.php?f=2&p=1'); $this->assertContains($this->lang('CONFIRM_CODE'), $crawler->filter('html')->text()); -- cgit v1.2.1 From 5ed4dbb5b7aa4a0a00560eb7f3226d81ce54eca5 Mon Sep 17 00:00:00 2001 From: Dhruv Date: Sun, 23 Jun 2013 22:40:55 +0530 Subject: [ticket/10838] separate database used mentioned in unit tests Separate database used for tests which is deleted each time tests are run information is added to unit tests. PHPBB3-10838 --- tests/RUNNING_TESTS.md | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'tests') diff --git a/tests/RUNNING_TESTS.md b/tests/RUNNING_TESTS.md index bde1455855..49c59fd928 100644 --- a/tests/RUNNING_TESTS.md +++ b/tests/RUNNING_TESTS.md @@ -47,9 +47,11 @@ Database Tests By default all tests requiring a database connection will use sqlite. If you do not have sqlite installed the tests will be skipped. If you wish to run the tests on a different database you have to create a test_config.php file within -your tests directory following the same format as phpBB's config.php. An -example for mysqli can be found below. More information on configuration -options can be found on the wiki (see below). +your tests directory following the same format as phpBB's config.php. Testing +makes use of a seperate database defined in this config file and before running +the tests each time this database is deleted. An example for mysqli can be +found below. More information on configuration options can be found on the +wiki (see below). Date: Thu, 27 Jun 2013 18:38:44 +0530 Subject: [ticket/10838] Fix missing data PHPBB3-10838 --- tests/RUNNING_TESTS.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/RUNNING_TESTS.md b/tests/RUNNING_TESTS.md index 49c59fd928..d43e503e03 100644 --- a/tests/RUNNING_TESTS.md +++ b/tests/RUNNING_TESTS.md @@ -130,7 +130,7 @@ Running the tests requires your phpBB3 repository to be accessible through a local web server. As of PHP 5.4 a builtin webserver is available. If you are on PHP 5.3 you will also need to supply the URL to a webserver of your own in the 'tests/test_config.php' file. This is as simple as defining the -'$phpbb_functional_url', which contains the URL for the directory containing +'$phpbb_functional_url' variable, which contains the URL for the directory containing the board. Make sure you include the trailing slash. Note that without extensive changes to the test framework, you cannot use a board outside of the repository on which to run tests. @@ -145,7 +145,7 @@ configure the port the builtin webserver runs on using To then run the tests, you run PHPUnit, but use the phpunit.xml.functional config file instead of the default one. Specify this through the "-c" option: - phpunit -c phpunit.xml.functional + $ phpBB/vendor/bin/phpunit -c phpunit.xml.functional This will change your board's config.php file, but it makes a backup at config_dev.php, so you can restore it after the test run is complete. -- cgit v1.2.1 From 89393e11e8e10632520dc80dab638635d773e643 Mon Sep 17 00:00:00 2001 From: Dhruv Date: Sat, 29 Jun 2013 18:42:17 +0530 Subject: [ticket/10838] Remove php 5.4 and builtin server references PHPBB3-10838 --- tests/RUNNING_TESTS.md | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) (limited to 'tests') diff --git a/tests/RUNNING_TESTS.md b/tests/RUNNING_TESTS.md index d43e503e03..a6448c9b09 100644 --- a/tests/RUNNING_TESTS.md +++ b/tests/RUNNING_TESTS.md @@ -127,8 +127,7 @@ Running ======= Running the tests requires your phpBB3 repository to be accessible through a -local web server. As of PHP 5.4 a builtin webserver is available. If you are -on PHP 5.3 you will also need to supply the URL to a webserver of your own in +local web server. You will need to supply the URL to the webserver in the 'tests/test_config.php' file. This is as simple as defining the '$phpbb_functional_url' variable, which contains the URL for the directory containing the board. Make sure you include the trailing slash. Note that without extensive @@ -137,11 +136,6 @@ on which to run tests. $phpbb_functional_url = 'http://localhost/phpBB3/'; -On PHP 5.4 you do not need the $phpbb_functional_url parameter but you can -configure the port the builtin webserver runs on using - - $phpbb_functional_port = 8000; - To then run the tests, you run PHPUnit, but use the phpunit.xml.functional config file instead of the default one. Specify this through the "-c" option: -- cgit v1.2.1 From 440986dc3f941835febf75a30f41b69cb748a15a Mon Sep 17 00:00:00 2001 From: Dhruv Date: Sat, 29 Jun 2013 19:32:15 +0530 Subject: [ticket/10838] Fix URL for wiki and remove irrelevant line PHPBB3-10838 --- tests/RUNNING_TESTS.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/RUNNING_TESTS.md b/tests/RUNNING_TESTS.md index a6448c9b09..23c74f4411 100644 --- a/tests/RUNNING_TESTS.md +++ b/tests/RUNNING_TESTS.md @@ -121,7 +121,7 @@ Functional tests Functional tests test software the way a user would. They simulate a user browsing the website, but they do these steps in an automated way. -phpBB allows you to write such tests. This document will tell you how. +phpBB allows you to write such tests. Running ======= @@ -148,4 +148,4 @@ More Information ================ Further information is available on phpbb wiki: -http://wiki.phpbb.com/Unit_Tests +http://wiki.phpbb.com/Automated_Tests -- cgit v1.2.1 From 950a3a7d952cd361c9dc3c3ff8138b0becea6f74 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Wed, 3 Jul 2013 15:31:24 +0200 Subject: [ticket/11619] Some tests for get_remote_file(). PHPBB3-11619 --- tests/functions/get_remote_file_test.php | 75 ++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 tests/functions/get_remote_file_test.php (limited to 'tests') diff --git a/tests/functions/get_remote_file_test.php b/tests/functions/get_remote_file_test.php new file mode 100644 index 0000000000..4032ca5b58 --- /dev/null +++ b/tests/functions/get_remote_file_test.php @@ -0,0 +1,75 @@ +markTestSkipped(sprintf( + 'Could not find a DNS record for hostname %s. ' . + 'Assuming network is down.', + $hostname + )); + } + + $errstr = $errno = null; + $file = get_remote_file($hostname, '/phpbb', '30x.txt', $errstr, $errno); + + $this->assertNotEquals( + 0, + strlen($file), + 'Failed asserting that the response is not empty.' + ); + + $this->assertSame( + '', + $errstr, + 'Failed asserting that the error string is empty.' + ); + + $this->assertSame( + 0, + $errno, + 'Failed asserting that the error number is 0 (i.e. no error occurred).' + ); + + $lines = explode("\n", $file); + + $this->assertGreaterThanOrEqual( + 2, + sizeof($lines), + 'Failed asserting that the version file has at least two lines.' + ); + + $this->assertStringStartsWith( + '3.', + $lines[0], + "Failed asserting that the first line of the version file starts with '3.'" + ); + + $this->assertNotSame( + false, + filter_var($lines[1], FILTER_VALIDATE_URL), + 'Failed asserting that the second line of the version file is a valid URL.' + ); + + $this->assertContains('http', $lines[1]); + $this->assertContains('phpbb.com', $lines[1], '', true); + } +} -- cgit v1.2.1