summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--controller/itemcontroller.php15
-rw-r--r--dependencyinjection/dicontainer.php16
-rw-r--r--tests/unit/controller/ItemControllerTest.php51
3 files changed, 71 insertions, 11 deletions
diff --git a/controller/itemcontroller.php b/controller/itemcontroller.php
index 9081578ed..84f177cd6 100644
--- a/controller/itemcontroller.php
+++ b/controller/itemcontroller.php
@@ -30,16 +30,20 @@ use \OCA\AppFramework\Core\API;
use \OCA\AppFramework\Http\Request;
use \OCA\News\BusinessLayer\ItemBusinessLayer;
+use \OCA\News\BusinessLayer\FeedBusinessLayer;
class ItemController extends Controller {
private $itemBusinessLayer;
+ private $feedBusinessLayer;
public function __construct(API $api, Request $request,
- ItemBusinessLayer $itemBusinessLayer){
+ ItemBusinessLayer $itemBusinessLayer,
+ FeedBusinessLayer $feedBusinessLayer){
parent::__construct($api, $request);
$this->itemBusinessLayer = $itemBusinessLayer;
+ $this->feedBusinessLayer = $feedBusinessLayer;
}
@@ -63,6 +67,9 @@ class ItemController extends Controller {
$offset = (int) $this->params('offset', 0);
$items = $this->itemBusinessLayer->findAll($id, $type, (int) $limit,
$offset, $showAll, $userId);
+ if($offset === 0) {
+ $feeds = $this->feedBusinessLayer->findAll($userId);
+ }
} else {
$updatedSince = (int) $this->params('updatedSince');
$items = $this->itemBusinessLayer->findAllNew($id, $type,
@@ -73,6 +80,12 @@ class ItemController extends Controller {
'items' => $items
);
+ // we need to pass the newest feeds to not let the unread count get out
+ // of sync
+ if(isset($feeds)) {
+ $params['feeds'] = $feeds;
+ }
+
return $this->renderJSON($params);
}
diff --git a/dependencyinjection/dicontainer.php b/dependencyinjection/dicontainer.php
index 10dd56578..80a88f0c4 100644
--- a/dependencyinjection/dicontainer.php
+++ b/dependencyinjection/dicontainer.php
@@ -75,21 +75,25 @@ class DIContainer extends BaseContainer {
});
$this['FolderController'] = $this->share(function($c){
- return new FolderController($c['API'], $c['Request'], $c['FolderBusinessLayer']);
+ return new FolderController($c['API'], $c['Request'],
+ $c['FolderBusinessLayer']);
});
$this['FeedController'] = $this->share(function($c){
- return new FeedController($c['API'], $c['Request'], $c['FeedBusinessLayer'],
- $c['FolderBusinessLayer']);
+ return new FeedController($c['API'], $c['Request'],
+ $c['FeedBusinessLayer'], $c['FolderBusinessLayer']);
});
$this['ItemController'] = $this->share(function($c){
- return new ItemController($c['API'], $c['Request'], $c['ItemBusinessLayer']);
+ return new ItemController($c['API'], $c['Request'],
+ $c['ItemBusinessLayer'], $c['FeedBusinessLayer']);
});
$this['ExportController'] = $this->share(function($c){
- return new ExportController($c['API'], $c['Request'], $c['FeedBusinessLayer'],
- $c['FolderBusinessLayer'], $c['OPMLExporter']);
+ return new ExportController($c['API'], $c['Request'],
+ $c['FeedBusinessLayer'],
+ $c['FolderBusinessLayer'],
+ $c['OPMLExporter']);
});
$this['UserSettingsController'] = $this->share(function($c){
diff --git a/tests/unit/controller/ItemControllerTest.php b/tests/unit/controller/ItemControllerTest.php
index 417997d30..00d455830 100644
--- a/tests/unit/controller/ItemControllerTest.php
+++ b/tests/unit/controller/ItemControllerTest.php
@@ -30,6 +30,7 @@ use \OCA\AppFramework\Http\JSONResponse;
use \OCA\AppFramework\Utility\ControllerTestUtility;
use \OCA\News\Db\Item;
+use \OCA\News\Db\Feed;
use \OCA\News\Db\FeedType;
require_once(__DIR__ . "/../../classloader.php");
@@ -39,6 +40,7 @@ class ItemControllerTest extends ControllerTestUtility {
private $api;
private $itemBusinessLayer;
+ private $feedBusinessLayer;
private $request;
private $controller;
@@ -48,12 +50,17 @@ class ItemControllerTest extends ControllerTestUtility {
*/
public function setUp(){
$this->api = $this->getAPIMock();
- $this->itemBusinessLayer = $this->getMockBuilder('\OCA\News\BusinessLayer\ItemBusinessLayer')
+ $this->itemBusinessLayer =
+ $this->getMockBuilder('\OCA\News\BusinessLayer\ItemBusinessLayer')
+ ->disableOriginalConstructor()
+ ->getMock();
+ $this->feedBusinessLayer =
+ $this->getMockBuilder('\OCA\News\BusinessLayer\FeedBusinessLayer')
->disableOriginalConstructor()
->getMock();
$this->request = new Request();
$this->controller = new ItemController($this->api, $this->request,
- $this->itemBusinessLayer);
+ $this->itemBusinessLayer, $this->feedBusinessLayer);
$this->user = 'jackob';
}
@@ -64,7 +71,8 @@ class ItemControllerTest extends ControllerTestUtility {
);
$request = $this->getRequest($post);
- return new ItemController($this->api, $request, $this->itemBusinessLayer);
+ return new ItemController($this->api, $request, $this->itemBusinessLayer,
+ $this->feedBusinessLayer);
}
@@ -258,8 +266,10 @@ class ItemControllerTest extends ControllerTestUtility {
public function testItems(){
+ $feeds = array(new Feed());
$result = array(
- 'items' => array(new Item())
+ 'items' => array(new Item()),
+ 'feeds' => $feeds
);
$post = array(
'limit' => 3,
@@ -277,12 +287,45 @@ class ItemControllerTest extends ControllerTestUtility {
$post['offset'], true, $this->user)
->will($this->returnValue($result['items']));
+ $this->feedBusinessLayer->expects($this->once())
+ ->method('findAll')
+ ->with($this->equalTo($this->user))
+ ->will($this->returnValue($feeds));
+
$response = $this->controller->items();
$this->assertEquals($result, $response->getParams());
$this->assertTrue($response instanceof JSONResponse);
}
+ public function testItemsDoesNotReturnFeedsIfOffsetNotZero(){
+ $result = array(
+ 'items' => array(new Item())
+ );
+ $post = array(
+ 'limit' => 3,
+ 'type' => FeedType::FEED,
+ 'id' => 2,
+ 'offset' => 10
+ );
+ $this->controller = $this->getPostController($post);
+
+ $this->itemsApiExpects($post['id'], $post['type']);
+
+ $this->itemBusinessLayer->expects($this->once())
+ ->method('findAll')
+ ->with($post['id'], $post['type'], $post['limit'],
+ $post['offset'], true, $this->user)
+ ->will($this->returnValue($result['items']));
+
+ $this->feedBusinessLayer->expects($this->never())
+ ->method('findAll');
+
+ $response = $this->controller->items();
+ $this->assertEquals($result, $response->getParams());
+ $this->assertTrue($response instanceof JSONResponse);
+ }
+
public function testItemsNew(){
$result = array(
'items' => array(new Item())