[ticket/701] Fix tests and move declarations to services file
B3P-701
This commit is contained in:
@@ -51,7 +51,9 @@ services:
|
||||
- '@auth'
|
||||
- '@config'
|
||||
- '@controller.helper'
|
||||
- '@dbal.conn'
|
||||
- '@request'
|
||||
- '%tables.styles%'
|
||||
|
||||
board3.portal.columns:
|
||||
class: board3\portal\portal\columns
|
||||
|
||||
@@ -230,16 +230,9 @@ class helper
|
||||
*/
|
||||
public function assign_module_vars($row, $template_module)
|
||||
{
|
||||
$use_fa = 0;
|
||||
$fa_styles = explode(';', $this->config['board3_portal_fa_styles']);
|
||||
foreach ($fa_styles as $fa_style)
|
||||
{
|
||||
if ($this->user->style['style_name'] == $fa_style)
|
||||
{
|
||||
$use_fa = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
$fa_styles = json_decode($this->config['board3_portal_fa_styles']);
|
||||
$use_fa = !empty($fa_styles) && in_array($this->user->style['style_name'], $fa_styles);
|
||||
|
||||
if (is_array($template_module))
|
||||
{
|
||||
$this->template->assign_block_vars('modules_' . $this->portal_columns->number_to_string($row['module_column']), array(
|
||||
@@ -250,8 +243,8 @@ class helper
|
||||
'MODULE_ID' => $row['module_id'],
|
||||
'IMAGE_WIDTH' => $row['module_image_width'],
|
||||
'IMAGE_HEIGHT' => $row['module_image_height'],
|
||||
'FA_ICON' => utf8_htmlspecialchars($row['module_fa_icon']),
|
||||
'FA_SIZE' => $row['module_fa_size'],
|
||||
'FA_ICON' => isset($row['module_fa_icon']) ? utf8_htmlspecialchars($row['module_fa_icon']) : '',
|
||||
'FA_SIZE' => $row['module_fa_size'] ?? '',
|
||||
'FA_ENABLED' => $use_fa,
|
||||
));
|
||||
}
|
||||
@@ -264,8 +257,8 @@ class helper
|
||||
'IMAGE_HEIGHT' => $row['module_image_height'],
|
||||
'MODULE_ID' => $row['module_id'],
|
||||
'TITLE' => (isset($this->user->lang[$row['module_name']])) ? $this->user->lang[$row['module_name']] : utf8_normalize_nfc($row['module_name']),
|
||||
'FA_ICON' => utf8_htmlspecialchars($row['module_fa_icon']),
|
||||
'FA_SIZE' => $row['module_fa_size'],
|
||||
'FA_ICON' => isset($row['module_fa_icon']) ? utf8_htmlspecialchars($row['module_fa_icon']) : '',
|
||||
'FA_SIZE' => $row['module_fa_size'] ?? '',
|
||||
'FA_ENABLED' => $use_fa,
|
||||
));
|
||||
}
|
||||
|
||||
@@ -25,6 +25,9 @@ class modules_helper
|
||||
*/
|
||||
protected $config;
|
||||
|
||||
/** @var \phpbb\db\driver\driver_interface */
|
||||
protected $db;
|
||||
|
||||
/** @var \phpbb\controller\helper Controller helper */
|
||||
protected $controller_helper;
|
||||
|
||||
@@ -34,6 +37,9 @@ class modules_helper
|
||||
*/
|
||||
protected $request;
|
||||
|
||||
/** @var string Styles table */
|
||||
protected $styles_table;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* NOTE: The parameters of this method must match in order and type with
|
||||
@@ -41,14 +47,18 @@ class modules_helper
|
||||
* @param \phpbb\auth\auth $auth Auth object
|
||||
* @param \phpbb\config\config $config phpBB config
|
||||
* @param \phpbb\controller\helper $controller_helper Controller helper
|
||||
* @param \phpbb\db\driver\driver_interface $db Dbal connection
|
||||
* @param \phpbb\request\request $request phpBB request
|
||||
* @param string $styles_table Styles table
|
||||
*/
|
||||
public function __construct($auth, $config, $controller_helper, $request)
|
||||
public function __construct($auth, $config, $controller_helper, $db, $request, string $styles_table)
|
||||
{
|
||||
$this->auth = $auth;
|
||||
$this->config = $config;
|
||||
$this->controller_helper = $controller_helper;
|
||||
$this->db = $db;
|
||||
$this->request = $request;
|
||||
$this->styles_table = $styles_table;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -194,30 +204,27 @@ class modules_helper
|
||||
*
|
||||
* @return string Select with available styles
|
||||
*/
|
||||
public function display_fa_styles()
|
||||
public function display_fa_styles(): string
|
||||
{
|
||||
global $phpbb_container;
|
||||
$table_prefix = $phpbb_container->getParameter('core.table_prefix');
|
||||
$db = $phpbb_container->get('dbal.conn');
|
||||
$selected = explode(';', $this->config['board3_portal_fa_styles']);
|
||||
$portal_fa_styles = json_decode($this->config->offsetGet('board3_portal_fa_styles'));
|
||||
if (!$portal_fa_styles)
|
||||
{
|
||||
$portal_fa_styles = [];
|
||||
}
|
||||
$options = '';
|
||||
$query = 'SELECT style_name
|
||||
FROM ' . $table_prefix . 'styles';
|
||||
$result = $db->sql_query($query);
|
||||
while ($row = $db->sql_fetchrow($result))
|
||||
FROM ' . $this->styles_table;
|
||||
$result = $this->db->sql_query($query);
|
||||
while ($row = $this->db->sql_fetchrow($result))
|
||||
{
|
||||
$options .= '<option value="' . $row['style_name'] . '"';
|
||||
foreach ($selected as $style)
|
||||
{
|
||||
if ($style == $row['style_name'])
|
||||
if (in_array($row['style_name'], $portal_fa_styles))
|
||||
{
|
||||
$options .= ' selected';
|
||||
break;
|
||||
}
|
||||
}
|
||||
$options .= '>' . $row['style_name'] . '</option>';
|
||||
}
|
||||
$db->sql_freeresult($result);
|
||||
$this->db->sql_freeresult($result);
|
||||
return '<select id="board3_fa_styles" name="board3_fa_styles[]" multiple>' . $options . '</select>';
|
||||
}
|
||||
|
||||
@@ -226,15 +233,9 @@ class modules_helper
|
||||
*
|
||||
* @param string $key Key of the parameter
|
||||
*/
|
||||
public function store_fa_styles($key)
|
||||
public function store_fa_styles(string $key): void
|
||||
{
|
||||
$style_array = $this->request->variable($key, array(''));
|
||||
$styles = '';
|
||||
foreach ($style_array as $style)
|
||||
{
|
||||
$styles .= ($styles == '' ? '' : ';') . $style;
|
||||
}
|
||||
var_dump($styles);
|
||||
$this->config->set('board3_portal_fa_styles', $styles);
|
||||
$style_array = $this->request->variable($key, ['']);
|
||||
$this->config->set('board3_portal_fa_styles', json_encode($style_array));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -65,6 +65,7 @@ class phpbb_acp_move_module_test extends \board3\portal\tests\testframework\data
|
||||
$phpbb_container = new \phpbb_mock_container_builder();
|
||||
// Mock module service collection
|
||||
$config = new \phpbb\config\config([]);
|
||||
$db = $this->db;
|
||||
$auth = $this->getMockBuilder('\phpbb\auth\auth')
|
||||
->setMethods(['acl_get'])
|
||||
->getMock();
|
||||
@@ -74,7 +75,7 @@ class phpbb_acp_move_module_test extends \board3\portal\tests\testframework\data
|
||||
->will($this->returnValue(true));
|
||||
$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, new \phpbb_mock_request);
|
||||
$modules_helper = new \board3\portal\includes\modules_helper($auth, $config, $controller_helper, $db, new \phpbb_mock_request, $table_prefix . 'styles');
|
||||
$phpbb_container->set('board3.portal.module_collection',
|
||||
array(
|
||||
new \board3\portal\modules\clock($config, $template),
|
||||
@@ -84,9 +85,10 @@ class phpbb_acp_move_module_test extends \board3\portal\tests\testframework\data
|
||||
));
|
||||
$this->portal_helper = new \board3\portal\includes\helper($phpbb_container->get('board3.portal.module_collection'));
|
||||
$phpbb_container->set('board3.portal.helper', $this->portal_helper);
|
||||
$phpbb_container->set('board3.portal.modules_helper', new \board3\portal\includes\modules_helper(new \phpbb\auth\auth(), $config, $controller_helper, $request));
|
||||
$phpbb_container->set('board3.portal.modules_helper', $modules_helper);
|
||||
$phpbb_container->setParameter('board3.portal.modules.table', $table_prefix . 'portal_modules');
|
||||
$phpbb_container->setParameter('board3.portal.config.table', $table_prefix . 'portal_config');
|
||||
$phpbb_container->setParameter('core.table_prefix', $table_prefix);
|
||||
$this->portal_columns = new \board3\portal\portal\columns();
|
||||
$phpbb_container->set('board3.portal.columns', $this->portal_columns);
|
||||
$cache = $this->getMockBuilder('\phpbb\cache\service')
|
||||
@@ -114,7 +116,6 @@ class phpbb_acp_move_module_test extends \board3\portal\tests\testframework\data
|
||||
->method('sql_save')
|
||||
->with($this->anything())
|
||||
->will($this->returnArgument(2));
|
||||
$db = $this->db;
|
||||
$this->language->set(array(
|
||||
'UNABLE_TO_MOVE' => 'UNABLE_TO_MOVE',
|
||||
'UNABLE_TO_MOVE_ROW' => 'UNABLE_TO_MOVE_ROW',
|
||||
@@ -208,6 +209,8 @@ class phpbb_acp_move_module_test extends \board3\portal\tests\testframework\data
|
||||
'module_image_height' => '0',
|
||||
'module_group_ids' => '',
|
||||
'module_status' => '1',
|
||||
'module_fa_icon' => '',
|
||||
'module_fa_size' => '16',
|
||||
), $module_data);
|
||||
}
|
||||
|
||||
|
||||
@@ -43,6 +43,7 @@ class helper_test extends \board3\portal\tests\testframework\test_case
|
||||
$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->user->style['style_name'] = 'prosilver';
|
||||
$this->phpbb_root_path = dirname(__FILE__) . '/../../../../../../';
|
||||
$phpbb_extension_manager = new \phpbb_mock_extension_manager($this->phpbb_root_path, array('board3/portal'));
|
||||
$this->language_file_loader->set_extension_manager($phpbb_extension_manager);
|
||||
|
||||
@@ -19,7 +19,7 @@ class phpbb_functions_fetch_news_test extends \board3\portal\tests\testframework
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
global $auth, $cache, $config, $phpbb_container, $phpbb_dispatcher, $template, $user, $phpbb_root_path, $phpEx;
|
||||
global $auth, $cache, $config, $phpbb_container, $phpbb_dispatcher, $template, $user, $phpbb_root_path, $phpEx, $table_prefix;
|
||||
|
||||
$config = new \phpbb\config\config([
|
||||
'allow_nocensors' => false,
|
||||
@@ -71,7 +71,7 @@ class phpbb_functions_fetch_news_test extends \board3\portal\tests\testframework
|
||||
$phpbb_container = new \phpbb_mock_container_builder();
|
||||
$controller_helper = new \board3\portal\tests\mock\controller_helper($phpbb_root_path, $phpEx);
|
||||
$controller_helper->add_route('board3_portal_controller', 'portal');
|
||||
$this->modules_helper = new \board3\portal\includes\modules_helper($auth, $this->config, $controller_helper, $request);
|
||||
$this->modules_helper = new \board3\portal\includes\modules_helper($auth, $this->config, $controller_helper, $this->db, $request, $table_prefix . 'styles');
|
||||
$phpbb_container->set('board3.portal.modules_helper', $this->modules_helper);
|
||||
$phpbb_container->set('board3.portal.fetch_posts', new \board3\portal\portal\fetch_posts($auth, $cache, $this->config, $this->db, $this->modules_helper, $user));
|
||||
$template = $this->getMockBuilder('\phpbb\template')
|
||||
|
||||
@@ -26,7 +26,7 @@ class board3_includes_modules_helper_test extends \board3\portal\tests\testframe
|
||||
|
||||
public function setUp(): void
|
||||
{
|
||||
global $phpbb_root_path, $phpEx, $phpbb_dispatcher;
|
||||
global $phpbb_root_path, $phpEx, $phpbb_dispatcher, $table_prefix;
|
||||
|
||||
parent::setUp();
|
||||
|
||||
@@ -35,7 +35,6 @@ class board3_includes_modules_helper_test extends \board3\portal\tests\testframe
|
||||
$request = new \phpbb_mock_request(array('foo' => array('bar')));
|
||||
$controller_helper = new \board3\portal\tests\mock\controller_helper($phpbb_root_path, $phpEx);
|
||||
$controller_helper->add_route('board3_portal_controller', 'portal');
|
||||
$phpbb_container = new \phpbb_mock_container_builder();
|
||||
$phpbb_dispatcher = $this->getMockBuilder('\phpbb\event\dispatcher')
|
||||
->setMethods(['trigger_event'])
|
||||
->getMock();
|
||||
@@ -44,7 +43,7 @@ class board3_includes_modules_helper_test extends \board3\portal\tests\testframe
|
||||
->with($this->anything())
|
||||
->will($this->returnArgument(1));
|
||||
|
||||
$this->modules_helper = new \board3\portal\includes\modules_helper($auth, $this->config, $controller_helper, $request);
|
||||
$this->modules_helper = new \board3\portal\includes\modules_helper($auth, $this->config, $controller_helper, $this->db, $request, $table_prefix . 'styles');
|
||||
$phpbb_dispatcher = new \phpbb_mock_event_dispatcher();
|
||||
}
|
||||
|
||||
|
||||
@@ -38,7 +38,7 @@ class phpbb_unit_modules_calendar_test extends \board3\portal\tests\testframewor
|
||||
public function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
global $cache, $config, $phpbb_root_path, $phpEx, $phpbb_dispatcher, $request, $user;
|
||||
global $cache, $config, $phpbb_root_path, $phpEx, $phpbb_dispatcher, $request, $user, $table_prefix;
|
||||
|
||||
$this->path_helper = new \phpbb\path_helper(
|
||||
new \phpbb\symfony_request(
|
||||
@@ -65,7 +65,7 @@ class phpbb_unit_modules_calendar_test extends \board3\portal\tests\testframewor
|
||||
$this->template = new \board3\portal\tests\mock\template($this);
|
||||
$controller_helper = new \board3\portal\tests\mock\controller_helper($phpbb_root_path, $phpEx);
|
||||
$controller_helper->add_route('board3_portal_controller', 'portal');
|
||||
$modules_helper = new \board3\portal\includes\modules_helper(new \phpbb\auth\auth(), new \phpbb\config\config(array()), $controller_helper, new \phpbb_mock_request());
|
||||
$modules_helper = new \board3\portal\includes\modules_helper(new \phpbb\auth\auth(), new \phpbb\config\config(array()), $controller_helper, $this->db, new \phpbb_mock_request(), $table_prefix . 'styles');
|
||||
$request = $this->request = new \phpbb_mock_request();
|
||||
$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);
|
||||
|
||||
@@ -22,7 +22,7 @@ class phpbb_portal_fetch_posts_test extends \board3\portal\tests\testframework\d
|
||||
|
||||
public function setUp(): void
|
||||
{
|
||||
global $auth, $cache, $config, $phpbb_dispatcher, $phpbb_root_path, $phpEx, $template, $user;
|
||||
global $auth, $cache, $config, $phpbb_dispatcher, $phpbb_root_path, $phpEx, $template, $user, $table_prefix;
|
||||
|
||||
parent::setUp();
|
||||
|
||||
@@ -76,7 +76,7 @@ class phpbb_portal_fetch_posts_test extends \board3\portal\tests\testframework\d
|
||||
$this->auth = $auth;
|
||||
$controller_helper = new \board3\portal\tests\mock\controller_helper($phpbb_root_path, $phpEx);
|
||||
$controller_helper->add_route('board3_portal_controller', 'portal');
|
||||
$this->modules_helper = new \board3\portal\includes\modules_helper($auth, $this->config, $controller_helper, new phpbb_mock_request());
|
||||
$this->modules_helper = new \board3\portal\includes\modules_helper($auth, $this->config, $controller_helper, $this->db, new phpbb_mock_request(), $table_prefix . 'styles');
|
||||
$this->user = $user;
|
||||
$template = $this->getMockBuilder('\phpbb\template')
|
||||
->setMethods(['set_filenames', 'destroy_block_vars', 'assign_block_vars', 'assign_display'])
|
||||
|
||||
@@ -39,7 +39,7 @@ class modules_manager_confirm_box_test extends \board3\portal\tests\testframewor
|
||||
|
||||
public function setUp(): void
|
||||
{
|
||||
global $cache, $db, $portal_config, $phpbb_root_path, $phpEx;
|
||||
global $cache, $db, $portal_config, $phpbb_root_path, $phpEx, $table_prefix;
|
||||
|
||||
parent::setUp();
|
||||
|
||||
@@ -56,7 +56,7 @@ class modules_manager_confirm_box_test extends \board3\portal\tests\testframewor
|
||||
|
||||
$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, $this->db, $this->request, $table_prefix . 'styles');
|
||||
|
||||
$this->portal_helper = new \board3\portal\includes\helper(array(
|
||||
new \board3\portal\modules\clock($config, null),
|
||||
|
||||
@@ -33,7 +33,7 @@ class board3_portal_modules_manager_test extends \board3\portal\tests\testframew
|
||||
|
||||
public function setUp(): void
|
||||
{
|
||||
global $cache, $db, $phpbb_root_path, $phpEx;
|
||||
global $cache, $db, $phpbb_root_path, $phpEx, $table_prefix;
|
||||
|
||||
parent::setUp();
|
||||
|
||||
@@ -47,7 +47,7 @@ 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, $request);
|
||||
$modules_helper = new \board3\portal\includes\modules_helper($auth, $config, $controller_helper, $this->db, $request, $table_prefix . 'styles');
|
||||
|
||||
$portal_helper = new \board3\portal\includes\helper(array(
|
||||
new \board3\portal\modules\clock($config, null),
|
||||
|
||||
Reference in New Issue
Block a user