From bb12538fab250b049c79752156623afb81dff327 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Tue, 15 Mar 2022 10:18:28 +0100 Subject: [PATCH] Added new endpoint for API: config --- .../Controller/ConfigRestController.php | 23 +++++++++ .../Resources/config/routing_rest.yml | 5 ++ .../Controller/ConfigRestControllerTest.php | 49 +++++++++++++++++++ 3 files changed, 77 insertions(+) create mode 100644 src/Wallabag/ApiBundle/Controller/ConfigRestController.php create mode 100644 tests/Wallabag/ApiBundle/Controller/ConfigRestControllerTest.php diff --git a/src/Wallabag/ApiBundle/Controller/ConfigRestController.php b/src/Wallabag/ApiBundle/Controller/ConfigRestController.php new file mode 100644 index 000000000..65046ff5f --- /dev/null +++ b/src/Wallabag/ApiBundle/Controller/ConfigRestController.php @@ -0,0 +1,23 @@ +validateAuthentication(); + + return $this->sendResponse($this->getUser()->getConfig()); + } +} diff --git a/src/Wallabag/ApiBundle/Resources/config/routing_rest.yml b/src/Wallabag/ApiBundle/Resources/config/routing_rest.yml index 98efeeb12..7785d25f2 100644 --- a/src/Wallabag/ApiBundle/Resources/config/routing_rest.yml +++ b/src/Wallabag/ApiBundle/Resources/config/routing_rest.yml @@ -32,3 +32,8 @@ user: type: rest resource: "WallabagApiBundle:UserRest" name_prefix: api_ + +config: + type: rest + resource: "WallabagApiBundle:ConfigRest" + name_prefix: api_ diff --git a/tests/Wallabag/ApiBundle/Controller/ConfigRestControllerTest.php b/tests/Wallabag/ApiBundle/Controller/ConfigRestControllerTest.php new file mode 100644 index 000000000..f4ca14ccf --- /dev/null +++ b/tests/Wallabag/ApiBundle/Controller/ConfigRestControllerTest.php @@ -0,0 +1,49 @@ +client->request('GET', '/api/config.json'); + $this->assertSame(200, $this->client->getResponse()->getStatusCode()); + + $content = json_decode($this->client->getResponse()->getContent(), true); + + $this->assertArrayHasKey('id', $content); + $this->assertArrayHasKey('theme', $content); + $this->assertArrayHasKey('items_per_page', $content); + $this->assertArrayHasKey('language', $content); + $this->assertArrayHasKey('feed_token', $content); + $this->assertArrayHasKey('feed_limit', $content); + $this->assertArrayHasKey('reading_speed', $content); + $this->assertArrayHasKey('pocket_consumer_key', $content); + $this->assertArrayHasKey('action_mark_as_read', $content); + $this->assertArrayHasKey('list_mode', $content); + + $this->assertSame('material', $content['theme']); + $this->assertSame(200.0, $content['reading_speed']); + $this->assertSame('xxxxx', $content['pocket_consumer_key']); + + $this->assertSame('application/json', $this->client->getResponse()->headers->get('Content-Type')); + } + + public function testGetConfigWithoutAuthentication() + { + $client = static::createClient(); + $client->request('GET', '/api/config.json'); + $this->assertSame(401, $client->getResponse()->getStatusCode()); + + $content = json_decode($client->getResponse()->getContent(), true); + + $this->assertArrayHasKey('error', $content); + $this->assertArrayHasKey('error_description', $content); + + $this->assertSame('access_denied', $content['error']); + + $this->assertSame('application/json', $client->getResponse()->headers->get('Content-Type')); + } +}