From f30b87519e9ead41525e1979cbce874e8a84e2b8 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Mon, 9 Sep 2013 17:28:56 -0500 Subject: [PATCH 01/19] [ticket/11832] Inject dependencies for phpbb_get_web_root_path (also moving) Function moved from phpbb_get_web_root_path to filesystem::get_web_root_path PHPBB3-11832 --- phpBB/common.php | 2 +- phpBB/config/services.yml | 2 + phpBB/includes/functions.php | 49 ++----------- phpBB/phpbb/filesystem.php | 69 +++++++++++++++++++ tests/dbal/migrator_test.php | 2 +- tests/extension/manager_test.php | 2 +- tests/extension/metadata_manager_test.php | 2 +- tests/filesystem/clean_path_test.php | 2 +- tests/mock/extension_manager.php | 2 +- .../phpbb_functional_test_case.php | 2 +- 10 files changed, 83 insertions(+), 51 deletions(-) diff --git a/phpBB/common.php b/phpBB/common.php index a7b7db28ac..cbcd146832 100644 --- a/phpBB/common.php +++ b/phpBB/common.php @@ -47,7 +47,7 @@ if (!defined('PHPBB_INSTALLED')) // Eliminate . and .. from the path require($phpbb_root_path . 'phpbb/filesystem.' . $phpEx); - $phpbb_filesystem = new phpbb_filesystem(); + $phpbb_filesystem = new phpbb_filesystem($phpbb_root_path); $script_path = $phpbb_filesystem->clean_path($script_path); $url = (($secure) ? 'https://' : 'http://') . $server_name; diff --git a/phpBB/config/services.yml b/phpBB/config/services.yml index 2808e81337..01e470f87f 100644 --- a/phpBB/config/services.yml +++ b/phpBB/config/services.yml @@ -169,6 +169,8 @@ services: filesystem: class: phpbb_filesystem + arguments: + - %core.root_path% groupposition.legend: class: phpbb_groupposition_legend diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index 7cc3e11129..844609e4e3 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -7,8 +7,6 @@ * */ -use Symfony\Component\HttpFoundation\Request; - /** * @ignore */ @@ -2413,7 +2411,7 @@ function append_sid($url, $params = false, $is_amp = true, $session_id = false) { global $_SID, $_EXTRA_URL, $phpbb_hook; global $phpbb_dispatcher; - global $symfony_request, $phpbb_root_path; + global $symfony_request, $phpbb_root_path, $phpbb_container; if ($params === '' || (is_array($params) && empty($params))) { @@ -2421,7 +2419,8 @@ function append_sid($url, $params = false, $is_amp = true, $session_id = false) $params = false; } - $corrected_path = $symfony_request !== null ? phpbb_get_web_root_path($symfony_request, $phpbb_root_path) : ''; + $phpbb_filesystem = $phpbb_container->get('filesystem'); + $corrected_path = $phpbb_filesystem->get_web_root_path($symfony_request); if ($corrected_path) { $url = substr($corrected_path . $url, strlen($phpbb_root_path)); @@ -5218,7 +5217,8 @@ function page_header($page_title = '', $display_online_list = true, $item_id = 0 // This path is sent with the base template paths in the assign_vars() // call below. We need to correct it in case we are accessing from a // controller because the web paths will be incorrect otherwise. - $corrected_path = $symfony_request !== null ? phpbb_get_web_root_path($symfony_request, $phpbb_root_path) : ''; + $phpbb_filesystem = $phpbb_container->get('filesystem'); + $corrected_path = $phpbb_filesystem->get_web_root_path($symfony_request); $web_path = (defined('PHPBB_USE_BOARD_URL_PATH') && PHPBB_USE_BOARD_URL_PATH) ? $board_url : $corrected_path; // Send a proper content-language to the output @@ -5725,42 +5725,3 @@ function phpbb_create_symfony_request(phpbb_request $request) $symfony_request = new Request($get_parameters, $post_parameters, array(), $cookie_parameters, $files_parameters, $server_parameters); return $symfony_request; } - -/** -* Get a relative root path from the current URL -* -* @param Request $symfony_request Symfony Request object -*/ -function phpbb_get_web_root_path(Request $symfony_request, $phpbb_root_path = '') -{ - global $phpbb_container; - - static $path; - if (null !== $path) - { - return $path; - } - - $path_info = $symfony_request->getPathInfo(); - if ($path_info === '/') - { - $path = $phpbb_root_path; - return $path; - } - - $filesystem = $phpbb_container->get('filesystem'); - $path_info = $filesystem->clean_path($path_info); - - // Do not count / at start of path - $corrections = substr_count(substr($path_info, 1), '/'); - - // When URL Rewriting is enabled, app.php is optional. We have to - // correct for it not being there - if (strpos($symfony_request->getRequestUri(), $symfony_request->getScriptName()) === false) - { - $corrections -= 1; - } - - $path = $phpbb_root_path . str_repeat('../', $corrections); - return $path; -} diff --git a/phpBB/phpbb/filesystem.php b/phpBB/phpbb/filesystem.php index 27cab48fb0..a85a254865 100644 --- a/phpBB/phpbb/filesystem.php +++ b/phpBB/phpbb/filesystem.php @@ -6,6 +6,9 @@ * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 * */ + +use Symfony\Component\HttpFoundation\Request; + /** * @ignore */ @@ -20,6 +23,72 @@ if (!defined('IN_PHPBB')) */ class phpbb_filesystem { + /** @var string */ + protected $phpbb_root_path; + + /** + * Constructor + * + * @param string $phpbb_root_path + */ + public function __construct($phpbb_root_path) + { + $this->phpbb_root_path = $phpbb_root_path; + } + + /** + * Get the phpBB root path + * + * @return string + */ + public function get_phpbb_root_path() + { + return $this->phpbb_root_path; + } + + /** + * Get a relative root path from the current URL + * + * @param Request $symfony_request Symfony Request object + * @return string + */ + function get_web_root_path(Request $symfony_request = null) + { + if ($symfony_request === null) + { + return ''; + } + + static $path; + if (null !== $path) + { + return $path; + } + + $path_info = $symfony_request->getPathInfo(); + if ($path_info === '/') + { + $path = $this->phpbb_root_path; + return $path; + } + + $path_info = $this->clean_path($path_info); + + // Do not count / at start of path + $corrections = substr_count(substr($path_info, 1), '/'); + + // When URL Rewriting is enabled, app.php is optional. We have to + // correct for it not being there + if (strpos($symfony_request->getRequestUri(), $symfony_request->getScriptName()) === false) + { + $corrections -= 1; + } + + $path = $this->phpbb_root_path . str_repeat('../', $corrections); + + return $path; + } + /** * Eliminates useless . and .. components from specified path. * diff --git a/tests/dbal/migrator_test.php b/tests/dbal/migrator_test.php index 9e55e4dd35..4be1fbe176 100644 --- a/tests/dbal/migrator_test.php +++ b/tests/dbal/migrator_test.php @@ -59,7 +59,7 @@ class phpbb_dbal_migrator_test extends phpbb_database_test_case $container, $this->db, $this->config, - new phpbb_filesystem(), + new phpbb_filesystem(dirname(__FILE__) . '/../../phpBB/'), 'phpbb_ext', dirname(__FILE__) . '/../../phpBB/', 'php', diff --git a/tests/extension/manager_test.php b/tests/extension/manager_test.php index a23e5a18d9..2da6ba5df5 100644 --- a/tests/extension/manager_test.php +++ b/tests/extension/manager_test.php @@ -114,7 +114,7 @@ class phpbb_extension_manager_test extends phpbb_database_test_case $container, $db, $config, - new phpbb_filesystem(), + new phpbb_filesystem($phpbb_root_path), 'phpbb_ext', dirname(__FILE__) . '/', $php_ext, diff --git a/tests/extension/metadata_manager_test.php b/tests/extension/metadata_manager_test.php index e5bd29092e..594568b805 100644 --- a/tests/extension/metadata_manager_test.php +++ b/tests/extension/metadata_manager_test.php @@ -65,7 +65,7 @@ class phpbb_extension_metadata_manager_test extends phpbb_database_test_case $container, $this->db, $this->config, - new phpbb_filesystem(), + new phpbb_filesystem($this->phpbb_root_path), 'phpbb_ext', $this->phpbb_root_path, $this->phpEx, diff --git a/tests/filesystem/clean_path_test.php b/tests/filesystem/clean_path_test.php index 50951fc88c..88352838bb 100644 --- a/tests/filesystem/clean_path_test.php +++ b/tests/filesystem/clean_path_test.php @@ -14,7 +14,7 @@ class phpbb_filesystem_clean_path_test extends phpbb_test_case public function setUp() { parent::setUp(); - $this->filesystem = new phpbb_filesystem(); + $this->filesystem = new phpbb_filesystem(__DIR__ . './../../phpBB/'); } public function clean_path_data() diff --git a/tests/mock/extension_manager.php b/tests/mock/extension_manager.php index 10b3595206..28eec5930f 100644 --- a/tests/mock/extension_manager.php +++ b/tests/mock/extension_manager.php @@ -14,6 +14,6 @@ class phpbb_mock_extension_manager extends phpbb_extension_manager $this->phpbb_root_path = $phpbb_root_path; $this->php_ext = 'php'; $this->extensions = $extensions; - $this->filesystem = new phpbb_filesystem(); + $this->filesystem = new phpbb_filesystem($phpbb_root_path); } } diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index ce748bb9cf..dedaf4cd68 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -203,7 +203,7 @@ class phpbb_functional_test_case extends phpbb_test_case $container, $db, $config, - new phpbb_filesystem(), + new phpbb_filesystem($phpbb_root_path), self::$config['table_prefix'] . 'ext', dirname(__FILE__) . '/', $php_ext, From 6692db892f538d3a72f1dbd06af9a94f24a9da9a Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Mon, 9 Sep 2013 18:19:50 -0500 Subject: [PATCH 02/19] [ticket/11832] update_web_root_path helper and tests PHPBB3-11832 --- phpBB/includes/functions.php | 7 +-- phpBB/phpbb/filesystem.php | 34 +++++++++--- tests/filesystem/web_root_path_test.php | 70 +++++++++++++++++++++++++ 3 files changed, 99 insertions(+), 12 deletions(-) create mode 100644 tests/filesystem/web_root_path_test.php diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index 844609e4e3..124c0de169 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -2419,12 +2419,9 @@ function append_sid($url, $params = false, $is_amp = true, $session_id = false) $params = false; } + // Update the root path with the correct relative web path $phpbb_filesystem = $phpbb_container->get('filesystem'); - $corrected_path = $phpbb_filesystem->get_web_root_path($symfony_request); - if ($corrected_path) - { - $url = substr($corrected_path . $url, strlen($phpbb_root_path)); - } + $url = $phpbb_filesystem->update_web_root_path($url, $symfony_request); $append_sid_overwrite = false; diff --git a/phpBB/phpbb/filesystem.php b/phpBB/phpbb/filesystem.php index a85a254865..e8fd03d103 100644 --- a/phpBB/phpbb/filesystem.php +++ b/phpBB/phpbb/filesystem.php @@ -46,17 +46,40 @@ class phpbb_filesystem return $this->phpbb_root_path; } + /** + * Update a path to the correct relative root path + * + * This replaces $phpbb_root_path . some_url with + * get_web_root_path() . some_url OR if $phpbb_root_path + * is not at the beginning of $path, just prepends the + * web root path + * + * @param Request $symfony_request Symfony Request object + * @return string + */ + public function update_web_root_path($path, Request $symfony_request = null) + { + $web_root_path = $this->get_web_root_path($symfony_request); + + if (strpos($path, $this->phpbb_root_path) === 0) + { + $path = substr($path, strlen($this->phpbb_root_path)); + } + + return $web_root_path . $path; + } + /** * Get a relative root path from the current URL * * @param Request $symfony_request Symfony Request object * @return string */ - function get_web_root_path(Request $symfony_request = null) + public function get_web_root_path(Request $symfony_request = null) { if ($symfony_request === null) { - return ''; + return $this->phpbb_root_path; } static $path; @@ -68,8 +91,7 @@ class phpbb_filesystem $path_info = $symfony_request->getPathInfo(); if ($path_info === '/') { - $path = $this->phpbb_root_path; - return $path; + return $path = $this->phpbb_root_path; } $path_info = $this->clean_path($path_info); @@ -84,9 +106,7 @@ class phpbb_filesystem $corrections -= 1; } - $path = $this->phpbb_root_path . str_repeat('../', $corrections); - - return $path; + return $path = $this->phpbb_root_path . str_repeat('../', $corrections); } /** diff --git a/tests/filesystem/web_root_path_test.php b/tests/filesystem/web_root_path_test.php new file mode 100644 index 0000000000..7b44ac8c67 --- /dev/null +++ b/tests/filesystem/web_root_path_test.php @@ -0,0 +1,70 @@ +set_phpbb_root_path(); + + $this->filesystem = new phpbb_filesystem($this->phpbb_root_path); + } + + /** + * Set the phpbb_root_path + * + * This is necessary because dataProvider functions are called + * before setUp or setUpBeforeClass; so we must set the path + * any time we wish to use it in one of these functions (and + * also in general for everything else) + */ + public function set_phpbb_root_path() + { + $this->phpbb_root_path = __DIR__ . './../../phpBB/'; + } + + public function test_get_web_root_path() + { + // Symfony Request = null, so always should return phpbb_root_path + $this->assertEquals($this->phpbb_root_path, $this->filesystem->get_web_root_path()); + } + + public function update_web_root_path_data() + { + $this->set_phpbb_root_path(); + + return array( + array( + $this->phpbb_root_path . 'test.php', + $this->phpbb_root_path . 'test.php', + ), + array( + 'test.php', + $this->phpbb_root_path . 'test.php', + ), + array( + $this->phpbb_root_path . $this->phpbb_root_path . 'test.php', + $this->phpbb_root_path . $this->phpbb_root_path . 'test.php', + ), + ); + } + + /** + * @dataProvider update_web_root_path_data + */ + public function test_update_web_root_path($input, $expected) + { + $this->assertEquals($expected, $this->filesystem->update_web_root_path($input)); + } +} From 289bc2a411aac4f0adb9b7b649dfd9ef073eaed9 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Mon, 9 Sep 2013 18:27:12 -0500 Subject: [PATCH 03/19] [ticket/11832] Fix log tests PHPBB3-11832 --- tests/log/function_view_log_test.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/log/function_view_log_test.php b/tests/log/function_view_log_test.php index 6827aaa1b6..a634863fb6 100644 --- a/tests/log/function_view_log_test.php +++ b/tests/log/function_view_log_test.php @@ -23,8 +23,10 @@ class phpbb_log_function_view_log_test extends phpbb_database_test_case public static function view_log_function_data() { - global $phpEx, $phpbb_dispatcher; + global $phpEx, $phpbb_dispatcher, $phpbb_container, $phpbb_root_path; $phpbb_dispatcher = new phpbb_mock_event_dispatcher(); + $phpbb_container = new phpbb_mock_container_builder(); + $phpbb_container->set('filesystem', new phpbb_filesystem($phpbb_root_path)); $expected_data_sets = array( 1 => array( From 5e09afa0bc3ff9014812282fd4454f0df54b9dfd Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Mon, 9 Sep 2013 18:47:25 -0500 Subject: [PATCH 04/19] [ticket/11832] Make $phpbb_container a global initiated by the framework Setup common items needed from the container (e.g. filesystem) PHPBB3-11832 --- tests/acp_board/select_auth_method_test.php | 5 +---- tests/content_visibility/delete_post_test.php | 7 +++---- tests/log/function_view_log_test.php | 4 +--- tests/test_framework/phpbb_database_test_case.php | 11 +++++++++++ tests/test_framework/phpbb_test_case.php | 11 +++++++++++ 5 files changed, 27 insertions(+), 11 deletions(-) diff --git a/tests/acp_board/select_auth_method_test.php b/tests/acp_board/select_auth_method_test.php index 91aa5d1232..aaad05b33a 100644 --- a/tests/acp_board/select_auth_method_test.php +++ b/tests/acp_board/select_auth_method_test.php @@ -27,10 +27,7 @@ class phpbb_acp_board_select_auth_method_test extends phpbb_test_case { parent::setUp(); - global $phpbb_container; - $phpbb_container = new phpbb_mock_container_builder(); - - $phpbb_container->set('auth.provider_collection', array( + $this->phpbb_container->set('auth.provider_collection', array( 'auth.provider.acp_board_valid' => new phpbb_auth_provider_acp_board_valid, 'auth.provider.acp_board_invalid' => new phpbb_auth_provider_acp_board_invalid, )); diff --git a/tests/content_visibility/delete_post_test.php b/tests/content_visibility/delete_post_test.php index 6234aac9ad..f5df5e9cba 100644 --- a/tests/content_visibility/delete_post_test.php +++ b/tests/content_visibility/delete_post_test.php @@ -262,7 +262,7 @@ class phpbb_content_visibility_delete_post_test extends phpbb_database_test_case */ public function test_delete_post($forum_id, $topic_id, $post_id, $data, $is_soft, $reason, $expected_posts, $expected_topic, $expected_forum) { - global $auth, $cache, $config, $db, $phpbb_container, $phpbb_root_path, $phpEx; + global $auth, $cache, $config, $db, $phpbb_root_path, $phpEx; $config['search_type'] = 'phpbb_mock_search'; $cache = new phpbb_mock_cache; @@ -279,9 +279,8 @@ class phpbb_content_visibility_delete_post_test extends phpbb_database_test_case ))); $user = $this->getMock('phpbb_user'); - $phpbb_container = new phpbb_mock_container_builder(); - $phpbb_container->set('notification_manager', new phpbb_mock_notification_manager()); - $phpbb_container->set('content.visibility', new phpbb_content_visibility($auth, $db, $user, $phpbb_root_path, $phpEx, FORUMS_TABLE, POSTS_TABLE, TOPICS_TABLE, USERS_TABLE)); + $this->phpbb_container->set('notification_manager', new phpbb_mock_notification_manager()); + $this->phpbb_container->set('content.visibility', new phpbb_content_visibility($auth, $db, $user, $phpbb_root_path, $phpEx, FORUMS_TABLE, POSTS_TABLE, TOPICS_TABLE, USERS_TABLE)); delete_post($forum_id, $topic_id, $post_id, $data, $is_soft, $reason); diff --git a/tests/log/function_view_log_test.php b/tests/log/function_view_log_test.php index a634863fb6..6827aaa1b6 100644 --- a/tests/log/function_view_log_test.php +++ b/tests/log/function_view_log_test.php @@ -23,10 +23,8 @@ class phpbb_log_function_view_log_test extends phpbb_database_test_case public static function view_log_function_data() { - global $phpEx, $phpbb_dispatcher, $phpbb_container, $phpbb_root_path; + global $phpEx, $phpbb_dispatcher; $phpbb_dispatcher = new phpbb_mock_event_dispatcher(); - $phpbb_container = new phpbb_mock_container_builder(); - $phpbb_container->set('filesystem', new phpbb_filesystem($phpbb_root_path)); $expected_data_sets = array( 1 => array( diff --git a/tests/test_framework/phpbb_database_test_case.php b/tests/test_framework/phpbb_database_test_case.php index c72ea5f765..124706afa6 100644 --- a/tests/test_framework/phpbb_database_test_case.php +++ b/tests/test_framework/phpbb_database_test_case.php @@ -17,9 +17,20 @@ abstract class phpbb_database_test_case extends PHPUnit_Extensions_Database_Test protected $fixture_xml_data; + protected $phpbb_container; + public function __construct($name = NULL, array $data = array(), $dataName = '') { parent::__construct($name, $data, $dataName); + + global $phpbb_container, $phpbb_root_path; + + // Setup the container for global usage + $this->phpbb_container = $phpbb_container = new phpbb_mock_container_builder(); + + // Set some commonly needed systems up + $phpbb_container->set('filesystem', new phpbb_filesystem($phpbb_root_path)); + $this->backupStaticAttributesBlacklist += array( 'PHP_CodeCoverage' => array('instance'), 'PHP_CodeCoverage_Filter' => array('instance'), diff --git a/tests/test_framework/phpbb_test_case.php b/tests/test_framework/phpbb_test_case.php index 8b16f02638..48c2f48887 100644 --- a/tests/test_framework/phpbb_test_case.php +++ b/tests/test_framework/phpbb_test_case.php @@ -11,9 +11,20 @@ class phpbb_test_case extends PHPUnit_Framework_TestCase { protected $test_case_helpers; + protected $phpbb_container; + public function __construct($name = NULL, array $data = array(), $dataName = '') { parent::__construct($name, $data, $dataName); + + global $phpbb_container, $phpbb_root_path; + + // Setup the container for global usage + $this->phpbb_container = $phpbb_container = new phpbb_mock_container_builder(); + + // Set some commonly needed systems up + $phpbb_container->set('filesystem', new phpbb_filesystem($phpbb_root_path)); + $this->backupStaticAttributesBlacklist += array( 'PHP_CodeCoverage' => array('instance'), 'PHP_CodeCoverage_Filter' => array('instance'), From d5f93f5ce4c25b4bd0aff9473eb47eeeb1afccd4 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Tue, 10 Sep 2013 10:06:13 -0500 Subject: [PATCH 05/19] Revert "[ticket/11832] Make $phpbb_container a global initiated by the framework" This reverts commit 5e09afa0bc3ff9014812282fd4454f0df54b9dfd. --- tests/acp_board/select_auth_method_test.php | 5 ++++- tests/content_visibility/delete_post_test.php | 7 ++++--- tests/log/function_view_log_test.php | 4 +++- tests/test_framework/phpbb_database_test_case.php | 11 ----------- tests/test_framework/phpbb_test_case.php | 11 ----------- 5 files changed, 11 insertions(+), 27 deletions(-) diff --git a/tests/acp_board/select_auth_method_test.php b/tests/acp_board/select_auth_method_test.php index aaad05b33a..91aa5d1232 100644 --- a/tests/acp_board/select_auth_method_test.php +++ b/tests/acp_board/select_auth_method_test.php @@ -27,7 +27,10 @@ class phpbb_acp_board_select_auth_method_test extends phpbb_test_case { parent::setUp(); - $this->phpbb_container->set('auth.provider_collection', array( + global $phpbb_container; + $phpbb_container = new phpbb_mock_container_builder(); + + $phpbb_container->set('auth.provider_collection', array( 'auth.provider.acp_board_valid' => new phpbb_auth_provider_acp_board_valid, 'auth.provider.acp_board_invalid' => new phpbb_auth_provider_acp_board_invalid, )); diff --git a/tests/content_visibility/delete_post_test.php b/tests/content_visibility/delete_post_test.php index f5df5e9cba..6234aac9ad 100644 --- a/tests/content_visibility/delete_post_test.php +++ b/tests/content_visibility/delete_post_test.php @@ -262,7 +262,7 @@ class phpbb_content_visibility_delete_post_test extends phpbb_database_test_case */ public function test_delete_post($forum_id, $topic_id, $post_id, $data, $is_soft, $reason, $expected_posts, $expected_topic, $expected_forum) { - global $auth, $cache, $config, $db, $phpbb_root_path, $phpEx; + global $auth, $cache, $config, $db, $phpbb_container, $phpbb_root_path, $phpEx; $config['search_type'] = 'phpbb_mock_search'; $cache = new phpbb_mock_cache; @@ -279,8 +279,9 @@ class phpbb_content_visibility_delete_post_test extends phpbb_database_test_case ))); $user = $this->getMock('phpbb_user'); - $this->phpbb_container->set('notification_manager', new phpbb_mock_notification_manager()); - $this->phpbb_container->set('content.visibility', new phpbb_content_visibility($auth, $db, $user, $phpbb_root_path, $phpEx, FORUMS_TABLE, POSTS_TABLE, TOPICS_TABLE, USERS_TABLE)); + $phpbb_container = new phpbb_mock_container_builder(); + $phpbb_container->set('notification_manager', new phpbb_mock_notification_manager()); + $phpbb_container->set('content.visibility', new phpbb_content_visibility($auth, $db, $user, $phpbb_root_path, $phpEx, FORUMS_TABLE, POSTS_TABLE, TOPICS_TABLE, USERS_TABLE)); delete_post($forum_id, $topic_id, $post_id, $data, $is_soft, $reason); diff --git a/tests/log/function_view_log_test.php b/tests/log/function_view_log_test.php index 6827aaa1b6..a634863fb6 100644 --- a/tests/log/function_view_log_test.php +++ b/tests/log/function_view_log_test.php @@ -23,8 +23,10 @@ class phpbb_log_function_view_log_test extends phpbb_database_test_case public static function view_log_function_data() { - global $phpEx, $phpbb_dispatcher; + global $phpEx, $phpbb_dispatcher, $phpbb_container, $phpbb_root_path; $phpbb_dispatcher = new phpbb_mock_event_dispatcher(); + $phpbb_container = new phpbb_mock_container_builder(); + $phpbb_container->set('filesystem', new phpbb_filesystem($phpbb_root_path)); $expected_data_sets = array( 1 => array( diff --git a/tests/test_framework/phpbb_database_test_case.php b/tests/test_framework/phpbb_database_test_case.php index 124706afa6..c72ea5f765 100644 --- a/tests/test_framework/phpbb_database_test_case.php +++ b/tests/test_framework/phpbb_database_test_case.php @@ -17,20 +17,9 @@ abstract class phpbb_database_test_case extends PHPUnit_Extensions_Database_Test protected $fixture_xml_data; - protected $phpbb_container; - public function __construct($name = NULL, array $data = array(), $dataName = '') { parent::__construct($name, $data, $dataName); - - global $phpbb_container, $phpbb_root_path; - - // Setup the container for global usage - $this->phpbb_container = $phpbb_container = new phpbb_mock_container_builder(); - - // Set some commonly needed systems up - $phpbb_container->set('filesystem', new phpbb_filesystem($phpbb_root_path)); - $this->backupStaticAttributesBlacklist += array( 'PHP_CodeCoverage' => array('instance'), 'PHP_CodeCoverage_Filter' => array('instance'), diff --git a/tests/test_framework/phpbb_test_case.php b/tests/test_framework/phpbb_test_case.php index 48c2f48887..8b16f02638 100644 --- a/tests/test_framework/phpbb_test_case.php +++ b/tests/test_framework/phpbb_test_case.php @@ -11,20 +11,9 @@ class phpbb_test_case extends PHPUnit_Framework_TestCase { protected $test_case_helpers; - protected $phpbb_container; - public function __construct($name = NULL, array $data = array(), $dataName = '') { parent::__construct($name, $data, $dataName); - - global $phpbb_container, $phpbb_root_path; - - // Setup the container for global usage - $this->phpbb_container = $phpbb_container = new phpbb_mock_container_builder(); - - // Set some commonly needed systems up - $phpbb_container->set('filesystem', new phpbb_filesystem($phpbb_root_path)); - $this->backupStaticAttributesBlacklist += array( 'PHP_CodeCoverage' => array('instance'), 'PHP_CodeCoverage_Filter' => array('instance'), From 3684d8e9711516264fedac0519262891d9894ea1 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Tue, 10 Sep 2013 10:13:26 -0500 Subject: [PATCH 06/19] [ticket/11832] Use $phpbb_filesystem instead of the container in append_sid PHPBB3-11832 --- phpBB/includes/functions.php | 10 ++++++---- tests/filesystem/web_root_path_test.php | 4 +++- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index 124c0de169..45f0ae44da 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -2409,7 +2409,7 @@ function phpbb_on_page($template, $user, $base_url, $num_items, $per_page, $star */ function append_sid($url, $params = false, $is_amp = true, $session_id = false) { - global $_SID, $_EXTRA_URL, $phpbb_hook; + global $_SID, $_EXTRA_URL, $phpbb_hook, $phpbb_filesystem; global $phpbb_dispatcher; global $symfony_request, $phpbb_root_path, $phpbb_container; @@ -2420,8 +2420,10 @@ function append_sid($url, $params = false, $is_amp = true, $session_id = false) } // Update the root path with the correct relative web path - $phpbb_filesystem = $phpbb_container->get('filesystem'); - $url = $phpbb_filesystem->update_web_root_path($url, $symfony_request); + if ($phpbb_filesystem instanceof phpbb_filesystem) + { + $url = $phpbb_filesystem->update_web_root_path($url, $symfony_request); + } $append_sid_overwrite = false; @@ -5719,6 +5721,6 @@ function phpbb_create_symfony_request(phpbb_request $request) array_walk_recursive($get_parameters, $sanitizer); array_walk_recursive($post_parameters, $sanitizer); - $symfony_request = new Request($get_parameters, $post_parameters, array(), $cookie_parameters, $files_parameters, $server_parameters); + $symfony_request = new Symfony\Component\HttpFoundation\Request($get_parameters, $post_parameters, array(), $cookie_parameters, $files_parameters, $server_parameters); return $symfony_request; } diff --git a/tests/filesystem/web_root_path_test.php b/tests/filesystem/web_root_path_test.php index 7b44ac8c67..3c530619dc 100644 --- a/tests/filesystem/web_root_path_test.php +++ b/tests/filesystem/web_root_path_test.php @@ -18,7 +18,9 @@ class phpbb_filesystem_web_root_path_test extends phpbb_test_case $this->set_phpbb_root_path(); - $this->filesystem = new phpbb_filesystem($this->phpbb_root_path); + global $phpbb_filesystem; + + $phpbb_filesystem = $this->filesystem = new phpbb_filesystem($this->phpbb_root_path); } /** From c46637990e5937881f98d9711783fe9982532884 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Tue, 10 Sep 2013 10:14:57 -0500 Subject: [PATCH 07/19] [ticket/11832] Use dirname(__FILE__) PHPBB3-11832 --- tests/filesystem/web_root_path_test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/filesystem/web_root_path_test.php b/tests/filesystem/web_root_path_test.php index 3c530619dc..3c9637fe06 100644 --- a/tests/filesystem/web_root_path_test.php +++ b/tests/filesystem/web_root_path_test.php @@ -33,7 +33,7 @@ class phpbb_filesystem_web_root_path_test extends phpbb_test_case */ public function set_phpbb_root_path() { - $this->phpbb_root_path = __DIR__ . './../../phpBB/'; + $this->phpbb_root_path = dirname(__FILE__) . './../../phpBB/'; } public function test_get_web_root_path() From 3a4efa79592616ac099e95d07e9aed52bc5a19a3 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Tue, 10 Sep 2013 11:15:24 -0500 Subject: [PATCH 08/19] [ticket/11832] More extensive testing PHPBB3-11832 --- phpBB/phpbb/filesystem.php | 12 +++--- tests/filesystem/web_root_path_test.php | 49 +++++++++++++++++++++---- 2 files changed, 49 insertions(+), 12 deletions(-) diff --git a/phpBB/phpbb/filesystem.php b/phpBB/phpbb/filesystem.php index e8fd03d103..6c037b2656 100644 --- a/phpBB/phpbb/filesystem.php +++ b/phpBB/phpbb/filesystem.php @@ -26,6 +26,9 @@ class phpbb_filesystem /** @var string */ protected $phpbb_root_path; + /** @var string */ + protected $web_root_path; + /** * Constructor * @@ -82,16 +85,15 @@ class phpbb_filesystem return $this->phpbb_root_path; } - static $path; - if (null !== $path) + if (null !== $this->web_root_path) { - return $path; + return $this->web_root_path; } $path_info = $symfony_request->getPathInfo(); if ($path_info === '/') { - return $path = $this->phpbb_root_path; + return $this->web_root_path = $this->phpbb_root_path; } $path_info = $this->clean_path($path_info); @@ -106,7 +108,7 @@ class phpbb_filesystem $corrections -= 1; } - return $path = $this->phpbb_root_path . str_repeat('../', $corrections); + return $this->web_root_path = $this->phpbb_root_path . str_repeat('../', $corrections); } /** diff --git a/tests/filesystem/web_root_path_test.php b/tests/filesystem/web_root_path_test.php index 3c9637fe06..badc2fab58 100644 --- a/tests/filesystem/web_root_path_test.php +++ b/tests/filesystem/web_root_path_test.php @@ -18,9 +18,7 @@ class phpbb_filesystem_web_root_path_test extends phpbb_test_case $this->set_phpbb_root_path(); - global $phpbb_filesystem; - - $phpbb_filesystem = $this->filesystem = new phpbb_filesystem($this->phpbb_root_path); + $this->filesystem = new phpbb_filesystem($this->phpbb_root_path); } /** @@ -49,7 +47,6 @@ class phpbb_filesystem_web_root_path_test extends phpbb_test_case return array( array( $this->phpbb_root_path . 'test.php', - $this->phpbb_root_path . 'test.php', ), array( 'test.php', @@ -57,7 +54,28 @@ class phpbb_filesystem_web_root_path_test extends phpbb_test_case ), array( $this->phpbb_root_path . $this->phpbb_root_path . 'test.php', - $this->phpbb_root_path . $this->phpbb_root_path . 'test.php', + ), + array( + $this->phpbb_root_path . 'test.php', + $this->phpbb_root_path . 'test.php', + '/', + ), + array( + $this->phpbb_root_path . 'test.php', + $this->phpbb_root_path . 'test.php', + '//', + ), + array( + $this->phpbb_root_path . 'test.php', + $this->phpbb_root_path . '../test.php', + '//', + 'foo/bar.php', + 'bar.php', + ), + array( + $this->phpbb_root_path . 'test.php', + $this->phpbb_root_path . '../../test.php', + '////', ), ); } @@ -65,8 +83,25 @@ class phpbb_filesystem_web_root_path_test extends phpbb_test_case /** * @dataProvider update_web_root_path_data */ - public function test_update_web_root_path($input, $expected) + public function test_update_web_root_path($input, $expected = null, $getPathInfo = null, $getRequestUri = null, $getScriptName = null) { - $this->assertEquals($expected, $this->filesystem->update_web_root_path($input)); + $expected = ($expected === null) ? $input : $expected; + + $symfony_request = null; + if ($getPathInfo !== null) + { + $symfony_request = $this->getMock("Symfony\Component\HttpFoundation\Request"); + $symfony_request->expects($this->any()) + ->method('getPathInfo') + ->will($this->returnValue($getPathInfo)); + $symfony_request->expects($this->any()) + ->method('getRequestUri') + ->will($this->returnValue($getRequestUri)); + $symfony_request->expects($this->any()) + ->method('getScriptName') + ->will($this->returnValue($getScriptName)); + } + + $this->assertEquals($expected, $this->filesystem->update_web_root_path($input, $symfony_request)); } } From b06c8a80d15c52dd53b12065d5e6e9d56f203ceb Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Thu, 12 Sep 2013 10:25:49 -0500 Subject: [PATCH 09/19] [ticket/11832] Fix the web path corrections Add some real life examples to test PHPBB3-11832 --- phpBB/phpbb/filesystem.php | 44 +++++++++++++++++++------ tests/filesystem/web_root_path_test.php | 13 ++++++-- 2 files changed, 45 insertions(+), 12 deletions(-) diff --git a/phpBB/phpbb/filesystem.php b/phpBB/phpbb/filesystem.php index 6c037b2656..a2dfab40e5 100644 --- a/phpBB/phpbb/filesystem.php +++ b/phpBB/phpbb/filesystem.php @@ -90,25 +90,49 @@ class phpbb_filesystem return $this->web_root_path; } - $path_info = $symfony_request->getPathInfo(); + // Path info (e.g. /foo/bar) + $path_info = $this->clean_path($symfony_request->getPathInfo()); + + // Full request URI (e.g. phpBB/index.php/foo/bar) + $request_uri = $symfony_request->getRequestUri(); + + // Script name URI (e.g. phpBB/index.php) + $script_name = $symfony_request->getScriptName(); + + /* + * If the path info is empty (single /), then we're not using + * a route like index.php/foo/bar + */ if ($path_info === '/') { return $this->web_root_path = $this->phpbb_root_path; } - $path_info = $this->clean_path($path_info); + // How many corrections might we need? + $corrections = substr_count($path_info, '/'); - // Do not count / at start of path - $corrections = substr_count(substr($path_info, 1), '/'); - - // When URL Rewriting is enabled, app.php is optional. We have to - // correct for it not being there - if (strpos($symfony_request->getRequestUri(), $symfony_request->getScriptName()) === false) + /* + * If the script name (e.g. phpBB/app.php) exists in the + * requestUri (e.g. phpBB/app.php/foo/template), then we + * are have a non-rewritten URL. + */ + if (strpos($request_uri, $script_name) === 0) { - $corrections -= 1; + /* + * Append ../ to the end of the phpbb_root_path as many times + * as / exists in path_info + */ + return $this->web_root_path = $this->phpbb_root_path . str_repeat('../', $corrections); } - return $this->web_root_path = $this->phpbb_root_path . str_repeat('../', $corrections); + /* + * If we're here it means we're at a re-written path, so we must + * correct the relative path for web URLs. We must append ../ + * to the end of the root path as many times as / exists in path_info + * less one time (because the script, e.g. /app.php, doesn't exist in + * the URL) + */ + return $this->web_root_path = $this->phpbb_root_path . str_repeat('../', $corrections - 1); } /** diff --git a/tests/filesystem/web_root_path_test.php b/tests/filesystem/web_root_path_test.php index badc2fab58..8e0ba278e0 100644 --- a/tests/filesystem/web_root_path_test.php +++ b/tests/filesystem/web_root_path_test.php @@ -62,7 +62,7 @@ class phpbb_filesystem_web_root_path_test extends phpbb_test_case ), array( $this->phpbb_root_path . 'test.php', - $this->phpbb_root_path . 'test.php', + $this->phpbb_root_path . '../test.php', '//', ), array( @@ -75,7 +75,16 @@ class phpbb_filesystem_web_root_path_test extends phpbb_test_case array( $this->phpbb_root_path . 'test.php', $this->phpbb_root_path . '../../test.php', - '////', + '/foo/template', + '/phpbb3-fork/phpBB/app.php/foo/template', + '/phpbb3-fork/phpBB/app.php', + ), + array( + $this->phpbb_root_path . 'test.php', + $this->phpbb_root_path . '../test.php', + '/foo/template', + '/phpbb3-fork/phpBB/foo/template', + '/phpbb3-fork/phpBB/app.php', ), ); } From 946ab9aa75a3b45cc3f6ad17f5a1773bab4fa209 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Thu, 12 Sep 2013 11:05:14 -0500 Subject: [PATCH 10/19] [ticket/11832] We must instantiate the $phpbb_filesystem in common PHPBB3-11832 --- phpBB/common.php | 1 + 1 file changed, 1 insertion(+) diff --git a/phpBB/common.php b/phpBB/common.php index cbcd146832..bfbc5989aa 100644 --- a/phpBB/common.php +++ b/phpBB/common.php @@ -101,6 +101,7 @@ $cache = $phpbb_container->get('cache'); // Instantiate some basic classes $phpbb_dispatcher = $phpbb_container->get('dispatcher'); +$phpbb_filesystem = $phpbb_container->get('filesystem'); $request = $phpbb_container->get('request'); $user = $phpbb_container->get('user'); $auth = $phpbb_container->get('auth'); From 4c00c77739cc20db26d5f87bf26a9a953bc92d3a Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Thu, 12 Sep 2013 11:08:40 -0500 Subject: [PATCH 11/19] [ticket/11832] Changing comments to say app.php rather than index.php PHPBB3-11832 --- phpBB/phpbb/filesystem.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/phpBB/phpbb/filesystem.php b/phpBB/phpbb/filesystem.php index a2dfab40e5..5d70b88a29 100644 --- a/phpBB/phpbb/filesystem.php +++ b/phpBB/phpbb/filesystem.php @@ -93,15 +93,15 @@ class phpbb_filesystem // Path info (e.g. /foo/bar) $path_info = $this->clean_path($symfony_request->getPathInfo()); - // Full request URI (e.g. phpBB/index.php/foo/bar) + // Full request URI (e.g. phpBB/app.php/foo/bar) $request_uri = $symfony_request->getRequestUri(); - // Script name URI (e.g. phpBB/index.php) + // Script name URI (e.g. phpBB/app.php) $script_name = $symfony_request->getScriptName(); /* * If the path info is empty (single /), then we're not using - * a route like index.php/foo/bar + * a route like app.php/foo/bar */ if ($path_info === '/') { From 934786d45da83ec85f5d45794eef8a6221803259 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Thu, 12 Sep 2013 12:30:16 -0500 Subject: [PATCH 12/19] [ticket/11832] Fix build_url and the S_LOGIN_ACTION PHPBB3-11832 --- phpBB/includes/functions.php | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index 2f13de88b6..49d4e03921 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -2814,8 +2814,22 @@ function build_url($strip_vars = false) { global $user, $phpbb_root_path; + $page = $user->page['page']; + + // We need to be cautious here. + // On some situations, the redirect path is an absolute URL, sometimes a relative path + // For a relative path, let's prefix it with $phpbb_root_path to point to the correct location, + // else we use the URL directly. + $url_parts = @parse_url($page); + + // URL + if ($url_parts !== false && !empty($url_parts['scheme']) && !empty($url_parts['host'])) + { + $page = $phpbb_root_path . $page; + } + // Append SID - $redirect = append_sid($user->page['page'], false, false); + $redirect = append_sid($page, false, false); // Add delimiter if not there... if (strpos($redirect, '?') === false) @@ -2870,19 +2884,7 @@ function build_url($strip_vars = false) $redirect .= ($query) ? '?' . $query : ''; } - // We need to be cautious here. - // On some situations, the redirect path is an absolute URL, sometimes a relative path - // For a relative path, let's prefix it with $phpbb_root_path to point to the correct location, - // else we use the URL directly. - $url_parts = @parse_url($redirect); - - // URL - if ($url_parts !== false && !empty($url_parts['scheme']) && !empty($url_parts['host'])) - { - return str_replace('&', '&', $redirect); - } - - return $phpbb_root_path . str_replace('&', '&', $redirect); + return str_replace('&', '&', $redirect); } /** @@ -5079,7 +5081,7 @@ function phpbb_build_hidden_fields_for_query_params($request, $exclude = null) function page_header($page_title = '', $display_online_list = true, $item_id = 0, $item = 'forum') { global $db, $config, $template, $SID, $_SID, $_EXTRA_URL, $user, $auth, $phpEx, $phpbb_root_path; - global $phpbb_dispatcher, $request, $phpbb_container, $symfony_request; + global $phpbb_dispatcher, $request, $phpbb_container, $symfony_request, $adm_relative_path; if (defined('HEADER_INC')) { @@ -5379,7 +5381,7 @@ function page_header($page_title = '', $display_online_list = true, $item_id = 0 'S_FORUM_ID' => $forum_id, 'S_TOPIC_ID' => $topic_id, - 'S_LOGIN_ACTION' => ((!defined('ADMIN_START')) ? append_sid("{$phpbb_root_path}ucp.$phpEx", 'mode=login') : append_sid("index.$phpEx", false, true, $user->session_id)), + 'S_LOGIN_ACTION' => ((!defined('ADMIN_START')) ? append_sid("{$phpbb_root_path}ucp.$phpEx", 'mode=login') : append_sid("{$phpbb_root_path}{$adm_relative_path}index.$phpEx", false, true, $user->session_id)), 'S_LOGIN_REDIRECT' => build_hidden_fields(array('redirect' => build_url())), 'S_ENABLE_FEEDS' => ($config['feed_enable']) ? true : false, From aa710df2db2512f6065f91dcf8b5fc7d100edf41 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Fri, 13 Sep 2013 09:52:02 -0500 Subject: [PATCH 13/19] [ticket/11832] Create phpbb_symfony_request to handle initiating symfony_request Now symfony_request is also a service (removed the function phpbb_create_symfony_request). Inject symfony request into filesystem Cleanup for the tests PHPBB3-11832 --- phpBB/common.php | 4 +- phpBB/config/services.yml | 6 +++ phpBB/includes/functions.php | 41 ------------------ phpBB/phpbb/filesystem.php | 26 ++++++------ phpBB/phpbb/symfony_request.php | 46 +++++++++++++++++++++ tests/filesystem/clean_path_test.php | 7 +++- tests/filesystem/web_root_path_test.php | 55 ++++++++++++++++--------- 7 files changed, 110 insertions(+), 75 deletions(-) create mode 100644 phpBB/phpbb/symfony_request.php diff --git a/phpBB/common.php b/phpBB/common.php index bfbc5989aa..43beb86972 100644 --- a/phpBB/common.php +++ b/phpBB/common.php @@ -101,7 +101,6 @@ $cache = $phpbb_container->get('cache'); // Instantiate some basic classes $phpbb_dispatcher = $phpbb_container->get('dispatcher'); -$phpbb_filesystem = $phpbb_container->get('filesystem'); $request = $phpbb_container->get('request'); $user = $phpbb_container->get('user'); $auth = $phpbb_container->get('auth'); @@ -111,7 +110,8 @@ $db = $phpbb_container->get('dbal.conn'); request_var('', 0, false, false, $request); // "dependency injection" for a function // Create a Symfony Request object from our phpbb_request object -$symfony_request = phpbb_create_symfony_request($request); +$symfony_request = $phpbb_container->get('symfony_request'); +$phpbb_filesystem = $phpbb_container->get('filesystem'); // Grab global variables, re-cache if necessary $config = $phpbb_container->get('config'); diff --git a/phpBB/config/services.yml b/phpBB/config/services.yml index e6a76ce88e..a9c819fe9a 100644 --- a/phpBB/config/services.yml +++ b/phpBB/config/services.yml @@ -170,6 +170,7 @@ services: filesystem: class: phpbb_filesystem arguments: + - @symfony_request - %core.root_path% groupposition.legend: @@ -254,6 +255,11 @@ services: request: class: phpbb_request + symfony_request: + class: phpbb_symfony_request + arguments: + - @request + template: class: phpbb_template_twig arguments: diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index 49d4e03921..ab4df9be54 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -5708,44 +5708,3 @@ function phpbb_convert_30_dbms_to_31($dbms) throw new \RuntimeException("You have specified an invalid dbms driver: $dbms"); } - -/** -* Create a Symfony Request object from phpbb_request object -* -* @param phpbb_request $request Request object -* @return Request A Symfony Request object -*/ -function phpbb_create_symfony_request(phpbb_request $request) -{ - // If we have already gotten it, don't go back through all the trouble of - // creating it again; instead, just return it. This allows multiple calls - // of this method so we don't have to globalize $symfony_request in other - // functions. - static $symfony_request; - if (null !== $symfony_request) - { - return $symfony_request; - } - - // This function is meant to sanitize the global input arrays - $sanitizer = function(&$value, $key) { - $type_cast_helper = new phpbb_request_type_cast_helper(); - $type_cast_helper->set_var($value, $value, gettype($value), true); - }; - - // We need to re-enable the super globals so we can access them here - $request->enable_super_globals(); - $get_parameters = $_GET; - $post_parameters = $_POST; - $server_parameters = $_SERVER; - $files_parameters = $_FILES; - $cookie_parameters = $_COOKIE; - // And now disable them again for security - $request->disable_super_globals(); - - array_walk_recursive($get_parameters, $sanitizer); - array_walk_recursive($post_parameters, $sanitizer); - - $symfony_request = new Symfony\Component\HttpFoundation\Request($get_parameters, $post_parameters, array(), $cookie_parameters, $files_parameters, $server_parameters); - return $symfony_request; -} diff --git a/phpBB/phpbb/filesystem.php b/phpBB/phpbb/filesystem.php index 5d70b88a29..e6c36375af 100644 --- a/phpBB/phpbb/filesystem.php +++ b/phpBB/phpbb/filesystem.php @@ -7,8 +7,6 @@ * */ -use Symfony\Component\HttpFoundation\Request; - /** * @ignore */ @@ -23,6 +21,9 @@ if (!defined('IN_PHPBB')) */ class phpbb_filesystem { + /** @var phpbb_symfony_request */ + protected $symfony_request; + /** @var string */ protected $phpbb_root_path; @@ -32,10 +33,12 @@ class phpbb_filesystem /** * Constructor * + * @param phpbb_symfony_request $symfony_request * @param string $phpbb_root_path */ - public function __construct($phpbb_root_path) + public function __construct(phpbb_symfony_request $symfony_request, $phpbb_root_path) { + $this->symfony_request = $symfony_request; $this->phpbb_root_path = $phpbb_root_path; } @@ -57,12 +60,12 @@ class phpbb_filesystem * is not at the beginning of $path, just prepends the * web root path * - * @param Request $symfony_request Symfony Request object + * @param string $path The path to be updated * @return string */ - public function update_web_root_path($path, Request $symfony_request = null) + public function update_web_root_path($path) { - $web_root_path = $this->get_web_root_path($symfony_request); + $web_root_path = $this->get_web_root_path($this->symfony_request); if (strpos($path, $this->phpbb_root_path) === 0) { @@ -75,12 +78,11 @@ class phpbb_filesystem /** * Get a relative root path from the current URL * - * @param Request $symfony_request Symfony Request object * @return string */ - public function get_web_root_path(Request $symfony_request = null) + public function get_web_root_path() { - if ($symfony_request === null) + if ($this->symfony_request === null) { return $this->phpbb_root_path; } @@ -91,13 +93,13 @@ class phpbb_filesystem } // Path info (e.g. /foo/bar) - $path_info = $this->clean_path($symfony_request->getPathInfo()); + $path_info = $this->clean_path($this->symfony_request->getPathInfo()); // Full request URI (e.g. phpBB/app.php/foo/bar) - $request_uri = $symfony_request->getRequestUri(); + $request_uri = $this->symfony_request->getRequestUri(); // Script name URI (e.g. phpBB/app.php) - $script_name = $symfony_request->getScriptName(); + $script_name = $this->symfony_request->getScriptName(); /* * If the path info is empty (single /), then we're not using diff --git a/phpBB/phpbb/symfony_request.php b/phpBB/phpbb/symfony_request.php new file mode 100644 index 0000000000..29ab8c000e --- /dev/null +++ b/phpBB/phpbb/symfony_request.php @@ -0,0 +1,46 @@ +set_var($value, $value, gettype($value), true); + }; + + $get_parameters = $phpbb_request->get_super_global(phpbb_request_interface::GET); + $post_parameters = $phpbb_request->get_super_global(phpbb_request_interface::POST); + $server_parameters = $phpbb_request->get_super_global(phpbb_request_interface::SERVER); + $files_parameters = $phpbb_request->get_super_global(phpbb_request_interface::FILES); + $cookie_parameters = $phpbb_request->get_super_global(phpbb_request_interface::COOKIE); + + array_walk_recursive($get_parameters, $sanitizer); + array_walk_recursive($post_parameters, $sanitizer); + + parent::__construct($get_parameters, $post_parameters, array(), $cookie_parameters, $files_parameters, $server_parameters); + } +} diff --git a/tests/filesystem/clean_path_test.php b/tests/filesystem/clean_path_test.php index 88352838bb..b79668fc33 100644 --- a/tests/filesystem/clean_path_test.php +++ b/tests/filesystem/clean_path_test.php @@ -14,7 +14,12 @@ class phpbb_filesystem_clean_path_test extends phpbb_test_case public function setUp() { parent::setUp(); - $this->filesystem = new phpbb_filesystem(__DIR__ . './../../phpBB/'); + $this->filesystem = new phpbb_filesystem( + new phpbb_symfony_request( + new phpbb_mock_request() + ), + dirname(__FILE__) . './../../phpBB/' + ); } public function clean_path_data() diff --git a/tests/filesystem/web_root_path_test.php b/tests/filesystem/web_root_path_test.php index 8e0ba278e0..b681c26de9 100644 --- a/tests/filesystem/web_root_path_test.php +++ b/tests/filesystem/web_root_path_test.php @@ -18,7 +18,8 @@ class phpbb_filesystem_web_root_path_test extends phpbb_test_case $this->set_phpbb_root_path(); - $this->filesystem = new phpbb_filesystem($this->phpbb_root_path); + $symfony_request = new phpbb_symfony_request(new phpbb_mock_request()); + $this->filesystem = new phpbb_filesystem($symfony_request, $this->phpbb_root_path); } /** @@ -40,13 +41,14 @@ class phpbb_filesystem_web_root_path_test extends phpbb_test_case $this->assertEquals($this->phpbb_root_path, $this->filesystem->get_web_root_path()); } - public function update_web_root_path_data() + public function basic_update_web_root_path_data() { $this->set_phpbb_root_path(); return array( array( $this->phpbb_root_path . 'test.php', + $this->phpbb_root_path . 'test.php', ), array( 'test.php', @@ -54,7 +56,24 @@ class phpbb_filesystem_web_root_path_test extends phpbb_test_case ), array( $this->phpbb_root_path . $this->phpbb_root_path . 'test.php', + $this->phpbb_root_path . $this->phpbb_root_path . 'test.php', ), + ); + } + + /** + * @dataProvider basic_update_web_root_path_data + */ + public function test_basic_update_web_root_path($input, $expected) + { + $this->assertEquals($expected, $this->filesystem->update_web_root_path($input, $symfony_request)); + } + + public function update_web_root_path_data() + { + $this->set_phpbb_root_path(); + + return array( array( $this->phpbb_root_path . 'test.php', $this->phpbb_root_path . 'test.php', @@ -92,25 +111,23 @@ class phpbb_filesystem_web_root_path_test extends phpbb_test_case /** * @dataProvider update_web_root_path_data */ - public function test_update_web_root_path($input, $expected = null, $getPathInfo = null, $getRequestUri = null, $getScriptName = null) + public function test_update_web_root_path($input, $expected, $getPathInfo, $getRequestUri = null, $getScriptName = null) { - $expected = ($expected === null) ? $input : $expected; + $symfony_request = $this->getMock("phpbb_symfony_request", array(), array( + new phpbb_mock_request(), + )); + $symfony_request->expects($this->any()) + ->method('getPathInfo') + ->will($this->returnValue($getPathInfo)); + $symfony_request->expects($this->any()) + ->method('getRequestUri') + ->will($this->returnValue($getRequestUri)); + $symfony_request->expects($this->any()) + ->method('getScriptName') + ->will($this->returnValue($getScriptName)); - $symfony_request = null; - if ($getPathInfo !== null) - { - $symfony_request = $this->getMock("Symfony\Component\HttpFoundation\Request"); - $symfony_request->expects($this->any()) - ->method('getPathInfo') - ->will($this->returnValue($getPathInfo)); - $symfony_request->expects($this->any()) - ->method('getRequestUri') - ->will($this->returnValue($getRequestUri)); - $symfony_request->expects($this->any()) - ->method('getScriptName') - ->will($this->returnValue($getScriptName)); - } + $filesystem = new phpbb_filesystem($symfony_request, $this->phpbb_root_path); - $this->assertEquals($expected, $this->filesystem->update_web_root_path($input, $symfony_request)); + $this->assertEquals($expected, $filesystem->update_web_root_path($input, $symfony_request)); } } From f8e665751a0926807c8352eb2b2d942247d3c029 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Fri, 13 Sep 2013 09:56:00 -0500 Subject: [PATCH 14/19] [ticket/11832] Fix smiley paths PHPBB3-11832 --- phpBB/includes/functions_content.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/phpBB/includes/functions_content.php b/phpBB/includes/functions_content.php index 05d3c5fde2..5fa37f60bd 100644 --- a/phpBB/includes/functions_content.php +++ b/phpBB/includes/functions_content.php @@ -813,7 +813,7 @@ function bbcode_nl2br($text) */ function smiley_text($text, $force_option = false) { - global $config, $user, $phpbb_root_path; + global $config, $user, $phpbb_filesystem; if ($force_option || !$config['allow_smilies'] || !$user->optionget('viewsmilies')) { @@ -821,7 +821,7 @@ function smiley_text($text, $force_option = false) } else { - $root_path = (defined('PHPBB_USE_BOARD_URL_PATH') && PHPBB_USE_BOARD_URL_PATH) ? generate_board_url() . '/' : $phpbb_root_path; + $root_path = (defined('PHPBB_USE_BOARD_URL_PATH') && PHPBB_USE_BOARD_URL_PATH) ? generate_board_url() . '/' : $phpbb_filesystem->get_web_root_path(); return preg_replace('#is_relative()) {\n") ->indent() ->write("\$asset_path = \$asset->get_path();") - ->write("\$local_file = \$this->getEnvironment()->get_phpbb_root_path() . \$asset_path;\n") + ->write("\$local_file = \$this->getEnvironment()->get_web_root_path() . \$asset_path;\n") ->write("if (!file_exists(\$local_file)) {\n") ->indent() ->write("\$local_file = \$this->getEnvironment()->findTemplate(\$asset_path);\n") diff --git a/phpBB/phpbb/template/twig/twig.php b/phpBB/phpbb/template/twig/twig.php index 5746cc64a3..3aa063ffc6 100644 --- a/phpBB/phpbb/template/twig/twig.php +++ b/phpBB/phpbb/template/twig/twig.php @@ -30,6 +30,12 @@ class phpbb_template_twig extends phpbb_template_base */ private $cachepath = ''; + /** + * phpBB filesystem + * @var phpbb_filesystem + */ + protected $phpbb_filesystem; + /** * phpBB root path * @var string @@ -71,24 +77,23 @@ class phpbb_template_twig extends phpbb_template_base /** * Constructor. * - * @param string $phpbb_root_path phpBB root path - * @param string $php_ext php extension (typically 'php') + * @param phpbb_filesystem $phpbb_filesystem * @param phpbb_config $config * @param phpbb_user $user * @param phpbb_template_context $context template context * @param phpbb_extension_manager $extension_manager extension manager, if null then template events will not be invoked - * @param string $adm_relative_path relative path to adm directory */ - public function __construct($phpbb_root_path, $php_ext, $config, $user, phpbb_template_context $context, phpbb_extension_manager $extension_manager = null, $adm_relative_path = null) + public function __construct(phpbb_filesystem $phpbb_filesystem, $config, $user, phpbb_template_context $context, phpbb_extension_manager $extension_manager = null) { - $this->phpbb_root_path = $phpbb_root_path; - $this->php_ext = $php_ext; + $this->phpbb_filesystem = $phpbb_filesystem; + $this->phpbb_root_path = $phpbb_filesystem->get_phpbb_root_path(); + $this->php_ext = $phpbb_filesystem->get_php_ext(); $this->config = $config; $this->user = $user; $this->context = $context; $this->extension_manager = $extension_manager; - $this->cachepath = $phpbb_root_path . 'cache/twig/'; + $this->cachepath = $this->phpbb_root_path . 'cache/twig/'; // Initiate the loader, __main__ namespace paths will be setup later in set_style_names() $loader = new phpbb_template_twig_loader(''); @@ -96,7 +101,7 @@ class phpbb_template_twig extends phpbb_template_base $this->twig = new phpbb_template_twig_environment( $this->config, ($this->extension_manager) ? $this->extension_manager->all_enabled() : array(), - $this->phpbb_root_path, + $this->phpbb_filesystem, $loader, array( 'cache' => (defined('IN_INSTALL')) ? false : $this->cachepath, @@ -118,9 +123,9 @@ class phpbb_template_twig extends phpbb_template_base $this->twig->setLexer($lexer); // Add admin namespace - if ($adm_relative_path !== null && is_dir($this->phpbb_root_path . $adm_relative_path . 'style/')) + if ($this->phpbb_filesystem->get_adm_relative_path() !== null && is_dir($this->phpbb_root_path . $this->phpbb_filesystem->get_adm_relative_path() . 'style/')) { - $this->twig->getLoader()->setPaths($this->phpbb_root_path . $adm_relative_path . 'style/', 'admin'); + $this->twig->getLoader()->setPaths($this->phpbb_root_path . $this->phpbb_filesystem->get_adm_relative_path() . 'style/', 'admin'); } } diff --git a/tests/controller/helper_url_test.php b/tests/controller/helper_url_test.php index da90947bb5..2dd7269caa 100644 --- a/tests/controller/helper_url_test.php +++ b/tests/controller/helper_url_test.php @@ -49,7 +49,14 @@ class phpbb_controller_helper_url_test extends phpbb_test_case $phpbb_dispatcher = new phpbb_mock_event_dispatcher; $this->user = $this->getMock('phpbb_user'); - $this->template = new phpbb_template_twig($phpbb_root_path, $phpEx, $config, $this->user, new phpbb_template_context()); + $phpbb_filesystem = new phpbb_filesystem( + new phpbb_symfony_request( + new phpbb_mock_request() + ), + $phpbb_root_path, + $phpEx + ); + $this->template = new phpbb_template_twig($phpbb_filesystem, $config, $this->user, new phpbb_template_context()); // We don't use mod_rewrite in these tests $config = new phpbb_config(array('enable_mod_rewrite' => '0')); @@ -94,7 +101,14 @@ class phpbb_controller_helper_url_test extends phpbb_test_case $phpbb_dispatcher = new phpbb_mock_event_dispatcher; $this->user = $this->getMock('phpbb_user'); - $this->template = new phpbb_template_twig($phpbb_root_path, $phpEx, $config, $this->user, new phpbb_template_context()); + $phpbb_filesystem = new phpbb_filesystem( + new phpbb_symfony_request( + new phpbb_mock_request() + ), + $phpbb_root_path, + $phpEx + ); + $this->template = new phpbb_template_twig($phpbb_filesystem, $config, $this->user, new phpbb_template_context()); $config = new phpbb_config(array('enable_mod_rewrite' => '1')); $helper = new phpbb_controller_helper($this->template, $this->user, $config, '', 'php'); diff --git a/tests/dbal/migrator_test.php b/tests/dbal/migrator_test.php index 5f0818d568..d722439b3f 100644 --- a/tests/dbal/migrator_test.php +++ b/tests/dbal/migrator_test.php @@ -63,7 +63,8 @@ class phpbb_dbal_migrator_test extends phpbb_database_test_case new phpbb_symfony_request( new phpbb_mock_request() ), - dirname(__FILE__) . '/../../phpBB/' + dirname(__FILE__) . '/../../phpBB/', + 'php' ), 'phpbb_ext', dirname(__FILE__) . '/../../phpBB/', diff --git a/tests/extension/manager_test.php b/tests/extension/manager_test.php index b9a920d092..07ca9fb417 100644 --- a/tests/extension/manager_test.php +++ b/tests/extension/manager_test.php @@ -118,7 +118,8 @@ class phpbb_extension_manager_test extends phpbb_database_test_case new phpbb_symfony_request( new phpbb_mock_request() ), - $phpbb_root_path + $phpbb_root_path, + $php_ext ), 'phpbb_ext', dirname(__FILE__) . '/', diff --git a/tests/extension/metadata_manager_test.php b/tests/extension/metadata_manager_test.php index 6b27929ebf..3ee10c3a74 100644 --- a/tests/extension/metadata_manager_test.php +++ b/tests/extension/metadata_manager_test.php @@ -41,8 +41,13 @@ class phpbb_extension_metadata_manager_test extends phpbb_database_test_case $this->table_prefix = 'phpbb_'; $this->template = new phpbb_template_twig( - $this->phpbb_root_path, - $this->phpEx, + new phpbb_filesystem( + new phpbb_symfony_request( + new phpbb_mock_request() + ), + $this->phpbb_root_path, + $this->phpEx + ), $this->config, $this->user, new phpbb_template_context() @@ -69,7 +74,8 @@ class phpbb_extension_metadata_manager_test extends phpbb_database_test_case new phpbb_symfony_request( new phpbb_mock_request() ), - $this->phpbb_root_path + $this->phpbb_root_path, + $this->phpEx ), 'phpbb_ext', $this->phpbb_root_path, diff --git a/tests/filesystem/clean_path_test.php b/tests/filesystem/clean_path_test.php index b79668fc33..38ccf1b603 100644 --- a/tests/filesystem/clean_path_test.php +++ b/tests/filesystem/clean_path_test.php @@ -18,7 +18,8 @@ class phpbb_filesystem_clean_path_test extends phpbb_test_case new phpbb_symfony_request( new phpbb_mock_request() ), - dirname(__FILE__) . './../../phpBB/' + dirname(__FILE__) . './../../phpBB/', + 'php' ); } diff --git a/tests/filesystem/web_root_path_test.php b/tests/filesystem/web_root_path_test.php index b681c26de9..ae59d4f709 100644 --- a/tests/filesystem/web_root_path_test.php +++ b/tests/filesystem/web_root_path_test.php @@ -18,8 +18,13 @@ class phpbb_filesystem_web_root_path_test extends phpbb_test_case $this->set_phpbb_root_path(); - $symfony_request = new phpbb_symfony_request(new phpbb_mock_request()); - $this->filesystem = new phpbb_filesystem($symfony_request, $this->phpbb_root_path); + $this->filesystem = new phpbb_filesystem( + new phpbb_symfony_request( + new phpbb_mock_request() + ), + $this->phpbb_root_path, + 'php' + ); } /** @@ -126,7 +131,11 @@ class phpbb_filesystem_web_root_path_test extends phpbb_test_case ->method('getScriptName') ->will($this->returnValue($getScriptName)); - $filesystem = new phpbb_filesystem($symfony_request, $this->phpbb_root_path); + $filesystem = new phpbb_filesystem( + $symfony_request, + $this->phpbb_root_path, + 'php' + ); $this->assertEquals($expected, $filesystem->update_web_root_path($input, $symfony_request)); } diff --git a/tests/mock/extension_manager.php b/tests/mock/extension_manager.php index 0c73adcf47..0d1b6940ca 100644 --- a/tests/mock/extension_manager.php +++ b/tests/mock/extension_manager.php @@ -18,7 +18,8 @@ class phpbb_mock_extension_manager extends phpbb_extension_manager new phpbb_symfony_request( new phpbb_mock_request() ), - $phpbb_root_path + $this->phpbb_root_path, + $this->php_ext ); } } diff --git a/tests/template/template_events_test.php b/tests/template/template_events_test.php index 4280a7e7ff..58691a36da 100644 --- a/tests/template/template_events_test.php +++ b/tests/template/template_events_test.php @@ -116,7 +116,14 @@ Zeta test event in all', $this->extension_manager = new phpbb_mock_filesystem_extension_manager( dirname(__FILE__) . "/datasets/$dataset/" ); - $this->template = new phpbb_template_twig($phpbb_root_path, $phpEx, $config, $user, new phpbb_template_context, $this->extension_manager); + $phpbb_filesystem = new phpbb_filesystem( + new phpbb_symfony_request( + new phpbb_mock_request() + ), + $phpbb_root_path, + $phpEx + ); + $this->template = new phpbb_template_twig($phpbb_filesystem, $config, $user, new phpbb_template_context, $this->extension_manager); $this->template->set_custom_style(((!empty($style_names)) ? $style_names : 'silver'), array($this->template_path)); } } diff --git a/tests/template/template_test_case.php b/tests/template/template_test_case.php index 91895502ad..8151e15b24 100644 --- a/tests/template/template_test_case.php +++ b/tests/template/template_test_case.php @@ -63,8 +63,16 @@ class phpbb_template_template_test_case extends phpbb_test_case $config = new phpbb_config(array_merge($defaults, $new_config)); $this->user = new phpbb_user; + $phpbb_filesystem = new phpbb_filesystem( + new phpbb_symfony_request( + new phpbb_mock_request() + ), + $phpbb_root_path, + $phpEx + ); + $this->template_path = $this->test_path . '/templates'; - $this->template = new phpbb_template_twig($phpbb_root_path, $phpEx, $config, $this->user, new phpbb_template_context()); + $this->template = new phpbb_template_twig($phpbb_filesystem, $config, $this->user, new phpbb_template_context()); $this->template->set_custom_style('tests', $this->template_path); } diff --git a/tests/template/template_test_case_with_tree.php b/tests/template/template_test_case_with_tree.php index 477192c28a..c4f3b4a257 100644 --- a/tests/template/template_test_case_with_tree.php +++ b/tests/template/template_test_case_with_tree.php @@ -18,9 +18,17 @@ class phpbb_template_template_test_case_with_tree extends phpbb_template_templat $defaults = $this->config_defaults(); $config = new phpbb_config(array_merge($defaults, $new_config)); + $phpbb_filesystem = new phpbb_filesystem( + new phpbb_symfony_request( + new phpbb_mock_request() + ), + $phpbb_root_path, + $phpEx + ); + $this->template_path = $this->test_path . '/templates'; $this->parent_template_path = $this->test_path . '/parent_templates'; - $this->template = new phpbb_template_twig($phpbb_root_path, $phpEx, $config, $user, new phpbb_template_context()); + $this->template = new phpbb_template_twig($phpbb_filesystem, $config, $user, new phpbb_template_context()); $this->template->set_custom_style('tests', array($this->template_path, $this->parent_template_path)); } } diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index 48c5649281..00f166d4fe 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -207,7 +207,8 @@ class phpbb_functional_test_case extends phpbb_test_case new phpbb_symfony_request( new phpbb_mock_request() ), - $phpbb_root_path + $phpbb_root_path, + $php_ext ), self::$config['table_prefix'] . 'ext', dirname(__FILE__) . '/', From 9e8babbf6eae65aa894cb0d8c4b452133ac344a8 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Sun, 15 Sep 2013 16:42:02 -0500 Subject: [PATCH 17/19] [ticket/11832] get_url() from phpbb_template_asset should return web path PHPBB3-11832 --- phpBB/phpbb/template/asset.php | 9 +++++++-- phpBB/phpbb/template/twig/node/includeasset.php | 4 ++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/phpBB/phpbb/template/asset.php b/phpBB/phpbb/template/asset.php index 7c322cd971..2b10dd8848 100644 --- a/phpBB/phpbb/template/asset.php +++ b/phpBB/phpbb/template/asset.php @@ -19,13 +19,18 @@ class phpbb_template_asset { protected $components = array(); + /** @var phpbb_filesystem **/ + protected $phpbb_filesystem; + /** * Constructor * * @param string $url URL */ - public function __construct($url) + public function __construct($url, phpbb_filesystem $phpbb_filesystem) { + $this->phpbb_filesystem = $phpbb_filesystem; + $this->set_url($url); } @@ -112,7 +117,7 @@ class phpbb_template_asset */ public function get_url() { - return $this->join_url($this->components); + return $this->phpbb_filesystem->update_web_root_path($this->join_url($this->components)); } /** diff --git a/phpBB/phpbb/template/twig/node/includeasset.php b/phpBB/phpbb/template/twig/node/includeasset.php index 2dcd2003a3..8629395898 100644 --- a/phpBB/phpbb/template/twig/node/includeasset.php +++ b/phpBB/phpbb/template/twig/node/includeasset.php @@ -33,11 +33,11 @@ abstract class phpbb_template_twig_node_includeasset extends Twig_Node ->write("\$asset_file = ") ->subcompile($this->getNode('expr')) ->raw(";\n") - ->write("\$asset = new phpbb_template_asset(\$asset_file);\n") + ->write("\$asset = new phpbb_template_asset(\$asset_file, \$this->getEnvironment()->get_filesystem());\n") ->write("if (substr(\$asset_file, 0, 2) !== './' && \$asset->is_relative()) {\n") ->indent() ->write("\$asset_path = \$asset->get_path();") - ->write("\$local_file = \$this->getEnvironment()->get_web_root_path() . \$asset_path;\n") + ->write("\$local_file = \$this->getEnvironment()->get_phpbb_root_path() . \$asset_path;\n") ->write("if (!file_exists(\$local_file)) {\n") ->indent() ->write("\$local_file = \$this->getEnvironment()->findTemplate(\$asset_path);\n") From 8e02f9bd7d84dd798cae37e880db1c70fb323acb Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Sun, 15 Sep 2013 16:44:09 -0500 Subject: [PATCH 18/19] [ticket/11832] Correct ROOT_PATH variable PHPBB3-11832 --- phpBB/includes/functions.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index b28e808606..d0344b7866 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -5330,7 +5330,7 @@ function page_header($page_title = '', $display_online_list = true, $item_id = 0 'SID' => $SID, '_SID' => $_SID, 'SESSION_ID' => $user->session_id, - 'ROOT_PATH' => $phpbb_root_path, + 'ROOT_PATH' => $web_path, 'BOARD_URL' => $board_url, 'L_LOGIN_LOGOUT' => $l_login_logout, From cd141883a59ca474c844f9e206333dbd79699695 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Sun, 15 Sep 2013 18:55:18 -0500 Subject: [PATCH 19/19] [ticket/11832] Correct paths in tests PHPBB3-11832 --- tests/template/template_includecss_test.php | 4 +-- tests/template/template_includejs_test.php | 28 ++++++++++--------- .../template/template_test_case_with_tree.php | 4 +-- 3 files changed, 19 insertions(+), 17 deletions(-) diff --git a/tests/template/template_includecss_test.php b/tests/template/template_includecss_test.php index f8999ad1a9..c00aa8e9bb 100644 --- a/tests/template/template_includecss_test.php +++ b/tests/template/template_includecss_test.php @@ -18,8 +18,8 @@ class phpbb_template_template_includecss_test extends phpbb_template_template_te // Prepare correct result $scripts = array( - '', - '', + '', + '', ); // Run test diff --git a/tests/template/template_includejs_test.php b/tests/template/template_includejs_test.php index b67fa123a1..2faeb5fcaa 100644 --- a/tests/template/template_includejs_test.php +++ b/tests/template/template_includejs_test.php @@ -13,6 +13,8 @@ class phpbb_template_template_includejs_test extends phpbb_template_template_tes { public function template_data() { + $this->setup_engine(); + return array( /* array( @@ -22,51 +24,51 @@ class phpbb_template_template_includejs_test extends phpbb_template_template_tes */ array( array('TEST' => 1), - '', + '', ), array( array('TEST' => 2), - '', + '', ), array( array('TEST' => 3), - '', + '', ), array( array('TEST' => 4), - '', + '', ), array( array('TEST' => 6), - '', + '', ), array( array('TEST' => 7), - '', + '', ), array( array('TEST' => 8), - '', + '', ), array( array('TEST' => 9), - '', + '', ), array( array('TEST' => 10), - '', + '', ), array( array('TEST' => 11), - '', + '', ), array( array('TEST' => 12), - '', + '', ), array( array('TEST' => 14), - '', + '', ), array( array('TEST' => 15), @@ -82,7 +84,7 @@ class phpbb_template_template_includejs_test extends phpbb_template_template_tes ), array( array('TEST' => 18), - '', + '', ), ); } diff --git a/tests/template/template_test_case_with_tree.php b/tests/template/template_test_case_with_tree.php index c4f3b4a257..c7bd03a3c7 100644 --- a/tests/template/template_test_case_with_tree.php +++ b/tests/template/template_test_case_with_tree.php @@ -18,7 +18,7 @@ class phpbb_template_template_test_case_with_tree extends phpbb_template_templat $defaults = $this->config_defaults(); $config = new phpbb_config(array_merge($defaults, $new_config)); - $phpbb_filesystem = new phpbb_filesystem( + $this->phpbb_filesystem = new phpbb_filesystem( new phpbb_symfony_request( new phpbb_mock_request() ), @@ -28,7 +28,7 @@ class phpbb_template_template_test_case_with_tree extends phpbb_template_templat $this->template_path = $this->test_path . '/templates'; $this->parent_template_path = $this->test_path . '/parent_templates'; - $this->template = new phpbb_template_twig($phpbb_filesystem, $config, $user, new phpbb_template_context()); + $this->template = new phpbb_template_twig($this->phpbb_filesystem, $config, $user, new phpbb_template_context()); $this->template->set_custom_style('tests', array($this->template_path, $this->parent_template_path)); } }