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\BaseCrudPanel |
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 testItCanRemoveAllColumns() |
446
|
|
|
{ |
447
|
|
|
$this->crudPanel->addColumns(['column1', 'column2', 'column3']); |
448
|
|
|
|
449
|
|
|
$this->crudPanel->removeAllColumns(); |
450
|
|
|
|
451
|
|
|
$this->assertEmpty($this->crudPanel->columns()); |
452
|
|
|
} |
453
|
|
|
|
454
|
|
|
public function testItCanSetColumnDetails() |
455
|
|
|
{ |
456
|
|
|
$this->crudPanel->addColumns(['column1', 'column2', 'column3', 'column4', 'column5']); |
457
|
|
|
|
458
|
|
|
$this->crudPanel->setColumnsDetails(['column1', 'column2'], ['label' => 'New Label']); |
459
|
|
|
$this->crudPanel->setColumnDetails('column3', ['label' => 'Old Label']); |
460
|
|
|
$this->crudPanel->modifyColumn('column4', ['label' => 'Alias Label']); |
461
|
|
|
$this->crudPanel->setColumnLabel('column5', 'Setting Label'); |
462
|
|
|
|
463
|
|
|
$this->assertEquals('New Label', $this->crudPanel->columns()['column1']['label']); |
464
|
|
|
$this->assertEquals('New Label', $this->crudPanel->columns()['column2']['label']); |
465
|
|
|
$this->assertEquals('Old Label', $this->crudPanel->columns()['column3']['label']); |
466
|
|
|
$this->assertEquals('Alias Label', $this->crudPanel->columns()['column4']['label']); |
467
|
|
|
$this->assertEquals('Setting Label', $this->crudPanel->columns()['column5']['label']); |
468
|
|
|
} |
469
|
|
|
|
470
|
|
|
public function testItCanFindAColumnById() |
471
|
|
|
{ |
472
|
|
|
$this->crudPanel->addColumns(['column1', 'column2', 'column3']); |
473
|
|
|
|
474
|
|
|
$column = $this->crudPanel->findColumnById(1); |
475
|
|
|
|
476
|
|
|
$this->assertEquals('column2', $column['name']); |
477
|
|
|
} |
478
|
|
|
|
479
|
|
|
public function testItCanGetAndSetActionsColumnPriority() |
480
|
|
|
{ |
481
|
|
|
$this->assertEquals(1, $this->crudPanel->getActionsColumnPriority()); |
482
|
|
|
$this->crudPanel->setActionsColumnPriority(2); |
483
|
|
|
$this->assertEquals(2, $this->crudPanel->getActionsColumnPriority()); |
484
|
|
|
} |
485
|
|
|
|
486
|
|
|
public function testItCanGetAndSetColumnsRemovingPreviouslySet() |
487
|
|
|
{ |
488
|
|
|
$this->crudPanel->addColumns(['column1', 'column2', 'column3']); |
489
|
|
|
|
490
|
|
|
$this->crudPanel->setColumns('column4'); |
491
|
|
|
|
492
|
|
|
$this->assertEquals(1, count($this->crudPanel->columns())); |
493
|
|
|
$this->assertEquals(['column4'], array_keys($this->crudPanel->columns())); |
494
|
|
|
|
495
|
|
|
$this->crudPanel->setColumns(['column5', 'column6']); |
496
|
|
|
$this->assertEquals(2, count($this->crudPanel->columns())); |
497
|
|
|
$this->assertEquals(['column5', 'column6'], array_keys($this->crudPanel->columns())); |
498
|
|
|
|
499
|
|
|
$this->crudPanel->setColumns(['column7', [ |
500
|
|
|
'name' => 'column8', |
501
|
|
|
]]); |
502
|
|
|
$this->assertEquals(2, count($this->crudPanel->columns())); |
503
|
|
|
$this->assertEquals(['column7', 'column8'], array_keys($this->crudPanel->columns())); |
504
|
|
|
} |
505
|
|
|
|
506
|
|
|
public function testRemoveUnknownColumnName() |
507
|
|
|
{ |
508
|
|
|
$unknownColumnName = 'column4'; |
509
|
|
|
$this->crudPanel->addColumns(['column1', 'column2', 'column3']); |
510
|
|
|
|
511
|
|
|
$this->crudPanel->removeColumn($unknownColumnName); |
512
|
|
|
|
513
|
|
|
$this->assertEquals(3, count($this->crudPanel->columns())); |
514
|
|
|
$this->assertEquals(['column1', 'column2', 'column3'], array_keys($this->crudPanel->columns())); |
515
|
|
|
$this->assertNotContains($this->otherOneColumnArray, $this->crudPanel->columns()); |
516
|
|
|
} |
517
|
|
|
|
518
|
|
|
public function testRemoveColumnsByName() |
519
|
|
|
{ |
520
|
|
|
$this->crudPanel->addColumns(['column1', 'column2', 'column3']); |
521
|
|
|
|
522
|
|
|
$this->crudPanel->removeColumns($this->twoColumnsArray); |
523
|
|
|
|
524
|
|
|
$this->assertEquals(1, count($this->crudPanel->columns())); |
525
|
|
|
$this->assertEquals(['column3'], array_keys($this->crudPanel->columns())); |
526
|
|
|
$this->assertNotEquals($this->expectedThreeColumnsArray, $this->crudPanel->columns()); |
527
|
|
|
} |
528
|
|
|
|
529
|
|
|
public function testRemoveUnknownColumnsByName() |
530
|
|
|
{ |
531
|
|
|
$unknownColumnNames = ['column4', 'column5']; |
532
|
|
|
$this->crudPanel->addColumns(['column1', 'column2', 'column3']); |
533
|
|
|
|
534
|
|
|
$this->crudPanel->removeColumns($unknownColumnNames); |
535
|
|
|
|
536
|
|
|
$this->assertEquals(3, count($this->crudPanel->columns())); |
537
|
|
|
$this->assertEquals(['column1', 'column2', 'column3'], array_keys($this->crudPanel->columns())); |
538
|
|
|
$this->assertNotContains($this->otherOneColumnArray, $this->crudPanel->columns()); |
539
|
|
|
} |
540
|
|
|
|
541
|
|
|
public function testItThrowsAnErrorWhenAttemptingToChangeTheKeyInAColumnWithoutName() |
542
|
|
|
{ |
543
|
|
|
$this->expectException(\Exception::class); |
544
|
|
|
$this->crudPanel->addColumn(['type' => 'text'])->key('new_key'); |
|
|
|
|
545
|
|
|
} |
546
|
|
|
|
547
|
|
|
public function itCanSetTheUploadAttributeOnColumn() |
548
|
|
|
{ |
549
|
|
|
$this->crudPanel->addColumn('column1')->upload(); |
|
|
|
|
550
|
|
|
|
551
|
|
|
$this->assertEquals(true, $this->crudPanel->columns()['column1']['upload']); |
552
|
|
|
} |
553
|
|
|
|
554
|
|
|
public function testOrderColumns() |
555
|
|
|
{ |
556
|
|
|
$this->crudPanel->addColumns($this->threeColumnsArray); |
557
|
|
|
|
558
|
|
|
$this->crudPanel->orderColumns(['column2', 'column1', 'column3']); |
559
|
|
|
|
560
|
|
|
$this->assertEquals(['column2', 'column1', 'column3'], array_keys($this->crudPanel->columns())); |
561
|
|
|
} |
562
|
|
|
|
563
|
|
|
public function testOrderColumnsIncompleteList() |
564
|
|
|
{ |
565
|
|
|
$this->crudPanel->addColumns($this->threeColumnsArray); |
566
|
|
|
|
567
|
|
|
$this->crudPanel->orderColumns(['column2', 'column3']); |
568
|
|
|
|
569
|
|
|
$this->assertEquals(['column2', 'column3', 'column1'], array_keys($this->crudPanel->columns())); |
570
|
|
|
} |
571
|
|
|
|
572
|
|
|
public function testOrderColumnsEmptyList() |
573
|
|
|
{ |
574
|
|
|
$this->crudPanel->addColumns($this->threeColumnsArray); |
575
|
|
|
|
576
|
|
|
$this->crudPanel->orderColumns([]); |
577
|
|
|
|
578
|
|
|
$this->assertEquals($this->expectedThreeColumnsArray, $this->crudPanel->columns()); |
579
|
|
|
} |
580
|
|
|
|
581
|
|
|
public function testOrderColumnsUnknownList() |
582
|
|
|
{ |
583
|
|
|
$this->crudPanel->addColumns($this->threeColumnsArray); |
584
|
|
|
|
585
|
|
|
$this->crudPanel->orderColumns(['column4', 'column5', 'column6']); |
586
|
|
|
|
587
|
|
|
$this->assertEquals($this->expectedThreeColumnsArray, $this->crudPanel->columns()); |
588
|
|
|
} |
589
|
|
|
|
590
|
|
|
public function testOrderColumnsMixedList() |
591
|
|
|
{ |
592
|
|
|
$this->crudPanel->addColumns($this->threeColumnsArray); |
593
|
|
|
|
594
|
|
|
$this->crudPanel->orderColumns(['column2', 'column5', 'column6']); |
595
|
|
|
|
596
|
|
|
$this->assertEquals(['column2', 'column1', 'column3'], array_keys($this->crudPanel->columns())); |
597
|
|
|
} |
598
|
|
|
|
599
|
|
|
public function testItDoesNotAttemptToGetEntityWhenColumnNameIsArray() |
600
|
|
|
{ |
601
|
|
|
$this->crudPanel->addColumn(['name' => ['test1', 'test2'], 'label' => 'Column1', 'type' => 'text', 'key' => 'column1']); |
602
|
|
|
$this->assertArrayNotHasKey('entity', $this->crudPanel->firstColumnWhere('key', 'column1')); |
|
|
|
|
603
|
|
|
} |
604
|
|
|
|
605
|
|
|
public function testItCanInferTheEntityFromColumnNameUsingEntity_idConvention() |
606
|
|
|
{ |
607
|
|
|
$this->crudPanel->addColumn('article_id'); |
608
|
|
|
|
609
|
|
|
$this->assertEquals('article', $this->crudPanel->firstColumnWhere('name', 'article_id')['entity']); |
610
|
|
|
} |
611
|
|
|
|
612
|
|
|
public function testItAlwaysHasDatabaseColumnWhenDriverIsNotSql() |
613
|
|
|
{ |
614
|
|
|
$this->crudPanel = new \Backpack\CRUD\Tests\config\CrudPanel\NoSqlDriverCrudPanel(); |
615
|
|
|
$this->crudPanel->setModel(User::class); |
616
|
|
|
|
617
|
|
|
$this->assertTrue($this->invokeMethod($this->crudPanel, 'hasDatabaseColumn', ['test', 'test'])); |
618
|
|
|
} |
619
|
|
|
|
620
|
|
|
public function testItCanGetTheColumnTypeFromModelCasts() |
621
|
|
|
{ |
622
|
|
|
$this->crudPanel->addColumn('arrayCast'); |
623
|
|
|
$this->crudPanel->addColumn('jsonCast'); |
624
|
|
|
$this->crudPanel->addColumn('dateCast'); |
625
|
|
|
$this->crudPanel->addColumn('booleanCast'); |
626
|
|
|
$this->crudPanel->addColumn('datetimeCast'); |
627
|
|
|
$this->crudPanel->addColumn('numberCast'); |
628
|
|
|
|
629
|
|
|
$this->assertEquals('array', $this->crudPanel->firstColumnWhere('name', 'arrayCast')['type']); |
630
|
|
|
$this->assertEquals('json', $this->crudPanel->firstColumnWhere('name', 'jsonCast')['type']); |
631
|
|
|
$this->assertEquals('date', $this->crudPanel->firstColumnWhere('name', 'dateCast')['type']); |
632
|
|
|
$this->assertEquals('check', $this->crudPanel->firstColumnWhere('name', 'booleanCast')['type']); |
633
|
|
|
$this->assertEquals('datetime', $this->crudPanel->firstColumnWhere('name', 'datetimeCast')['type']); |
634
|
|
|
$this->assertEquals('number', $this->crudPanel->firstColumnWhere('name', 'numberCast')['type']); |
635
|
|
|
} |
636
|
|
|
|
637
|
|
|
public function testItCanGetTheColumnTypeFromModelDates() |
638
|
|
|
{ |
639
|
|
|
$this->crudPanel->addColumn('created_at'); |
640
|
|
|
|
641
|
|
|
$this->assertEquals('datetime', $this->crudPanel->firstColumnWhere('name', 'created_at')['type']); |
642
|
|
|
} |
643
|
|
|
|
644
|
|
|
public function testMakeFirstColumnReturnFalseWhenNoColumnsExist() |
645
|
|
|
{ |
646
|
|
|
$this->assertEmpty($this->crudPanel->columns()); |
647
|
|
|
$column = $this->crudPanel->makeFirstColumn(); |
648
|
|
|
$this->assertFalse($column); |
649
|
|
|
} |
650
|
|
|
|
651
|
|
|
public function testItSetsTextColumnTypeForTranslatableColumns() |
652
|
|
|
{ |
653
|
|
|
$this->crudPanel->setModel(\Backpack\CRUD\Tests\config\Models\TestModelWithTranslations::class); |
654
|
|
|
$this->crudPanel->addColumn('translatableColumn'); |
655
|
|
|
|
656
|
|
|
$this->assertEquals('text', $this->crudPanel->firstColumnWhere('name', 'translatableColumn')['type']); |
657
|
|
|
} |
658
|
|
|
|
659
|
|
|
public function testItCanAddADefaultTypeToTheColumn() |
660
|
|
|
{ |
661
|
|
|
$column = $this->crudPanel->addDefaultTypeToColumn(['name' => 'name']); |
662
|
|
|
|
663
|
|
|
$this->assertEquals('text', $column['type']); |
664
|
|
|
} |
665
|
|
|
|
666
|
|
|
public function testItReturnFalseWhenTryingToAddTypeToAColumnWithoutName() |
667
|
|
|
{ |
668
|
|
|
$column = $this->crudPanel->addDefaultTypeToColumn(['attribute' => 'name']); |
669
|
|
|
|
670
|
|
|
$this->assertFalse($column); |
671
|
|
|
} |
672
|
|
|
|
673
|
|
|
public function testItCanChangeTheColumnKey() |
674
|
|
|
{ |
675
|
|
|
$this->crudPanel->column('test'); |
676
|
|
|
|
677
|
|
|
$this->assertEquals('test', $this->crudPanel->columns()['test']['key']); |
678
|
|
|
|
679
|
|
|
$this->crudPanel->column('test')->key('new_key'); |
680
|
|
|
|
681
|
|
|
$this->assertEquals('new_key', $this->crudPanel->columns()['new_key']['key']); |
682
|
|
|
} |
683
|
|
|
|
684
|
|
|
public function testItCanAddAFluentColumn() |
685
|
|
|
{ |
686
|
|
|
$this->crudPanel->setModel(User::class); |
687
|
|
|
|
688
|
|
|
$this->crudPanel->column('my_column')->label('my_column'); |
689
|
|
|
|
690
|
|
|
$this->assertCount(1, $this->crudPanel->columns()); |
691
|
|
|
|
692
|
|
|
$this->assertEquals([ |
693
|
|
|
'name' => 'my_column', |
694
|
|
|
'type' => 'text', |
695
|
|
|
'label' => 'my_column', |
696
|
|
|
'key' => 'my_column', |
697
|
|
|
'priority' => 0, |
698
|
|
|
'tableColumn' => false, |
699
|
|
|
'orderable' => false, |
700
|
|
|
'searchLogic' => false, |
701
|
|
|
], $this->crudPanel->columns()['my_column']); |
702
|
|
|
} |
703
|
|
|
|
704
|
|
|
public function testItCanMakeAColumnFirstFluently() |
705
|
|
|
{ |
706
|
|
|
$this->crudPanel->column('test1'); |
707
|
|
|
$this->crudPanel->column('test2')->makeFirst(); |
708
|
|
|
$crudColumns = $this->crudPanel->columns(); |
709
|
|
|
$firstColumn = reset($crudColumns); |
710
|
|
|
$this->assertEquals($firstColumn['name'], 'test2'); |
711
|
|
|
} |
712
|
|
|
|
713
|
|
|
public function testItCanMakeAColumnLastFluently() |
714
|
|
|
{ |
715
|
|
|
$this->crudPanel->column('test1'); |
716
|
|
|
$this->crudPanel->column('test2'); |
717
|
|
|
$this->crudPanel->column('test1')->makeLast(); |
718
|
|
|
$crudColumns = $this->crudPanel->columns(); |
719
|
|
|
$firstColumn = reset($crudColumns); |
720
|
|
|
$this->assertEquals($firstColumn['name'], 'test2'); |
721
|
|
|
} |
722
|
|
|
|
723
|
|
|
public function testItCanPlaceColumnsFluently() |
724
|
|
|
{ |
725
|
|
|
$this->crudPanel->column('test1'); |
726
|
|
|
$this->crudPanel->column('test2'); |
727
|
|
|
$this->crudPanel->column('test3')->after('test1'); |
728
|
|
|
|
729
|
|
|
$crudColumnsNames = array_column($this->crudPanel->columns(), 'name'); |
730
|
|
|
$this->assertEquals($crudColumnsNames, ['test1', 'test3', 'test2']); |
731
|
|
|
|
732
|
|
|
$this->crudPanel->column('test4')->before('test1'); |
733
|
|
|
$crudColumnsNames = array_column($this->crudPanel->columns(), 'name'); |
734
|
|
|
$this->assertEquals($crudColumnsNames, ['test4', 'test1', 'test3', 'test2']); |
735
|
|
|
|
736
|
|
|
$this->crudPanel->column('test5')->afterColumn('test1'); |
737
|
|
|
$crudColumnsNames = array_column($this->crudPanel->columns(), 'name'); |
738
|
|
|
$this->assertEquals($crudColumnsNames, ['test4', 'test1', 'test5', 'test3', 'test2']); |
739
|
|
|
} |
740
|
|
|
|
741
|
|
|
public function testItCanRemoveColumnAttributesFluently() |
742
|
|
|
{ |
743
|
|
|
$this->crudPanel->column('test1')->type('test'); |
744
|
|
|
$this->assertEquals($this->crudPanel->columns()['test1']['type'], 'test'); |
745
|
|
|
$this->crudPanel->column('test1')->forget('type'); |
746
|
|
|
$this->assertNull($this->crudPanel->columns()['test1']['type'] ?? null); |
747
|
|
|
} |
748
|
|
|
|
749
|
|
|
public function testItCanRemoveColumnFluently() |
750
|
|
|
{ |
751
|
|
|
$this->crudPanel->column('test1')->type('test'); |
752
|
|
|
$this->assertCount(1, $this->crudPanel->columns()); |
753
|
|
|
$this->crudPanel->column('test1')->remove(); |
754
|
|
|
$this->assertCount(0, $this->crudPanel->columns()); |
755
|
|
|
} |
756
|
|
|
|
757
|
|
|
public function testItCanAddAColumnToCrudFromClass() |
758
|
|
|
{ |
759
|
|
|
CrudColumn::name('test'); |
760
|
|
|
$this->assertCount(1, $this->crudPanel->columns()); |
761
|
|
|
} |
762
|
|
|
|
763
|
|
|
public function testItCanAddAFluentColumnUsingArray() |
764
|
|
|
{ |
765
|
|
|
$this->crudPanel->column($this->oneColumnArray); |
766
|
|
|
$this->assertCount(1, $this->crudPanel->columns()); |
767
|
|
|
} |
768
|
|
|
|
769
|
|
|
public function testItCanAddAFluentColumnUsingArrayWithoutName() |
770
|
|
|
{ |
771
|
|
|
$this->crudPanel->column(['type' => 'text']); |
772
|
|
|
$this->assertCount(1, $this->crudPanel->columns()); |
773
|
|
|
} |
774
|
|
|
|
775
|
|
|
public function testColumnLinkToThrowsExceptionWhenNotAllRequiredParametersAreFilled() |
776
|
|
|
{ |
777
|
|
|
$this->expectException(\Exception::class); |
778
|
|
|
$this->expectExceptionMessage('Route [article.show.detail] expects parameters [id, detail]. Insufficient parameters provided in column: [articles].'); |
779
|
|
|
$this->crudPanel->column('articles')->entity('articles')->linkTo('article.show.detail', ['test' => 'testing']); |
|
|
|
|
780
|
|
|
} |
781
|
|
|
|
782
|
|
|
public function testItThrowsExceptionIfRouteNotFound() |
783
|
|
|
{ |
784
|
|
|
$this->expectException(\Exception::class); |
785
|
|
|
$this->expectExceptionMessage('Route [users.route.doesnt.exist] not found while building the link for column [id].'); |
786
|
|
|
|
787
|
|
|
CrudColumn::name('id')->linkTo('users.route.doesnt.exist')->toArray(); |
|
|
|
|
788
|
|
|
} |
789
|
|
|
|
790
|
|
|
public function testColumnLinkToWithRouteNameOnly() |
791
|
|
|
{ |
792
|
|
|
$this->crudPanel->column('articles')->entity('articles')->linkTo('articles.show'); |
793
|
|
|
$columnArray = $this->crudPanel->columns()['articles']; |
794
|
|
|
$reflection = new \ReflectionFunction($columnArray['wrapper']['href']); |
795
|
|
|
$arguments = $reflection->getClosureUsedVariables(); |
|
|
|
|
796
|
|
|
$this->crudPanel->entry = $this->makeAnArticleModel(); |
797
|
|
|
$url = $columnArray['wrapper']['href']($this->crudPanel, $columnArray, $this->crudPanel->entry, 1); |
798
|
|
|
$this->assertEquals('articles.show', $arguments['route']); |
799
|
|
|
$this->assertCount(1, $arguments['parameters']); |
800
|
|
|
$this->assertEquals('http://localhost/admin/articles/1/show', $url); |
801
|
|
|
} |
802
|
|
|
|
803
|
|
|
public function testColumnLinkToWithRouteNameAndAdditionalParameters() |
804
|
|
|
{ |
805
|
|
|
$this->crudPanel->column('articles')->entity('articles')->linkTo('articles.show', ['test' => 'testing', 'test2' => 'testing2']); |
806
|
|
|
$columnArray = $this->crudPanel->columns()['articles']; |
807
|
|
|
$reflection = new \ReflectionFunction($columnArray['wrapper']['href']); |
808
|
|
|
$arguments = $reflection->getClosureUsedVariables(); |
809
|
|
|
$this->assertEquals('articles.show', $arguments['route']); |
810
|
|
|
$this->assertCount(3, $arguments['parameters']); |
811
|
|
|
$this->crudPanel->entry = $this->makeAnArticleModel(); |
812
|
|
|
$url = $columnArray['wrapper']['href']($this->crudPanel, $columnArray, $this->crudPanel->entry, 1); |
813
|
|
|
$this->assertEquals('http://localhost/admin/articles/1/show?test=testing&test2=testing2', $url); |
814
|
|
|
} |
815
|
|
|
|
816
|
|
|
public function testColumnLinkToWithCustomParameters() |
817
|
|
|
{ |
818
|
|
|
$this->crudPanel->column('articles')->entity('articles')->linkTo('article.show.detail', ['detail' => 'testing', 'otherParam' => 'test']); |
819
|
|
|
$columnArray = $this->crudPanel->columns()['articles']; |
820
|
|
|
$this->crudPanel->entry = $this->makeAnArticleModel(); |
821
|
|
|
$url = $columnArray['wrapper']['href']($this->crudPanel, $columnArray, $this->crudPanel->entry, 1); |
822
|
|
|
$this->assertEquals('http://localhost/admin/articles/1/show/testing?otherParam=test', $url); |
823
|
|
|
} |
824
|
|
|
|
825
|
|
|
public function testColumnLinkToWithCustomClosureParameters() |
826
|
|
|
{ |
827
|
|
|
$this->crudPanel->column('articles') |
828
|
|
|
->entity('articles') |
829
|
|
|
->linkTo('article.show.detail', ['detail' => fn ($entry, $related_key) => $related_key, 'otherParam' => fn ($entry) => $entry->content]); |
830
|
|
|
$columnArray = $this->crudPanel->columns()['articles']; |
831
|
|
|
$this->crudPanel->entry = $this->makeAnArticleModel(); |
832
|
|
|
$url = $columnArray['wrapper']['href']($this->crudPanel, $columnArray, $this->crudPanel->entry, 1); |
833
|
|
|
$this->assertEquals('http://localhost/admin/articles/1/show/1?otherParam=Some%20Content', $url); |
834
|
|
|
} |
835
|
|
|
|
836
|
|
|
public function testColumnLinkToDontAutoInferParametersIfAllProvided() |
837
|
|
|
{ |
838
|
|
|
$this->crudPanel->column('articles') |
839
|
|
|
->entity('articles') |
840
|
|
|
->linkTo('article.show.detail', ['id' => 123, 'detail' => fn ($entry, $related_key) => $related_key, 'otherParam' => fn ($entry) => $entry->content]); |
841
|
|
|
$columnArray = $this->crudPanel->columns()['articles']; |
842
|
|
|
$this->crudPanel->entry = $this->makeAnArticleModel(); |
843
|
|
|
$url = $columnArray['wrapper']['href']($this->crudPanel, $columnArray, $this->crudPanel->entry, 1); |
844
|
|
|
$this->assertEquals('http://localhost/admin/articles/123/show/1?otherParam=Some%20Content', $url); |
845
|
|
|
} |
846
|
|
|
|
847
|
|
|
public function testColumnLinkToAutoInferAnySingleParameter() |
848
|
|
|
{ |
849
|
|
|
$this->crudPanel->column('articles') |
850
|
|
|
->entity('articles') |
851
|
|
|
->linkTo('article.show.detail', ['id' => 123, 'otherParam' => fn ($entry) => $entry->content]); |
852
|
|
|
$columnArray = $this->crudPanel->columns()['articles']; |
853
|
|
|
$this->crudPanel->entry = $this->makeAnArticleModel(); |
854
|
|
|
$url = $columnArray['wrapper']['href']($this->crudPanel, $columnArray, $this->crudPanel->entry, 1); |
855
|
|
|
$this->assertEquals('http://localhost/admin/articles/123/show/1?otherParam=Some%20Content', $url); |
856
|
|
|
} |
857
|
|
|
|
858
|
|
|
public function testColumnLinkToWithClosure() |
859
|
|
|
{ |
860
|
|
|
$this->crudPanel->column('articles') |
861
|
|
|
->entity('articles') |
862
|
|
|
->linkTo(fn ($entry) => route('articles.show', $entry->content)); |
|
|
|
|
863
|
|
|
$columnArray = $this->crudPanel->columns()['articles']; |
864
|
|
|
$this->crudPanel->entry = $this->makeAnArticleModel(); |
865
|
|
|
$url = $columnArray['wrapper']['href']($this->crudPanel, $columnArray, $this->crudPanel->entry, 1); |
866
|
|
|
$this->assertEquals('http://localhost/admin/articles/Some%20Content/show', $url); |
867
|
|
|
} |
868
|
|
|
|
869
|
|
|
public function testColumnArrayDefinitionLinkToRouteAsClosure() |
870
|
|
|
{ |
871
|
|
|
$this->crudPanel->setModel(User::class); |
872
|
|
|
$this->crudPanel->column([ |
873
|
|
|
'name' => 'articles', |
874
|
|
|
'entity' => 'articles', |
875
|
|
|
'linkTo' => fn ($entry) => route('articles.show', ['id' => $entry->id, 'test' => 'testing']), |
876
|
|
|
]); |
877
|
|
|
$columnArray = $this->crudPanel->columns()['articles']; |
878
|
|
|
$this->crudPanel->entry = $this->makeAnArticleModel(); |
879
|
|
|
$url = $columnArray['wrapper']['href']($this->crudPanel, $columnArray, $this->crudPanel->entry, 1); |
880
|
|
|
$this->assertEquals('http://localhost/admin/articles/1/show?test=testing', $url); |
881
|
|
|
} |
882
|
|
|
|
883
|
|
|
public function testColumnArrayDefinitionLinkToRouteNameOnly() |
884
|
|
|
{ |
885
|
|
|
$this->crudPanel->setModel(User::class); |
886
|
|
|
$this->crudPanel->column([ |
887
|
|
|
'name' => 'articles', |
888
|
|
|
'entity' => 'articles', |
889
|
|
|
'linkTo' => 'articles.show', |
890
|
|
|
]); |
891
|
|
|
$columnArray = $this->crudPanel->columns()['articles']; |
892
|
|
|
$this->crudPanel->entry = $this->makeAnArticleModel(); |
893
|
|
|
$url = $columnArray['wrapper']['href']($this->crudPanel, $columnArray, $this->crudPanel->entry, 1); |
894
|
|
|
$this->assertEquals('http://localhost/admin/articles/1/show', $url); |
895
|
|
|
} |
896
|
|
|
|
897
|
|
|
public function testColumnArrayDefinitionLinkToRouteNameAndAdditionalParameters() |
898
|
|
|
{ |
899
|
|
|
$this->crudPanel->setModel(User::class); |
900
|
|
|
$this->crudPanel->column([ |
901
|
|
|
'name' => 'articles', |
902
|
|
|
'entity' => 'articles', |
903
|
|
|
'linkTo' => [ |
904
|
|
|
'route' => 'articles.show', |
905
|
|
|
'parameters' => [ |
906
|
|
|
'test' => 'testing', |
907
|
|
|
'test2' => fn ($entry) => $entry->content, |
908
|
|
|
], |
909
|
|
|
], |
910
|
|
|
]); |
911
|
|
|
$columnArray = $this->crudPanel->columns()['articles']; |
912
|
|
|
$reflection = new \ReflectionFunction($columnArray['wrapper']['href']); |
913
|
|
|
$arguments = $reflection->getClosureUsedVariables(); |
914
|
|
|
$this->assertEquals('articles.show', $arguments['route']); |
915
|
|
|
$this->assertCount(3, $arguments['parameters']); |
916
|
|
|
$this->crudPanel->entry = $this->makeAnArticleModel(); |
917
|
|
|
$url = $columnArray['wrapper']['href']($this->crudPanel, $columnArray, $this->crudPanel->entry, 1); |
918
|
|
|
$this->assertEquals('http://localhost/admin/articles/1/show?test=testing&test2=Some%20Content', $url); |
919
|
|
|
} |
920
|
|
|
} |
921
|
|
|
|