Skip to content
Permalink
Browse files

Fix pagination regarding 0 value persistence.

  • Loading branch information...
dereuromark committed Jun 15, 2015
1 parent 464dc9c commit 121b88783b7c651de5e308d185cc579ea72e688c
Showing with 14 additions and 10 deletions.
  1. +5 −1 src/View/Helper/PaginatorHelper.php
  2. +9 −9 tests/TestCase/View/Helper/PaginatorHelperTest.php
@@ -428,7 +428,11 @@ public function generateUrl(array $options = [], $model = null, $full = false)
if (!empty($this->_config['options']['url'])) {
$url = array_merge($url, $this->_config['options']['url']);
}
$url = array_merge(array_filter($url), $options);
$callback = function($value) {
return ($value || is_numeric($value));
};
$url = array_merge(array_filter($url, $callback), $options);
if (!empty($url['page']) && $url['page'] == 1) {
$url['page'] = null;
@@ -799,13 +799,13 @@ public function testPassedArgsMergingWithUrlOptions()
];
$this->Paginator->request->params['pass'] = [2];
$this->Paginator->request->query = ['page' => 1, 'foo' => 'bar', 'x' => 'y'];
$this->Paginator->request->query = ['page' => 1, 'foo' => 'bar', 'x' => 'y', 'num' => 0, 'empty' => ''];
$this->View->request = $this->Paginator->request;
$this->Paginator = new PaginatorHelper($this->View);
$result = $this->Paginator->sort('title');
$expected = [
'a' => ['href' => '/articles/index/2?foo=bar&x=y&sort=title&direction=asc'],
'a' => ['href' => '/articles/index/2?foo=bar&x=y&num=0&sort=title&direction=asc'],
'Title',
'/a'
];
@@ -814,19 +814,19 @@ public function testPassedArgsMergingWithUrlOptions()
$result = $this->Paginator->numbers();
$expected = [
['li' => ['class' => 'active']], '<a href=""', '1', '/a', '/li',
['li' => []], ['a' => ['href' => '/articles/index/2?page=2&amp;foo=bar&amp;x=y']], '2', '/a', '/li',
['li' => []], ['a' => ['href' => '/articles/index/2?page=3&amp;foo=bar&amp;x=y']], '3', '/a', '/li',
['li' => []], ['a' => ['href' => '/articles/index/2?page=4&amp;foo=bar&amp;x=y']], '4', '/a', '/li',
['li' => []], ['a' => ['href' => '/articles/index/2?page=5&amp;foo=bar&amp;x=y']], '5', '/a', '/li',
['li' => []], ['a' => ['href' => '/articles/index/2?page=6&amp;foo=bar&amp;x=y']], '6', '/a', '/li',
['li' => []], ['a' => ['href' => '/articles/index/2?page=7&amp;foo=bar&amp;x=y']], '7', '/a', '/li',
['li' => []], ['a' => ['href' => '/articles/index/2?page=2&amp;foo=bar&amp;x=y&amp;num=0']], '2', '/a', '/li',
['li' => []], ['a' => ['href' => '/articles/index/2?page=3&amp;foo=bar&amp;x=y&amp;num=0']], '3', '/a', '/li',
['li' => []], ['a' => ['href' => '/articles/index/2?page=4&amp;foo=bar&amp;x=y&amp;num=0']], '4', '/a', '/li',
['li' => []], ['a' => ['href' => '/articles/index/2?page=5&amp;foo=bar&amp;x=y&amp;num=0']], '5', '/a', '/li',
['li' => []], ['a' => ['href' => '/articles/index/2?page=6&amp;foo=bar&amp;x=y&amp;num=0']], '6', '/a', '/li',
['li' => []], ['a' => ['href' => '/articles/index/2?page=7&amp;foo=bar&amp;x=y&amp;num=0']], '7', '/a', '/li',
];
$this->assertHtml($expected, $result);
$result = $this->Paginator->next('Next');
$expected = [
'li' => ['class' => 'next'],
'a' => ['href' => '/articles/index/2?page=2&amp;foo=bar&amp;x=y', 'rel' => 'next'],
'a' => ['href' => '/articles/index/2?page=2&amp;foo=bar&amp;x=y&amp;num=0', 'rel' => 'next'],
'Next',
'/a',
'/li'

0 comments on commit 121b887

Please sign in to comment.
You can’t perform that action at this time.