summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorBernhard Posselt <dev@bernhard-posselt.com>2015-10-25 14:11:23 +0100
committerBernhard Posselt <dev@bernhard-posselt.com>2015-10-25 14:11:23 +0100
commit29dba079be70723f5202ebfafbae4771b18e7eb0 (patch)
tree93ccd72121cac75575ab9add5e4d67c3159e612a /tests
parentc10358a0f69789306d65daf23f79a07c271268e2 (diff)
fix #877
Diffstat (limited to 'tests')
-rw-r--r--tests/unit/service/FeedServiceTest.php74
1 files changed, 74 insertions, 0 deletions
diff --git a/tests/unit/service/FeedServiceTest.php b/tests/unit/service/FeedServiceTest.php
index 001d69adf..923685e3e 100644
--- a/tests/unit/service/FeedServiceTest.php
+++ b/tests/unit/service/FeedServiceTest.php
@@ -362,8 +362,79 @@ class FeedServiceTest extends \PHPUnit_Framework_TestCase {
$this->assertEquals($return, $feed);
}
+ public function testUpdateUpdatesWhenPubdateIsNewer() {
+ $feed = new Feed();
+ $feed->setId(3);
+ $feed->setArticlesPerUpdate(1);
+ $feed->setLink('http://test');
+ $feed->setUrl('http://test');
+ $feed->setUrlHash('yo');
+ $feed->setLastModified(3);
+ $feed->setEtag(4);
+
+ $item = new Item();
+ $item->setGuidHash(md5('hi'));
+ $item->setFeedId(3);
+ $item->setPubDate(2);
+ $item->setTitle('hey');
+ $item->setAuthor('aut');
+ $item->setBody('new');
+ $item2 = new Item();
+ $item2->setGuidHash(md5('hi'));
+ $item2->setFeedId(3);
+ $item2->setPubDate(1);
+ $item->setTitle('ho');
+ $item->setAuthor('auto');
+ $item->setBody('old');
+ $items = [$item];
+
+ $ex = new DoesNotExistException('hi');
+
+ $fetchReturn = [$feed, $items];
+
+ $this->feedMapper->expects($this->at(0))
+ ->method('find')
+ ->with($this->equalTo($feed->getId()),
+ $this->equalTo($this->user))
+ ->will($this->returnValue($feed));
+ $this->fetcher->expects($this->once())
+ ->method('fetch')
+ ->with(
+ $this->equalTo('http://test'),
+ $this->equalTo(false),
+ $this->equalTo(3),
+ $this->equalTo(4)
+ )
+ ->will($this->returnValue($fetchReturn));
+ $this->feedMapper->expects($this->at(1))
+ ->method('update')
+ ->with($this->equalTo($feed));
+ $this->itemMapper->expects($this->once())
+ ->method('findByGuidHash')
+ ->with($this->equalTo($items[0]->getGuidHash()),
+ $this->equalTo($items[0]->getFeedId()),
+ $this->equalTo($this->user))
+ ->will($this->returnValue($item2));
+ $this->purifier->expects($this->at(0))
+ ->method('purify')
+ ->with($this->equalTo($items[0]->getBody()))
+ ->will($this->returnValue($items[0]->getBody()));
+ $this->itemMapper->expects($this->once())
+ ->method('update')
+ ->with($this->equalTo($items[0]));
+
+ $this->feedMapper->expects($this->at(2))
+ ->method('find')
+ ->with($feed->getId(), $this->user)
+ ->will($this->returnValue($feed));
+ $return = $this->feedService->update($feed->getId(), $this->user);
+
+ $this->assertEquals($return, $feed);
+
+ }
+
public function testUpdateUpdatesArticlesPerFeedCount() {
$feed = new Feed();
$feed->setId(3);
@@ -389,6 +460,9 @@ class FeedServiceTest extends \PHPUnit_Framework_TestCase {
->method('update')
->with($this->equalTo($existingFeed));
+ $this->itemMapper->expects($this->any())
+ ->method('findByGuidHash')
+ ->will($this->returnValue($item));
$this->feedService->update($feed->getId(), $this->user);
}