summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBernhard Posselt <nukeawhale@gmail.com>2013-06-22 15:02:33 +0200
committerBernhard Posselt <nukeawhale@gmail.com>2013-06-22 15:02:33 +0200
commit7d1c2b2c2cab883c63b074cec87dcc8729b52d1b (patch)
tree0258a0d651fe2c80795f385d603872cbcf847a41
parent984f0270e2e2310a8ec4c4209e00fa41fe7dbbe0 (diff)
fix #253, use current date when no pubdate is provided
-rw-r--r--tests/unit/utility/FeedFetcherTest.php28
-rw-r--r--utility/feedfetcher.php13
2 files changed, 35 insertions, 6 deletions
diff --git a/tests/unit/utility/FeedFetcherTest.php b/tests/unit/utility/FeedFetcherTest.php
index b783da296..b624d998e 100644
--- a/tests/unit/utility/FeedFetcherTest.php
+++ b/tests/unit/utility/FeedFetcherTest.php
@@ -167,7 +167,7 @@ class FeedFetcherTest extends \OCA\AppFramework\Utility\TestUtility {
}
- private function createItem($author=false, $enclosureType=null) {
+ private function createItem($author=false, $enclosureType=null, $noPubDate=false) {
$this->purifier->expects($this->once())
->method('purify')
->with($this->equalTo($this->body))
@@ -176,9 +176,17 @@ class FeedFetcherTest extends \OCA\AppFramework\Utility\TestUtility {
$this->expectItem('get_title', $this->title);
$this->expectItem('get_id', $this->guid);
$this->expectItem('get_content', $this->body);
- $this->expectItem('get_date', $this->pub);
$item = new Item();
+
+ if($noPubDate) {
+ $this->expectItem('get_date', 0);
+ $item->setPubDate($this->time);
+ } else {
+ $this->expectItem('get_date', $this->pub);
+ $item->setPubDate($this->pub);
+ }
+
$item->setStatus(0);
$item->setUnread();
$item->setUrl($this->permalink);
@@ -186,7 +194,6 @@ class FeedFetcherTest extends \OCA\AppFramework\Utility\TestUtility {
$item->setGuid($this->guid);
$item->setGuidHash(md5($this->guid));
$item->setBody($this->body2);
- $item->setPubDate($this->pub);
$item->setLastModified($this->time);
if($author) {
$mock = $this->getMock('author', array('get_name'));
@@ -313,6 +320,20 @@ class FeedFetcherTest extends \OCA\AppFramework\Utility\TestUtility {
$this->assertEquals(array($feed, array($item)), $result);
}
+
+ public function testFetchMapItemsNoPubdate(){
+ $this->core->expects($this->once())
+ ->method('init')
+ ->will($this->returnValue(true));
+ $item = $this->createItem(false, true, true);
+ $feed = $this->createFeed(false, true);
+ $this->expectCore('get_items', array($this->item));
+ $result = $this->fetcher->fetch($this->url);
+
+ $this->assertEquals(array($feed, array($item)), $result);
+ }
+
+
public function testFetchMapItemsGetFavicon() {
$this->expectCore('get_title', $this->feedTitle);
$this->expectCore('get_link', $this->feedLink);
@@ -365,4 +386,5 @@ class FeedFetcherTest extends \OCA\AppFramework\Utility\TestUtility {
$this->assertEquals(array($feed, array($item)), $result);
}
+
}
diff --git a/utility/feedfetcher.php b/utility/feedfetcher.php
index 016aae8de..27eeb31a6 100644
--- a/utility/feedfetcher.php
+++ b/utility/feedfetcher.php
@@ -120,9 +120,16 @@ class FeedFetcher implements IFeedFetcher {
$item->setGuid($guid);
$item->setGuidHash(md5($guid));
$item->setBody(str_replace('<a', '<a target="_blank"',
- // escape XSS
- $this->purifier->purify($simplePieItem->get_content())));
- $item->setPubDate($simplePieItem->get_date('U'));
+ // escape XSS
+ $this->purifier->purify($simplePieItem->get_content())));
+
+ // pubdate is not required. if not given use the current date
+ $date = $simplePieItem->get_date('U');
+ if(!$date) {
+ $date = $this->time->getTime();
+ }
+
+ $item->setPubDate($date);
$item->setLastModified($this->time->getTime());
$author = $simplePieItem->get_author();