Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
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...
commit 7c4d60abe8b16fef0cc89596038af5ce8e60e209 1 parent 4f2d415
@markstory markstory authored
View
4 cake/libs/view/helpers/paginator.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);
View
35 cake/tests/cases/libs/view/helpers/paginator.test.php
@@ -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
*
Please sign in to comment.
Something went wrong with that request. Please try again.