mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-19 11:06:15 +00:00
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:
parent
b45a369d1d
commit
cc098629a6
2 changed files with 8 additions and 0 deletions
|
@ -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');
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue