Browse Source

Merge pull request #2408 from ADmad/2.4-paginator-exception

Moved exception throwing to after paging info it set for request.

Fixes #2402
Mark Story 12 years ago
parent
commit
b8268cd055

+ 4 - 3
lib/Cake/Controller/Component/PaginatorComponent.php

@@ -212,9 +212,6 @@ class PaginatorComponent extends Component {
 		$pageCount = intval(ceil($count / $limit));
 		$requestedPage = $page;
 		$page = max(min($page, $pageCount), 1);
-		if ($requestedPage > $page) {
-			throw new NotFoundException();
-		}
 
 		$paging = array(
 			'page' => $page,
@@ -237,6 +234,10 @@ class PaginatorComponent extends Component {
 			array($object->alias => $paging)
 		);
 
+		if ($requestedPage > $page) {
+			throw new NotFoundException();
+		}
+
 		if (
 			!in_array('Paginator', $this->Controller->helpers) &&
 			!array_key_exists('Paginator', $this->Controller->helpers)

+ 11 - 2
lib/Cake/Test/Case/Controller/Component/PaginatorComponentTest.php

@@ -919,7 +919,6 @@ class PaginatorComponentTest extends CakeTestCase {
 /**
  * testOutOfRangePageNumberAndPageCountZero
  *
- * @expectedException NotFoundException
  * @return void
  */
 	public function testOutOfRangePageNumberAndPageCountZero() {
@@ -933,7 +932,17 @@ class PaginatorComponentTest extends CakeTestCase {
 		$Controller->paginate = array(
 			'conditions' => array('PaginatorControllerPost.id >' => 100)
 		);
-		$Controller->Paginator->paginate('PaginatorControllerPost');
+
+		try {
+			$Controller->Paginator->paginate('PaginatorControllerPost');
+			$this->fail();
+		} catch (NotFoundException $e) {
+			$this->assertEquals(
+				1,
+				$Controller->request->params['paging']['PaginatorControllerPost']['page'],
+				'Page number should not be 0'
+			);
+		}
 	}
 
 /**