Merge pull request #5970 from cakephp/issue-5964

Allow numeric sorts in PaginatorComponent.
This commit is contained in:
José Lorenzo Rodríguez 2015-02-26 09:01:39 +01:00
commit de255aebb6
2 changed files with 16 additions and 2 deletions

View file

@ -388,6 +388,10 @@ class PaginatorComponent extends Component {
if (!empty($options['order']) && is_array($options['order'])) {
$order = array();
foreach ($options['order'] as $key => $value) {
if (is_int($key)) {
$key = $value;
$value = 'asc';
}
$field = $key;
$alias = $object->alias;
if (strpos($key, '.') !== false) {

View file

@ -454,6 +454,13 @@ class PaginatorComponentTest extends CakeTestCase {
$this->assertEquals(array(1, 2, 3), Hash::extract($result, '{n}.PaginatorControllerPost.id'));
$this->assertTrue(!isset($Controller->PaginatorControllerPost->lastQueries[1]['contain']));
$Controller->Paginator->settings = array(
'order' => array('PaginatorControllerPost.author_id')
);
$result = $Controller->Paginator->paginate('PaginatorControllerPost');
$this->assertEquals(1, $Controller->params['paging']['PaginatorControllerPost']['page']);
$this->assertEquals(array(1, 3, 2), Hash::extract($result, '{n}.PaginatorControllerPost.id'));
$Controller->request->params['named'] = array('page' => '-1');
$Controller->Paginator->settings = array(
'PaginatorControllerPost' => array(
@ -606,7 +613,7 @@ class PaginatorComponentTest extends CakeTestCase {
$Controller->PaginatorControllerPost->order = array('PaginatorControllerPost.id');
$result = $Controller->Paginator->validateSort($Controller->PaginatorControllerPost, array());
$this->assertEmpty($result['order']);
$this->assertEquals(array('PaginatorControllerPost.id' => 'asc'), $result['order']);
$Controller->PaginatorControllerPost->order = 'PaginatorControllerPost.id';
$result = $Controller->Paginator->validateSort($Controller->PaginatorControllerPost, array());
@ -617,7 +624,10 @@ class PaginatorComponentTest extends CakeTestCase {
'PaginatorControllerPost.created' => 'asc'
);
$result = $Controller->Paginator->validateSort($Controller->PaginatorControllerPost, array());
$expected = array('PaginatorControllerPost.created' => 'asc');
$expected = array(
'PaginatorControllerPost.id' => 'asc',
'PaginatorControllerPost.created' => 'asc'
);
$this->assertEquals($expected, $result['order']);
}