Skip to content

Commit 423a950

Browse files
committed
Unit Tests for the new features added to the pagination
1 parent f43f3a5 commit 423a950

1 file changed

Lines changed: 73 additions & 2 deletions

File tree

tests/system/Pager/PagerRendererTest.php

Lines changed: 73 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
<?php namespace CodeIgniter\Pager;
1+
<?php
2+
3+
namespace CodeIgniter\Pager;
24

35
use CodeIgniter\HTTP\URI;
46

@@ -243,7 +245,7 @@ public function testSurroundCount()
243245
'uri' => $uri,
244246
'pageCount' => 10, // 10 pages
245247
'currentPage' => 4,
246-
'total' => 100,// 100 records, so 10 per page
248+
'total' => 100, // 100 records, so 10 per page
247249
];
248250

249251
$pager = new PagerRenderer($details);
@@ -451,4 +453,73 @@ public function testGetFirstAndGetLastSegment()
451453
$this->assertEquals('http://example.com/foo/50?foo=bar', $pager->getLast());
452454
}
453455

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->assertFalse($pager->hasPreviousPage());
470+
}
471+
472+
//--------------------------------------------------------------------
473+
474+
public function testHasNextPageReturnsFalseWhenCurrentPageIsLast()
475+
{
476+
$details = [
477+
'uri' => $this->uri,
478+
'pageCount' => 5,
479+
'currentPage' => 5,
480+
'total' => 100
481+
];
482+
483+
$pager = new PagerRenderer($details);
484+
485+
$this->assertFalse($pager->hasNextPage());
486+
}
487+
488+
//--------------------------------------------------------------------
489+
490+
public function testHasPreviousPageReturnsTrueWhenFirstIsMoreThanCurrent()
491+
{
492+
$uri = $this->uri;
493+
494+
$details = [
495+
'uri' => $uri,
496+
'pageCount' => 10,
497+
'currentPage' => 3,
498+
'total' => 100
499+
];
500+
501+
$pager = new PagerRenderer($details);
502+
503+
$this->assertTrue($pager->hasPreviousPage());
504+
$this->assertEquals('http://example.com/foo?page=2', $pager->getPreviousPage());
505+
}
506+
507+
//--------------------------------------------------------------------
508+
509+
public function testHasNextPageReturnsTrueWhenLastIsMoreThanCurrent()
510+
{
511+
$uri = $this->uri;
512+
513+
$details = [
514+
'uri' => $uri,
515+
'pageCount' => 10,
516+
'currentPage' => 3,
517+
'total' => 100
518+
];
519+
520+
$pager = new PagerRenderer($details);
521+
522+
$this->assertTrue($pager->hasNextPage());
523+
$this->assertEquals('http://example.com/foo?page=4', $pager->getNextPage());
524+
}
454525
}

0 commit comments

Comments
 (0)