Skip to content

Commit

Permalink
passedArgs from current request are auto merged with url options of p…
Browse files Browse the repository at this point in the history
…aginator helper

Signed-off-by: Florian Krämer <florian.kraemer@cakedc.com>
  • Loading branch information
ADmad authored and burzum committed Nov 6, 2009
1 parent ce15cc6 commit 002a01a
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 12 deletions.
11 changes: 10 additions & 1 deletion cake/libs/view/helpers/paginator.php
Expand Up @@ -77,7 +77,7 @@ class PaginatorHelper extends AppHelper {
* Constructor for the helper. Sets up the helper that is used for creating 'AJAX' links.
*
* Use `var $helpers = array('Paginator' => array('ajax' => 'CustomHelper'));` to set a custom Helper
* or choose a non JsHelper Helper. If you want to use a specific library with JsHelper declare JsHelper and its
* or choose a non JsHelper Helper. If you want to use a specific library with JsHelper declare JsHelper and its
* adapter before including PaginatorHelper in your helpers array.
*
* The chosen custom helper must implement a `link()` method.
Expand All @@ -100,6 +100,15 @@ function __construct($config = array()) {
}
}

/**
* Before render callback. Overridden to merge passed args with url options.
*/
function beforeRender() {
$this->options['url'] = array_merge($this->params['pass'], $this->params['named']);

parent::beforeRender();
}

/**
* Gets the current paging parameters from the resultset for the given model
*
Expand Down
67 changes: 56 additions & 11 deletions cake/tests/cases/libs/view/helpers/paginator.test.php
Expand Up @@ -198,7 +198,7 @@ function testSortLinks() {
}


/**
/**
* testSortLinksUsingDirectionOption method
*
* @access public
Expand All @@ -208,7 +208,7 @@ function testSortLinksUsingDirectionOption(){
Router::reload();
Router::parse('/');
Router::setRequestInfo(array(
array('plugin' => null, 'controller' => 'accounts', 'action' => 'index', 'pass' => array(),
array('plugin' => null, 'controller' => 'accounts', 'action' => 'index', 'pass' => array(),
'form' => array(), 'url' => array('url' => 'accounts/', 'mod_rewrite' => 'true'), 'bare' => 0),
array('plugin' => null, 'controller' => null, 'action' => null, 'base' => '/', 'here' => '/accounts/',
'webroot' => '/', 'passedArgs' => array())
Expand Down Expand Up @@ -551,6 +551,51 @@ function testOptions() {
$this->assertEqual($expected, $this->Paginator->params['paging']);
}

/**
* testPassedArgsMergingWithUrlOptions method
*
* @access public
* @return void
*/
function testPassedArgsMergingWithUrlOptions() {
Router::reload();
Router::parse('/');
Router::setRequestInfo(array(
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['pass'] = array(2);
$this->Paginator->params['named'] = array('foo' => 'bar');
$this->Paginator->beforeRender();

$result = $this->Paginator->sort('title');
$expected = array(
'a' => array('href' => '/articles/index/2/page:1/foo:bar/sort:title/direction:asc'),
'Title',
'/a'
);
$this->assertTags($result, $expected);

$result = $this->Paginator->numbers();
$expected = array(
array('span' => array('class' => 'current')), '1', '/span',
' | ',
array('span' => array()), array('a' => array('href' => '/articles/index/2/page:2/foo:bar')), '2', '/a', '/span',
' | ',
array('span' => array()), array('a' => array('href' => '/articles/index/2/page:3/foo:bar')), '3', '/a', '/span',
' | ',
array('span' => array()), array('a' => array('href' => '/articles/index/2/page:4/foo:bar')), '4', '/a', '/span',
' | ',
array('span' => array()), array('a' => array('href' => '/articles/index/2/page:5/foo:bar')), '5', '/a', '/span',
' | ',
array('span' => array()), array('a' => array('href' => '/articles/index/2/page:6/foo:bar')), '6', '/a', '/span',
' | ',
array('span' => array()), array('a' => array('href' => '/articles/index/2/page:7/foo:bar')), '7', '/a', '/span',
);
$this->assertTags($result, $expected);
}

/**
* testPagingLinks method
*
Expand Down Expand Up @@ -690,8 +735,8 @@ function testPagingLinks() {
function testPagingLinksOptionsReplaceEmptyDisabledOptions() {
$this->Paginator->params['paging'] = array(
'Client' => array(
'page' => 1, 'current' => 3, 'count' => 13, 'prevPage' => false,
'nextPage' => true, 'pageCount' => 5,
'page' => 1, 'current' => 3, 'count' => 13, 'prevPage' => false,
'nextPage' => true, 'pageCount' => 5,
'defaults' => array(
'limit' => 3, 'step' => 1, 'order' => array('Client.name' => 'DESC'), 'conditions' => array()
),
Expand Down Expand Up @@ -919,7 +964,7 @@ function testNumbers() {
array('span' => array()), array('a' => array('href' => '/index/page:15')), 'last', '/a', '/span',
);
$this->assertTags($result, $expected);

$this->Paginator->params['paging'] = array('Client' => array(
'page' => 1, 'current' => 3, 'count' => 30, 'prevPage' => false, 'nextPage' => 2, 'pageCount' => 15,
'defaults' => array('limit' => 3, 'step' => 1, 'order' => array('Client.name' => 'DESC'), 'conditions' => array()),
Expand All @@ -946,7 +991,7 @@ function testNumbers() {
array('span' => array()), array('a' => array('href' => '/index/page:9')), '9', '/a', '/span',
);
$this->assertTags($result, $expected);


$this->Paginator->params['paging'] = array('Client' => array(
'page' => 14, 'current' => 3, 'count' => 30, 'prevPage' => false, 'nextPage' => 2, 'pageCount' => 15,
Expand Down Expand Up @@ -1201,7 +1246,7 @@ function testNumbers() {
array('span' => array()), array('a' => array('href' => '/index/page:4/sort:Client.name/direction:DESC')), '4', '/a', '/span',
);
$this->assertTags($result, $expected);


$this->Paginator->params['paging'] = array('Client' => array(
'page' => 4895, 'current' => 10, 'count' => 48962, 'prevPage' => 1, 'nextPage' => 1, 'pageCount' => 4897,
Expand Down Expand Up @@ -1258,7 +1303,7 @@ function testNumbers() {
array('span' => array()), array('a' => array('href' => '/index/page:4897')), '4897', '/a', '/span',
);
$this->assertTags($result, $expected);

$result = $this->Paginator->numbers(array('first' => 5, 'modulus' => 5, 'last' => 5, 'separator' => ' - '));
$expected = array(
array('span' => array()), array('a' => array('href' => '/index/page:1')), '1', '/a', '/span',
Expand All @@ -1284,7 +1329,7 @@ function testNumbers() {
array('span' => array()), array('a' => array('href' => '/index/page:4897')), '4897', '/a', '/span',
);
$this->assertTags($result, $expected);

$this->Paginator->params['paging']['Client']['page'] = 4893;
$result = $this->Paginator->numbers(array('first' => 5, 'modulus' => 4, 'last' => 5, 'separator' => ' - '));
$expected = array(
Expand Down Expand Up @@ -1313,7 +1358,7 @@ function testNumbers() {
array('span' => array()), array('a' => array('href' => '/index/page:4897')), '4897', '/a', '/span',
);
$this->assertTags($result, $expected);

$this->Paginator->params['paging']['Client']['page'] = 58;
$result = $this->Paginator->numbers(array('first' => 5, 'modulus' => 4, 'last' => 5, 'separator' => ' - '));
$expected = array(
Expand Down Expand Up @@ -1348,7 +1393,7 @@ function testNumbers() {
array('span' => array()), array('a' => array('href' => '/index/page:4897')), '4897', '/a', '/span',
);
$this->assertTags($result, $expected);

$this->Paginator->params['paging']['Client']['page'] = 5;
$result = $this->Paginator->numbers(array('first' => 5, 'modulus' => 4, 'last' => 5, 'separator' => ' - '));
$expected = array(
Expand Down

0 comments on commit 002a01a

Please sign in to comment.