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
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
|
<?php
declare(strict_types=1);
namespace PhpMyAdmin\Tests\Config;
use PhpMyAdmin\Config;
use PhpMyAdmin\Config\FormDisplayTemplate;
use PhpMyAdmin\Tests\AbstractTestCase;
/**
* @covers \PhpMyAdmin\Config\FormDisplayTemplate
*/
class FormDisplayTemplateTest extends AbstractTestCase
{
/** @var FormDisplayTemplate */
protected $formDisplayTemplate;
/** @var Config */
protected $config;
/**
* Setup tests
*/
protected function setUp(): void
{
parent::setUp();
parent::setLanguage();
$this->config = new Config();
$this->formDisplayTemplate = new FormDisplayTemplate($this->config);
}
/**
* Test for displayInput()
*/
public function testDisplayInput(): void
{
$opts = [];
$opts['errors'] = ['e1'];
$opts['userprefs_allow'] = false;
$opts['setvalue'] = ':group';
$opts['doc'] = 'https://example.com/';
$opts['comment'] = 'testComment';
$opts['comment_warning'] = true;
$opts['show_restore_default'] = true;
$result = $this->formDisplayTemplate->displayInput(
'test/path',
'testName',
'text',
'val',
'desc',
false,
$opts
);
$this->assertStringContainsString('<tr class="group-header-field group-header-1 disabled-field">', $result);
$this->assertStringContainsString('<label for="test/path">', $result);
$this->assertStringContainsString('<a href="https://example.com/" target="documentation"', $result);
$this->assertStringContainsString(
'<img src="themes/dot.gif" title="Documentation" alt="Documentation" class="icon ic_b_help"',
$result
);
$this->assertStringContainsString('<span class="disabled-notice"', $result);
$this->assertStringContainsString('<small>', $result);
$this->assertStringContainsString(
'<input type="text" name="test/path" id="test/path" value="val" class="w-75 custom field-error">',
$result
);
$this->assertStringContainsString('<a class="restore-default hide" href="#test/path"', $result);
$this->assertStringContainsString('<dl class="inline_errors">', $result);
$this->assertStringContainsString('<dd>e1</dd>', $result);
$this->assertStringContainsString('</dl>', $result);
// second case
$this->config->set('is_setup', true);
$opts = [];
$opts['errors'] = [];
$opts['setvalue'] = 'setVal';
$opts['comment'] = 'testComment';
$opts['show_restore_default'] = true;
$opts['userprefs_comment'] = 'userprefsComment';
$opts['userprefs_allow'] = true;
$result = $this->formDisplayTemplate->displayInput(
'test/path',
'testName',
'checkbox',
'val',
'',
false,
$opts
);
$this->assertStringContainsString('<tr class="group-field group-field-1">', $result);
$this->assertStringContainsString('<input type="checkbox" name="test/path" id="test/path" checked>', $result);
$this->assertStringContainsString('<a class="userprefs-comment" title="userprefsComment">', $result);
$this->assertStringContainsString(
'<td class="userprefs-allow" title="Allow users to customize this value">',
$result
);
$this->assertStringContainsString(
'<a class="set-value hide" href="#test/path=setVal" title="Set value: setVal">',
$result
);
// short_text
$opts = [];
$opts['errors'] = [];
$result = $this->formDisplayTemplate->displayInput(
'test/path',
'testName',
'short_text',
'val',
'',
true,
$opts
);
$this->assertStringContainsString(
'<input type="text" size="25" name="test/path" id="test/path" value="val" class="">',
$result
);
// number_text
$result = $this->formDisplayTemplate->displayInput(
'test/path',
'testName',
'number_text',
'val',
'',
true,
$opts
);
$this->assertStringContainsString(
'<input type="number" name="test/path" id="test/path" value="val" class="">',
$result
);
// select case 1
$opts['values_escaped'] = true;
$opts['values_disabled'] = [
1,
2,
];
$opts['values'] = [
1 => 'test',
'key1' => true,
'key2' => false,
];
$result = $this->formDisplayTemplate->displayInput('test/path', 'testName', 'select', true, '', true, $opts);
$this->assertStringContainsString('<select name="test/path" id="test/path" class="w-75">', $result);
$this->assertStringContainsString('<option value="1" selected disabled>', $result);
$this->assertStringContainsString('<option value="key1">', $result);
$this->assertStringContainsString('<option value="key2">', $result);
// select case 2
$opts['values_escaped'] = false;
$opts['values_disabled'] = [
1,
2,
];
$opts['values'] = [
'a<b' => 'c&d',
'key1' => true,
'key2' => false,
];
$result = $this->formDisplayTemplate->displayInput('test/path', 'testName', 'select', false, '', true, $opts);
$this->assertStringContainsString('<select name="test/path" id="test/path" class="w-75">', $result);
// assertContains doesn't seem to work with htmlentities
$this->assertStringContainsString('<option value="a<b">c&d</option>', $result);
// list
$result = $this->formDisplayTemplate->displayInput(
'test/path',
'testName',
'list',
[
'foo',
'bar',
],
'',
true,
$opts
);
$this->assertStringContainsString(
'<textarea cols="35" rows="5" name="test/path" id="test/path" class="">',
$result
);
}
/**
* Test for displayGroupHeader()
*/
public function testDisplayGroupHeader(): void
{
$this->assertEquals(
'',
$this->formDisplayTemplate->displayGroupHeader('')
);
$this->formDisplayTemplate->group = 3;
$this->config->set('is_setup', true);
$result = $this->formDisplayTemplate->displayGroupHeader('headerText');
$this->assertStringContainsString('<tr class="group-header group-header-4">', $result);
// without PMA_SETUP
$this->config->set('is_setup', false);
$this->formDisplayTemplate->group = 3;
$result = $this->formDisplayTemplate->displayGroupHeader('headerText');
$this->assertStringContainsString('<tr class="group-header group-header-4">', $result);
}
/**
* Test for displayGroupFooter()
*/
public function testDisplayGroupFooter(): void
{
$this->formDisplayTemplate->group = 3;
$this->formDisplayTemplate->displayGroupFooter();
$this->assertEquals(2, $this->formDisplayTemplate->group);
}
/**
* Test for addJsValidate()
*/
public function testAddJsValidate(): void
{
$validators = [
'one' => [
'\\\';',
'\r\n\\\'<scrIpt></\' + \'script>',
],
'two' => [],
];
$js = [];
$this->formDisplayTemplate->addJsValidate('testID', $validators, $js);
$this->assertEquals(
[
'registerFieldValidator(\'testID\', \'\\\';\', true, '
. '[\'\\\\r\\\\n\\\\\\\''
. '<scrIpt></\\\' + \\\'script>\'])',
'registerFieldValidator(\'testID\', \'\', true)',
],
$js
);
}
}
|