diff options
Diffstat (limited to 'tests')
110 files changed, 3334 insertions, 656 deletions
diff --git a/tests/auth/provider_apache_test.php b/tests/auth/provider_apache_test.php index 2decf0f18c..68ad7b2c19 100644 --- a/tests/auth/provider_apache_test.php +++ b/tests/auth/provider_apache_test.php @@ -29,7 +29,7 @@ class phpbb_auth_provider_apache_test extends phpbb_database_test_case $db = $this->new_dbal(); $config = new \phpbb\config\config(array()); $this->request = $this->getMock('\phpbb\request\request'); - $this->user = $this->getMock('\phpbb\user'); + $this->user = new \phpbb\user('\phpbb\datetime'); $driver_helper = new \phpbb\passwords\driver\helper($config); $passwords_drivers = array( 'passwords.driver.bcrypt_2y' => new \phpbb\passwords\driver\bcrypt_2y($config, $driver_helper), diff --git a/tests/auth/provider_db_test.php b/tests/auth/provider_db_test.php index 23324f87f2..e33eae6b54 100644 --- a/tests/auth/provider_db_test.php +++ b/tests/auth/provider_db_test.php @@ -39,7 +39,7 @@ class phpbb_auth_provider_db_test extends phpbb_database_test_case 'max_login_attempts' => 0, )); $request = $this->getMock('\phpbb\request\request'); - $user = $this->getMock('\phpbb\user'); + $user = new \phpbb\user('\phpbb\datetime'); $driver_helper = new \phpbb\passwords\driver\helper($config); $passwords_drivers = array( 'passwords.driver.bcrypt_2y' => new \phpbb\passwords\driver\bcrypt_2y($config, $driver_helper), @@ -52,7 +52,9 @@ class phpbb_auth_provider_db_test extends phpbb_database_test_case // Set up passwords manager $passwords_manager = new \phpbb\passwords\manager($config, $passwords_drivers, $passwords_helper, array_keys($passwords_drivers)); - $provider = new \phpbb\auth\provider\db($db, $config, $passwords_manager, $request, $user, $phpbb_root_path, $phpEx); + $phpbb_container = new phpbb_mock_container_builder(); + + $provider = new \phpbb\auth\provider\db($db, $config, $passwords_manager, $request, $user, $phpbb_container, $phpbb_root_path, $phpEx); if (version_compare(PHP_VERSION, '5.3.7', '<')) { $password_hash = '$2a$10$e01Syh9PbJjUkio66eFuUu4FhCE2nRgG7QPc1JACalsPXcIuG2bbi'; diff --git a/tests/auth/provider_oauth_token_storage_test.php b/tests/auth/provider_oauth_token_storage_test.php index 45daa9816b..71b49ff439 100644 --- a/tests/auth/provider_oauth_token_storage_test.php +++ b/tests/auth/provider_oauth_token_storage_test.php @@ -31,7 +31,7 @@ class phpbb_auth_provider_oauth_token_storage_test extends phpbb_database_test_c global $phpbb_root_path, $phpEx; $this->db = $this->new_dbal(); - $this->user = $this->getMock('\phpbb\user'); + $this->user = new \phpbb\user('\phpbb\datetime'); $this->service_name = 'auth.provider.oauth.service.testing'; $this->token_storage_table = 'phpbb_oauth_tokens'; diff --git a/tests/avatar/fixtures/users.xml b/tests/avatar/fixtures/users.xml new file mode 100644 index 0000000000..3e6586e909 --- /dev/null +++ b/tests/avatar/fixtures/users.xml @@ -0,0 +1,33 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<dataset> + <table name="phpbb_users"> + <column>user_id</column> + <column>username_clean</column> + <column>user_permissions</column> + <column>user_sig</column> + <column>user_avatar</column> + <column>user_avatar_type</column> + <column>user_avatar_width</column> + <column>user_avatar_height</column> + <row> + <value>1</value> + <value>barfoo</value> + <value></value> + <value></value> + <value>foobar@example.com</value> + <value>avatar.driver.gravatar</value> + <value>80</value> + <value>80</value> + </row> + <row> + <value>2</value> + <value>foobar</value> + <value></value> + <value></value> + <value></value> + <value></value> + <value></value> + <value></value> + </row> + </table> +</dataset> diff --git a/tests/avatar/manager_test.php b/tests/avatar/manager_test.php index d8099b40d4..81c153aed4 100644 --- a/tests/avatar/manager_test.php +++ b/tests/avatar/manager_test.php @@ -13,13 +13,18 @@ require_once dirname(__FILE__) . '/driver/foobar.php'; -class phpbb_avatar_manager_test extends \phpbb_test_case +class phpbb_avatar_manager_test extends \phpbb_database_test_case { /** @var \phpbb\avatar\manager */ protected $manager; protected $avatar_foobar; protected $avatar_barfoo; + public function getDataSet() + { + return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/users.xml'); + } + public function setUp() { global $phpbb_root_path, $phpEx; @@ -31,7 +36,7 @@ class phpbb_avatar_manager_test extends \phpbb_test_case ->will($this->returnArgument(0)); // Prepare dependencies for avatar manager and driver - $config = new \phpbb\config\config(array()); + $this->config = new \phpbb\config\config(array()); $cache = $this->getMock('\phpbb\cache\driver\driver_interface'); $path_helper = new \phpbb\path_helper( new \phpbb\symfony_request( @@ -52,7 +57,7 @@ class phpbb_avatar_manager_test extends \phpbb_test_case $guesser = new \phpbb\mimetype\guesser($guessers); // $this->avatar_foobar will be needed later on - $this->avatar_foobar = $this->getMock('\phpbb\avatar\driver\foobar', array('get_name'), array($config, $phpbb_root_path, $phpEx, $path_helper, $cache)); + $this->avatar_foobar = $this->getMock('\phpbb\avatar\driver\foobar', array('get_name'), array($this->config, $phpbb_root_path, $phpEx, $path_helper, $cache)); $this->avatar_foobar->expects($this->any()) ->method('get_name') ->will($this->returnValue('avatar.driver.foobar')); @@ -67,24 +72,26 @@ class phpbb_avatar_manager_test extends \phpbb_test_case { if ($driver !== 'upload') { - $cur_avatar = $this->getMock('\phpbb\avatar\driver\\' . $driver, array('get_name'), array($config, $phpbb_root_path, $phpEx, $path_helper, $cache)); + $cur_avatar = $this->getMock('\phpbb\avatar\driver\\' . $driver, array('get_name'), array($this->config, $phpbb_root_path, $phpEx, $path_helper, $cache)); } else { - $cur_avatar = $this->getMock('\phpbb\avatar\driver\\' . $driver, array('get_name'), array($config, $phpbb_root_path, $phpEx, $path_helper, $guesser, $cache)); + $cur_avatar = $this->getMock('\phpbb\avatar\driver\\' . $driver, array('get_name'), array($this->config, $phpbb_root_path, $phpEx, $path_helper, $guesser, $cache)); } $cur_avatar->expects($this->any()) ->method('get_name') ->will($this->returnValue('avatar.driver.' . $driver)); - $config['allow_avatar_' . get_class($cur_avatar)] = false; + $this->config['allow_avatar_' . get_class($cur_avatar)] = $driver == 'gravatar'; $avatar_drivers[] = $cur_avatar; } - $config['allow_avatar_' . get_class($this->avatar_foobar)] = true; - $config['allow_avatar_' . get_class($this->avatar_barfoo)] = false; + $this->config['allow_avatar_' . get_class($this->avatar_foobar)] = true; + $this->config['allow_avatar_' . get_class($this->avatar_barfoo)] = false; // Set up avatar manager - $this->manager = new \phpbb\avatar\manager($config, $avatar_drivers, $phpbb_container); + $this->manager = new \phpbb\avatar\manager($this->config, $avatar_drivers, $phpbb_container); + $this->db = $this->new_dbal(); + $this->user = new \phpbb\user('\phpbb\datetime'); } protected function avatar_drivers() @@ -122,6 +129,7 @@ class phpbb_avatar_manager_test extends \phpbb_test_case { return array( array('avatar.driver.foobar', 'avatar.driver.foobar'), + array('avatar.driver.gravatar', 'avatar.driver.gravatar'), array('avatar.driver.foo_wrong', null), array('avatar.driver.local', null), array(AVATAR_GALLERY, null), @@ -196,8 +204,8 @@ class phpbb_avatar_manager_test extends \phpbb_test_case array( 'avatar' => '', 'avatar_type' => '', - 'avatar_width' => '', - 'avatar_height' => '', + 'avatar_width' => 0, + 'avatar_height' => 0, ), ), array( @@ -266,7 +274,7 @@ class phpbb_avatar_manager_test extends \phpbb_test_case public function test_localize_errors() { - $user = $this->getMock('\phpbb\user'); + $user = $this->getMock('\phpbb\user', array(), array('\phpbb\datetime')); $lang_array = array( array('FOOBAR_OFF', 'foobar_off'), array('FOOBAR_EXPLAIN', 'FOOBAR_EXPLAIN %s'), @@ -287,4 +295,42 @@ class phpbb_avatar_manager_test extends \phpbb_test_case array('FOOBAR_EXPLAIN', 'foo'), ))); } + + public function data_handle_avatar_delete() + { + return array( + array(array( + 'avatar' => '', + 'avatar_type' => '', + 'avatar_width' => 0, + 'avatar_height' => 0, + ), 1, array( + 'avatar' => 'foobar@example.com', + 'avatar_type' => 'avatar.driver.gravatar', + 'avatar_width' => '16', + 'avatar_height' => '16', + ), USERS_TABLE, 'user_'), + ); + } + + /** + * @dataProvider data_handle_avatar_delete + */ + public function test_handle_avatar_delete($expected, $id, $avatar_data, $table, $prefix) + { + $this->config['allow_avatar_gravatar'] = true; + $this->assertNull($this->manager->handle_avatar_delete($this->db, $this->user, $avatar_data, $table, $prefix)); + + $sql = 'SELECT * FROM ' . $table . ' + WHERE ' . $prefix . 'id = ' . $id; + $result = $this->db->sql_query_limit($sql, 1); + + $row = $this->manager->clean_row($this->db->sql_fetchrow($result), substr($prefix, 0, -1)); + $this->db->sql_freeresult($result); + + foreach ($expected as $key => $value) + { + $this->assertEquals($value, $row[$key]); + } + } } diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 2856ba02bb..40c6ef7dfa 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -19,6 +19,7 @@ require_once $phpbb_root_path . 'includes/startup.php'; $table_prefix = 'phpbb_'; require_once $phpbb_root_path . 'includes/constants.php'; require_once $phpbb_root_path . 'phpbb/class_loader.' . $phpEx; +require_once($phpbb_root_path . 'includes/utf/utf_tools.' . $phpEx); $phpbb_class_loader_mock = new \phpbb\class_loader('phpbb_mock_', $phpbb_root_path . '../tests/mock/', "php"); $phpbb_class_loader_mock->register(); @@ -31,5 +32,4 @@ require_once 'test_framework/phpbb_test_case_helpers.php'; require_once 'test_framework/phpbb_test_case.php'; require_once 'test_framework/phpbb_database_test_case.php'; require_once 'test_framework/phpbb_database_test_connection_manager.php'; -require_once 'test_framework/phpbb_mink_test_case.php'; require_once 'test_framework/phpbb_functional_test_case.php'; diff --git a/tests/config_php_file_test.php b/tests/config_php_file_test.php index c2e4eb21c7..c319678108 100644 --- a/tests/config_php_file_test.php +++ b/tests/config_php_file_test.php @@ -17,6 +17,7 @@ class phpbb_config_php_file_test extends phpbb_test_case { $config_php = new \phpbb\config_php_file(dirname( __FILE__ ) . '/fixtures/', 'php'); $this->assertSame('bar', $config_php->get('foo')); + $this->assertNull($config_php->get('bar')); $this->assertSame(array('foo' => 'bar', 'foo_foo' => 'bar bar'), $config_php->get_all()); } @@ -25,6 +26,15 @@ class phpbb_config_php_file_test extends phpbb_test_case $config_php = new \phpbb\config_php_file(dirname( __FILE__ ) . '/fixtures/', 'php'); $config_php->set_config_file(dirname( __FILE__ ) . '/fixtures/config_other.php'); $this->assertSame('foo', $config_php->get('bar')); + $this->assertNull($config_php->get('foo')); $this->assertSame(array('bar' => 'foo', 'bar_bar' => 'foo foo'), $config_php->get_all()); } + + public function test_non_existent_file() + { + $config_php = new \phpbb\config_php_file(dirname( __FILE__ ) . '/fixtures/non_existent/', 'php'); + $this->assertNull($config_php->get('bar')); + $this->assertNull($config_php->get('foo')); + $this->assertSame(array(), $config_php->get_all()); + } } diff --git a/tests/console/cache/purge_test.php b/tests/console/cache/purge_test.php new file mode 100644 index 0000000000..96988c1028 --- /dev/null +++ b/tests/console/cache/purge_test.php @@ -0,0 +1,95 @@ +<?php +/** +* +* This file is part of the phpBB Forum Software package. +* +* @copyright (c) phpBB Limited <https://www.phpbb.com> +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ + +use Symfony\Component\Console\Application; +use Symfony\Component\Console\Tester\CommandTester; +use phpbb\console\command\cache\purge; + +require_once dirname(__FILE__) . '/../../../phpBB/includes/functions_admin.php'; + +class phpbb_console_command_cache_purge_test extends phpbb_test_case +{ + protected $cache_dir; + protected $cache; + protected $command_name; + protected $db; + protected $config; + + public function __construct() + { + $this->cache_dir = dirname(__FILE__) . '/tmp/cache/'; + } + + protected function setUp() + { + if (file_exists($this->cache_dir)) + { + // cache directory possibly left after aborted + // or failed run earlier + $this->remove_cache_dir(); + } + $this->create_cache_dir(); + + $this->cache = new \phpbb\cache\driver\file($this->cache_dir); + + $this->db = $this->getMock('\phpbb\db\driver\driver_interface'); + + $this->config = new \phpbb\config\config(array('assets_version' => 1)); + $this->user = $this->getMock('\phpbb\user', array(), array('\phpbb\datetime')); + } + + public function test_purge() + { + $this->cache->put('test_key', 'test_value'); + + $this->assertEquals( + 'test_value', + $this->cache->get('test_key'), + 'File ACM put and get' + ); + + $command_tester = $this->get_command_tester(); + $exit_status = $command_tester->execute(array('command' => $this->command_name)); + + $this->assertSame(false, $this->cache->get('test_key')); + $this->assertSame(2, $this->config['assets_version']); + } + + private function create_cache_dir() + { + $this->get_test_case_helpers()->makedirs($this->cache_dir); + } + + private function remove_cache_dir() + { + $iterator = new DirectoryIterator($this->cache_dir); + foreach ($iterator as $file) + { + if ($file != '.' && $file != '..') + { + unlink($this->cache_dir . '/' . $file); + } + } + rmdir($this->cache_dir); + } + + public function get_command_tester() + { + $application = new Application(); + $application->add(new purge($this->user, $this->cache, $this->db, $this->getMock('\phpbb\auth\auth'), new \phpbb\log\null(), $this->config)); + + $command = $application->find('cache:purge'); + $this->command_name = $command->getName(); + return new CommandTester($command); + } +} diff --git a/tests/console/config/config_test.php b/tests/console/config/config_test.php new file mode 100644 index 0000000000..7c098af004 --- /dev/null +++ b/tests/console/config/config_test.php @@ -0,0 +1,251 @@ +<?php +/** +* +* This file is part of the phpBB Forum Software package. +* +* @copyright (c) phpBB Limited <https://www.phpbb.com> +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ + +use Symfony\Component\Console\Application; +use Symfony\Component\Console\Tester\CommandTester; + +class phpbb_console_command_config_test extends phpbb_test_case +{ + protected $config; + protected $command_name; + protected $user; + + public function setUp() + { + $this->config = new \phpbb\config\config(array()); + + $this->user = $this->getMock('\phpbb\user', array(), array('\phpbb\datetime')); + $this->user->method('lang')->will($this->returnArgument(0)); + } + + public function test_set_dynamic() + { + $this->assertEmpty($this->config); + + $command_tester = $this->get_command_tester('set'); + $command_tester->execute(array( + 'command' => $this->command_name, + 'key' => 'test_key', + 'value' => 'test_value', + '--dynamic' => true, + )); + + $this->assertSame($this->config['test_key'], 'test_value'); + } + + public function test_set_no_dynamic() + { + $this->assertEmpty($this->config); + + $command_tester = $this->get_command_tester('set'); + $command_tester->execute(array( + 'command' => $this->command_name, + 'key' => 'test_key', + 'value' => 'test_value', + '--dynamic' => false, + )); + + $this->assertSame($this->config['test_key'], 'test_value'); + } + + public function test_set_atomic_dynamic() + { + $this->assertEmpty($this->config); + + $this->config->set('test_key', 'old_value', true); + $this->assertSame($this->config['test_key'], 'old_value'); + + $command_tester = $this->get_command_tester('set_atomic'); + $command_tester->execute(array( + 'command' => $this->command_name, + 'key' => 'test_key', + 'old' => 'old_value', + 'new' => 'new_value', + '--dynamic' => true, + )); + + $this->assertSame($this->config['test_key'], 'new_value'); + } + + public function test_set_atomic_no_dynamic() + { + $this->assertEmpty($this->config); + + $this->config->set('test_key', 'old_value', false); + $this->assertSame($this->config['test_key'], 'old_value'); + + $command_tester = $this->get_command_tester('set_atomic'); + $command_tester->execute(array( + 'command' => $this->command_name, + 'key' => 'test_key', + 'old' => 'old_value', + 'new' => 'new_value', + '--dynamic' => false, + )); + + $this->assertSame($this->config['test_key'], 'new_value'); + } + + public function test_set_atomic_error_dynamic() + { + $this->assertEmpty($this->config); + + $this->config->set('test_key', 'wrong_value', true); + $this->assertSame($this->config['test_key'], 'wrong_value'); + + $command_tester = $this->get_command_tester('set_atomic'); + $command_tester->execute(array( + 'command' => $this->command_name, + 'key' => 'test_key', + 'old' => 'old_value', + 'new' => 'new_value', + '--dynamic' => true, + )); + + $this->assertSame($this->config['test_key'], 'wrong_value'); + } + + public function test_get_no_new_line() + { + $this->config->set('test_key', 'test_value', false); + $this->assertSame($this->config['test_key'], 'test_value'); + + $command_tester = $this->get_command_tester('get'); + $command_tester->execute(array( + 'command' => $this->command_name, + 'key' => 'test_key', + '--no-newline' => true, + )); + + $this->assertSame($this->config['test_key'], $command_tester->getDisplay()); + } + + public function test_get_new_line() + { + $this->config->set('test_key', 'test_value', false); + $this->assertSame($this->config['test_key'], 'test_value'); + + $command_tester = $this->get_command_tester('get'); + $command_tester->execute(array( + 'command' => $this->command_name, + 'key' => 'test_key', + '--no-newline' => false, + )); + + $this->assertSame($this->config['test_key'] . PHP_EOL, $command_tester->getDisplay()); + } + + public function test_get_error() + { + $this->config->set('test_key', 'test_value', false); + $this->assertSame($this->config['test_key'], 'test_value'); + + $command_tester = $this->get_command_tester('get'); + $command_tester->execute(array( + 'command' => $this->command_name, + 'key' => 'wrong_key', + '--no-newline' => false, + )); + + $this->assertContains('CLI_CONFIG_NOT_EXISTS', $command_tester->getDisplay()); + } + + public function test_increment_dynamic() + { + $this->config->set('test_key', 0, false); + $this->assertSame($this->config['test_key'], 0); + + $command_tester = $this->get_command_tester('increment'); + $command_tester->execute(array( + 'command' => $this->command_name, + 'key' => 'test_key', + 'increment' => 2, + '--dynamic' => true, + )); + + $this->assertContains('CLI_CONFIG_INCREMENT_SUCCESS', $command_tester->getDisplay()); + $this->assertSame(2, $this->config['test_key']); + } + + public function test_increment_no_dynamic() + { + $this->config->set('test_key', 0, false); + $this->assertSame($this->config['test_key'], 0); + + $command_tester = $this->get_command_tester('increment'); + $command_tester->execute(array( + 'command' => $this->command_name, + 'key' => 'test_key', + 'increment' => 2, + '--dynamic' => false, + )); + + $this->assertContains('CLI_CONFIG_INCREMENT_SUCCESS', $command_tester->getDisplay()); + $this->assertSame(2, $this->config['test_key']); + } + + public function test_increment_no_set() + { + $this->assertEmpty($this->config); + + $command_tester = $this->get_command_tester('increment'); + $command_tester->execute(array( + 'command' => $this->command_name, + 'key' => 'test_key', + 'increment' => 2, + '--dynamic' => true, + )); + + $this->assertContains('CLI_CONFIG_INCREMENT_SUCCESS', $command_tester->getDisplay()); + $this->assertSame(2, $this->config['test_key']); + } + + public function test_delete_ok() + { + $this->config->set('test_key', 'test_value', false); + $this->assertSame($this->config['test_key'], 'test_value'); + + $command_tester = $this->get_command_tester('delete'); + $command_tester->execute(array( + 'command' => $this->command_name, + 'key' => 'test_key', + )); + + $this->assertContains('CLI_CONFIG_DELETE_SUCCESS', $command_tester->getDisplay()); + $this->assertEmpty($this->config); + } + + public function test_delete_error() + { + $this->assertEmpty($this->config); + + $command_tester = $this->get_command_tester('delete'); + $command_tester->execute(array( + 'command' => $this->command_name, + 'key' => 'wrong_key', + )); + + $this->assertContains('CLI_CONFIG_NOT_EXISTS', $command_tester->getDisplay()); + $this->assertEmpty($this->config); + } + + public function get_command_tester($class_name) + { + $command_complete_name = '\phpbb\console\command\config' . '\\' . $class_name; + $application = new Application(); + $application->add(new $command_complete_name($this->user, $this->config)); + $command = $application->find('config:' . $this->command_name); + $this->command_name = $command->getName(); + return new CommandTester($command); + } +} diff --git a/tests/console/cron/cron_list_test.php b/tests/console/cron/cron_list_test.php index 1059a3f221..22423304be 100644 --- a/tests/console/cron/cron_list_test.php +++ b/tests/console/cron/cron_list_test.php @@ -32,7 +32,7 @@ class phpbb_console_command_cron_list_test extends phpbb_test_case protected function setUp() { - $this->user = $this->getMock('\phpbb\user'); + $this->user = $this->getMock('\phpbb\user', array(), array('\phpbb\datetime')); $this->user->method('lang')->will($this->returnArgument(0)); } diff --git a/tests/console/cron/run_test.php b/tests/console/cron/run_test.php index 60bd74e1f0..029dc5249b 100644 --- a/tests/console/cron/run_test.php +++ b/tests/console/cron/run_test.php @@ -41,7 +41,7 @@ class phpbb_console_command_cron_run_test extends phpbb_database_test_case set_config(null, null, null, $this->config); $this->lock = new \phpbb\lock\db('cron_lock', $this->config, $this->db); - $this->user = $this->getMock('\phpbb\user'); + $this->user = $this->getMock('\phpbb\user', array(), array('\phpbb\datetime')); $this->user->method('lang')->will($this->returnArgument(0)); $this->task = new phpbb_cron_task_simple(); diff --git a/tests/content_visibility/delete_post_test.php b/tests/content_visibility/delete_post_test.php index aa705c52a5..65dda3ce48 100644 --- a/tests/content_visibility/delete_post_test.php +++ b/tests/content_visibility/delete_post_test.php @@ -67,6 +67,9 @@ class phpbb_content_visibility_delete_post_test extends phpbb_database_test_case array( array('forum_posts_approved' => 2, 'forum_posts_unapproved' => 0, 'forum_posts_softdeleted' => 0, 'forum_topics_approved' => 1, 'forum_topics_unapproved' => 0, 'forum_topics_softdeleted' => 0, 'forum_last_post_id' => 3), ), + array( + array('user_posts' => 3), + ), ), array( 1, 1, 1, @@ -93,6 +96,9 @@ class phpbb_content_visibility_delete_post_test extends phpbb_database_test_case array( array('forum_posts_approved' => 2, 'forum_posts_unapproved' => 0, 'forum_posts_softdeleted' => 0, 'forum_topics_approved' => 1, 'forum_topics_unapproved' => 0, 'forum_topics_softdeleted' => 0, 'forum_last_post_id' => 3), ), + array( + array('user_posts' => 3), + ), ), array( 1, 1, 3, @@ -119,6 +125,9 @@ class phpbb_content_visibility_delete_post_test extends phpbb_database_test_case array( array('forum_posts_approved' => 2, 'forum_posts_unapproved' => 0, 'forum_posts_softdeleted' => 0, 'forum_topics_approved' => 1, 'forum_topics_unapproved' => 0, 'forum_topics_softdeleted' => 0, 'forum_last_post_id' => 2), ), + array( + array('user_posts' => 3), + ), ), array( 1, 1, 2, @@ -145,6 +154,9 @@ class phpbb_content_visibility_delete_post_test extends phpbb_database_test_case array( array('forum_posts_approved' => 2, 'forum_posts_unapproved' => 0, 'forum_posts_softdeleted' => 1, 'forum_topics_approved' => 1, 'forum_topics_unapproved' => 0, 'forum_topics_softdeleted' => 0, 'forum_last_post_id' => 3), ), + array( + array('user_posts' => 3), + ), ), array( 1, 1, 1, @@ -171,6 +183,9 @@ class phpbb_content_visibility_delete_post_test extends phpbb_database_test_case array( array('forum_posts_approved' => 2, 'forum_posts_unapproved' => 0, 'forum_posts_softdeleted' => 1, 'forum_topics_approved' => 1, 'forum_topics_unapproved' => 0, 'forum_topics_softdeleted' => 0, 'forum_last_post_id' => 3), ), + array( + array('user_posts' => 3), + ), ), array( 1, 1, 3, @@ -197,6 +212,9 @@ class phpbb_content_visibility_delete_post_test extends phpbb_database_test_case array( array('forum_posts_approved' => 2, 'forum_posts_unapproved' => 0, 'forum_posts_softdeleted' => 1, 'forum_topics_approved' => 1, 'forum_topics_unapproved' => 0, 'forum_topics_softdeleted' => 0, 'forum_last_post_id' => 2), ), + array( + array('user_posts' => 3), + ), ), array( @@ -222,6 +240,9 @@ class phpbb_content_visibility_delete_post_test extends phpbb_database_test_case array( array('forum_posts_approved' => 0, 'forum_posts_unapproved' => 0, 'forum_posts_softdeleted' => 0, 'forum_topics_approved' => 0, 'forum_topics_unapproved' => 0, 'forum_topics_softdeleted' => 0, 'forum_last_post_id' => 0), ), + array( + array('user_posts' => 3), + ), ), array( @@ -257,6 +278,9 @@ class phpbb_content_visibility_delete_post_test extends phpbb_database_test_case array( array('forum_posts_approved' => 0, 'forum_posts_unapproved' => 0, 'forum_posts_softdeleted' => 1, 'forum_topics_approved' => 0, 'forum_topics_unapproved' => 0, 'forum_topics_softdeleted' => 1, 'forum_last_post_id' => 0), ), + array( + array('user_posts' => 3), + ), ), ); } @@ -264,7 +288,7 @@ class phpbb_content_visibility_delete_post_test extends phpbb_database_test_case /** * @dataProvider delete_post_data */ - public function test_delete_post($forum_id, $topic_id, $post_id, $data, $is_soft, $reason, $expected_posts, $expected_topic, $expected_forum) + public function test_delete_post($forum_id, $topic_id, $post_id, $data, $is_soft, $reason, $expected_posts, $expected_topic, $expected_forum, $expected_user) { global $auth, $cache, $config, $db, $phpbb_container, $phpbb_dispatcher, $phpbb_root_path, $phpEx; @@ -282,7 +306,7 @@ class phpbb_content_visibility_delete_post_test extends phpbb_database_test_case ->will($this->returnValueMap(array( array('m_approve', 1, true), ))); - $user = $this->getMock('\phpbb\user'); + $user = new \phpbb\user('\phpbb\datetime'); $phpbb_dispatcher = new phpbb_mock_event_dispatcher(); @@ -313,5 +337,13 @@ class phpbb_content_visibility_delete_post_test extends phpbb_database_test_case $this->assertEquals($expected_forum, $db->sql_fetchrowset($result)); $db->sql_freeresult($result); + + $sql = 'SELECT user_posts + FROM ' . USERS_TABLE . ' + WHERE user_id = ' . (int) $data['poster_id']; + $result = $db->sql_query($sql); + + $this->assertEquals($expected_user, $db->sql_fetchrowset($result)); + $db->sql_freeresult($result); } } diff --git a/tests/content_visibility/get_forums_visibility_sql_test.php b/tests/content_visibility/get_forums_visibility_sql_test.php index 7e4ce6577d..fe7ab36436 100644 --- a/tests/content_visibility/get_forums_visibility_sql_test.php +++ b/tests/content_visibility/get_forums_visibility_sql_test.php @@ -134,7 +134,7 @@ class phpbb_content_visibility_get_forums_visibility_sql_test extends phpbb_data ->method('acl_getf') ->with($this->stringContains('_'), $this->anything()) ->will($this->returnValueMap($permissions)); - $user = $this->getMock('\phpbb\user'); + $user = new \phpbb\user('\phpbb\datetime'); $config = new phpbb\config\config(array()); $content_visibility = new \phpbb\content_visibility($auth, $config, $db, $user, $phpbb_root_path, $phpEx, FORUMS_TABLE, POSTS_TABLE, TOPICS_TABLE, USERS_TABLE); diff --git a/tests/content_visibility/get_global_visibility_sql_test.php b/tests/content_visibility/get_global_visibility_sql_test.php index 082e0d76ab..43a80c792b 100644 --- a/tests/content_visibility/get_global_visibility_sql_test.php +++ b/tests/content_visibility/get_global_visibility_sql_test.php @@ -134,7 +134,7 @@ class phpbb_content_visibility_get_global_visibility_sql_test extends phpbb_data ->method('acl_getf') ->with($this->stringContains('_'), $this->anything()) ->will($this->returnValueMap($permissions)); - $user = $this->getMock('\phpbb\user'); + $user = new \phpbb\user('\phpbb\datetime'); $config = new phpbb\config\config(array()); $content_visibility = new \phpbb\content_visibility($auth, $config, $db, $user, $phpbb_root_path, $phpEx, FORUMS_TABLE, POSTS_TABLE, TOPICS_TABLE, USERS_TABLE); diff --git a/tests/content_visibility/get_visibility_sql_test.php b/tests/content_visibility/get_visibility_sql_test.php index 2d4f24f1c6..f718e6c29a 100644 --- a/tests/content_visibility/get_visibility_sql_test.php +++ b/tests/content_visibility/get_visibility_sql_test.php @@ -81,7 +81,7 @@ class phpbb_content_visibility_get_visibility_sql_test extends phpbb_database_te ->method('acl_get') ->with($this->stringContains('_'), $this->anything()) ->will($this->returnValueMap($permissions)); - $user = $this->getMock('\phpbb\user'); + $user = new \phpbb\user('\phpbb\datetime'); $config = new phpbb\config\config(array()); $content_visibility = new \phpbb\content_visibility($auth, $config, $db, $user, $phpbb_root_path, $phpEx, FORUMS_TABLE, POSTS_TABLE, TOPICS_TABLE, USERS_TABLE); diff --git a/tests/content_visibility/set_post_visibility_test.php b/tests/content_visibility/set_post_visibility_test.php index a596b45714..ab79fbc2ee 100644 --- a/tests/content_visibility/set_post_visibility_test.php +++ b/tests/content_visibility/set_post_visibility_test.php @@ -124,7 +124,7 @@ class phpbb_content_visibility_set_post_visibility_test extends phpbb_database_t $cache = new phpbb_mock_cache; $db = $this->new_dbal(); $auth = $this->getMock('\phpbb\auth\auth'); - $user = $this->getMock('\phpbb\user'); + $user = new \phpbb\user('\phpbb\datetime'); $config = new phpbb\config\config(array()); $content_visibility = new \phpbb\content_visibility($auth, $config, $db, $user, $phpbb_root_path, $phpEx, FORUMS_TABLE, POSTS_TABLE, TOPICS_TABLE, USERS_TABLE); @@ -174,7 +174,7 @@ class phpbb_content_visibility_set_post_visibility_test extends phpbb_database_t $cache = new phpbb_mock_cache; $db = $this->new_dbal(); $auth = $this->getMock('\phpbb\auth\auth'); - $user = $this->getMock('\phpbb\user'); + $user = new \phpbb\user('\phpbb\datetime'); $config = new phpbb\config\config(array()); $content_visibility = new \phpbb\content_visibility($auth, $config, $db, $user, $phpbb_root_path, $phpEx, FORUMS_TABLE, POSTS_TABLE, TOPICS_TABLE, USERS_TABLE); diff --git a/tests/content_visibility/set_topic_visibility_test.php b/tests/content_visibility/set_topic_visibility_test.php index 230474428c..4d02a55490 100644 --- a/tests/content_visibility/set_topic_visibility_test.php +++ b/tests/content_visibility/set_topic_visibility_test.php @@ -88,7 +88,7 @@ class phpbb_content_visibility_set_topic_visibility_test extends phpbb_database_ $cache = new phpbb_mock_cache; $db = $this->new_dbal(); $auth = $this->getMock('\phpbb\auth\auth'); - $user = $this->getMock('\phpbb\user'); + $user = new \phpbb\user('\phpbb\datetime'); $config = new phpbb\config\config(array()); $content_visibility = new \phpbb\content_visibility($auth, $config, $db, $user, $phpbb_root_path, $phpEx, FORUMS_TABLE, POSTS_TABLE, TOPICS_TABLE, USERS_TABLE); diff --git a/tests/controller/common_helper_route.php b/tests/controller/common_helper_route.php new file mode 100644 index 0000000000..859832412d --- /dev/null +++ b/tests/controller/common_helper_route.php @@ -0,0 +1,416 @@ +<?php +/** +* +* This file is part of the phpBB Forum Software package. +* +* @copyright (c) phpBB Limited <https://www.phpbb.com> +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ + +require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php'; + +use Symfony\Component\Routing\Generator\UrlGeneratorInterface; + +abstract class phpbb_controller_common_helper_route extends phpbb_test_case +{ + protected $root_path; + + public function setUp() + { + global $phpbb_dispatcher, $phpbb_root_path, $phpEx; + + $this->extension_manager = new phpbb_mock_extension_manager( + dirname(__FILE__) . '/', + array( + 'vendor2/foo' => array( + 'ext_name' => 'vendor2/foo', + 'ext_active' => '1', + 'ext_path' => 'ext/vendor2/foo/', + ), + ) + ); + $this->generate_route_objects(); + $phpbb_dispatcher = new phpbb_mock_event_dispatcher; + $this->user = new \phpbb\user('\phpbb\datetime'); + + $this->config = new \phpbb\config\config(array('enable_mod_rewrite' => '0')); + $this->template = new phpbb\template\twig\twig($this->phpbb_path_helper, $this->config, $this->user, new \phpbb\template\context()); + } + + protected function get_phpbb_root_path() + { + return ''; + } + + protected function get_uri() + { + return '/app.php'; + } + + protected function get_script_name() + { + return 'app.php'; + } + + protected function path_to_app() + { + return ''; + } + + protected function generate_route_objects() + { + $request = new phpbb_mock_request(); + $request->overwrite('SCRIPT_NAME', $this->get_uri(), \phpbb\request\request_interface::SERVER); + $request->overwrite('SCRIPT_FILENAME', $this->get_script_name(), \phpbb\request\request_interface::SERVER); + $request->overwrite('REQUEST_URI', $this->get_uri(), \phpbb\request\request_interface::SERVER); + $request->overwrite('SERVER_NAME', 'localhost', \phpbb\request\request_interface::SERVER); + $request->overwrite('SERVER_PORT', '80', \phpbb\request\request_interface::SERVER); + + $this->symfony_request = new \phpbb\symfony_request( + $request + ); + $this->filesystem = new \phpbb\filesystem(); + $this->phpbb_path_helper = new \phpbb\path_helper( + $this->symfony_request, + $this->filesystem, + $this->getMock('\phpbb\request\request'), + $phpbb_root_path, + $phpEx + ); + + $finder = new \phpbb\finder( + new \phpbb\filesystem(), + dirname(__FILE__) . '/', + new phpbb_mock_cache() + ); + $finder->set_extensions(array_keys($this->extension_manager->all_enabled())); + $this->provider = new \phpbb\controller\provider(); + $this->provider->find_routing_files($finder); + $this->provider->find(dirname(__FILE__) . '/'); + // Set correct current phpBB root path + $this->root_path = $this->get_phpbb_root_path(); + } + + public function helper_url_data_no_rewrite() + { + return array( + array('controller2', array('t' => 1, 'f' => 2), true, false, '/' . $this->path_to_app() . 'app.php/foo/bar?t=1&f=2', 'parameters in params-argument as array'), + array('controller2', array('t' => 1, 'f' => 2), false, false, '/' . $this->path_to_app() . 'app.php/foo/bar?t=1&f=2', 'parameters in params-argument as array'), + array('controller3', array('p' => 3, 't' => 1, 'f' => 2), true, false, '/' . $this->path_to_app() . 'app.php/foo/bar/p-3?t=1&f=2', 'parameters in params-argument as array'), + array('controller3', array('p' => 3, 't' => 1, 'f' => 2), false, false, '/' . $this->path_to_app() . 'app.php/foo/bar/p-3?t=1&f=2', 'parameters in params-argument as array'), + + // Custom sid parameter + array('controller2', array('t' => 1, 'f' => 2), true, 'custom-sid', '/' . $this->path_to_app() . 'app.php/foo/bar?t=1&f=2&sid=custom-sid', 'params-argument (array) using session_id'), + array('controller2', array('t' => 1, 'f' => 2), false, 'custom-sid', '/' . $this->path_to_app() . 'app.php/foo/bar?t=1&f=2&sid=custom-sid', 'params-argument (array) using session_id'), + array('controller3', array('p' => 3, 't' => 1, 'f' => 2), true, 'custom-sid', '/' . $this->path_to_app() . 'app.php/foo/bar/p-3?t=1&f=2&sid=custom-sid', 'params-argument (array) using session_id'), + + // Testing anchors + array('controller2', array('t' => 1, 'f' => 2, '#' => 'anchor'), true, false, '/' . $this->path_to_app() . 'app.php/foo/bar?t=1&f=2#anchor', 'anchor in params-argument (array)'), + array('controller2', array('t' => 1, 'f' => 2, '#' => 'anchor'), false, false, '/' . $this->path_to_app() . 'app.php/foo/bar?t=1&f=2#anchor', 'anchor in params-argument (array)'), + array('controller3', array('p' => 3, 't' => 1, 'f' => 2, '#' => 'anchor'), true, false, '/' . $this->path_to_app() . 'app.php/foo/bar/p-3?t=1&f=2#anchor', 'anchor in params-argument (array)'), + + // Anchors and custom sid + array('controller2', array('t' => 1, 'f' => 2, '#' => 'anchor'), true, 'custom-sid', '/' . $this->path_to_app() . 'app.php/foo/bar?t=1&f=2&sid=custom-sid#anchor', 'anchor in params-argument (array) using session_id'), + array('controller2', array('t' => 1, 'f' => 2, '#' => 'anchor'), false, 'custom-sid', '/' . $this->path_to_app() . 'app.php/foo/bar?t=1&f=2&sid=custom-sid#anchor', 'anchor in params-argument (array) using session_id'), + array('controller3', array('p' => 3, 't' => 1, 'f' => 2, '#' => 'anchor'), true, 'custom-sid', '/' . $this->path_to_app() . 'app.php/foo/bar/p-3?t=1&f=2&sid=custom-sid#anchor', 'anchor in params-argument (array) using session_id'), + + // Empty parameters should not append the & or ? + array('controller2', array(), true, false, '/' . $this->path_to_app() . 'app.php/foo/bar', 'no params using empty array'), + array('controller2', array(), false, false, '/' . $this->path_to_app() . 'app.php/foo/bar', 'no params using empty array'), + array('controller3', array('p' => 3), true, false, '/' . $this->path_to_app() . 'app.php/foo/bar/p-3', 'no params using empty array'), + ); + } + + /** + * @dataProvider helper_url_data_no_rewrite() + */ + public function test_helper_url_no_rewrite($route, $params, $is_amp, $session_id, $expected, $description) + { + $this->helper = new phpbb_mock_controller_helper($this->template, $this->user, $this->config, $this->provider, $this->extension_manager, $this->symfony_request, $this->filesystem, $this->root_path, 'php', dirname(__FILE__) . '/'); + $this->assertEquals($expected, $this->helper->route($route, $params, $is_amp, $session_id)); + } + + public function helper_url_data_with_rewrite() + { + return array( + array('controller2', array('t' => 1, 'f' => 2), true, false, '/' . $this->path_to_app() . 'foo/bar?t=1&f=2', 'parameters in params-argument as array'), + array('controller2', array('t' => 1, 'f' => 2), false, false, '/' . $this->path_to_app() . 'foo/bar?t=1&f=2', 'parameters in params-argument as array'), + array('controller3', array('p' => 3, 't' => 1, 'f' => 2), true, false, '/' . $this->path_to_app() . 'foo/bar/p-3?t=1&f=2', 'parameters in params-argument as array'), + array('controller3', array('p' => 3, 't' => 1, 'f' => 2), false, false, '/' . $this->path_to_app() . 'foo/bar/p-3?t=1&f=2', 'parameters in params-argument as array'), + + // Custom sid parameter + array('controller2', array('t' => 1, 'f' => 2), true, 'custom-sid', '/' . $this->path_to_app() . 'foo/bar?t=1&f=2&sid=custom-sid', 'params-argument (array) using session_id'), + array('controller2', array('t' => 1, 'f' => 2), false, 'custom-sid', '/' . $this->path_to_app() . 'foo/bar?t=1&f=2&sid=custom-sid', 'params-argument (array) using session_id'), + array('controller3', array('p' => 3, 't' => 1, 'f' => 2), true, 'custom-sid', '/' . $this->path_to_app() . 'foo/bar/p-3?t=1&f=2&sid=custom-sid', 'params-argument (array) using session_id'), + + // Testing anchors + array('controller2', array('t' => 1, 'f' => 2, '#' => 'anchor'), true, false, '/' . $this->path_to_app() . 'foo/bar?t=1&f=2#anchor', 'anchor in params-argument (array)'), + array('controller2', array('t' => 1, 'f' => 2, '#' => 'anchor'), false, false, '/' . $this->path_to_app() . 'foo/bar?t=1&f=2#anchor', 'anchor in params-argument (array)'), + array('controller3', array('p' => 3, 't' => 1, 'f' => 2, '#' => 'anchor'), true, false, '/' . $this->path_to_app() . 'foo/bar/p-3?t=1&f=2#anchor', 'anchor in params-argument (array)'), + + // Anchors and custom sid + array('controller2', array('t' => 1, 'f' => 2, '#' => 'anchor'), true, 'custom-sid', '/' . $this->path_to_app() . 'foo/bar?t=1&f=2&sid=custom-sid#anchor', 'anchor in params-argument (array) using session_id'), + array('controller2', array('t' => 1, 'f' => 2, '#' => 'anchor'), false, 'custom-sid', '/' . $this->path_to_app() . 'foo/bar?t=1&f=2&sid=custom-sid#anchor', 'anchor in params-argument (array) using session_id'), + array('controller3', array('p' => 3, 't' => 1, 'f' => 2, '#' => 'anchor'), true, 'custom-sid', '/' . $this->path_to_app() . 'foo/bar/p-3?t=1&f=2&sid=custom-sid#anchor', 'anchor in params-argument (array) using session_id'), + + // Empty parameters should not append the & or ? + array('controller2', array(), true, false, '/' . $this->path_to_app() . 'foo/bar', 'no params using empty array'), + array('controller2', array(), false, false, '/' . $this->path_to_app() . 'foo/bar', 'no params using empty array'), + array('controller3', array('p' => 3), true, false, '/' . $this->path_to_app() . 'foo/bar/p-3', 'no params using empty array'), + ); + } + + /** + * @dataProvider helper_url_data_with_rewrite() + */ + public function test_helper_url_with_rewrite($route, $params, $is_amp, $session_id, $expected, $description) + { + $this->config = new \phpbb\config\config(array('enable_mod_rewrite' => '1')); + $this->helper = new phpbb_mock_controller_helper($this->template, $this->user, $this->config, $this->provider, $this->extension_manager, $this->symfony_request, $this->filesystem, $this->root_path, 'php', dirname(__FILE__) . '/'); + $this->assertEquals($expected, $this->helper->route($route, $params, $is_amp, $session_id)); + } + + public function helper_url_data_absolute() + { + return array( + array('controller2', array('t' => 1, 'f' => 2), true, false, 'http://localhost/' . $this->path_to_app() . 'app.php/foo/bar?t=1&f=2', 'parameters in params-argument as array'), + array('controller2', array('t' => 1, 'f' => 2), false, false, 'http://localhost/' . $this->path_to_app() . 'app.php/foo/bar?t=1&f=2', 'parameters in params-argument as array'), + array('controller3', array('p' => 3, 't' => 1, 'f' => 2), true, false, 'http://localhost/' . $this->path_to_app() . 'app.php/foo/bar/p-3?t=1&f=2', 'parameters in params-argument as array'), + array('controller3', array('p' => 3, 't' => 1, 'f' => 2), false, false, 'http://localhost/' . $this->path_to_app() . 'app.php/foo/bar/p-3?t=1&f=2', 'parameters in params-argument as array'), + + // Custom sid parameter + array('controller2', array('t' => 1, 'f' => 2), true, 'custom-sid', 'http://localhost/' . $this->path_to_app() . 'app.php/foo/bar?t=1&f=2&sid=custom-sid', 'params-argument (array) using session_id'), + array('controller2', array('t' => 1, 'f' => 2), false, 'custom-sid', 'http://localhost/' . $this->path_to_app() . 'app.php/foo/bar?t=1&f=2&sid=custom-sid', 'params-argument (array) using session_id'), + array('controller3', array('p' => 3, 't' => 1, 'f' => 2), true, 'custom-sid', 'http://localhost/' . $this->path_to_app() . 'app.php/foo/bar/p-3?t=1&f=2&sid=custom-sid', 'params-argument (array) using session_id'), + + // Testing anchors + array('controller2', array('t' => 1, 'f' => 2, '#' => 'anchor'), true, false, 'http://localhost/' . $this->path_to_app() . 'app.php/foo/bar?t=1&f=2#anchor', 'anchor in params-argument (array)'), + array('controller2', array('t' => 1, 'f' => 2, '#' => 'anchor'), false, false, 'http://localhost/' . $this->path_to_app() . 'app.php/foo/bar?t=1&f=2#anchor', 'anchor in params-argument (array)'), + array('controller3', array('p' => 3, 't' => 1, 'f' => 2, '#' => 'anchor'), true, false, 'http://localhost/' . $this->path_to_app() . 'app.php/foo/bar/p-3?t=1&f=2#anchor', 'anchor in params-argument (array)'), + + // Anchors and custom sid + array('controller2', array('t' => 1, 'f' => 2, '#' => 'anchor'), true, 'custom-sid', 'http://localhost/' . $this->path_to_app() . 'app.php/foo/bar?t=1&f=2&sid=custom-sid#anchor', 'anchor in params-argument (array) using session_id'), + array('controller2', array('t' => 1, 'f' => 2, '#' => 'anchor'), false, 'custom-sid', 'http://localhost/' . $this->path_to_app() . 'app.php/foo/bar?t=1&f=2&sid=custom-sid#anchor', 'anchor in params-argument (array) using session_id'), + array('controller3', array('p' => 3, 't' => 1, 'f' => 2, '#' => 'anchor'), true, 'custom-sid', 'http://localhost/' . $this->path_to_app() . 'app.php/foo/bar/p-3?t=1&f=2&sid=custom-sid#anchor', 'anchor in params-argument (array) using session_id'), + + // Empty parameters should not append the & or ? + array('controller2', array(), true, false, 'http://localhost/' . $this->path_to_app() . 'app.php/foo/bar', 'no params using empty array'), + array('controller2', array(), false, false, 'http://localhost/' . $this->path_to_app() . 'app.php/foo/bar', 'no params using empty array'), + array('controller3', array('p' => 3), true, false, 'http://localhost/' . $this->path_to_app() . 'app.php/foo/bar/p-3', 'no params using empty array'), + ); + } + + /** + * @dataProvider helper_url_data_absolute() + */ + public function test_helper_url_absolute($route, $params, $is_amp, $session_id, $expected, $description) + { + $this->config = new \phpbb\config\config(array('enable_mod_rewrite' => '0')); + $this->helper = new phpbb_mock_controller_helper($this->template, $this->user, $this->config, $this->provider, $this->extension_manager, $this->symfony_request, $this->filesystem, $this->root_path, 'php', dirname(__FILE__) . '/'); + $this->assertEquals($expected, $this->helper->route($route, $params, $is_amp, $session_id, UrlGeneratorInterface::ABSOLUTE_URL)); + } + + public function helper_url_data_relative_path() + { + return array( + array('controller2', array('t' => 1, 'f' => 2), true, false, 'app.php/foo/bar?t=1&f=2', 'parameters in params-argument as array'), + array('controller2', array('t' => 1, 'f' => 2), false, false, 'app.php/foo/bar?t=1&f=2', 'parameters in params-argument as array'), + array('controller3', array('p' => 3, 't' => 1, 'f' => 2), true, false, 'app.php/foo/bar/p-3?t=1&f=2', 'parameters in params-argument as array'), + array('controller3', array('p' => 3, 't' => 1, 'f' => 2), false, false, 'app.php/foo/bar/p-3?t=1&f=2', 'parameters in params-argument as array'), + + // Custom sid parameter + array('controller2', array('t' => 1, 'f' => 2), true, 'custom-sid', 'app.php/foo/bar?t=1&f=2&sid=custom-sid', 'params-argument (array) using session_id'), + array('controller2', array('t' => 1, 'f' => 2), false, 'custom-sid', 'app.php/foo/bar?t=1&f=2&sid=custom-sid', 'params-argument (array) using session_id'), + array('controller3', array('p' => 3, 't' => 1, 'f' => 2), true, 'custom-sid', 'app.php/foo/bar/p-3?t=1&f=2&sid=custom-sid', 'params-argument (array) using session_id'), + + // Testing anchors + array('controller2', array('t' => 1, 'f' => 2, '#' => 'anchor'), true, false, 'app.php/foo/bar?t=1&f=2#anchor', 'anchor in params-argument (array)'), + array('controller2', array('t' => 1, 'f' => 2, '#' => 'anchor'), false, false, 'app.php/foo/bar?t=1&f=2#anchor', 'anchor in params-argument (array)'), + array('controller3', array('p' => 3, 't' => 1, 'f' => 2, '#' => 'anchor'), true, false, 'app.php/foo/bar/p-3?t=1&f=2#anchor', 'anchor in params-argument (array)'), + + // Anchors and custom sid + array('controller2', array('t' => 1, 'f' => 2, '#' => 'anchor'), true, 'custom-sid', 'app.php/foo/bar?t=1&f=2&sid=custom-sid#anchor', 'anchor in params-argument (array) using session_id'), + array('controller2', array('t' => 1, 'f' => 2, '#' => 'anchor'), false, 'custom-sid', 'app.php/foo/bar?t=1&f=2&sid=custom-sid#anchor', 'anchor in params-argument (array) using session_id'), + array('controller3', array('p' => 3, 't' => 1, 'f' => 2, '#' => 'anchor'), true, 'custom-sid', 'app.php/foo/bar/p-3?t=1&f=2&sid=custom-sid#anchor', 'anchor in params-argument (array) using session_id'), + + // Empty parameters should not append the & or ? + array('controller2', array(), true, false, 'app.php/foo/bar', 'no params using empty array'), + array('controller2', array(), false, false, 'app.php/foo/bar', 'no params using empty array'), + array('controller3', array('p' => 3), true, false, 'app.php/foo/bar/p-3', 'no params using empty array'), + ); + } + + /** + * @dataProvider helper_url_data_relative_path() + */ + public function test_helper_url_relative_path($route, $params, $is_amp, $session_id, $expected, $description) + { + $this->config = new \phpbb\config\config(array('enable_mod_rewrite' => '0')); + $this->helper = new phpbb_mock_controller_helper($this->template, $this->user, $this->config, $this->provider, $this->extension_manager, $this->symfony_request, $this->filesystem, $this->root_path, 'php', dirname(__FILE__) . '/'); + $this->assertEquals($expected, $this->helper->route($route, $params, $is_amp, $session_id, UrlGeneratorInterface::RELATIVE_PATH)); + } + + public function helper_url_data_network() + { + return array( + array('controller2', array('t' => 1, 'f' => 2), true, false, '//localhost/' . $this->path_to_app() . 'app.php/foo/bar?t=1&f=2', 'parameters in params-argument as array'), + array('controller2', array('t' => 1, 'f' => 2), false, false, '//localhost/' . $this->path_to_app() . 'app.php/foo/bar?t=1&f=2', 'parameters in params-argument as array'), + array('controller3', array('p' => 3, 't' => 1, 'f' => 2), true, false, '//localhost/' . $this->path_to_app() . 'app.php/foo/bar/p-3?t=1&f=2', 'parameters in params-argument as array'), + array('controller3', array('p' => 3, 't' => 1, 'f' => 2), false, false, '//localhost/' . $this->path_to_app() . 'app.php/foo/bar/p-3?t=1&f=2', 'parameters in params-argument as array'), + + // Custom sid parameter + array('controller2', array('t' => 1, 'f' => 2), true, 'custom-sid', '//localhost/' . $this->path_to_app() . 'app.php/foo/bar?t=1&f=2&sid=custom-sid', 'params-argument (array) using session_id'), + array('controller2', array('t' => 1, 'f' => 2), false, 'custom-sid', '//localhost/' . $this->path_to_app() . 'app.php/foo/bar?t=1&f=2&sid=custom-sid', 'params-argument (array) using session_id'), + array('controller3', array('p' => 3, 't' => 1, 'f' => 2), true, 'custom-sid', '//localhost/' . $this->path_to_app() . 'app.php/foo/bar/p-3?t=1&f=2&sid=custom-sid', 'params-argument (array) using session_id'), + + // Testing anchors + array('controller2', array('t' => 1, 'f' => 2, '#' => 'anchor'), true, false, '//localhost/' . $this->path_to_app() . 'app.php/foo/bar?t=1&f=2#anchor', 'anchor in params-argument (array)'), + array('controller2', array('t' => 1, 'f' => 2, '#' => 'anchor'), false, false, '//localhost/' . $this->path_to_app() . 'app.php/foo/bar?t=1&f=2#anchor', 'anchor in params-argument (array)'), + array('controller3', array('p' => 3, 't' => 1, 'f' => 2, '#' => 'anchor'), true, false, '//localhost/' . $this->path_to_app() . 'app.php/foo/bar/p-3?t=1&f=2#anchor', 'anchor in params-argument (array)'), + + // Anchors and custom sid + array('controller2', array('t' => 1, 'f' => 2, '#' => 'anchor'), true, 'custom-sid', '//localhost/' . $this->path_to_app() . 'app.php/foo/bar?t=1&f=2&sid=custom-sid#anchor', 'anchor in params-argument (array) using session_id'), + array('controller2', array('t' => 1, 'f' => 2, '#' => 'anchor'), false, 'custom-sid', '//localhost/' . $this->path_to_app() . 'app.php/foo/bar?t=1&f=2&sid=custom-sid#anchor', 'anchor in params-argument (array) using session_id'), + array('controller3', array('p' => 3, 't' => 1, 'f' => 2, '#' => 'anchor'), true, 'custom-sid', '//localhost/' . $this->path_to_app() . 'app.php/foo/bar/p-3?t=1&f=2&sid=custom-sid#anchor', 'anchor in params-argument (array) using session_id'), + + // Empty parameters should not append the & or ? + array('controller2', array(), true, false, '//localhost/' . $this->path_to_app() . 'app.php/foo/bar', 'no params using empty array'), + array('controller2', array(), false, false, '//localhost/' . $this->path_to_app() . 'app.php/foo/bar', 'no params using empty array'), + array('controller3', array('p' => 3), true, false, '//localhost/' . $this->path_to_app() . 'app.php/foo/bar/p-3', 'no params using empty array'), + ); + } + + /** + * @dataProvider helper_url_data_network() + */ + public function test_helper_url_network($route, $params, $is_amp, $session_id, $expected, $description) + { + $this->config = new \phpbb\config\config(array('enable_mod_rewrite' => '0')); + $this->helper = new phpbb_mock_controller_helper($this->template, $this->user, $this->config, $this->provider, $this->extension_manager, $this->symfony_request, $this->filesystem, $this->root_path, 'php', dirname(__FILE__) . '/'); + $this->assertEquals($expected, $this->helper->route($route, $params, $is_amp, $session_id, UrlGeneratorInterface::NETWORK_PATH)); + } +//TODO + public function helper_url_data_absolute_with_rewrite() + { + return array( + array('controller2', array('t' => 1, 'f' => 2), true, false, 'http://localhost/' . $this->path_to_app() . 'foo/bar?t=1&f=2', 'parameters in params-argument as array'), + array('controller2', array('t' => 1, 'f' => 2), false, false, 'http://localhost/' . $this->path_to_app() . 'foo/bar?t=1&f=2', 'parameters in params-argument as array'), + array('controller3', array('p' => 3, 't' => 1, 'f' => 2), true, false, 'http://localhost/' . $this->path_to_app() . 'foo/bar/p-3?t=1&f=2', 'parameters in params-argument as array'), + array('controller3', array('p' => 3, 't' => 1, 'f' => 2), false, false, 'http://localhost/' . $this->path_to_app() . 'foo/bar/p-3?t=1&f=2', 'parameters in params-argument as array'), + + // Custom sid parameter + array('controller2', array('t' => 1, 'f' => 2), true, 'custom-sid', 'http://localhost/' . $this->path_to_app() . 'foo/bar?t=1&f=2&sid=custom-sid', 'params-argument (array) using session_id'), + array('controller2', array('t' => 1, 'f' => 2), false, 'custom-sid', 'http://localhost/' . $this->path_to_app() . 'foo/bar?t=1&f=2&sid=custom-sid', 'params-argument (array) using session_id'), + array('controller3', array('p' => 3, 't' => 1, 'f' => 2), true, 'custom-sid', 'http://localhost/' . $this->path_to_app() . 'foo/bar/p-3?t=1&f=2&sid=custom-sid', 'params-argument (array) using session_id'), + + // Testing anchors + array('controller2', array('t' => 1, 'f' => 2, '#' => 'anchor'), true, false, 'http://localhost/' . $this->path_to_app() . 'foo/bar?t=1&f=2#anchor', 'anchor in params-argument (array)'), + array('controller2', array('t' => 1, 'f' => 2, '#' => 'anchor'), false, false, 'http://localhost/' . $this->path_to_app() . 'foo/bar?t=1&f=2#anchor', 'anchor in params-argument (array)'), + array('controller3', array('p' => 3, 't' => 1, 'f' => 2, '#' => 'anchor'), true, false, 'http://localhost/' . $this->path_to_app() . 'foo/bar/p-3?t=1&f=2#anchor', 'anchor in params-argument (array)'), + + // Anchors and custom sid + array('controller2', array('t' => 1, 'f' => 2, '#' => 'anchor'), true, 'custom-sid', 'http://localhost/' . $this->path_to_app() . 'foo/bar?t=1&f=2&sid=custom-sid#anchor', 'anchor in params-argument (array) using session_id'), + array('controller2', array('t' => 1, 'f' => 2, '#' => 'anchor'), false, 'custom-sid', 'http://localhost/' . $this->path_to_app() . 'foo/bar?t=1&f=2&sid=custom-sid#anchor', 'anchor in params-argument (array) using session_id'), + array('controller3', array('p' => 3, 't' => 1, 'f' => 2, '#' => 'anchor'), true, 'custom-sid', 'http://localhost/' . $this->path_to_app() . 'foo/bar/p-3?t=1&f=2&sid=custom-sid#anchor', 'anchor in params-argument (array) using session_id'), + + // Empty parameters should not append the & or ? + array('controller2', array(), true, false, 'http://localhost/' . $this->path_to_app() . 'foo/bar', 'no params using empty array'), + array('controller2', array(), false, false, 'http://localhost/' . $this->path_to_app() . 'foo/bar', 'no params using empty array'), + array('controller3', array('p' => 3), true, false, 'http://localhost/' . $this->path_to_app() . 'foo/bar/p-3', 'no params using empty array'), + ); + } + + /** + * @dataProvider helper_url_data_absolute_with_rewrite() + */ + public function test_helper_url_absolute_with_rewrite($route, $params, $is_amp, $session_id, $expected, $description) + { + $this->config = new \phpbb\config\config(array('enable_mod_rewrite' => '1')); + $this->helper = new phpbb_mock_controller_helper($this->template, $this->user, $this->config, $this->provider, $this->extension_manager, $this->symfony_request, $this->filesystem, $this->root_path, 'php', dirname(__FILE__) . '/'); + $this->assertEquals($expected, $this->helper->route($route, $params, $is_amp, $session_id, UrlGeneratorInterface::ABSOLUTE_URL)); + } + + public function helper_url_data_relative_path_with_rewrite() + { + return array( + array('controller2', array('t' => 1, 'f' => 2), true, false, 'foo/bar?t=1&f=2', 'parameters in params-argument as array'), + array('controller2', array('t' => 1, 'f' => 2), false, false, 'foo/bar?t=1&f=2', 'parameters in params-argument as array'), + array('controller3', array('p' => 3, 't' => 1, 'f' => 2), true, false, 'foo/bar/p-3?t=1&f=2', 'parameters in params-argument as array'), + array('controller3', array('p' => 3, 't' => 1, 'f' => 2), false, false, 'foo/bar/p-3?t=1&f=2', 'parameters in params-argument as array'), + + // Custom sid parameter + array('controller2', array('t' => 1, 'f' => 2), true, 'custom-sid', 'foo/bar?t=1&f=2&sid=custom-sid', 'params-argument (array) using session_id'), + array('controller2', array('t' => 1, 'f' => 2), false, 'custom-sid', 'foo/bar?t=1&f=2&sid=custom-sid', 'params-argument (array) using session_id'), + array('controller3', array('p' => 3, 't' => 1, 'f' => 2), true, 'custom-sid', 'foo/bar/p-3?t=1&f=2&sid=custom-sid', 'params-argument (array) using session_id'), + + // Testing anchors + array('controller2', array('t' => 1, 'f' => 2, '#' => 'anchor'), true, false, 'foo/bar?t=1&f=2#anchor', 'anchor in params-argument (array)'), + array('controller2', array('t' => 1, 'f' => 2, '#' => 'anchor'), false, false, 'foo/bar?t=1&f=2#anchor', 'anchor in params-argument (array)'), + array('controller3', array('p' => 3, 't' => 1, 'f' => 2, '#' => 'anchor'), true, false, 'foo/bar/p-3?t=1&f=2#anchor', 'anchor in params-argument (array)'), + + // Anchors and custom sid + array('controller2', array('t' => 1, 'f' => 2, '#' => 'anchor'), true, 'custom-sid', 'foo/bar?t=1&f=2&sid=custom-sid#anchor', 'anchor in params-argument (array) using session_id'), + array('controller2', array('t' => 1, 'f' => 2, '#' => 'anchor'), false, 'custom-sid', 'foo/bar?t=1&f=2&sid=custom-sid#anchor', 'anchor in params-argument (array) using session_id'), + array('controller3', array('p' => 3, 't' => 1, 'f' => 2, '#' => 'anchor'), true, 'custom-sid', 'foo/bar/p-3?t=1&f=2&sid=custom-sid#anchor', 'anchor in params-argument (array) using session_id'), + + // Empty parameters should not append the & or ? + array('controller2', array(), true, false, 'foo/bar', 'no params using empty array'), + array('controller2', array(), false, false, 'foo/bar', 'no params using empty array'), + array('controller3', array('p' => 3), true, false, 'foo/bar/p-3', 'no params using empty array'), + ); + } + + /** + * @dataProvider helper_url_data_relative_path_with_rewrite() + */ + public function test_helper_url_relative_path_with_rewrite($route, $params, $is_amp, $session_id, $expected, $description) + { + $this->config = new \phpbb\config\config(array('enable_mod_rewrite' => '1')); + $this->helper = new phpbb_mock_controller_helper($this->template, $this->user, $this->config, $this->provider, $this->extension_manager, $this->symfony_request, $this->filesystem, $this->root_path, 'php', dirname(__FILE__) . '/'); + $this->assertEquals($expected, $this->helper->route($route, $params, $is_amp, $session_id, UrlGeneratorInterface::RELATIVE_PATH)); + } + + public function helper_url_data_network_with_rewrite() + { + return array( + array('controller2', array('t' => 1, 'f' => 2), true, false, '//localhost/' . $this->path_to_app() . 'foo/bar?t=1&f=2', 'parameters in params-argument as array'), + array('controller2', array('t' => 1, 'f' => 2), false, false, '//localhost/' . $this->path_to_app() . 'foo/bar?t=1&f=2', 'parameters in params-argument as array'), + array('controller3', array('p' => 3, 't' => 1, 'f' => 2), true, false, '//localhost/' . $this->path_to_app() . 'foo/bar/p-3?t=1&f=2', 'parameters in params-argument as array'), + array('controller3', array('p' => 3, 't' => 1, 'f' => 2), false, false, '//localhost/' . $this->path_to_app() . 'foo/bar/p-3?t=1&f=2', 'parameters in params-argument as array'), + + // Custom sid parameter + array('controller2', array('t' => 1, 'f' => 2), true, 'custom-sid', '//localhost/' . $this->path_to_app() . 'foo/bar?t=1&f=2&sid=custom-sid', 'params-argument (array) using session_id'), + array('controller2', array('t' => 1, 'f' => 2), false, 'custom-sid', '//localhost/' . $this->path_to_app() . 'foo/bar?t=1&f=2&sid=custom-sid', 'params-argument (array) using session_id'), + array('controller3', array('p' => 3, 't' => 1, 'f' => 2), true, 'custom-sid', '//localhost/' . $this->path_to_app() . 'foo/bar/p-3?t=1&f=2&sid=custom-sid', 'params-argument (array) using session_id'), + + // Testing anchors + array('controller2', array('t' => 1, 'f' => 2, '#' => 'anchor'), true, false, '//localhost/' . $this->path_to_app() . 'foo/bar?t=1&f=2#anchor', 'anchor in params-argument (array)'), + array('controller2', array('t' => 1, 'f' => 2, '#' => 'anchor'), false, false, '//localhost/' . $this->path_to_app() . 'foo/bar?t=1&f=2#anchor', 'anchor in params-argument (array)'), + array('controller3', array('p' => 3, 't' => 1, 'f' => 2, '#' => 'anchor'), true, false, '//localhost/' . $this->path_to_app() . 'foo/bar/p-3?t=1&f=2#anchor', 'anchor in params-argument (array)'), + + // Anchors and custom sid + array('controller2', array('t' => 1, 'f' => 2, '#' => 'anchor'), true, 'custom-sid', '//localhost/' . $this->path_to_app() . 'foo/bar?t=1&f=2&sid=custom-sid#anchor', 'anchor in params-argument (array) using session_id'), + array('controller2', array('t' => 1, 'f' => 2, '#' => 'anchor'), false, 'custom-sid', '//localhost/' . $this->path_to_app() . 'foo/bar?t=1&f=2&sid=custom-sid#anchor', 'anchor in params-argument (array) using session_id'), + array('controller3', array('p' => 3, 't' => 1, 'f' => 2, '#' => 'anchor'), true, 'custom-sid', '//localhost/' . $this->path_to_app() . 'foo/bar/p-3?t=1&f=2&sid=custom-sid#anchor', 'anchor in params-argument (array) using session_id'), + + // Empty parameters should not append the & or ? + array('controller2', array(), true, false, '//localhost/' . $this->path_to_app() . 'foo/bar', 'no params using empty array'), + array('controller2', array(), false, false, '//localhost/' . $this->path_to_app() . 'foo/bar', 'no params using empty array'), + array('controller3', array('p' => 3), true, false, '//localhost/' . $this->path_to_app() . 'foo/bar/p-3', 'no params using empty array'), + ); + } + + /** + * @dataProvider helper_url_data_network_with_rewrite() + */ + public function test_helper_url_network_with_rewrite($route, $params, $is_amp, $session_id, $expected, $description) + { + $this->config = new \phpbb\config\config(array('enable_mod_rewrite' => '1')); + $this->helper = new phpbb_mock_controller_helper($this->template, $this->user, $this->config, $this->provider, $this->extension_manager, $this->symfony_request, $this->filesystem, $this->root_path, 'php', dirname(__FILE__) . '/'); + $this->assertEquals($expected, $this->helper->route($route, $params, $is_amp, $session_id, UrlGeneratorInterface::NETWORK_PATH)); + } +} diff --git a/tests/controller/controller_test.php b/tests/controller/controller_test.php index 67faf83e29..58bcf0ef81 100644 --- a/tests/controller/controller_test.php +++ b/tests/controller/controller_test.php @@ -72,7 +72,7 @@ class phpbb_controller_controller_test extends phpbb_test_case include(__DIR__.'/phpbb/controller/foo.php'); } - $resolver = new \phpbb\controller\resolver(new \phpbb\user, $container, dirname(__FILE__) . '/'); + $resolver = new \phpbb\controller\resolver(new \phpbb\user('\phpbb\datetime'), $container, dirname(__FILE__) . '/'); $symfony_request = new Request(); $symfony_request->attributes->set('_controller', 'foo.controller:handle'); diff --git a/tests/controller/helper_route_adm_subdir_test.php b/tests/controller/helper_route_adm_subdir_test.php new file mode 100644 index 0000000000..f27ac81b04 --- /dev/null +++ b/tests/controller/helper_route_adm_subdir_test.php @@ -0,0 +1,33 @@ +<?php +/** +* +* This file is part of the phpBB Forum Software package. +* +* @copyright (c) phpBB Limited <https://www.phpbb.com> +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ + +require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php'; +require_once dirname(__FILE__) . '/common_helper_route.php'; + +class phpbb_controller_helper_route_adm_subdir_test extends phpbb_controller_common_helper_route +{ + protected function get_phpbb_root_path() + { + return './../../'; + } + + protected function get_uri() + { + return '/adm/subdir/index.php'; + } + + protected function get_script_name() + { + return 'index.php'; + } +} diff --git a/tests/controller/helper_route_adm_test.php b/tests/controller/helper_route_adm_test.php new file mode 100644 index 0000000000..86dc36ef1f --- /dev/null +++ b/tests/controller/helper_route_adm_test.php @@ -0,0 +1,33 @@ +<?php +/** +* +* This file is part of the phpBB Forum Software package. +* +* @copyright (c) phpBB Limited <https://www.phpbb.com> +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ + +require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php'; +require_once dirname(__FILE__) . '/common_helper_route.php'; + +class phpbb_controller_helper_route_adm_test extends phpbb_controller_common_helper_route +{ + protected function get_phpbb_root_path() + { + return './../'; + } + + protected function get_uri() + { + return '/adm/index.php'; + } + + protected function get_script_name() + { + return 'index.php'; + } +} diff --git a/tests/controller/helper_route_other_app.php b/tests/controller/helper_route_other_app.php new file mode 100644 index 0000000000..e5513a5180 --- /dev/null +++ b/tests/controller/helper_route_other_app.php @@ -0,0 +1,37 @@ +<?php +/** +* +* This file is part of the phpBB Forum Software package. +* +* @copyright (c) phpBB Limited <https://www.phpbb.com> +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ + +require_once dirname(__FILE__) . '/common_helper_route.php'; + +class phpbb_controller_helper_route_other_app_test extends phpbb_controller_common_helper_route +{ + protected function get_phpbb_root_path() + { + return './../'; + } + + protected function get_uri() + { + return '/foo/app.php'; + } + + protected function get_script_name() + { + return 'app.php'; + } + + protected function path_to_app() + { + return 'foo/'; + } +} diff --git a/tests/controller/helper_route_root_test.php b/tests/controller/helper_route_root_test.php new file mode 100644 index 0000000000..63a2f2f8f7 --- /dev/null +++ b/tests/controller/helper_route_root_test.php @@ -0,0 +1,33 @@ +<?php +/** +* +* This file is part of the phpBB Forum Software package. +* +* @copyright (c) phpBB Limited <https://www.phpbb.com> +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ + +require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php'; +require_once dirname(__FILE__) . '/common_helper_route.php'; + +class phpbb_controller_helper_route_test extends phpbb_controller_common_helper_route +{ + protected function get_phpbb_root_path() + { + return ''; + } + + protected function get_uri() + { + return '/app.php'; + } + + protected function get_script_name() + { + return 'app.php'; + } +} diff --git a/tests/controller/helper_route_test.php b/tests/controller/helper_route_test.php deleted file mode 100644 index 206c3a4f0b..0000000000 --- a/tests/controller/helper_route_test.php +++ /dev/null @@ -1,135 +0,0 @@ -<?php -/** -* -* This file is part of the phpBB Forum Software package. -* -* @copyright (c) phpBB Limited <https://www.phpbb.com> -* @license GNU General Public License, version 2 (GPL-2.0) -* -* For full copyright and license information, please see -* the docs/CREDITS.txt file. -* -*/ - -require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php'; - -class phpbb_controller_helper_route_test extends phpbb_test_case -{ - public function setUp() - { - global $phpbb_dispatcher, $phpbb_root_path, $phpEx; - - $phpbb_dispatcher = new phpbb_mock_event_dispatcher; - $this->user = $this->getMock('\phpbb\user'); - $phpbb_path_helper = new \phpbb\path_helper( - new \phpbb\symfony_request( - new phpbb_mock_request() - ), - new \phpbb\filesystem(), - $this->getMock('\phpbb\request\request'), - $phpbb_root_path, - $phpEx - ); - $this->config = new \phpbb\config\config(array('enable_mod_rewrite' => '0')); - $this->template = new phpbb\template\twig\twig($phpbb_path_helper, $this->config, $this->user, new \phpbb\template\context()); - $this->extension_manager = new phpbb_mock_extension_manager( - dirname(__FILE__) . '/', - array( - 'vendor2/foo' => array( - 'ext_name' => 'vendor2/foo', - 'ext_active' => '1', - 'ext_path' => 'ext/vendor2/foo/', - ), - ) - ); - - $finder = new \phpbb\finder( - new \phpbb\filesystem(), - dirname(__FILE__) . '/', - new phpbb_mock_cache() - ); - $finder->set_extensions(array_keys($this->extension_manager->all_enabled())); - $this->provider = new \phpbb\controller\provider(); - $this->provider->find_routing_files($finder); - $this->provider->find(dirname(__FILE__) . '/'); - } - - public function helper_url_data_no_rewrite() - { - return array( - array('controller2', array('t' => 1, 'f' => 2), true, false, 'app.php/foo/bar?t=1&f=2', 'parameters in params-argument as array'), - array('controller2', array('t' => 1, 'f' => 2), false, false, 'app.php/foo/bar?t=1&f=2', 'parameters in params-argument as array'), - array('controller3', array('p' => 3, 't' => 1, 'f' => 2), true, false, 'app.php/foo/bar/p-3?t=1&f=2', 'parameters in params-argument as array'), - array('controller3', array('p' => 3, 't' => 1, 'f' => 2), false, false, 'app.php/foo/bar/p-3?t=1&f=2', 'parameters in params-argument as array'), - - // Custom sid parameter - array('controller2', array('t' => 1, 'f' => 2), true, 'custom-sid', 'app.php/foo/bar?t=1&f=2&sid=custom-sid', 'params-argument (array) using session_id'), - array('controller2', array('t' => 1, 'f' => 2), false, 'custom-sid', 'app.php/foo/bar?t=1&f=2&sid=custom-sid', 'params-argument (array) using session_id'), - array('controller3', array('p' => 3, 't' => 1, 'f' => 2), true, 'custom-sid', 'app.php/foo/bar/p-3?t=1&f=2&sid=custom-sid', 'params-argument (array) using session_id'), - - // Testing anchors - array('controller2', array('t' => 1, 'f' => 2, '#' => 'anchor'), true, false, 'app.php/foo/bar?t=1&f=2#anchor', 'anchor in params-argument (array)'), - array('controller2', array('t' => 1, 'f' => 2, '#' => 'anchor'), false, false, 'app.php/foo/bar?t=1&f=2#anchor', 'anchor in params-argument (array)'), - array('controller3', array('p' => 3, 't' => 1, 'f' => 2, '#' => 'anchor'), true, false, 'app.php/foo/bar/p-3?t=1&f=2#anchor', 'anchor in params-argument (array)'), - - // Anchors and custom sid - array('controller2', array('t' => 1, 'f' => 2, '#' => 'anchor'), true, 'custom-sid', 'app.php/foo/bar?t=1&f=2&sid=custom-sid#anchor', 'anchor in params-argument (array) using session_id'), - array('controller2', array('t' => 1, 'f' => 2, '#' => 'anchor'), false, 'custom-sid', 'app.php/foo/bar?t=1&f=2&sid=custom-sid#anchor', 'anchor in params-argument (array) using session_id'), - array('controller3', array('p' => 3, 't' => 1, 'f' => 2, '#' => 'anchor'), true, 'custom-sid', 'app.php/foo/bar/p-3?t=1&f=2&sid=custom-sid#anchor', 'anchor in params-argument (array) using session_id'), - - // Empty parameters should not append the & or ? - array('controller2', array(), true, false, 'app.php/foo/bar', 'no params using empty array'), - array('controller2', array(), false, false, 'app.php/foo/bar', 'no params using empty array'), - array('controller3', array('p' => 3), true, false, 'app.php/foo/bar/p-3', 'no params using empty array'), - ); - } - - /** - * @dataProvider helper_url_data_no_rewrite() - */ - public function test_helper_url_no_rewrite($route, $params, $is_amp, $session_id, $expected, $description) - { - $this->helper = new phpbb_mock_controller_helper($this->template, $this->user, $this->config, $this->provider, $this->extension_manager, '', 'php', dirname(__FILE__) . '/'); - $this->assertEquals($expected, $this->helper->route($route, $params, $is_amp, $session_id)); - } - - public function helper_url_data_with_rewrite() - { - return array( - array('controller2', array('t' => 1, 'f' => 2), true, false, 'foo/bar?t=1&f=2', 'parameters in params-argument as array'), - array('controller2', array('t' => 1, 'f' => 2), false, false, 'foo/bar?t=1&f=2', 'parameters in params-argument as array'), - array('controller3', array('p' => 3, 't' => 1, 'f' => 2), true, false, 'foo/bar/p-3?t=1&f=2', 'parameters in params-argument as array'), - array('controller3', array('p' => 3, 't' => 1, 'f' => 2), false, false, 'foo/bar/p-3?t=1&f=2', 'parameters in params-argument as array'), - - // Custom sid parameter - array('controller2', array('t' => 1, 'f' => 2), true, 'custom-sid', 'foo/bar?t=1&f=2&sid=custom-sid', 'params-argument (array) using session_id'), - array('controller2', array('t' => 1, 'f' => 2), false, 'custom-sid', 'foo/bar?t=1&f=2&sid=custom-sid', 'params-argument (array) using session_id'), - array('controller3', array('p' => 3, 't' => 1, 'f' => 2), true, 'custom-sid', 'foo/bar/p-3?t=1&f=2&sid=custom-sid', 'params-argument (array) using session_id'), - - // Testing anchors - array('controller2', array('t' => 1, 'f' => 2, '#' => 'anchor'), true, false, 'foo/bar?t=1&f=2#anchor', 'anchor in params-argument (array)'), - array('controller2', array('t' => 1, 'f' => 2, '#' => 'anchor'), false, false, 'foo/bar?t=1&f=2#anchor', 'anchor in params-argument (array)'), - array('controller3', array('p' => 3, 't' => 1, 'f' => 2, '#' => 'anchor'), true, false, 'foo/bar/p-3?t=1&f=2#anchor', 'anchor in params-argument (array)'), - - // Anchors and custom sid - array('controller2', array('t' => 1, 'f' => 2, '#' => 'anchor'), true, 'custom-sid', 'foo/bar?t=1&f=2&sid=custom-sid#anchor', 'anchor in params-argument (array) using session_id'), - array('controller2', array('t' => 1, 'f' => 2, '#' => 'anchor'), false, 'custom-sid', 'foo/bar?t=1&f=2&sid=custom-sid#anchor', 'anchor in params-argument (array) using session_id'), - array('controller3', array('p' => 3, 't' => 1, 'f' => 2, '#' => 'anchor'), true, 'custom-sid', 'foo/bar/p-3?t=1&f=2&sid=custom-sid#anchor', 'anchor in params-argument (array) using session_id'), - - // Empty parameters should not append the & or ? - array('controller2', array(), true, false, 'foo/bar', 'no params using empty array'), - array('controller2', array(), false, false, 'foo/bar', 'no params using empty array'), - array('controller3', array('p' => 3), true, false, 'foo/bar/p-3', 'no params using empty array'), - ); - } - - /** - * @dataProvider helper_url_data_with_rewrite() - */ - public function test_helper_url_with_rewrite($route, $params, $is_amp, $session_id, $expected, $description) - { - $this->config = new \phpbb\config\config(array('enable_mod_rewrite' => '1')); - $this->helper = new phpbb_mock_controller_helper($this->template, $this->user, $this->config, $this->provider, $this->extension_manager, '', 'php', dirname(__FILE__) . '/'); - $this->assertEquals($expected, $this->helper->route($route, $params, $is_amp, $session_id)); - } -} diff --git a/tests/controller/helper_route_unclean_path_test.php b/tests/controller/helper_route_unclean_path_test.php new file mode 100644 index 0000000000..9d8b62bc1c --- /dev/null +++ b/tests/controller/helper_route_unclean_path_test.php @@ -0,0 +1,33 @@ +<?php +/** +* +* This file is part of the phpBB Forum Software package. +* +* @copyright (c) phpBB Limited <https://www.phpbb.com> +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ + +require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php'; +require_once dirname(__FILE__) . '/common_helper_route.php'; + +class phpbb_controller_helper_route_unclean_path_test extends phpbb_controller_common_helper_route +{ + protected function get_phpbb_root_path() + { + return './../'; + } + + protected function get_uri() + { + return '/adm/../bertie/index.php'; + } + + protected function get_script_name() + { + return 'index.php'; + } +} diff --git a/tests/datetime/from_format_test.php b/tests/datetime/from_format_test.php index 88eec525a3..f10402e8cb 100644 --- a/tests/datetime/from_format_test.php +++ b/tests/datetime/from_format_test.php @@ -37,9 +37,7 @@ class phpbb_datetime_from_format_test extends phpbb_test_case */ public function test_from_format($timezone, $format, $expected) { - global $user; - - $user = new \phpbb\user(); + $user = new \phpbb\user('\phpbb\datetime'); $user->timezone = new DateTimeZone($timezone); $user->lang['datetime'] = array( 'TODAY' => 'Today', @@ -55,4 +53,74 @@ class phpbb_datetime_from_format_test extends phpbb_test_case $timestamp = $user->get_timestamp_from_format($format, $expected, new DateTimeZone($timezone)); $this->assertEquals($expected, $user->format_date($timestamp, $format, true)); } + + + public function relative_format_date_data() + { + // If the current time is too close to the testing time, + // the relative time will use "x minutes ago" instead of "today ..." + // So we use 18:01 in the morning and 06:01 in the afternoon. + $testing_time = date('H') <= 12 ? '18:01' : '06:01'; + + return array( + array( + date('Y-m-d', time() + 2 * 86400) . ' ' . $testing_time, false, + date('Y-m-d', time() + 2 * 86400) . ' ' . $testing_time, + ), + + array( + date('Y-m-d', time() + 86400) . ' ' . $testing_time, false, + 'Tomorrow ' . $testing_time, + ), + array( + date('Y-m-d', time() + 86400) . ' ' . $testing_time, true, + date('Y-m-d', time() + 86400) . ' ' . $testing_time, + ), + + array( + date('Y-m-d') . ' ' . $testing_time, false, + 'Today ' . $testing_time, + ), + array( + date('Y-m-d') . ' ' . $testing_time, true, + date('Y-m-d') . ' ' . $testing_time, + ), + + array( + date('Y-m-d', time() - 86400) . ' ' . $testing_time, false, + 'Yesterday ' . $testing_time, + ), + array( + date('Y-m-d', time() - 86400) . ' ' . $testing_time, true, + date('Y-m-d', time() - 86400) . ' ' . $testing_time, + ), + + array( + date('Y-m-d', time() - 2 * 86400) . ' ' . $testing_time, false, + date('Y-m-d', time() - 2 * 86400) . ' ' . $testing_time, + ), + ); + } + + /** + * @dataProvider relative_format_date_data() + */ + public function test_relative_format_date($timestamp, $forcedate, $expected) + { + $user = new \phpbb\user('\phpbb\datetime'); + $user->timezone = new DateTimeZone('UTC'); + $user->lang['datetime'] = array( + 'TODAY' => 'Today', + 'TOMORROW' => 'Tomorrow', + 'YESTERDAY' => 'Yesterday', + 'AGO' => array( + 0 => 'less than a minute ago', + 1 => '%d minute ago', + 2 => '%d minutes ago', + ), + ); + + $timestamp = $user->get_timestamp_from_format('Y-m-d H:i', $timestamp, new DateTimeZone('UTC')); + $this->assertEquals($expected, $user->format_date($timestamp, '|Y-m-d| H:i', $forcedate)); + } } diff --git a/tests/dbal/db_tools_test.php b/tests/dbal/db_tools_test.php index 6cc2f8ec0f..51f9daacfb 100644 --- a/tests/dbal/db_tools_test.php +++ b/tests/dbal/db_tools_test.php @@ -288,13 +288,13 @@ class phpbb_dbal_db_tools_test extends phpbb_database_test_case $this->assertTrue($this->tools->sql_column_exists('prefix_table_name', 'c_bug_12012_2')); // Create index over the column - $this->assertFalse($this->tools->sql_index_exists('prefix_table_name', 'i_bug_12012_2')); - $this->assertTrue($this->tools->sql_create_index('prefix_table_name', 'i_bug_12012_2', array('c_bug_12012_2', 'c_bool'))); - $this->assertTrue($this->tools->sql_index_exists('prefix_table_name', 'i_bug_12012_2')); + $this->assertFalse($this->tools->sql_index_exists('prefix_table_name', 'bug_12012_2')); + $this->assertTrue($this->tools->sql_create_index('prefix_table_name', 'bug_12012_2', array('c_bug_12012_2', 'c_bool'))); + $this->assertTrue($this->tools->sql_index_exists('prefix_table_name', 'bug_12012_2')); - $this->assertFalse($this->tools->sql_index_exists('prefix_table_name', 'i_bug_12012_3')); - $this->assertTrue($this->tools->sql_create_index('prefix_table_name', 'i_bug_12012_3', array('c_bug_12012_2'))); - $this->assertTrue($this->tools->sql_index_exists('prefix_table_name', 'i_bug_12012_3')); + $this->assertFalse($this->tools->sql_index_exists('prefix_table_name', 'bug_12012_3')); + $this->assertTrue($this->tools->sql_create_index('prefix_table_name', 'bug_12012_3', array('c_bug_12012_2'))); + $this->assertTrue($this->tools->sql_index_exists('prefix_table_name', 'bug_12012_3')); // Remove the column $this->assertTrue($this->tools->sql_column_exists('prefix_table_name', 'c_bug_12012_2')); diff --git a/tests/dbal/migrator_test.php b/tests/dbal/migrator_test.php index 4a1d15aea4..10a9444d63 100644 --- a/tests/dbal/migrator_test.php +++ b/tests/dbal/migrator_test.php @@ -60,7 +60,7 @@ class phpbb_dbal_migrator_test extends phpbb_database_test_case $container = new phpbb_mock_container_builder(); $container->set('migrator', $migrator); - $user = new \phpbb\user(); + $user = new \phpbb\user('\phpbb\datetime'); $this->extension_manager = new \phpbb\extension\manager( $container, diff --git a/tests/dbal/migrator_tool_module_test.php b/tests/dbal/migrator_tool_module_test.php index aeb69e27ac..08c3e979b8 100644 --- a/tests/dbal/migrator_tool_module_test.php +++ b/tests/dbal/migrator_tool_module_test.php @@ -32,7 +32,7 @@ class phpbb_dbal_migrator_tool_module_test extends phpbb_database_test_case $db = $this->db = $this->new_dbal(); $this->cache = new \phpbb\cache\service(new \phpbb\cache\driver\null(), new \phpbb\config\config(array()), $this->db, $phpbb_root_path, $phpEx); - $user = $this->user = new \phpbb\user(); + $user = $this->user = new \phpbb\user('\phpbb\user'); $cache = new phpbb_mock_cache; $phpbb_dispatcher = new phpbb_mock_event_dispatcher(); diff --git a/tests/dbal/select_test.php b/tests/dbal/select_test.php index e480716a49..b7074552ba 100644 --- a/tests/dbal/select_test.php +++ b/tests/dbal/select_test.php @@ -233,6 +233,66 @@ class phpbb_dbal_select_test extends phpbb_database_test_case $db->sql_freeresult($result); } + public function not_like_expression_data() + { + // * = any_char; # = one_char + return array( + array('barfoo', array( + array('username_clean' => 'foobar'), + array('username_clean' => 'bertie') + )), + array('bar', array( + array('username_clean' => 'barfoo'), + array('username_clean' => 'foobar'), + array('username_clean' => 'bertie'), + )), + array('bar*', array( + array('username_clean' => 'foobar'), + array('username_clean' => 'bertie')) + ), + array('*bar*', array(array('username_clean' => 'bertie'))), + array('b*r', array( + array('username_clean' => 'barfoo'), + array('username_clean' => 'foobar'), + array('username_clean' => 'bertie') + )), + array('b*e', array( + array('username_clean' => 'barfoo'), + array('username_clean' => 'foobar') + )), + array('#b*e', array( + array('username_clean' => 'barfoo'), + array('username_clean' => 'foobar'), + array('username_clean' => 'bertie') + )), + array('b####e', array( + array('username_clean' => 'barfoo'), + array('username_clean' => 'foobar') + )), + ); + } + + /** + * @dataProvider not_like_expression_data + */ + public function test_not_like_expression($like_expression, $expected) + { + $db = $this->new_dbal(); + + $like_expression = str_replace('*', $db->get_any_char(), $like_expression); + $like_expression = str_replace('#', $db->get_one_char(), $like_expression); + $where = ($like_expression) ? 'username_clean ' . $db->sql_not_like_expression($like_expression) : ''; + + $result = $db->sql_query('SELECT username_clean + FROM phpbb_users + ' . (($where) ? ' WHERE ' . $where : '') . ' + ORDER BY user_id ASC'); + + $this->assertEquals($expected, $db->sql_fetchrowset($result)); + + $db->sql_freeresult($result); + } + public function in_set_data() { return array( diff --git a/tests/di/create_container_test.php b/tests/di/create_container_test.php index 559c0b122c..4ae6017989 100644 --- a/tests/di/create_container_test.php +++ b/tests/di/create_container_test.php @@ -191,6 +191,10 @@ namespace phpbb\db\driver { } + function sql_not_like_expression($expression) + { + } + function sql_fetchrowset($query_id = false) { return array( diff --git a/tests/extension/ext/vendor2/bar/migrations/migration.php b/tests/extension/ext/vendor2/bar/migrations/migration.php new file mode 100644 index 0000000000..71caa34fd9 --- /dev/null +++ b/tests/extension/ext/vendor2/bar/migrations/migration.php @@ -0,0 +1,18 @@ +<?php +/** +* +* This file is part of the phpBB Forum Software package. +* +* @copyright (c) phpBB Limited <https://www.phpbb.com> +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ + +namespace vendor2\bar\migrations; + +class migration extends \phpbb\db\migration\migration +{ +} diff --git a/tests/extension/ext/vendor4/bar/composer.json b/tests/extension/ext/vendor4/bar/composer.json new file mode 100644 index 0000000000..1a2fddc3f4 --- /dev/null +++ b/tests/extension/ext/vendor4/bar/composer.json @@ -0,0 +1,23 @@ +{ + "name": "vendor4/bar", + "type": "phpbb-extension", + "description": "An example/sample extension to be used for testing purposes in phpBB Development.", + "version": "1.0.0", + "time": "2012-02-15 01:01:01", + "license": "GPL-2.0", + "authors": [{ + "name": "John Smith", + "email": "email@phpbb.com", + "homepage": "http://phpbb.com", + "role": "N/A" + }], + "require": { + "php": ">=5.3" + }, + "extra": { + "display-name": "phpBB Bar Extension", + "soft-require": { + "phpbb/phpbb": "3.1.*@dev" + } + } +} diff --git a/tests/extension/ext/vendor4/bar/styles/all/template/foobar_body.html b/tests/extension/ext/vendor4/bar/styles/all/template/foobar_body.html new file mode 100644 index 0000000000..c8f8cf957e --- /dev/null +++ b/tests/extension/ext/vendor4/bar/styles/all/template/foobar_body.html @@ -0,0 +1 @@ +All folder diff --git a/tests/extension/extension_base_test.php b/tests/extension/extension_base_test.php new file mode 100644 index 0000000000..eee38186db --- /dev/null +++ b/tests/extension/extension_base_test.php @@ -0,0 +1,79 @@ +<?php +/** +* +* This file is part of the phpBB Forum Software package. +* +* @copyright (c) phpBB Limited <https://www.phpbb.com> +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ +require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php'; + +class phpbb_extension_extension_base_test extends phpbb_test_case +{ + protected static $reflection_method_get_migration_file_list; + + /** @var phpbb_mock_extension_manager */ + protected $extension_manager; + + public static function setUpBeforeClass() + { + parent::setUpBeforeClass(); + + $reflection_class = new ReflectionClass('\phpbb\extension\base'); + self::$reflection_method_get_migration_file_list = $reflection_class->getMethod('get_migration_file_list'); + self::$reflection_method_get_migration_file_list->setAccessible(true); + } + + public function setUp() + { + $container = new phpbb_mock_container_builder(); + $migrator = new phpbb_mock_migrator(); + $container->set('migrator', $migrator); + + $this->extension_manager = new phpbb_mock_extension_manager( + dirname(__FILE__) . '/', + array( + 'vendor2/foo' => array( + 'ext_name' => 'vendor2/foo', + 'ext_active' => '1', + 'ext_path' => 'ext/vendor2/foo/', + ), + 'vendor3/bar' => array( + 'ext_name' => 'vendor3/bar', + 'ext_active' => '1', + 'ext_path' => 'ext/vendor3/bar/', + ), + 'vendor2/bar' => array( + 'ext_name' => 'vendor2/bar', + 'ext_active' => '1', + 'ext_path' => 'ext/vendor2/bar/', + ), + ), + $container); + } + + public function data_test_suffix_get_classes() + { + return array( + array( + 'vendor2/bar', + array( + '\vendor2\bar\migrations\migration', + ), + ), + ); + } + + /** + * @dataProvider data_test_suffix_get_classes + */ + public function test_suffix_get_classes($extension_name, $expected) + { + $extension = $this->extension_manager->get_extension($extension_name); + $this->assertEquals($expected, self::$reflection_method_get_migration_file_list->invoke($extension)); + } +} diff --git a/tests/extension/manager_test.php b/tests/extension/manager_test.php index 1e43c2a0a3..5c7cad89f6 100644 --- a/tests/extension/manager_test.php +++ b/tests/extension/manager_test.php @@ -36,7 +36,7 @@ class phpbb_extension_manager_test extends phpbb_database_test_case public function test_all_available() { // barfoo and vendor3/bar should not listed due to missing composer.json. barfoo also has incorrect dir structure. - $this->assertEquals(array('vendor/moo', 'vendor2/bar', 'vendor2/foo', 'vendor3/foo'), array_keys($this->extension_manager->all_available())); + $this->assertEquals(array('vendor/moo', 'vendor2/bar', 'vendor2/foo', 'vendor3/foo', 'vendor4/bar'), array_keys($this->extension_manager->all_available())); } public function test_all_enabled() @@ -154,7 +154,7 @@ class phpbb_extension_manager_test extends phpbb_database_test_case $phpbb_root_path = __DIR__ . './../../phpBB/'; $php_ext = 'php'; $table_prefix = 'phpbb_'; - $user = new \phpbb\user(); + $user = new \phpbb\user('\phpbb\user'); $migrator = new \phpbb\db\migrator( $config, diff --git a/tests/extension/metadata_manager_test.php b/tests/extension/metadata_manager_test.php index 535e4fe0d5..8e27b39459 100644 --- a/tests/extension/metadata_manager_test.php +++ b/tests/extension/metadata_manager_test.php @@ -44,7 +44,7 @@ class phpbb_extension_metadata_manager_test extends phpbb_database_test_case $this->db_tools = new \phpbb\db\tools($this->db); $this->phpbb_root_path = dirname(__FILE__) . '/'; $this->phpEx = 'php'; - $this->user = new \phpbb\user(); + $this->user = new \phpbb\user('\phpbb\datetime'); $this->table_prefix = 'phpbb_'; $this->template = new \phpbb\template\twig\twig( diff --git a/tests/functional/avatar_acp_groups_test.php b/tests/functional/avatar_acp_groups_test.php index 35f7956252..925335a2f7 100644 --- a/tests/functional/avatar_acp_groups_test.php +++ b/tests/functional/avatar_acp_groups_test.php @@ -48,7 +48,7 @@ class phpbb_functional_avatar_acp_groups_test extends phpbb_functional_common_av ), // Delete avatar image to reset group settings array( - 'GROUP_UPDATED', + array('CONFIRM_AVATAR_DELETE', 'GROUP_UPDATED'), 'avatar_driver_gravatar', array( 'avatar_delete' => array('tick', ''), diff --git a/tests/functional/avatar_acp_users_test.php b/tests/functional/avatar_acp_users_test.php index 38e001f516..5eca473157 100644 --- a/tests/functional/avatar_acp_users_test.php +++ b/tests/functional/avatar_acp_users_test.php @@ -46,7 +46,7 @@ class phpbb_functional_avatar_acp_users_test extends phpbb_functional_common_ava ), // Reset avatar settings array( - 'USER_AVATAR_UPDATED', + array('CONFIRM_AVATAR_DELETE', 'USER_AVATAR_UPDATED'), 'avatar_driver_gravatar', array( 'avatar_delete' => array('tick', ''), diff --git a/tests/functional/avatar_ucp_groups_test.php b/tests/functional/avatar_ucp_groups_test.php index fddf66933f..1e8ca911c6 100644 --- a/tests/functional/avatar_ucp_groups_test.php +++ b/tests/functional/avatar_ucp_groups_test.php @@ -55,7 +55,7 @@ class phpbb_functional_avatar_ucp_groups_test extends phpbb_functional_common_av ), ), array( - 'GROUP_UPDATED', + array('CONFIRM_AVATAR_DELETE', 'GROUP_UPDATED'), 'avatar_driver_gravatar', array( 'avatar_delete' => array('tick', ''), diff --git a/tests/functional/avatar_ucp_users_test.php b/tests/functional/avatar_ucp_users_test.php index 62cd79c307..972bfa0fb2 100644 --- a/tests/functional/avatar_ucp_users_test.php +++ b/tests/functional/avatar_ucp_users_test.php @@ -36,18 +36,9 @@ class phpbb_functional_avatar_ucp_users_test extends phpbb_functional_common_ava 'avatar_gravatar_height' => 80, ), ), - // Wrong driver selected - array( - 'NO_AVATAR_SELECTED', - 'avatar_driver_upload', - array( - 'avatar_remote_url' => 'https://secure.gravatar.com/avatar/55502f40dc8b7c769880b10874abc9d0.jpg', - 'avatar_remote_width' => 80, - 'avatar_remote_height' => 80, - ), - ), + array( - 'PROFILE_UPDATED', + array('CONFIRM_AVATAR_DELETE', 'PROFILE_UPDATED'), 'avatar_driver_gravatar', array( 'avatar_delete' => array('tick', ''), diff --git a/tests/functional/common_avatar_test.php b/tests/functional/common_avatar_test.php index 1bb9e5cd8e..82d7136c98 100644 --- a/tests/functional/common_avatar_test.php +++ b/tests/functional/common_avatar_test.php @@ -50,7 +50,7 @@ abstract class phpbb_functional_common_avatar_test extends phpbb_functional_test $this->assertContainsLang('CONFIG_UPDATED', $crawler->text()); } - public function assert_avatar_submit($expected, $type, $data, $button_text = 'SUBMIT') + public function assert_avatar_submit($expected, $type, $data, $delete = false, $button_text = 'SUBMIT') { $crawler = self::request('GET', $this->get_url() . '&sid=' . $this->sid); @@ -72,6 +72,12 @@ abstract class phpbb_functional_common_avatar_test extends phpbb_functional_test $crawler = self::submit($form); + if (is_array($expected)) + { + $delete_expected = $expected[1]; + $expected = $expected[0]; + } + try { $this->assertContainsLang($expected, $crawler->text()); @@ -80,5 +86,12 @@ abstract class phpbb_functional_common_avatar_test extends phpbb_functional_test { $this->assertContains($expected, $crawler->text()); } + + if ($delete) + { + $form = $crawler->selectButton('confirm')->form(); + $crawler = self::submit($form); + $this->assertContainsLang($delete_expected, $crawler->text()); + } } } diff --git a/tests/functional/download_test.php b/tests/functional/download_test.php index 6a6df14c81..4e4995c21e 100644 --- a/tests/functional/download_test.php +++ b/tests/functional/download_test.php @@ -80,20 +80,6 @@ class phpbb_functional_download_test extends phpbb_functional_test_case 'attachments' => true, )); - // Download topic archive as guest - $crawler = self::request('GET', "download/file.php?archive=.zip&topic_id={$this->data['topics']['Download Topic #1']}", array(), false); - self::assert_response_status_code(200); - $content = self::$client->getResponse()->getContent(); - $finfo = new finfo(FILEINFO_MIME_TYPE); - self::assertEquals('application/zip', $finfo->buffer($content)); - - // Download post archive as guest - $crawler = self::request('GET', "download/file.php?archive=.zip&post_id={$this->data['posts']['Re: Download Topic #1-#2']}", array(), false); - self::assert_response_status_code(200); - $content = self::$client->getResponse()->getContent(); - $finfo = new finfo(FILEINFO_MIME_TYPE); - self::assertEquals('application/zip', $finfo->buffer($content)); - // Download attachment as guest $crawler = self::request('GET', "download/file.php?id={$this->data['attachments'][$this->data['posts']['Re: Download Topic #1-#2']]}", array(), false); self::assert_response_status_code(200); @@ -147,18 +133,6 @@ class phpbb_functional_download_test extends phpbb_functional_test_case )); $this->add_lang('viewtopic'); - // Download topic archive as guest: still works - $crawler = self::request('GET', "download/file.php?archive=.zip&topic_id={$this->data['topics']['Download Topic #1']}", array(), false); - self::assert_response_status_code(200); - $content = self::$client->getResponse()->getContent(); - $finfo = new finfo(FILEINFO_MIME_TYPE); - self::assertEquals('application/zip', $finfo->buffer($content)); - - // No download post archive as guest - $crawler = self::request('GET', "download/file.php?archive=.zip&post_id={$this->data['posts']['Re: Download Topic #1-#2']}", array(), false); - self::assert_response_html(404); - $this->assertContainsLang('ERROR_NO_ATTACHMENT', $crawler->filter('#message')->text()); - // No download attachment as guest $crawler = self::request('GET', "download/file.php?id={$this->data['attachments'][$this->data['posts']['Re: Download Topic #1-#2']]}", array(), false); self::assert_response_html(404); @@ -167,20 +141,6 @@ class phpbb_functional_download_test extends phpbb_functional_test_case // Login as admin and try again, should work now. $this->login(); - // Download topic archive as admin - $crawler = self::request('GET', "download/file.php?archive=.zip&topic_id={$this->data['topics']['Download Topic #1']}", array(), false); - self::assert_response_status_code(200); - $content = self::$client->getResponse()->getContent(); - $finfo = new finfo(FILEINFO_MIME_TYPE); - self::assertEquals('application/zip', $finfo->buffer($content)); - - // Download post archive as admin - $crawler = self::request('GET', "download/file.php?archive=.zip&post_id={$this->data['posts']['Re: Download Topic #1-#2']}", array(), false); - self::assert_response_status_code(200); - $content = self::$client->getResponse()->getContent(); - $finfo = new finfo(FILEINFO_MIME_TYPE); - self::assertEquals('application/zip', $finfo->buffer($content)); - // Download attachment as admin $crawler = self::request('GET', "download/file.php?id={$this->data['attachments'][$this->data['posts']['Re: Download Topic #1-#2']]}", array(), false); self::assert_response_status_code(200); @@ -235,16 +195,6 @@ class phpbb_functional_download_test extends phpbb_functional_test_case )); $this->add_lang('viewtopic'); - // Download topic archive as guest: still works - $crawler = self::request('GET', "download/file.php?archive=.zip&topic_id={$this->data['topics']['Download Topic #1']}", array(), false); - self::assert_response_html(404); - $this->assertContainsLang('ERROR_NO_ATTACHMENT', $crawler->filter('#message')->text()); - - // No download post archive as guest - $crawler = self::request('GET', "download/file.php?archive=.zip&post_id={$this->data['posts']['Re: Download Topic #1-#2']}", array(), false); - self::assert_response_html(404); - $this->assertContainsLang('ERROR_NO_ATTACHMENT', $crawler->filter('#message')->text()); - // No download attachment as guest $crawler = self::request('GET', "download/file.php?id={$this->data['attachments'][$this->data['posts']['Re: Download Topic #1-#2']]}", array(), false); self::assert_response_html(404); @@ -253,20 +203,6 @@ class phpbb_functional_download_test extends phpbb_functional_test_case // Login as admin and try again, should work now. $this->login(); - // Download topic archive as admin - $crawler = self::request('GET', "download/file.php?archive=.zip&topic_id={$this->data['topics']['Download Topic #1']}", array(), false); - self::assert_response_status_code(200); - $content = self::$client->getResponse()->getContent(); - $finfo = new finfo(FILEINFO_MIME_TYPE); - self::assertEquals('application/zip', $finfo->buffer($content)); - - // Download post archive as admin - $crawler = self::request('GET', "download/file.php?archive=.zip&post_id={$this->data['posts']['Re: Download Topic #1-#2']}", array(), false); - self::assert_response_status_code(200); - $content = self::$client->getResponse()->getContent(); - $finfo = new finfo(FILEINFO_MIME_TYPE); - self::assertEquals('application/zip', $finfo->buffer($content)); - // Download attachment as admin $crawler = self::request('GET', "download/file.php?id={$this->data['attachments'][$this->data['posts']['Re: Download Topic #1-#2']]}", array(), false); self::assert_response_status_code(200); diff --git a/tests/functional/extension_acp_test.php b/tests/functional/extension_acp_test.php index 6490c1ead3..7be8957ec7 100644 --- a/tests/functional/extension_acp_test.php +++ b/tests/functional/extension_acp_test.php @@ -84,7 +84,7 @@ class phpbb_functional_extension_acp_test extends phpbb_functional_test_case $crawler = self::request('GET', 'adm/index.php?i=acp_extensions&mode=main&sid=' . $this->sid); $this->assertCount(1, $crawler->filter('.ext_enabled')); - $this->assertCount(5, $crawler->filter('.ext_disabled')); + $this->assertCount(6, $crawler->filter('.ext_disabled')); $this->assertContains('phpBB Foo Extension', $crawler->filter('.ext_enabled')->eq(0)->text()); $this->assertContainsLang('EXTENSION_DISABLE', $crawler->filter('.ext_enabled')->eq(0)->text()); diff --git a/tests/functional/extension_controller_test.php b/tests/functional/extension_controller_test.php index 532a160a47..18eb9ad4c6 100644 --- a/tests/functional/extension_controller_test.php +++ b/tests/functional/extension_controller_test.php @@ -26,6 +26,8 @@ class phpbb_functional_extension_controller_test extends phpbb_functional_test_c 'foo/bar/event/', 'foo/bar/language/en/', 'foo/bar/styles/prosilver/template/', + 'foo/foo/config/', + 'foo/foo/controller/', ); static public function setUpBeforeClass() @@ -65,6 +67,18 @@ class phpbb_functional_extension_controller_test extends phpbb_functional_test_c } /** + * Check a controller for extension foo/bar. + */ + public function test_routing_resources() + { + $this->phpbb_extension_manager->enable('foo/foo'); + $crawler = self::request('GET', 'app.php/foo/foo', array(), false); + self::assert_response_status_code(); + $this->assertContains("foo/foo controller handle() method", $crawler->filter('body')->text()); + $this->phpbb_extension_manager->purge('foo/foo'); + } + + /** * Check the output of a controller using the template system */ public function test_controller_with_template() diff --git a/tests/functional/fileupload_form_test.php b/tests/functional/fileupload_form_test.php index 29036c821e..b8c48389e0 100644 --- a/tests/functional/fileupload_form_test.php +++ b/tests/functional/fileupload_form_test.php @@ -42,8 +42,6 @@ class phpbb_functional_fileupload_form_test extends phpbb_functional_test_case unlink($fileinfo->getPathname()); } - - parent::tearDown(); } private function upload_file($filename, $mimetype) @@ -109,9 +107,9 @@ class phpbb_functional_fileupload_form_test extends phpbb_functional_test_case $crawler = $this->upload_file('disallowed.jpg', 'image/jpeg'); - // Hitting the ATTACHED_IMAGE_NOT_IMAGE error means we passed the + // Hitting the UNABLE_GET_IMAGE_SIZE error means we passed the // DISALLOWED_CONTENT check - $this->assertContains($this->lang('ATTACHED_IMAGE_NOT_IMAGE'), $crawler->text()); + $this->assertContainsLang('UNABLE_GET_IMAGE_SIZE', $crawler->text()); } public function test_too_large() diff --git a/tests/functional/fileupload_remote_test.php b/tests/functional/fileupload_remote_test.php index ef39e1d71b..6ece150b23 100644 --- a/tests/functional/fileupload_remote_test.php +++ b/tests/functional/fileupload_remote_test.php @@ -45,8 +45,6 @@ class phpbb_functional_fileupload_remote_test extends phpbb_functional_test_case global $config, $user; $user = null; $config = array(); - - parent::tearDown(); } public function test_invalid_extension() diff --git a/tests/functional/fixtures/ext/foo/foo/composer.json b/tests/functional/fixtures/ext/foo/foo/composer.json new file mode 100644 index 0000000000..d85c76a6a2 --- /dev/null +++ b/tests/functional/fixtures/ext/foo/foo/composer.json @@ -0,0 +1,24 @@ +{ + "name": "foo/foo", + "type": "phpbb-extension", + "description": "Testing extensions", + "homepage": "", + "version": "1.0.0", + "time": "2013-03-21 01:01:01", + "license": "GPL-2.0", + "authors": [{ + "name": "Tristan Darricau", + "email": "nicofuma@phpbb.com", + "homepage": "http://www.phpbb.com", + "role": "Developer" + }], + "require": { + "php": ">=5.3" + }, + "extra": { + "display-name": "phpBB 3.1 Extension Testing", + "soft-require": { + "phpbb/phpbb": "3.1.*@dev" + } + } +} diff --git a/tests/functional/fixtures/ext/foo/foo/config/resource.yml b/tests/functional/fixtures/ext/foo/foo/config/resource.yml new file mode 100644 index 0000000000..ed1d018016 --- /dev/null +++ b/tests/functional/fixtures/ext/foo/foo/config/resource.yml @@ -0,0 +1,3 @@ +foo_foo_controller: + pattern: /foo + defaults: { _controller: foo_foo.controller:handle } diff --git a/tests/functional/fixtures/ext/foo/foo/config/routing.yml b/tests/functional/fixtures/ext/foo/foo/config/routing.yml new file mode 100644 index 0000000000..c2c401687d --- /dev/null +++ b/tests/functional/fixtures/ext/foo/foo/config/routing.yml @@ -0,0 +1,3 @@ +foo_foo.general: + resource: "resource.yml" + prefix: /foo diff --git a/tests/functional/fixtures/ext/foo/foo/config/services.yml b/tests/functional/fixtures/ext/foo/foo/config/services.yml new file mode 100644 index 0000000000..b3c7719715 --- /dev/null +++ b/tests/functional/fixtures/ext/foo/foo/config/services.yml @@ -0,0 +1,3 @@ +services: + foo_foo.controller: + class: foo\foo\controller\controller diff --git a/tests/functional/fixtures/ext/foo/foo/controller/controller.php b/tests/functional/fixtures/ext/foo/foo/controller/controller.php new file mode 100644 index 0000000000..771eaeacfc --- /dev/null +++ b/tests/functional/fixtures/ext/foo/foo/controller/controller.php @@ -0,0 +1,13 @@ +<?php + +namespace foo\foo\controller; + +use Symfony\Component\HttpFoundation\Response; + +class controller +{ + public function handle() + { + return new Response('foo/foo controller handle() method', 200); + } +} diff --git a/tests/functional/fixtures/ext/foo/foo/ext.php b/tests/functional/fixtures/ext/foo/foo/ext.php new file mode 100644 index 0000000000..80acda74fe --- /dev/null +++ b/tests/functional/fixtures/ext/foo/foo/ext.php @@ -0,0 +1,8 @@ +<?php + +namespace foo\foo; + +class ext extends \phpbb\extension\base +{ + +} diff --git a/tests/functional/forgot_password_test.php b/tests/functional/forgot_password_test.php index c95efc5b2e..64fa19557f 100644 --- a/tests/functional/forgot_password_test.php +++ b/tests/functional/forgot_password_test.php @@ -57,7 +57,5 @@ class phpbb_functional_forgot_password_test extends phpbb_functional_test_case 'config[allow_password_reset]' => 1, )); $crawler = self::submit($form); - - parent::tearDown(); } } diff --git a/tests/functional/notification_test.php b/tests/functional/notification_test.php index e4a960f862..667d268b1e 100644 --- a/tests/functional/notification_test.php +++ b/tests/functional/notification_test.php @@ -21,20 +21,20 @@ class phpbb_functional_notification_test extends phpbb_functional_test_case 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), + array('notification.type.post_notification', true), + array('notification.type.topic_notification', true), + array('notification.type.post_notification.method.email', true), + array('notification.type.topic_notification.method.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), + array('notification.type.bookmark_notification', true), + array('notification.type.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), + array('notification.type.bookmark_notification.method.email', false), + array('notification.type.quote_notification.method.email', false), ); } diff --git a/tests/functional/plupload_test.php b/tests/functional/plupload_test.php index d9faec035c..ee71597ffc 100644 --- a/tests/functional/plupload_test.php +++ b/tests/functional/plupload_test.php @@ -57,8 +57,6 @@ class phpbb_functional_plupload_test extends phpbb_functional_test_case unlink($fileinfo->getPathname()); } - - parent::tearDown(); } public function get_urls() diff --git a/tests/functional/ucp_preferences_test.php b/tests/functional/ucp_preferences_test.php new file mode 100644 index 0000000000..7ef325dc4b --- /dev/null +++ b/tests/functional/ucp_preferences_test.php @@ -0,0 +1,85 @@ +<?php +/** +* +* This file is part of the phpBB Forum Software package. +* +* @copyright (c) phpBB Limited <https://www.phpbb.com> +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ + +/** +* @group functional +*/ +class phpbb_functional_ucp_preferences_test extends phpbb_functional_test_case +{ + public function test_submitting_preferences_view() + { + $this->add_lang('ucp'); + $this->login(); + + $crawler = self::request('GET', 'ucp.php?i=ucp_prefs&mode=view'); + $this->assertContainsLang('UCP_PREFS_VIEW', $crawler->filter('#cp-main h2')->text()); + + $form = $crawler->selectButton('Submit')->form(array( + 'topic_sk' => 'a', + 'topic_sd' => 'a', + 'topic_st' => '1', + 'post_sk' => 'a', + 'post_sd' => 'a', + 'post_st' => '1', + )); + + $crawler = self::submit($form); + $this->assertContainsLang('PREFERENCES_UPDATED', $crawler->filter('#message')->text()); + } + + public function test_submitting_invalid_preferences_view() + { + $this->add_lang('ucp'); + $this->login(); + + $crawler = self::request('GET', 'ucp.php?i=ucp_prefs&mode=view'); + $this->assertContainsLang('UCP_PREFS_VIEW', $crawler->filter('#cp-main h2')->text()); + $form = $crawler->selectButton('Submit')->form(); + + if (!method_exists($form, 'disableValidation')) + { + $this->markTestIncomplete('The crawler cannot select invalid values, until Symfony 2.4!'); + } + + $form = $form->disableValidation(); + $form['topic_sk']->select('z'); + $form['topic_sd']->select('z'); + $form['topic_st']->select('test'); + $form['post_sk']->select('z'); + $form['post_sd']->select('z'); + $form['post_st']->select('test'); + + $crawler = self::submit($form); + $this->assertContainsLang('WRONG_DATA_POST_SD', $crawler->filter('#cp-main')->text()); + $this->assertContainsLang('WRONG_DATA_POST_SK', $crawler->filter('#cp-main')->text()); + $this->assertContainsLang('WRONG_DATA_TOPIC_SD', $crawler->filter('#cp-main')->text()); + $this->assertContainsLang('WRONG_DATA_TOPIC_SK', $crawler->filter('#cp-main')->text()); + } + + public function test_read_preferences_view() + { + $this->add_lang('ucp'); + $this->login(); + + $crawler = self::request('GET', 'ucp.php?i=ucp_prefs&mode=view'); + $this->assertContainsLang('UCP_PREFS_VIEW', $crawler->filter('#cp-main h2')->text()); + $form = $crawler->selectButton('Submit')->form(); + + $this->assertEquals('a', $form->get('topic_sk')->getValue()); + $this->assertEquals('a', $form->get('topic_sd')->getValue()); + $this->assertEquals('1', $form->get('topic_st')->getValue()); + $this->assertEquals('a', $form->get('post_sk')->getValue()); + $this->assertEquals('a', $form->get('post_sd')->getValue()); + $this->assertEquals('1', $form->get('post_st')->getValue()); + } +} diff --git a/tests/functions/generate_string_list.php b/tests/functions/generate_string_list.php index 32a04c1501..cd1e37618a 100644 --- a/tests/functions/generate_string_list.php +++ b/tests/functions/generate_string_list.php @@ -22,7 +22,7 @@ class phpbb_generate_string_list_test extends phpbb_test_case { parent::setUp(); - $this->user = new \phpbb\user(); + $this->user = new \phpbb\user('\phpbb\datetime'); $this->user->data = array('user_lang' => 'en'); $this->user->add_lang('common'); } diff --git a/tests/functions/get_preg_expression_test.php b/tests/functions/get_preg_expression_test.php new file mode 100644 index 0000000000..e74017d315 --- /dev/null +++ b/tests/functions/get_preg_expression_test.php @@ -0,0 +1,40 @@ +<?php +/** +* +* This file is part of the phpBB Forum Software package. +* +* @copyright (c) phpBB Limited <https://www.phpbb.com> +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ + +require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php'; + +class phpbb_functions_get_preg_expression_test extends phpbb_test_case +{ + public function data_path_remove_dot_trailing_slash() + { + return array( + array('./../', '$2', '/..'), + array('/../', '$2', '/..'), + array('', '$2', ''), + array('./', '$2', ''), + array('/', '$2', ''), + array('./../../', '$2', '/../..'), + array('/../../', '$2', '/../..'), + array('./dir/', '$2', '/dir'), + array('./../dir/', '$2', '/../dir'), + ); + } + + /** + * @dataProvider data_path_remove_dot_trailing_slash + */ + public function test_path_remove_dot_trailing_slash($input, $replace, $expected) + { + $this->assertSame($expected, preg_replace(get_preg_expression('path_remove_dot_trailing_slash'), $replace, $input)); + } +} diff --git a/tests/functions/insert_config_array_test.php b/tests/functions/insert_config_array_test.php new file mode 100644 index 0000000000..bfcb05862e --- /dev/null +++ b/tests/functions/insert_config_array_test.php @@ -0,0 +1,142 @@ +<?php +/** +* +* This file is part of the phpBB Forum Software package. +* +* @copyright (c) phpBB Limited <https://www.phpbb.com> +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ + +class phpbb_functions_insert_config_array_test extends phpbb_test_case +{ + public function config_display_vars() + { + return array( + 'legend1' => '', + 'acp_config_1' => array(), + 'acp_config_2' => array(), + 'acp_config_3' => array(), + 'acp_config_4' => array(), + 'acp_config_5' => array(), + ); + } + + public function insert_config_array_data() + { + return array( + array( // Add a new config after 1st array item + array('new_config_1' => array()), + array('after' => 'legend1'), + array( + 'legend1' => '', + 'new_config_1' => array(), + 'acp_config_1' => array(), + 'acp_config_2' => array(), + 'acp_config_3' => array(), + 'acp_config_4' => array(), + 'acp_config_5' => array(), + ), + ), + array( // Add a new config after last array item + array('new_config_1' => array()), + array('after' => 'acp_config_5'), + array( + 'legend1' => '', + 'acp_config_1' => array(), + 'acp_config_2' => array(), + 'acp_config_3' => array(), + 'acp_config_4' => array(), + 'acp_config_5' => array(), + 'new_config_1' => array(), + ), + ), + array( // Add a new config before 2nd array item + array('new_config_1' => array()), + array('before' => 'acp_config_1'), + array( + 'legend1' => '', + 'new_config_1' => array(), + 'acp_config_1' => array(), + 'acp_config_2' => array(), + 'acp_config_3' => array(), + 'acp_config_4' => array(), + 'acp_config_5' => array(), + ), + ), + array( // Add a new config before last config item + array('new_config_1' => array()), + array('before' => 'acp_config_5'), + array( + 'legend1' => '', + 'acp_config_1' => array(), + 'acp_config_2' => array(), + 'acp_config_3' => array(), + 'acp_config_4' => array(), + 'new_config_1' => array(), + 'acp_config_5' => array(), + ), + ), + array( // When an array key does not exist + array('new_config_1' => array()), + array('after' => 'foobar'), + array( + 'legend1' => '', + 'acp_config_1' => array(), + 'acp_config_2' => array(), + 'acp_config_3' => array(), + 'acp_config_4' => array(), + 'acp_config_5' => array(), + ), + ), + array( // When after|before is not used correctly (defaults to after) + array('new_config_1' => array()), + array('foobar' => 'acp_config_1'), + array( + 'legend1' => '', + 'acp_config_1' => array(), + 'new_config_1' => array(), + 'acp_config_2' => array(), + 'acp_config_3' => array(), + 'acp_config_4' => array(), + 'acp_config_5' => array(), + ), + ), + array( // Add a new config set after the last array item + array( + 'legend2' => array(), + 'new_config_1' => array(), + 'new_config_2' => array(), + 'new_config_3' => array(), + ), + array('after' => 'acp_config_5'), + array( + 'legend1' => '', + 'acp_config_1' => array(), + 'acp_config_2' => array(), + 'acp_config_3' => array(), + 'acp_config_4' => array(), + 'acp_config_5' => array(), + 'legend2' => array(), + 'new_config_1' => array(), + 'new_config_2' => array(), + 'new_config_3' => array(), + ), + ), + ); + } + + /** + * @dataProvider insert_config_array_data + */ + public function test_insert_config_array($new_config, $position, $expected) + { + $config_array = $this->config_display_vars(); + $new_config_array = phpbb_insert_config_array($config_array, $new_config, $position); + + $this->assertSame($expected, $new_config_array); + } +} diff --git a/tests/functions_user/delete_user_test.php b/tests/functions_user/delete_user_test.php new file mode 100644 index 0000000000..d5c78c64ad --- /dev/null +++ b/tests/functions_user/delete_user_test.php @@ -0,0 +1,440 @@ +<?php +/** +* +* @package testing +* @copyright (c) 2014 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_user.php'; +require_once dirname(__FILE__) . '/../../phpBB/includes/utf/utf_tools.php'; + +class phpbb_functions_user_delete_user_test extends phpbb_database_test_case +{ + /** @var \phpbb\db\driver\driver_interface */ + protected $db; + + public function getDataSet() + { + return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/delete_user.xml'); + } + + protected function setUp() + { + parent::setUp(); + + global $cache, $config, $db, $phpbb_dispatcher, $phpbb_container; + + $db = $this->db = $this->new_dbal(); + $config = new \phpbb\config\config(array( + 'load_online_time' => 5, + 'search_type' => '\phpbb\search\fulltext_mysql', + )); + set_config(false, false, false, $config); + set_config_count(false, false, false, $config); + $cache = new phpbb_mock_null_cache(); + $phpbb_dispatcher = new phpbb_mock_event_dispatcher(); + $phpbb_container = new phpbb_mock_container_builder(); + $phpbb_container->set('notification_manager', new phpbb_mock_notification_manager()); + } + + public function first_last_post_data() + { + return array( + array( + 'retain', false, + array( + array('post_id' => 1, 'poster_id' => ANONYMOUS, 'post_username' => ''), + array('post_id' => 2, 'poster_id' => ANONYMOUS, 'post_username' => 'Other'), + array('post_id' => 3, 'poster_id' => ANONYMOUS, 'post_username' => ''), + array('post_id' => 4, 'poster_id' => ANONYMOUS, 'post_username' => 'Other'), + ), + array( + array( + 'topic_id' => 1, + 'topic_poster' => ANONYMOUS, 'topic_first_poster_name' => '', 'topic_first_poster_colour' => '', + 'topic_last_poster_id' => ANONYMOUS, 'topic_last_poster_name' => '', 'topic_last_poster_colour' => '', + ), + array( + 'topic_id' => 2, + 'topic_poster' => ANONYMOUS, 'topic_first_poster_name' => 'Other', 'topic_first_poster_colour' => '', + 'topic_last_poster_id' => ANONYMOUS, 'topic_last_poster_name' => 'Other', 'topic_last_poster_colour' => '', + ), + array( + 'topic_id' => 3, + 'topic_poster' => ANONYMOUS, 'topic_first_poster_name' => '', 'topic_first_poster_colour' => '', + 'topic_last_poster_id' => ANONYMOUS, 'topic_last_poster_name' => '', 'topic_last_poster_colour' => '', + ), + array( + 'topic_id' => 4, + 'topic_poster' => ANONYMOUS, 'topic_first_poster_name' => 'Other', 'topic_first_poster_colour' => '', + 'topic_last_poster_id' => ANONYMOUS, 'topic_last_poster_name' => 'Other', 'topic_last_poster_colour' => '', + ), + ), + array( + array('forum_id' => 1, 'forum_last_poster_id' => ANONYMOUS, 'forum_last_poster_name' => '', 'forum_last_poster_colour' => ''), + array('forum_id' => 2, 'forum_last_poster_id' => ANONYMOUS, 'forum_last_poster_name' => 'Other', 'forum_last_poster_colour' => ''), + array('forum_id' => 3, 'forum_last_poster_id' => ANONYMOUS, 'forum_last_poster_name' => '', 'forum_last_poster_colour' => ''), + array('forum_id' => 4, 'forum_last_poster_id' => ANONYMOUS, 'forum_last_poster_name' => 'Other', 'forum_last_poster_colour' => ''), + ), + ), + array( + 'remove', false, + array( + array('post_id' => 2, 'poster_id' => ANONYMOUS, 'post_username' => 'Other'), + array('post_id' => 4, 'poster_id' => ANONYMOUS, 'post_username' => 'Other'), + ), + array( + array( + 'topic_id' => 2, + 'topic_poster' => ANONYMOUS, 'topic_first_poster_name' => 'Other', 'topic_first_poster_colour' => '', + 'topic_last_poster_id' => ANONYMOUS, 'topic_last_poster_name' => 'Other', 'topic_last_poster_colour' => '', + ), + array( + 'topic_id' => 4, + 'topic_poster' => ANONYMOUS, 'topic_first_poster_name' => 'Other', 'topic_first_poster_colour' => '', + 'topic_last_poster_id' => ANONYMOUS, 'topic_last_poster_name' => 'Other', 'topic_last_poster_colour' => '', + ), + ), + array( + array('forum_id' => 1, 'forum_last_poster_id' => 0, 'forum_last_poster_name' => '', 'forum_last_poster_colour' => ''), + array('forum_id' => 2, 'forum_last_poster_id' => ANONYMOUS, 'forum_last_poster_name' => 'Other', 'forum_last_poster_colour' => ''), + array('forum_id' => 3, 'forum_last_poster_id' => 0, 'forum_last_poster_name' => '', 'forum_last_poster_colour' => ''), + array('forum_id' => 4, 'forum_last_poster_id' => ANONYMOUS, 'forum_last_poster_name' => 'Other', 'forum_last_poster_colour' => ''), + ), + ), + array( + 'retain', true, + array( + array('post_id' => 1, 'poster_id' => ANONYMOUS, 'post_username' => 'Foobar'), + array('post_id' => 2, 'poster_id' => ANONYMOUS, 'post_username' => 'Other'), + array('post_id' => 3, 'poster_id' => ANONYMOUS, 'post_username' => 'Foobar'), + array('post_id' => 4, 'poster_id' => ANONYMOUS, 'post_username' => 'Other'), + ), + array( + array( + 'topic_id' => 1, + 'topic_poster' => ANONYMOUS, 'topic_first_poster_name' => 'Foobar', 'topic_first_poster_colour' => '', + 'topic_last_poster_id' => ANONYMOUS, 'topic_last_poster_name' => 'Foobar', 'topic_last_poster_colour' => '', + ), + array( + 'topic_id' => 2, + 'topic_poster' => ANONYMOUS, 'topic_first_poster_name' => 'Other', 'topic_first_poster_colour' => '', + 'topic_last_poster_id' => ANONYMOUS, 'topic_last_poster_name' => 'Other', 'topic_last_poster_colour' => '', + ), + array( + 'topic_id' => 3, + 'topic_poster' => ANONYMOUS, 'topic_first_poster_name' => 'Foobar', 'topic_first_poster_colour' => '', + 'topic_last_poster_id' => ANONYMOUS, 'topic_last_poster_name' => 'Foobar', 'topic_last_poster_colour' => '', + ), + array( + 'topic_id' => 4, + 'topic_poster' => ANONYMOUS, 'topic_first_poster_name' => 'Other', 'topic_first_poster_colour' => '', + 'topic_last_poster_id' => ANONYMOUS, 'topic_last_poster_name' => 'Other', 'topic_last_poster_colour' => '', + ), + ), + array( + array('forum_id' => 1, 'forum_last_poster_id' => ANONYMOUS, 'forum_last_poster_name' => 'Foobar', 'forum_last_poster_colour' => ''), + array('forum_id' => 2, 'forum_last_poster_id' => ANONYMOUS, 'forum_last_poster_name' => 'Other', 'forum_last_poster_colour' => ''), + array('forum_id' => 3, 'forum_last_poster_id' => ANONYMOUS, 'forum_last_poster_name' => 'Foobar', 'forum_last_poster_colour' => ''), + array('forum_id' => 4, 'forum_last_poster_id' => ANONYMOUS, 'forum_last_poster_name' => 'Other', 'forum_last_poster_colour' => ''), + ), + ), + array( + 'remove', true, + array( + array('post_id' => 2, 'poster_id' => ANONYMOUS, 'post_username' => 'Other'), + array('post_id' => 4, 'poster_id' => ANONYMOUS, 'post_username' => 'Other'), + ), + array( + array( + 'topic_id' => 2, + 'topic_poster' => ANONYMOUS, 'topic_first_poster_name' => 'Other', 'topic_first_poster_colour' => '', + 'topic_last_poster_id' => ANONYMOUS, 'topic_last_poster_name' => 'Other', 'topic_last_poster_colour' => '', + ), + array( + 'topic_id' => 4, + 'topic_poster' => ANONYMOUS, 'topic_first_poster_name' => 'Other', 'topic_first_poster_colour' => '', + 'topic_last_poster_id' => ANONYMOUS, 'topic_last_poster_name' => 'Other', 'topic_last_poster_colour' => '', + ), + ), + array( + array('forum_id' => 1, 'forum_last_poster_id' => 0, 'forum_last_poster_name' => '', 'forum_last_poster_colour' => ''), + array('forum_id' => 2, 'forum_last_poster_id' => ANONYMOUS, 'forum_last_poster_name' => 'Other', 'forum_last_poster_colour' => ''), + array('forum_id' => 3, 'forum_last_poster_id' => 0, 'forum_last_poster_name' => '', 'forum_last_poster_colour' => ''), + array('forum_id' => 4, 'forum_last_poster_id' => ANONYMOUS, 'forum_last_poster_name' => 'Other', 'forum_last_poster_colour' => ''), + ), + ), + ); + } + + /** + * @dataProvider first_last_post_data + */ + public function test_first_last_post_info($mode, $retain_username, $expected_posts, $expected_topics, $expected_forums) + { + $this->assertFalse(user_delete($mode, 2, $retain_username)); + + $sql = 'SELECT post_id, poster_id, post_username + FROM ' . POSTS_TABLE . ' + ORDER BY post_id ASC'; + $result = $this->db->sql_query($sql); + $this->assertEquals($expected_posts, $this->db->sql_fetchrowset($result), 'Post table poster info is mismatching after deleting a user.'); + $this->db->sql_freeresult($result); + + $sql = 'SELECT topic_id, topic_poster, topic_first_poster_name, topic_first_poster_colour, topic_last_poster_id, topic_last_poster_name, topic_last_poster_colour + FROM ' . TOPICS_TABLE . ' + ORDER BY topic_id ASC'; + $result = $this->db->sql_query($sql); + $this->assertEquals($expected_topics, $this->db->sql_fetchrowset($result), 'Topic table first/last poster info is mismatching after deleting a user.'); + $this->db->sql_freeresult($result); + + $sql = 'SELECT forum_id, forum_last_poster_id, forum_last_poster_name, forum_last_poster_colour + FROM ' . FORUMS_TABLE . ' + ORDER BY forum_id ASC'; + $result = $this->db->sql_query($sql); + $this->assertEquals($expected_forums, $this->db->sql_fetchrowset($result), 'Forum table last poster info is mismatching after deleting a user.'); + $this->db->sql_freeresult($result); + } + + public function report_attachment_data() + { + return array( + array( + 'retain', + array( + array('post_id' => 1, 'post_reported' => 1, 'post_edit_user' => 1, 'post_delete_user' => 1), + array('post_id' => 2, 'post_reported' => 1, 'post_edit_user' => 1, 'post_delete_user' => 1), + array('post_id' => 3, 'post_reported' => 0, 'post_edit_user' => 1, 'post_delete_user' => 1), + array('post_id' => 4, 'post_reported' => 0, 'post_edit_user' => 1, 'post_delete_user' => 1), + ), + array( + array('report_id' => 1, 'post_id' => 1, 'user_id' => 1), + array('report_id' => 3, 'post_id' => 2, 'user_id' => 1), + ), + array( + array('topic_id' => 1, 'topic_reported' => 1, 'topic_delete_user' => 1), + array('topic_id' => 2, 'topic_reported' => 1, 'topic_delete_user' => 1), + array('topic_id' => 3, 'topic_reported' => 0, 'topic_delete_user' => 1), + array('topic_id' => 4, 'topic_reported' => 0, 'topic_delete_user' => 1), + ), + array( + array('attach_id' => 1, 'post_msg_id' => 1, 'poster_id' => 1), + array('attach_id' => 2, 'post_msg_id' => 2, 'poster_id' => 1), + array('attach_id' => 3, 'post_msg_id' => 0, 'poster_id' => 1), // TODO should be deleted: PHPBB3-13089 + ), + ), + array( + 'remove', + array( + array('post_id' => 2, 'post_reported' => 1, 'post_edit_user' => 1, 'post_delete_user' => 1), + array('post_id' => 4, 'post_reported' => 0, 'post_edit_user' => 1, 'post_delete_user' => 1), + ), + array( + array('report_id' => 3, 'post_id' => 2, 'user_id' => 1), + ), + array( + array('topic_id' => 2, 'topic_reported' => 1, 'topic_delete_user' => 1), + array('topic_id' => 4, 'topic_reported' => 0, 'topic_delete_user' => 1), + ), + array( + array('attach_id' => 2, 'post_msg_id' => 2, 'poster_id' => 1), + array('attach_id' => 3, 'post_msg_id' => 0, 'poster_id' => 2), // TODO should be deleted: PHPBB3-13089 + ), + ), + ); + } + + /** + * @dataProvider report_attachment_data + */ + public function test_report_attachment_info($mode, $expected_posts, $expected_reports, $expected_topics, $expected_attach) + { + $this->assertFalse(user_delete($mode, 2)); + + $sql = 'SELECT post_id, post_reported, post_edit_user, post_delete_user + FROM ' . POSTS_TABLE . ' + ORDER BY post_id ASC'; + $result = $this->db->sql_query($sql); + $this->assertEquals($expected_posts, $this->db->sql_fetchrowset($result), 'Post report status content is mismatching after deleting a user.'); + $this->db->sql_freeresult($result); + + $sql = 'SELECT report_id, post_id, user_id + FROM ' . REPORTS_TABLE . ' + ORDER BY report_id ASC'; + $result = $this->db->sql_query($sql); + $this->assertEquals($expected_reports, $this->db->sql_fetchrowset($result), 'Report table content is mismatching after deleting a user.'); + $this->db->sql_freeresult($result); + + $sql = 'SELECT topic_id, topic_reported, topic_delete_user + FROM ' . TOPICS_TABLE . ' + ORDER BY topic_id ASC'; + $result = $this->db->sql_query($sql); + $this->assertEquals($expected_topics, $this->db->sql_fetchrowset($result), 'Topic report status is mismatching after deleting a user.'); + $this->db->sql_freeresult($result); + + $sql = 'SELECT attach_id, post_msg_id, poster_id + FROM ' . ATTACHMENTS_TABLE . ' + ORDER BY attach_id ASC'; + $result = $this->db->sql_query($sql); + $this->assertEquals($expected_attach, $this->db->sql_fetchrowset($result), 'Attachment table content is mismatching after deleting a user.'); + $this->db->sql_freeresult($result); + } + + public function delete_data() + { + return array( + array( + 'retain', + array(array('user_id' => 1, 'user_posts' => 4)), + array(array('user_id' => 1, 'zebra_id' => 3)), + array(array('ban_id' => 2), array('ban_id' => 3)), + array(array('session_id' => '12345678901234567890123456789013')), + array( + array('log_id' => 2, 'user_id' => 1, 'reportee_id' => 1), + array('log_id' => 3, 'user_id' => 1, 'reportee_id' => 1), + ), + array( + array('msg_id' => 1, 'author_id' => 3, 'message_edit_user' => 3), + array('msg_id' => 2, 'author_id' => 1, 'message_edit_user' => 1), + ), + ), + array( + 'remove', + array(array('user_id' => 1, 'user_posts' => 2)), + array(array('user_id' => 1, 'zebra_id' => 3)), + array(array('ban_id' => 2), array('ban_id' => 3)), + array(array('session_id' => '12345678901234567890123456789013')), + array( + array('log_id' => 2, 'user_id' => 1, 'reportee_id' => 1), + array('log_id' => 3, 'user_id' => 1, 'reportee_id' => 1), + ), + array( + array('msg_id' => 1, 'author_id' => 3, 'message_edit_user' => 3), + array('msg_id' => 2, 'author_id' => 1, 'message_edit_user' => 1), + ), + ), + ); + } + + /** + * @dataProvider delete_data + */ + public function test_delete_data($mode, $expected_users, $expected_zebra, $expected_ban, $expected_sessions, $expected_logs, $expected_pms) + { + $this->assertFalse(user_delete($mode, 2)); + + $sql = 'SELECT user_id, user_posts + FROM ' . USERS_TABLE . ' + ORDER BY user_id ASC'; + $result = $this->db->sql_query($sql); + $this->assertEquals($expected_users, $this->db->sql_fetchrowset($result), 'User table content is mismatching after deleting a user.'); + $this->db->sql_freeresult($result); + + $sql = 'SELECT user_id, zebra_id + FROM ' . ZEBRA_TABLE . ' + ORDER BY user_id ASC, zebra_id ASC'; + $result = $this->db->sql_query($sql); + $this->assertEquals($expected_zebra, $this->db->sql_fetchrowset($result), 'Zebra table content is mismatching after deleting a user.'); + $this->db->sql_freeresult($result); + + $sql = 'SELECT ban_id + FROM ' . BANLIST_TABLE . ' + ORDER BY ban_id ASC'; + $result = $this->db->sql_query($sql); + $this->assertEquals($expected_ban, $this->db->sql_fetchrowset($result), 'Ban table content is mismatching after deleting a user.'); + $this->db->sql_freeresult($result); + + $sql = 'SELECT session_id + FROM ' . SESSIONS_TABLE . ' + ORDER BY session_id ASC'; + $result = $this->db->sql_query($sql); + $this->assertEquals($expected_sessions, $this->db->sql_fetchrowset($result), 'Session table content is mismatching after deleting a user.'); + $this->db->sql_freeresult($result); + + $sql = 'SELECT log_id, user_id, reportee_id + FROM ' . LOG_TABLE . ' + ORDER BY log_id ASC'; + $result = $this->db->sql_query($sql); + $this->assertEquals($expected_logs, $this->db->sql_fetchrowset($result), 'Log table content is mismatching after deleting a user.'); + $this->db->sql_freeresult($result); + + $sql = 'SELECT msg_id, author_id, message_edit_user + FROM ' . PRIVMSGS_TABLE . ' + ORDER BY msg_id ASC'; + $result = $this->db->sql_query($sql); + $this->assertEquals($expected_pms, $this->db->sql_fetchrowset($result), 'Private messages table content is mismatching after deleting a user.'); + $this->db->sql_freeresult($result); + } + + public function delete_user_id_data() + { + return array( + array( + 'retain', + array( + USER_GROUP_TABLE, + TOPICS_WATCH_TABLE, + FORUMS_WATCH_TABLE, + ACL_USERS_TABLE, + TOPICS_TRACK_TABLE, + TOPICS_POSTED_TABLE, + FORUMS_TRACK_TABLE, + PROFILE_FIELDS_DATA_TABLE, + MODERATOR_CACHE_TABLE, + DRAFTS_TABLE, + BOOKMARKS_TABLE, + SESSIONS_KEYS_TABLE, + PRIVMSGS_FOLDER_TABLE, + PRIVMSGS_RULES_TABLE, + ), + ), + array( + 'remove', + array( + USER_GROUP_TABLE, + TOPICS_WATCH_TABLE, + FORUMS_WATCH_TABLE, + ACL_USERS_TABLE, + TOPICS_TRACK_TABLE, + TOPICS_POSTED_TABLE, + FORUMS_TRACK_TABLE, + PROFILE_FIELDS_DATA_TABLE, + MODERATOR_CACHE_TABLE, + DRAFTS_TABLE, + BOOKMARKS_TABLE, + SESSIONS_KEYS_TABLE, + PRIVMSGS_FOLDER_TABLE, + PRIVMSGS_RULES_TABLE, + ), + ), + ); + } + + /** + * @dataProvider delete_user_id_data + */ + public function test_delete_user_id_data($mode, $cleaned_tables) + { + $this->assertFalse(user_delete($mode, 2)); + + foreach ($cleaned_tables as $table) + { + $sql = 'SELECT user_id + FROM ' . $table . ' + WHERE user_id = 2'; + $result = $this->db->sql_query($sql); + $this->assertFalse($this->db->sql_fetchfield('user_id'), 'Found data for deleted user in table: ' . $table); + $this->db->sql_freeresult($result); + + $sql = 'SELECT user_id + FROM ' . $table . ' + WHERE user_id = 3'; + $result = $this->db->sql_query($sql); + $this->assertEquals(3, $this->db->sql_fetchfield('user_id'), 'Missing data for user in table: ' . $table); + $this->db->sql_freeresult($result); + } + } +} diff --git a/tests/functions_user/fixtures/delete_user.xml b/tests/functions_user/fixtures/delete_user.xml new file mode 100644 index 0000000000..56014b35d1 --- /dev/null +++ b/tests/functions_user/fixtures/delete_user.xml @@ -0,0 +1,549 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<dataset> + <table name="phpbb_attachments"> + <column>attach_id</column> + <column>post_msg_id</column> + <column>topic_id</column> + <column>in_message</column> + <column>poster_id</column> + <column>is_orphan</column> + <column>attach_comment</column> + <row> + <value>1</value> + <value>1</value> + <value>1</value> + <value>0</value> + <value>2</value> + <value>0</value> + <value></value> + </row> + <row> + <value>2</value> + <value>2</value> + <value>2</value> + <value>0</value> + <value>1</value> + <value>0</value> + <value></value> + </row> + <row> + <value>3</value> + <value>0</value> + <value>0</value> + <value>0</value> + <value>2</value> + <value>1</value> + <value></value> + </row> + </table> + <table name="phpbb_banlist"> + <column>ban_id</column> + <column>ban_userid</column> + <column>ban_email</column> + <column>ban_reason</column> + <column>ban_give_reason</column> + <row> + <value>1</value> + <value>2</value> + <value></value> + <value></value> + <value></value> + </row> + <row> + <value>2</value> + <value>3</value> + <value></value> + <value></value> + <value></value> + </row> + <row> + <value>3</value> + <value>0</value> + <value></value> + <value></value> + <value></value> + </row> + </table> + <table name="phpbb_forums"> + <column>forum_id</column> + <column>forum_last_poster_id</column> + <column>forum_last_poster_name</column> + <column>forum_last_poster_colour</column> + <column>forum_parents</column> + <column>forum_desc</column> + <column>forum_rules</column> + <row> + <value>1</value> + <value>2</value> + <value></value> + <value>00AA00</value> + <value></value> + <value></value> + <value></value> + </row> + <row> + <value>2</value> + <value>1</value> + <value>Other</value> + <value></value> + <value></value> + <value></value> + <value></value> + </row> + <row> + <value>3</value> + <value>2</value> + <value></value> + <value>00AA00</value> + <value></value> + <value></value> + <value></value> + </row> + <row> + <value>4</value> + <value>1</value> + <value>Other</value> + <value></value> + <value></value> + <value></value> + <value></value> + </row> + </table> + <table name="phpbb_log"> + <column>log_id</column> + <column>user_id</column> + <column>reportee_id</column> + <column>log_operation</column> + <column>log_data</column> + <row> + <value>1</value> + <value>1</value> + <value>2</value> + <value></value> + <value></value> + </row> + <row> + <value>2</value> + <value>2</value> + <value>1</value> + <value></value> + <value></value> + </row> + <row> + <value>3</value> + <value>1</value> + <value>1</value> + <value></value> + <value></value> + </row> + <row> + <value>4</value> + <value>2</value> + <value>2</value> + <value></value> + <value></value> + </row> + </table> + <table name="phpbb_posts"> + <column>post_id</column> + <column>poster_id</column> + <column>post_edit_user</column> + <column>post_delete_user</column> + <column>post_username</column> + <column>topic_id</column> + <column>forum_id</column> + <column>post_visibility</column> + <column>post_time</column> + <column>post_text</column> + <column>post_reported</column> + <row> + <value>1</value> + <value>2</value> + <value>2</value> + <value>2</value> + <value></value> + <value>1</value> + <value>1</value> + <value>1</value> + <value>1</value> + <value></value> + <value>1</value> + </row> + <row> + <value>2</value> + <value>1</value> + <value>1</value> + <value>1</value> + <value>Other</value> + <value>2</value> + <value>2</value> + <value>1</value> + <value>1</value> + <value></value> + <value>1</value> + </row> + <row> + <value>3</value> + <value>2</value> + <value>2</value> + <value>2</value> + <value></value> + <value>3</value> + <value>3</value> + <value>1</value> + <value>1</value> + <value></value> + <value>1</value> + </row> + <row> + <value>4</value> + <value>1</value> + <value>1</value> + <value>1</value> + <value>Other</value> + <value>4</value> + <value>4</value> + <value>1</value> + <value>1</value> + <value></value> + <value>1</value> + </row> + </table> + <table name="phpbb_privmsgs"> + <column>msg_id</column> + <column>author_id</column> + <column>message_edit_user</column> + <column>message_text</column> + <column>to_address</column> + <column>bcc_address</column> + <row> + <value>1</value> + <value>3</value> + <value>3</value> + <value></value> + <value></value> + <value></value> + </row> + <row> + <value>2</value> + <value>2</value> + <value>2</value> + <value></value> + <value></value> + <value></value> + </row> + </table> + <table name="phpbb_privmsgs_to"> + <column>msg_id</column> + <column>user_id</column> + <column>author_id</column> + <row> + <value>1</value> + <value>3</value> + <value>3</value> + </row> + <row> + <value>1</value> + <value>2</value> + <value>3</value> + </row> + <row> + <value>2</value> + <value>3</value> + <value>2</value> + </row> + <row> + <value>2</value> + <value>2</value> + <value>2</value> + </row> + </table> + <table name="phpbb_reports"> + <column>report_id</column> + <column>post_id</column> + <column>user_id</column> + <column>report_text</column> + <column>reported_post_text</column> + <row> + <value>1</value> + <value>1</value> + <value>1</value> + <value>Post Removed?</value> + <value></value> + </row> + <row> + <value>2</value> + <value>3</value> + <value>2</value> + <value>Post Removed?</value> + <value></value> + </row> + <row> + <value>3</value> + <value>2</value> + <value>1</value> + <value>Keep</value> + <value></value> + </row> + <row> + <value>4</value> + <value>4</value> + <value>2</value> + <value>Remove Report</value> + <value></value> + </row> + </table> + <table name="phpbb_sessions"> + <column>session_id</column> + <column>session_user_id</column> + <column>session_page</column> + <row> + <value>12345678901234567890123456789012</value> + <value>2</value> + <value></value> + </row> + <row> + <value>12345678901234567890123456789013</value> + <value>3</value> + <value></value> + </row> + </table> + <table name="phpbb_topics"> + <column>topic_id</column> + <column>forum_id</column> + <column>topic_reported</column> + <column>topic_poster</column> + <column>topic_delete_user</column> + <column>topic_first_poster_name</column> + <column>topic_first_poster_colour</column> + <column>topic_last_poster_id</column> + <column>topic_last_poster_name</column> + <column>topic_last_poster_colour</column> + <row> + <value>1</value> + <value>1</value> + <value>1</value> + <value>2</value> + <value>2</value> + <value></value> + <value>00AA00</value> + <value>2</value> + <value></value> + <value>00AA00</value> + </row> + <row> + <value>2</value> + <value>2</value> + <value>1</value> + <value>1</value> + <value>1</value> + <value>Other</value> + <value></value> + <value>1</value> + <value>Other</value> + <value></value> + </row> + <row> + <value>3</value> + <value>3</value> + <value>1</value> + <value>2</value> + <value>2</value> + <value></value> + <value>00AA00</value> + <value>2</value> + <value></value> + <value>00AA00</value> + </row> + <row> + <value>4</value> + <value>4</value> + <value>1</value> + <value>1</value> + <value>1</value> + <value>Other</value> + <value></value> + <value>1</value> + <value>Other</value> + <value></value> + </row> + </table> + <table name="phpbb_users"> + <column>user_id</column> + <column>username</column> + <column>username_clean</column> + <column>user_permissions</column> + <column>user_sig</column> + <column>user_posts</column> + <row> + <value>1</value> + <value>Anonymous</value> + <value>anonymous</value> + <value></value> + <value></value> + <value>2</value> + </row> + <row> + <value>2</value> + <value>Foobar</value> + <value>foobar</value> + <value></value> + <value></value> + <value>2</value> + </row> + </table> + <table name="phpbb_zebra"> + <column>user_id</column> + <column>zebra_id</column> + <row> + <value>1</value> + <value>2</value> + </row> + <row> + <value>1</value> + <value>3</value> + </row> + <row> + <value>2</value> + <value>1</value> + </row> + </table> + <table name="phpbb_user_group"> + <column>user_id</column> + <row> + <value>2</value> + </row> + <row> + <value>3</value> + </row> + </table> + <table name="phpbb_topics_watch"> + <column>user_id</column> + <row> + <value>2</value> + </row> + <row> + <value>3</value> + </row> + </table> + <table name="phpbb_forums_watch"> + <column>user_id</column> + <row> + <value>2</value> + </row> + <row> + <value>3</value> + </row> + </table> + <table name="phpbb_acl_users"> + <column>user_id</column> + <row> + <value>2</value> + </row> + <row> + <value>3</value> + </row> + </table> + <table name="phpbb_topics_track"> + <column>user_id</column> + <row> + <value>2</value> + </row> + <row> + <value>3</value> + </row> + </table> + <table name="phpbb_forums_track"> + <column>user_id</column> + <row> + <value>2</value> + </row> + <row> + <value>3</value> + </row> + </table> + <table name="phpbb_topics_posted"> + <column>user_id</column> + <row> + <value>2</value> + </row> + <row> + <value>3</value> + </row> + </table> + <table name="phpbb_profile_fields_data"> + <column>user_id</column> + <column>pf_phpbb_interests</column> + <column>pf_phpbb_occupation</column> + <row> + <value>2</value> + <value></value> + <value></value> + </row> + <row> + <value>3</value> + <value></value> + <value></value> + </row> + </table> + <table name="phpbb_moderator_cache"> + <column>user_id</column> + <row> + <value>2</value> + </row> + <row> + <value>3</value> + </row> + </table> + <table name="phpbb_bookmarks"> + <column>user_id</column> + <row> + <value>2</value> + </row> + <row> + <value>3</value> + </row> + </table> + <table name="phpbb_sessions_keys"> + <column>user_id</column> + <row> + <value>2</value> + </row> + <row> + <value>3</value> + </row> + </table> + <table name="phpbb_privmsgs_folder"> + <column>user_id</column> + <row> + <value>2</value> + </row> + <row> + <value>3</value> + </row> + </table> + <table name="phpbb_privmsgs_rules"> + <column>user_id</column> + <column>rule_string</column> + <row> + <value>2</value> + <value></value> + </row> + <row> + <value>3</value> + <value></value> + </row> + </table> + <table name="phpbb_drafts"> + <column>user_id</column> + <column>draft_message</column> + <row> + <value>2</value> + <value></value> + </row> + <row> + <value>3</value> + <value></value> + </row> + </table> +</dataset> diff --git a/tests/groupposition/legend_test.php b/tests/groupposition/legend_test.php index 4bad598a31..fe003e93a7 100644 --- a/tests/groupposition/legend_test.php +++ b/tests/groupposition/legend_test.php @@ -37,7 +37,7 @@ class phpbb_groupposition_legend_test extends phpbb_database_test_case $cache = new phpbb_mock_cache; $db = $this->new_dbal(); - $user = new \phpbb\user; + $user = new \phpbb\user('\phpbb\datetime'); $user->lang = array(); if ($throws_exception) @@ -55,7 +55,7 @@ class phpbb_groupposition_legend_test extends phpbb_database_test_case $cache = new phpbb_mock_cache; $db = $this->new_dbal(); - $user = new \phpbb\user; + $user = new \phpbb\user('\phpbb\datetime'); $user->lang = array(); $test_class = new \phpbb\groupposition\legend($db, $user); @@ -95,7 +95,7 @@ class phpbb_groupposition_legend_test extends phpbb_database_test_case $cache = new phpbb_mock_cache; $db = $this->new_dbal(); - $user = new \phpbb\user; + $user = new \phpbb\user('\phpbb\datetime'); $user->lang = array(); $test_class = new \phpbb\groupposition\legend($db, $user); @@ -183,7 +183,7 @@ class phpbb_groupposition_legend_test extends phpbb_database_test_case $cache = new phpbb_mock_cache; $db = $this->new_dbal(); - $user = new \phpbb\user; + $user = new \phpbb\user('\phpbb\datetime'); $user->lang = array(); $test_class = new \phpbb\groupposition\legend($db, $user); @@ -238,7 +238,7 @@ class phpbb_groupposition_legend_test extends phpbb_database_test_case $cache = new phpbb_mock_cache; $db = $this->new_dbal(); - $user = new \phpbb\user; + $user = new \phpbb\user('\phpbb\datetime'); $user->lang = array(); $test_class = new \phpbb\groupposition\legend($db, $user); @@ -293,7 +293,7 @@ class phpbb_groupposition_legend_test extends phpbb_database_test_case $cache = new phpbb_mock_cache; $db = $this->new_dbal(); - $user = new \phpbb\user; + $user = new \phpbb\user('\phpbb\datetime'); $user->lang = array(); $test_class = new \phpbb\groupposition\legend($db, $user); @@ -391,7 +391,7 @@ class phpbb_groupposition_legend_test extends phpbb_database_test_case $cache = new phpbb_mock_cache; $db = $this->new_dbal(); - $user = new \phpbb\user; + $user = new \phpbb\user('\phpbb\datetime'); $user->lang = array(); $test_class = new \phpbb\groupposition\legend($db, $user); diff --git a/tests/groupposition/teampage_test.php b/tests/groupposition/teampage_test.php index dbdeb35e9f..1e61e3ebfb 100644 --- a/tests/groupposition/teampage_test.php +++ b/tests/groupposition/teampage_test.php @@ -39,7 +39,7 @@ class phpbb_groupposition_teampage_test extends phpbb_database_test_case $cache = new phpbb_mock_cache; $db = $this->new_dbal(); - $user = new \phpbb\user; + $user = new \phpbb\user('\phpbb\datetime'); $user->lang = array(); if ($throws_exception) @@ -57,7 +57,7 @@ class phpbb_groupposition_teampage_test extends phpbb_database_test_case $cache = new phpbb_mock_cache; $db = $this->new_dbal(); - $user = new \phpbb\user; + $user = new \phpbb\user('\phpbb\datetime'); $user->lang = array(); $test_class = new \phpbb\groupposition\teampage($db, $user, $cache); @@ -141,7 +141,7 @@ class phpbb_groupposition_teampage_test extends phpbb_database_test_case $cache = new phpbb_mock_cache; $db = $this->new_dbal(); - $user = new \phpbb\user; + $user = new \phpbb\user('\phpbb\datetime'); $user->lang = array(); $test_class = new \phpbb\groupposition\teampage($db, $user, $cache); @@ -184,7 +184,7 @@ class phpbb_groupposition_teampage_test extends phpbb_database_test_case $cache = new phpbb_mock_cache; $db = $this->new_dbal(); - $user = new \phpbb\user; + $user = new \phpbb\user('\phpbb\datetime'); $user->lang = array(); $test_class = new \phpbb\groupposition\teampage($db, $user, $cache); @@ -251,7 +251,7 @@ class phpbb_groupposition_teampage_test extends phpbb_database_test_case $cache = new phpbb_mock_cache; $db = $this->new_dbal(); - $user = new \phpbb\user; + $user = new \phpbb\user('\phpbb\datetime'); $user->lang = array(); $test_class = new \phpbb\groupposition\teampage($db, $user, $cache); @@ -303,7 +303,7 @@ class phpbb_groupposition_teampage_test extends phpbb_database_test_case $cache = new phpbb_mock_cache; $db = $this->new_dbal(); - $user = new \phpbb\user; + $user = new \phpbb\user('\phpbb\datetime'); $user->lang = array(); $test_class = new \phpbb\groupposition\teampage($db, $user, $cache); @@ -466,7 +466,7 @@ class phpbb_groupposition_teampage_test extends phpbb_database_test_case $cache = new phpbb_mock_cache; $db = $this->new_dbal(); - $user = new \phpbb\user; + $user = new \phpbb\user('\phpbb\datetime'); $user->lang = array(); $test_class = new \phpbb\groupposition\teampage($db, $user, $cache); @@ -629,7 +629,7 @@ class phpbb_groupposition_teampage_test extends phpbb_database_test_case $cache = new phpbb_mock_cache; $db = $this->new_dbal(); - $user = new \phpbb\user; + $user = new \phpbb\user('\phpbb\datetime'); $user->lang = array(); $test_class = new \phpbb\groupposition\teampage($db, $user, $cache); diff --git a/tests/lock/flock_test.php b/tests/lock/flock_test.php index 0ff38b6cc8..554b7e57f4 100644 --- a/tests/lock/flock_test.php +++ b/tests/lock/flock_test.php @@ -83,9 +83,9 @@ class phpbb_lock_flock_test extends phpbb_test_case sleep(1); $lock = new \phpbb\lock\flock($path); - $start = time(); + $start = microtime(true); $ok = $lock->acquire(); - $delta = time() - $start; + $delta = microtime(true) - $start; $this->assertTrue($ok); $this->assertTrue($lock->owns_lock()); $this->assertGreaterThan(0.5, $delta, 'First lock acquired too soon'); @@ -94,9 +94,9 @@ class phpbb_lock_flock_test extends phpbb_test_case $this->assertFalse($lock->owns_lock()); // acquire again, this should be instantaneous - $start = time(); + $start = microtime(true); $ok = $lock->acquire(); - $delta = time() - $start; + $delta = microtime(true) - $start; $this->assertTrue($ok); $this->assertTrue($lock->owns_lock()); $this->assertLessThan(0.1, $delta, 'Second lock not acquired instantaneously'); diff --git a/tests/log/add_test.php b/tests/log/add_test.php index d7e3760f0f..bacc0c76f7 100644 --- a/tests/log/add_test.php +++ b/tests/log/add_test.php @@ -27,7 +27,7 @@ class phpbb_log_add_test extends phpbb_database_test_case $db = $this->new_dbal(); $cache = new phpbb_mock_cache; $phpbb_dispatcher = new phpbb_mock_event_dispatcher(); - $user = $this->getMock('\phpbb\user'); + $user = new \phpbb\user('\phpbb\datetime'); $auth = $this->getMock('\phpbb\auth\auth'); $log = new \phpbb\log\log($db, $user, $auth, $phpbb_dispatcher, $phpbb_root_path, 'adm/', $phpEx, LOG_TABLE); @@ -56,7 +56,7 @@ class phpbb_log_add_test extends phpbb_database_test_case $db = $this->new_dbal(); $cache = new phpbb_mock_cache; $phpbb_dispatcher = new phpbb_mock_event_dispatcher(); - $user = $this->getMock('\phpbb\user'); + $user = new \phpbb\user('\phpbb\datetime'); $auth = $this->getMock('\phpbb\auth\auth'); $log = new \phpbb\log\log($db, $user, $auth, $phpbb_dispatcher, $phpbb_root_path, 'adm/', $phpEx, LOG_TABLE); diff --git a/tests/log/delete_test.php b/tests/log/delete_test.php index b8be15efa5..ec43182a0c 100644 --- a/tests/log/delete_test.php +++ b/tests/log/delete_test.php @@ -30,7 +30,7 @@ class phpbb_log_delete_test extends phpbb_database_test_case $db = $this->new_dbal(); $phpbb_dispatcher = new phpbb_mock_event_dispatcher(); - $user = $this->getMock('\phpbb\user'); + $user = new \phpbb\user('\phpbb\datetime'); $user->data['user_id'] = 1; $auth = $this->getMock('\phpbb\auth\auth'); diff --git a/tests/log/function_add_log_test.php b/tests/log/function_add_log_test.php index 99d412537c..63e468498e 100644 --- a/tests/log/function_add_log_test.php +++ b/tests/log/function_add_log_test.php @@ -161,7 +161,7 @@ class phpbb_log_function_add_log_test extends phpbb_database_test_case $db = $this->new_dbal(); $cache = new phpbb_mock_cache; $phpbb_dispatcher = new phpbb_mock_event_dispatcher(); - $user = $this->getMock('\phpbb\user'); + $user = $this->getMock('\phpbb\user', array(), array('\phpbb\datetime')); $auth = $this->getMock('\phpbb\auth\auth'); $phpbb_log = new \phpbb\log\log($db, $user, $auth, $phpbb_dispatcher, $phpbb_root_path, 'adm/', $phpEx, LOG_TABLE); diff --git a/tests/mimetype/guesser_test.php b/tests/mimetype/guesser_test.php index b74a9f236e..fa53e6c8c4 100644 --- a/tests/mimetype/guesser_test.php +++ b/tests/mimetype/guesser_test.php @@ -206,4 +206,25 @@ class guesser_test extends \phpbb_test_case $this->assertInstanceOf('\phpbb\mimetype\content_guesser', $guessers[0]); $this->assertInstanceOf('\phpbb\mimetype\extension_guesser', $guessers[3]); } + + public function data_choose_mime_type() + { + return array( + array('application/octet-stream', 'application/octet-stream', null), + array('application/octet-stream', 'application/octet-stream', 'application/octet-stream'), + array('binary', 'application/octet-stream', 'binary'), + array('image/jpeg', 'application/octet-stream', 'image/jpeg'), + array('image/jpeg', 'binary', 'image/jpeg'), + array('image/jpeg', 'image/jpg', 'image/jpeg'), + array('image/jpeg', 'image/jpeg', 'binary'), + ); + } + + /** + * @dataProvider data_choose_mime_type + */ + public function test_choose_mime_type($expected, $mime_type, $guess) + { + $this->assertSame($expected, $this->guesser->choose_mime_type($mime_type, $guess)); + } } diff --git a/tests/mock/controller_helper.php b/tests/mock/controller_helper.php index f9d231258e..9c13c309f2 100644 --- a/tests/mock/controller_helper.php +++ b/tests/mock/controller_helper.php @@ -13,11 +13,13 @@ class phpbb_mock_controller_helper extends \phpbb\controller\helper { - public function __construct(\phpbb\template\template $template, \phpbb\user $user, \phpbb\config\config $config, \phpbb\controller\provider $provider, \phpbb\extension\manager $manager, $phpbb_root_path, $php_ext, $phpbb_root_path_ext) + public function __construct(\phpbb\template\template $template, \phpbb\user $user, \phpbb\config\config $config, \phpbb\controller\provider $provider, \phpbb\extension\manager $manager, \phpbb\symfony_request $symfony_request, \phpbb\filesystem $filesystem, $phpbb_root_path, $php_ext, $phpbb_root_path_ext) { $this->template = $template; $this->user = $user; $this->config = $config; + $this->symfony_request = $symfony_request; + $this->filesystem = $filesystem; $this->phpbb_root_path = $phpbb_root_path; $this->php_ext = $php_ext; $provider->find_routing_files($manager->get_finder()); diff --git a/tests/mock/event_dispatcher.php b/tests/mock/event_dispatcher.php index 613551bffd..fa8b4a1036 100644 --- a/tests/mock/event_dispatcher.php +++ b/tests/mock/event_dispatcher.php @@ -11,9 +11,18 @@ * */ -class phpbb_mock_event_dispatcher +class phpbb_mock_event_dispatcher extends \phpbb\event\dispatcher { - public function trigger_event($eventName, $data) + /** + * Constructor. + * + * Overwrite the constructor to get rid of ContainerInterface param instance + */ + public function __construct() + { + } + + public function trigger_event($eventName, $data = array()) { return array(); } diff --git a/tests/mock/extension_manager.php b/tests/mock/extension_manager.php index 1a475f62e0..3b759fbbc2 100644 --- a/tests/mock/extension_manager.php +++ b/tests/mock/extension_manager.php @@ -13,11 +13,12 @@ class phpbb_mock_extension_manager extends \phpbb\extension\manager { - public function __construct($phpbb_root_path, $extensions = array()) + public function __construct($phpbb_root_path, $extensions = array(), $container = null) { $this->phpbb_root_path = $phpbb_root_path; $this->php_ext = 'php'; $this->extensions = $extensions; $this->filesystem = new \phpbb\filesystem(); + $this->container = $container; } } diff --git a/tests/mock/migrator.php b/tests/mock/migrator.php new file mode 100644 index 0000000000..293f115335 --- /dev/null +++ b/tests/mock/migrator.php @@ -0,0 +1,55 @@ +<?php +/** +* +* This file is part of the phpBB Forum Software package. +* +* @copyright (c) phpBB Limited <https://www.phpbb.com> +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ + +class phpbb_mock_migrator extends \phpbb\db\migrator +{ + public function __construct() + { + } + + public function load_migration_state() + { + } + + public function set_migrations($class_names) + { + } + + public function update() + { + } + + public function revert($migration) + { + } + + public function unfulfillable($name) + { + } + + public function finished() + { + } + + public function migration_state($migration) + { + } + + public function populate_migrations($migrations) + { + } + + public function create_migrations_table() + { + } +} diff --git a/tests/notification/base.php b/tests/notification/base.php index a66e5986fd..c97b7c24e2 100644 --- a/tests/notification/base.php +++ b/tests/notification/base.php @@ -21,21 +21,21 @@ abstract class phpbb_tests_notification_base extends phpbb_database_test_case { return array( 'test', - 'approve_post', - 'approve_topic', - 'bookmark', - 'disapprove_post', - 'disapprove_topic', - 'pm', - 'post', - 'post_in_queue', - 'quote', - 'report_pm', - 'report_pm_closed', - 'report_post', - 'report_post_closed', - 'topic', - 'topic_in_queue', + 'notification.type.approve_post', + 'notification.type.approve_topic', + 'notification.type.bookmark', + 'notification.type.disapprove_post', + 'notification.type.disapprove_topic', + 'notification.type.pm', + 'notification.type.post', + 'notification.type.post_in_queue', + 'notification.type.quote', + 'notification.type.report_pm', + 'notification.type.report_pm_closed', + 'notification.type.report_post', + 'notification.type.report_post_closed', + 'notification.type.topic', + 'notification.type.topic_in_queue', ); } @@ -56,7 +56,7 @@ abstract class phpbb_tests_notification_base extends phpbb_database_test_case 'allow_topic_notify' => true, 'allow_forum_notify' => true, )); - $user = $this->user = new \phpbb\user(); + $user = $this->user = new \phpbb\user('\phpbb\datetime'); $this->user_loader = new \phpbb\user_loader($this->db, $phpbb_root_path, $phpEx, 'phpbb_users'); $auth = $this->auth = new phpbb_mock_notifications_auth(); $cache = $this->cache = new \phpbb\cache\service( @@ -92,10 +92,11 @@ abstract class phpbb_tests_notification_base extends phpbb_database_test_case $types = array(); foreach ($this->get_notification_types() as $type) { - $class = $this->build_type('phpbb\notification\type\\' . $type); + $type_parts = explode('.', $type); + $class = $this->build_type('phpbb\notification\type\\' . array_pop($type_parts)); $types[$type] = $class; - $this->container->set('notification.type.' . $type, $class); + $this->container->set($type, $class); } $this->notifications->set_var('notification_types', $types); diff --git a/tests/notification/fixtures/submit_post_bookmark.xml b/tests/notification/fixtures/submit_post_notification.type.bookmark.xml index 525d0484e0..a1413e2cf8 100644 --- a/tests/notification/fixtures/submit_post_bookmark.xml +++ b/tests/notification/fixtures/submit_post_notification.type.bookmark.xml @@ -50,7 +50,7 @@ <column>notification_type_enabled</column> <row> <value>1</value> - <value>bookmark</value> + <value>notification.type.bookmark</value> <value>1</value> </row> </table> @@ -123,35 +123,35 @@ <column>method</column> <column>notify</column> <row> - <value>bookmark</value> + <value>notification.type.bookmark</value> <value>0</value> <value>2</value> <value></value> <value>1</value> </row> <row> - <value>bookmark</value> + <value>notification.type.bookmark</value> <value>0</value> <value>3</value> <value></value> <value>1</value> </row> <row> - <value>bookmark</value> + <value>notification.type.bookmark</value> <value>0</value> <value>4</value> <value></value> <value>1</value> </row> <row> - <value>bookmark</value> + <value>notification.type.bookmark</value> <value>0</value> <value>5</value> <value></value> <value>1</value> </row> <row> - <value>bookmark</value> + <value>notification.type.bookmark</value> <value>0</value> <value>6</value> <value></value> diff --git a/tests/notification/fixtures/submit_post_post.xml b/tests/notification/fixtures/submit_post_notification.type.post.xml index a38ca77ea0..ed75787c70 100644 --- a/tests/notification/fixtures/submit_post_post.xml +++ b/tests/notification/fixtures/submit_post_notification.type.post.xml @@ -50,7 +50,7 @@ <column>notification_type_enabled</column> <row> <value>1</value> - <value>post</value> + <value>notification.type.post</value> <value>1</value> </row> </table> @@ -153,49 +153,49 @@ <column>method</column> <column>notify</column> <row> - <value>post</value> + <value>notification.type.post</value> <value>0</value> <value>2</value> <value></value> <value>1</value> </row> <row> - <value>post</value> + <value>notification.type.post</value> <value>0</value> <value>3</value> <value></value> <value>1</value> </row> <row> - <value>post</value> + <value>notification.type.post</value> <value>0</value> <value>4</value> <value></value> <value>1</value> </row> <row> - <value>post</value> + <value>notification.type.post</value> <value>0</value> <value>5</value> <value></value> <value>1</value> </row> <row> - <value>post</value> + <value>notification.type.post</value> <value>0</value> <value>6</value> <value></value> <value>1</value> </row> <row> - <value>post</value> + <value>notification.type.post</value> <value>0</value> <value>7</value> <value></value> <value>1</value> </row> <row> - <value>post</value> + <value>notification.type.post</value> <value>0</value> <value>8</value> <value></value> diff --git a/tests/notification/fixtures/submit_post_post_in_queue.xml b/tests/notification/fixtures/submit_post_notification.type.post_in_queue.xml index 28cb69be36..2dea8e34dd 100644 --- a/tests/notification/fixtures/submit_post_post_in_queue.xml +++ b/tests/notification/fixtures/submit_post_notification.type.post_in_queue.xml @@ -22,7 +22,7 @@ <column>notification_type_enabled</column> <row> <value>1</value> - <value>post_in_queue</value> + <value>notification.type.post_in_queue</value> <value>1</value> </row> </table> @@ -107,49 +107,49 @@ <column>method</column> <column>notify</column> <row> - <value>needs_approval</value> + <value>notification.type.needs_approval</value> <value>0</value> <value>2</value> <value></value> <value>1</value> </row> <row> - <value>needs_approval</value> + <value>notification.type.needs_approval</value> <value>0</value> <value>3</value> <value></value> <value>1</value> </row> <row> - <value>needs_approval</value> + <value>notification.type.needs_approval</value> <value>0</value> <value>4</value> <value></value> <value>1</value> </row> <row> - <value>needs_approval</value> + <value>notification.type.needs_approval</value> <value>0</value> <value>5</value> <value></value> <value>1</value> </row> <row> - <value>needs_approval</value> + <value>notification.type.needs_approval</value> <value>0</value> <value>6</value> <value></value> <value>1</value> </row> <row> - <value>needs_approval</value> + <value>notification.type.needs_approval</value> <value>0</value> <value>7</value> <value></value> <value>0</value> </row> <row> - <value>needs_approval</value> + <value>notification.type.needs_approval</value> <value>0</value> <value>9</value> <value></value> diff --git a/tests/notification/fixtures/submit_post_quote.xml b/tests/notification/fixtures/submit_post_notification.type.quote.xml index 2b11992e54..dd5bc620cd 100644 --- a/tests/notification/fixtures/submit_post_quote.xml +++ b/tests/notification/fixtures/submit_post_notification.type.quote.xml @@ -22,7 +22,7 @@ <column>notification_type_enabled</column> <row> <value>1</value> - <value>quote</value> + <value>notification.type.quote</value> <value>1</value> </row> </table> @@ -95,35 +95,35 @@ <column>method</column> <column>notify</column> <row> - <value>quote</value> + <value>notification.type.quote</value> <value>0</value> <value>2</value> <value></value> <value>1</value> </row> <row> - <value>quote</value> + <value>notification.type.quote</value> <value>0</value> <value>3</value> <value></value> <value>1</value> </row> <row> - <value>quote</value> + <value>notification.type.quote</value> <value>0</value> <value>4</value> <value></value> <value>1</value> </row> <row> - <value>quote</value> + <value>notification.type.quote</value> <value>0</value> <value>5</value> <value></value> <value>1</value> </row> <row> - <value>quote</value> + <value>notification.type.quote</value> <value>0</value> <value>6</value> <value></value> diff --git a/tests/notification/fixtures/submit_post_topic.xml b/tests/notification/fixtures/submit_post_notification.type.topic.xml index 5e179d9b99..1ba8d05699 100644 --- a/tests/notification/fixtures/submit_post_topic.xml +++ b/tests/notification/fixtures/submit_post_notification.type.topic.xml @@ -42,7 +42,7 @@ <column>notification_type_enabled</column> <row> <value>1</value> - <value>topic</value> + <value>notification.type.topic</value> <value>1</value> </row> </table> @@ -103,28 +103,28 @@ <column>method</column> <column>notify</column> <row> - <value>topic</value> + <value>notification.type.topic</value> <value>0</value> <value>2</value> <value></value> <value>1</value> </row> <row> - <value>topic</value> + <value>notification.type.topic</value> <value>0</value> <value>6</value> <value></value> <value>1</value> </row> <row> - <value>topic</value> + <value>notification.type.topic</value> <value>0</value> <value>7</value> <value></value> <value>1</value> </row> <row> - <value>topic</value> + <value>notification.type.topic</value> <value>0</value> <value>8</value> <value></value> diff --git a/tests/notification/group_request_test.php b/tests/notification/group_request_test.php index 14ed4ff62c..afbc586601 100644 --- a/tests/notification/group_request_test.php +++ b/tests/notification/group_request_test.php @@ -25,8 +25,8 @@ class phpbb_notification_group_request_test extends phpbb_tests_notification_bas return array_merge( parent::get_notification_types(), array( - 'group_request', - 'group_request_approved', + 'notification.type.group_request', + 'notification.type.group_request_approved', ) ); } diff --git a/tests/notification/manager_helper.php b/tests/notification/manager_helper.php index 24030f5775..75b7275d3a 100644 --- a/tests/notification/manager_helper.php +++ b/tests/notification/manager_helper.php @@ -43,7 +43,8 @@ class phpbb_notification_manager_helper extends \phpbb\notification\manager */ public function get_item_type_class($item_type, $data = array()) { - $item_type = 'phpbb\notification\type\\' . $item_type; + $item_parts = explode('.', $item_type); + $item_type = 'phpbb\notification\type\\' . array_pop($item_parts); $item = new $item_type($this->user_loader, $this->db, $this->cache->get_driver(), $this->user, $this->auth, $this->config, $this->phpbb_root_path, $this->php_ext, $this->notification_types_table, $this->notifications_table, $this->user_notifications_table); diff --git a/tests/notification/notification_test.php b/tests/notification/notification_test.php index 27ea8ddb44..79fa5338c4 100644 --- a/tests/notification/notification_test.php +++ b/tests/notification/notification_test.php @@ -25,22 +25,22 @@ class phpbb_notification_test extends phpbb_tests_notification_base public function test_get_notification_type_id() { // They should be inserted the first time - $post_type_id = $this->notifications->get_notification_type_id('post'); - $quote_type_id = $this->notifications->get_notification_type_id('quote'); + $post_type_id = $this->notifications->get_notification_type_id('notification.type.post'); + $quote_type_id = $this->notifications->get_notification_type_id('notification.type.quote'); $test_type_id = $this->notifications->get_notification_type_id('test'); $this->assertEquals(array( 'test' => $test_type_id, - 'quote' => $quote_type_id, - 'post' => $post_type_id, + 'notification.type.quote' => $quote_type_id, + 'notification.type.post' => $post_type_id, ), $this->notifications->get_notification_type_ids(array( 'test', - 'quote', - 'post', + 'notification.type.quote', + 'notification.type.post', ) )); - $this->assertEquals($quote_type_id, $this->notifications->get_notification_type_id('quote')); + $this->assertEquals($quote_type_id, $this->notifications->get_notification_type_id('notification.type.quote')); try { @@ -58,12 +58,12 @@ class phpbb_notification_test extends phpbb_tests_notification_base $this->assertArrayHasKey('NOTIFICATION_GROUP_MISCELLANEOUS', $subscription_types); $this->assertArrayHasKey('NOTIFICATION_GROUP_POSTING', $subscription_types); - $this->assertArrayHasKey('bookmark', $subscription_types['NOTIFICATION_GROUP_POSTING']); - $this->assertArrayHasKey('post', $subscription_types['NOTIFICATION_GROUP_POSTING']); - $this->assertArrayHasKey('quote', $subscription_types['NOTIFICATION_GROUP_POSTING']); - $this->assertArrayHasKey('topic', $subscription_types['NOTIFICATION_GROUP_POSTING']); + $this->assertArrayHasKey('notification.type.bookmark', $subscription_types['NOTIFICATION_GROUP_POSTING']); + $this->assertArrayHasKey('notification.type.post', $subscription_types['NOTIFICATION_GROUP_POSTING']); + $this->assertArrayHasKey('notification.type.quote', $subscription_types['NOTIFICATION_GROUP_POSTING']); + $this->assertArrayHasKey('notification.type.topic', $subscription_types['NOTIFICATION_GROUP_POSTING']); - $this->assertArrayHasKey('pm', $subscription_types['NOTIFICATION_GROUP_MISCELLANEOUS']); + $this->assertArrayHasKey('notification.type.pm', $subscription_types['NOTIFICATION_GROUP_MISCELLANEOUS']); //get_subscription_types //get_subscription_methods @@ -72,12 +72,12 @@ class phpbb_notification_test extends phpbb_tests_notification_base public function test_subscriptions() { $expected_subscriptions = array( - 'post' => array(''), - 'topic' => array(''), - 'quote' => array(''), - 'bookmark' => array(''), + 'notification.type.post' => array(''), + 'notification.type.topic' => array(''), + 'notification.type.quote' => array(''), + 'notification.type.bookmark' => array(''), 'test' => array(''), - 'pm' => array(''), + 'notification.type.pm' => array(''), ); $subscriptions = $this->notifications->get_global_subscriptions(2); @@ -92,20 +92,20 @@ class phpbb_notification_test extends phpbb_tests_notification_base $this->assert_array_content_equals($methods, $expected_subscriptions[$item_type]); } - $this->notifications->delete_subscription('post', 0, '', 2); + $this->notifications->delete_subscription('notification.type.post', 0, '', 2); - $this->assertArrayNotHasKey('post', $this->notifications->get_global_subscriptions(2)); + $this->assertArrayNotHasKey('notification.type.post', $this->notifications->get_global_subscriptions(2)); - $this->notifications->add_subscription('post', 0, '', 2); + $this->notifications->add_subscription('notification.type.post', 0, '', 2); - $this->assertArrayHasKey('post', $this->notifications->get_global_subscriptions(2)); + $this->assertArrayHasKey('notification.type.post', $this->notifications->get_global_subscriptions(2)); } public function test_notifications() { $this->db->sql_query('DELETE FROM phpbb_notification_types'); - $types = array('quote', 'bookmark', 'post', 'test'); + $types = array('notification.type.quote', 'notification.type.bookmark', 'notification.type.post', 'test'); foreach ($types as $id => $type) { $this->db->sql_query('INSERT INTO phpbb_notification_types ' . @@ -150,7 +150,7 @@ class phpbb_notification_test extends phpbb_tests_notification_base 'post_time' => 1349413323, )); - $this->notifications->add_notifications(array('quote', 'bookmark', 'post', 'test'), array( + $this->notifications->add_notifications(array('notification.type.quote', 'notification.type.bookmark', 'notification.type.post', 'test'), array( 'post_id' => '4', 'topic_id' => '2', 'post_time' => 1349413324, @@ -166,7 +166,7 @@ class phpbb_notification_test extends phpbb_tests_notification_base 'user_id' => 0, ))); - $this->notifications->add_notifications(array('quote', 'bookmark', 'post', 'test'), array( + $this->notifications->add_notifications(array('notification.type.quote', 'notification.type.bookmark', 'notification.type.post', 'test'), array( 'post_id' => '5', 'topic_id' => '2', 'post_time' => 1349413325, @@ -258,7 +258,7 @@ class phpbb_notification_test extends phpbb_tests_notification_base 'post_time' => 1234, // change time )); - $this->notifications->update_notifications(array('quote', 'bookmark', 'post', 'test'), array( + $this->notifications->update_notifications(array('notification.type.quote', 'notification.type.bookmark', 'notification.type.post', 'test'), array( 'post_id' => '5', 'topic_id' => '2', 'poster_id' => 2, diff --git a/tests/notification/submit_post_base.php b/tests/notification/submit_post_base.php index bd926e2a98..684dd99280 100644 --- a/tests/notification/submit_post_base.php +++ b/tests/notification/submit_post_base.php @@ -85,7 +85,7 @@ abstract class phpbb_notification_submit_post_base extends phpbb_database_test_c $phpbb_dispatcher = new phpbb_mock_event_dispatcher(); // User - $user = $this->getMock('\phpbb\user'); + $user = $this->getMock('\phpbb\user', array(), array('\phpbb\datetime')); $user->ip = ''; $user->data = array( 'user_id' => 2, diff --git a/tests/notification/submit_post_type_bookmark_test.php b/tests/notification/submit_post_type_bookmark_test.php index 6d7747c2ba..7c3b9f938f 100644 --- a/tests/notification/submit_post_type_bookmark_test.php +++ b/tests/notification/submit_post_type_bookmark_test.php @@ -15,7 +15,7 @@ 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'; + protected $item_type = 'notification.type.bookmark'; public function setUp() { diff --git a/tests/notification/submit_post_type_post_in_queue_test.php b/tests/notification/submit_post_type_post_in_queue_test.php index 6bd9c8c93f..1390e92d96 100644 --- a/tests/notification/submit_post_type_post_in_queue_test.php +++ b/tests/notification/submit_post_type_post_in_queue_test.php @@ -15,7 +15,7 @@ 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'; + protected $item_type = 'notification.type.post_in_queue'; public function setUp() { diff --git a/tests/notification/submit_post_type_post_test.php b/tests/notification/submit_post_type_post_test.php index 5007424690..037c326bc0 100644 --- a/tests/notification/submit_post_type_post_test.php +++ b/tests/notification/submit_post_type_post_test.php @@ -15,7 +15,7 @@ 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'; + protected $item_type = 'notification.type.post'; public function setUp() { diff --git a/tests/notification/submit_post_type_quote_test.php b/tests/notification/submit_post_type_quote_test.php index 94979fd154..61e3840773 100644 --- a/tests/notification/submit_post_type_quote_test.php +++ b/tests/notification/submit_post_type_quote_test.php @@ -15,7 +15,7 @@ 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'; + protected $item_type = 'notification.type.quote'; public function setUp() { diff --git a/tests/notification/submit_post_type_topic_test.php b/tests/notification/submit_post_type_topic_test.php index 52e9353c7c..c095fbc4ba 100644 --- a/tests/notification/submit_post_type_topic_test.php +++ b/tests/notification/submit_post_type_topic_test.php @@ -15,7 +15,7 @@ require_once dirname(__FILE__) . '/submit_post_base.php'; class phpbb_notification_submit_post_type_topic_test extends phpbb_notification_submit_post_base { - protected $item_type = 'topic'; + protected $item_type = 'notification.type.topic'; public function setUp() { diff --git a/tests/notification/user_list_trim_test.php b/tests/notification/user_list_trim_test.php index 851c9ec221..c43eff729c 100644 --- a/tests/notification/user_list_trim_test.php +++ b/tests/notification/user_list_trim_test.php @@ -53,7 +53,7 @@ class phpbb_notification_user_list_trim_test extends phpbb_database_test_case array('u_viewprofile', 1, false), ))); - $user = new \phpbb\user(); + $user = new \phpbb\user('\phpbb\datetime'); $user->data = array('user_lang' => 'en'); $user->add_lang('common'); diff --git a/tests/pagination/pagination_test.php b/tests/pagination/pagination_test.php index ace8c1eed0..d36aa11a8a 100644 --- a/tests/pagination/pagination_test.php +++ b/tests/pagination/pagination_test.php @@ -28,15 +28,16 @@ class phpbb_pagination_pagination_test extends phpbb_template_template_test_case global $phpbb_dispatcher; - $phpbb_dispatcher = new phpbb_mock_event_dispatcher; - $this->user = $this->getMock('\phpbb\user'); + $phpbb_dispatcher = new phpbb_mock_event_dispatcher(); + $this->user = $this->getMock('\phpbb\user', array(), array('\phpbb\datetime')); $this->user->expects($this->any()) ->method('lang') ->will($this->returnCallback(array($this, 'return_callback_implode'))); + $filesystem = new \phpbb\filesystem(); $manager = new phpbb_mock_extension_manager(dirname(__FILE__) . '/', array()); $finder = new \phpbb\finder( - new \phpbb\filesystem(), + $filesystem, dirname(__FILE__) . '/', new phpbb_mock_cache() ); @@ -46,8 +47,18 @@ class phpbb_pagination_pagination_test extends phpbb_template_template_test_case $provider = new \phpbb\controller\provider(); $provider->find_routing_files($finder); $provider->find(dirname(__FILE__) . '/'); - $this->helper = new phpbb_mock_controller_helper($this->template, $this->user, $this->config, $provider, $manager, '', 'php', dirname(__FILE__) . '/'); - $this->pagination = new \phpbb\pagination($this->template, $this->user, $this->helper); + + $request = new phpbb_mock_request(); + $request->overwrite('SCRIPT_NAME', '/app.php', \phpbb\request\request_interface::SERVER); + $request->overwrite('SCRIPT_FILENAME', 'app.php', \phpbb\request\request_interface::SERVER); + $request->overwrite('REQUEST_URI', '/app.php', \phpbb\request\request_interface::SERVER); + + $symfony_request = new \phpbb\symfony_request( + $request + ); + + $this->helper = new phpbb_mock_controller_helper($this->template, $this->user, $this->config, $provider, $manager, $symfony_request, $filesystem, '', 'php', dirname(__FILE__) . '/'); + $this->pagination = new \phpbb\pagination($this->template, $this->user, $this->helper, $phpbb_dispatcher); } public function generate_template_pagination_data() @@ -110,17 +121,17 @@ class phpbb_pagination_pagination_test extends phpbb_template_template_test_case :per_page:10 :current_page:2 :base_url: - :previous::test - :else:1:test - :current:2:test/page/2 - :else:3:test/page/3 - :else:4:test/page/4 - :else:5:test/page/5 - :ellipsis:9:test/page/9 - :else:10:test/page/10 - :next::test/page/3 - :u_prev:test - :u_next:test/page/3', + :previous::/test + :else:1:/test + :current:2:/test/page/2 + :else:3:/test/page/3 + :else:4:/test/page/4 + :else:5:/test/page/5 + :ellipsis:9:/test/page/9 + :else:10:/test/page/10 + :next::/test/page/3 + :u_prev:/test + :u_next:/test/page/3', ), array( array('routes' => array( @@ -135,17 +146,17 @@ class phpbb_pagination_pagination_test extends phpbb_template_template_test_case :per_page:10 :current_page:3 :base_url: - :previous::test/page/2 - :else:1:test - :else:2:test/page/2 - :current:3:test/page/3 - :else:4:test/page/4 - :else:5:test/page/5 - :ellipsis:9:test/page/9 - :else:10:test/page/10 - :next::test/page/4 - :u_prev:test/page/2 - :u_next:test/page/4', + :previous::/test/page/2 + :else:1:/test + :else:2:/test/page/2 + :current:3:/test/page/3 + :else:4:/test/page/4 + :else:5:/test/page/5 + :ellipsis:9:/test/page/9 + :else:10:/test/page/10 + :next::/test/page/4 + :u_prev:/test/page/2 + :u_next:/test/page/4', ), ); } diff --git a/tests/path_helper/path_helper_test.php b/tests/path_helper/path_helper_test.php index 27e94d6a07..3832307897 100644 --- a/tests/path_helper/path_helper_test.php +++ b/tests/path_helper/path_helper_test.php @@ -205,6 +205,18 @@ class phpbb_path_helper_test extends phpbb_test_case array('test' => 'xyz', 'var' => 'value'), 'test=xyz&var=value', ), + array( + array('test' => null), + 'test', + ), + array( + array('test' => null, 'var' => null), + 'test&var', + ), + array( + array('test' => 'xyz', 'var' => null, 'bar' => 'value'), + 'test=xyz&var&bar=value', + ), ); } @@ -254,6 +266,21 @@ class phpbb_path_helper_test extends phpbb_test_case true, array('base' => 'mcp.php', 'params' => array('f' => '3')), ), + array( + 'index.php?ready', + false, + array('base' => 'index.php', 'params' => array('ready' => null)), + ), + array( + 'index.php?i=1&ready', + true, + array('base' => 'index.php', 'params' => array('i' => '1', 'ready' => null)), + ), + array( + 'index.php?ready&i=1', + false, + array('base' => 'index.php', 'params' => array('ready' => null, 'i' => '1')), + ), ); } diff --git a/tests/profilefields/type_bool_test.php b/tests/profilefields/type_bool_test.php index bdab179c8c..41c40ddb4b 100644 --- a/tests/profilefields/type_bool_test.php +++ b/tests/profilefields/type_bool_test.php @@ -25,7 +25,7 @@ class phpbb_profilefield_type_bool_test extends phpbb_test_case */ public function setUp() { - $user = $this->getMock('\phpbb\user'); + $user = $this->getMock('\phpbb\user', array(), array('\phpbb\datetime')); $user->expects($this->any()) ->method('lang') ->will($this->returnCallback(array($this, 'return_callback_implode'))); diff --git a/tests/profilefields/type_date_test.php b/tests/profilefields/type_date_test.php index 0ad2cde9fe..123955198e 100644 --- a/tests/profilefields/type_date_test.php +++ b/tests/profilefields/type_date_test.php @@ -25,7 +25,7 @@ class phpbb_profilefield_type_date_test extends phpbb_test_case */ public function setUp() { - $this->user = $this->getMock('\phpbb\user'); + $this->user = $this->getMock('\phpbb\user', array(), array('\phpbb\datetime')); $this->user->expects($this->any()) ->method('lang') ->will($this->returnCallback(array($this, 'return_callback_implode'))); diff --git a/tests/profilefields/type_dropdown_test.php b/tests/profilefields/type_dropdown_test.php index ebecbf97f0..3845a8e96b 100644 --- a/tests/profilefields/type_dropdown_test.php +++ b/tests/profilefields/type_dropdown_test.php @@ -25,7 +25,7 @@ class phpbb_profilefield_type_dropdown_test extends phpbb_test_case */ public function setUp() { - $user = $this->getMock('\phpbb\user'); + $user = $this->getMock('\phpbb\user', array(), array('\phpbb\datetime')); $user->expects($this->any()) ->method('lang') ->will($this->returnCallback(array($this, 'return_callback_implode'))); diff --git a/tests/profilefields/type_googleplus_test.php b/tests/profilefields/type_googleplus_test.php index fdbdd86553..f3db6ef01f 100644 --- a/tests/profilefields/type_googleplus_test.php +++ b/tests/profilefields/type_googleplus_test.php @@ -11,8 +11,27 @@ * */ +require_once __DIR__ . '/../../phpBB/includes/utf/utf_tools.php'; + class phpbb_profilefield_type_googleplus_test extends phpbb_test_case { + protected $field; + + public function setUp() + { + parent::setUp(); + + $user = new \phpbb\user('\phpbb\datetime'); + $user->add_lang('ucp'); + $request = $this->getMock('\phpbb\request\request'); + $template = $this->getMock('\phpbb\template\template'); + + $this->field = new \phpbb\profilefields\type\type_googleplus( + $request, + $template, + $user + ); + } public function get_profile_contact_value_data() { return array( @@ -36,16 +55,6 @@ class phpbb_profilefield_type_googleplus_test extends phpbb_test_case */ public function test_get_profile_contact_value($value, $field_options, $expected, $description) { - $user = $this->getMock('\phpbb\user'); - $request = $this->getMock('\phpbb\request\request'); - $template = $this->getMock('\phpbb\template\template'); - - $field = new \phpbb\profilefields\type\type_googleplus( - $request, - $template, - $user - ); - $default_field_options = array( 'field_type' => '\phpbb\profilefields\type\type_googleplus', 'field_name' => 'field', @@ -57,6 +66,29 @@ class phpbb_profilefield_type_googleplus_test extends phpbb_test_case ); $field_options = array_merge($default_field_options, $field_options); - $this->assertSame($expected, $field->get_profile_contact_value($value, $field_options), $description); + $this->assertSame($expected, $this->field->get_profile_contact_value($value, $field_options), $description); + } + + public function data_validate_googleplus() + { + return array( + array('foobar', false), + array('2342340929304', false), + array('foo<bar', 'The field “googleplus” has invalid characters.'), + array('klkd.klkl', false), + array('kl+', 'The field “googleplus” has invalid characters.'), + array('foo=bar', 'The field “googleplus” has invalid characters.'), + array('..foo', 'The field “googleplus” has invalid characters.'), + array('foo..bar', 'The field “googleplus” has invalid characters.'), + ); + } + + /** + * @dataProvider data_validate_googleplus + */ + public function test_validate_googleplus($input, $expected) + { + $field_data = array_merge(array('lang_name' => 'googleplus'), $this->field->get_default_option_values()); + $this->assertSame($expected, $this->field->validate_string_profile_field('string', $input, $field_data)); } } diff --git a/tests/profilefields/type_int_test.php b/tests/profilefields/type_int_test.php index ac48c10a84..07b22525e2 100644 --- a/tests/profilefields/type_int_test.php +++ b/tests/profilefields/type_int_test.php @@ -24,7 +24,7 @@ class phpbb_profilefield_type_int_test extends phpbb_test_case */ public function setUp() { - $user = $this->getMock('\phpbb\user'); + $user = $this->getMock('\phpbb\user', array(), array('\phpbb\datetime')); $user->expects($this->any()) ->method('lang') ->will($this->returnCallback(array($this, 'return_callback_implode'))); diff --git a/tests/profilefields/type_string_test.php b/tests/profilefields/type_string_test.php index 2277526758..a7be087fb5 100644 --- a/tests/profilefields/type_string_test.php +++ b/tests/profilefields/type_string_test.php @@ -30,7 +30,7 @@ class phpbb_profilefield_type_string_test extends phpbb_test_case { global $request, $user, $cache; - $user = $this->getMock('\phpbb\user'); + $user = $this->getMock('\phpbb\user', array(), array('\phpbb\datetime')); $cache = new phpbb_mock_cache; $user->expects($this->any()) ->method('lang') @@ -167,6 +167,55 @@ class phpbb_profilefield_type_string_test extends phpbb_test_case 'FIELD_INVALID_CHARS_ALPHA_PUNCTUATION-field', 'Required field should reject field having invalid input for the given validation', ), + // UTF-8 string tests + array( + 'ö äö äö ä', + array('field_validation' => '[\p{Lu}\p{Ll}0-9]+'), + 'FIELD_INVALID_CHARS_LETTER_NUM_ONLY-field', + 'Required field should reject spaces in UTF-8 letternumeric only field', + ), + array( + 'Имя123', + array('field_validation' => '[\p{Lu}\p{Ll}0-9]+'), + false, + 'Required field should accept UTF-8 letternumeric only field', + ), + array( + 'Ö äö äö- ä+', + array('field_validation' => '[\p{Lu}\p{Ll}0-9_]+'), + 'FIELD_INVALID_CHARS_LETTER_NUM_UNDERSCORE-field', + 'Required field should reject spacers in UTF-8 letternumeric with underscore field', + ), + array( + 'Правильное.Имя123', + array('field_validation' => '[\p{Lu}\p{Ll}0-9.]+'), + false, + 'Required field should accept UTF-8 letternumeric field with dots', + ), + array( + 'Неправильное.,имя123', + array('field_validation' => '[\p{Lu}\p{Ll}0-9.]+'), + 'FIELD_INVALID_CHARS_LETTER_NUM_DOTS-field', + 'Required field should reject comma in UTF-8 letternumeric field with dots', + ), + array( + 'Ö äö äö- ä+', + array('field_validation' => '[\p{Lu}\p{Ll}0-9\x20_+\-\[\]]+'), + false, + 'Required field should accept spacers in UTF-8 letternumeric with spacers field', + ), + array( + 'skype.test.name,_this', + array('field_validation' => '[\p{Lu}\p{Ll}][\p{Lu}\p{Ll}0-9.,\-_]+'), + false, + 'Required field should accept alphanumeric value for UTF-8 letternumeric field with punctuations', + ), + array( + '1skype.this.should.fail', + array('field_validation' => '[\p{Lu}\p{Ll}][\p{Lu}\p{Ll}0-9.,\-_]+'), + 'FIELD_INVALID_CHARS_LETTER_NUM_PUNCTUATION-field', + 'Required field should reject field having leading numeric for UTF-8 letternumeric field with punctuations', + ), ); } diff --git a/tests/profilefields/type_url_test.php b/tests/profilefields/type_url_test.php index a45a28e7c7..372c07418f 100644 --- a/tests/profilefields/type_url_test.php +++ b/tests/profilefields/type_url_test.php @@ -26,7 +26,7 @@ class phpbb_profilefield_type_url_test extends phpbb_test_case */ public function setUp() { - $user = $this->getMock('\phpbb\user'); + $user = $this->getMock('\phpbb\user', array(), array('\phpbb\datetime')); $user->expects($this->any()) ->method('lang') ->will($this->returnCallback(array($this, 'return_callback_implode'))); diff --git a/tests/security/base.php b/tests/security/base.php index 83d0649dfa..5519cac441 100644 --- a/tests/security/base.php +++ b/tests/security/base.php @@ -59,7 +59,7 @@ abstract class phpbb_security_test_base extends phpbb_test_case $phpbb_filesystem = new \phpbb\filesystem($symfony_request, $phpbb_root_path, $phpEx); // Set no user and trick a bit to circumvent errors - $user = new \phpbb\user(); + $user = new \phpbb\user('\phpbb\datetime'); $user->lang = true; $user->browser = $server['HTTP_USER_AGENT']; $user->referer = ''; diff --git a/tests/session/fixtures/sessions_empty.xml b/tests/session/fixtures/sessions_empty.xml index 2acba58f45..068951dc4c 100644 --- a/tests/session/fixtures/sessions_empty.xml +++ b/tests/session/fixtures/sessions_empty.xml @@ -30,4 +30,11 @@ <column>session_ip</column> <column>session_browser</column> </table> + <table name="phpbb_banlist"> + <column>ban_id</column> + <column>ban_userid</column> + <column>ban_email</column> + <column>ban_reason</column> + <column>ban_give_reason</column> + </table> </dataset> diff --git a/tests/session/garbage_collection_test.php b/tests/session/garbage_collection_test.php index 0fbc71dcd7..3fad81c68b 100644 --- a/tests/session/garbage_collection_test.php +++ b/tests/session/garbage_collection_test.php @@ -12,6 +12,7 @@ */ require_once dirname(__FILE__) . '/../test_framework/phpbb_session_test_case.php'; +require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php'; class phpbb_session_garbage_collection_test extends phpbb_session_test_case { @@ -26,6 +27,19 @@ class phpbb_session_garbage_collection_test extends phpbb_session_test_case { parent::setUp(); $this->session = $this->session_factory->get_session($this->db); + + global $phpbb_container; + + $plugins = new \phpbb\di\service_collection($phpbb_container); + $plugins->add('core.captcha.plugins.nogd'); + $phpbb_container->set( + 'captcha.factory', + new \phpbb\captcha\factory($phpbb_container, $plugins) + ); + $phpbb_container->set( + 'core.captcha.plugins.nogd', + new \phpbb\captcha\plugins\nogd() + ); } public function test_cleanup_all() @@ -47,7 +61,7 @@ class phpbb_session_garbage_collection_test extends phpbb_session_test_case global $config; $config['session_length'] = 0; // There is an error unless the captcha plugin is set - $config['captcha_plugin'] = 'phpbb_captcha_nogd'; + $config['captcha_plugin'] = 'core.captcha.plugins.nogd'; $this->session->session_gc(); $this->check_sessions_equals( array(), diff --git a/tests/template/template_allfolder_test.php b/tests/template/template_allfolder_test.php new file mode 100644 index 0000000000..b4ad84e9c3 --- /dev/null +++ b/tests/template/template_allfolder_test.php @@ -0,0 +1,59 @@ +<?php +/** +* +* This file is part of the phpBB Forum Software package. +* +* @copyright (c) phpBB Limited <https://www.phpbb.com> +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ + +require_once dirname(__FILE__) . '/template_test_case.php'; + +class phpbb_template_allfolder_test extends phpbb_template_template_test_case +{ + public function test_allfolder() + { + $this->setup_engine_for_allfolder(); + + $this->run_template('foobar_body.html', array(), array(), array(), "All folder"); + } + + protected function setup_engine_for_allfolder(array $new_config = array()) + { + global $phpbb_root_path, $phpEx; + + $defaults = $this->config_defaults(); + $config = new \phpbb\config\config(array_merge($defaults, $new_config)); + $this->user = new \phpbb\user('\phpbb\datetime'); + + $path_helper = new \phpbb\path_helper( + new \phpbb\symfony_request( + new phpbb_mock_request() + ), + new \phpbb\filesystem(), + $this->getMock('\phpbb\request\request'), + $phpbb_root_path, + $phpEx + ); + + $this->extension_manager = new phpbb_mock_extension_manager( + dirname(__FILE__) . '/', + array( + 'vendor4/bar' => array( + 'ext_name' => 'vendor4/bar', + 'ext_active' => '1', + 'ext_path' => 'ext/vendor4/bar/', + ), + ) + ); + + $this->template_path = $this->test_path . '/templates'; + $this->ext_template_path = 'tests/extension/ext/vendor4/bar/styles/all/template'; + $this->template = new \phpbb\template\twig\twig($path_helper, $config, $this->user, new \phpbb\template\context(), $this->extension_manager); + $this->template->set_custom_style('all', array($this->template_path, $this->ext_template_path)); + } +} diff --git a/tests/template/template_test_case.php b/tests/template/template_test_case.php index 83446b5352..1250397401 100644 --- a/tests/template/template_test_case.php +++ b/tests/template/template_test_case.php @@ -65,7 +65,7 @@ class phpbb_template_template_test_case extends phpbb_test_case $defaults = $this->config_defaults(); $config = new \phpbb\config\config(array_merge($defaults, $new_config)); - $this->user = new \phpbb\user; + $this->user = new \phpbb\user('\phpbb\datetime'); $path_helper = new \phpbb\path_helper( new \phpbb\symfony_request( diff --git a/tests/test_framework/phpbb_database_test_case.php b/tests/test_framework/phpbb_database_test_case.php index 46276bcfcb..9dbb7150f1 100644 --- a/tests/test_framework/phpbb_database_test_case.php +++ b/tests/test_framework/phpbb_database_test_case.php @@ -69,10 +69,9 @@ abstract class phpbb_database_test_case extends PHPUnit_Extensions_Database_Test global $phpbb_root_path, $phpEx, $table_prefix; $finder = new \phpbb\finder(new \phpbb\filesystem(), $phpbb_root_path, null, $phpEx); - $classes = $finder->core_path('phpbb/') - ->core_directory('/db/migration/data') + $classes = $finder->core_path('phpbb/db/migration/data/') ->set_extensions($setup_extensions) - ->extension_directory('migrations') + ->extension_directory('/migrations') ->get_classes(); $db = new \phpbb\db\driver\sqlite(); diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index 9bb4d69bf4..49cc72363e 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -11,12 +11,14 @@ * */ use Symfony\Component\BrowserKit\CookieJar; -use Behat\Mink\Driver\Goutte\Client; -use Behat\Mink\Driver\GoutteDriver; -class phpbb_functional_test_case extends phpbb_mink_test_case +require_once __DIR__ . '/../../phpBB/includes/functions_install.php'; + +class phpbb_functional_test_case extends phpbb_test_case { + static protected $client; static protected $cookieJar; + static protected $root_url; protected $cache = null; protected $db = null; @@ -34,6 +36,7 @@ class phpbb_functional_test_case extends phpbb_mink_test_case */ protected $lang = array(); + static protected $config = array(); static protected $already_installed = false; static public function setUpBeforeClass() @@ -43,24 +46,6 @@ class phpbb_functional_test_case extends phpbb_mink_test_case self::$config = phpbb_test_case_helpers::get_test_config(); self::$root_url = self::$config['phpbb_functional_url']; - self::$cookieJar = new CookieJar; - self::$client = new Client(array(), null, self::$cookieJar); - - $client_options = array( - Guzzle\Http\Client::DISABLE_REDIRECTS => true, - 'curl.options' => array( - CURLOPT_TIMEOUT => 120, - ), - ); - - self::$client->setClient(new Guzzle\Http\Client('', $client_options)); - - // Reset the curl handle because it is 0 at this point and not a valid - // resource - self::$client->getClient()->getCurlMulti()->reset(true); - - self::$driver = new GoutteDriver(self::$client); - // Important: this is used both for installation and by // test cases for querying the tables. // Therefore table prefix must be set before a board is @@ -93,6 +78,12 @@ class phpbb_functional_test_case extends phpbb_mink_test_case $this->bootstrap(); + self::$cookieJar = new CookieJar; + self::$client = new Goutte\Client(array(), null, self::$cookieJar); + // Reset the curl handle because it is 0 at this point and not a valid + // resource + self::$client->getClient()->getCurlMulti()->reset(true); + // Clear the language array so that things // that were added in other tests are gone $this->lang = array(); @@ -119,14 +110,13 @@ class phpbb_functional_test_case extends phpbb_mink_test_case protected function tearDown() { + parent::tearDown(); + if ($this->db instanceof \phpbb\db\driver\driver_interface) { // Close the database connections again this test $this->db->sql_close(); } - - self::$cookieJar->clear(); - parent::tearDown(); } /** @@ -249,7 +239,7 @@ class phpbb_functional_test_case extends phpbb_mink_test_case ); $container = new phpbb_mock_container_builder(); $container->set('migrator', $migrator); - $user = new \phpbb\user(); + $user = new \phpbb\user('\phpbb\datetime'); $extension_manager = new \phpbb\extension\manager( $container, @@ -266,6 +256,144 @@ class phpbb_functional_test_case extends phpbb_mink_test_case return $extension_manager; } + static protected function install_board() + { + global $phpbb_root_path, $phpEx; + + self::recreate_database(self::$config); + + $config_file = $phpbb_root_path . "config.$phpEx"; + $config_file_dev = $phpbb_root_path . "config_dev.$phpEx"; + $config_file_test = $phpbb_root_path . "config_test.$phpEx"; + + if (file_exists($config_file)) + { + if (!file_exists($config_file_dev)) + { + rename($config_file, $config_file_dev); + } + else + { + unlink($config_file); + } + } + + self::$cookieJar = new CookieJar; + self::$client = new Goutte\Client(array(), null, self::$cookieJar); + // Set client manually so we can increase the cURL timeout + self::$client->setClient(new Guzzle\Http\Client('', array( + Guzzle\Http\Client::DISABLE_REDIRECTS => true, + 'curl.options' => array( + CURLOPT_TIMEOUT => 120, + ), + ))); + + // Reset the curl handle because it is 0 at this point and not a valid + // resource + self::$client->getClient()->getCurlMulti()->reset(true); + + $parseURL = parse_url(self::$config['phpbb_functional_url']); + + $crawler = self::request('GET', 'install/index.php?mode=install&language=en'); + self::assertContains('Welcome to Installation', $crawler->filter('#main')->text()); + $form = $crawler->selectButton('submit')->form(); + + // install/index.php?mode=install&sub=requirements + $crawler = self::submit($form); + self::assertContains('Installation compatibility', $crawler->filter('#main')->text()); + $form = $crawler->selectButton('submit')->form(); + + // install/index.php?mode=install&sub=database + $crawler = self::submit($form); + self::assertContains('Database configuration', $crawler->filter('#main')->text()); + $form = $crawler->selectButton('submit')->form(array( + // Installer uses 3.0-style dbms name + 'dbms' => str_replace('phpbb\db\driver\\', '', self::$config['dbms']), + 'dbhost' => self::$config['dbhost'], + 'dbport' => self::$config['dbport'], + 'dbname' => self::$config['dbname'], + 'dbuser' => self::$config['dbuser'], + 'dbpasswd' => self::$config['dbpasswd'], + 'table_prefix' => self::$config['table_prefix'], + )); + + // install/index.php?mode=install&sub=database + $crawler = self::submit($form); + self::assertContains('Successful connection', $crawler->filter('#main')->text()); + $form = $crawler->selectButton('submit')->form(); + + // install/index.php?mode=install&sub=administrator + $crawler = self::submit($form); + self::assertContains('Administrator configuration', $crawler->filter('#main')->text()); + $form = $crawler->selectButton('submit')->form(array( + 'default_lang' => 'en', + 'admin_name' => 'admin', + 'admin_pass1' => 'adminadmin', + 'admin_pass2' => 'adminadmin', + 'board_email' => 'nobody@example.com', + )); + + // install/index.php?mode=install&sub=administrator + $crawler = self::submit($form); + self::assertContains('Tests passed', $crawler->filter('#main')->text()); + $form = $crawler->selectButton('submit')->form(); + + // We have to skip install/index.php?mode=install&sub=config_file + // because that step will create a config.php file if phpBB has the + // permission to do so. We have to create the config file on our own + // in order to get the DEBUG constants defined. + $config_php_data = phpbb_create_config_file_data(self::$config, self::$config['dbms'], true, false, true); + $config_created = file_put_contents($config_file, $config_php_data) !== false; + if (!$config_created) + { + self::markTestSkipped("Could not write $config_file file."); + } + + // We also have to create a install lock that is normally created by + // the installer. The file will be removed by the final step of the + // installer. + $install_lock_file = $phpbb_root_path . 'cache/install_lock'; + $lock_created = file_put_contents($install_lock_file, '') !== false; + if (!$lock_created) + { + self::markTestSkipped("Could not create $lock_created file."); + } + @chmod($install_lock_file, 0666); + + // install/index.php?mode=install&sub=advanced + $form_data = $form->getValues(); + unset($form_data['submit']); + + $crawler = self::request('POST', 'install/index.php?mode=install&sub=advanced', $form_data); + self::assertContains('The settings on this page are only necessary to set if you know that you require something different from the default.', $crawler->filter('#main')->text()); + $form = $crawler->selectButton('submit')->form(array( + 'email_enable' => true, + 'smtp_delivery' => true, + 'smtp_host' => 'nxdomain.phpbb.com', + 'smtp_auth' => 'PLAIN', + 'smtp_user' => 'nxuser', + 'smtp_pass' => 'nxpass', + 'cookie_secure' => false, + 'force_server_vars' => false, + 'server_protocol' => $parseURL['scheme'] . '://', + 'server_name' => 'localhost', + 'server_port' => isset($parseURL['port']) ? (int) $parseURL['port'] : 80, + 'script_path' => $parseURL['path'], + )); + + // install/index.php?mode=install&sub=create_table + $crawler = self::submit($form); + self::assertContains('The database tables used by phpBB', $crawler->filter('#main')->text()); + self::assertContains('have been created and populated with some initial data.', $crawler->filter('#main')->text()); + $form = $crawler->selectButton('submit')->form(); + + // install/index.php?mode=install&sub=final + $crawler = self::submit($form); + self::assertContains('You have successfully installed', $crawler->text()); + + copy($config_file, $config_file_test); + } + public function install_ext($extension) { $this->login(); @@ -284,6 +412,12 @@ class phpbb_functional_test_case extends phpbb_mink_test_case $this->logout(); } + static private function recreate_database($config) + { + $db_conn_mgr = new phpbb_database_test_connection_manager($config); + $db_conn_mgr->recreate_db(); + } + /** * Creates a new style * @@ -464,7 +598,7 @@ class phpbb_functional_test_case extends phpbb_mink_test_case $db = $this->get_db(); $phpbb_dispatcher = new phpbb_mock_event_dispatcher(); - $user = $this->getMock('\phpbb\user'); + $user = $this->getMock('\phpbb\user', array(), array('\phpbb\datetime')); $auth = $this->getMock('\phpbb\auth\auth'); $phpbb_log = new \phpbb\log\log($db, $user, $auth, $phpbb_dispatcher, $phpbb_root_path, 'adm/', $phpEx, LOG_TABLE); @@ -503,7 +637,7 @@ class phpbb_functional_test_case extends phpbb_mink_test_case $db = $this->get_db(); $phpbb_dispatcher = new phpbb_mock_event_dispatcher(); - $user = $this->getMock('\phpbb\user'); + $user = $this->getMock('\phpbb\user', array(), array('\phpbb\datetime')); $auth = $this->getMock('\phpbb\auth\auth'); $phpbb_log = new \phpbb\log\log($db, $user, $auth, $phpbb_dispatcher, $phpbb_root_path, 'adm/', $phpEx, LOG_TABLE); diff --git a/tests/test_framework/phpbb_mink_test_case.php b/tests/test_framework/phpbb_mink_test_case.php deleted file mode 100644 index ba480e35fb..0000000000 --- a/tests/test_framework/phpbb_mink_test_case.php +++ /dev/null @@ -1,183 +0,0 @@ -<?php -/** -* -* This file is part of the phpBB Forum Software package. -* -* @copyright (c) phpBB Limited <https://www.phpbb.com> -* @license GNU General Public License, version 2 (GPL-2.0) -* -* For full copyright and license information, please see -* the docs/CREDITS.txt file. -* -*/ -use \Behat\Mink\Session; - -require_once __DIR__ . '/../../phpBB/includes/functions_install.php'; - -abstract class phpbb_mink_test_case extends phpbb_test_case -{ - static protected $driver; - static protected $client; - static protected $session; - static protected $config = array(); - static protected $root_url; - - public function __construct($name = null, array $data = array(), $dataName = '') - { - parent::__construct($name, $data, $dataName); - - $this->backupStaticAttributesBlacklist += array( - 'phpbb_mink_test_case' => array('config', 'already_installed'), - ); - } - - static public function setUpBeforeClass() - { - parent::setUpBeforeClass(); - } - - public function setUp() - { - parent::setUp(); - - if (!self::$driver) - { - self::markTestSkipped('Mink driver not initialized.'); - } - - if (!self::$session) - { - self::$session = new Session(self::$driver); - } - } - - static protected function recreate_database($config) - { - $db_conn_mgr = new phpbb_database_test_connection_manager($config); - $db_conn_mgr->recreate_db(); - } - - protected function tearDown() - { - self::$session->reset(); - parent::tearDown(); - } - - static protected function visit($path) - { - self::$session->visit(self::$root_url . $path); - return self::$session->getPage(); - } - - static protected function click_submit($submit_button_id = 'submit') - { - self::$session->getPage()->findById($submit_button_id)->click(); - return self::$session->getPage(); - } - - static protected function install_board() - { - global $phpbb_root_path, $phpEx; - - self::recreate_database(self::$config); - self::$session = new Session(self::$driver); - - $config_file = $phpbb_root_path . "config.$phpEx"; - $config_file_dev = $phpbb_root_path . "config_dev.$phpEx"; - $config_file_test = $phpbb_root_path . "config_test.$phpEx"; - - if (file_exists($config_file)) - { - if (!file_exists($config_file_dev)) - { - rename($config_file, $config_file_dev); - } - else - { - unlink($config_file); - } - } - - $parseURL = parse_url(self::$config['phpbb_functional_url']); - - $page = self::visit('install/index.php?mode=install'); - self::assertContains('Welcome to Installation', $page->findById('main')->getText()); - - // install/index.php?mode=install&sub=requirements - $page = self::click_submit(); - self::assertContains('Installation compatibility', $page->findById('main')->getText()); - - // install/index.php?mode=install&sub=database - $page = self::click_submit(); - self::assertContains('Database configuration', $page->findById('main')->getText()); - - $page->findById('dbms')->setValue(str_replace('phpbb\db\driver\\', '', self::$config['dbms'])); - $page->findById('dbhost')->setValue(self::$config['dbhost']); - $page->findById('dbport')->setValue(self::$config['dbport']); - $page->findById('dbname')->setValue(self::$config['dbname']); - $page->findById('dbuser')->setValue(self::$config['dbuser']); - $page->findById('dbpasswd')->setValue(self::$config['dbpasswd']); - $page->findById('table_prefix')->setValue(self::$config['table_prefix']); - - // install/index.php?mode=install&sub=database - $page = self::click_submit(); - self::assertContains('Successful connection', $page->findById('main')->getText()); - - // install/index.php?mode=install&sub=administrator - $page = self::click_submit(); - self::assertContains('Administrator configuration', $page->findById('main')->getText()); - - $page->findById('admin_name')->setValue('admin'); - $page->findById('admin_pass1')->setValue('adminadmin'); - $page->findById('admin_pass2')->setValue('adminadmin'); - $page->findById('board_email')->setValue('nobody@example.com'); - - // install/index.php?mode=install&sub=administrator - $page = self::click_submit(); - self::assertContains('Tests passed', $page->findById('main')->getText()); - - // install/index.php?mode=install&sub=config_file - $page = self::click_submit(); - - // Installer has created a config.php file, we will overwrite it with a - // config file of our own in order to get the DEBUG constants defined - $config_php_data = phpbb_create_config_file_data(self::$config, self::$config['dbms'], true, false, true); - $config_created = file_put_contents($config_file, $config_php_data) !== false; - if (!$config_created) - { - self::markTestSkipped("Could not write $config_file file."); - } - - if (strpos($page->findById('main')->getText(), 'The configuration file has been written') === false) - { - $page = self::click_submit('dldone'); - } - self::assertContains('The configuration file has been written', $page->findById('main')->getText()); - - // install/index.php?mode=install&sub=advanced - $page = self::click_submit(); - self::assertContains('The settings on this page are only necessary to set if you know that you require something different from the default.', $page->findById('main')->getText()); - - $page->findById('smtp_delivery')->setValue('1'); - $page->findById('smtp_host')->setValue('nxdomain.phpbb.com'); - $page->findById('smtp_user')->setValue('nxuser'); - $page->findById('smtp_pass')->setValue('nxpass'); - $page->findById('server_protocol')->setValue($parseURL['scheme'] . '://'); - $page->findById('server_name')->setValue('localhost'); - $page->findById('server_port')->setValue(isset($parseURL['port']) ? $parseURL['port'] : 80); - $page->findById('script_path')->setValue($parseURL['path']); - - // install/index.php?mode=install&sub=create_table - $page = self::click_submit(); - self::assertContains('The database tables used by phpBB', $page->findById('main')->getText()); - self::assertContains('have been created and populated with some initial data.', $page->findById('main')->getText()); - - // install/index.php?mode=install&sub=final - $page = self::click_submit(); - self::assertContains('You have successfully installed', $page->getText()); - - copy($config_file, $config_file_test); - - self::$session->stop(); - } -} diff --git a/tests/user/lang_test.php b/tests/user/lang_test.php index 45c6b04c65..bb11bb63cb 100644 --- a/tests/user/lang_test.php +++ b/tests/user/lang_test.php @@ -17,7 +17,7 @@ class phpbb_user_lang_test extends phpbb_test_case { public function test_user_lang_sprintf() { - $user = new \phpbb\user; + $user = new \phpbb\user('\phpbb\datetime'); $user->lang = array( 'FOO' => 'BAR', 'BARZ' => 'PENG', @@ -99,7 +99,7 @@ class phpbb_user_lang_test extends phpbb_test_case $this->assertEquals($user->lang('ARRY', 1, 's', 2), '1 post'); // ticket PHPBB3-10345 - different plural rules, not just 0/1/2+ - $user = new \phpbb\user; + $user = new \phpbb\user('\phpbb\datetime'); $user->lang = array( 'PLURAL_RULE' => 13, 'ARRY' => array( diff --git a/tests/version/version_fetch_test.php b/tests/version/version_fetch_test.php index aa0ebaaa26..05eac58a52 100644 --- a/tests/version/version_fetch_test.php +++ b/tests/version/version_fetch_test.php @@ -33,7 +33,7 @@ class phpbb_version_helper_fetch_test extends phpbb_test_case new \phpbb\config\config(array( 'version' => '3.1.0', )), - new \phpbb\user() + new \phpbb\user('\phpbb\datetime') ); } diff --git a/tests/version/version_test.php b/tests/version/version_test.php index bc4f2c0294..ba31c79a79 100644 --- a/tests/version/version_test.php +++ b/tests/version/version_test.php @@ -30,7 +30,7 @@ class phpbb_version_helper_test extends phpbb_test_case new \phpbb\config\config(array( 'version' => '3.1.0', )), - new \phpbb\user() + new \phpbb\user('\phpbb\datetime') ); } @@ -208,7 +208,7 @@ class phpbb_version_helper_test extends phpbb_test_case new \phpbb\config\config(array( 'version' => $current_version, )), - new \phpbb\user(), + new \phpbb\user('\phpbb\datetime'), )) ->getMock() ; @@ -318,7 +318,7 @@ class phpbb_version_helper_test extends phpbb_test_case new \phpbb\config\config(array( 'version' => $current_version, )), - new \phpbb\user(), + new \phpbb\user('\phpbb\datetime'), )) ->getMock() ; diff --git a/tests/wrapper/gmgetdate_test.php b/tests/wrapper/gmgetdate_test.php index dc0e38544d..2e55a78d21 100644 --- a/tests/wrapper/gmgetdate_test.php +++ b/tests/wrapper/gmgetdate_test.php @@ -50,7 +50,18 @@ class phpbb_wrapper_gmgetdate_test extends phpbb_test_case $date_array['year'] ); - $this->assertEquals($expected, $actual); + // Calling second-granularity time functions twice isn't guaranteed to + // give the same results. As long as they're in the right order, allow + // a 1 second difference. + $this->assertGreaterThanOrEqual( + $expected, $actual, + 'Expected second time to be after (or equal to) the previous one' + ); + $this->assertLessThanOrEqual( + 1, + abs($actual - $expected), + "Expected $actual to be within 1 second of $expected." + ); if (isset($current_timezone)) { |