浏览代码

Fix counter.

mscherer 5 年之前
父节点
当前提交
dd72da462e
共有 2 个文件被更改,包括 13 次插入5 次删除
  1. 1 3
      src/View/Helper/FormatHelper.php
  2. 12 2
      tests/TestCase/View/Helper/FormatHelperTest.php

+ 1 - 3
src/View/Helper/FormatHelper.php

@@ -504,9 +504,7 @@ class FormatHelper extends Helper {
 
 		if ($dir === 'DESC') {
 			$currentCount = $count + ($pageCount - $currentPage) * $limit * $step;
-			if ($pageCount > 1) {
-				$currentCount -= $pageCount * $limit * $step - $totalCount;
-			}
+			$currentCount -= $pageCount * $limit * $step - $totalCount;
 		} else {
 			$currentCount = $count + ($currentPage - 1) * $limit * $step;
 		}

+ 12 - 2
tests/TestCase/View/Helper/FormatHelperTest.php

@@ -249,7 +249,7 @@ class FormatHelperTest extends TestCase {
 	 * @return void
 	 */
 	public function testAbsolutePaginateCountDesc() {
-		// 2nd element on page 1
+		// 2nd element on page 1/3
 		$paginator = [
 			'page' => 1,
 			'pageCount' => 3,
@@ -259,7 +259,7 @@ class FormatHelperTest extends TestCase {
 		$result = $this->Format->absolutePaginateCount($paginator, 2, 'DESC');
 		$this->assertSame(24, $result);
 
-		// 3rd element on page 3
+		// 3rd element on page 3/3
 		$paginator = [
 			'page' => 3,
 			'pageCount' => 3,
@@ -268,6 +268,16 @@ class FormatHelperTest extends TestCase {
 		];
 		$result = $this->Format->absolutePaginateCount($paginator, 3, 'DESC');
 		$this->assertSame(3, $result);
+
+		// 2nd element on page 1/1
+		$paginator = [
+			'page' => 1,
+			'pageCount' => 1,
+			'count' => 9,
+			'perPage' => 10,
+		];
+		$result = $this->Format->absolutePaginateCount($paginator, 2, 'DESC');
+		$this->assertSame(8, $result);
 	}
 
 	/**