예제 #1
0
 public function testPaginator()
 {
     $paginator = new Paginator(['a', 'b', 'c', 'd'], 2);
     $this->assertEquals(2, $paginator->getTotalPages());
     $this->assertEquals(4, $paginator->getTotalItems());
     $this->assertEquals(2, $paginator->getItemsPerPage());
     $this->assertEquals(1, $paginator->getCurrentPage());
     $this->assertEquals('a', $paginator->getItem());
     $this->assertCount(2, $paginator->getItemsCurrentPage());
     $this->assertTrue($paginator->pageChanged());
     $this->assertEquals(2, $paginator->getNextPage());
     $this->assertFalse($paginator->getPreviousPage());
     $existsMore = $paginator->nextItem();
     $this->assertTrue($existsMore);
     $this->assertEquals(1, $paginator->getCurrentPage());
     $this->assertEquals('b', $paginator->getItem());
     $this->assertFalse($paginator->pageChanged());
     $this->assertEquals(2, $paginator->getNextPage());
     $this->assertFalse($paginator->getPreviousPage());
     $existsMore = $paginator->nextItem();
     $this->assertTrue($existsMore);
     $this->assertCount(2, $paginator->getItemsCurrentPage());
     $this->assertEquals(2, $paginator->getCurrentPage());
     $this->assertEquals('c', $paginator->getItem());
     $this->assertTrue($paginator->pageChanged());
     $this->assertFalse($paginator->getNextPage());
     $this->assertEquals(1, $paginator->getPreviousPage());
     $existsMore = $paginator->nextItem();
     $this->assertTrue($existsMore);
     $this->assertEquals(2, $paginator->getCurrentPage());
     $this->assertEquals('d', $paginator->getItem());
     $this->assertFalse($paginator->pageChanged());
     $this->assertFalse($paginator->getNextPage());
     $this->assertEquals(1, $paginator->getPreviousPage());
     $existsMore = $paginator->nextItem();
     $this->assertFalse($existsMore);
     $this->assertEquals(2, $paginator->getCurrentPage());
     $this->assertFalse($paginator->getNextPage());
 }
예제 #2
0
 private function getPaginatorPayload(Paginator $paginator)
 {
     $result = [];
     $result['per_page'] = $paginator->getItemsPerPage();
     $result['posts'] = $paginator->getItemsCurrentPage();
     $result['total_posts'] = $paginator->getTotalItems();
     $result['total_pages'] = $paginator->getTotalPages();
     $result['page'] = $paginator->getCurrentPage();
     $result['previous_page'] = $paginator->getPreviousPage();
     $result['previous_page_path'] = $this->getPageRelativePath($result['previous_page']);
     $result['next_page'] = $paginator->getNextPage();
     $result['next_page_path'] = $this->getPageRelativePath($result['next_page']);
     return $result;
 }