Browse Source

Fixed paginate conditions applied twice

Cory Thompson 11 years ago
parent
commit
599a370dca

+ 2 - 1
src/Controller/Component/PaginatorComponent.php

@@ -159,9 +159,10 @@ class PaginatorComponent extends Component {
 
 		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;

+ 16 - 16
tests/TestCase/Controller/Component/PaginatorComponentTest.php

@@ -121,11 +121,11 @@ class PaginatorComponentTest extends TestCase {
 				'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())
@@ -203,13 +203,13 @@ class PaginatorComponentTest extends TestCase {
 			'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([
@@ -233,13 +233,13 @@ class PaginatorComponentTest extends TestCase {
 			'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([
@@ -418,13 +418,13 @@ class PaginatorComponentTest extends TestCase {
  * @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,
@@ -789,13 +789,13 @@ class PaginatorComponentTest extends TestCase {
 			'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);