summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorBernhard Posselt <dev@bernhard-posselt.com>2014-10-22 11:35:12 +0200
committerBernhard Posselt <dev@bernhard-posselt.com>2014-10-22 11:35:12 +0200
commitc102123dc902b855842d3e9942b4629abba83ebb (patch)
tree8d3058583cc0727ef79daa6d5ab34b2dd669fb0e /tests
parentdc8b8301d387d48e38624423cba9cf5323f26291 (diff)
add caching
Diffstat (limited to 'tests')
-rw-r--r--tests/unit/fetcher/FeedFetcherTest.php15
-rw-r--r--tests/unit/service/FeedServiceTest.php41
2 files changed, 50 insertions, 6 deletions
diff --git a/tests/unit/fetcher/FeedFetcherTest.php b/tests/unit/fetcher/FeedFetcherTest.php
index db954d952..a0bd0b866 100644
--- a/tests/unit/fetcher/FeedFetcherTest.php
+++ b/tests/unit/fetcher/FeedFetcherTest.php
@@ -121,7 +121,10 @@ class FeedFetcherTest extends \PHPUnit_Framework_TestCase {
->method('getEtag')
->will($this->returnValue($this->etag));
- if ($noParser) {
+ if (!$modified) {
+ $this->reader->expects($this->never())
+ ->method('getParser');
+ } else if ($noParser) {
$this->reader->expects($this->once())
->method('getParser')
->will($this->returnValue(false));
@@ -141,10 +144,9 @@ class FeedFetcherTest extends \PHPUnit_Framework_TestCase {
}
}
- // uncomment if testing caching
- /*$this->client->expects($this->once())
+ $this->client->expects($this->once())
->method('isModified')
- ->will($this->returnValue($modified));*/
+ ->will($this->returnValue($modified));
}
@@ -234,6 +236,11 @@ class FeedFetcherTest extends \PHPUnit_Framework_TestCase {
$this->fetcher->fetch($this->url);
}
+ public function testNoFetchIfNotModified(){
+ $this->setUpReader($this->url, false);;
+ $result = $this->fetcher->fetch($this->url);
+ }
+
public function testFetch(){
$this->setUpReader($this->url);
$item = $this->createItem();
diff --git a/tests/unit/service/FeedServiceTest.php b/tests/unit/service/FeedServiceTest.php
index 104413788..2b7205dba 100644
--- a/tests/unit/service/FeedServiceTest.php
+++ b/tests/unit/service/FeedServiceTest.php
@@ -262,7 +262,11 @@ class FeedServiceTest extends \PHPUnit_Framework_TestCase {
$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'));
@@ -280,7 +284,16 @@ class FeedServiceTest extends \PHPUnit_Framework_TestCase {
->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()),
@@ -300,11 +313,12 @@ class FeedServiceTest extends \PHPUnit_Framework_TestCase {
->method('insert')
->with($this->equalTo($items[0]));
- $this->feedMapper->expects($this->at(1))
+ $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);
@@ -408,6 +422,9 @@ class FeedServiceTest extends \PHPUnit_Framework_TestCase {
->with($this->equalTo($feed->getId()),
$this->equalTo($this->user))
->will($this->returnValue($feed));
+ $this->feedMapper->expects($this->at(1))
+ ->method('update')
+ ->with($this->equalTo($feed));
$this->fetcher->expects($this->once())
->method('fetch')
->will($this->returnValue($fetchReturn));
@@ -418,7 +435,7 @@ class FeedServiceTest extends \PHPUnit_Framework_TestCase {
$this->equalTo($this->user))
->will($this->returnValue($item2));;
- $this->feedMapper->expects($this->at(1))
+ $this->feedMapper->expects($this->at(2))
->method('find')
->with($this->equalTo($feed->getId()),
$this->equalTo($this->user))
@@ -450,6 +467,26 @@ class FeedServiceTest extends \PHPUnit_Framework_TestCase {
}
+ public function testUpdateDoesntUpdateIfNoFeed() {
+ $feedId = 3;
+ $feed = new Feed();
+ $feed->setFolderId(16);
+ $feed->setId($feedId);
+
+ $this->feedMapper->expects($this->once())
+ ->method('find')
+ ->with($this->equalTo($feedId),
+ $this->equalTo($this->user))
+ ->will($this->returnValue($feed));
+ $this->fetcher->expects($this->once())
+ ->method('fetch')
+ ->will($this->returnValue([null, null]));
+
+ $return = $this->feedService->update($feedId, $this->user);
+ $this->assertEquals($feed, $return);
+ }
+
+
public function testMove(){
$feedId = 3;
$folderId = 4;