forked from laravel/framework
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPaginatorTest.php
74 lines (57 loc) · 2.29 KB
/
PaginatorTest.php
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
62
63
64
65
66
67
68
69
70
71
72
73
74
<?php
namespace Illuminate\Tests\Pagination;
use Illuminate\Pagination\Paginator;
use PHPUnit\Framework\TestCase;
class PaginatorTest extends TestCase
{
public function testSimplePaginatorReturnsRelevantContextInformation()
{
/** @var Paginator<int, string> $p */
$p = new Paginator(['item3', 'item4', 'item5'], 2, 2);
$this->assertEquals(2, $p->currentPage());
$this->assertTrue($p->hasPages());
$this->assertTrue($p->hasMorePages());
$this->assertEquals(['item3', 'item4'], $p->items());
$pageInfo = [
'per_page' => 2,
'current_page' => 2,
'first_page_url' => '/?page=1',
'next_page_url' => '/?page=3',
'prev_page_url' => '/?page=1',
'from' => 3,
'to' => 4,
'data' => ['item3', 'item4'],
'path' => '/',
];
$this->assertEquals($pageInfo, $p->toArray());
}
public function testPaginatorRemovesTrailingSlashes()
{
$p = new Paginator(['item1', 'item2', 'item3'], 2, 2, ['path' => 'http://website.com/test/']);
$this->assertSame('http://website.com/test?page=1', $p->previousPageUrl());
}
public function testPaginatorGeneratesUrlsWithoutTrailingSlash()
{
$p = new Paginator(['item1', 'item2', 'item3'], 2, 2, ['path' => 'http://website.com/test']);
$this->assertSame('http://website.com/test?page=1', $p->previousPageUrl());
}
public function testItRetrievesThePaginatorOptions()
{
$p = new Paginator(['item1', 'item2', 'item3'], 2, 2, ['path' => 'http://website.com/test']);
$this->assertSame(['path' => 'http://website.com/test'], $p->getOptions());
}
public function testPaginatorReturnsPath()
{
$p = new Paginator(['item1', 'item2', 'item3'], 2, 2, ['path' => 'http://website.com/test']);
$this->assertSame('http://website.com/test', $p->path());
}
public function testCanTransformPaginatorItems()
{
$p = new Paginator(['item1', 'item2', 'item3'], 3, 1, ['path' => 'http://website.com/test']);
$p->through(function ($item) {
return substr($item, 4, 1);
});
$this->assertInstanceOf(Paginator::class, $p);
$this->assertSame(['1', '2', '3'], $p->items());
}
}