diff options
author | adev <adev2000@gmail.com> | 2017-05-08 12:35:02 +0200 |
---|---|---|
committer | adev <adev2000@gmail.com> | 2017-05-08 14:57:25 +0200 |
commit | 08f29ae7b6af585f3af1dd2f8b01854fb0985668 (patch) | |
tree | 859985863551dcaf699a5b32a8e8d4afc45e7a78 | |
parent | f2beee5185e0bf7f983fb97a34480b4c74d7eb8c (diff) | |
download | wallabag-08f29ae7b6af585f3af1dd2f8b01854fb0985668.tar.gz wallabag-08f29ae7b6af585f3af1dd2f8b01854fb0985668.tar.zst wallabag-08f29ae7b6af585f3af1dd2f8b01854fb0985668.zip |
Create a new entry via API even when its content can't be retrieved
Fix #2988
-rw-r--r-- | src/Wallabag/ApiBundle/Controller/EntryRestController.php | 17 | ||||
-rw-r--r-- | tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php | 24 |
2 files changed, 37 insertions, 4 deletions
diff --git a/src/Wallabag/ApiBundle/Controller/EntryRestController.php b/src/Wallabag/ApiBundle/Controller/EntryRestController.php index 2c2ec0c1..e9e1aca3 100644 --- a/src/Wallabag/ApiBundle/Controller/EntryRestController.php +++ b/src/Wallabag/ApiBundle/Controller/EntryRestController.php | |||
@@ -199,10 +199,19 @@ class EntryRestController extends WallabagRestController | |||
199 | $entry = $this->get('wallabag_core.entry_repository')->findByUrlAndUserId($url, $this->getUser()->getId()); | 199 | $entry = $this->get('wallabag_core.entry_repository')->findByUrlAndUserId($url, $this->getUser()->getId()); |
200 | 200 | ||
201 | if (false === $entry) { | 201 | if (false === $entry) { |
202 | $entry = $this->get('wallabag_core.content_proxy')->updateEntry( | 202 | $entry = new Entry($this->getUser()); |
203 | new Entry($this->getUser()), | 203 | try { |
204 | $url | 204 | $entry = $this->get('wallabag_core.content_proxy')->updateEntry( |
205 | ); | 205 | $entry, |
206 | $url | ||
207 | ); | ||
208 | } catch (\Exception $e) { | ||
209 | $this->get('logger')->error('Error while saving an entry', [ | ||
210 | 'exception' => $e, | ||
211 | 'entry' => $entry, | ||
212 | ]); | ||
213 | $entry->setUrl($url); | ||
214 | } | ||
206 | } | 215 | } |
207 | 216 | ||
208 | if (!is_null($title)) { | 217 | if (!is_null($title)) { |
diff --git a/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php b/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php index 409a8291..0979ca93 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 | ||
5 | use Tests\Wallabag\ApiBundle\WallabagApiTestCase; | 5 | use Tests\Wallabag\ApiBundle\WallabagApiTestCase; |
6 | use Wallabag\CoreBundle\Entity\Tag; | 6 | use Wallabag\CoreBundle\Entity\Tag; |
7 | use Wallabag\CoreBundle\Helper\ContentProxy; | ||
7 | 8 | ||
8 | class EntryRestControllerTest extends WallabagApiTestCase | 9 | class EntryRestControllerTest extends WallabagApiTestCase |
9 | { | 10 | { |
@@ -359,6 +360,29 @@ class EntryRestControllerTest extends WallabagApiTestCase | |||
359 | $this->assertCount(2, $content['tags']); | 360 | $this->assertCount(2, $content['tags']); |
360 | } | 361 | } |
361 | 362 | ||
363 | public function testPostEntryWhenFetchContentFails() | ||
364 | { | ||
365 | /** @var \Symfony\Component\DependencyInjection\Container $container */ | ||
366 | $container = $this->client->getContainer(); | ||
367 | $contentProxy = $this->getMockBuilder(ContentProxy::class) | ||
368 | ->disableOriginalConstructor() | ||
369 | ->setMethods(['updateEntry']) | ||
370 | ->getMock(); | ||
371 | $contentProxy->expects($this->any()) | ||
372 | ->method('updateEntry') | ||
373 | ->willThrowException(new \Exception('Test Fetch content fails')); | ||
374 | $container->set('wallabag_core.content_proxy', $contentProxy); | ||
375 | |||
376 | $this->client->request('POST', '/api/entries.json', [ | ||
377 | 'url' => 'http://www.example.com/', | ||
378 | ]); | ||
379 | |||
380 | $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); | ||
381 | $content = json_decode($this->client->getResponse()->getContent(), true); | ||
382 | $this->assertGreaterThan(0, $content['id']); | ||
383 | $this->assertEquals('http://www.example.com/', $content['url']); | ||
384 | } | ||
385 | |||
362 | public function testPostArchivedAndStarredEntry() | 386 | public function testPostArchivedAndStarredEntry() |
363 | { | 387 | { |
364 | $this->client->request('POST', '/api/entries.json', [ | 388 | $this->client->request('POST', '/api/entries.json', [ |