1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace League\Fractal\Test\Pagination; |
4
|
|
|
|
5
|
|
|
use League\Fractal\Pagination\IlluminatePaginatorAdapter; |
6
|
|
|
use League\Fractal\Test\TestCase; |
7
|
|
|
use Mockery; |
8
|
|
|
|
9
|
|
|
class IlluminatePaginatorAdapterTest extends TestCase |
10
|
|
|
{ |
11
|
|
|
public function testPaginationAdapter() |
12
|
|
|
{ |
13
|
|
|
$total = 50; |
14
|
|
|
$count = 10; |
15
|
|
|
$perPage = 10; |
16
|
|
|
$currentPage = 2; |
17
|
|
|
$lastPage = 5; |
18
|
|
|
$url = 'http://example.com/foo?page=1'; |
19
|
|
|
|
20
|
|
|
$paginator = Mockery::mock('Illuminate\Contracts\Pagination\LengthAwarePaginator'); |
21
|
|
|
$paginator->shouldReceive('currentPage')->andReturn($currentPage); |
22
|
|
|
$paginator->shouldReceive('lastPage')->andReturn($lastPage); |
23
|
|
|
$paginator->shouldReceive('items')->andReturn(array_fill(0, $count, '')); |
24
|
|
|
$paginator->shouldReceive('total')->andReturn($total); |
25
|
|
|
$paginator->shouldReceive('perPage')->andReturn($perPage); |
26
|
|
|
$paginator->shouldReceive('url')->with(1)->andReturn($url); |
27
|
|
|
|
28
|
|
|
$adapter = new IlluminatePaginatorAdapter($paginator); |
29
|
|
|
|
30
|
|
|
$this->assertInstanceOf('League\Fractal\Pagination\PaginatorInterface', $adapter); |
31
|
|
|
$this->assertInstanceOf('Illuminate\Contracts\Pagination\LengthAwarePaginator', $adapter->getPaginator()); |
32
|
|
|
|
33
|
|
|
$this->assertSame($currentPage, $adapter->getCurrentPage()); |
34
|
|
|
$this->assertSame($lastPage, $adapter->getLastPage()); |
35
|
|
|
$this->assertSame($count, $adapter->getCount()); |
36
|
|
|
$this->assertSame($total, $adapter->getTotal()); |
37
|
|
|
$this->assertSame($perPage, $adapter->getPerPage()); |
38
|
|
|
$this->assertSame('http://example.com/foo?page=1', $adapter->getUrl(1)); |
39
|
|
|
} |
40
|
|
|
} |
41
|
|
|
|