aboutsummaryrefslogtreecommitdiffstats
path: root/tests/functions_acp/build_cfg_template_test.php
blob: acf4da1bd62ae2ce1d69026c55a3bee082e8b234 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
<?php
/**
*
* @package testing
* @copyright (c) 2010 phpBB Group
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/

require_once dirname(__FILE__) . '/../../phpBB/includes/functions_acp.php';

class phpbb_functions_acp_build_cfg_template_test extends phpbb_test_case
{
	public function build_cfg_template_text_data()
	{
		return array(
			array(
				array('text', 20, 255),
				'key_name',
				array('config_key_name'	=> '1'),
				'config_key_name',
				array(),
				'<input id="key_name" type="text" size="20" maxlength="255" name="config[config_key_name]" value="1" />',
			),
			array(
				array('password', 20, 128),
				'key_name',
				array('config_key_name'	=> '2'),
				'config_key_name',
				array(),
				'<input id="key_name" type="password" size="20" maxlength="128" name="config[config_key_name]" value="2" autocomplete="off" />',
			),
			array(
				array('text', 0, 255),
				'key_name',
				array('config_key_name'	=> '3'),
				'config_key_name',
				array(),
				'<input id="key_name" type="text" maxlength="255" name="config[config_key_name]" value="3" />',
			),
		);
	}

	/**
	* @dataProvider build_cfg_template_text_data
	*/
	public function test_build_cfg_template_text($tpl_type, $key, $new, $config_key, $vars, $expected)
	{
		global $user, $phpbb_dispatcher;

		$phpbb_dispatcher = new phpbb_mock_event_dispatcher();
		$user = new phpbb_mock_user();
		$user->lang = new phpbb_mock_lang();

		$this->assertEquals($expected, build_cfg_template($tpl_type, $key, $new, $config_key, $vars));
	}

	public function build_cfg_template_dimension_data()
	{
		return array(
			array(
				array('dimension', 5, 15),
				'number_key_name',
				array('config_key_name_width' => 10, 'config_key_name_height' => 20),
				'config_key_name',
				array(),
				'<input id="number_key_name" type="number" size="2" maxlength="2" min="5" max="15" name="config[config_key_name_width]" value="10" /> x <input type="number" size="2" maxlength="2" min="5" max="15" name="config[config_key_name_height]" value="20" />',
			),
			array(
				array('dimension', 0, 15),
				'number_key_name',
				array('config_key_name_width' => 10, 'config_key_name_height' => 20),
				'config_key_name',
				array(),
				'<input id="number_key_name" type="number" size="2" maxlength="2" min="0" max="15" name="config[config_key_name_width]" value="10" /> x <input type="number" size="2" maxlength="2" min="0" max="15" name="config[config_key_name_height]" value="20" />',
			),
		);
	}

	/**
	* @dataProvider build_cfg_template_dimension_data
	*/
	public function test_build_cfg_template_dimension($tpl_type, $key, $new, $config_key, $vars, $expected)
	{
		global $user, $phpbb_dispatcher;

		$phpbb_dispatcher = new phpbb_mock_event_dispatcher();
		$user = new phpbb_mock_user();
		$user->lang = new phpbb_mock_lang();

		$this->assertEquals($expected, build_cfg_template($tpl_type, $key, $new, $config_key, $vars));
	}

	public function build_cfg_template_number_data()
	{
		return array(
			array(
				array('number', 5, 15),
				'number_key_name',
				array('config_key_name' => 10),
				'config_key_name',
				array(),
				'<input id="number_key_name" type="number" maxlength="2" min="5" max="15" name="config[config_key_name]" value="10" />',
			),
			array(
				array('number', -1, 9999),
				'number_key_name',
				array('config_key_name' => 10),
				'config_key_name',
				array(),
				'<input id="number_key_name" type="number" maxlength="4" min="-1" max="9999" name="config[config_key_name]" value="10" />',
			),
		);
	}

	/**
	* @dataProvider build_cfg_template_number_data
	*/
	public function test_build_cfg_template_number($tpl_type, $key, $new, $config_key, $vars, $expected)
	{
		global $user, $phpbb_dispatcher;

		$phpbb_dispatcher = new phpbb_mock_event_dispatcher();
		$user = new phpbb_mock_user();
		$user->lang = new phpbb_mock_lang();

		$this->assertEquals($expected, build_cfg_template($tpl_type, $key, $new, $config_key, $vars));
	}

	public function build_cfg_template_textarea_data()
	{
		return array(
			array(
				array('textarea', 5, 30),
				'key_name',
				array('config_key_name' => 'phpBB'),
				'config_key_name',
				array(),
				'<textarea id="key_name" name="config[config_key_name]" rows="5" cols="30">phpBB</textarea>',
			),
		);
	}

	/**
	* @dataProvider build_cfg_template_textarea_data
	*/
	public function test_build_cfg_template_textarea($tpl_type, $key, $new, $config_key, $vars, $expected)
	{
		global $user, $phpbb_dispatcher;

		$phpbb_dispatcher = new phpbb_mock_event_dispatcher();
		$user = new phpbb_mock_user();
		$user->lang = new phpbb_mock_lang();

		$this->assertEquals($expected, build_cfg_template($tpl_type, $key, $new, $config_key, $vars));
	}

	public function build_cfg_template_radio_data()
	{
		return array(
			array(
				array('radio', 'enabled_disabled'),
				'key_name',
				array('config_key_name'	=> '0'),
				'config_key_name',
				array(),
				'<label><input type="radio" id="key_name" name="config[config_key_name]" value="1" class="radio" /> ENABLED</label><label><input type="radio" name="config[config_key_name]" value="0" checked="checked" class="radio" /> DISABLED</label>',
			),
			array(
				array('radio', 'enabled_disabled'),
				'key_name',
				array('config_key_name'	=> '1'),
				'config_key_name',
				array(),
				'<label><input type="radio" id="key_name" name="config[config_key_name]" value="1" checked="checked" class="radio" /> ENABLED</label><label><input type="radio" name="config[config_key_name]" value="0" class="radio" /> DISABLED</label>',
			),
			array(
				array('radio', 'yes_no'),
				'key_name',
				array('config_key_name'	=> '0'),
				'config_key_name',
				array(),
				'<label><input type="radio" id="key_name" name="config[config_key_name]" value="1" class="radio" /> YES</label><label><input type="radio" name="config[config_key_name]" value="0" checked="checked" class="radio" /> NO</label>',
			),
			array(
				array('radio', 'yes_no'),
				'key_name',
				array('config_key_name'	=> '1'),
				'config_key_name',
				array(),
				'<label><input type="radio" id="key_name" name="config[config_key_name]" value="1" checked="checked" class="radio" /> YES</label><label><input type="radio" name="config[config_key_name]" value="0" class="radio" /> NO</label>',
			),
		);
	}

	/**
	* @dataProvider build_cfg_template_radio_data
	*/
	public function test_build_cfg_template_radio($tpl_type, $key, $new, $config_key, $vars, $expected)
	{
		global $user, $phpbb_dispatcher;

		$phpbb_dispatcher = new phpbb_mock_event_dispatcher();
		$user = new phpbb_mock_user();
		$user->lang = new phpbb_mock_lang();

		$this->assertEquals($expected, build_cfg_template($tpl_type, $key, $new, $config_key, $vars));
	}

	public function build_cfg_template_append_data()
	{
		return array(
			array(
				array('textarea', 5, 30),
				'key_name',
				array('config_key_name' => 'phpBB'),
				'config_key_name',
				array('append' => 'Bertie is cool!'),
				'<textarea id="key_name" name="config[config_key_name]" rows="5" cols="30">phpBB</textarea>Bertie is cool!',
			),
		);
	}

	/**
	* @dataProvider build_cfg_template_append_data
	*/
	public function test_build_cfg_template_append($tpl_type, $key, $new, $config_key, $vars, $expected)
	{
		global $user, $phpbb_dispatcher;

		$phpbb_dispatcher = new phpbb_mock_event_dispatcher();
		$user = new phpbb_mock_user();
		$user->lang = new phpbb_mock_lang();

		$this->assertEquals($expected, build_cfg_template($tpl_type, $key, $new, $config_key, $vars));
	}
}