mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Merge pull request #5970 from cakephp/issue-5964
Allow numeric sorts in PaginatorComponent.
This commit is contained in:
commit
de255aebb6
2 changed files with 16 additions and 2 deletions
|
@ -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) {
|
||||
|
|
|
@ -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']);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue