[ticket/11997] Use path_helper in in foo/bar extension for redirect URLs

By using path_helper's clean_url() method, we'll be able to properly check
the full URL instead of just parts of the expected URL.

PHPBB3-11997
This commit is contained in:
Marc Alexander 2013-12-27 17:51:40 +01:00
parent a304d99b2b
commit 68ce16f9b3
3 changed files with 17 additions and 10 deletions

View file

@ -134,7 +134,7 @@ class phpbb_functional_extension_controller_test extends phpbb_functional_test_c
$redirect = $crawler->filter('#redirect_' . $row_num)->text(); $redirect = $crawler->filter('#redirect_' . $row_num)->text();
$redirect = substr($redirect, 0, strpos($redirect, 'sid') - 1); $redirect = substr($redirect, 0, strpos($redirect, 'sid') - 1);
$this->assertContains($crawler->filter('#redirect_expected_' . $row_num)->text(), $redirect); $this->assertEquals($crawler->filter('#redirect_expected_' . $row_num)->text(), $redirect);
} }
$this->phpbb_extension_manager->purge('foo/bar'); $this->phpbb_extension_manager->purge('foo/bar');

View file

@ -3,6 +3,7 @@ services:
class: foo\bar\controller\controller class: foo\bar\controller\controller
arguments: arguments:
- @controller.helper - @controller.helper
- @path_helper
- @template - @template
- %core.root_path% - %core.root_path%
- %core.php_ext% - %core.php_ext%

View file

@ -8,10 +8,11 @@ class controller
{ {
protected $template; protected $template;
public function __construct(\phpbb\controller\helper $helper, \phpbb\template\template $template, $root_path, $php_ext) public function __construct(\phpbb\controller\helper $helper, \phpbb\path_helper $path_helper, \phpbb\template\template $template, $root_path, $php_ext)
{ {
$this->template = $template; $this->template = $template;
$this->helper = $helper; $this->helper = $helper;
$this->path_helper = $path_helper;
$this->root_path = $root_path; $this->root_path = $root_path;
$this->php_ext = $php_ext; $this->php_ext = $php_ext;
} }
@ -40,6 +41,7 @@ class controller
public function redirect() public function redirect()
{ {
$url_root = generate_board_url();
$redirects = array( $redirects = array(
array( array(
append_sid($this->root_path . 'index.' . $this->php_ext), append_sid($this->root_path . 'index.' . $this->php_ext),
@ -47,7 +49,7 @@ class controller
), ),
array( array(
append_sid($this->root_path . '../index.' . $this->php_ext), append_sid($this->root_path . '../index.' . $this->php_ext),
'index.php', '../index.php',
), ),
array( array(
append_sid($this->root_path . 'tests/index.' . $this->php_ext), append_sid($this->root_path . 'tests/index.' . $this->php_ext),
@ -55,7 +57,7 @@ class controller
), ),
array( array(
append_sid($this->root_path . '../tests/index.' . $this->php_ext), append_sid($this->root_path . '../tests/index.' . $this->php_ext),
'tests/index.php', '../tests/index.php',
), ),
array( array(
$this->helper->url('index'), $this->helper->url('index'),
@ -63,11 +65,11 @@ class controller
), ),
array( array(
$this->helper->url('../index'), $this->helper->url('../index'),
'app.php/index', 'index',
), ),
array( array(
$this->helper->url('../../index'), $this->helper->url('../../index'),
'app.php/index', '../index',
), ),
array( array(
$this->helper->url('tests/index'), $this->helper->url('tests/index'),
@ -75,15 +77,19 @@ class controller
), ),
array( array(
$this->helper->url('../tests/index'), $this->helper->url('../tests/index'),
'app.php/tests/index', 'tests/index',
), ),
array( array(
$this->helper->url('../../tests/index'), $this->helper->url('../../tests/index'),
'app.php/tests/index', '../tests/index',
), ),
array( array(
$this->helper->url('../tests/../index'), $this->helper->url('../tests/../index'),
'app.php/tests/index', 'index',
),
array(
$this->helper->url('tests/../index'),
'app.php/index',
), ),
); );
@ -94,7 +100,7 @@ class controller
)); ));
$this->template->assign_block_vars('redirects_expected', array( $this->template->assign_block_vars('redirects_expected', array(
'URL' => $redirect[1], 'URL' => $this->path_helper->clean_url($url_root . '/' . $redirect[1]),
)); ));
} }