Added direction check to Controller::paginate(). paginate() now forces 'asc' when wrong. Added tests. Closes #5120

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@7357 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
mark_story 2008-07-24 02:46:39 +00:00
parent b45a369d1d
commit cc098629a6
2 changed files with 8 additions and 0 deletions

View file

@ -913,6 +913,9 @@ class Controller extends Object {
}
if (isset($options['sort']) && isset($options['direction'])) {
if (!in_array(strtolower($options['direction']), array('asc', 'desc'))) {
$options['direction'] = 'asc';
}
$options['order'] = array($options['sort'] => $options['direction']);
} elseif (isset($options['sort'])) {
$options['order'] = array($options['sort'] => 'asc');

View file

@ -323,6 +323,11 @@ class ControllerTest extends CakeTestCase {
$results = Set::extract($Controller->paginate('ControllerPost'), '{n}.ControllerPost.id');
$this->assertEqual($Controller->params['paging']['ControllerPost']['page'], 1);
$this->assertEqual($results, array(1, 2, 3));
$Controller->passedArgs = array('sort' => 'ControllerPost.author_id', 'direction' => 'allYourBase');
$results = Set::extract($Controller->paginate('ControllerPost'), '{n}.ControllerPost.id');
$this->assertEqual($Controller->ControllerPost->lastQuery['order'][0], array('ControllerPost.author_id' => 'asc'));
$this->assertEqual($results, array(1, 3, 2));
}
/**
* testPaginateExtraParams method