1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Backpack\CRUD\Tests\Unit\CrudPanel; |
4
|
|
|
|
5
|
|
|
use Backpack\CRUD\Tests\config\Models\Article; |
6
|
|
|
use Backpack\CRUD\Tests\config\Models\Role; |
7
|
|
|
use Backpack\CRUD\Tests\config\Models\User; |
8
|
|
|
use Illuminate\Database\Eloquent\ModelNotFoundException; |
9
|
|
|
use Illuminate\Support\Collection; |
10
|
|
|
use Illuminate\Support\Facades\DB; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* @covers Backpack\CRUD\app\Library\CrudPanel\Traits\Read |
14
|
|
|
* @covers Backpack\CRUD\app\Library\CrudPanel\CrudPanel |
15
|
|
|
*/ |
16
|
|
|
class CrudPanelReadTest extends \Backpack\CRUD\Tests\config\CrudPanel\BaseDBCrudPanel |
17
|
|
|
{ |
18
|
|
|
private $relationshipColumn = [ |
19
|
|
|
'name' => 'user_id', |
20
|
|
|
'type' => 'select', |
21
|
|
|
'entity' => 'user', |
22
|
|
|
'attribute' => 'name', |
23
|
|
|
]; |
24
|
|
|
|
25
|
|
|
private $relationshipMultipleColumn = [ |
|
|
|
|
26
|
|
|
'name' => 'roles', |
27
|
|
|
'type' => 'select', |
28
|
|
|
'entity' => 'roles', |
29
|
|
|
'attribute' => 'name', |
30
|
|
|
'model' => Role::class, |
31
|
|
|
]; |
32
|
|
|
|
33
|
|
|
private $nonRelationshipColumn = [ |
34
|
|
|
'name' => 'field1', |
35
|
|
|
'label' => 'Field1', |
36
|
|
|
]; |
37
|
|
|
|
38
|
|
|
private $articleFieldsArray = [ |
39
|
|
|
[ |
40
|
|
|
'name' => 'content', |
41
|
|
|
'label' => 'The Content', |
42
|
|
|
'type' => 'text', |
43
|
|
|
], |
44
|
|
|
[ |
45
|
|
|
'name' => 'metas', |
46
|
|
|
'label' => 'Metas', |
47
|
|
|
], |
48
|
|
|
[ |
49
|
|
|
'name' => 'tags', |
50
|
|
|
], |
51
|
|
|
[ |
52
|
|
|
'name' => 'extras', |
53
|
|
|
], |
54
|
|
|
]; |
55
|
|
|
|
56
|
|
|
private $expectedCreateFormArticleFieldsArray = [ |
57
|
|
|
'content' => [ |
58
|
|
|
'name' => 'content', |
59
|
|
|
'label' => 'The Content', |
60
|
|
|
'type' => 'text', |
61
|
|
|
'entity' => false, |
62
|
|
|
], |
63
|
|
|
'metas' => [ |
64
|
|
|
'name' => 'metas', |
65
|
|
|
'label' => 'Metas', |
66
|
|
|
'type' => 'text', |
67
|
|
|
'entity' => false, |
68
|
|
|
], |
69
|
|
|
'tags' => [ |
70
|
|
|
'name' => 'tags', |
71
|
|
|
'label' => 'Tags', |
72
|
|
|
'type' => 'text', |
73
|
|
|
'entity' => false, |
74
|
|
|
], |
75
|
|
|
'extras' => [ |
76
|
|
|
'name' => 'extras', |
77
|
|
|
'label' => 'Extras', |
78
|
|
|
'type' => 'text', |
79
|
|
|
'entity' => false, |
80
|
|
|
], |
81
|
|
|
]; |
82
|
|
|
|
83
|
|
|
private $expectedUpdateFormArticleFieldsArray = [ |
84
|
|
|
'content' => [ |
85
|
|
|
'name' => 'content', |
86
|
|
|
'label' => 'The Content', |
87
|
|
|
'type' => 'text', |
88
|
|
|
'value' => 'Some Content', |
89
|
|
|
'entity' => false, |
90
|
|
|
], |
91
|
|
|
'metas' => [ |
92
|
|
|
'name' => 'metas', |
93
|
|
|
'label' => 'Metas', |
94
|
|
|
'type' => 'text', |
95
|
|
|
'value' => '{"meta_title":"Meta Title Value","meta_description":"Meta Description Value"}', |
96
|
|
|
'entity' => false, |
97
|
|
|
], |
98
|
|
|
'tags' => [ |
99
|
|
|
'name' => 'tags', |
100
|
|
|
'label' => 'Tags', |
101
|
|
|
'type' => 'text', |
102
|
|
|
'value' => '{"tags":["tag1","tag2","tag3"]}', |
103
|
|
|
'entity' => false, |
104
|
|
|
], |
105
|
|
|
'extras' => [ |
106
|
|
|
'name' => 'extras', |
107
|
|
|
'label' => 'Extras', |
108
|
|
|
'type' => 'text', |
109
|
|
|
'value' => '{"extra_details":["detail1","detail2","detail3"]}', |
110
|
|
|
'entity' => false, |
111
|
|
|
], |
112
|
|
|
'id' => [ |
113
|
|
|
'name' => 'id', |
114
|
|
|
'type' => 'hidden', |
115
|
|
|
'value' => 1, |
116
|
|
|
], |
117
|
|
|
]; |
118
|
|
|
|
119
|
|
|
private $uploadField = [ |
120
|
|
|
'name' => 'image', |
121
|
|
|
'label' => 'Image', |
122
|
|
|
'type' => 'upload', |
123
|
|
|
'upload' => true, |
124
|
|
|
]; |
125
|
|
|
|
126
|
|
|
private $multipleUploadField = [ |
127
|
|
|
'name' => 'photos', |
128
|
|
|
'label' => 'Photos', |
129
|
|
|
'type' => 'upload_multiple', |
130
|
|
|
'upload' => true, |
131
|
|
|
]; |
132
|
|
|
|
133
|
|
|
private $defaultPaginator = [[10, 20, 30], ['t1', 't2', 't3']]; |
134
|
|
|
|
135
|
|
|
public function testGetEntry() |
136
|
|
|
{ |
137
|
|
|
$this->crudPanel->setModel(User::class); |
138
|
|
|
$user = User::find(1); |
139
|
|
|
|
140
|
|
|
$entry = $this->crudPanel->getEntry($user->id); |
|
|
|
|
141
|
|
|
|
142
|
|
|
$this->assertEquals($user, $entry); |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
public function testGetEntryWithFakes() |
146
|
|
|
{ |
147
|
|
|
$this->markTestIncomplete('Not correctly implemented'); |
148
|
|
|
|
149
|
|
|
$this->crudPanel->setModel(Article::class); |
150
|
|
|
$article = Article::find(1); |
151
|
|
|
|
152
|
|
|
$entry = $this->crudPanel->getEntry($article->id); |
153
|
|
|
|
154
|
|
|
// TODO: the withFakes call is needed for this to work. the state of the model should not be changed by the |
155
|
|
|
// getEntry method. the transformation of the fakes columns should be kept in a different crud panel |
156
|
|
|
// attribute or, at most, the getEntry method should be renamed. |
157
|
|
|
$article->withFakes(); |
158
|
|
|
|
159
|
|
|
$this->assertEquals($article, $entry); |
160
|
|
|
} |
161
|
|
|
|
162
|
|
|
public function testGetEntryExists() |
163
|
|
|
{ |
164
|
|
|
$this->crudPanel->setModel(User::class); |
165
|
|
|
$userEntry = $this->crudPanel->getEntry(1); |
166
|
|
|
|
167
|
|
|
$this->assertInstanceOf(User::class, $userEntry); |
168
|
|
|
|
169
|
|
|
$this->crudPanel->setModel(Article::class); |
170
|
|
|
$articleEntry = $this->crudPanel->getEntry(1); |
171
|
|
|
|
172
|
|
|
$this->assertInstanceOf(Article::class, $articleEntry); |
173
|
|
|
} |
174
|
|
|
|
175
|
|
|
public function testGetEntryUnknownId() |
176
|
|
|
{ |
177
|
|
|
$this->expectException(ModelNotFoundException::class); |
178
|
|
|
|
179
|
|
|
$this->crudPanel->setModel(User::class); |
180
|
|
|
|
181
|
|
|
$unknownId = DB::getPdo()->lastInsertId() + 2; |
182
|
|
|
$this->crudPanel->getEntry($unknownId); |
183
|
|
|
} |
184
|
|
|
|
185
|
|
|
public function testAutoEagerLoadRelationshipColumns() |
186
|
|
|
{ |
187
|
|
|
$this->crudPanel->setModel(Article::class); |
188
|
|
|
$this->crudPanel->setOperation('list'); |
189
|
|
|
$this->crudPanel->addColumn($this->relationshipColumn); |
190
|
|
|
|
191
|
|
|
$this->crudPanel->autoEagerLoadRelationshipColumns(); |
192
|
|
|
|
193
|
|
|
$this->assertArrayHasKey('user', $this->crudPanel->query->getEagerLoads()); |
194
|
|
|
} |
195
|
|
|
|
196
|
|
|
public function testAutoEagerLoadRelationshipColumnsNoRelationships() |
197
|
|
|
{ |
198
|
|
|
$this->crudPanel->setModel(Article::class); |
199
|
|
|
$this->crudPanel->addColumn($this->nonRelationshipColumn); |
200
|
|
|
|
201
|
|
|
$this->crudPanel->autoEagerLoadRelationshipColumns(); |
202
|
|
|
|
203
|
|
|
$this->assertEmpty($this->crudPanel->query->getEagerLoads()); |
204
|
|
|
} |
205
|
|
|
|
206
|
|
|
public function testGetEntries() |
207
|
|
|
{ |
208
|
|
|
$this->crudPanel->setModel(User::class); |
209
|
|
|
|
210
|
|
|
$entries = $this->crudPanel->getEntries(); |
211
|
|
|
|
212
|
|
|
$this->assertInstanceOf(Collection::class, $entries); |
213
|
|
|
$this->assertEquals(2, $entries->count()); |
214
|
|
|
$this->assertEquals(User::find(1), $entries->first()); |
215
|
|
|
} |
216
|
|
|
|
217
|
|
|
public function testGetEntriesWithFakes() |
218
|
|
|
{ |
219
|
|
|
$this->markTestIncomplete('Not correctly implemented'); |
220
|
|
|
|
221
|
|
|
$this->crudPanel->setModel(Article::class); |
222
|
|
|
|
223
|
|
|
$entries = $this->crudPanel->getEntries(); |
224
|
|
|
|
225
|
|
|
// TODO: the getEntries method automatically adds fakes. the state of the models should not be changed by the |
226
|
|
|
// getEntries method. at most, the getEntries method should be renamed. |
227
|
|
|
$this->assertInstanceOf(Collection::class, $entries); |
228
|
|
|
$this->assertEquals(1, $entries->count()); |
229
|
|
|
$this->assertEquals(Article::find(1), $entries->first()); |
230
|
|
|
} |
231
|
|
|
|
232
|
|
|
public function testGetFieldsCreateForm() |
233
|
|
|
{ |
234
|
|
|
$this->crudPanel->addFields($this->articleFieldsArray); |
235
|
|
|
|
236
|
|
|
// TODO: update method documentation. the $form parameter does not default to 'both'. |
237
|
|
|
$fields = $this->crudPanel->getFields('create'); |
|
|
|
|
238
|
|
|
|
239
|
|
|
$this->assertEquals($this->expectedCreateFormArticleFieldsArray, $fields); |
240
|
|
|
} |
241
|
|
|
|
242
|
|
|
public function testGetFieldsUpdateForm() |
243
|
|
|
{ |
244
|
|
|
$this->crudPanel->setModel(Article::class); |
245
|
|
|
|
246
|
|
|
$this->crudPanel->setOperation('update'); |
247
|
|
|
$this->crudPanel->addFields($this->articleFieldsArray); |
248
|
|
|
|
249
|
|
|
// TODO: update method documentation. the $form parameter does not default to 'both'. |
250
|
|
|
$fields = $this->crudPanel->getUpdateFields(1); |
251
|
|
|
|
252
|
|
|
$this->assertEquals($this->expectedUpdateFormArticleFieldsArray, $fields); |
253
|
|
|
} |
254
|
|
|
|
255
|
|
|
public function testHasUploadFieldsCreateForm() |
256
|
|
|
{ |
257
|
|
|
$this->crudPanel->addField($this->uploadField, 'create'); |
|
|
|
|
258
|
|
|
|
259
|
|
|
// TODO: update method documentation. the $form parameter does not default to 'both'. |
260
|
|
|
$hasUploadFields = $this->crudPanel->hasUploadFields('create'); |
|
|
|
|
261
|
|
|
|
262
|
|
|
$this->assertTrue($hasUploadFields); |
263
|
|
|
} |
264
|
|
|
|
265
|
|
|
public function testHasMultipleUploadFieldsCreateForm() |
266
|
|
|
{ |
267
|
|
|
$this->crudPanel->addField($this->multipleUploadField, 'create'); |
|
|
|
|
268
|
|
|
|
269
|
|
|
// TODO: update method documentation. the $form parameter does not default to 'both'. |
270
|
|
|
$hasMultipleUploadFields = $this->crudPanel->hasUploadFields('create'); |
|
|
|
|
271
|
|
|
|
272
|
|
|
$this->assertTrue($hasMultipleUploadFields); |
273
|
|
|
} |
274
|
|
|
|
275
|
|
|
public function testHasUploadFieldsUpdateForm() |
276
|
|
|
{ |
277
|
|
|
$this->crudPanel->setModel(Article::class); |
278
|
|
|
$this->crudPanel->addField($this->uploadField, 'update'); |
|
|
|
|
279
|
|
|
|
280
|
|
|
// TODO: update method documentation. the $form parameter does not default to 'both'. |
281
|
|
|
$hasUploadFields = $this->crudPanel->hasUploadFields('update', 1); |
|
|
|
|
282
|
|
|
|
283
|
|
|
$this->assertTrue($hasUploadFields); |
284
|
|
|
} |
285
|
|
|
|
286
|
|
|
public function testEnableDetailsRow() |
287
|
|
|
{ |
288
|
|
|
if (! backpack_pro()) { |
289
|
|
|
$this->expectException(\Backpack\CRUD\app\Exceptions\BackpackProRequiredException::class); |
290
|
|
|
} |
291
|
|
|
|
292
|
|
|
$this->crudPanel->setOperation('create'); |
293
|
|
|
$this->crudPanel->enableDetailsRow(); |
294
|
|
|
|
295
|
|
|
$this->assertTrue($this->crudPanel->getOperationSetting('detailsRow')); |
296
|
|
|
} |
297
|
|
|
|
298
|
|
|
public function testDisableDetailsRow() |
299
|
|
|
{ |
300
|
|
|
$this->crudPanel->setOperation('list'); |
301
|
|
|
$this->crudPanel->disableDetailsRow(); |
302
|
|
|
|
303
|
|
|
$this->assertFalse($this->crudPanel->get('list.detailsRow')); |
304
|
|
|
} |
305
|
|
|
|
306
|
|
|
public function testSetDefaultPageLength() |
307
|
|
|
{ |
308
|
|
|
$pageLength = 20; |
309
|
|
|
$this->crudPanel->setDefaultPageLength($pageLength); |
310
|
|
|
|
311
|
|
|
$this->assertEquals($pageLength, $this->crudPanel->getDefaultPageLength()); |
312
|
|
|
} |
313
|
|
|
|
314
|
|
|
public function testGetDefaultPageLength() |
315
|
|
|
{ |
316
|
|
|
$defaultPageLength = $this->crudPanel->getDefaultPageLength(); |
317
|
|
|
|
318
|
|
|
$this->assertEquals(25, $defaultPageLength); |
319
|
|
|
} |
320
|
|
|
|
321
|
|
|
public function testEnableExportButtons() |
322
|
|
|
{ |
323
|
|
|
if (! backpack_pro()) { |
324
|
|
|
$this->expectException(\Backpack\CRUD\app\Exceptions\BackpackProRequiredException::class); |
325
|
|
|
} |
326
|
|
|
|
327
|
|
|
$this->crudPanel->enableExportButtons(); |
328
|
|
|
$this->assertTrue($this->crudPanel->exportButtons()); |
329
|
|
|
} |
330
|
|
|
|
331
|
|
|
public function testGetExportButtons() |
332
|
|
|
{ |
333
|
|
|
$exportButtons = $this->crudPanel->exportButtons(); |
334
|
|
|
|
335
|
|
|
$this->assertFalse($exportButtons); |
336
|
|
|
} |
337
|
|
|
|
338
|
|
|
public function testGetRelatedEntriesAttributesFromBelongsToMany() |
339
|
|
|
{ |
340
|
|
|
$this->crudPanel->setModel(User::class); |
341
|
|
|
$this->crudPanel->setOperation('list'); |
342
|
|
|
$user = $this->crudPanel->getModel()->where('id', 2)->first(); |
343
|
|
|
$entries = $this->crudPanel->getRelatedEntriesAttributes($user, 'roles', 'name'); |
344
|
|
|
$this->assertEquals([1 => 'admin', 2 => 'user'], $entries); |
345
|
|
|
} |
346
|
|
|
|
347
|
|
|
public function testGetRelatedEntriesAttributesFromBelongsToManyWithAccessor() |
348
|
|
|
{ |
349
|
|
|
$this->crudPanel->setModel(User::class); |
350
|
|
|
$this->crudPanel->setOperation('list'); |
351
|
|
|
$user = $this->crudPanel->getModel()->where('id', 2)->first(); |
352
|
|
|
$entries = $this->crudPanel->getRelatedEntriesAttributes($user, 'roles', 'role_name'); |
353
|
|
|
$this->assertEquals([1 => 'admin++', 2 => 'user++'], $entries); |
354
|
|
|
} |
355
|
|
|
|
356
|
|
|
public function testGetRelatedEntriesAttributesFromHasMany() |
357
|
|
|
{ |
358
|
|
|
$this->crudPanel->setModel(User::class); |
359
|
|
|
$this->crudPanel->setOperation('list'); |
360
|
|
|
$user = $this->crudPanel->getModel()->first(); |
361
|
|
|
$entries = $this->crudPanel->getRelatedEntriesAttributes($user, 'articles', 'content'); |
362
|
|
|
$this->assertCount(1, $entries); |
363
|
|
|
} |
364
|
|
|
|
365
|
|
|
public function testGetRelatedEntriesAttributesFromHasManyWithAccessor() |
366
|
|
|
{ |
367
|
|
|
$this->crudPanel->setModel(User::class); |
368
|
|
|
$this->crudPanel->setOperation('list'); |
369
|
|
|
$user = $this->crudPanel->getModel()->first(); |
370
|
|
|
$entries = $this->crudPanel->getRelatedEntriesAttributes($user, 'articles', 'content_composed'); |
371
|
|
|
$this->assertCount(1, $entries); |
372
|
|
|
} |
373
|
|
|
|
374
|
|
|
public function testGetRelatedEntriesAttributesFromBelongsTo() |
375
|
|
|
{ |
376
|
|
|
$this->crudPanel->setModel(Article::class); |
377
|
|
|
$this->crudPanel->setOperation('list'); |
378
|
|
|
$article = $this->crudPanel->getModel()->first(); |
379
|
|
|
$entries = $this->crudPanel->getRelatedEntriesAttributes($article, 'user', 'name'); |
380
|
|
|
$this->assertCount(1, $entries); |
381
|
|
|
} |
382
|
|
|
|
383
|
|
|
public function testGetRelatedEntriesAttributesFromBelongsToWithAccessor() |
384
|
|
|
{ |
385
|
|
|
$this->crudPanel->setModel(Article::class); |
386
|
|
|
$this->crudPanel->setOperation('list'); |
387
|
|
|
$article = $this->crudPanel->getModel()->first(); |
388
|
|
|
$entries = $this->crudPanel->getRelatedEntriesAttributes($article, 'user', 'name_composed'); |
389
|
|
|
$this->assertCount(1, $entries); |
390
|
|
|
} |
391
|
|
|
|
392
|
|
|
public function testGetRelatedEntriesAttributesFromHasOne() |
393
|
|
|
{ |
394
|
|
|
$this->crudPanel->setModel(User::class); |
395
|
|
|
$this->crudPanel->setOperation('list'); |
396
|
|
|
$user = $this->crudPanel->getModel()->first(); |
397
|
|
|
$entries = $this->crudPanel->getRelatedEntriesAttributes($user, 'accountDetails', 'nickname'); |
398
|
|
|
$this->assertCount(1, $entries); |
399
|
|
|
} |
400
|
|
|
|
401
|
|
|
public function testGetRelatedEntriesAttributesFromHasOneWithAccessor() |
402
|
|
|
{ |
403
|
|
|
$this->crudPanel->setModel(User::class); |
404
|
|
|
$this->crudPanel->setOperation('list'); |
405
|
|
|
$user = $this->crudPanel->getModel()->first(); |
406
|
|
|
$entries = $this->crudPanel->getRelatedEntriesAttributes($user, 'accountDetails', 'nickname_composed'); |
407
|
|
|
$this->assertCount(1, $entries); |
408
|
|
|
} |
409
|
|
|
|
410
|
|
|
/** |
411
|
|
|
* Tests define paginator length with single array [20, 30, 40]. |
412
|
|
|
*/ |
413
|
|
|
public function testCrudPanelChangePaginatorLengthSingleArrayNoLabels() |
414
|
|
|
{ |
415
|
|
|
$this->crudPanel->setModel(User::class); |
416
|
|
|
$this->crudPanel->setOperation('list'); |
417
|
|
|
$this->crudPanel->setPageLengthMenu([20, 30, 40]); |
418
|
|
|
$this->assertCount(2, $this->crudPanel->getOperationSetting('pageLengthMenu')); |
|
|
|
|
419
|
|
|
$this->assertTrue(in_array(40, $this->crudPanel->getOperationSetting('pageLengthMenu')[0])); |
420
|
|
|
$this->assertTrue(in_array(40, $this->crudPanel->getOperationSetting('pageLengthMenu')[1])); |
421
|
|
|
} |
422
|
|
|
|
423
|
|
|
/** |
424
|
|
|
* Tests define paginator length with single array [20 => 'v', 30 => 't', 40 => 'q']. |
425
|
|
|
*/ |
426
|
|
|
public function testCrudPanelChangePaginatorLengthSingleArrayWithLabels() |
427
|
|
|
{ |
428
|
|
|
$this->crudPanel->setModel(User::class); |
429
|
|
|
$this->crudPanel->setOperation('list'); |
430
|
|
|
$this->crudPanel->setPageLengthMenu([20 => 'v', 30 => 't', 40 => 'q']); |
431
|
|
|
$this->assertCount(2, $this->crudPanel->getOperationSetting('pageLengthMenu')); |
|
|
|
|
432
|
|
|
$this->assertTrue(in_array(40, $this->crudPanel->getOperationSetting('pageLengthMenu')[0])); |
433
|
|
|
$this->assertEquals($this->crudPanel->getOperationSetting('pageLengthMenu')[1], ['v', 't', 'q']); |
434
|
|
|
} |
435
|
|
|
|
436
|
|
|
/** |
437
|
|
|
* Tests define paginator length with and 'all' options as -1 as defined in previous versions of BP. |
438
|
|
|
*/ |
439
|
|
|
public function testCrudPanelPaginatorWithAllAsOption() |
440
|
|
|
{ |
441
|
|
|
$this->crudPanel->setModel(User::class); |
442
|
|
|
$this->crudPanel->setOperation('list'); |
443
|
|
|
$this->crudPanel->setPageLengthMenu([-1 => 'All']); |
444
|
|
|
$this->assertCount(2, $this->crudPanel->getOperationSetting('pageLengthMenu')); |
|
|
|
|
445
|
|
|
$this->assertTrue(in_array(-1, $this->crudPanel->getOperationSetting('pageLengthMenu')[0])); |
446
|
|
|
|
447
|
|
|
$this->crudPanel->setPageLengthMenu([-1, 1]); |
448
|
|
|
$this->assertCount(2, $this->crudPanel->getOperationSetting('pageLengthMenu')); |
449
|
|
|
$this->assertTrue(in_array(-1, $this->crudPanel->getOperationSetting('pageLengthMenu')[0])); |
450
|
|
|
|
451
|
|
|
$this->crudPanel->setPageLengthMenu(-1); |
452
|
|
|
$this->assertCount(2, $this->crudPanel->getOperationSetting('pageLengthMenu')); |
453
|
|
|
$this->assertTrue(in_array(-1, $this->crudPanel->getOperationSetting('pageLengthMenu')[0])); |
454
|
|
|
} |
455
|
|
|
|
456
|
|
|
/** |
457
|
|
|
* Tests if paginator aborts when 0 is provided as key. |
458
|
|
|
*/ |
459
|
|
|
public function testCrudPanelPaginatorWithZeroAsOption() |
460
|
|
|
{ |
461
|
|
|
$this->crudPanel->setModel(User::class); |
462
|
|
|
$this->crudPanel->setOperation('list'); |
463
|
|
|
|
464
|
|
|
try { |
465
|
|
|
$this->crudPanel->setPageLengthMenu([0 => 'v', 30 => 't', 40 => 'q']); |
466
|
|
|
} catch (\Throwable $a) { |
|
|
|
|
467
|
|
|
} |
468
|
|
|
|
469
|
|
|
$this->assertEquals(500, $a->getStatusCode()); |
|
|
|
|
470
|
|
|
|
471
|
|
|
try { |
472
|
|
|
$this->crudPanel->setPageLengthMenu([0, 1]); |
473
|
|
|
} catch (\Throwable $b) { |
|
|
|
|
474
|
|
|
} |
475
|
|
|
|
476
|
|
|
$this->assertEquals(500, $b->getStatusCode()); |
|
|
|
|
477
|
|
|
|
478
|
|
|
try { |
479
|
|
|
$this->crudPanel->setPageLengthMenu(0); |
480
|
|
|
} catch (\Throwable $c) { |
|
|
|
|
481
|
|
|
} |
482
|
|
|
|
483
|
|
|
$this->assertEquals(500, $c->getStatusCode()); |
|
|
|
|
484
|
|
|
|
485
|
|
|
try { |
486
|
|
|
$this->crudPanel->setPageLengthMenu([[0, 1]]); |
487
|
|
|
} catch (\Throwable $d) { |
|
|
|
|
488
|
|
|
} |
489
|
|
|
|
490
|
|
|
$this->assertEquals(500, $d->getStatusCode()); |
|
|
|
|
491
|
|
|
} |
492
|
|
|
|
493
|
|
|
/** |
494
|
|
|
* Tests define paginator length with multi array [[20, 30, 40],['v', 't', 'q']]. |
495
|
|
|
*/ |
496
|
|
|
public function testCrudPanelChangePaginatorLengthMultiArrayWithLabels() |
497
|
|
|
{ |
498
|
|
|
$this->crudPanel->setModel(User::class); |
499
|
|
|
$this->crudPanel->setOperation('list'); |
500
|
|
|
$this->crudPanel->setPageLengthMenu([[20, 30, 40], ['v', 't', 'q']]); |
501
|
|
|
$this->assertCount(2, $this->crudPanel->getOperationSetting('pageLengthMenu')); |
|
|
|
|
502
|
|
|
$this->assertTrue(in_array(40, $this->crudPanel->getOperationSetting('pageLengthMenu')[0])); |
503
|
|
|
$this->assertEquals($this->crudPanel->getOperationSetting('pageLengthMenu')[1], ['v', 't', 'q']); |
504
|
|
|
} |
505
|
|
|
|
506
|
|
|
/** |
507
|
|
|
* Tests define paginator length with multi array [[20, 30, 40]]. |
508
|
|
|
*/ |
509
|
|
|
public function testCrudPanelChangePaginatorLengthMultiArrayNoLabels() |
510
|
|
|
{ |
511
|
|
|
$this->crudPanel->setModel(User::class); |
512
|
|
|
$this->crudPanel->setOperation('list'); |
513
|
|
|
$this->crudPanel->setPageLengthMenu([[20, 30, 40]]); |
514
|
|
|
$this->assertCount(2, $this->crudPanel->getOperationSetting('pageLengthMenu')); |
|
|
|
|
515
|
|
|
$this->assertTrue(in_array(40, $this->crudPanel->getOperationSetting('pageLengthMenu')[0])); |
516
|
|
|
$this->assertTrue(in_array(40, $this->crudPanel->getOperationSetting('pageLengthMenu')[1])); |
517
|
|
|
} |
518
|
|
|
|
519
|
|
|
/** |
520
|
|
|
* Tests define paginator length with single value 40. |
521
|
|
|
*/ |
522
|
|
|
public function testCrudPanelChangePaginatorLengthWithSingleValue() |
523
|
|
|
{ |
524
|
|
|
$this->crudPanel->setModel(User::class); |
525
|
|
|
$this->crudPanel->setOperation('list'); |
526
|
|
|
$this->crudPanel->setPageLengthMenu(40); |
527
|
|
|
$this->assertCount(2, $this->crudPanel->getOperationSetting('pageLengthMenu')); |
|
|
|
|
528
|
|
|
$this->assertTrue(in_array(40, $this->crudPanel->getOperationSetting('pageLengthMenu')[0])); |
529
|
|
|
$this->assertTrue(in_array(40, $this->crudPanel->getOperationSetting('pageLengthMenu')[1])); |
530
|
|
|
} |
531
|
|
|
|
532
|
|
|
/** |
533
|
|
|
* Tests if table paginator adds default option non-existent at time in the paginator. |
534
|
|
|
*/ |
535
|
|
|
public function testCrudPanelPaginatorAddsDefaultOptionNonExistent() |
536
|
|
|
{ |
537
|
|
|
$this->crudPanel->setModel(User::class); |
538
|
|
|
$this->crudPanel->setOperation('list'); |
539
|
|
|
$this->crudPanel->setDefaultPageLength(25); |
540
|
|
|
$this->crudPanel->setPageLengthMenu($this->defaultPaginator); |
541
|
|
|
|
542
|
|
|
$this->assertCount(2, $this->crudPanel->getPageLengthMenu()); |
543
|
|
|
$this->assertCount(4, $this->crudPanel->getOperationSetting('pageLengthMenu')[0]); |
544
|
|
|
$this->assertTrue(in_array(25, $this->crudPanel->getOperationSetting('pageLengthMenu')[0])); |
545
|
|
|
$this->assertEquals(array_values($this->crudPanel->getPageLengthMenu()[0]), [10, 20, 25, 30]); |
546
|
|
|
$this->assertEquals(array_values($this->crudPanel->getPageLengthMenu()[1]), ['t1', 't2', 25, 't3']); |
547
|
|
|
} |
548
|
|
|
|
549
|
|
|
/** |
550
|
|
|
* Tests if table paginator adds default option existent. |
551
|
|
|
*/ |
552
|
|
|
public function testCrudPanelPaginatorAddsDefaultOptionExistent() |
553
|
|
|
{ |
554
|
|
|
$this->crudPanel->setModel(User::class); |
555
|
|
|
$this->crudPanel->setOperation('list'); |
556
|
|
|
|
557
|
|
|
$this->crudPanel->setPageLengthMenu($this->defaultPaginator); |
558
|
|
|
$this->crudPanel->setDefaultPageLength(20); |
559
|
|
|
$this->assertCount(2, $this->crudPanel->getPageLengthMenu()); |
560
|
|
|
$this->assertCount(3, $this->crudPanel->getOperationSetting('pageLengthMenu')[0]); |
561
|
|
|
$this->assertTrue(in_array(10, $this->crudPanel->getOperationSetting('pageLengthMenu')[0])); |
562
|
|
|
$this->assertEquals(array_values($this->crudPanel->getPageLengthMenu()[0])[0], 10); |
563
|
|
|
} |
564
|
|
|
} |
565
|
|
|
|