summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--controller/feedcontroller.php24
-rw-r--r--dependencyinjection/dicontainer.php3
-rw-r--r--tests/controller/FeedControllerTest.php83
3 files changed, 95 insertions, 15 deletions
diff --git a/controller/feedcontroller.php b/controller/feedcontroller.php
index 62af79197..27ab07408 100644
--- a/controller/feedcontroller.php
+++ b/controller/feedcontroller.php
@@ -32,16 +32,21 @@ use \OCA\AppFramework\Db\DoesNotExistException;
use \OCA\AppFramework\Db\MultipleObjectsReturnedException;
use \OCA\News\Bl\FeedBl;
+use \OCA\News\Bl\FolderBl;
use \OCA\News\Bl\BLException;
+use \OCA\News\Db\FeedType;
class FeedController extends Controller {
private $feedBl;
+ private $folderBl;
- public function __construct(API $api, Request $request, FeedBl $feedBl){
+ public function __construct(API $api, Request $request, FeedBl $feedBl,
+ FolderBl $folderBl){
parent::__construct($api, $request);
$this->feedBl = $feedBl;
+ $this->folderBl = $folderBl;
}
@@ -68,8 +73,21 @@ class FeedController extends Controller {
* @Ajax
*/
public function active(){
- $feedId = $this->api->getUserValue('lastViewedFeedId');
- $feedType = $this->api->getUserValue('lastViewedFeedType');
+ $userId = $this->api->getUserId();
+ $feedId = $this->api->getUserValue($userId, 'lastViewedFeedId');
+ $feedType = $this->api->getUserValue($userId, 'lastViewedFeedType');
+
+ // check if feed or folder exist
+ try {
+ if($feedType === FeedType::FOLDER){
+ $this->folderBl->find($feedId, $userId);
+ } elseif ($feedType === FeedType::FEED){
+ $this->feedBl->find($feedId, $userId);
+ }
+ } catch (BLException $ex){
+ $feedId = 0;
+ $feedType = FeedType::SUBSCRIPTIONS;
+ }
$params = array(
'activeFeed' => array(
diff --git a/dependencyinjection/dicontainer.php b/dependencyinjection/dicontainer.php
index 1a4535920..970900ea5 100644
--- a/dependencyinjection/dicontainer.php
+++ b/dependencyinjection/dicontainer.php
@@ -69,7 +69,8 @@ class DIContainer extends BaseContainer {
});
$this['FeedController'] = $this->share(function($c){
- return new FeedController($c['API'], $c['Request'], $c['FeedBl']);
+ return new FeedController($c['API'], $c['Request'], $c['FeedBl'],
+ $c['FolderBl']);
});
$this['ItemController'] = $this->share(function($c){
diff --git a/tests/controller/FeedControllerTest.php b/tests/controller/FeedControllerTest.php
index cfb78083e..6adae204c 100644
--- a/tests/controller/FeedControllerTest.php
+++ b/tests/controller/FeedControllerTest.php
@@ -32,6 +32,7 @@ use \OCA\AppFramework\Db\DoesNotExistException;
use \OCA\AppFramework\Db\MultipleObjectsReturnedException;
use \OCA\News\Db\Feed;
+use \OCA\News\Db\FeedType;
use \OCA\News\Bl\BLException;
@@ -44,6 +45,7 @@ class FeedControllerTest extends ControllerTestUtility {
private $bl;
private $request;
private $controller;
+ private $folderBl;
/**
@@ -54,9 +56,12 @@ class FeedControllerTest extends ControllerTestUtility {
$this->bl = $this->getMockBuilder('\OCA\News\Bl\FeedBl')
->disableOriginalConstructor()
->getMock();
+ $this->folderBl = $this->getMockBuilder('\OCA\News\Bl\FolderBl')
+ ->disableOriginalConstructor()
+ ->getMock();
$this->request = new Request();
$this->controller = new FeedController($this->api, $this->request,
- $this->bl);
+ $this->bl, $this->folderBl);
$this->user = 'jack';
}
@@ -73,7 +78,7 @@ class FeedControllerTest extends ControllerTestUtility {
);
$request = $this->getRequest($post);
- return new FeedController($this->api, $request, $this->bl);
+ return new FeedController($this->api, $request, $this->bl, $this->folderBl);
}
@@ -128,9 +133,24 @@ class FeedControllerTest extends ControllerTestUtility {
}
+ private function activeInitMocks($id, $type){
+ $this->api->expects($this->at(0))
+ ->method('getUserId')
+ ->will($this->returnValue($this->user));
+ $this->api->expects($this->at(1))
+ ->method('getUserValue')
+ ->with($this->equalTo($this->user), $this->equalTo('lastViewedFeedId'))
+ ->will($this->returnValue($id));
+ $this->api->expects($this->at(2))
+ ->method('getUserValue')
+ ->with($this->equalTo($this->user), $this->equalTo('lastViewedFeedType'))
+ ->will($this->returnValue($type));
+ }
+
+
public function testActive(){
$id = 3;
- $type = 2;
+ $type = FeedType::STARRED;
$result = array(
'activeFeed' => array(
'id' => $id,
@@ -138,14 +158,55 @@ class FeedControllerTest extends ControllerTestUtility {
)
);
- $this->api->expects($this->at(0))
- ->method('getUserValue')
- ->with($this->equalTo('lastViewedFeedId'))
- ->will($this->returnValue($id));
- $this->api->expects($this->at(1))
- ->method('getUserValue')
- ->with($this->equalTo('lastViewedFeedType'))
- ->will($this->returnValue($type));
+ $this->activeInitMocks($id, $type);
+
+ $response = $this->controller->active();
+
+ $this->assertEquals($result, $response->getParams());
+ $this->assertTrue($response instanceof JSONResponse);
+ }
+
+
+ public function testActiveFeedDoesNotExist(){
+ $id = 3;
+ $type = FeedType::FEED;
+ $ex = new BLException('hiu');
+ $result = array(
+ 'activeFeed' => array(
+ 'id' => 0,
+ 'type' => FeedType::SUBSCRIPTIONS
+ )
+ );
+ $this->bl->expects($this->once())
+ ->method('find')
+ ->with($this->equalTo($id), $this->equalTo($this->user))
+ ->will($this->throwException($ex));
+
+ $this->activeInitMocks($id, $type);
+
+ $response = $this->controller->active();
+
+ $this->assertEquals($result, $response->getParams());
+ $this->assertTrue($response instanceof JSONResponse);
+ }
+
+
+ public function testActiveFolderDoesNotExist(){
+ $id = 3;
+ $type = FeedType::FOLDER;
+ $ex = new BLException('hiu');
+ $result = array(
+ 'activeFeed' => array(
+ 'id' => 0,
+ 'type' => FeedType::SUBSCRIPTIONS
+ )
+ );
+ $this->folderBl->expects($this->once())
+ ->method('find')
+ ->with($this->equalTo($id), $this->equalTo($this->user))
+ ->will($this->throwException($ex));
+
+ $this->activeInitMocks($id, $type);
$response = $this->controller->active();