1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Backpack\CRUD\Tests\Unit\CrudPanel; |
4
|
|
|
|
5
|
|
|
use Backpack\CRUD\app\Library\CrudPanel\CrudColumn; |
6
|
|
|
use Backpack\CRUD\Tests\Unit\Models\User; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* @covers Backpack\CRUD\app\Library\CrudPanel\Traits\Columns |
10
|
|
|
* @covers Backpack\CRUD\app\Library\CrudPanel\Traits\ColumnsProtectedMethods |
11
|
|
|
* @covers Backpack\CRUD\app\Library\CrudPanel\CrudColumn |
12
|
|
|
*/ |
13
|
|
|
class CrudPanelColumnsTest extends BaseDBCrudPanelTest |
14
|
|
|
{ |
15
|
|
|
private $oneColumnArray = [ |
16
|
|
|
'name' => 'column1', |
17
|
|
|
'label' => 'Column1', |
18
|
|
|
]; |
19
|
|
|
|
20
|
|
|
private $expectedOneColumnArray = [ |
21
|
|
|
'column1' => [ |
22
|
|
|
'label' => 'Column1', |
23
|
|
|
'name' => 'column1', |
24
|
|
|
'key' => 'column1', |
25
|
|
|
'type' => 'text', |
26
|
|
|
'tableColumn' => false, |
27
|
|
|
'orderable' => false, |
28
|
|
|
'searchLogic' => false, |
29
|
|
|
'priority' => 0, |
30
|
|
|
], |
31
|
|
|
]; |
32
|
|
|
|
33
|
|
|
private $otherOneColumnArray = [ |
34
|
|
|
'name' => 'column4', |
35
|
|
|
'label' => 'Column4', |
36
|
|
|
]; |
37
|
|
|
|
38
|
|
|
private $twoColumnsArray = [ |
39
|
|
|
[ |
40
|
|
|
'name' => 'column1', |
41
|
|
|
'label' => 'Column1', |
42
|
|
|
], |
43
|
|
|
[ |
44
|
|
|
'name' => 'column2', |
45
|
|
|
'label' => 'Column2', |
46
|
|
|
], |
47
|
|
|
]; |
48
|
|
|
|
49
|
|
|
private $expectedTwoColumnsArray = [ |
50
|
|
|
'column1' => [ |
51
|
|
|
'name' => 'column1', |
52
|
|
|
'key' => 'column1', |
53
|
|
|
'label' => 'Column1', |
54
|
|
|
'type' => 'text', |
55
|
|
|
'tableColumn' => false, |
56
|
|
|
'orderable' => false, |
57
|
|
|
'searchLogic' => false, |
58
|
|
|
'priority' => 0, |
59
|
|
|
|
60
|
|
|
], |
61
|
|
|
'column2' => [ |
62
|
|
|
'name' => 'column2', |
63
|
|
|
'key' => 'column2', |
64
|
|
|
'label' => 'Column2', |
65
|
|
|
'type' => 'text', |
66
|
|
|
'tableColumn' => false, |
67
|
|
|
'orderable' => false, |
68
|
|
|
'searchLogic' => false, |
69
|
|
|
'priority' => 1, |
70
|
|
|
], |
71
|
|
|
]; |
72
|
|
|
|
73
|
|
|
private $threeColumnsArray = [ |
74
|
|
|
[ |
75
|
|
|
'name' => 'column1', |
76
|
|
|
'label' => 'Column1', |
77
|
|
|
], |
78
|
|
|
[ |
79
|
|
|
'name' => 'column2', |
80
|
|
|
'label' => 'Column2', |
81
|
|
|
], |
82
|
|
|
[ |
83
|
|
|
'name' => 'column3', |
84
|
|
|
'label' => 'Column3', |
85
|
|
|
], |
86
|
|
|
]; |
87
|
|
|
|
88
|
|
|
private $expectedThreeColumnsArray = [ |
89
|
|
|
'column1' => [ |
90
|
|
|
'name' => 'column1', |
91
|
|
|
'key' => 'column1', |
92
|
|
|
'label' => 'Column1', |
93
|
|
|
'type' => 'text', |
94
|
|
|
'tableColumn' => false, |
95
|
|
|
'orderable' => false, |
96
|
|
|
'searchLogic' => false, |
97
|
|
|
'priority' => 0, |
98
|
|
|
], |
99
|
|
|
'column2' => [ |
100
|
|
|
'name' => 'column2', |
101
|
|
|
'key' => 'column2', |
102
|
|
|
'label' => 'Column2', |
103
|
|
|
'type' => 'text', |
104
|
|
|
'tableColumn' => false, |
105
|
|
|
'orderable' => false, |
106
|
|
|
'searchLogic' => false, |
107
|
|
|
'priority' => 1, |
108
|
|
|
], |
109
|
|
|
'column3' => [ |
110
|
|
|
'name' => 'column3', |
111
|
|
|
'key' => 'column3', |
112
|
|
|
'label' => 'Column3', |
113
|
|
|
'type' => 'text', |
114
|
|
|
'tableColumn' => false, |
115
|
|
|
'orderable' => false, |
116
|
|
|
'searchLogic' => false, |
117
|
|
|
'priority' => 2, |
118
|
|
|
], |
119
|
|
|
]; |
120
|
|
|
|
121
|
|
|
private $expectedRelationColumnsArrayWithoutPro = [ |
122
|
|
|
'accountDetails' => [ |
123
|
|
|
'name' => 'accountDetails', |
124
|
|
|
'label' => 'AccountDetails', |
125
|
|
|
'type' => 'text', |
126
|
|
|
'key' => 'accountDetails', |
127
|
|
|
'priority' => 0, |
128
|
|
|
'tableColumn' => false, |
129
|
|
|
'orderable' => false, |
130
|
|
|
'searchLogic' => false, |
131
|
|
|
'entity' => 'accountDetails', |
132
|
|
|
'model' => 'Backpack\CRUD\Tests\Unit\Models\AccountDetails', |
133
|
|
|
'relation_type' => 'HasOne', |
134
|
|
|
'attribute' => 'nickname', |
135
|
|
|
], |
136
|
|
|
'accountDetails__nickname' => [ |
137
|
|
|
'name' => 'accountDetails.nickname', |
138
|
|
|
'label' => 'AccountDetails.nickname', |
139
|
|
|
'type' => 'text', |
140
|
|
|
'key' => 'accountDetails__nickname', |
141
|
|
|
'priority' => 1, |
142
|
|
|
'attribute' => 'nickname', |
143
|
|
|
'tableColumn' => false, |
144
|
|
|
'orderable' => false, |
145
|
|
|
'searchLogic' => false, |
146
|
|
|
'relation_type' => 'HasOne', |
147
|
|
|
'entity' => 'accountDetails.nickname', |
148
|
|
|
'model' => 'Backpack\CRUD\Tests\Unit\Models\AccountDetails', |
149
|
|
|
], |
150
|
|
|
'accountDetails__user' => [ |
151
|
|
|
'name' => 'accountDetails.user', |
152
|
|
|
'label' => 'AccountDetails.user', |
153
|
|
|
'type' => 'select', |
154
|
|
|
'key' => 'accountDetails__user', |
155
|
|
|
'priority' => 2, |
156
|
|
|
'tableColumn' => false, |
157
|
|
|
'orderable' => false, |
158
|
|
|
'searchLogic' => false, |
159
|
|
|
'relation_type' => 'BelongsTo', |
160
|
|
|
'entity' => 'accountDetails.user', |
161
|
|
|
'model' => 'Backpack\CRUD\Tests\Unit\Models\User', |
162
|
|
|
'attribute' => 'name', |
163
|
|
|
], |
164
|
|
|
]; |
165
|
|
|
|
166
|
|
|
private $expectedRelationColumnsArrayWithPro = [ |
167
|
|
|
'accountDetails' => [ |
168
|
|
|
'name' => 'accountDetails', |
169
|
|
|
'label' => 'AccountDetails', |
170
|
|
|
'type' => 'relationship', |
171
|
|
|
'key' => 'accountDetails', |
172
|
|
|
'priority' => 0, |
173
|
|
|
'tableColumn' => false, |
174
|
|
|
'orderable' => false, |
175
|
|
|
'searchLogic' => false, |
176
|
|
|
'entity' => 'accountDetails', |
177
|
|
|
'model' => 'Backpack\CRUD\Tests\Unit\Models\AccountDetails', |
178
|
|
|
'relation_type' => 'HasOne', |
179
|
|
|
'attribute' => 'nickname', |
180
|
|
|
], |
181
|
|
|
'accountDetails__nickname' => [ |
182
|
|
|
'name' => 'accountDetails.nickname', |
183
|
|
|
'label' => 'AccountDetails.nickname', |
184
|
|
|
'type' => 'relationship', |
185
|
|
|
'key' => 'accountDetails__nickname', |
186
|
|
|
'priority' => 1, |
187
|
|
|
'attribute' => 'nickname', |
188
|
|
|
'tableColumn' => false, |
189
|
|
|
'orderable' => false, |
190
|
|
|
'searchLogic' => false, |
191
|
|
|
'relation_type' => 'HasOne', |
192
|
|
|
'entity' => 'accountDetails.nickname', |
193
|
|
|
'model' => 'Backpack\CRUD\Tests\Unit\Models\AccountDetails', |
194
|
|
|
], |
195
|
|
|
'accountDetails__user' => [ |
196
|
|
|
'name' => 'accountDetails.user', |
197
|
|
|
'label' => 'AccountDetails.user', |
198
|
|
|
'type' => 'relationship', |
199
|
|
|
'key' => 'accountDetails__user', |
200
|
|
|
'priority' => 2, |
201
|
|
|
'tableColumn' => false, |
202
|
|
|
'orderable' => false, |
203
|
|
|
'searchLogic' => false, |
204
|
|
|
'relation_type' => 'BelongsTo', |
205
|
|
|
'entity' => 'accountDetails.user', |
206
|
|
|
'model' => 'Backpack\CRUD\Tests\Unit\Models\User', |
207
|
|
|
'attribute' => 'name', |
208
|
|
|
], |
209
|
|
|
]; |
210
|
|
|
|
211
|
|
|
private $relationColumnArray = [ |
212
|
|
|
'name' => 'nickname', |
213
|
|
|
'type' => 'select', |
214
|
|
|
'entity' => 'accountDetails', |
215
|
|
|
'attribute' => 'nickname', |
216
|
|
|
]; |
217
|
|
|
|
218
|
|
|
private $expectedRelationColumnArray = [ |
219
|
|
|
'nickname' => [ |
220
|
|
|
'name' => 'nickname', |
221
|
|
|
'type' => 'select', |
222
|
|
|
'entity' => 'accountDetails', |
223
|
|
|
'attribute' => 'nickname', |
224
|
|
|
'label' => 'Nickname', |
225
|
|
|
'model' => 'Backpack\CRUD\Tests\Unit\Models\AccountDetails', |
226
|
|
|
'key' => 'nickname', |
227
|
|
|
'tableColumn' => false, |
228
|
|
|
'orderable' => false, |
229
|
|
|
'searchLogic' => false, |
230
|
|
|
'priority' => 0, |
231
|
|
|
'relation_type' => 'HasOne', |
232
|
|
|
], |
233
|
|
|
]; |
234
|
|
|
|
235
|
|
|
private $nestedRelationColumnArray = [ |
236
|
|
|
'name' => 'accountDetails.article', |
237
|
|
|
]; |
238
|
|
|
|
239
|
|
|
private $secondNestedRelationColumnArray = [ |
240
|
|
|
'name' => 'accountDetails.article', |
241
|
|
|
'attribute' => 'content', |
242
|
|
|
'key' => 'ac_article_content', |
243
|
|
|
]; |
244
|
|
|
|
245
|
|
|
private $expectedNestedRelationColumnArrayWithPro = [ |
246
|
|
|
'accountDetails__article' => [ |
247
|
|
|
'name' => 'accountDetails.article', |
248
|
|
|
'type' => 'relationship', |
249
|
|
|
'entity' => 'accountDetails.article', |
250
|
|
|
'label' => 'AccountDetails.article', |
251
|
|
|
'model' => 'Backpack\CRUD\Tests\Unit\Models\Article', |
252
|
|
|
'key' => 'accountDetails__article', |
253
|
|
|
'tableColumn' => false, |
254
|
|
|
'orderable' => false, |
255
|
|
|
'searchLogic' => false, |
256
|
|
|
'priority' => 0, |
257
|
|
|
'relation_type' => 'BelongsTo', |
258
|
|
|
'attribute' => 'content', |
259
|
|
|
], |
260
|
|
|
'ac_article_content' => [ |
261
|
|
|
'name' => 'accountDetails.article', |
262
|
|
|
'type' => 'relationship', |
263
|
|
|
'entity' => 'accountDetails.article', |
264
|
|
|
'label' => 'AccountDetails.article', |
265
|
|
|
'model' => 'Backpack\CRUD\Tests\Unit\Models\Article', |
266
|
|
|
'key' => 'ac_article_content', |
267
|
|
|
'tableColumn' => false, |
268
|
|
|
'orderable' => false, |
269
|
|
|
'searchLogic' => false, |
270
|
|
|
'priority' => 1, |
271
|
|
|
'relation_type' => 'BelongsTo', |
272
|
|
|
'attribute' => 'content', |
273
|
|
|
], |
274
|
|
|
]; |
275
|
|
|
|
276
|
|
|
private $expectedNestedRelationColumnArrayWithoutPro = [ |
277
|
|
|
'accountDetails__article' => [ |
278
|
|
|
'name' => 'accountDetails.article', |
279
|
|
|
'type' => 'select', |
280
|
|
|
'entity' => 'accountDetails.article', |
281
|
|
|
'label' => 'AccountDetails.article', |
282
|
|
|
'model' => 'Backpack\CRUD\Tests\Unit\Models\Article', |
283
|
|
|
'key' => 'accountDetails__article', |
284
|
|
|
'tableColumn' => false, |
285
|
|
|
'orderable' => false, |
286
|
|
|
'searchLogic' => false, |
287
|
|
|
'priority' => 0, |
288
|
|
|
'relation_type' => 'BelongsTo', |
289
|
|
|
'attribute' => 'content', |
290
|
|
|
], |
291
|
|
|
'ac_article_content' => [ |
292
|
|
|
'name' => 'accountDetails.article', |
293
|
|
|
'type' => 'select', |
294
|
|
|
'entity' => 'accountDetails.article', |
295
|
|
|
'label' => 'AccountDetails.article', |
296
|
|
|
'model' => 'Backpack\CRUD\Tests\Unit\Models\Article', |
297
|
|
|
'key' => 'ac_article_content', |
298
|
|
|
'tableColumn' => false, |
299
|
|
|
'orderable' => false, |
300
|
|
|
'searchLogic' => false, |
301
|
|
|
'priority' => 1, |
302
|
|
|
'relation_type' => 'BelongsTo', |
303
|
|
|
'attribute' => 'content', |
304
|
|
|
], |
305
|
|
|
]; |
306
|
|
|
|
307
|
|
|
/** |
308
|
|
|
* Setup the test environment. |
309
|
|
|
* |
310
|
|
|
* @return void |
311
|
|
|
*/ |
312
|
|
|
protected function setUp(): void |
313
|
|
|
{ |
314
|
|
|
parent::setUp(); |
315
|
|
|
|
316
|
|
|
$this->crudPanel->setOperation('list'); |
317
|
|
|
} |
318
|
|
|
|
319
|
|
|
public function testAddColumnByName() |
320
|
|
|
{ |
321
|
|
|
$this->crudPanel->addColumn('column1'); |
322
|
|
|
|
323
|
|
|
$this->assertEquals($this->expectedOneColumnArray, $this->crudPanel->columns()); |
324
|
|
|
} |
325
|
|
|
|
326
|
|
|
public function testAddColumnsByName() |
327
|
|
|
{ |
328
|
|
|
$this->crudPanel->addColumns(['column1', 'column2']); |
329
|
|
|
|
330
|
|
|
$this->assertEquals(2, count($this->crudPanel->columns())); |
331
|
|
|
$this->assertEquals($this->expectedTwoColumnsArray, $this->crudPanel->columns()); |
332
|
|
|
} |
333
|
|
|
|
334
|
|
|
public function testAddColumnAsArray() |
335
|
|
|
{ |
336
|
|
|
$this->crudPanel->addColumn($this->oneColumnArray); |
337
|
|
|
|
338
|
|
|
$this->assertEquals($this->expectedOneColumnArray, $this->crudPanel->columns()); |
339
|
|
|
} |
340
|
|
|
|
341
|
|
|
public function testAddColumnsAsArray() |
342
|
|
|
{ |
343
|
|
|
$this->crudPanel->addColumns($this->twoColumnsArray); |
344
|
|
|
|
345
|
|
|
$this->assertEquals(2, count($this->crudPanel->columns())); |
346
|
|
|
$this->assertEquals($this->expectedTwoColumnsArray, $this->crudPanel->columns()); |
347
|
|
|
} |
348
|
|
|
|
349
|
|
|
public function testAddColumnNotArray() |
350
|
|
|
{ |
351
|
|
|
$this->expectException(PHP_MAJOR_VERSION == 7 ? \ErrorException::class : \TypeError::class); |
352
|
|
|
// Why? When calling count() on a non-countable entity, |
353
|
|
|
// PHP 7.x will through ErrorException, but PHP 8.x will throw TypeError. |
354
|
|
|
|
355
|
|
|
$this->crudPanel->addColumns('column1'); |
|
|
|
|
356
|
|
|
} |
357
|
|
|
|
358
|
|
|
public function testAddRelationsByName() |
359
|
|
|
{ |
360
|
|
|
$this->crudPanel->setModel(User::class); |
361
|
|
|
$this->crudPanel->addColumn('accountDetails'); |
362
|
|
|
$this->crudPanel->addColumn('accountDetails.nickname'); |
363
|
|
|
$this->crudPanel->addColumn('accountDetails.user'); |
364
|
|
|
|
365
|
|
|
if (backpack_pro()) { |
366
|
|
|
$this->assertEquals($this->expectedRelationColumnsArrayWithPro, $this->crudPanel->columns()); |
367
|
|
|
} else { |
368
|
|
|
$this->assertEquals($this->expectedRelationColumnsArrayWithoutPro, $this->crudPanel->columns()); |
369
|
|
|
} |
370
|
|
|
} |
371
|
|
|
|
372
|
|
|
public function testAddRelationColumn() |
373
|
|
|
{ |
374
|
|
|
$this->crudPanel->setModel(User::class); |
375
|
|
|
$this->crudPanel->addColumn($this->relationColumnArray); |
376
|
|
|
|
377
|
|
|
$this->assertEquals($this->expectedRelationColumnArray, $this->crudPanel->columns()); |
378
|
|
|
} |
379
|
|
|
|
380
|
|
|
public function testAddNestedRelationColumn() |
381
|
|
|
{ |
382
|
|
|
$this->crudPanel->setModel(User::class); |
383
|
|
|
$this->crudPanel->addColumn($this->nestedRelationColumnArray); |
384
|
|
|
$this->crudPanel->addColumn($this->secondNestedRelationColumnArray); |
385
|
|
|
|
386
|
|
|
if (backpack_pro()) { |
387
|
|
|
$this->assertEquals($this->expectedNestedRelationColumnArrayWithPro, $this->crudPanel->columns()); |
388
|
|
|
} else { |
389
|
|
|
$this->assertEquals($this->expectedNestedRelationColumnArrayWithoutPro, $this->crudPanel->columns()); |
390
|
|
|
} |
391
|
|
|
} |
392
|
|
|
|
393
|
|
|
public function testMoveColumnBefore() |
394
|
|
|
{ |
395
|
|
|
$this->crudPanel->addColumns($this->twoColumnsArray); |
396
|
|
|
|
397
|
|
|
$this->crudPanel->beforeColumn('column1'); |
398
|
|
|
|
399
|
|
|
$keys = array_keys($this->crudPanel->columns()); |
400
|
|
|
$this->assertEquals($this->expectedTwoColumnsArray['column2'], $this->crudPanel->columns()[$keys[0]]); |
401
|
|
|
$this->assertEquals(['column2', 'column1'], $keys); |
402
|
|
|
} |
403
|
|
|
|
404
|
|
|
public function testMoveColumnBeforeUnknownColumnName() |
405
|
|
|
{ |
406
|
|
|
$this->crudPanel->addColumns($this->twoColumnsArray); |
407
|
|
|
|
408
|
|
|
$this->crudPanel->beforeColumn('column3'); |
409
|
|
|
|
410
|
|
|
$this->assertEquals(array_keys($this->expectedTwoColumnsArray), array_keys($this->crudPanel->columns())); |
411
|
|
|
} |
412
|
|
|
|
413
|
|
|
public function testMoveColumnAfter() |
414
|
|
|
{ |
415
|
|
|
$this->crudPanel->addColumns($this->threeColumnsArray); |
416
|
|
|
|
417
|
|
|
$this->crudPanel->afterColumn('column1'); |
418
|
|
|
|
419
|
|
|
$keys = array_keys($this->crudPanel->columns()); |
420
|
|
|
$this->assertEquals($this->expectedThreeColumnsArray['column3'], $this->crudPanel->columns()[$keys[1]]); |
421
|
|
|
$this->assertEquals(['column1', 'column3', 'column2'], $keys); |
422
|
|
|
} |
423
|
|
|
|
424
|
|
|
public function testMoveColumnAfterUnknownColumnName() |
425
|
|
|
{ |
426
|
|
|
$this->crudPanel->addColumns($this->twoColumnsArray); |
427
|
|
|
|
428
|
|
|
$this->crudPanel->afterColumn('column3'); |
429
|
|
|
|
430
|
|
|
$this->assertEquals(array_keys($this->expectedTwoColumnsArray), array_keys($this->crudPanel->columns())); |
431
|
|
|
} |
432
|
|
|
|
433
|
|
|
public function testRemoveColumnByName() |
434
|
|
|
{ |
435
|
|
|
$this->crudPanel->addColumns(['column1', 'column2', 'column3']); |
436
|
|
|
|
437
|
|
|
$this->crudPanel->removeColumn('column1'); |
438
|
|
|
|
439
|
|
|
$this->assertEquals(2, count($this->crudPanel->columns())); |
440
|
|
|
$this->assertEquals(['column2', 'column3'], array_keys($this->crudPanel->columns())); |
441
|
|
|
$this->assertNotContains($this->oneColumnArray, $this->crudPanel->columns()); |
442
|
|
|
} |
443
|
|
|
|
444
|
|
|
public function testRemoveUnknownColumnName() |
445
|
|
|
{ |
446
|
|
|
$unknownColumnName = 'column4'; |
447
|
|
|
$this->crudPanel->addColumns(['column1', 'column2', 'column3']); |
448
|
|
|
|
449
|
|
|
$this->crudPanel->removeColumn($unknownColumnName); |
450
|
|
|
|
451
|
|
|
$this->assertEquals(3, count($this->crudPanel->columns())); |
452
|
|
|
$this->assertEquals(['column1', 'column2', 'column3'], array_keys($this->crudPanel->columns())); |
453
|
|
|
$this->assertNotContains($this->otherOneColumnArray, $this->crudPanel->columns()); |
454
|
|
|
} |
455
|
|
|
|
456
|
|
|
public function testRemoveColumnsByName() |
457
|
|
|
{ |
458
|
|
|
$this->crudPanel->addColumns(['column1', 'column2', 'column3']); |
459
|
|
|
|
460
|
|
|
$this->crudPanel->removeColumns($this->twoColumnsArray); |
461
|
|
|
|
462
|
|
|
$this->assertEquals(1, count($this->crudPanel->columns())); |
463
|
|
|
$this->assertEquals(['column3'], array_keys($this->crudPanel->columns())); |
464
|
|
|
$this->assertNotEquals($this->expectedThreeColumnsArray, $this->crudPanel->columns()); |
465
|
|
|
} |
466
|
|
|
|
467
|
|
|
public function testRemoveUnknownColumnsByName() |
468
|
|
|
{ |
469
|
|
|
$unknownColumnNames = ['column4', 'column5']; |
470
|
|
|
$this->crudPanel->addColumns(['column1', 'column2', 'column3']); |
471
|
|
|
|
472
|
|
|
$this->crudPanel->removeColumns($unknownColumnNames); |
473
|
|
|
|
474
|
|
|
$this->assertEquals(3, count($this->crudPanel->columns())); |
475
|
|
|
$this->assertEquals(['column1', 'column2', 'column3'], array_keys($this->crudPanel->columns())); |
476
|
|
|
$this->assertNotContains($this->otherOneColumnArray, $this->crudPanel->columns()); |
477
|
|
|
} |
478
|
|
|
|
479
|
|
|
public function testSetColumnDetails() |
480
|
|
|
{ |
481
|
|
|
$this->markTestIncomplete('Not correctly implemented'); |
482
|
|
|
|
483
|
|
|
// TODO: refactor crud panel sync method |
484
|
|
|
} |
485
|
|
|
|
486
|
|
|
public function testSetColumnsDetails() |
487
|
|
|
{ |
488
|
|
|
$this->markTestIncomplete('Not correctly implemented'); |
489
|
|
|
|
490
|
|
|
// TODO: refactor crud panel sync method |
491
|
|
|
} |
492
|
|
|
|
493
|
|
|
public function testOrderColumns() |
494
|
|
|
{ |
495
|
|
|
$this->crudPanel->addColumns($this->threeColumnsArray); |
496
|
|
|
|
497
|
|
|
$this->crudPanel->orderColumns(['column2', 'column1', 'column3']); |
498
|
|
|
|
499
|
|
|
$this->assertEquals(['column2', 'column1', 'column3'], array_keys($this->crudPanel->columns())); |
500
|
|
|
} |
501
|
|
|
|
502
|
|
|
public function testOrderColumnsIncompleteList() |
503
|
|
|
{ |
504
|
|
|
$this->crudPanel->addColumns($this->threeColumnsArray); |
505
|
|
|
|
506
|
|
|
$this->crudPanel->orderColumns(['column2', 'column3']); |
507
|
|
|
|
508
|
|
|
$this->assertEquals(['column2', 'column3', 'column1'], array_keys($this->crudPanel->columns())); |
509
|
|
|
} |
510
|
|
|
|
511
|
|
|
public function testOrderColumnsEmptyList() |
512
|
|
|
{ |
513
|
|
|
$this->crudPanel->addColumns($this->threeColumnsArray); |
514
|
|
|
|
515
|
|
|
$this->crudPanel->orderColumns([]); |
516
|
|
|
|
517
|
|
|
$this->assertEquals($this->expectedThreeColumnsArray, $this->crudPanel->columns()); |
518
|
|
|
} |
519
|
|
|
|
520
|
|
|
public function testOrderColumnsUnknownList() |
521
|
|
|
{ |
522
|
|
|
$this->crudPanel->addColumns($this->threeColumnsArray); |
523
|
|
|
|
524
|
|
|
$this->crudPanel->orderColumns(['column4', 'column5', 'column6']); |
525
|
|
|
|
526
|
|
|
$this->assertEquals($this->expectedThreeColumnsArray, $this->crudPanel->columns()); |
527
|
|
|
} |
528
|
|
|
|
529
|
|
|
public function testOrderColumnsMixedList() |
530
|
|
|
{ |
531
|
|
|
$this->crudPanel->addColumns($this->threeColumnsArray); |
532
|
|
|
|
533
|
|
|
$this->crudPanel->orderColumns(['column2', 'column5', 'column6']); |
534
|
|
|
|
535
|
|
|
$this->assertEquals(['column2', 'column1', 'column3'], array_keys($this->crudPanel->columns())); |
536
|
|
|
} |
537
|
|
|
|
538
|
|
|
public function testItCanAddAFluentColumn() |
539
|
|
|
{ |
540
|
|
|
$this->crudPanel->setModel(User::class); |
541
|
|
|
|
542
|
|
|
$this->crudPanel->column('my_column')->label('my_column'); |
543
|
|
|
|
544
|
|
|
$this->assertCount(1, $this->crudPanel->columns()); |
545
|
|
|
|
546
|
|
|
$this->assertEquals([ |
547
|
|
|
'name' => 'my_column', |
548
|
|
|
'type' => 'text', |
549
|
|
|
'label' => 'my_column', |
550
|
|
|
'key' => 'my_column', |
551
|
|
|
'priority' => 0, |
552
|
|
|
'tableColumn' => false, |
553
|
|
|
'orderable' => false, |
554
|
|
|
'searchLogic' => false, |
555
|
|
|
], $this->crudPanel->columns()['my_column']); |
556
|
|
|
} |
557
|
|
|
|
558
|
|
|
public function testItCanMakeAColumnFirstFluently() |
559
|
|
|
{ |
560
|
|
|
$this->crudPanel->column('test1'); |
561
|
|
|
$this->crudPanel->column('test2')->makeFirst(); |
562
|
|
|
$crudColumns = $this->crudPanel->columns(); |
563
|
|
|
$firstColumn = reset($crudColumns); |
564
|
|
|
$this->assertEquals($firstColumn['name'], 'test2'); |
565
|
|
|
} |
566
|
|
|
|
567
|
|
|
public function testItCanMakeAColumnLastFluently() |
568
|
|
|
{ |
569
|
|
|
$this->crudPanel->column('test1'); |
570
|
|
|
$this->crudPanel->column('test2'); |
571
|
|
|
$this->crudPanel->column('test1')->makeLast(); |
572
|
|
|
$crudColumns = $this->crudPanel->columns(); |
573
|
|
|
$firstColumn = reset($crudColumns); |
574
|
|
|
$this->assertEquals($firstColumn['name'], 'test2'); |
575
|
|
|
} |
576
|
|
|
|
577
|
|
|
public function testItCanPlaceColumnsFluently() |
578
|
|
|
{ |
579
|
|
|
$this->crudPanel->column('test1'); |
580
|
|
|
$this->crudPanel->column('test2'); |
581
|
|
|
$this->crudPanel->column('test3')->after('test1'); |
582
|
|
|
|
583
|
|
|
$crudColumnsNames = array_column($this->crudPanel->columns(), 'name'); |
584
|
|
|
$this->assertEquals($crudColumnsNames, ['test1', 'test3', 'test2']); |
585
|
|
|
|
586
|
|
|
$this->crudPanel->column('test4')->before('test1'); |
587
|
|
|
$crudColumnsNames = array_column($this->crudPanel->columns(), 'name'); |
588
|
|
|
$this->assertEquals($crudColumnsNames, ['test4', 'test1', 'test3', 'test2']); |
589
|
|
|
} |
590
|
|
|
|
591
|
|
|
public function testItCanRemoveColumnAttributesFluently() |
592
|
|
|
{ |
593
|
|
|
$this->crudPanel->column('test1')->type('test'); |
594
|
|
|
$this->assertEquals($this->crudPanel->columns()['test1']['type'], 'test'); |
595
|
|
|
$this->crudPanel->column('test1')->forget('type'); |
596
|
|
|
$this->assertNull($this->crudPanel->columns()['test1']['type'] ?? null); |
597
|
|
|
} |
598
|
|
|
|
599
|
|
|
public function testItCanRemoveColumnFluently() |
600
|
|
|
{ |
601
|
|
|
$this->crudPanel->column('test1')->type('test'); |
602
|
|
|
$this->assertCount(1, $this->crudPanel->columns()); |
603
|
|
|
$this->crudPanel->column('test1')->remove(); |
604
|
|
|
$this->assertCount(0, $this->crudPanel->columns()); |
605
|
|
|
} |
606
|
|
|
|
607
|
|
|
public function testItCanAddAColumnToCrudFromClass() |
608
|
|
|
{ |
609
|
|
|
CrudColumn::name('test'); |
610
|
|
|
$this->assertCount(1, $this->crudPanel->columns()); |
611
|
|
|
} |
612
|
|
|
} |
613
|
|
|
|