Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fix sortDir() to read default params.

sortDir() also did not reflect the default paging parameters.
This would result in initial links not matching the query used.

Fixes #2640
  • Loading branch information...
commit dde19f97c784952ba716b841eddd482a2c70184b 1 parent 8f72b69
@markstory markstory authored
View
35 lib/Cake/Test/Case/View/Helper/PaginatorHelperTest.php
@@ -384,6 +384,15 @@ public function testSortKeyFallbackToParams() {
$result = $this->Paginator->sortKey('Article');
$this->assertEquals('Article.body', $result);
+
+ $this->Paginator->request->params['paging']['Article']['order'] = array(
+ 'Article.body' => 'DESC'
+ );
+ $result = $this->Paginator->sortKey();
+ $this->assertEquals('Article.body', $result);
+
+ $result = $this->Paginator->sortKey('Article');
+ $this->assertEquals('Article.body', $result);
}
/**
@@ -456,6 +465,32 @@ public function testSortDir() {
}
/**
+ * Test that sortDir falls back to the default sorting options set
+ * in the $params which are the default pagination options.
+ *
+ * @return void
+ */
+ public function testSortDirFallbackToParams() {
+ $this->Paginator->request->params['paging']['Article']['order'] = array(
+ 'Article.body' => 'ASC'
+ );
+ $result = $this->Paginator->sortDir();
+ $this->assertEquals('asc', $result);
+
+ $result = $this->Paginator->sortDir('Article');
+ $this->assertEquals('asc', $result);
+
+ $this->Paginator->request->params['paging']['Article']['order'] = array(
+ 'Article.body' => 'DESC'
+ );
+ $result = $this->Paginator->sortDir();
+ $this->assertEquals('desc', $result);
+
+ $result = $this->Paginator->sortDir('Article');
+ $this->assertEquals('desc', $result);
+ }
+
+/**
* testSortAdminLinks method
*
* @return void
View
2  lib/Cake/View/Helper/PaginatorHelper.php
@@ -232,6 +232,8 @@ public function sortDir($model = null, $options = array()) {
$dir = strtolower($options['direction']);
} elseif (isset($options['order']) && is_array($options['order'])) {
$dir = strtolower(current($options['order']));
+ } elseif (isset($params['order']) && is_array($params['order'])) {
+ $dir = strtolower(current($params['order']));
}
if ($dir == 'desc') {
Please sign in to comment.
Something went wrong with that request. Please try again.