Skip to content

Commit

Permalink
Fixed paginate conditions applied twice
Browse files Browse the repository at this point in the history
  • Loading branch information
Cory Thompson committed Dec 18, 2014
1 parent b23f8c4 commit 599a370
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 17 deletions.
3 changes: 2 additions & 1 deletion src/Controller/Component/PaginatorComponent.php
Expand Up @@ -159,9 +159,10 @@ public function paginate($object, array $settings = []) {

if (empty($query)) {
$query = $object->find($finder, $options);
} else {
$query->applyOptions($options);
}

$query->applyOptions($options);
$results = $query->all();
$numResults = count($results);
$count = $numResults ? $query->count() : 0;
Expand Down
32 changes: 16 additions & 16 deletions tests/TestCase/Controller/Component/PaginatorComponentTest.php
Expand Up @@ -121,11 +121,11 @@ public function testPaginateExtraParams() {
'order' => array('PaginatorPosts.id' => 'ASC')
),
);
$table = $this->_getMockPosts(['find']);
$table = $this->_getMockPosts(['query']);
$query = $this->_getMockFindQuery();

$table->expects($this->once())
->method('find')
->with('all')
->method('query')
->will($this->returnValue($query));

$query->expects($this->once())
Expand Down Expand Up @@ -203,13 +203,13 @@ public function testDefaultPaginateParams() {
'maxLimit' => 10,
);

$table = $this->_getMockPosts(['find']);
$table = $this->_getMockPosts(['query']);
$query = $this->_getMockFindQuery();

$table->expects($this->once())
->method('find')
->with('all')
->method('query')
->will($this->returnValue($query));

$query->expects($this->once())
->method('applyOptions')
->with([
Expand All @@ -233,13 +233,13 @@ public function testDefaultPaginateParamsIntoRequest() {
'maxLimit' => 10,
);

$table = $this->_getMockPosts(['find']);
$table = $this->_getMockPosts(['query']);
$query = $this->_getMockFindQuery();

$table->expects($this->once())
->method('find')
->with('all')
->method('query')
->will($this->returnValue($query));

$query->expects($this->once())
->method('applyOptions')
->with([
Expand Down Expand Up @@ -418,13 +418,13 @@ public function testMergeOptionsMaxLimit() {
* @return void
*/
public function testValidateSortInvalid() {
$table = $this->_getMockPosts(['find']);
$table = $this->_getMockPosts(['query']);
$query = $this->_getMockFindQuery();

$table->expects($this->once())
->method('find')
->with('all')
->method('query')
->will($this->returnValue($query));

$query->expects($this->once())->method('applyOptions')
->with([
'limit' => 20,
Expand Down Expand Up @@ -789,13 +789,13 @@ public function testPaginateCustomFindCount() {
'finder' => 'published',
'limit' => 2
);
$table = $this->_getMockPosts(['find']);
$table = $this->_getMockPosts(['query']);
$query = $this->_getMockFindQuery();

$table->expects($this->once())
->method('find')
->with('published')
->method('query')
->will($this->returnValue($query));

$query->expects($this->once())->method('applyOptions')
->with(['limit' => 2, 'page' => 1, 'order' => [], 'whitelist' => ['limit', 'sort', 'page', 'direction']]);
$this->Paginator->paginate($table, $settings);
Expand Down

0 comments on commit 599a370

Please sign in to comment.