mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-08 04:18:52 +00:00
[ticket/12261] Add a functional test for redirect after using login_box()
PHPBB3-12261
This commit is contained in:
parent
b876c07377
commit
e8fdc1545a
5 changed files with 38 additions and 5 deletions
|
@ -4899,8 +4899,6 @@ function page_header($page_title = '', $display_online_list = true, $item_id = 0
|
|||
$hidden_fields_for_jumpbox = phpbb_build_hidden_fields_for_query_params($request, array('f'));
|
||||
$notification_mark_hash = generate_link_hash('mark_all_notifications_read');
|
||||
|
||||
$redirect_url = $phpbb_path_helper->remove_web_root_path(build_url());
|
||||
|
||||
// The following assigns all _common_ variables that may be used at any point in a template.
|
||||
$template->assign_vars(array(
|
||||
'SITENAME' => $config['sitename'],
|
||||
|
@ -4985,7 +4983,7 @@ function page_header($page_title = '', $display_online_list = true, $item_id = 0
|
|||
'S_TOPIC_ID' => $topic_id,
|
||||
|
||||
'S_LOGIN_ACTION' => ((!defined('ADMIN_START')) ? append_sid("{$phpbb_root_path}ucp.$phpEx", 'mode=login') : append_sid("{$phpbb_admin_path}index.$phpEx", false, true, $user->session_id)),
|
||||
'S_LOGIN_REDIRECT' => build_hidden_fields(array('redirect' => $redirect_url)),
|
||||
'S_LOGIN_REDIRECT' => build_hidden_fields(array('redirect' => $phpbb_path_helper->remove_web_root_path(build_url()))),
|
||||
|
||||
'S_ENABLE_FEEDS' => ($config['feed_enable']) ? true : false,
|
||||
'S_ENABLE_FEEDS_OVERALL' => ($config['feed_overall']) ? true : false,
|
||||
|
|
|
@ -112,12 +112,28 @@ class phpbb_functional_extension_controller_test extends phpbb_functional_test_c
|
|||
$this->assertContains('No route found for "GET /does/not/exist"', $crawler->filter('body')->text());
|
||||
}
|
||||
|
||||
/**
|
||||
* Check the redirect after using he login_box() form
|
||||
*/
|
||||
public function test_login_redirect()
|
||||
{
|
||||
$this->phpbb_extension_manager->enable('foo/bar');
|
||||
$crawler = self::request('GET', 'app.php/foo/login_redirect');
|
||||
$this->assertContainsLang('LOGIN', $crawler->filter('h2')->text());
|
||||
$form = $crawler->selectButton('login')->form(array(
|
||||
'username' => 'admin',
|
||||
'password' => 'adminadmin',
|
||||
));
|
||||
$crawler = self::submit($form);
|
||||
$this->assertContains("I am a variable", $crawler->filter('#content')->text(), 'Unsuccessful redirect after using login_box()');
|
||||
$this->phpbb_extension_manager->purge('foo/bar');
|
||||
}
|
||||
|
||||
/**
|
||||
* 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');
|
||||
|
||||
|
|
|
@ -14,6 +14,10 @@ foo_exception_controller:
|
|||
pattern: /foo/exception
|
||||
defaults: { _controller: foo_bar.controller:exception }
|
||||
|
||||
foo_login_redirect_controller:
|
||||
pattern: /foo/login_redirect
|
||||
defaults: { _controller: foo_bar.controller:login_redirect }
|
||||
|
||||
foo_redirect_controller:
|
||||
pattern: /foo/redirect
|
||||
defaults: { _controller: foo_bar.controller:redirect }
|
||||
|
|
|
@ -6,6 +6,7 @@ services:
|
|||
- @path_helper
|
||||
- @template
|
||||
- @config
|
||||
- @user
|
||||
- %core.root_path%
|
||||
- %core.php_ext%
|
||||
|
||||
|
|
|
@ -10,13 +10,15 @@ class controller
|
|||
protected $helper;
|
||||
protected $path_helper;
|
||||
protected $config;
|
||||
protected $user;
|
||||
|
||||
public function __construct(\phpbb\controller\helper $helper, \phpbb\path_helper $path_helper, \phpbb\template\template $template, \phpbb\config\config $config, $root_path, $php_ext)
|
||||
public function __construct(\phpbb\controller\helper $helper, \phpbb\path_helper $path_helper, \phpbb\template\template $template, \phpbb\config\config $config, \phpbb\user $user, $root_path, $php_ext)
|
||||
{
|
||||
$this->template = $template;
|
||||
$this->helper = $helper;
|
||||
$this->path_helper = $path_helper;
|
||||
$this->config = $config;
|
||||
$this->user = $user;
|
||||
$this->root_path = $root_path;
|
||||
$this->php_ext = $php_ext;
|
||||
}
|
||||
|
@ -43,6 +45,18 @@ class controller
|
|||
throw new \phpbb\controller\exception('Exception thrown from foo/exception route');
|
||||
}
|
||||
|
||||
public function login_redirect()
|
||||
{
|
||||
if (!$this->user->data['is_registered'])
|
||||
{
|
||||
login_box();
|
||||
}
|
||||
|
||||
$this->template->assign_var('A_VARIABLE', 'I am a variable');
|
||||
|
||||
return $this->helper->render('foo_bar_body.html');
|
||||
}
|
||||
|
||||
public function redirect()
|
||||
{
|
||||
$url_root = generate_board_url();
|
||||
|
|
Loading…
Add table
Reference in a new issue