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 testAddRelationByNameWithMutator() |
374
|
|
|
{ |
375
|
|
|
$this->crudPanel->setModel(User::class); |
376
|
|
|
$this->crudPanel->addColumn('accountDetails.nicknamutator'); |
377
|
|
|
if (backpack_pro()) { |
378
|
|
|
$this->assertEquals(['accountDetails__nicknamutator' => [ |
379
|
|
|
'name' => 'accountDetails.nicknamutator', |
380
|
|
|
'label' => 'AccountDetails.nicknamutator', |
381
|
|
|
'type' => 'relationship', |
382
|
|
|
'key' => 'accountDetails__nicknamutator', |
383
|
|
|
'priority' => 0, |
384
|
|
|
'attribute' => 'nicknamutator', |
385
|
|
|
'tableColumn' => false, |
386
|
|
|
'orderable' => false, |
387
|
|
|
'searchLogic' => false, |
388
|
|
|
'relation_type' => 'HasOne', |
389
|
|
|
'entity' => 'accountDetails.nicknamutator', |
390
|
|
|
'model' => 'Backpack\CRUD\Tests\Config\Models\AccountDetails', |
391
|
|
|
]], $this->crudPanel->columns()); |
392
|
|
|
} else { |
393
|
|
|
$this->assertEquals(['accountDetails__nicknamutator' => [ |
394
|
|
|
'name' => 'accountDetails.nicknamutator', |
395
|
|
|
'label' => 'AccountDetails.nicknamutator', |
396
|
|
|
'type' => 'text', |
397
|
|
|
'key' => 'accountDetails__nicknamutator', |
398
|
|
|
'priority' => 0, |
399
|
|
|
'attribute' => 'nicknamutator', |
400
|
|
|
'tableColumn' => false, |
401
|
|
|
'orderable' => false, |
402
|
|
|
'searchLogic' => false, |
403
|
|
|
'relation_type' => 'HasOne', |
404
|
|
|
'entity' => 'accountDetails.nicknamutator', |
405
|
|
|
'model' => 'Backpack\CRUD\Tests\Config\Models\AccountDetails', |
406
|
|
|
]], $this->crudPanel->columns()); |
407
|
|
|
} |
408
|
|
|
} |
409
|
|
|
|
410
|
|
|
|
411
|
|
|
|
412
|
|
|
public function testAddRelationColumn() |
413
|
|
|
{ |
414
|
|
|
$this->crudPanel->setModel(User::class); |
415
|
|
|
$this->crudPanel->addColumn($this->relationColumnArray); |
416
|
|
|
|
417
|
|
|
$this->assertEquals($this->expectedRelationColumnArray, $this->crudPanel->columns()); |
418
|
|
|
} |
419
|
|
|
|
420
|
|
|
public function testAddNestedRelationColumn() |
421
|
|
|
{ |
422
|
|
|
$this->crudPanel->setModel(User::class); |
423
|
|
|
$this->crudPanel->addColumn($this->nestedRelationColumnArray); |
424
|
|
|
$this->crudPanel->addColumn($this->secondNestedRelationColumnArray); |
425
|
|
|
|
426
|
|
|
if (backpack_pro()) { |
427
|
|
|
$this->assertEquals($this->expectedNestedRelationColumnArrayWithPro, $this->crudPanel->columns()); |
428
|
|
|
} else { |
429
|
|
|
$this->assertEquals($this->expectedNestedRelationColumnArrayWithoutPro, $this->crudPanel->columns()); |
430
|
|
|
} |
431
|
|
|
} |
432
|
|
|
|
433
|
|
|
public function testMoveColumnBefore() |
434
|
|
|
{ |
435
|
|
|
$this->crudPanel->addColumns($this->twoColumnsArray); |
436
|
|
|
|
437
|
|
|
$this->crudPanel->beforeColumn('column1'); |
438
|
|
|
|
439
|
|
|
$keys = array_keys($this->crudPanel->columns()); |
440
|
|
|
$expected = $this->expectedTwoColumnsArray['column2']; |
441
|
|
|
$expected['priority'] = 0; |
442
|
|
|
$this->assertEquals($expected, $this->crudPanel->columns()[$keys[0]]); |
443
|
|
|
$this->assertEquals(['column2', 'column1'], $keys); |
444
|
|
|
} |
445
|
|
|
|
446
|
|
|
public function testItDoesNotChangeThePriorityIfDeveloperDefinedIt() |
447
|
|
|
{ |
448
|
|
|
$this->crudPanel->addColumn('column1'); |
449
|
|
|
$this->crudPanel->addColumn(['name' => 'column2', 'priority' => 5])->beforeColumn('column1'); |
450
|
|
|
$this->assertEquals(5, $this->crudPanel->firstColumnWhere('name', 'column2')['priority']); |
451
|
|
|
} |
452
|
|
|
|
453
|
|
|
public function testMoveColumnBeforeUnknownColumnName() |
454
|
|
|
{ |
455
|
|
|
$this->crudPanel->addColumns($this->twoColumnsArray); |
456
|
|
|
|
457
|
|
|
$this->crudPanel->beforeColumn('column3'); |
458
|
|
|
|
459
|
|
|
$this->assertEquals(array_keys($this->expectedTwoColumnsArray), array_keys($this->crudPanel->columns())); |
460
|
|
|
} |
461
|
|
|
|
462
|
|
|
public function testMoveColumnAfter() |
463
|
|
|
{ |
464
|
|
|
$this->crudPanel->addColumns($this->threeColumnsArray); |
465
|
|
|
|
466
|
|
|
$this->crudPanel->afterColumn('column1'); |
467
|
|
|
|
468
|
|
|
$keys = array_keys($this->crudPanel->columns()); |
469
|
|
|
$expected = $this->expectedThreeColumnsArray['column3']; |
470
|
|
|
$expected['priority'] = 1; |
471
|
|
|
$this->assertEquals($expected, $this->crudPanel->columns()[$keys[1]]); |
472
|
|
|
$this->assertEquals(['column1', 'column3', 'column2'], $keys); |
473
|
|
|
} |
474
|
|
|
|
475
|
|
|
public function testMoveColumnAfterUnknownColumnName() |
476
|
|
|
{ |
477
|
|
|
$this->crudPanel->addColumns($this->twoColumnsArray); |
478
|
|
|
|
479
|
|
|
$this->crudPanel->afterColumn('column3'); |
480
|
|
|
|
481
|
|
|
$this->assertEquals(array_keys($this->expectedTwoColumnsArray), array_keys($this->crudPanel->columns())); |
482
|
|
|
} |
483
|
|
|
|
484
|
|
|
public function testRemoveColumnByName() |
485
|
|
|
{ |
486
|
|
|
$this->crudPanel->addColumns(['column1', 'column2', 'column3']); |
487
|
|
|
|
488
|
|
|
$this->crudPanel->removeColumn('column1'); |
489
|
|
|
|
490
|
|
|
$this->assertEquals(2, count($this->crudPanel->columns())); |
491
|
|
|
$this->assertEquals(['column2', 'column3'], array_keys($this->crudPanel->columns())); |
492
|
|
|
$this->assertNotContains($this->oneColumnArray, $this->crudPanel->columns()); |
493
|
|
|
} |
494
|
|
|
|
495
|
|
|
public function testItCanRemoveAllColumns() |
496
|
|
|
{ |
497
|
|
|
$this->crudPanel->addColumns(['column1', 'column2', 'column3']); |
498
|
|
|
|
499
|
|
|
$this->crudPanel->removeAllColumns(); |
500
|
|
|
|
501
|
|
|
$this->assertEmpty($this->crudPanel->columns()); |
502
|
|
|
} |
503
|
|
|
|
504
|
|
|
public function testItCanSetColumnDetails() |
505
|
|
|
{ |
506
|
|
|
$this->crudPanel->addColumns(['column1', 'column2', 'column3', 'column4', 'column5']); |
507
|
|
|
|
508
|
|
|
$this->crudPanel->setColumnsDetails(['column1', 'column2'], ['label' => 'New Label']); |
509
|
|
|
$this->crudPanel->setColumnDetails('column3', ['label' => 'Old Label']); |
510
|
|
|
$this->crudPanel->modifyColumn('column4', ['label' => 'Alias Label']); |
511
|
|
|
$this->crudPanel->setColumnLabel('column5', 'Setting Label'); |
512
|
|
|
|
513
|
|
|
$this->assertEquals('New Label', $this->crudPanel->columns()['column1']['label']); |
514
|
|
|
$this->assertEquals('New Label', $this->crudPanel->columns()['column2']['label']); |
515
|
|
|
$this->assertEquals('Old Label', $this->crudPanel->columns()['column3']['label']); |
516
|
|
|
$this->assertEquals('Alias Label', $this->crudPanel->columns()['column4']['label']); |
517
|
|
|
$this->assertEquals('Setting Label', $this->crudPanel->columns()['column5']['label']); |
518
|
|
|
} |
519
|
|
|
|
520
|
|
|
public function testItCanFindAColumnById() |
521
|
|
|
{ |
522
|
|
|
$this->crudPanel->addColumns(['column1', 'column2', 'column3']); |
523
|
|
|
|
524
|
|
|
$column = $this->crudPanel->findColumnById(1); |
525
|
|
|
|
526
|
|
|
$this->assertEquals('column2', $column['name']); |
527
|
|
|
} |
528
|
|
|
|
529
|
|
|
public function testItCanGetAndSetActionsColumnPriority() |
530
|
|
|
{ |
531
|
|
|
$this->assertEquals(1, $this->crudPanel->getActionsColumnPriority()); |
532
|
|
|
$this->crudPanel->setActionsColumnPriority(2); |
533
|
|
|
$this->assertEquals(2, $this->crudPanel->getActionsColumnPriority()); |
534
|
|
|
} |
535
|
|
|
|
536
|
|
|
public function testItCanGetAndSetColumnsRemovingPreviouslySet() |
537
|
|
|
{ |
538
|
|
|
$this->crudPanel->addColumns(['column1', 'column2', 'column3']); |
539
|
|
|
|
540
|
|
|
$this->crudPanel->setColumns('column4'); |
541
|
|
|
|
542
|
|
|
$this->assertEquals(1, count($this->crudPanel->columns())); |
543
|
|
|
$this->assertEquals(['column4'], array_keys($this->crudPanel->columns())); |
544
|
|
|
|
545
|
|
|
$this->crudPanel->setColumns(['column5', 'column6']); |
546
|
|
|
$this->assertEquals(2, count($this->crudPanel->columns())); |
547
|
|
|
$this->assertEquals(['column5', 'column6'], array_keys($this->crudPanel->columns())); |
548
|
|
|
|
549
|
|
|
$this->crudPanel->setColumns(['column7', [ |
550
|
|
|
'name' => 'column8', |
551
|
|
|
]]); |
552
|
|
|
$this->assertEquals(2, count($this->crudPanel->columns())); |
553
|
|
|
$this->assertEquals(['column7', 'column8'], array_keys($this->crudPanel->columns())); |
554
|
|
|
} |
555
|
|
|
|
556
|
|
|
public function testRemoveUnknownColumnName() |
557
|
|
|
{ |
558
|
|
|
$unknownColumnName = 'column4'; |
559
|
|
|
$this->crudPanel->addColumns(['column1', 'column2', 'column3']); |
560
|
|
|
|
561
|
|
|
$this->crudPanel->removeColumn($unknownColumnName); |
562
|
|
|
|
563
|
|
|
$this->assertEquals(3, count($this->crudPanel->columns())); |
564
|
|
|
$this->assertEquals(['column1', 'column2', 'column3'], array_keys($this->crudPanel->columns())); |
565
|
|
|
$this->assertNotContains($this->otherOneColumnArray, $this->crudPanel->columns()); |
566
|
|
|
} |
567
|
|
|
|
568
|
|
|
public function testRemoveColumnsByName() |
569
|
|
|
{ |
570
|
|
|
$this->crudPanel->addColumns(['column1', 'column2', 'column3']); |
571
|
|
|
|
572
|
|
|
$this->crudPanel->removeColumns($this->twoColumnsArray); |
573
|
|
|
|
574
|
|
|
$this->assertEquals(1, count($this->crudPanel->columns())); |
575
|
|
|
$this->assertEquals(['column3'], array_keys($this->crudPanel->columns())); |
576
|
|
|
$this->assertNotEquals($this->expectedThreeColumnsArray, $this->crudPanel->columns()); |
577
|
|
|
} |
578
|
|
|
|
579
|
|
|
public function testRemoveUnknownColumnsByName() |
580
|
|
|
{ |
581
|
|
|
$unknownColumnNames = ['column4', 'column5']; |
582
|
|
|
$this->crudPanel->addColumns(['column1', 'column2', 'column3']); |
583
|
|
|
|
584
|
|
|
$this->crudPanel->removeColumns($unknownColumnNames); |
585
|
|
|
|
586
|
|
|
$this->assertEquals(3, count($this->crudPanel->columns())); |
587
|
|
|
$this->assertEquals(['column1', 'column2', 'column3'], array_keys($this->crudPanel->columns())); |
588
|
|
|
$this->assertNotContains($this->otherOneColumnArray, $this->crudPanel->columns()); |
589
|
|
|
} |
590
|
|
|
|
591
|
|
|
public function testItThrowsAnErrorWhenAttemptingToChangeTheKeyInAColumnWithoutName() |
592
|
|
|
{ |
593
|
|
|
$this->expectException(\Exception::class); |
594
|
|
|
$this->crudPanel->addColumn(['type' => 'text'])->key('new_key'); |
595
|
|
|
} |
596
|
|
|
|
597
|
|
|
public function itCanSetTheUploadAttributeOnColumn() |
598
|
|
|
{ |
599
|
|
|
$this->crudPanel->addColumn('column1')->upload(); |
600
|
|
|
|
601
|
|
|
$this->assertEquals(true, $this->crudPanel->columns()['column1']['upload']); |
602
|
|
|
} |
603
|
|
|
|
604
|
|
|
public function testOrderColumns() |
605
|
|
|
{ |
606
|
|
|
$this->crudPanel->addColumns($this->threeColumnsArray); |
607
|
|
|
|
608
|
|
|
$this->crudPanel->orderColumns(['column2', 'column1', 'column3']); |
609
|
|
|
|
610
|
|
|
$this->assertEquals(['column2', 'column1', 'column3'], array_keys($this->crudPanel->columns())); |
611
|
|
|
} |
612
|
|
|
|
613
|
|
|
public function testOrderColumnsIncompleteList() |
614
|
|
|
{ |
615
|
|
|
$this->crudPanel->addColumns($this->threeColumnsArray); |
616
|
|
|
|
617
|
|
|
$this->crudPanel->orderColumns(['column2', 'column3']); |
618
|
|
|
|
619
|
|
|
$this->assertEquals(['column2', 'column3', 'column1'], array_keys($this->crudPanel->columns())); |
620
|
|
|
} |
621
|
|
|
|
622
|
|
|
public function testOrderColumnsEmptyList() |
623
|
|
|
{ |
624
|
|
|
$this->crudPanel->addColumns($this->threeColumnsArray); |
625
|
|
|
|
626
|
|
|
$this->crudPanel->orderColumns([]); |
627
|
|
|
|
628
|
|
|
$this->assertEquals($this->expectedThreeColumnsArray, $this->crudPanel->columns()); |
629
|
|
|
} |
630
|
|
|
|
631
|
|
|
public function testOrderColumnsUnknownList() |
632
|
|
|
{ |
633
|
|
|
$this->crudPanel->addColumns($this->threeColumnsArray); |
634
|
|
|
|
635
|
|
|
$this->crudPanel->orderColumns(['column4', 'column5', 'column6']); |
636
|
|
|
|
637
|
|
|
$this->assertEquals($this->expectedThreeColumnsArray, $this->crudPanel->columns()); |
638
|
|
|
} |
639
|
|
|
|
640
|
|
|
public function testOrderColumnsMixedList() |
641
|
|
|
{ |
642
|
|
|
$this->crudPanel->addColumns($this->threeColumnsArray); |
643
|
|
|
|
644
|
|
|
$this->crudPanel->orderColumns(['column2', 'column5', 'column6']); |
645
|
|
|
|
646
|
|
|
$this->assertEquals(['column2', 'column1', 'column3'], array_keys($this->crudPanel->columns())); |
647
|
|
|
} |
648
|
|
|
|
649
|
|
|
public function testItDoesNotAttemptToGetEntityWhenColumnNameIsArray() |
650
|
|
|
{ |
651
|
|
|
$this->crudPanel->addColumn(['name' => ['test1', 'test2'], 'label' => 'Column1', 'type' => 'text', 'key' => 'column1']); |
652
|
|
|
$this->assertArrayNotHasKey('entity', $this->crudPanel->firstColumnWhere('key', 'column1')); |
|
|
|
|
653
|
|
|
} |
654
|
|
|
|
655
|
|
|
public function testItCanInferTheEntityFromColumnNameUsingEntity_idConvention() |
656
|
|
|
{ |
657
|
|
|
$this->crudPanel->addColumn('article_id'); |
658
|
|
|
|
659
|
|
|
$this->assertEquals('article', $this->crudPanel->firstColumnWhere('name', 'article_id')['entity']); |
660
|
|
|
} |
661
|
|
|
|
662
|
|
|
public function testItAlwaysHasDatabaseColumnWhenDriverIsNotSql() |
663
|
|
|
{ |
664
|
|
|
$this->crudPanel = new \Backpack\CRUD\Tests\config\CrudPanel\NoSqlDriverCrudPanel(); |
665
|
|
|
$this->crudPanel->setModel(User::class); |
666
|
|
|
|
667
|
|
|
$this->assertTrue($this->invokeMethod($this->crudPanel, 'hasDatabaseColumn', ['test', 'test'])); |
668
|
|
|
} |
669
|
|
|
|
670
|
|
|
public function testItCanGetTheColumnTypeFromModelCasts() |
671
|
|
|
{ |
672
|
|
|
$this->crudPanel->addColumn('arrayCast'); |
673
|
|
|
$this->crudPanel->addColumn('jsonCast'); |
674
|
|
|
$this->crudPanel->addColumn('dateCast'); |
675
|
|
|
$this->crudPanel->addColumn('booleanCast'); |
676
|
|
|
$this->crudPanel->addColumn('datetimeCast'); |
677
|
|
|
$this->crudPanel->addColumn('numberCast'); |
678
|
|
|
|
679
|
|
|
$this->assertEquals('array', $this->crudPanel->firstColumnWhere('name', 'arrayCast')['type']); |
680
|
|
|
$this->assertEquals('json', $this->crudPanel->firstColumnWhere('name', 'jsonCast')['type']); |
681
|
|
|
$this->assertEquals('date', $this->crudPanel->firstColumnWhere('name', 'dateCast')['type']); |
682
|
|
|
$this->assertEquals('check', $this->crudPanel->firstColumnWhere('name', 'booleanCast')['type']); |
683
|
|
|
$this->assertEquals('datetime', $this->crudPanel->firstColumnWhere('name', 'datetimeCast')['type']); |
684
|
|
|
$this->assertEquals('number', $this->crudPanel->firstColumnWhere('name', 'numberCast')['type']); |
685
|
|
|
} |
686
|
|
|
|
687
|
|
|
public function testItCanGetTheColumnTypeFromModelDates() |
688
|
|
|
{ |
689
|
|
|
$this->crudPanel->addColumn('created_at'); |
690
|
|
|
|
691
|
|
|
$this->assertEquals('datetime', $this->crudPanel->firstColumnWhere('name', 'created_at')['type']); |
692
|
|
|
} |
693
|
|
|
|
694
|
|
|
public function testMakeFirstColumnReturnFalseWhenNoColumnsExist() |
695
|
|
|
{ |
696
|
|
|
$this->assertEmpty($this->crudPanel->columns()); |
697
|
|
|
$column = $this->crudPanel->makeFirstColumn(); |
698
|
|
|
$this->assertFalse($column); |
699
|
|
|
} |
700
|
|
|
|
701
|
|
|
public function testItSetsTextColumnTypeForTranslatableColumns() |
702
|
|
|
{ |
703
|
|
|
$this->crudPanel->setModel(\Backpack\CRUD\Tests\config\Models\TestModelWithTranslations::class); |
704
|
|
|
$this->crudPanel->addColumn('translatableColumn'); |
705
|
|
|
|
706
|
|
|
$this->assertEquals('text', $this->crudPanel->firstColumnWhere('name', 'translatableColumn')['type']); |
707
|
|
|
} |
708
|
|
|
|
709
|
|
|
public function testItCanAddADefaultTypeToTheColumn() |
710
|
|
|
{ |
711
|
|
|
$column = $this->crudPanel->addDefaultTypeToColumn(['name' => 'name']); |
712
|
|
|
|
713
|
|
|
$this->assertEquals('text', $column['type']); |
714
|
|
|
} |
715
|
|
|
|
716
|
|
|
public function testItReturnFalseWhenTryingToAddTypeToAColumnWithoutName() |
717
|
|
|
{ |
718
|
|
|
$column = $this->crudPanel->addDefaultTypeToColumn(['attribute' => 'name']); |
719
|
|
|
|
720
|
|
|
$this->assertFalse($column); |
721
|
|
|
} |
722
|
|
|
|
723
|
|
|
public function testItCanChangeTheColumnKey() |
724
|
|
|
{ |
725
|
|
|
$this->crudPanel->column('test'); |
726
|
|
|
|
727
|
|
|
$this->assertEquals('test', $this->crudPanel->columns()['test']['key']); |
728
|
|
|
|
729
|
|
|
$this->crudPanel->column('test')->key('new_key'); |
730
|
|
|
|
731
|
|
|
$this->assertEquals('new_key', $this->crudPanel->columns()['new_key']['key']); |
732
|
|
|
} |
733
|
|
|
|
734
|
|
|
public function testItCanAddAFluentColumn() |
735
|
|
|
{ |
736
|
|
|
$this->crudPanel->setModel(User::class); |
737
|
|
|
|
738
|
|
|
$this->crudPanel->column('my_column')->label('my_column'); |
739
|
|
|
|
740
|
|
|
$this->assertCount(1, $this->crudPanel->columns()); |
741
|
|
|
|
742
|
|
|
$this->assertEquals([ |
743
|
|
|
'name' => 'my_column', |
744
|
|
|
'type' => 'text', |
745
|
|
|
'label' => 'my_column', |
746
|
|
|
'key' => 'my_column', |
747
|
|
|
'priority' => 0, |
748
|
|
|
'tableColumn' => false, |
749
|
|
|
'orderable' => false, |
750
|
|
|
'searchLogic' => false, |
751
|
|
|
], $this->crudPanel->columns()['my_column']); |
752
|
|
|
} |
753
|
|
|
|
754
|
|
|
public function testItCanMakeAColumnFirstFluently() |
755
|
|
|
{ |
756
|
|
|
$this->crudPanel->column('test1'); |
757
|
|
|
$this->crudPanel->column('test2')->makeFirst(); |
758
|
|
|
$crudColumns = $this->crudPanel->columns(); |
759
|
|
|
$firstColumn = reset($crudColumns); |
760
|
|
|
$this->assertEquals($firstColumn['name'], 'test2'); |
761
|
|
|
} |
762
|
|
|
|
763
|
|
|
public function testItCanMakeAColumnLastFluently() |
764
|
|
|
{ |
765
|
|
|
$this->crudPanel->column('test1'); |
766
|
|
|
$this->crudPanel->column('test2'); |
767
|
|
|
$this->crudPanel->column('test1')->makeLast(); |
768
|
|
|
$crudColumns = $this->crudPanel->columns(); |
769
|
|
|
$firstColumn = reset($crudColumns); |
770
|
|
|
$this->assertEquals($firstColumn['name'], 'test2'); |
771
|
|
|
} |
772
|
|
|
|
773
|
|
|
public function testItCanPlaceColumnsFluently() |
774
|
|
|
{ |
775
|
|
|
$this->crudPanel->column('test1'); |
776
|
|
|
$this->crudPanel->column('test2'); |
777
|
|
|
$this->crudPanel->column('test3')->after('test1'); |
778
|
|
|
|
779
|
|
|
$crudColumnsNames = array_column($this->crudPanel->columns(), 'name'); |
780
|
|
|
$this->assertEquals($crudColumnsNames, ['test1', 'test3', 'test2']); |
781
|
|
|
|
782
|
|
|
$this->crudPanel->column('test4')->before('test1'); |
783
|
|
|
$crudColumnsNames = array_column($this->crudPanel->columns(), 'name'); |
784
|
|
|
$this->assertEquals($crudColumnsNames, ['test4', 'test1', 'test3', 'test2']); |
785
|
|
|
|
786
|
|
|
$this->crudPanel->column('test5')->afterColumn('test1'); |
787
|
|
|
$crudColumnsNames = array_column($this->crudPanel->columns(), 'name'); |
788
|
|
|
$this->assertEquals($crudColumnsNames, ['test4', 'test1', 'test5', 'test3', 'test2']); |
789
|
|
|
} |
790
|
|
|
|
791
|
|
|
public function testItCanRemoveColumnAttributesFluently() |
792
|
|
|
{ |
793
|
|
|
$this->crudPanel->column('test1')->type('test'); |
794
|
|
|
$this->assertEquals($this->crudPanel->columns()['test1']['type'], 'test'); |
795
|
|
|
$this->crudPanel->column('test1')->forget('type'); |
796
|
|
|
$this->assertNull($this->crudPanel->columns()['test1']['type'] ?? null); |
797
|
|
|
} |
798
|
|
|
|
799
|
|
|
public function testItCanRemoveColumnFluently() |
800
|
|
|
{ |
801
|
|
|
$this->crudPanel->column('test1')->type('test'); |
802
|
|
|
$this->assertCount(1, $this->crudPanel->columns()); |
803
|
|
|
$this->crudPanel->column('test1')->remove(); |
804
|
|
|
$this->assertCount(0, $this->crudPanel->columns()); |
805
|
|
|
} |
806
|
|
|
|
807
|
|
|
public function testItCanAddAColumnToCrudFromClass() |
808
|
|
|
{ |
809
|
|
|
CrudColumn::name('test'); |
810
|
|
|
$this->assertCount(1, $this->crudPanel->columns()); |
811
|
|
|
} |
812
|
|
|
|
813
|
|
|
public function testItCanAddAFluentColumnUsingArray() |
814
|
|
|
{ |
815
|
|
|
$this->crudPanel->column($this->oneColumnArray); |
816
|
|
|
$this->assertCount(1, $this->crudPanel->columns()); |
817
|
|
|
} |
818
|
|
|
|
819
|
|
|
public function testItCanAddAFluentColumnUsingArrayWithoutName() |
820
|
|
|
{ |
821
|
|
|
$this->crudPanel->column(['type' => 'text']); |
822
|
|
|
$this->assertCount(1, $this->crudPanel->columns()); |
823
|
|
|
} |
824
|
|
|
|
825
|
|
|
public function testColumnLinkToThrowsExceptionWhenNotAllRequiredParametersAreFilled() |
826
|
|
|
{ |
827
|
|
|
$this->expectException(\Exception::class); |
828
|
|
|
$this->expectExceptionMessage('Route [article.show.detail] expects parameters [id, detail]. Insufficient parameters provided in column: [articles].'); |
829
|
|
|
$this->crudPanel->column('articles')->entity('articles')->linkTo('article.show.detail', ['test' => 'testing']); |
|
|
|
|
830
|
|
|
} |
831
|
|
|
|
832
|
|
|
public function testItThrowsExceptionIfRouteNotFound() |
833
|
|
|
{ |
834
|
|
|
$this->expectException(\Exception::class); |
835
|
|
|
$this->expectExceptionMessage('Route [users.route.doesnt.exist] not found while building the link for column [id].'); |
836
|
|
|
|
837
|
|
|
CrudColumn::name('id')->linkTo('users.route.doesnt.exist')->toArray(); |
|
|
|
|
838
|
|
|
} |
839
|
|
|
|
840
|
|
|
public function testColumnLinkToWithRouteNameOnly() |
841
|
|
|
{ |
842
|
|
|
$this->crudPanel->column('articles')->entity('articles')->linkTo('articles.show'); |
843
|
|
|
$columnArray = $this->crudPanel->columns()['articles']; |
844
|
|
|
$reflection = new \ReflectionFunction($columnArray['wrapper']['href']); |
845
|
|
|
$arguments = $reflection->getClosureUsedVariables(); |
|
|
|
|
846
|
|
|
$this->crudPanel->entry = $this->makeAnArticleModel(); |
847
|
|
|
$url = $columnArray['wrapper']['href']($this->crudPanel, $columnArray, $this->crudPanel->entry, 1); |
848
|
|
|
$this->assertEquals('articles.show', $arguments['route']); |
849
|
|
|
$this->assertCount(1, $arguments['parameters']); |
850
|
|
|
$this->assertEquals('http://localhost/admin/articles/1/show', $url); |
851
|
|
|
} |
852
|
|
|
|
853
|
|
|
public function testColumnLinkToWithRouteNameAndAdditionalParameters() |
854
|
|
|
{ |
855
|
|
|
$this->crudPanel->column('articles')->entity('articles')->linkTo('articles.show', ['test' => 'testing', 'test2' => 'testing2']); |
856
|
|
|
$columnArray = $this->crudPanel->columns()['articles']; |
857
|
|
|
$reflection = new \ReflectionFunction($columnArray['wrapper']['href']); |
858
|
|
|
$arguments = $reflection->getClosureUsedVariables(); |
859
|
|
|
$this->assertEquals('articles.show', $arguments['route']); |
860
|
|
|
$this->assertCount(3, $arguments['parameters']); |
861
|
|
|
$this->crudPanel->entry = $this->makeAnArticleModel(); |
862
|
|
|
$url = $columnArray['wrapper']['href']($this->crudPanel, $columnArray, $this->crudPanel->entry, 1); |
863
|
|
|
$this->assertEquals('http://localhost/admin/articles/1/show?test=testing&test2=testing2', $url); |
864
|
|
|
} |
865
|
|
|
|
866
|
|
|
public function testColumnLinkToWithCustomParameters() |
867
|
|
|
{ |
868
|
|
|
$this->crudPanel->column('articles')->entity('articles')->linkTo('article.show.detail', ['detail' => 'testing', 'otherParam' => 'test']); |
869
|
|
|
$columnArray = $this->crudPanel->columns()['articles']; |
870
|
|
|
$this->crudPanel->entry = $this->makeAnArticleModel(); |
871
|
|
|
$url = $columnArray['wrapper']['href']($this->crudPanel, $columnArray, $this->crudPanel->entry, 1); |
872
|
|
|
$this->assertEquals('http://localhost/admin/articles/1/show/testing?otherParam=test', $url); |
873
|
|
|
} |
874
|
|
|
|
875
|
|
|
public function testColumnLinkToWithCustomClosureParameters() |
876
|
|
|
{ |
877
|
|
|
$this->crudPanel->column('articles') |
878
|
|
|
->entity('articles') |
879
|
|
|
->linkTo('article.show.detail', ['detail' => fn ($entry, $related_key) => $related_key, 'otherParam' => fn ($entry) => $entry->content]); |
880
|
|
|
$columnArray = $this->crudPanel->columns()['articles']; |
881
|
|
|
$this->crudPanel->entry = $this->makeAnArticleModel(); |
882
|
|
|
$url = $columnArray['wrapper']['href']($this->crudPanel, $columnArray, $this->crudPanel->entry, 1); |
883
|
|
|
$this->assertEquals('http://localhost/admin/articles/1/show/1?otherParam=Some%20Content', $url); |
884
|
|
|
} |
885
|
|
|
|
886
|
|
|
public function testColumnLinkToDontAutoInferParametersIfAllProvided() |
887
|
|
|
{ |
888
|
|
|
$this->crudPanel->column('articles') |
889
|
|
|
->entity('articles') |
890
|
|
|
->linkTo('article.show.detail', ['id' => 123, 'detail' => fn ($entry, $related_key) => $related_key, 'otherParam' => fn ($entry) => $entry->content]); |
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/123/show/1?otherParam=Some%20Content', $url); |
895
|
|
|
} |
896
|
|
|
|
897
|
|
|
public function testColumnLinkToAutoInferAnySingleParameter() |
898
|
|
|
{ |
899
|
|
|
$this->crudPanel->column('articles') |
900
|
|
|
->entity('articles') |
901
|
|
|
->linkTo('article.show.detail', ['id' => 123, 'otherParam' => fn ($entry) => $entry->content]); |
902
|
|
|
$columnArray = $this->crudPanel->columns()['articles']; |
903
|
|
|
$this->crudPanel->entry = $this->makeAnArticleModel(); |
904
|
|
|
$url = $columnArray['wrapper']['href']($this->crudPanel, $columnArray, $this->crudPanel->entry, 1); |
905
|
|
|
$this->assertEquals('http://localhost/admin/articles/123/show/1?otherParam=Some%20Content', $url); |
906
|
|
|
} |
907
|
|
|
|
908
|
|
|
public function testColumnLinkToWithClosure() |
909
|
|
|
{ |
910
|
|
|
$this->crudPanel->column('articles') |
911
|
|
|
->entity('articles') |
912
|
|
|
->linkTo(fn ($entry) => route('articles.show', $entry->content)); |
|
|
|
|
913
|
|
|
$columnArray = $this->crudPanel->columns()['articles']; |
914
|
|
|
$this->crudPanel->entry = $this->makeAnArticleModel(); |
915
|
|
|
$url = $columnArray['wrapper']['href']($this->crudPanel, $columnArray, $this->crudPanel->entry, 1); |
916
|
|
|
$this->assertEquals('http://localhost/admin/articles/Some%20Content/show', $url); |
917
|
|
|
} |
918
|
|
|
|
919
|
|
|
public function testColumnArrayDefinitionLinkToRouteAsClosure() |
920
|
|
|
{ |
921
|
|
|
$this->crudPanel->setModel(User::class); |
922
|
|
|
$this->crudPanel->column([ |
923
|
|
|
'name' => 'articles', |
924
|
|
|
'entity' => 'articles', |
925
|
|
|
'linkTo' => fn ($entry) => route('articles.show', ['id' => $entry->id, 'test' => 'testing']), |
926
|
|
|
]); |
927
|
|
|
$columnArray = $this->crudPanel->columns()['articles']; |
928
|
|
|
$this->crudPanel->entry = $this->makeAnArticleModel(); |
929
|
|
|
$url = $columnArray['wrapper']['href']($this->crudPanel, $columnArray, $this->crudPanel->entry, 1); |
930
|
|
|
$this->assertEquals('http://localhost/admin/articles/1/show?test=testing', $url); |
931
|
|
|
} |
932
|
|
|
|
933
|
|
|
public function testColumnArrayDefinitionLinkToRouteNameOnly() |
934
|
|
|
{ |
935
|
|
|
$this->crudPanel->setModel(User::class); |
936
|
|
|
$this->crudPanel->column([ |
937
|
|
|
'name' => 'articles', |
938
|
|
|
'entity' => 'articles', |
939
|
|
|
'linkTo' => 'articles.show', |
940
|
|
|
]); |
941
|
|
|
$columnArray = $this->crudPanel->columns()['articles']; |
942
|
|
|
$this->crudPanel->entry = $this->makeAnArticleModel(); |
943
|
|
|
$url = $columnArray['wrapper']['href']($this->crudPanel, $columnArray, $this->crudPanel->entry, 1); |
944
|
|
|
$this->assertEquals('http://localhost/admin/articles/1/show', $url); |
945
|
|
|
} |
946
|
|
|
|
947
|
|
|
public function testColumnArrayDefinitionLinkToRouteNameAndAdditionalParameters() |
948
|
|
|
{ |
949
|
|
|
$this->crudPanel->setModel(User::class); |
950
|
|
|
$this->crudPanel->column([ |
951
|
|
|
'name' => 'articles', |
952
|
|
|
'entity' => 'articles', |
953
|
|
|
'linkTo' => [ |
954
|
|
|
'route' => 'articles.show', |
955
|
|
|
'parameters' => [ |
956
|
|
|
'test' => 'testing', |
957
|
|
|
'test2' => fn ($entry) => $entry->content, |
958
|
|
|
], |
959
|
|
|
], |
960
|
|
|
]); |
961
|
|
|
$columnArray = $this->crudPanel->columns()['articles']; |
962
|
|
|
$reflection = new \ReflectionFunction($columnArray['wrapper']['href']); |
963
|
|
|
$arguments = $reflection->getClosureUsedVariables(); |
964
|
|
|
$this->assertEquals('articles.show', $arguments['route']); |
965
|
|
|
$this->assertCount(3, $arguments['parameters']); |
966
|
|
|
$this->crudPanel->entry = $this->makeAnArticleModel(); |
967
|
|
|
$url = $columnArray['wrapper']['href']($this->crudPanel, $columnArray, $this->crudPanel->entry, 1); |
968
|
|
|
$this->assertEquals('http://localhost/admin/articles/1/show?test=testing&test2=Some%20Content', $url); |
969
|
|
|
} |
970
|
|
|
|
971
|
|
|
public function testItCanInferFieldAttributesFromADynamicRelation() |
972
|
|
|
{ |
973
|
|
|
User::resolveRelationUsing('dynamicRelation', function ($user) { |
974
|
|
|
return $user->belongsTo(\Backpack\CRUD\Tests\config\Models\Bang::class); |
975
|
|
|
}); |
976
|
|
|
|
977
|
|
|
$this->crudPanel->setModel(User::class); |
978
|
|
|
$this->crudPanel->addColumn('dynamicRelation'); |
979
|
|
|
|
980
|
|
|
$column = $this->crudPanel->columns()['dynamicRelation']; |
981
|
|
|
|
982
|
|
|
$this->assertEquals('dynamicRelation', $column['name']); |
983
|
|
|
$this->assertEquals('name', $column['attribute']); |
984
|
|
|
$this->assertEquals('relationship', $column['type']); |
985
|
|
|
$this->assertEquals('BelongsTo', $column['relation_type']); |
986
|
|
|
} |
987
|
|
|
} |
988
|
|
|
|