mirror of
https://github.com/phpbb/phpbb.git
synced 2025-08-14 04:34:07 +02:00
Merge remote-tracking branch 'Marc/ticket/11997' into develop
* Marc/ticket/11997: (23 commits) [ticket/11997] Use functional test cases that should always work [ticket/11997] Fix redirect tests for mod rewrite [ticket/11997] Add user's page dir to redirect path and fix unit tests for it [ticket/11997] Remove obsolete function get_controller_redirect_url() [ticket/11997] Use path_helper in in foo/bar extension for redirect URLs [ticket/11997] Add remove_web_root_path() in order to prevent incorrect URLs [ticket/11997] Do not check if file or dir we redirect to exist [ticket/11997] Modifiy tests after adding path_helper clean_url method [ticket/11997] Add clean_url() method to path_helper [ticket/11997] Allow redirects to parent folders like previously [ticket/11997] Move expected redirect returns to controller and output to HTML [ticket/11997] Fix tests for path_helper's get_controller_redirect_url() [ticket/11997] Use get_controller_redirect_url() in redirect() function [ticket/11997] Add method for controller redirect URLs to path helper [ticket/11997] Undo changes to phpbb_own_realpath() [ticket/11997] Remove obsolete failover_flag in function redirect() [ticket/11997] Add functional test for redirects in controller [ticket/11997] Fix missing global [ticket/11997] Fix redirects from inside controllers [ticket/11997] Use $phpbb_filesystem->clean_path() for proper redirect paths ...
This commit is contained in:
@@ -111,4 +111,32 @@ class phpbb_functional_extension_controller_test extends phpbb_functional_test_c
|
||||
$this->assert_response_html(404);
|
||||
$this->assertContains('No route found for "GET /does/not/exist"', $crawler->filter('body')->text());
|
||||
}
|
||||
|
||||
/**
|
||||
* Check the output of a controller using the template system
|
||||
*/
|
||||
public function test_redirect()
|
||||
{
|
||||
$filesystem = new \phpbb\filesystem();
|
||||
$this->phpbb_extension_manager->enable('foo/bar');
|
||||
$crawler = self::request('GET', 'app.php/foo/redirect');
|
||||
|
||||
$nodes = $crawler->filter('div')->extract(array('id'));
|
||||
|
||||
foreach ($nodes as $redirect)
|
||||
{
|
||||
if (strpos($redirect, 'redirect_expected') !== 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
$row_num = str_replace('redirect_expected_', '', $redirect);
|
||||
|
||||
$redirect = $crawler->filter('#redirect_' . $row_num)->text();
|
||||
$redirect = substr($redirect, 0, strpos($redirect, 'sid') - 1);
|
||||
$this->assertEquals($crawler->filter('#redirect_expected_' . $row_num)->text(), $redirect);
|
||||
}
|
||||
|
||||
$this->phpbb_extension_manager->purge('foo/bar');
|
||||
}
|
||||
}
|
||||
|
@@ -13,3 +13,7 @@ foo_template_controller:
|
||||
foo_exception_controller:
|
||||
pattern: /foo/exception
|
||||
defaults: { _controller: foo_bar.controller:exception }
|
||||
|
||||
foo_redirect_controller:
|
||||
pattern: /foo/redirect
|
||||
defaults: { _controller: foo_bar.controller:redirect }
|
||||
|
@@ -3,7 +3,12 @@ services:
|
||||
class: foo\bar\controller\controller
|
||||
arguments:
|
||||
- @controller.helper
|
||||
- @path_helper
|
||||
- @template
|
||||
- @config
|
||||
- %core.root_path%
|
||||
- %core.php_ext%
|
||||
|
||||
foo_bar.listener.permission:
|
||||
class: foo\bar\event\permission
|
||||
tags:
|
||||
@@ -12,4 +17,3 @@ services:
|
||||
class: foo\bar\event\user_setup
|
||||
tags:
|
||||
- { name: event.listener }
|
||||
|
||||
|
@@ -7,11 +7,18 @@ use Symfony\Component\HttpFoundation\Response;
|
||||
class controller
|
||||
{
|
||||
protected $template;
|
||||
protected $helper;
|
||||
protected $path_helper;
|
||||
protected $config;
|
||||
|
||||
public function __construct(\phpbb\controller\helper $helper, \phpbb\template\template $template)
|
||||
public function __construct(\phpbb\controller\helper $helper, \phpbb\path_helper $path_helper, \phpbb\template\template $template, \phpbb\config\config $config, $root_path, $php_ext)
|
||||
{
|
||||
$this->template = $template;
|
||||
$this->helper = $helper;
|
||||
$this->path_helper = $path_helper;
|
||||
$this->config = $config;
|
||||
$this->root_path = $root_path;
|
||||
$this->php_ext = $php_ext;
|
||||
}
|
||||
|
||||
public function handle()
|
||||
@@ -35,4 +42,75 @@ class controller
|
||||
{
|
||||
throw new \phpbb\controller\exception('Exception thrown from foo/exception route');
|
||||
}
|
||||
|
||||
public function redirect()
|
||||
{
|
||||
$url_root = generate_board_url();
|
||||
|
||||
$rewrite_prefix = (!empty($this->config['enable_mod_rewrite'])) ? '' : 'app.php/';
|
||||
|
||||
$redirects = array(
|
||||
array(
|
||||
append_sid($this->root_path . 'index.' . $this->php_ext),
|
||||
'index.php',
|
||||
),
|
||||
array(
|
||||
append_sid($this->root_path . 'foo/bar/index.' . $this->php_ext),
|
||||
'foo/bar/index.php',
|
||||
),
|
||||
array(
|
||||
append_sid($this->root_path . 'tests/index.' . $this->php_ext),
|
||||
'tests/index.php',
|
||||
),
|
||||
array(
|
||||
$this->helper->url('index'),
|
||||
$rewrite_prefix . 'index',
|
||||
),
|
||||
array(
|
||||
$this->helper->url('tests/index'),
|
||||
$rewrite_prefix . 'tests/index',
|
||||
),
|
||||
array(
|
||||
$this->helper->url('tests/../index'),
|
||||
$rewrite_prefix . 'index',
|
||||
),
|
||||
/*
|
||||
// helper URLs starting with ../ are prone to failure.
|
||||
// Do not test them right now.
|
||||
array(
|
||||
$this->helper->url('../index'),
|
||||
'../index',
|
||||
),
|
||||
array(
|
||||
$this->helper->url('../../index'),
|
||||
'../index',
|
||||
),
|
||||
array(
|
||||
$this->helper->url('../tests/index'),
|
||||
$rewrite_prefix . '../tests/index',
|
||||
),
|
||||
array(
|
||||
$this->helper->url('../tests/../index'),
|
||||
'../index',
|
||||
),
|
||||
array(
|
||||
$this->helper->url('../../tests/index'),
|
||||
'../tests/index',
|
||||
),
|
||||
*/
|
||||
);
|
||||
|
||||
foreach ($redirects as $redirect)
|
||||
{
|
||||
$this->template->assign_block_vars('redirects', array(
|
||||
'URL' => redirect($redirect[0], true),
|
||||
));
|
||||
|
||||
$this->template->assign_block_vars('redirects_expected', array(
|
||||
'URL' => $this->path_helper->clean_url($url_root . '/' . $redirect[1]),
|
||||
));
|
||||
}
|
||||
|
||||
return $this->helper->render('redirect_body.html');
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,8 @@
|
||||
<!-- INCLUDE overall_header.html -->
|
||||
<!-- BEGIN redirects -->
|
||||
<div id="redirect_{redirects.S_ROW_COUNT}">{redirects.URL}</div>
|
||||
<!-- END redirects -->
|
||||
<!-- BEGIN redirects_expected -->
|
||||
<div id="redirect_expected_{redirects_expected.S_ROW_COUNT}">{redirects_expected.URL}</div>
|
||||
<!-- END redirects_expected -->
|
||||
<!-- INCLUDE overall_footer.html -->
|
Reference in New Issue
Block a user