Merge pull request #10698 from lucasferreira/2.next

Cake 2.x - Some fix into Paginator component for order / sort classic sintax
This commit is contained in:
Mark Story 2017-06-14 00:13:00 -04:00 committed by GitHub
commit 8289b367f9
2 changed files with 20 additions and 3 deletions

View file

@ -382,13 +382,13 @@ class PaginatorComponent extends Component {
}
return $options;
}
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 = explode(' ', $value);
$key = $field[0];
$value = count($field) === 2 ? trim($field[1]) : 'asc';
}
$field = $key;
$alias = $object->alias;

View file

@ -326,6 +326,12 @@ class PaginatorComponentTest extends CakeTestCase {
$results = Hash::extract($Controller->Paginator->paginate('PaginatorControllerComment'), '{n}.PaginatorControllerComment.id');
$this->assertEquals(array(1, 2, 3, 4, 5, 6), $results);
$Controller->Paginator->settings = array(
'order' => array('PaginatorControllerComment.id DESC')
);
$results = Hash::extract($Controller->Paginator->paginate('PaginatorControllerComment'), '{n}.PaginatorControllerComment.id');
$this->assertEquals(array(6, 5, 4, 3, 2, 1), $results);
$Controller->Paginator->settings = array(
'order' => array('PaginatorControllerPost.id' => 'ASC')
);
@ -629,6 +635,17 @@ class PaginatorComponentTest extends CakeTestCase {
'PaginatorControllerPost.created' => 'asc'
);
$this->assertEquals($expected, $result['order']);
$Controller->PaginatorControllerPost->order = array(
'PaginatorControllerPost.id ASC',
'PaginatorControllerPost.created DESC'
);
$result = $Controller->Paginator->validateSort($Controller->PaginatorControllerPost, array());
$expected = array(
'PaginatorControllerPost.id' => 'ASC',
'PaginatorControllerPost.created' => 'DESC'
);
$this->assertEquals($expected, $result['order']);
}
/**