diff options
Diffstat (limited to 'tests/unit/businesslayer')
-rw-r--r-- | tests/unit/businesslayer/FeedBusinessLayerTest.php | 163 |
1 files changed, 23 insertions, 140 deletions
diff --git a/tests/unit/businesslayer/FeedBusinessLayerTest.php b/tests/unit/businesslayer/FeedBusinessLayerTest.php index 0a923cace..7a4cf24e6 100644 --- a/tests/unit/businesslayer/FeedBusinessLayerTest.php +++ b/tests/unit/businesslayer/FeedBusinessLayerTest.php @@ -48,6 +48,7 @@ class FeedBusinessLayerTest extends \OCA\AppFramework\Utility\TestUtility { private $time; private $importParser; private $autoPurgeMinimumInterval; + private $enhancer; protected function setUp(){ $this->api = $this->getAPIMock(); @@ -72,9 +73,13 @@ class FeedBusinessLayerTest extends \OCA\AppFramework\Utility\TestUtility { $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->importParser, $this->autoPurgeMinimumInterval, + $this->enhancer); $this->user = 'jack'; $response = 'hi'; } @@ -146,6 +151,10 @@ class FeedBusinessLayerTest extends \OCA\AppFramework\Utility\TestUtility { $this->equalTo($item2->getFeedId()), $this->equalTo($this->user)) ->will($this->throwException($ex)); + $this->enhancer->expects($this->at(0)) + ->method('enhance') + ->with($this->equalTo($return[1][1])) + ->will($this->returnValue($return[1][1])); $this->itemMapper->expects($this->at(1)) ->method('insert') ->with($this->equalTo($return[1][1])); @@ -156,6 +165,10 @@ class FeedBusinessLayerTest extends \OCA\AppFramework\Utility\TestUtility { $this->equalTo($item1->getFeedId()), $this->equalTo($this->user)) ->will($this->throwException($ex)); + $this->enhancer->expects($this->at(1)) + ->method('enhance') + ->with($this->equalTo($return[1][0])) + ->will($this->returnValue($return[1][0])); $this->itemMapper->expects($this->at(3)) ->method('insert') ->with($this->equalTo($return[1][0])); @@ -201,6 +214,10 @@ class FeedBusinessLayerTest extends \OCA\AppFramework\Utility\TestUtility { $this->equalTo($item2->getFeedId()), $this->equalTo($this->user)) ->will($this->throwException($ex)); + $this->enhancer->expects($this->at(0)) + ->method('enhance') + ->with($this->equalTo($return[1][1])) + ->will($this->returnValue($return[1][1])); $this->itemMapper->expects($this->at(1)) ->method('insert') ->with($this->equalTo($return[1][1])); @@ -249,6 +266,10 @@ class FeedBusinessLayerTest extends \OCA\AppFramework\Utility\TestUtility { $this->equalTo($items[0]->getFeedId()), $this->equalTo($this->user)) ->will($this->throwException($ex)); + $this->enhancer->expects($this->at(0)) + ->method('enhance') + ->with($this->equalTo($items[0])) + ->will($this->returnValue($items[0])); $this->itemMapper->expects($this->once()) ->method('insert') ->with($this->equalTo($items[0])); @@ -263,145 +284,7 @@ class FeedBusinessLayerTest extends \OCA\AppFramework\Utility\TestUtility { $this->assertEquals($return, $feed); } - - public function testUpdateUpdatesEntryNotWhenPubDateSame(){ - $feed = new Feed(); - $feed->setId(3); - $feed->getUrl('test'); - - $item = new Item(); - $item->setGuidHash(md5('hi')); - $item->setPubDate(3333); - $items = array( - $item - ); - - $fetchReturn = array($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') - ->will($this->returnValue($fetchReturn)); - $this->itemMapper->expects($this->once()) - ->method('findByGuidHash') - ->with($this->equalTo($item->getGuidHash()), - $this->equalTo($feed->getId()), - $this->equalTo($this->user)) - ->will($this->returnValue($item)); - $this->itemMapper->expects($this->never()) - ->method('insert'); - $this->itemMapper->expects($this->never()) - ->method('delete'); - - $this->feedMapper->expects($this->at(1)) - ->method('find') - ->with($feed->getId(), $this->user) - ->will($this->returnValue($feed)); - - $return = $this->feedBusinessLayer->update($feed->getId(), $this->user); - - $this->assertEquals($return, $feed); - } - - - public function testUpdateUpdatesEntryNotWhenPubDateUnkown(){ - $feed = new Feed(); - $feed->setId(3); - $feed->getUrl('test'); - - $item = new Item(); - $item->setGuidHash(md5('hi')); - $item->setPubDate(false); - $items = array( - $item - ); - - $item2 = new Item(); - $item2->setPubDate(0); - - $fetchReturn = array($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') - ->will($this->returnValue($fetchReturn)); - $this->itemMapper->expects($this->once()) - ->method('findByGuidHash') - ->with($this->equalTo($item->getGuidHash()), - $this->equalTo($feed->getId()), - $this->equalTo($this->user)) - ->will($this->returnValue($item2)); - $this->itemMapper->expects($this->never()) - ->method('insert'); - $this->itemMapper->expects($this->never()) - ->method('delete'); - - $this->feedMapper->expects($this->at(1)) - ->method('find') - ->with($feed->getId(), $this->user) - ->will($this->returnValue($feed)); - - $return = $this->feedBusinessLayer->update($feed->getId(), $this->user); - - $this->assertEquals($return, $feed); - } - - public function testUpdateUpdatesEntryNotWhenNoPubDate(){ - $feed = new Feed(); - $feed->setId(3); - $feed->getUrl('test'); - - $item = new Item(); - $item->setGuidHash(md5('hi')); - $item->setPubDate(null); - $items = array( - $item - ); - - $item2 = new Item(); - $item2->setPubDate(null); - - $fetchReturn = array($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') - ->will($this->returnValue($fetchReturn)); - $this->itemMapper->expects($this->once()) - ->method('findByGuidHash') - ->with($this->equalTo($item->getGuidHash()), - $this->equalTo($feed->getId()), - $this->equalTo($this->user)) - ->will($this->returnValue($item2)); - $this->itemMapper->expects($this->never()) - ->method('insert'); - $this->itemMapper->expects($this->never()) - ->method('delete'); - - $this->feedMapper->expects($this->at(1)) - ->method('find') - ->with($feed->getId(), $this->user) - ->will($this->returnValue($feed)); - - $return = $this->feedBusinessLayer->update($feed->getId(), $this->user); - - $this->assertEquals($return, $feed); - } - - - public function testCreateUpdateFails(){ + public function testUpdateFails(){ $feed = new Feed(); $feed->setId(3); $feed->getUrl('test'); |