]> git.immae.eu Git - github/wallabag/wallabag.git/blobdiff - tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php
Create a new entry via API even when its content can't be retrieved
[github/wallabag/wallabag.git] / tests / Wallabag / ApiBundle / Controller / EntryRestControllerTest.php
index 566e9493ae811e057daaf28836769f5e4c561e07..0979ca93c3c2a6d24c9ec4e27e166866ab3c9b8c 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
 {
@@ -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', [
@@ -678,4 +702,40 @@ class EntryRestControllerTest extends WallabagApiTestCase
 
         $this->assertEquals(403, $this->client->getResponse()->getStatusCode());
     }
+
+    public function testReloadEntryErrorWhileFetching()
+    {
+        $entry = $this->client->getContainer()->get('doctrine.orm.entity_manager')
+            ->getRepository('WallabagCoreBundle:Entry')
+            ->findByUrlAndUserId('http://0.0.0.0/entry4', 1);
+
+        if (!$entry) {
+            $this->markTestSkipped('No content found in db.');
+        }
+
+        $this->client->request('PATCH', '/api/entries/'.$entry->getId().'/reload.json');
+        $this->assertEquals(304, $this->client->getResponse()->getStatusCode());
+    }
+
+    public function testReloadEntry()
+    {
+        $this->client->request('POST', '/api/entries.json', [
+            'url' => 'http://www.lemonde.fr/pixels/article/2015/03/28/plongee-dans-l-univers-d-ingress-le-jeu-de-google-aux-frontieres-du-reel_4601155_4408996.html',
+            'archive' => '1',
+            'tags' => 'google, apple',
+        ]);
+
+        $json = json_decode($this->client->getResponse()->getContent(), true);
+
+        $this->setUp();
+
+        $this->client->request('PATCH', '/api/entries/'.$json['id'].'/reload.json');
+        $this->assertEquals(200, $this->client->getResponse()->getStatusCode());
+
+        $content = json_decode($this->client->getResponse()->getContent(), true);
+
+        $this->assertNotEmpty($content['title']);
+
+        $this->assertEquals('application/json', $this->client->getResponse()->headers->get('Content-Type'));
+    }
 }