aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/Wallabag/ApiBundle/Controller/SearchRestControllerTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'tests/Wallabag/ApiBundle/Controller/SearchRestControllerTest.php')
-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}