Merge branch '3.2.x'

This commit is contained in:
Marc Alexander 2016-04-07 21:59:44 +02:00
commit 662fbc7cde
3 changed files with 76 additions and 19 deletions

View file

@ -52,15 +52,15 @@ class helper
protected $routing_helper; protected $routing_helper;
/** /**
* Constructor * Constructor
* *
* @param \phpbb\template\template $template Template object * @param \phpbb\template\template $template Template object
* @param \phpbb\user $user User object * @param \phpbb\user $user User object
* @param \phpbb\config\config $config Config object * @param \phpbb\config\config $config Config object
* @param \phpbb\symfony_request $symfony_request Symfony Request object * @param \phpbb\symfony_request $symfony_request Symfony Request object
* @param \phpbb\request\request_interface $request phpBB request object * @param \phpbb\request\request_interface $request phpBB request object
* @param \phpbb\routing\helper $routing_helper Helper to generate the routes * @param \phpbb\routing\helper $routing_helper Helper to generate the routes
*/ */
public function __construct(\phpbb\template\template $template, \phpbb\user $user, \phpbb\config\config $config, \phpbb\symfony_request $symfony_request, \phpbb\request\request_interface $request, \phpbb\routing\helper $routing_helper) public function __construct(\phpbb\template\template $template, \phpbb\user $user, \phpbb\config\config $config, \phpbb\symfony_request $symfony_request, \phpbb\request\request_interface $request, \phpbb\routing\helper $routing_helper)
{ {
$this->template = $template; $this->template = $template;

View file

@ -104,6 +104,15 @@ class helper
$context = new RequestContext(); $context = new RequestContext();
$context->fromRequest($this->symfony_request); $context->fromRequest($this->symfony_request);
if ($this->config['force_server_vars'])
{
$context->setHost($this->config['server_name']);
$context->setScheme(substr($this->config['server_protocol'], 0, -3));
$context->setHttpPort($this->config['server_port']);
$context->setHttpsPort($this->config['server_port']);
$context->setBaseUrl(rtrim($this->config['script_path'], '/'));
}
$script_name = $this->symfony_request->getScriptName(); $script_name = $this->symfony_request->getScriptName();
$page_name = substr($script_name, -1, 1) == '/' ? '' : utf8_basename($script_name); $page_name = substr($script_name, -1, 1) == '/' ? '' : utf8_basename($script_name);
@ -119,7 +128,7 @@ class helper
$base_url = str_replace('/' . $page_name, empty($this->config['enable_mod_rewrite']) ? '/app.' . $this->php_ext : '', $base_url); $base_url = str_replace('/' . $page_name, empty($this->config['enable_mod_rewrite']) ? '/app.' . $this->php_ext : '', $base_url);
// We need to update the base url to move to the directory of the app.php file if the current script is not app.php // We need to update the base url to move to the directory of the app.php file if the current script is not app.php
if ($page_name !== 'app.php') if ($page_name !== 'app.php' && !$this->config['force_server_vars'])
{ {
if (empty($this->config['enable_mod_rewrite'])) if (empty($this->config['enable_mod_rewrite']))
{ {

View file

@ -16,6 +16,18 @@ use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
abstract class phpbb_controller_common_helper_route extends phpbb_test_case abstract class phpbb_controller_common_helper_route extends phpbb_test_case
{ {
protected $root_path; protected $root_path;
private $user;
private $config;
private $template;
private $extension_manager;
private $request;
private $symfony_request;
private $provider;
private $filesystem;
private $phpbb_path_helper;
private $helper;
private $router;
private $routing_helper;
public function setUp() public function setUp()
{ {
@ -62,6 +74,8 @@ abstract class phpbb_controller_common_helper_route extends phpbb_test_case
protected function generate_route_objects() protected function generate_route_objects()
{ {
global $request;
$this->request = new phpbb_mock_request(); $this->request = new phpbb_mock_request();
$this->request->overwrite('SCRIPT_NAME', $this->get_uri(), \phpbb\request\request_interface::SERVER); $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('SCRIPT_FILENAME', $this->get_script_name(), \phpbb\request\request_interface::SERVER);
@ -69,6 +83,8 @@ abstract class phpbb_controller_common_helper_route extends phpbb_test_case
$this->request->overwrite('SERVER_NAME', 'localhost', \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->request->overwrite('SERVER_PORT', '80', \phpbb\request\request_interface::SERVER);
$request = $this->request;
$this->symfony_request = new \phpbb\symfony_request( $this->symfony_request = new \phpbb\symfony_request(
$this->request $this->request
); );
@ -171,7 +187,7 @@ abstract class phpbb_controller_common_helper_route extends phpbb_test_case
$this->config = new \phpbb\config\config(array('enable_mod_rewrite' => '0')); $this->config = new \phpbb\config\config(array('enable_mod_rewrite' => '0'));
$this->routing_helper = new \phpbb\routing\helper($this->config, $this->router, $this->symfony_request, $this->request, $this->filesystem, $this->root_path, 'php'); $this->routing_helper = new \phpbb\routing\helper($this->config, $this->router, $this->symfony_request, $this->request, $this->filesystem, $this->root_path, 'php');
$this->helper = new phpbb_mock_controller_helper($this->template, $this->user, $this->config, $this->symfony_request, $this->request, $this->routing_helper); $this->helper = new phpbb_mock_controller_helper($this->template, $this->user, $this->config, $this->symfony_request, $this->request, $this->routing_helper);
$this->assertEquals($expected, $this->helper->route($route, $params, $is_amp, $session_id), $description); static::assertEquals($expected, $this->helper->route($route, $params, $is_amp, $session_id), $description);
} }
public function helper_url_data_with_rewrite() public function helper_url_data_with_rewrite()
@ -215,7 +231,7 @@ abstract class phpbb_controller_common_helper_route extends phpbb_test_case
$this->config = new \phpbb\config\config(array('enable_mod_rewrite' => '1')); $this->config = new \phpbb\config\config(array('enable_mod_rewrite' => '1'));
$this->routing_helper = new \phpbb\routing\helper($this->config, $this->router, $this->symfony_request, $this->request, $this->filesystem, $this->root_path, 'php'); $this->routing_helper = new \phpbb\routing\helper($this->config, $this->router, $this->symfony_request, $this->request, $this->filesystem, $this->root_path, 'php');
$this->helper = new phpbb_mock_controller_helper($this->template, $this->user, $this->config, $this->symfony_request, $this->request, $this->routing_helper); $this->helper = new phpbb_mock_controller_helper($this->template, $this->user, $this->config, $this->symfony_request, $this->request, $this->routing_helper);
$this->assertEquals($expected, $this->helper->route($route, $params, $is_amp, $session_id), $description); static::assertEquals($expected, $this->helper->route($route, $params, $is_amp, $session_id), $description);
} }
public function helper_url_data_absolute() public function helper_url_data_absolute()
@ -259,7 +275,7 @@ abstract class phpbb_controller_common_helper_route extends phpbb_test_case
$this->config = new \phpbb\config\config(array('enable_mod_rewrite' => '0')); $this->config = new \phpbb\config\config(array('enable_mod_rewrite' => '0'));
$this->routing_helper = new \phpbb\routing\helper($this->config, $this->router, $this->symfony_request, $this->request, $this->filesystem, $this->root_path, 'php'); $this->routing_helper = new \phpbb\routing\helper($this->config, $this->router, $this->symfony_request, $this->request, $this->filesystem, $this->root_path, 'php');
$this->helper = new phpbb_mock_controller_helper($this->template, $this->user, $this->config, $this->symfony_request, $this->request, $this->routing_helper); $this->helper = new phpbb_mock_controller_helper($this->template, $this->user, $this->config, $this->symfony_request, $this->request, $this->routing_helper);
$this->assertEquals($expected, $this->helper->route($route, $params, $is_amp, $session_id, UrlGeneratorInterface::ABSOLUTE_URL), $description); static::assertEquals($expected, $this->helper->route($route, $params, $is_amp, $session_id, UrlGeneratorInterface::ABSOLUTE_URL), $description);
} }
public function helper_url_data_relative_path() public function helper_url_data_relative_path()
@ -303,7 +319,7 @@ abstract class phpbb_controller_common_helper_route extends phpbb_test_case
$this->config = new \phpbb\config\config(array('enable_mod_rewrite' => '0')); $this->config = new \phpbb\config\config(array('enable_mod_rewrite' => '0'));
$this->routing_helper = new \phpbb\routing\helper($this->config, $this->router, $this->symfony_request, $this->request, $this->filesystem, $this->root_path, 'php'); $this->routing_helper = new \phpbb\routing\helper($this->config, $this->router, $this->symfony_request, $this->request, $this->filesystem, $this->root_path, 'php');
$this->helper = new phpbb_mock_controller_helper($this->template, $this->user, $this->config, $this->symfony_request, $this->request, $this->routing_helper); $this->helper = new phpbb_mock_controller_helper($this->template, $this->user, $this->config, $this->symfony_request, $this->request, $this->routing_helper);
$this->assertEquals($expected, $this->helper->route($route, $params, $is_amp, $session_id, UrlGeneratorInterface::RELATIVE_PATH), $description); static::assertEquals($expected, $this->helper->route($route, $params, $is_amp, $session_id, UrlGeneratorInterface::RELATIVE_PATH), $description);
} }
public function helper_url_data_network() public function helper_url_data_network()
@ -347,7 +363,7 @@ abstract class phpbb_controller_common_helper_route extends phpbb_test_case
$this->config = new \phpbb\config\config(array('enable_mod_rewrite' => '0')); $this->config = new \phpbb\config\config(array('enable_mod_rewrite' => '0'));
$this->routing_helper = new \phpbb\routing\helper($this->config, $this->router, $this->symfony_request, $this->request, $this->filesystem, $this->root_path, 'php'); $this->routing_helper = new \phpbb\routing\helper($this->config, $this->router, $this->symfony_request, $this->request, $this->filesystem, $this->root_path, 'php');
$this->helper = new phpbb_mock_controller_helper($this->template, $this->user, $this->config, $this->symfony_request, $this->request, $this->routing_helper); $this->helper = new phpbb_mock_controller_helper($this->template, $this->user, $this->config, $this->symfony_request, $this->request, $this->routing_helper);
$this->assertEquals($expected, $this->helper->route($route, $params, $is_amp, $session_id, UrlGeneratorInterface::NETWORK_PATH), $description); static::assertEquals($expected, $this->helper->route($route, $params, $is_amp, $session_id, UrlGeneratorInterface::NETWORK_PATH), $description);
} }
public function helper_url_data_absolute_with_rewrite() public function helper_url_data_absolute_with_rewrite()
@ -391,7 +407,7 @@ abstract class phpbb_controller_common_helper_route extends phpbb_test_case
$this->config = new \phpbb\config\config(array('enable_mod_rewrite' => '1')); $this->config = new \phpbb\config\config(array('enable_mod_rewrite' => '1'));
$this->routing_helper = new \phpbb\routing\helper($this->config, $this->router, $this->symfony_request, $this->request, $this->filesystem, $this->root_path, 'php'); $this->routing_helper = new \phpbb\routing\helper($this->config, $this->router, $this->symfony_request, $this->request, $this->filesystem, $this->root_path, 'php');
$this->helper = new phpbb_mock_controller_helper($this->template, $this->user, $this->config, $this->symfony_request, $this->request, $this->routing_helper); $this->helper = new phpbb_mock_controller_helper($this->template, $this->user, $this->config, $this->symfony_request, $this->request, $this->routing_helper);
$this->assertEquals($expected, $this->helper->route($route, $params, $is_amp, $session_id, UrlGeneratorInterface::ABSOLUTE_URL), $description); static::assertEquals($expected, $this->helper->route($route, $params, $is_amp, $session_id, UrlGeneratorInterface::ABSOLUTE_URL), $description);
} }
public function helper_url_data_relative_path_with_rewrite() public function helper_url_data_relative_path_with_rewrite()
@ -432,7 +448,7 @@ abstract class phpbb_controller_common_helper_route extends phpbb_test_case
$this->config = new \phpbb\config\config(array('enable_mod_rewrite' => '1')); $this->config = new \phpbb\config\config(array('enable_mod_rewrite' => '1'));
$this->routing_helper = new \phpbb\routing\helper($this->config, $this->router, $this->symfony_request, $this->request, $this->filesystem, $this->root_path, 'php'); $this->routing_helper = new \phpbb\routing\helper($this->config, $this->router, $this->symfony_request, $this->request, $this->filesystem, $this->root_path, 'php');
$this->helper = new phpbb_mock_controller_helper($this->template, $this->user, $this->config, $this->symfony_request, $this->request, $this->routing_helper); $this->helper = new phpbb_mock_controller_helper($this->template, $this->user, $this->config, $this->symfony_request, $this->request, $this->routing_helper);
$this->assertEquals($expected, $this->helper->route($route, $params, $is_amp, $session_id, UrlGeneratorInterface::RELATIVE_PATH), $description); static::assertEquals($expected, $this->helper->route($route, $params, $is_amp, $session_id, UrlGeneratorInterface::RELATIVE_PATH), $description);
} }
public function helper_url_data_network_with_rewrite() public function helper_url_data_network_with_rewrite()
@ -473,9 +489,41 @@ 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) 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->config = new \phpbb\config\config(['enable_mod_rewrite' => '1']);
$this->routing_helper = new \phpbb\routing\helper($this->config, $this->router, $this->symfony_request, $this->request, $this->filesystem, $this->root_path, 'php'); $this->routing_helper = new \phpbb\routing\helper($this->config, $this->router, $this->symfony_request, $this->request, $this->filesystem, $this->root_path, 'php');
$this->helper = new phpbb_mock_controller_helper($this->template, $this->user, $this->config, $this->symfony_request, $this->request, $this->routing_helper); $this->helper = new phpbb_mock_controller_helper($this->template, $this->user, $this->config, $this->symfony_request, $this->request, $this->routing_helper);
$this->assertEquals($expected, $this->helper->route($route, $params, $is_amp, $session_id, UrlGeneratorInterface::NETWORK_PATH), $description); static::assertEquals($expected, $this->helper->route($route, $params, $is_amp, $session_id, UrlGeneratorInterface::NETWORK_PATH), $description);
}
public function helper_url_data_force_server_vars()
{
return array(
array(false, true, 'my_server', 443, '/my/board', 'http://', UrlGeneratorInterface::ABSOLUTE_URL, 'http://my_server:443/my/board/app.php/foo'),
array(true, true, 'my_server', 444, '/my/board', 'https://', UrlGeneratorInterface::ABSOLUTE_URL, 'https://my_server:444/my/board/foo'),
array(false, true, 'my_server', 443, '/my/board', 'http://', UrlGeneratorInterface::NETWORK_PATH, '//my_server:443/my/board/app.php/foo'),
array(true, true, 'my_server', 444, '/my/board', 'https://', UrlGeneratorInterface::NETWORK_PATH, '//my_server:444/my/board/foo'),
array(false, true, 'my_server', 443, '/my/board', 'http://', UrlGeneratorInterface::ABSOLUTE_PATH, '/my/board/app.php/foo'),
array(true, true, 'my_server', 443, '/my/board', 'http://', UrlGeneratorInterface::ABSOLUTE_PATH, '/my/board/foo'),
array(false, true, 'my_server', 443, '/my/board', 'http://', UrlGeneratorInterface::RELATIVE_PATH, 'app.php/foo'),
array(true, true, 'my_server', 443, '/my/board', 'http://', UrlGeneratorInterface::RELATIVE_PATH, 'foo'), );
}
/**
* @dataProvider helper_url_data_force_server_vars()
*/
public function test_helper_url_force_server_vars($enable_mod_rewrite, $force_server_vars, $server_name, $server_port, $script_path, $server_protocol, $type, $expected)
{
$this->config = new \phpbb\config\config(array(
'enable_mod_rewrite' => $enable_mod_rewrite,
'force_server_vars' => $force_server_vars,
'server_name' => $server_name,
'server_port' => $server_port,
'script_path' => $script_path,
'server_protocol' => $server_protocol,
));
$this->routing_helper = new \phpbb\routing\helper($this->config, $this->router, $this->symfony_request, $this->request, $this->filesystem, $this->root_path, 'php');
$this->helper = new phpbb_mock_controller_helper($this->template, $this->user, $this->config, $this->symfony_request, $this->request, $this->routing_helper);
static::assertEquals($expected, $this->helper->route('controller1', array(), false, false, $type));
} }
} }