From 08f29ae7b6af585f3af1dd2f8b01854fb0985668 Mon Sep 17 00:00:00 2001 From: adev Date: Mon, 8 May 2017 12:35:02 +0200 Subject: Create a new entry via API even when its content can't be retrieved Fix #2988 --- .../Controller/EntryRestControllerTest.php | 24 ++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'tests') 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; use Tests\Wallabag\ApiBundle\WallabagApiTestCase; use Wallabag\CoreBundle\Entity\Tag; +use Wallabag\CoreBundle\Helper\ContentProxy; class EntryRestControllerTest extends WallabagApiTestCase { @@ -359,6 +360,29 @@ class EntryRestControllerTest extends WallabagApiTestCase $this->assertCount(2, $content['tags']); } + public function testPostEntryWhenFetchContentFails() + { + /** @var \Symfony\Component\DependencyInjection\Container $container */ + $container = $this->client->getContainer(); + $contentProxy = $this->getMockBuilder(ContentProxy::class) + ->disableOriginalConstructor() + ->setMethods(['updateEntry']) + ->getMock(); + $contentProxy->expects($this->any()) + ->method('updateEntry') + ->willThrowException(new \Exception('Test Fetch content fails')); + $container->set('wallabag_core.content_proxy', $contentProxy); + + $this->client->request('POST', '/api/entries.json', [ + 'url' => 'http://www.example.com/', + ]); + + $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); + $content = json_decode($this->client->getResponse()->getContent(), true); + $this->assertGreaterThan(0, $content['id']); + $this->assertEquals('http://www.example.com/', $content['url']); + } + public function testPostArchivedAndStarredEntry() { $this->client->request('POST', '/api/entries.json', [ -- cgit v1.2.3 From a9357a8311b2a3a9a114ec8400a9878d5f1f8345 Mon Sep 17 00:00:00 2001 From: adev Date: Tue, 9 May 2017 23:19:24 +0200 Subject: Remove the created entry to avoid side effects on other tests --- .../Controller/EntryRestControllerTest.php | 26 +++++++++++++++------- 1 file changed, 18 insertions(+), 8 deletions(-) (limited to 'tests') diff --git a/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php b/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php index 0979ca93..deafd1fa 100644 --- a/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php +++ b/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php @@ -373,14 +373,24 @@ class EntryRestControllerTest extends WallabagApiTestCase ->willThrowException(new \Exception('Test Fetch content fails')); $container->set('wallabag_core.content_proxy', $contentProxy); - $this->client->request('POST', '/api/entries.json', [ - 'url' => 'http://www.example.com/', - ]); - - $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); - $content = json_decode($this->client->getResponse()->getContent(), true); - $this->assertGreaterThan(0, $content['id']); - $this->assertEquals('http://www.example.com/', $content['url']); + try { + $this->client->request('POST', '/api/entries.json', [ + 'url' => 'http://www.example.com/', + ]); + + $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); + $content = json_decode($this->client->getResponse()->getContent(), true); + $this->assertGreaterThan(0, $content['id']); + $this->assertEquals('http://www.example.com/', $content['url']); + } finally { + // Remove the created entry to avoid side effects on other tests + if (isset($content['id'])) { + $em = $this->client->getContainer()->get('doctrine.orm.entity_manager'); + $entry = $em->getReference('WallabagCoreBundle:Entry', $content['id']); + $em->remove($entry); + $em->flush(); + } + } } public function testPostArchivedAndStarredEntry() -- cgit v1.2.3