Skip to content

Commit

Permalink
- Tests for array order syntax fix
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasferreira committed May 26, 2017
1 parent b539161 commit ee1980b
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions lib/Cake/Test/Case/Controller/Component/PaginatorComponentTest.php
Expand Up @@ -320,12 +320,20 @@ public function testPaginate() {

$Controller->PaginatorControllerPost->order = null;

/* ORDER ARRAY FIELD => SORT MODE */
$Controller->Paginator->settings = array(
'order' => array('PaginatorControllerComment.id' => 'ASC')
);
$results = Hash::extract($Controller->Paginator->paginate('PaginatorControllerComment'), '{n}.PaginatorControllerComment.id');
$this->assertEquals(array(1, 2, 3, 4, 5, 6), $results);

/* ORDER ARRAY "FIELD SORT" MODE */
$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')
);
Expand Down Expand Up @@ -619,6 +627,7 @@ public function testPaginateOrderModelDefault() {
$result = $Controller->Paginator->validateSort($Controller->PaginatorControllerPost, array());
$this->assertArrayNotHasKey('order', $result);

/* DEFAULT */
$Controller->PaginatorControllerPost->order = array(
'PaginatorControllerPost.id',
'PaginatorControllerPost.created' => 'asc'
Expand All @@ -629,6 +638,18 @@ public function testPaginateOrderModelDefault() {
'PaginatorControllerPost.created' => 'asc'
);
$this->assertEquals($expected, $result['order']);

/* CLASSIC */
$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']);
}

/**
Expand Down

0 comments on commit ee1980b

Please sign in to comment.