summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBernhard Posselt <Raydiation@users.noreply.github.com>2014-01-24 06:27:36 -0800
committerBernhard Posselt <Raydiation@users.noreply.github.com>2014-01-24 06:27:36 -0800
commitbbee204478bb7b9384947af37b2e707e9176bf11 (patch)
tree9b70f5d39240163d691d52bee64a5f3536439846
parenta0ff604013d7ae03aa44924dc108d37b0c88f990 (diff)
parentd38f2576b2d38f1ac9ce24a5bd73ffb02ede63f6 (diff)
Merge pull request #460 from owncloud/fallback-url
fallback to using the feed link if an item doesn't specificy a link
-rw-r--r--fetcher/feedfetcher.php11
-rw-r--r--tests/unit/fetcher/FeedFetcherTest.php16
2 files changed, 16 insertions, 11 deletions
diff --git a/fetcher/feedfetcher.php b/fetcher/feedfetcher.php
index 705404518..0476a9d3a 100644
--- a/fetcher/feedfetcher.php
+++ b/fetcher/feedfetcher.php
@@ -94,9 +94,10 @@ class FeedFetcher implements IFeedFetcher {
try {
// somehow $simplePie turns into a feed after init
$items = array();
+ $permaLink = $simplePie->get_permalink();
if ($feedItems = $simplePie->get_items()) {
foreach($feedItems as $feedItem) {
- array_push($items, $this->buildItem($feedItem));
+ array_push($items, $this->buildItem($feedItem, $permaLink));
}
}
@@ -125,11 +126,15 @@ class FeedFetcher implements IFeedFetcher {
}
- protected function buildItem($simplePieItem) {
+ protected function buildItem($simplePieItem, $feedLink) {
$item = new Item();
$item->setStatus(0);
$item->setUnread();
- $item->setUrl($this->decodeTwice($simplePieItem->get_permalink()));
+ $url = $this->decodeTwice($simplePieItem->get_permalink());
+ if (!$url) {
+ $url = $feedLink;
+ }
+ $item->setUrl($url);
// unescape content because angularjs helps against XSS
$item->setTitle($this->decodeTwice($simplePieItem->get_title()));
diff --git a/tests/unit/fetcher/FeedFetcherTest.php b/tests/unit/fetcher/FeedFetcherTest.php
index 83ba3b809..b9f68fdae 100644
--- a/tests/unit/fetcher/FeedFetcherTest.php
+++ b/tests/unit/fetcher/FeedFetcherTest.php
@@ -160,14 +160,14 @@ class FeedFetcherTest extends \OCA\AppFramework\Utility\TestUtility {
}
- private function expectCore($method, $return) {
- $this->core->expects($this->once())
+ private function expectCore($method, $return, $count = 1) {
+ $this->core->expects($this->exactly($count))
->method($method)
->will($this->returnValue($return));
}
- private function expectItem($method, $return) {
- $this->item->expects($this->once())
+ private function expectItem($method, $return, $count = 1) {
+ $this->item->expects($this->exactly($count))
->method($method)
->will($this->returnValue($return));
}
@@ -236,7 +236,7 @@ class FeedFetcherTest extends \OCA\AppFramework\Utility\TestUtility {
private function createFeed($hasFeedFavicon=false, $hasWebFavicon=false) {
$this->expectCore('get_title', $this->feedTitle);
- $this->expectCore('get_permalink', $this->feedLink);
+ $this->expectCore('get_permalink', $this->feedLink, 2);
$feed = new Feed();
$feed->setTitle(html_entity_decode($this->feedTitle));
@@ -280,7 +280,7 @@ class FeedFetcherTest extends \OCA\AppFramework\Utility\TestUtility {
public function testFetchMapItemsNoFeedTitleUsesUrl(){
$this->expectCore('get_title', '');
- $this->expectCore('get_permalink', $this->feedLink);
+ $this->expectCore('get_permalink', $this->feedLink, 2);
$feed = new Feed();
$feed->setTitle($this->url);
@@ -340,7 +340,7 @@ class FeedFetcherTest extends \OCA\AppFramework\Utility\TestUtility {
public function testFetchMapItemsGetFavicon() {
$this->expectCore('get_title', $this->feedTitle);
- $this->expectCore('get_permalink', $this->feedLink);
+ $this->expectCore('get_permalink', $this->feedLink, 2);
$feed = new Feed();
$feed->setTitle(html_entity_decode($this->feedTitle));
@@ -366,7 +366,7 @@ class FeedFetcherTest extends \OCA\AppFramework\Utility\TestUtility {
public function testFetchMapItemsNoGetFavicon() {
$this->expectCore('get_title', $this->feedTitle);
- $this->expectCore('get_permalink', $this->feedLink);
+ $this->expectCore('get_permalink', $this->feedLink, 2);
$feed = new Feed();
$feed->setTitle(html_entity_decode($this->feedTitle));