]> git.immae.eu Git - github/wallabag/wallabag.git/blame - tests/Wallabag/ApiBundle/Controller/SearchRestControllerTest.php
Merge pull request #3627 from craig0990/feature/add-search-api-endpoint
[github/wallabag/wallabag.git] / tests / Wallabag / ApiBundle / Controller / SearchRestControllerTest.php
CommitLineData
b3205798
CR
1<?php
2
3namespace Tests\Wallabag\ApiBundle\Controller;
4
5use Tests\Wallabag\ApiBundle\WallabagApiTestCase;
b3205798
CR
6
7class SearchRestControllerTest extends WallabagApiTestCase
8{
9 public function testGetSearchWithFullOptions()
10 {
11 $this->client->request('GET', '/api/search', [
12 'page' => 1,
13 'perPage' => 2,
9133bd02 14 'term' => 'entry', // 6 results
b3205798
CR
15 ]);
16
17 $this->assertSame(200, $this->client->getResponse()->getStatusCode());
18
19 $content = json_decode($this->client->getResponse()->getContent(), true);
20
019e1acc 21 $this->assertGreaterThanOrEqual(1, \count($content));
b3205798
CR
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', [
9133bd02 44 'term' => 'entry',
b3205798
CR
45 ]);
46
47 $this->assertSame(200, $this->client->getResponse()->getStatusCode());
48
49 $content = json_decode($this->client->getResponse()->getContent(), true);
50
019e1acc 51 $this->assertGreaterThanOrEqual(1, \count($content));
b3205798
CR
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}