Skip to content

Commit

Permalink
Fixes bug in the first link of PaginatorHelper::numbers().
Browse files Browse the repository at this point in the history
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
Phally committed Jul 18, 2013
1 parent e03d3df commit 32b818d
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 1 deletion.
72 changes: 72 additions & 0 deletions lib/Cake/Test/Case/View/Helper/PaginatorHelperTest.php
Expand Up @@ -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);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/Cake/View/Helper/PaginatorHelper.php
Expand Up @@ -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']);
Expand Down

0 comments on commit 32b818d

Please sign in to comment.