1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-08-11 11:13:59 +02:00

[ticket/17151] Refactor radio buttons output logic

PHPBB3-17151
This commit is contained in:
rxu
2023-09-23 23:14:32 +07:00
parent 830c1f3dc3
commit 9401a59cfc
9 changed files with 214 additions and 370 deletions

View File

@@ -41,15 +41,15 @@ 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' => '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_10'=> ['lang' => 'SETTING_10', 'validate' => 'bool', 'type' => 'radio:{"LABEL_1":1, "LABEL_3":3, "LABEL_2":2}', 'explain' => true],
'setting_9' => ['lang' => 'SETTING_9', 'validate' => 'bool', 'type' => 'radio', 'function' => 'build_radio', 'params' => ['{CONFIG_VALUE}', '{KEY}', [1 => 'ENABLED', 0 => 'DISABLED']], 'explain' => true],
'setting_10'=> ['lang' => 'SETTING_10', 'validate' => 'bool', 'type' => 'radio', 'function' => 'build_radio', 'params' => ['{CONFIG_VALUE}', '{KEY}', [1 => 'LABEL_1', 3 => 'LABEL_3', 2 => 'LABEL_2']], 'explain' => true],
]
];

View File

@@ -259,13 +259,13 @@ class phpbb_functions_acp_build_cfg_template_test extends phpbb_test_case
public function build_cfg_template_radio_data()
{
return array(
array(
array('radio', 'enabled_disabled'),
return [
[
['radio'],
'key_name',
array('config_key_name' => '0'),
['config_key_name' => '0'],
'config_key_name',
array(),
['function' => 'build_radio', 'params' => ['{CONFIG_VALUE}', '{KEY}', [1 => 'ENABLED', 0 => 'DISABLED']]],
[
'tag' => 'radio',
'buttons' => [
@@ -286,13 +286,13 @@ 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' => '1'],
'config_key_name',
array(),
['function' => 'build_radio', 'params' => ['{CONFIG_VALUE}', '{KEY}', [1 => 'ENABLED', 0 => 'DISABLED']]],
[
'tag' => 'radio',
'buttons' => [
@@ -313,13 +313,13 @@ 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' => '0'],
'config_key_name',
array(),
['function' => 'build_radio', 'params' => ['{CONFIG_VALUE}', '{KEY}', [1 => 'YES', 0 => 'NO']]],
[
'tag' => 'radio',
'buttons' => [
@@ -340,13 +340,13 @@ 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' => '1'],
'config_key_name',
array(),
['function' => 'build_radio', 'params' => ['{CONFIG_VALUE}', '{KEY}', [1 => 'YES', 0 => 'NO']]],
[
'tag' => 'radio',
'buttons' => [
@@ -367,8 +367,8 @@ class phpbb_functions_acp_build_cfg_template_test extends phpbb_test_case
],
],
],
),
);
],
];
}
/**

View File

@@ -1,130 +0,0 @@
<?php
/**
*
* This file is part of the phpBB Forum Software package.
*
* @copyright (c) phpBB Limited <https://www.phpbb.com>
* @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,
'<label><input type="radio" name="test_name" value="test" class="radio" /> TEST</label><label><input type="radio" name="test_name" value="second" class="radio" /> SEC_OPTION</label>',
),
array(
'test_name',
array(
'test' => 'TEST',
'second' => 'SEC_OPTION',
),
'test',
false,
false,
'<label><input type="radio" name="test_name" value="test" checked="checked" class="radio" /> TEST</label><label><input type="radio" name="test_name" value="second" class="radio" /> SEC_OPTION</label>',
),
array(
'test_name',
array(
'test' => 'TEST',
'second' => 'SEC_OPTION',
),
false,
'test_id',
false,
'<label><input type="radio" name="test_name" id="test_id" value="test" class="radio" /> TEST</label><label><input type="radio" name="test_name" value="second" class="radio" /> SEC_OPTION</label>',
),
array(
'test_name',
array(
'test' => 'TEST',
'second' => 'SEC_OPTION',
),
'test',
'test_id',
false,
'<label><input type="radio" name="test_name" id="test_id" value="test" checked="checked" class="radio" /> TEST</label><label><input type="radio" name="test_name" value="second" class="radio" /> SEC_OPTION</label>',
),
array(
'test_name',
array(
'test' => 'TEST',
'second' => 'SEC_OPTION',
),
false,
false,
'k',
'<label><input type="radio" name="test_name" value="test" accesskey="k" class="radio" /> TEST</label><label><input type="radio" name="test_name" value="second" accesskey="k" class="radio" /> SEC_OPTION</label>',
),
array(
'test_name',
array(
'test' => 'TEST',
'second' => 'SEC_OPTION',
),
'test',
false,
'k',
'<label><input type="radio" name="test_name" value="test" checked="checked" accesskey="k" class="radio" /> TEST</label><label><input type="radio" name="test_name" value="second" accesskey="k" class="radio" /> SEC_OPTION</label>',
),
array(
'test_name',
array(
'test' => 'TEST',
'second' => 'SEC_OPTION',
),
false,
'test_id',
'k',
'<label><input type="radio" name="test_name" id="test_id" value="test" accesskey="k" class="radio" /> TEST</label><label><input type="radio" name="test_name" value="second" accesskey="k" class="radio" /> SEC_OPTION</label>',
),
array(
'test_name',
array(
'test' => 'TEST',
'second' => 'SEC_OPTION',
),
'test',
'test_id',
'k',
'<label><input type="radio" name="test_name" id="test_id" value="test" checked="checked" accesskey="k" class="radio" /> TEST</label><label><input type="radio" name="test_name" value="second" accesskey="k" class="radio" /> SEC_OPTION</label>',
),
);
}
/**
* @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));
}
}