aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/Wallabag/ApiBundle/Controller
diff options
context:
space:
mode:
Diffstat (limited to 'tests/Wallabag/ApiBundle/Controller')
-rw-r--r--tests/Wallabag/ApiBundle/Controller/DeveloperControllerTest.php14
-rw-r--r--tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php13
-rw-r--r--tests/Wallabag/ApiBundle/Controller/TagRestControllerTest.php46
-rw-r--r--tests/Wallabag/ApiBundle/Controller/WallabagRestControllerTest.php17
4 files changed, 86 insertions, 4 deletions
diff --git a/tests/Wallabag/ApiBundle/Controller/DeveloperControllerTest.php b/tests/Wallabag/ApiBundle/Controller/DeveloperControllerTest.php
index 090155d7..5586c70d 100644
--- a/tests/Wallabag/ApiBundle/Controller/DeveloperControllerTest.php
+++ b/tests/Wallabag/ApiBundle/Controller/DeveloperControllerTest.php
@@ -56,6 +56,20 @@ class DeveloperControllerTest extends WallabagCoreTestCase
56 $this->assertArrayHasKey('refresh_token', $data); 56 $this->assertArrayHasKey('refresh_token', $data);
57 } 57 }
58 58
59 public function testCreateTokenWithBadClientId()
60 {
61 $client = $this->getClient();
62 $client->request('POST', '/oauth/v2/token', [
63 'grant_type' => 'password',
64 'client_id' => '$WALLABAG_CLIENT_ID',
65 'client_secret' => 'secret',
66 'username' => 'admin',
67 'password' => 'mypassword',
68 ]);
69
70 $this->assertSame(400, $client->getResponse()->getStatusCode());
71 }
72
59 public function testListingClient() 73 public function testListingClient()
60 { 74 {
61 $this->logInAs('admin'); 75 $this->logInAs('admin');
diff --git a/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php b/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php
index 3696f8f9..0b0c0276 100644
--- a/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php
+++ b/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php
@@ -242,6 +242,15 @@ class EntryRestControllerTest extends WallabagApiTestCase
242 $this->assertSame(2, $content['limit']); 242 $this->assertSame(2, $content['limit']);
243 } 243 }
244 244
245 public function testGetStarredEntriesWithBadSort()
246 {
247 $this->client->request('GET', '/api/entries', ['starred' => 1, 'sort' => 'updated', 'order' => 'unknown']);
248
249 $this->assertSame(400, $this->client->getResponse()->getStatusCode());
250
251 $this->assertSame('application/json', $this->client->getResponse()->headers->get('Content-Type'));
252 }
253
245 public function testGetStarredEntries() 254 public function testGetStarredEntries()
246 { 255 {
247 $this->client->request('GET', '/api/entries', ['starred' => 1, 'sort' => 'updated']); 256 $this->client->request('GET', '/api/entries', ['starred' => 1, 'sort' => 'updated']);
@@ -785,7 +794,7 @@ class EntryRestControllerTest extends WallabagApiTestCase
785 $content = json_decode($this->client->getResponse()->getContent(), true); 794 $content = json_decode($this->client->getResponse()->getContent(), true);
786 795
787 $this->assertArrayHasKey('tags', $content); 796 $this->assertArrayHasKey('tags', $content);
788 $this->assertSame($nbTags + 3, \count($content['tags'])); 797 $this->assertCount($nbTags + 3, $content['tags']);
789 798
790 $entryDB = $this->client->getContainer() 799 $entryDB = $this->client->getContainer()
791 ->get('doctrine.orm.entity_manager') 800 ->get('doctrine.orm.entity_manager')
@@ -825,7 +834,7 @@ class EntryRestControllerTest extends WallabagApiTestCase
825 $content = json_decode($this->client->getResponse()->getContent(), true); 834 $content = json_decode($this->client->getResponse()->getContent(), true);
826 835
827 $this->assertArrayHasKey('tags', $content); 836 $this->assertArrayHasKey('tags', $content);
828 $this->assertSame($nbTags - 1, \count($content['tags'])); 837 $this->assertCount($nbTags - 1, $content['tags']);
829 } 838 }
830 839
831 public function testSaveIsArchivedAfterPost() 840 public function testSaveIsArchivedAfterPost()
diff --git a/tests/Wallabag/ApiBundle/Controller/TagRestControllerTest.php b/tests/Wallabag/ApiBundle/Controller/TagRestControllerTest.php
index 430e548d..9daa94cd 100644
--- a/tests/Wallabag/ApiBundle/Controller/TagRestControllerTest.php
+++ b/tests/Wallabag/ApiBundle/Controller/TagRestControllerTest.php
@@ -7,6 +7,8 @@ use Wallabag\CoreBundle\Entity\Tag;
7 7
8class TagRestControllerTest extends WallabagApiTestCase 8class TagRestControllerTest extends WallabagApiTestCase
9{ 9{
10 private $otherUserTagLabel = 'bob';
11
10 public function testGetUserTags() 12 public function testGetUserTags()
11 { 13 {
12 $this->client->request('GET', '/api/tags.json'); 14 $this->client->request('GET', '/api/tags.json');
@@ -19,17 +21,33 @@ class TagRestControllerTest extends WallabagApiTestCase
19 $this->assertArrayHasKey('id', $content[0]); 21 $this->assertArrayHasKey('id', $content[0]);
20 $this->assertArrayHasKey('label', $content[0]); 22 $this->assertArrayHasKey('label', $content[0]);
21 23
24 $tagLabels = array_map(function ($i) {
25 return $i['label'];
26 }, $content);
27
28 $this->assertNotContains($this->otherUserTagLabel, $tagLabels, 'There is a possible tag leak');
29
22 return end($content); 30 return end($content);
23 } 31 }
24 32
25 public function testDeleteUserTag() 33 public function testDeleteUserTag()
26 { 34 {
35 $em = $this->client->getContainer()->get('doctrine.orm.entity_manager');
36 $entry = $this->client->getContainer()
37 ->get('doctrine.orm.entity_manager')
38 ->getRepository('WallabagCoreBundle:Entry')
39 ->findOneWithTags($this->user->getId());
40
41 $entry = $entry[0];
42
27 $tagLabel = 'tagtest'; 43 $tagLabel = 'tagtest';
28 $tag = new Tag(); 44 $tag = new Tag();
29 $tag->setLabel($tagLabel); 45 $tag->setLabel($tagLabel);
30
31 $em = $this->client->getContainer()->get('doctrine.orm.entity_manager');
32 $em->persist($tag); 46 $em->persist($tag);
47
48 $entry->addTag($tag);
49
50 $em->persist($entry);
33 $em->flush(); 51 $em->flush();
34 $em->clear(); 52 $em->clear();
35 53
@@ -53,6 +71,16 @@ class TagRestControllerTest extends WallabagApiTestCase
53 $this->assertNull($tag, $tagLabel . ' was removed because it begun an orphan tag'); 71 $this->assertNull($tag, $tagLabel . ' was removed because it begun an orphan tag');
54 } 72 }
55 73
74 public function testDeleteOtherUserTag()
75 {
76 $em = $this->client->getContainer()->get('doctrine.orm.entity_manager');
77 $tag = $em->getRepository('WallabagCoreBundle:Tag')->findOneByLabel($this->otherUserTagLabel);
78
79 $this->client->request('DELETE', '/api/tags/' . $tag->getId() . '.json');
80
81 $this->assertSame(404, $this->client->getResponse()->getStatusCode());
82 }
83
56 public function dataForDeletingTagByLabel() 84 public function dataForDeletingTagByLabel()
57 { 85 {
58 return [ 86 return [
@@ -112,6 +140,13 @@ class TagRestControllerTest extends WallabagApiTestCase
112 $this->assertSame(404, $this->client->getResponse()->getStatusCode()); 140 $this->assertSame(404, $this->client->getResponse()->getStatusCode());
113 } 141 }
114 142
143 public function testDeleteTagByLabelOtherUser()
144 {
145 $this->client->request('DELETE', '/api/tag/label.json', ['tag' => $this->otherUserTagLabel]);
146
147 $this->assertSame(404, $this->client->getResponse()->getStatusCode());
148 }
149
115 /** 150 /**
116 * @dataProvider dataForDeletingTagByLabel 151 * @dataProvider dataForDeletingTagByLabel
117 */ 152 */
@@ -180,4 +215,11 @@ class TagRestControllerTest extends WallabagApiTestCase
180 215
181 $this->assertSame(404, $this->client->getResponse()->getStatusCode()); 216 $this->assertSame(404, $this->client->getResponse()->getStatusCode());
182 } 217 }
218
219 public function testDeleteTagsByLabelOtherUser()
220 {
221 $this->client->request('DELETE', '/api/tags/label.json', ['tags' => $this->otherUserTagLabel]);
222
223 $this->assertSame(404, $this->client->getResponse()->getStatusCode());
224 }
183} 225}
diff --git a/tests/Wallabag/ApiBundle/Controller/WallabagRestControllerTest.php b/tests/Wallabag/ApiBundle/Controller/WallabagRestControllerTest.php
index ac4d6cdc..8b49c0ae 100644
--- a/tests/Wallabag/ApiBundle/Controller/WallabagRestControllerTest.php
+++ b/tests/Wallabag/ApiBundle/Controller/WallabagRestControllerTest.php
@@ -18,4 +18,21 @@ class WallabagRestControllerTest extends WallabagApiTestCase
18 18
19 $this->assertSame($client->getContainer()->getParameter('wallabag_core.version'), $content); 19 $this->assertSame($client->getContainer()->getParameter('wallabag_core.version'), $content);
20 } 20 }
21
22 public function testGetInfo()
23 {
24 // create a new client instead of using $this->client to be sure client isn't authenticated
25 $client = static::createClient();
26 $client->request('GET', '/api/info');
27
28 $this->assertSame(200, $client->getResponse()->getStatusCode());
29
30 $content = json_decode($client->getResponse()->getContent(), true);
31
32 $this->assertArrayHasKey('appname', $content);
33 $this->assertArrayHasKey('version', $content);
34 $this->assertArrayHasKey('allowed_registration', $content);
35
36 $this->assertSame('wallabag', $content['appname']);
37 }
21} 38}