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/EntryRestControllerTest.php55
1 files changed, 53 insertions, 2 deletions
diff --git a/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php b/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php
index 2151f587..8d96d7b8 100644
--- a/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php
+++ b/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php
@@ -987,6 +987,8 @@ class EntryRestControllerTest extends WallabagApiTestCase
987 { 987 {
988 $this->client->request('GET', '/api/entries/exists?url=http://0.0.0.0/entry2'); 988 $this->client->request('GET', '/api/entries/exists?url=http://0.0.0.0/entry2');
989 989
990 $this->client->request('GET', '/api/entries/exists?hashedurl=' . hash('md5', 'http://0.0.0.0/entry2'));
991
990 $this->assertSame(200, $this->client->getResponse()->getStatusCode()); 992 $this->assertSame(200, $this->client->getResponse()->getStatusCode());
991 993
992 $content = json_decode($this->client->getResponse()->getContent(), true); 994 $content = json_decode($this->client->getResponse()->getContent(), true);
@@ -994,10 +996,22 @@ class EntryRestControllerTest extends WallabagApiTestCase
994 $this->assertTrue($content['exists']); 996 $this->assertTrue($content['exists']);
995 } 997 }
996 998
999 public function testGetEntriesExistsWithHash()
1000 {
1001 $this->client->request('GET', '/api/entries/exists?hashedurl=' . hash('md5', 'http://0.0.0.0/entry2'));
1002
1003 $this->assertSame(200, $this->client->getResponse()->getStatusCode());
1004
1005 $content = json_decode($this->client->getResponse()->getContent(), true);
1006
1007 $this->assertSame(2, $content['exists']);
1008 }
1009
997 public function testGetEntriesExistsWithManyUrls() 1010 public function testGetEntriesExistsWithManyUrls()
998 { 1011 {
999 $url1 = 'http://0.0.0.0/entry2'; 1012 $url1 = 'http://0.0.0.0/entry2';
1000 $url2 = 'http://0.0.0.0/entry10'; 1013 $url2 = 'http://0.0.0.0/entry10';
1014
1001 $this->client->request('GET', '/api/entries/exists?urls[]=' . $url1 . '&urls[]=' . $url2 . '&return_id=1'); 1015 $this->client->request('GET', '/api/entries/exists?urls[]=' . $url1 . '&urls[]=' . $url2 . '&return_id=1');
1002 1016
1003 $this->assertSame(200, $this->client->getResponse()->getStatusCode()); 1017 $this->assertSame(200, $this->client->getResponse()->getStatusCode());
@@ -1027,9 +1041,46 @@ class EntryRestControllerTest extends WallabagApiTestCase
1027 $this->assertFalse($content[$url2]); 1041 $this->assertFalse($content[$url2]);
1028 } 1042 }
1029 1043
1044 public function testGetEntriesExistsWithManyUrlsHashed()
1045 {
1046 $url1 = 'http://0.0.0.0/entry2';
1047 $url2 = 'http://0.0.0.0/entry10';
1048 $this->client->request('GET', '/api/entries/exists?hashedurls[]='.hash('md5',$url1).'&hashedurls[]='.hash('md5',$url2) . '&return_id=1');
1049
1050 $this->assertSame(200, $this->client->getResponse()->getStatusCode());
1051
1052 $content = json_decode($this->client->getResponse()->getContent(), true);
1053
1054 $this->assertArrayHasKey($url1, $content);
1055 $this->assertArrayHasKey($url2, $content);
1056 $this->assertSame(2, $content[$url1]);
1057 $this->assertNull($content[$url2]);
1058
1059 $this->assertArrayHasKey(hash('md5', $url1), $content);
1060 $this->assertArrayHasKey(hash('md5', $url2), $content);
1061 $this->assertEquals(2, $content[hash('md5', $url1)]);
1062 $this->assertEquals(false, $content[hash('md5', $url2)]);
1063 }
1064
1065 public function testGetEntriesExistsWithManyUrlsHashedReturnBool()
1066 {
1067 $url1 = 'http://0.0.0.0/entry2';
1068 $url2 = 'http://0.0.0.0/entry10';
1069 $this->client->request('GET', '/api/entries/exists?hashedurls[]='.hash('md5',$url1).'&hashedurls[]='.hash('md5',$url2));
1070
1071 $this->assertSame(200, $this->client->getResponse()->getStatusCode());
1072
1073 $content = json_decode($this->client->getResponse()->getContent(), true);
1074
1075 $this->assertArrayHasKey($url1, $content);
1076 $this->assertArrayHasKey($url2, $content);
1077 $this->assertTrue($content[$url1]);
1078 $this->assertFalse($content[$url2]);
1079 }
1080
1030 public function testGetEntriesExistsWhichDoesNotExists() 1081 public function testGetEntriesExistsWhichDoesNotExists()
1031 { 1082 {
1032 $this->client->request('GET', '/api/entries/exists?url=http://google.com/entry2'); 1083 $this->client->request('GET', '/api/entries/exists?hashedurl='.hash('md5','http://google.com/entry2'));
1033 1084
1034 $this->assertSame(200, $this->client->getResponse()->getStatusCode()); 1085 $this->assertSame(200, $this->client->getResponse()->getStatusCode());
1035 1086
@@ -1040,7 +1091,7 @@ class EntryRestControllerTest extends WallabagApiTestCase
1040 1091
1041 public function testGetEntriesExistsWithNoUrl() 1092 public function testGetEntriesExistsWithNoUrl()
1042 { 1093 {
1043 $this->client->request('GET', '/api/entries/exists?url='); 1094 $this->client->request('GET', '/api/entries/exists?hashedurl=');
1044 1095
1045 $this->assertSame(403, $this->client->getResponse()->getStatusCode()); 1096 $this->assertSame(403, $this->client->getResponse()->getStatusCode());
1046 } 1097 }