From c08f728fe452fbb1ecc5f74b8bdba4e294599ba5 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Sun, 4 Jan 2015 15:40:42 +0100 Subject: [PATCH 1/4] [ticket/436] Use controller helper for generating URLs in announcements B3P-436 --- config/modules.yml | 1 + modules/announcements.php | 15 ++++++++++----- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/config/modules.yml b/config/modules.yml index 77e11098..d27793ea 100644 --- a/config/modules.yml +++ b/config/modules.yml @@ -14,6 +14,7 @@ services: - %core.root_path% - @user - @board3.portal.fetch_posts + - @controller.helper tags: - { name: board3.portal.module } diff --git a/modules/announcements.php b/modules/announcements.php index c95c10d7..8cdfd81a 100644 --- a/modules/announcements.php +++ b/modules/announcements.php @@ -80,6 +80,9 @@ class announcements extends module_base /** @var \board3\portal\portal\fetch_posts */ protected $fetch_posts; + /** @var \phpbb\controller\helper */ + protected $controller_helper; + /** * Construct an announcements object * @@ -95,8 +98,9 @@ class announcements extends module_base * @param string $phpbb_root_path phpBB root path * @param \phpbb\user $user phpBB user object * @param \board3\portal\portal\fetch_posts $fetch_posts Fetch posts object + * @param \phpbb\controller\helper $controller_helper Controller helper */ - public function __construct($auth, $cache, $config, $template, $db, $pagination, $modules_helper, $request, $phpEx, $phpbb_root_path, $user, $fetch_posts) + public function __construct($auth, $cache, $config, $template, $db, $pagination, $modules_helper, $request, $phpEx, $phpbb_root_path, $user, $fetch_posts, $controller_helper) { $this->auth = $auth; $this->cache = $cache; @@ -110,6 +114,7 @@ class announcements extends module_base $this->phpbb_root_path = $phpbb_root_path; $this->user = $user; $this->fetch_posts = $fetch_posts; + $this->controller_helper = $controller_helper; } /** @@ -234,7 +239,7 @@ class announcements extends module_base if ($this->config['board3_number_of_announcements_' . $module_id] != 0 && $this->config['board3_announcements_archive_' . $module_id]) { - $pagination = generate_portal_pagination(append_sid("{$this->phpbb_root_path}app.{$this->php_ext}/portal"), $total_announcements, $this->config['board3_number_of_announcements_' . $module_id], $start, 'announcements', $module_id); + $pagination = generate_portal_pagination($this->controller_helper->route('board3_portal_controller'), $total_announcements, $this->config['board3_number_of_announcements_' . $module_id], $start, 'announcements', $module_id); $announcements_row = array_merge($announcements_row, array( 'AP_PAGINATION' => (isset($pagination)) ? $pagination : '', @@ -340,7 +345,7 @@ class announcements extends module_base 'U_VIEW_COMMENTS' => append_sid("{$this->phpbb_root_path}viewtopic.{$this->php_ext}", (($real_forum_id) ? 'f=' . $real_forum_id . '&' : '') . 't=' . $topic_id), 'U_VIEW_UNREAD' => append_sid("{$this->phpbb_root_path}viewtopic.{$this->php_ext}", (($real_forum_id) ? 'f=' . $real_forum_id . '&' : '') . 't=' . $topic_id . '&view=unread#unread'), 'U_POST_COMMENT' => append_sid("{$this->phpbb_root_path}posting.{$this->php_ext}", 'mode=reply&' . (($real_forum_id) ? 'f=' . $real_forum_id . '&' : '') . 't=' . $topic_id), - 'U_READ_FULL' => append_sid("{$this->phpbb_root_path}app.{$this->php_ext}/portal", $read_full_url), + 'U_READ_FULL' => $this->controller_helper->route('board3_portal_controller') . '?' . $read_full_url, 'L_READ_FULL' => $read_full, 'OPEN' => $open_bracket, 'CLOSE' => $close_bracket, @@ -374,7 +379,7 @@ class announcements extends module_base */ if (!isset($fetch_news[$i])) { - redirect(append_sid($this->phpbb_root_path . 'app.' . $this->php_ext, '/portal#top')); + redirect($this->controller_helper->route('board3_portal_controller') . '#top'); } $forum_id = $fetch_news[$i]['forum_id']; @@ -386,7 +391,7 @@ class announcements extends module_base $read_full = $this->user->lang['BACK']; $real_forum_id = ($forum_id == 0) ? $fetch_news['global_id']: $forum_id; - $read_full_url = ($this->request->is_set('ap_' . $module_id)) ? append_sid("{$this->phpbb_root_path}app.{$this->php_ext}/portal", "ap_{$module_id}=$start#a_{$module_id}_$i") : append_sid("{$this->phpbb_root_path}app.{$this->php_ext}/portal#a_{$module_id}_$i"); + $read_full_url = ($this->request->is_set('ap_' . $module_id)) ? $this->controller_helper->route('board3_portal_controller') . "?ap_{$module_id}=$start#a_{$module_id}_$i" : $this->controller_helper->route('board3_portal_controller') . "#a_{$module_id}_$i"; $view_topic_url = append_sid("{$this->phpbb_root_path}viewtopic.{$this->php_ext}", 'f=' . (($fetch_news[$i]['forum_id']) ? $fetch_news[$i]['forum_id'] : $forum_id) . '&t=' . $topic_id); $this->template->assign_block_vars('announcements.center_row', array( From 2640fea63564800cff3512bd6b7bc33893ef4afe Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Sun, 4 Jan 2015 16:09:43 +0100 Subject: [PATCH 2/4] [ticket/436] Generate routes with modules_helper and remove use of app.php Modules should generate routes with the modules helper instead of directly creating links to app.php. B3P-436 --- config/modules.yml | 6 +++--- config/services.yml | 1 + includes/modules_helper.php | 25 ++++++++++++++++++++++++- modules/announcements.php | 15 +++++---------- modules/calendar.php | 23 ++++++++++++++--------- modules/news.php | 6 +++--- modules/poll.php | 13 +++++++++---- modules/stylechanger.php | 33 ++++++++++++++------------------- 8 files changed, 73 insertions(+), 49 deletions(-) diff --git a/config/modules.yml b/config/modules.yml index d27793ea..ef555153 100644 --- a/config/modules.yml +++ b/config/modules.yml @@ -14,7 +14,6 @@ services: - %core.root_path% - @user - @board3.portal.fetch_posts - - @controller.helper tags: - { name: board3.portal.module } @@ -47,6 +46,7 @@ services: class: board3\portal\modules\calendar arguments: - @config + - @board3.portal.modules_helper - @template - @dbal.conn - @request @@ -211,6 +211,7 @@ services: - %core.root_path% - %core.php_ext% - @user + - @board3.portal.modules_helper tags: - { name: board3.portal.module } @@ -260,11 +261,10 @@ services: class: board3\portal\modules\stylechanger arguments: - @config + - @board3.portal.modules_helper - @template - @dbal.conn - @request - - %core.php_ext% - - %core.root_path% - @user tags: - { name: board3.portal.module } diff --git a/config/services.yml b/config/services.yml index f560c8d4..593fb918 100644 --- a/config/services.yml +++ b/config/services.yml @@ -68,6 +68,7 @@ services: arguments: - @auth - @config + - @controller.helper - @request board3.portal.columns: diff --git a/includes/modules_helper.php b/includes/modules_helper.php index 10738891..a8f7858f 100644 --- a/includes/modules_helper.php +++ b/includes/modules_helper.php @@ -9,6 +9,8 @@ namespace board3\portal\includes; +use Symfony\Component\Routing\Generator\UrlGeneratorInterface; + class modules_helper { /** @@ -23,6 +25,9 @@ class modules_helper */ protected $config; + /** @var \phpbb\controller\helper Controller helper */ + protected $controller_helper; + /** * phpBB request * @var \phpbb\request\request @@ -35,12 +40,14 @@ class modules_helper * the dependencies defined in the services.yml file for this service. * @param \phpbb\auth\auth $auth Auth object * @param \phpbb\config\config $config phpBB config + * @param \phpbb\controller\helper $controller_helper Controller helper * @param \phpbb\request\request $request phpBB request */ - public function __construct($auth, $config, $request) + public function __construct($auth, $config, $controller_helper, $request) { $this->auth = $auth; $this->config = $config; + $this->controller_helper = $controller_helper; $this->request = $request; } @@ -135,4 +142,20 @@ class modules_helper $news = implode(',', $values); $this->config->set($key, $news); } + + /** + * Wrapper method for controller_helper::route() + * + * @param string $route Route name + * @param array $params Route parameters + * @param bool $is_amp + * @param bool $session_id + * @param bool $reference_type + * + * @return string URL for route + */ + public function route($route, $params = array(), $is_amp = true, $session_id = false, $reference_type = UrlGeneratorInterface::ABSOLUTE_PATH) + { + return $this->controller_helper->route($route, $params, $is_amp, $session_id, $reference_type); + } } diff --git a/modules/announcements.php b/modules/announcements.php index 8cdfd81a..88399a29 100644 --- a/modules/announcements.php +++ b/modules/announcements.php @@ -80,9 +80,6 @@ class announcements extends module_base /** @var \board3\portal\portal\fetch_posts */ protected $fetch_posts; - /** @var \phpbb\controller\helper */ - protected $controller_helper; - /** * Construct an announcements object * @@ -98,9 +95,8 @@ class announcements extends module_base * @param string $phpbb_root_path phpBB root path * @param \phpbb\user $user phpBB user object * @param \board3\portal\portal\fetch_posts $fetch_posts Fetch posts object - * @param \phpbb\controller\helper $controller_helper Controller helper */ - public function __construct($auth, $cache, $config, $template, $db, $pagination, $modules_helper, $request, $phpEx, $phpbb_root_path, $user, $fetch_posts, $controller_helper) + public function __construct($auth, $cache, $config, $template, $db, $pagination, $modules_helper, $request, $phpEx, $phpbb_root_path, $user, $fetch_posts) { $this->auth = $auth; $this->cache = $cache; @@ -114,7 +110,6 @@ class announcements extends module_base $this->phpbb_root_path = $phpbb_root_path; $this->user = $user; $this->fetch_posts = $fetch_posts; - $this->controller_helper = $controller_helper; } /** @@ -239,7 +234,7 @@ class announcements extends module_base if ($this->config['board3_number_of_announcements_' . $module_id] != 0 && $this->config['board3_announcements_archive_' . $module_id]) { - $pagination = generate_portal_pagination($this->controller_helper->route('board3_portal_controller'), $total_announcements, $this->config['board3_number_of_announcements_' . $module_id], $start, 'announcements', $module_id); + $pagination = generate_portal_pagination($this->modules_helper->route('board3_portal_controller'), $total_announcements, $this->config['board3_number_of_announcements_' . $module_id], $start, 'announcements', $module_id); $announcements_row = array_merge($announcements_row, array( 'AP_PAGINATION' => (isset($pagination)) ? $pagination : '', @@ -345,7 +340,7 @@ class announcements extends module_base 'U_VIEW_COMMENTS' => append_sid("{$this->phpbb_root_path}viewtopic.{$this->php_ext}", (($real_forum_id) ? 'f=' . $real_forum_id . '&' : '') . 't=' . $topic_id), 'U_VIEW_UNREAD' => append_sid("{$this->phpbb_root_path}viewtopic.{$this->php_ext}", (($real_forum_id) ? 'f=' . $real_forum_id . '&' : '') . 't=' . $topic_id . '&view=unread#unread'), 'U_POST_COMMENT' => append_sid("{$this->phpbb_root_path}posting.{$this->php_ext}", 'mode=reply&' . (($real_forum_id) ? 'f=' . $real_forum_id . '&' : '') . 't=' . $topic_id), - 'U_READ_FULL' => $this->controller_helper->route('board3_portal_controller') . '?' . $read_full_url, + 'U_READ_FULL' => $this->modules_helper->route('board3_portal_controller') . '?' . $read_full_url, 'L_READ_FULL' => $read_full, 'OPEN' => $open_bracket, 'CLOSE' => $close_bracket, @@ -379,7 +374,7 @@ class announcements extends module_base */ if (!isset($fetch_news[$i])) { - redirect($this->controller_helper->route('board3_portal_controller') . '#top'); + redirect($this->modules_helper->route('board3_portal_controller') . '#top'); } $forum_id = $fetch_news[$i]['forum_id']; @@ -391,7 +386,7 @@ class announcements extends module_base $read_full = $this->user->lang['BACK']; $real_forum_id = ($forum_id == 0) ? $fetch_news['global_id']: $forum_id; - $read_full_url = ($this->request->is_set('ap_' . $module_id)) ? $this->controller_helper->route('board3_portal_controller') . "?ap_{$module_id}=$start#a_{$module_id}_$i" : $this->controller_helper->route('board3_portal_controller') . "#a_{$module_id}_$i"; + $read_full_url = ($this->request->is_set('ap_' . $module_id)) ? $this->modules_helper->route('board3_portal_controller') . "?ap_{$module_id}=$start#a_{$module_id}_$i" : $this->modules_helper->route('board3_portal_controller') . "#a_{$module_id}_$i"; $view_topic_url = append_sid("{$this->phpbb_root_path}viewtopic.{$this->php_ext}", 'f=' . (($fetch_news[$i]['forum_id']) ? $fetch_news[$i]['forum_id'] : $forum_id) . '&t=' . $topic_id); $this->template->assign_block_vars('announcements.center_row', array( diff --git a/modules/calendar.php b/modules/calendar.php index 60589d79..17a80a11 100644 --- a/modules/calendar.php +++ b/modules/calendar.php @@ -89,13 +89,13 @@ class calendar extends module_base /** @var \phpbb\config\config */ protected $config; - /** @var \phpbb\template */ + /** @var \phpbb\template\template */ protected $template; - /** @var \phpbb\db\driver */ + /** @var \phpbb\db\driver\driver_interface */ protected $db; - /** @var \phpbb\request\request */ + /** @var \phpbb\request\request_interface */ protected $request; /** @var string PHP file extension */ @@ -116,22 +116,27 @@ class calendar extends module_base /** @var \phpbb\log\log phpBB log */ protected $log; + /** @var \board3\portal\includes\modules_helper */ + protected $modules_helper; + /** * Construct a calendar object * * @param \phpbb\config\config $config phpBB config - * @param \phpbb\template $template phpBB template - * @param \phpbb\db\driver $db Database driver - * @param \phpbb\request\request $request phpBB request + * @param \board3\portal\includes\modules_helper $modules_helper Modules helper + * @param \phpbb\template\template $template phpBB template + * @param \phpbb\db\driver\driver_interface $db Database driver + * @param \phpbb\request\request_interface $request phpBB request * @param string $phpEx php file extension * @param string $phpbb_root_path phpBB root path * @param \phpbb\user $user phpBB user object * @param \phpbb\path_helper $path_helper phpBB path helper * @param \phpbb\log\log $log phpBB log object */ - public function __construct($config, $template, $db, $request, $phpbb_root_path, $phpEx, $user, $path_helper, $log) + public function __construct($config, $modules_helper, $template, $db, $request, $phpbb_root_path, $phpEx, $user, $path_helper, $log) { $this->config = $config; + $this->modules_helper = $modules_helper; $this->template = $template; $this->db = $db; $this->request = $request; @@ -183,8 +188,8 @@ class calendar extends module_base // output our general calendar bits $down = $this->mini_cal_month - 1; $up = $this->mini_cal_month + 1; - $prev_month = 'phpbb_root_path}app.{$this->php_ext}/portal", "m$module_id=$down#minical$module_id") . '"><<'; - $next_month = 'phpbb_root_path}app.{$this->php_ext}/portal", "m$module_id=$up#minical$module_id") . '">>>'; + $prev_month = '<<'; + $next_month = '>>'; $this->template->assign_block_vars('minical', array( 'S_SUNDAY_FIRST' => ($this->config['board3_sunday_first_' . $module_id]) ? true : false, diff --git a/modules/news.php b/modules/news.php index 1fdda29a..3d31e9e5 100644 --- a/modules/news.php +++ b/modules/news.php @@ -228,7 +228,7 @@ class news extends module_base // Create pagination if necessary if ($this->config['board3_news_archive_' . $module_id]) { - $pagination = generate_portal_pagination(append_sid("{$this->phpbb_root_path}app.{$this->php_ext}/portal"), $total_news, $this->config['board3_number_of_news_' . $module_id], $start, ($this->config['board3_show_all_news_' . $module_id]) ? 'news_all' : 'news', $module_id); + $pagination = generate_portal_pagination($this->modules_helper->route('board3_portal_controller'), $total_news, $this->config['board3_number_of_news_' . $module_id], $start, ($this->config['board3_show_all_news_' . $module_id]) ? 'news_all' : 'news', $module_id); } if ($this->config['board3_number_of_news_' . $module_id] <> 0 && $this->config['board3_news_archive_' . $module_id]) @@ -338,7 +338,7 @@ class news extends module_base 'U_VIEW_COMMENTS' => append_sid("{$this->phpbb_root_path}viewtopic.{$this->php_ext}", 'f=' . $fetch_news[$i]['forum_id'] . '&t=' . $fetch_news[$i]['topic_id']), 'U_VIEW_UNREAD' => append_sid("{$this->phpbb_root_path}viewtopic.{$this->php_ext}", 'f=' . $fetch_news[$i]['forum_id'] . '&t=' . $fetch_news[$i]['topic_id'] . '&view=unread#unread'), 'U_POST_COMMENT' => append_sid("{$this->phpbb_root_path}posting.{$this->php_ext}", 'mode=reply&f=' . $fetch_news[$i]['forum_id'] . '&t=' . $fetch_news[$i]['topic_id']), - 'U_READ_FULL' => append_sid("{$this->phpbb_root_path}app.{$this->php_ext}/portal", $read_full_url), + 'U_READ_FULL' => $this->modules_helper->route('board3_portal_controller') . '?' . $read_full_url, 'L_READ_FULL' => $read_full, 'OPEN' => $open_bracket, 'CLOSE' => $close_bracket, @@ -370,7 +370,7 @@ class news extends module_base $close_bracket = ' ]'; $read_full = $this->user->lang['BACK']; - $read_full_url = ($this->request->is_set('np_' . $module_id)) ? append_sid("{$this->phpbb_root_path}app.{$this->php_ext}/portal", "np_$module_id=$start#n_{$module_id}_$i") : append_sid("{$this->phpbb_root_path}app.{$this->php_ext}/portal#n_{$module_id}_$i"); + $read_full_url = ($this->request->is_set('np_' . $module_id)) ? $this->modules_helper->route('board3_portal_controller') . "?np_$module_id=$start#n_{$module_id}_$i" : $this->modules_helper->route('board3_portal_controller') . "#n_{$module_id}_$i"; $view_topic_url = append_sid("{$this->phpbb_root_path}viewtopic.{$this->php_ext}", 'f=' . (($fetch_news[$i]['forum_id']) ? $fetch_news[$i]['forum_id'] : $forum_id) . '&t=' . $topic_id); $this->template->assign_block_vars('news.news_row', array( diff --git a/modules/poll.php b/modules/poll.php index 51495967..4480b4a5 100644 --- a/modules/poll.php +++ b/modules/poll.php @@ -71,6 +71,9 @@ class poll extends module_base /** @var \phpbb\user */ protected $user; + /** @var \board3\portal\includes\modules_helper */ + protected $modules_helper; + /** * Construct a poll object * @@ -82,8 +85,9 @@ class poll extends module_base * @param string $phpEx php file extension * @param string $phpbb_root_path phpBB root path * @param \phpbb\user $user phpBB user object + * @param \board3\portal\includes\modules_helper $modules_helper Modules helper */ - public function __construct($auth, $config, $db, $request, $template, $phpbb_root_path, $phpEx, $user) + public function __construct($auth, $config, $db, $request, $template, $phpbb_root_path, $phpEx, $user, $modules_helper) { $this->auth = $auth; $this->config = $config; @@ -93,6 +97,7 @@ class poll extends module_base $this->php_ext = $phpEx; $this->phpbb_root_path = $phpbb_root_path; $this->user = $user; + $this->modules_helper = $modules_helper; } /** @@ -231,7 +236,7 @@ class poll extends module_base if($s_can_up_vote) { - $redirect_url = append_sid("{$this->phpbb_root_path}app.{$this->php_ext}/portal"); + $redirect_url = $this->modules_helper->route('board3_portal_controller'); if (!sizeof($voted_id) || sizeof($voted_id) > $topic_data['poll_max_options'] || in_array(VOTE_CONVERTED, $cur_voted_id)) { @@ -449,8 +454,8 @@ class poll extends module_base } $poll_view_str = urlencode(implode(',', $make_poll_view)); - $portalpoll_url= append_sid("{$this->phpbb_root_path}app.{$this->php_ext}/portal", "polls=$poll_view_str"); - $portalvote_url= append_sid("{$this->phpbb_root_path}app.{$this->php_ext}/portal", "f=$forum_id&t=$topic_id"); + $portalpoll_url= $this->modules_helper->route('board3_portal_controller') . "polls=$poll_view_str"; + $portalvote_url= $this->modules_helper->route('board3_portal_controller') . "f=$forum_id&t=$topic_id"; $viewtopic_url = append_sid("{$this->phpbb_root_path}viewtopic.{$this->php_ext}", "f=$forum_id&t=$topic_id"); $poll_end = $data['poll_length'] + $data['poll_start']; diff --git a/modules/stylechanger.php b/modules/stylechanger.php index 162dad7c..637199f6 100644 --- a/modules/stylechanger.php +++ b/modules/stylechanger.php @@ -44,21 +44,18 @@ class stylechanger extends module_base /** @var \phpbb\config\config */ protected $config; - /** @var \phpbb\template */ + /** @var \board3\portal\includes\modules_helper */ + protected $modules_helper; + + /** @var \phpbb\template\template */ protected $template; - /** @var \phpbb\db\driver */ + /** @var \phpbb\db\driver\driver_interface */ protected $db; - /** @var \phpbb\request\request */ + /** @var \phpbb\request\request_interface */ protected $request; - /** @var string PHP file extension */ - protected $php_ext; - - /** @var string phpBB root path */ - protected $phpbb_root_path; - /** @var \phpbb\user */ protected $user; @@ -66,21 +63,19 @@ class stylechanger extends module_base * Construct a stylechanger object * * @param \phpbb\config\config $config phpBB config - * @param \phpbb\template $template phpBB template - * @param \phpbb\db\driver $db Database driver - * @param \phpbb\request\request $request phpBB request - * @param string $phpEx php file extension - * @param string $phpbb_root_path phpBB root path + * @param \board3\portal\includes\modules_helper $modules_helper Modules helper + * @param \phpbb\template\template $template phpBB template + * @param \phpbb\db\driver\driver_interface $db Database driver + * @param \phpbb\request\request_interface $request phpBB request * @param \phpbb\user $user phpBB user object */ - public function __construct($config, $template, $db, $request, $phpEx, $phpbb_root_path, $user) + public function __construct($config, $modules_helper, $template, $db, $request, $user) { $this->config = $config; + $this->modules_helper = $modules_helper; $this->template = $template; $this->db = $db; $this->request = $request; - $this->php_ext = $phpEx; - $this->phpbb_root_path = $phpbb_root_path; $this->user = $user; } @@ -101,11 +96,11 @@ class stylechanger extends module_base $style = $this->request->variable('style', 0); if (!empty($style)) { - $url = str_replace('style=' . $style, 'style=' . $row['style_id'], append_sid("{$this->phpbb_root_path}app.{$this->php_ext}/portal")); + $url = str_replace('style=' . $style, 'style=' . $row['style_id'], $this->modules_helper->route('board3_portal_controller')); } else { - $url = append_sid("{$this->phpbb_root_path}app.{$this->php_ext}/portal", 'style=' . $row['style_id']); + $url = $this->modules_helper->route('board3_portal_controller') . '?style=' . $row['style_id']; } ++$style_count; $style_select .= ''; From b4999f2c38b528d3ebb70a5de7d2d9365ab5e945 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Sun, 18 Jan 2015 15:11:54 +0100 Subject: [PATCH 3/4] [ticket/436] Correctly generate links for poll module B3P-436 --- modules/poll.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/poll.php b/modules/poll.php index 4480b4a5..b5a621de 100644 --- a/modules/poll.php +++ b/modules/poll.php @@ -454,8 +454,8 @@ class poll extends module_base } $poll_view_str = urlencode(implode(',', $make_poll_view)); - $portalpoll_url= $this->modules_helper->route('board3_portal_controller') . "polls=$poll_view_str"; - $portalvote_url= $this->modules_helper->route('board3_portal_controller') . "f=$forum_id&t=$topic_id"; + $portalpoll_url= $this->modules_helper->route('board3_portal_controller') . "?polls=$poll_view_str"; + $portalvote_url= $this->modules_helper->route('board3_portal_controller') . "?f=$forum_id&t=$topic_id"; $viewtopic_url = append_sid("{$this->phpbb_root_path}viewtopic.{$this->php_ext}", "f=$forum_id&t=$topic_id"); $poll_end = $data['poll_length'] + $data['poll_start']; From f4ceb4412480f8cc3544a8f321b010287d766de2 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Sun, 18 Jan 2015 15:12:18 +0100 Subject: [PATCH 4/4] [ticket/436] Mock controller helper for unit tests B3P-436 --- tests/mock/controller_helper.php | 35 +++++++++++++++++++++ tests/unit/acp/move_module_test.php | 4 ++- tests/unit/functions/fetch_news_test.php | 6 ++-- tests/unit/includes/modules_helper_test.php | 6 +++- tests/unit/modules/calendar_test.php | 7 +++-- tests/unit/portal/fetch_posts_test.php | 6 ++-- 6 files changed, 56 insertions(+), 8 deletions(-) create mode 100644 tests/mock/controller_helper.php diff --git a/tests/mock/controller_helper.php b/tests/mock/controller_helper.php new file mode 100644 index 00000000..d76594a4 --- /dev/null +++ b/tests/mock/controller_helper.php @@ -0,0 +1,35 @@ +phpbb_root_path = $phpbb_root_path; + $this->php_ext = $php_ext; + } + + public function add_route($name, $url) + { + $this->routes[$name] = $url; + } + + public function route($route) + { + return append_sid("{$this->phpbb_root_path}app.{$this->php_ext}/{$this->routes[$route]}"); + } +} diff --git a/tests/unit/acp/move_module_test.php b/tests/unit/acp/move_module_test.php index f960375b..c4a33cbb 100644 --- a/tests/unit/acp/move_module_test.php +++ b/tests/unit/acp/move_module_test.php @@ -53,8 +53,10 @@ class phpbb_acp_move_module_test extends \board3\portal\tests\testframework\data new \board3\portal\modules\donation($config, $template, $user), )); $this->portal_helper = new \board3\portal\includes\helper($phpbb_container->get('board3.portal.module_collection')); + $controller_helper = new \board3\portal\tests\mock\controller_helper($phpbb_root_path, $phpEx); + $controller_helper->add_route('board3_portal_controller', 'portal'); $phpbb_container->set('board3.portal.helper', $this->portal_helper); - $phpbb_container->set('board3.portal.modules_helper', new \board3\portal\includes\modules_helper(new \phpbb\auth\auth(), $config, $request)); + $phpbb_container->set('board3.portal.modules_helper', new \board3\portal\includes\modules_helper(new \phpbb\auth\auth(), $config, $controller_helper, $request)); $phpbb_container->setParameter('board3.portal.modules.table', $table_prefix . 'portal_modules'); $phpbb_container->setParameter('board3.portal.config.table', $table_prefix . 'portal_config'); $this->portal_columns = new \board3\portal\portal\columns(); diff --git a/tests/unit/functions/fetch_news_test.php b/tests/unit/functions/fetch_news_test.php index 552299b0..c3eb8cd4 100644 --- a/tests/unit/functions/fetch_news_test.php +++ b/tests/unit/functions/fetch_news_test.php @@ -20,7 +20,7 @@ class phpbb_functions_fetch_news_test extends \board3\portal\tests\testframework { parent::setUp(); - global $auth, $cache, $config, $phpbb_container, $phpbb_dispatcher, $template, $user; + global $auth, $cache, $phpbb_container, $phpbb_dispatcher, $template, $user, $phpbb_root_path, $phpEx; $user = new \phpbb\user('\phpbb\datetime'); $user->data['user_id'] = 2; @@ -52,7 +52,9 @@ class phpbb_functions_fetch_news_test extends \board3\portal\tests\testframework $this->auth = $auth; $this->user = $user; $phpbb_container = new \phpbb_mock_container_builder(); - $this->modules_helper = new \board3\portal\includes\modules_helper($auth, $this->config, $request); + $controller_helper = new \board3\portal\tests\mock\controller_helper($phpbb_root_path, $phpEx); + $controller_helper->add_route('board3_portal_controller', 'portal'); + $this->modules_helper = new \board3\portal\includes\modules_helper($auth, $this->config, $controller_helper, $request); $phpbb_container->set('board3.portal.modules_helper', $this->modules_helper); $phpbb_container->set('board3.portal.fetch_posts', new \board3\portal\portal\fetch_posts($auth, $cache, $this->config, $this->db, $this->modules_helper, $user)); $template = $this->getMock('\phpbb\template', array('set_filenames', 'destroy_block_vars', 'assign_block_vars', 'assign_display')); diff --git a/tests/unit/includes/modules_helper_test.php b/tests/unit/includes/modules_helper_test.php index 03b05134..9578e1b2 100644 --- a/tests/unit/includes/modules_helper_test.php +++ b/tests/unit/includes/modules_helper_test.php @@ -23,13 +23,17 @@ class board3_includes_modules_helper_test extends \board3\portal\tests\testframe public function setUp() { + global $phpbb_root_path, $phpEx; + parent::setUp(); $auth = new \phpbb\auth\auth(); $this->config = new \phpbb\config\config(array()); $request = new \phpbb_mock_request(array('foo' => array('bar'))); + $controller_helper = new \board3\portal\tests\mock\controller_helper($phpbb_root_path, $phpEx); + $controller_helper->add_route('board3_portal_controller', 'portal'); - $this->modules_helper = new \board3\portal\includes\modules_helper($auth, $this->config, $request); + $this->modules_helper = new \board3\portal\includes\modules_helper($auth, $this->config, $controller_helper, $request); } public function data_get_disallowed_forums() diff --git a/tests/unit/modules/calendar_test.php b/tests/unit/modules/calendar_test.php index de96ab82..86cce026 100644 --- a/tests/unit/modules/calendar_test.php +++ b/tests/unit/modules/calendar_test.php @@ -28,7 +28,7 @@ class phpbb_unit_modules_calendar_test extends \board3\portal\tests\testframewor public function setUp() { parent::setUp(); - global $cache, $phpbb_root_path; + global $cache, $phpbb_root_path, $phpEx; $this->path_helper = new \phpbb\path_helper( new \phpbb\symfony_request( @@ -40,7 +40,10 @@ class phpbb_unit_modules_calendar_test extends \board3\portal\tests\testframewor 'php' ); self::$config = new \phpbb\config\config(array()); - $this->calendar = new \board3\portal\modules\calendar(self::$config, null, null, null, dirname(__FILE__) . '/../../../', 'php', null, $this->path_helper, null); + $controller_helper = new \board3\portal\tests\mock\controller_helper($phpbb_root_path, $phpEx); + $controller_helper->add_route('board3_portal_controller', 'portal'); + $modules_helper = new \board3\portal\includes\modules_helper(new \phpbb\auth\auth(), new \phpbb\config\config(array()), $controller_helper, new \phpbb_mock_request()); + $this->calendar = new \board3\portal\modules\calendar(self::$config, $modules_helper, null, null, null, dirname(__FILE__) . '/../../../', 'php', null, $this->path_helper, null); define('PORTAL_MODULES_TABLE', 'phpbb_portal_modules'); define('PORTAL_CONFIG_TABLE', 'phpbb_portal_config'); $cache = $this->getMock('\phpbb\cache\cache', array('destroy', 'sql_exists', 'get', 'put')); diff --git a/tests/unit/portal/fetch_posts_test.php b/tests/unit/portal/fetch_posts_test.php index 154057c7..6409b5ce 100644 --- a/tests/unit/portal/fetch_posts_test.php +++ b/tests/unit/portal/fetch_posts_test.php @@ -19,7 +19,7 @@ class phpbb_portal_fetch_posts_test extends \board3\portal\tests\testframework\d public function setUp() { - global $auth, $cache, $phpbb_dispatcher, $template, $user; + global $auth, $cache, $phpbb_dispatcher, $phpbb_root_path, $phpEx, $template, $user; parent::setUp(); @@ -50,7 +50,9 @@ class phpbb_portal_fetch_posts_test extends \board3\portal\tests\testframework\d // Pretend to allow downloads in forum 1 $auth->acl[1][0] = true; $this->auth = $auth; - $this->modules_helper = new \board3\portal\includes\modules_helper($auth, $this->config, new phpbb_mock_request()); + $controller_helper = new \board3\portal\tests\mock\controller_helper($phpbb_root_path, $phpEx); + $controller_helper->add_route('board3_portal_controller', 'portal'); + $this->modules_helper = new \board3\portal\includes\modules_helper($auth, $this->config, $controller_helper, new phpbb_mock_request()); $this->user = $user; $template = $this->getMock('\phpbb\template', array('set_filenames', 'destroy_block_vars', 'assign_block_vars', 'assign_display')); $this->fetch_posts = new \board3\portal\portal\fetch_posts($auth, $cache, $this->config, $this->db, $this->modules_helper, $user);