aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/Wallabag/ApiBundle/Controller/DeveloperControllerTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'tests/Wallabag/ApiBundle/Controller/DeveloperControllerTest.php')
-rw-r--r--tests/Wallabag/ApiBundle/Controller/DeveloperControllerTest.php40
1 files changed, 28 insertions, 12 deletions
diff --git a/tests/Wallabag/ApiBundle/Controller/DeveloperControllerTest.php b/tests/Wallabag/ApiBundle/Controller/DeveloperControllerTest.php
index 6659443b..d37cbbf9 100644
--- a/tests/Wallabag/ApiBundle/Controller/DeveloperControllerTest.php
+++ b/tests/Wallabag/ApiBundle/Controller/DeveloperControllerTest.php
@@ -3,6 +3,7 @@
3namespace Tests\Wallabag\ApiBundle\Controller; 3namespace Tests\Wallabag\ApiBundle\Controller;
4 4
5use Tests\Wallabag\CoreBundle\WallabagCoreTestCase; 5use Tests\Wallabag\CoreBundle\WallabagCoreTestCase;
6use Wallabag\ApiBundle\Entity\Client;
6 7
7class DeveloperControllerTest extends WallabagCoreTestCase 8class DeveloperControllerTest extends WallabagCoreTestCase
8{ 9{
@@ -33,14 +34,10 @@ class DeveloperControllerTest extends WallabagCoreTestCase
33 $this->assertContains('My app', $alert[0]); 34 $this->assertContains('My app', $alert[0]);
34 } 35 }
35 36
36 /**
37 * @depends testCreateClient
38 */
39 public function testCreateToken() 37 public function testCreateToken()
40 { 38 {
41 $client = $this->getClient(); 39 $client = $this->getClient();
42 $em = $client->getContainer()->get('doctrine.orm.entity_manager'); 40 $apiClient = $this->createApiClientForUser('admin');
43 $apiClient = $em->getRepository('WallabagApiBundle:Client')->findOneByName('My app');
44 41
45 $client->request('POST', '/oauth/v2/token', [ 42 $client->request('POST', '/oauth/v2/token', [
46 'grant_type' => 'password', 43 'grant_type' => 'password',
@@ -83,6 +80,7 @@ class DeveloperControllerTest extends WallabagCoreTestCase
83 public function testRemoveClient() 80 public function testRemoveClient()
84 { 81 {
85 $client = $this->getClient(); 82 $client = $this->getClient();
83 $adminApiClient = $this->createApiClientForUser('admin');
86 $em = $client->getContainer()->get('doctrine.orm.entity_manager'); 84 $em = $client->getContainer()->get('doctrine.orm.entity_manager');
87 85
88 // Try to remove an admin's client with a wrong user 86 // Try to remove an admin's client with a wrong user
@@ -90,12 +88,8 @@ class DeveloperControllerTest extends WallabagCoreTestCase
90 $client->request('GET', '/developer'); 88 $client->request('GET', '/developer');
91 $this->assertContains('no_client', $client->getResponse()->getContent()); 89 $this->assertContains('no_client', $client->getResponse()->getContent());
92 90
93 // get an ID of a admin's client
94 $this->logInAs('admin');
95 $nbClients = $em->getRepository('WallabagApiBundle:Client')->findByUser($this->getLoggedInUserId());
96
97 $this->logInAs('bob'); 91 $this->logInAs('bob');
98 $client->request('GET', '/developer/client/delete/'.$nbClients[0]->getId()); 92 $client->request('GET', '/developer/client/delete/'.$adminApiClient->getId());
99 $this->assertEquals(403, $client->getResponse()->getStatusCode()); 93 $this->assertEquals(403, $client->getResponse()->getStatusCode());
100 94
101 // Try to remove the admin's client with the good user 95 // Try to remove the admin's client with the good user
@@ -111,7 +105,29 @@ class DeveloperControllerTest extends WallabagCoreTestCase
111 $client->click($link); 105 $client->click($link);
112 $this->assertEquals(302, $client->getResponse()->getStatusCode()); 106 $this->assertEquals(302, $client->getResponse()->getStatusCode());
113 107
114 $newNbClients = $em->getRepository('WallabagApiBundle:Client')->findByUser($this->getLoggedInUserId()); 108 $this->assertNull(
115 $this->assertGreaterThan(count($newNbClients), count($nbClients)); 109 $em->getRepository('WallabagApiBundle:Client')->find($adminApiClient->getId()),
110 'The client should have been removed'
111 );
112 }
113
114 /**
115 * @param string $username
116 *
117 * @return Client
118 */
119 private function createApiClientForUser($username)
120 {
121 $client = $this->getClient();
122 $em = $client->getContainer()->get('doctrine.orm.entity_manager');
123 $userManager = $client->getContainer()->get('fos_user.user_manager');
124 $user = $userManager->findUserBy(array('username' => $username));
125 $apiClient = new Client($user);
126 $apiClient->setName('My app');
127 $apiClient->setAllowedGrantTypes(['password']);
128 $em->persist($apiClient);
129 $em->flush();
130
131 return $apiClient;
116 } 132 }
117} 133}