mirror of
https://github.com/wallabag/wallabag.git
synced 2024-11-26 11:01:04 +00:00
Added new endpoint for API: config
This commit is contained in:
parent
88fd7afeb5
commit
bb12538fab
3 changed files with 77 additions and 0 deletions
23
src/Wallabag/ApiBundle/Controller/ConfigRestController.php
Normal file
23
src/Wallabag/ApiBundle/Controller/ConfigRestController.php
Normal file
|
@ -0,0 +1,23 @@
|
|||
<?php
|
||||
|
||||
namespace Wallabag\ApiBundle\Controller;
|
||||
|
||||
use Nelmio\ApiDocBundle\Annotation\ApiDoc;
|
||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||
|
||||
class ConfigRestController extends WallabagRestController
|
||||
{
|
||||
/**
|
||||
* Retrieve configuration for current user.
|
||||
*
|
||||
* @ApiDoc()
|
||||
*
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function getConfigAction()
|
||||
{
|
||||
$this->validateAuthentication();
|
||||
|
||||
return $this->sendResponse($this->getUser()->getConfig());
|
||||
}
|
||||
}
|
|
@ -32,3 +32,8 @@ user:
|
|||
type: rest
|
||||
resource: "WallabagApiBundle:UserRest"
|
||||
name_prefix: api_
|
||||
|
||||
config:
|
||||
type: rest
|
||||
resource: "WallabagApiBundle:ConfigRest"
|
||||
name_prefix: api_
|
||||
|
|
|
@ -0,0 +1,49 @@
|
|||
<?php
|
||||
|
||||
namespace Tests\Wallabag\ApiBundle\Controller;
|
||||
|
||||
use Tests\Wallabag\ApiBundle\WallabagApiTestCase;
|
||||
|
||||
class ConfigRestControllerTest extends WallabagApiTestCase
|
||||
{
|
||||
public function testGetConfig()
|
||||
{
|
||||
$this->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'));
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue