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
This commit is contained in:
mark_story 2012-03-03 23:06:45 -05:00
parent 3f4be3bc38
commit 8f72b696a0
2 changed files with 23 additions and 5 deletions

View file

@ -53,6 +53,8 @@ class PaginatorHelperTest extends CakeTestCase {
'prevPage' => false,
'nextPage' => true,
'pageCount' => 7,
'order' => null,
'limit' => 20,
'options' => array(
'page' => 1,
'conditions' => array()
@ -369,6 +371,21 @@ class PaginatorHelperTest extends CakeTestCase {
$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
*

View file

@ -199,13 +199,14 @@ class PaginatorHelper extends AppHelper {
$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;
}