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