Skip to content

Commit

Permalink
Fixed helperPaginator::numbers() to get it working with a string nu…
Browse files Browse the repository at this point in the history
…mber

Also, added testscase for `Paginator::first()` & `Paginator::last()`for the same thing.
  • Loading branch information
Xety committed Dec 14, 2015
1 parent b8e6a9f commit fd6bd3c
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/View/Helper/PaginatorHelper.php
Expand Up @@ -820,9 +820,10 @@ protected function _firstNumber($ellipsis, $params, $start, $options)
protected function _lastNumber($ellipsis, $params, $end, $options)
{
$out = '';
$last = is_int($options['last']) ? $options['last'] : 0;
if ($options['last'] && $end < $params['pageCount']) {
$offset = ($params['pageCount'] < $end + (int)$options['last']) ? $params['pageCount'] - $end : $options['last'];
if ($offset <= $options['last'] && $params['pageCount'] - $end > $offset) {
$offset = ($params['pageCount'] < $end + $last) ? $params['pageCount'] - $end : $options['last'];
if ($offset <= $options['last'] && $params['pageCount'] - $end > $last) {
$out .= $ellipsis;
}
$out .= $this->last($offset, $options);
Expand Down
38 changes: 38 additions & 0 deletions tests/TestCase/View/Helper/PaginatorHelperTest.php
Expand Up @@ -1147,6 +1147,24 @@ public function testNumbers()
];
$this->assertHtml($expected, $result);

$result = $this->Paginator->numbers(['first' => '2', 'last' => '8']);
$expected = [
['li' => ['class' => 'first']], ['a' => ['href' => '/index']], '2', '/a', '/li',
['li' => ['class' => 'ellipsis']], '...', '/li',
['li' => []], ['a' => ['href' => '/index?page=4']], '4', '/a', '/li',
['li' => []], ['a' => ['href' => '/index?page=5']], '5', '/a', '/li',
['li' => []], ['a' => ['href' => '/index?page=6']], '6', '/a', '/li',
['li' => []], ['a' => ['href' => '/index?page=7']], '7', '/a', '/li',
['li' => ['class' => 'active']], '<a href=""', '8', '/a', '/li',
['li' => []], ['a' => ['href' => '/index?page=9']], '9', '/a', '/li',
['li' => []], ['a' => ['href' => '/index?page=10']], '10', '/a', '/li',
['li' => []], ['a' => ['href' => '/index?page=11']], '11', '/a', '/li',
['li' => []], ['a' => ['href' => '/index?page=12']], '12', '/a', '/li',
['li' => ['class' => 'ellipsis']], '...', '/li',
['li' => ['class' => 'last']], ['a' => ['href' => '/index?page=15']], '8', '/a', '/li',
];
$this->assertHtml($expected, $result);

$this->Paginator->request->params['paging'] = [
'Client' => [
'page' => 1,
Expand Down Expand Up @@ -1750,6 +1768,16 @@ public function testFirstAndLastTag()
];
$this->assertHtml($expected, $result);

$result = $this->Paginator->first('5');
$expected = [
'li' => ['class' => 'first'],
'a' => ['href' => '/index'],
'5',
'/a',
'/li'
];
$this->assertHtml($expected, $result);

$result = $this->Paginator->last(2);
$expected = [
'<li',
Expand All @@ -1760,6 +1788,16 @@ public function testFirstAndLastTag()
'/li',
];
$this->assertHtml($expected, $result);

$result = $this->Paginator->last('9');
$expected = [
'li' => ['class' => 'last'],
'a' => ['href' => '/index?page=7'],
'9',
'/a',
'/li'
];
$this->assertHtml($expected, $result);
}

/**
Expand Down

0 comments on commit fd6bd3c

Please sign in to comment.