From d5c2cc54b5490b0bec46f39d7706d5d46869e872 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Tue, 30 May 2017 17:48:24 +0200 Subject: Fix tests --- src/Wallabag/CoreBundle/Helper/ContentProxy.php | 27 +++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) (limited to 'src/Wallabag/CoreBundle/Helper') diff --git a/src/Wallabag/CoreBundle/Helper/ContentProxy.php b/src/Wallabag/CoreBundle/Helper/ContentProxy.php index 88873bd5..cd18c668 100644 --- a/src/Wallabag/CoreBundle/Helper/ContentProxy.php +++ b/src/Wallabag/CoreBundle/Helper/ContentProxy.php @@ -34,13 +34,17 @@ class ContentProxy /** * Update existing entry by fetching from URL using Graby. * - * @param Entry $entry Entry to update - * @param string $url Url to grab content for + * @param Entry $entry Entry to update + * @param string $url Url to grab content for */ public function updateEntry(Entry $entry, $url) { $content = $this->graby->fetchContent($url); + // be sure to keep the url in case of error + // so we'll be able to refetch it in the future + $content['url'] = $content['url'] ?: $url; + $this->stockEntry($entry, $content); } @@ -53,7 +57,14 @@ class ContentProxy */ public function importEntry(Entry $entry, array $content, $disableContentUpdate = false) { - $this->validateContent($content); + try { + $this->validateContent($content); + } catch (\Exception $e) { + // validation failed but do we want to disable updating content? + if (true === $disableContentUpdate) { + throw $e; + } + } if (false === $disableContentUpdate) { try { @@ -79,8 +90,8 @@ class ContentProxy * Stock entry with fetched or imported content. * Will fall back to OpenGraph data if available. * - * @param Entry $entry Entry to stock - * @param array $content Array with at least title and URL + * @param Entry $entry Entry to stock + * @param array $content Array with at least title and URL */ private function stockEntry(Entry $entry, array $content) { @@ -162,15 +173,15 @@ class ContentProxy */ private function validateContent(array $content) { - if (!empty($content['title']))) { + if (empty($content['title'])) { throw new Exception('Missing title from imported entry!'); } - if (!empty($content['url']))) { + if (empty($content['url'])) { throw new Exception('Missing URL from imported entry!'); } - if (!empty($content['html']))) { + if (empty($content['html'])) { throw new Exception('Missing html from imported entry!'); } } -- cgit v1.2.3