diff options
author | Bernhard Posselt <nukeawhale@gmail.com> | 2013-04-22 18:24:31 +0200 |
---|---|---|
committer | Bernhard Posselt <nukeawhale@gmail.com> | 2013-04-22 18:24:31 +0200 |
commit | df18314b32b05f10720936831ed43573e1792ae6 (patch) | |
tree | a2b8e28e165727e7a88d7ac3529f64d5f6b938e2 /tests/unit/businesslayer | |
parent | 366c1b15545b4da69bc8e236ba4350c28ad24e77 (diff) |
added import from google reader, fix #80
Diffstat (limited to 'tests/unit/businesslayer')
-rw-r--r-- | tests/unit/businesslayer/FeedBusinessLayerTest.php | 102 |
1 files changed, 101 insertions, 1 deletions
diff --git a/tests/unit/businesslayer/FeedBusinessLayerTest.php b/tests/unit/businesslayer/FeedBusinessLayerTest.php index cd044161f..0f8f61e4f 100644 --- a/tests/unit/businesslayer/FeedBusinessLayerTest.php +++ b/tests/unit/businesslayer/FeedBusinessLayerTest.php @@ -34,6 +34,7 @@ use \OCA\News\Db\Feed; use \OCA\News\Db\Item; use \OCA\News\Utility\Fetcher; use \OCA\News\Utility\FetcherException; +use \OCA\News\Utility\ImportParser; class FeedBusinessLayerTest extends \OCA\AppFramework\Utility\TestUtility { @@ -45,6 +46,7 @@ class FeedBusinessLayerTest extends \OCA\AppFramework\Utility\TestUtility { private $itemMapper; private $threshold; private $time; + private $importParser; protected function setUp(){ $this->api = $this->getAPIMock(); @@ -65,9 +67,12 @@ class FeedBusinessLayerTest extends \OCA\AppFramework\Utility\TestUtility { $this->itemMapper = $this->getMockBuilder('\OCA\News\Db\ItemMapper') ->disableOriginalConstructor() ->getMock(); + $this->importParser = $this->getMockBuilder('\OCA\News\Utility\ImportParser') + ->disableOriginalConstructor() + ->getMock(); $this->businessLayer = new FeedBusinessLayer($this->mapper, $this->fetcher, $this->itemMapper, $this->api, - $timeFactory); + $timeFactory, $this->importParser); $this->user = 'jack'; $response = 'hi'; } @@ -576,5 +581,100 @@ class FeedBusinessLayerTest extends \OCA\AppFramework\Utility\TestUtility { } + public function testImportGoogleReaderJSON(){ + $url = 'http://owncloud/googlereader'; + $urlHash = md5($url); + + $feed = new Feed(); + $feed->setId(3); + $feed->setUserId($this->user); + $feed->setUrlHash($urlHash); + $feed->setUrl($url); + $feed->setTitle('Google Reader'); + $feed->setAdded($this->time); + $feed->setFolderId(0); + $feed->setPreventUpdate(true); + + $items = array(new Item()); + + $this->mapper->expects($this->at(0)) + ->method('findByUrlHash') + ->with($this->equalTo($urlHash), + $this->equalTo($this->user)) + ->will($this->throwException(new DoesNotExistException('hi'))); + $this->mapper->expects($this->at(1)) + ->method('insert') + ->will($this->returnValue($feed)); + $this->mapper->expects($this->at(2)) + ->method('findByUrlHash') + ->with($this->equalTo($urlHash), + $this->equalTo($this->user)) + ->will($this->returnValue($feed)); + $this->importParser->expects($this->once()) + ->method('parse') + ->will($this->returnValue($items)); + $this->itemMapper->expects($this->once()) + ->method('findByGuidHash'); + $this->itemMapper->expects($this->never()) + ->method('insert'); + + + $result = $this->businessLayer->importGoogleReaderJSON(array(), $this->user); + + $this->assertEquals($feed, $result); + } + + + public function testImportGoogleReaderJSONFeedExists(){ + $url = 'http://owncloud/googlereader'; + $urlHash = md5($url); + + $feed = new Feed(); + $feed->setUserId($this->user); + $feed->setUrlHash($urlHash); + $feed->setUrl($url); + $feed->setTitle('Google Reader'); + $feed->setAdded($this->time); + $feed->setFolderId(0); + $feed->setPreventUpdate(true); + $feed->setId(3); + + $item = new Item(); + $item->setGuidHash('hi'); + $items = array($item); + $savedItem = new Item(); + $savedItem->setFeedId($feed->getId()); + $savedItem->setGuidHash('hi'); + + $in = array(); + + $this->mapper->expects($this->at(0)) + ->method('findByUrlHash') + ->with($this->equalTo($urlHash), + $this->equalTo($this->user)) + ->will($this->returnValue($feed)); + $this->mapper->expects($this->at(1)) + ->method('findByUrlHash') + ->with($this->equalTo($urlHash), + $this->equalTo($this->user)) + ->will($this->returnValue($feed)); + $this->importParser->expects($this->once()) + ->method('parse') + ->with($this->equalTo($in)) + ->will($this->returnValue($items)); + $this->itemMapper->expects($this->once()) + ->method('findByGuidHash') + ->with($this->equalTo($savedItem->getGuidHash()), + $this->equalTo($savedItem->getFeedId()), + $this->equalTo($this->user)) + ->will($this->throwException(new DoesNotExistException('ho'))); + $this->itemMapper->expects($this->once()) + ->method('insert') + ->with($this->equalTo($savedItem)); + + $result = $this->businessLayer->importGoogleReaderJSON($in, $this->user); + + $this->assertEquals($feed, $result); + } } |