2018-04-09 09:24:45 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Tests\Wallabag\ApiBundle\Controller;
|
|
|
|
|
|
|
|
use Tests\Wallabag\ApiBundle\WallabagApiTestCase;
|
|
|
|
|
|
|
|
class SearchRestControllerTest extends WallabagApiTestCase
|
|
|
|
{
|
|
|
|
public function testGetSearchWithFullOptions()
|
|
|
|
{
|
|
|
|
$this->client->request('GET', '/api/search', [
|
|
|
|
'page' => 1,
|
|
|
|
'perPage' => 2,
|
2018-04-10 11:50:26 +00:00
|
|
|
'term' => 'entry', // 6 results
|
2018-04-09 09:24:45 +00:00
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertSame(200, $this->client->getResponse()->getStatusCode());
|
|
|
|
|
|
|
|
$content = json_decode($this->client->getResponse()->getContent(), true);
|
|
|
|
|
2018-10-24 18:11:45 +00:00
|
|
|
$this->assertGreaterThanOrEqual(1, \count($content));
|
2018-04-09 09:24:45 +00:00
|
|
|
$this->assertArrayHasKey('items', $content['_embedded']);
|
|
|
|
$this->assertGreaterThanOrEqual(0, $content['total']);
|
|
|
|
$this->assertSame(1, $content['page']);
|
|
|
|
$this->assertSame(2, $content['limit']);
|
|
|
|
$this->assertGreaterThanOrEqual(1, $content['pages']);
|
|
|
|
|
|
|
|
$this->assertArrayHasKey('_links', $content);
|
|
|
|
$this->assertArrayHasKey('self', $content['_links']);
|
|
|
|
$this->assertArrayHasKey('first', $content['_links']);
|
|
|
|
$this->assertArrayHasKey('last', $content['_links']);
|
|
|
|
|
|
|
|
foreach (['self', 'first', 'last'] as $link) {
|
|
|
|
$this->assertArrayHasKey('href', $content['_links'][$link]);
|
2020-06-15 11:37:50 +00:00
|
|
|
$this->assertStringContainsString('term=entry', $content['_links'][$link]['href']);
|
2018-04-09 09:24:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$this->assertSame('application/json', $this->client->getResponse()->headers->get('Content-Type'));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetSearchWithNoLimit()
|
|
|
|
{
|
|
|
|
$this->client->request('GET', '/api/search', [
|
2018-04-10 11:50:26 +00:00
|
|
|
'term' => 'entry',
|
2018-04-09 09:24:45 +00:00
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertSame(200, $this->client->getResponse()->getStatusCode());
|
|
|
|
|
|
|
|
$content = json_decode($this->client->getResponse()->getContent(), true);
|
|
|
|
|
2018-10-24 18:11:45 +00:00
|
|
|
$this->assertGreaterThanOrEqual(1, \count($content));
|
2018-04-09 09:24:45 +00:00
|
|
|
$this->assertArrayHasKey('items', $content['_embedded']);
|
|
|
|
$this->assertGreaterThanOrEqual(0, $content['total']);
|
|
|
|
$this->assertSame(1, $content['page']);
|
|
|
|
$this->assertGreaterThanOrEqual(1, $content['pages']);
|
|
|
|
|
|
|
|
$this->assertArrayHasKey('_links', $content);
|
|
|
|
$this->assertArrayHasKey('self', $content['_links']);
|
|
|
|
$this->assertArrayHasKey('first', $content['_links']);
|
|
|
|
$this->assertArrayHasKey('last', $content['_links']);
|
|
|
|
|
|
|
|
foreach (['self', 'first', 'last'] as $link) {
|
|
|
|
$this->assertArrayHasKey('href', $content['_links'][$link]);
|
2020-06-15 11:37:50 +00:00
|
|
|
$this->assertStringContainsString('term=entry', $content['_links'][$link]['href']);
|
2018-04-09 09:24:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$this->assertSame('application/json', $this->client->getResponse()->headers->get('Content-Type'));
|
|
|
|
}
|
|
|
|
}
|