aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php')
-rw-r--r--tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php88
1 files changed, 77 insertions, 11 deletions
diff --git a/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php b/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php
index 2151f587..8cc12ed3 100644
--- a/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php
+++ b/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php
@@ -971,33 +971,49 @@ class EntryRestControllerTest extends WallabagApiTestCase
971 $this->assertGreaterThanOrEqual($now->getTimestamp(), (new \DateTime($content['starred_at']))->getTimestamp()); 971 $this->assertGreaterThanOrEqual($now->getTimestamp(), (new \DateTime($content['starred_at']))->getTimestamp());
972 } 972 }
973 973
974 public function testGetEntriesExistsWithReturnId() 974 public function dataForEntriesExistWithUrl()
975 { 975 {
976 $this->client->request('GET', '/api/entries/exists?url=http://0.0.0.0/entry2&return_id=1'); 976 $url = hash('sha1', 'http://0.0.0.0/entry2');
977 977
978 $this->assertSame(200, $this->client->getResponse()->getStatusCode()); 978 return [
979 979 'with_id' => [
980 $content = json_decode($this->client->getResponse()->getContent(), true); 980 'url' => '/api/entries/exists?url=http://0.0.0.0/entry2&return_id=1',
981 981 'expectedValue' => 2,
982 // it returns a database id, we don't know it, so we only check it's greater than the lowest possible value 982 ],
983 $this->assertGreaterThan(1, $content['exists']); 983 'without_id' => [
984 'url' => '/api/entries/exists?url=http://0.0.0.0/entry2',
985 'expectedValue' => true,
986 ],
987 'hashed_url_with_id' => [
988 'url' => '/api/entries/exists?hashed_url=' . $url . '&return_id=1',
989 'expectedValue' => 2,
990 ],
991 'hashed_url_without_id' => [
992 'url' => '/api/entries/exists?hashed_url=' . $url . '',
993 'expectedValue' => true,
994 ],
995 ];
984 } 996 }
985 997
986 public function testGetEntriesExistsWithoutReturnId() 998 /**
999 * @dataProvider dataForEntriesExistWithUrl
1000 */
1001 public function testGetEntriesExists($url, $expectedValue)
987 { 1002 {
988 $this->client->request('GET', '/api/entries/exists?url=http://0.0.0.0/entry2'); 1003 $this->client->request('GET', $url);
989 1004
990 $this->assertSame(200, $this->client->getResponse()->getStatusCode()); 1005 $this->assertSame(200, $this->client->getResponse()->getStatusCode());
991 1006
992 $content = json_decode($this->client->getResponse()->getContent(), true); 1007 $content = json_decode($this->client->getResponse()->getContent(), true);
993 1008
994 $this->assertTrue($content['exists']); 1009 $this->assertSame($expectedValue, $content['exists']);
995 } 1010 }
996 1011
997 public function testGetEntriesExistsWithManyUrls() 1012 public function testGetEntriesExistsWithManyUrls()
998 { 1013 {
999 $url1 = 'http://0.0.0.0/entry2'; 1014 $url1 = 'http://0.0.0.0/entry2';
1000 $url2 = 'http://0.0.0.0/entry10'; 1015 $url2 = 'http://0.0.0.0/entry10';
1016
1001 $this->client->request('GET', '/api/entries/exists?urls[]=' . $url1 . '&urls[]=' . $url2 . '&return_id=1'); 1017 $this->client->request('GET', '/api/entries/exists?urls[]=' . $url1 . '&urls[]=' . $url2 . '&return_id=1');
1002 1018
1003 $this->assertSame(200, $this->client->getResponse()->getStatusCode()); 1019 $this->assertSame(200, $this->client->getResponse()->getStatusCode());
@@ -1027,6 +1043,38 @@ class EntryRestControllerTest extends WallabagApiTestCase
1027 $this->assertFalse($content[$url2]); 1043 $this->assertFalse($content[$url2]);
1028 } 1044 }
1029 1045
1046 public function testGetEntriesExistsWithManyUrlsHashed()
1047 {
1048 $url1 = 'http://0.0.0.0/entry2';
1049 $url2 = 'http://0.0.0.0/entry10';
1050 $this->client->request('GET', '/api/entries/exists?hashed_urls[]=' . hash('sha1', $url1) . '&hashed_urls[]=' . hash('sha1', $url2) . '&return_id=1');
1051
1052 $this->assertSame(200, $this->client->getResponse()->getStatusCode());
1053
1054 $content = json_decode($this->client->getResponse()->getContent(), true);
1055
1056 $this->assertArrayHasKey(hash('sha1', $url1), $content);
1057 $this->assertArrayHasKey(hash('sha1', $url2), $content);
1058 $this->assertSame(2, $content[hash('sha1', $url1)]);
1059 $this->assertNull($content[hash('sha1', $url2)]);
1060 }
1061
1062 public function testGetEntriesExistsWithManyUrlsHashedReturnBool()
1063 {
1064 $url1 = 'http://0.0.0.0/entry2';
1065 $url2 = 'http://0.0.0.0/entry10';
1066 $this->client->request('GET', '/api/entries/exists?hashed_urls[]=' . hash('sha1', $url1) . '&hashed_urls[]=' . hash('sha1', $url2));
1067
1068 $this->assertSame(200, $this->client->getResponse()->getStatusCode());
1069
1070 $content = json_decode($this->client->getResponse()->getContent(), true);
1071
1072 $this->assertArrayHasKey(hash('sha1', $url1), $content);
1073 $this->assertArrayHasKey(hash('sha1', $url2), $content);
1074 $this->assertTrue($content[hash('sha1', $url1)]);
1075 $this->assertFalse($content[hash('sha1', $url2)]);
1076 }
1077
1030 public function testGetEntriesExistsWhichDoesNotExists() 1078 public function testGetEntriesExistsWhichDoesNotExists()
1031 { 1079 {
1032 $this->client->request('GET', '/api/entries/exists?url=http://google.com/entry2'); 1080 $this->client->request('GET', '/api/entries/exists?url=http://google.com/entry2');
@@ -1038,6 +1086,17 @@ class EntryRestControllerTest extends WallabagApiTestCase
1038 $this->assertFalse($content['exists']); 1086 $this->assertFalse($content['exists']);
1039 } 1087 }
1040 1088
1089 public function testGetEntriesExistsWhichDoesNotExistsWithHashedUrl()
1090 {
1091 $this->client->request('GET', '/api/entries/exists?hashed_url=' . hash('sha1', 'http://google.com/entry2'));
1092
1093 $this->assertSame(200, $this->client->getResponse()->getStatusCode());
1094
1095 $content = json_decode($this->client->getResponse()->getContent(), true);
1096
1097 $this->assertFalse($content['exists']);
1098 }
1099
1041 public function testGetEntriesExistsWithNoUrl() 1100 public function testGetEntriesExistsWithNoUrl()
1042 { 1101 {
1043 $this->client->request('GET', '/api/entries/exists?url='); 1102 $this->client->request('GET', '/api/entries/exists?url=');
@@ -1045,6 +1104,13 @@ class EntryRestControllerTest extends WallabagApiTestCase
1045 $this->assertSame(403, $this->client->getResponse()->getStatusCode()); 1104 $this->assertSame(403, $this->client->getResponse()->getStatusCode());
1046 } 1105 }
1047 1106
1107 public function testGetEntriesExistsWithNoHashedUrl()
1108 {
1109 $this->client->request('GET', '/api/entries/exists?hashed_url=');
1110
1111 $this->assertSame(403, $this->client->getResponse()->getStatusCode());
1112 }
1113
1048 public function testReloadEntryErrorWhileFetching() 1114 public function testReloadEntryErrorWhileFetching()
1049 { 1115 {
1050 $entry = $this->client->getContainer()->get('doctrine.orm.entity_manager') 1116 $entry = $this->client->getContainer()->get('doctrine.orm.entity_manager')