Skip to content

Commit

Permalink
Fix notice errors in pagination link generation.
Browse files Browse the repository at this point in the history
No errors should be emitted when creating links for models that were not
paginated.

Refs #6090
  • Loading branch information
markstory committed Mar 18, 2015
1 parent c3e1ba1 commit 6df7bf9
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 2 deletions.
41 changes: 41 additions & 0 deletions lib/Cake/Test/Case/View/Helper/PaginatorHelperTest.php
Expand Up @@ -1260,6 +1260,14 @@ public function testPagingLinksNotDefaultModel() {
'paramType' => 'named'
)
);
$result = $this->Paginator->sort('title', 'Title', array('model' => 'Client'));
$expected = array(
'a' => array('href' => '/index/sort:title/direction:asc'),
'Title',
'/a'
);
$this->assertTags($result, $expected);

$result = $this->Paginator->next('Next', array('model' => 'Client'));
$expected = array(
'span' => array('class' => 'next'),
Expand All @@ -1277,6 +1285,39 @@ public function testPagingLinksNotDefaultModel() {
$this->assertTags($result, $expected);
}

/**
* Test creating paging links for missing models.
*
* @return void
*/
public function testPagingLinksMissingModel() {
$result = $this->Paginator->sort('title', 'Title', array('model' => 'Missing'));
$expected = array(
'a' => array('href' => '/index/sort:title/direction:asc'),
'Title',
'/a'
);
$this->assertTags($result, $expected);

$result = $this->Paginator->next('Next', array('model' => 'Missing'));
$expected = array(
'span' => array('class' => 'next'),
'a' => array('href' => '/index/page:2', 'rel' => 'next'),
'Next',
'/a',
'/span'
);
$this->assertTags($result, $expected);

$result = $this->Paginator->prev('Prev', array('model' => 'Missing'));
$expected = array(
'span' => array('class' => 'prev'),
'Prev',
'/span'
);
$this->assertTags($result, $expected);
}

/**
* testGenericLinks method
*
Expand Down
11 changes: 9 additions & 2 deletions lib/Cake/View/Helper/PaginatorHelper.php
Expand Up @@ -120,15 +120,22 @@ public function beforeRender($viewFile) {
* Gets the current paging parameters from the resultset for the given model
*
* @param string $model Optional model name. Uses the default if none is specified.
* @return array|null The array of paging parameters for the paginated resultset.
* @return array The array of paging parameters for the paginated resultset.
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/paginator.html#PaginatorHelper::params
*/
public function params($model = null) {
if (empty($model)) {
$model = $this->defaultModel();
}
if (!isset($this->request->params['paging']) || empty($this->request->params['paging'][$model])) {
return null;
return array(
'prevPage' => false,
'nextPage' => true,
'paramType' => 'named',
'pageCount' => 1,
'options' => array(),
'page' => 1
);
}
return $this->request->params['paging'][$model];
}
Expand Down

0 comments on commit 6df7bf9

Please sign in to comment.