3 namespace Tests\Wallabag\ApiBundle\Controller
;
5 use Tests\Wallabag\ApiBundle\WallabagApiTestCase
;
7 class SearchRestControllerTest
extends WallabagApiTestCase
9 public function testGetSearchWithFullOptions()
11 $this->client
->request('GET', '/api/search', [
14 'term' => 'entry', // 6 results
17 $this->assertSame(200, $this->client
->getResponse()->getStatusCode());
19 $content = json_decode($this->client
->getResponse()->getContent(), true);
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']);
28 $this->assertArrayHasKey('_links', $content);
29 $this->assertArrayHasKey('self', $content['_links']);
30 $this->assertArrayHasKey('first', $content['_links']);
31 $this->assertArrayHasKey('last', $content['_links']);
33 foreach (['self', 'first', 'last'] as $link) {
34 $this->assertArrayHasKey('href', $content['_links'][$link]);
35 $this->assertContains('term=entry', $content['_links'][$link]['href']);
38 $this->assertSame('application/json', $this->client
->getResponse()->headers
->get('Content-Type'));
41 public function testGetSearchWithNoLimit()
43 $this->client
->request('GET', '/api/search', [
47 $this->assertSame(200, $this->client
->getResponse()->getStatusCode());
49 $content = json_decode($this->client
->getResponse()->getContent(), true);
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']);
57 $this->assertArrayHasKey('_links', $content);
58 $this->assertArrayHasKey('self', $content['_links']);
59 $this->assertArrayHasKey('first', $content['_links']);
60 $this->assertArrayHasKey('last', $content['_links']);
62 foreach (['self', 'first', 'last'] as $link) {
63 $this->assertArrayHasKey('href', $content['_links'][$link]);
64 $this->assertContains('term=entry', $content['_links'][$link]['href']);
67 $this->assertSame('application/json', $this->client
->getResponse()->headers
->get('Content-Type'));