|
1 | | -<?php namespace CodeIgniter\Pager; |
| 1 | +<?php |
| 2 | + |
| 3 | +namespace CodeIgniter\Pager; |
2 | 4 |
|
3 | 5 | use CodeIgniter\HTTP\URI; |
4 | 6 |
|
@@ -243,7 +245,7 @@ public function testSurroundCount() |
243 | 245 | 'uri' => $uri, |
244 | 246 | 'pageCount' => 10, // 10 pages |
245 | 247 | 'currentPage' => 4, |
246 | | - 'total' => 100,// 100 records, so 10 per page |
| 248 | + 'total' => 100, // 100 records, so 10 per page |
247 | 249 | ]; |
248 | 250 |
|
249 | 251 | $pager = new PagerRenderer($details); |
@@ -451,4 +453,77 @@ public function testGetFirstAndGetLastSegment() |
451 | 453 | $this->assertEquals('http://example.com/foo/50?foo=bar', $pager->getLast()); |
452 | 454 | } |
453 | 455 |
|
| 456 | + //-------------------------------------------------------------------- |
| 457 | + |
| 458 | + public function testHasPreviousPageReturnsFalseWhenCurrentPageIsFirst() |
| 459 | + { |
| 460 | + $details = [ |
| 461 | + 'uri' => $this->uri, |
| 462 | + 'pageCount' => 5, |
| 463 | + 'currentPage' => 1, |
| 464 | + 'total' => 100 |
| 465 | + ]; |
| 466 | + |
| 467 | + $pager = new PagerRenderer($details); |
| 468 | + |
| 469 | + $this->assertNull($pager->getPreviousPage()); |
| 470 | + $this->assertFalse($pager->hasPreviousPage()); |
| 471 | + } |
| 472 | + |
| 473 | + //-------------------------------------------------------------------- |
| 474 | + |
| 475 | + public function testHasNextPageReturnsFalseWhenCurrentPageIsLast() |
| 476 | + { |
| 477 | + $details = [ |
| 478 | + 'uri' => $this->uri, |
| 479 | + 'pageCount' => 5, |
| 480 | + 'currentPage' => 5, |
| 481 | + 'total' => 100 |
| 482 | + ]; |
| 483 | + |
| 484 | + $pager = new PagerRenderer($details); |
| 485 | + |
| 486 | + $this->assertNull($pager->getNextPage()); |
| 487 | + $this->assertFalse($pager->hasNextPage()); |
| 488 | + } |
| 489 | + |
| 490 | + //-------------------------------------------------------------------- |
| 491 | + |
| 492 | + public function testHasPreviousPageReturnsTrueWhenFirstIsMoreThanCurrent() |
| 493 | + { |
| 494 | + $uri = $this->uri; |
| 495 | + |
| 496 | + $details = [ |
| 497 | + 'uri' => $uri, |
| 498 | + 'pageCount' => 10, |
| 499 | + 'currentPage' => 3, |
| 500 | + 'total' => 100 |
| 501 | + ]; |
| 502 | + |
| 503 | + $pager = new PagerRenderer($details); |
| 504 | + |
| 505 | + $this->assertNotNull($pager->getPreviousPage()); |
| 506 | + $this->assertTrue($pager->hasPreviousPage()); |
| 507 | + $this->assertEquals('http://example.com/foo?page=2', $pager->getPreviousPage()); |
| 508 | + } |
| 509 | + |
| 510 | + //-------------------------------------------------------------------- |
| 511 | + |
| 512 | + public function testHasNextPageReturnsTrueWhenLastIsMoreThanCurrent() |
| 513 | + { |
| 514 | + $uri = $this->uri; |
| 515 | + |
| 516 | + $details = [ |
| 517 | + 'uri' => $uri, |
| 518 | + 'pageCount' => 10, |
| 519 | + 'currentPage' => 3, |
| 520 | + 'total' => 100 |
| 521 | + ]; |
| 522 | + |
| 523 | + $pager = new PagerRenderer($details); |
| 524 | + |
| 525 | + $this->assertNotNull($pager->getNextPage()); |
| 526 | + $this->assertTrue($pager->hasNextPage()); |
| 527 | + $this->assertEquals('http://example.com/foo?page=4', $pager->getNextPage()); |
| 528 | + } |
454 | 529 | } |
0 commit comments