1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Backpack\CRUD\Tests\Unit\CrudPanel; |
4
|
|
|
|
5
|
|
|
use Backpack\CRUD\Tests\Unit\Models\ColumnType; |
6
|
|
|
use Exception; |
7
|
|
|
|
8
|
|
|
class MyColumnTypeWithOtherConnection extends ColumnType |
9
|
|
|
{ |
10
|
|
|
protected $connection = 'testing_2'; |
11
|
|
|
} |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* @covers Backpack\CRUD\app\Library\CrudPanel\Traits\Autoset |
15
|
|
|
* @covers Backpack\CRUD\app\Library\CrudPanel\CrudPanel |
16
|
|
|
*/ |
17
|
|
|
class CrudPanelAutoSetTest extends BaseDBCrudPanelTest |
18
|
|
|
{ |
19
|
|
|
private $expectedUnknownFieldType = 'text'; |
20
|
|
|
|
21
|
|
|
private $expectedFieldTypeFromColumnType = [ |
22
|
|
|
'bigIntegerCol' => 'number', |
23
|
|
|
'binaryCol' => 'text', |
24
|
|
|
'booleanCol' => 'boolean', |
25
|
|
|
'charCol' => 'text', |
26
|
|
|
'dateCol' => 'date', |
27
|
|
|
'dateTimeCol' => 'datetime', |
28
|
|
|
'dateTimeTzCol' => 'datetime', |
29
|
|
|
'decimalCol' => 'text', |
30
|
|
|
'doubleCol' => 'text', |
31
|
|
|
'enumCol' => 'text', |
32
|
|
|
'floatCol' => 'text', |
33
|
|
|
'integerCol' => 'number', |
34
|
|
|
'ipAddressCol' => 'text', |
35
|
|
|
'jsonCol' => 'textarea', |
36
|
|
|
'jsonbCol' => 'textarea', |
37
|
|
|
'longTextCol' => 'textarea', |
38
|
|
|
'macAddressCol' => 'text', |
39
|
|
|
'mediumIntegerCol' => 'number', |
40
|
|
|
'mediumTextCol' => 'textarea', |
41
|
|
|
'smallIntegerCol' => 'number', |
42
|
|
|
'stringCol' => 'text', |
43
|
|
|
'textCol' => 'textarea', |
44
|
|
|
'timeCol' => 'time', |
45
|
|
|
'timeTzCol' => 'time', |
46
|
|
|
'tinyIntegerCol' => 'number', |
47
|
|
|
'timestampCol' => 'datetime', |
48
|
|
|
'timestampTzCol' => 'datetime', |
49
|
|
|
'uuidCol' => 'text', |
50
|
|
|
]; |
51
|
|
|
|
52
|
|
|
private $expectedColumnTypesFromDb = [ |
53
|
|
|
'bigIntegerCol' => [ |
54
|
|
|
'type' => 'integer', |
55
|
|
|
'default' => '', |
56
|
|
|
], |
57
|
|
|
'binaryCol' => [ |
58
|
|
|
'type' => 'blob', |
59
|
|
|
'default' => '', |
60
|
|
|
], |
61
|
|
|
'booleanCol' => [ |
62
|
|
|
'type' => 'boolean', |
63
|
|
|
'default' => '', |
64
|
|
|
], |
65
|
|
|
'charCol' => [ |
66
|
|
|
'type' => 'string', |
67
|
|
|
'default' => '', |
68
|
|
|
], |
69
|
|
|
'dateCol' => [ |
70
|
|
|
'type' => 'date', |
71
|
|
|
'default' => '', |
72
|
|
|
], |
73
|
|
|
'dateTimeCol' => [ |
74
|
|
|
'type' => 'datetime', |
75
|
|
|
'default' => '', |
76
|
|
|
], |
77
|
|
|
'dateTimeTzCol' => [ |
78
|
|
|
'type' => 'datetime', |
79
|
|
|
'default' => '', |
80
|
|
|
], |
81
|
|
|
'decimalCol' => [ |
82
|
|
|
'type' => 'decimal', |
83
|
|
|
'default' => '', |
84
|
|
|
], |
85
|
|
|
'doubleCol' => [ |
86
|
|
|
'type' => 'float', |
87
|
|
|
'default' => '', |
88
|
|
|
], |
89
|
|
|
'enumCol' => [ |
90
|
|
|
'type' => 'string', |
91
|
|
|
'default' => '', |
92
|
|
|
], |
93
|
|
|
'floatCol' => [ |
94
|
|
|
'type' => 'float', |
95
|
|
|
'default' => '', |
96
|
|
|
], |
97
|
|
|
'integerCol' => [ |
98
|
|
|
'type' => 'integer', |
99
|
|
|
'default' => '', |
100
|
|
|
], |
101
|
|
|
'ipAddressCol' => [ |
102
|
|
|
'type' => 'string', |
103
|
|
|
'default' => '', |
104
|
|
|
], |
105
|
|
|
'jsonCol' => [ |
106
|
|
|
'type' => 'text', |
107
|
|
|
'default' => '', |
108
|
|
|
], |
109
|
|
|
'jsonbCol' => [ |
110
|
|
|
'type' => 'text', |
111
|
|
|
'default' => '', |
112
|
|
|
], |
113
|
|
|
'longTextCol' => [ |
114
|
|
|
'type' => 'text', |
115
|
|
|
'default' => '', |
116
|
|
|
], |
117
|
|
|
'macAddressCol' => [ |
118
|
|
|
'type' => 'string', |
119
|
|
|
'default' => '', |
120
|
|
|
], |
121
|
|
|
'mediumIntegerCol' => [ |
122
|
|
|
'type' => 'integer', |
123
|
|
|
'default' => '', |
124
|
|
|
], |
125
|
|
|
'mediumTextCol' => [ |
126
|
|
|
'type' => 'text', |
127
|
|
|
'default' => '', |
128
|
|
|
], |
129
|
|
|
'smallIntegerCol' => [ |
130
|
|
|
'type' => 'integer', |
131
|
|
|
'default' => '', |
132
|
|
|
], |
133
|
|
|
'stringCol' => [ |
134
|
|
|
'type' => 'string', |
135
|
|
|
'default' => '', |
136
|
|
|
], |
137
|
|
|
'textCol' => [ |
138
|
|
|
'type' => 'text', |
139
|
|
|
'default' => '', |
140
|
|
|
], |
141
|
|
|
'timeCol' => [ |
142
|
|
|
'type' => 'time', |
143
|
|
|
'default' => '', |
144
|
|
|
], |
145
|
|
|
'timeTzCol' => [ |
146
|
|
|
'type' => 'time', |
147
|
|
|
'default' => '', |
148
|
|
|
], |
149
|
|
|
'tinyIntegerCol' => [ |
150
|
|
|
'type' => 'integer', |
151
|
|
|
'default' => '', |
152
|
|
|
], |
153
|
|
|
'timestampCol' => [ |
154
|
|
|
'type' => 'datetime', |
155
|
|
|
'default' => '', |
156
|
|
|
], |
157
|
|
|
'timestampTzCol' => [ |
158
|
|
|
'type' => 'datetime', |
159
|
|
|
'default' => '', |
160
|
|
|
], |
161
|
|
|
'uuidCol' => [ |
162
|
|
|
'type' => 'string', |
163
|
|
|
'default' => '', |
164
|
|
|
], |
165
|
|
|
]; |
166
|
|
|
|
167
|
|
|
private $expectedColumnTypes = [ |
168
|
|
|
'bigIntegerCol' => [ |
169
|
|
|
'name' => 'bigIntegerCol', |
170
|
|
|
'label' => 'BigIntegerCol', |
171
|
|
|
'value' => null, |
172
|
|
|
'default' => null, |
173
|
|
|
'type' => 'number', |
174
|
|
|
'values' => [], |
175
|
|
|
'attributes' => [], |
176
|
|
|
'autoset' => true, |
177
|
|
|
], |
178
|
|
|
'binaryCol' => [ |
179
|
|
|
'name' => 'binaryCol', |
180
|
|
|
'label' => 'BinaryCol', |
181
|
|
|
'value' => null, |
182
|
|
|
'default' => null, |
183
|
|
|
'type' => 'text', |
184
|
|
|
'values' => [], |
185
|
|
|
'attributes' => [], |
186
|
|
|
'autoset' => true, |
187
|
|
|
], |
188
|
|
|
'booleanCol' => [ |
189
|
|
|
'name' => 'booleanCol', |
190
|
|
|
'label' => 'BooleanCol', |
191
|
|
|
'value' => null, |
192
|
|
|
'default' => null, |
193
|
|
|
'type' => 'boolean', |
194
|
|
|
'values' => [], |
195
|
|
|
'attributes' => [], |
196
|
|
|
'autoset' => true, |
197
|
|
|
], |
198
|
|
|
'charCol' => [ |
199
|
|
|
'name' => 'charCol', |
200
|
|
|
'label' => 'CharCol', |
201
|
|
|
'value' => null, |
202
|
|
|
'default' => null, |
203
|
|
|
'type' => 'text', |
204
|
|
|
'values' => [], |
205
|
|
|
'attributes' => [], |
206
|
|
|
'autoset' => true, |
207
|
|
|
], |
208
|
|
|
'dateCol' => [ |
209
|
|
|
'name' => 'dateCol', |
210
|
|
|
'label' => 'DateCol', |
211
|
|
|
'value' => null, |
212
|
|
|
'default' => null, |
213
|
|
|
'type' => 'date', |
214
|
|
|
'values' => [], |
215
|
|
|
'attributes' => [], |
216
|
|
|
'autoset' => true, |
217
|
|
|
], |
218
|
|
|
'dateTimeCol' => [ |
219
|
|
|
'name' => 'dateTimeCol', |
220
|
|
|
'label' => 'DateTimeCol', |
221
|
|
|
'value' => null, |
222
|
|
|
'default' => null, |
223
|
|
|
'type' => 'datetime', |
224
|
|
|
'values' => [], |
225
|
|
|
'attributes' => [], |
226
|
|
|
'autoset' => true, |
227
|
|
|
], |
228
|
|
|
'dateTimeTzCol' => [ |
229
|
|
|
'name' => 'dateTimeTzCol', |
230
|
|
|
'label' => 'DateTimeTzCol', |
231
|
|
|
'value' => null, |
232
|
|
|
'default' => null, |
233
|
|
|
'type' => 'datetime', |
234
|
|
|
'values' => [], |
235
|
|
|
'attributes' => [], |
236
|
|
|
'autoset' => true, |
237
|
|
|
], |
238
|
|
|
'decimalCol' => [ |
239
|
|
|
'name' => 'decimalCol', |
240
|
|
|
'label' => 'DecimalCol', |
241
|
|
|
'value' => null, |
242
|
|
|
'default' => null, |
243
|
|
|
'type' => 'text', |
244
|
|
|
'values' => [], |
245
|
|
|
'attributes' => [], |
246
|
|
|
'autoset' => true, |
247
|
|
|
], |
248
|
|
|
'doubleCol' => [ |
249
|
|
|
'name' => 'doubleCol', |
250
|
|
|
'label' => 'DoubleCol', |
251
|
|
|
'value' => null, |
252
|
|
|
'default' => null, |
253
|
|
|
'type' => 'text', |
254
|
|
|
'values' => [], |
255
|
|
|
'attributes' => [], |
256
|
|
|
'autoset' => true, |
257
|
|
|
], |
258
|
|
|
'enumCol' => [ |
259
|
|
|
'name' => 'enumCol', |
260
|
|
|
'label' => 'EnumCol', |
261
|
|
|
'value' => null, |
262
|
|
|
'default' => null, |
263
|
|
|
'type' => 'text', |
264
|
|
|
'values' => [], |
265
|
|
|
'attributes' => [], |
266
|
|
|
'autoset' => true, |
267
|
|
|
], |
268
|
|
|
'floatCol' => [ |
269
|
|
|
'name' => 'floatCol', |
270
|
|
|
'label' => 'FloatCol', |
271
|
|
|
'value' => null, |
272
|
|
|
'default' => null, |
273
|
|
|
'type' => 'text', |
274
|
|
|
'values' => [], |
275
|
|
|
'attributes' => [], |
276
|
|
|
'autoset' => true, |
277
|
|
|
], |
278
|
|
|
'integerCol' => [ |
279
|
|
|
'name' => 'integerCol', |
280
|
|
|
'label' => 'IntegerCol', |
281
|
|
|
'value' => null, |
282
|
|
|
'default' => null, |
283
|
|
|
'type' => 'number', |
284
|
|
|
'values' => [], |
285
|
|
|
'attributes' => [], |
286
|
|
|
'autoset' => true, |
287
|
|
|
], |
288
|
|
|
'ipAddressCol' => [ |
289
|
|
|
'name' => 'ipAddressCol', |
290
|
|
|
'label' => 'IpAddressCol', |
291
|
|
|
'value' => null, |
292
|
|
|
'default' => null, |
293
|
|
|
'type' => 'text', |
294
|
|
|
'values' => [], |
295
|
|
|
'attributes' => [], |
296
|
|
|
'autoset' => true, |
297
|
|
|
], |
298
|
|
|
'jsonCol' => [ |
299
|
|
|
'name' => 'jsonCol', |
300
|
|
|
'label' => 'JsonCol', |
301
|
|
|
'value' => null, |
302
|
|
|
'default' => null, |
303
|
|
|
'type' => 'textarea', |
304
|
|
|
'values' => [], |
305
|
|
|
'attributes' => [], |
306
|
|
|
'autoset' => true, |
307
|
|
|
], |
308
|
|
|
'jsonbCol' => [ |
309
|
|
|
'name' => 'jsonbCol', |
310
|
|
|
'label' => 'JsonbCol', |
311
|
|
|
'value' => null, |
312
|
|
|
'default' => null, |
313
|
|
|
'type' => 'textarea', |
314
|
|
|
'values' => [], |
315
|
|
|
'attributes' => [], |
316
|
|
|
'autoset' => true, |
317
|
|
|
], |
318
|
|
|
'longTextCol' => [ |
319
|
|
|
'name' => 'longTextCol', |
320
|
|
|
'label' => 'LongTextCol', |
321
|
|
|
'value' => null, |
322
|
|
|
'default' => null, |
323
|
|
|
'type' => 'textarea', |
324
|
|
|
'values' => [], |
325
|
|
|
'attributes' => [], |
326
|
|
|
'autoset' => true, |
327
|
|
|
], |
328
|
|
|
'macAddressCol' => [ |
329
|
|
|
'name' => 'macAddressCol', |
330
|
|
|
'label' => 'MacAddressCol', |
331
|
|
|
'value' => null, |
332
|
|
|
'default' => null, |
333
|
|
|
'type' => 'text', |
334
|
|
|
'values' => [], |
335
|
|
|
'attributes' => [], |
336
|
|
|
'autoset' => true, |
337
|
|
|
], |
338
|
|
|
'mediumIntegerCol' => [ |
339
|
|
|
'name' => 'mediumIntegerCol', |
340
|
|
|
'label' => 'MediumIntegerCol', |
341
|
|
|
'value' => null, |
342
|
|
|
'default' => null, |
343
|
|
|
'type' => 'number', |
344
|
|
|
'values' => [], |
345
|
|
|
'attributes' => [], |
346
|
|
|
'autoset' => true, |
347
|
|
|
], |
348
|
|
|
'mediumTextCol' => [ |
349
|
|
|
'name' => 'mediumTextCol', |
350
|
|
|
'label' => 'MediumTextCol', |
351
|
|
|
'value' => null, |
352
|
|
|
'default' => null, |
353
|
|
|
'type' => 'textarea', |
354
|
|
|
'values' => [], |
355
|
|
|
'attributes' => [], |
356
|
|
|
'autoset' => true, |
357
|
|
|
], |
358
|
|
|
'smallIntegerCol' => [ |
359
|
|
|
'name' => 'smallIntegerCol', |
360
|
|
|
'label' => 'SmallIntegerCol', |
361
|
|
|
'value' => null, |
362
|
|
|
'default' => null, |
363
|
|
|
'type' => 'number', |
364
|
|
|
'values' => [], |
365
|
|
|
'attributes' => [], |
366
|
|
|
'autoset' => true, |
367
|
|
|
], |
368
|
|
|
'stringCol' => [ |
369
|
|
|
'name' => 'stringCol', |
370
|
|
|
'label' => 'StringCol', |
371
|
|
|
'value' => null, |
372
|
|
|
'default' => null, |
373
|
|
|
'type' => 'text', |
374
|
|
|
'values' => [], |
375
|
|
|
'attributes' => [], |
376
|
|
|
'autoset' => true, |
377
|
|
|
], |
378
|
|
|
'textCol' => [ |
379
|
|
|
'name' => 'textCol', |
380
|
|
|
'label' => 'TextCol', |
381
|
|
|
'value' => null, |
382
|
|
|
'default' => null, |
383
|
|
|
'type' => 'textarea', |
384
|
|
|
'values' => [], |
385
|
|
|
'attributes' => [], |
386
|
|
|
'autoset' => true, |
387
|
|
|
], |
388
|
|
|
'timeCol' => [ |
389
|
|
|
'name' => 'timeCol', |
390
|
|
|
'label' => 'TimeCol', |
391
|
|
|
'value' => null, |
392
|
|
|
'default' => null, |
393
|
|
|
'type' => 'time', |
394
|
|
|
'values' => [], |
395
|
|
|
'attributes' => [], |
396
|
|
|
'autoset' => true, |
397
|
|
|
], |
398
|
|
|
'timeTzCol' => [ |
399
|
|
|
'name' => 'timeTzCol', |
400
|
|
|
'label' => 'TimeTzCol', |
401
|
|
|
'value' => null, |
402
|
|
|
'default' => null, |
403
|
|
|
'type' => 'time', |
404
|
|
|
'values' => [], |
405
|
|
|
'attributes' => [], |
406
|
|
|
'autoset' => true, |
407
|
|
|
], |
408
|
|
|
'tinyIntegerCol' => [ |
409
|
|
|
'name' => 'tinyIntegerCol', |
410
|
|
|
'label' => 'TinyIntegerCol', |
411
|
|
|
'value' => null, |
412
|
|
|
'default' => null, |
413
|
|
|
'type' => 'number', |
414
|
|
|
'values' => [], |
415
|
|
|
'attributes' => [], |
416
|
|
|
'autoset' => true, |
417
|
|
|
], |
418
|
|
|
'timestampCol' => [ |
419
|
|
|
'name' => 'timestampCol', |
420
|
|
|
'label' => 'TimestampCol', |
421
|
|
|
'value' => null, |
422
|
|
|
'default' => null, |
423
|
|
|
'type' => 'datetime', |
424
|
|
|
'values' => [], |
425
|
|
|
'attributes' => [], |
426
|
|
|
'autoset' => true, |
427
|
|
|
], |
428
|
|
|
'timestampTzCol' => [ |
429
|
|
|
'name' => 'timestampTzCol', |
430
|
|
|
'label' => 'TimestampTzCol', |
431
|
|
|
'value' => null, |
432
|
|
|
'default' => null, |
433
|
|
|
'type' => 'datetime', |
434
|
|
|
'values' => [], |
435
|
|
|
'attributes' => [], |
436
|
|
|
'autoset' => true, |
437
|
|
|
], |
438
|
|
|
'uuidCol' => [ |
439
|
|
|
'name' => 'uuidCol', |
440
|
|
|
'label' => 'UuidCol', |
441
|
|
|
'value' => null, |
442
|
|
|
'default' => null, |
443
|
|
|
'type' => 'text', |
444
|
|
|
'values' => [], |
445
|
|
|
'attributes' => [], |
446
|
|
|
'autoset' => true, |
447
|
|
|
], |
448
|
|
|
]; |
449
|
|
|
|
450
|
|
|
private $expectedFieldsFromDb = [ |
451
|
|
|
'bigIntegerCol' => [ |
452
|
|
|
'name' => 'bigIntegerCol', |
453
|
|
|
'label' => 'BigIntegerCol', |
454
|
|
|
'value' => null, |
455
|
|
|
'default' => null, |
456
|
|
|
'type' => 'number', |
457
|
|
|
'values' => [], |
458
|
|
|
'attributes' => [], |
459
|
|
|
'autoset' => true, |
460
|
|
|
'entity' => false, |
461
|
|
|
], |
462
|
|
|
'binaryCol' => [ |
463
|
|
|
'name' => 'binaryCol', |
464
|
|
|
'label' => 'BinaryCol', |
465
|
|
|
'value' => null, |
466
|
|
|
'default' => null, |
467
|
|
|
'type' => 'text', |
468
|
|
|
'values' => [], |
469
|
|
|
'attributes' => [], |
470
|
|
|
'autoset' => true, |
471
|
|
|
'entity' => false, |
472
|
|
|
], |
473
|
|
|
'booleanCol' => [ |
474
|
|
|
'name' => 'booleanCol', |
475
|
|
|
'label' => 'BooleanCol', |
476
|
|
|
'value' => null, |
477
|
|
|
'default' => null, |
478
|
|
|
'type' => 'boolean', |
479
|
|
|
'values' => [], |
480
|
|
|
'attributes' => [], |
481
|
|
|
'autoset' => true, |
482
|
|
|
'entity' => false, |
483
|
|
|
], |
484
|
|
|
'charCol' => [ |
485
|
|
|
'name' => 'charCol', |
486
|
|
|
'label' => 'CharCol', |
487
|
|
|
'value' => null, |
488
|
|
|
'default' => null, |
489
|
|
|
'type' => 'text', |
490
|
|
|
'values' => [], |
491
|
|
|
'attributes' => [], |
492
|
|
|
'autoset' => true, |
493
|
|
|
'entity' => false, |
494
|
|
|
], |
495
|
|
|
'dateCol' => [ |
496
|
|
|
'name' => 'dateCol', |
497
|
|
|
'label' => 'DateCol', |
498
|
|
|
'value' => null, |
499
|
|
|
'default' => null, |
500
|
|
|
'type' => 'date', |
501
|
|
|
'values' => [], |
502
|
|
|
'attributes' => [], |
503
|
|
|
'autoset' => true, |
504
|
|
|
'entity' => false, |
505
|
|
|
], |
506
|
|
|
'dateTimeCol' => [ |
507
|
|
|
'name' => 'dateTimeCol', |
508
|
|
|
'label' => 'DateTimeCol', |
509
|
|
|
'value' => null, |
510
|
|
|
'default' => null, |
511
|
|
|
'type' => 'datetime', |
512
|
|
|
'values' => [], |
513
|
|
|
'attributes' => [], |
514
|
|
|
'autoset' => true, |
515
|
|
|
'entity' => false, |
516
|
|
|
], |
517
|
|
|
'dateTimeTzCol' => [ |
518
|
|
|
'name' => 'dateTimeTzCol', |
519
|
|
|
'label' => 'DateTimeTzCol', |
520
|
|
|
'value' => null, |
521
|
|
|
'default' => null, |
522
|
|
|
'type' => 'datetime', |
523
|
|
|
'values' => [], |
524
|
|
|
'attributes' => [], |
525
|
|
|
'autoset' => true, |
526
|
|
|
'entity' => false, |
527
|
|
|
], |
528
|
|
|
'decimalCol' => [ |
529
|
|
|
'name' => 'decimalCol', |
530
|
|
|
'label' => 'DecimalCol', |
531
|
|
|
'value' => null, |
532
|
|
|
'default' => null, |
533
|
|
|
'type' => 'text', |
534
|
|
|
'values' => [], |
535
|
|
|
'attributes' => [], |
536
|
|
|
'autoset' => true, |
537
|
|
|
'entity' => false, |
538
|
|
|
], |
539
|
|
|
'doubleCol' => [ |
540
|
|
|
'name' => 'doubleCol', |
541
|
|
|
'label' => 'DoubleCol', |
542
|
|
|
'value' => null, |
543
|
|
|
'default' => null, |
544
|
|
|
'type' => 'text', |
545
|
|
|
'values' => [], |
546
|
|
|
'attributes' => [], |
547
|
|
|
'autoset' => true, |
548
|
|
|
'entity' => false, |
549
|
|
|
], |
550
|
|
|
'enumCol' => [ |
551
|
|
|
'name' => 'enumCol', |
552
|
|
|
'label' => 'EnumCol', |
553
|
|
|
'value' => null, |
554
|
|
|
'default' => null, |
555
|
|
|
'type' => 'text', |
556
|
|
|
'values' => [], |
557
|
|
|
'attributes' => [], |
558
|
|
|
'autoset' => true, |
559
|
|
|
'entity' => false, |
560
|
|
|
], |
561
|
|
|
'floatCol' => [ |
562
|
|
|
'name' => 'floatCol', |
563
|
|
|
'label' => 'FloatCol', |
564
|
|
|
'value' => null, |
565
|
|
|
'default' => null, |
566
|
|
|
'type' => 'text', |
567
|
|
|
'values' => [], |
568
|
|
|
'attributes' => [], |
569
|
|
|
'autoset' => true, |
570
|
|
|
'entity' => false, |
571
|
|
|
], |
572
|
|
|
'integerCol' => [ |
573
|
|
|
'name' => 'integerCol', |
574
|
|
|
'label' => 'IntegerCol', |
575
|
|
|
'value' => null, |
576
|
|
|
'default' => null, |
577
|
|
|
'type' => 'number', |
578
|
|
|
'values' => [], |
579
|
|
|
'attributes' => [], |
580
|
|
|
'autoset' => true, |
581
|
|
|
'entity' => false, |
582
|
|
|
], |
583
|
|
|
'ipAddressCol' => [ |
584
|
|
|
'name' => 'ipAddressCol', |
585
|
|
|
'label' => 'IpAddressCol', |
586
|
|
|
'value' => null, |
587
|
|
|
'default' => null, |
588
|
|
|
'type' => 'text', |
589
|
|
|
'values' => [], |
590
|
|
|
'attributes' => [], |
591
|
|
|
'autoset' => true, |
592
|
|
|
'entity' => false, |
593
|
|
|
], |
594
|
|
|
'jsonCol' => [ |
595
|
|
|
'name' => 'jsonCol', |
596
|
|
|
'label' => 'JsonCol', |
597
|
|
|
'value' => null, |
598
|
|
|
'default' => null, |
599
|
|
|
'type' => 'textarea', |
600
|
|
|
'values' => [], |
601
|
|
|
'attributes' => [], |
602
|
|
|
'autoset' => true, |
603
|
|
|
'entity' => false, |
604
|
|
|
], |
605
|
|
|
'jsonbCol' => [ |
606
|
|
|
'name' => 'jsonbCol', |
607
|
|
|
'label' => 'JsonbCol', |
608
|
|
|
'value' => null, |
609
|
|
|
'default' => null, |
610
|
|
|
'type' => 'textarea', |
611
|
|
|
'values' => [], |
612
|
|
|
'attributes' => [], |
613
|
|
|
'autoset' => true, |
614
|
|
|
'entity' => false, |
615
|
|
|
], |
616
|
|
|
'longTextCol' => [ |
617
|
|
|
'name' => 'longTextCol', |
618
|
|
|
'label' => 'LongTextCol', |
619
|
|
|
'value' => null, |
620
|
|
|
'default' => null, |
621
|
|
|
'type' => 'textarea', |
622
|
|
|
'values' => [], |
623
|
|
|
'attributes' => [], |
624
|
|
|
'autoset' => true, |
625
|
|
|
'entity' => false, |
626
|
|
|
], |
627
|
|
|
'macAddressCol' => [ |
628
|
|
|
'name' => 'macAddressCol', |
629
|
|
|
'label' => 'MacAddressCol', |
630
|
|
|
'value' => null, |
631
|
|
|
'default' => null, |
632
|
|
|
'type' => 'text', |
633
|
|
|
'values' => [], |
634
|
|
|
'attributes' => [], |
635
|
|
|
'autoset' => true, |
636
|
|
|
'entity' => false, |
637
|
|
|
], |
638
|
|
|
'mediumIntegerCol' => [ |
639
|
|
|
'name' => 'mediumIntegerCol', |
640
|
|
|
'label' => 'MediumIntegerCol', |
641
|
|
|
'value' => null, |
642
|
|
|
'default' => null, |
643
|
|
|
'type' => 'number', |
644
|
|
|
'values' => [], |
645
|
|
|
'attributes' => [], |
646
|
|
|
'autoset' => true, |
647
|
|
|
'entity' => false, |
648
|
|
|
], |
649
|
|
|
'mediumTextCol' => [ |
650
|
|
|
'name' => 'mediumTextCol', |
651
|
|
|
'label' => 'MediumTextCol', |
652
|
|
|
'value' => null, |
653
|
|
|
'default' => null, |
654
|
|
|
'type' => 'textarea', |
655
|
|
|
'values' => [], |
656
|
|
|
'attributes' => [], |
657
|
|
|
'autoset' => true, |
658
|
|
|
'entity' => false, |
659
|
|
|
], |
660
|
|
|
'smallIntegerCol' => [ |
661
|
|
|
'name' => 'smallIntegerCol', |
662
|
|
|
'label' => 'SmallIntegerCol', |
663
|
|
|
'value' => null, |
664
|
|
|
'default' => null, |
665
|
|
|
'type' => 'number', |
666
|
|
|
'values' => [], |
667
|
|
|
'attributes' => [], |
668
|
|
|
'autoset' => true, |
669
|
|
|
'entity' => false, |
670
|
|
|
], |
671
|
|
|
'stringCol' => [ |
672
|
|
|
'name' => 'stringCol', |
673
|
|
|
'label' => 'StringCol', |
674
|
|
|
'value' => null, |
675
|
|
|
'default' => null, |
676
|
|
|
'type' => 'text', |
677
|
|
|
'values' => [], |
678
|
|
|
'attributes' => [], |
679
|
|
|
'autoset' => true, |
680
|
|
|
'entity' => false, |
681
|
|
|
], |
682
|
|
|
'textCol' => [ |
683
|
|
|
'name' => 'textCol', |
684
|
|
|
'label' => 'TextCol', |
685
|
|
|
'value' => null, |
686
|
|
|
'default' => null, |
687
|
|
|
'type' => 'textarea', |
688
|
|
|
'values' => [], |
689
|
|
|
'attributes' => [], |
690
|
|
|
'autoset' => true, |
691
|
|
|
'entity' => false, |
692
|
|
|
], |
693
|
|
|
'timeCol' => [ |
694
|
|
|
'name' => 'timeCol', |
695
|
|
|
'label' => 'TimeCol', |
696
|
|
|
'value' => null, |
697
|
|
|
'default' => null, |
698
|
|
|
'type' => 'time', |
699
|
|
|
'values' => [], |
700
|
|
|
'attributes' => [], |
701
|
|
|
'autoset' => true, |
702
|
|
|
'entity' => false, |
703
|
|
|
], |
704
|
|
|
'timeTzCol' => [ |
705
|
|
|
'name' => 'timeTzCol', |
706
|
|
|
'label' => 'TimeTzCol', |
707
|
|
|
'value' => null, |
708
|
|
|
'default' => null, |
709
|
|
|
'type' => 'time', |
710
|
|
|
'values' => [], |
711
|
|
|
'attributes' => [], |
712
|
|
|
'autoset' => true, |
713
|
|
|
'entity' => false, |
714
|
|
|
], |
715
|
|
|
'tinyIntegerCol' => [ |
716
|
|
|
'name' => 'tinyIntegerCol', |
717
|
|
|
'label' => 'TinyIntegerCol', |
718
|
|
|
'value' => null, |
719
|
|
|
'default' => null, |
720
|
|
|
'type' => 'number', |
721
|
|
|
'values' => [], |
722
|
|
|
'attributes' => [], |
723
|
|
|
'autoset' => true, |
724
|
|
|
'entity' => false, |
725
|
|
|
], |
726
|
|
|
'timestampCol' => [ |
727
|
|
|
'name' => 'timestampCol', |
728
|
|
|
'label' => 'TimestampCol', |
729
|
|
|
'value' => null, |
730
|
|
|
'default' => null, |
731
|
|
|
'type' => 'datetime', |
732
|
|
|
'values' => [], |
733
|
|
|
'attributes' => [], |
734
|
|
|
'autoset' => true, |
735
|
|
|
'entity' => false, |
736
|
|
|
], |
737
|
|
|
'timestampTzCol' => [ |
738
|
|
|
'name' => 'timestampTzCol', |
739
|
|
|
'label' => 'TimestampTzCol', |
740
|
|
|
'value' => null, |
741
|
|
|
'default' => null, |
742
|
|
|
'type' => 'datetime', |
743
|
|
|
'values' => [], |
744
|
|
|
'attributes' => [], |
745
|
|
|
'autoset' => true, |
746
|
|
|
'entity' => false, |
747
|
|
|
], |
748
|
|
|
'uuidCol' => [ |
749
|
|
|
'name' => 'uuidCol', |
750
|
|
|
'label' => 'UuidCol', |
751
|
|
|
'value' => null, |
752
|
|
|
'default' => null, |
753
|
|
|
'type' => 'text', |
754
|
|
|
'values' => [], |
755
|
|
|
'attributes' => [], |
756
|
|
|
'autoset' => true, |
757
|
|
|
'entity' => false, |
758
|
|
|
], |
759
|
|
|
]; |
760
|
|
|
|
761
|
|
|
public function testGetFieldTypeFromDbColumnType() |
762
|
|
|
{ |
763
|
|
|
$this->crudPanel->setModel(ColumnType::class); |
764
|
|
|
$this->crudPanel->setOperation('create'); |
765
|
|
|
$this->crudPanel->setFromDb(); |
766
|
|
|
|
767
|
|
|
$fieldTypesFromColumnType = []; |
768
|
|
|
|
769
|
|
|
foreach ($this->crudPanel->fields() as $field) { |
770
|
|
|
$fieldTypesFromColumnType[] = $this->invokeMethod($this->crudPanel, 'inferFieldTypeFromDbColumnType', [$field['name']]); |
771
|
|
|
} |
772
|
|
|
|
773
|
|
|
$this->assertEquals(array_values($this->expectedFieldTypeFromColumnType), $fieldTypesFromColumnType); |
774
|
|
|
} |
775
|
|
|
|
776
|
|
|
public function testSetFromDb() |
777
|
|
|
{ |
778
|
|
|
$this->crudPanel->setModel(ColumnType::class); |
779
|
|
|
$this->crudPanel->setOperation('create'); |
780
|
|
|
$this->crudPanel->setFromDb(); |
781
|
|
|
|
782
|
|
|
$this->assertEquals($this->expectedFieldsFromDb, $this->crudPanel->fields()); |
783
|
|
|
} |
784
|
|
|
|
785
|
|
|
public function testGetDbColumnTypes() |
786
|
|
|
{ |
787
|
|
|
$this->crudPanel->setModel(ColumnType::class); |
788
|
|
|
|
789
|
|
|
$columnTypes = $this->crudPanel->getDbColumnTypes(); |
790
|
|
|
|
791
|
|
|
$this->assertEquals($this->expectedColumnTypesFromDb, $columnTypes); |
792
|
|
|
} |
793
|
|
|
|
794
|
|
|
public function testGetFieldTypeFromDbColumnTypeUnknownField() |
795
|
|
|
{ |
796
|
|
|
$fieldType = $this->invokeMethod($this->crudPanel, 'inferFieldTypeFromDbColumnType', ['someUnknowField1']); |
797
|
|
|
|
798
|
|
|
$this->assertEquals($this->expectedUnknownFieldType, $fieldType); |
799
|
|
|
} |
800
|
|
|
|
801
|
|
|
public function testMakeLabel() |
802
|
|
|
{ |
803
|
|
|
$this->markTestIncomplete('Not correctly implemented'); |
804
|
|
|
|
805
|
|
|
$idLabel = $this->crudPanel->makeLabel('id'); |
806
|
|
|
$snakeCaseFKLabel = $this->crudPanel->makeLabel('id_user'); |
807
|
|
|
$camelCaseFKLabel = $this->crudPanel->makeLabel('idUser'); |
808
|
|
|
$camelCaseFKLabelReversed = $this->crudPanel->makeLabel('userId'); |
809
|
|
|
$dateLabel = $this->crudPanel->makeLabel('created_at'); |
810
|
|
|
$camelCaseLabel = $this->crudPanel->makeLabel('camelCaseLabel'); |
811
|
|
|
$camelCaseRandomLabel = $this->crudPanel->makeLabel('camelCaseLabelRANDOMCase'); |
812
|
|
|
$simpleLabel = $this->crudPanel->makeLabel('label'); |
813
|
|
|
$snakeCaseLabel = $this->crudPanel->makeLabel('snake_case_label'); |
814
|
|
|
$snakeCaseRandomLabel = $this->crudPanel->makeLabel('snake_Case_random_CASE'); |
815
|
|
|
$allCapsLabel = $this->crudPanel->makeLabel('ALLCAPSLABEL'); |
816
|
|
|
|
817
|
|
|
// TODO: the id label gets removed. it should not be removed if it is not followed by anything. |
818
|
|
|
// TODO: improve method documentation to know what to expect. |
819
|
|
|
$this->assertEquals('Id', $idLabel); |
820
|
|
|
$this->assertEquals('Id user', $snakeCaseFKLabel); |
821
|
|
|
$this->assertEquals('IdUser', $camelCaseFKLabel); |
822
|
|
|
$this->assertEquals('User', $camelCaseFKLabelReversed); |
823
|
|
|
$this->assertEquals('Created', $dateLabel); |
824
|
|
|
$this->assertEquals('CamelCaseLabel', $camelCaseLabel); |
825
|
|
|
$this->assertEquals('CamelCaseLabelRANDOMCase', $camelCaseRandomLabel); |
826
|
|
|
$this->assertEquals('Label', $simpleLabel); |
827
|
|
|
$this->assertEquals('Snake case label', $snakeCaseLabel); |
828
|
|
|
$this->assertEquals('Snake Case random CASE', $snakeCaseRandomLabel); |
829
|
|
|
$this->assertEquals('ALLCAPSLABEL', $allCapsLabel); |
830
|
|
|
} |
831
|
|
|
|
832
|
|
|
public function testMakeLabelEmpty() |
833
|
|
|
{ |
834
|
|
|
$label = $this->crudPanel->makeLabel(''); |
835
|
|
|
|
836
|
|
|
$this->assertEmpty($label); |
837
|
|
|
} |
838
|
|
|
|
839
|
|
|
public function testGetDbColumnsNames() |
840
|
|
|
{ |
841
|
|
|
$this->crudPanel->setModel(ColumnType::class); |
842
|
|
|
|
843
|
|
|
$columnNames = $this->crudPanel->getDbColumnsNames(); |
844
|
|
|
|
845
|
|
|
$this->assertEquals(array_keys($this->expectedColumnTypes), $columnNames); |
846
|
|
|
} |
847
|
|
|
|
848
|
|
|
public function testSetDoctrineTypesMapping() |
849
|
|
|
{ |
850
|
|
|
$original_db_config = $this->app['config']->get('database.connections.testing'); |
851
|
|
|
$new_model_db_config = array_merge($original_db_config, ['prefix' => 'testing2']); |
852
|
|
|
|
853
|
|
|
$this->app['config']->set('database.connections.testing_2', $new_model_db_config); |
854
|
|
|
|
855
|
|
|
$original_db_platform = $this->crudPanel->getModel()->getConnection()->getDoctrineConnection()->getDatabasePlatform(); |
856
|
|
|
$this->crudPanel->setDoctrineTypesMapping(); |
|
|
|
|
857
|
|
|
$type = $original_db_platform->getDoctrineTypeMapping('enum'); |
|
|
|
|
858
|
|
|
|
859
|
|
|
$this->crudPanel->setModel(MyColumnTypeWithOtherConnection::class); |
860
|
|
|
$new_model_db_platform = $this->crudPanel->getModel()->getConnection()->getDoctrineConnection()->getDatabasePlatform(); |
861
|
|
|
|
862
|
|
|
try { |
863
|
|
|
$new_model_db_platform->getDoctrineTypeMapping('enum'); |
864
|
|
|
} catch (Exception $e) { |
865
|
|
|
$this->assertInstanceOf(Exception::class, $e); |
866
|
|
|
} |
867
|
|
|
$this->crudPanel->setDoctrineTypesMapping(); |
|
|
|
|
868
|
|
|
|
869
|
|
|
$type = $new_model_db_platform->getDoctrineTypeMapping('enum'); |
870
|
|
|
$this->assertEquals('string', $type); |
871
|
|
|
} |
872
|
|
|
} |
873
|
|
|
|