diff options
Diffstat (limited to 'tests/Wallabag/ApiBundle')
-rw-r--r-- | tests/Wallabag/ApiBundle/Controller/DeveloperControllerTest.php | 104 | ||||
-rw-r--r-- | tests/Wallabag/ApiBundle/Controller/WallabagRestControllerTest.php | 25 |
2 files changed, 129 insertions, 0 deletions
diff --git a/tests/Wallabag/ApiBundle/Controller/DeveloperControllerTest.php b/tests/Wallabag/ApiBundle/Controller/DeveloperControllerTest.php new file mode 100644 index 00000000..95befa9c --- /dev/null +++ b/tests/Wallabag/ApiBundle/Controller/DeveloperControllerTest.php | |||
@@ -0,0 +1,104 @@ | |||
1 | <?php | ||
2 | |||
3 | namespace Tests\Wallabag\ApiBundle\Controller; | ||
4 | |||
5 | use Tests\Wallabag\CoreBundle\WallabagCoreTestCase; | ||
6 | |||
7 | class DeveloperControllerTest extends WallabagCoreTestCase | ||
8 | { | ||
9 | public function testCreateClient() | ||
10 | { | ||
11 | $this->logInAs('admin'); | ||
12 | $client = $this->getClient(); | ||
13 | $em = $client->getContainer()->get('doctrine.orm.entity_manager'); | ||
14 | $nbClients = $em->getRepository('WallabagApiBundle:Client')->findAll(); | ||
15 | |||
16 | $crawler = $client->request('GET', '/developer/client/create'); | ||
17 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | ||
18 | |||
19 | $form = $crawler->filter('button[type=submit]')->form(); | ||
20 | |||
21 | $data = [ | ||
22 | 'client[name]' => 'My app', | ||
23 | ]; | ||
24 | |||
25 | $crawler = $client->submit($form, $data); | ||
26 | |||
27 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | ||
28 | |||
29 | $newNbClients = $em->getRepository('WallabagApiBundle:Client')->findAll(); | ||
30 | $this->assertGreaterThan(count($nbClients), count($newNbClients)); | ||
31 | |||
32 | $this->assertGreaterThan(1, $alert = $crawler->filter('.settings ul li strong')->extract(['_text'])); | ||
33 | $this->assertContains('My app', $alert[0]); | ||
34 | } | ||
35 | |||
36 | /** | ||
37 | * @depends testCreateClient | ||
38 | */ | ||
39 | public function testCreateToken() | ||
40 | { | ||
41 | $client = $this->getClient(); | ||
42 | $em = $client->getContainer()->get('doctrine.orm.entity_manager'); | ||
43 | $apiClient = $em->getRepository('WallabagApiBundle:Client')->findOneByName('My app'); | ||
44 | |||
45 | $client->request('POST', '/oauth/v2/token', [ | ||
46 | 'grant_type' => 'password', | ||
47 | 'client_id' => $apiClient->getPublicId(), | ||
48 | 'client_secret' => $apiClient->getSecret(), | ||
49 | 'username' => 'admin', | ||
50 | 'password' => 'mypassword', | ||
51 | ]); | ||
52 | |||
53 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | ||
54 | |||
55 | $data = json_decode($client->getResponse()->getContent(), true); | ||
56 | $this->assertArrayHasKey('access_token', $data); | ||
57 | $this->assertArrayHasKey('expires_in', $data); | ||
58 | $this->assertArrayHasKey('token_type', $data); | ||
59 | $this->assertArrayHasKey('refresh_token', $data); | ||
60 | } | ||
61 | |||
62 | public function testListingClient() | ||
63 | { | ||
64 | $this->logInAs('admin'); | ||
65 | $client = $this->getClient(); | ||
66 | $em = $client->getContainer()->get('doctrine.orm.entity_manager'); | ||
67 | $nbClients = $em->getRepository('WallabagApiBundle:Client')->findAll(); | ||
68 | |||
69 | $crawler = $client->request('GET', '/developer'); | ||
70 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | ||
71 | $this->assertEquals(count($nbClients), $crawler->filter('ul[class=collapsible] li')->count()); | ||
72 | } | ||
73 | |||
74 | public function testDeveloperHowto() | ||
75 | { | ||
76 | $this->logInAs('admin'); | ||
77 | $client = $this->getClient(); | ||
78 | |||
79 | $crawler = $client->request('GET', '/developer/howto/first-app'); | ||
80 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | ||
81 | } | ||
82 | |||
83 | public function testRemoveClient() | ||
84 | { | ||
85 | $this->logInAs('admin'); | ||
86 | $client = $this->getClient(); | ||
87 | $em = $client->getContainer()->get('doctrine.orm.entity_manager'); | ||
88 | $nbClients = $em->getRepository('WallabagApiBundle:Client')->findAll(); | ||
89 | |||
90 | $crawler = $client->request('GET', '/developer'); | ||
91 | |||
92 | $link = $crawler | ||
93 | ->filter('div[class=collapsible-body] p a') | ||
94 | ->eq(0) | ||
95 | ->link() | ||
96 | ; | ||
97 | |||
98 | $client->click($link); | ||
99 | $this->assertEquals(302, $client->getResponse()->getStatusCode()); | ||
100 | |||
101 | $newNbClients = $em->getRepository('WallabagApiBundle:Client')->findAll(); | ||
102 | $this->assertGreaterThan(count($newNbClients), count($nbClients)); | ||
103 | } | ||
104 | } | ||
diff --git a/tests/Wallabag/ApiBundle/Controller/WallabagRestControllerTest.php b/tests/Wallabag/ApiBundle/Controller/WallabagRestControllerTest.php index 65b65290..5dcb3e00 100644 --- a/tests/Wallabag/ApiBundle/Controller/WallabagRestControllerTest.php +++ b/tests/Wallabag/ApiBundle/Controller/WallabagRestControllerTest.php | |||
@@ -561,6 +561,8 @@ class WallabagRestControllerTest extends WallabagApiTestCase | |||
561 | */ | 561 | */ |
562 | public function testDeleteUserTag($tag) | 562 | public function testDeleteUserTag($tag) |
563 | { | 563 | { |
564 | $tagName = $tag['label']; | ||
565 | |||
564 | $this->client->request('DELETE', '/api/tags/'.$tag['id'].'.json'); | 566 | $this->client->request('DELETE', '/api/tags/'.$tag['id'].'.json'); |
565 | 567 | ||
566 | $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); | 568 | $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); |
@@ -577,6 +579,13 @@ class WallabagRestControllerTest extends WallabagApiTestCase | |||
577 | ->findAllByTagId($this->user->getId(), $tag['id']); | 579 | ->findAllByTagId($this->user->getId(), $tag['id']); |
578 | 580 | ||
579 | $this->assertCount(0, $entries); | 581 | $this->assertCount(0, $entries); |
582 | |||
583 | $tag = $this->client->getContainer() | ||
584 | ->get('doctrine.orm.entity_manager') | ||
585 | ->getRepository('WallabagCoreBundle:Tag') | ||
586 | ->findOneByLabel($tagName); | ||
587 | |||
588 | $this->assertNull($tag, $tagName.' was removed because it begun an orphan tag'); | ||
580 | } | 589 | } |
581 | 590 | ||
582 | public function testDeleteTagByLabel() | 591 | public function testDeleteTagByLabel() |
@@ -794,6 +803,22 @@ class WallabagRestControllerTest extends WallabagApiTestCase | |||
794 | $this->assertEquals(true, $content['exists']); | 803 | $this->assertEquals(true, $content['exists']); |
795 | } | 804 | } |
796 | 805 | ||
806 | public function testGetEntriesExistsWithManyUrls() | ||
807 | { | ||
808 | $url1 = 'http://0.0.0.0/entry2'; | ||
809 | $url2 = 'http://0.0.0.0/entry10'; | ||
810 | $this->client->request('GET', '/api/entries/exists?urls[]='.$url1.'&urls[]='.$url2); | ||
811 | |||
812 | $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); | ||
813 | |||
814 | $content = json_decode($this->client->getResponse()->getContent(), true); | ||
815 | |||
816 | $this->assertArrayHasKey($url1, $content); | ||
817 | $this->assertArrayHasKey($url2, $content); | ||
818 | $this->assertEquals(true, $content[$url1]); | ||
819 | $this->assertEquals(false, $content[$url2]); | ||
820 | } | ||
821 | |||
797 | public function testGetEntriesExistsWhichDoesNotExists() | 822 | public function testGetEntriesExistsWhichDoesNotExists() |
798 | { | 823 | { |
799 | $this->client->request('GET', '/api/entries/exists?url=http://google.com/entry2'); | 824 | $this->client->request('GET', '/api/entries/exists?url=http://google.com/entry2'); |