[ticket/715] Resolve issues with portal and tests on PHP 8.0

B3P-715
This commit is contained in:
Marc Alexander
2021-09-04 11:09:52 +02:00
parent 9eb415b79c
commit ed54e3ef0c
30 changed files with 233 additions and 143 deletions

View File

@@ -12,7 +12,7 @@ namespace board3\portal\acp;
class portal_module class portal_module
{ {
public $u_action; public $u_action;
public $new_config = array(); public $new_config = [];
/** @var \board3\portal\modules\module_interface */ /** @var \board3\portal\modules\module_interface */
protected $c_class; protected $c_class;
@@ -148,7 +148,7 @@ class portal_module
$groups_ary = explode(',', $module_data['module_group_ids']); $groups_ary = explode(',', $module_data['module_group_ids']);
// get group info from database and assign the block vars // 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 . ' FROM ' . GROUPS_TABLE . '
ORDER BY group_id ASC'; ORDER BY group_id ASC';
$result = $this->db->sql_query($sql); $result = $this->db->sql_query($sql);
@@ -318,7 +318,7 @@ class portal_module
$this->page_title = $display_vars['title']; $this->page_title = $display_vars['title'];
$this->template->assign_vars(array( $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'] : '', 'L_TITLE_EXPLAIN' => (isset($this->user->lang[$display_vars['title'] . '_EXP'])) ? $this->user->lang[$display_vars['title'] . '_EXP'] : '',
'S_ERROR' => (sizeof($error)) ? true : false, 'S_ERROR' => (sizeof($error)) ? true : false,

View File

@@ -266,7 +266,7 @@ class helper
$this->check_permission(); $this->check_permission();
// Load language file // Load language file
$this->user->add_lang_ext('board3/portal', 'portal'); $this->language->add_lang('portal', 'board3/portal');
// Obtain portal config // Obtain portal config
obtain_portal_config(); obtain_portal_config();

View File

@@ -117,8 +117,11 @@ class main
$this->includes_path = $phpbb_root_path . 'ext/board3/portal/includes/'; $this->includes_path = $phpbb_root_path . 'ext/board3/portal/includes/';
$this->root_path = $phpbb_root_path . 'ext/board3/portal/'; $this->root_path = $phpbb_root_path . 'ext/board3/portal/';
$portal_root_path = $this->root_path; $portal_root_path = $this->root_path;
define('PORTAL_MODULES_TABLE', $modules_table); if (!defined('PORTAL_MODULES_TABLE'))
define('PORTAL_CONFIG_TABLE', $config_table); {
define('PORTAL_MODULES_TABLE', $modules_table);
define('PORTAL_CONFIG_TABLE', $config_table);
}
if (!function_exists('obtain_portal_config')) if (!function_exists('obtain_portal_config'))
{ {

View File

@@ -93,21 +93,6 @@ function obtain_portal_modules()
return $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 * 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 // 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)) 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 . '<br />'; $error .= $user->lang('B3P_FILE_NOT_FOUND') . ': styles/all/theme/images/portal/' . $value . '<br />';
} }
if (!empty($error)) if (!empty($error))

View File

@@ -131,7 +131,7 @@ class announcements extends module_base
$this->config['board3_announcements_permissions_' . $module_id], $this->config['board3_announcements_permissions_' . $module_id],
$this->config['board3_number_of_announcements_' . $module_id], $this->config['board3_number_of_announcements_' . $module_id],
$portal_announcement_length, $portal_announcement_length,
$this->config['board3_announcements_day_' . $module_id], (int) $this->config['board3_announcements_day_' . $module_id],
'announcements', 'announcements',
$start, $start,
(bool) $this->config['board3_announcements_forum_exclude_' . $module_id] (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 = $this->config['board3_global_announcements_forum_' . $module_id];
$forum_from = (strpos($forum_from, ',') !== false) ? explode(',', $forum_from) : (($forum_from != '') ? array($forum_from) : array()); $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); $post_time = ($time == 0) ? '' : 'AND topic_time > ' . (time() - $time * 86400);
$str_where = ''; $str_where = '';

View File

@@ -188,19 +188,19 @@ class calendar extends module_base
// output our general calendar bits // output our general calendar bits
$down = $this->mini_cal_month - 1; $down = $this->mini_cal_month - 1;
$up = $this->mini_cal_month + 1; $up = $this->mini_cal_month + 1;
$prev_month = '<a href="' . $this->modules_helper->route('board3_portal_controller') . "?m$module_id=$down#minical$module_id" . '" rel="nofollow"><i class="fa fa-backward" aria-hidden="true" title="' . $this->user->lang['VIEW_PREVIOUS_MONTH'] . '"></i></a>'; $prev_month = '<a href="' . $this->modules_helper->route('board3_portal_controller') . "?m$module_id=$down#minical$module_id" . '" rel="nofollow"><i class="fa fa-backward" aria-hidden="true" title="' . $this->user->lang('VIEW_PREVIOUS_MONTH') . '"></i></a>';
$next_month = '<a href="' . $this->modules_helper->route('board3_portal_controller') . "?m$module_id=$up#minical$module_id" . '" rel="nofollow"><i class="fa fa-forward" aria-hidden="true" title="' . $this->user->lang['VIEW_NEXT_MONTH'] . '"></i></a>'; $next_month = '<a href="' . $this->modules_helper->route('board3_portal_controller') . "?m$module_id=$up#minical$module_id" . '" rel="nofollow"><i class="fa fa-forward" aria-hidden="true" title="' . $this->user->lang('VIEW_NEXT_MONTH') . '"></i></a>';
$this->template->assign_block_vars('minical', array( $this->template->assign_block_vars('minical', array(
'S_SUNDAY_FIRST' => ($this->config['board3_sunday_first_' . $module_id]) ? true : false, '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_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' => '<span style="color: ' . $this->config['board3_calendar_sunday_color_' . $module_id] . ';">' . $this->user->lang['mini_cal']['day'][1] . '</span>', 'L_MINI_CAL_SUN' => '<span style="color: ' . $this->config['board3_calendar_sunday_color_' . $module_id] . ';">' . $this->user->lang(['mini_cal', 'day'], 1) . '</span>',
'L_MINI_CAL_MON' => $this->user->lang['mini_cal']['day'][2], '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_TUE' => $this->user->lang(['mini_cal', 'day'], 3),
'L_MINI_CAL_WED' => $this->user->lang['mini_cal']['day'][4], '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_THU' => $this->user->lang(['mini_cal', 'day'], 5),
'L_MINI_CAL_FRI' => $this->user->lang['mini_cal']['day'][6], '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_SAT' => $this->user->lang(['mini_cal', 'day'], 7),
'U_PREV_MONTH' => $prev_month, 'U_PREV_MONTH' => $prev_month,
'U_NEXT_MONTH' => $next_month, 'U_NEXT_MONTH' => $next_month,
'S_DISPLAY_EVENTS' => ($this->config['board3_display_events_' . $module_id]) ? true : false, 'S_DISPLAY_EVENTS' => ($this->config['board3_display_events_' . $module_id]) ? true : false,
@@ -488,13 +488,13 @@ class calendar extends module_base
// Check for errors // Check for errors
if (!$event_title) 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 // 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)) if (isset($link_id) && $link_id < sizeof($events))
{ {
$message = $this->user->lang['EVENT_UPDATED']; $message = $this->user->lang('EVENT_UPDATED');
$events[$link_id] = array( $events[$link_id] = array(
'title' => $event_title, 'title' => $event_title,
@@ -510,7 +510,7 @@ class calendar extends module_base
} }
else else
{ {
$message = $this->user->lang['EVENT_ADDED']; $message = $this->user->lang('EVENT_ADDED');
$events[] = array( $events[] = array(
'title' => $event_title, 'title' => $event_title,

View File

@@ -63,10 +63,10 @@ class phpbb_functional_portal_acp_test extends \board3\portal\tests\testframewor
$crawler = self::request('GET', $module_link); $crawler = self::request('GET', $module_link);
preg_match('/module_classname=(?:([a-z0-9\\\_]+))/', $module_link, $module_name); preg_match('/module_classname=(?:([a-z0-9\\\_]+))/', $module_link, $module_name);
$module_name = $module_name[1]; $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(); $form = $crawler->selectButton('confirm')->form();
$crawler = self::submit($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 // 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); $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 // Take a look at the logs
$crawler = self::request('GET', 'adm/index.php?i=acp_logs&mode=admin&sid=' . $this->sid); $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() 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')); $form->setValues(array('link_title' => 'foobar'));
$crawler = self::submit($form); $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); $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); $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() 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 = $crawler->selectButton('submit')->form();
$form['module_classname']->disableValidation()->select($module_class); $form['module_classname']->disableValidation()->select($module_class);
$crawler = self::submit($form); $crawler = self::submit($form);
$this->assertContains($expected_message, $crawler->text()); $this->assertStringContainsString($expected_message, $crawler->text());
} }
} }

View File

@@ -60,6 +60,8 @@ class phpbb_functional_portal_announcement_test extends \board3\portal\tests\tes
public function test_shortened_message() public function test_shortened_message()
{ {
$this->purge_cache();
// Create topic as announcement // Create topic as announcement
$data = $this->create_topic(2, 'Portal-announce-global', str_repeat('This is a global announcement for the portal', 6), array( $data = $this->create_topic(2, 'Portal-announce-global', str_repeat('This is a global announcement for the portal', 6), array(
'topic_type' => POST_GLOBAL, '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 // no errors should appear on portal
$crawler = self::request('GET', 'app.php/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());
} }
} }
} }

View File

@@ -47,6 +47,6 @@ class phpbb_functional_portal_birthday_list_test extends \board3\portal\tests\te
public function test_after_announce() public function test_after_announce()
{ {
$crawler = self::request('GET', 'app.php/portal'); $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());
} }
} }

View File

@@ -23,7 +23,7 @@ class phpbb_functional_portal_link_test extends \board3\portal\tests\testframewo
public function test_portal_link() public function test_portal_link()
{ {
$crawler = self::request('GET', 'index.php?sid=' . $this->sid); $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() 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) foreach ($vals as $val)
{ {
$this->assertNotContains('Portal', $val); $this->assertStringNotContainsString('Portal', $val);
} }
// Try to access portal directly // Try to access portal directly
@@ -56,7 +56,7 @@ class phpbb_functional_portal_link_test extends \board3\portal\tests\testframewo
}); });
foreach ($vals as $val) foreach ($vals as $val)
{ {
$this->assertNotContains('Portal', $val); $this->assertStringNotContainsString('Portal', $val);
} }
// Enable portal again // Enable portal again

View File

@@ -42,7 +42,7 @@ class phpbb_functional_portal_no_error_test extends \board3\portal\tests\testfra
public function test_portal_all_pages($style_id) public function test_portal_all_pages($style_id)
{ {
$crawler = self::request('GET', 'index.php?style=' . $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); $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()); $this->assertContainsLang('CONFIG_UPDATED', $crawler->text());
$crawler = self::request('GET', 'index.php?style=' . $style_id); $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); $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()); $this->assertContainsLang('CONFIG_UPDATED', $crawler->text());
$crawler = self::request('GET', 'index.php?style=' . $style_id); $crawler = self::request('GET', 'index.php?style=' . $style_id);
$this->assertNotContains('Board Style', $crawler->text()); $this->assertStringNotContainsString('Board Style', $crawler->text());
$this->assertContains('User menu', $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); $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()); $this->assertContainsLang('CONFIG_UPDATED', $crawler->text());
$crawler = self::request('GET', 'index.php?style=' . $style_id); $crawler = self::request('GET', 'index.php?style=' . $style_id);
$this->assertNotContains('Menu', $crawler->text()); $this->assertStringNotContainsString('Menu', $crawler->text());
} }
} }

View File

@@ -29,13 +29,13 @@ class phpbb_functional_portal_redirect_test extends \board3\portal\tests\testfra
} }
else else
{ {
$mod_rewrite = (getenv('HTTP_MOD_REWRITE')=='On') ? true : false; $mod_rewrite = getenv('HTTP_MOD_REWRITE') == 'On';
} }
if ($mod_rewrite) if ($mod_rewrite)
{ {
$crawler = self::request('GET', ''); $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 // Make sure we are logged out
$this->logout(); $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 = $crawler->selectButton('Login')->form();
$form->setValues(array( $form->setValues(array(
'username' => 'admin', 'username' => 'admin',
@@ -54,6 +54,6 @@ class phpbb_functional_portal_redirect_test extends \board3\portal\tests\testfra
$crawler = self::submit($form); $crawler = self::submit($form);
// Should be redirected to portal and logged in // Should be redirected to portal and logged in
$this->assertContains('Site Admin', $crawler->text()); $this->assertStringContainsString('Site Admin', $crawler->text());
} }
} }

View File

@@ -103,8 +103,8 @@ class phpbb_functional_portal_visit_registered_test extends \board3\portal\tests
$crawler = self::request('GET', 'app.php/portal'); $crawler = self::request('GET', 'app.php/portal');
$legend = $crawler->filter('dd.portal-responsive-show p em')->text(); $legend = $crawler->filter('dd.portal-responsive-show p em')->text();
$this->assertContains('Administrators', $legend); $this->assertStringContainsString('Administrators', $legend);
$this->assertContains('Global moderators', $legend); $this->assertStringContainsString('Global moderators', $legend);
} }
public function test_setup_hidden_forum() 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 = $crawler->selectButton('Submit')->form();
$form['forum_perm_from']->select(2); $form['forum_perm_from']->select(2);
$crawler = self::submit($form); $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 // Hide forum using permissions from registered users
$crawler = self::request('GET', 'adm/index.php?i=acp_permissions&mode=setting_group_local&sid=' . $this->sid); $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->logout();
$this->login('standard-user'); $this->login('standard-user');
$crawler = self::request('GET', 'index.php'); $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'); $crawler = self::request('GET', 'app.php/portal');
$this->assertNotContains('Hidden topic', $crawler->text()); $this->assertStringNotContainsString('Hidden topic', $crawler->text());
} }
} }

View File

@@ -33,10 +33,10 @@ class phpbb_functional_portal_vote_poll_test extends \board3\portal\tests\testfr
$crawler = self::request('GET', 'app.php/portal'); $crawler = self::request('GET', 'app.php/portal');
$form = $crawler->selectButton('Submit vote')->form(); $form = $crawler->selectButton('Submit vote')->form();
$form->setValues(array('vote_id' => array(1))); $form->setValues(array('vote_id' => array(1)));
$crawler = self::submit($form); self::submit($form);
// no errors should appear on portal // 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() public function test_after_poll()
{ {
$this->logout(); $this->logout();
$crawler = self::request('GET', 'app.php/portal'); self::request('GET', 'app.php/portal');
} }
} }

View File

@@ -9,10 +9,8 @@
namespace board3\portal\tests\mock; namespace board3\portal\tests\mock;
class user extends \phpbb\user class language extends \phpbb\language\language
{ {
public $lang = array();
public function set($data) public function set($data)
{ {
foreach ($data as $key => $column) 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) public function add_lang_ext($ext_name, $lang_set, $use_db = false, $use_help = false)
{ {
if ($ext_name != 'board3/portal') if ($ext_name != 'board3/portal')
@@ -39,7 +49,8 @@ class user extends \phpbb\user
if (file_exists(dirname(__FILE__) . '/../../language/en/' . $lang_set . '.php')) 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)) if (isset($lang))
{ {
@@ -47,10 +58,4 @@ class user extends \phpbb\user
} }
} }
} }
public function lang()
{
$args = func_get_args();
return $this->lang[$args[0]];
}
} }

View File

@@ -64,6 +64,11 @@ class template
$this->test_case->assertSame($expected, $this->data[$row]); $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) public function delete_var($key)
{ {
unset($this->data[$key]); unset($this->data[$key]);
@@ -71,6 +76,6 @@ class template
public function get_row($row) public function get_row($row)
{ {
return $this->data[$row]; return $this->data[$row] ?? null;
} }
} }

View File

@@ -40,12 +40,23 @@ class phpbb_acp_move_module_test extends \board3\portal\tests\testframework\data
public function setUp(): void public function setUp(): void
{ {
parent::setUp(); 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; global $phpbb_dispatcher;
$this->language_file_loader = new \phpbb\language\language_file_loader($phpbb_root_path, 'php'); $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);
$user = new \board3\portal\tests\mock\user($this->language, '\phpbb\datetime'); $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); $template = new \board3\portal\tests\mock\template($this);
$this->template = $template; $this->template = $template;
@@ -53,7 +64,7 @@ class phpbb_acp_move_module_test extends \board3\portal\tests\testframework\data
$this->request = $request; $this->request = $request;
$phpbb_container = new \phpbb_mock_container_builder(); $phpbb_container = new \phpbb_mock_container_builder();
// Mock module service collection // Mock module service collection
$config = new \phpbb\config\config(array()); $config = new \phpbb\config\config([]);
$auth = $this->getMockBuilder('\phpbb\auth\auth') $auth = $this->getMockBuilder('\phpbb\auth\auth')
->setMethods(['acl_get']) ->setMethods(['acl_get'])
->getMock(); ->getMock();
@@ -104,7 +115,7 @@ class phpbb_acp_move_module_test extends \board3\portal\tests\testframework\data
->with($this->anything()) ->with($this->anything())
->will($this->returnArgument(2)); ->will($this->returnArgument(2));
$db = $this->db; $db = $this->db;
$user->set(array( $this->language->set(array(
'UNABLE_TO_MOVE' => 'UNABLE_TO_MOVE', 'UNABLE_TO_MOVE' => 'UNABLE_TO_MOVE',
'UNABLE_TO_MOVE_ROW' => 'UNABLE_TO_MOVE_ROW', '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->modules_manager->move_module_vertical(2, \board3\portal\portal\modules\database_handler::MOVE_DIRECTION_UP);
$this->assertTrue(self::$redirected); $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; self::$redirected = false;
$this->modules_manager->move_module_vertical(2, \board3\portal\portal\modules\database_handler::MOVE_DIRECTION_UP); $this->modules_manager->move_module_vertical(2, \board3\portal\portal\modules\database_handler::MOVE_DIRECTION_UP);
$this->assertFalse(self::$redirected); $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->modules_manager->move_module_vertical(3, \board3\portal\portal\modules\database_handler::MOVE_DIRECTION_DOWN);
$this->assertTrue(self::$redirected); $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; self::$redirected = false;
$this->modules_manager->move_module_vertical(3, \board3\portal\portal\modules\database_handler::MOVE_DIRECTION_DOWN); $this->modules_manager->move_module_vertical(3, \board3\portal\portal\modules\database_handler::MOVE_DIRECTION_DOWN);
$this->assertFalse(self::$redirected); $this->assertFalse(self::$redirected);
@@ -258,7 +269,7 @@ class phpbb_acp_move_module_test extends \board3\portal\tests\testframework\data
{ {
if ($error) if ($error)
{ {
$this->setExpectedTriggerError(E_USER_NOTICE, $error); $this->setExpectedTriggerError(E_USER_NOTICE, $this->language->lang($error));
} }
else else
{ {
@@ -311,7 +322,7 @@ class phpbb_acp_move_module_test extends \board3\portal\tests\testframework\data
$column_start++; $column_start++;
$this->update_portal_modules(); $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); $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(); $this->update_portal_modules();
$column_start--; $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); $this->modules_manager->move_module_horizontal($module_id, \board3\portal\portal\modules\database_handler::MOVE_DIRECTION_LEFT);
} }

View File

@@ -40,7 +40,7 @@ class helper_test extends \board3\portal\tests\testframework\test_case
)); ));
$this->template = new \board3\portal\tests\mock\template($this); $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_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 = new \phpbb\user($this->language, '\phpbb\datetime');
$this->user->data['group_id'] = 2; $this->user->data['group_id'] = 2;
$this->phpbb_root_path = dirname(__FILE__) . '/../../../../../../'; $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->language_file_loader->set_extension_manager($phpbb_extension_manager);
$this->php_ext = 'php'; $this->php_ext = 'php';
$this->portal_columns = new \board3\portal\portal\columns(); $this->portal_columns = new \board3\portal\portal\columns();
$this->language_file_loader = new \phpbb\language\language_file_loader($phpbb_root_path, 'php'); $user = $this->user;
$this->language = new \phpbb\language\language($this->language_file_loader);
$user = new \board3\portal\tests\mock\user($this->language, '\phpbb\datetime');
$this->modules = array( $this->modules = array(
'\board3\portal\modules\link_us' => new \board3\portal\modules\link_us($this->config, new \board3\portal\tests\mock\template($this), $user), '\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; 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->assertFalse(isset($this->user->lang['PORTAL_LEADERS_EXT']));
$this->language_file_loader = new \phpbb\language\language_file_loader($phpbb_root_path, 'php'); $user = new \phpbb\user($this->language, '\phpbb\datetime');
$this->language = new \phpbb\language\language($this->language_file_loader);
$user = new \board3\portal\tests\mock\user($this->language, '\phpbb\datetime');
$module = $this->getMockBuilder('\board3\portal\modules\link_us') $module = $this->getMockBuilder('\board3\portal\modules\link_us')
->setMethods(['get_language']) ->setMethods(['get_language'])
->setConstructorArgs([$this->config, new \board3\portal\tests\mock\template($this), $user]) ->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', 'vendor' => 'board3/portal',
'file' => 'modules/portal_leaders_module', 'file' => 'modules/portal_leaders_module',
)); ));
$this->assertNull($this->controller_helper->load_module_language($module)); $this->controller_helper->load_module_language($module);
$this->assertNotEmpty($this->user->lang('ACP_PORTAL_LEADERS')); $this->assertNotEmpty($this->language->lang('ACP_PORTAL_LEADERS'));
} }
public function data_assign_module_vars() public function data_assign_module_vars()
@@ -176,16 +172,21 @@ class helper_test extends \board3\portal\tests\testframework\test_case
'module_id' => 1, 'module_id' => 1,
'module_image_width' => 16, 'module_image_width' => 16,
'module_image_height' => 16, 'module_image_height' => 16,
'module_image_src' => '',
'module_name' => 'foo',
), array( ), array(
'template' => 'foobar.html', 'template' => 'foobar.html',
'title' => 'foo', 'title' => 'foo',
'code' => 'bar', 'code' => 'bar',
'image_src' => '',
)), )),
array(array( array(array(
'module_column' => 1, 'module_column' => 1,
'module_id' => 1, 'module_id' => 1,
'module_image_width' => 16, 'module_image_width' => 16,
'module_image_height' => 16, 'module_image_height' => 16,
'module_image_src' => '',
'module_name' => 'foo',
), 'foobar.html'), ), 'foobar.html'),
); );
} }

View File

@@ -44,8 +44,12 @@ class main_test extends \board3\portal\tests\testframework\database_test_case
$cache = new \phpbb\cache\driver\dummy(); $cache = new \phpbb\cache\driver\dummy();
$this->language_file_loader = new \phpbb\language\language_file_loader($phpbb_root_path, 'php'); $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);
$user = new \board3\portal\tests\mock\user($this->language, '\phpbb\datetime'); $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'; $config_table = $table_prefix . 'portal_config';
$modules_table = $table_prefix . 'portal_modules'; $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->assert_same(true, 'S_PORTAL_ALL');
$this->template->delete_var('S_PORTAL_ALL'); $this->template->delete_var('S_PORTAL_ALL');
$this->assertNull($this->controller_main->handle(array('left' => 1))); $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() 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->assertNull($this->controller_main->handle(array('left' => 1)));
$this->template->assert_same(true, 'S_PORTAL_ALL'); $this->template->assert_same(true, 'S_PORTAL_ALL');
$this->config['board3_left_column'] = false; $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)
));
} }
} }

View File

@@ -122,8 +122,8 @@ class listener_test extends \phpbb_template_template_test_case
), ),
new \phpbb\filesystem\filesystem(), new \phpbb\filesystem\filesystem(),
new \phpbb_mock_request(), new \phpbb_mock_request(),
$this->phpbb_root_path, $phpbb_root_path,
$this->php_ext $phpEx
); );
$this->controller = $this->getMockBuilder('\board3\portal\controller\main') $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->phpbb_dispatcher->addListener('core.page_header', array($this->listener, 'add_portal_link'));
$this->controller_helper->set_current_url(''); $this->controller_helper->set_current_url('');
$vars = [];
$result = $this->phpbb_dispatcher->trigger_event('core.page_header', compact($vars)); $result = $this->phpbb_dispatcher->trigger_event('core.page_header', compact($vars));
$this->assertEmpty($result); $this->assertEmpty($result);

View File

@@ -19,7 +19,12 @@ class phpbb_functions_check_file_src_test extends \board3\portal\tests\testframe
parent::setUp(); parent::setUp();
global $user; 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/'; $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() public function test_check_file_src()
{ {
$this->assertFalse(check_file_src('portal_attach.png', '', 15, false)); $this->assertFalse(check_file_src('portal_attach.png', '', 15, false));
$this->assertEquals(': styles/all/theme/images/portal/portal_foobar.png<br />', check_file_src('portal_foobar.png', '', 15, false)); $this->assertEquals('B3P_FILE_NOT_FOUND: styles/all/theme/images/portal/portal_foobar.png<br />', check_file_src('portal_foobar.png', '', 15, false));
} }
public function test_check_file_src_error() public function test_check_file_src_error()

View File

@@ -19,8 +19,11 @@ class phpbb_functions_fetch_news_test extends \board3\portal\tests\testframework
{ {
parent::setUp(); 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_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 \phpbb\language\language($this->language_file_loader);
$user = new \phpbb\user($this->language, '\phpbb\datetime'); $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(); $auth = new \phpbb\auth\auth();
$userdata = array( $userdata = array(
'user_id' => 2, 'user_id' => 2,
'user_permissions' => '',
'user_type' => USER_NORMAL,
); );
$user->data['user_options'] = 0;
$auth->acl($userdata); $auth->acl($userdata);
// Pretend to allow downloads // Pretend to allow downloads
$auth->acl[0][0] = true; $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, 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) $invert = false, $text_length = 150, $expected_exception = false)
{ {
global $phpbb_container;
$module_id = 5; $module_id = 5;
$time = time(); $time = time();
$start = 0; $start = 0;
@@ -207,7 +215,10 @@ class phpbb_functions_fetch_news_test extends \board3\portal\tests\testframework
$this->expectException($expected_exception); $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) if (!$empty)
{ {
@@ -257,24 +268,31 @@ class phpbb_functions_fetch_news_test extends \board3\portal\tests\testframework
->with($this->anything()) ->with($this->anything())
->will($this->returnValue(array())); ->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)); $b3p_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->set_module_id(5);
$fetch_posts = $b3p_fetch_posts->get_posts('', false, 5, 150, time(), 'announcements');
$this->assertEmpty($fetch_posts); $this->assertEmpty($fetch_posts);
} }
public function test_no_allowed_forums() public function test_no_allowed_forums()
{ {
global $auth; global $auth, $phpbb_container;
$auth = new \phpbb\auth\auth(); $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); $this->assertSame(array(), $fetch_posts);
} }
public function test_number_replies() 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 // 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']);
$this->assertEquals(1, $fetch_posts[0]['topic_replies_real']); $this->assertEquals(1, $fetch_posts[0]['topic_replies_real']);

View File

@@ -17,8 +17,8 @@ class board3_includes_helper_test extends \board3\portal\tests\testframework\tes
{ {
global $phpbb_root_path; global $phpbb_root_path;
$this->language_file_loader = new \phpbb\language\language_file_loader($phpbb_root_path, 'php'); $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);
$user = new \board3\portal\tests\mock\user($this->language, '\phpbb\datetime'); $user = new \phpbb\user($this->language, '\phpbb\datetime');
$config = new \phpbb\config\config(array()); $config = new \phpbb\config\config(array());
$this->modules = array( $this->modules = array(

View File

@@ -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->template = new \board3\portal\tests\mock\template($this);
$this->config = new \phpbb\config\config(array()); $this->config = new \phpbb\config\config(array());
$this->language_file_loader = new \phpbb\language\language_file_loader($phpbb_root_path, 'php'); $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 = new \phpbb\user($this->language, '\phpbb\datetime');
$this->user->timezone = new \DateTimeZone('UTC'); $this->user->timezone = new \DateTimeZone('UTC');
$this->user->add_lang('common'); $this->user->add_lang('common');

View File

@@ -38,7 +38,7 @@ class phpbb_unit_modules_calendar_test extends \board3\portal\tests\testframewor
public function setUp(): void public function setUp(): void
{ {
parent::setUp(); 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( $this->path_helper = new \phpbb\path_helper(
new \phpbb\symfony_request( new \phpbb\symfony_request(
@@ -57,7 +57,10 @@ class phpbb_unit_modules_calendar_test extends \board3\portal\tests\testframewor
->method('trigger_event') ->method('trigger_event')
->with($this->anything()) ->with($this->anything())
->will($this->returnArgument(1)); ->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); \set_config('foobar', false, false, self::$config);
$this->template = new \board3\portal\tests\mock\template($this); $this->template = new \board3\portal\tests\mock\template($this);
$controller_helper = new \board3\portal\tests\mock\controller_helper($phpbb_root_path, $phpEx); $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()); $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(); $request = $this->request = new \phpbb_mock_request();
$this->language_file_loader = new \phpbb\language\language_file_loader($phpbb_root_path, 'php'); $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 = 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->timezone = new \DateTimeZone('UTC');
$user->add_lang('common');
$log = $this->getMockBuilder('\phpbb\log') $log = $this->getMockBuilder('\phpbb\log')
->setMethods(array('add')) ->setMethods(array('add'))
->disableOriginalConstructor() ->disableOriginalConstructor()
@@ -78,8 +87,6 @@ class phpbb_unit_modules_calendar_test extends \board3\portal\tests\testframewor
->with($this->anything()) ->with($this->anything())
->will($this->returnValue(true)); ->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); $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') $cache = $this->getMockBuilder('\phpbb\cache\driver\dummy')
->setMethods(['destroy', 'sql_exists', 'get', 'put']) ->setMethods(['destroy', 'sql_exists', 'get', 'put'])
->getMock(); ->getMock();
@@ -188,6 +195,7 @@ class phpbb_unit_modules_calendar_test extends \board3\portal\tests\testframewor
public function test_update_events_no_error() public function test_update_events_no_error()
{ {
set_portal_config('board3_calendar_events_5', '[]');
$this->calendar->update_events('foobar', 5); $this->calendar->update_events('foobar', 5);
$this->assertNull($this->template->get_row('events')); $this->assertNull($this->template->get_row('events'));
} }

View File

@@ -32,7 +32,7 @@ class phpbb_unit_modules_clock_test extends \board3\portal\tests\testframework\t
public function test_get_template_side() public function test_get_template_side()
{ {
$this->assertSame('clock_side.html', $this->clock->get_template_side(5)); $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->config->set('board3_clock_src_5', 'foobar');
$this->assertSame('clock_side.html', $this->clock->get_template_side(5)); $this->assertSame('clock_side.html', $this->clock->get_template_side(5));
$this->template->assert_same('foobar', 'B3P_CLOCK_SRC'); $this->template->assert_same('foobar', 'B3P_CLOCK_SRC');

View File

@@ -45,9 +45,10 @@ class phpbb_unit_modules_welcome_test extends \board3\portal\tests\testframework
$request = $this->request; $request = $this->request;
$this->template = new \board3\portal\tests\mock\template($this); $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_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 = new \phpbb\user($this->language, '\phpbb\datetime');
$user = $this->user; $user = $this->user;
$user->data['user_options'] = 0;
$cache = $this->getMockBuilder('\phpbb\cache\driver\dummy') $cache = $this->getMockBuilder('\phpbb\cache\driver\dummy')
->setMethods(['destroy', 'sql_exists', 'get', 'put', 'sql_load']) ->setMethods(['destroy', 'sql_exists', 'get', 'put', 'sql_load'])
->getMock(); ->getMock();
@@ -172,6 +173,7 @@ class phpbb_unit_modules_welcome_test extends \board3\portal\tests\testframework
public function test_update_welcome() public function test_update_welcome()
{ {
\set_portal_config('board3_welcome_message_' . 5, 'Welcome to my Community!');
$this->welcome->update_welcome('foobar', 5); $this->welcome->update_welcome('foobar', 5);
$this->template->assert_same(true, 'S_EDIT'); $this->template->assert_same(true, 'S_EDIT');
$this->request->overwrite('preview', true, \phpbb\request\request_interface::POST); $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->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('submit', true, \phpbb\request\request_interface::POST);
$this->request->overwrite('welcome_message', ''); $this->request->overwrite('welcome_message', '');
$this->setExpectedTriggerError(E_USER_WARNING); $this->setExpectedTriggerError(E_WARNING);
check_form_key::$form_key_valid = true; check_form_key::$form_key_valid = true;
$this->welcome->update_welcome('foobar', 5); $this->welcome->update_welcome('foobar', 5);
} }

View File

@@ -22,14 +22,17 @@ class phpbb_portal_fetch_posts_test extends \board3\portal\tests\testframework\d
public function setUp(): void 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(); parent::setUp();
$this->language_file_loader = new \phpbb\language\language_file_loader($phpbb_root_path, 'php'); $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 \phpbb\language\language($this->language_file_loader);
$user = new \phpbb\user($this->language, '\phpbb\datetime'); $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->timezone = new \DateTimeZone('UTC');
$user->add_lang('common'); $user->add_lang('common');
$user->add_lang('../../ext/board3/portal/language/en/portal'); $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()) ->with($this->anything())
->will($this->returnArgument(2)); ->will($this->returnArgument(2));
require_once(dirname(__FILE__) . '/../../../../../../includes/functions_content.php'); 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(); $auth = new \phpbb\auth\auth();
$userdata = array( $userdata = array(
'user_id' => 2, 'user_id' => 2,
'user_permissions' => '',
'user_type' => USER_NORMAL,
); );
$auth->acl($userdata); $auth->acl($userdata);
// Pretend to allow downloads // Pretend to allow downloads

View File

@@ -44,8 +44,9 @@ class modules_manager_confirm_box_test extends \board3\portal\tests\testframewor
parent::setUp(); parent::setUp();
$this->language_file_loader = new \phpbb\language\language_file_loader($phpbb_root_path, 'php'); $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);
$user = new \board3\portal\tests\mock\user($this->language, '\phpbb\datetime'); $this->language->add_lang_ext('board3/portal', 'portal_acp');
$user = new \phpbb\user($this->language, '\phpbb\datetime');
$request =new \phpbb_mock_request(); $request =new \phpbb_mock_request();
$this->request = $request; $this->request = $request;
$this->user = $user; $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( $this->portal_helper = new \board3\portal\includes\helper(array(
new \board3\portal\modules\clock($config, null), new \board3\portal\modules\clock($config, null),
new \board3\portal\modules\birthday_list($config, null, $this->db, $user), 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), 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 // Build confirm box first
$this->modules_manager->set_u_action('adm/index.php?i=15&amp;mode=foobar')->set_acp_class('foo\bar'); $this->modules_manager->set_u_action('adm/index.php?i=15&amp;mode=foobar')->set_acp_class('foo\bar');
self::$confirm = false; 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('<input type="hidden" name="i" value="15" /> $this->assertEquals('<input type="hidden" name="i" value="15" />
<input type="hidden" name="mode" value="barfoo" /> <input type="hidden" name="mode" value="barfoo" />
<input type="hidden" name="module_reset" value="1" /> <input type="hidden" name="module_reset" value="1" />
@@ -132,13 +141,13 @@ class modules_manager_confirm_box_test extends \board3\portal\tests\testframewor
// Actually reset module // Actually reset module
phpbb_acp_move_module_test::$override_trigger_error = true; phpbb_acp_move_module_test::$override_trigger_error = true;
self::$confirm = 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( $this->assertEquals(array(
'seconds' => 3, 'seconds' => 3,
'link' => 'adm/index.php?i=-foo-bar&amp;mode=config&amp;module_id=6', 'link' => 'adm/index.php?i=-foo-bar&amp;mode=config&amp;module_id=6',
), self::$meta_refresh); ), self::$meta_refresh);
$this->assertEquals(phpbb_acp_move_module_test::$error_type, E_USER_NOTICE); $this->assertEquals(E_USER_NOTICE, phpbb_acp_move_module_test::$error_type);
$this->assertEquals(phpbb_acp_move_module_test::$error, 'adm/index.php?i=15&amp;mode=foobar&amp;module_id=6'); $this->assertEquals($this->language->lang('MODULE_RESET_SUCCESS') . 'adm/index.php?i=15&amp;mode=foobar&amp;module_id=6', phpbb_acp_move_module_test::$error);
phpbb_acp_move_module_test::$override_trigger_error = false; 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; modules_manager_confirm_box_test::$confirm = true;
$this->assertNull($this->modules_manager->module_delete(6, 'foobar', 'module_delete', 6)); $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(E_USER_NOTICE, phpbb_acp_move_module_test::$error_type);
$this->assertEquals('adm/index.php?i=15&amp;mode=foobar', phpbb_acp_move_module_test::$error); $this->assertEquals($this->language->lang('SUCCESS_DELETE'). 'adm/index.php?i=15&amp;mode=foobar', phpbb_acp_move_module_test::$error);
phpbb_acp_move_module_test::$override_trigger_error = false; phpbb_acp_move_module_test::$override_trigger_error = false;
} }
} }

View File

@@ -37,10 +37,9 @@ class board3_portal_modules_manager_test extends \board3\portal\tests\testframew
parent::setUp(); parent::setUp();
$language = $this->getMockBuilder('\phpbb\language\language') $this->language_file_loader = new \phpbb\language\language_file_loader($phpbb_root_path, 'php');
->disableOriginalConstructor() $this->language = new \board3\portal\tests\mock\language($this->language_file_loader);
->getMock(); $user = new \phpbb\user($this->language, '\phpbb\datetime');
$user = new \board3\portal\tests\mock\user($language, '\phpbb\datetime');
$request =new \phpbb_mock_request(); $request =new \phpbb_mock_request();
$config = new \phpbb\config\config(array()); $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 = new \board3\portal\tests\mock\controller_helper($phpbb_root_path, $phpEx);
$controller_helper->add_route('board3_portal_controller', 'portal'); $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( $portal_helper = new \board3\portal\includes\helper(array(
new \board3\portal\modules\clock($config, null), new \board3\portal\modules\clock($config, null),
new \board3\portal\modules\birthday_list($config, null, $this->db, $user), 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), 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()) ->with($this->anything())
->will($this->returnArgument(2)); ->will($this->returnArgument(2));
$db = $this->db; $db = $this->db;
$user->set(array( $this->language->set(array(
'UNABLE_TO_MOVE' => 'UNABLE_TO_MOVE', 'UNABLE_TO_MOVE' => 'UNABLE_TO_MOVE',
'UNABLE_TO_MOVE_ROW' => 'UNABLE_TO_MOVE_ROW', '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), new \board3\portal\tests\mock\template($this),
$user, $user,
$this->path_helper, $this->path_helper,
$this->portal_helper, $portal_helper,
$phpbb_root_path, $phpbb_root_path,
$phpEx $phpEx
); );