diff options
author | Jérémy Benoist <j0k3r@users.noreply.github.com> | 2019-01-23 09:19:37 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-01-23 09:19:37 +0100 |
commit | c6024246b744e411175318065f7c396bbb5a213e (patch) | |
tree | 635cbb8cd75888990e90c52317db72068196291d /tests/Wallabag/ApiBundle/Controller/SearchRestControllerTest.php | |
parent | a8f4f7665c98753cca15140c283d49e0aa4cd0ab (diff) | |
parent | 801042544444d58580d87d04d5602797027153fc (diff) | |
download | wallabag-2.4.tar.gz wallabag-2.4.tar.zst wallabag-2.4.zip |
Merge pull request #3627 from craig0990/feature/add-search-api-endpoint2.4
Add a basic Search REST endpoint
Diffstat (limited to 'tests/Wallabag/ApiBundle/Controller/SearchRestControllerTest.php')
-rw-r--r-- | tests/Wallabag/ApiBundle/Controller/SearchRestControllerTest.php | 69 |
1 files changed, 69 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..fd524639 --- /dev/null +++ b/tests/Wallabag/ApiBundle/Controller/SearchRestControllerTest.php | |||
@@ -0,0 +1,69 @@ | |||
1 | <?php | ||
2 | |||
3 | namespace Tests\Wallabag\ApiBundle\Controller; | ||
4 | |||
5 | use Tests\Wallabag\ApiBundle\WallabagApiTestCase; | ||
6 | |||
7 | class SearchRestControllerTest extends WallabagApiTestCase | ||
8 | { | ||
9 | public function testGetSearchWithFullOptions() | ||
10 | { | ||
11 | $this->client->request('GET', '/api/search', [ | ||
12 | 'page' => 1, | ||
13 | 'perPage' => 2, | ||
14 | 'term' => 'entry', // 6 results | ||
15 | ]); | ||
16 | |||
17 | $this->assertSame(200, $this->client->getResponse()->getStatusCode()); | ||
18 | |||
19 | $content = json_decode($this->client->getResponse()->getContent(), true); | ||
20 | |||
21 | $this->assertGreaterThanOrEqual(1, \count($content)); | ||
22 | $this->assertArrayHasKey('items', $content['_embedded']); | ||
23 | $this->assertGreaterThanOrEqual(0, $content['total']); | ||
24 | $this->assertSame(1, $content['page']); | ||
25 | $this->assertSame(2, $content['limit']); | ||
26 | $this->assertGreaterThanOrEqual(1, $content['pages']); | ||
27 | |||
28 | $this->assertArrayHasKey('_links', $content); | ||
29 | $this->assertArrayHasKey('self', $content['_links']); | ||
30 | $this->assertArrayHasKey('first', $content['_links']); | ||
31 | $this->assertArrayHasKey('last', $content['_links']); | ||
32 | |||
33 | foreach (['self', 'first', 'last'] as $link) { | ||
34 | $this->assertArrayHasKey('href', $content['_links'][$link]); | ||
35 | $this->assertContains('term=entry', $content['_links'][$link]['href']); | ||
36 | } | ||
37 | |||
38 | $this->assertSame('application/json', $this->client->getResponse()->headers->get('Content-Type')); | ||
39 | } | ||
40 | |||
41 | public function testGetSearchWithNoLimit() | ||
42 | { | ||
43 | $this->client->request('GET', '/api/search', [ | ||
44 | 'term' => 'entry', | ||
45 | ]); | ||
46 | |||
47 | $this->assertSame(200, $this->client->getResponse()->getStatusCode()); | ||
48 | |||
49 | $content = json_decode($this->client->getResponse()->getContent(), true); | ||
50 | |||
51 | $this->assertGreaterThanOrEqual(1, \count($content)); | ||
52 | $this->assertArrayHasKey('items', $content['_embedded']); | ||
53 | $this->assertGreaterThanOrEqual(0, $content['total']); | ||
54 | $this->assertSame(1, $content['page']); | ||
55 | $this->assertGreaterThanOrEqual(1, $content['pages']); | ||
56 | |||
57 | $this->assertArrayHasKey('_links', $content); | ||
58 | $this->assertArrayHasKey('self', $content['_links']); | ||
59 | $this->assertArrayHasKey('first', $content['_links']); | ||
60 | $this->assertArrayHasKey('last', $content['_links']); | ||
61 | |||
62 | foreach (['self', 'first', 'last'] as $link) { | ||
63 | $this->assertArrayHasKey('href', $content['_links'][$link]); | ||
64 | $this->assertContains('term=entry', $content['_links'][$link]['href']); | ||
65 | } | ||
66 | |||
67 | $this->assertSame('application/json', $this->client->getResponse()->headers->get('Content-Type')); | ||
68 | } | ||
69 | } | ||