|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace League\Fractal\Test\Pagination; |
|
4
|
|
|
|
|
5
|
|
|
use League\Fractal\Pagination\PagerfantaPaginatorAdapter; |
|
6
|
|
|
use League\Fractal\Test\TestCase; |
|
7
|
|
|
use Mockery; |
|
8
|
|
|
|
|
9
|
|
|
class PagerfantaPaginatorAdapterTest extends TestCase |
|
10
|
|
|
{ |
|
11
|
|
|
public function testPaginationAdapter() |
|
12
|
|
|
{ |
|
13
|
|
|
$items = [ |
|
14
|
|
|
'Item 1', 'Item 2', 'Item 3', 'Item 4', 'Item 5', 'Item 6', 'Item 7', 'Item 8', 'Item 9', 'Item 10', |
|
15
|
|
|
'Item 11', 'Item 12', 'Item 13', 'Item 14', 'Item 15', 'Item 16', 'Item 17', 'Item 18', 'Item 19', 'Item 20', |
|
16
|
|
|
'Item 21', 'Item 22', 'Item 23', 'Item 24', 'Item 25', 'Item 26', 'Item 27', 'Item 28', 'Item 29', 'Item 30', |
|
17
|
|
|
'Item 31', 'Item 32', 'Item 33', 'Item 34', 'Item 35', 'Item 36', 'Item 37', 'Item 38', 'Item 39', 'Item 40', |
|
18
|
|
|
'Item 41', 'Item 42', 'Item 43', 'Item 44', 'Item 45', 'Item 46', 'Item 47', 'Item 48', 'Item 49', 'Item 50', |
|
19
|
|
|
]; |
|
20
|
|
|
|
|
21
|
|
|
$adapter = Mockery::mock('Pagerfanta\Adapter\ArrayAdapter', [$items])->makePartial(); |
|
22
|
|
|
|
|
23
|
|
|
$total = 50; |
|
24
|
|
|
$count = 5; |
|
25
|
|
|
$perPage = 5; |
|
26
|
|
|
$currentPage = 2; |
|
27
|
|
|
$lastPage = 10; |
|
28
|
|
|
|
|
29
|
|
|
$paginator = Mockery::mock('Pagerfanta\Pagerfanta', [$adapter])->makePartial(); |
|
30
|
|
|
|
|
31
|
|
|
$paginator->shouldReceive('getCurrentPage')->andReturn($currentPage); |
|
32
|
|
|
$paginator->shouldReceive('getLastPage')->andReturn($lastPage); |
|
33
|
|
|
$paginator->shouldReceive('getMaxPerPage')->andReturn($perPage); |
|
34
|
|
|
|
|
35
|
|
|
$adapter = new PagerfantaPaginatorAdapter($paginator, function ($page) { |
|
36
|
|
|
return 'http://example.com/foo?page=' . $page; |
|
37
|
|
|
}); |
|
38
|
|
|
|
|
39
|
|
|
$this->assertInstanceOf( |
|
40
|
|
|
'League\Fractal\Pagination\PaginatorInterface', |
|
41
|
|
|
$adapter |
|
42
|
|
|
); |
|
43
|
|
|
|
|
44
|
|
|
$this->assertSame($currentPage, $adapter->getCurrentPage()); |
|
45
|
|
|
$this->assertSame($lastPage, $adapter->getLastPage()); |
|
46
|
|
|
$this->assertSame($count, $adapter->getCount()); |
|
47
|
|
|
$this->assertSame($total, $adapter->getTotal()); |
|
48
|
|
|
$this->assertSame($perPage, $adapter->getPerPage()); |
|
49
|
|
|
$this->assertSame( |
|
50
|
|
|
'http://example.com/foo?page=1', |
|
51
|
|
|
$adapter->getUrl(1) |
|
52
|
|
|
); |
|
53
|
|
|
$this->assertSame( |
|
54
|
|
|
'http://example.com/foo?page=3', |
|
55
|
|
|
$adapter->getUrl(3) |
|
56
|
|
|
); |
|
57
|
|
|
} |
|
58
|
|
|
} |
|
59
|
|
|
|