summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorBernhard Posselt <nukeawhale@gmail.com>2013-03-25 12:54:38 +0100
committerBernhard Posselt <nukeawhale@gmail.com>2013-03-25 12:54:38 +0100
commit0f9e0e3de77de68cc75ccd69395665f9e1346951 (patch)
treebe6398f7134c3192e4ee0f89a88cbbfadfffc808 /tests
parent77ec6f08aa4fb223fba859ca0f6060e84006da43 (diff)
implemented feed update
Diffstat (limited to 'tests')
-rw-r--r--tests/bl/FeedBlTest.php109
-rw-r--r--tests/bl/ItemBlTest.php11
-rw-r--r--tests/db/ItemMapperTest.php16
3 files changed, 112 insertions, 24 deletions
diff --git a/tests/bl/FeedBlTest.php b/tests/bl/FeedBlTest.php
index 15414a721..2ec3d3e47 100644
--- a/tests/bl/FeedBlTest.php
+++ b/tests/bl/FeedBlTest.php
@@ -23,7 +23,12 @@
*
*/
-namespace OCA\News\Bl;
+namespace {
+ class DatabaseException extends Exception{};
+}
+
+
+namespace OCA\News\Bl {
require_once(__DIR__ . "/../classloader.php");
@@ -42,7 +47,7 @@ class FeedBlTest extends \OCA\AppFramework\Utility\TestUtility {
protected $user;
protected $response;
protected $fetcher;
- protected $itemBl;
+ protected $itemMapper;
protected function setUp(){
$this->api = $this->getAPIMock();
@@ -52,10 +57,11 @@ class FeedBlTest extends \OCA\AppFramework\Utility\TestUtility {
$this->fetcher = $this->getMockBuilder('\OCA\News\Utility\FeedFetcher')
->disableOriginalConstructor()
->getMock();
- $this->itemBl = $this->getMockBuilder('\OCA\News\Bl\ItemBl')
+ $this->itemMapper = $this->getMockBuilder('\OCA\News\Db\ItemMapper')
->disableOriginalConstructor()
->getMock();
- $this->bl = new FeedBl($this->mapper, $this->fetcher, $this->itemBl);
+ $this->bl = new FeedBl($this->mapper,
+ $this->fetcher, $this->itemMapper, $this->api);
$this->user = 'jack';
$response = 'hi';
}
@@ -110,11 +116,11 @@ class FeedBlTest extends \OCA\AppFramework\Utility\TestUtility {
->method('insert')
->with($this->equalTo($createdFeed))
->will($this->returnValue($createdFeed));
- $this->itemBl->expects($this->at(0))
- ->method('create')
+ $this->itemMapper->expects($this->at(0))
+ ->method('insert')
->with($this->equalTo($return[1][0]));
- $this->itemBl->expects($this->at(1))
- ->method('create')
+ $this->itemMapper->expects($this->at(1))
+ ->method('insert')
->with($this->equalTo($return[1][1]));
$feed = $this->bl->create($url, $folderId, $this->user);
@@ -130,14 +136,95 @@ class FeedBlTest extends \OCA\AppFramework\Utility\TestUtility {
->with($this->equalTo(md5($url)), $this->equalTo($this->user));
$this->setExpectedException('\OCA\News\Bl\BLException');
$this->bl->create($url, 1, $this->user);
+ }
+
+
+ public function testUpdateCreatesNewEntry(){
+ $feed = new Feed();
+ $feed->setId(3);
+ $feed->getUrl('test');
+
+ $item = new Item();
+ $item->setGuidHash(md5('hi'));
+ $items = array(
+ $item
+ );
+
+ $fetchReturn = array($feed, $items);
+ $this->mapper->expects($this->once())
+ ->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('insert')
+ ->with($this->equalTo($items[0]));
+
+ $this->bl->update($feed->getId(), $this->user);
}
- public function testUpdate(){
- // TODO
+ public function testUpdateUpdatesEntry(){
+ $feed = new Feed();
+ $feed->setId(3);
+ $feed->getUrl('test');
+ $ex = new \DatabaseException('');
+
+ $item = new Item();
+ $item->setGuidHash(md5('hi'));
+ $items = array(
+ $item
+ );
+
+ $fetchReturn = array($feed, $items);
+
+ $this->mapper->expects($this->once())
+ ->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('insert')
+ ->with($this->equalTo($items[0]))
+ ->will($this->throwException($ex));
+ $this->itemMapper->expects($this->once())
+ ->method('findByGuidHash')
+ ->with($this->equalTo($item->getGuidHash()),
+ $this->equalTo($this->user))
+ ->will($this->returnValue($item));
+ $this->itemMapper->expects($this->once())
+ ->method('update')
+ ->with($this->equalTo($item));
+
+ $this->bl->update($feed->getId(), $this->user);
}
+ public function testCreateUpdateFails(){
+ $feed = new Feed();
+ $feed->setId(3);
+ $feed->getUrl('test');
+ $ex = new FetcherException('');
+
+ $this->mapper->expects($this->once())
+ ->method('find')
+ ->with($this->equalTo($feed->getId()),
+ $this->equalTo($this->user))
+ ->will($this->returnValue($feed));
+ $this->fetcher->expects($this->once())
+ ->method('fetch')
+ ->will($this->throwException($ex));
+ $this->api->expects($this->once())
+ ->method('log');
+
+ $this->bl->update($feed->getId(), $this->user);
+ }
public function testMove(){
$feedId = 3;
@@ -161,4 +248,6 @@ class FeedBlTest extends \OCA\AppFramework\Utility\TestUtility {
}
+}
+
} \ No newline at end of file
diff --git a/tests/bl/ItemBlTest.php b/tests/bl/ItemBlTest.php
index e8c4cc9d7..dcc208705 100644
--- a/tests/bl/ItemBlTest.php
+++ b/tests/bl/ItemBlTest.php
@@ -238,17 +238,6 @@ class ItemBlTest extends \OCA\AppFramework\Utility\TestUtility {
$this->bl->readFeed($feedId, $this->user);
}
-
- public function testCreate(){
- $item = new Item();
-
- $this->mapper->expects($this->once())
- ->method('insert')
- ->with($this->equalTo($item));
-
- $this->bl->create($item, $this->user);
- }
-
}
diff --git a/tests/db/ItemMapperTest.php b/tests/db/ItemMapperTest.php
index 626ac2cd0..433120a9f 100644
--- a/tests/db/ItemMapperTest.php
+++ b/tests/db/ItemMapperTest.php
@@ -88,13 +88,12 @@ class ItemMapperTest extends \OCA\AppFramework\Utility\MapperTestUtility {
public function testFind(){
- $sql = $this->makeSelectQuery('WHERE `*PREFIX*news_items`.`id` = ? ');
+ $sql = $this->makeSelectQuery('AND `*PREFIX*news_items`.`id` = ? ');
- $this->setMapperResult($sql, array($this->id, $this->userId), $this->row);
+ $this->setMapperResult($sql, array($this->userId, $this->id), $this->row);
$result = $this->mapper->find($this->id, $this->userId);
$this->assertEquals($this->items[0], $result);
-
}
@@ -248,4 +247,15 @@ class ItemMapperTest extends \OCA\AppFramework\Utility\MapperTestUtility {
$this->assertEquals($this->items, $result);
}
+
+ public function testFindByGuidHash(){
+ $hash = md5('test');
+ $sql = $this->makeSelectQuery('AND `*PREFIX*news_items`.`guid_hash` = ? ');
+
+ $this->setMapperResult($sql, array($this->userId, $hash), $this->row);
+
+ $result = $this->mapper->findByGuidHash($hash, $this->userId);
+ $this->assertEquals($this->items[0], $result);
+ }
+
} \ No newline at end of file