Skip to content
Permalink
Browse files

Fixed setting of order in Paginator options when using model's order.…

… Refs f680c76, #3902
  • Loading branch information...
ADmad committed Sep 10, 2013
1 parent 994a5b0 commit 1d0c78572512409857e75ebb1603c94827ce25ff
@@ -361,6 +361,10 @@ public function getDefaults($alias) {
* @return array An array of options with sort + direction removed and replaced with order if possible.
*/
public function validateSort(Model $object, array $options, array $whitelist = array()) {
if (empty($options['order']) && is_array($object->order)) {
$options['order'] = $object->order;
}
if (isset($options['sort'])) {
$direction = null;
if (isset($options['direction'])) {
@@ -401,9 +405,7 @@ public function validateSort(Model $object, array $options, array $whitelist = a
}
$options['order'] = $order;
}
if (empty($options['order']) && !empty($object->order)) {
$options['order'] = $object->order;
}
return $options;
}
@@ -601,7 +601,26 @@ public function testPaginateOrderModelDefault() {
$result = $Controller->Paginator->paginate('PaginatorControllerPost');
$expected = array('2007-03-18 10:43:23', '2007-03-18 10:41:23', '2007-03-18 10:39:23');
$this->assertEquals($expected, Hash::extract($result, '{n}.PaginatorControllerPost.created'));
$this->assertEquals($Controller->PaginatorControllerPost->order, $this->Controller->request['paging']['PaginatorControllerPost']['order']);
$this->assertEquals(
$Controller->PaginatorControllerPost->order,
$Controller->request->paging['PaginatorControllerPost']['options']['order']
);
$Controller->PaginatorControllerPost->order = array('PaginatorControllerPost.id');
$result = $Controller->Paginator->validateSort($Controller->PaginatorControllerPost, array());
$this->assertEmpty($result['order']);
$Controller->PaginatorControllerPost->order = 'PaginatorControllerPost.id';
$results = $Controller->Paginator->validateSort($Controller->PaginatorControllerPost, array());
$this->assertEmpty($result['order']);
$Controller->PaginatorControllerPost->order = array(
'PaginatorControllerPost.id',
'PaginatorControllerPost.created' => 'asc'
);
$result = $Controller->Paginator->validateSort($Controller->PaginatorControllerPost, array());
$expected = array('PaginatorControllerPost.created' => 'asc');
$this->assertEquals($expected, $result['order']);
}
/**

0 comments on commit 1d0c785

Please sign in to comment.
You can’t perform that action at this time.