From ed54e3ef0c5308da15145a371436511992ef7653 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Sat, 4 Sep 2021 11:09:52 +0200 Subject: [PATCH] [ticket/715] Resolve issues with portal and tests on PHP 8.0 B3P-715 --- acp/portal_module.php | 6 ++-- controller/helper.php | 2 +- controller/main.php | 7 ++-- includes/functions.php | 17 +--------- modules/announcements.php | 4 +-- modules/calendar.php | 26 +++++++------- tests/functional/portal_acp_test.php | 12 +++---- tests/functional/portal_announcement_test.php | 4 ++- .../functional/portal_birthday_list_test.php | 2 +- tests/functional/portal_link_test.php | 6 ++-- tests/functional/portal_no_error_test.php | 10 +++--- tests/functional/portal_redirect_test.php | 8 ++--- .../portal_visit_registered_test.php | 10 +++--- tests/functional/portal_vote_poll_test.php | 6 ++-- tests/mock/{user.php => language.php} | 25 ++++++++------ tests/mock/template.php | 7 +++- tests/unit/acp/move_module_test.php | 31 +++++++++++------ tests/unit/controller/helper_test.php | 21 ++++++------ tests/unit/controller/main_test.php | 34 ++++++++++++++++--- tests/unit/event/listener_test.php | 5 +-- tests/unit/functions/check_file_src_test.php | 9 +++-- tests/unit/functions/fetch_news_test.php | 32 +++++++++++++---- tests/unit/includes/helper_test.php | 4 +-- tests/unit/modules/birthday_list_test.php | 5 ++- tests/unit/modules/calendar_test.php | 20 +++++++---- tests/unit/modules/clock_test.php | 2 +- tests/unit/modules/welcome_test.php | 6 ++-- tests/unit/portal/fetch_posts_test.php | 15 ++++++-- .../modules_manager_confirm_box_test.php | 25 +++++++++----- tests/unit/portal/modules_manager_test.php | 15 ++++---- 30 files changed, 233 insertions(+), 143 deletions(-) rename tests/mock/{user.php => language.php} (65%) diff --git a/acp/portal_module.php b/acp/portal_module.php index 3aa4c7ef..e2b0e97b 100644 --- a/acp/portal_module.php +++ b/acp/portal_module.php @@ -12,7 +12,7 @@ namespace board3\portal\acp; class portal_module { public $u_action; - public $new_config = array(); + public $new_config = []; /** @var \board3\portal\modules\module_interface */ protected $c_class; @@ -148,7 +148,7 @@ class portal_module $groups_ary = explode(',', $module_data['module_group_ids']); // get group info from database and assign the block vars - $sql = 'SELECT group_id, group_name + $sql = 'SELECT group_id, group_name FROM ' . GROUPS_TABLE . ' ORDER BY group_id ASC'; $result = $this->db->sql_query($sql); @@ -318,7 +318,7 @@ class portal_module $this->page_title = $display_vars['title']; $this->template->assign_vars(array( - 'L_TITLE' => $this->user->lang[$display_vars['title']], + 'L_TITLE' => $this->user->lang($display_vars['title']), 'L_TITLE_EXPLAIN' => (isset($this->user->lang[$display_vars['title'] . '_EXP'])) ? $this->user->lang[$display_vars['title'] . '_EXP'] : '', 'S_ERROR' => (sizeof($error)) ? true : false, diff --git a/controller/helper.php b/controller/helper.php index bcd72257..2a0f8694 100644 --- a/controller/helper.php +++ b/controller/helper.php @@ -266,7 +266,7 @@ class helper $this->check_permission(); // Load language file - $this->user->add_lang_ext('board3/portal', 'portal'); + $this->language->add_lang('portal', 'board3/portal'); // Obtain portal config obtain_portal_config(); diff --git a/controller/main.php b/controller/main.php index 88d7e459..7727891d 100644 --- a/controller/main.php +++ b/controller/main.php @@ -117,8 +117,11 @@ class main $this->includes_path = $phpbb_root_path . 'ext/board3/portal/includes/'; $this->root_path = $phpbb_root_path . 'ext/board3/portal/'; $portal_root_path = $this->root_path; - define('PORTAL_MODULES_TABLE', $modules_table); - define('PORTAL_CONFIG_TABLE', $config_table); + if (!defined('PORTAL_MODULES_TABLE')) + { + define('PORTAL_MODULES_TABLE', $modules_table); + define('PORTAL_CONFIG_TABLE', $config_table); + } if (!function_exists('obtain_portal_config')) { diff --git a/includes/functions.php b/includes/functions.php index dd75bed3..12f6b875 100644 --- a/includes/functions.php +++ b/includes/functions.php @@ -93,21 +93,6 @@ function obtain_portal_modules() return $portal_modules; } -/** -* Fetch post for news & announce -* -* @deprecated 2.1.0-b1 (To be removed: 2.2.0) -*/ -function phpbb_fetch_posts($module_id, $forum_from, $permissions, $number_of_posts, $text_length, $time, $type, $start = 0, $invert = false) -{ - global $phpbb_container; - - $fetch_posts = $phpbb_container->get('board3.portal.fetch_posts'); - $fetch_posts->set_module_id($module_id); - - return $fetch_posts->get_posts($forum_from, $permissions, $number_of_posts, $text_length, $time, $type, $start, $invert); -} - /** * Censor title, return short title * @@ -390,7 +375,7 @@ function check_file_src($value, $key, $module_id, $force_error = true) // We check if the chosen file is present in the styles/all/ folder if (!file_exists($portal_root_path . 'styles/all/theme/images/portal/' . $value)) { - $error .= $user->lang['B3P_FILE_NOT_FOUND'] . ': styles/all/theme/images/portal/' . $value . '
'; + $error .= $user->lang('B3P_FILE_NOT_FOUND') . ': styles/all/theme/images/portal/' . $value . '
'; } if (!empty($error)) diff --git a/modules/announcements.php b/modules/announcements.php index 5d3a10a8..573aba16 100644 --- a/modules/announcements.php +++ b/modules/announcements.php @@ -131,7 +131,7 @@ class announcements extends module_base $this->config['board3_announcements_permissions_' . $module_id], $this->config['board3_number_of_announcements_' . $module_id], $portal_announcement_length, - $this->config['board3_announcements_day_' . $module_id], + (int) $this->config['board3_announcements_day_' . $module_id], 'announcements', $start, (bool) $this->config['board3_announcements_forum_exclude_' . $module_id] @@ -174,7 +174,7 @@ class announcements extends module_base $forum_from = $this->config['board3_global_announcements_forum_' . $module_id]; $forum_from = (strpos($forum_from, ',') !== false) ? explode(',', $forum_from) : (($forum_from != '') ? array($forum_from) : array()); - $time = ($this->config['board3_announcements_day_' . $module_id] == 0) ? 0 : $this->config['board3_announcements_day_' . $module_id]; + $time = ($this->config['board3_announcements_day_' . $module_id] == 0) ? 0 : (int) $this->config['board3_announcements_day_' . $module_id]; $post_time = ($time == 0) ? '' : 'AND topic_time > ' . (time() - $time * 86400); $str_where = ''; diff --git a/modules/calendar.php b/modules/calendar.php index 60e5f6d4..973e3e1c 100644 --- a/modules/calendar.php +++ b/modules/calendar.php @@ -188,19 +188,19 @@ class calendar extends module_base // output our general calendar bits $down = $this->mini_cal_month - 1; $up = $this->mini_cal_month + 1; - $prev_month = ''; - $next_month = ''; + $prev_month = ''; + $next_month = ''; $this->template->assign_block_vars('minical', array( 'S_SUNDAY_FIRST' => ($this->config['board3_sunday_first_' . $module_id]) ? true : false, - 'L_MINI_CAL_MONTH' => (($this->config['board3_long_month_' . $module_id]) ? $this->user->lang['mini_cal']['long_month'][$this->day[0][1]] : $this->user->lang['mini_cal']['month'][$this->day[0][1]]) . " " . $this->day[0][2], - 'L_MINI_CAL_SUN' => '' . $this->user->lang['mini_cal']['day'][1] . '', - 'L_MINI_CAL_MON' => $this->user->lang['mini_cal']['day'][2], - 'L_MINI_CAL_TUE' => $this->user->lang['mini_cal']['day'][3], - 'L_MINI_CAL_WED' => $this->user->lang['mini_cal']['day'][4], - 'L_MINI_CAL_THU' => $this->user->lang['mini_cal']['day'][5], - 'L_MINI_CAL_FRI' => $this->user->lang['mini_cal']['day'][6], - 'L_MINI_CAL_SAT' => $this->user->lang['mini_cal']['day'][7], + 'L_MINI_CAL_MONTH' => (($this->config['board3_long_month_' . $module_id]) ? $this->user->lang(['mini_cal', 'long_month'], $this->day[0][1]) : $this->user->lang(['mini_cal', 'month'], $this->day[0][1])) . " " . $this->day[0][2], + 'L_MINI_CAL_SUN' => '' . $this->user->lang(['mini_cal', 'day'], 1) . '', + 'L_MINI_CAL_MON' => $this->user->lang(['mini_cal', 'day'], 2), + 'L_MINI_CAL_TUE' => $this->user->lang(['mini_cal', 'day'], 3), + 'L_MINI_CAL_WED' => $this->user->lang(['mini_cal', 'day'], 4), + 'L_MINI_CAL_THU' => $this->user->lang(['mini_cal', 'day'], 5), + 'L_MINI_CAL_FRI' => $this->user->lang(['mini_cal', 'day'], 6), + 'L_MINI_CAL_SAT' => $this->user->lang(['mini_cal', 'day'], 7), 'U_PREV_MONTH' => $prev_month, 'U_NEXT_MONTH' => $next_month, 'S_DISPLAY_EVENTS' => ($this->config['board3_display_events_' . $module_id]) ? true : false, @@ -488,13 +488,13 @@ class calendar extends module_base // Check for errors if (!$event_title) { - trigger_error($this->user->lang['NO_EVENT_TITLE'] . adm_back_link($u_action), E_USER_WARNING); + trigger_error($this->user->lang('NO_EVENT_TITLE') . adm_back_link($u_action), E_USER_WARNING); } // overwrite already existing events and make sure we don't try to save an event outside of the normal array size of $events if (isset($link_id) && $link_id < sizeof($events)) { - $message = $this->user->lang['EVENT_UPDATED']; + $message = $this->user->lang('EVENT_UPDATED'); $events[$link_id] = array( 'title' => $event_title, @@ -510,7 +510,7 @@ class calendar extends module_base } else { - $message = $this->user->lang['EVENT_ADDED']; + $message = $this->user->lang('EVENT_ADDED'); $events[] = array( 'title' => $event_title, diff --git a/tests/functional/portal_acp_test.php b/tests/functional/portal_acp_test.php index 7dd4eaad..597f22b8 100644 --- a/tests/functional/portal_acp_test.php +++ b/tests/functional/portal_acp_test.php @@ -63,10 +63,10 @@ class phpbb_functional_portal_acp_test extends \board3\portal\tests\testframewor $crawler = self::request('GET', $module_link); preg_match('/module_classname=(?:([a-z0-9\\\_]+))/', $module_link, $module_name); $module_name = $module_name[1]; - $this->assertContains('Are you sure you wish to delete the module', $crawler->text()); + $this->assertStringContainsString('Are you sure you wish to delete the module', $crawler->text()); $form = $crawler->selectButton('confirm')->form(); $crawler = self::submit($form); - $this->assertContains('The module was removed successfully.', $crawler->text()); + $this->assertStringContainsString('The module was removed successfully.', $crawler->text()); // Add it back $crawler = self::request('GET', 'adm/index.php?i=\board3\portal\acp\portal_module&mode=modules&add[center]=true&module_column=2&sid=' . $this->sid); @@ -85,7 +85,7 @@ class phpbb_functional_portal_acp_test extends \board3\portal\tests\testframewor // Take a look at the logs $crawler = self::request('GET', 'adm/index.php?i=acp_logs&mode=admin&sid=' . $this->sid); - $this->assertContains(strip_tags(html_entity_decode($this->lang('LOG_PORTAL_CONFIG', $this->lang('ACP_PORTAL_GENERAL_INFO')), ENT_COMPAT, 'UTF-8')), $crawler->text()); + $this->assertStringContainsString(strip_tags(html_entity_decode($this->lang('LOG_PORTAL_CONFIG', $this->lang('ACP_PORTAL_GENERAL_INFO')), ENT_COMPAT, 'UTF-8')), $crawler->text()); } public function test_portal_permissions() @@ -105,9 +105,9 @@ class phpbb_functional_portal_acp_test extends \board3\portal\tests\testframewor $form->setValues(array('link_title' => 'foobar')); $crawler = self::submit($form); $crawler = self::request('GET', 'adm/index.php?i=\board3\portal\acp\portal_module&mode=config&module_id=1&sid=' . $this->sid); - $this->assertContains('foobar', $crawler->text()); + $this->assertStringContainsString('foobar', $crawler->text()); $crawler = self::request('GET', 'app.php/portal?sid=' . $this->sid); - $this->assertContains('foobar', $crawler->text()); + $this->assertStringContainsString('foobar', $crawler->text()); } public function data_add_second_module() @@ -131,6 +131,6 @@ class phpbb_functional_portal_acp_test extends \board3\portal\tests\testframewor $form = $crawler->selectButton('submit')->form(); $form['module_classname']->disableValidation()->select($module_class); $crawler = self::submit($form); - $this->assertContains($expected_message, $crawler->text()); + $this->assertStringContainsString($expected_message, $crawler->text()); } } diff --git a/tests/functional/portal_announcement_test.php b/tests/functional/portal_announcement_test.php index 05f05be1..6edfb2d2 100644 --- a/tests/functional/portal_announcement_test.php +++ b/tests/functional/portal_announcement_test.php @@ -60,6 +60,8 @@ class phpbb_functional_portal_announcement_test extends \board3\portal\tests\tes public function test_shortened_message() { + $this->purge_cache(); + // Create topic as announcement $data = $this->create_topic(2, 'Portal-announce-global', str_repeat('This is a global announcement for the portal', 6), array( 'topic_type' => POST_GLOBAL, @@ -69,7 +71,7 @@ class phpbb_functional_portal_announcement_test extends \board3\portal\tests\tes { // no errors should appear on portal $crawler = self::request('GET', 'app.php/portal'); - $this->assertContains('This is a global announc ...', $crawler->text()); + $this->assertStringContainsString('This is a global announc ...', $crawler->text()); } } } diff --git a/tests/functional/portal_birthday_list_test.php b/tests/functional/portal_birthday_list_test.php index fc8010fa..fb5d46b0 100644 --- a/tests/functional/portal_birthday_list_test.php +++ b/tests/functional/portal_birthday_list_test.php @@ -47,6 +47,6 @@ class phpbb_functional_portal_birthday_list_test extends \board3\portal\tests\te public function test_after_announce() { $crawler = self::request('GET', 'app.php/portal'); - $this->assertContains(date('d M', time() + 86400*2), $crawler->html()); + $this->assertStringContainsString(date('d M', time() + 86400*2), $crawler->html()); } } diff --git a/tests/functional/portal_link_test.php b/tests/functional/portal_link_test.php index dde9fe38..2b860cd8 100644 --- a/tests/functional/portal_link_test.php +++ b/tests/functional/portal_link_test.php @@ -23,7 +23,7 @@ class phpbb_functional_portal_link_test extends \board3\portal\tests\testframewo public function test_portal_link() { $crawler = self::request('GET', 'index.php?sid=' . $this->sid); - $this->assertContains('Portal', $crawler->text()); + $this->assertStringContainsString('Portal', $crawler->text()); } public function test_disabled_portal_link() @@ -46,7 +46,7 @@ class phpbb_functional_portal_link_test extends \board3\portal\tests\testframewo }); foreach ($vals as $val) { - $this->assertNotContains('Portal', $val); + $this->assertStringNotContainsString('Portal', $val); } // Try to access portal directly @@ -56,7 +56,7 @@ class phpbb_functional_portal_link_test extends \board3\portal\tests\testframewo }); foreach ($vals as $val) { - $this->assertNotContains('Portal', $val); + $this->assertStringNotContainsString('Portal', $val); } // Enable portal again diff --git a/tests/functional/portal_no_error_test.php b/tests/functional/portal_no_error_test.php index 4a76937c..6c2e8543 100644 --- a/tests/functional/portal_no_error_test.php +++ b/tests/functional/portal_no_error_test.php @@ -42,7 +42,7 @@ class phpbb_functional_portal_no_error_test extends \board3\portal\tests\testfra public function test_portal_all_pages($style_id) { $crawler = self::request('GET', 'index.php?style=' . $style_id); - $this->assertNotContains('Menu', $crawler->text()); + $this->assertStringNotContainsString('Menu', $crawler->text()); $crawler = self::request('GET', 'adm/index.php?i=-board3-portal-acp-portal_module&mode=config&sid=' . $this->sid); @@ -54,7 +54,7 @@ class phpbb_functional_portal_no_error_test extends \board3\portal\tests\testfra $this->assertContainsLang('CONFIG_UPDATED', $crawler->text()); $crawler = self::request('GET', 'index.php?style=' . $style_id); - $this->assertContains('Menu', $crawler->text()); + $this->assertStringContainsString('Menu', $crawler->text()); $crawler = self::request('GET', 'adm/index.php?i=-board3-portal-acp-portal_module&mode=config&sid=' . $this->sid); @@ -66,8 +66,8 @@ class phpbb_functional_portal_no_error_test extends \board3\portal\tests\testfra $this->assertContainsLang('CONFIG_UPDATED', $crawler->text()); $crawler = self::request('GET', 'index.php?style=' . $style_id); - $this->assertNotContains('Board Style', $crawler->text()); - $this->assertContains('User menu', $crawler->text()); + $this->assertStringNotContainsString('Board Style', $crawler->text()); + $this->assertStringContainsString('User menu', $crawler->text()); $crawler = self::request('GET', 'adm/index.php?i=-board3-portal-acp-portal_module&mode=config&sid=' . $this->sid); @@ -79,6 +79,6 @@ class phpbb_functional_portal_no_error_test extends \board3\portal\tests\testfra $this->assertContainsLang('CONFIG_UPDATED', $crawler->text()); $crawler = self::request('GET', 'index.php?style=' . $style_id); - $this->assertNotContains('Menu', $crawler->text()); + $this->assertStringNotContainsString('Menu', $crawler->text()); } } diff --git a/tests/functional/portal_redirect_test.php b/tests/functional/portal_redirect_test.php index bcc88e93..dbad43a8 100644 --- a/tests/functional/portal_redirect_test.php +++ b/tests/functional/portal_redirect_test.php @@ -29,13 +29,13 @@ class phpbb_functional_portal_redirect_test extends \board3\portal\tests\testfra } else { - $mod_rewrite = (getenv('HTTP_MOD_REWRITE')=='On') ? true : false; + $mod_rewrite = getenv('HTTP_MOD_REWRITE') == 'On'; } if ($mod_rewrite) { $crawler = self::request('GET', ''); - $this->assertContains('Board3 Portal', $crawler->text()); + $this->assertStringContainsString('Board3 Portal', $crawler->text()); } } @@ -44,7 +44,7 @@ class phpbb_functional_portal_redirect_test extends \board3\portal\tests\testfra // Make sure we are logged out $this->logout(); - $crawler = self::request('GET', 'app.php/portal?sid=' . $this->sid); + $crawler = self::request('GET', 'app.php/portal'); $form = $crawler->selectButton('Login')->form(); $form->setValues(array( 'username' => 'admin', @@ -54,6 +54,6 @@ class phpbb_functional_portal_redirect_test extends \board3\portal\tests\testfra $crawler = self::submit($form); // Should be redirected to portal and logged in - $this->assertContains('Site Admin', $crawler->text()); + $this->assertStringContainsString('Site Admin', $crawler->text()); } } diff --git a/tests/functional/portal_visit_registered_test.php b/tests/functional/portal_visit_registered_test.php index ed416f93..ffee94c6 100644 --- a/tests/functional/portal_visit_registered_test.php +++ b/tests/functional/portal_visit_registered_test.php @@ -103,8 +103,8 @@ class phpbb_functional_portal_visit_registered_test extends \board3\portal\tests $crawler = self::request('GET', 'app.php/portal'); $legend = $crawler->filter('dd.portal-responsive-show p em')->text(); - $this->assertContains('Administrators', $legend); - $this->assertContains('Global moderators', $legend); + $this->assertStringContainsString('Administrators', $legend); + $this->assertStringContainsString('Global moderators', $legend); } public function test_setup_hidden_forum() @@ -121,7 +121,7 @@ class phpbb_functional_portal_visit_registered_test extends \board3\portal\tests $form = $crawler->selectButton('Submit')->form(); $form['forum_perm_from']->select(2); $crawler = self::submit($form); - $this->assertContains('Forum created successfully', $crawler->text()); + $this->assertStringContainsString('Forum created successfully', $crawler->text()); // Hide forum using permissions from registered users $crawler = self::request('GET', 'adm/index.php?i=acp_permissions&mode=setting_group_local&sid=' . $this->sid); @@ -180,8 +180,8 @@ class phpbb_functional_portal_visit_registered_test extends \board3\portal\tests $this->logout(); $this->login('standard-user'); $crawler = self::request('GET', 'index.php'); - $this->assertNotContains('Hidden forum', $crawler->text()); + $this->assertStringNotContainsString('Hidden forum', $crawler->text()); $crawler = self::request('GET', 'app.php/portal'); - $this->assertNotContains('Hidden topic', $crawler->text()); + $this->assertStringNotContainsString('Hidden topic', $crawler->text()); } } diff --git a/tests/functional/portal_vote_poll_test.php b/tests/functional/portal_vote_poll_test.php index 43a8b5ed..8bd195ac 100644 --- a/tests/functional/portal_vote_poll_test.php +++ b/tests/functional/portal_vote_poll_test.php @@ -33,10 +33,10 @@ class phpbb_functional_portal_vote_poll_test extends \board3\portal\tests\testfr $crawler = self::request('GET', 'app.php/portal'); $form = $crawler->selectButton('Submit vote')->form(); $form->setValues(array('vote_id' => array(1))); - $crawler = self::submit($form); + self::submit($form); // no errors should appear on portal - $crawler = self::request('GET', 'app.php/portal'); + self::request('GET', 'app.php/portal'); } } @@ -46,6 +46,6 @@ class phpbb_functional_portal_vote_poll_test extends \board3\portal\tests\testfr public function test_after_poll() { $this->logout(); - $crawler = self::request('GET', 'app.php/portal'); + self::request('GET', 'app.php/portal'); } } diff --git a/tests/mock/user.php b/tests/mock/language.php similarity index 65% rename from tests/mock/user.php rename to tests/mock/language.php index d123b5c1..63cd3033 100644 --- a/tests/mock/user.php +++ b/tests/mock/language.php @@ -9,10 +9,8 @@ namespace board3\portal\tests\mock; -class user extends \phpbb\user +class language extends \phpbb\language\language { - public $lang = array(); - public function set($data) { foreach ($data as $key => $column) @@ -21,6 +19,18 @@ class user extends \phpbb\user } } + public function add_lang($component, $extension_name = null) + { + if (!$extension_name !== null) + { + $this->add_lang_ext($extension_name, $component); + } + else + { + parent::add_lang($component, $extension_name); + } + } + public function add_lang_ext($ext_name, $lang_set, $use_db = false, $use_help = false) { if ($ext_name != 'board3/portal') @@ -39,7 +49,8 @@ class user extends \phpbb\user if (file_exists(dirname(__FILE__) . '/../../language/en/' . $lang_set . '.php')) { - include_once(dirname(__FILE__) . '/../../language/en/' . $lang_set . '.php'); + $foo = dirname(__FILE__) . '/../../language/en/' . $lang_set . '.php'; + include(dirname(__FILE__) . '/../../language/en/' . $lang_set . '.php'); if (isset($lang)) { @@ -47,10 +58,4 @@ class user extends \phpbb\user } } } - - public function lang() - { - $args = func_get_args(); - return $this->lang[$args[0]]; - } } diff --git a/tests/mock/template.php b/tests/mock/template.php index 30e7bb5a..16860e37 100644 --- a/tests/mock/template.php +++ b/tests/mock/template.php @@ -64,6 +64,11 @@ class template $this->test_case->assertSame($expected, $this->data[$row]); } + public function assert_not_exist($row) + { + $this->test_case->assertArrayNotHasKey($row, $this->data); + } + public function delete_var($key) { unset($this->data[$key]); @@ -71,6 +76,6 @@ class template public function get_row($row) { - return $this->data[$row]; + return $this->data[$row] ?? null; } } diff --git a/tests/unit/acp/move_module_test.php b/tests/unit/acp/move_module_test.php index 590ccee4..f14d051a 100644 --- a/tests/unit/acp/move_module_test.php +++ b/tests/unit/acp/move_module_test.php @@ -40,12 +40,23 @@ class phpbb_acp_move_module_test extends \board3\portal\tests\testframework\data public function setUp(): void { parent::setUp(); - global $db, $cache, $phpbb_root_path, $phpEx, $user, $phpbb_container, $request, $template, $table_prefix; + global $config, $db, $cache, $phpbb_root_path, $phpEx, $user, $phpbb_container, $request, $template, $table_prefix; global $phpbb_dispatcher; $this->language_file_loader = new \phpbb\language\language_file_loader($phpbb_root_path, 'php'); - $this->language = new \phpbb\language\language($this->language_file_loader); - $user = new \board3\portal\tests\mock\user($this->language, '\phpbb\datetime'); + $this->language = new \board3\portal\tests\mock\language($this->language_file_loader); + $user = new \phpbb\user($this->language, '\phpbb\datetime'); + $user->data['user_id'] = 2; + $user->data['user_form_salt'] = 'foobar'; + $user->lang['ACP_PORTAL_GENERAL_TITLE'] = 'ACP_PORTAL_GENERAL_TITLE'; + $user->lang['YES'] = 'YES'; + $user->lang['NO'] = 'NO'; + $this->language->add_lang_ext('board3/portal', 'portal_acp'); + $this->language->set([ + 'ACP_PORTAL_GENERAL_TITLE' => 'ACP_PORTAL_GENERAL_TITLE', + 'PORTAL_SHOW_ALL_LEFT' => 'PORTAL_SHOW_ALL_LEFT', + 'PORTAL_SHOW_ALL_RIGHT' => 'PORTAL_SHOW_ALL_RIGHT', + ]); $template = new \board3\portal\tests\mock\template($this); $this->template = $template; @@ -53,7 +64,7 @@ class phpbb_acp_move_module_test extends \board3\portal\tests\testframework\data $this->request = $request; $phpbb_container = new \phpbb_mock_container_builder(); // Mock module service collection - $config = new \phpbb\config\config(array()); + $config = new \phpbb\config\config([]); $auth = $this->getMockBuilder('\phpbb\auth\auth') ->setMethods(['acl_get']) ->getMock(); @@ -104,7 +115,7 @@ class phpbb_acp_move_module_test extends \board3\portal\tests\testframework\data ->with($this->anything()) ->will($this->returnArgument(2)); $db = $this->db; - $user->set(array( + $this->language->set(array( 'UNABLE_TO_MOVE' => 'UNABLE_TO_MOVE', 'UNABLE_TO_MOVE_ROW' => 'UNABLE_TO_MOVE_ROW', )); @@ -224,7 +235,7 @@ class phpbb_acp_move_module_test extends \board3\portal\tests\testframework\data $this->modules_manager->move_module_vertical(2, \board3\portal\portal\modules\database_handler::MOVE_DIRECTION_UP); $this->assertTrue(self::$redirected); - $this->setExpectedTriggerError(E_USER_NOTICE, 'UNABLE_TO_MOVE_ROW'); + $this->setExpectedTriggerError(E_USER_NOTICE, $this->language->lang('UNABLE_TO_MOVE_ROW')); self::$redirected = false; $this->modules_manager->move_module_vertical(2, \board3\portal\portal\modules\database_handler::MOVE_DIRECTION_UP); $this->assertFalse(self::$redirected); @@ -236,7 +247,7 @@ class phpbb_acp_move_module_test extends \board3\portal\tests\testframework\data $this->modules_manager->move_module_vertical(3, \board3\portal\portal\modules\database_handler::MOVE_DIRECTION_DOWN); $this->assertTrue(self::$redirected); - $this->setExpectedTriggerError(E_USER_NOTICE, 'UNABLE_TO_MOVE_ROW'); + $this->setExpectedTriggerError(E_USER_NOTICE, $this->language->lang('UNABLE_TO_MOVE_ROW')); self::$redirected = false; $this->modules_manager->move_module_vertical(3, \board3\portal\portal\modules\database_handler::MOVE_DIRECTION_DOWN); $this->assertFalse(self::$redirected); @@ -258,7 +269,7 @@ class phpbb_acp_move_module_test extends \board3\portal\tests\testframework\data { if ($error) { - $this->setExpectedTriggerError(E_USER_NOTICE, $error); + $this->setExpectedTriggerError(E_USER_NOTICE, $this->language->lang($error)); } else { @@ -311,7 +322,7 @@ class phpbb_acp_move_module_test extends \board3\portal\tests\testframework\data $column_start++; $this->update_portal_modules(); } - $this->setExpectedTriggerError(E_USER_NOTICE, 'UNABLE_TO_MOVE'); + $this->setExpectedTriggerError(E_USER_NOTICE, $this->language->lang('UNABLE_TO_MOVE')); $this->modules_manager->move_module_horizontal($module_id, \board3\portal\portal\modules\database_handler::MOVE_DIRECTION_RIGHT); } @@ -364,7 +375,7 @@ class phpbb_acp_move_module_test extends \board3\portal\tests\testframework\data $this->update_portal_modules(); $column_start--; } - $this->setExpectedTriggerError(E_USER_NOTICE, 'UNABLE_TO_MOVE'); + $this->setExpectedTriggerError(E_USER_NOTICE, $this->language->lang('UNABLE_TO_MOVE')); $this->modules_manager->move_module_horizontal($module_id, \board3\portal\portal\modules\database_handler::MOVE_DIRECTION_LEFT); } diff --git a/tests/unit/controller/helper_test.php b/tests/unit/controller/helper_test.php index 99fcbd71..15221289 100644 --- a/tests/unit/controller/helper_test.php +++ b/tests/unit/controller/helper_test.php @@ -40,7 +40,7 @@ class helper_test extends \board3\portal\tests\testframework\test_case )); $this->template = new \board3\portal\tests\mock\template($this); $this->language_file_loader = new \phpbb\language\language_file_loader($phpbb_root_path, 'php'); - $this->language = new \phpbb\language\language($this->language_file_loader); + $this->language = new \board3\portal\tests\mock\language($this->language_file_loader); $this->user = new \phpbb\user($this->language, '\phpbb\datetime'); $this->user->data['group_id'] = 2; $this->phpbb_root_path = dirname(__FILE__) . '/../../../../../../'; @@ -48,9 +48,7 @@ class helper_test extends \board3\portal\tests\testframework\test_case $this->language_file_loader->set_extension_manager($phpbb_extension_manager); $this->php_ext = 'php'; $this->portal_columns = new \board3\portal\portal\columns(); - $this->language_file_loader = new \phpbb\language\language_file_loader($phpbb_root_path, 'php'); - $this->language = new \phpbb\language\language($this->language_file_loader); - $user = new \board3\portal\tests\mock\user($this->language, '\phpbb\datetime'); + $user = $this->user; $this->modules = array( '\board3\portal\modules\link_us' => new \board3\portal\modules\link_us($this->config, new \board3\portal\tests\mock\template($this), $user), ); @@ -149,11 +147,9 @@ class helper_test extends \board3\portal\tests\testframework\test_case { global $phpbb_root_path; - $this->assertNull($this->controller_helper->load_module_language($this->modules['\board3\portal\modules\link_us'])); + $this->controller_helper->load_module_language($this->modules['\board3\portal\modules\link_us']); $this->assertFalse(isset($this->user->lang['PORTAL_LEADERS_EXT'])); - $this->language_file_loader = new \phpbb\language\language_file_loader($phpbb_root_path, 'php'); - $this->language = new \phpbb\language\language($this->language_file_loader); - $user = new \board3\portal\tests\mock\user($this->language, '\phpbb\datetime'); + $user = new \phpbb\user($this->language, '\phpbb\datetime'); $module = $this->getMockBuilder('\board3\portal\modules\link_us') ->setMethods(['get_language']) ->setConstructorArgs([$this->config, new \board3\portal\tests\mock\template($this), $user]) @@ -164,8 +160,8 @@ class helper_test extends \board3\portal\tests\testframework\test_case 'vendor' => 'board3/portal', 'file' => 'modules/portal_leaders_module', )); - $this->assertNull($this->controller_helper->load_module_language($module)); - $this->assertNotEmpty($this->user->lang('ACP_PORTAL_LEADERS')); + $this->controller_helper->load_module_language($module); + $this->assertNotEmpty($this->language->lang('ACP_PORTAL_LEADERS')); } public function data_assign_module_vars() @@ -176,16 +172,21 @@ class helper_test extends \board3\portal\tests\testframework\test_case 'module_id' => 1, 'module_image_width' => 16, 'module_image_height' => 16, + 'module_image_src' => '', + 'module_name' => 'foo', ), array( 'template' => 'foobar.html', 'title' => 'foo', 'code' => 'bar', + 'image_src' => '', )), array(array( 'module_column' => 1, 'module_id' => 1, 'module_image_width' => 16, 'module_image_height' => 16, + 'module_image_src' => '', + 'module_name' => 'foo', ), 'foobar.html'), ); } diff --git a/tests/unit/controller/main_test.php b/tests/unit/controller/main_test.php index 98716c9a..775a4e7c 100644 --- a/tests/unit/controller/main_test.php +++ b/tests/unit/controller/main_test.php @@ -44,8 +44,12 @@ class main_test extends \board3\portal\tests\testframework\database_test_case $cache = new \phpbb\cache\driver\dummy(); $this->language_file_loader = new \phpbb\language\language_file_loader($phpbb_root_path, 'php'); - $this->language = new \phpbb\language\language($this->language_file_loader); - $user = new \board3\portal\tests\mock\user($this->language, '\phpbb\datetime'); + $this->language = new \board3\portal\tests\mock\language($this->language_file_loader); + $this->language->set([ + 'S_PORTAL_ALL' => 'S_PORTAL_ALL', + ]); + $user = new \phpbb\user($this->language, '\phpbb\datetime'); + $user->style['style_path'] = 'prosilver'; $config_table = $table_prefix . 'portal_config'; $modules_table = $table_prefix . 'portal_modules'; @@ -103,15 +107,35 @@ class main_test extends \board3\portal\tests\testframework\database_test_case $this->template->assert_same(true, 'S_PORTAL_ALL'); $this->template->delete_var('S_PORTAL_ALL'); $this->assertNull($this->controller_main->handle(array('left' => 1))); - $this->template->assert_same(null, 'S_PORTAL_ALL'); + $this->template->assert_not_exist('S_PORTAL_ALL'); } public function test_is_enabled_side_column() { - $this->assertFalse($this->controller_main->get_module_template(array(), new \board3\portal\modules\clock($this->config, $this->template))); + $this->assertFalse($this->controller_main->get_module_template( + [ + 'module_column' => 1, + 'module_id' => 1, + 'module_image_width' => 16, + 'module_image_height' => 16, + 'module_image_src' => '', + 'module_name' => 'foo', + ], + new \board3\portal\modules\clock($this->config, $this->template) + )); $this->assertNull($this->controller_main->handle(array('left' => 1))); $this->template->assert_same(true, 'S_PORTAL_ALL'); $this->config['board3_left_column'] = false; - $this->assertSame('clock_side.html', $this->controller_main->get_module_template(array('module_column' => 1), new \board3\portal\modules\clock($this->config, $this->template))); + $this->assertSame('clock_side.html', $this->controller_main->get_module_template( + [ + 'module_column' => 1, + 'module_id' => 1, + 'module_image_width' => 16, + 'module_image_height' => 16, + 'module_image_src' => '', + 'module_name' => 'foo', + ], + new \board3\portal\modules\clock($this->config, $this->template) + )); } } diff --git a/tests/unit/event/listener_test.php b/tests/unit/event/listener_test.php index a0dc3fc9..ad8225d1 100644 --- a/tests/unit/event/listener_test.php +++ b/tests/unit/event/listener_test.php @@ -122,8 +122,8 @@ class listener_test extends \phpbb_template_template_test_case ), new \phpbb\filesystem\filesystem(), new \phpbb_mock_request(), - $this->phpbb_root_path, - $this->php_ext + $phpbb_root_path, + $phpEx ); $this->controller = $this->getMockBuilder('\board3\portal\controller\main') @@ -212,6 +212,7 @@ class listener_test extends \phpbb_template_template_test_case $this->phpbb_dispatcher->addListener('core.page_header', array($this->listener, 'add_portal_link')); $this->controller_helper->set_current_url(''); + $vars = []; $result = $this->phpbb_dispatcher->trigger_event('core.page_header', compact($vars)); $this->assertEmpty($result); diff --git a/tests/unit/functions/check_file_src_test.php b/tests/unit/functions/check_file_src_test.php index 607b4a63..b7ca1ef8 100644 --- a/tests/unit/functions/check_file_src_test.php +++ b/tests/unit/functions/check_file_src_test.php @@ -19,7 +19,12 @@ class phpbb_functions_check_file_src_test extends \board3\portal\tests\testframe parent::setUp(); global $user; - $user = new phpbb_mock_user(); + $language_file_loader = new \phpbb\language\language_file_loader($phpbb_root_path, 'php'); + $language = new \board3\portal\tests\mock\language($language_file_loader); + $language->set([ + 'B3P_FILE_NOT_FOUND' => 'B3P_FILE_NOT_FOUND', + ]); + $user = new \phpbb\user($language, '\phpbb\datetime'); $portal_root_path = $phpbb_root_path . 'ext/board3/portal/'; } @@ -32,7 +37,7 @@ class phpbb_functions_check_file_src_test extends \board3\portal\tests\testframe public function test_check_file_src() { $this->assertFalse(check_file_src('portal_attach.png', '', 15, false)); - $this->assertEquals(': styles/all/theme/images/portal/portal_foobar.png
', check_file_src('portal_foobar.png', '', 15, false)); + $this->assertEquals('B3P_FILE_NOT_FOUND: styles/all/theme/images/portal/portal_foobar.png
', check_file_src('portal_foobar.png', '', 15, false)); } public function test_check_file_src_error() diff --git a/tests/unit/functions/fetch_news_test.php b/tests/unit/functions/fetch_news_test.php index 52dc1cef..03dda888 100644 --- a/tests/unit/functions/fetch_news_test.php +++ b/tests/unit/functions/fetch_news_test.php @@ -19,8 +19,11 @@ class phpbb_functions_fetch_news_test extends \board3\portal\tests\testframework { parent::setUp(); - global $auth, $cache, $phpbb_container, $phpbb_dispatcher, $template, $user, $phpbb_root_path, $phpEx; + global $auth, $cache, $config, $phpbb_container, $phpbb_dispatcher, $template, $user, $phpbb_root_path, $phpEx; + $config = new \phpbb\config\config([ + 'allow_nocensors' => false, + ]); $this->language_file_loader = new \phpbb\language\language_file_loader($phpbb_root_path, 'php'); $this->language = new \phpbb\language\language($this->language_file_loader); $user = new \phpbb\user($this->language, '\phpbb\datetime'); @@ -54,7 +57,10 @@ class phpbb_functions_fetch_news_test extends \board3\portal\tests\testframework $auth = new \phpbb\auth\auth(); $userdata = array( 'user_id' => 2, + 'user_permissions' => '', + 'user_type' => USER_NORMAL, ); + $user->data['user_options'] = 0; $auth->acl($userdata); // Pretend to allow downloads $auth->acl[0][0] = true; @@ -198,6 +204,8 @@ class phpbb_functions_fetch_news_test extends \board3\portal\tests\testframework public function test_phpbb_fetch_news($type, $expected_columns, $expected_main_columns = array(), $number_of_posts = 5, $forum_from = '', $empty = false, $permissions = false, $invert = false, $text_length = 150, $expected_exception = false) { + global $phpbb_container; + $module_id = 5; $time = time(); $start = 0; @@ -207,7 +215,10 @@ class phpbb_functions_fetch_news_test extends \board3\portal\tests\testframework $this->expectException($expected_exception); } - $fetch_posts = phpbb_fetch_posts($module_id, $forum_from, $permissions, $number_of_posts, $text_length, $time, $type, $start, $invert); + $b3p_fetch_posts = $phpbb_container->get('board3.portal.fetch_posts'); + $b3p_fetch_posts->set_module_id($module_id); + + $fetch_posts = $b3p_fetch_posts->get_posts($forum_from, $permissions, $number_of_posts, $text_length, $time, $type, $start, $invert); if (!$empty) { @@ -257,24 +268,31 @@ class phpbb_functions_fetch_news_test extends \board3\portal\tests\testframework ->with($this->anything()) ->will($this->returnValue(array())); - $phpbb_container->set('board3.portal.fetch_posts', new \board3\portal\portal\fetch_posts($this->auth, $cache, $this->config, $this->db, $this->modules_helper, $this->user)); - $fetch_posts = phpbb_fetch_posts(5, '', false, 5, 150, time(), 'announcements'); + $b3p_fetch_posts = new \board3\portal\portal\fetch_posts($this->auth, $cache, $this->config, $this->db, $this->modules_helper, $this->user); + $b3p_fetch_posts->set_module_id(5); + $fetch_posts = $b3p_fetch_posts->get_posts('', false, 5, 150, time(), 'announcements'); $this->assertEmpty($fetch_posts); } public function test_no_allowed_forums() { - global $auth; + global $auth, $phpbb_container; $auth = new \phpbb\auth\auth(); - $fetch_posts = phpbb_fetch_posts(5, '2', true, 5, 150, time(), 'announcements'); + $b3p_fetch_posts = $phpbb_container->get('board3.portal.fetch_posts'); + $b3p_fetch_posts->set_module_id(5); + $fetch_posts = $b3p_fetch_posts->get_posts('2', true, 5, 150, time(), 'announcements'); $this->assertSame(array(), $fetch_posts); } public function test_number_replies() { - $fetch_posts = phpbb_fetch_posts(5, '', false, 5, 150, time(), 'news'); + global $phpbb_container; + + $b3p_fetch_posts = $phpbb_container->get('board3.portal.fetch_posts'); + $b3p_fetch_posts->set_module_id(5); + $fetch_posts = $b3p_fetch_posts->get_posts('', false, 5, 150, time(), 'news'); // Topic has 2 posts which means there is only one reply $this->assertEquals(1, $fetch_posts[0]['topic_replies']); $this->assertEquals(1, $fetch_posts[0]['topic_replies_real']); diff --git a/tests/unit/includes/helper_test.php b/tests/unit/includes/helper_test.php index d3b5ef27..cd6c3a6c 100644 --- a/tests/unit/includes/helper_test.php +++ b/tests/unit/includes/helper_test.php @@ -17,8 +17,8 @@ class board3_includes_helper_test extends \board3\portal\tests\testframework\tes { global $phpbb_root_path; $this->language_file_loader = new \phpbb\language\language_file_loader($phpbb_root_path, 'php'); - $this->language = new \phpbb\language\language($this->language_file_loader); - $user = new \board3\portal\tests\mock\user($this->language, '\phpbb\datetime'); + $this->language = new \board3\portal\tests\mock\language($this->language_file_loader); + $user = new \phpbb\user($this->language, '\phpbb\datetime'); $config = new \phpbb\config\config(array()); $this->modules = array( diff --git a/tests/unit/modules/birthday_list_test.php b/tests/unit/modules/birthday_list_test.php index b99fbdb9..3298f927 100644 --- a/tests/unit/modules/birthday_list_test.php +++ b/tests/unit/modules/birthday_list_test.php @@ -40,7 +40,10 @@ class phpbb_unit_modules_birthday_list_test extends \board3\portal\tests\testfra $this->template = new \board3\portal\tests\mock\template($this); $this->config = new \phpbb\config\config(array()); $this->language_file_loader = new \phpbb\language\language_file_loader($phpbb_root_path, 'php'); - $this->language = new \phpbb\language\language($this->language_file_loader); + $this->language = new \board3\portal\tests\mock\language($this->language_file_loader); + $this->language->set([ + 'BIRTHDAYS_AHEAD' => 'BIRTHDAYS_AHEAD', + ]); $this->user = new \phpbb\user($this->language, '\phpbb\datetime'); $this->user->timezone = new \DateTimeZone('UTC'); $this->user->add_lang('common'); diff --git a/tests/unit/modules/calendar_test.php b/tests/unit/modules/calendar_test.php index 6a390127..9a60d8e9 100644 --- a/tests/unit/modules/calendar_test.php +++ b/tests/unit/modules/calendar_test.php @@ -38,7 +38,7 @@ class phpbb_unit_modules_calendar_test extends \board3\portal\tests\testframewor public function setUp(): void { parent::setUp(); - global $cache, $phpbb_root_path, $phpEx, $phpbb_dispatcher, $request, $user; + global $cache, $config, $phpbb_root_path, $phpEx, $phpbb_dispatcher, $request, $user; $this->path_helper = new \phpbb\path_helper( new \phpbb\symfony_request( @@ -57,7 +57,10 @@ class phpbb_unit_modules_calendar_test extends \board3\portal\tests\testframewor ->method('trigger_event') ->with($this->anything()) ->will($this->returnArgument(1)); - self::$config = new \phpbb\config\config(array()); + self::$config = new \phpbb\config\config([ + 'force_server_vars' => false, + ]); + $config = self::$config; \set_config('foobar', false, false, self::$config); $this->template = new \board3\portal\tests\mock\template($this); $controller_helper = new \board3\portal\tests\mock\controller_helper($phpbb_root_path, $phpEx); @@ -65,10 +68,16 @@ class phpbb_unit_modules_calendar_test extends \board3\portal\tests\testframewor $modules_helper = new \board3\portal\includes\modules_helper(new \phpbb\auth\auth(), new \phpbb\config\config(array()), $controller_helper, new \phpbb_mock_request()); $request = $this->request = new \phpbb_mock_request(); $this->language_file_loader = new \phpbb\language\language_file_loader($phpbb_root_path, 'php'); - $this->language = new \phpbb\language\language($this->language_file_loader); + $this->language = new \board3\portal\tests\mock\language($this->language_file_loader); + $this->language->add_lang('common'); + $this->language->add_lang_ext('board3/portal', 'modules/portal_calendar_module'); $user = new \phpbb\user($this->language, '\phpbb\datetime'); + $user->data = [ + 'user_id' => 2, + 'user_ip' => '127.0.0.1', + 'user_dateformat' => 'dmY', + ]; $user->timezone = new \DateTimeZone('UTC'); - $user->add_lang('common'); $log = $this->getMockBuilder('\phpbb\log') ->setMethods(array('add')) ->disableOriginalConstructor() @@ -78,8 +87,6 @@ class phpbb_unit_modules_calendar_test extends \board3\portal\tests\testframewor ->with($this->anything()) ->will($this->returnValue(true)); $this->calendar = new \board3\portal\modules\calendar(self::$config, $modules_helper, $this->template, $db, $this->request, dirname(__FILE__) . '/../../../', 'php', $user, $this->path_helper, $log); - define('PORTAL_MODULES_TABLE', 'phpbb_portal_modules'); - define('PORTAL_CONFIG_TABLE', 'phpbb_portal_config'); $cache = $this->getMockBuilder('\phpbb\cache\driver\dummy') ->setMethods(['destroy', 'sql_exists', 'get', 'put']) ->getMock(); @@ -188,6 +195,7 @@ class phpbb_unit_modules_calendar_test extends \board3\portal\tests\testframewor public function test_update_events_no_error() { + set_portal_config('board3_calendar_events_5', '[]'); $this->calendar->update_events('foobar', 5); $this->assertNull($this->template->get_row('events')); } diff --git a/tests/unit/modules/clock_test.php b/tests/unit/modules/clock_test.php index 9db1bc15..14259863 100644 --- a/tests/unit/modules/clock_test.php +++ b/tests/unit/modules/clock_test.php @@ -32,7 +32,7 @@ class phpbb_unit_modules_clock_test extends \board3\portal\tests\testframework\t public function test_get_template_side() { $this->assertSame('clock_side.html', $this->clock->get_template_side(5)); - $this->template->assert_same(null, 'B3P_CLOCK_SRC'); + $this->template->assert_not_exist( 'B3P_CLOCK_SRC'); $this->config->set('board3_clock_src_5', 'foobar'); $this->assertSame('clock_side.html', $this->clock->get_template_side(5)); $this->template->assert_same('foobar', 'B3P_CLOCK_SRC'); diff --git a/tests/unit/modules/welcome_test.php b/tests/unit/modules/welcome_test.php index 18b548ff..95188999 100644 --- a/tests/unit/modules/welcome_test.php +++ b/tests/unit/modules/welcome_test.php @@ -45,9 +45,10 @@ class phpbb_unit_modules_welcome_test extends \board3\portal\tests\testframework $request = $this->request; $this->template = new \board3\portal\tests\mock\template($this); $this->language_file_loader = new \phpbb\language\language_file_loader($phpbb_root_path, 'php'); - $this->language = new \phpbb\language\language($this->language_file_loader); + $this->language = new \board3\portal\tests\mock\language($this->language_file_loader); $this->user = new \phpbb\user($this->language, '\phpbb\datetime'); $user = $this->user; + $user->data['user_options'] = 0; $cache = $this->getMockBuilder('\phpbb\cache\driver\dummy') ->setMethods(['destroy', 'sql_exists', 'get', 'put', 'sql_load']) ->getMock(); @@ -172,6 +173,7 @@ class phpbb_unit_modules_welcome_test extends \board3\portal\tests\testframework public function test_update_welcome() { + \set_portal_config('board3_welcome_message_' . 5, 'Welcome to my Community!'); $this->welcome->update_welcome('foobar', 5); $this->template->assert_same(true, 'S_EDIT'); $this->request->overwrite('preview', true, \phpbb\request\request_interface::POST); @@ -205,7 +207,7 @@ class phpbb_unit_modules_welcome_test extends \board3\portal\tests\testframework $this->welcome = new \board3\portal\modules\welcome($this->config, $this->request, $this->template, $this->user, '', ''); $this->request->overwrite('submit', true, \phpbb\request\request_interface::POST); $this->request->overwrite('welcome_message', ''); - $this->setExpectedTriggerError(E_USER_WARNING); + $this->setExpectedTriggerError(E_WARNING); check_form_key::$form_key_valid = true; $this->welcome->update_welcome('foobar', 5); } diff --git a/tests/unit/portal/fetch_posts_test.php b/tests/unit/portal/fetch_posts_test.php index 02cd41ec..27c114b5 100644 --- a/tests/unit/portal/fetch_posts_test.php +++ b/tests/unit/portal/fetch_posts_test.php @@ -22,14 +22,17 @@ class phpbb_portal_fetch_posts_test extends \board3\portal\tests\testframework\d public function setUp(): void { - global $auth, $cache, $phpbb_dispatcher, $phpbb_root_path, $phpEx, $template, $user; + global $auth, $cache, $config, $phpbb_dispatcher, $phpbb_root_path, $phpEx, $template, $user; parent::setUp(); $this->language_file_loader = new \phpbb\language\language_file_loader($phpbb_root_path, 'php'); $this->language = new \phpbb\language\language($this->language_file_loader); $user = new \phpbb\user($this->language, '\phpbb\datetime'); - $user->data['user_id'] = 2; + $user->data = [ + 'user_id' => 2, + 'user_options' => 0, + ]; $user->timezone = new \DateTimeZone('UTC'); $user->add_lang('common'); $user->add_lang('../../ext/board3/portal/language/en/portal'); @@ -54,10 +57,16 @@ class phpbb_portal_fetch_posts_test extends \board3\portal\tests\testframework\d ->with($this->anything()) ->will($this->returnArgument(2)); require_once(dirname(__FILE__) . '/../../../../../../includes/functions_content.php'); - $this->config = new \phpbb\config\config(array('allow_attachments' => 1)); + $this->config = new \phpbb\config\config([ + 'allow_attachments' => 1, + 'allow_smilies' => 1, + ]); + $config = $this->config; $auth = new \phpbb\auth\auth(); $userdata = array( 'user_id' => 2, + 'user_permissions' => '', + 'user_type' => USER_NORMAL, ); $auth->acl($userdata); // Pretend to allow downloads diff --git a/tests/unit/portal/modules_manager_confirm_box_test.php b/tests/unit/portal/modules_manager_confirm_box_test.php index 7d3ced2a..141482b6 100644 --- a/tests/unit/portal/modules_manager_confirm_box_test.php +++ b/tests/unit/portal/modules_manager_confirm_box_test.php @@ -44,8 +44,9 @@ class modules_manager_confirm_box_test extends \board3\portal\tests\testframewor parent::setUp(); $this->language_file_loader = new \phpbb\language\language_file_loader($phpbb_root_path, 'php'); - $this->language = new \phpbb\language\language($this->language_file_loader); - $user = new \board3\portal\tests\mock\user($this->language, '\phpbb\datetime'); + $this->language = new \board3\portal\tests\mock\language($this->language_file_loader); + $this->language->add_lang_ext('board3/portal', 'portal_acp'); + $user = new \phpbb\user($this->language, '\phpbb\datetime'); $request =new \phpbb_mock_request(); $this->request = $request; $this->user = $user; @@ -60,7 +61,7 @@ class modules_manager_confirm_box_test extends \board3\portal\tests\testframewor $this->portal_helper = new \board3\portal\includes\helper(array( new \board3\portal\modules\clock($config, null), new \board3\portal\modules\birthday_list($config, null, $this->db, $user), - new \board3\portal\modules\welcome($config, new \phpbb_mock_request, $this->db, $user, $this->phpbb_root_path, $this->phpEx), + new \board3\portal\modules\welcome($config, new \phpbb_mock_request, $this->db, $user, $phpbb_root_path, $phpEx), new \board3\portal\modules\donation($config, $this->request, null, $user, $modules_helper), )); @@ -122,7 +123,15 @@ class modules_manager_confirm_box_test extends \board3\portal\tests\testframewor // Build confirm box first $this->modules_manager->set_u_action('adm/index.php?i=15&mode=foobar')->set_acp_class('foo\bar'); self::$confirm = false; - $this->assertNull($this->modules_manager->reset_module(15, 'barfoo', 6, array())); + $module_data = [ + 'module_column' => 1, + 'module_id' => 6, + 'module_image_width' => 16, + 'module_image_height' => 16, + 'module_image_src' => '', + 'module_name' => 'foo', + ]; + $this->assertNull($this->modules_manager->reset_module(15, 'barfoo', 6, $module_data)); $this->assertEquals(' @@ -132,13 +141,13 @@ class modules_manager_confirm_box_test extends \board3\portal\tests\testframewor // Actually reset module phpbb_acp_move_module_test::$override_trigger_error = true; self::$confirm = true; - $this->assertNull($this->modules_manager->reset_module(15, 'barfoo', 6, array())); + $this->assertNull($this->modules_manager->reset_module(15, 'barfoo', 6, $module_data)); $this->assertEquals(array( 'seconds' => 3, 'link' => 'adm/index.php?i=-foo-bar&mode=config&module_id=6', ), self::$meta_refresh); - $this->assertEquals(phpbb_acp_move_module_test::$error_type, E_USER_NOTICE); - $this->assertEquals(phpbb_acp_move_module_test::$error, 'adm/index.php?i=15&mode=foobar&module_id=6'); + $this->assertEquals(E_USER_NOTICE, phpbb_acp_move_module_test::$error_type); + $this->assertEquals($this->language->lang('MODULE_RESET_SUCCESS') . 'adm/index.php?i=15&mode=foobar&module_id=6', phpbb_acp_move_module_test::$error); phpbb_acp_move_module_test::$override_trigger_error = false; } @@ -182,7 +191,7 @@ class modules_manager_confirm_box_test extends \board3\portal\tests\testframewor modules_manager_confirm_box_test::$confirm = true; $this->assertNull($this->modules_manager->module_delete(6, 'foobar', 'module_delete', 6)); $this->assertEquals(E_USER_NOTICE, phpbb_acp_move_module_test::$error_type); - $this->assertEquals('adm/index.php?i=15&mode=foobar', phpbb_acp_move_module_test::$error); + $this->assertEquals($this->language->lang('SUCCESS_DELETE'). 'adm/index.php?i=15&mode=foobar', phpbb_acp_move_module_test::$error); phpbb_acp_move_module_test::$override_trigger_error = false; } } diff --git a/tests/unit/portal/modules_manager_test.php b/tests/unit/portal/modules_manager_test.php index 856ace24..8f06f80d 100644 --- a/tests/unit/portal/modules_manager_test.php +++ b/tests/unit/portal/modules_manager_test.php @@ -37,10 +37,9 @@ class board3_portal_modules_manager_test extends \board3\portal\tests\testframew parent::setUp(); - $language = $this->getMockBuilder('\phpbb\language\language') - ->disableOriginalConstructor() - ->getMock(); - $user = new \board3\portal\tests\mock\user($language, '\phpbb\datetime'); + $this->language_file_loader = new \phpbb\language\language_file_loader($phpbb_root_path, 'php'); + $this->language = new \board3\portal\tests\mock\language($this->language_file_loader); + $user = new \phpbb\user($this->language, '\phpbb\datetime'); $request =new \phpbb_mock_request(); $config = new \phpbb\config\config(array()); @@ -48,12 +47,12 @@ class board3_portal_modules_manager_test extends \board3\portal\tests\testframew $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($auth, $config, $controller_helper, $this->request); + $modules_helper = new \board3\portal\includes\modules_helper($auth, $config, $controller_helper, $request); $portal_helper = new \board3\portal\includes\helper(array( new \board3\portal\modules\clock($config, null), new \board3\portal\modules\birthday_list($config, null, $this->db, $user), - new \board3\portal\modules\welcome($config, new \phpbb_mock_request, $this->db, $user, $this->phpbb_root_path, $this->phpEx), + new \board3\portal\modules\welcome($config, new \phpbb_mock_request, $this->db, $user, $phpbb_root_path, $phpEx), new \board3\portal\modules\donation($config, $request, null, $user, $modules_helper), )); @@ -84,7 +83,7 @@ class board3_portal_modules_manager_test extends \board3\portal\tests\testframew ->with($this->anything()) ->will($this->returnArgument(2)); $db = $this->db; - $user->set(array( + $this->language->set(array( 'UNABLE_TO_MOVE' => 'UNABLE_TO_MOVE', 'UNABLE_TO_MOVE_ROW' => 'UNABLE_TO_MOVE_ROW', )); @@ -112,7 +111,7 @@ class board3_portal_modules_manager_test extends \board3\portal\tests\testframew new \board3\portal\tests\mock\template($this), $user, $this->path_helper, - $this->portal_helper, + $portal_helper, $phpbb_root_path, $phpEx );