Browse Source

Add tests for PaginatorHelper in case of SimplePaginator.

ADmad 6 years ago
parent
commit
8a4c3c7759
1 changed files with 54 additions and 0 deletions
  1. 54 0
      tests/TestCase/View/Helper/PaginatorHelperTest.php

+ 54 - 0
tests/TestCase/View/Helper/PaginatorHelperTest.php

@@ -3174,4 +3174,58 @@ class PaginatorHelperTest extends TestCase
         ];
         $this->assertHtml($expected, $out);
     }
+
+    /**
+     * Test using paging params set by SimplePaginator which doesn't do count query.
+     *
+     * @return void
+     */
+    public function testMethodsWhenThereIsNoPageCount()
+    {
+        $request = new ServerRequest([
+            'url' => '/',
+            'params' => [
+                'paging' => [
+                    'Article' => [
+                        'page' => 1,
+                        'current' => 9,
+                        'count' => null,
+                        'prevPage' => false,
+                        'nextPage' => true,
+                        'pageCount' => 0,
+                        'start' => 1,
+                        'end' => 9,
+                        'sort' => null,
+                        'direction' => null,
+                        'limit' => null,
+                    ]
+                ]
+            ]
+        ]);
+
+        $view = new View($request);
+        $paginator = new PaginatorHelper($view);
+
+        $result = $paginator->first();
+        $this->assertFalse($result);
+
+        $result = $paginator->last();
+        $this->assertFalse($result);
+
+        // Using below methods when SimplePaginator is used makes no practical sense.
+        // The asserts are just to ensure they return a reasonable value.
+
+        $result = $paginator->numbers();
+        $this->assertFalse($result);
+
+        $result = $paginator->hasNext();
+        $this->assertTrue($result);
+
+        $result = $paginator->counter();
+        // counter() sets `pageCount` to 1 if empty.
+        $this->assertEquals('1 of 1', $result);
+
+        $result = $paginator->total();
+        $this->assertSame(0, $result);
+    }
 }