Skip to content
Permalink
Browse files

Adding patch from 'grncdr' to allow default direction to be set for s…

…ort links created with PaginatorHelper::sort. Fixes #5151
  • Loading branch information...
markstory committed Aug 27, 2009
1 parent 4f2d415 commit 7c4d60abe8b16fef0cc89596038af5ce8e60e209
Showing with 38 additions and 1 deletion.
  1. +3 −1 cake/libs/view/helpers/paginator.php
  2. +35 −0 cake/tests/cases/libs/view/helpers/paginator.test.php
@@ -233,7 +233,9 @@ function sort($title, $key = null, $options = array()) {
$key = $title;
$title = __(Inflector::humanize(preg_replace('/_id$/', '', $title)), true);
}
$dir = 'asc';
$dir = isset($options['direction']) ? $options['direction'] : 'asc';
unset($options['direction']);
$sortKey = $this->sortKey($options['model']);
$isSorted = ($sortKey === $key || $sortKey === $this->defaultModel() . '.' . $key);
@@ -199,6 +199,41 @@ function testSortLinks() {
$this->assertPattern('/\/accounts\/index\/param\/page:1\/sort:title\/direction:desc" class="asc">Title<\/a>$/', $result);
}
/**
* testSortLinksUsingDirectionOption method
*
* @access public
* @return void
*/
function testSortLinksUsingDirectionOption(){
Router::reload();
Router::parse('/');
Router::setRequestInfo(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())
));
$this->Paginator->options(array('url' => array('param')));
$result = $this->Paginator->sort('TestTitle', 'title', array('direction' => 'desc'));
$expected = array(
'a' => array('href' => '/accounts/index/param/page:1/sort:title/direction:desc'),
'TestTitle',
'/a'
);
$this->assertTags($result, $expected);
$result = $this->Paginator->sort(array('asc' => 'ascending', 'desc' => 'descending'), 'title', array('direction' => 'desc'));
$expected = array(
'a' => array('href' => '/accounts/index/param/page:1/sort:title/direction:desc'),
'descending',
'/a'
);
$this->assertTags($result, $expected);
}
/**
* testSortLinksUsingDotNotation method
*

0 comments on commit 7c4d60a

Please sign in to comment.
You can’t perform that action at this time.