diff options
author | Marc Alexander <admin@m-a-styles.de> | 2013-05-12 22:41:00 +0200 |
---|---|---|
committer | Marc Alexander <admin@m-a-styles.de> | 2013-05-12 22:41:00 +0200 |
commit | 7e70eec5a37ddfe112e12b976821c5b944128d32 (patch) | |
tree | bc5c4b8d279474dc78207f72d65915d2b4ff1064 /tests | |
parent | f90ed6c3cb9e1b8baeb352a07b81608fa7c067b5 (diff) | |
parent | fe13b89dd4bd6d808d81c903e66fe869ccd43050 (diff) | |
download | forums-7e70eec5a37ddfe112e12b976821c5b944128d32.tar forums-7e70eec5a37ddfe112e12b976821c5b944128d32.tar.gz forums-7e70eec5a37ddfe112e12b976821c5b944128d32.tar.bz2 forums-7e70eec5a37ddfe112e12b976821c5b944128d32.tar.xz forums-7e70eec5a37ddfe112e12b976821c5b944128d32.zip |
Merge branch 'develop' of https://github.com/phpbb/phpbb3 into ticket/11465
Diffstat (limited to 'tests')
50 files changed, 3417 insertions, 82 deletions
diff --git a/tests/RUNNING_TESTS.txt b/tests/RUNNING_TESTS.md index cede81d59d..f89c1fefeb 100644 --- a/tests/RUNNING_TESTS.txt +++ b/tests/RUNNING_TESTS.md @@ -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 -------------- @@ -77,14 +82,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. @@ -113,7 +120,7 @@ Running Once the prerequisites are installed, run the tests from the project root directory (above phpBB): - $ phpunit + $ phpBB/vendor/bin/phpunit Slow tests -------------- @@ -123,7 +130,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 ================ 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'; 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/controller_test.php b/tests/controller/controller_test.php index 198fb3c6dd..c06bf7d548 100644 --- a/tests/controller/controller_test.php +++ b/tests/controller/controller_test.php @@ -14,7 +14,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() { diff --git a/tests/controller/helper_url_test.php b/tests/controller/helper_url_test.php new file mode 100644 index 0000000000..2c22700ca6 --- /dev/null +++ b/tests/controller/helper_url_test.php @@ -0,0 +1,59 @@ +<?php +/** +* +* @package testing +* @copyright (c) 2013 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ + +require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php'; + +class phpbb_controller_helper_url_test extends phpbb_test_case +{ + + public function helper_url_data() + { + return array( + 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'), + + // 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 + 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 + 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'), + + // 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; + $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); + } +} + diff --git a/tests/dbal/migrator_test.php b/tests/dbal/migrator_test.php index 89669b85ec..6390d6a715 100644 --- a/tests/dbal/migrator_test.php +++ b/tests/dbal/migrator_test.php @@ -60,9 +60,10 @@ 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', + 'php', null ); } @@ -144,15 +145,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() diff --git a/tests/dbal/sql_insert_buffer_test.php b/tests/dbal/sql_insert_buffer_test.php new file mode 100644 index 0000000000..45339a6b50 --- /dev/null +++ b/tests/dbal/sql_insert_buffer_test.php @@ -0,0 +1,116 @@ +<?php +/** +* +* @package testing +* @copyright (c) 2013 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ + +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); + $this->assert_config_count(2); + } + + public function getDataSet() + { + return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/config.xml'); + } + + public function test_multi_insert_disabled_insert_and_flush() + { + $this->db->multi_insert = false; + $this->assertTrue($this->buffer->insert($this->get_row(1))); + $this->assert_config_count(3); + $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->assertFalse($this->buffer->insert($this->get_row(1))); + $this->assert_config_count(2); + $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->assert_config_count(3); + $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->assert_config_count(2); + $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); + $this->assertTrue($this->buffer->flush()); + $this->assert_config_count(5); + } + + protected function assert_config_count($num_configs) + { + $sql = 'SELECT COUNT(*) AS num_configs + FROM phpbb_config'; + $result = $this->db->sql_query($sql); + $this->assertEquals($num_configs, $this->db->sql_fetchfield('num_configs')); + $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( + 'config_name' => "name$rownum", + 'config_value' => "value$rownum", + 'is_dynamic' => '0', + ); + } + + protected function get_rows($n) + { + $result = array(); + for ($i = 0; $i < $n; ++$i) + { + $result[] = $this->get_row($i); + } + return $result; + } +} 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! diff --git a/tests/extension/finder_test.php b/tests/extension/finder_test.php index c96b11a73c..dc3e26be02 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 { @@ -66,7 +67,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); @@ -142,13 +143,28 @@ 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 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( @@ -188,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 8a4fd3fd20..c5b8237b82 100644 --- a/tests/extension/manager_test.php +++ b/tests/extension/manager_test.php @@ -112,9 +112,10 @@ class phpbb_extension_manager_test extends phpbb_database_test_case $db, $config, $migrator, + new phpbb_filesystem(), 'phpbb_ext', dirname(__FILE__) . '/', - '.' . $php_ext, + $php_ext, ($with_cache) ? new phpbb_mock_cache() : null ); } diff --git a/tests/extension/metadata_manager_test.php b/tests/extension/metadata_manager_test.php index 081a32e277..2f38a26217 100644 --- a/tests/extension/metadata_manager_test.php +++ b/tests/extension/metadata_manager_test.php @@ -7,7 +7,9 @@ * */ -class metadata_manager_test extends phpbb_database_test_case +require_once dirname(__FILE__) . '/../../phpBB/includes/db/db_tools.php'; + +class phpbb_extension_metadata_manager_test extends phpbb_database_test_case { protected $class_loader; protected $extension_manager; @@ -36,7 +38,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_'; @@ -64,6 +66,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, @@ -415,31 +418,16 @@ class 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->db, + $this->config, $this->extension_manager, - $this->phpbb_root_path, - $this->phpEx, $this->template, - $this->config + $this->phpbb_root_path ); } } - -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/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 @@ +<?php +/** +* +* @package testing +* @copyright (c) 2013 phpBB Group +* @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_style_path_provider_test extends phpbb_test_case +{ + protected $relative_root_path; + protected $root_path; + + public function setUp() + { + $this->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 @@ +<?php +/** +* +* @package testing +* @copyright (c) 2013 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ +require_once dirname(__FILE__) . '/../style_path_provider_test.php'; + +class phpbb_extension_subdir_style_path_provider_test extends phpbb_extension_style_path_provider_test +{ + public function setUp() + { + $this->relative_root_path = '../'; + $this->root_path = dirname(__FILE__) . '/../'; + } +} diff --git a/tests/functions/clean_path_test.php b/tests/filesystem/clean_path_test.php index bcbe9838d9..50951fc88c 100644 --- a/tests/functions/clean_path_test.php +++ b/tests/filesystem/clean_path_test.php @@ -7,11 +7,17 @@ * */ -require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php'; - -class phpbb_clean_path_test extends phpbb_test_case +class phpbb_filesystem_clean_path_test extends phpbb_test_case { - public function clean_path_test_data() + protected $filesystem; + + public function setUp() + { + parent::setUp(); + $this->filesystem = new phpbb_filesystem(); + } + + public function clean_path_data() { return array( array('foo', 'foo'), @@ -33,12 +39,10 @@ class phpbb_clean_path_test extends phpbb_test_case } /** - * @dataProvider clean_path_test_data + * @dataProvider clean_path_data */ public function test_clean_path($input, $expected) { - $output = phpbb_clean_path($input); - - $this->assertEquals($expected, $output); + $this->assertEquals($expected, $this->filesystem->clean_path($input)); } } diff --git a/tests/extension/acp.php b/tests/functional/extension_acp_test.php index 790df77c0d..1879cbd62c 100644 --- a/tests/extension/acp.php +++ b/tests/functional/extension_acp_test.php @@ -7,7 +7,10 @@ * */ -class acp_test extends phpbb_functional_test_case +/** +* @group functional +*/ +class phpbb_functional_extension_acp_test extends phpbb_functional_test_case { static private $copied_files = array(); static private $helper; @@ -24,14 +27,19 @@ class 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__) . '/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() @@ -84,13 +92,19 @@ class 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/'); - - self::$copied_files[] = $phpbb_root_path . 'store/temp_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); + + if (file_exists($phpbb_root_path . 'store/temp_ext/')) + { + self::$helper->empty_dir($phpbb_root_path . 'store/temp_ext/'); + } } public function test_list() 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..067a9d38eb --- /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" + } +} diff --git a/tests/functional/forgot_password_test.php b/tests/functional/forgot_password_test.php new file mode 100644 index 0000000000..bfb4616d64 --- /dev/null +++ b/tests/functional/forgot_password_test.php @@ -0,0 +1,51 @@ +<?php +/** +* +* @package testing +* @copyright (c) 2012 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ + +/** +* @group functional +*/ +class phpbb_functional_forgot_password_test extends phpbb_functional_test_case +{ + public function test_forgot_password_enabled() + { + 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()); + } + + 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'); + $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); + + $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 879bee2f0e..92ede8bd04 100644 --- a/tests/functional/memberlist_test.php +++ b/tests/functional/memberlist_test.php @@ -40,4 +40,60 @@ class phpbb_functional_memberlist_test extends phpbb_functional_test_case $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'); + } + + public function test_leaders() + { + $this->login(); + $this->create_user('memberlist-test-moderator'); + + $crawler = $this->get_memberlist_leaders_table_crawler(); + + // Admin in admin group, but not in moderators + $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', $crawler->eq(0)->text()); + $this->assertNotContains('memberlist-test-user', $crawler->eq(1)->text()); + + // memberlist-test-moderator in neither group + $this->assertNotContains('memberlist-test-moderator', $crawler->eq(0)->text()); + $this->assertNotContains('memberlist-test-moderator', $crawler->eq(1)->text()); + } + + public function test_leaders_remove_users() + { + $this->login(); + + // Remove admin from admins, but is now in moderators + $this->remove_user_group('ADMINISTRATORS', array('admin')); + $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_table_crawler(); + $this->assertNotContains('admin', $crawler->eq(0)->text()); + $this->assertNotContains('admin', $crawler->eq(1)->text()); + } + + public function test_leaders_add_users() + { + $this->login(); + + // Add memberlist-test-moderator to moderators + $this->add_user_group('GLOBAL_MODERATORS', array('memberlist-test-moderator')); + $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()); + } } diff --git a/tests/functional/metadata_manager_test.php b/tests/functional/metadata_manager_test.php new file mode 100644 index 0000000000..0125886e04 --- /dev/null +++ b/tests/functional/metadata_manager_test.php @@ -0,0 +1,111 @@ +<?php +/** +* +* @package testing +* @copyright (c) 2013 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ + +require_once dirname(__FILE__) . '/../../phpBB/includes/db/db_tools.php'; + +/** +* @group functional +*/ +class phpbb_functional_metadata_manager_test extends phpbb_functional_test_case +{ + protected $phpbb_extension_manager; + + static private $helpers; + + static protected $fixtures = array( + '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() + { + 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); + } + } + + /** + * 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) + { + self::$helpers->empty_dir($phpbb_root_path . 'ext/' . $fixture); + } + self::$helpers->empty_dir($phpbb_root_path . 'ext/foo/'); + } + + public function setUp() + { + parent::setUp(); + + $this->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'), $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() + { + $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()); + $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 + // 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('<p id="require_php">>=5.3</p>', $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:', $crawler->filter('#main')->text()); + } +} diff --git a/tests/functional/notification_test.php b/tests/functional/notification_test.php new file mode 100644 index 0000000000..ec495da602 --- /dev/null +++ b/tests/functional/notification_test.php @@ -0,0 +1,56 @@ +<?php +/** +* +* @package testing +* @copyright (c) 2013 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ + +/** +* @group functional +*/ +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), + 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), + ); + } + + /** + * @dataProvider user_subscription_data + */ + public function test_user_subscriptions($checkbox_name, $expected_status) + { + $this->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); + } + } +} 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')); 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 = '') { diff --git a/tests/mock/extension_manager.php b/tests/mock/extension_manager.php index fdda4cbadc..10b3595206 100644 --- a/tests/mock/extension_manager.php +++ b/tests/mock/extension_manager.php @@ -12,7 +12,8 @@ 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(); } } 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 @@ +<?php +/** +* +* @package testing +* @copyright (c) 2013 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ + +class phpbb_mock_metadata_manager 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); + } +} 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 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<dataset> + <table name="phpbb_bookmarks"> + <column>topic_id</column> + <column>user_id</column> + <row> + <value>1</value> + <value>2</value> + </row> + <row> + <value>1</value> + <value>3</value> + </row> + <row> + <value>1</value> + <value>4</value> + </row> + <row> + <value>1</value> + <value>5</value> + </row> + <row> + <value>1</value> + <value>6</value> + </row> + <row> + <value>1</value> + <value>7</value> + </row> + </table> + <table name="phpbb_notifications"> + <column>item_type</column> + <column>user_id</column> + <column>item_id</column> + <column>item_parent_id</column> + <column>notification_read</column> + <column>notification_data</column> + <row> + <value>bookmark</value> + <value>5</value> + <value>1</value> + <value>1</value> + <value>0</value> + <value></value> + </row> + </table> + <table name="phpbb_notification_types"> + <column>notification_type</column> + <column>notification_type_enabled</column> + <row> + <value>bookmark</value> + <value>1</value> + </row> + </table> + <table name="phpbb_posts"> + <column>post_id</column> + <column>topic_id</column> + <column>forum_id</column> + <column>post_text</column> + <row> + <value>1</value> + <value>1</value> + <value>1</value> + <value></value> + </row> + </table> + <table name="phpbb_topics"> + <column>topic_id</column> + <column>forum_id</column> + <row> + <value>1</value> + <value>1</value> + </row> + </table> + <table name="phpbb_users"> + <column>user_id</column> + <column>username_clean</column> + <column>user_permissions</column> + <column>user_sig</column> + <column>user_occ</column> + <column>user_interests</column> + <row> + <value>2</value> + <value>poster</value> + <value></value> + <value></value> + <value></value> + <value></value> + </row> + <row> + <value>3</value> + <value>test</value> + <value></value> + <value></value> + <value></value> + <value></value> + </row> + <row> + <value>4</value> + <value>unauthorized</value> + <value></value> + <value></value> + <value></value> + <value></value> + </row> + <row> + <value>5</value> + <value>notified</value> + <value></value> + <value></value> + <value></value> + <value></value> + </row> + <row> + <value>6</value> + <value>disabled</value> + <value></value> + <value></value> + <value></value> + <value></value> + </row> + <row> + <value>7</value> + <value>default</value> + <value></value> + <value></value> + <value></value> + <value></value> + </row> + </table> + <table name="phpbb_user_notifications"> + <column>item_type</column> + <column>item_id</column> + <column>user_id</column> + <column>method</column> + <column>notify</column> + <row> + <value>bookmark</value> + <value>0</value> + <value>2</value> + <value></value> + <value>1</value> + </row> + <row> + <value>bookmark</value> + <value>0</value> + <value>3</value> + <value></value> + <value>1</value> + </row> + <row> + <value>bookmark</value> + <value>0</value> + <value>4</value> + <value></value> + <value>1</value> + </row> + <row> + <value>bookmark</value> + <value>0</value> + <value>5</value> + <value></value> + <value>1</value> + </row> + <row> + <value>bookmark</value> + <value>0</value> + <value>6</value> + <value></value> + <value>0</value> + </row> + </table> +</dataset> 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 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<dataset> + <table name="phpbb_forums_watch"> + <column>forum_id</column> + <column>user_id</column> + <column>notify_status</column> + <row> + <value>1</value> + <value>6</value> + <value>0</value> + </row> + <row> + <value>1</value> + <value>7</value> + <value>0</value> + </row> + <row> + <value>1</value> + <value>8</value> + <value>0</value> + </row> + </table> + <table name="phpbb_notifications"> + <column>item_type</column> + <column>user_id</column> + <column>item_id</column> + <column>item_parent_id</column> + <column>notification_read</column> + <column>notification_data</column> + <row> + <value>post</value> + <value>5</value> + <value>1</value> + <value>1</value> + <value>0</value> + <value></value> + </row> + <row> + <value>post</value> + <value>8</value> + <value>1</value> + <value>1</value> + <value>0</value> + <value></value> + </row> + </table> + <table name="phpbb_notification_types"> + <column>notification_type</column> + <column>notification_type_enabled</column> + <row> + <value>post</value> + <value>1</value> + </row> + </table> + <table name="phpbb_posts"> + <column>post_id</column> + <column>topic_id</column> + <column>forum_id</column> + <column>post_text</column> + <row> + <value>1</value> + <value>1</value> + <value>1</value> + <value></value> + </row> + </table> + <table name="phpbb_topics"> + <column>topic_id</column> + <column>forum_id</column> + <row> + <value>1</value> + <value>1</value> + </row> + </table> + <table name="phpbb_topics_watch"> + <column>topic_id</column> + <column>user_id</column> + <column>notify_status</column> + <row> + <value>1</value> + <value>2</value> + <value>0</value> + </row> + <row> + <value>1</value> + <value>3</value> + <value>0</value> + </row> + <row> + <value>1</value> + <value>4</value> + <value>0</value> + </row> + <row> + <value>1</value> + <value>5</value> + <value>0</value> + </row> + <row> + <value>1</value> + <value>6</value> + <value>0</value> + </row> + </table> + <table name="phpbb_users"> + <column>user_id</column> + <column>username_clean</column> + <column>user_permissions</column> + <column>user_sig</column> + <column>user_occ</column> + <column>user_interests</column> + <row> + <value>2</value> + <value>poster</value> + <value></value> + <value></value> + <value></value> + <value></value> + </row> + <row> + <value>3</value> + <value>test</value> + <value></value> + <value></value> + <value></value> + <value></value> + </row> + <row> + <value>4</value> + <value>unauthorized</value> + <value></value> + <value></value> + <value></value> + <value></value> + </row> + <row> + <value>5</value> + <value>notified</value> + <value></value> + <value></value> + <value></value> + <value></value> + </row> + <row> + <value>6</value> + <value>disabled</value> + <value></value> + <value></value> + <value></value> + <value></value> + </row> + <row> + <value>7</value> + <value>default</value> + <value></value> + <value></value> + <value></value> + <value></value> + </row> + </table> + <table name="phpbb_user_notifications"> + <column>item_type</column> + <column>item_id</column> + <column>user_id</column> + <column>method</column> + <column>notify</column> + <row> + <value>post</value> + <value>0</value> + <value>2</value> + <value></value> + <value>1</value> + </row> + <row> + <value>post</value> + <value>0</value> + <value>3</value> + <value></value> + <value>1</value> + </row> + <row> + <value>post</value> + <value>0</value> + <value>4</value> + <value></value> + <value>1</value> + </row> + <row> + <value>post</value> + <value>0</value> + <value>5</value> + <value></value> + <value>1</value> + </row> + <row> + <value>post</value> + <value>0</value> + <value>6</value> + <value></value> + <value>1</value> + </row> + <row> + <value>post</value> + <value>0</value> + <value>7</value> + <value></value> + <value>1</value> + </row> + <row> + <value>post</value> + <value>0</value> + <value>8</value> + <value></value> + <value>1</value> + </row> + </table> +</dataset> 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..eedcebf71d --- /dev/null +++ b/tests/notification/fixtures/submit_post_post_in_queue.xml @@ -0,0 +1,175 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<dataset> + <table name="phpbb_notifications"> + <column>item_type</column> + <column>user_id</column> + <column>item_id</column> + <column>item_parent_id</column> + <column>notification_read</column> + <column>notification_data</column> + <row> + <value>post_in_queue</value> + <value>6</value> + <value>1</value> + <value>1</value> + <value>0</value> + <value></value> + </row> + </table> + <table name="phpbb_notification_types"> + <column>notification_type</column> + <column>notification_type_enabled</column> + <row> + <value>post_in_queue</value> + <value>1</value> + </row> + </table> + <table name="phpbb_posts"> + <column>post_id</column> + <column>topic_id</column> + <column>forum_id</column> + <column>post_text</column> + <row> + <value>1</value> + <value>1</value> + <value>1</value> + <value></value> + </row> + </table> + <table name="phpbb_topics"> + <column>topic_id</column> + <column>forum_id</column> + <row> + <value>1</value> + <value>1</value> + </row> + </table> + <table name="phpbb_users"> + <column>user_id</column> + <column>username_clean</column> + <column>user_permissions</column> + <column>user_sig</column> + <column>user_occ</column> + <column>user_interests</column> + <row> + <value>2</value> + <value>poster</value> + <value></value> + <value></value> + <value></value> + <value></value> + </row> + <row> + <value>3</value> + <value>test</value> + <value></value> + <value></value> + <value></value> + <value></value> + </row> + <row> + <value>4</value> + <value>unauthorized-mod</value> + <value></value> + <value></value> + <value></value> + <value></value> + </row> + <row> + <value>5</value> + <value>unauthorized-read</value> + <value></value> + <value></value> + <value></value> + <value></value> + </row> + <row> + <value>6</value> + <value>notified</value> + <value></value> + <value></value> + <value></value> + <value></value> + </row> + <row> + <value>7</value> + <value>disabled</value> + <value></value> + <value></value> + <value></value> + <value></value> + </row> + <row> + <value>8</value> + <value>default</value> + <value></value> + <value></value> + <value></value> + <value></value> + </row> + <row> + <value>9</value> + <value>test glboal-permissions</value> + <value></value> + <value></value> + <value></value> + <value></value> + </row> + </table> + <table name="phpbb_user_notifications"> + <column>item_type</column> + <column>item_id</column> + <column>user_id</column> + <column>method</column> + <column>notify</column> + <row> + <value>needs_approval</value> + <value>0</value> + <value>2</value> + <value></value> + <value>1</value> + </row> + <row> + <value>needs_approval</value> + <value>0</value> + <value>3</value> + <value></value> + <value>1</value> + </row> + <row> + <value>needs_approval</value> + <value>0</value> + <value>4</value> + <value></value> + <value>1</value> + </row> + <row> + <value>needs_approval</value> + <value>0</value> + <value>5</value> + <value></value> + <value>1</value> + </row> + <row> + <value>needs_approval</value> + <value>0</value> + <value>6</value> + <value></value> + <value>1</value> + </row> + <row> + <value>needs_approval</value> + <value>0</value> + <value>7</value> + <value></value> + <value>0</value> + </row> + <row> + <value>needs_approval</value> + <value>0</value> + <value>9</value> + <value></value> + <value>1</value> + </row> + </table> +</dataset> 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 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<dataset> + <table name="phpbb_notifications"> + <column>item_type</column> + <column>user_id</column> + <column>item_id</column> + <column>item_parent_id</column> + <column>notification_read</column> + <column>notification_data</column> + <row> + <value>quote</value> + <value>5</value> + <value>1</value> + <value>1</value> + <value>0</value> + <value></value> + </row> + </table> + <table name="phpbb_notification_types"> + <column>notification_type</column> + <column>notification_type_enabled</column> + <row> + <value>quote</value> + <value>1</value> + </row> + </table> + <table name="phpbb_posts"> + <column>post_id</column> + <column>topic_id</column> + <column>forum_id</column> + <column>post_text</column> + <row> + <value>1</value> + <value>1</value> + <value>1</value> + <value></value> + </row> + </table> + <table name="phpbb_topics"> + <column>topic_id</column> + <column>forum_id</column> + <row> + <value>1</value> + <value>1</value> + </row> + </table> + <table name="phpbb_users"> + <column>user_id</column> + <column>username_clean</column> + <column>user_permissions</column> + <column>user_sig</column> + <column>user_occ</column> + <column>user_interests</column> + <row> + <value>2</value> + <value>poster</value> + <value></value> + <value></value> + <value></value> + <value></value> + </row> + <row> + <value>3</value> + <value>test</value> + <value></value> + <value></value> + <value></value> + <value></value> + </row> + <row> + <value>4</value> + <value>unauthorized</value> + <value></value> + <value></value> + <value></value> + <value></value> + </row> + <row> + <value>5</value> + <value>notified</value> + <value></value> + <value></value> + <value></value> + <value></value> + </row> + <row> + <value>6</value> + <value>disabled</value> + <value></value> + <value></value> + <value></value> + <value></value> + </row> + <row> + <value>7</value> + <value>default</value> + <value></value> + <value></value> + <value></value> + <value></value> + </row> + </table> + <table name="phpbb_user_notifications"> + <column>item_type</column> + <column>item_id</column> + <column>user_id</column> + <column>method</column> + <column>notify</column> + <row> + <value>quote</value> + <value>0</value> + <value>2</value> + <value></value> + <value>1</value> + </row> + <row> + <value>quote</value> + <value>0</value> + <value>3</value> + <value></value> + <value>1</value> + </row> + <row> + <value>quote</value> + <value>0</value> + <value>4</value> + <value></value> + <value>1</value> + </row> + <row> + <value>quote</value> + <value>0</value> + <value>5</value> + <value></value> + <value>1</value> + </row> + <row> + <value>quote</value> + <value>0</value> + <value>6</value> + <value></value> + <value>0</value> + </row> + </table> +</dataset> diff --git a/tests/notification/submit_post_base.php b/tests/notification/submit_post_base.php new file mode 100644 index 0000000000..953bedac80 --- /dev/null +++ b/tests/notification/submit_post_base.php @@ -0,0 +1,141 @@ +<?php +/** +* +* @package testing +* @copyright (c) 2013 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ + +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'; + +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_' . $this->item_type . '.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', 'post_in_queue'); + 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)); + } + } + + /** + * @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); + + $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 . " + 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_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 @@ +<?php +/** +* +* @package testing +* @copyright (c) 2013 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ + +require_once dirname(__FILE__) . '/submit_post_base.php'; + +class phpbb_notification_submit_post_type_bookmark_test extends phpbb_notification_submit_post_base +{ + protected $item_type = 'bookmark'; + + public function setUp() + { + parent::setUp(); + + global $auth; + + // Add additional permissions + $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), + ), + ), + ), + ))); + } + + /** + * 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), + ), + ), + ); + } +} 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..6a7ac44e39 --- /dev/null +++ b/tests/notification/submit_post_type_post_in_queue_test.php @@ -0,0 +1,107 @@ +<?php +/** +* +* @package testing +* @copyright (c) 2013 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ + +require_once dirname(__FILE__) . '/submit_post_base.php'; + +class phpbb_notification_submit_post_type_post_in_queue_test extends phpbb_notification_submit_post_base +{ + protected $item_type = 'post_in_queue'; + + public function setUp() + { + parent::setUp(); + + global $auth; + + // Add additional permissions + $auth->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( + 0 => array( + 'm_approve' => array(9), + ), + 1 => array( + 'm_approve' => array(3, 4, 6, 7, 8), + ), + ), + ), + array( + array(3, 4, 6, 7, 8, 9), + 'f_read', + 1, + array( + 1 => array( + 'f_read' => array(3, 6, 7, 8, 9), + ), + ), + ), + ))); + } + + /** + * 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 + * 9 => Moderator, has only global mod permissions, 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), + array('user_id' => 9, 'item_id' => 2, 'item_parent_id' => 1), + ), + ), + ); + } +} 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..473247a764 --- /dev/null +++ b/tests/notification/submit_post_type_post_test.php @@ -0,0 +1,96 @@ +<?php +/** +* +* @package testing +* @copyright (c) 2013 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ + +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(); + + global $auth; + + // Add additional permissions + $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), + ), + ), + ), + ))); + } + + /** + * submit_post() Notifications test + * + * submit_post() $mode = 'reply' + * Notification item_type = 'post' + */ + public function submit_post_data() + { + 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), + ), + ), + + /** + * 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), + ), + ), + ); + } +} 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..2b66d9c6a1 --- /dev/null +++ b/tests/notification/submit_post_type_quote_test.php @@ -0,0 +1,113 @@ +<?php +/** +* +* @package testing +* @copyright (c) 2013 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ + +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(); + + global $auth; + + // Add additional permissions + $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), + ), + ), + ), + ))); + } + + /** + * submit_post() Notifications test + * + * submit_post() $mode = 'reply' + * Notification item_type = 'quote' + */ + public function submit_post_data() + { + 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), + ), + ), + + /** + * 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), + ), + ), + ); + } +} 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(), + ), ); } 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), ); } 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} + +<div class="{VARIABLE}">test</div> 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..49d8a6b873 --- /dev/null +++ b/tests/template/datasets/ext_trivial/styles/silver/template/variable_spacing.html @@ -0,0 +1 @@ +<!-- EVENT event_variable_spacing --> 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 diff --git a/tests/template/template_spacing_test.php b/tests/template/template_spacing_test.php new file mode 100644 index 0000000000..fb4161066a --- /dev/null +++ b/tests/template/template_spacing_test.php @@ -0,0 +1,91 @@ +<?php +/** +* +* @package testing +* @copyright (c) 2013 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ + +require_once dirname(__FILE__) . '/template_test_case.php'; + +class phpbb_template_template_spacing_test extends phpbb_template_template_test_case +{ + public function template_data() + { + return array( + /* + array( + '', // Description + '', // dataset + array(), // style names + '', // file + array(), // vars + array(), // block vars + array(), // destroy + '', // expected result + ), + */ + array( + 'Spacing in templates', + 'ext_trivial', + array(), + 'variable_spacing.html', + array( + 'VARIABLE' => '{}', + ), + array(), + array(), + '|{}| +{}|{}| +|{} +<div class="{}">test</div>', + ), + ); + } + + /** + * @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) + { + $this->markTestIncomplete( + 'This test will fail until PHPBB3-11435 is fixed' + ); + + // 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..028f8aa0d1 --- /dev/null +++ b/tests/template/templates/variable_spacing.html @@ -0,0 +1,6 @@ +|{VARIABLE}| +{VARIABLE}|{VARIABLE}| + +|{VARIABLE} + +<div class="{VARIABLE}">test</div> diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index 887dfea3b5..dae37f336d 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -153,9 +153,10 @@ class phpbb_functional_test_case extends phpbb_test_case $db, $config, $migrator, + new phpbb_filesystem(), self::$config['table_prefix'] . 'ext', dirname(__FILE__) . '/', - '.' . $php_ext, + $php_ext, $this->get_cache_driver() ); @@ -196,12 +197,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'] . '://', @@ -316,6 +317,90 @@ 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_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 = 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(); + $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'); + } + + $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 add_user_group($group_name, $usernames) + { + 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 = 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(); + $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'); + } + + $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'); @@ -340,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. @@ -446,6 +542,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); } public function assert_filter($crawler, $expr, $msg = null) @@ -463,4 +562,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; + } } diff --git a/tests/tree/fixtures/phpbb_forums.xml b/tests/tree/fixtures/phpbb_forums.xml new file mode 100644 index 0000000000..8f133078a9 --- /dev/null +++ b/tests/tree/fixtures/phpbb_forums.xml @@ -0,0 +1,13 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<dataset> + <table name="phpbb_forums"> + <column>forum_id</column> + <column>parent_id</column> + <column>left_id</column> + <column>right_id</column> + <column>forum_parents</column> + <column>forum_name</column> + <column>forum_desc</column> + <column>forum_rules</column> + </table> +</dataset> diff --git a/tests/tree/nestedset_forum_base.php b/tests/tree/nestedset_forum_base.php new file mode 100644 index 0000000000..776e822280 --- /dev/null +++ b/tests/tree/nestedset_forum_base.php @@ -0,0 +1,90 @@ +<?php +/** +* +* @package tree +* @copyright (c) 2013 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ + +class phpbb_tests_tree_nestedset_forum_base extends phpbb_database_test_case +{ + public function getDataSet() + { + return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/phpbb_forums.xml'); + } + + protected $forum_data = array( + // \__/ + 1 => array('forum_id' => 1, 'parent_id' => 0, 'user_id' => 0, 'left_id' => 1, 'right_id' => 6, 'forum_parents' => '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' => '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' => '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:{}'), + + // 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:{}'), + ); + + 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(); + + $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); + } + + 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..ca1863e55e --- /dev/null +++ b/tests/tree/nestedset_forum_get_data_test.php @@ -0,0 +1,119 @@ +<?php +/** +* +* @package tree +* @copyright (c) 2013 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ + +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_path_and_subtree_data_data() + { + return array( + array(1, true, true, array(1, 2, 3)), + array(1, true, false, array(2, 3)), + array(1, false, true, array(3, 2, 1)), + array(1, false, false, array(3, 2)), + + array(2, true, true, array(1, 2)), + array(2, true, false, array(1)), + array(2, false, true, array(2, 1)), + array(2, false, false, array(1)), + + array(5, true, true, array(4, 5, 6)), + array(5, true, false, array(4, 6)), + array(5, false, true, array(6, 5, 4)), + array(5, false, false, array(6, 4)), + ); + } + + /** + * @dataProvider get_path_and_subtree_data_data + */ + 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_asc, $include_item))); + } + + public function get_path_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_path_data_data + */ + 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_asc, $include_item))); + } + + public function get_subtree_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_subtree_data_data + */ + 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_asc, $include_item))); + } + + public function get_path_basic_data_data() + { + return array( + 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_parents, $expected) + { + $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 new file mode 100644 index 0000000000..d0e9e02c2e --- /dev/null +++ b/tests/tree/nestedset_forum_insert_delete_test.php @@ -0,0 +1,120 @@ +<?php +/** +* +* @package tree +* @copyright (c) 2013 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ + +require_once dirname(__FILE__) . '/nestedset_forum_base.php'; + +class phpbb_tests_tree_nestedset_forum_add_remove_test extends phpbb_tests_tree_nestedset_forum_base +{ + 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), + 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), + 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), + )), + ); + } + + /** + * @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 + FROM phpbb_forums + ORDER BY left_id, forum_id ASC"); + $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( + 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), + 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('forum_id' => 12, 'parent_id' => 0, 'left_id' => 23, 'right_id' => 24), + )), + ); + } + + /** + * @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 + 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 new file mode 100644 index 0000000000..fe506c8278 --- /dev/null +++ b/tests/tree/nestedset_forum_move_test.php @@ -0,0 +1,569 @@ +<?php +/** +* +* @package tree +* @copyright (c) 2013 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ + +require_once dirname(__FILE__) . '/nestedset_forum_base.php'; + +class phpbb_tests_tree_nestedset_forum_move_test extends phpbb_tests_tree_nestedset_forum_base +{ + public function move_data() + { + return array( + array('Move first item up', + 1, 1, false, array( + array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 6), + 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), + 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), + 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), + 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), + 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), + 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), + 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), + )), + ); + } + + /** + * @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 + 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), + 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), + 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), + )), + ); + } + + /** + * @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 + 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), + 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), + 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), + )), + ); + } + + /** + * @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 + 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' => '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' => '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' => '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' => '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' => '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' => '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' => '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 down', + 5, 7, 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' => 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' => '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' => 'a:0:{}'), + + 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' => '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' => 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' => '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' => 'a:0:{}'), + + 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' => ''), + )), + ); + } + + /** + * @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' => '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' => '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' => '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' => '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' => '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 down', + 6, 7, 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' => 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' => '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' => 'a:0:{}'), + + 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' => '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' => 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' => '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' => 'a:0:{}'), + + 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' => ''), + )), + ); + } + + /** + * @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..38338dbc4d --- /dev/null +++ b/tests/tree/nestedset_forum_regenerate_test.php @@ -0,0 +1,72 @@ +<?php +/** +* +* @package tree +* @copyright (c) 2013 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ + +require_once dirname(__FILE__) . '/nestedset_forum_base.php'; + +class phpbb_tests_tree_nestedset_forum_regenerate_test extends phpbb_tests_tree_nestedset_forum_base +{ + protected $fixed_set = array( + array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 6, 'forum_parents' => ''), + array('forum_id' => 2, 'parent_id' => 1, 'left_id' => 2, 'right_id' => 3, 'forum_parents' => ''), + array('forum_id' => 3, 'parent_id' => 1, 'left_id' => 4, 'right_id' => 5, 'forum_parents' => ''), + + array('forum_id' => 4, 'parent_id' => 0, 'left_id' => 7, 'right_id' => 12, 'forum_parents' => ''), + array('forum_id' => 5, 'parent_id' => 4, 'left_id' => 8, 'right_id' => 11, 'forum_parents' => ''), + array('forum_id' => 6, 'parent_id' => 5, 'left_id' => 9, 'right_id' => 10, 'forum_parents' => ''), + + array('forum_id' => 7, 'parent_id' => 0, 'left_id' => 13, 'right_id' => 22, 'forum_parents' => ''), + array('forum_id' => 8, 'parent_id' => 7, 'left_id' => 14, 'right_id' => 15, 'forum_parents' => ''), + array('forum_id' => 9, 'parent_id' => 7, 'left_id' => 16, 'right_id' => 19, 'forum_parents' => ''), + array('forum_id' => 10, 'parent_id' => 9, 'left_id' => 17, 'right_id' => 18, 'forum_parents' => ''), + array('forum_id' => 11, 'parent_id' => 7, 'left_id' => 20, 'right_id' => 21, 'forum_parents' => ''), + ); + + public function regenerate_left_right_ids_data() + { + return array( + array('UPDATE phpbb_forums + SET left_id = 0, + right_id = 0', false), + array('UPDATE phpbb_forums + SET left_id = 28, + right_id = 28 + WHERE left_id > 12', false), + array('UPDATE phpbb_forums + SET left_id = left_id * 2, + right_id = right_id * 2', false), + array('UPDATE phpbb_forums + SET left_id = left_id * 2, + right_id = right_id * 2 + WHERE left_id > 12', false), + array('UPDATE phpbb_forums + SET left_id = left_id - 4, + right_id = right_id * 4 + WHERE left_id > 4', false), + array('UPDATE phpbb_forums + SET left_id = 0, + right_id = 0 + WHERE left_id > 12', true), + ); + } + + /** + * @dataProvider regenerate_left_right_ids_data + */ + public function test_regenerate_left_right_ids($breaking_query, $reset_ids) + { + $result = $this->db->sql_query($breaking_query); + + $this->assertEquals(23, $this->set->regenerate_left_right_ids(1, 0, $reset_ids)); + + $result = $this->db->sql_query('SELECT forum_id, parent_id, left_id, right_id, forum_parents + FROM phpbb_forums + ORDER BY left_id, forum_id ASC'); + $this->assertEquals($this->fixed_set, $this->db->sql_fetchrowset($result)); + } +} diff --git a/tests/tree/nestedset_forum_test.php b/tests/tree/nestedset_forum_test.php new file mode 100644 index 0000000000..516c794ffc --- /dev/null +++ b/tests/tree/nestedset_forum_test.php @@ -0,0 +1,116 @@ +<?php +/** +* +* @package tree +* @copyright (c) 2013 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ + +require_once dirname(__FILE__) . '/nestedset_forum_base.php'; + +class pphpbb_tests_tree_nestedset_forum_test extends phpbb_tests_tree_nestedset_forum_base +{ + public function forum_constructor_data() + { + return array( + array(array( + array('forum_id' => 1, 'parent_id' => 0, 'left_id' => 1, 'right_id' => 6), + 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), + )), + ); + } + + /** + * @dataProvider forum_constructor_data + */ + public function test_forum_constructor($expected) + { + $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)); + } + + public function get_sql_where_data() + { + return array( + array('SELECT forum_id + FROM phpbb_forums + %s + ORDER BY forum_id ASC', + 'WHERE', '', array( + array('forum_id' => 1), + array('forum_id' => 2), + array('forum_id' => 3), + + array('forum_id' => 4), + array('forum_id' => 5), + array('forum_id' => 6), + + 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 + FROM phpbb_forums f + %s + ORDER BY f.forum_id ASC', + 'WHERE', 'f.', array( + array('forum_id' => 1), + array('forum_id' => 2), + array('forum_id' => 3), + + array('forum_id' => 4), + array('forum_id' => 5), + array('forum_id' => 6), + + array('forum_id' => 7), + array('forum_id' => 8), + array('forum_id' => 9), + array('forum_id' => 10), + array('forum_id' => 11), + )), + array('SELECT forum_id + FROM phpbb_forums + WHERE forum_id < 4 %s + ORDER BY forum_id ASC', + 'AND', '', array( + array('forum_id' => 1), + array('forum_id' => 2), + array('forum_id' => 3), + )), + array('SELECT f.forum_id + FROM phpbb_forums f + WHERE f.forum_id < 4 %s + ORDER BY f.forum_id ASC', + 'AND', 'f.', array( + array('forum_id' => 1), + array('forum_id' => 2), + array('forum_id' => 3), + )), + ); + } + + /** + * @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)); + } +} |