From: Jérémy Benoist Date: Tue, 9 May 2017 07:12:15 +0000 (+0200) Subject: Merge pull request #3096 from aaa2000/fix-api-entries-pagination-with-perpage X-Git-Tag: 2.2.3~8 X-Git-Url: https://git.immae.eu/?a=commitdiff_plain;h=832fbd94c0e9de98d26cc8a939f1e537b8cb00b8;hp=f2beee5185e0bf7f983fb97a34480b4c74d7eb8c;p=github%2Fwallabag%2Fwallabag.git Merge pull request #3096 from aaa2000/fix-api-entries-pagination-with-perpage Fix API pagination is broken if perPage is custom value --- diff --git a/src/Wallabag/ApiBundle/Controller/EntryRestController.php b/src/Wallabag/ApiBundle/Controller/EntryRestController.php index 2c2ec0c1..c544815e 100644 --- a/src/Wallabag/ApiBundle/Controller/EntryRestController.php +++ b/src/Wallabag/ApiBundle/Controller/EntryRestController.php @@ -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( diff --git a/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php b/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php index 409a8291..63d70bd9 100644 --- a/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php +++ b/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php @@ -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']);