Browse files

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.
  • Loading branch information...
1 parent e03d3df commit 32b818d2d87890e8b225af57921363510df57ab3 @Phally Phally committed Jul 18, 2013
View
72 lib/Cake/Test/Case/View/Helper/PaginatorHelperTest.php
@@ -2027,6 +2027,78 @@ public function testNumbers() {
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);
}
/**
View
2 lib/Cake/View/Helper/PaginatorHelper.php
@@ -428,7 +428,7 @@ public function url($options = array(), $asArray = false, $model = null) {
}
$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']);

0 comments on commit 32b818d

Please sign in to comment.