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