Browse files

Fix sortKey() not looking at default params.

sortKey() only looked at the options values, which do not include
default sorting options declared as settings in the helper.

Fixes #2640
  • Loading branch information...
1 parent 3f4be3b commit 8f72b696a0956fd6e594132c1fd9dfac75b032a7 @markstory markstory committed Mar 3, 2012
Showing with 23 additions and 5 deletions.
  1. +17 −0 lib/Cake/Test/Case/View/Helper/PaginatorHelperTest.php
  2. +6 −5 lib/Cake/View/Helper/PaginatorHelper.php
View
17 lib/Cake/Test/Case/View/Helper/PaginatorHelperTest.php
@@ -53,6 +53,8 @@ public function setUp() {
'prevPage' => false,
'nextPage' => true,
'pageCount' => 7,
+ 'order' => null,
+ 'limit' => 20,
'options' => array(
'page' => 1,
'conditions' => array()
@@ -370,6 +372,21 @@ public function testSortKey() {
}
/**
+ * Test that sortKey falls back to the default sorting options set
+ * in the $params which are the default pagination options.
+ *
+ * @return void
+ */
+ public function testSortKeyFallbackToParams() {
+ $this->Paginator->request->params['paging']['Article']['order'] = 'Article.body';
+ $result = $this->Paginator->sortKey();
+ $this->assertEquals('Article.body', $result);
+
+ $result = $this->Paginator->sortKey('Article');
+ $this->assertEquals('Article.body', $result);
+ }
+
+/**
* testSortDir method
*
* @return void
View
11 lib/Cake/View/Helper/PaginatorHelper.php
@@ -199,13 +199,14 @@ public function sortKey($model = null, $options = array()) {
$params = $this->params($model);
$options = $params['options'];
}
-
if (isset($options['sort']) && !empty($options['sort'])) {
return $options['sort'];
- } elseif (isset($options['order']) && is_array($options['order'])) {
- return key($options['order']);
- } elseif (isset($options['order']) && is_string($options['order'])) {
- return $options['order'];
+ }
+ if (isset($options['order'])) {
+ return is_array($options['order']) ? key($options['order']) : $options['order'];
+ }
+ if (isset($params['order'])) {
+ return is_array($params['order']) ? key($params['order']) : $params['order'];
}
return null;
}

0 comments on commit 8f72b69

Please sign in to comment.