summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBenjamin Brahmer <info@b-brahmer.de>2022-08-05 10:53:49 +0200
committerBenjamin Brahmer <info@b-brahmer.de>2022-08-05 11:10:02 +0200
commite84f4c74f424ddacee6e661e7226607d3cfce774 (patch)
treea3db883b8ec64a874fd54227979f35dd458d29e9
parenteb7e2161630bccaa76cf285ae0b25a1bf93c9939 (diff)
Fix format and tests
Signed-off-by: Benjamin Brahmer <info@b-brahmer.de>
-rw-r--r--lib/Service/FeedServiceV2.php24
-rw-r--r--tests/Unit/Service/FeedServiceTest.php22
-rw-r--r--tests/api/feeds.bats3
3 files changed, 24 insertions, 25 deletions
diff --git a/lib/Service/FeedServiceV2.php b/lib/Service/FeedServiceV2.php
index 6b354dc1b..4dddc9408 100644
--- a/lib/Service/FeedServiceV2.php
+++ b/lib/Service/FeedServiceV2.php
@@ -204,21 +204,17 @@ class FeedServiceV2 extends Service
list($feed, $items) = $this->feedFetcher->fetch($feedUrl, $full_text, $user, $password);
} catch (ReadErrorException $ex) {
$this->logger->debug($ex->getMessage());
- # the url did not lead to a valid feed, try autodiscover
if ($full_discover === false) {
-throw new ServiceNotFoundException($ex->getMessage());
-}
- $this->logger->warning("No valid feed found at URL, attempting auto discovery");
- $feeds = $this->explorer->discover($feedUrl);
- if ($feeds !== []) {
- $feedUrl = array_shift($feeds);
- }
- try {
- list($feed, $items) = $this->feedFetcher->fetch($feedUrl, $full_text, $user, $password);
- } catch (ReadErrorException $ex) {
- throw new ServiceNotFoundException($ex->getMessage());
- }
- } else {
+ throw new ServiceNotFoundException($ex->getMessage());
+ }
+ $this->logger->warning("No valid feed found at URL, attempting auto discovery");
+ $feeds = $this->explorer->discover($feedUrl);
+ if ($feeds !== []) {
+ $feedUrl = array_shift($feeds);
+ }
+ try {
+ list($feed, $items) = $this->feedFetcher->fetch($feedUrl, $full_text, $user, $password);
+ } catch (ReadErrorException $ex) {
throw new ServiceNotFoundException($ex->getMessage());
}
}
diff --git a/tests/Unit/Service/FeedServiceTest.php b/tests/Unit/Service/FeedServiceTest.php
index 9f4743777..b237cff0a 100644
--- a/tests/Unit/Service/FeedServiceTest.php
+++ b/tests/Unit/Service/FeedServiceTest.php
@@ -209,15 +209,16 @@ class FeedServiceTest extends TestCase
->method('findByURL')
->with($this->uid, $url)
->will($this->throwException(new DoesNotExistException('no')));
- $this->explorer->expects($this->once())
- ->method('discover')
- ->with($url)
- ->will($this->returnValue([]));
+ $this->explorer->expects($this->never())
+ ->method('discover')
+ ->with($url)
+ ->will($this->returnValue([]));
$this->fetcher->expects($this->once())
->method('fetch')
->with($url)
->will($this->returnValue($return));
+
$this->mapper->expects($this->once())
->method('insert')
->with($createdFeed)
@@ -268,7 +269,7 @@ class FeedServiceTest extends TestCase
->method('findByURL')
->with($this->uid, $url)
->will($this->throwException(new DoesNotExistException('no')));
- $this->explorer->expects($this->once())
+ $this->explorer->expects($this->never())
->method('discover')
->with($url)
->will($this->returnValue([]));
@@ -332,10 +333,13 @@ class FeedServiceTest extends TestCase
->method('discover')
->with($url)
->will($this->returnValue(['http://discover.test']));
- $this->fetcher->expects($this->once())
+ $this->fetcher->expects($this->exactly(2))
->method('fetch')
- ->with('http://discover.test')
- ->will($this->returnValue($return));
+ ->withConsecutive(
+ ['http://test'],
+ ['http://discover.test']
+ )
+ ->willReturnOnConsecutiveCalls($this->throwException(new ReadErrorException('There is no feed')), $this->returnValue($return));
$this->mapper->expects($this->once())
->method('insert')
@@ -434,7 +438,7 @@ class FeedServiceTest extends TestCase
$url = 'http://test';
$folderId = 10;
- $this->fetcher->expects($this->once())
+ $this->fetcher->expects($this->exactly(2))
->method('fetch')
->with($url)
->will($this->throwException(new ReadErrorException('ERROR')));
diff --git a/tests/api/feeds.bats b/tests/api/feeds.bats
index 054fd776a..d789a554f 100644
--- a/tests/api/feeds.bats
+++ b/tests/api/feeds.bats
@@ -37,8 +37,7 @@ teardown() {
# run is not working here.
output=$(http --ignore-stdin -b -a ${user}:${user} POST ${BASE_URLv1}/feeds url=$NC_FEED | jq '.feeds | .[0].url')
- # self reference of feed is used here
- assert_output '"https://nextcloud.com/feed/"'
+ assert_output '"https://nextcloud.com/blog/static-feed/"'
}
@test "[$TESTSUITE] Create new inside folder" {