summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--businesslayer/itembusinesslayer.php8
-rw-r--r--dependencyinjection/dicontainer.php2
-rw-r--r--tests/unit/businesslayer/ItemBusinessLayerTest.php39
3 files changed, 40 insertions, 9 deletions
diff --git a/businesslayer/itembusinesslayer.php b/businesslayer/itembusinesslayer.php
index d97108431..4fbca4af0 100644
--- a/businesslayer/itembusinesslayer.php
+++ b/businesslayer/itembusinesslayer.php
@@ -25,6 +25,8 @@
namespace OCA\News\BusinessLayer;
+use \OCA\AppFramework\Utility\TimeFactory;
+
use \OCA\News\Db\Item;
use \OCA\News\Db\ItemMapper;
use \OCA\News\Db\StatusFlag;
@@ -35,12 +37,14 @@ class ItemBusinessLayer extends BusinessLayer {
private $statusFlag;
private $autoPurgeCount;
+ private $timeFactory;
public function __construct(ItemMapper $itemMapper, StatusFlag $statusFlag,
- $autoPurgeCount=0){
+ TimeFactory $timeFactory, $autoPurgeCount=0){
parent::__construct($itemMapper);
$this->statusFlag = $statusFlag;
$this->autoPurgeCount = $autoPurgeCount;
+ $this->timeFactory = $timeFactory;
}
@@ -96,6 +100,7 @@ class ItemBusinessLayer extends BusinessLayer {
public function star($feedId, $guidHash, $isStarred, $userId){
// FIXME: this can throw two possible exceptions
$item = $this->mapper->findByGuidHash($guidHash, $feedId, $userId);
+ $item->setLastModified($this->timeFactory->getTime());
if($isStarred){
$item->setStarred();
} else {
@@ -107,6 +112,7 @@ class ItemBusinessLayer extends BusinessLayer {
public function read($itemId, $isRead, $userId){
$item = $this->find($itemId, $userId);
+ $item->setLastModified($this->timeFactory->getTime());
if($isRead){
$item->setRead();
} else {
diff --git a/dependencyinjection/dicontainer.php b/dependencyinjection/dicontainer.php
index 80a88f0c4..a4202e12c 100644
--- a/dependencyinjection/dicontainer.php
+++ b/dependencyinjection/dicontainer.php
@@ -116,7 +116,7 @@ class DIContainer extends BaseContainer {
$this['ItemBusinessLayer'] = $this->share(function($c){
return new ItemBusinessLayer($c['ItemMapper'], $c['StatusFlag'],
- $c['autoPurgeCount']);
+ $c['TimeFactory'], $c['autoPurgeCount']);
});
diff --git a/tests/unit/businesslayer/ItemBusinessLayerTest.php b/tests/unit/businesslayer/ItemBusinessLayerTest.php
index e3ae280a6..17c477398 100644
--- a/tests/unit/businesslayer/ItemBusinessLayerTest.php
+++ b/tests/unit/businesslayer/ItemBusinessLayerTest.php
@@ -41,9 +41,18 @@ class ItemBusinessLayerTest extends \OCA\AppFramework\Utility\TestUtility {
private $user;
private $response;
private $status;
+ private $time;
protected function setUp(){
+ $this->time = 222;
+ $timeFactory = $this->getMockBuilder(
+ '\OCA\AppFramework\Utility\TimeFactory')
+ ->disableOriginalConstructor()
+ ->getMock();
+ $timeFactory->expects($this->any())
+ ->method('getTime')
+ ->will($this->returnValue($this->time));
$this->api = $this->getAPIMock();
$this->mapper = $this->getMockBuilder('\OCA\News\Db\ItemMapper')
->disableOriginalConstructor()
@@ -56,7 +65,8 @@ class ItemBusinessLayerTest extends \OCA\AppFramework\Utility\TestUtility {
->method('typeToStatus')
->will($this->returnValue($this->status));
$this->threshold = 2;
- $this->itemBusinessLayer = new ItemBusinessLayer($this->mapper, $statusFlag, $this->threshold);
+ $this->itemBusinessLayer = new ItemBusinessLayer($this->mapper,
+ $statusFlag, $timeFactory, $this->threshold);
$this->user = 'jack';
$response = 'hi';
$this->id = 3;
@@ -188,12 +198,20 @@ class ItemBusinessLayerTest extends \OCA\AppFramework\Utility\TestUtility {
public function testStar(){
- $feedId = 3;
+ $itemId = 3;
+ $feedId = 5;
$guidHash = md5('hihi');
$item = new Item();
$item->setStatus(128);
- $item->setId($feedId);
+ $item->setId($itemId);
+ $item->setUnstarred();
+
+ $expectedItem = new Item();
+ $expectedItem->setStatus(128);
+ $expectedItem->setStarred();
+ $expectedItem->setId($itemId);
+ $expectedItem->setLastModified($this->time);
$this->mapper->expects($this->once())
->method('findByGuidHash')
@@ -205,11 +223,11 @@ class ItemBusinessLayerTest extends \OCA\AppFramework\Utility\TestUtility {
$this->mapper->expects($this->once())
->method('update')
- ->with($this->equalTo($item));
+ ->with($this->equalTo($expectedItem));
- $this->itemBusinessLayer->star($feedId, $guidHash, false, $this->user);
+ $this->itemBusinessLayer->star($feedId, $guidHash, true, $this->user);
- $this->assertTrue($item->isUnstarred());
+ $this->assertTrue($item->isStarred());
}
@@ -218,6 +236,13 @@ class ItemBusinessLayerTest extends \OCA\AppFramework\Utility\TestUtility {
$item = new Item();
$item->setStatus(128);
$item->setId($itemId);
+ $item->setRead();
+
+ $expectedItem = new Item();
+ $expectedItem->setStatus(128);
+ $expectedItem->setUnread();
+ $expectedItem->setId($itemId);
+ $expectedItem->setLastModified($this->time);
$this->mapper->expects($this->once())
->method('find')
@@ -226,7 +251,7 @@ class ItemBusinessLayerTest extends \OCA\AppFramework\Utility\TestUtility {
$this->mapper->expects($this->once())
->method('update')
- ->with($this->equalTo($item));
+ ->with($this->equalTo($expectedItem));
$this->itemBusinessLayer->read($itemId, false, $this->user);