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
use IMATHUZH\Qfq\Core\BuildFormPlain;
Marc Egger's avatar
Marc Egger committed
9
10

use IMATHUZH\Qfq\Core\Helper\Path;
Marc Egger's avatar
Marc Egger committed
11
12
13
14
15
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');
16

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

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

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

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

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

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

    }

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

        $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);
    }

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

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

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

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

Carsten  Rose's avatar
Carsten Rose committed
91
        $result = $build->buildInput($formElement, 'name:1', '', $json);
92
        $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
93
        $this->assertEquals(['disabled' => false, FE_MODE_REQUIRED => '', 'form-element' => 'name:1', 'value' => '', API_ELEMENT_UPDATE => $label], $json);
94

95
        // Min/Max
96
97
        $formElement[FE_MIN] = '1';
        $formElement[FE_MAX] = '10';
Carsten  Rose's avatar
Carsten Rose committed
98
        $result = $build->buildInput($formElement, 'name:1', '', $json);
99
        $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);
100
        $this->assertEquals(['disabled' => false, FE_MODE_REQUIRED => '', 'form-element' => 'name:1', 'value' => '', API_ELEMENT_UPDATE => $label], $json);
101

102
        $formElement[FE_MIN] = '1';
103
104
        $formElement[FE_MAX] = '';
        $result = $build->buildInput($formElement, 'name:1', '', $json);
105
        $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);
106
        $this->assertEquals(['disabled' => false, FE_MODE_REQUIRED => '', 'form-element' => 'name:1', 'value' => '', API_ELEMENT_UPDATE => $label], $json);
107
108

        $formElement[FE_MIN] = '';
109
        $formElement[FE_MAX] = '10';
110
        $result = $build->buildInput($formElement, 'name:1', '', $json);
111
        $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);
112
        $this->assertEquals(['disabled' => false, FE_MODE_REQUIRED => '', 'form-element' => 'name:1', 'value' => '', API_ELEMENT_UPDATE => $label], $json);
113
114
115
116

        $formElement[FE_MIN] = '0';
        $formElement[FE_MAX] = '10';
        $result = $build->buildInput($formElement, 'name:1', '', $json);
117
        $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);
118
119
120
121
122
        $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);
123
        $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);
124
125
        $this->assertEquals(['disabled' => false, FE_MODE_REQUIRED => '', 'form-element' => 'name:1', 'value' => '', API_ELEMENT_UPDATE => $label], $json);

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

130
        // CheckType: custom pattern, standard data-pattern-error
131
132
        $formElement[FE_CHECK_TYPE] = SANITIZE_ALLOW_PATTERN;
        $formElement[FE_CHECK_PATTERN] = '^[a-z]*$';
Carsten  Rose's avatar
Carsten Rose committed
133
        $result = $build->buildInput($formElement, 'name:1', '', $json);
134
        $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
135
        $label['123'][API_ELEMENT_ATTRIBUTE]['pattern'] = '^[a-z]*$';
136
        $this->assertEquals(['disabled' => false, FE_MODE_REQUIRED => '', 'form-element' => 'name:1', 'value' => '', API_ELEMENT_UPDATE => $label], $json);
137

138
139
        $formElement[FE_CHECK_TYPE] = SANITIZE_ALLOW_DIGIT;
        $formElement[FE_CHECK_PATTERN] = '';
Carsten  Rose's avatar
Carsten Rose committed
140
        $result = $build->buildInput($formElement, 'name:1', '', $json);
141
        $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
142
143

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

146
147
        $formElement[FE_CHECK_TYPE] = SANITIZE_ALLOW_EMAIL;
        $formElement[FE_CHECK_PATTERN] = '';
Carsten  Rose's avatar
Carsten Rose committed
148
        $result = $build->buildInput($formElement, 'name:1', '', $json);
Marc Egger's avatar
Marc Egger committed
149
        $label['123'][API_ELEMENT_ATTRIBUTE]['pattern'] = '^([a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,})?$';
150
        $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);
151
        $this->assertEquals(['disabled' => false, FE_MODE_REQUIRED => '', 'form-element' => 'name:1', 'value' => '', API_ELEMENT_UPDATE => $label], $json);
152

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


157
158
159
        // Decimal format
        $formElement[FE_DECIMAL_FORMAT] = '5,2';
        $result = $build->buildInput($formElement, 'name:1', '', $json);
160
        $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
161
        $label['123'][API_ELEMENT_ATTRIBUTE]['pattern'] = '^-?[0-9]{0,3}(\.[0-9]{0,2})?$';
162
        $this->assertEquals(['disabled' => false, FE_MODE_REQUIRED => '', 'form-element' => 'name:1', 'value' => '', API_ELEMENT_UPDATE => $label], $json);
163
164
165
166
167

        $formElement[FE_DECIMAL_FORMAT] = '';


        // Explicit size
168
169
        $formElement['size'] = 40;
        $formElement['maxLength'] = 40;
Carsten  Rose's avatar
Carsten Rose committed
170
        $result = $build->buildInput($formElement, 'name:1', '', $json);
171
        $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
172
        unset($label['123'][API_ELEMENT_ATTRIBUTE]['pattern']);
173
        $this->assertEquals(['disabled' => false, FE_MODE_REQUIRED => '', 'form-element' => 'name:1', 'value' => '', API_ELEMENT_UPDATE => $label], $json);
174
175

        // maxlength bigger than physical spec:
176
        $formElement['maxLength'] = 1000;
Carsten  Rose's avatar
Carsten Rose committed
177
        $result = $build->buildInput($formElement, 'name:1', '', $json);
178
        $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);
179
        $this->assertEquals(['disabled' => false, FE_MODE_REQUIRED => '', 'form-element' => 'name:1', 'value' => '', API_ELEMENT_UPDATE => $label], $json);
180

181
182
183
184
185
186
        // 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);
187
        $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);
188
189
190
191

        // no size,  given maxlength and column not in primary table
        $formElement2['maxLength'] = '10';
        $result = $build->buildInput($formElement2, 'specialname:1', '', $json);
192
        $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);
193
194
195
196
197

        // size given, no maxlength and column not in primary table
        $formElement2['maxLength'] = '';
        $formElement2['size'] = '10';
        $result = $build->buildInput($formElement2, 'specialname:1', '', $json);
198
        $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);
199
200
201
202
203

        // size given, maxlength given and column not in primary table
        $formElement2['maxLength'] = '20';
        $formElement2['size'] = '10';
        $result = $build->buildInput($formElement2, 'specialname:1', '', $json);
204
        $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);
205
206
        $formElement2['maxLength'] = '';
        $formElement2['size'] = '';
207

208
        // Explicit: further
209
210
211
        $formElement2['tooltip'] = 'Nice Tooltip';
        $formElement2['placeholder'] = 'Please type a name';
        $result = $build->buildInput($formElement2, 'name:1', 'Hello World', $json);
212
        $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
213
        $label['123'][API_ELEMENT_ATTRIBUTE] = ['value' => 'Hello World', 'required' => false, 'hidden' => false];
214
        $this->assertEquals(['disabled' => false, FE_MODE_REQUIRED => '', 'form-element' => 'name:1', 'value' => 'Hello World', API_ELEMENT_UPDATE => $label], $json);
215
216

        // textarea
217
218
        $formElement2['size'] = '40,10';
        $result = $build->buildInput($formElement2, 'name:1', 'Hello World', $json);
219
        $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);
220

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

223
224
        $formElement2['size'] = ' 40     , 10 ';
        $result = $build->buildInput($formElement2, 'name:1', 'Hello World', $json);
225
        $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);
226
        $this->assertEquals(['disabled' => false, FE_MODE_REQUIRED => '', 'form-element' => 'name:1', 'value' => 'Hello World', API_ELEMENT_UPDATE => $label], $json);
227
228
    }

229
    /**
Marc Egger's avatar
Marc Egger committed
230
231
232
     * @throws \CodeException
     * @throws \UserFormException
     * @throws \UserReportException
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
     */
    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);
251
        $this->assertEquals('<input id="123" name="name:1" maxlength="255" type="input" value="" pattern="' . PATTERN_ALNUMX .
252
            '" data-pattern-error="' . SANITIZE_ALLOW_ALNUMX_MESSAGE .
253
            '" data-error="Error" data-hidden="no" data-required="no" class="form-control" ><div class="help-block with-errors hidden"></div>', $result);
254
255
256

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

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

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

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

        $formElement[FE_CHECK_TYPE] = SANITIZE_ALLOW_ALL;
        $result = $build->buildInput($formElement, 'name:1', '', $json);
281
        $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);
282
283
284
285

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

    /**
Marc Egger's avatar
Marc Egger committed
292
293
294
     * @throws \CodeException
     * @throws \UserFormException
     * @throws \UserReportException
295
     */
Carsten  Rose's avatar
Carsten Rose committed
296
    public function testBuildInputSpecificErrorTextDefault() {
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
        $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);
314
        $this->assertEquals('<input id="123" name="name:1" maxlength="255" type="input" value="" pattern="' . PATTERN_ALNUMX .
315
            '" data-pattern-error="' . SANITIZE_ALLOW_ALNUMX_MESSAGE .
316
            '" 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);
317

Carsten  Rose's avatar
Carsten Rose committed
318
319
320
        // Defaults data-pattern-error: DIGIT
        $formElement[FE_CHECK_TYPE] = SANITIZE_ALLOW_DIGIT;
        $result = $build->buildInput($formElement, 'name:1', '', $json);
321
        $this->assertEquals('<input id="123" name="name:1" maxlength="255" type="input" value="" pattern="' . PATTERN_DIGIT .
Carsten  Rose's avatar
Carsten Rose committed
322
            '" data-pattern-error="' . SANITIZE_ALLOW_DIGIT_MESSAGE .
323
            '" 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);
324

Carsten  Rose's avatar
Carsten Rose committed
325
326
327
        // Defaults data-pattern-error: NUMERICAL
        $formElement[FE_CHECK_TYPE] = SANITIZE_ALLOW_NUMERICAL;
        $result = $build->buildInput($formElement, 'name:1', '', $json);
328
        $this->assertEquals('<input id="123" name="name:1" maxlength="255" type="input" value="" pattern="' . PATTERN_NUMERICAL .
Carsten  Rose's avatar
Carsten Rose committed
329
            '" data-pattern-error="' . SANITIZE_ALLOW_NUMERICAL_MESSAGE .
330
            '" 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
331
332
333
334

        // Defaults data-pattern-error: EMAIL
        $formElement[FE_CHECK_TYPE] = SANITIZE_ALLOW_EMAIL;
        $result = $build->buildInput($formElement, 'name:1', '', $json);
335
        $this->assertEquals('<input id="123" name="name:1" maxlength="255" type="input" value="" pattern="' . PATTERN_EMAIL .
Carsten  Rose's avatar
Carsten Rose committed
336
            '" data-pattern-error="' . SANITIZE_ALLOW_EMAIL_MESSAGE .
337
            '" 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
338
339
340
341

        // Defaults data-pattern-error: ALLBUT
        $formElement[FE_CHECK_TYPE] = SANITIZE_ALLOW_ALLBUT;
        $result = $build->buildInput($formElement, 'name:1', '', $json);
342
        $this->assertEquals('<input id="123" name="name:1" maxlength="255" type="input" value="" pattern="' . PATTERN_ALLBUT .
Carsten  Rose's avatar
Carsten Rose committed
343
            '" data-pattern-error="' . SANITIZE_ALLOW_ALLBUT_MESSAGE .
344
            '" 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
345
346
347
    }

    /**
Marc Egger's avatar
Marc Egger committed
348
349
350
     * @throws \CodeException
     * @throws \UserFormException
     * @throws \UserReportException
Carsten  Rose's avatar
Carsten Rose committed
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
     */
    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);
372
        $this->assertEquals('<input id="123" name="name:1" maxlength="255" type="input" value="" pattern="' . PATTERN_ALNUMX .
Carsten  Rose's avatar
Carsten Rose committed
373
            '" data-pattern-error="' . $formElement[F_FE_DATA_PATTERN_ERROR] .
374
            '" 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
375
376
377
378
379
380
381

        // 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);
382
        $this->assertEquals('<input id="123" name="name:1" maxlength="255" type="input" value="" pattern="[0-4]' .
Carsten  Rose's avatar
Carsten Rose committed
383
            '" data-pattern-error="' . $formElement[F_FE_DATA_PATTERN_ERROR] .
384
            '" 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);
385
386
    }

387
388

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

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

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

        // id: 1, firstName: John, name: Doe
406
        $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
407
        $formElement[SUBRECORD_PARAMETER_FORM] = 'Person';
Carsten  Rose's avatar
Carsten Rose committed
408
        $formElement[FE_SUBRECORD_OPTION] = '';
Carsten  Rose's avatar
Carsten Rose committed
409

410
        $result = $build->buildSubrecord($formElement, 'name:1', '', $json);
Carsten  Rose's avatar
Carsten Rose committed
411
        $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
412
 //       $this->assertEquals('Please save this record first.', $result);
413
414

        $this->store->setStore(['id' => 1], STORE_RECORD, true);
415
        $result = $build->buildSubrecord($formElement, 'name:1', '', $json);
Carsten  Rose's avatar
Carsten Rose committed
416
        $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);
417
418

        // _id: 1, name: Doe,
419
        $formElement['sql1'] = $this->dbArray[DB_INDEX_DEFAULT]->sql('SELECT id AS "_id", name FROM Person ORDER BY id LIMIT 2');
420
        $result = $build->buildSubrecord($formElement, 'name:1', '', $json);
Carsten  Rose's avatar
Carsten Rose committed
421
        $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);
422

423
        // _id: 1, name: Doe,title=''
424
        $formElement['sql1'] = $this->dbArray[DB_INDEX_DEFAULT]->sql('SELECT id AS "_id", name AS "title=" FROM Person ORDER BY id LIMIT 2');
425
        $result = $build->buildSubrecord($formElement, 'name:1', '', $json);
Carsten  Rose's avatar
Carsten Rose committed
426
        $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);
427
428

        // _id: 1, name: Doe, column: _Person
429
        $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');
430
        $result = $build->buildSubrecord($formElement, 'name:1', '', $json);
Carsten  Rose's avatar
Carsten Rose committed
431
        $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);
432

433
        // _id: 1, name: Doe, title: PERSON
434
        $formElement['sql1'] = $this->dbArray[DB_INDEX_DEFAULT]->sql('SELECT id AS "_id", name AS "PERSON" FROM Person ORDER BY id LIMIT 2');
435
        $result = $build->buildSubrecord($formElement, 'name:1', '', $json);
Carsten  Rose's avatar
Carsten Rose committed
436
        $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);
437
438

        // _id: 1, "This is a much longer text than necessary": Default max:20
439
        $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');
440
        $result = $build->buildSubrecord($formElement, 'name:1', '', $json);
Carsten  Rose's avatar
Carsten Rose committed
441
        $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);
442
443

        // _id: 1, name: Jo (width:2)
444
        $formElement['sql1'] = $this->dbArray[DB_INDEX_DEFAULT]->sql('SELECT id AS "_id", name AS "2" FROM Person ORDER BY id LIMIT 2');
445
        $result = $build->buildSubrecord($formElement, 'name:1', '', $json);
Carsten  Rose's avatar
Carsten Rose committed
446
        $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);
447
448

        // _id: 1, name: Jo (width:2)
449
        $formElement['sql1'] = $this->dbArray[DB_INDEX_DEFAULT]->sql('SELECT id AS "_id", name AS "2|PERSON" FROM Person ORDER BY id LIMIT 2');
450
        $result = $build->buildSubrecord($formElement, 'name:1', '', $json);
Carsten  Rose's avatar
Carsten Rose committed
451
        $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);
452
453

        // _id: 1, name: Doe ('width':3)
454
        $formElement['sql1'] = $this->dbArray[DB_INDEX_DEFAULT]->sql('SELECT id AS "_id", name AS "Name|width=3" FROM Person ORDER BY id LIMIT 2');
455
        $result = $build->buildSubrecord($formElement, 'name:1', '', $json);
Carsten  Rose's avatar
Carsten Rose committed
456
        $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);
457
458

        // _id: 1, name: Doe (width:3, title:PERSON)
459
        $formElement['sql1'] = $this->dbArray[DB_INDEX_DEFAULT]->sql('SELECT id AS "_id", name AS "3|title=PERSON" FROM Person ORDER BY id LIMIT 2');
460
        $result = $build->buildSubrecord($formElement, 'name:1', '', $json);
Carsten  Rose's avatar
Carsten Rose committed
461
        $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);
462
463

        // _id: 1, name: <b>Doe</b>
464
        $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');
465
        $result = $build->buildSubrecord($formElement, 'name:1', '', $json);
Carsten  Rose's avatar
Carsten Rose committed
466
        $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);
467

468
        // _id: 1, name: <b>Doe</b>, width=2
469
        $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');
470
        $result = $build->buildSubrecord($formElement, 'name:1', '', $json);
Carsten  Rose's avatar
Carsten Rose committed
471
        $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);
472

473
        // _id: 1, name: <b>Doe</b> , nostrip
474
        $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');
475
        $result = $build->buildSubrecord($formElement, 'name:1', '', $json);
Carsten  Rose's avatar
Carsten Rose committed
476
        $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);
477
478

        // _id: 1, icon: bullet-green.gif
479
        $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');
480
        $result = $build->buildSubrecord($formElement, 'name:1', '', $json);
Carsten  Rose's avatar
Carsten Rose committed
481
        $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);
482
483

        // _id: 1, mailto: john@doe.com
484
        $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');
485
        $result = $build->buildSubrecord($formElement, 'name:1', '', $json);
Carsten  Rose's avatar
Carsten Rose committed
486
        $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);
487
488

        // _id: 1, url: www.uzh.ch
489
        $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');
490
        $result = $build->buildSubrecord($formElement, 'name:1', '', $json);
Carsten  Rose's avatar
Carsten Rose committed
491
        $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);
492
493

        // _id: 1, name: Doe, _rowclass (text)
494
        $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');
495
        $result = $build->buildSubrecord($formElement, 'name:1', '', $json);
Carsten  Rose's avatar
Carsten Rose committed
496
        $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);
497
498

        // _id: 1, name: Doe, _rowClass (text & background)
499
        $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');
500
        $result = $build->buildSubrecord($formElement, 'name:1', '', $json);
Carsten  Rose's avatar
Carsten Rose committed
501
        $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);
502
503

        // _id: 1, name: Doe, _rowTitle
504
        $formElement['sql1'] = $this->dbArray[DB_INDEX_DEFAULT]->sql('SELECT id AS "_id", name, firstName AS _rowTitle FROM Person ORDER BY id LIMIT 2');
505
        $result = $build->buildSubrecord($formElement, 'name:1', '', $json);
Carsten  Rose's avatar
Carsten Rose committed
506
        $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);
507
508

        // _id: 1, name: Doe, title, width, nostrip
509
        $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');
510
        $result = $build->buildSubrecord($formElement, 'name:1', '', $json);
Carsten  Rose's avatar
Carsten Rose committed
511
        $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);
512
513

        // _id: 1, name: Doe, link
514
        $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');
515
        $result = $build->buildSubrecord($formElement, 'name:1', '', $json);
Carsten  Rose's avatar
Carsten Rose committed
516
        $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);
517
518
    }

519
    /**
520
521
     * @param array $form
     * @param array $formElement
522
523
524
     */
    private function templateFormNFormElement(array &$form, array &$formElement) {
        $form = [
Carsten  Rose's avatar
Carsten Rose committed
525
526
527
528
529
530
531
            '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',
532
            'permitUrlParameter' => '',
Carsten  Rose's avatar
Carsten Rose committed
533
534
            'render' => 'bootstrap',
            'multiMode' => 'none',
535
            F_MULTI_SQL => '',
536
537
            'multiDetailForm' => '',
            'multiDetailFormParameter' => '',
Carsten  Rose's avatar
Carsten Rose committed
538
539
540
541
542
543
544
            F_FORWARD_MODE => 'auto',
            F_FORWARD_PAGE => '',
            'bsLabelColumns' => '',
            'bsInputColumns' => '',
            'bsNoteColumns' => '',
            'parameter' => 'maxVisiblePill=>3',
            'deleted' => 'no',
Carsten  Rose's avatar
Carsten Rose committed
545
            F_DB_INDEX => DB_INDEX_DEFAULT,
546
547
548
        ];

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

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

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

    }

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

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

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

602
603
604
            // 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
605
            $this->executeSQLFile(__DIR__ . '/../../../Classes/Sql/formEditor.sql', true);
606

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

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

617

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

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

622
623
624
625
626
627
            // 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';
        }
628
629
    }
}
630

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

640

641