summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBernhard Posselt <nukeawhale@gmail.com>2013-03-23 13:24:35 +0100
committerBernhard Posselt <nukeawhale@gmail.com>2013-03-23 13:24:35 +0100
commit3455fe9cb792e584671f465ff6d51732fc1802ff (patch)
tree817a26f6d03bed8939c0842a63ca5349e28ed099
parentf4f27ab927f16d7ff8900e92ecf7aee75f355f34 (diff)
finished findall methods in itembl
-rw-r--r--README.rst2
-rw-r--r--bl/itembl.php43
-rw-r--r--db/itemmapper.php29
-rw-r--r--db/statusflag.php22
-rw-r--r--dependencyinjection/dicontainer.php7
-rw-r--r--tests/bl/ItemBlTest.php127
-rw-r--r--tests/bl/StatusFlagTest.php74
7 files changed, 289 insertions, 15 deletions
diff --git a/README.rst b/README.rst
index 39367b96e..56dcaf6e2 100644
--- a/README.rst
+++ b/README.rst
@@ -9,7 +9,7 @@ TODO
* Referential integrity (delete items and feeds when feed or folder with FK was deleted)
* Port coffeescript
* make export work -> generate xml with template
-* implement findAll methods in itemBl and itemMapper
+* implement findAll methods in itemMapper
* make feed update work
* fix search plugin
* fix background job \ No newline at end of file
diff --git a/bl/itembl.php b/bl/itembl.php
index 6f3e5d002..c45ee3a91 100644
--- a/bl/itembl.php
+++ b/bl/itembl.php
@@ -27,24 +27,61 @@ namespace OCA\News\Bl;
use \OCA\News\Db\Item;
use \OCA\News\Db\ItemMapper;
+use \OCA\News\Db\StatusFlag;
+use \OCA\News\Db\FeedType;
class ItemBl extends Bl {
- public function __construct(ItemMapper $itemMapper){
+ private $statusFlag;
+
+ public function __construct(ItemMapper $itemMapper, StatusFlag $statusFlag){
parent::__construct($itemMapper);
+ $this->statusFlag = $statusFlag;
}
public function findAllNew($id, $type, $updatedSince,
$showAll, $userId){
- // TODO all the crazy finding of items
+ $status = $this->statusFlag->typeToStatus($type, $showAll);
+
+ switch($type){
+ case FeedType::FEED:
+ $items = $this->mapper->findAllNewFeed($id, $updatedSince,
+ $status, $userId);
+ break;
+ case FeedType::FOLDER:
+ $items = $this->mapper->findAllNewFolder($id, $updatedSince,
+ $status, $userId);
+ break;
+ default:
+ $items = $this->mapper->findAllNew($updatedSince, $status,
+ $userId);
+ }
+
+ return $items;
}
public function findAll($id, $type, $limit, $offset,
$showAll, $userId){
- // TODO all the crazy finding of items
+ $status = $this->statusFlag->typeToStatus($type, $showAll);
+
+ switch($type){
+ case FeedType::FEED:
+ $items = $this->mapper->findAllFeed($id, $limit, $offset,
+ $status, $userId);
+ break;
+ case FeedType::FOLDER:
+ $items = $this->mapper->findAllFolder($id, $limit, $offset,
+ $status, $userId);
+ break;
+ default:
+ $items = $this->mapper->findAll($limit, $offset, $status,
+ $userId);
+ }
+
+ return $items;
}
diff --git a/db/itemmapper.php b/db/itemmapper.php
index 7d0279264..77621be2a 100644
--- a/db/itemmapper.php
+++ b/db/itemmapper.php
@@ -104,6 +104,35 @@ class ItemMapper extends Mapper implements IMapper {
}
+ public function findAllNewFeed($id, $updatedSince, $status, $userId){
+ // TODO
+ }
+
+
+ public function findAllNewFolder($id, $updatedSince, $status, $userId){
+ // TODO
+ }
+
+
+ public function findAllNew($updatedSince, $status, $userId){
+ // TODO
+ }
+
+
+ public function findAllFeed($id, $limit, $offset, $status, $userId){
+ // TODO
+ }
+
+
+ public function findAllFolder($id, $limit, $offset, $status, $userId){
+ // TODO
+ }
+
+
+ public function findAll($limit, $offset, $status, $userId){
+ // TODO
+ }
+
}
/**
* Queries to find all items from a folder that belongs to a user
diff --git a/db/statusflag.php b/db/statusflag.php
index eccf1e199..96d64915b 100644
--- a/db/statusflag.php
+++ b/db/statusflag.php
@@ -30,4 +30,26 @@ class StatusFlag {
const STARRED = 0x04;
const DELETED = 0x08;
const UPDATED = 0x16;
+
+
+ /**
+ * Get status for query
+ */
+ public function typeToStatus($type, $showAll){
+ if($type === FeedType::STARRED){
+ $status = self::STARRED;
+ } else {
+ $status = 0;
+ }
+
+ if($showAll){
+ $status |= self::UNREAD;
+ } else {
+ $status &= ~self::UNREAD;
+ }
+
+ return $status;
+ }
+
+
} \ No newline at end of file
diff --git a/dependencyinjection/dicontainer.php b/dependencyinjection/dicontainer.php
index 970900ea5..319517ba1 100644
--- a/dependencyinjection/dicontainer.php
+++ b/dependencyinjection/dicontainer.php
@@ -41,6 +41,7 @@ use OCA\News\Bl\ItemBl;
use OCA\News\Db\FolderMapper;
use OCA\News\Db\FeedMapper;
use OCA\News\Db\ItemMapper;
+use OCA\News\Db\StatusFlag;
require_once __DIR__ . '/../3rdparty/SimplePie/autoloader.php';
@@ -99,7 +100,7 @@ class DIContainer extends BaseContainer {
});
$this['ItemBl'] = $this->share(function($c){
- return new ItemBl($c['ItemMapper']);
+ return new ItemBl($c['ItemMapper'], $c['StatusFlag']);
});
@@ -126,6 +127,10 @@ class DIContainer extends BaseContainer {
return new FeedFetcher();
});
+ $this['StatusFlag'] = $this->share(function($c){
+ return new StatusFlag();
+ });
+
}
}
diff --git a/tests/bl/ItemBlTest.php b/tests/bl/ItemBlTest.php
index 4b4c71219..e8c4cc9d7 100644
--- a/tests/bl/ItemBlTest.php
+++ b/tests/bl/ItemBlTest.php
@@ -29,41 +29,148 @@ require_once(__DIR__ . "/../classloader.php");
use \OCA\News\Db\Item;
+use \OCA\News\Db\StatusFlag;
+use \OCA\News\Db\FeedType;
class ItemBlTest extends \OCA\AppFramework\Utility\TestUtility {
- protected $api;
- protected $mapper;
- protected $bl;
- protected $user;
- protected $response;
+ private $api;
+ private $mapper;
+ private $bl;
+ private $user;
+ private $response;
+ private $status;
+
protected function setUp(){
$this->api = $this->getAPIMock();
$this->mapper = $this->getMockBuilder('\OCA\News\Db\ItemMapper')
->disableOriginalConstructor()
->getMock();
- $this->bl = new ItemBl($this->mapper);
+ $statusFlag = $this->getMockBuilder('\OCA\News\Db\StatusFlag')
+ ->disableOriginalConstructor()
+ ->getMock();
+ $this->status = StatusFlag::STARRED;
+ $statusFlag->expects($this->any())
+ ->method('typeToStatus')
+ ->will($this->returnValue($this->status));
+ $this->bl = new ItemBl($this->mapper, $statusFlag);
$this->user = 'jack';
$response = 'hi';
+ $this->id = 3;
+ $this->updatedSince = 20333;
+ $this->showAll = true;
+ $this->offset = 5;
+ $this->limit = 20;
+ }
+
+
+ public function testFindAllNewFeed(){
+ $type = FeedType::FEED;
+ $this->mapper->expects($this->once())
+ ->method('findAllNewFeed')
+ ->with($this->equalTo($this->id),
+ $this->equalTo($this->updatedSince),
+ $this->equalTo($this->status),
+ $this->equalTo($this->user))
+ ->will($this->returnValue($this->response));
+
+ $result = $this->bl->findAllNew(
+ $this->id, $type, $this->updatedSince, $this->showAll,
+ $this->user);
+ $this->assertEquals($this->response, $result);
+ }
+
+
+ public function testFindAllNewFolder(){
+ $type = FeedType::FOLDER;
+ $this->mapper->expects($this->once())
+ ->method('findAllNewFolder')
+ ->with($this->equalTo($this->id),
+ $this->equalTo($this->updatedSince),
+ $this->equalTo($this->status),
+ $this->equalTo($this->user))
+ ->will($this->returnValue($this->response));
+
+ $result = $this->bl->findAllNew(
+ $this->id, $type, $this->updatedSince, $this->showAll,
+ $this->user);
+ $this->assertEquals($this->response, $result);
+ }
+
+
+ public function testFindAllNew(){
+ $type = FeedType::STARRED;
+ $this->mapper->expects($this->once())
+ ->method('findAllNew')
+ ->with( $this->equalTo($this->updatedSince),
+ $this->equalTo($this->status),
+ $this->equalTo($this->user))
+ ->will($this->returnValue($this->response));
+
+ $result = $this->bl->findAllNew(
+ $this->id, $type, $this->updatedSince, $this->showAll,
+ $this->user);
+ $this->assertEquals($this->response, $result);
+ }
+
+
+ public function testFindAllFeed(){
+ $type = FeedType::FEED;
+ $this->mapper->expects($this->once())
+ ->method('findAllFeed')
+ ->with($this->equalTo($this->id),
+ $this->equalTo($this->limit),
+ $this->equalTo($this->offset),
+ $this->equalTo($this->status),
+ $this->equalTo($this->user))
+ ->will($this->returnValue($this->response));
+
+ $result = $this->bl->findAll(
+ $this->id, $type, $this->limit,
+ $this->offset, $this->showAll,
+ $this->user);
+ $this->assertEquals($this->response, $result);
}
+ public function testFindAllFolder(){
+ $type = FeedType::FOLDER;
+ $this->mapper->expects($this->once())
+ ->method('findAllFolder')
+ ->with($this->equalTo($this->id),
+ $this->equalTo($this->limit),
+ $this->equalTo($this->offset),
+ $this->equalTo($this->status),
+ $this->equalTo($this->user))
+ ->will($this->returnValue($this->response));
+
+ $result = $this->bl->findAll(
+ $this->id, $type, $this->limit,
+ $this->offset, $this->showAll,
+ $this->user);
+ $this->assertEquals($this->response, $result);
+ }
- /*
public function testFindAll(){
+ $type = FeedType::STARRED;
$this->mapper->expects($this->once())
->method('findAll')
- ->with($this->equalTo($this->user))
+ ->with( $this->equalTo($this->limit),
+ $this->equalTo($this->offset),
+ $this->equalTo($this->status),
+ $this->equalTo($this->user))
->will($this->returnValue($this->response));
- $result = $this->bl->findAllFromUser($this->user);
+ $result = $this->bl->findAll(
+ $this->id, $type, $this->limit,
+ $this->offset, $this->showAll,
+ $this->user);
$this->assertEquals($this->response, $result);
}
- */
public function testStarredCount(){
$star = 18;
diff --git a/tests/bl/StatusFlagTest.php b/tests/bl/StatusFlagTest.php
new file mode 100644
index 000000000..9e9be9fca
--- /dev/null
+++ b/tests/bl/StatusFlagTest.php
@@ -0,0 +1,74 @@
+<?php
+
+/**
+* ownCloud - News
+*
+* @author Alessandro Copyright
+* @author Bernhard Posselt
+* @copyright 2012 Alessandro Cosentino cosenal@gmail.com
+* @copyright 2012 Bernhard Posselt nukeawhale@gmail.com
+*
+* This library is free software; you can redistribute it and/or
+* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
+* License as published by the Free Software Foundation; either
+* version 3 of the License, or any later version.
+*
+* This library is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
+*
+* You should have received a copy of the GNU Affero General Public
+* License along with this library. If not, see <http://www.gnu.org/licenses/>.
+*
+*/
+
+namespace OCA\News\Db;
+
+use \OCA\AppFramework\Utility\TestUtility;
+
+
+require_once(__DIR__ . "/../classloader.php");
+
+
+class StatusFlagTest extends TestUtility {
+
+ private $statusFlag;
+
+ protected function setUp(){
+ $this->statusFlag = new StatusFlag();
+ }
+
+
+ public function testTypeToStatusUnreadStarred(){
+ $expected = StatusFlag::UNREAD | StatusFlag::STARRED;
+ $status = $this->statusFlag->typeToStatus(FeedType::STARRED, true);
+
+ $this->assertEquals($expected, $status);
+ }
+
+
+ public function testTypeToStatusUnread(){
+ $expected = StatusFlag::UNREAD;
+ $status = $this->statusFlag->typeToStatus(FeedType::FEED, true);
+
+ $this->assertEquals($expected, $status);
+ }
+
+
+ public function testTypeToStatusReadStarred(){
+ $expected = (~StatusFlag::UNREAD) & StatusFlag::STARRED;
+ $status = $this->statusFlag->typeToStatus(FeedType::STARRED, false);
+
+ $this->assertEquals($expected, $status);
+ }
+
+
+ public function testTypeToStatusRead(){
+ $expected = (~StatusFlag::UNREAD) & 0;
+ $status = $this->statusFlag->typeToStatus(FeedType::FEED, false);
+
+ $this->assertEquals($expected, $status);
+ }
+
+} \ No newline at end of file