Skip to content

Commit

Permalink
Fix errors generated when option['order'] is undefined.
Browse files Browse the repository at this point in the history
Fixes #2447
  • Loading branch information
markstory committed Jan 9, 2012
1 parent 3c48552 commit f4c27e0
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/Cake/Controller/Component/PaginatorComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ public function validateSort($object, $options, $whitelist = array()) {
$options['order'] = array($options['sort'] => $direction);
}

if (!empty($whitelist)) {
if (!empty($whitelist) && isset($options['order']) && is_array($options['order'])) {
$field = key($options['order']);
if (!in_array($field, $whitelist)) {
$options['order'] = null;
Expand Down
20 changes: 20 additions & 0 deletions lib/Cake/Test/Case/Controller/Component/PaginatorComponentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -776,6 +776,26 @@ public function testValidateSortMultiple() {
$this->assertEquals($expected, $result['order']);
}

/**
* Test that no sort doesn't trigger an error.
*
* @return void
*/
public function testValidateSortNoSort() {
$model = $this->getMock('Model');
$model->alias = 'model';
$model->expects($this->any())->method('hasField')->will($this->returnValue(true));

$options = array('direction' => 'asc');
$result = $this->Paginator->validateSort($model, $options, array('title', 'id'));
$this->assertFalse(isset($result['order']));

$options = array('order' => 'invalid desc');
$result = $this->Paginator->validateSort($model, $options, array('title', 'id'));

$this->assertEquals($options['order'], $result['order']);
}

/**
* test that maxLimit is respected
*
Expand Down

0 comments on commit f4c27e0

Please sign in to comment.