Scrutinizer GitHub App not installed

We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.

Install GitHub App

Test Failed
Push — add-more-tests ( 5019ae...3f486c )
by Pedro
09:43 queued 08:21
created

CrudPanelAutoSetTest::invokeMethod()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

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

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

855
        /** @scrutinizer ignore-deprecated */ $this->crudPanel->setDoctrineTypesMapping();
Loading history...
856
        $type = $original_db_platform->getDoctrineTypeMapping('enum');
0 ignored issues
show
Unused Code introduced by
The assignment to $type is dead and can be removed.
Loading history...
857
858
        $this->crudPanel->setModel(MyColumnTypeWithOtherConnection::class);
859
        $new_model_db_platform = $this->crudPanel->getModel()->getConnection()->getDoctrineConnection()->getDatabasePlatform();
860
861
        try {
862
            $new_model_db_platform->getDoctrineTypeMapping('enum');
863
        } catch (Exception $e) {
864
            $this->assertInstanceOf(Exception::class, $e);
865
        }
866
        $this->crudPanel->setDoctrineTypesMapping();
0 ignored issues
show
Deprecated Code introduced by
The function Backpack\CRUD\app\Librar...tDoctrineTypesMapping() has been deprecated. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

866
        /** @scrutinizer ignore-deprecated */ $this->crudPanel->setDoctrineTypesMapping();
Loading history...
867
868
        $type = $new_model_db_platform->getDoctrineTypeMapping('enum');
869
        $this->assertEquals('string', $type);
870
    }
871
}
872