diff --git a/phpBB/adm/style/acp_bots.html b/phpBB/adm/style/acp_bots.html index b4f8ea5072..8332df7e2b 100644 --- a/phpBB/adm/style/acp_bots.html +++ b/phpBB/adm/style/acp_bots.html @@ -27,7 +27,9 @@

{L_BOT_STYLE_EXPLAIN}
-
+
+ {{ FormsSelect(S_STYLE_OPTIONS) }} +

{L_BOT_LANG_EXPLAIN}
@@ -37,7 +39,9 @@
-
+
+ {{ FormsSelect(S_ACTIVE_OPTIONS) }} +

{L_BOT_AGENT_EXPLAIN}
diff --git a/phpBB/adm/style/acp_users_prefs.html b/phpBB/adm/style/acp_users_prefs.html index 68420389b4..d485d1e113 100644 --- a/phpBB/adm/style/acp_users_prefs.html +++ b/phpBB/adm/style/acp_users_prefs.html @@ -48,7 +48,9 @@
-
+
+ {{ FormsSelect(S_STYLE_OPTIONS) }} +
diff --git a/phpBB/includes/acp/acp_attachments.php b/phpBB/includes/acp/acp_attachments.php index 4eb06bd6f8..0d66dfde4f 100644 --- a/phpBB/includes/acp/acp_attachments.php +++ b/phpBB/includes/acp/acp_attachments.php @@ -180,12 +180,12 @@ class acp_attachments 'allow_pm_attach' => array('lang' => 'ALLOW_PM_ATTACHMENTS', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => false), 'max_attachments' => array('lang' => 'MAX_ATTACHMENTS', 'validate' => 'int:0:999', 'type' => 'number:0:999', 'explain' => false), 'max_attachments_pm' => array('lang' => 'MAX_ATTACHMENTS_PM', 'validate' => 'int:0:999', 'type' => 'number:0:999', 'explain' => false), - 'display_order' => array('lang' => 'DISPLAY_ORDER', 'validate' => 'bool', 'type' => 'custom', 'method' => 'display_order', 'explain' => true), + 'display_order' => array('lang' => 'DISPLAY_ORDER', 'validate' => 'bool', 'type' => 'radio', 'function' => 'phpbb_build_radio', 'params' => ['{CONFIG_VALUE}', '{KEY}', ['DESCENDING', 'ASCENDING']], 'explain' => true), 'attachment_quota' => array('lang' => 'ATTACH_QUOTA', 'validate' => 'string', 'type' => 'custom', 'method' => 'max_filesize', 'explain' => true), 'max_filesize' => array('lang' => 'ATTACH_MAX_FILESIZE', 'validate' => 'string', 'type' => 'custom', 'method' => 'max_filesize', 'explain' => true), 'max_filesize_pm' => array('lang' => 'ATTACH_MAX_PM_FILESIZE','validate' => 'string', 'type' => 'custom', 'method' => 'max_filesize', 'explain' => true), 'secure_downloads' => array('lang' => 'SECURE_DOWNLOADS', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true), - 'secure_allow_deny' => array('lang' => 'SECURE_ALLOW_DENY', 'validate' => 'int', 'type' => 'custom', 'method' => 'select_allow_deny', 'explain' => true), + 'secure_allow_deny' => array('lang' => 'SECURE_ALLOW_DENY', 'validate' => 'int', 'type' => 'radio', 'function' => 'phpbb_build_radio', 'params' => ['{CONFIG_VALUE}', '{KEY}', [1 => 'ORDER_ALLOW_DENY', 0 => 'ORDER_DENY_ALLOW']], 'explain' => true), 'secure_allow_empty_referer' => array('lang' => 'SECURE_EMPTY_REFERRER', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true), 'check_attachment_content' => array('lang' => 'CHECK_CONTENT', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true), @@ -331,7 +331,7 @@ class acp_attachments $l_explain = (isset($user->lang[$vars['lang'] . '_EXPLAIN'])) ? $user->lang[$vars['lang'] . '_EXPLAIN'] : ''; } - $content = build_cfg_template($type, $config_key, $this->new_config, $config_key, $vars); + $content = phpbb_build_cfg_template($type, $config_key, $this->new_config, $config_key, $vars); if (empty($content)) { continue; @@ -1718,16 +1718,6 @@ class acp_attachments } } - /** - * Write display_order config field - */ - function display_order($value, $key = '') - { - $radio_ary = array(0 => 'DESCENDING', 1 => 'ASCENDING'); - - return h_radio('config[display_order]', $radio_ary, $value, $key); - } - /** * Adjust all three max_filesize config vars for display */ @@ -1756,15 +1746,4 @@ class acp_attachments ] ]; } - - /** - * Write secure_allow_deny config field - */ - function select_allow_deny($value, $key = '') - { - $radio_ary = array(1 => 'ORDER_ALLOW_DENY', 0 => 'ORDER_DENY_ALLOW'); - - return h_radio('config[' . $key . ']', $radio_ary, $value, $key); - } - } diff --git a/phpBB/includes/acp/acp_board.php b/phpBB/includes/acp/acp_board.php index d0ced6788f..27d3be83e7 100644 --- a/phpBB/includes/acp/acp_board.php +++ b/phpBB/includes/acp/acp_board.php @@ -86,8 +86,8 @@ class acp_board 'board_timezone' => array('lang' => 'SYSTEM_TIMEZONE', 'validate' => 'timezone', 'type' => 'custom', 'method' => 'timezone_select', 'explain' => true), 'legend2' => 'BOARD_STYLE', - 'default_style' => array('lang' => 'DEFAULT_STYLE', 'validate' => 'int', 'type' => 'select', 'function' => 'style_select', 'params' => array('{CONFIG_VALUE}', false), 'explain' => true), - 'guest_style' => array('lang' => 'GUEST_STYLE', 'validate' => 'int', 'type' => 'select', 'function' => 'style_select', 'params' => array($this->guest_style_get(), false), 'explain' => true), + 'default_style' => array('lang' => 'DEFAULT_STYLE', 'validate' => 'int', 'type' => 'select', 'method' => 'phpbb_style_select', 'params' => array('{CONFIG_VALUE}', false), 'explain' => true), + 'guest_style' => array('lang' => 'GUEST_STYLE', 'validate' => 'int', 'type' => 'select', 'method' => 'phpbb_style_select', 'params' => array($this->guest_style_get(), false), 'explain' => true), 'override_user_style' => array('lang' => 'OVERRIDE_STYLE', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true), 'legend3' => 'WARNINGS', @@ -432,10 +432,10 @@ class acp_board 'allow_autologin' => array('lang' => 'ALLOW_AUTOLOGIN', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true), 'allow_password_reset' => array('lang' => 'ALLOW_PASSWORD_RESET', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true), 'max_autologin_time' => array('lang' => 'AUTOLOGIN_LENGTH', 'validate' => 'int:0:99999', 'type' => 'number:0:99999', 'explain' => true, 'append' => ' ' . $user->lang['DAYS']), - 'ip_check' => array('lang' => 'IP_VALID', 'validate' => 'int', 'type' => 'custom', 'method' => 'select_ip_check', 'explain' => true), + 'ip_check' => array('lang' => 'IP_VALID', 'validate' => 'int', 'type' => 'radio', 'function' => 'phpbb_build_radio', 'params' => ['{CONFIG_VALUE}', '{KEY}', [4 => 'ALL', 3 => 'CLASS_C', 2 => 'CLASS_B', 0 => 'NO_IP_VALIDATION']], 'explain' => true), 'browser_check' => array('lang' => 'BROWSER_VALID', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true), 'forwarded_for_check' => array('lang' => 'FORWARDED_FOR_VALID', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true), - 'referer_validation' => array('lang' => 'REFERRER_VALID', 'validate' => 'int:0:3','type' => 'custom', 'method' => 'select_ref_check', 'explain' => true), + 'referer_validation' => array('lang' => 'REFERRER_VALID', 'validate' => 'int:0:3','type' => 'radio', 'function' => 'phpbb_build_radio', 'params' => ['{CONFIG_VALUE}', '{KEY}', [REFERER_VALIDATE_PATH => 'REF_PATH', REFERER_VALIDATE_HOST => 'REF_HOST', REFERER_VALIDATE_NONE => 'NO_REF_VALIDATION']], 'explain' => true), 'check_dnsbl' => array('lang' => 'CHECK_DNSBL', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true), 'email_check_mx' => array('lang' => 'EMAIL_CHECK_MX', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true), 'min_pass_chars' => array('lang' => 'PASSWORD_LENGTH', 'validate' => 'int:1', 'type' => 'custom', 'method' => 'password_length', 'explain' => true), @@ -798,7 +798,7 @@ class acp_board $l_explain = (isset($user->lang[$vars['lang'] . '_EXPLAIN'])) ? $user->lang[$vars['lang'] . '_EXPLAIN'] : ''; } - $content = build_cfg_template($type, $config_key, $this->new_config, $config_key, $vars); + $content = phpbb_build_cfg_template($type, $config_key, $this->new_config, $config_key, $vars); if (empty($content)) { @@ -851,7 +851,7 @@ class acp_board /* @var $auth_providers \phpbb\auth\provider_collection */ $auth_providers = $phpbb_container->get('auth.provider_collection'); - $auth_plugins = array(); + $auth_plugins = []; foreach ($auth_providers as $key => $value) { @@ -864,14 +864,22 @@ class acp_board sort($auth_plugins); - $auth_select = ''; + $auth_select_options = []; foreach ($auth_plugins as $method) { - $selected = ($selected_method == $method) ? ' selected="selected"' : ''; - $auth_select .= "'; + $auth_select_options[] = [ + 'value' => $method, + 'selected' => $selected_method == $method, + 'label' => ucfirst($method), + 'data' => [ + 'toggle-setting' => "#auth_{$method}_settings", + ], + ]; } - return $auth_select; + return [ + 'options' => $auth_select_options, + ]; } /** @@ -881,15 +889,21 @@ class acp_board { global $user; - $auth_methods = array('PLAIN', 'LOGIN', 'CRAM-MD5', 'DIGEST-MD5', 'POP-BEFORE-SMTP'); - $s_smtp_auth_options = ''; + $auth_methods = ['PLAIN', 'LOGIN', 'CRAM-MD5', 'DIGEST-MD5', 'POP-BEFORE-SMTP']; + $s_smtp_auth_options = []; foreach ($auth_methods as $method) { - $s_smtp_auth_options .= ''; + $s_smtp_auth_options[] = [ + 'value' => $method, + 'selected' => $selected_method == $method, + 'label' => $user->lang('SMTP_' . str_replace('-', '_', $method)), + ]; } - return $s_smtp_auth_options; + return [ + 'options' => $s_smtp_auth_options, + ]; } /** @@ -899,27 +913,22 @@ class acp_board { global $user; - return ''; - } + $full_folder_select_options = [ + 0 => [ + 'value' => 1, + 'selected' => $value == 1, + 'label' => $user->lang('DELETE_OLDEST_MESSAGES'), + ], + 1 => [ + 'value' => 2, + 'selected' => $value == 2, + 'label' => $user->lang('HOLD_NEW_MESSAGES_SHORT'), + ], + ]; - /** - * Select ip validation - */ - function select_ip_check($value, $key = '') - { - $radio_ary = array(4 => 'ALL', 3 => 'CLASS_C', 2 => 'CLASS_B', 0 => 'NO_IP_VALIDATION'); - - return h_radio('config[ip_check]', $radio_ary, $value, $key); - } - - /** - * Select referer validation - */ - function select_ref_check($value, $key = '') - { - $radio_ary = array(REFERER_VALIDATE_PATH => 'REF_PATH', REFERER_VALIDATE_HOST => 'REF_HOST', REFERER_VALIDATE_NONE => 'NO_REF_VALIDATION'); - - return h_radio('config[referer_validation]', $radio_ary, $value, $key); + return [ + 'options' => $full_folder_select_options, + ]; } /** @@ -929,23 +938,28 @@ class acp_board { global $user, $config; - $act_ary = array( - 'ACC_DISABLE' => array(true, USER_ACTIVATION_DISABLE), - 'ACC_NONE' => array(true, USER_ACTIVATION_NONE), - 'ACC_USER' => array($config['email_enable'], USER_ACTIVATION_SELF), - 'ACC_ADMIN' => array($config['email_enable'], USER_ACTIVATION_ADMIN), - ); + $act_ary = [ + 'ACC_DISABLE' => [true, USER_ACTIVATION_DISABLE], + 'ACC_NONE' => [true, USER_ACTIVATION_NONE], + 'ACC_USER' => [$config['email_enable'], USER_ACTIVATION_SELF], + 'ACC_ADMIN' => [$config['email_enable'], USER_ACTIVATION_ADMIN], + ]; - $act_options = ''; + $act_options = []; foreach ($act_ary as $key => $data) { list($available, $value) = $data; - $selected = ($selected_value == $value) ? ' selected="selected"' : ''; - $class = (!$available) ? ' class="disabled-option"' : ''; - $act_options .= ''; + $act_options[] = [ + 'value' => $value, + 'selected' => $selected_value == $value, + 'label' => $user->lang($key), + 'class' => !$available ? 'disabled-option' : '', + ]; } - return $act_options; + return [ + 'options' => $act_options, + ]; } /** @@ -955,7 +969,27 @@ class acp_board { global $user; - return ' ' . $user->lang['MIN_CHARS'] . '   ' . $user->lang['MAX_CHARS']; + return [ + [ + 'tag' => 'input', + 'id' => $key, + 'type' => 'number', + 'name' => 'config[min_name_chars]', + 'min' => 1, + 'max' => 999, + 'value' => $value, + 'append' => $user->lang('MIN_CHARS') . '  ', + ], + [ + 'tag' => 'input', + 'type' => 'number', + 'name' => 'config[max_name_chars]', + 'min' => 8, + 'max' => 180, + 'value' => $this->new_config['max_name_chars'], + 'append' => $user->lang('MAX_CHARS'), + ], + ]; } /** @@ -965,15 +999,20 @@ class acp_board { global $user; - $user_char_ary = array('USERNAME_CHARS_ANY', 'USERNAME_ALPHA_ONLY', 'USERNAME_ALPHA_SPACERS', 'USERNAME_LETTER_NUM', 'USERNAME_LETTER_NUM_SPACERS', 'USERNAME_ASCII'); - $user_char_options = ''; + $user_char_ary = ['USERNAME_CHARS_ANY', 'USERNAME_ALPHA_ONLY', 'USERNAME_ALPHA_SPACERS', 'USERNAME_LETTER_NUM', 'USERNAME_LETTER_NUM_SPACERS', 'USERNAME_ASCII']; + $user_char_options = []; foreach ($user_char_ary as $user_type) { - $selected = ($selected_value == $user_type) ? ' selected="selected"' : ''; - $user_char_options .= ''; + $user_char_options[] = [ + 'value' => $user_type, + 'selected' => $selected_value == $user_type, + 'label' => $user->lang($user_type), + ]; } - return $user_char_options; + return [ + 'options' => $user_char_options, + ]; } /** @@ -983,7 +1022,16 @@ class acp_board { global $user; - return ' ' . $user->lang['MIN_CHARS']; + return [ + [ + 'tag' => 'input', + 'id' => $key, + 'type' => 'number', + 'name' => 'config[min_pass_chars]', + 'value' => $value, + 'append' => $user->lang('MIN_CHARS'), + ], + ]; } /** @@ -994,14 +1042,20 @@ class acp_board global $user; $pass_type_ary = array('PASS_TYPE_ANY', 'PASS_TYPE_CASE', 'PASS_TYPE_ALPHA', 'PASS_TYPE_SYMBOL'); - $pass_char_options = ''; + $pass_char_options = []; foreach ($pass_type_ary as $pass_type) { - $selected = ($selected_value == $pass_type) ? ' selected="selected"' : ''; - $pass_char_options .= ''; + $pass_char_options[] = [ + 'tag' => 'select', + 'value' => $pass_type, + 'selected' => $selected_value == $pass_type, + 'label' => $user->lang[$pass_type], + ]; } - return $pass_char_options; + return [ + 'options' => $pass_char_options, + ]; } /** @@ -1050,7 +1104,22 @@ class acp_board { global $db; - return phpbb_language_select($db, $default, $langdata); + return ['options' => phpbb_language_select($db, $default, $langdata)]; + } + + /** + * Wrapper function for style_select() + * + * @param int|string $default Style ID to be selected in the dropdown list + * @param bool $all Flag indicating if all styles data including inactive should be fetched + * + * @return array + */ + public function phpbb_style_select(int|string $default, bool $all): array + { + global $db; + + return ['options' => style_select($default, $all)]; } /** @@ -1058,9 +1127,20 @@ class acp_board */ function board_disable($value, $key) { - $radio_ary = array(1 => 'YES', 0 => 'NO'); + $options = phpbb_build_radio($value, $key, [1 => 'YES', 0 => 'NO']); - return h_radio('config[board_disable]', $radio_ary, $value) . '
'; + return [ + array_merge(['tag' => 'radio'], $options), + [ + 'tag' => 'input', + 'type' => 'text', + 'name' => 'config[board_disable_msg]', + 'maxlength' => 255, + 'size' => 40, + 'id' => $key, + 'value' => $this->new_config['board_disable_msg'] ?: '', + ], + ]; } /** @@ -1072,7 +1152,7 @@ class acp_board */ public function board_disable_access(int $value) : array { - return [ + return ['options' => [ [ 'value' => 0, 'selected' => $value == 0, @@ -1088,7 +1168,7 @@ class acp_board 'selected' => $value == 2, 'label' => $this->language->lang('DISABLE_BOARD_ACCESS_ADMIN_ALL_MODS'), ], - ]; + ]]; } /** @@ -1096,12 +1176,21 @@ class acp_board */ function quick_reply($value, $key) { - global $user; + global $language; - $radio_ary = array(1 => 'YES', 0 => 'NO'); + $options = phpbb_build_radio($value, $key, [1 => 'YES', 0 => 'NO']); - return h_radio('config[allow_quick_reply]', $radio_ary, $value) . - '

'; + return [ + array_merge(['tag' => 'radio', 'append' => '

'], $options), + [ + 'tag' => 'input', + 'type' => 'submit', + 'class' => 'button2', + 'name' => $key . '_enable', + 'id' => $key . '_enable', + 'value' => $language->lang('ALLOW_QUICK_REPLY_BUTTON'), + ], + ]; } /** @@ -1320,7 +1409,7 @@ class acp_board */ function enable_mod_rewrite($value, $key) { - global $user; + global $language; // Determine whether mod_rewrite is enabled on the server // NOTE: This only works on Apache servers on which PHP is NOT @@ -1347,20 +1436,43 @@ class acp_board $value = ($mod_rewrite === false) ? 0 : $value; $message = $mod_rewrite === null ? 'MOD_REWRITE_INFORMATION_UNAVAILABLE' : ($mod_rewrite === false ? 'MOD_REWRITE_DISABLED' : false); - // Let's do some friendly HTML injection if we want to disable the - // form field because h_radio() has no pretty way of doing so - $field_name = 'config[enable_mod_rewrite]' . ($message === 'MOD_REWRITE_DISABLED' ? '" disabled="disabled' : ''); + $options = phpbb_build_radio($value, $key, [1 => 'YES', 0 => 'NO']); + foreach ($options['buttons'] as $i => $button) + { + $options['buttons'][$i]['disabled'] = $message === 'MOD_REWRITE_DISABLED'; + } - return h_radio($field_name, array(1 => 'YES', 0 => 'NO'), $value) . - ($message !== false ? '
' . $user->lang($message) . '' : ''); + $tpl = array_merge( + [ + 'tag' => 'radio', + 'append' => ($message !== false) ? '
' . $language->lang($message) . '' : '', + ], + $options + ); + + return $tpl; } function send_test_email($value, $key) { global $user; - return ' - '; + return [ + [ + 'tag' => 'input', + 'type' => 'submit', + 'name' => $key, + 'id' => $key, + 'class' => 'button2', + 'value' => $user->lang('SEND_TEST_EMAIL'), + ], + [ + 'tag' => 'textarea', + 'name' => $key . '_text', + 'id' => $key . '_text', + 'placeholder' => $user->lang('MESSAGE'), + ], + ]; } /** diff --git a/phpBB/includes/acp/acp_bots.php b/phpBB/includes/acp/acp_bots.php index 323dd1baee..982a8967b7 100644 --- a/phpBB/includes/acp/acp_bots.php +++ b/phpBB/includes/acp/acp_bots.php @@ -321,12 +321,15 @@ class acp_bots unset($bot_row['user_lang'], $bot_row['user_style']); } - $s_active_options = ''; + $s_active_options = []; $_options = array('0' => 'NO', '1' => 'YES'); foreach ($_options as $value => $lang) { - $selected = ($bot_row['bot_active'] == $value) ? ' selected="selected"' : ''; - $s_active_options .= ''; + $s_active_options[] = [ + 'value' => $value, + 'selected' => $bot_row['bot_active'] == $value, + 'label' => $user->lang($lang), + ]; } $style_select = style_select($bot_row['bot_style'], true); @@ -345,14 +348,22 @@ class acp_bots 'BOT_AGENT' => $bot_row['bot_agent'], 'S_EDIT_BOT' => true, - 'S_ACTIVE_OPTIONS' => $s_active_options, - 'S_STYLE_OPTIONS' => $style_select, + 'S_ACTIVE_OPTIONS' => [ + 'id' => 'bot_active', + 'name' => 'bot_active', + 'options' => $s_active_options, + ], + 'S_STYLE_OPTIONS' => [ + 'id' => 'bot_style', + 'name' => 'bot_style', + 'options' => $style_select, + ], 'LANG_OPTIONS' => [ 'id' => 'bot_lang', 'name' => 'bot_lang', 'options' => $lang_options, ], - 'S_ERROR' => (count($error)) ? true : false, + 'S_ERROR' => (bool) count($error), )); return; diff --git a/phpBB/includes/acp/acp_users.php b/phpBB/includes/acp/acp_users.php index 21f6542410..db429e4f36 100644 --- a/phpBB/includes/acp/acp_users.php +++ b/phpBB/includes/acp/acp_users.php @@ -1842,7 +1842,11 @@ class acp_users 'name' => 'lang', 'options' => $lang_options, ], - 'S_STYLE_OPTIONS' => style_select($data['style']), + 'S_STYLE_OPTIONS' => [ + 'id' => 'style', + 'name' => 'style', + 'options' => style_select($data['style']) + ], 'TIMEZONE_OPTIONS' => [ 'tag' => 'select', 'name' => 'tz', diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index bca9a97c48..68e4e75dda 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -319,11 +319,14 @@ function style_select($default = '', $all = false, array $styledata = []) $db->sql_freeresult($result); } - $style_options = ''; + $style_options = []; foreach ($styledata as $row) { - $selected = ($row['style_id'] == $default) ? ' selected="selected"' : ''; - $style_options .= ''; + $style_options[] = [ + 'value' => $row['style_id'], + 'selected' => $row['style_id'] == $default, + 'label' => $row['style_name'], + ]; } return $style_options; diff --git a/phpBB/includes/functions_acp.php b/phpBB/includes/functions_acp.php index b8f007cdfd..646d2f34d5 100644 --- a/phpBB/includes/functions_acp.php +++ b/phpBB/includes/functions_acp.php @@ -208,14 +208,19 @@ function adm_back_link($u_action) } /** -* Build select field options in acp pages -*/ -function build_select($option_ary, $option_default = false): array + * Build select field options in acp pages + * + * @param array $options_ary Configuration options data + * @param int|string|bool $option_default Configuration option selected value + * + * @return array + */ +function build_select(array $options_ary, int|string|bool $option_default = false): array { global $language; $options = []; - foreach ($option_ary as $value => $title) + foreach ($options_ary as $value => $title) { $options[] = [ 'value' => $value, @@ -228,37 +233,50 @@ function build_select($option_ary, $option_default = false): array } /** -* Build radio fields in acp pages -*/ -function h_radio($name, $input_ary, $input_default = false, $id = false, $key = false, $separator = '') + * Build radio fields in acp pages + * + * @param int|string $value Configuration option value + * @param string $key Configuration option key name + * @param array $options Configuration options data + * representing array of [values => language_keys] + * + * @return array + */ +function phpbb_build_radio(int|string $value, string $key, array $options): array { - global $user; + global $language; - $html = ''; - $id_assigned = false; - foreach ($input_ary as $value => $title) + $buttons = []; + foreach ($options as $val => $title) { - $selected = ($input_default !== false && $value == $input_default) ? ' checked="checked"' : ''; - $html .= '' . $separator; - $id_assigned = true; + $buttons[] = [ + 'type' => 'radio', + 'value' => $val, + 'name' => 'config[' . $key . ']', + 'checked' => $val == $value, + 'label' => $language->lang($title), + ]; } - return $html; + return [ + 'buttons' => $buttons, + ]; } /** - * HTML-less version of build_cfg_template + * Build configuration data arrays or templates for configuration settings * - * @param array $tpl_type Template type - * @param string $key Config key - * @param $new_ary - * @param $config_key - * @param $vars - * @return array + * @param array $tpl_type Configuration setting type data + * @param string $key Configuration option name + * @param array|object $new_ary Updated configuration data + * @param string $config_key Configuration option name + * @param array $vars Configuration setting data + * + * @return array|string */ -function phpbb_build_cfg_template(array $tpl_type, string $key, &$new_ary, $config_key, $vars): array +function phpbb_build_cfg_template(array $tpl_type, string $key, array|object &$new_ary, string $config_key, array $vars): array|string { - global $language; + global $language, $module, $phpbb_dispatcher; $tpl = []; $name = 'config[' . $config_key . ']'; @@ -368,154 +386,102 @@ function phpbb_build_cfg_template(array $tpl_type, string $key, &$new_ary, $conf break; case 'radio': - $tpl_type_cond = explode('_', $tpl_type[1]); - $type_no = $tpl_type_cond[0] != 'disabled' && $tpl_type_cond[0] != 'enabled'; - - $no_button = [ - 'type' => 'radio', - 'name' => $name, - 'value' => 0, - 'checked' => !$new_ary[$config_key], - 'label' => $type_no ? $language->lang('NO') : $language->lang('DISABLED'), - ]; - - $yes_button = [ - 'id' => $key, - 'type' => 'radio', - 'name' => $name, - 'value' => 1, - 'checked' => (bool) $new_ary[$config_key], - 'label' => $type_no ? $language->lang('YES') : $language->lang('ENABLED'), - ]; - - $tpl = ['tag' => 'radio']; - if ($tpl_type_cond[0] == 'yes' || $tpl_type_cond[0] == 'enabled') + if (!isset($vars['method']) && !isset($vars['function'])) { - $tpl['buttons'] = [$yes_button, $no_button]; - } - else - { - $tpl['buttons'] = [$no_button, $yes_button]; - } - break; - } - - return $tpl; -} - -/** -* Build configuration template for acp configuration pages -*/ -function build_cfg_template($tpl_type, $key, &$new_ary, $config_key, $vars) -{ - global $module, $phpbb_dispatcher; - - $tpl = ''; - $name = 'config[' . $config_key . ']'; - - // Make sure there is no notice printed out for non-existent config options (we simply set them) - if (!isset($new_ary[$config_key])) - { - $new_ary[$config_key] = ''; - } - - switch ($tpl_type[0]) - { - case 'password': - case 'text': - case 'url': - case 'email': - case 'tel': - case 'search': - case 'color': - case 'datetime': - case 'datetime-local': - case 'month': - case 'week': - case 'date': - case 'time': - case 'number': - case 'range': - case 'dimension': - case 'textarea': - case 'radio': - $tpl = phpbb_build_cfg_template($tpl_type, $key, $new_ary, $config_key, $vars); - break; - - case 'select': - case 'custom': - - if (isset($vars['method'])) - { - $call = array($module->module, $vars['method']); - } - else if (isset($vars['function'])) - { - $call = $vars['function']; - } - else - { - break; - } - - if (isset($vars['params'])) - { - $args = array(); - foreach ($vars['params'] as $value) + if (in_array($tpl_type[1], ['yes_no', 'enabled_disabled'])) { - switch ($value) - { - case '{CONFIG_VALUE}': - $value = $new_ary[$config_key]; - break; - - case '{KEY}': - $value = $key; - break; - } - - $args[] = $value; + $options = array_reverse(explode('_', strtoupper($tpl_type[1]))); + krsort($options); + $tpl_type = array_merge ($tpl_type, phpbb_build_radio($new_ary[$config_key], $config_key, $options)); } } - else + case 'button': + case 'select': + case 'custom': + $args = []; + $call = $vars['function'] ?? (isset($vars['method']) ? [$module->module, $vars['method']] : false); + + if ($call) { - $args = array($new_ary[$config_key], $key); + if (isset($vars['params'])) + { + foreach ($vars['params'] as $value) + { + switch ($value) + { + case '{CONFIG_VALUE}': + $value = $new_ary[$config_key]; + break; + + case '{KEY}': + $value = $config_key; + break; + } + + $args[] = $value; + } + } + else + { + $args = array($new_ary[$config_key], $config_key); + } } - $return = call_user_func_array($call, $args); + $return = $call ? call_user_func_array($call, $args) : []; - if ($tpl_type[0] == 'select') + if (in_array($tpl_type[0], ['select', 'radio', 'button'])) { - $size = (isset($tpl_type[1])) ? (int) $tpl_type[1] : 1; + $tpl_type = array_merge($tpl_type, $return); - if (is_string($return)) + if ($tpl_type[0] == 'select') { - $data_toggle = (!empty($tpl_type[2])) ? ' data-togglable-settings="true"' : ''; + $tpl = [ + 'tag' => 'select', + 'class' => $tpl_type['class'] ?? false, + 'id' => $key, + 'data' => $tpl_type['data'] ?? [], + 'name' => $name, + 'toggleable' => !empty($tpl_type[2]) || !empty($tpl_type['toggleable']), + 'options' => $tpl_type['options'], + 'group_only' => $tpl_type['group_only'] ?? false, + 'size' => $tpl_type[1] ?? $tpl_type['size'] ?? 1, + 'multiple' => $tpl_type['multiple'] ?? false, + ]; + } + else if ($tpl_type[0] == 'radio') + { + // Only assign id to the one (1st) radio button in the list + $id_assigned = false; + foreach ($tpl_type['buttons'] as $i => $button) + { + if (!$id_assigned) + { + $tpl_type['buttons'][$i]['id'] = $key; + $id_assigned = true; + } + } - $tpl = ''; + $tpl = [ + 'tag' => 'radio', + 'buttons' => $tpl_type['buttons'], + ]; } else { $tpl = [ - 'tag' => 'select', - 'id' => $key, - 'name' => $name, - 'toggleable' => !empty($tpl_type[2]), - 'options' => $return, + 'tag' => 'input', + 'class' => $tpl_type['options']['class'], + 'id' => $key, + 'type' => $tpl_type['options']['type'], + 'name' => $tpl_type['options']['name'] ?? $name, + 'value' => $tpl_type['options']['value'], ]; - - // Add size if it differs from default value of 1 - if ($size != 1) - { - $tpl['size'] = $size; - } } } else { $tpl = $return; } - break; default: @@ -539,16 +505,17 @@ function build_cfg_template($tpl_type, $key, &$new_ary, $config_key, $vars) * Overwrite the html code we display for the config value * * @event core.build_config_template - * @var array tpl_type Config type array: - * 0 => data type - * 1 [optional] => string: size, int: minimum - * 2 [optional] => string: max. length, int: maximum - * @var string key Should be used for the id attribute in html - * @var array new Array with the config values we display - * @var string name Should be used for the name attribute - * @var array vars Array with the options for the config - * @var string tpl The resulting html code we display + * @var array tpl_type Config type array: + * 0 => data type + * 1 [optional] => string: size, int: minimum + * 2 [optional] => string: max. length, int: maximum + * @var string key Should be used for the id attribute in html + * @var array new Array with the config values we display + * @var string name Should be used for the name attribute + * @var array vars Array with the options for the config + * @var array|string tpl The resulting html code we display * @since 3.1.0-a1 + * @changed 4.0.0-a1 The event location's function renamed from build_config_template() to phpbb_build_cfg_template() */ $vars = array('tpl_type', 'key', 'new', 'name', 'vars', 'tpl'); extract($phpbb_dispatcher->trigger_event('core.build_config_template', compact($vars))); diff --git a/phpBB/includes/ucp/ucp_prefs.php b/phpBB/includes/ucp/ucp_prefs.php index d2fc72621d..8c682cebc0 100644 --- a/phpBB/includes/ucp/ucp_prefs.php +++ b/phpBB/includes/ucp/ucp_prefs.php @@ -179,7 +179,7 @@ class ucp_prefs $lang_options = phpbb_language_select($db, $data['lang'], $lang_row); - $template->assign_vars(array( + $template->assign_vars([ 'ERROR' => (count($error)) ? implode('
', $error) : '', 'S_NOTIFY_EMAIL' => ($data['notifymethod'] == NOTIFY_EMAIL) ? true : false, @@ -205,15 +205,19 @@ class ucp_prefs 'name' => 'lang', 'options' => $lang_options, ], - 'S_STYLE_OPTIONS' => ($config['override_user_style']) ? '' : style_select($data['user_style'], false, $styles_row), + 'S_STYLE_OPTIONS' => ($config['override_user_style']) ? '' : [ + 'id' => 'user_style', + 'name' => 'user_style', + 'options' => style_select($data['user_style'], false, $styles_row) + ], 'TIMEZONE_OPTIONS' => [ 'tag' => 'select', 'name' => 'tz', 'options' => $timezone_select, ], - 'S_CAN_HIDE_ONLINE' => ($auth->acl_get('u_hideonline')) ? true : false, - 'S_SELECT_NOTIFY' => ($config['jab_enable'] && $user->data['user_jabber'] && @extension_loaded('xml')) ? true : false) - ); + 'S_CAN_HIDE_ONLINE' => (bool) $auth->acl_get('u_hideonline'), + 'S_SELECT_NOTIFY' => (bool) ($config['jab_enable'] && $user->data['user_jabber'] && @extension_loaded('xml')), + ]); break; diff --git a/phpBB/phpbb/template/twig/extension/forms.php b/phpBB/phpbb/template/twig/extension/forms.php index 4d8de94b9d..5a3d9420db 100644 --- a/phpBB/phpbb/template/twig/extension/forms.php +++ b/phpBB/phpbb/template/twig/extension/forms.php @@ -129,6 +129,7 @@ class forms extends AbstractExtension 'MAX' => (int) ($form_data['max'] ?? 0), 'STEP' => (int) ($form_data['step'] ?? 0), 'CHECKED' => (bool) ($form_data['checked'] ?? false), + 'DISABLED' => (bool) ($form_data['disabled'] ?? false), 'VALUE' => (string) ($form_data['value']), ]); } @@ -151,10 +152,7 @@ class forms extends AbstractExtension try { return $environment->render('macros/forms/radio_buttons.twig', [ - 'FIRST_BUTTON' => $form_data['buttons'][0], - 'FIRST_BUTTON_LABEL' => $form_data['buttons'][0]['label'], - 'SECOND_BUTTON' => $form_data['buttons'][1], - 'SECOND_BUTTON_LABEL' => $form_data['buttons'][1]['label'], + 'BUTTONS' => $form_data['buttons'], ]); } catch (\Twig\Error\Error $e) @@ -179,7 +177,7 @@ class forms extends AbstractExtension 'CLASS' => (string) ($form_data['class'] ?? ''), 'ID' => (string) ($form_data['id'] ?? ''), 'DATA' => $form_data['data'] ?? [], - 'NAME' => (string) $form_data['name'], + 'NAME' => (string) ($form_data['name'] ?? ''), 'TOGGLEABLE' => (bool) ($form_data['toggleable'] ?? false), 'OPTIONS' => $form_data['options'] ?? [], 'GROUP_ONLY' => (bool) ($form_data['group_only'] ?? false), @@ -206,13 +204,14 @@ class forms extends AbstractExtension try { return $environment->render('macros/forms/textarea.twig', [ - 'CLASS' => (string) ($form_data['class'] ?? ''), + 'CLASS' => (string) ($form_data['class'] ?? ''), 'ID' => (string) $form_data['id'], - 'DATA' => $form_data['data'] ?? [], + 'DATA' => $form_data['data'] ?? [], 'NAME' => (string) $form_data['name'], - 'ROWS' => (int) $form_data['rows'], - 'COLS' => (int) $form_data['cols'], - 'CONTENT' => (string) $form_data['content'], + 'ROWS' => (int) ($form_data['rows'] ?? ''), + 'COLS' => (int) ($form_data['cols'] ?? ''), + 'CONTENT' => (string) ($form_data['content'] ?? ''), + 'PLACEHOLDER' => (string) ($form_data['placeholder'] ?? ''), ]); } catch (\Twig\Error\Error $e) diff --git a/phpBB/styles/all/template/macros/forms/input.twig b/phpBB/styles/all/template/macros/forms/input.twig index 1a2ff13fa3..4016ad9da3 100644 --- a/phpBB/styles/all/template/macros/forms/input.twig +++ b/phpBB/styles/all/template/macros/forms/input.twig @@ -1,4 +1,4 @@ -{% apply replace({"\n": ' ', "\t": ''}) %} +{% apply replace({"\n\t": ' ', "\t": '', "\n": ''}) %} {% endapply %} diff --git a/phpBB/styles/all/template/macros/forms/radio_buttons.twig b/phpBB/styles/all/template/macros/forms/radio_buttons.twig index 1ef7804c29..4d5b5c438a 100644 --- a/phpBB/styles/all/template/macros/forms/radio_buttons.twig +++ b/phpBB/styles/all/template/macros/forms/radio_buttons.twig @@ -1,2 +1,3 @@ - - +{% for button in BUTTONS %} + +{% endfor %} diff --git a/phpBB/styles/all/template/macros/forms/select.twig b/phpBB/styles/all/template/macros/forms/select.twig index 3cab1e7199..827ccb1121 100644 --- a/phpBB/styles/all/template/macros/forms/select.twig +++ b/phpBB/styles/all/template/macros/forms/select.twig @@ -1,4 +1,4 @@ -{% apply replace({"\n": ' ', "\t": ''}) %} +{% apply replace({"\n\t": ' ', "\t": '', "\n": ''}) %} +{% endapply %} diff --git a/phpBB/styles/all/template/macros/forms/textarea.twig b/phpBB/styles/all/template/macros/forms/textarea.twig index e4fada13f2..10934f067f 100644 --- a/phpBB/styles/all/template/macros/forms/textarea.twig +++ b/phpBB/styles/all/template/macros/forms/textarea.twig @@ -1,10 +1,11 @@ -{% apply replace({"\n": ' ', '\t': ''}) %} +{% apply replace({"\n": ' ', '\t': ''}) %} + cols="{{ COLS }}" + {% if PLACEHOLDER %}placeholder="{{ PLACEHOLDER }}"{% endif %}>{% endapply %}{{ CONTENT }} diff --git a/phpBB/styles/prosilver/template/ucp_prefs_personal.html b/phpBB/styles/prosilver/template/ucp_prefs_personal.html index 4e81b78fb3..fe1ea17c74 100644 --- a/phpBB/styles/prosilver/template/ucp_prefs_personal.html +++ b/phpBB/styles/prosilver/template/ucp_prefs_personal.html @@ -61,7 +61,9 @@
-
+
+ {{ FormsSelect(S_STYLE_OPTIONS) }} +
diff --git a/tests/acp_board/select_auth_method_test.php b/tests/acp_board/select_auth_method_test.php index e06b5f845d..a9efdbc0ad 100644 --- a/tests/acp_board/select_auth_method_test.php +++ b/tests/acp_board/select_auth_method_test.php @@ -22,8 +22,36 @@ class phpbb_acp_board_select_auth_method_test extends phpbb_test_case public static function select_auth_method_data() { return [ - ['acp_board_valid', ''], - ['acp_board_invalid', ''], + [ + 'acp_board_valid', + [ + 'options' => [ + 0 => [ + 'value' => 'acp_board_valid', + 'label' => 'Acp_board_valid', + 'selected' => true, + 'data' => [ + 'toggle-setting' => '#auth_acp_board_valid_settings', + ], + ] + ], + ] + ], + [ + 'acp_board_invalid', + [ + 'options' => [ + 0 => [ + 'value' => 'acp_board_valid', + 'label' => 'Acp_board_valid', + 'selected' => false, + 'data' => [ + 'toggle-setting' => '#auth_acp_board_valid_settings', + ], + ] + ], + ] + ], ]; } diff --git a/tests/avatar/manager_test.php b/tests/avatar/manager_test.php index 19b7797eb4..3af80b8a40 100644 --- a/tests/avatar/manager_test.php +++ b/tests/avatar/manager_test.php @@ -191,9 +191,14 @@ class phpbb_avatar_manager_test extends \phpbb_database_test_case { $avatar_settings = $this->manager->get_avatar_settings($this->avatar_foobar); - $expected_settings = array( - 'allow_avatar_' . get_class($this->avatar_foobar) => array('lang' => 'ALLOW_' . strtoupper(get_class($this->avatar_foobar)), 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true), - ); + $expected_settings = [ + 'allow_avatar_' . get_class($this->avatar_foobar) => [ + 'lang' => 'ALLOW_' . strtoupper(get_class($this->avatar_foobar)), + 'validate' => 'bool', + 'type' => 'radio:yes_no', + 'explain' => true + ], + ]; $this->assertEquals($expected_settings, $avatar_settings); } diff --git a/tests/functional/acp_main_test.php b/tests/functional/acp_main_test.php index d392102e1a..2caa3bbae2 100644 --- a/tests/functional/acp_main_test.php +++ b/tests/functional/acp_main_test.php @@ -28,4 +28,42 @@ class phpbb_functional_acp_main_test extends phpbb_functional_test_case $this->assertContainsLang('DATABASE_SIZE', $crawler->filter('tbody > tr')->eq(2)->filter('td[class="tabled"]')->eq(0)->text()); $this->assertNotContainsLang('NOT_AVAILABLE', $crawler->filter('tbody > tr')->eq(2)->filter('td[class="tabled"]')->eq(1)->text()); } + + public function test_all_acp_module_links() + { + $this->add_lang('common'); + $this->login(); + $this->admin_login(); + + // Browse ACP main page + $crawler = self::request('GET', 'index.php'); + $crawler = self::$client->click($crawler->selectLink($this->lang('ACP_SHORT'))->link()); + + // Get all ACP module URLs array + $acp_modules = $crawler->filter('.tabs a')->each( + function ($node, $i) + { + return $node->link(); + } + ); + + // Browse all ACP modules and get their mode URLs array + $acp_submodules = []; + foreach ($acp_modules as $module) + { + $crawler = self::$client->click($module); + $acp_submodules = array_merge($acp_submodules, $crawler->filter('.menu-block > ul a')->each( + function ($node, $i) + { + return $node->link(); + } + )); + } + + // Browse all ACP submodules' modes + foreach ($acp_submodules as $acp_submodule) + { + self::$client->click($acp_submodule); + } + } } diff --git a/tests/functional/extension_module_test.php b/tests/functional/extension_module_test.php index 67dc35ae73..0e56e43c78 100644 --- a/tests/functional/extension_module_test.php +++ b/tests/functional/extension_module_test.php @@ -54,6 +54,7 @@ class phpbb_functional_extension_module_test extends phpbb_functional_test_case public function test_acp() { + $this->add_lang('common'); $this->login(); $this->admin_login(); @@ -64,43 +65,86 @@ class phpbb_functional_extension_module_test extends phpbb_functional_test_case $this->assertStringContainsString('SETTING_0', $crawler->filter('dl')->eq(0)->filter('dt > label[for="setting_0"]')->text()); $this->assertStringContainsString('SETTING_0_EXPLAIN', $crawler->filter('dl')->eq(0)->filter('dt > span')->text()); $this->assertEquals(2, $crawler->filter('dl')->eq(0)->filter('dd > input[type="number"]')->count()); + $this->assertEquals(1, $crawler->filter('dl')->eq(0)->filter('dd > input[type="number"]')->eq(0)->attr('value')); + $this->assertEquals(17, $crawler->filter('dl')->eq(0)->filter('dd > input[type="number"]')->eq(1)->attr('value')); $this->assertStringContainsString('SETTING_1', $crawler->filter('dl')->eq(1)->filter('dt > label[for="setting_1"]')->text()); $this->assertStringContainsString('CUSTOM_LANG_EXPLAIN', $crawler->filter('dl')->eq(1)->filter('dt > span')->text()); $this->assertEquals(1, $crawler->filter('dl')->eq(1)->filter('dd > input[type="submit"]')->count()); + $this->assertEquals('Test submit button', $crawler->filter('dl')->eq(1)->filter('dd > input[type="submit"]')->attr('value')); $this->assertStringContainsString('SETTING_2', $crawler->filter('dl')->eq(2)->filter('dt > label[for="setting_2"]')->text()); $this->assertEquals(0, $crawler->filter('dl')->eq(2)->filter('dt > span')->count()); $this->assertEquals(2, $crawler->filter('dl')->eq(2)->filter('dd > label > input[type="radio"]')->count()); + $this->assertContainsLang('YES', $crawler->filter('dl')->eq(2)->filter('dd > label')->eq(0)->text()); + $this->assertEquals(1, $crawler->filter('dl')->eq(2)->filter('dd > label > input[type="radio"]')->eq(0)->attr('value')); + $this->assertEquals('checked', $crawler->filter('dl')->eq(2)->filter('dd > label > input[type="radio"]')->eq(0)->attr('checked')); + $this->assertContainsLang('NO', $crawler->filter('dl')->eq(2)->filter('dd > label')->eq(1)->text()); + $this->assertEquals(0, $crawler->filter('dl')->eq(2)->filter('dd > label > input[type="radio"]')->eq(1)->attr('value')); $this->assertStringContainsString('SETTING_3', $crawler->filter('dl')->eq(3)->filter('dt > label[for="setting_3"]')->text()); $this->assertStringContainsString('SETTING_3_EXPLAIN', $crawler->filter('dl')->eq(3)->filter('dt > span')->text()); $this->assertEquals(1, $crawler->filter('dl')->eq(3)->filter('dd > input[type="number"]')->count()); + $this->assertEquals(15, $crawler->filter('dl')->eq(3)->filter('dd > input[type="number"]')->attr('value')); $this->assertStringContainsString('SETTING_4', $crawler->filter('dl')->eq(4)->filter('dt > label[for="setting_4"]')->text()); $this->assertStringContainsString('SETTING_4_EXPLAIN', $crawler->filter('dl')->eq(4)->filter('dt > span')->text()); $this->assertEquals(1, $crawler->filter('dl')->eq(4)->filter('dd > select[id="setting_4"]')->count()); $this->assertEquals(3, $crawler->filter('dl')->eq(4)->filter('dd > select > option')->count()); + $this->assertEquals(2, $crawler->filter('dl')->eq(4)->filter('dd > select > option')->eq(1)->attr('value')); + $this->assertEquals('selected', $crawler->filter('dl')->eq(4)->filter('dd > select > option')->eq(1)->attr('selected')); $this->assertStringContainsString('SETTING_5', $crawler->filter('dl')->eq(5)->filter('dt > label[for="setting_5"]')->text()); $this->assertStringContainsString('SETTING_5_EXPLAIN', $crawler->filter('dl')->eq(5)->filter('dt > span')->text()); $this->assertEquals(1, $crawler->filter('dl')->eq(5)->filter('dd > input[type="text"]')->count()); + $this->assertEquals('Setting 5', $crawler->filter('dl')->eq(5)->filter('dd > input[type="text"]')->attr('value')); $this->assertStringContainsString('SETTING_6', $crawler->filter('dl')->eq(6)->filter('dt > label[for="setting_6"]')->text()); $this->assertStringContainsString('SETTING_6_EXPLAIN', $crawler->filter('dl')->eq(6)->filter('dt > span')->text()); $this->assertEquals(1, $crawler->filter('dl')->eq(6)->filter('dd > input[type="password"]')->count()); + $this->assertEquals('********', $crawler->filter('dl')->eq(6)->filter('dd > input[type="password"]')->attr('value')); $this->assertStringContainsString('SETTING_7', $crawler->filter('dl')->eq(7)->filter('dt > label[for="setting_7"]')->text()); $this->assertStringContainsString('SETTING_7_EXPLAIN', $crawler->filter('dl')->eq(7)->filter('dt > span')->text()); $this->assertEquals(1, $crawler->filter('dl')->eq(7)->filter('dd > input[type="email"]')->count()); + $this->assertEquals('test@example.dom', $crawler->filter('dl')->eq(7)->filter('dd > input[type="email"]')->attr('value')); $this->assertStringContainsString('SETTING_8', $crawler->filter('dl')->eq(8)->filter('dt > label[for="setting_8"]')->text()); $this->assertStringContainsString('SETTING_8_EXPLAIN', $crawler->filter('dl')->eq(8)->filter('dt > span')->text()); $this->assertEquals(1, $crawler->filter('dl')->eq(8)->filter('dd > textarea[name="config[setting_8]"]')->count()); + $this->assertEquals('Textarea', $crawler->filter('dl')->eq(8)->filter('dd > textarea[name="config[setting_8]"]')->text()); $this->assertStringContainsString('SETTING_9', $crawler->filter('dl')->eq(9)->filter('dt > label[for="setting_9"]')->text()); $this->assertStringContainsString('SETTING_9_EXPLAIN', $crawler->filter('dl')->eq(9)->filter('dt > span')->text()); $this->assertEquals(2, $crawler->filter('dl')->eq(9)->filter('dd > label > input[type="radio"]')->count()); + $this->assertEquals('checked', $crawler->filter('dl')->eq(9)->filter('dd > label > input[type="radio"]')->eq(0)->attr('checked')); + + $this->assertStringContainsString('SETTING_10', $crawler->filter('dl')->eq(10)->filter('dt > label[for="setting_10"]')->text()); + $this->assertStringContainsString('SETTING_10_EXPLAIN', $crawler->filter('dl')->eq(10)->filter('dt > span')->text()); + $this->assertEquals(3, $crawler->filter('dl')->eq(10)->filter('dd > label > input[type="radio"]')->count()); + $this->assertEquals(1, $crawler->filter('dl')->eq(10)->filter('dd > label > input[type="radio"]')->eq(0)->attr('value')); + $this->assertStringContainsString('LABEL_1', $crawler->filter('dl')->eq(10)->filter('dd > label')->eq(0)->text()); + $this->assertEquals(3, $crawler->filter('dl')->eq(10)->filter('dd > label > input[type="radio"]')->eq(1)->attr('value')); + $this->assertEquals('checked', $crawler->filter('dl')->eq(10)->filter('dd > label > input[type="radio"]')->eq(1)->attr('checked')); + $this->assertStringContainsString('LABEL_3', $crawler->filter('dl')->eq(10)->filter('dd > label')->eq(1)->text()); + $this->assertEquals(2, $crawler->filter('dl')->eq(10)->filter('dd > label > input[type="radio"]')->eq(2)->attr('value')); + $this->assertStringContainsString('LABEL_2', $crawler->filter('dl')->eq(10)->filter('dd > label')->eq(2)->text()); + + $this->assertStringContainsString('SETTING_11', $crawler->filter('dl')->eq(11)->filter('dt > label[for="setting_11"]')->text()); + $this->assertStringContainsString('SETTING_11_EXPLAIN', $crawler->filter('dl')->eq(11)->filter('dt > span')->text()); + $this->assertEquals('1', $crawler->filter('dl')->eq(11)->filter('dd > label > input[type="radio"]')->eq(0)->attr('value')); + $this->assertEquals('0', $crawler->filter('dl')->eq(11)->filter('dd > label > input[type="radio"]')->eq(1)->attr('value')); + $this->assertEquals('checked', $crawler->filter('dl')->eq(11)->filter('dd > label > input[type="radio"]')->eq(1)->attr('checked')); + $this->assertContainsLang('YES', $crawler->filter('dl')->eq(11)->filter('dd > label')->eq(0)->text()); + $this->assertContainsLang('NO', $crawler->filter('dl')->eq(11)->filter('dd > label')->eq(1)->text()); + + $this->assertStringContainsString('SETTING_12', $crawler->filter('dl')->eq(12)->filter('dt > label[for="setting_12"]')->text()); + $this->assertStringContainsString('SETTING_12_EXPLAIN', $crawler->filter('dl')->eq(12)->filter('dt > span')->text()); + $this->assertContainsLang('ENABLED', $crawler->filter('dl')->eq(12)->filter('dd > label')->eq(0)->text()); + $this->assertEquals(1, $crawler->filter('dl')->eq(12)->filter('dd > label > input[type="radio"]')->eq(0)->attr('value')); + $this->assertContainsLang('DISABLED', $crawler->filter('dl')->eq(12)->filter('dd > label')->eq(1)->text()); + $this->assertEquals(0, $crawler->filter('dl')->eq(12)->filter('dd > label > input[type="radio"]')->eq(1)->attr('value')); + $this->assertEquals('checked', $crawler->filter('dl')->eq(12)->filter('dd > label > input[type="radio"]')->eq(1)->attr('checked')); } public function test_ucp() diff --git a/tests/functional/fixtures/ext/foo/bar/acp/main_module.php b/tests/functional/fixtures/ext/foo/bar/acp/main_module.php index 08cb73da07..ec9e8d0145 100644 --- a/tests/functional/fixtures/ext/foo/bar/acp/main_module.php +++ b/tests/functional/fixtures/ext/foo/bar/acp/main_module.php @@ -41,18 +41,39 @@ class main_module 'setting_0_height' => ['lang' => 'SETTING_0', 'validate' => 'int:0', 'type' => false, 'method' => false, 'explain' => false], 'setting_0' => ['lang' => 'SETTING_0', 'validate' => 'int:0:16', 'type' => 'dimension:0:999', 'explain' => true, 'append' => ' ' . $language->lang('PIXEL')], 'setting_1' => ['lang' => 'SETTING_1', 'validate' => 'bool', 'type' => 'custom', 'method' => 'submit_button', 'lang_explain' => 'CUSTOM_LANG_EXPLAIN', 'explain' => true], - 'setting_2' => ['lang' => 'SETTING_2', 'validate' => 'bool', 'type' => 'radio:yes_no'], + 'setting_2' => ['lang' => 'SETTING_2', 'validate' => 'bool', 'type' => 'radio', 'function' => 'phpbb_build_radio', 'params' => ['{CONFIG_VALUE}', '{KEY}', [1 => 'YES', 0 => 'NO']]], 'setting_3' => ['lang' => 'SETTING_3', 'validate' => 'int:0:99999','type' => 'number:0:99999', 'explain' => true], 'setting_4' => ['lang' => 'SETTING_4', 'validate' => 'string', 'type' => 'select', 'method' => 'create_select', 'explain' => true], 'setting_5' => ['lang' => 'SETTING_5', 'validate' => 'string', 'type' => 'text:25:255', 'explain' => true], 'setting_6' => ['lang' => 'SETTING_6', 'validate' => 'string', 'type' => 'password:25:255', 'explain' => true], 'setting_7' => ['lang' => 'SETTING_7', 'validate' => 'email', 'type' => 'email:0:100', 'explain' => true], 'setting_8' => ['lang' => 'SETTING_8', 'validate' => 'string', 'type' => 'textarea:5:30', 'explain' => true], - 'setting_9' => ['lang' => 'SETTING_9', 'validate' => 'bool', 'type' => 'radio:enabled_disabled', 'explain' => true], + 'setting_9' => ['lang' => 'SETTING_9', 'validate' => 'bool', 'type' => 'radio', 'function' => 'phpbb_build_radio', 'params' => ['{CONFIG_VALUE}', '{KEY}', [1 => 'ENABLED', 0 => 'DISABLED']], 'explain' => true], + 'setting_10'=> ['lang' => 'SETTING_10', 'validate' => 'int', 'type' => 'radio', 'function' => 'phpbb_build_radio', 'params' => ['{CONFIG_VALUE}', '{KEY}', [1 => 'LABEL_1', 3 => 'LABEL_3', 2 => 'LABEL_2']], 'explain' => true], + 'setting_11'=> ['lang' => 'SETTING_11', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true], + 'setting_12'=> ['lang' => 'SETTING_12', 'validate' => 'bool', 'type' => 'radio:enabled_disabled', 'explain' => true], ] ]; - $this->new_config = $cfg_array = $error = []; + $config = new \phpbb\config\config([ + 'setting_0_width' => '1', + 'setting_0_height' => '17', + 'setting_0' => '10', + 'setting_2' => '1', + 'setting_3' => '15', + 'setting_4' => '2', + 'setting_5' => 'Setting 5', + 'setting_6' => 'password', + 'setting_7' => 'test@example.dom', + 'setting_8' => 'Textarea', + 'setting_9' => '1', + 'setting_10' => '3', + 'setting_11' => '0', + 'setting_12' => '0', + ]); + $this->new_config = clone $config; + $cfg_array = (isset($_REQUEST['config'])) ? $request->variable('config', ['' => ''], true) : $this->new_config; + $error = []; validate_config_vars($display_vars['vars'], $cfg_array, $error); @@ -104,7 +125,7 @@ class main_module $l_explain = $language->lang($vars['lang_explain'] ?: $vars['lang'] . '_EXPLAIN'); } - $content = build_cfg_template($type, $config_key, $this->new_config, $config_key, $vars); + $content = phpbb_build_cfg_template($type, $config_key, $this->new_config, $config_key, $vars); if (empty($content)) { @@ -123,13 +144,15 @@ class main_module } } - function create_select() + function create_select($value) { - return ' - - - - '; + $options = [ + 1 => 'Option 1', + 2 => 'Option 2', + 3 => 'Option 3', + ]; + + return ['options' => build_select($options, $value)]; } function submit_button() diff --git a/tests/functions/style_select_test.php b/tests/functions/style_select_test.php index e36b799bde..aadacadb02 100644 --- a/tests/functions/style_select_test.php +++ b/tests/functions/style_select_test.php @@ -20,14 +20,119 @@ class phpbb_functions_style_select_test extends phpbb_database_test_case static public function style_select_data() { - return array( - array('', false, ''), - array('', true, ''), - array('1', false, ''), - array('1', true, ''), - array('3', false, ''), - array('3', true, ''), - ); + return [ + [ + '', + false, + [ + [ + 'value' => '1', + 'selected' => false, + 'label' => 'prosilver', + ], + [ + 'value' => '2', + 'selected' => false, + 'label' => 'subsilver2', + ], + ] + ], + [ + '', + true, + [ + [ + 'value' => '1', + 'selected' => false, + 'label' => 'prosilver', + ], + [ + 'value' => '2', + 'selected' => false, + 'label' => 'subsilver2', + ], + [ + 'value' => '3', + 'selected' => false, + 'label' => 'zoo', + ], + ] + ], + [ + '1', + false, + [ + [ + 'value' => '1', + 'selected' => true, + 'label' => 'prosilver', + ], + [ + 'value' => '2', + 'selected' => false, + 'label' => 'subsilver2', + ], + ] + ], + [ + '1', + true, + [ + [ + 'value' => '1', + 'selected' => true, + 'label' => 'prosilver', + ], + [ + 'value' => '2', + 'selected' => false, + 'label' => 'subsilver2', + ], + [ + 'value' => '3', + 'selected' => false, + 'label' => 'zoo', + ], + ] + ], + [ + '3', + false, + [ + [ + 'value' => '1', + 'selected' => false, + 'label' => 'prosilver', + ], + [ + 'value' => '2', + 'selected' => false, + 'label' => 'subsilver2', + ], + ] + ], + [ + '3', + true, + [ + [ + 'value' => '1', + 'selected' => false, + 'label' => 'prosilver', + ], + [ + 'value' => '2', + 'selected' => false, + 'label' => 'subsilver2', + ], + [ + 'value' => '3', + 'selected' => true, + 'label' => 'zoo', + ], + ] + ], + ]; } /** diff --git a/tests/functions_acp/build_cfg_template_test.php b/tests/functions_acp/build_cfg_template_test.php index 76558152ff..bdb2bb36e4 100644 --- a/tests/functions_acp/build_cfg_template_test.php +++ b/tests/functions_acp/build_cfg_template_test.php @@ -81,7 +81,7 @@ class phpbb_functions_acp_build_cfg_template_test extends phpbb_test_case $language = new phpbb_mock_lang(); $user->lang = $language; - $this->assertEquals($expected, build_cfg_template($tpl_type, $key, $new, $config_key, $vars)); + $this->assertEquals($expected, phpbb_build_cfg_template($tpl_type, $key, $new, $config_key, $vars)); } public function build_cfg_template_dimension_data() @@ -151,7 +151,7 @@ class phpbb_functions_acp_build_cfg_template_test extends phpbb_test_case $user = new phpbb_mock_user(); $user->lang = new phpbb_mock_lang(); - $this->assertEquals($expected, build_cfg_template($tpl_type, $key, $new, $config_key, $vars)); + $this->assertEquals($expected, phpbb_build_cfg_template($tpl_type, $key, $new, $config_key, $vars)); } public function build_cfg_template_number_data() @@ -219,7 +219,7 @@ class phpbb_functions_acp_build_cfg_template_test extends phpbb_test_case $user = new phpbb_mock_user(); $user->lang = new phpbb_mock_lang(); - $this->assertEquals($expected, build_cfg_template($tpl_type, $key, $new, $config_key, $vars)); + $this->assertEquals($expected, phpbb_build_cfg_template($tpl_type, $key, $new, $config_key, $vars)); } public function build_cfg_template_textarea_data() @@ -254,18 +254,18 @@ class phpbb_functions_acp_build_cfg_template_test extends phpbb_test_case $user = new phpbb_mock_user(); $user->lang = new phpbb_mock_lang(); - $this->assertEquals($expected, build_cfg_template($tpl_type, $key, $new, $config_key, $vars)); + $this->assertEquals($expected, phpbb_build_cfg_template($tpl_type, $key, $new, $config_key, $vars)); } public function build_cfg_template_radio_data() { - return array( - array( - array('radio', 'enabled_disabled'), + return [ + [ + ['radio', 'enabled_disabled'], 'key_name', - array('config_key_name' => '0'), + ['config_key_name' => '0'], 'config_key_name', - array(), + [], [ 'tag' => 'radio', 'buttons' => [ @@ -286,13 +286,40 @@ class phpbb_functions_acp_build_cfg_template_test extends phpbb_test_case ], ], ], - ), - array( - array('radio', 'enabled_disabled'), + ], + [ + ['radio'], 'key_name', - array('config_key_name' => '1'), + ['config_key_name' => '0'], 'config_key_name', - array(), + ['function' => 'phpbb_build_radio', 'params' => ['{CONFIG_VALUE}', '{KEY}', [1 => 'ENABLED', 0 => 'DISABLED']]], + [ + 'tag' => 'radio', + 'buttons' => [ + [ + 'id' => 'key_name', + 'type' => 'radio', + 'value' => 1, + 'name' => 'config[config_key_name]', + 'label' => 'ENABLED', + 'checked' => false, + ], + [ + 'type' => 'radio', + 'value' => 0, + 'checked' => true, + 'name' => 'config[config_key_name]', + 'label' => 'DISABLED', + ], + ], + ], + ], + [ + ['radio', 'enabled_disabled'], + 'key_name', + ['config_key_name' => '1'], + 'config_key_name', + [], [ 'tag' => 'radio', 'buttons' => [ @@ -313,13 +340,40 @@ class phpbb_functions_acp_build_cfg_template_test extends phpbb_test_case ], ], ], - ), - array( - array('radio', 'yes_no'), + ], + [ + ['radio'], 'key_name', - array('config_key_name' => '0'), + ['config_key_name' => '1'], 'config_key_name', - array(), + ['function' => 'phpbb_build_radio', 'params' => ['{CONFIG_VALUE}', '{KEY}', [1 => 'ENABLED', 0 => 'DISABLED']]], + [ + 'tag' => 'radio', + 'buttons' => [ + [ + 'id' => 'key_name', + 'type' => 'radio', + 'value' => 1, + 'name' => 'config[config_key_name]', + 'label' => 'ENABLED', + 'checked' => true, + ], + [ + 'type' => 'radio', + 'value' => 0, + 'checked' => false, + 'name' => 'config[config_key_name]', + 'label' => 'DISABLED', + ], + ], + ], + ], + [ + ['radio', 'yes_no'], + 'key_name', + ['config_key_name' => '0'], + 'config_key_name', + [], [ 'tag' => 'radio', 'buttons' => [ @@ -340,13 +394,40 @@ class phpbb_functions_acp_build_cfg_template_test extends phpbb_test_case ], ], ], - ), - array( - array('radio', 'yes_no'), + ], + [ + ['radio'], 'key_name', - array('config_key_name' => '1'), + ['config_key_name' => '0'], 'config_key_name', - array(), + ['function' => 'phpbb_build_radio', 'params' => ['{CONFIG_VALUE}', '{KEY}', [1 => 'YES', 0 => 'NO']]], + [ + 'tag' => 'radio', + 'buttons' => [ + [ + 'id' => 'key_name', + 'type' => 'radio', + 'value' => 1, + 'name' => 'config[config_key_name]', + 'label' => 'YES', + 'checked' => false, + ], + [ + 'type' => 'radio', + 'value' => 0, + 'checked' => true, + 'name' => 'config[config_key_name]', + 'label' => 'NO', + ], + ], + ], + ], + [ + ['radio', 'yes_no'], + 'key_name', + ['config_key_name' => '1'], + 'config_key_name', + [], [ 'tag' => 'radio', 'buttons' => [ @@ -367,8 +448,35 @@ class phpbb_functions_acp_build_cfg_template_test extends phpbb_test_case ], ], ], - ), - ); + ], + [ + ['radio'], + 'key_name', + ['config_key_name' => '1'], + 'config_key_name', + ['function' => 'phpbb_build_radio', 'params' => ['{CONFIG_VALUE}', '{KEY}', [1 => 'YES', 0 => 'NO']]], + [ + 'tag' => 'radio', + 'buttons' => [ + [ + 'id' => 'key_name', + 'type' => 'radio', + 'value' => 1, + 'name' => 'config[config_key_name]', + 'label' => 'YES', + 'checked' => true, + ], + [ + 'type' => 'radio', + 'value' => 0, + 'checked' => false, + 'name' => 'config[config_key_name]', + 'label' => 'NO', + ], + ], + ], + ], + ]; } /** @@ -381,7 +489,7 @@ class phpbb_functions_acp_build_cfg_template_test extends phpbb_test_case $phpbb_dispatcher = new phpbb_mock_event_dispatcher(); $language = new \phpbb_mock_lang(); - $this->assertEquals($expected, build_cfg_template($tpl_type, $key, $new, $config_key, $vars)); + $this->assertEquals($expected, phpbb_build_cfg_template($tpl_type, $key, $new, $config_key, $vars)); } public function build_cfg_template_append_data() @@ -417,7 +525,7 @@ class phpbb_functions_acp_build_cfg_template_test extends phpbb_test_case $user = new phpbb_mock_user(); $user->lang = new phpbb_mock_lang(); - $this->assertEquals($expected, build_cfg_template($tpl_type, $key, $new, $config_key, $vars)); + $this->assertEquals($expected, phpbb_build_cfg_template($tpl_type, $key, $new, $config_key, $vars)); } public function build_cfg_template_select_data() @@ -431,8 +539,11 @@ class phpbb_functions_acp_build_cfg_template_test extends phpbb_test_case ['method' => 'select_helper'], [ 'tag' => 'select', + 'class' => false, 'id' => 'key_name', + 'data' => [], 'name' => 'config[config_key_name]', + 'toggleable' => false, 'options' => [ [ 'value' => 1, @@ -450,7 +561,9 @@ class phpbb_functions_acp_build_cfg_template_test extends phpbb_test_case 'selected' => false, ] ], - 'toggleable' => false, + 'group_only' => false, + 'size' => 1, + 'multiple' => false, ], ], [ @@ -461,9 +574,11 @@ class phpbb_functions_acp_build_cfg_template_test extends phpbb_test_case ['method' => 'select_helper'], [ 'tag' => 'select', + 'class' => false, 'id' => 'key_name', + 'data' => [], 'name' => 'config[config_key_name]', - 'size' => 8, + 'toggleable' => false, 'options' => [ [ 'value' => 1, @@ -481,7 +596,9 @@ class phpbb_functions_acp_build_cfg_template_test extends phpbb_test_case 'selected' => false, ] ], - 'toggleable' => false, + 'group_only' => false, + 'size' => 8, + 'multiple' => false, ], ], ]; @@ -501,18 +618,19 @@ class phpbb_functions_acp_build_cfg_template_test extends phpbb_test_case $user->module = $this; $module = $user; - $this->assertEquals($expected, build_cfg_template($tpl_type, $key, $new, $config_key, $vars)); + $this->assertEquals($expected, phpbb_build_cfg_template($tpl_type, $key, $new, $config_key, $vars)); } public function select_helper() { - return build_select( - array( - '1' => 'First_Option', - '2' => 'Second_Option', - '3' => 'Third_Option', - ), - '2' - ); + return [ + 'options' => build_select( + [ + '1' => 'First_Option', + '2' => 'Second_Option', + '3' => 'Third_Option', + ], + '2'), + ]; } } diff --git a/tests/functions_acp/h_radio_test.php b/tests/functions_acp/h_radio_test.php deleted file mode 100644 index acba1068f4..0000000000 --- a/tests/functions_acp/h_radio_test.php +++ /dev/null @@ -1,130 +0,0 @@ - -* @license GNU General Public License, version 2 (GPL-2.0) -* -* For full copyright and license information, please see -* the docs/CREDITS.txt file. -* -*/ - -require_once __DIR__ . '/../../phpBB/includes/functions_acp.php'; - -class phpbb_functions_acp_h_radio_test extends phpbb_test_case -{ - protected function setUp(): void - { - parent::setUp(); - - global $user; - - $user = new phpbb_mock_user(); - $user->lang = new phpbb_mock_lang(); - } - - public function h_radio_data() - { - return array( - array( - 'test_name', - array( - 'test' => 'TEST', - 'second' => 'SEC_OPTION', - ), - false, - false, - false, - '', - ), - array( - 'test_name', - array( - 'test' => 'TEST', - 'second' => 'SEC_OPTION', - ), - 'test', - false, - false, - '', - ), - array( - 'test_name', - array( - 'test' => 'TEST', - 'second' => 'SEC_OPTION', - ), - false, - 'test_id', - false, - '', - ), - array( - 'test_name', - array( - 'test' => 'TEST', - 'second' => 'SEC_OPTION', - ), - 'test', - 'test_id', - false, - '', - ), - - array( - 'test_name', - array( - 'test' => 'TEST', - 'second' => 'SEC_OPTION', - ), - false, - false, - 'k', - '', - ), - array( - 'test_name', - array( - 'test' => 'TEST', - 'second' => 'SEC_OPTION', - ), - 'test', - false, - 'k', - '', - ), - array( - 'test_name', - array( - 'test' => 'TEST', - 'second' => 'SEC_OPTION', - ), - false, - 'test_id', - 'k', - '', - ), - array( - 'test_name', - array( - 'test' => 'TEST', - 'second' => 'SEC_OPTION', - ), - 'test', - 'test_id', - 'k', - '', - ), - ); - } - - /** - * @dataProvider h_radio_data - */ - public function test_h_radio($name, $input_ary, $input_default, $id, $key, $expected) - { - $this->assertEquals($expected, h_radio($name, $input_ary, $input_default, $id, $key)); - } -}