From b32057980e33e7ddd93480017496a589006b8260 Mon Sep 17 00:00:00 2001 From: Craig Roberts Date: Mon, 9 Apr 2018 17:24:45 +0800 Subject: Fixes [wallabag/wallabag#2611] Add a basic Search REST endpoint - 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 --- .../Controller/SearchRestControllerTest.php | 73 ++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 tests/Wallabag/ApiBundle/Controller/SearchRestControllerTest.php (limited to 'tests/Wallabag/ApiBundle/Controller/SearchRestControllerTest.php') diff --git a/tests/Wallabag/ApiBundle/Controller/SearchRestControllerTest.php b/tests/Wallabag/ApiBundle/Controller/SearchRestControllerTest.php new file mode 100644 index 00000000..5900ae53 --- /dev/null +++ b/tests/Wallabag/ApiBundle/Controller/SearchRestControllerTest.php @@ -0,0 +1,73 @@ +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')); + } +} -- cgit v1.2.3 From 9133bd02d11c37c98b2c7c979e363cc7bff8f914 Mon Sep 17 00:00:00 2001 From: Craig Roberts Date: Tue, 10 Apr 2018 19:50:26 +0800 Subject: [wallabag/wallabag#2611] Fix PHPCS lint errors --- tests/Wallabag/ApiBundle/Controller/SearchRestControllerTest.php | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) (limited to 'tests/Wallabag/ApiBundle/Controller/SearchRestControllerTest.php') diff --git a/tests/Wallabag/ApiBundle/Controller/SearchRestControllerTest.php b/tests/Wallabag/ApiBundle/Controller/SearchRestControllerTest.php index 5900ae53..f096f21b 100644 --- a/tests/Wallabag/ApiBundle/Controller/SearchRestControllerTest.php +++ b/tests/Wallabag/ApiBundle/Controller/SearchRestControllerTest.php @@ -4,9 +4,6 @@ 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 { @@ -15,7 +12,7 @@ class SearchRestControllerTest extends WallabagApiTestCase $this->client->request('GET', '/api/search', [ 'page' => 1, 'perPage' => 2, - 'term' => 'entry' // 6 results + 'term' => 'entry', // 6 results ]); $this->assertSame(200, $this->client->getResponse()->getStatusCode()); @@ -45,7 +42,7 @@ class SearchRestControllerTest extends WallabagApiTestCase public function testGetSearchWithNoLimit() { $this->client->request('GET', '/api/search', [ - 'term' => 'entry' + 'term' => 'entry', ]); $this->assertSame(200, $this->client->getResponse()->getStatusCode()); -- cgit v1.2.3 From 019e1acc4962229a538421b6f2b0643d03c1d72c Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Wed, 24 Oct 2018 20:11:45 +0200 Subject: Factorize sendResponse between Api controllers And run newer cs fixer --- tests/Wallabag/ApiBundle/Controller/SearchRestControllerTest.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'tests/Wallabag/ApiBundle/Controller/SearchRestControllerTest.php') diff --git a/tests/Wallabag/ApiBundle/Controller/SearchRestControllerTest.php b/tests/Wallabag/ApiBundle/Controller/SearchRestControllerTest.php index f096f21b..fd524639 100644 --- a/tests/Wallabag/ApiBundle/Controller/SearchRestControllerTest.php +++ b/tests/Wallabag/ApiBundle/Controller/SearchRestControllerTest.php @@ -3,7 +3,6 @@ namespace Tests\Wallabag\ApiBundle\Controller; use Tests\Wallabag\ApiBundle\WallabagApiTestCase; -use Wallabag\CoreBundle\Entity\Entry; class SearchRestControllerTest extends WallabagApiTestCase { @@ -19,7 +18,7 @@ class SearchRestControllerTest extends WallabagApiTestCase $content = json_decode($this->client->getResponse()->getContent(), true); - $this->assertGreaterThanOrEqual(1, count($content)); + $this->assertGreaterThanOrEqual(1, \count($content)); $this->assertArrayHasKey('items', $content['_embedded']); $this->assertGreaterThanOrEqual(0, $content['total']); $this->assertSame(1, $content['page']); @@ -49,7 +48,7 @@ class SearchRestControllerTest extends WallabagApiTestCase $content = json_decode($this->client->getResponse()->getContent(), true); - $this->assertGreaterThanOrEqual(1, count($content)); + $this->assertGreaterThanOrEqual(1, \count($content)); $this->assertArrayHasKey('items', $content['_embedded']); $this->assertGreaterThanOrEqual(0, $content['total']); $this->assertSame(1, $content['page']); -- cgit v1.2.3