DatabaseTest.php 19.3 KB
Newer Older
1
2
3
4
5
6
<?php
/**
 * @author Rafael Ostertag <rafael.ostertag@math.uzh.ch>
 */

require_once(__DIR__ . '/AbstractDatabaseTest.php');
7
require_once(__DIR__ . '/../../qfq/database/Database.php');
8
require_once(__DIR__ . '/../../qfq/exceptions/DbException.php');
9
10
11

class DatabaseTest extends AbstractDatabaseTest {

12
    /**
13
     * @throws \qfq\DbException
14
     */
15
    public function testFetchAll() {
16
        $allRows = $this->dbArray[DB_INDEX_DATA_DEFAULT]->sql('SELECT * FROM Person ORDER BY id LIMIT 2');
17
18
19
20
21
22

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

23
    /**
24
     * @throws \qfq\DbException
25
     */
26
    public function testFetchAllEmpty() {
27
        $allRows = $this->dbArray[DB_INDEX_DATA_DEFAULT]->sql('SELECT * FROM Person WHERE id=0 ORDER BY id');
28

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

32
    /**
33
     * @throws \qfq\DbException
34
     */
35
36
37
38
    public function testQuerySimple() {

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

56
57

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

136
137
    }

138
    /**
139
     * @throws \qfq\DbException
140
     */
Carsten  Rose's avatar
Carsten Rose committed
141
    public function testQuerySimpleParameter() {
142
143
144
        $stat = array();
        $dummy = array();

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

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

153
        $dataArray = $this->dbArray[DB_INDEX_DATA_DEFAULT]->sql('INSERT INTO Person (`name`, `firstname`, `groups`) VALUES ( ?, ? ,? )', ROW_REGULAR, ['Meier', 'John', 'a'], 'fake', $dummy, $stat);
154
155
        $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
156

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

161
        $dataArray = $this->dbArray[DB_INDEX_DATA_DEFAULT]->sql('DELETE FROM Person WHERE name = ?', ROW_REGULAR, ['Meier']);
162
        $this->assertEquals(2, $this->store->getVar(SYSTEM_SQL_COUNT, STORE_SYSTEM));
163

164
    }
165
166
167
168
169

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

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

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

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

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

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

208
    /**
209
     * @throws \qfq\DbException
210
     */
211
    public function testParameters() {
212
213
214
        //TODO: ParameterName
//        $this->db->prepareExecute('SELECT * FROM Person WHERE id = :valueOfA', [':valueOfA' => 2]);
//        $this->assertEquals(1, $this->db->getRowCount());
215
216
    }

217
218
219
    /**
     *
     */
220
    public function testGetSetValueList() {
221
        $valueList = $this->dbArray[DB_INDEX_DATA_DEFAULT]->getEnumSetValueList('Person', 'gender');
222
223
224
225
        $expected = [0 => '', 1 => 'male', 2 => 'female'];
        $this->assertEquals($expected, $valueList);

        $expected = [0 => '', 1 => 'a', 2 => 'b', 3 => 'c'];
226
        $valueList = $this->dbArray[DB_INDEX_DATA_DEFAULT]->getEnumSetValueList('Person', 'groups');
227
228
229
        $this->assertEquals($expected, $valueList);
    }

230
    /**
231
     * @throws \qfq\DbException
232
     */
233
234
235
236
237
238
    public function testSelectReturn() {
        $dummy = array();
        $stat = array();

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

239
        $rc = $this->dbArray[DB_INDEX_DATA_DEFAULT]->sql($sql, ROW_REGULAR, $dummy, 'fake', $dummy, $stat);
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
        $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]);
    }

    /**
     * @throws \qfq\DbException
     */
    public function testShowReturn() {
        $dummy = array();
        $stat = array();

        $sql = "SHOW TABLES";

255
        $rc = $this->dbArray[DB_INDEX_DATA_DEFAULT]->sql($sql, ROW_REGULAR, $dummy, 'fake', $dummy, $stat);
256
257

        // DB_NUM_ROWS | DB_INSERT_ID | DB_AFFECTED_ROWS
258
        $this->assertEquals(14, $stat[DB_NUM_ROWS]);
259
260
261
262
263
264
265
266
267
268
269
    }

    /**
     * @throws \qfq\DbException
     */
    public function testExplainReturn() {
        $dummy = array();
        $stat = array();

        $sql = "EXPLAIN Person";

270
        $rc = $this->dbArray[DB_INDEX_DATA_DEFAULT]->sql($sql, ROW_REGULAR, $dummy, 'fake', $dummy, $stat);
271
272

        // DB_NUM_ROWS | DB_INSERT_ID | DB_AFFECTED_ROWS
273
        $this->assertEquals(8, $stat[DB_NUM_ROWS]);
274
275
276
277
278
279
    }

    /**
     * @throws \qfq\DbException
     */
    public function testInsertReturn() {
280
281
        $dummy = array();
        $stat = array();
282

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

285
        $rc = $this->dbArray[DB_INDEX_DATA_DEFAULT]->sql($sql, ROW_REGULAR, $dummy, 'fake', $dummy, $stat);
286
        // DB_NUM_ROWS | DB_INSERT_ID | DB_AFFECTED_ROWS
287
        $this->assertEquals(3, $stat[DB_INSERT_ID]);
288
289
290
291
292
293
294
295
296
297
298
299
300
301
        $this->assertEquals(1, $stat[DB_AFFECTED_ROWS]);

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

    /**
     * @throws \qfq\DbException
     */
    public function testUpdateReturn() {
        $dummy = array();
        $stat = array();

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

302
        $rc = $this->dbArray[DB_INDEX_DATA_DEFAULT]->sql($sql, ROW_REGULAR, $dummy, 'fake', $dummy, $stat);
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320

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

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

    /**
     * @throws \qfq\DbException
     */
    public function testDeleteReturn() {
        $dummy = array();
        $stat = array();

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

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

321
        $rc = $this->dbArray[DB_INDEX_DATA_DEFAULT]->sql($sql, ROW_REGULAR, $dummy, 'fake', $dummy, $stat);
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341

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

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

    }


    /**
     * @throws \qfq\DbException
     */
    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','')";

342
        $rc = $this->dbArray[DB_INDEX_DATA_DEFAULT]->sql($sql, ROW_REGULAR, $dummy, 'fake', $dummy, $stat);
343
344
345
346
347
348
349
350
351
        // 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','')";

352
        $rc = $this->dbArray[DB_INDEX_DATA_DEFAULT]->sql($sql, ROW_REGULAR, $dummy, 'fake', $dummy, $stat);
353
354
355
356
357
        // 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);
358
359
    }

360
361
362
363
364
365
366
    /**
     *
     */
    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' => ''],
367
368
            ['Field' => 'firstName', 'Type' => 'varchar(128)', 'Null' => 'YES', 'Key' => '', 'Default' => '', 'Extra' => ''],
            ['Field' => 'adrId', 'Type' => 'int(11)', 'Null' => 'NO', 'Key' => '', 'Default' => '0', 'Extra' => ''],
369
            ['Field' => 'gender', 'Type' => "enum('','male','female')", 'Null' => 'NO', 'Key' => '', 'Default' => 'male', 'Extra' => ''],
370
            ['Field' => 'groups', 'Type' => "set('','a','b','c')", 'Null' => 'NO', 'Key' => '', 'Default' => '', 'Extra' => ''],
371
372
            ['Field' => 'modified', 'Type' => "timestamp", 'Null' => 'NO', 'Key' => '', 'Default' => 'CURRENT_TIMESTAMP', 'Extra' => 'on update CURRENT_TIMESTAMP'],
            ['Field' => 'created', 'Type' => "datetime", 'Null' => 'NO', 'Key' => '', 'Default' => '', 'Extra' => ''],
373
374
        ];

375
        $this->assertEquals($expected, $this->dbArray[DB_INDEX_DATA_DEFAULT]->getTableDefinition('Person'));
376
377
    }

378
379
380
    /**
     *
     */
381
382
383
384
385
386
387
388
    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'
389
        $stat = array();
390
        $dataArray = $this->dbArray[DB_INDEX_DATA_DEFAULT]->sqlKeys('SELECT id AS "id", name, "0" AS "id" FROM Person ORDER BY id LIMIT 3', $keys, $stat);
391
392
393
394
395
396
397

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

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

399
400
401
402
403
    /**
     *
     */
    public function testhasLimit() {

404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
        $this->assertEquals(false, $this->dbArray[DB_INDEX_DATA_DEFAULT]->hasLimit(''));
        $this->assertEquals(false, $this->dbArray[DB_INDEX_DATA_DEFAULT]->hasLimit('SELECT'));
        $this->assertEquals(true, $this->dbArray[DB_INDEX_DATA_DEFAULT]->hasLimit('SELECT ... LIMIT 1'));
        $this->assertEquals(true, $this->dbArray[DB_INDEX_DATA_DEFAULT]->hasLimit('SELECT ... LIMIT 1 '));
        $this->assertEquals(true, $this->dbArray[DB_INDEX_DATA_DEFAULT]->hasLimit('SELECT ... LIMIT  1  '));
        $this->assertEquals(true, $this->dbArray[DB_INDEX_DATA_DEFAULT]->hasLimit('SELECT ... LIMIT 1,1'));
        $this->assertEquals(true, $this->dbArray[DB_INDEX_DATA_DEFAULT]->hasLimit('SELECT ... LIMIT 1,1 '));
        $this->assertEquals(true, $this->dbArray[DB_INDEX_DATA_DEFAULT]->hasLimit('SELECT ... LIMIT  1,1 '));
        $this->assertEquals(true, $this->dbArray[DB_INDEX_DATA_DEFAULT]->hasLimit('SELECT ... LIMIT  1,1  '));
        $this->assertEquals(true, $this->dbArray[DB_INDEX_DATA_DEFAULT]->hasLimit('SELECT ... LIMIT 1 ,1 '));
        $this->assertEquals(true, $this->dbArray[DB_INDEX_DATA_DEFAULT]->hasLimit('SELECT ... LIMIT 1 , 1 '));
        $this->assertEquals(true, $this->dbArray[DB_INDEX_DATA_DEFAULT]->hasLimit('SELECT ... LIMIT 1 ,  1 '));
        $this->assertEquals(true, $this->dbArray[DB_INDEX_DATA_DEFAULT]->hasLimit('SELECT ... LIMIT 1  ,  1 '));
        $this->assertEquals(true, $this->dbArray[DB_INDEX_DATA_DEFAULT]->hasLimit('SELECT ... LIMIT 1  ,  1  '));
        $this->assertEquals(true, $this->dbArray[DB_INDEX_DATA_DEFAULT]->hasLimit('SELECT ... LIMIT  1  ,  1  '));
        $this->assertEquals(true, $this->dbArray[DB_INDEX_DATA_DEFAULT]->hasLimit('SELECT ... LIMIT   1   ,   1   '));
420
421
422
423
    }

    public function testMakeArrayDict() {

424
        $this->assertEquals(array(), $this->dbArray[DB_INDEX_DATA_DEFAULT]->makeArrayDict(array(), 'key', 'value'));
425
426
427

        $arr[] = ['red', 'green'];
        $expect[] = ['key' => 'red', 'value' => 'green'];
428
        $this->assertEquals($expect, $this->dbArray[DB_INDEX_DATA_DEFAULT]->makeArrayDict($arr, 'key', 'value'));
429
430
431

        $arr[] = ['blue', 'orange'];
        $expect[] = ['key' => 'blue', 'value' => 'orange'];
432
        $this->assertEquals($expect, $this->dbArray[DB_INDEX_DATA_DEFAULT]->makeArrayDict($arr, 'key', 'value'));
433
434

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

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

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

        $arr = [['key' => 'red', 'value' => 'green'], ['key' => 'blue', 'value' => 'orange']];
444
        $this->assertEquals($expect, $this->dbArray[DB_INDEX_DATA_DEFAULT]->makeArrayDict($arr, 'key', 'value'));
445
446

        $arr = [['value' => 'green', 'key' => 'red'], ['value' => 'orange', 'key' => 'blue']];
447
        $this->assertEquals($expect, $this->dbArray[DB_INDEX_DATA_DEFAULT]->makeArrayDict($arr, 'key', 'value'));
448
449
450

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

        $arr = [['value1' => 'green'], ['value1' => 'orange']];
454
        $this->assertEquals($expect, $this->dbArray[DB_INDEX_DATA_DEFAULT]->makeArrayDict($arr, 'key', 'value'));
455
456

        $arr = [['key' => 'green'], ['key' => 'orange']];
457
        $this->assertEquals($expect, $this->dbArray[DB_INDEX_DATA_DEFAULT]->makeArrayDict($arr, 'key', 'value'));
458
459

        $arr = [['value' => 'green'], ['value' => 'orange']];
460
        $this->assertEquals($expect, $this->dbArray[DB_INDEX_DATA_DEFAULT]->makeArrayDict($arr, 'key', 'value'));
461
462
463

    }

464
465
466
    /**
     * @throws Exception
     */
467
468
469
470
471
472
    protected function setUp() {
        parent::setUp();

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