mirror of
https://github.com/wallabag/wallabag.git
synced 2024-12-23 16:10:28 +00:00
b32057980e
- Adds a new `search` key to `src/Wallabag/ApiBundle/Resources/config/routing_rest.yml` - Reuses the `getBuilderForSearchByUser` method from the EntryRepository - Supports, `term`, `page`, and `perPage` query parameters - Some very basic tests
73 lines
2.8 KiB
PHP
73 lines
2.8 KiB
PHP
<?php
|
|
|
|
namespace Tests\Wallabag\ApiBundle\Controller;
|
|
|
|
use Tests\Wallabag\ApiBundle\WallabagApiTestCase;
|
|
use Wallabag\CoreBundle\Entity\Entry;
|
|
use Wallabag\CoreBundle\Entity\Tag;
|
|
use Wallabag\CoreBundle\Helper\ContentProxy;
|
|
use Wallabag\UserBundle\Entity\User;
|
|
|
|
class SearchRestControllerTest extends WallabagApiTestCase
|
|
{
|
|
public function testGetSearchWithFullOptions()
|
|
{
|
|
$this->client->request('GET', '/api/search', [
|
|
'page' => 1,
|
|
'perPage' => 2,
|
|
'term' => 'entry' // 6 results
|
|
]);
|
|
|
|
$this->assertSame(200, $this->client->getResponse()->getStatusCode());
|
|
|
|
$content = json_decode($this->client->getResponse()->getContent(), true);
|
|
|
|
$this->assertGreaterThanOrEqual(1, count($content));
|
|
$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]);
|
|
$this->assertContains('term=entry', $content['_links'][$link]['href']);
|
|
}
|
|
|
|
$this->assertSame('application/json', $this->client->getResponse()->headers->get('Content-Type'));
|
|
}
|
|
|
|
public function testGetSearchWithNoLimit()
|
|
{
|
|
$this->client->request('GET', '/api/search', [
|
|
'term' => 'entry'
|
|
]);
|
|
|
|
$this->assertSame(200, $this->client->getResponse()->getStatusCode());
|
|
|
|
$content = json_decode($this->client->getResponse()->getContent(), true);
|
|
|
|
$this->assertGreaterThanOrEqual(1, count($content));
|
|
$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]);
|
|
$this->assertContains('term=entry', $content['_links'][$link]['href']);
|
|
}
|
|
|
|
$this->assertSame('application/json', $this->client->getResponse()->headers->get('Content-Type'));
|
|
}
|
|
}
|