BuildFormPlainTest.php 40.9 KB
Newer Older
1
<?php
2
/**
3
 * @author Carsten Rose <carsten.rose@math.uzh.ch>
4
 */
5

Marc Egger's avatar
Marc Egger committed
6
namespace IMATHUZH\Qfq\Tests\Unit\Core;
7

Marc Egger's avatar
Marc Egger committed
8
9
10
11
12
13
14
use IMATHUZH\Qfq\Core\BuildFormPlain;
 
use IMATHUZH\Qfq\Core\Helper\Support;
use IMATHUZH\Qfq\Core\QuickFormQuery;
use IMATHUZH\Qfq\Tests\Unit\Core\Database\AbstractDatabaseTest;

require_once(__DIR__ . '/Database/AbstractDatabaseTest.php');
15

16
17
18
/**
 * Class BuildFormPlainTest
 */
19
20
class BuildFormPlainTest extends AbstractDatabaseTest {

21
    /**
Marc Egger's avatar
Marc Egger committed
22
23
24
     * @throws \CodeException
     * @throws \UserFormException
     * @throws \UserReportException
25
     */
26
27
    public function testGetProcessFilter() {

Carsten  Rose's avatar
Carsten Rose committed
28
        $build = new BuildFormPlain([F_DB_INDEX => DB_INDEX_DEFAULT], array(), array(), $this->dbArray);
Marc Egger's avatar
Marc Egger committed
29
      $this->assertEquals(FORM_ELEMENTS_NATIVE, $build->getProcessFilter());
30
31
    }

32
    /**
Marc Egger's avatar
Marc Egger committed
33
34
35
     * @throws \CodeException
     * @throws \UserFormException
     * @throws \UserReportException
36
37
     */
    public function testGetFormId() {
Carsten  Rose's avatar
Carsten Rose committed
38
        $build = new BuildFormPlain([F_DB_INDEX => DB_INDEX_DEFAULT], array(), array(), $this->dbArray);
39
40
41
42
43
44
45
46
47

        $formId1 = $build->getFormId();
        $this->assertRegExp('/qfq-form-[0-9a-f]{13}/', $formId1);

        $formId2 = $build->getFormId();
        $this->assertEquals($formId1, $formId2);

    }

48
    /**
Marc Egger's avatar
Marc Egger committed
49
50
51
     * @throws \CodeException
     * @throws \UserFormException
     * @throws \UserReportException
52
     */
53
    public function testWrapItem() {
Carsten  Rose's avatar
Carsten Rose committed
54
        $build = new BuildFormPlain([F_DB_INDEX => DB_INDEX_DEFAULT], array(), array(), $this->dbArray);
55
56
57
58
59
60
61
62
63
64
65
66
67
68

        $result = $build->wrapItem(WRAP_SETUP_ELEMENT, 'Hello World', false);
        $this->assertEquals('<p>Hello World</p>', $result);

        $result = $build->wrapItem(WRAP_SETUP_ELEMENT, 'Hello World', true);
        $this->assertEquals('<p>Hello World</p>', $result);

        $result = $build->wrapItem(WRAP_SETUP_ELEMENT, '', false);
        $this->assertEquals('<p></p>', $result);

        $result = $build->wrapItem(WRAP_SETUP_ELEMENT, '', true);
        $this->assertEquals('', $result);
    }

69
    /**
Marc Egger's avatar
Marc Egger committed
70
71
72
     * @throws \CodeException
     * @throws \UserFormException
     * @throws \UserReportException
73
     */
74
75
76
    public function testBuildInput() {
        $form = array();
        $formElement = array();
Carsten  Rose's avatar
Carsten Rose committed
77
        $json = array();
78

79
        $this->templateFormNFormElement($form, $formElement);
80

81
        $build = new BuildFormPlain($form, array(), [$formElement], $this->dbArray);
Elias Villiger's avatar
Elias Villiger committed
82
        $formElement[FE_CHECK_TYPE] = SANITIZE_ALLOW_ALL;
Carsten  Rose's avatar
Carsten Rose committed
83
        $formElement[FE_DECIMAL_FORMAT] = '';
84

85
        $label['123-l'][API_ELEMENT_CONTENT] = '<label for="name:1" class="control-label" >Name</label>';
Carsten  Rose's avatar
Carsten Rose committed
86
87
//        $label['123'][API_ELEMENT_ATTRIBUTE] = ['value' => ''];
        $label['123'][API_ELEMENT_ATTRIBUTE] = ['value' => '', 'required' => false, 'hidden' => false];
Carsten  Rose's avatar
Carsten Rose committed
88
        $label['123-r'][API_ELEMENT_ATTRIBUTE] = ['class' => ''];
89

Carsten  Rose's avatar
Carsten Rose committed
90
        $result = $build->buildInput($formElement, 'name:1', '', $json);
91
        $this->assertEquals('<input id="123" name="name:1" maxlength="255" type="input" value="" data-error="Error" data-hidden="no" data-required="no" class="form-control" ><div class="help-block with-errors hidden"></div>', $result);
Carsten  Rose's avatar
Carsten Rose committed
92
        $this->assertEquals(['disabled' => false, FE_MODE_REQUIRED => '', 'form-element' => 'name:1', 'value' => '', API_ELEMENT_UPDATE => $label], $json);
93

94
        // Min/Max
95
96
        $formElement[FE_MIN] = '1';
        $formElement[FE_MAX] = '10';
Carsten  Rose's avatar
Carsten Rose committed
97
        $result = $build->buildInput($formElement, 'name:1', '', $json);
98
        $this->assertEquals('<input id="123" name="name:1" maxlength="255" type="number" value="" data-error="Error" min="1" max="10" data-hidden="no" data-required="no" class="form-control" ><div class="help-block with-errors hidden"></div>', $result);
99
        $this->assertEquals(['disabled' => false, FE_MODE_REQUIRED => '', 'form-element' => 'name:1', 'value' => '', API_ELEMENT_UPDATE => $label], $json);
100

101
        $formElement[FE_MIN] = '1';
102
103
        $formElement[FE_MAX] = '';
        $result = $build->buildInput($formElement, 'name:1', '', $json);
104
        $this->assertEquals('<input id="123" name="name:1" maxlength="255" type="input" value="" data-error="Error" min="1" data-hidden="no" data-required="no" class="form-control" ><div class="help-block with-errors hidden"></div>', $result);
105
        $this->assertEquals(['disabled' => false, FE_MODE_REQUIRED => '', 'form-element' => 'name:1', 'value' => '', API_ELEMENT_UPDATE => $label], $json);
106
107

        $formElement[FE_MIN] = '';
108
        $formElement[FE_MAX] = '10';
109
        $result = $build->buildInput($formElement, 'name:1', '', $json);
110
        $this->assertEquals('<input id="123" name="name:1" maxlength="255" type="input" value="" data-error="Error" max="10" data-hidden="no" data-required="no" class="form-control" ><div class="help-block with-errors hidden"></div>', $result);
111
        $this->assertEquals(['disabled' => false, FE_MODE_REQUIRED => '', 'form-element' => 'name:1', 'value' => '', API_ELEMENT_UPDATE => $label], $json);
112
113
114
115

        $formElement[FE_MIN] = '0';
        $formElement[FE_MAX] = '10';
        $result = $build->buildInput($formElement, 'name:1', '', $json);
116
        $this->assertEquals('<input id="123" name="name:1" maxlength="255" type="input" value="" data-error="Error" min="0" max="10" data-hidden="no" data-required="no" class="form-control" ><div class="help-block with-errors hidden"></div>', $result);
117
118
119
120
121
        $this->assertEquals(['disabled' => false, FE_MODE_REQUIRED => '', 'form-element' => 'name:1', 'value' => '', API_ELEMENT_UPDATE => $label], $json);

        $formElement[FE_MIN] = '-5';
        $formElement[FE_MAX] = '0';
        $result = $build->buildInput($formElement, 'name:1', '', $json);
122
        $this->assertEquals('<input id="123" name="name:1" maxlength="255" type="input" value="" data-error="Error" min="-5" max="0" data-hidden="no" data-required="no" class="form-control" ><div class="help-block with-errors hidden"></div>', $result);
123
124
        $this->assertEquals(['disabled' => false, FE_MODE_REQUIRED => '', 'form-element' => 'name:1', 'value' => '', API_ELEMENT_UPDATE => $label], $json);

125
126
127
        // reset so they don't interfere with next tests
        $formElement[FE_MIN] = '';
        $formElement[FE_MAX] = '';
128

129
        // CheckType: custom pattern, standard data-pattern-error
130
131
        $formElement[FE_CHECK_TYPE] = SANITIZE_ALLOW_PATTERN;
        $formElement[FE_CHECK_PATTERN] = '^[a-z]*$';
Carsten  Rose's avatar
Carsten Rose committed
132
        $result = $build->buildInput($formElement, 'name:1', '', $json);
133
        $this->assertEquals('<input id="123" name="name:1" maxlength="255" type="input" value="" pattern="^[a-z]*$" data-pattern-error="' . F_FE_DATA_PATTERN_ERROR_DEFAULT . '" data-error="Error" data-hidden="no" data-required="no" class="form-control" ><div class="help-block with-errors hidden"></div>', $result);
Carsten  Rose's avatar
Carsten Rose committed
134
        $label['123'][API_ELEMENT_ATTRIBUTE]['pattern'] = '^[a-z]*$';
135
        $this->assertEquals(['disabled' => false, FE_MODE_REQUIRED => '', 'form-element' => 'name:1', 'value' => '', API_ELEMENT_UPDATE => $label], $json);
136

137
138
        $formElement[FE_CHECK_TYPE] = SANITIZE_ALLOW_DIGIT;
        $formElement[FE_CHECK_PATTERN] = '';
Carsten  Rose's avatar
Carsten Rose committed
139
        $result = $build->buildInput($formElement, 'name:1', '', $json);
140
        $this->assertEquals('<input id="123" name="name:1" maxlength="255" type="input" value="" pattern="^[\d]*$" data-pattern-error="' . SANITIZE_ALLOW_DIGIT_MESSAGE . '" data-error="Error" data-hidden="no" data-required="no" class="form-control" ><div class="help-block with-errors hidden"></div>', $result);
Carsten  Rose's avatar
Carsten Rose committed
141
142

        $label['123'][API_ELEMENT_ATTRIBUTE]['pattern'] = '^[\d]*$';
143
        $this->assertEquals(['disabled' => false, FE_MODE_REQUIRED => '', 'form-element' => 'name:1', 'value' => '', API_ELEMENT_UPDATE => $label], $json);
144

145
146
        $formElement[FE_CHECK_TYPE] = SANITIZE_ALLOW_EMAIL;
        $formElement[FE_CHECK_PATTERN] = '';
Carsten  Rose's avatar
Carsten Rose committed
147
        $result = $build->buildInput($formElement, 'name:1', '', $json);
Marc Egger's avatar
Marc Egger committed
148
        $label['123'][API_ELEMENT_ATTRIBUTE]['pattern'] = '^([a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,})?$';
149
        $this->assertEquals('<input id="123" name="name:1" maxlength="255" type="input" value="" pattern="^([a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,})?$" data-pattern-error="' . SANITIZE_ALLOW_EMAIL_MESSAGE . '" data-error="Error" data-hidden="no" data-required="no" class="form-control" ><div class="help-block with-errors hidden"></div>', $result);
150
        $this->assertEquals(['disabled' => false, FE_MODE_REQUIRED => '', 'form-element' => 'name:1', 'value' => '', API_ELEMENT_UPDATE => $label], $json);
151

152
        $formElement[FE_CHECK_TYPE] = SANITIZE_ALLOW_ALL;
153
        $formElement[FE_CHECK_PATTERN] = '';
154
155


156
157
158
        // Decimal format
        $formElement[FE_DECIMAL_FORMAT] = '5,2';
        $result = $build->buildInput($formElement, 'name:1', '', $json);
159
        $this->assertEquals('<input id="123" name="name:1" maxlength="255" type="input" value="" pattern="^-?[0-9]{0,3}(\.[0-9]{0,2})?$" data-pattern-error="Requested decimal format (mantis,decimal): 5,2" data-error="Error" data-hidden="no" data-required="no" class="form-control" ><div class="help-block with-errors hidden"></div>', $result);
Carsten  Rose's avatar
Carsten Rose committed
160
        $label['123'][API_ELEMENT_ATTRIBUTE]['pattern'] = '^-?[0-9]{0,3}(\.[0-9]{0,2})?$';
161
        $this->assertEquals(['disabled' => false, FE_MODE_REQUIRED => '', 'form-element' => 'name:1', 'value' => '', API_ELEMENT_UPDATE => $label], $json);
162
163
164
165
166

        $formElement[FE_DECIMAL_FORMAT] = '';


        // Explicit size
167
168
        $formElement['size'] = 40;
        $formElement['maxLength'] = 40;
Carsten  Rose's avatar
Carsten Rose committed
169
        $result = $build->buildInput($formElement, 'name:1', '', $json);
170
        $this->assertEquals('<input id="123" name="name:1" maxlength="40" type="input" size="40" value="" data-error="Error" data-hidden="no" data-required="no" class="form-control" ><div class="help-block with-errors hidden"></div>', $result);
Carsten  Rose's avatar
Carsten Rose committed
171
        unset($label['123'][API_ELEMENT_ATTRIBUTE]['pattern']);
172
        $this->assertEquals(['disabled' => false, FE_MODE_REQUIRED => '', 'form-element' => 'name:1', 'value' => '', API_ELEMENT_UPDATE => $label], $json);
173
174

        // maxlength bigger than physical spec:
175
        $formElement['maxLength'] = 1000;
Carsten  Rose's avatar
Carsten Rose committed
176
        $result = $build->buildInput($formElement, 'name:1', '', $json);
177
        $this->assertEquals('<input id="123" name="name:1" maxlength="1000" type="input" size="40" value="" data-error="Error" data-hidden="no" data-required="no" class="form-control" ><div class="help-block with-errors hidden"></div>', $result);
178
        $this->assertEquals(['disabled' => false, FE_MODE_REQUIRED => '', 'form-element' => 'name:1', 'value' => '', API_ELEMENT_UPDATE => $label], $json);
179

180
181
182
183
184
185
        // no size, no maxlength and column not in primary table
        $formElement2 = $formElement;
        $formElement2['maxLength'] = '';
        $formElement2['size'] = '';
        $formElement2['name'] = 'specialname';
        $result = $build->buildInput($formElement2, 'specialname:1', '', $json);
186
        $this->assertEquals('<input id="123" name="specialname:1" type="input" value="" data-error="Error" data-hidden="no" data-required="no" class="form-control" ><div class="help-block with-errors hidden"></div>', $result);
187
188
189
190

        // no size,  given maxlength and column not in primary table
        $formElement2['maxLength'] = '10';
        $result = $build->buildInput($formElement2, 'specialname:1', '', $json);
191
        $this->assertEquals('<input id="123" name="specialname:1" maxlength="10" type="input" value="" data-error="Error" data-hidden="no" data-required="no" class="form-control" ><div class="help-block with-errors hidden"></div>', $result);
192
193
194
195
196

        // size given, no maxlength and column not in primary table
        $formElement2['maxLength'] = '';
        $formElement2['size'] = '10';
        $result = $build->buildInput($formElement2, 'specialname:1', '', $json);
197
        $this->assertEquals('<input id="123" name="specialname:1" type="input" size="10" value="" data-error="Error" data-hidden="no" data-required="no" class="form-control" ><div class="help-block with-errors hidden"></div>', $result);
198
199
200
201
202

        // size given, maxlength given and column not in primary table
        $formElement2['maxLength'] = '20';
        $formElement2['size'] = '10';
        $result = $build->buildInput($formElement2, 'specialname:1', '', $json);
203
        $this->assertEquals('<input id="123" name="specialname:1" maxlength="20" type="input" size="10" value="" data-error="Error" data-hidden="no" data-required="no" class="form-control" ><div class="help-block with-errors hidden"></div>', $result);
204
205
        $formElement2['maxLength'] = '';
        $formElement2['size'] = '';
206

207
        // Explicit: further
208
209
210
        $formElement2['tooltip'] = 'Nice Tooltip';
        $formElement2['placeholder'] = 'Please type a name';
        $result = $build->buildInput($formElement2, 'name:1', 'Hello World', $json);
211
        $this->assertEquals('<input id="123" name="name:1" type="input" value="Hello World" placeholder="Please type a name" data-error="Error" title="Nice Tooltip" data-hidden="no" data-required="no" class="form-control" ><div class="help-block with-errors hidden"></div>', $result);
Carsten  Rose's avatar
Carsten Rose committed
212
        $label['123'][API_ELEMENT_ATTRIBUTE] = ['value' => 'Hello World', 'required' => false, 'hidden' => false];
213
        $this->assertEquals(['disabled' => false, FE_MODE_REQUIRED => '', 'form-element' => 'name:1', 'value' => 'Hello World', API_ELEMENT_UPDATE => $label], $json);
214
215

        // textarea
216
217
        $formElement2['size'] = '40,10';
        $result = $build->buildInput($formElement2, 'name:1', 'Hello World', $json);
218
        $this->assertEquals('<textarea id="123" name="name:1" cols="40" rows="10" data-max-height="350" placeholder="Please type a name" data-error="Error" title="Nice Tooltip" data-hidden="no" data-required="no" class="form-control qfq-auto-grow" >Hello World</textarea><div class="help-block with-errors hidden"></div>', $result);
219

220
        $this->assertEquals(['disabled' => false, FE_MODE_REQUIRED => '', 'form-element' => 'name:1', 'value' => 'Hello World', API_ELEMENT_UPDATE => $label], $json);
221

222
223
        $formElement2['size'] = ' 40     , 10 ';
        $result = $build->buildInput($formElement2, 'name:1', 'Hello World', $json);
224
        $this->assertEquals('<textarea id="123" name="name:1" cols="40" rows="10" data-max-height="350" placeholder="Please type a name" data-error="Error" title="Nice Tooltip" data-hidden="no" data-required="no" class="form-control qfq-auto-grow" >Hello World</textarea><div class="help-block with-errors hidden"></div>', $result);
225
        $this->assertEquals(['disabled' => false, FE_MODE_REQUIRED => '', 'form-element' => 'name:1', 'value' => 'Hello World', API_ELEMENT_UPDATE => $label], $json);
226
227
    }

228
    /**
Marc Egger's avatar
Marc Egger committed
229
230
231
     * @throws \CodeException
     * @throws \UserFormException
     * @throws \UserReportException
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
     */
    public function testBuildInputPattern() {
        $form = array();
        $formElement = array();
        $json = array();

        $this->templateFormNFormElement($form, $formElement);

        $build = new BuildFormPlain($form, array(), [$formElement], $this->dbArray);
        $formElement[FE_CHECK_TYPE] = SANITIZE_ALLOW_ALL;
        $formElement[FE_DECIMAL_FORMAT] = '';

        $label['123-l'][API_ELEMENT_CONTENT] = '<label for="name:1" class="control-label" >Name</label>';
        $label['123'][API_ELEMENT_ATTRIBUTE] = ['value' => '', 'required' => false, 'hidden' => false];
        $label['123-r'][API_ELEMENT_ATTRIBUTE] = ['class' => ''];

        $formElement[FE_CHECK_TYPE] = SANITIZE_ALLOW_ALNUMX;
        $result = $build->buildInput($formElement, 'name:1', '', $json);
250
        $this->assertEquals('<input id="123" name="name:1" maxlength="255" type="input" value="" pattern="' . PATTERN_ALNUMX .
251
            '" data-pattern-error="' . SANITIZE_ALLOW_ALNUMX_MESSAGE .
252
            '" data-error="Error" data-hidden="no" data-required="no" class="form-control" ><div class="help-block with-errors hidden"></div>', $result);
253
254
255

        $formElement[FE_CHECK_TYPE] = SANITIZE_ALLOW_DIGIT;
        $result = $build->buildInput($formElement, 'name:1', '', $json);
256
        $this->assertEquals('<input id="123" name="name:1" maxlength="255" type="input" value="" pattern="' . PATTERN_DIGIT .
257
            '" data-pattern-error="' . SANITIZE_ALLOW_DIGIT_MESSAGE .
258
            '" data-error="Error" data-hidden="no" data-required="no" class="form-control" ><div class="help-block with-errors hidden"></div>', $result);
259
260
261

        $formElement[FE_CHECK_TYPE] = SANITIZE_ALLOW_NUMERICAL;
        $result = $build->buildInput($formElement, 'name:1', '', $json);
262
        $this->assertEquals('<input id="123" name="name:1" maxlength="255" type="input" value="" pattern="' . PATTERN_NUMERICAL .
263
            '" data-pattern-error="' . SANITIZE_ALLOW_NUMERICAL_MESSAGE .
264
            '" data-error="Error" data-hidden="no" data-required="no" class="form-control" ><div class="help-block with-errors hidden"></div>', $result);
265
266
267

        $formElement[FE_CHECK_TYPE] = SANITIZE_ALLOW_EMAIL;
        $result = $build->buildInput($formElement, 'name:1', '', $json);
268
        $this->assertEquals('<input id="123" name="name:1" maxlength="255" type="input" value="" pattern="' . PATTERN_EMAIL .
269
            '" data-pattern-error="' . SANITIZE_ALLOW_EMAIL_MESSAGE .
270
            '" data-error="Error" data-hidden="no" data-required="no" class="form-control" ><div class="help-block with-errors hidden"></div>', $result);
271
272
273

        $formElement[FE_CHECK_TYPE] = SANITIZE_ALLOW_ALLBUT;
        $result = $build->buildInput($formElement, 'name:1', '', $json);
274
        $this->assertEquals('<input id="123" name="name:1" maxlength="255" type="input" value="" pattern="' . PATTERN_ALLBUT .
275
            '" data-pattern-error="' . SANITIZE_ALLOW_ALLBUT_MESSAGE .
276
            '" data-error="Error" data-hidden="no" data-required="no" class="form-control" ><div class="help-block with-errors hidden"></div>', $result);
277
278
279

        $formElement[FE_CHECK_TYPE] = SANITIZE_ALLOW_ALL;
        $result = $build->buildInput($formElement, 'name:1', '', $json);
280
        $this->assertEquals('<input id="123" name="name:1" maxlength="255" type="input" value="" data-error="Error" data-hidden="no" data-required="no" class="form-control" ><div class="help-block with-errors hidden"></div>', $result);
281
282
283
284

        $formElement[FE_CHECK_TYPE] = SANITIZE_ALLOW_PATTERN;
        $formElement[FE_CHECK_PATTERN] = '^[0-2]$';
        $result = $build->buildInput($formElement, 'name:1', '', $json);
285
        $this->assertEquals('<input id="123" name="name:1" maxlength="255" type="input" value="" pattern="' . $formElement[FE_CHECK_PATTERN] .
286
            '" data-pattern-error="' . F_FE_DATA_PATTERN_ERROR_DEFAULT .
287
            '" data-error="Error" data-hidden="no" data-required="no" class="form-control" ><div class="help-block with-errors hidden"></div>', $result);
288
289
290
    }

    /**
Marc Egger's avatar
Marc Egger committed
291
292
293
     * @throws \CodeException
     * @throws \UserFormException
     * @throws \UserReportException
294
     */
Carsten  Rose's avatar
Carsten Rose committed
295
    public function testBuildInputSpecificErrorTextDefault() {
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
        $form = array();
        $formElement = array();
        $json = array();

        $this->templateFormNFormElement($form, $formElement);

        $build = new BuildFormPlain($form, array(), [$formElement], $this->dbArray);
        $formElement[FE_CHECK_TYPE] = SANITIZE_ALLOW_ALL;
        $formElement[FE_DECIMAL_FORMAT] = '';

        $label['123-l'][API_ELEMENT_CONTENT] = '<label for="name:1" class="control-label" >Name</label>';
        $label['123'][API_ELEMENT_ATTRIBUTE] = ['value' => '', 'required' => false, 'hidden' => false];
        $label['123-r'][API_ELEMENT_ATTRIBUTE] = ['class' => ''];

        // Defaults data-pattern-error: ALNUMX
        $formElement[FE_CHECK_TYPE] = SANITIZE_ALLOW_ALNUMX;
        $result = $build->buildInput($formElement, 'name:1', '', $json);
313
        $this->assertEquals('<input id="123" name="name:1" maxlength="255" type="input" value="" pattern="' . PATTERN_ALNUMX .
314
            '" data-pattern-error="' . SANITIZE_ALLOW_ALNUMX_MESSAGE .
315
            '" data-error="' . F_FE_DATA_ERROR_DEFAULT . '" data-hidden="no" data-required="no" class="form-control" ><div class="help-block with-errors hidden"></div>', $result);
316

Carsten  Rose's avatar
Carsten Rose committed
317
318
319
        // Defaults data-pattern-error: DIGIT
        $formElement[FE_CHECK_TYPE] = SANITIZE_ALLOW_DIGIT;
        $result = $build->buildInput($formElement, 'name:1', '', $json);
320
        $this->assertEquals('<input id="123" name="name:1" maxlength="255" type="input" value="" pattern="' . PATTERN_DIGIT .
Carsten  Rose's avatar
Carsten Rose committed
321
            '" data-pattern-error="' . SANITIZE_ALLOW_DIGIT_MESSAGE .
322
            '" data-error="' . F_FE_DATA_ERROR_DEFAULT . '" data-hidden="no" data-required="no" class="form-control" ><div class="help-block with-errors hidden"></div>', $result);
323

Carsten  Rose's avatar
Carsten Rose committed
324
325
326
        // Defaults data-pattern-error: NUMERICAL
        $formElement[FE_CHECK_TYPE] = SANITIZE_ALLOW_NUMERICAL;
        $result = $build->buildInput($formElement, 'name:1', '', $json);
327
        $this->assertEquals('<input id="123" name="name:1" maxlength="255" type="input" value="" pattern="' . PATTERN_NUMERICAL .
Carsten  Rose's avatar
Carsten Rose committed
328
            '" data-pattern-error="' . SANITIZE_ALLOW_NUMERICAL_MESSAGE .
329
            '" data-error="' . F_FE_DATA_ERROR_DEFAULT . '" data-hidden="no" data-required="no" class="form-control" ><div class="help-block with-errors hidden"></div>', $result);
Carsten  Rose's avatar
Carsten Rose committed
330
331
332
333

        // Defaults data-pattern-error: EMAIL
        $formElement[FE_CHECK_TYPE] = SANITIZE_ALLOW_EMAIL;
        $result = $build->buildInput($formElement, 'name:1', '', $json);
334
        $this->assertEquals('<input id="123" name="name:1" maxlength="255" type="input" value="" pattern="' . PATTERN_EMAIL .
Carsten  Rose's avatar
Carsten Rose committed
335
            '" data-pattern-error="' . SANITIZE_ALLOW_EMAIL_MESSAGE .
336
            '" data-error="' . F_FE_DATA_ERROR_DEFAULT . '" data-hidden="no" data-required="no" class="form-control" ><div class="help-block with-errors hidden"></div>', $result);
Carsten  Rose's avatar
Carsten Rose committed
337
338
339
340

        // Defaults data-pattern-error: ALLBUT
        $formElement[FE_CHECK_TYPE] = SANITIZE_ALLOW_ALLBUT;
        $result = $build->buildInput($formElement, 'name:1', '', $json);
341
        $this->assertEquals('<input id="123" name="name:1" maxlength="255" type="input" value="" pattern="' . PATTERN_ALLBUT .
Carsten  Rose's avatar
Carsten Rose committed
342
            '" data-pattern-error="' . SANITIZE_ALLOW_ALLBUT_MESSAGE .
343
            '" data-error="' . F_FE_DATA_ERROR_DEFAULT . '" data-hidden="no" data-required="no" class="form-control" ><div class="help-block with-errors hidden"></div>', $result);
Carsten  Rose's avatar
Carsten Rose committed
344
345
346
    }

    /**
Marc Egger's avatar
Marc Egger committed
347
348
349
     * @throws \CodeException
     * @throws \UserFormException
     * @throws \UserReportException
Carsten  Rose's avatar
Carsten Rose committed
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
     */
    public function testBuildInputCustomErrorText() {
        $form = array();
        $formElement = array();
        $json = array();

        $this->templateFormNFormElement($form, $formElement);

        $build = new BuildFormPlain($form, array(), [$formElement], $this->dbArray);
        $formElement[FE_CHECK_TYPE] = SANITIZE_ALLOW_ALL;
        $formElement[FE_DECIMAL_FORMAT] = '';

        $label['123-l'][API_ELEMENT_CONTENT] = '<label for="name:1" class="control-label" >Name</label>';
        $label['123'][API_ELEMENT_ATTRIBUTE] = ['value' => '', 'required' => false, 'hidden' => false];
        $label['123-r'][API_ELEMENT_ATTRIBUTE] = ['class' => ''];

        // Defaults data-error: ALNUMX
        $formElement[FE_CHECK_TYPE] = SANITIZE_ALLOW_ALNUMX;
        $formElement[F_FE_DATA_ERROR] = 'custom data text';
        $formElement[F_FE_DATA_PATTERN_ERROR] = 'custom pattern text';
        $result = $build->buildInput($formElement, 'name:1', '', $json);
371
        $this->assertEquals('<input id="123" name="name:1" maxlength="255" type="input" value="" pattern="' . PATTERN_ALNUMX .
Carsten  Rose's avatar
Carsten Rose committed
372
            '" data-pattern-error="' . $formElement[F_FE_DATA_PATTERN_ERROR] .
373
            '" data-error="' . $formElement[F_FE_DATA_ERROR] . '" data-hidden="no" data-required="no" class="form-control" ><div class="help-block with-errors hidden"></div>', $result);
Carsten  Rose's avatar
Carsten Rose committed
374
375
376
377
378
379
380

        // Defaults data-error: ALNUMX
        $formElement[FE_CHECK_TYPE] = SANITIZE_ALLOW_PATTERN;
        $formElement[FE_CHECK_PATTERN] = '[0-4]';
        $formElement[F_FE_DATA_ERROR] = 'custom data text';
        $formElement[F_FE_DATA_PATTERN_ERROR] = 'custom pattern text';
        $result = $build->buildInput($formElement, 'name:1', '', $json);
381
        $this->assertEquals('<input id="123" name="name:1" maxlength="255" type="input" value="" pattern="[0-4]' .
Carsten  Rose's avatar
Carsten Rose committed
382
            '" data-pattern-error="' . $formElement[F_FE_DATA_PATTERN_ERROR] .
383
            '" data-error="' . $formElement[F_FE_DATA_ERROR] . '" data-hidden="no" data-required="no" class="form-control" ><div class="help-block with-errors hidden"></div>', $result);
384
385
    }

386
387

    /**
Marc Egger's avatar
Marc Egger committed
388
389
390
391
     * @throws \CodeException
     * @throws \DbException
     * @throws \UserFormException
     * @throws \UserReportException
392
393
394
395
396
397
398
     */
    public function testBuildSubrecord() {
        $form = array();
        $formElement = array();
        $json = array();

        $this->templateFormNFormElement($form, $formElement);
Carsten  Rose's avatar
Carsten Rose committed
399
        $formElement = Support::setFeDefaults($formElement);
Carsten  Rose's avatar
Carsten Rose committed
400

401
        // CheckType
Carsten  Rose's avatar
Carsten Rose committed
402
        $build = new BuildFormPlain($form, array(), [$formElement], $this->dbArray);
403
404

        // id: 1, firstName: John, name: Doe
405
        $formElement['sql1'] = $this->dbArray[DB_INDEX_DEFAULT]->sql('SELECT id, name, firstName FROM Person ORDER BY id LIMIT 2');
Carsten  Rose's avatar
Carsten Rose committed
406
        $formElement[SUBRECORD_PARAMETER_FORM] = 'Person';
Carsten  Rose's avatar
Carsten Rose committed
407
        $formElement[FE_SUBRECORD_OPTION] = '';
Carsten  Rose's avatar
Carsten Rose committed
408

409
        $result = $build->buildSubrecord($formElement, 'name:1', '', $json);
Carsten  Rose's avatar
Carsten Rose committed
410
        $this->assertEquals('<table class="table table-hover qfq-subrecord-table qfq-color-grey-2" id="1-123" ><thead><tr><th>id</th><th>name</th><th>firstName</th></tr></thead><tbody ><tr class="record" ><td><span class="text-muted">1</span></td><td>Doe</td><td>John</td></tr><tr class="record" ><td><span class="text-muted">2</span></td><td>Smith</td><td>Jane</td></tr></tbody></table>', $result);
Marc Egger's avatar
Marc Egger committed
411
 //       $this->assertEquals('Please save this record first.', $result);
412
413

        $this->store->setStore(['id' => 1], STORE_RECORD, true);
414
        $result = $build->buildSubrecord($formElement, 'name:1', '', $json);
Carsten  Rose's avatar
Carsten Rose committed
415
        $this->assertEquals('<table class="table table-hover qfq-subrecord-table qfq-color-grey-2" id="1-123" ><thead><tr><th>id</th><th>name</th><th>firstName</th></tr></thead><tbody ><tr class="record" ><td><span class="text-muted">1</span></td><td>Doe</td><td>John</td></tr><tr class="record" ><td><span class="text-muted">2</span></td><td>Smith</td><td>Jane</td></tr></tbody></table>', $result);
416
417

        // _id: 1, name: Doe,
418
        $formElement['sql1'] = $this->dbArray[DB_INDEX_DEFAULT]->sql('SELECT id AS "_id", name FROM Person ORDER BY id LIMIT 2');
419
        $result = $build->buildSubrecord($formElement, 'name:1', '', $json);
Carsten  Rose's avatar
Carsten Rose committed
420
        $this->assertEquals('<table class="' . SUBRECORD_TABLE_CLASS_DEFAULT . '" id="1-123" ><thead><tr><th>name</th></tr></thead><tbody ><tr class="record" ><td>Doe</td></tr><tr class="record" ><td>Smith</td></tr></tbody></table>', $result);
421

422
        // _id: 1, name: Doe,title=''
423
        $formElement['sql1'] = $this->dbArray[DB_INDEX_DEFAULT]->sql('SELECT id AS "_id", name AS "title=" FROM Person ORDER BY id LIMIT 2');
424
        $result = $build->buildSubrecord($formElement, 'name:1', '', $json);
Carsten  Rose's avatar
Carsten Rose committed
425
        $this->assertEquals('<table class="' . SUBRECORD_TABLE_CLASS_DEFAULT . '" id="1-123" ><thead><tr><th></th></tr></thead><tbody ><tr class="record" ><td>Doe</td></tr><tr class="record" ><td>Smith</td></tr></tbody></table>', $result);
426
427

        // _id: 1, name: Doe, column: _Person
428
        $formElement['sql1'] = $this->dbArray[DB_INDEX_DEFAULT]->sql('SELECT id AS "_id", name AS "unused|width=2|title=_Person", firstName  FROM Person ORDER BY id LIMIT 2');
429
        $result = $build->buildSubrecord($formElement, 'name:1', '', $json);
Carsten  Rose's avatar
Carsten Rose committed
430
        $this->assertEquals('<table class="' . SUBRECORD_TABLE_CLASS_DEFAULT . '" id="1-123" ><thead><tr><th>firstName</th></tr></thead><tbody ><tr class="record" ><td>John</td></tr><tr class="record" ><td>Jane</td></tr></tbody></table>', $result);
431

432
        // _id: 1, name: Doe, title: PERSON
433
        $formElement['sql1'] = $this->dbArray[DB_INDEX_DEFAULT]->sql('SELECT id AS "_id", name AS "PERSON" FROM Person ORDER BY id LIMIT 2');
434
        $result = $build->buildSubrecord($formElement, 'name:1', '', $json);
Carsten  Rose's avatar
Carsten Rose committed
435
        $this->assertEquals('<table class="' . SUBRECORD_TABLE_CLASS_DEFAULT . '" id="1-123" ><thead><tr><th>PERSON</th></tr></thead><tbody ><tr class="record" ><td>Doe</td></tr><tr class="record" ><td>Smith</td></tr></tbody></table>', $result);
436
437

        // _id: 1, "This is a much longer text than necessary": Default max:20
438
        $formElement['sql1'] = $this->dbArray[DB_INDEX_DEFAULT]->sql('SELECT id AS "_id", "This is a much longer text than necessary" FROM Person ORDER BY id LIMIT 1');
439
        $result = $build->buildSubrecord($formElement, 'name:1', '', $json);
Carsten  Rose's avatar
Carsten Rose committed
440
        $this->assertEquals('<table class="' . SUBRECORD_TABLE_CLASS_DEFAULT . '" id="1-123" ><thead><tr><th>This is a much longe</th></tr></thead><tbody ><tr class="record" ><td>This is a much longe</td></tr></tbody></table>', $result);
441
442

        // _id: 1, name: Jo (width:2)
443
        $formElement['sql1'] = $this->dbArray[DB_INDEX_DEFAULT]->sql('SELECT id AS "_id", name AS "2" FROM Person ORDER BY id LIMIT 2');
444
        $result = $build->buildSubrecord($formElement, 'name:1', '', $json);
Carsten  Rose's avatar
Carsten Rose committed
445
        $this->assertEquals('<table class="' . SUBRECORD_TABLE_CLASS_DEFAULT . '" id="1-123" ><thead><tr><th></th></tr></thead><tbody ><tr class="record" ><td>Do</td></tr><tr class="record" ><td>Sm</td></tr></tbody></table>', $result);
446
447

        // _id: 1, name: Jo (width:2)
448
        $formElement['sql1'] = $this->dbArray[DB_INDEX_DEFAULT]->sql('SELECT id AS "_id", name AS "2|PERSON" FROM Person ORDER BY id LIMIT 2');
449
        $result = $build->buildSubrecord($formElement, 'name:1', '', $json);
Carsten  Rose's avatar
Carsten Rose committed
450
        $this->assertEquals('<table class="' . SUBRECORD_TABLE_CLASS_DEFAULT . '" id="1-123" ><thead><tr><th>PE</th></tr></thead><tbody ><tr class="record" ><td>Do</td></tr><tr class="record" ><td>Sm</td></tr></tbody></table>', $result);
451
452

        // _id: 1, name: Doe ('width':3)
453
        $formElement['sql1'] = $this->dbArray[DB_INDEX_DEFAULT]->sql('SELECT id AS "_id", name AS "Name|width=3" FROM Person ORDER BY id LIMIT 2');
454
        $result = $build->buildSubrecord($formElement, 'name:1', '', $json);
Carsten  Rose's avatar
Carsten Rose committed
455
        $this->assertEquals('<table class="' . SUBRECORD_TABLE_CLASS_DEFAULT . '" id="1-123" ><thead><tr><th>Nam</th></tr></thead><tbody ><tr class="record" ><td>Doe</td></tr><tr class="record" ><td>Smi</td></tr></tbody></table>', $result);
456
457

        // _id: 1, name: Doe (width:3, title:PERSON)
458
        $formElement['sql1'] = $this->dbArray[DB_INDEX_DEFAULT]->sql('SELECT id AS "_id", name AS "3|title=PERSON" FROM Person ORDER BY id LIMIT 2');
459
        $result = $build->buildSubrecord($formElement, 'name:1', '', $json);
Carsten  Rose's avatar
Carsten Rose committed
460
        $this->assertEquals('<table class="' . SUBRECORD_TABLE_CLASS_DEFAULT . '" id="1-123" ><thead><tr><th>PER</th></tr></thead><tbody ><tr class="record" ><td>Doe</td></tr><tr class="record" ><td>Smi</td></tr></tbody></table>', $result);
461
462

        // _id: 1, name: <b>Doe</b>
463
        $formElement['sql1'] = $this->dbArray[DB_INDEX_DEFAULT]->sql('SELECT id AS "_id", CONCAT("<b>", name, "</b>") AS "Name" FROM Person ORDER BY id LIMIT 2');
464
        $result = $build->buildSubrecord($formElement, 'name:1', '', $json);
Carsten  Rose's avatar
Carsten Rose committed
465
        $this->assertEquals('<table class="' . SUBRECORD_TABLE_CLASS_DEFAULT . '" id="1-123" ><thead><tr><th>Name</th></tr></thead><tbody ><tr class="record" ><td>Doe</td></tr><tr class="record" ><td>Smith</td></tr></tbody></table>', $result);
466

467
        // _id: 1, name: <b>Doe</b>, width=2
468
        $formElement['sql1'] = $this->dbArray[DB_INDEX_DEFAULT]->sql('SELECT id AS "_id", CONCAT("<b>", name, "</b>") AS "Name|2" FROM Person ORDER BY id LIMIT 2');
469
        $result = $build->buildSubrecord($formElement, 'name:1', '', $json);
Carsten  Rose's avatar
Carsten Rose committed
470
        $this->assertEquals('<table class="' . SUBRECORD_TABLE_CLASS_DEFAULT . '" id="1-123" ><thead><tr><th>Na</th></tr></thead><tbody ><tr class="record" ><td>Do</td></tr><tr class="record" ><td>Sm</td></tr></tbody></table>', $result);
471

472
        // _id: 1, name: <b>Doe</b> , nostrip
473
        $formElement['sql1'] = $this->dbArray[DB_INDEX_DEFAULT]->sql('SELECT id AS "_id", CONCAT("<b>", name, "</b>") AS "Name|nostrip" FROM Person ORDER BY id LIMIT 2');
474
        $result = $build->buildSubrecord($formElement, 'name:1', '', $json);
Carsten  Rose's avatar
Carsten Rose committed
475
        $this->assertEquals('<table class="' . SUBRECORD_TABLE_CLASS_DEFAULT . '" id="1-123" ><thead><tr><th>Name</th></tr></thead><tbody ><tr class="record" ><td><b>Doe</b></td></tr><tr class="record" ><td><b>Smith</b></td></tr></tbody></table>', $result);
476
477

        // _id: 1, icon: bullet-green.gif
478
        $formElement['sql1'] = $this->dbArray[DB_INDEX_DEFAULT]->sql('SELECT id AS "_id", "bullet-green.gif" AS "Status|icon" FROM Person ORDER BY id LIMIT 2');
479
        $result = $build->buildSubrecord($formElement, 'name:1', '', $json);
Carsten  Rose's avatar
Carsten Rose committed
480
        $this->assertEquals('<table class="' . SUBRECORD_TABLE_CLASS_DEFAULT . '" id="1-123" ><thead><tr><th>Status</th></tr></thead><tbody ><tr class="record" ><td><image src=\'typo3conf/ext/qfq/Resources/Public/icons/bullet-green.gif\'></td></tr><tr class="record" ><td><image src=\'typo3conf/ext/qfq/Resources/Public/icons/bullet-green.gif\'></td></tr></tbody></table>', $result);
481
482

        // _id: 1, mailto: john@doe.com
483
        $formElement['sql1'] = $this->dbArray[DB_INDEX_DEFAULT]->sql('SELECT id AS "_id", "john@doe.com" AS "EMail|mailto" FROM Person ORDER BY id LIMIT 2');
484
        $result = $build->buildSubrecord($formElement, 'name:1', '', $json);
Carsten  Rose's avatar
Carsten Rose committed
485
        $this->assertEquals('<table class="' . SUBRECORD_TABLE_CLASS_DEFAULT . '" id="1-123" ><thead><tr><th>EMail</th></tr></thead><tbody ><tr class="record" ><td><a href="mailto:john@doe.com" >john@doe.com</a></td></tr><tr class="record" ><td><a href="mailto:john@doe.com" >john@doe.com</a></td></tr></tbody></table>', $result);
486
487

        // _id: 1, url: www.uzh.ch
488
        $formElement['sql1'] = $this->dbArray[DB_INDEX_DEFAULT]->sql('SELECT id AS "_id", "www.uzh.ch" AS "URL|url" FROM Person ORDER BY id LIMIT 2');
489
        $result = $build->buildSubrecord($formElement, 'name:1', '', $json);
Carsten  Rose's avatar
Carsten Rose committed
490
        $this->assertEquals('<table class="' . SUBRECORD_TABLE_CLASS_DEFAULT . '" id="1-123" ><thead><tr><th>URL</th></tr></thead><tbody ><tr class="record" ><td><a href="www.uzh.ch" >www.uzh.ch</a></td></tr><tr class="record" ><td><a href="www.uzh.ch" >www.uzh.ch</a></td></tr></tbody></table>', $result);
491
492

        // _id: 1, name: Doe, _rowclass (text)
493
        $formElement['sql1'] = $this->dbArray[DB_INDEX_DEFAULT]->sql('SELECT id AS "_id", name, IF(id=1,"text-warning", "text-danger") AS _rowClass FROM Person ORDER BY id LIMIT 2');
494
        $result = $build->buildSubrecord($formElement, 'name:1', '', $json);
Carsten  Rose's avatar
Carsten Rose committed
495
        $this->assertEquals('<table class="' . SUBRECORD_TABLE_CLASS_DEFAULT . '" id="1-123" ><thead><tr><th>name</th></tr></thead><tbody ><tr class="record text-warning" ><td>Doe</td></tr><tr class="record text-danger" ><td>Smith</td></tr></tbody></table>', $result);
496
497

        // _id: 1, name: Doe, _rowClass (text & background)
498
        $formElement['sql1'] = $this->dbArray[DB_INDEX_DEFAULT]->sql('SELECT id AS "_id", name, IF(id=1,"text-warning active", "text-danger success") AS _rowClass FROM Person ORDER BY id LIMIT 2');
499
        $result = $build->buildSubrecord($formElement, 'name:1', '', $json);
Carsten  Rose's avatar
Carsten Rose committed
500
        $this->assertEquals('<table class="' . SUBRECORD_TABLE_CLASS_DEFAULT . '" id="1-123" ><thead><tr><th>name</th></tr></thead><tbody ><tr class="record text-warning active" ><td>Doe</td></tr><tr class="record text-danger success" ><td>Smith</td></tr></tbody></table>', $result);
501
502

        // _id: 1, name: Doe, _rowTitle
503
        $formElement['sql1'] = $this->dbArray[DB_INDEX_DEFAULT]->sql('SELECT id AS "_id", name, firstName AS _rowTitle FROM Person ORDER BY id LIMIT 2');
504
        $result = $build->buildSubrecord($formElement, 'name:1', '', $json);
Carsten  Rose's avatar
Carsten Rose committed
505
        $this->assertEquals('<table class="' . SUBRECORD_TABLE_CLASS_DEFAULT . '" id="1-123" ><thead><tr><th>name</th></tr></thead><tbody ><tr class="record" title="John" ><td>Doe</td></tr><tr class="record" title="Jane" ><td>Smith</td></tr></tbody></table>', $result);
506
507

        // _id: 1, name: Doe, title, width, nostrip
508
        $formElement['sql1'] = $this->dbArray[DB_INDEX_DEFAULT]->sql('SELECT id AS "_id", name, "<b>This again is a very long text</b>" AS "title=Important|width=10|nostrip" FROM Person ORDER BY id LIMIT 2');
509
        $result = $build->buildSubrecord($formElement, 'name:1', '', $json);
Carsten  Rose's avatar
Carsten Rose committed
510
        $this->assertEquals('<table class="' . SUBRECORD_TABLE_CLASS_DEFAULT . '" id="1-123" ><thead><tr><th>name</th><th>Important</th></tr></thead><tbody ><tr class="record" ><td>Doe</td><td><b>This again is a very long text</b></td></tr><tr class="record" ><td>Smith</td><td><b>This again is a very long text</b></td></tr></tbody></table>', $result);
511
512

        // _id: 1, name: Doe, link
513
        $formElement['sql1'] = $this->dbArray[DB_INDEX_DEFAULT]->sql('SELECT id AS "_id", name, CONCAT("s:1|p:form&form=person&r=" , id , "|t:", name) AS "link" FROM Person ORDER BY id LIMIT 2');
514
        $result = $build->buildSubrecord($formElement, 'name:1', '', $json);
Carsten  Rose's avatar
Carsten Rose committed
515
        $this->assertEquals('<table class="' . SUBRECORD_TABLE_CLASS_DEFAULT . '" id="1-123" ><thead><tr><th>name</th><th></th></tr></thead><tbody ><tr class="record" ><td>Doe</td><td><a href="index.php?id=form&s=badcaffee1234" >Doe</a></td></tr><tr class="record" ><td>Smith</td><td><a href="index.php?id=form&s=badcaffee1234" >Smith</a></td></tr></tbody></table>', $result);
516
517
    }

518
    /**
519
520
     * @param array $form
     * @param array $formElement
521
522
523
     */
    private function templateFormNFormElement(array &$form, array &$formElement) {
        $form = [
Carsten  Rose's avatar
Carsten Rose committed
524
525
526
527
528
529
530
            'id' => '1',
            'name' => 'form',
            'title' => 'Form Editor: {{SELECT id, " / ", title FROM Form WHERE id => {{recordId:S0}}}}',
            'noteInternal' => 'Please secure the form',
            'tableName' => 'Form',
            'permitNew' => 'always',
            'permitEdit' => 'always',
531
            'permitUrlParameter' => '',
Carsten  Rose's avatar
Carsten Rose committed
532
533
            'render' => 'bootstrap',
            'multiMode' => 'none',
534
            F_MULTI_SQL => '',
535
536
            'multiDetailForm' => '',
            'multiDetailFormParameter' => '',
Carsten  Rose's avatar
Carsten Rose committed
537
538
539
540
541
542
543
            F_FORWARD_MODE => 'auto',
            F_FORWARD_PAGE => '',
            'bsLabelColumns' => '',
            'bsInputColumns' => '',
            'bsNoteColumns' => '',
            'parameter' => 'maxVisiblePill=>3',
            'deleted' => 'no',
Carsten  Rose's avatar
Carsten Rose committed
544
            F_DB_INDEX => DB_INDEX_DEFAULT,
545
546
547
        ];

        $formElement = [
Carsten  Rose's avatar
Carsten Rose committed
548
            'id' => 123,
Carsten  Rose's avatar
Carsten Rose committed
549
            FE_FORM_ID => 1,
550
551
            FE_ID_CONTAINER => 0,
            FE_DYNAMIC_UPDATE => 'no',
Carsten  Rose's avatar
Carsten Rose committed
552
553
554
555
            'enabled' => 'yes',
            FE_NAME => 'name',
            FE_LABEL => 'Name',
            FE_MODE => 'show',
Carsten  Rose's avatar
Carsten Rose committed
556
            FE_MODE_SQL => '',
Carsten  Rose's avatar
Carsten Rose committed
557
558
559
560
561
562
563
564
565
566
567
568
            'class' => 'native',
            FE_TYPE => 'input',
            'value' => '',
            'sql1' => '',
            'parameter' => '',
            'debug' => 'no',
            'deleted' => 'no',
            'size' => '',
            'maxLength' => '255',
            'tooltip' => '',
            'placeholder' => '',
            FE_CHECK_TYPE => '',
569
            FE_CHECK_PATTERN => '',
Carsten  Rose's avatar
Carsten Rose committed
570
571
            FE_HTML_ID => '123',
            FE_HIDE_ZERO => '0',
Carsten  Rose's avatar
Carsten Rose committed
572
            FE_DATA_REFERENCE => '',
573

574
575
            F_FE_DATA_ERROR => F_FE_DATA_ERROR_DEFAULT,
            F_FE_DATA_PATTERN_ERROR => F_FE_DATA_PATTERN_ERROR_DEFAULT,
576
            F_FE_DATA_PATTERN_ERROR_SYSTEM => F_FE_DATA_PATTERN_ERROR_DEFAULT,
577

Carsten  Rose's avatar
Carsten Rose committed
578
            'tabindex' => 0,
579
580
581
582
583
584
585
586
587
588
589
590
591
        ];

    }

//    /**
//     * @throws Exception
//     */
//    protected function setUp() {
//        parent::setUp();
//
//        $this->executeSQLFile(__DIR__ . '/fixtures/Generic.sql', true);
//    }

592
    /**
Marc Egger's avatar
Marc Egger committed
593
     *
594
595
596
597
     */
    protected function setUp() {
        $_GET['form'] = 'phpunit_person';

598
599
        try {
            parent::setUp();
600

601
602
603
            // Use always the latest (production) FormEditor: played during QuickFormQuery()
            $this->dbArray[DB_INDEX_DEFAULT]->sql("DROP TABLE IF EXISTS `Form`");
            $this->dbArray[DB_INDEX_DEFAULT]->sql("DROP TABLE IF EXISTS `FormElement`");
Marc Egger's avatar
Marc Egger committed
604
            $this->executeSQLFile(__DIR__ . '/../../../Classes/Sql/formEditor.sql', true);
605

606
            $this->store->unsetStore(STORE_ADDITIONAL_FORM_ELEMENTS);
Marc Egger's avatar
Marc Egger committed
607
608
            $this->executeSQLFile(__DIR__ . '/Database/fixtures/Generic.sql', true);
            $this->executeSQLFile(__DIR__ . '/Database/fixtures/TestForm.sql', true);
609

610
611
612
            // Defaults
            $this->store->setVar('name', 'varchar(255)', STORE_TABLE_COLUMN_TYPES, true);
            $this->store->setVar('deleted', "enum('yes','no')", STORE_TABLE_COLUMN_TYPES, true);
613
614
615
//        $this->store->setVar(SYSTEM_DB_INDEX_DATA, DB_INDEX_DEFAULT, true);
//        $this->store->setVar(SYSTEM_DB_INDEX_QFQ, DB_INDEX_DEFAULT, true);

616

617
            $GLOBALS["TSFE"] = new FakeTSFEBuildPlain();
618

619
            $form = new QuickFormQuery(['bodytext' => "form=form\nr=3", 'uid' => 1234], true);
Carsten  Rose's avatar
Carsten Rose committed
620

621
622
623
624
625
626
            // After instantiating QuickFormQuery, the latest updates will be played. The SIP is by default activated which breaks current tests.
            $this->dbArray[DB_INDEX_DEFAULT]->sql("UPDATE Form SET permitNew='always', permitEdit='always' WHERE name='form' ");
            $form->process();
        } catch (\Exception $e) {
            echo 'unhandled exception';
        }
627
628
    }
}
629

630
631
632
/**
 * Class FakeTSFEBuildPlain
 */
633
class FakeTSFEBuildPlain {
634
    public $id = 1;
635
636
    public $type = 1;
    public $sys_language_uid = 1;
637
638
}

639

640