diff options
Diffstat (limited to 'tests')
47 files changed, 957 insertions, 193 deletions
diff --git a/tests/auth/provider_db_test.php b/tests/auth/provider_db_test.php index e33eae6b54..09ca0816bf 100644 --- a/tests/auth/provider_db_test.php +++ b/tests/auth/provider_db_test.php @@ -78,7 +78,14 @@ class phpbb_auth_provider_db_test extends phpbb_database_test_case ), ); - $this->assertEquals($expected, $provider->login('foobar', 'example')); + $login_return = $provider->login('foobar', 'example'); + $this->assertEquals($expected['status'], $login_return['status']); + $this->assertEquals($expected['error_msg'], $login_return['error_msg']); + + foreach ($expected['user_row'] as $key => $value) + { + $this->assertEquals($value, $login_return['user_row'][$key]); + } // Check if convert works $login_return = $provider->login('foobar2', 'example'); diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 40c6ef7dfa..0e81f4372a 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -33,3 +33,9 @@ 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_functional_test_case.php'; +require_once 'test_framework/phpbb_ui_test_case.php'; + +if (version_compare(PHP_VERSION, '5.3.19', ">=") && file_exists(__DIR__ . '/vendor/autoload.php')) +{ + require_once __DIR__ . '/vendor/autoload.php'; +} diff --git a/tests/composer.json b/tests/composer.json new file mode 100644 index 0000000000..69512f30a6 --- /dev/null +++ b/tests/composer.json @@ -0,0 +1,5 @@ +{ + "require-dev": { + "facebook/webdriver": "dev-master" + } +} diff --git a/tests/composer.lock b/tests/composer.lock new file mode 100644 index 0000000000..f714495d84 --- /dev/null +++ b/tests/composer.lock @@ -0,0 +1,66 @@ +{ + "_readme": [ + "This file locks the dependencies of your project to a known state", + "Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file" + ], + "hash": "cf1d8a4841e5e669b148e0df6645a788", + "packages": [ + + ], + "packages-dev": [ + { + "name": "facebook/webdriver", + "version": "dev-master", + "source": { + "type": "git", + "url": "https://github.com/facebook/php-webdriver.git", + "reference": "b6e002e5bf811a8edba393ce6872322c1b7cf796" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/facebook/php-webdriver/zipball/b6e002e5bf811a8edba393ce6872322c1b7cf796", + "reference": "b6e002e5bf811a8edba393ce6872322c1b7cf796", + "shasum": "" + }, + "require": { + "php": ">=5.3.19" + }, + "require-dev": { + "phpdocumentor/phpdocumentor": "2.*", + "phpunit/phpunit": "3.7.*" + }, + "type": "library", + "autoload": { + "classmap": [ + "lib/" + ] + }, + "notification-url": "http://packagist.org/downloads/", + "license": [ + "Apache-2.0" + ], + "description": "A php client for WebDriver", + "homepage": "https://github.com/facebook/php-webdriver", + "keywords": [ + "facebook", + "php", + "selenium", + "webdriver" + ], + "time": "2014-08-05 02:55:46" + } + ], + "aliases": [ + + ], + "minimum-stability": "stable", + "stability-flags": { + "facebook/webdriver": 20 + }, + "platform": [ + + ], + "platform-dev": [ + + ] +} diff --git a/tests/console/cron/run_test.php b/tests/console/cron/run_test.php index 029dc5249b..f76e967484 100644 --- a/tests/console/cron/run_test.php +++ b/tests/console/cron/run_test.php @@ -16,6 +16,7 @@ use Symfony\Component\Console\Tester\CommandTester; use phpbb\console\command\cron\run; require_once dirname(__FILE__) . '/tasks/simple.php'; +require_once dirname(__FILE__) . '/../../../phpBB/includes/functions.php'; class phpbb_console_command_cron_run_test extends phpbb_database_test_case { diff --git a/tests/controller/common_helper_route.php b/tests/controller/common_helper_route.php index 859832412d..6723e3bc52 100644 --- a/tests/controller/common_helper_route.php +++ b/tests/controller/common_helper_route.php @@ -63,21 +63,21 @@ abstract class phpbb_controller_common_helper_route extends phpbb_test_case 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->request = new phpbb_mock_request(); + $this->request->overwrite('SCRIPT_NAME', $this->get_uri(), \phpbb\request\request_interface::SERVER); + $this->request->overwrite('SCRIPT_FILENAME', $this->get_script_name(), \phpbb\request\request_interface::SERVER); + $this->request->overwrite('REQUEST_URI', $this->get_uri(), \phpbb\request\request_interface::SERVER); + $this->request->overwrite('SERVER_NAME', 'localhost', \phpbb\request\request_interface::SERVER); + $this->request->overwrite('SERVER_PORT', '80', \phpbb\request\request_interface::SERVER); $this->symfony_request = new \phpbb\symfony_request( - $request + $this->request ); $this->filesystem = new \phpbb\filesystem(); $this->phpbb_path_helper = new \phpbb\path_helper( $this->symfony_request, $this->filesystem, - $this->getMock('\phpbb\request\request'), + $this->request, $phpbb_root_path, $phpEx ); @@ -130,7 +130,7 @@ abstract class phpbb_controller_common_helper_route extends phpbb_test_case */ 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->helper = new phpbb_mock_controller_helper($this->template, $this->user, $this->config, $this->provider, $this->extension_manager, $this->symfony_request, $this->request, $this->filesystem, $this->root_path, 'php', dirname(__FILE__) . '/'); $this->assertEquals($expected, $this->helper->route($route, $params, $is_amp, $session_id)); } @@ -170,7 +170,7 @@ abstract class phpbb_controller_common_helper_route extends phpbb_test_case 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->helper = new phpbb_mock_controller_helper($this->template, $this->user, $this->config, $this->provider, $this->extension_manager, $this->symfony_request, $this->request, $this->filesystem, $this->root_path, 'php', dirname(__FILE__) . '/'); $this->assertEquals($expected, $this->helper->route($route, $params, $is_amp, $session_id)); } @@ -210,7 +210,7 @@ abstract class phpbb_controller_common_helper_route extends phpbb_test_case 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->helper = new phpbb_mock_controller_helper($this->template, $this->user, $this->config, $this->provider, $this->extension_manager, $this->symfony_request, $this->request, $this->filesystem, $this->root_path, 'php', dirname(__FILE__) . '/'); $this->assertEquals($expected, $this->helper->route($route, $params, $is_amp, $session_id, UrlGeneratorInterface::ABSOLUTE_URL)); } @@ -250,7 +250,7 @@ abstract class phpbb_controller_common_helper_route extends phpbb_test_case 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->helper = new phpbb_mock_controller_helper($this->template, $this->user, $this->config, $this->provider, $this->extension_manager, $this->symfony_request, $this->request, $this->filesystem, $this->root_path, 'php', dirname(__FILE__) . '/'); $this->assertEquals($expected, $this->helper->route($route, $params, $is_amp, $session_id, UrlGeneratorInterface::RELATIVE_PATH)); } @@ -290,7 +290,7 @@ abstract class phpbb_controller_common_helper_route extends phpbb_test_case 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->helper = new phpbb_mock_controller_helper($this->template, $this->user, $this->config, $this->provider, $this->extension_manager, $this->symfony_request, $this->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 @@ -330,7 +330,7 @@ abstract class phpbb_controller_common_helper_route extends phpbb_test_case 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->helper = new phpbb_mock_controller_helper($this->template, $this->user, $this->config, $this->provider, $this->extension_manager, $this->symfony_request, $this->request, $this->filesystem, $this->root_path, 'php', dirname(__FILE__) . '/'); $this->assertEquals($expected, $this->helper->route($route, $params, $is_amp, $session_id, UrlGeneratorInterface::ABSOLUTE_URL)); } @@ -370,7 +370,7 @@ abstract class phpbb_controller_common_helper_route extends phpbb_test_case 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->helper = new phpbb_mock_controller_helper($this->template, $this->user, $this->config, $this->provider, $this->extension_manager, $this->symfony_request, $this->request, $this->filesystem, $this->root_path, 'php', dirname(__FILE__) . '/'); $this->assertEquals($expected, $this->helper->route($route, $params, $is_amp, $session_id, UrlGeneratorInterface::RELATIVE_PATH)); } @@ -410,7 +410,7 @@ abstract class phpbb_controller_common_helper_route extends phpbb_test_case 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->helper = new phpbb_mock_controller_helper($this->template, $this->user, $this->config, $this->provider, $this->extension_manager, $this->symfony_request, $this->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 58bcf0ef81..62feee3fed 100644 --- a/tests/controller/controller_test.php +++ b/tests/controller/controller_test.php @@ -11,6 +11,8 @@ * */ +require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php'; + use Symfony\Component\HttpFoundation\Request; use Symfony\Component\Config\FileLocator; use Symfony\Component\DependencyInjection\ContainerBuilder; diff --git a/tests/datetime/from_format_test.php b/tests/datetime/from_format_test.php index f10402e8cb..8968619bb5 100644 --- a/tests/datetime/from_format_test.php +++ b/tests/datetime/from_format_test.php @@ -60,44 +60,44 @@ class phpbb_datetime_from_format_test extends phpbb_test_case // 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'; + $testing_time = gmdate('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, + gmdate('Y-m-d', time() + 2 * 86400) . ' ' . $testing_time, false, + gmdate('Y-m-d', time() + 2 * 86400) . ' ' . $testing_time, ), array( - date('Y-m-d', time() + 86400) . ' ' . $testing_time, false, + gmdate('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, + gmdate('Y-m-d', time() + 86400) . ' ' . $testing_time, true, + gmdate('Y-m-d', time() + 86400) . ' ' . $testing_time, ), array( - date('Y-m-d') . ' ' . $testing_time, false, + gmdate('Y-m-d') . ' ' . $testing_time, false, 'Today ' . $testing_time, ), array( - date('Y-m-d') . ' ' . $testing_time, true, - date('Y-m-d') . ' ' . $testing_time, + gmdate('Y-m-d') . ' ' . $testing_time, true, + gmdate('Y-m-d') . ' ' . $testing_time, ), array( - date('Y-m-d', time() - 86400) . ' ' . $testing_time, false, + gmdate('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, + gmdate('Y-m-d', time() - 86400) . ' ' . $testing_time, true, + gmdate('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, + gmdate('Y-m-d', time() - 2 * 86400) . ' ' . $testing_time, false, + gmdate('Y-m-d', time() - 2 * 86400) . ' ' . $testing_time, ), ); } diff --git a/tests/event/fixtures/trigger_wspace.test b/tests/event/fixtures/trigger_wspace.test new file mode 100644 index 0000000000..0334a9c80b --- /dev/null +++ b/tests/event/fixtures/trigger_wspace.test @@ -0,0 +1,15 @@ +<?php + + /** + * Event after the post data has been assigned to the template + * + * @event core.trigger + * @var int start Start item of this page + * @var int current_row_number Number of the post on this page + * @var int end Number of posts on this page + * @var array row Array with original post and user data + * @var array cp_row Custom profile field data of the poster + * @since 3.1.0-a3 + */ + $vars = array('start', 'current_row_number', 'end', 'row', 'cp_row'); + extract($phpbb_dispatcher->trigger_event('core.trigger', compact($vars))); diff --git a/tests/event/php_exporter_test.php b/tests/event/php_exporter_test.php index b52d68e305..692a57f93c 100644 --- a/tests/event/php_exporter_test.php +++ b/tests/event/php_exporter_test.php @@ -62,6 +62,18 @@ class phpbb_event_php_exporter_test extends phpbb_test_case ), ), array( + 'trigger_wspace.test', + array( + 'core.trigger' => array( + 'event' => 'core.trigger', + 'file' => 'trigger_wspace.test', + 'arguments' => array('cp_row', 'current_row_number', 'end', 'row', 'start'), + 'since' => '3.1.0-a3', + 'description' => 'Event after the post data has been assigned to the template', + ), + ), + ), + array( 'trigger_many_vars.test', array( 'core.posting_modify_template_vars' => array( @@ -119,6 +131,7 @@ class phpbb_event_php_exporter_test extends phpbb_test_case array('* @since 3.1.0-b3', '3.1.0-b3'), array(' * @since 3.1.0-b3', '3.1.0-b3'), array('* @since 3.1.0-RC2', '3.1.0-RC2'), + array(' * @since 3.1.0-a1', '3.1.0-a1'), ); } @@ -133,7 +146,6 @@ class phpbb_event_php_exporter_test extends phpbb_test_case static public function validate_since_throws_data() { return array( - array(' * @since 3.1.0-a1'), array('* @since 3.1.0-a1 '), array('* @since 3.1.0-a1 bertie is cool'), array('bertie* @since 3.1.0-a1'), @@ -156,6 +168,7 @@ class phpbb_event_php_exporter_test extends phpbb_test_case return array( array('test.event', '* @event test.event', 'test.event'), array('test.event2', ' * @event test.event2', 'test.event2'), + array('test.event', ' * @event test.event', 'test.event'), ); } @@ -170,7 +183,6 @@ class phpbb_event_php_exporter_test extends phpbb_test_case static public function validate_event_throws_data() { return array( - array('test.event', ' * @event test.event', 1), array('test.event', '* @event test.event bertie is cool', 2), array('test.event', 'bertie* @event test.event', 2), ); diff --git a/tests/functional/acp_groups_test.php b/tests/functional/acp_groups_test.php index 4eb4747572..9dfdc93474 100644 --- a/tests/functional/acp_groups_test.php +++ b/tests/functional/acp_groups_test.php @@ -11,12 +11,12 @@ * */ -require_once dirname(__FILE__) . '/common_groups_test.php'; +require_once dirname(__FILE__) . '/common_groups_test_case.php'; /** * @group functional */ -class phpbb_functional_acp_groups_test extends phpbb_functional_common_groups_test +class phpbb_functional_acp_groups_test extends phpbb_functional_common_groups_test_case { protected $form_data; diff --git a/tests/functional/acp_registration_test.php b/tests/functional/acp_registration_test.php new file mode 100644 index 0000000000..ef9843679e --- /dev/null +++ b/tests/functional/acp_registration_test.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. +* +*/ + +/** +* @group functional +*/ +class phpbb_functional_acp_registration_test extends phpbb_functional_test_case +{ + protected function set_email_enable($db, $status) + { + $sql = "UPDATE phpbb_config + SET config_value = '" . (($status) ? '1' : '0') . "' + WHERE config_name = 'email_enable'"; + $db->sql_query($sql); + + $this->purge_cache(); + } + + public function test_submitting_activation_method() + { + $db = $this->get_db(); + + $this->set_email_enable($db, false); + + $this->add_lang('acp/board'); + $this->login(); + $this->admin_login(); + + $crawler = self::request('GET', 'adm/index.php?i=acp_board&mode=registration&sid=' . $this->sid); + $this->assertContainsLang('ACP_REGISTER_SETTINGS_EXPLAIN', $this->get_content()); + + $form = $crawler->selectButton($this->lang('SUBMIT'))->form(); + $form['config[require_activation]']->select(USER_ACTIVATION_ADMIN); + $crawler = self::submit($form); + $this->assertContainsLang('ACC_ACTIVATION_WARNING', $crawler->filter('div.main')->text()); + + $crawler = self::request('GET', 'adm/index.php?i=acp_board&mode=registration&sid=' . $this->sid); + $form = $crawler->selectButton($this->lang('SUBMIT'))->form(); + $form['config[require_activation]']->select(USER_ACTIVATION_NONE); + $crawler = self::submit($form); + $this->assertNotContainsLang('ACC_ACTIVATION_WARNING', $crawler->filter('div.main')->text()); + + $this->set_email_enable($db, true); + } +} diff --git a/tests/functional/auth_test.php b/tests/functional/auth_test.php index b4b4279bf1..76e1709afb 100644 --- a/tests/functional/auth_test.php +++ b/tests/functional/auth_test.php @@ -34,6 +34,25 @@ class phpbb_functional_auth_test extends phpbb_functional_test_case } /** + * @dependsOn test_login_other + */ + public function test_login_ucp_other_auth_provider() + { + global $cache, $config; + $cache = new phpbb_mock_null_cache; + $db = $this->get_db(); + $sql = 'UPDATE ' . CONFIG_TABLE . " SET config_value = 'foobar' WHERE config_name = 'auth_method'"; + $db->sql_query($sql); + $config['auth_method'] = 'foobar'; + $this->login('anothertestuser'); + $crawler = self::request('GET', 'index.php'); + $this->assertContains('anothertestuser', $crawler->filter('#username_logged_in')->text()); + $sql = 'UPDATE ' . CONFIG_TABLE . " SET config_value = 'db' WHERE config_name = 'auth_method'"; + $db->sql_query($sql); + $config['auth_method'] = 'db'; + } + + /** * @depends test_login */ public function test_logout() diff --git a/tests/functional/avatar_acp_groups_test.php b/tests/functional/avatar_acp_groups_test.php index 925335a2f7..ca8c84ab2e 100644 --- a/tests/functional/avatar_acp_groups_test.php +++ b/tests/functional/avatar_acp_groups_test.php @@ -11,12 +11,12 @@ * */ -require_once dirname(__FILE__) . '/common_avatar_test.php'; +require_once dirname(__FILE__) . '/common_avatar_test_case.php'; /** * @group functional */ -class phpbb_functional_avatar_acp_groups_test extends phpbb_functional_common_avatar_test +class phpbb_functional_avatar_acp_groups_test extends phpbb_functional_common_avatar_test_case { public function get_url() { diff --git a/tests/functional/avatar_acp_users_test.php b/tests/functional/avatar_acp_users_test.php index 5eca473157..8b05a28658 100644 --- a/tests/functional/avatar_acp_users_test.php +++ b/tests/functional/avatar_acp_users_test.php @@ -11,12 +11,12 @@ * */ -require_once dirname(__FILE__) . '/common_avatar_test.php'; +require_once dirname(__FILE__) . '/common_avatar_test_case.php'; /** * @group functional */ -class phpbb_functional_avatar_acp_users_test extends phpbb_functional_common_avatar_test +class phpbb_functional_avatar_acp_users_test extends phpbb_functional_common_avatar_test_case { public function get_url() { diff --git a/tests/functional/avatar_ucp_groups_test.php b/tests/functional/avatar_ucp_groups_test.php index 1e8ca911c6..52ef67543e 100644 --- a/tests/functional/avatar_ucp_groups_test.php +++ b/tests/functional/avatar_ucp_groups_test.php @@ -10,12 +10,12 @@ * the docs/CREDITS.txt file. * */ -require_once dirname(__FILE__) . '/common_avatar_test.php'; +require_once dirname(__FILE__) . '/common_avatar_test_case.php'; /** * @group functional */ -class phpbb_functional_avatar_ucp_groups_test extends phpbb_functional_common_avatar_test +class phpbb_functional_avatar_ucp_groups_test extends phpbb_functional_common_avatar_test_case { public function get_url() { diff --git a/tests/functional/avatar_ucp_users_test.php b/tests/functional/avatar_ucp_users_test.php index 972bfa0fb2..2f0832e092 100644 --- a/tests/functional/avatar_ucp_users_test.php +++ b/tests/functional/avatar_ucp_users_test.php @@ -11,12 +11,12 @@ * */ -require_once dirname(__FILE__) . '/common_avatar_test.php'; +require_once dirname(__FILE__) . '/common_avatar_test_case.php'; /** * @group functional */ -class phpbb_functional_avatar_ucp_users_test extends phpbb_functional_common_avatar_test +class phpbb_functional_avatar_ucp_users_test extends phpbb_functional_common_avatar_test_case { public function get_url() { diff --git a/tests/functional/common_avatar_test.php b/tests/functional/common_avatar_test_case.php index 82d7136c98..7278f23bcc 100644 --- a/tests/functional/common_avatar_test.php +++ b/tests/functional/common_avatar_test_case.php @@ -14,7 +14,7 @@ /** * @group functional */ -abstract class phpbb_functional_common_avatar_test extends phpbb_functional_test_case +abstract class phpbb_functional_common_avatar_test_case extends phpbb_functional_test_case { private $path; private $form_content; diff --git a/tests/functional/common_groups_test.php b/tests/functional/common_groups_test_case.php index 748d4d5e0a..521b7c84d2 100644 --- a/tests/functional/common_groups_test.php +++ b/tests/functional/common_groups_test_case.php @@ -14,7 +14,7 @@ /** * @group functional */ -abstract class phpbb_functional_common_groups_test extends phpbb_functional_test_case +abstract class phpbb_functional_common_groups_test_case extends phpbb_functional_test_case { abstract protected function get_url(); diff --git a/tests/functional/feed_test.php b/tests/functional/feed_test.php index 7aa2d0da7d..9041c8dc69 100644 --- a/tests/functional/feed_test.php +++ b/tests/functional/feed_test.php @@ -322,15 +322,9 @@ class phpbb_functional_feed_test extends phpbb_functional_test_case $post = $this->create_topic($this->data['forums']['Feeds #news'], 'Feeds #news - Topic #1', 'This is a test topic posted by the testing framework.'); $this->data['topics']['Feeds #news - Topic #1'] = (int) $post['topic_id']; - // Travis is too fast, so we have to wait - sleep(1); - $post = $this->create_topic($this->data['forums']['Feeds #news'], 'Feeds #news - Topic #2', 'This is a test topic posted by the testing framework.'); $crawler = self::request('GET', "viewtopic.php?t={$post['topic_id']}&sid={$this->sid}"); - // Travis is too fast, so we have to wait - sleep(1); - $this->assertContains('Feeds #news - Topic #2', $crawler->filter('html')->text()); $this->data['topics']['Feeds #news - Topic #2'] = (int) $post['topic_id']; $this->data['posts']['Feeds #news - Topic #2'] = (int) $this->get_parameter_from_link($crawler->filter('.post')->selectLink($this->lang('POST', '', ''))->link()->getUri(), 'p'); @@ -456,9 +450,6 @@ class phpbb_functional_feed_test extends phpbb_functional_test_case $post = $this->create_topic($this->data['forums']['Feeds #1'], 'Feeds #1 - Topic #1', 'This is a test topic posted by the testing framework.'); $this->data['topics']['Feeds #1 - Topic #1'] = (int) $post['topic_id']; - // Travis is too fast, so we have to wait - sleep(1); - $post = $this->create_topic($this->data['forums']['Feeds #1.1'], 'Feeds #1.1 - Topic #1', 'This is a test topic posted by the testing framework.'); $this->data['topics']['Feeds #1.1 - Topic #1'] = (int) $post['topic_id']; } @@ -494,9 +485,6 @@ class phpbb_functional_feed_test extends phpbb_functional_test_case $post = $this->create_topic($this->data['forums']['Feeds #1'], 'Feeds #1 - Topic #2', 'This is a test topic posted by the testing framework.'); $this->data['topics']['Feeds #1 - Topic #2'] = (int) $post['topic_id']; - // Travis is too fast, so we have to wait - sleep(1); - // Test creating a reply $post2 = $this->create_post($this->data['forums']['Feeds #1'], $post['topic_id'], 'Re: Feeds #1 - Topic #2', 'This is a test post posted by the testing framework.'); $crawler = self::request('GET', "viewtopic.php?t={$post2['topic_id']}&sid={$this->sid}"); @@ -852,9 +840,7 @@ class phpbb_functional_feed_test extends phpbb_functional_test_case 'Feeds #1.1', ), )); - - // We have to wait because of the flood interval. - sleep(15); + $this->set_flood_interval(0); $this->login('disapprove_user'); $post = $this->create_topic($this->data['forums']['Feeds #1.1'], 'Feeds #1.1 - Topic #3', 'This is a test topic posted by the testing framework.', array(), 'POST_STORED_MOD'); @@ -862,6 +848,27 @@ class phpbb_functional_feed_test extends phpbb_functional_test_case $crawler = self::request('GET', "viewforum.php?f={$this->data['forums']['Feeds #1.1']}&sid={$this->sid}"); $this->assertNotContains('Feeds #1.1 - Topic #3', $crawler->filter('html')->text()); + + $this->logout(); + $this->set_flood_interval(15); + } + + protected function set_flood_interval($flood_interval) + { + $this->login(); + $this->admin_login(); + + $crawler = self::request('GET', 'adm/index.php?sid=' . $this->sid . '&i=acp_board&mode=post'); + + $form = $crawler->selectButton('Submit')->form(); + $values = $form->getValues(); + + $values["config[flood_interval]"] = $flood_interval; + $form->setValues($values); + $crawler = self::submit($form); + $this->assertGreaterThan(0, $crawler->filter('.successbox')->count()); + + $this->logout(); } public function test_feeds_unapproved_topic_admin() diff --git a/tests/functional/memberlist_test.php b/tests/functional/memberlist_test.php index c76ba6e37d..1da5c39401 100644 --- a/tests/functional/memberlist_test.php +++ b/tests/functional/memberlist_test.php @@ -106,4 +106,32 @@ class phpbb_functional_memberlist_test extends phpbb_functional_test_case $this->assertContains('admin', $crawler->eq(0)->text()); $this->assertNotContains('admin', $crawler->eq(1)->text()); } + + public function test_group_rank() + { + copy(__DIR__ . '/fixtures/files/valid.jpg', __DIR__ . '/../../phpBB/images/ranks/valid.jpg'); + + $this->login(); + $this->admin_login(); + $this->add_lang(array('acp/groups', 'acp/posting')); + + // Set a group rank to the registered users + $crawler = self::request('GET', "adm/index.php?sid={$this->sid}&i=acp_groups&mode=manage&action=edit&g=2"); + $form = $crawler->selectButton('Submit')->form(); + $form['group_rank']->select('1'); + $crawler = self::submit($form); + $this->assertContainsLang('GROUP_UPDATED', $crawler->filter('.successbox')->text()); + + // Set a rank image for site_admin + $crawler = self::request('GET', "adm/index.php?sid={$this->sid}&i=acp_ranks&mode=ranks&action=edit&id=1"); + $form = $crawler->selectButton('Submit')->form(); + $form['rank_image']->select('valid.jpg'); + $crawler = self::submit($form); + $this->assertContainsLang('RANK_UPDATED', $crawler->filter('.successbox')->text()); + + $crawler = self::request('GET', 'memberlist.php?mode=group&g=2'); + $this->assertContains('memberlist-test-user', $crawler->text()); + + unlink(__DIR__ . '/../../phpBB/images/ranks/valid.jpg'); + } } diff --git a/tests/functional/notification_test.php b/tests/functional/notification_test.php index 667d268b1e..ec03f7a6a4 100644 --- a/tests/functional/notification_test.php +++ b/tests/functional/notification_test.php @@ -82,8 +82,6 @@ class phpbb_functional_notification_test extends phpbb_functional_test_case // Get form token $link = $crawler->selectLink($this->lang('NOTIFICATIONS_MARK_ALL_READ'))->link()->getUri(); $crawler = self::request('GET', substr($link, strpos($link, 'ucp.'))); - $form = $crawler->selectButton($this->lang('YES'))->form(); - $crawler = self::submit($form); $this->assertEquals(0, $crawler->filter('#notification_list_button strong')->text()); } } diff --git a/tests/functional/prune_shadow_topic_test.php b/tests/functional/prune_shadow_topic_test.php index 84f07e9802..f00303060d 100644 --- a/tests/functional/prune_shadow_topic_test.php +++ b/tests/functional/prune_shadow_topic_test.php @@ -129,8 +129,8 @@ class phpbb_functional_prune_shadow_topic_test extends phpbb_functional_test_cas $result = $this->db->sql_query($sql); $crawler = self::request('GET', "viewforum.php?f={$this->data['forums']['Prune Shadow']}&sid={$this->sid}"); - $cron_link = $crawler->filter('img')->last()->attr('src'); - $crawler = self::request('GET', $cron_link . "&sid={$this->sid}", array(), false); + $this->assertNotEmpty($crawler->filter('img')->last()->attr('src')); + self::request('GET', "cron.php?cron_type=cron.task.core.prune_shadow_topics&f={$this->data['forums']['Prune Shadow']}&sid={$this->sid}", array(), false); $this->assert_forum_details($this->data['forums']['Prune Shadow'], array( 'forum_posts_approved' => 0, diff --git a/tests/functional/registration_test.php b/tests/functional/registration_test.php index 45a684db19..690f4ae9f2 100644 --- a/tests/functional/registration_test.php +++ b/tests/functional/registration_test.php @@ -45,12 +45,23 @@ class phpbb_functional_registration_test extends phpbb_functional_test_case $form = $crawler->selectButton('Submit')->form(array( 'username' => 'user-reg-test', 'email' => 'user-reg-test@phpbb.com', - 'new_password' => 'testtest', - 'password_confirm' => 'testtest', + 'new_password' => 'user-reg-testuser-reg-test', + 'password_confirm' => 'user-reg-testuser-reg-test', )); $form['tz']->select('Europe/Berlin'); $crawler = self::submit($form); $this->assertContainsLang('ACCOUNT_ADDED', $crawler->filter('#message')->text()); } + + /** + * @depends test_register_new_account + */ + public function test_default_subscription_options() + { + $this->login('user-reg-test'); + $crawler = self::request('GET', 'ucp.php?i=ucp_notifications&mode=notification_options&sid=' . $this->sid); + $this->assert_checkbox_is_checked($crawler, 'notification.type.post_notification.method.email'); + $this->assert_checkbox_is_checked($crawler, 'notification.type.topic_notification.method.email'); + } } diff --git a/tests/functional/ucp_groups_test.php b/tests/functional/ucp_groups_test.php index 2b075b37a5..cd18a0fcae 100644 --- a/tests/functional/ucp_groups_test.php +++ b/tests/functional/ucp_groups_test.php @@ -11,12 +11,12 @@ * */ -require_once dirname(__FILE__) . '/common_groups_test.php'; +require_once dirname(__FILE__) . '/common_groups_test_case.php'; /** * @group functional */ -class phpbb_functional_ucp_groups_test extends phpbb_functional_common_groups_test +class phpbb_functional_ucp_groups_test extends phpbb_functional_common_groups_test_case { protected $db; diff --git a/tests/functional/viewforum_paging_test.php b/tests/functional/viewforum_paging_test.php new file mode 100644 index 0000000000..4a574bebbb --- /dev/null +++ b/tests/functional/viewforum_paging_test.php @@ -0,0 +1,256 @@ +<?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 viewforum_paging_test extends phpbb_functional_test_case +{ + protected $data = array(); + + public function test_setup_forums() + { + $this->login(); + $this->admin_login(); + + $crawler = self::request('GET', "adm/index.php?i=acp_forums&mode=manage&sid={$this->sid}"); + $form = $crawler->selectButton('addforum')->form(array( + 'forum_name' => 'Viewforum Pagination Test #1', + )); + $crawler = self::submit($form); + $form = $crawler->selectButton('update')->form(array( + 'forum_perm_from' => 2, + )); + self::submit($form); + + $crawler = self::request('GET', "adm/index.php?i=acp_forums&mode=manage&sid={$this->sid}"); + $form = $crawler->selectButton('addforum')->form(array( + 'forum_name' => 'Viewforum Pagination Test #2', + )); + $crawler = self::submit($form); + $form = $crawler->selectButton('update')->form(array( + 'forum_perm_from' => 2, + )); + self::submit($form); + + $this->set_post_settings(array( + 'flood_interval' => 0, + 'topics_per_page' => 3, + )); + } + + public function test_create_posts() + { + $this->login(); + $this->load_ids(array( + 'forums' => array( + 'Viewforum Pagination Test #1', + 'Viewforum Pagination Test #2', + ), + )); + + $this->assert_forum_details($this->data['forums']['Viewforum Pagination Test #1'], 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, + ), 'initial comparison'); + + for ($topic_id = 1; $topic_id <= 6; $topic_id++) + { + $this->create_topic($this->data['forums']['Viewforum Pagination Test #1'], 'Viewforum Pagination TestTopic #' . $topic_id, 'This is a test topic posted by the testing framework.'); + } + + $this->create_topic($this->data['forums']['Viewforum Pagination Test #2'], 'Viewforum Pagination TestTopic #GA1', 'This is a test topic posted by the testing framework.', array( + 'topic_type' => POST_GLOBAL, + )); + + $this->assert_forum_details($this->data['forums']['Viewforum Pagination Test #1'], array( + 'forum_posts_approved' => 6, + 'forum_posts_unapproved' => 0, + 'forum_posts_softdeleted' => 0, + 'forum_topics_approved' => 6, + 'forum_topics_unapproved' => 0, + 'forum_topics_softdeleted' => 0, + ), 'after creating topics'); + + $this->assert_forum_details($this->data['forums']['Viewforum Pagination Test #2'], array( + 'forum_posts_approved' => 1, + 'forum_posts_unapproved' => 0, + 'forum_posts_softdeleted' => 0, + 'forum_topics_approved' => 1, + 'forum_topics_unapproved' => 0, + 'forum_topics_softdeleted' => 0, + ), 'after creating GA'); + + // Set flood interval back to 15 + $this->admin_login(); + $this->set_post_settings(array( + 'flood_interval' => 15, + )); + } + + public function test_viewforum_first_page() + { + $this->load_ids(array( + 'forums' => array( + 'Viewforum Pagination Test #1', + 'Viewforum Pagination Test #2', + ), + )); + $crawler = self::request('GET', 'viewforum.php?f=' . $this->data['forums']['Viewforum Pagination Test #1']); + + // Test the topics that are displayed + $topiclists = $crawler->filter('.forumbg .topics'); + $this->assertEquals(2, $topiclists->count()); + $topiclist = $topiclists->eq(0)->filter('li'); + $this->assertStringEndsWith('TestTopic #GA1', $topiclist->eq(0)->filter('.topictitle')->text()); + $topiclist = $topiclists->eq(1)->filter('li'); + $this->assertStringEndsWith('TestTopic #6', $topiclist->eq(0)->filter('.topictitle')->text()); + $this->assertStringEndsWith('TestTopic #5', $topiclist->eq(1)->filter('.topictitle')->text()); + $this->assertStringEndsWith('TestTopic #4', $topiclist->eq(2)->filter('.topictitle')->text()); + + // Test the pagination, should only have: 1 - 2 - Next + $this->assertEquals(2, $crawler->filter('div.pagination')->count()); + $top_pagination = $crawler->filter('div.pagination')->eq(0); + $this->assertEquals(3, $top_pagination->filter('li')->count(), 'Number of pagination items on page 1 does not match'); + $this->assertContains('1', $top_pagination->filter('li')->eq(0)->text()); + $this->assertContains('2', $top_pagination->filter('li')->eq(1)->text()); + $this->assertContainsLang('NEXT', $top_pagination->filter('li')->eq(2)->text()); + } + + public function test_viewforum_second_page() + { + $this->load_ids(array( + 'forums' => array( + 'Viewforum Pagination Test #1', + 'Viewforum Pagination Test #2', + ), + )); + $crawler = self::request('GET', 'viewforum.php?f=' . $this->data['forums']['Viewforum Pagination Test #1'] . '&start=3'); + + // Test the topics that are displayed + $topiclists = $crawler->filter('.forumbg .topics'); + $this->assertEquals(2, $topiclists->count()); + $topiclist = $topiclists->eq(0)->filter('li'); + $this->assertStringEndsWith('TestTopic #GA1', $topiclist->eq(0)->filter('.topictitle')->text()); + $topiclist = $topiclists->eq(1)->filter('li'); + $this->assertStringEndsWith('TestTopic #3', $topiclist->eq(0)->filter('.topictitle')->text()); + $this->assertStringEndsWith('TestTopic #2', $topiclist->eq(1)->filter('.topictitle')->text()); + $this->assertStringEndsWith('TestTopic #1', $topiclist->eq(2)->filter('.topictitle')->text()); + + // Test the pagination, should only have: Previous - 1 - 2 + $this->assertEquals(2, $crawler->filter('div.pagination')->count()); + $top_pagination = $crawler->filter('div.pagination')->eq(0); + $this->assertEquals(3, $top_pagination->filter('li')->count(), 'Number of pagination items on page 2 does not match'); + $this->assertContainsLang('PREVIOUS', $top_pagination->filter('li')->eq(0)->text()); + $this->assertContains('1', $top_pagination->filter('li')->eq(1)->text()); + $this->assertContains('2', $top_pagination->filter('li')->eq(2)->text()); + } + + protected function assert_forum_details($forum_id, $details, $additional_error_message = '') + { + $this->db = $this->get_db(); + + $sql = 'SELECT ' . implode(', ', array_keys($details)) . ' + FROM phpbb_forums + WHERE forum_id = ' . (int) $forum_id; + $result = $this->db->sql_query($sql); + $data = $this->db->sql_fetchrow($result); + $this->db->sql_freeresult($result); + + $this->assertEquals($details, $data, "Forum {$forum_id} does not match expected {$additional_error_message}"); + } + + /** + * Sets the post setting via the ACP page + * + * @param array $settings + */ + protected function set_post_settings($settings) + { + $crawler = self::request('GET', 'adm/index.php?sid=' . $this->sid . '&i=acp_board&mode=post'); + + $form = $crawler->selectButton('Submit')->form(); + $values = $form->getValues(); + + foreach ($settings as $setting => $value) + { + $values["config[{$setting}]"] = $value; + } + $form->setValues($values); + $crawler = self::submit($form); + $this->assertGreaterThan(0, $crawler->filter('.successbox')->count()); + } + + /** + * Loads forum, topic and post IDs + * + * @param array $data + */ + protected function load_ids($data) + { + $this->db = $this->get_db(); + + if (!empty($data['forums'])) + { + $sql = 'SELECT * + FROM phpbb_forums + WHERE ' . $this->db->sql_in_set('forum_name', $data['forums']); + $result = $this->db->sql_query($sql); + while ($row = $this->db->sql_fetchrow($result)) + { + if (in_array($row['forum_name'], $data['forums'])) + { + $this->data['forums'][$row['forum_name']] = (int) $row['forum_id']; + } + } + $this->db->sql_freeresult($result); + } + + if (!empty($data['topics'])) + { + $sql = 'SELECT * + FROM phpbb_topics + WHERE ' . $this->db->sql_in_set('topic_title', $data['topics']); + $result = $this->db->sql_query($sql); + while ($row = $this->db->sql_fetchrow($result)) + { + if (in_array($row['topic_title'], $data['topics'])) + { + $this->data['topics'][$row['topic_title']] = (int) $row['topic_id']; + } + } + $this->db->sql_freeresult($result); + } + + if (!empty($data['posts'])) + { + $sql = 'SELECT * + FROM phpbb_posts + WHERE ' . $this->db->sql_in_set('post_subject', $data['posts']); + $result = $this->db->sql_query($sql); + while ($row = $this->db->sql_fetchrow($result)) + { + if (in_array($row['post_subject'], $data['posts'])) + { + $this->data['posts'][$row['post_subject']] = (int) $row['post_id']; + } + } + $this->db->sql_freeresult($result); + } + } +} diff --git a/tests/functions/build_url_test.php b/tests/functions/build_url_test.php index 06415a424e..a59b94c744 100644 --- a/tests/functions/build_url_test.php +++ b/tests/functions/build_url_test.php @@ -69,6 +69,11 @@ class phpbb_build_url_test extends phpbb_test_case array('f', 'style', 't'), 'http://test.phpbb.com/viewtopic.php?', ), + array( + 'posting.php?f=2&mode=delete&p=20%22%3Cscript%3Ealert%281%29%3B%3C%2Fscript%3E', + false, + 'phpBB/posting.php?f=2&mode=delete&p=20%22%3Cscript%3Ealert%281%29%3B%3C%2Fscript%3E', + ) ); } diff --git a/tests/functions/validate_username_test.php b/tests/functions/validate_username_test.php index dc9f685f04..4fa5af7ff3 100644 --- a/tests/functions/validate_username_test.php +++ b/tests/functions/validate_username_test.php @@ -11,6 +11,7 @@ * */ +require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php'; require_once dirname(__FILE__) . '/../../phpBB/includes/functions_user.php'; require_once dirname(__FILE__) . '/../../phpBB/includes/utf/utf_tools.php'; require_once dirname(__FILE__) . '/../mock/cache.php'; diff --git a/tests/functions/insert_config_array_test.php b/tests/functions_acp/insert_config_array_test.php index bfcb05862e..1264b35bf4 100644 --- a/tests/functions/insert_config_array_test.php +++ b/tests/functions_acp/insert_config_array_test.php @@ -11,6 +11,8 @@ * */ +require_once dirname(__FILE__) . '/../../phpBB/includes/functions_acp.php'; + class phpbb_functions_insert_config_array_test extends phpbb_test_case { public function config_display_vars() diff --git a/tests/mock/controller_helper.php b/tests/mock/controller_helper.php index 9c13c309f2..ae3e7bf432 100644 --- a/tests/mock/controller_helper.php +++ b/tests/mock/controller_helper.php @@ -13,12 +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\symfony_request $symfony_request, \phpbb\filesystem $filesystem, $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\request\request_interface $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->request = $request; $this->filesystem = $filesystem; $this->phpbb_root_path = $phpbb_root_path; $this->php_ext = $php_ext; diff --git a/tests/mock/request.php b/tests/mock/request.php index 304fcf0eaf..e7217a94a9 100644 --- a/tests/mock/request.php +++ b/tests/mock/request.php @@ -114,4 +114,25 @@ class phpbb_mock_request implements \phpbb\request\request_interface { $this->data[$super_global] = array_merge($this->data[$super_global], $values); } + + public function escape($var, $multibyte) + { + $type_cast_helper = new \phpbb\request\type_cast_helper(); + if (is_array($var)) + { + $result = array(); + foreach ($var as $key => $value) + { + $type_cast_helper->set_var($key, $key, gettype($key), $multibyte); + $result[$key] = $this->escape($value, $multibyte); + } + $var = $result; + } + else + { + $type_cast_helper->set_var($var, $var, 'string', $multibyte); + } + + return $var; + } } diff --git a/tests/notification/group_request_test.php b/tests/notification/group_request_test.php index afbc586601..0d1bda95ce 100644 --- a/tests/notification/group_request_test.php +++ b/tests/notification/group_request_test.php @@ -12,6 +12,7 @@ */ require_once dirname(__FILE__) . '/base.php'; +require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php'; class phpbb_notification_group_request_test extends phpbb_tests_notification_base { diff --git a/tests/pagination/pagination_test.php b/tests/pagination/pagination_test.php index d36aa11a8a..494c667198 100644 --- a/tests/pagination/pagination_test.php +++ b/tests/pagination/pagination_test.php @@ -57,7 +57,7 @@ class phpbb_pagination_pagination_test extends phpbb_template_template_test_case $request ); - $this->helper = new phpbb_mock_controller_helper($this->template, $this->user, $this->config, $provider, $manager, $symfony_request, $filesystem, '', 'php', dirname(__FILE__) . '/'); + $this->helper = new phpbb_mock_controller_helper($this->template, $this->user, $this->config, $provider, $manager, $symfony_request, $request, $filesystem, '', 'php', dirname(__FILE__) . '/'); $this->pagination = new \phpbb\pagination($this->template, $this->user, $this->helper, $phpbb_dispatcher); } diff --git a/tests/passwords/drivers_test.php b/tests/passwords/drivers_test.php index ccfb05c40f..5f9fd523c9 100644 --- a/tests/passwords/drivers_test.php +++ b/tests/passwords/drivers_test.php @@ -35,7 +35,7 @@ class phpbb_passwords_helper_test extends \phpbb_test_case 'passwords.driver.md5_vb' => new \phpbb\passwords\driver\md5_vb($config, $this->driver_helper), 'passwords.driver.sha_xf1' => new \phpbb\passwords\driver\sha_xf1($config, $this->driver_helper), ); - $this->passwords_drivers['passwords.driver.md5_phpbb2'] = new \phpbb\passwords\driver\md5_phpbb2($request, $this->passwords_drivers['passwords.driver.salted_md5'], $phpbb_root_path, $php_ext); + $this->passwords_drivers['passwords.driver.md5_phpbb2'] = new \phpbb\passwords\driver\md5_phpbb2($request, $this->passwords_drivers['passwords.driver.salted_md5'], $this->driver_helper, $phpbb_root_path, $php_ext); $this->passwords_drivers['passwords.driver.bcrypt_wcf2'] = new \phpbb\passwords\driver\bcrypt_wcf2($this->passwords_drivers['passwords.driver.bcrypt'], $this->driver_helper); } diff --git a/tests/passwords/manager_test.php b/tests/passwords/manager_test.php index e46cf820f2..333834ee07 100644 --- a/tests/passwords/manager_test.php +++ b/tests/passwords/manager_test.php @@ -41,7 +41,7 @@ class phpbb_passwords_manager_test extends \phpbb_test_case 'passwords.driver.md5_vb' => new \phpbb\passwords\driver\md5_vb($config, $this->driver_helper), 'passwords.driver.sha_xf1' => new \phpbb\passwords\driver\sha_xf1($config, $this->driver_helper), ); - $this->passwords_drivers['passwords.driver.md5_phpbb2'] = new \phpbb\passwords\driver\md5_phpbb2($request, $this->passwords_drivers['passwords.driver.salted_md5'], $phpbb_root_path, $php_ext); + $this->passwords_drivers['passwords.driver.md5_phpbb2'] = new \phpbb\passwords\driver\md5_phpbb2($request, $this->passwords_drivers['passwords.driver.salted_md5'], $this->driver_helper, $phpbb_root_path, $php_ext); $this->passwords_drivers['passwords.driver.bcrypt_wcf2'] = new \phpbb\passwords\driver\bcrypt_wcf2($this->passwords_drivers['passwords.driver.bcrypt'], $this->driver_helper); $this->helper = new \phpbb\passwords\helper; @@ -326,4 +326,22 @@ class phpbb_passwords_manager_test extends \phpbb_test_case $this->assertFalse($this->manager->hash(str_repeat('a', 1024 * 1024 * 16))); $this->assertLessThanOrEqual(5, time() - $start_time); } + + public function data_test_string_compare() + { + return array( + array('foo', 'bar', false), + array(1, '1', false), + array('one', 'one', true), + array('foobar', 'foobaf', false), + ); + } + + /** + * @dataProvider data_test_string_compare + */ + public function test_string_compare($a, $b, $expected) + { + $this->assertSame($expected, $this->driver_helper->string_compare($a, $b)); + } } diff --git a/tests/security/base.php b/tests/security/base.php index 5519cac441..330408b448 100644 --- a/tests/security/base.php +++ b/tests/security/base.php @@ -13,6 +13,8 @@ abstract class phpbb_security_test_base extends phpbb_test_case { + protected $server = array(); + /** * Set up the required user object and server variables for the suites */ @@ -21,17 +23,18 @@ abstract class phpbb_security_test_base extends phpbb_test_case global $user, $phpbb_root_path, $phpEx, $request, $symfony_request, $phpbb_filesystem; // Put this into a global function being run by every test to init a proper user session - $server['HTTP_HOST'] = 'localhost'; - $server['SERVER_NAME'] = 'localhost'; - $server['SERVER_ADDR'] = '127.0.0.1'; - $server['SERVER_PORT'] = 80; - $server['REMOTE_ADDR'] = '127.0.0.1'; - $server['QUERY_STRING'] = ''; - $server['REQUEST_URI'] = '/tests/'; - $server['SCRIPT_NAME'] = '/tests/index.php'; - $server['PHP_SELF'] = '/tests/index.php'; - $server['HTTP_USER_AGENT'] = 'Mozilla/5.0 (Windows; U; Windows NT 6.0; de; rv:1.8.1.14) Gecko/20080404 Firefox/2.0.0.14'; - $server['HTTP_ACCEPT_LANGUAGE'] = 'de-de,de;q=0.8,en-us;q=0.5,en;q=0.3'; + $this->server['HTTP_HOST'] = 'localhost'; + $this->server['SERVER_NAME'] = 'localhost'; + $this->server['SERVER_ADDR'] = '127.0.0.1'; + $this->server['SERVER_PORT'] = 80; + $this->server['REMOTE_ADDR'] = '127.0.0.1'; + $this->server['QUERY_STRING'] = ''; + $this->server['REQUEST_URI'] = '/tests/'; + $this->server['SCRIPT_NAME'] = '/tests/index.php'; + $this->server['SCRIPT_FILENAME'] = '/var/www/tests/index.php'; + $this->server['PHP_SELF'] = '/tests/index.php'; + $this->server['HTTP_USER_AGENT'] = 'Mozilla/5.0 (Windows; U; Windows NT 6.0; de; rv:1.8.1.14) Gecko/20080404 Firefox/2.0.0.14'; + $this->server['HTTP_ACCEPT_LANGUAGE'] = 'de-de,de;q=0.8,en-us;q=0.5,en;q=0.3'; /* [HTTP_ACCEPT_ENCODING] => gzip,deflate @@ -40,31 +43,18 @@ abstract class phpbb_security_test_base extends phpbb_test_case [SCRIPT_FILENAME] => /var/www/tests/index.php */ - $request = new phpbb_mock_request(array(), array(), array(), $server); - $symfony_request = $this->getMock("\phpbb\symfony_request", array(), array( - $request, - )); - $symfony_request->expects($this->any()) - ->method('getScriptName') - ->will($this->returnValue($server['SCRIPT_NAME'])); - $symfony_request->expects($this->any()) - ->method('getQueryString') - ->will($this->returnValue($server['QUERY_STRING'])); - $symfony_request->expects($this->any()) - ->method('getBasePath') - ->will($this->returnValue($server['REQUEST_URI'])); - $symfony_request->expects($this->any()) - ->method('getPathInfo') - ->will($this->returnValue('/')); - $phpbb_filesystem = new \phpbb\filesystem($symfony_request, $phpbb_root_path, $phpEx); + $request = new phpbb_mock_request(array(), array(), array(), $this->server); + $symfony_request = new \phpbb\symfony_request($request); + + $phpbb_filesystem = new \phpbb\filesystem(); // Set no user and trick a bit to circumvent errors $user = new \phpbb\user('\phpbb\datetime'); $user->lang = true; - $user->browser = $server['HTTP_USER_AGENT']; + $user->browser = $this->server['HTTP_USER_AGENT']; $user->referer = ''; $user->forwarded_for = ''; - $user->host = $server['HTTP_HOST']; + $user->host = $this->server['HTTP_HOST']; $user->page = \phpbb\session::extract_current_page($phpbb_root_path); } diff --git a/tests/security/extract_current_page_test.php b/tests/security/extract_current_page_test.php index 58dea68dc8..767b901a43 100644 --- a/tests/security/extract_current_page_test.php +++ b/tests/security/extract_current_page_test.php @@ -20,33 +20,25 @@ class phpbb_security_extract_current_page_test extends phpbb_security_test_base public function security_variables() { return array( - array('http://localhost/phpBB/index.php', 'mark=forums&x="><script>alert(/XSS/);</script>', 'mark=forums&x=%22%3E%3Cscript%3Ealert(/XSS/);%3C/script%3E'), - array('http://localhost/phpBB/index.php', 'mark=forums&x=%22%3E%3Cscript%3Ealert(/XSS/);%3C/script%3E', 'mark=forums&x=%22%3E%3Cscript%3Ealert(/XSS/);%3C/script%3E'), + array('mark=forums&x="><script>alert(/XSS/);</script>', 'mark=forums&x=%22%3E%3Cscript%3Ealert%28%2FXSS%2F%29%3B%3C%2Fscript%3E'), + array('mark=forums&x=%22%3E%3Cscript%3Ealert(/XSS/);%3C/script%3E', 'mark=forums&x=%22%3E%3Cscript%3Ealert%28%2FXSS%2F%29%3B%3C%2Fscript%3E'), + array('mark=forums&x=%22%3E%3Cscript%3Ealert%28%2FXSS%2F%29%3B%3C%2Fscript%3E', 'mark=forums&x=%22%3E%3Cscript%3Ealert%28%2FXSS%2F%29%3B%3C%2Fscript%3E'), ); } /** * @dataProvider security_variables */ - public function test_query_string_php_self($url, $query_string, $expected) + public function test_query_string_php_self($query_string, $expected) { global $symfony_request, $request; - $symfony_request = $this->getMock("\phpbb\symfony_request", array(), array( - $request, - )); - $symfony_request->expects($this->any()) - ->method('getScriptName') - ->will($this->returnValue($url)); - $symfony_request->expects($this->any()) - ->method('getQueryString') - ->will($this->returnValue($query_string)); - $symfony_request->expects($this->any()) - ->method('getBasePath') - ->will($this->returnValue($server['REQUEST_URI'])); - $symfony_request->expects($this->any()) - ->method('getPathInfo') - ->will($this->returnValue('/')); + $this->server['REQUEST_URI'] = ''; + $this->server['QUERY_STRING'] = $query_string; + + $request = new phpbb_mock_request(array(), array(), array(), $this->server); + $symfony_request = new \phpbb\symfony_request($request); + $result = \phpbb\session::extract_current_page('./'); $label = 'Running extract_current_page on ' . $query_string . ' with PHP_SELF filled.'; @@ -56,25 +48,14 @@ class phpbb_security_extract_current_page_test extends phpbb_security_test_base /** * @dataProvider security_variables */ - public function test_query_string_request_uri($url, $query_string, $expected) + public function test_query_string_request_uri($query_string, $expected) { global $symfony_request, $request; - $symfony_request = $this->getMock("\phpbb\symfony_request", array(), array( - $request, - )); - $symfony_request->expects($this->any()) - ->method('getScriptName') - ->will($this->returnValue($url)); - $symfony_request->expects($this->any()) - ->method('getQueryString') - ->will($this->returnValue($query_string)); - $symfony_request->expects($this->any()) - ->method('getBasePath') - ->will($this->returnValue($server['REQUEST_URI'])); - $symfony_request->expects($this->any()) - ->method('getPathInfo') - ->will($this->returnValue('/')); + $this->server['QUERY_STRING'] = $query_string; + + $request = new phpbb_mock_request(array(), array(), array(), $this->server); + $symfony_request = new \phpbb\symfony_request($request); $result = \phpbb\session::extract_current_page('./'); diff --git a/tests/security/redirect_test.php b/tests/security/redirect_test.php index 3961c2781e..21fb103ed1 100644 --- a/tests/security/redirect_test.php +++ b/tests/security/redirect_test.php @@ -73,6 +73,8 @@ class phpbb_security_redirect_test extends phpbb_security_test_base protected function setUp() { + global $phpbb_dispatcher; + parent::setUp(); $GLOBALS['config'] = array( @@ -80,6 +82,8 @@ class phpbb_security_redirect_test extends phpbb_security_test_base ); $this->path_helper = $this->get_path_helper(); + + $phpbb_dispatcher = new phpbb_mock_event_dispatcher(); } /** diff --git a/tests/session/extract_page_test.php b/tests/session/extract_page_test.php index f314d35f87..f0d1cdb60e 100644 --- a/tests/session/extract_page_test.php +++ b/tests/session/extract_page_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_extract_page_test extends phpbb_session_test_case { @@ -99,7 +100,7 @@ class phpbb_session_extract_page_test extends phpbb_session_test_case // ^-- Ignored because .. returns different directory in live vs testing 'query_string' => '', 'script_path' => '/phpBB/adm/', - //'root_script_path' => '/phpBB/', + //'root_script_path' => '/phpBB/adm/', //'page' => 'adm/index.php', 'forum' => 0, ), @@ -108,15 +109,15 @@ class phpbb_session_extract_page_test extends phpbb_session_test_case './', '/phpBB/adm/app.php', 'page=1&test=2', - '/phpBB/', + '/phpBB/adm/', '/foo/bar', array( 'page_name' => 'app.php/foo/bar', - 'page_dir' => '', + //'page_dir' => '', 'query_string' => 'page=1&test=2', - 'script_path' => '/phpBB/', - 'root_script_path' => '/phpBB/', - 'page' => 'app.php/foo/bar?page=1&test=2', + 'script_path' => '/phpBB/adm/', + //'root_script_path' => '/phpBB/adm/', + //'page' => 'app.php/foo/bar?page=1&test=2', 'forum' => 0, ), ), @@ -142,23 +143,25 @@ class phpbb_session_extract_page_test extends phpbb_session_test_case /** @dataProvider extract_current_page_data */ function test_extract_current_page($root_path, $getScriptName, $getQueryString, $getBasePath, $getPathInfo, $expected) { - global $symfony_request; + global $symfony_request, $request, $phpbb_filesystem; + + $phpbb_filesystem = new \phpbb\filesystem(); + + $server['HTTP_HOST'] = 'localhost'; + $server['SERVER_NAME'] = 'localhost'; + $server['SERVER_ADDR'] = '127.0.0.1'; + $server['SERVER_PORT'] = 80; + $server['REMOTE_ADDR'] = '127.0.0.1'; + $server['QUERY_STRING'] = $getQueryString; + $server['REQUEST_URI'] = $getScriptName . $getPathInfo . ($getQueryString === '' ? '' : '?' . $getQueryString); + $server['SCRIPT_NAME'] = $getScriptName; + $server['SCRIPT_FILENAME'] = '/var/www/' . $getScriptName; + $server['PHP_SELF'] = $getScriptName; + $server['HTTP_USER_AGENT'] = 'Mozilla/5.0 (Windows; U; Windows NT 6.0; de; rv:1.8.1.14) Gecko/20080404 Firefox/2.0.0.14'; + $server['HTTP_ACCEPT_LANGUAGE'] = 'de-de,de;q=0.8,en-us;q=0.5,en;q=0.3'; - $symfony_request = $this->getMock("\phpbb\symfony_request", array(), array( - new phpbb_mock_request(), - )); - $symfony_request->expects($this->any()) - ->method('getScriptName') - ->will($this->returnValue($getScriptName)); - $symfony_request->expects($this->any()) - ->method('getQueryString') - ->will($this->returnValue($getQueryString)); - $symfony_request->expects($this->any()) - ->method('getBasePath') - ->will($this->returnValue($getBasePath)); - $symfony_request->expects($this->any()) - ->method('getPathInfo') - ->will($this->returnValue($getPathInfo)); + $request = new phpbb_mock_request(array(), array(), array(), $server); + $symfony_request = new \phpbb\symfony_request($request); $output = \phpbb\session::extract_current_page($root_path); diff --git a/tests/session/session_key_test.php b/tests/session/session_key_test.php index 31a470615c..bf3dfcaa3c 100644 --- a/tests/session/session_key_test.php +++ b/tests/session/session_key_test.php @@ -11,6 +11,7 @@ * */ +require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php'; require_once dirname(__FILE__) . '/../test_framework/phpbb_session_test_case.php'; class phpbb_session_login_keys_test extends phpbb_session_test_case @@ -28,13 +29,14 @@ class phpbb_session_login_keys_test extends phpbb_session_test_case // With AutoLogin setup $this->session_factory->merge_config_data(array('allow_autologin' => true)); $session = $this->session_factory->get_session($this->db); + // Using a user_id and key that is already in the database $session->cookie_data['u'] = $this->user_id; $session->cookie_data['k'] = $this->key_id; - // Try to access session - $session->session_create($this->user_id, false, $this->user_id); - $this->assertEquals($this->user_id, $session->data['user_id'], "session should automatically login"); + // Try to access session with the session key + $session->session_create(false, false, false); + $this->assertEquals($this->user_id, $session->data['user_id'], 'User should be logged in by the session key'); } public function test_reset_keys() @@ -42,14 +44,19 @@ class phpbb_session_login_keys_test extends phpbb_session_test_case // With AutoLogin setup $this->session_factory->merge_config_data(array('allow_autologin' => true)); $session = $this->session_factory->get_session($this->db); + // Reset of the keys for this user $session->reset_login_keys($this->user_id); + // Using a user_id and key that was in the database (before reset) $session->cookie_data['u'] = $this->user_id; $session->cookie_data['k'] = $this->key_id; - // Try to access session - $session->session_create($this->user_id, false, $this->user_id); - $this->assertNotEquals($this->user_id, $session->data['user_id'], "session should be cleared"); + // Try to access session with the session key + $session->session_create(false, false, $this->user_id); + $this->assertNotEquals($this->user_id, $session->data['user_id'], 'User is not logged in because the session key is invalid'); + + $session->session_create($this->user_id, false, false); + $this->assertEquals($this->user_id, $session->data['user_id'], 'User should be logged in because we create a new session'); } } diff --git a/tests/test_framework/phpbb_database_test_case.php b/tests/test_framework/phpbb_database_test_case.php index 26989fa345..fc1a3632f4 100644 --- a/tests/test_framework/phpbb_database_test_case.php +++ b/tests/test_framework/phpbb_database_test_case.php @@ -54,37 +54,31 @@ abstract class phpbb_database_test_case extends PHPUnit_Extensions_Database_Test static public function setUpBeforeClass() { + global $phpbb_root_path, $phpEx; + $setup_extensions = static::setup_extensions(); - $schema_md5 = md5(serialize($setup_extensions)); - self::$schema_file = __DIR__ . '/../tmp/' . $schema_md5 . '.json'; + $finder = new \phpbb\finder(new \phpbb\filesystem(), $phpbb_root_path, null, $phpEx); + $finder->core_path('phpbb/db/migration/data/'); + if (!empty($setup_extensions)) + { + $finder->set_extensions($setup_extensions) + ->extension_directory('/migrations'); + } + $classes = $finder->get_classes(); + + $schema_sha1 = sha1(serialize($classes)); + self::$schema_file = __DIR__ . '/../tmp/' . $schema_sha1 . '.json'; self::$install_schema_file = __DIR__ . '/../../phpBB/install/schemas/schema.json'; if (!file_exists(self::$schema_file)) { - global $phpbb_root_path, $phpEx, $table_prefix; - $finder = new \phpbb\finder(new \phpbb\filesystem(), $phpbb_root_path, null, $phpEx); - - if (!empty($setup_extensions)) - { - $classes = $finder->core_path('phpbb/db/migration/data/') - ->set_extensions($setup_extensions) - ->extension_directory('/migrations') - ->get_classes(); - - } - else - { - $classes = $finder->core_path('phpbb/db/migration/data/') - ->get_classes(); - } + global $table_prefix; $db = new \phpbb\db\driver\sqlite(); $schema_generator = new \phpbb\db\migration\schema_generator($classes, new \phpbb\config\config(array()), $db, new \phpbb\db\tools($db, true), $phpbb_root_path, $phpEx, $table_prefix); - $schema_data = $schema_generator->get_schema(); - - file_put_contents(self::$schema_file, json_encode($schema_data)); + file_put_contents(self::$schema_file, json_encode($schema_generator->get_schema())); } copy(self::$schema_file, self::$install_schema_file); @@ -94,7 +88,11 @@ abstract class phpbb_database_test_case extends PHPUnit_Extensions_Database_Test static public function tearDownAfterClass() { - unlink(self::$install_schema_file); + if (file_exists(self::$install_schema_file)) + { + unlink(self::$install_schema_file); + } + parent::tearDownAfterClass(); } diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index 49cc72363e..51bae7a723 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -38,6 +38,7 @@ class phpbb_functional_test_case extends phpbb_test_case static protected $config = array(); static protected $already_installed = false; + static protected $last_post_timestamp = 0; static public function setUpBeforeClass() { @@ -556,12 +557,10 @@ class phpbb_functional_test_case extends phpbb_test_case $cache = new phpbb_mock_null_cache; $cache_driver = new \phpbb\cache\driver\null(); - $phpbb_container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface'); - $phpbb_container - ->expects($this->any()) - ->method('get') - ->with('cache.driver') - ->will($this->returnValue($cache_driver)); + $phpbb_container = new phpbb_mock_container_builder(); + $phpbb_container->set('cache.driver', $cache_driver); + $phpbb_notifications = new phpbb_mock_notification_manager(); + $phpbb_container->set('notification_manager', $phpbb_notifications); if (!function_exists('utf_clean_string')) { @@ -1100,6 +1099,12 @@ class phpbb_functional_test_case extends phpbb_test_case */ protected function submit_message($posting_url, $posting_contains, $form_data) { + if (time() == self::$last_post_timestamp) + { + // Travis is too fast, so we have to wait to not mix up the post/topic order + sleep(1); + } + self::$last_post_timestamp = time(); $crawler = self::request('GET', $posting_url); $this->assertContains($this->lang($posting_contains), $crawler->filter('html')->text()); diff --git a/tests/test_framework/phpbb_session_test_case.php b/tests/test_framework/phpbb_session_test_case.php index d4fc174a12..1bf0277fe0 100644 --- a/tests/test_framework/phpbb_session_test_case.php +++ b/tests/test_framework/phpbb_session_test_case.php @@ -11,13 +11,19 @@ * */ +require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php'; require_once dirname(__FILE__) . '/../session/testable_factory.php'; require_once dirname(__FILE__) . '/../session/testable_facade.php'; abstract class phpbb_session_test_case extends phpbb_database_test_case { + /** @var phpbb_session_testable_factory */ protected $session_factory; + + /** @var phpbb_session_testable_facade */ protected $session_facade; + + /** @var \phpbb\db\driver\driver_interface */ protected $db; function setUp() diff --git a/tests/test_framework/phpbb_test_case.php b/tests/test_framework/phpbb_test_case.php index c39f7835d1..01d26fb67d 100644 --- a/tests/test_framework/phpbb_test_case.php +++ b/tests/test_framework/phpbb_test_case.php @@ -26,7 +26,7 @@ class phpbb_test_case extends PHPUnit_Framework_TestCase 'PHP_Token_Stream' => array('customTokens'), 'PHP_Token_Stream_CachingFactory' => array('cache'), - 'phpbb_database_test_case' => array('already_connected'), + 'phpbb_database_test_case' => array('already_connected', 'last_post_timestamp'), ); } diff --git a/tests/test_framework/phpbb_ui_test_case.php b/tests/test_framework/phpbb_ui_test_case.php new file mode 100644 index 0000000000..c8ac492e25 --- /dev/null +++ b/tests/test_framework/phpbb_ui_test_case.php @@ -0,0 +1,204 @@ +<?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 __DIR__ . '/../../phpBB/includes/functions_install.php'; + +class phpbb_ui_test_case extends phpbb_test_case +{ + static protected $host = '127.0.0.1'; + static protected $port = 8910; + + /** + * @var \RemoteWebDriver + */ + static protected $webDriver; + + static protected $config; + static protected $root_url; + static protected $already_installed = false; + + static public function setUpBeforeClass() + { + parent::setUpBeforeClass(); + + if (version_compare(PHP_VERSION, '5.3.19', '<')) + { + self::markTestSkipped('UI test case requires at least PHP 5.3.19.'); + } + else if (!class_exists('\RemoteWebDriver')) + { + self::markTestSkipped( + 'Could not find RemoteWebDriver class. ' . + 'Run "php ../composer.phar install" from the tests folder.' + ); + } + + self::$config = phpbb_test_case_helpers::get_test_config(); + self::$root_url = self::$config['phpbb_functional_url']; + + // 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 + // installed, and also before each test case is run. + self::$config['table_prefix'] = 'phpbb_'; + + if (!isset(self::$config['phpbb_functional_url'])) + { + self::markTestSkipped('phpbb_functional_url was not set in test_config and wasn\'t set as PHPBB_FUNCTIONAL_URL environment variable either.'); + } + + if (!self::$webDriver) + { + try { + $capabilities = array(\WebDriverCapabilityType::BROWSER_NAME => 'firefox'); + self::$webDriver = RemoteWebDriver::create(self::$host . ':' . self::$port, $capabilities); + } catch (WebDriverCurlException $e) { + self::markTestSkipped('PhantomJS webserver is not running.'); + } + } + + if (!self::$already_installed) + { + self::install_board(); + self::$already_installed = true; + } + } + + static public function visit($path) + { + self::$webDriver->get(self::$root_url . $path); + } + + static protected function recreate_database($config) + { + $db_conn_mgr = new phpbb_database_test_connection_manager($config); + $db_conn_mgr->recreate_db(); + } + + static public function find_element($type, $value) + { + return self::$webDriver->findElement(WebDriverBy::$type($value)); + } + + static public function submit($type = 'id', $value = 'submit') + { + $element = self::find_element($type, $value); + $element->click(); + } + + static public 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); + } + } + + $parseURL = parse_url(self::$config['phpbb_functional_url']); + + self::visit('install/index.php?mode=install&language=en'); + self::assertContains('Welcome to Installation', self::find_element('id', 'main')->getText()); + + // install/index.php?mode=install&sub=requirements + self::submit(); + self::assertContains('Installation compatibility', self::find_element('id', 'main')->getText()); + + // install/index.php?mode=install&sub=database + self::submit(); + self::assertContains('Database configuration', self::find_element('id', 'main')->getText()); + + self::find_element('id','dbms')->sendKeys(str_replace('phpbb\db\driver\\', '', self::$config['dbms'])); + self::find_element('id','dbhost')->sendKeys(self::$config['dbhost']); + self::find_element('id','dbport')->sendKeys(self::$config['dbport']); + self::find_element('id','dbname')->sendKeys(self::$config['dbname']); + self::find_element('id','dbuser')->sendKeys(self::$config['dbuser']); + self::find_element('id','dbpasswd')->sendKeys(self::$config['dbpasswd']); + + // Need to clear default phpbb_ prefix + self::find_element('id','table_prefix')->clear(); + self::find_element('id','table_prefix')->sendKeys(self::$config['table_prefix']); + + // install/index.php?mode=install&sub=database + self::submit(); + self::assertContains('Successful connection', self::find_element('id','main')->getText()); + + // install/index.php?mode=install&sub=administrator + self::submit(); + self::assertContains('Administrator configuration', self::find_element('id','main')->getText()); + + self::find_element('id','admin_name')->sendKeys('admin'); + self::find_element('id','admin_pass1')->sendKeys('adminadmin'); + self::find_element('id','admin_pass2')->sendKeys('adminadmin'); + self::find_element('id','board_email')->sendKeys('nobody@example.com'); + + // install/index.php?mode=install&sub=administrator + self::submit(); + self::assertContains('Tests passed', self::find_element('id','main')->getText()); + + // install/index.php?mode=install&sub=config_file + self::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(self::find_element('id','main')->getText(), 'The configuration file has been written') === false) + { + self::submit('id', 'dldone'); + } + self::assertContains('The configuration file has been written', self::find_element('id','main')->getText()); + + // install/index.php?mode=install&sub=advanced + self::submit(); + self::assertContains('The settings on this page are only necessary to set if you know that you require something different from the default.', self::find_element('id','main')->getText()); + + self::find_element('id','smtp_delivery')->sendKeys('1'); + self::find_element('id','smtp_host')->sendKeys('nxdomain.phpbb.com'); + self::find_element('id','smtp_user')->sendKeys('nxuser'); + self::find_element('id','smtp_pass')->sendKeys('nxpass'); + self::find_element('id','server_protocol')->sendKeys($parseURL['scheme'] . '://'); + self::find_element('id','server_name')->sendKeys('localhost'); + self::find_element('id','server_port')->sendKeys(isset($parseURL['port']) ? $parseURL['port'] : 80); + self::find_element('id','script_path')->sendKeys($parseURL['path']); + + // install/index.php?mode=install&sub=create_table + self::submit(); + self::assertContains('The database tables used by phpBB', self::find_element('id','main')->getText()); + self::assertContains('have been created and populated with some initial data.', self::find_element('id','main')->getText()); + + // install/index.php?mode=install&sub=final + self::submit(); + self::assertContains('You have successfully installed', self::find_element('id', 'main')->getText()); + + copy($config_file, $config_file_test); + } +} diff --git a/tests/tree/nestedset_forum_base.php b/tests/tree/nestedset_forum_base.php index 449b2e5ca8..c56be1f81e 100644 --- a/tests/tree/nestedset_forum_base.php +++ b/tests/tree/nestedset_forum_base.php @@ -11,6 +11,8 @@ * */ +require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php'; + class phpbb_tests_tree_nestedset_forum_base extends phpbb_database_test_case { public function getDataSet() diff --git a/tests/ui/quick_links_test.php b/tests/ui/quick_links_test.php new file mode 100644 index 0000000000..5bddb44a8b --- /dev/null +++ b/tests/ui/quick_links_test.php @@ -0,0 +1,27 @@ +<?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 ui +*/ +class quick_links_test extends phpbb_ui_test_case +{ + + public function test_quick_links() + { + $this->visit('index.php'); + $this->assertEmpty(self::find_element('className', 'dropdown')->getText()); + self::find_element('className', 'dropdown-toggle')->click(); + $this->assertNotNull(self::find_element('className', 'dropdown')->getText()); + } +} |