aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--src/Wallabag/ApiBundle/Controller/WallabagRestController.php32
-rw-r--r--src/Wallabag/CoreBundle/Repository/EntryRepository.php2
-rw-r--r--tests/Wallabag/ApiBundle/Controller/WallabagRestControllerTest.php22
-rw-r--r--tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php44
4 files changed, 99 insertions, 1 deletions
diff --git a/src/Wallabag/ApiBundle/Controller/WallabagRestController.php b/src/Wallabag/ApiBundle/Controller/WallabagRestController.php
index dd17ef97..104720a9 100644
--- a/src/Wallabag/ApiBundle/Controller/WallabagRestController.php
+++ b/src/Wallabag/ApiBundle/Controller/WallabagRestController.php
@@ -23,6 +23,38 @@ class WallabagRestController extends FOSRestController
23 } 23 }
24 24
25 /** 25 /**
26 * Check if an entry exist by url.
27 *
28 * @ApiDoc(
29 * parameters={
30 * {"name"="url", "dataType"="string", "required"=true, "format"="An url", "description"="Url to check if it exists"}
31 * }
32 * )
33 *
34 * @return JsonResponse
35 */
36 public function getEntriesExistsAction(Request $request)
37 {
38 $this->validateAuthentication();
39
40 $url = $request->query->get('url', '');
41
42 if (empty($url)) {
43 throw $this->createAccessDeniedException('URL is empty?, logged user id: '.$user->getId());
44 }
45
46 $res = $this->getDoctrine()
47 ->getRepository('WallabagCoreBundle:Entry')
48 ->findByUrlAndUserId($url, $this->getUser()->getId());
49
50 $exists = false === $res ? false : true;
51
52 $json = $this->get('serializer')->serialize(['exists' => $exists], 'json');
53
54 return (new JsonResponse())->setJson($json);
55 }
56
57 /**
26 * Retrieve all entries. It could be filtered by many options. 58 * Retrieve all entries. It could be filtered by many options.
27 * 59 *
28 * @ApiDoc( 60 * @ApiDoc(
diff --git a/src/Wallabag/CoreBundle/Repository/EntryRepository.php b/src/Wallabag/CoreBundle/Repository/EntryRepository.php
index 302e5a53..1b023e96 100644
--- a/src/Wallabag/CoreBundle/Repository/EntryRepository.php
+++ b/src/Wallabag/CoreBundle/Repository/EntryRepository.php
@@ -281,7 +281,7 @@ class EntryRepository extends EntityRepository
281 public function findByUrlAndUserId($url, $userId) 281 public function findByUrlAndUserId($url, $userId)
282 { 282 {
283 $res = $this->createQueryBuilder('e') 283 $res = $this->createQueryBuilder('e')
284 ->where('e.url = :url')->setParameter('url', $url) 284 ->where('e.url = :url')->setParameter('url', urldecode($url))
285 ->andWhere('e.user = :user_id')->setParameter('user_id', $userId) 285 ->andWhere('e.user = :user_id')->setParameter('user_id', $userId)
286 ->getQuery() 286 ->getQuery()
287 ->getResult(); 287 ->getResult();
diff --git a/tests/Wallabag/ApiBundle/Controller/WallabagRestControllerTest.php b/tests/Wallabag/ApiBundle/Controller/WallabagRestControllerTest.php
index 101c20eb..9b5760bc 100644
--- a/tests/Wallabag/ApiBundle/Controller/WallabagRestControllerTest.php
+++ b/tests/Wallabag/ApiBundle/Controller/WallabagRestControllerTest.php
@@ -684,4 +684,26 @@ class WallabagRestControllerTest extends WallabagApiTestCase
684 684
685 $this->assertEquals(true, $content['is_starred']); 685 $this->assertEquals(true, $content['is_starred']);
686 } 686 }
687
688 public function testGetEntriesExists()
689 {
690 $this->client->request('GET', '/api/entries/exists?url=http://0.0.0.0/entry2');
691
692 $this->assertEquals(200, $this->client->getResponse()->getStatusCode());
693
694 $content = json_decode($this->client->getResponse()->getContent(), true);
695
696 $this->assertEquals(true, $content['exists']);
697 }
698
699 public function testGetEntriesExistsWhichDoesNotExists()
700 {
701 $this->client->request('GET', '/api/entries/exists?url=http://google.com/entry2');
702
703 $this->assertEquals(200, $this->client->getResponse()->getStatusCode());
704
705 $content = json_decode($this->client->getResponse()->getContent(), true);
706
707 $this->assertEquals(false, $content['exists']);
708 }
687} 709}
diff --git a/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php b/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php
index 053aa679..c40e10a5 100644
--- a/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php
+++ b/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php
@@ -160,6 +160,50 @@ class EntryControllerTest extends WallabagCoreTestCase
160 $this->assertContains('/view/', $client->getResponse()->getTargetUrl()); 160 $this->assertContains('/view/', $client->getResponse()->getTargetUrl());
161 } 161 }
162 162
163 public function testPostNewOkUrlExistWithAccent()
164 {
165 $this->logInAs('admin');
166 $client = $this->getClient();
167
168 $url = 'http://www.aritylabs.com/post/106091708292/des-contr%C3%B4leurs-optionnels-gr%C3%A2ce-%C3%A0-constmissing';
169
170 $crawler = $client->request('GET', '/new');
171
172 $this->assertEquals(200, $client->getResponse()->getStatusCode());
173
174 $form = $crawler->filter('form[name=entry]')->form();
175
176 $data = [
177 'entry[url]' => $url,
178 ];
179
180 $client->submit($form, $data);
181
182 $crawler = $client->request('GET', '/new');
183
184 $this->assertEquals(200, $client->getResponse()->getStatusCode());
185
186 $form = $crawler->filter('form[name=entry]')->form();
187
188 $data = [
189 'entry[url]' => $url,
190 ];
191
192 $client->submit($form, $data);
193
194 $this->assertEquals(302, $client->getResponse()->getStatusCode());
195 $this->assertContains('/view/', $client->getResponse()->getTargetUrl());
196
197 $em = $client->getContainer()
198 ->get('doctrine.orm.entity_manager');
199 $entry = $em
200 ->getRepository('WallabagCoreBundle:Entry')
201 ->findOneByUrl(urldecode($url));
202
203 $em->remove($entry);
204 $em->flush();
205 }
206
163 /** 207 /**
164 * This test will require an internet connection. 208 * This test will require an internet connection.
165 */ 209 */