Fix parameters in API _links

We forgot to pass them to the factory
This commit is contained in:
Jeremy Benoist 2016-10-02 15:41:08 +02:00
parent 1dc3bee6b9
commit c3f8b428dd
No known key found for this signature in database
GPG key ID: BCA73962457ACC3C
3 changed files with 115 additions and 4 deletions

View file

@ -82,8 +82,8 @@ class WallabagRestController extends FOSRestController
$order = $request->query->get('order', 'desc');
$page = (int) $request->query->get('page', 1);
$perPage = (int) $request->query->get('perPage', 30);
$since = $request->query->get('since', 0);
$tags = $request->query->get('tags', '');
$since = $request->query->get('since', 0);
$pager = $this->getDoctrine()
->getRepository('WallabagCoreBundle:Entry')
@ -95,7 +95,20 @@ class WallabagRestController extends FOSRestController
$pagerfantaFactory = new PagerfantaFactory('page', 'perPage');
$paginatedCollection = $pagerfantaFactory->createRepresentation(
$pager,
new Route('api_get_entries', [], UrlGeneratorInterface::ABSOLUTE_URL)
new Route(
'api_get_entries',
[
'archive' => $isArchived,
'starred' => $isStarred,
'sort' => $sort,
'order' => $order,
'page' => $page,
'perPage' => $perPage,
'tags' => $tags,
'since' => $since,
],
UrlGeneratorInterface::ABSOLUTE_URL
)
);
$json = $this->get('serializer')->serialize($paginatedCollection, 'json');

View file

@ -128,7 +128,7 @@ class EntryRepository extends EntityRepository
$qb->andWhere('e.isStarred =:isStarred')->setParameter('isStarred', (bool) $isStarred);
}
if ($since >= 0) {
if ($since > 0) {
$qb->andWhere('e.updatedAt > :since')->setParameter('since', new \DateTime(date('Y-m-d H:i:s', $since)));
}

View file

@ -78,6 +78,53 @@ class WallabagRestControllerTest extends WallabagApiTestCase
);
}
public function testGetEntriesWithFullOptions()
{
$this->client->request('GET', '/api/entries', [
'archive' => 1,
'starred' => 1,
'sort' => 'updated',
'order' => 'asc',
'page' => 1,
'perPage' => 2,
'tags' => 'foo',
'since' => 1443274283,
]);
$this->assertEquals(200, $this->client->getResponse()->getStatusCode());
$content = json_decode($this->client->getResponse()->getContent(), true);
$this->assertGreaterThanOrEqual(1, count($content));
$this->assertArrayHasKey('items', $content['_embedded']);
$this->assertGreaterThanOrEqual(0, $content['total']);
$this->assertEquals(1, $content['page']);
$this->assertEquals(2, $content['limit']);
$this->assertGreaterThanOrEqual(1, $content['pages']);
$this->assertArrayHasKey('_links', $content);
$this->assertArrayHasKey('self', $content['_links']);
$this->assertArrayHasKey('first', $content['_links']);
$this->assertArrayHasKey('last', $content['_links']);
foreach (['self', 'first', 'last'] as $link) {
$this->assertArrayHasKey('href', $content['_links'][$link]);
$this->assertContains('archive=1', $content['_links'][$link]['href']);
$this->assertContains('starred=1', $content['_links'][$link]['href']);
$this->assertContains('sort=updated', $content['_links'][$link]['href']);
$this->assertContains('order=asc', $content['_links'][$link]['href']);
$this->assertContains('tags=foo', $content['_links'][$link]['href']);
$this->assertContains('since=1443274283', $content['_links'][$link]['href']);
}
$this->assertTrue(
$this->client->getResponse()->headers->contains(
'Content-Type',
'application/json'
)
);
}
public function testGetStarredEntries()
{
$this->client->request('GET', '/api/entries', ['starred' => 1, 'sort' => 'updated']);
@ -92,6 +139,17 @@ class WallabagRestControllerTest extends WallabagApiTestCase
$this->assertEquals(1, $content['page']);
$this->assertGreaterThanOrEqual(1, $content['pages']);
$this->assertArrayHasKey('_links', $content);
$this->assertArrayHasKey('self', $content['_links']);
$this->assertArrayHasKey('first', $content['_links']);
$this->assertArrayHasKey('last', $content['_links']);
foreach (['self', 'first', 'last'] as $link) {
$this->assertArrayHasKey('href', $content['_links'][$link]);
$this->assertContains('starred=1', $content['_links'][$link]['href']);
$this->assertContains('sort=updated', $content['_links'][$link]['href']);
}
$this->assertTrue(
$this->client->getResponse()->headers->contains(
'Content-Type',
@ -114,6 +172,16 @@ class WallabagRestControllerTest extends WallabagApiTestCase
$this->assertEquals(1, $content['page']);
$this->assertGreaterThanOrEqual(1, $content['pages']);
$this->assertArrayHasKey('_links', $content);
$this->assertArrayHasKey('self', $content['_links']);
$this->assertArrayHasKey('first', $content['_links']);
$this->assertArrayHasKey('last', $content['_links']);
foreach (['self', 'first', 'last'] as $link) {
$this->assertArrayHasKey('href', $content['_links'][$link]);
$this->assertContains('archive=1', $content['_links'][$link]['href']);
}
$this->assertTrue(
$this->client->getResponse()->headers->contains(
'Content-Type',
@ -136,6 +204,16 @@ class WallabagRestControllerTest extends WallabagApiTestCase
$this->assertEquals(1, $content['page']);
$this->assertGreaterThanOrEqual(1, $content['pages']);
$this->assertArrayHasKey('_links', $content);
$this->assertArrayHasKey('self', $content['_links']);
$this->assertArrayHasKey('first', $content['_links']);
$this->assertArrayHasKey('last', $content['_links']);
foreach (['self', 'first', 'last'] as $link) {
$this->assertArrayHasKey('href', $content['_links'][$link]);
$this->assertContains('tags='.urlencode('foo,bar'), $content['_links'][$link]['href']);
}
$this->assertTrue(
$this->client->getResponse()->headers->contains(
'Content-Type',
@ -146,7 +224,7 @@ class WallabagRestControllerTest extends WallabagApiTestCase
public function testGetDatedEntries()
{
$this->client->request('GET', '/api/entries', ['since' => 1]);
$this->client->request('GET', '/api/entries', ['since' => 1443274283]);
$this->assertEquals(200, $this->client->getResponse()->getStatusCode());
@ -158,6 +236,16 @@ class WallabagRestControllerTest extends WallabagApiTestCase
$this->assertEquals(1, $content['page']);
$this->assertGreaterThanOrEqual(1, $content['pages']);
$this->assertArrayHasKey('_links', $content);
$this->assertArrayHasKey('self', $content['_links']);
$this->assertArrayHasKey('first', $content['_links']);
$this->assertArrayHasKey('last', $content['_links']);
foreach (['self', 'first', 'last'] as $link) {
$this->assertArrayHasKey('href', $content['_links'][$link]);
$this->assertContains('since=1443274283', $content['_links'][$link]['href']);
}
$this->assertTrue(
$this->client->getResponse()->headers->contains(
'Content-Type',
@ -181,6 +269,16 @@ class WallabagRestControllerTest extends WallabagApiTestCase
$this->assertEquals(1, $content['page']);
$this->assertEquals(1, $content['pages']);
$this->assertArrayHasKey('_links', $content);
$this->assertArrayHasKey('self', $content['_links']);
$this->assertArrayHasKey('first', $content['_links']);
$this->assertArrayHasKey('last', $content['_links']);
foreach (['self', 'first', 'last'] as $link) {
$this->assertArrayHasKey('href', $content['_links'][$link]);
$this->assertContains('since='.($future->getTimestamp() + 1000), $content['_links'][$link]['href']);
}
$this->assertTrue(
$this->client->getResponse()->headers->contains(
'Content-Type',