FormActionTest.php 17.8 KB
Newer Older
1
2
3
4
5
6
7
8
<?php
/**
 * Created by PhpStorm.
 * User: crose
 * Date: 1/15/16
 * Time: 8:24 AM
 */

Marc Egger's avatar
Marc Egger committed
9
namespace IMATHUZH\Qfq\Tests\Unit\Core\Form;
10

Marc Egger's avatar
Marc Egger committed
11
12
13
14
15
16
 
use IMATHUZH\Qfq\Core\Form\FormAction;
use IMATHUZH\Qfq\Core\Store\Store;
use IMATHUZH\Qfq\Tests\Unit\Core\Database\AbstractDatabaseTest;

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

18
19
20
21
/**
 * Class FormActionTest
 * @package qfq
 */
22
class FormActionTest extends AbstractDatabaseTest {
23

Carsten  Rose's avatar
Carsten Rose committed
24
    /**
Marc Egger's avatar
Marc Egger committed
25
26
27
28
29
     * @throws \CodeException
     * @throws \DbException
     * @throws \DownloadException
     * @throws \UserFormException
     * @throws \UserReportException
Carsten  Rose's avatar
Carsten Rose committed
30
31
32
33
     * @throws \PhpOffice\PhpSpreadsheet\Exception
     * @throws \PhpOffice\PhpSpreadsheet\Reader\Exception
     * @throws \PhpOffice\PhpSpreadsheet\Writer\Exception
     */
34
35
    public function testBeforeLoad() {
        $formSpec[F_TABLE_NAME] = 'Person';
36
        $formAction = new FormAction($formSpec, $this->dbArray[DB_INDEX_DEFAULT], true);
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65

        // Nothing to do: should not throw an exception
        $formAction->elements(0, array(), '');
        $formAction->elements(0, array(), FE_TYPE_BEFORE_LOAD . ',' . FE_TYPE_AFTER_LOAD);

        $feSpecAction[FE_NAME] = '';
        $feSpecAction[FE_TYPE] = FE_TYPE_BEFORE_LOAD;
        $feSpecAction[FE_MESSAGE_FAIL] = 'error';
        $formAction->elements(0, [$feSpecAction], FE_TYPE_BEFORE_LOAD);

        // Fire sqlValidate with one record, expect 1 record
        $feSpecAction[FE_TYPE] = FE_TYPE_BEFORE_LOAD;
        $feSpecAction[FE_SQL_VALIDATE] = '{{!SELECT id FROM Person LIMIT 1}}';
        $feSpecAction[FE_EXPECT_RECORDS] = '1';
        $formAction->elements(0, [$feSpecAction], FE_TYPE_BEFORE_LOAD);

        // Fire sqlValidate with one record, expect 0-2 records
        $feSpecAction[FE_EXPECT_RECORDS] = '0,1,2';
        $formAction->elements(0, [$feSpecAction], FE_TYPE_BEFORE_LOAD);

        // Fire sqlValidate with one record, expect 0-2 records
        $feSpecAction[FE_TYPE] = FE_TYPE_BEFORE_LOAD;
        $feSpecAction[FE_EXPECT_RECORDS] = '0,1,2';
        $formAction->elements(0, [$feSpecAction], FE_TYPE_BEFORE_LOAD);

        // Check with more classes
        $feSpecAction[FE_TYPE] = FE_TYPE_AFTER_LOAD;
        $feSpecAction[FE_EXPECT_RECORDS] = '0,1,2';
        $formAction->elements(0, [$feSpecAction], FE_TYPE_BEFORE_LOAD . ',' . FE_TYPE_AFTER_LOAD);
Carsten  Rose's avatar
Carsten Rose committed
66
67
68

        # Fake to suppress phpUnit about missing test.
        $this->assertEquals('', '');
69
70
71
72
    }

    /**
     * Expect 0 recrod, but get 1
Marc Egger's avatar
Marc Egger committed
73
     * @expectedException \UserFormException
Carsten  Rose's avatar
Carsten Rose committed
74
     *
Marc Egger's avatar
Marc Egger committed
75
76
77
78
79
     * @throws \CodeException
     * @throws \DbException
     * @throws \DownloadException
     * @throws \UserFormException
     * @throws \UserReportException
Carsten  Rose's avatar
Carsten Rose committed
80
81
82
83
     * @throws \PhpOffice\PhpSpreadsheet\Exception
     * @throws \PhpOffice\PhpSpreadsheet\Reader\Exception
     * @throws \PhpOffice\PhpSpreadsheet\Writer\Exception
     */
84
85
    public function testBeforeLoadException1() {
        $formSpec[F_TABLE_NAME] = 'Person';
86
        $formAction = new FormAction($formSpec, $this->dbArray[DB_INDEX_DEFAULT], true);
87
88
89
90
91
92
93
94
95
96
97

        $feSpecAction[FE_NAME] = '';
        $feSpecAction[FE_TYPE] = FE_TYPE_BEFORE_LOAD;
        $feSpecAction[FE_MESSAGE_FAIL] = 'error';
        $feSpecAction[FE_SQL_VALIDATE] = '{{!SELECT id FROM Person LIMIT 1}}';
        $feSpecAction[FE_EXPECT_RECORDS] = '0';
        $formAction->elements(0, [$feSpecAction], FE_TYPE_BEFORE_LOAD);
    }

    /**
     * Expect 1 recrod, but get 0
Marc Egger's avatar
Marc Egger committed
98
     * @expectedException \UserFormException
Carsten  Rose's avatar
Carsten Rose committed
99
     *
Marc Egger's avatar
Marc Egger committed
100
101
102
103
104
     * @throws \CodeException
     * @throws \DbException
     * @throws \DownloadException
     * @throws \UserFormException
     * @throws \UserReportException
Carsten  Rose's avatar
Carsten Rose committed
105
106
107
108
     * @throws \PhpOffice\PhpSpreadsheet\Exception
     * @throws \PhpOffice\PhpSpreadsheet\Reader\Exception
     * @throws \PhpOffice\PhpSpreadsheet\Writer\Exception
     */
109
110
    public function testBeforeLoadException0() {
        $formSpec[F_TABLE_NAME] = 'Person';
111
        $formAction = new FormAction($formSpec, $this->dbArray[DB_INDEX_DEFAULT], true);
112
113
114
115
116
117
118
119
120
121
122

        $feSpecAction[FE_NAME] = '';
        $feSpecAction[FE_TYPE] = FE_TYPE_BEFORE_LOAD;
        $feSpecAction[FE_MESSAGE_FAIL] = 'error';
        $feSpecAction[FE_SQL_VALIDATE] = '{{!SELECT id FROM Person LIMIT 0}}';
        $feSpecAction[FE_EXPECT_RECORDS] = '1';
        $formAction->elements(0, [$feSpecAction], FE_TYPE_BEFORE_LOAD);
    }

    /**
     * Expect '0,1', but get 2 records
Marc Egger's avatar
Marc Egger committed
123
     * @expectedException \UserFormException
Carsten  Rose's avatar
Carsten Rose committed
124
     *
Marc Egger's avatar
Marc Egger committed
125
126
127
128
129
     * @throws \CodeException
     * @throws \DbException
     * @throws \DownloadException
     * @throws \UserFormException
     * @throws \UserReportException
Carsten  Rose's avatar
Carsten Rose committed
130
131
132
133
     * @throws \PhpOffice\PhpSpreadsheet\Exception
     * @throws \PhpOffice\PhpSpreadsheet\Reader\Exception
     * @throws \PhpOffice\PhpSpreadsheet\Writer\Exception
     */
134
135
    public function testBeforeLoadException2() {
        $formSpec[F_TABLE_NAME] = 'Person';
136
        $formAction = new FormAction($formSpec, $this->dbArray[DB_INDEX_DEFAULT], true);
137
138
139
140
141
142
143
144
145
146
147

        $feSpecAction[FE_NAME] = '';
        $feSpecAction[FE_TYPE] = FE_TYPE_BEFORE_LOAD;
        $feSpecAction[FE_MESSAGE_FAIL] = 'error';
        $feSpecAction[FE_SQL_VALIDATE] = '{{!SELECT id FROM Person LIMIT 2}}';
        $feSpecAction[FE_EXPECT_RECORDS] = '0,1';
        $formAction->elements(0, [$feSpecAction], FE_TYPE_BEFORE_LOAD);
    }

    /**
     * Expect '0,1', but get 2 records
Marc Egger's avatar
Marc Egger committed
148
     * @expectedException \UserFormException
Carsten  Rose's avatar
Carsten Rose committed
149
     *
Marc Egger's avatar
Marc Egger committed
150
151
152
153
154
     * @throws \CodeException
     * @throws \DbException
     * @throws \DownloadException
     * @throws \UserFormException
     * @throws \UserReportException
Carsten  Rose's avatar
Carsten Rose committed
155
156
157
158
     * @throws \PhpOffice\PhpSpreadsheet\Exception
     * @throws \PhpOffice\PhpSpreadsheet\Reader\Exception
     * @throws \PhpOffice\PhpSpreadsheet\Writer\Exception
     */
159
160
    public function testBeforeLoadException3() {
        $formSpec[F_TABLE_NAME] = 'Person';
161
        $formAction = new FormAction($formSpec, $this->dbArray[DB_INDEX_DEFAULT], true);
162
163
164
165
166
167
168
169
170
171
172

        $feSpecAction[FE_NAME] = '';
        $feSpecAction[FE_TYPE] = FE_TYPE_AFTER_UPDATE;
        $feSpecAction[FE_MESSAGE_FAIL] = 'error';
        $feSpecAction[FE_SQL_VALIDATE] = '{{!SELECT id FROM Person LIMIT 2}}';
        $feSpecAction[FE_EXPECT_RECORDS] = '0,1';
        $formAction->elements(0, [$feSpecAction], FE_TYPE_BEFORE_LOAD . ',' . FE_TYPE_AFTER_LOAD . ',' . FE_TYPE_AFTER_UPDATE . ',' . FE_TYPE_BEFORE_SAVE);
    }

    /**
     * Necessary FE is empty > don't process check
Carsten  Rose's avatar
Carsten Rose committed
173
     *
Marc Egger's avatar
Marc Egger committed
174
175
176
177
178
     * @throws \CodeException
     * @throws \DbException
     * @throws \DownloadException
     * @throws \UserFormException
     * @throws \UserReportException
Carsten  Rose's avatar
Carsten Rose committed
179
180
181
182
     * @throws \PhpOffice\PhpSpreadsheet\Exception
     * @throws \PhpOffice\PhpSpreadsheet\Reader\Exception
     * @throws \PhpOffice\PhpSpreadsheet\Writer\Exception
     */
183
184
    public function testBeforeLoadException4() {
        $formSpec[F_TABLE_NAME] = 'Person';
185
        $formAction = new FormAction($formSpec, $this->dbArray[DB_INDEX_DEFAULT], true);
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202

        $feSpecAction[FE_NAME] = '';
        $feSpecAction[FE_TYPE] = FE_TYPE_AFTER_UPDATE;
        $feSpecAction[FE_MESSAGE_FAIL] = 'error';
        $feSpecAction[FE_SQL_VALIDATE] = '{{!SELECT id FROM Person LIMIT 2}}';
        $feSpecAction[FE_EXPECT_RECORDS] = '0,1';

        // one FE in list
        $this->store->setVar('street', 'Street', STORE_FORM, true);
        $this->store->setVar('city', '', STORE_FORM, true);
        $feSpecAction[FE_REQUIRED_LIST] = 'city';
        $formAction->elements(0, [$feSpecAction], FE_TYPE_BEFORE_LOAD . ',' . FE_TYPE_AFTER_LOAD . ',' . FE_TYPE_AFTER_UPDATE . ',' . FE_TYPE_BEFORE_SAVE);

        // three FE in list. one is set, one not, one dont exist
        $this->store->setVar('city', '', STORE_FORM, true);
        $feSpecAction[FE_REQUIRED_LIST] = 'street,city,downtown';
        $formAction->elements(0, [$feSpecAction], FE_TYPE_BEFORE_LOAD . ',' . FE_TYPE_AFTER_LOAD . ',' . FE_TYPE_AFTER_UPDATE . ',' . FE_TYPE_BEFORE_SAVE);
Carsten  Rose's avatar
Carsten Rose committed
203
204
205
206

        # Fake to suppress phpUnit about missing test.
        $this->assertEquals('', '');

207
208
209
210
    }

    /**
     * Expect '0,1', but get 2 records
Marc Egger's avatar
Marc Egger committed
211
     * @expectedException \UserFormException
Carsten  Rose's avatar
Carsten Rose committed
212
     *
Marc Egger's avatar
Marc Egger committed
213
214
215
216
217
     * @throws \CodeException
     * @throws \DbException
     * @throws \DownloadException
     * @throws \UserFormException
     * @throws \UserReportException
Carsten  Rose's avatar
Carsten Rose committed
218
219
220
221
     * @throws \PhpOffice\PhpSpreadsheet\Exception
     * @throws \PhpOffice\PhpSpreadsheet\Reader\Exception
     * @throws \PhpOffice\PhpSpreadsheet\Writer\Exception
     */
222
223
    public function testBeforeLoadException5() {
        $formSpec[F_TABLE_NAME] = 'Person';
224
        $formAction = new FormAction($formSpec, $this->dbArray[DB_INDEX_DEFAULT], true);
225
226
227
228
229
230
231
232
233
234
235
236

        $this->store->setVar('city', 'New York', STORE_FORM, true);
        $feSpecAction[FE_NAME] = '';
        $feSpecAction[FE_TYPE] = FE_TYPE_AFTER_UPDATE;
        $feSpecAction[FE_MESSAGE_FAIL] = 'error';
        $feSpecAction[FE_SQL_VALIDATE] = '{{!SELECT id FROM Person LIMIT 2}}';
        $feSpecAction[FE_EXPECT_RECORDS] = '0,1';
        $formAction->elements(0, [$feSpecAction], FE_TYPE_BEFORE_LOAD . ',' . FE_TYPE_AFTER_LOAD . ',' . FE_TYPE_AFTER_UPDATE . ',' . FE_TYPE_BEFORE_SAVE);
    }

    /**
     * Do check for 2 action records
Carsten  Rose's avatar
Carsten Rose committed
237
     *
Marc Egger's avatar
Marc Egger committed
238
239
240
241
242
     * @throws \CodeException
     * @throws \DbException
     * @throws \DownloadException
     * @throws \UserFormException
     * @throws \UserReportException
Carsten  Rose's avatar
Carsten Rose committed
243
244
245
246
     * @throws \PhpOffice\PhpSpreadsheet\Exception
     * @throws \PhpOffice\PhpSpreadsheet\Reader\Exception
     * @throws \PhpOffice\PhpSpreadsheet\Writer\Exception
     */
247
248
    public function testBeforeLoad2() {
        $formSpec[F_TABLE_NAME] = 'Person';
249
        $formAction = new FormAction($formSpec, $this->dbArray[DB_INDEX_DEFAULT], true);
250
251
252
253
254
255
256

        $feSpecAction[FE_NAME] = '';
        $feSpecAction[FE_TYPE] = FE_TYPE_AFTER_LOAD;
        $feSpecAction[FE_MESSAGE_FAIL] = 'error';
        $feSpecAction[FE_SQL_VALIDATE] = '{{!SELECT id FROM Person LIMIT 2}}';
        $feSpecAction[FE_EXPECT_RECORDS] = '2';
        $formAction->elements(0, [$feSpecAction, $feSpecAction], FE_TYPE_BEFORE_LOAD . ',' . FE_TYPE_AFTER_LOAD . ',' . FE_TYPE_AFTER_UPDATE . ',' . FE_TYPE_BEFORE_SAVE);
Carsten  Rose's avatar
Carsten Rose committed
257
258
259

        # Fake to suppress phpUnit about missing test.
        $this->assertEquals('', '');
260
261
262
263
    }

    /**
     * Do check for 2 action records, fail on second.
Marc Egger's avatar
Marc Egger committed
264
     * @expectedException \UserFormException
Carsten  Rose's avatar
Carsten Rose committed
265
     *
Marc Egger's avatar
Marc Egger committed
266
267
268
269
270
     * @throws \CodeException
     * @throws \DbException
     * @throws \DownloadException
     * @throws \UserFormException
     * @throws \UserReportException
Carsten  Rose's avatar
Carsten Rose committed
271
272
273
274
     * @throws \PhpOffice\PhpSpreadsheet\Exception
     * @throws \PhpOffice\PhpSpreadsheet\Reader\Exception
     * @throws \PhpOffice\PhpSpreadsheet\Writer\Exception
     */
275
276
    public function testBeforeLoadException6() {
        $formSpec[F_TABLE_NAME] = 'Person';
277
        $formAction = new FormAction($formSpec, $this->dbArray[DB_INDEX_DEFAULT], true);
278
279
280
281
282
283
284
285
286
287
288
289
290

        $feSpecAction[FE_NAME] = '';
        $feSpecAction[FE_TYPE] = FE_TYPE_AFTER_LOAD;
        $feSpecAction[FE_MESSAGE_FAIL] = 'error';
        $feSpecAction[FE_SQL_VALIDATE] = '{{!SELECT id FROM Person LIMIT 2}}';
        $feSpecAction[FE_EXPECT_RECORDS] = '2';
        $feSpecAction2 = $feSpecAction;
        $feSpecAction2[FE_EXPECT_RECORDS] = '0';
        $formAction->elements(0, [$feSpecAction, $feSpecAction2], FE_TYPE_BEFORE_LOAD . ',' . FE_TYPE_AFTER_LOAD . ',' . FE_TYPE_AFTER_UPDATE . ',' . FE_TYPE_BEFORE_SAVE);
    }

    /**
     * Process INSERT
Carsten  Rose's avatar
Carsten Rose committed
291
     *
Marc Egger's avatar
Marc Egger committed
292
293
294
295
296
     * @throws \CodeException
     * @throws \DbException
     * @throws \DownloadException
     * @throws \UserFormException
     * @throws \UserReportException
Carsten  Rose's avatar
Carsten Rose committed
297
298
299
300
     * @throws \PhpOffice\PhpSpreadsheet\Exception
     * @throws \PhpOffice\PhpSpreadsheet\Reader\Exception
     * @throws \PhpOffice\PhpSpreadsheet\Writer\Exception
     */
301
302
303
    public function testInsert() {

        $formSpec[F_TABLE_NAME] = 'Person';
304
        $formAction = new FormAction($formSpec, $this->dbArray[DB_INDEX_DEFAULT], true);
305
306
307
308
309
310
311
312
313
314
315

        $feSpecAction[FE_NAME] = '';
        $feSpecAction[FE_TYPE] = FE_TYPE_AFTER_SAVE;
        $feSpecAction[FE_SQL_INSERT] = '{{ INSERT INTO Address (city, personId) VALUES ("Downtown", {{r}}) }} ';
        $feSpecAction[FE_SQL_UPDATE] = '{{ UPDATE Address SET city="invalid" WHERE id={{r}} }} ';
        $feSpecAction[FE_SQL_DELETE] = '{{ DELETE FROM Address WHERE personId={{r}} AND id=0 }} ';

        $this->store->setVar('r', '2', STORE_SIP, true);

        // slaveId: 0
        $feSpecAction[FE_SLAVE_ID] = '0';
316
        $result = $this->dbArray[DB_INDEX_DEFAULT]->sql('TRUNCATE Address');
317
318
        $formAction->elements(2, [$feSpecAction], FE_TYPE_AFTER_SAVE);

319
        $result = $this->dbArray[DB_INDEX_DEFAULT]->sql('SELECT id, city, personId FROM Address', ROW_IMPLODE_ALL);
320
321
322
323
324
        $this->assertEquals('1Downtown2', $result);


        // slaveId: SELECT ... >> ''
        $feSpecAction[FE_SLAVE_ID] = '{{SELECT id FROM Address WHERE personId={{r}} ORDER BY id LIMIT 1}}';
325
        $result = $this->dbArray[DB_INDEX_DEFAULT]->sql('TRUNCATE Address');
326
327
        $formAction->elements(2, [$feSpecAction], FE_TYPE_AFTER_SAVE);

328
        $result = $this->dbArray[DB_INDEX_DEFAULT]->sql('SELECT id, city, personId FROM Address', ROW_IMPLODE_ALL);
329
330
331
332
333
334
335
336
        $this->assertEquals('1Downtown2', $result);


        // slaveId: slaveId through column in master record & update Master record with slaveId
        $this->store->setVar('adrId', '0', STORE_RECORD);
        $feSpecAction[FE_NAME] = 'adrId';
        $feSpecAction[FE_SLAVE_ID] = '';

337
        $result = $this->dbArray[DB_INDEX_DEFAULT]->sql('TRUNCATE Address');
338
339
340
        $formAction->elements(2, [$feSpecAction], FE_TYPE_AFTER_SAVE);

        // get the new slave record
341
        $result = $this->dbArray[DB_INDEX_DEFAULT]->sql('SELECT id, city, personId FROM Address', ROW_IMPLODE_ALL);
342
        $this->assertEquals('1Downtown2', $result);
343

344
        // get the updated id in the master record
345
        $result = $this->dbArray[DB_INDEX_DEFAULT]->sql('SELECT id, name, adrId FROM Person WHERE id=2', ROW_IMPLODE_ALL);
346
347
348
349
350
        $this->assertEquals('2Smith1', $result);
    }

    /**
     * Process UPDATE
Carsten  Rose's avatar
Carsten Rose committed
351
     *
Marc Egger's avatar
Marc Egger committed
352
353
354
355
356
     * @throws \CodeException
     * @throws \DbException
     * @throws \DownloadException
     * @throws \UserFormException
     * @throws \UserReportException
Carsten  Rose's avatar
Carsten Rose committed
357
358
359
360
     * @throws \PhpOffice\PhpSpreadsheet\Exception
     * @throws \PhpOffice\PhpSpreadsheet\Reader\Exception
     * @throws \PhpOffice\PhpSpreadsheet\Writer\Exception
     */
361
362
363
    public function testUpdate() {

        $formSpec[F_TABLE_NAME] = 'Person';
364
        $formAction = new FormAction($formSpec, $this->dbArray[DB_INDEX_DEFAULT], true);
365
366
367
368
369
370
371
372

        $masterId = 2;

        $feSpecAction[FE_NAME] = '';
        $feSpecAction[FE_TYPE] = FE_TYPE_AFTER_SAVE;
        $feSpecAction[FE_SQL_INSERT] = "{{ INSERT INTO Address (city, personId) VALUES ('invalid', {{r}}) }} ";
        $feSpecAction[FE_SQL_UPDATE] = "{{ UPDATE Address SET city='Uptown' WHERE id={{slaveId:V}} }} ";

373
374
375
376
        $result = $this->dbArray[DB_INDEX_DEFAULT]->sql("TRUNCATE Address");
        $result = $this->dbArray[DB_INDEX_DEFAULT]->sql("INSERT INTO Address (city, personId) VALUES ('Downtown1', 1)");
        $result = $this->dbArray[DB_INDEX_DEFAULT]->sql("INSERT INTO Address (city, personId) VALUES ('Downtown2', 1)");
        $result = $this->dbArray[DB_INDEX_DEFAULT]->sql("INSERT INTO Address (city, personId) VALUES ('Downtown3', $masterId)");
377
378
379
380
381
382
383

        $this->store->setVar('r', "$masterId", STORE_SIP, true);

        // slaveId: 1 - hard coded
        $feSpecAction[FE_SLAVE_ID] = '3';
        $formAction->elements($masterId, [$feSpecAction], FE_TYPE_AFTER_SAVE);

384
        $result = $this->dbArray[DB_INDEX_DEFAULT]->sql("SELECT id, city, personId FROM Address WHERE personId=$masterId", ROW_IMPLODE_ALL);
385
386
387
388
389
390
391
        $this->assertEquals('3Uptown' . $masterId, $result);


        // slaveId: SELECT ... >> ''
        $feSpecAction[FE_SLAVE_ID] = "{{SELECT id FROM Address WHERE personId={{r}} ORDER BY id LIMIT 1}}";
        $formAction->elements($masterId, [$feSpecAction], FE_TYPE_AFTER_SAVE);

392
        $result = $this->dbArray[DB_INDEX_DEFAULT]->sql("SELECT id, city, personId FROM Address WHERE personId=$masterId", ROW_IMPLODE_ALL);
393
394
395
396
        $this->assertEquals('3Uptown' . $masterId, $result);


        // slaveId: column in master record
397
        $this->dbArray[DB_INDEX_DEFAULT]->sql("UPDATE Person SET adrId=3 WHERE id=$masterId", ROW_IMPLODE_ALL);
398
399
400
401
402
403
//        $this->store->setVar('adrId', '3', STORE_RECORD);
        $feSpecAction[FE_NAME] = 'adrId';
        $feSpecAction[FE_SLAVE_ID] = '';

        $formAction->elements($masterId, [$feSpecAction], FE_TYPE_AFTER_SAVE);

404
        $result = $this->dbArray[DB_INDEX_DEFAULT]->sql("SELECT id, city, personId FROM Address WHERE personId=$masterId", ROW_IMPLODE_ALL);
405
        $this->assertEquals('3Uptown' . $masterId, $result);
406

407
        // Check updated primary record: person.adrId
408
        $result = $this->dbArray[DB_INDEX_DEFAULT]->sql("SELECT id, name, adrId FROM Person WHERE id=$masterId", ROW_IMPLODE_ALL);
409
410
411
412
413
414
415
        $this->assertEquals('2Smith3', $result);


        // Same situation as above, with sqlDelete.
        $feSpecAction[FE_SQL_DELETE] = "{{ DELETE FROM Address WHERE id={{slaveId}} }} ";
        $formAction->elements($masterId, [$feSpecAction], FE_TYPE_AFTER_SAVE);

416
        $result = $this->dbArray[DB_INDEX_DEFAULT]->sql("SELECT id, city, personId FROM Address WHERE personId=$masterId", ROW_IMPLODE_ALL);
417
418
419
        $this->assertEquals('', $result);

        // Check updated primary record: person.adrId
420
        $result = $this->dbArray[DB_INDEX_DEFAULT]->sql("SELECT id, name, adrId FROM Person WHERE id=$masterId", ROW_IMPLODE_ALL);
421
        $this->assertEquals('2Smith0', $result);
422
423
    }

Carsten  Rose's avatar
Carsten Rose committed
424
    /**
Marc Egger's avatar
Marc Egger committed
425
426
427
428
     * @throws \CodeException
     * @throws \DbException
     * @throws \UserFormException
     * @throws \UserReportException
Carsten  Rose's avatar
Carsten Rose committed
429
     */
430
431
432
433
434
435
    protected function setUp() {

        $this->store = Store::getInstance('form=TestFormName', true);
        parent::setUp();

        $this->store->setVar('form', 'TestFormName', STORE_TYPO3);
Marc Egger's avatar
Marc Egger committed
436
        $this->executeSQLFile(__DIR__ . '/../Database/fixtures/Generic.sql', true);
437
438
439
440

    }

}