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