first commit

This commit is contained in:
2024-12-17 13:43:22 +01:00
commit 8e6cd8b410
21292 changed files with 3514826 additions and 0 deletions

View File

@@ -0,0 +1,123 @@
<?php
namespace JasonGrimes\Tests;
use JasonGrimes\Paginator;
class PaginatorTest extends \PHPUnit_Framework_TestCase
{
/** @var Paginator */
protected $paginator;
public function setUp()
{
$numItems = 100;
$itemsPerPage = 10;
$currentPage = 5;
$urlPattern = '/example/page(:num)';
$this->paginator = new Paginator($numItems, $itemsPerPage, $currentPage, $urlPattern);
}
public function testGetNextPage()
{
$this->paginator->setCurrentPage(1);
$this->assertEquals(2, $this->paginator->getNextPage());
// If we're on the last page, getNextPage() returns null.
$this->paginator->setCurrentPage($this->paginator->getNumPages());
$this->assertNull($this->paginator->getNextPage());
}
public function testGetPrevPage()
{
$this->paginator->setCurrentPage(2);
$this->assertEquals(1, $this->paginator->getPrevPage());
// If we're on the first page, getPrevPage() returns null.
$this->paginator->setCurrentPage(1);
$this->assertNull($this->paginator->getPrevPage());
}
public function testGetNextUrl()
{
$this->paginator->setCurrentPage(1);
$this->paginator->setUrlPattern('/example/page(:num)');
$this->assertEquals('/example/page2', $this->paginator->getNextUrl());
// Returns null if on the last page.
$this->paginator->setCurrentPage($this->paginator->getNumPages());
$this->assertNull($this->paginator->getNextUrl());
}
public function testGetPrevUrl()
{
$this->paginator->setCurrentPage(2);
$this->paginator->setUrlPattern('/example/page(:num)');
$this->assertEquals('/example/page1', $this->paginator->getPrevUrl());
// Returns null if on the first page.
$this->paginator->setCurrentPage(1);
$this->assertNull($this->paginator->getPrevUrl());
}
/**
* @dataProvider getTestData
*/
public function testGetPages($numPages, $currentPage, $maxPages, $expected)
{
$paginator = new Paginator($numPages, 1, $currentPage);
$paginator->setMaxPagesToShow($maxPages);
$pages = $paginator->getPages();
$pageNums = array_map(function($page) { return $page['num']; }, $pages);
$this->assertEquals($expected, $pageNums);
}
public function getTestData()
{
return array(
// num pages, current page, max pages to show, expected pagination
array(13, 2, 5, array(1, 2, 3, 4, '...', 13)),
array(13, 4, 5, array(1, '...', 3, 4, 5, '...', 13)),
array(13, 5, 5, array(1, '...', 4, 5, 6, '...', 13)),
array(13, 11, 5, array(1, '...', 10, 11, 12, 13)),
array(13, 10, 5, array(1, '...', 9, 10, 11, '...', 13)),
array(20, 1, 10, array(1, 2, 3, 4, 5, 6, 7, 8, 9, '...', 20)),
array(20, 2, 10, array(1, 2, 3, 4, 5, 6, 7, 8, 9, '...', 20)),
array(20, 20, 10, array(1, '...', 12, 13, 14, 15, 16, 17, 18, 19, 20)),
array(20, 19, 10, array(1, '...', 12, 13, 14, 15, 16, 17, 18, 19, 20)),
array(20, 10, 10, array(1, '...', 7, 8, 9, 10, 11, 12, 13, 14, '...', 20)),
array(20, 9, 10, array(1, '...', 6, 7, 8, 9, 10, 11, 12, 13, '...', 20)),
array(5, 3, 10, array(1, 2, 3, 4, 5)),
array(1, 1, 10, array()), // No pagination if there's only one page.
array(20, 5, 3, array(1, '...', 5, '...', 20)),
);
}
/**
* @dataProvider getRangeData
*/
public function testGetItemRanges($numItems, $itemsPerPage, $currentPage, $expectedFirst, $expectedLast)
{
$paginator = new Paginator($numItems, $itemsPerPage, $currentPage);
$this->assertEquals($numItems, $paginator->getTotalItems());
$this->assertEquals($expectedFirst, $paginator->getCurrentPageFirstItem());
$this->assertEquals($expectedLast, $paginator->getCurrentPageLastItem());
}
public function getRangeData()
{
return array(
// $numItems, $itemsPerPage, $currentPage, $expectedFirstItem, $expectedLastItem
array(95, 10, 1, 1, 10),
array(95, 10, 2, 11, 20),
array(95, 10, 10, 91, 95),
array(95, 10, 11, null, null), // If current page exceeds total items, first and last item are null.
);
}
}

View File

@@ -0,0 +1,34 @@
<?php
/**
* 2007-2018 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2018 PrestaShop SA
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
header('Cache-Control: no-store, no-cache, must-revalidate');
header('Cache-Control: post-check=0, pre-check=0', false);
header('Pragma: no-cache');
header('Location: ../');
exit;

View File

@@ -0,0 +1,34 @@
<?php
/**
* 2007-2018 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2018 PrestaShop SA
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
header('Cache-Control: no-store, no-cache, must-revalidate');
header('Cache-Control: post-check=0, pre-check=0', false);
header('Pragma: no-cache');
header('Location: ../');
exit;