]> git.immae.eu Git - github/wallabag/wallabag.git/commitdiff
Fix API pagination is broken if perPage is custom value 3096/head
authoradev <adev2000@gmail.com>
Mon, 8 May 2017 14:27:16 +0000 (16:27 +0200)
committeradev <adev2000@gmail.com>
Mon, 8 May 2017 14:27:16 +0000 (16:27 +0200)
Fix #2720

src/Wallabag/ApiBundle/Controller/EntryRestController.php
tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php

index 2c2ec0c106ac1d72073649907f45a634ff7ad2ba..c544815ebc7dee9bb308787940559ee376565af3 100644 (file)
@@ -98,12 +98,13 @@ class EntryRestController extends WallabagRestController
         $tags = $request->query->get('tags', '');
         $since = $request->query->get('since', 0);
 
+        /** @var \Pagerfanta\Pagerfanta $pager */
         $pager = $this->getDoctrine()
             ->getRepository('WallabagCoreBundle:Entry')
             ->findEntries($this->getUser()->getId(), $isArchived, $isStarred, $sort, $order, $since, $tags);
 
-        $pager->setCurrentPage($page);
         $pager->setMaxPerPage($perPage);
+        $pager->setCurrentPage($page);
 
         $pagerfantaFactory = new PagerfantaFactory('page', 'perPage');
         $paginatedCollection = $pagerfantaFactory->createRepresentation(
index 409a82914680f8618139ced4632491fd61f34dc2..63d70bd9bb3b1c2ef51f59a6e1c05921e0cd4c88 100644 (file)
@@ -156,6 +156,22 @@ class EntryRestControllerTest extends WallabagApiTestCase
         $this->assertEquals('application/json', $this->client->getResponse()->headers->get('Content-Type'));
     }
 
+    public function testGetEntriesOnPageTwo()
+    {
+        $this->client->request('GET', '/api/entries', [
+            'page' => 2,
+            'perPage' => 2,
+        ]);
+
+        $this->assertEquals(200, $this->client->getResponse()->getStatusCode());
+
+        $content = json_decode($this->client->getResponse()->getContent(), true);
+
+        $this->assertGreaterThanOrEqual(0, $content['total']);
+        $this->assertEquals(2, $content['page']);
+        $this->assertEquals(2, $content['limit']);
+    }
+
     public function testGetStarredEntries()
     {
         $this->client->request('GET', '/api/entries', ['starred' => 1, 'sort' => 'updated']);