mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
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:
parent
3f4be3bc38
commit
8f72b696a0
2 changed files with 23 additions and 5 deletions
|
@ -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
|
||||
*
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue