From 00c6e040deec9c3998ab679dcb84fc46ae72d2ac Mon Sep 17 00:00:00 2001 From: Bernhard Posselt Date: Wed, 11 Sep 2013 20:31:58 +0200 Subject: removed google importer on the serverside, add importer for articles --- tests/unit/businesslayer/FeedBusinessLayerTest.php | 69 +++++++++++----------- 1 file changed, 36 insertions(+), 33 deletions(-) (limited to 'tests/unit/businesslayer') diff --git a/tests/unit/businesslayer/FeedBusinessLayerTest.php b/tests/unit/businesslayer/FeedBusinessLayerTest.php index 220b1c980..23bb98c55 100644 --- a/tests/unit/businesslayer/FeedBusinessLayerTest.php +++ b/tests/unit/businesslayer/FeedBusinessLayerTest.php @@ -34,7 +34,6 @@ 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 { @@ -70,15 +69,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->enhancer = $this->getMockBuilder('\OCA\News\Utility\ArticleEnhancer\Enhancer') ->disableOriginalConstructor() ->getMock(); $this->feedBusinessLayer = new FeedBusinessLayer($this->feedMapper, $this->fetcher, $this->itemMapper, $this->api, - $timeFactory, $this->importParser, $this->autoPurgeMinimumInterval, + $timeFactory, $this->autoPurgeMinimumInterval, $this->enhancer); $this->user = 'jack'; $response = 'hi'; @@ -423,51 +419,58 @@ class FeedBusinessLayerTest extends \OCA\AppFramework\Utility\TestUtility { } - public function testImportGoogleReaderJSON(){ - $url = 'http://owncloud/googlereader'; - $urlHash = md5($url); + public function testImportArticles(){ + $url = 'http://owncloud/nofeed'; $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); - $items = array(new Item()); + $feeds = array($feed); + + $item = new Item(); + $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); + + $json = $item->toExport(array('feed3' => $feed)); + + $items = array($json); + + $this->feedMapper->expects($this->once()) + ->method('findAllFromUser') + ->with($this->equalTo($this->user)) + ->will($this->returnValue($feeds)); - $this->feedMapper->expects($this->at(0)) - ->method('findByUrlHash') - ->with($this->equalTo($urlHash), - $this->equalTo($this->user)) - ->will($this->throwException(new DoesNotExistException('hi'))); - $this->feedMapper->expects($this->at(1)) - ->method('insert') - ->will($this->returnValue($feed)); - $this->feedMapper->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'); + ->method('findByGuidHash') + ->will($this->throwException(new DoesNotExistException('yo'))); + $this->itemMapper->expects($this->once()) + ->method('insert') + ->with($this->equalTo($item)); - $result = $this->feedBusinessLayer->importGoogleReaderJSON(array(), $this->user); + $result = $this->feedBusinessLayer->importArticles($items, $this->user); - $this->assertEquals($feed, $result); + $this->assertEquals(null, $result); } - public function testImportGoogleReaderJSONFeedExists(){ + public function atestImportGoogleReaderJSONFeedExists(){ $url = 'http://owncloud/googlereader'; $urlHash = md5($url); -- cgit v1.2.3