aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/Wallabag
diff options
context:
space:
mode:
authorCraig Roberts <craig@craig0990.co.uk>2018-04-09 17:24:45 +0800
committerJeremy Benoist <jeremy.benoist@gmail.com>2019-01-22 20:42:24 +0100
commitb32057980e33e7ddd93480017496a589006b8260 (patch)
tree901d98556d378b68c2e654f3c892616b302331aa /tests/Wallabag
parent3527c300215e6e6010efb8bb840b8b6f5c63a1cc (diff)
downloadwallabag-b32057980e33e7ddd93480017496a589006b8260.tar.gz
wallabag-b32057980e33e7ddd93480017496a589006b8260.tar.zst
wallabag-b32057980e33e7ddd93480017496a589006b8260.zip
Fixes [wallabag/wallabag#2611] Add a basic Search REST endpoint
- Adds a new `search` key to `src/Wallabag/ApiBundle/Resources/config/routing_rest.yml` - Reuses the `getBuilderForSearchByUser` method from the EntryRepository - Supports, `term`, `page`, and `perPage` query parameters - Some very basic tests
Diffstat (limited to 'tests/Wallabag')
-rw-r--r--tests/Wallabag/ApiBundle/Controller/SearchRestControllerTest.php73
1 files changed, 73 insertions, 0 deletions
diff --git a/tests/Wallabag/ApiBundle/Controller/SearchRestControllerTest.php b/tests/Wallabag/ApiBundle/Controller/SearchRestControllerTest.php
new file mode 100644
index 00000000..5900ae53
--- /dev/null
+++ b/tests/Wallabag/ApiBundle/Controller/SearchRestControllerTest.php
@@ -0,0 +1,73 @@
1<?php
2
3namespace Tests\Wallabag\ApiBundle\Controller;
4
5use Tests\Wallabag\ApiBundle\WallabagApiTestCase;
6use Wallabag\CoreBundle\Entity\Entry;
7use Wallabag\CoreBundle\Entity\Tag;
8use Wallabag\CoreBundle\Helper\ContentProxy;
9use Wallabag\UserBundle\Entity\User;
10
11class SearchRestControllerTest extends WallabagApiTestCase
12{
13 public function testGetSearchWithFullOptions()
14 {
15 $this->client->request('GET', '/api/search', [
16 'page' => 1,
17 'perPage' => 2,
18 'term' => 'entry' // 6 results
19 ]);
20
21 $this->assertSame(200, $this->client->getResponse()->getStatusCode());
22
23 $content = json_decode($this->client->getResponse()->getContent(), true);
24
25 $this->assertGreaterThanOrEqual(1, count($content));
26 $this->assertArrayHasKey('items', $content['_embedded']);
27 $this->assertGreaterThanOrEqual(0, $content['total']);
28 $this->assertSame(1, $content['page']);
29 $this->assertSame(2, $content['limit']);
30 $this->assertGreaterThanOrEqual(1, $content['pages']);
31
32 $this->assertArrayHasKey('_links', $content);
33 $this->assertArrayHasKey('self', $content['_links']);
34 $this->assertArrayHasKey('first', $content['_links']);
35 $this->assertArrayHasKey('last', $content['_links']);
36
37 foreach (['self', 'first', 'last'] as $link) {
38 $this->assertArrayHasKey('href', $content['_links'][$link]);
39 $this->assertContains('term=entry', $content['_links'][$link]['href']);
40 }
41
42 $this->assertSame('application/json', $this->client->getResponse()->headers->get('Content-Type'));
43 }
44
45 public function testGetSearchWithNoLimit()
46 {
47 $this->client->request('GET', '/api/search', [
48 'term' => 'entry'
49 ]);
50
51 $this->assertSame(200, $this->client->getResponse()->getStatusCode());
52
53 $content = json_decode($this->client->getResponse()->getContent(), true);
54
55 $this->assertGreaterThanOrEqual(1, count($content));
56 $this->assertArrayHasKey('items', $content['_embedded']);
57 $this->assertGreaterThanOrEqual(0, $content['total']);
58 $this->assertSame(1, $content['page']);
59 $this->assertGreaterThanOrEqual(1, $content['pages']);
60
61 $this->assertArrayHasKey('_links', $content);
62 $this->assertArrayHasKey('self', $content['_links']);
63 $this->assertArrayHasKey('first', $content['_links']);
64 $this->assertArrayHasKey('last', $content['_links']);
65
66 foreach (['self', 'first', 'last'] as $link) {
67 $this->assertArrayHasKey('href', $content['_links'][$link]);
68 $this->assertContains('term=entry', $content['_links'][$link]['href']);
69 }
70
71 $this->assertSame('application/json', $this->client->getResponse()->headers->get('Content-Type'));
72 }
73}