From f24ea59ea4e854d8a699f51a7347af9d4a222de8 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Nicolas=20L=C5=93uillet?= Date: Fri, 28 Oct 2016 10:55:39 +0200 Subject: [PATCH] Fixed migration and added tests --- .../Version20161024212538.php | 1 + .../Controller/AnnotationControllerTest.php | 2 +- .../Controller/DeveloperControllerTest.php | 19 ++++++++++++++++--- 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/app/DoctrineMigrations/Version20161024212538.php b/app/DoctrineMigrations/Version20161024212538.php index 75973b33..b9dc500c 100644 --- a/app/DoctrineMigrations/Version20161024212538.php +++ b/app/DoctrineMigrations/Version20161024212538.php @@ -34,6 +34,7 @@ class Version20161024212538 extends AbstractMigration implements ContainerAwareI { $this->skipIf($this->connection->getDatabasePlatform()->getName() == 'sqlite', 'Migration can only be executed safely on \'mysql\' or \'postgresql\'.'); + $this->addSql('ALTER TABLE '.$this->getTable('oauth2_clients').' ADD `user_id` INT(11) DEFAULT NULL'); $this->addSql('ALTER TABLE '.$this->getTable('oauth2_clients').' ADD CONSTRAINT FK_clients_user_clients FOREIGN KEY (user_id) REFERENCES '.$this->getTable('user').' (id) ON DELETE CASCADE'); } diff --git a/tests/Wallabag/AnnotationBundle/Controller/AnnotationControllerTest.php b/tests/Wallabag/AnnotationBundle/Controller/AnnotationControllerTest.php index cee0b847..81f9e9ec 100644 --- a/tests/Wallabag/AnnotationBundle/Controller/AnnotationControllerTest.php +++ b/tests/Wallabag/AnnotationBundle/Controller/AnnotationControllerTest.php @@ -11,7 +11,7 @@ class AnnotationControllerTest extends WallabagAnnotationTestCase /** * This data provider allow to tests annotation from the : * - API POV (when user use the api to manage annotations) - * - and User POV (when user use the web interface - using javascript - to manage annotations) + * - and User POV (when user use the web interface - using javascript - to manage annotations). */ public function dataForEachAnnotations() { diff --git a/tests/Wallabag/ApiBundle/Controller/DeveloperControllerTest.php b/tests/Wallabag/ApiBundle/Controller/DeveloperControllerTest.php index 95befa9c..6659443b 100644 --- a/tests/Wallabag/ApiBundle/Controller/DeveloperControllerTest.php +++ b/tests/Wallabag/ApiBundle/Controller/DeveloperControllerTest.php @@ -82,11 +82,24 @@ class DeveloperControllerTest extends WallabagCoreTestCase public function testRemoveClient() { - $this->logInAs('admin'); $client = $this->getClient(); $em = $client->getContainer()->get('doctrine.orm.entity_manager'); - $nbClients = $em->getRepository('WallabagApiBundle:Client')->findAll(); + // Try to remove an admin's client with a wrong user + $this->logInAs('bob'); + $client->request('GET', '/developer'); + $this->assertContains('no_client', $client->getResponse()->getContent()); + + // get an ID of a admin's client + $this->logInAs('admin'); + $nbClients = $em->getRepository('WallabagApiBundle:Client')->findByUser($this->getLoggedInUserId()); + + $this->logInAs('bob'); + $client->request('GET', '/developer/client/delete/'.$nbClients[0]->getId()); + $this->assertEquals(403, $client->getResponse()->getStatusCode()); + + // Try to remove the admin's client with the good user + $this->logInAs('admin'); $crawler = $client->request('GET', '/developer'); $link = $crawler @@ -98,7 +111,7 @@ class DeveloperControllerTest extends WallabagCoreTestCase $client->click($link); $this->assertEquals(302, $client->getResponse()->getStatusCode()); - $newNbClients = $em->getRepository('WallabagApiBundle:Client')->findAll(); + $newNbClients = $em->getRepository('WallabagApiBundle:Client')->findByUser($this->getLoggedInUserId()); $this->assertGreaterThan(count($newNbClients), count($nbClients)); } } -- 2.41.0