From 32b818d2d87890e8b225af57921363510df57ab3 Mon Sep 17 00:00:00 2001 From: Phally Date: Thu, 18 Jul 2013 16:48:34 +0200 Subject: [PATCH] Fixes bug in the first link of PaginatorHelper::numbers(). The link was the current URL instead of a link to the first page. This only happened with named parameters. This commit also includes a test for querystring parameters. Refs #1432. --- .../Case/View/Helper/PaginatorHelperTest.php | 72 +++++++++++++++++++ lib/Cake/View/Helper/PaginatorHelper.php | 2 +- 2 files changed, 73 insertions(+), 1 deletion(-) diff --git a/lib/Cake/Test/Case/View/Helper/PaginatorHelperTest.php b/lib/Cake/Test/Case/View/Helper/PaginatorHelperTest.php index c948b1c2f..88d5425b1 100644 --- a/lib/Cake/Test/Case/View/Helper/PaginatorHelperTest.php +++ b/lib/Cake/Test/Case/View/Helper/PaginatorHelperTest.php @@ -2027,6 +2027,78 @@ class PaginatorHelperTest extends CakeTestCase { array('span' => array()), array('a' => array('href' => '/index/page:4897')), '4897', '/a', '/span', ); $this->assertTags($result, $expected); + + $this->Paginator->request->params['paging'] = array( + 'Client' => array( + 'page' => 2, + 'current' => 2, + 'count' => 30, + 'prevPage' => false, + 'nextPage' => 3, + 'pageCount' => 3, + 'options' => array( + 'page' => 1, + ), + 'paramType' => 'named' + ) + ); + + $request = new CakeRequest(); + $request->addParams(array( + 'controller' => 'clients', 'action' => 'index', 'plugin' => null, 'page' => 2 + )); + $request->base = ''; + $request->here = '/clients/index/page:2'; + $request->webroot = '/'; + + Router::setRequestInfo($request); + + $result = $this->Paginator->numbers(); + $expected = array( + array('span' => array()), array('a' => array('href' => '/clients')), '1', '/a', '/span', + ' | ', + array('span' => array('class' => 'current')), '2', '/span', + ' | ', + array('span' => array()), array('a' => array('href' => '/clients/index/page:3')), '3', '/a', '/span', + + ); + $this->assertTags($result, $expected); + + $this->Paginator->request->params['paging'] = array( + 'Client' => array( + 'page' => 2, + 'current' => 2, + 'count' => 30, + 'prevPage' => false, + 'nextPage' => 3, + 'pageCount' => 3, + 'options' => array( + 'page' => 1, + ), + 'paramType' => 'querystring' + ) + ); + + $request = new CakeRequest(); + $request->addParams(array( + 'controller' => 'clients', 'action' => 'index', 'plugin' => null + )); + $request->base = ''; + $request->here = '/clients?page=2'; + $request->webroot = '/'; + + Router::setRequestInfo($request); + + $result = $this->Paginator->numbers(); + $expected = array( + array('span' => array()), array('a' => array('href' => '/clients')), '1', '/a', '/span', + ' | ', + array('span' => array('class' => 'current')), '2', '/span', + ' | ', + array('span' => array()), array('a' => array('href' => '/clients?page=3')), '3', '/a', '/span', + + ); + $this->assertTags($result, $expected); } /** diff --git a/lib/Cake/View/Helper/PaginatorHelper.php b/lib/Cake/View/Helper/PaginatorHelper.php index fabb67998..46c7d7806 100644 --- a/lib/Cake/View/Helper/PaginatorHelper.php +++ b/lib/Cake/View/Helper/PaginatorHelper.php @@ -428,7 +428,7 @@ class PaginatorHelper extends AppHelper { } $url = $this->_convertUrlKeys($url, $paging['paramType']); if (!empty($url['page']) && $url['page'] == 1) { - unset($url['page']); + $url['page'] = null; } if (!empty($url['?']['page']) && $url['?']['page'] == 1) { unset($url['?']['page']);