diff options
author | Bernhard Posselt <nukeawhale@gmail.com> | 2013-09-12 00:59:39 +0200 |
---|---|---|
committer | Bernhard Posselt <nukeawhale@gmail.com> | 2013-09-12 01:00:32 +0200 |
commit | 2391e6bf62e0a3624685a2a7c72bdb7de499bef2 (patch) | |
tree | bd8bbc00f9894a082f5628efd3ad79916da16e4d /tests/unit/businesslayer/FeedBusinessLayerTest.php | |
parent | 00c6e040deec9c3998ab679dcb84fc46ae72d2ac (diff) |
fix #342
Diffstat (limited to 'tests/unit/businesslayer/FeedBusinessLayerTest.php')
-rw-r--r-- | tests/unit/businesslayer/FeedBusinessLayerTest.php | 100 |
1 files changed, 65 insertions, 35 deletions
diff --git a/tests/unit/businesslayer/FeedBusinessLayerTest.php b/tests/unit/businesslayer/FeedBusinessLayerTest.php index 23bb98c55..17222c57b 100644 --- a/tests/unit/businesslayer/FeedBusinessLayerTest.php +++ b/tests/unit/businesslayer/FeedBusinessLayerTest.php @@ -470,55 +470,85 @@ class FeedBusinessLayerTest extends \OCA\AppFramework\Utility\TestUtility { } - public function atestImportGoogleReaderJSONFeedExists(){ - $url = 'http://owncloud/googlereader'; - $urlHash = md5($url); - + public function testImportArticlesCreatesOwnFeedWhenNotFound(){ + $url = 'http://owncloud/args'; $feed = new Feed(); + $feed->setId(3); $feed->setUserId($this->user); - $feed->setUrlHash($urlHash); $feed->setUrl($url); - $feed->setTitle('Google Reader'); + $feed->setLink($url); + $feed->setTitle('Articles without feed'); $feed->setAdded($this->time); $feed->setFolderId(0); $feed->setPreventUpdate(true); - $feed->setId(3); + + $feeds = array($feed); $item = new Item(); - $item->setGuidHash('hi'); - $items = array($item); - $savedItem = new Item(); - $savedItem->setFeedId($feed->getId()); - $savedItem->setGuidHash('hi'); + $item->setFeedId(3); + $item->setAuthor('john'); + $item->setGuid('s'); + $item->setTitle('hey'); + $item->setPubDate(333); + $item->setBody('come over'); + $item->setEnclosureMime('mime'); + $item->setEnclosureLink('lin'); + $item->setUnread(); + $item->setUnstarred(); + $item->setLastModified($this->time); - $in = array(); + $json = $item->toExport(array('feed3' => $feed)); + $json2 = $json; + $json2['feedLink'] = 'http://test.com'; // believe it or not this copies stuff :D - $this->feedMapper->expects($this->at(0)) - ->method('findByUrlHash') - ->with($this->equalTo($urlHash), - $this->equalTo($this->user)) - ->will($this->returnValue($feed)); - $this->feedMapper->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()) + $items = array($json, $json2); + + $insertFeed = new Feed(); + $insertFeed->setLink('http://owncloud/nofeed'); + $insertFeed->setUrl('http://owncloud/nofeed'); + $insertFeed->setUserId($this->user); + $insertFeed->setTitle('Articles without feed'); + $insertFeed->setAdded($this->time); + $insertFeed->setPreventUpdate(true); + $insertFeed->setFolderId(0); + + $trans = $this->getMock('trans', array('t')); + $trans->expects($this->once()) + ->method('t') + ->will($this->returnValue('Articles without feed')); + $this->feedMapper->expects($this->once()) + ->method('findAllFromUser') + ->with($this->equalTo($this->user)) + ->will($this->returnValue($feeds)); + $this->api->expects($this->once()) + ->method('getTrans') + ->will($this->returnValue($trans)); + $this->feedMapper->expects($this->once()) + ->method('insert') + ->with($this->equalTo($insertFeed)) + ->will($this->returnValue($insertFeed)); + + + $this->itemMapper->expects($this->at(0)) ->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()) + ->will($this->throwException(new DoesNotExistException('yo'))); + $this->itemMapper->expects($this->at(1)) ->method('insert') - ->with($this->equalTo($savedItem)); + ->with($this->equalTo($item)); + + $this->itemMapper->expects($this->at(2)) + ->method('findByGuidHash') + ->will($this->returnValue($item)); + $this->itemMapper->expects($this->at(3)) + ->method('update') + ->with($this->equalTo($item)); - $result = $this->feedBusinessLayer->importGoogleReaderJSON($in, $this->user); + $this->feedMapper->expects($this->once()) + ->method('findByUrlHash') + ->will($this->returnValue($feed)); + + $result = $this->feedBusinessLayer->importArticles($items, $this->user); $this->assertEquals($feed, $result); } |