summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorAccalia Elementia <accalia@elementia.me>2022-05-24 11:07:50 -0400
committerGitHub <noreply@github.com>2022-05-24 17:07:50 +0200
commitfdf037e7287616b5211f8f8f7c8ce85b260d781e (patch)
tree6371e0fce359c48f40450929bd0dade97cc7aa1e /tests
parent684af84ea957ff160d49d44826525d1684b6f975 (diff)
Use Feed Link as GUID when Feed omits Guid. (#1785)
* Use Feed Link as GUID when Feed omits Guid. As noted in nextcloud/news#1702 some feeds omit the GUID and are therefore not a valid RSS feed. nextcloud/news#1738 resolved the issue to allow valid feeds to update correctly when an invalid feed is present. This commit allows parsing of the invalid feed as well by assuming that the item link of the feed is unique to the feed and using it in place of the GUID when the feed omits the GUID. This will allow NextCloud News to accept and behave like many other popular feed aggregators when presented with such an invalid feed. Signed-off-by: Accalia <Accalia@Elementia.me> * Add basic Logging when using fallback guid Signed-off-by: Accalia <Accalia@Elementia.me> * Add basic Logging when using fallback guid - Fix Fatfinger Typo Signed-off-by: Accalia <Accalia@Elementia.me> * Add basic Logging when using fallback guid - Update tests to account for additional logging Signed-off-by: Accalia <Accalia@Elementia.me>
Diffstat (limited to 'tests')
-rw-r--r--tests/Unit/Fetcher/FeedFetcherTest.php44
1 files changed, 41 insertions, 3 deletions
diff --git a/tests/Unit/Fetcher/FeedFetcherTest.php b/tests/Unit/Fetcher/FeedFetcherTest.php
index 42f518453..af8066171 100644
--- a/tests/Unit/Fetcher/FeedFetcherTest.php
+++ b/tests/Unit/Fetcher/FeedFetcherTest.php
@@ -459,6 +459,40 @@ class FeedFetcherTest extends TestCase
}
/**
+ * Test if the fetch function fetches a feed that specifies a guid.
+ */
+ public function testFetchWithGuid()
+ {
+ $this->setUpReader($this->url);
+ $this->createItem();
+ $feed = $this->createFeed();
+ $this->mockIterator($this->feed_mock, [$this->item_mock]);
+ $result = $this->fetcher->fetch($this->url, false, null, null);
+ //Explicitly assert GUID value
+ $this->assertEquals(2, count($result));
+ $this->assertEquals(1, count($result[1]));
+ $resultItem = $result[1][0];
+ $this->assertEquals($this->guid, $resultItem->getGuid());
+ }
+
+ /**
+ * Test if the fetch function fetches a feed that does not specify a guid.
+ */
+ public function testFetchWithoutGuid()
+ {
+ $this->setUpReader($this->url);
+ $this->guid = null;
+ $this->createItem();
+ $feed = $this->createFeed();
+ $this->mockIterator($this->feed_mock, [$this->item_mock]);
+ $result = $this->fetcher->fetch($this->url, false, null, null);
+ //Explicitly assert GUID value
+ $this->assertEquals(2, count($result));
+ $this->assertEquals(1, count($result[1]));
+ $resultItem = $result[1][0];
+ $this->assertEquals($this->permalink, $resultItem->getGuid());
+ }
+ /**
* Mock an iteration option on an existing mock
*
* @param object $iteratorMock The mock to enhance
@@ -576,10 +610,10 @@ class FeedFetcherTest extends TestCase
$this->item_mock->expects($this->exactly(1))
->method('getLink')
->will($this->returnValue($this->permalink));
- $this->item_mock->expects($this->exactly(2))
+ $this->item_mock->expects($this->exactly(1))
->method('getTitle')
->will($this->returnValue($this->title));
- $this->item_mock->expects($this->exactly(2))
+ $this->item_mock->expects($this->exactly(1))
->method('getPublicId')
->will($this->returnValue($this->guid));
$this->item_mock->expects($this->exactly(1))
@@ -600,7 +634,6 @@ class FeedFetcherTest extends TestCase
$item->setUnread(true)
->setUrl($this->permalink)
->setTitle('my<\' title')
- ->setGuid($this->guid)
->setGuidHash($this->guid_hash)
->setBody($this->parsed_body)
->setRtl(false)
@@ -609,6 +642,11 @@ class FeedFetcherTest extends TestCase
->setAuthor(html_entity_decode($this->author->getName()))
->setCategoriesJson($this->categoriesJson);
+ // some tests deliberately omit this, so leave default value if the guid is to be ignored
+ if ($this->guid !== null) {
+ $item->setGuid($this->guid);
+ }
+
if ($enclosureType === 'audio/ogg' || $enclosureType === 'video/ogg') {
$media = $this->getMockbuilder(MediaInterface::class)->getMock();
$media->expects($this->once())