summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorBernhard Posselt <nukeawhale@gmail.com>2013-08-02 14:34:08 +0200
committerBernhard Posselt <nukeawhale@gmail.com>2013-08-02 14:34:08 +0200
commit27c7c7773eaaa0aa15fbf5bffeee501941d0d339 (patch)
tree18b1bcdb4e3d06c509d519cdb1865a626190c930 /tests
parent3b3b5b9033b060bc8428a397b34ccb2cad0d8307 (diff)
add api for updating feeds with a seperate cron job, #301
Diffstat (limited to 'tests')
-rw-r--r--tests/unit/businesslayer/FeedBusinessLayerTest.php35
-rw-r--r--tests/unit/external/FeedAPITest.php62
2 files changed, 86 insertions, 11 deletions
diff --git a/tests/unit/businesslayer/FeedBusinessLayerTest.php b/tests/unit/businesslayer/FeedBusinessLayerTest.php
index 0e3532f16..c16a8c4ae 100644
--- a/tests/unit/businesslayer/FeedBusinessLayerTest.php
+++ b/tests/unit/businesslayer/FeedBusinessLayerTest.php
@@ -72,7 +72,7 @@ class FeedBusinessLayerTest extends \OCA\AppFramework\Utility\TestUtility {
$this->importParser = $this->getMockBuilder('\OCA\News\Utility\ImportParser')
->disableOriginalConstructor()
->getMock();
- $this->feedBusinessLayer = new FeedBusinessLayer($this->feedMapper,
+ $this->feedBusinessLayer = new FeedBusinessLayer($this->feedMapper,
$this->fetcher, $this->itemMapper, $this->api,
$timeFactory, $this->importParser, $this->autoPurgeMinimumInterval);
$this->user = 'jack';
@@ -159,7 +159,7 @@ class FeedBusinessLayerTest extends \OCA\AppFramework\Utility\TestUtility {
$this->itemMapper->expects($this->at(3))
->method('insert')
->with($this->equalTo($return[1][0]));
-
+
$feed = $this->feedBusinessLayer->create($url, $folderId, $this->user);
$this->assertEquals($feed->getFolderId(), $folderId);
@@ -210,7 +210,7 @@ class FeedBusinessLayerTest extends \OCA\AppFramework\Utility\TestUtility {
$this->equalTo($item1->getGuidHash()),
$this->equalTo($item1->getFeedId()),
$this->equalTo($this->user));
-
+
$feed = $this->feedBusinessLayer->create($url, $folderId, $this->user);
$this->assertEquals($feed->getFolderId(), $folderId);
@@ -288,7 +288,7 @@ class FeedBusinessLayerTest extends \OCA\AppFramework\Utility\TestUtility {
->will($this->returnValue($fetchReturn));
$this->itemMapper->expects($this->once())
->method('findByGuidHash')
- ->with($this->equalTo($item->getGuidHash()),
+ ->with($this->equalTo($item->getGuidHash()),
$this->equalTo($feed->getId()),
$this->equalTo($this->user))
->will($this->returnValue($item));
@@ -296,7 +296,7 @@ class FeedBusinessLayerTest extends \OCA\AppFramework\Utility\TestUtility {
->method('insert');
$this->itemMapper->expects($this->never())
->method('delete');
-
+
$this->feedMapper->expects($this->at(1))
->method('find')
->with($feed->getId(), $this->user)
@@ -417,7 +417,7 @@ class FeedBusinessLayerTest extends \OCA\AppFramework\Utility\TestUtility {
->will($this->throwException($ex));
$this->api->expects($this->any())
->method('log');
-
+
$this->feedMapper->expects($this->at(1))
->method('find')
->with($feed->getId(), $this->user)
@@ -433,7 +433,7 @@ class FeedBusinessLayerTest extends \OCA\AppFramework\Utility\TestUtility {
$feed = new Feed();
$feed->setId(3);
$feed->getUrl('test');
-
+
$ex = new DoesNotExistException('');
$this->feedMapper->expects($this->at(0))
@@ -446,7 +446,7 @@ class FeedBusinessLayerTest extends \OCA\AppFramework\Utility\TestUtility {
$return = $this->feedBusinessLayer->update($feed->getId(), $this->user);
}
-
+
public function testUpdateDoesNotFindUpdatedEntry() {
$feed = new Feed();
$feed->setId(3);
@@ -476,11 +476,11 @@ class FeedBusinessLayerTest extends \OCA\AppFramework\Utility\TestUtility {
->will($this->returnValue($fetchReturn));
$this->itemMapper->expects($this->once())
->method('findByGuidHash')
- ->with($this->equalTo($item->getGuidHash()),
+ ->with($this->equalTo($item->getGuidHash()),
$this->equalTo($feed->getId()),
$this->equalTo($this->user))
->will($this->returnValue($item2));;
-
+
$this->feedMapper->expects($this->at(1))
->method('find')
->with($this->equalTo($feed->getId()),
@@ -502,7 +502,7 @@ class FeedBusinessLayerTest extends \OCA\AppFramework\Utility\TestUtility {
$this->feedMapper->expects($this->once())
->method('find')
- ->with($this->equalTo($feedId),
+ ->with($this->equalTo($feedId),
$this->equalTo($this->user))
->will($this->returnValue($feed));
$this->fetcher->expects($this->never())
@@ -711,4 +711,17 @@ class FeedBusinessLayerTest extends \OCA\AppFramework\Utility\TestUtility {
$this->feedBusinessLayer->purgeDeleted($this->user, false);
}
+
+
+ public function testfindAllFromAllUsers() {
+ $expected = 'hi';
+ $this->feedMapper->expects($this->once())
+ ->method('findAll')
+ ->will($this->returnValue($expected));
+ $result = $this->feedBusinessLayer->findAllFromAllUsers();
+ $this->assertEquals($expected, $result);
+ }
+
+
}
+
diff --git a/tests/unit/external/FeedAPITest.php b/tests/unit/external/FeedAPITest.php
index a42a1c8c9..6b133610e 100644
--- a/tests/unit/external/FeedAPITest.php
+++ b/tests/unit/external/FeedAPITest.php
@@ -115,6 +115,15 @@ class FeedAPITest extends ControllerTestUtility {
}
+ public function testGetAllFromUsersAnnotations(){
+ $this->assertDefaultAnnotations('getAllFromAllUsers');
+ }
+
+
+ public function testUpdateAnnotations(){
+ $this->assertDefaultAnnotations('update');
+ }
+
public function testGetAll() {
$feeds = array(
new Feed()
@@ -439,4 +448,57 @@ class FeedAPITest extends ControllerTestUtility {
$this->assertEquals($this->msg, $data['message']);
$this->assertEquals(Http::STATUS_NOT_FOUND, $response->getStatus());
}
+
+
+ public function testGetAllFromAllUsers(){
+ $feed = new Feed();
+ $feed->setUrl(3);
+ $feed->setId(1);
+ $feed->setUserId('john');
+ $feeds = array($feed);
+ $this->feedBusinessLayer->expects($this->once())
+ ->method('findAllFromAllUsers')
+ ->will($this->returnValue($feeds));
+ $response = $this->feedAPI->getAllFromAllUsers();
+ $this->assertTrue($response instanceof JSONResponse);
+ $this->assertEquals('{"feeds":[{"id":1,"userId":"john"}]}', $response->render());
+ }
+
+
+ public function testUpdate() {
+ $feedId = 3;
+ $userId = 'hi';
+ $request = new Request(array('params' => array(
+ 'feedId' => $feedId,
+ 'userId' => $userId
+ )));
+ $this->feedAPI = new FeedAPI(
+ $this->api,
+ $request,
+ $this->folderBusinessLayer,
+ $this->feedBusinessLayer,
+ $this->itemBusinessLayer
+ );
+ $this->feedBusinessLayer->expects($this->once())
+ ->method('update')
+ ->with($this->equalTo($feedId), $this->equalTo($userId));
+
+ $this->feedAPI->update();
+ }
+
+
+ public function testUpdateNotFound() {
+ $this->feedBusinessLayer->expects($this->once())
+ ->method('update')
+ ->will($this->throwException(new BusinessLayerException($this->msg)));
+
+ $response = $this->feedAPI->update();
+
+ $data = $response->getData();
+ $this->assertEquals($this->msg, $data['message']);
+ $this->assertEquals(Http::STATUS_NOT_FOUND, $response->getStatus());
+
+ }
+
+
}