Permalink
Browse files

Fix errors generated when option['order'] is undefined.

Fixes #2447
  • Loading branch information...
1 parent 3c48552 commit f4c27e04bcad304bf9a3127e778dfce1c82f9ed6 @markstory markstory committed Jan 9, 2012
@@ -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;
@@ -777,6 +777,26 @@ public function testValidateSortMultiple() {
}
/**
+ * 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
*
* @return void

0 comments on commit f4c27e0

Please sign in to comment.