ticket-3902 - paginator and display of order via model default order

This commit is contained in:
euromark 2013-07-04 13:07:14 +02:00
parent 726738308e
commit f680c763b2
2 changed files with 28 additions and 1 deletions
lib/Cake
Controller/Component
Test/Case/Controller/Component

View file

@ -396,7 +396,9 @@ class PaginatorComponent extends Component {
}
$options['order'] = $order;
}
if (empty($options['order']) && !empty($object->order)) {
$options['order'] = $object->order;
}
return $options;
}

View file

@ -577,6 +577,31 @@ class PaginatorComponentTest extends CakeTestCase {
$this->assertEquals(array(3, 2, 1), $results);
}
/**
* test paginate() and model default order
*
* @return void
*/
public function testPaginateOrderModelDefault() {
$Controller = new PaginatorTestController($this->request);
$Controller->uses = array('PaginatorControllerPost');
$Controller->params['url'] = array();
$Controller->constructClasses();
$Controller->PaginatorControllerPost->order = array(
$Controller->PaginatorControllerPost->alias . '.created' => 'desc'
);
$Controller->Paginator->settings = array(
'fields' => array('id', 'title', 'created'),
'maxLimit' => 10,
'paramType' => 'named'
);
$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']);
}
/**
* test paginate() and virtualField interactions
*