X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=tests%2FWallabag%2FCoreBundle%2FController%2FEntryControllerTest.php;h=0e7e157600c793db2f5a7558e0014351a199f4e8;hb=26e2f07419c9a16c2a304baa6d2cd36d6dddcd80;hp=e2fb8d7802f7fad3dc91ef0529858cfbef730878;hpb=97444566db31c287103468ee64e2b234d223a354;p=github%2Fwallabag%2Fwallabag.git diff --git a/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php b/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php index e2fb8d78..0e7e1576 100644 --- a/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php +++ b/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php @@ -6,10 +6,11 @@ use Tests\Wallabag\CoreBundle\WallabagCoreTestCase; use Wallabag\CoreBundle\Entity\Config; use Wallabag\CoreBundle\Entity\Entry; use Wallabag\CoreBundle\Entity\SiteCredential; +use Wallabag\CoreBundle\Helper\ContentProxy; class EntryControllerTest extends WallabagCoreTestCase { - const An_URL_CONTAINING_AN_ARTICLE_WITH_IMAGE = 'http://www.lemonde.fr/judo/article/2017/11/11/judo-la-decima-de-teddy-riner_5213605_1556020.html'; + const AN_URL_CONTAINING_AN_ARTICLE_WITH_IMAGE = 'http://www.lemonde.fr/judo/article/2017/11/11/judo-la-decima-de-teddy-riner_5213605_1556020.html'; public $downloadImagesEnabled = false; public $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'; @@ -137,6 +138,8 @@ class EntryControllerTest extends WallabagCoreTestCase $this->logInAs('admin'); $client = $this->getClient(); + $client->getContainer()->get('craue_config')->set('store_article_headers', 1); + $crawler = $client->request('GET', '/new'); $this->assertSame(200, $client->getResponse()->getStatusCode()); @@ -165,6 +168,7 @@ class EntryControllerTest extends WallabagCoreTestCase $this->assertSame('2015-03-28 11:43:19', $content->getPublishedAt()->format('Y-m-d H:i:s')); $this->assertSame('Morgane Tual', $author[0]); $this->assertArrayHasKey('x-varnish1', $content->getHeaders()); + $client->getContainer()->get('craue_config')->set('store_article_headers', 0); } public function testPostWithMultipleAuthors() @@ -519,7 +523,7 @@ class EntryControllerTest extends WallabagCoreTestCase $this->assertGreaterThan(1, $title = $crawler->filter('div[id=article] h1')->extract(['_text'])); $this->assertContains('My updated title hehe :)', $title[0]); - $this->assertSame(1, sizeof($stats = $crawler->filter('div[class=tools] ul[class=stats] li a[class=tool]')->extract(['_text']))); + $this->assertSame(1, count($stats = $crawler->filter('div[class=tools] ul[class=stats] li a[class=tool]')->extract(['_text']))); $this->assertNotContains('example.io', trim($stats[0])); } @@ -1014,7 +1018,7 @@ class EntryControllerTest extends WallabagCoreTestCase $this->logInAs('admin'); $client = $this->getClient(); - $url = self::An_URL_CONTAINING_AN_ARTICLE_WITH_IMAGE; + $url = self::AN_URL_CONTAINING_AN_ARTICLE_WITH_IMAGE; $client->getContainer()->get('craue_config')->set('download_images_enabled', 1); $crawler = $client->request('GET', '/new'); @@ -1056,7 +1060,7 @@ class EntryControllerTest extends WallabagCoreTestCase $this->logInAs('admin'); $client = $this->getClient(); - $url = self::An_URL_CONTAINING_AN_ARTICLE_WITH_IMAGE; + $url = self::AN_URL_CONTAINING_AN_ARTICLE_WITH_IMAGE; $client->getContainer()->get('craue_config')->set('download_images_enabled', 1); $crawler = $client->request('GET', '/new'); @@ -1426,4 +1430,52 @@ class EntryControllerTest extends WallabagCoreTestCase $client->getContainer()->get('craue_config')->set('restricted_access', 0); } + + public function testPostEntryWhenFetchFails() + { + $url = 'http://example.com/papers/email_tracking.pdf'; + $this->logInAs('admin'); + $client = $this->getClient(); + + $container = $client->getContainer(); + $contentProxy = $this->getMockBuilder(ContentProxy::class) + ->disableOriginalConstructor() + ->setMethods(['updateEntry']) + ->getMock(); + $contentProxy->expects($this->any()) + ->method('updateEntry') + ->willThrowException(new \Exception('Test Fetch content fails')); + + $crawler = $client->request('GET', '/new'); + + $this->assertSame(200, $client->getResponse()->getStatusCode()); + + $form = $crawler->filter('form[name=entry]')->form(); + + $data = [ + 'entry[url]' => $url, + ]; + + /** + * We generate a new client to be able to use Mock ContentProxy + * Also we reinject the cookie from the previous client to keep the + * session. + */ + $cookie = $client->getCookieJar()->all(); + $client = $this->getNewClient(); + $client->getCookieJar()->set($cookie[0]); + $client->getContainer()->set('wallabag_core.content_proxy', $contentProxy); + $client->submit($form, $data); + + $this->assertSame(302, $client->getResponse()->getStatusCode()); + + $content = $client->getContainer() + ->get('doctrine.orm.entity_manager') + ->getRepository('WallabagCoreBundle:Entry') + ->findByUrlAndUserId($url, $this->getLoggedInUserId()); + + $authors = $content->getPublishedBy(); + $this->assertSame('email_tracking.pdf', $content->getTitle()); + $this->assertSame('example.com', $content->getDomainName()); + } }