Skip to content

Commit

Permalink
Fix regression about other aliases to be sorted.
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark Scherer committed May 29, 2015
1 parent a4ad1cb commit 449a857
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/Controller/Component/PaginatorComponent.php
Expand Up @@ -357,7 +357,9 @@ protected function _prefix(Table $object, $order, $validate = false)
}
$correctAlias = ($tableAlias === $alias);

if ($correctAlias && (!$validate || $object->hasField($field))) {
if (!$correctAlias && !$validate) {
$tableOrder[$alias . '.' . $field] = $value;
} elseif ($correctAlias && (!$validate || $object->hasField($field))) {
$tableOrder[$tableAlias . '.' . $field] = $value;
}
}
Expand Down
29 changes: 29 additions & 0 deletions tests/TestCase/Controller/Component/PaginatorComponentTest.php
Expand Up @@ -568,6 +568,35 @@ public function testValidateSortWhitelistTrusted()
$this->assertEquals($expected, $result['order']);
}

/**
* test that multiple fields in the whitelist are not validated and properly aliased.
*
* @return void
*/
public function testValidateSortWhitelistMultiple()
{
$model = $this->getMock('Cake\ORM\Table');
$model->expects($this->any())
->method('alias')
->will($this->returnValue('model'));
$model->expects($this->never())->method('hasField');

$options = [
'order' => [
'body' => 'asc',
'foo.bar' => 'asc'
],
'sortWhitelist' => ['body', 'foo.bar']
];
$result = $this->Paginator->validateSort($model, $options);

$expected = [
'model.body' => 'asc',
'foo.bar' => 'asc'
];
$this->assertEquals($expected, $result['order']);
}

/**
* test that multiple sort works.
*
Expand Down

0 comments on commit 449a857

Please sign in to comment.