From 1a387e6b8ac90c8ab2f96a887d4d9dad8b536a64 Mon Sep 17 00:00:00 2001 From: Mark Story Date: Tue, 22 Dec 2009 19:05:06 -0500 Subject: [PATCH] Fixing url parameters set with options() or beforeRender not being merged on next() / prev(). Tests added. Fixes #129 This reverses the change made in efa36abdf049a57662bc3323828957de3742dfb1 which broke this behavior. --- cake/libs/view/helpers/paginator.php | 4 ++-- .../libs/view/helpers/paginator.test.php | 22 ++++++++++++++++++- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/cake/libs/view/helpers/paginator.php b/cake/libs/view/helpers/paginator.php index 84263d567..dd77f3d7b 100644 --- a/cake/libs/view/helpers/paginator.php +++ b/cake/libs/view/helpers/paginator.php @@ -411,10 +411,10 @@ class PaginatorHelper extends AppHelper { ${$key} = $options[$key]; unset($options[$key]); } - $urlParams = array('page' => $paging['page'] + ($which == 'Prev' ? $step * -1 : $step)); + $url = array_merge(array('page' => $paging['page'] + ($which == 'Prev' ? $step * -1 : $step)), $url); if ($this->{$check}($model)) { - return $this->link($title, $urlParams, array_merge($options, compact('escape', 'class', 'url'))); + return $this->link($title, $url, array_merge($options, compact('escape', 'class'))); } else { return $this->Html->tag($tag, $title, array_merge($options, compact('escape', 'class'))); } diff --git a/cake/tests/cases/libs/view/helpers/paginator.test.php b/cake/tests/cases/libs/view/helpers/paginator.test.php index 19d5853e6..af91ca26d 100644 --- a/cake/tests/cases/libs/view/helpers/paginator.test.php +++ b/cake/tests/cases/libs/view/helpers/paginator.test.php @@ -585,6 +585,18 @@ class PaginatorHelperTest extends CakeTestCase { array('plugin' => null, 'controller' => 'articles', 'action' => 'index', 'pass' => array('2'), 'named' => array('foo' => 'bar'), 'form' => array(), 'url' => array('url' => 'articles/index/2/foo:bar'), 'bare' => 0), array('plugin' => null, 'controller' => null, 'action' => null, 'base' => '/', 'here' => '/articles/', 'webroot' => '/', 'passedArgs' => array(0 => '2', 'foo' => 'bar')) )); + $this->Paginator->params['paging'] = array( + 'Article' => array( + 'page' => 1, 'current' => 3, 'count' => 13, + 'prevPage' => false, 'nextPage' => true, 'pageCount' => 8, + 'defaults' => array( + 'limit' => 3, 'step' => 1, 'order' => array(), 'conditions' => array() + ), + 'options' => array( + 'page' => 1, 'limit' => 3, 'order' => array(), 'conditions' => array() + ) + ) + ); $this->Paginator->params['pass'] = array(2); $this->Paginator->params['named'] = array('foo' => 'bar'); @@ -615,6 +627,14 @@ class PaginatorHelperTest extends CakeTestCase { array('span' => array()), array('a' => array('href' => '/articles/index/2/page:7/foo:bar')), '7', '/a', '/span', ); $this->assertTags($result, $expected); + + $result = $this->Paginator->next('Next'); + $expected = array( + 'a' => array('href' => '/articles/index/2/page:2/foo:bar', 'class' => 'next'), + 'Next', + '/a' + ); + $this->assertTags($result, $expected); } /** @@ -757,7 +777,7 @@ class PaginatorHelperTest extends CakeTestCase { ) ); $this->Paginator->options(array('url' => array(12, 'page' => 3))); - $result = $this->Paginator->prev('Prev', array('url' => array(12, 'foo' => 'bar'))); + $result = $this->Paginator->prev('Prev', array('url' => array('foo' => 'bar'))); $expected = array( 'a' => array('href' => '/index/12/page:1/limit:10/foo:bar', 'class' => 'prev'), 'Prev',