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

6
7
namespace qfq;

8
9
require_once(__DIR__ . '/AbstractDatabaseTest.php');

10
11
12
/**
 * Class DatabaseTest
 */
13
14
class DatabaseTest extends AbstractDatabaseTest {

15
16
    /**
     */
17
    public function testFetchAll() {
18
        $allRows = $this->dbArray[DB_INDEX_DEFAULT]->sql('SELECT * FROM Person ORDER BY id LIMIT 2');
19
20
21
22
23
24

        $this->assertCount(2, $allRows);
        $this->assertEquals(1, $allRows[0]['id']);
        $this->assertEquals(2, $allRows[1]['id']);
    }

25
26
    /**
     */
27
    public function testFetchAllEmpty() {
28
        $allRows = $this->dbArray[DB_INDEX_DEFAULT]->sql('SELECT * FROM Person WHERE id=0 ORDER BY id');
29

30
        $this->assertEquals(array(), $allRows);
31
32
    }

33
    /**
34
35
     * @throws \qfq\CodeException
     * @throws \qfq\UserFormException
36
     */
37
38
39
40
    public function testQuerySimple() {

        $expected = [
            [
Carsten  Rose's avatar
Carsten Rose committed
41
42
                'id' => '1',
                'name' => 'Doe',
43
                'firstName' => 'John',
Carsten  Rose's avatar
Carsten Rose committed
44
                'adrId' => '0',
45
                'gender' => 'male',
Carsten  Rose's avatar
Carsten Rose committed
46
                'groups' => 'c',
47
48
            ],
            [
Carsten  Rose's avatar
Carsten Rose committed
49
50
                'id' => '2',
                'name' => 'Smith',
51
                'firstName' => 'Jane',
Carsten  Rose's avatar
Carsten Rose committed
52
                'adrId' => '0',
53
                'gender' => 'female',
Carsten  Rose's avatar
Carsten Rose committed
54
                'groups' => 'a,c',
55
56
57
            ],
        ];

58
59

        // Check read rows
60
        $dataArray = $this->dbArray[DB_INDEX_DEFAULT]->sql('SELECT * FROM Person ORDER BY id LIMIT 1');
61
62
63
        // Check count
        $this->assertEquals(1, $this->store->getVar(SYSTEM_SQL_COUNT, STORE_SYSTEM));

64
        // Check read rows
65
        $dataArray = $this->dbArray[DB_INDEX_DEFAULT]->sql('SELECT id,name,firstName,adrId,gender,groups FROM Person ORDER BY id LIMIT 2');
66

67
68
69
        // Check count
        $this->assertEquals(2, $this->store->getVar(SYSTEM_SQL_COUNT, STORE_SYSTEM));
        // Compare rows
70
        $this->assertEquals($expected, $dataArray);
71
72
73
        // Check rows

        // Same as above, but specify 'ROW_REGULAR'
74
        $dataArray = $this->dbArray[DB_INDEX_DEFAULT]->sql('SELECT id,name,firstName,adrId,gender,groups FROM Person ORDER BY id LIMIT 2', ROW_REGULAR);
75
        $this->assertEquals(2, $this->store->getVar(SYSTEM_SQL_COUNT, STORE_SYSTEM));
76
        // Check rows
77
        $this->assertEquals($expected, $dataArray);
78

79
        // ROW_EXPECT_0
80
        $dataArray = $this->dbArray[DB_INDEX_DEFAULT]->sql('SELECT * FROM Person WHERE id=0', ROW_EXPECT_0);
81
        $this->assertEquals(0, $this->store->getVar(SYSTEM_SQL_COUNT, STORE_SYSTEM));
82
        // Check rows
83
        $this->assertEquals(array(), $dataArray);
84
85

        // ROW_EXPECT_1
86
        $dataArray = $this->dbArray[DB_INDEX_DEFAULT]->sql('SELECT id,name,firstName,adrId,gender,groups FROM Person WHERE id=1', ROW_EXPECT_1);
87
        $this->assertEquals(1, $this->store->getVar(SYSTEM_SQL_COUNT, STORE_SYSTEM));
88
        // Check rows
89
        $this->assertEquals($expected[0], $dataArray);
90

91
        // ROW_EXPECT_0_1: 1
92
        $dataArray = $this->dbArray[DB_INDEX_DEFAULT]->sql('SELECT id,name,firstName,adrId,gender,groups FROM Person WHERE id=1', ROW_EXPECT_0_1);
93
        $this->assertEquals(1, $this->store->getVar(SYSTEM_SQL_COUNT, STORE_SYSTEM));
94
        // Check rows
95
        $this->assertEquals($expected[0], $dataArray);
96

97
        // ROW_EXPECT_0_1: 0
98
        $dataArray = $this->dbArray[DB_INDEX_DEFAULT]->sql('SELECT * FROM Person WHERE id=0', ROW_EXPECT_0_1);
99
        $this->assertEquals(0, $this->store->getVar(SYSTEM_SQL_COUNT, STORE_SYSTEM));
100
        // Check rows
101
        $this->assertEquals(array(), $dataArray);
102

103
        //ROW_EXPECT_GE_1 - one record
104
        $dataArray = $this->dbArray[DB_INDEX_DEFAULT]->sql('SELECT id,name,firstName,adrId,gender,groups FROM Person WHERE id=1', ROW_EXPECT_GE_1);
105
        $this->assertEquals(1, $this->store->getVar(SYSTEM_SQL_COUNT, STORE_SYSTEM));
106
        // Check rows
107
        $this->assertEquals([$expected[0]], $dataArray);
108
109

        // ROW_EXPECT_GE_1 - two records
110
        $dataArray = $this->dbArray[DB_INDEX_DEFAULT]->sql('SELECT id,name,firstName,adrId,gender,groups FROM Person ORDER BY id LIMIT 2', ROW_EXPECT_GE_1);
111
        $this->assertEquals(2, $this->store->getVar(SYSTEM_SQL_COUNT, STORE_SYSTEM));
112
        // Check rows
113
        $this->assertEquals($expected, $dataArray);
114

115
        // Check Implode: 2 records
116
        $data = $this->dbArray[DB_INDEX_DEFAULT]->sql('SELECT id,name,firstName,adrId,gender,groups FROM Person ORDER BY id LIMIT 2', ROW_IMPLODE_ALL);
117
118
119
        $this->assertEquals(implode($expected[0]) . implode($expected[1]), $data);

        // Check Implode: 1 record
120
        $data = $this->dbArray[DB_INDEX_DEFAULT]->sql('SELECT id,name,firstName,adrId,gender,groups FROM Person ORDER BY id LIMIT 1', ROW_IMPLODE_ALL);
121
122
123
        $this->assertEquals(implode($expected[0]), $data);

        // Check Implode 0 record
124
        $data = $this->dbArray[DB_INDEX_DEFAULT]->sql('SELECT * FROM Person WHERE id=0 ORDER BY id LIMIT 2', ROW_IMPLODE_ALL);
125
        $this->assertEquals('', $data);
126

127
        $data = $this->dbArray[DB_INDEX_DEFAULT]->sql('SELECT "a", "b", "c"', ROW_IMPLODE_ALL);
128
129
130
        $this->assertEquals('abc', $data);

        // Multiple columns with same columnname
131
        $data = $this->dbArray[DB_INDEX_DEFAULT]->sql('SELECT "a", "b", "a"', ROW_IMPLODE_ALL);
132
133
134
        $this->assertEquals('aba', $data);

        // Multiple columns with same columnname
135
        $data = $this->dbArray[DB_INDEX_DEFAULT]->sql('SELECT id, name, firstname, name, id FROM Person', ROW_IMPLODE_ALL);
136
137
        $this->assertEquals('1DoeJohnDoe12SmithJaneSmith2', $data);

138
139
    }

140
    /**
141
142
     * @throws \qfq\CodeException
     * @throws \qfq\UserFormException
143
     */
Carsten  Rose's avatar
Carsten Rose committed
144
    public function testQuerySimpleParameter() {
145
146
147
        $stat = array();
        $dummy = array();

Carsten  Rose's avatar
Carsten Rose committed
148
        // Parameter Susbstitution by '?'
149
        $dataArray = $this->dbArray[DB_INDEX_DEFAULT]->sql('SELECT * FROM Person WHERE name LIKE ? ORDER BY id', ROW_REGULAR, ['Smith']);
Carsten  Rose's avatar
Carsten Rose committed
150
        // Check count
151
        $this->assertEquals(1, $this->store->getVar(SYSTEM_SQL_COUNT, STORE_SYSTEM));
Carsten  Rose's avatar
Carsten Rose committed
152

153
        $dataArray = $this->dbArray[DB_INDEX_DEFAULT]->sql('UPDATE Person SET groups = ?', ROW_REGULAR, ['a,b,c']);
154
        $this->assertEquals(2, $this->store->getVar(SYSTEM_SQL_COUNT, STORE_SYSTEM));
Carsten  Rose's avatar
Carsten Rose committed
155

156
        $dataArray = $this->dbArray[DB_INDEX_DEFAULT]->sql('INSERT INTO Person (`name`, `firstname`, `groups`) VALUES ( ?, ? ,? )', ROW_REGULAR, ['Meier', 'John', 'a'], 'fake', $dummy, $stat);
157
158
        $this->assertEquals(1, $this->store->getVar(SYSTEM_SQL_COUNT, STORE_SYSTEM));
        $this->assertEquals(3, $stat[DB_INSERT_ID]);
Carsten  Rose's avatar
Carsten Rose committed
159

160
        $dataArray = $this->dbArray[DB_INDEX_DEFAULT]->sql('INSERT INTO Person (`name`, `firstname`, `groups`) VALUES ( ?, ? ,? )', ROW_REGULAR, ['Meier', 'Jan', 'b'], 'fake', $dummy, $stat);
161
162
        $this->assertEquals(1, $this->store->getVar(SYSTEM_SQL_COUNT, STORE_SYSTEM));
        $this->assertEquals(4, $stat[DB_INSERT_ID]);
163

164
        $dataArray = $this->dbArray[DB_INDEX_DEFAULT]->sql('DELETE FROM Person WHERE name = ?', ROW_REGULAR, ['Meier']);
165
        $this->assertEquals(2, $this->store->getVar(SYSTEM_SQL_COUNT, STORE_SYSTEM));
166

167
    }
168
169
170
171
172

    /**
     * @expectedException \qfq\DbException
     */
    public function testSqlExceptionExpect0() {
173
        $data = $this->dbArray[DB_INDEX_DEFAULT]->sql('SELECT * FROM Person ORDER BY id LIMIT 1', ROW_EXPECT_0);
174
175
176
177
178
179
    }

    /**
     * @expectedException \qfq\DbException
     */
    public function testSqlExceptionExpect1_0() {
180
        $data = $this->dbArray[DB_INDEX_DEFAULT]->sql('SELECT * FROM Person ORDER BY id LIMIT 0', ROW_EXPECT_1);
181
182
183
184
185
186
    }

    /**
     * @expectedException \qfq\DbException
     */
    public function testSqlExceptionExpect1_2() {
187
        $data = $this->dbArray[DB_INDEX_DEFAULT]->sql('SELECT * FROM Person ORDER BY id ', ROW_EXPECT_1);
188
189
190
191
192
193
    }

    /**
     * @expectedException \qfq\DbException
     */
    public function testSqlExceptionExpect01() {
194
        $data = $this->dbArray[DB_INDEX_DEFAULT]->sql('SELECT * FROM Person ORDER BY id ', ROW_EXPECT_0_1);
195
196
197
198
199
200
    }

    /**
     * @expectedException \qfq\DbException
     */
    public function testSqlExceptionExpectGE1() {
201
        $data = $this->dbArray[DB_INDEX_DEFAULT]->sql('SELECT * FROM Person ORDER BY id LIMIT 0', ROW_EXPECT_GE_1);
202
203
    }

204
    /**
205
     * @expectedException \qfq\DbException
206
     */
Carsten  Rose's avatar
Carsten Rose committed
207
    public function testSanitizeException() {
208
        $this->dbArray[DB_INDEX_DEFAULT]->sql('some garbage');
209
210
    }

211
212
213
    /**
     *
     */
214
    public function testGetSetValueList() {
215
        $valueList = $this->dbArray[DB_INDEX_DEFAULT]->getEnumSetValueList('Person', 'gender');
216
217
218
219
        $expected = [0 => '', 1 => 'male', 2 => 'female'];
        $this->assertEquals($expected, $valueList);

        $expected = [0 => '', 1 => 'a', 2 => 'b', 3 => 'c'];
220
        $valueList = $this->dbArray[DB_INDEX_DEFAULT]->getEnumSetValueList('Person', 'groups');
221
222
223
        $this->assertEquals($expected, $valueList);
    }

224
225
    /**
     */
226
227
228
229
230
231
    public function testSelectReturn() {
        $dummy = array();
        $stat = array();

        $sql = "SELECT name FROM Person ORDER BY id";

232
        $rc = $this->dbArray[DB_INDEX_DEFAULT]->sql($sql, ROW_REGULAR, $dummy, 'fake', $dummy, $stat);
233
234
235
236
237
238
239
240
241
242
243
244
245
246
        $this->assertEquals([0 => ['name' => 'Doe'], 1 => ['name' => 'Smith']], $rc);

        // DB_NUM_ROWS | DB_INSERT_ID | DB_AFFECTED_ROWS
        $this->assertEquals(2, $stat[DB_NUM_ROWS]);
    }

    /**
     */
    public function testShowReturn() {
        $dummy = array();
        $stat = array();

        $sql = "SHOW TABLES";

247
        $rc = $this->dbArray[DB_INDEX_DEFAULT]->sql($sql, ROW_REGULAR, $dummy, 'fake', $dummy, $stat);
248
249

        // DB_NUM_ROWS | DB_INSERT_ID | DB_AFFECTED_ROWS
Carsten  Rose's avatar
Carsten Rose committed
250
251
252
253
254
        $all = '';
        foreach ($rc as $val) {
            $all .= '-' . implode('-', $val);
        }

Carsten  Rose's avatar
Carsten Rose committed
255
        $this->assertEquals(3, $stat[DB_NUM_ROWS]);
256
257
258
259
260
261
262
263
264
265
    }

    /**
     */
    public function testExplainReturn() {
        $dummy = array();
        $stat = array();

        $sql = "EXPLAIN Person";

266
        $rc = $this->dbArray[DB_INDEX_DEFAULT]->sql($sql, ROW_REGULAR, $dummy, 'fake', $dummy, $stat);
267
268

        // DB_NUM_ROWS | DB_INSERT_ID | DB_AFFECTED_ROWS
269
        $this->assertEquals(8, $stat[DB_NUM_ROWS]);
270
271
272
273
274
    }

    /**
     */
    public function testInsertReturn() {
275
276
        $dummy = array();
        $stat = array();
277

278
        $sql = "INSERT INTO Person (id, name, firstname, gender, groups) VALUES (NULL, 'Doe', 'Jonni', 'male','')";
279

280
        $rc = $this->dbArray[DB_INDEX_DEFAULT]->sql($sql, ROW_REGULAR, $dummy, 'fake', $dummy, $stat);
281
        // DB_NUM_ROWS | DB_INSERT_ID | DB_AFFECTED_ROWS
282
        $this->assertEquals(3, $stat[DB_INSERT_ID]);
283
284
285
286
287
288
289
290
291
292
293
294
295
        $this->assertEquals(1, $stat[DB_AFFECTED_ROWS]);

        $this->assertEquals(3, $rc);
    }

    /**
     */
    public function testUpdateReturn() {
        $dummy = array();
        $stat = array();

        $sql = "UPDATE Person SET groups = 'a'";

296
        $rc = $this->dbArray[DB_INDEX_DEFAULT]->sql($sql, ROW_REGULAR, $dummy, 'fake', $dummy, $stat);
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313

        $this->assertEquals(2, $rc);

        // DB_NUM_ROWS | DB_INSERT_ID | DB_AFFECTED_ROWS
        $this->assertEquals(2, $stat[DB_AFFECTED_ROWS]);
    }

    /**
     */
    public function testDeleteReturn() {
        $dummy = array();
        $stat = array();

        $this->executeSQLFile(__DIR__ . '/fixtures/Generic.sql', true);

        $sql = "DELETE FROM Person WHERE id=2";

314
        $rc = $this->dbArray[DB_INDEX_DEFAULT]->sql($sql, ROW_REGULAR, $dummy, 'fake', $dummy, $stat);
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333

        $this->assertEquals(1, $rc);

        // DB_NUM_ROWS | DB_INSERT_ID | DB_AFFECTED_ROWS
        $this->assertEquals(1, $stat[DB_AFFECTED_ROWS]);

    }


    /**
     */
    public function testReplaceReturn() {
        $dummy = array();
        $stat = array();

        $this->executeSQLFile(__DIR__ . '/fixtures/Generic.sql', true);

        $sql = "REPLACE INTO Person (id, name, firstname, gender, groups) VALUES (1, 'Doe', 'John', 'male','')";

334
        $rc = $this->dbArray[DB_INDEX_DEFAULT]->sql($sql, ROW_REGULAR, $dummy, 'fake', $dummy, $stat);
335
336
337
338
339
340
341
342
343
        // DB_NUM_ROWS | DB_INSERT_ID | DB_AFFECTED_ROWS
        $this->assertEquals(1, $stat[DB_INSERT_ID]);
        $this->assertEquals(2, $stat[DB_AFFECTED_ROWS]);

        $this->assertEquals(1, $rc);


        $sql = "REPLACE INTO Person (id, name, firstname, gender, groups) VALUES (100, 'Lincoln', 'Abraham', 'male','')";

344
        $rc = $this->dbArray[DB_INDEX_DEFAULT]->sql($sql, ROW_REGULAR, $dummy, 'fake', $dummy, $stat);
345
346
347
348
349
        // DB_NUM_ROWS | DB_INSERT_ID | DB_AFFECTED_ROWS
        $this->assertEquals(100, $stat[DB_INSERT_ID]);
        $this->assertEquals(1, $stat[DB_AFFECTED_ROWS]);

        $this->assertEquals(100, $rc);
350
351
    }

352
353
354
355
356
357
358
    /**
     *
     */
    public function testGetTableDefinition() {
        $expected = [
            ['Field' => 'id', 'Type' => 'bigint(20)', 'Null' => 'NO', 'Key' => 'PRI', 'Default' => '', 'Extra' => 'auto_increment'],
            ['Field' => 'name', 'Type' => 'varchar(128)', 'Null' => 'YES', 'Key' => '', 'Default' => '', 'Extra' => ''],
359
360
            ['Field' => 'firstName', 'Type' => 'varchar(128)', 'Null' => 'YES', 'Key' => '', 'Default' => '', 'Extra' => ''],
            ['Field' => 'adrId', 'Type' => 'int(11)', 'Null' => 'NO', 'Key' => '', 'Default' => '0', 'Extra' => ''],
361
            ['Field' => 'gender', 'Type' => "enum('','male','female')", 'Null' => 'NO', 'Key' => '', 'Default' => 'male', 'Extra' => ''],
362
            ['Field' => 'groups', 'Type' => "set('','a','b','c')", 'Null' => 'NO', 'Key' => '', 'Default' => '', 'Extra' => ''],
363
364
            ['Field' => 'modified', 'Type' => "timestamp", 'Null' => 'NO', 'Key' => '', 'Default' => 'CURRENT_TIMESTAMP', 'Extra' => 'on update CURRENT_TIMESTAMP'],
            ['Field' => 'created', 'Type' => "datetime", 'Null' => 'NO', 'Key' => '', 'Default' => '', 'Extra' => ''],
365
366
        ];

367
        $this->assertEquals($expected, $this->dbArray[DB_INDEX_DEFAULT]->getTableDefinition('Person'));
368
369
    }

370
371
372
    /**
     *
     */
373
374
375
376
377
378
379
380
    public function testSqlKeys() {
        $keys = array();

        $expected = [
            ['0' => '1', '1' => 'Doe', '2' => '0'],
            ['0' => '2', '1' => 'Smith', '2' => '0'],
        ];
        // Same as above, but specify 'ROW_REGULAR'
381
        $stat = array();
382
        $dataArray = $this->dbArray[DB_INDEX_DEFAULT]->sqlKeys('SELECT id AS "id", name, "0" AS "id" FROM Person ORDER BY id LIMIT 3', $keys, $stat);
383
384
385
386
387
388
389

        // Check rows
        $this->assertEquals($expected, $dataArray);

        // Check keys
        $this->assertEquals(['id', 'name', 'id'], $keys);
    }
390

391
392
393
394
395
    /**
     *
     */
    public function testhasLimit() {

396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
        $this->assertEquals(false, $this->dbArray[DB_INDEX_DEFAULT]->hasLimit(''));
        $this->assertEquals(false, $this->dbArray[DB_INDEX_DEFAULT]->hasLimit('SELECT'));
        $this->assertEquals(true, $this->dbArray[DB_INDEX_DEFAULT]->hasLimit('SELECT ... LIMIT 1'));
        $this->assertEquals(true, $this->dbArray[DB_INDEX_DEFAULT]->hasLimit('SELECT ... LIMIT 1 '));
        $this->assertEquals(true, $this->dbArray[DB_INDEX_DEFAULT]->hasLimit('SELECT ... LIMIT  1  '));
        $this->assertEquals(true, $this->dbArray[DB_INDEX_DEFAULT]->hasLimit('SELECT ... LIMIT 1,1'));
        $this->assertEquals(true, $this->dbArray[DB_INDEX_DEFAULT]->hasLimit('SELECT ... LIMIT 1,1 '));
        $this->assertEquals(true, $this->dbArray[DB_INDEX_DEFAULT]->hasLimit('SELECT ... LIMIT  1,1 '));
        $this->assertEquals(true, $this->dbArray[DB_INDEX_DEFAULT]->hasLimit('SELECT ... LIMIT  1,1  '));
        $this->assertEquals(true, $this->dbArray[DB_INDEX_DEFAULT]->hasLimit('SELECT ... LIMIT 1 ,1 '));
        $this->assertEquals(true, $this->dbArray[DB_INDEX_DEFAULT]->hasLimit('SELECT ... LIMIT 1 , 1 '));
        $this->assertEquals(true, $this->dbArray[DB_INDEX_DEFAULT]->hasLimit('SELECT ... LIMIT 1 ,  1 '));
        $this->assertEquals(true, $this->dbArray[DB_INDEX_DEFAULT]->hasLimit('SELECT ... LIMIT 1  ,  1 '));
        $this->assertEquals(true, $this->dbArray[DB_INDEX_DEFAULT]->hasLimit('SELECT ... LIMIT 1  ,  1  '));
        $this->assertEquals(true, $this->dbArray[DB_INDEX_DEFAULT]->hasLimit('SELECT ... LIMIT  1  ,  1  '));
        $this->assertEquals(true, $this->dbArray[DB_INDEX_DEFAULT]->hasLimit('SELECT ... LIMIT   1   ,   1   '));
412
413
414
415
    }

    public function testMakeArrayDict() {

416
        $this->assertEquals(array(), $this->dbArray[DB_INDEX_DEFAULT]->makeArrayDict(array(), 'key', 'value'));
417
418
419

        $arr[] = ['red', 'green'];
        $expect[] = ['key' => 'red', 'value' => 'green'];
420
        $this->assertEquals($expect, $this->dbArray[DB_INDEX_DEFAULT]->makeArrayDict($arr, 'key', 'value'));
421
422
423

        $arr[] = ['blue', 'orange'];
        $expect[] = ['key' => 'blue', 'value' => 'orange'];
424
        $this->assertEquals($expect, $this->dbArray[DB_INDEX_DEFAULT]->makeArrayDict($arr, 'key', 'value'));
425
426

        $arr = [['key1' => 'red', 'value1' => 'green'], ['key1' => 'blue', 'value1' => 'orange']];
427
        $this->assertEquals($expect, $this->dbArray[DB_INDEX_DEFAULT]->makeArrayDict($arr, 'key', 'value'));
428
429

        $arr = [['key' => 'red', 'value1' => 'green'], ['key' => 'blue', 'value1' => 'orange']];
430
        $this->assertEquals($expect, $this->dbArray[DB_INDEX_DEFAULT]->makeArrayDict($arr, 'key', 'value'));
431
432

        $arr = [['key1' => 'red', 'value' => 'green'], ['key1' => 'blue', 'value' => 'orange']];
433
        $this->assertEquals($expect, $this->dbArray[DB_INDEX_DEFAULT]->makeArrayDict($arr, 'key', 'value'));
434
435

        $arr = [['key' => 'red', 'value' => 'green'], ['key' => 'blue', 'value' => 'orange']];
436
        $this->assertEquals($expect, $this->dbArray[DB_INDEX_DEFAULT]->makeArrayDict($arr, 'key', 'value'));
437
438

        $arr = [['value' => 'green', 'key' => 'red'], ['value' => 'orange', 'key' => 'blue']];
439
        $this->assertEquals($expect, $this->dbArray[DB_INDEX_DEFAULT]->makeArrayDict($arr, 'key', 'value'));
440
441
442

        $arr = [['green'], ['orange']];
        $expect = [['key' => 'green', 'value' => 'green'], ['key' => 'orange', 'value' => 'orange']];
443
        $this->assertEquals($expect, $this->dbArray[DB_INDEX_DEFAULT]->makeArrayDict($arr, 'key', 'value'));
444
445

        $arr = [['value1' => 'green'], ['value1' => 'orange']];
446
        $this->assertEquals($expect, $this->dbArray[DB_INDEX_DEFAULT]->makeArrayDict($arr, 'key', 'value'));
447
448

        $arr = [['key' => 'green'], ['key' => 'orange']];
449
        $this->assertEquals($expect, $this->dbArray[DB_INDEX_DEFAULT]->makeArrayDict($arr, 'key', 'value'));
450
451

        $arr = [['value' => 'green'], ['value' => 'orange']];
452
        $this->assertEquals($expect, $this->dbArray[DB_INDEX_DEFAULT]->makeArrayDict($arr, 'key', 'value'));
453
454
455

    }

456
    /**
Carsten  Rose's avatar
Carsten Rose committed
457
458
459
460
     * @throws CodeException
     * @throws DbException
     * @throws UserFormException
     * @throws UserReportException
461
     */
462
463
464
    protected function setUp() {
        parent::setUp();

Carsten  Rose's avatar
Carsten Rose committed
465
        // remove existing tables
466
        $allTables = $this->dbArray[DB_INDEX_DEFAULT]->sql("SHOW TABLES", ROW_REGULAR);
Carsten  Rose's avatar
Carsten Rose committed
467
468
        foreach ($allTables AS $val) {
            $table = current($val);
469
            $this->dbArray[DB_INDEX_DEFAULT]->sql("DROP TABLE $table");
Carsten  Rose's avatar
Carsten Rose committed
470
471
        }

472
473
474
        $this->executeSQLFile(__DIR__ . '/fixtures/Generic.sql', true);
    }
}