Repository navigation
Expand file tree
/
Copy pathPaginateModelTest.php
More file actions
61 lines (48 loc) · 1.49 KB
/
Copy pathPaginateModelTest.php
File metadata and controls
61 lines (48 loc) · 1.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<?php
namespace CodeIgniter\Models;
use Tests\Support\Models\UserModel;
use Tests\Support\Models\ValidModel;
final class PaginateModelTest extends LiveModelTestCase
{
public function testPaginate(): void
{
$data = $this->createModel(ValidModel::class)->paginate();
$this->assertCount(4, $data);
}
public function testPaginateChangeConfigPager(): void
{
$perPage = config('Pager')->perPage;
config('Pager')->perPage = 1;
$data = $this->createModel(ValidModel::class)->paginate();
$this->assertCount(1, $data);
config('Pager')->perPage = $perPage;
}
public function testPaginatePassPerPageParameter(): void
{
$data = $this->createModel(ValidModel::class)->paginate(2);
$this->assertCount(2, $data);
}
public function testPaginateForQueryWithGroupBy(): void
{
$this->createModel(ValidModel::class);
$this->model->groupBy('id');
$this->model->paginate();
$this->assertSame(4, $this->model->pager->getDetails()['total']);
}
public function testPaginateWithDeleted(): void
{
$this->createModel(UserModel::class);
$this->model->delete(1);
$data = $this->model->withDeleted()->paginate();
$this->assertCount(4, $data);
$this->assertSame(4, $this->model->pager->getDetails()['total']);
}
public function testPaginateWithoutDeleted(): void
{
$this->createModel(UserModel::class);
$this->model->delete(1);
$data = $this->model->withDeleted(false)->paginate();
$this->assertCount(3, $data);
$this->assertSame(3, $this->model->pager->getDetails()['total']);
}
}