aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorThomas Citharel <tcit@tcit.fr>2017-05-10 09:38:55 +0200
committerGitHub <noreply@github.com>2017-05-10 09:38:55 +0200
commit91ba9a59754b09f0713161567d36c959c2aa5ffe (patch)
tree20af15a35468b7fb2aadb2405d39bde3f71a5190
parenta2ae05a61ca7aad476a48247a4559c25dd55618d (diff)
parenta9357a8311b2a3a9a114ec8400a9878d5f1f8345 (diff)
downloadwallabag-91ba9a59754b09f0713161567d36c959c2aa5ffe.tar.gz
wallabag-91ba9a59754b09f0713161567d36c959c2aa5ffe.tar.zst
wallabag-91ba9a59754b09f0713161567d36c959c2aa5ffe.zip
Merge pull request #3095 from aaa2000/api-error-on-fail-fetch-content
Create a new entry via API even when its content can't be retrieved
-rw-r--r--src/Wallabag/ApiBundle/Controller/EntryRestController.php17
-rw-r--r--tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php34
2 files changed, 47 insertions, 4 deletions
diff --git a/src/Wallabag/ApiBundle/Controller/EntryRestController.php b/src/Wallabag/ApiBundle/Controller/EntryRestController.php
index c544815e..54c1747c 100644
--- a/src/Wallabag/ApiBundle/Controller/EntryRestController.php
+++ b/src/Wallabag/ApiBundle/Controller/EntryRestController.php
@@ -200,10 +200,19 @@ class EntryRestController extends WallabagRestController
200 $entry = $this->get('wallabag_core.entry_repository')->findByUrlAndUserId($url, $this->getUser()->getId()); 200 $entry = $this->get('wallabag_core.entry_repository')->findByUrlAndUserId($url, $this->getUser()->getId());
201 201
202 if (false === $entry) { 202 if (false === $entry) {
203 $entry = $this->get('wallabag_core.content_proxy')->updateEntry( 203 $entry = new Entry($this->getUser());
204 new Entry($this->getUser()), 204 try {
205 $url 205 $entry = $this->get('wallabag_core.content_proxy')->updateEntry(
206 ); 206 $entry,
207 $url
208 );
209 } catch (\Exception $e) {
210 $this->get('logger')->error('Error while saving an entry', [
211 'exception' => $e,
212 'entry' => $entry,
213 ]);
214 $entry->setUrl($url);
215 }
207 } 216 }
208 217
209 if (!is_null($title)) { 218 if (!is_null($title)) {
diff --git a/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php b/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php
index 63d70bd9..0a65f9ce 100644
--- a/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php
+++ b/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php
@@ -4,6 +4,7 @@ namespace Tests\Wallabag\ApiBundle\Controller;
4 4
5use Tests\Wallabag\ApiBundle\WallabagApiTestCase; 5use Tests\Wallabag\ApiBundle\WallabagApiTestCase;
6use Wallabag\CoreBundle\Entity\Tag; 6use Wallabag\CoreBundle\Entity\Tag;
7use Wallabag\CoreBundle\Helper\ContentProxy;
7 8
8class EntryRestControllerTest extends WallabagApiTestCase 9class EntryRestControllerTest extends WallabagApiTestCase
9{ 10{
@@ -375,6 +376,39 @@ class EntryRestControllerTest extends WallabagApiTestCase
375 $this->assertCount(2, $content['tags']); 376 $this->assertCount(2, $content['tags']);
376 } 377 }
377 378
379 public function testPostEntryWhenFetchContentFails()
380 {
381 /** @var \Symfony\Component\DependencyInjection\Container $container */
382 $container = $this->client->getContainer();
383 $contentProxy = $this->getMockBuilder(ContentProxy::class)
384 ->disableOriginalConstructor()
385 ->setMethods(['updateEntry'])
386 ->getMock();
387 $contentProxy->expects($this->any())
388 ->method('updateEntry')
389 ->willThrowException(new \Exception('Test Fetch content fails'));
390 $container->set('wallabag_core.content_proxy', $contentProxy);
391
392 try {
393 $this->client->request('POST', '/api/entries.json', [
394 'url' => 'http://www.example.com/',
395 ]);
396
397 $this->assertEquals(200, $this->client->getResponse()->getStatusCode());
398 $content = json_decode($this->client->getResponse()->getContent(), true);
399 $this->assertGreaterThan(0, $content['id']);
400 $this->assertEquals('http://www.example.com/', $content['url']);
401 } finally {
402 // Remove the created entry to avoid side effects on other tests
403 if (isset($content['id'])) {
404 $em = $this->client->getContainer()->get('doctrine.orm.entity_manager');
405 $entry = $em->getReference('WallabagCoreBundle:Entry', $content['id']);
406 $em->remove($entry);
407 $em->flush();
408 }
409 }
410 }
411
378 public function testPostArchivedAndStarredEntry() 412 public function testPostArchivedAndStarredEntry()
379 { 413 {
380 $this->client->request('POST', '/api/entries.json', [ 414 $this->client->request('POST', '/api/entries.json', [