]>
Commit | Line | Data |
---|---|---|
b3205798 CR |
1 | <?php |
2 | ||
3 | namespace Tests\Wallabag\ApiBundle\Controller; | |
4 | ||
5 | use Tests\Wallabag\ApiBundle\WallabagApiTestCase; | |
6 | use Wallabag\CoreBundle\Entity\Entry; | |
b3205798 CR |
7 | |
8 | class SearchRestControllerTest extends WallabagApiTestCase | |
9 | { | |
10 | public function testGetSearchWithFullOptions() | |
11 | { | |
12 | $this->client->request('GET', '/api/search', [ | |
13 | 'page' => 1, | |
14 | 'perPage' => 2, | |
9133bd02 | 15 | 'term' => 'entry', // 6 results |
b3205798 CR |
16 | ]); |
17 | ||
18 | $this->assertSame(200, $this->client->getResponse()->getStatusCode()); | |
19 | ||
20 | $content = json_decode($this->client->getResponse()->getContent(), true); | |
21 | ||
22 | $this->assertGreaterThanOrEqual(1, count($content)); | |
23 | $this->assertArrayHasKey('items', $content['_embedded']); | |
24 | $this->assertGreaterThanOrEqual(0, $content['total']); | |
25 | $this->assertSame(1, $content['page']); | |
26 | $this->assertSame(2, $content['limit']); | |
27 | $this->assertGreaterThanOrEqual(1, $content['pages']); | |
28 | ||
29 | $this->assertArrayHasKey('_links', $content); | |
30 | $this->assertArrayHasKey('self', $content['_links']); | |
31 | $this->assertArrayHasKey('first', $content['_links']); | |
32 | $this->assertArrayHasKey('last', $content['_links']); | |
33 | ||
34 | foreach (['self', 'first', 'last'] as $link) { | |
35 | $this->assertArrayHasKey('href', $content['_links'][$link]); | |
36 | $this->assertContains('term=entry', $content['_links'][$link]['href']); | |
37 | } | |
38 | ||
39 | $this->assertSame('application/json', $this->client->getResponse()->headers->get('Content-Type')); | |
40 | } | |
41 | ||
42 | public function testGetSearchWithNoLimit() | |
43 | { | |
44 | $this->client->request('GET', '/api/search', [ | |
9133bd02 | 45 | 'term' => 'entry', |
b3205798 CR |
46 | ]); |
47 | ||
48 | $this->assertSame(200, $this->client->getResponse()->getStatusCode()); | |
49 | ||
50 | $content = json_decode($this->client->getResponse()->getContent(), true); | |
51 | ||
52 | $this->assertGreaterThanOrEqual(1, count($content)); | |
53 | $this->assertArrayHasKey('items', $content['_embedded']); | |
54 | $this->assertGreaterThanOrEqual(0, $content['total']); | |
55 | $this->assertSame(1, $content['page']); | |
56 | $this->assertGreaterThanOrEqual(1, $content['pages']); | |
57 | ||
58 | $this->assertArrayHasKey('_links', $content); | |
59 | $this->assertArrayHasKey('self', $content['_links']); | |
60 | $this->assertArrayHasKey('first', $content['_links']); | |
61 | $this->assertArrayHasKey('last', $content['_links']); | |
62 | ||
63 | foreach (['self', 'first', 'last'] as $link) { | |
64 | $this->assertArrayHasKey('href', $content['_links'][$link]); | |
65 | $this->assertContains('term=entry', $content['_links'][$link]['href']); | |
66 | } | |
67 | ||
68 | $this->assertSame('application/json', $this->client->getResponse()->headers->get('Content-Type')); | |
69 | } | |
70 | } |