]> git.immae.eu Git - github/wallabag/wallabag.git/blobdiff - tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php
Merge remote-tracking branch 'origin/master' into 2.3
[github/wallabag/wallabag.git] / tests / Wallabag / ApiBundle / Controller / EntryRestControllerTest.php
index 4f49f040f9e6d9ccfb4db6ef0e20fa0c7740b064..bf7d373aa94d57f8716ed59f5f6d02f37ccd3b6f 100644 (file)
@@ -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
 {
@@ -375,6 +376,39 @@ class EntryRestControllerTest extends WallabagApiTestCase
         $this->assertCount(3, $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);
+
+        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()
     {
         $this->client->request('POST', '/api/entries.json', [