diff --git a/app/config/routing.yml b/app/config/routing.yml index 2be74d7f0..750ed4356 100644 --- a/app/config/routing.yml +++ b/app/config/routing.yml @@ -12,6 +12,11 @@ wallabag_user: type: annotation prefix: /users +wallabag_api: + resource: "@WallabagApiBundle/Controller/" + type: annotation + prefix: / + wallabag_api: resource: "@WallabagApiBundle/Resources/config/routing.yml" prefix: / diff --git a/src/Wallabag/CoreBundle/Controller/DeveloperController.php b/src/Wallabag/ApiBundle/Controller/DeveloperController.php similarity index 97% rename from src/Wallabag/CoreBundle/Controller/DeveloperController.php rename to src/Wallabag/ApiBundle/Controller/DeveloperController.php index f3492b74e..5a36a2605 100644 --- a/src/Wallabag/CoreBundle/Controller/DeveloperController.php +++ b/src/Wallabag/ApiBundle/Controller/DeveloperController.php @@ -1,12 +1,12 @@ assertContains('My app', $alert[0]); } + /** + * @depends testCreateClient + */ + public function testCreateToken() + { + $client = $this->getClient(); + $em = $client->getContainer()->get('doctrine.orm.entity_manager'); + $apiClient = $em->getRepository('WallabagApiBundle:Client')->findOneByName('My app'); + + $client->request('POST', '/oauth/v2/token', [ + 'grant_type' => 'password', + 'client_id' => $apiClient->getPublicId(), + 'client_secret' => $apiClient->getSecret(), + 'username' => 'admin', + 'password' => 'mypassword', + ]); + + $this->assertEquals(200, $client->getResponse()->getStatusCode()); + + $data = json_decode($client->getResponse()->getContent(), true); + $this->assertArrayHasKey('access_token', $data); + $this->assertArrayHasKey('expires_in', $data); + $this->assertArrayHasKey('token_type', $data); + $this->assertArrayHasKey('refresh_token', $data); + } + public function testListingClient() { $this->logInAs('admin');