Skip to content

Commit

Permalink
Fix sortKey() not looking at default params.
Browse files Browse the repository at this point in the history
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
markstory committed Mar 4, 2012
1 parent 3f4be3b commit 8f72b69
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
17 changes: 17 additions & 0 deletions lib/Cake/Test/Case/View/Helper/PaginatorHelperTest.php
Expand Up @@ -53,6 +53,8 @@ public function setUp() {
'prevPage' => false,
'nextPage' => true,
'pageCount' => 7,
'order' => null,
'limit' => 20,
'options' => array(
'page' => 1,
'conditions' => array()
Expand Down Expand Up @@ -369,6 +371,21 @@ public function testSortKey() {
$this->assertEquals($result, 'Article');
}

/**
* 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
*
Expand Down
11 changes: 6 additions & 5 deletions lib/Cake/View/Helper/PaginatorHelper.php
Expand Up @@ -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;
}
Expand Down

0 comments on commit 8f72b69

Please sign in to comment.