Skip to content

Commit

Permalink
Moving test case and adding doc block.
Browse files Browse the repository at this point in the history
  • Loading branch information
markstory committed Dec 20, 2009
1 parent 4ac0a55 commit 7467224
Showing 1 changed file with 26 additions and 21 deletions.
47 changes: 26 additions & 21 deletions cake/tests/cases/libs/controller/controller.test.php
Expand Up @@ -706,6 +706,32 @@ function testDefaultPaginateParams() {
$this->assertEqual($results, array(3, 2, 1));
}

/**
* test paginate() and virtualField interactions
*
* @return void
*/
function testPaginateOrderVirtualField() {
$Controller =& new Controller();
$Controller->uses = array('ControllerPost', 'ControllerComment');
$Controller->params['url'] = array();
$Controller->constructClasses();
$Controller->ControllerPost->virtualFields = array(
'offset_test' => 'ControllerPost.id + 1'
);

$Controller->paginate = array(
'fields' => array('id', 'title', 'offset_test'),
'order' => array('offset_test' => 'DESC')
);
$result = $Controller->paginate('ControllerPost');
$this->assertEqual(Set::extract($result, '{n}.ControllerPost.offset_test'), array(4, 3, 2));

$Controller->passedArgs = array('sort' => 'offset_test', 'direction' => 'asc');
$result = $Controller->paginate('ControllerPost');
$this->assertEqual(Set::extract($result, '{n}.ControllerPost.offset_test'), array(2, 3, 4));
}

/**
* testFlash method
*
Expand Down Expand Up @@ -1281,26 +1307,5 @@ function testControllerHttpCodes() {
$expected = array(404 => 'Sorry Bro');
$this->assertEqual($result, $expected);
}

function testPaginateOrderVirtualField() {
$Controller =& new Controller();
$Controller->uses = array('ControllerPost', 'ControllerComment');
$Controller->params['url'] = array();
$Controller->constructClasses();
$Controller->ControllerPost->virtualFields = array(
'offset_test' => 'ControllerPost.id + 1'
);

$Controller->paginate = array(
'fields' => array('id', 'title', 'offset_test'),
'order' => array('offset_test' => 'DESC')
);
$result = $Controller->paginate('ControllerPost');
$this->assertEqual(Set::extract($result, '{n}.ControllerPost.offset_test'), array(4, 3, 2));

$Controller->passedArgs = array('sort' => 'offset_test', 'direction' => 'asc');
$result = $Controller->paginate('ControllerPost');
$this->assertEqual(Set::extract($result, '{n}.ControllerPost.offset_test'), array(2, 3, 4));
}
}
?>

0 comments on commit 7467224

Please sign in to comment.