From a0fca0acc24684615d123d71ce696e43ba4e2615 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 13 Nov 2013 12:03:06 +0100 Subject: [ticket/11997] Add functional test for redirects in controller PHPBB3-11997 --- .../fixtures/ext/foo/bar/controller/controller.php | 30 +++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) (limited to 'tests/functional/fixtures/ext/foo/bar/controller/controller.php') diff --git a/tests/functional/fixtures/ext/foo/bar/controller/controller.php b/tests/functional/fixtures/ext/foo/bar/controller/controller.php index 259d548299..ebb259af2f 100644 --- a/tests/functional/fixtures/ext/foo/bar/controller/controller.php +++ b/tests/functional/fixtures/ext/foo/bar/controller/controller.php @@ -8,10 +8,12 @@ class controller { protected $template; - public function __construct(\phpbb\controller\helper $helper, \phpbb\template\template $template) + public function __construct(\phpbb\controller\helper $helper, \phpbb\template\template $template, $root_path, $php_ext) { $this->template = $template; $this->helper = $helper; + $this->root_path = $root_path; + $this->php_ext = $php_ext; } public function handle() @@ -35,4 +37,30 @@ class controller { throw new \phpbb\controller\exception('Exception thrown from foo/exception route'); } + + public function redirect() + { + $redirects = array( + append_sid($this->root_path . 'index.' . $this->php_ext), + append_sid($this->root_path . '../index.' . $this->php_ext), + append_sid($this->root_path . 'tests/index.' . $this->php_ext), + append_sid($this->root_path . '../tests/index.' . $this->php_ext), + $this->helper->url('index'), + $this->helper->url('../index'), + $this->helper->url('../../index'), + $this->helper->url('tests/index'), + $this->helper->url('../tests/index'), + $this->helper->url('../../tests/index'), + $this->helper->url('../tests/../index'), + ); + + foreach ($redirects as $redirect) + { + $this->template->assign_block_vars('redirects', array( + 'URL' => redirect($redirect, true), + )); + } + + return $this->helper->render('redirect_body.html'); + } } -- cgit v1.2.1 From 15913fdf79b8e41049e3263e5e27e6690effc65e Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Fri, 20 Dec 2013 18:13:53 +0100 Subject: [ticket/11997] Move expected redirect returns to controller and output to HTML The controller will now output the expected redirect returns the same way the redirect returns are output. The extension controller test will compare those 2 outputs. PHPBB3-11997 --- .../fixtures/ext/foo/bar/controller/controller.php | 61 +++++++++++++++++----- 1 file changed, 49 insertions(+), 12 deletions(-) (limited to 'tests/functional/fixtures/ext/foo/bar/controller/controller.php') diff --git a/tests/functional/fixtures/ext/foo/bar/controller/controller.php b/tests/functional/fixtures/ext/foo/bar/controller/controller.php index ebb259af2f..18ec756d3c 100644 --- a/tests/functional/fixtures/ext/foo/bar/controller/controller.php +++ b/tests/functional/fixtures/ext/foo/bar/controller/controller.php @@ -41,23 +41,60 @@ class controller public function redirect() { $redirects = array( - append_sid($this->root_path . 'index.' . $this->php_ext), - append_sid($this->root_path . '../index.' . $this->php_ext), - append_sid($this->root_path . 'tests/index.' . $this->php_ext), - append_sid($this->root_path . '../tests/index.' . $this->php_ext), - $this->helper->url('index'), - $this->helper->url('../index'), - $this->helper->url('../../index'), - $this->helper->url('tests/index'), - $this->helper->url('../tests/index'), - $this->helper->url('../../tests/index'), - $this->helper->url('../tests/../index'), + array( + append_sid($this->root_path . 'index.' . $this->php_ext), + 'index.php', + ), + array( + append_sid($this->root_path . '../index.' . $this->php_ext), + 'index.php', + ), + array( + append_sid($this->root_path . 'tests/index.' . $this->php_ext), + 'tests/index.php', + ), + array( + append_sid($this->root_path . '../tests/index.' . $this->php_ext), + 'tests/index.php', + ), + array( + $this->helper->url('index'), + 'app.php/index', + ), + array( + $this->helper->url('../index'), + 'app.php/index', + ), + array( + $this->helper->url('../../index'), + 'app.php/index', + ), + array( + $this->helper->url('tests/index'), + 'app.php/tests/index', + ), + array( + $this->helper->url('../tests/index'), + 'app.php/tests/index', + ), + array( + $this->helper->url('../../tests/index'), + 'app.php/tests/index', + ), + array( + $this->helper->url('../tests/../index'), + 'app.php/tests/index', + ), ); foreach ($redirects as $redirect) { $this->template->assign_block_vars('redirects', array( - 'URL' => redirect($redirect, true), + 'URL' => redirect($redirect[0], true), + )); + + $this->template->assign_block_vars('redirects_expected', array( + 'URL' => $redirect[1], )); } -- cgit v1.2.1 From 68ce16f9b33c5aea8f7f6530dd06eb4661333b0b Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Fri, 27 Dec 2013 17:51:40 +0100 Subject: [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 --- .../fixtures/ext/foo/bar/controller/controller.php | 24 ++++++++++++++-------- 1 file changed, 15 insertions(+), 9 deletions(-) (limited to 'tests/functional/fixtures/ext/foo/bar/controller/controller.php') diff --git a/tests/functional/fixtures/ext/foo/bar/controller/controller.php b/tests/functional/fixtures/ext/foo/bar/controller/controller.php index 18ec756d3c..3ba253256a 100644 --- a/tests/functional/fixtures/ext/foo/bar/controller/controller.php +++ b/tests/functional/fixtures/ext/foo/bar/controller/controller.php @@ -8,10 +8,11 @@ class controller { 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->helper = $helper; + $this->path_helper = $path_helper; $this->root_path = $root_path; $this->php_ext = $php_ext; } @@ -40,6 +41,7 @@ class controller public function redirect() { + $url_root = generate_board_url(); $redirects = array( array( append_sid($this->root_path . 'index.' . $this->php_ext), @@ -47,7 +49,7 @@ class controller ), array( append_sid($this->root_path . '../index.' . $this->php_ext), - 'index.php', + '../index.php', ), array( append_sid($this->root_path . 'tests/index.' . $this->php_ext), @@ -55,7 +57,7 @@ class controller ), array( append_sid($this->root_path . '../tests/index.' . $this->php_ext), - 'tests/index.php', + '../tests/index.php', ), array( $this->helper->url('index'), @@ -63,11 +65,11 @@ class controller ), array( $this->helper->url('../index'), - 'app.php/index', + 'index', ), array( $this->helper->url('../../index'), - 'app.php/index', + '../index', ), array( $this->helper->url('tests/index'), @@ -75,15 +77,19 @@ class controller ), array( $this->helper->url('../tests/index'), - 'app.php/tests/index', + 'tests/index', ), array( $this->helper->url('../../tests/index'), - 'app.php/tests/index', + '../tests/index', ), array( $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( - 'URL' => $redirect[1], + 'URL' => $this->path_helper->clean_url($url_root . '/' . $redirect[1]), )); } -- cgit v1.2.1 From 3e815616c5e5237cc1201e6e29337c4a601049c5 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Sat, 28 Dec 2013 16:50:15 +0100 Subject: [ticket/11997] Fix redirect tests for mod rewrite Controller routes that are supposed to link to parent directories can't be tested as the links are incorrectly created depending on enabled mod rewrite or not. PHPBB3-11997 --- .../fixtures/ext/foo/bar/controller/controller.php | 41 ++++++++++++++-------- 1 file changed, 26 insertions(+), 15 deletions(-) (limited to 'tests/functional/fixtures/ext/foo/bar/controller/controller.php') diff --git a/tests/functional/fixtures/ext/foo/bar/controller/controller.php b/tests/functional/fixtures/ext/foo/bar/controller/controller.php index 3ba253256a..fc0f6e21af 100644 --- a/tests/functional/fixtures/ext/foo/bar/controller/controller.php +++ b/tests/functional/fixtures/ext/foo/bar/controller/controller.php @@ -7,12 +7,16 @@ use Symfony\Component\HttpFoundation\Response; class controller { protected $template; + protected $helper; + protected $path_helper; + protected $config; - public function __construct(\phpbb\controller\helper $helper, \phpbb\path_helper $path_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, \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; } @@ -42,6 +46,9 @@ class controller 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), @@ -61,36 +68,40 @@ class controller ), array( $this->helper->url('index'), - 'app.php/index', + $rewrite_prefix . 'index', ), array( - $this->helper->url('../index'), - 'index', + $this->helper->url('tests/index'), + $rewrite_prefix . 'tests/index', ), array( - $this->helper->url('../../index'), - '../index', + $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('tests/index'), - 'app.php/tests/index', + $this->helper->url('../index'), + '../index', ), array( - $this->helper->url('../tests/index'), - 'tests/index', + $this->helper->url('../../index'), + '../index', ), array( - $this->helper->url('../../tests/index'), - '../tests/index', + $this->helper->url('../tests/index'), + $rewrite_prefix . '../tests/index', ), array( $this->helper->url('../tests/../index'), - 'index', + '../index', ), array( - $this->helper->url('tests/../index'), - 'app.php/index', + $this->helper->url('../../tests/index'), + '../tests/index', ), + */ ); foreach ($redirects as $redirect) -- cgit v1.2.1 From f906fb41e9e995c0ea472a8d6594f54df6f208bf Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Sat, 28 Dec 2013 20:40:18 +0100 Subject: [ticket/11997] Use functional test cases that should always work The previous test cases that tried to redirect to ../index.php and similar might cause us to try to go to http://localhost/../index.php, which will result in http://index.php. As this obviously will trigger an error as intended, we should not put this inside our test cases for the redirect function. PHPBB3-11997 --- tests/functional/fixtures/ext/foo/bar/controller/controller.php | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) (limited to 'tests/functional/fixtures/ext/foo/bar/controller/controller.php') diff --git a/tests/functional/fixtures/ext/foo/bar/controller/controller.php b/tests/functional/fixtures/ext/foo/bar/controller/controller.php index fc0f6e21af..558b202948 100644 --- a/tests/functional/fixtures/ext/foo/bar/controller/controller.php +++ b/tests/functional/fixtures/ext/foo/bar/controller/controller.php @@ -55,17 +55,13 @@ class controller 'index.php', ), array( - append_sid($this->root_path . '../index.' . $this->php_ext), - '../index.php', + 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( - append_sid($this->root_path . '../tests/index.' . $this->php_ext), - '../tests/index.php', - ), array( $this->helper->url('index'), $rewrite_prefix . 'index', -- cgit v1.2.1