Add change database helper

Signed-off-by: Julius Härtl <jus@bitgrid.net>
This commit is contained in:
Julius Härtl
2018-10-27 16:04:43 +02:00
parent a068d6e1c6
commit a026ebf094
16 changed files with 192 additions and 42 deletions

View File

@@ -24,7 +24,6 @@
namespace OCA\Deck\Controller;
use OCA\Deck\Db\ChangeHelper;
use OCP\AppFramework\ApiController;
use OCP\AppFramework\Http;
use OCP\AppFramework\Http\DataResponse;
@@ -78,7 +77,7 @@ class BoardApiController extends ApiController {
*
* Return the board specified by $this->request->getParam('boardId').
*/
public function get() {
public function get() {
$board = $this->service->find($this->request->getParam('boardId'));
return new DataResponse($board, HTTP::STATUS_OK);
}

View File

@@ -23,7 +23,6 @@
namespace OCA\Deck\Controller;
use OCA\Deck\Db\ChangeHelper;
use OCP\AppFramework\ApiController;
use OCP\AppFramework\Http;
use OCP\AppFramework\Http\DataResponse;
@@ -71,7 +70,7 @@ class CardApiController extends ApiController {
* @params $title
* @params $type
* @params $order
*
*
* Get a specific card.
*/
public function create($title, $type = 'plain', $order = 999) {
@@ -83,20 +82,20 @@ class CardApiController extends ApiController {
* @NoAdminRequired
* @CORS
* @NoCSRFRequired
*
*
*
*
* Update a card
*/
public function update($title, $type, $order = 0, $description = '', $owner, $duedate = null) {
$card = $this->cardService->update($this->request->getParam('cardId'), $title, $this->request->getParam('stackId'), $type, $order, $description, $owner, $duedate, 0);
return new DataResponse($card, HTTP::STATUS_OK);
}
}
/**
* @NoAdminRequired
* @CORS
* @NoCSRFRequired
*
* @NoCSRFRequired
*
* Delete a specific card.
*/
public function delete() {
@@ -107,8 +106,8 @@ class CardApiController extends ApiController {
/**
* @NoAdminRequired
* @CORS
* @NoCSRFRequired
*
* @NoCSRFRequired
*
* Assign a label to a card.
*/
public function assignLabel($labelId) {

91
lib/Db/ChangeHelper.php Normal file
View File

@@ -0,0 +1,91 @@
<?php
/**
* @copyright Copyright (c) 2018 Julius Härtl <jus@bitgrid.net>
*
* @author Julius Härtl <jus@bitgrid.net>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program 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 program. If not, see <http://www.gnu.org/licenses/>.
*
*/
namespace OCA\Deck\Db;
use OCP\AppFramework\Db\DoesNotExistException;
use OCP\ICache;
use OCP\ICacheFactory;
use OCP\IDBConnection;
use OCP\IRequest;
use OCP\IUserManager;
use OCP\IGroupManager;
class ChangeHelper {
const TYPE_BOARD = 'boardChanged';
const TYPE_CARD = 'cardChanged';
private $db;
public function __construct(
IDBConnection $db,
ICacheFactory $cacheFactory,
IRequest $request
) {
$this->db = $db;
$this->cache = $cacheFactory->createDistributed('deck_changes');
$this->request = $request;
}
public function boardChanged($boardId) {
$time = time();
$etag = md5($time . microtime());
$this->cache->set(self::TYPE_BOARD . '-' . $boardId, $etag);
$sql = 'UPDATE `*PREFIX*deck_boards` SET `last_modified` = ? WHERE `id` = ?';
$this->db->executeUpdate($sql, [$time, $boardId]);
}
public function cardChanged($cardId, $updateCard = true) {
$time = time();
$etag = md5($time . microtime());
$this->cache->set(self::TYPE_CARD . '-' .$cardId, $etag);
if ($updateCard) {
$sql = 'UPDATE `*PREFIX*deck_cards` SET `last_modified` = ? WHERE `id` = ?';
$this->db->executeUpdate($sql, [time(), $cardId]);
}
$sql = 'SELECT s.board_id as id FROM oc_deck_stacks as s inner join oc_deck_cards as c ON c.stack_id = s.id WHERE c.id = ?';
$result = $this->db->executeQuery($sql, [$cardId]);
if ($row = $result->fetch()) {
$this->boardChanged($row['id']);
}
}
public function checkEtag($type, $id) {
$etag = $this->getEtag($type, $id);
if ($this->request->getHeader('If-None-Match') === $etag) {
return true;
}
return false;
}
public function getEtag($type, $id) {
$entry = $this->cache->get($type . '-' .$id);
if ($entry === 'null') {
return '';
}
return $entry;
}
}

View File

@@ -28,9 +28,9 @@ class Stack extends RelationalEntity {
protected $title;
protected $boardId;
protected $deletedAt = 0;
protected $lastModified = 0;
protected $cards = array();
protected $order;
protected $lastModified = 0;
public function __construct() {
$this->addType('id', 'integer');

View File

@@ -57,6 +57,8 @@ class AttachmentService {
private $l10n;
/** @var ActivityManager */
private $activityManager;
/** @var ChangeHelper */
private $changeHelper;
/**
* AttachmentService constructor.
@@ -219,12 +221,11 @@ class AttachmentService {
* @param $cardId
* @param $attachmentId
* @return Response
* @throws \OCA\Deck\NotFoundException
* @throws BadRequestException
* @throws NoPermissionException
* @throws NotFoundException
* @throws \OCP\AppFramework\Db\DoesNotExistException
* @throws \OCP\AppFramework\Db\
* @throws BadRequestException
* @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException
*/
public function display($cardId, $attachmentId) {

View File

@@ -28,6 +28,7 @@ use OCA\Deck\Activity\ChangeSet;
use OCA\Deck\Db\Acl;
use OCA\Deck\Db\AclMapper;
use OCA\Deck\Db\AssignedUsersMapper;
use OCA\Deck\Db\ChangeHelper;
use OCA\Deck\Db\IPermissionMapper;
use OCA\Deck\Db\Label;
use OCA\Deck\Notification\NotificationHelper;
@@ -54,6 +55,7 @@ class BoardService {
private $groupManager;
private $userId;
private $activityManager;
private $changeHelper;
public function __construct(
BoardMapper $boardMapper,
@@ -66,6 +68,7 @@ class BoardService {
IUserManager $userManager,
IGroupManager $groupManager,
ActivityManager $activityManager,
ChangeHelper $changeHelper,
$userId
) {
$this->boardMapper = $boardMapper;
@@ -78,6 +81,7 @@ class BoardService {
$this->userManager = $userManager;
$this->groupManager = $groupManager;
$this->activityManager = $activityManager;
$this->changeHelper = $changeHelper;
$this->userId = $userId;
}
@@ -276,6 +280,7 @@ class BoardService {
'PERMISSION_SHARE' => $permissions[Acl::PERMISSION_SHARE]
]);
$this->activityManager->triggerEvent(ActivityManager::DECK_OBJECT_BOARD, $new_board, ActivityManager::SUBJECT_BOARD_CREATE);
$this->changeHelper->boardChanged($new_board->getId());
return $new_board;
}
@@ -299,6 +304,7 @@ class BoardService {
$board->setDeletedAt(time());
$board = $this->boardMapper->update($board);
$this->activityManager->triggerEvent(ActivityManager::DECK_OBJECT_BOARD, $board, ActivityManager::SUBJECT_BOARD_DELETE);
$this->changeHelper->boardChanged($board->getId());
return $board;
}
@@ -320,6 +326,7 @@ class BoardService {
$board->setDeletedAt(0);
$board = $this->boardMapper->update($board);
$this->activityManager->triggerEvent(ActivityManager::DECK_OBJECT_BOARD, $board, ActivityManager::SUBJECT_BOARD_RESTORE);
$this->changeHelper->boardChanged($board->getId());
return $board;
}
@@ -380,6 +387,7 @@ class BoardService {
$this->boardMapper->update($board); // operate on clone so we can check for updated fields
$this->boardMapper->mapOwner($board);
$this->activityManager->triggerUpdateEvents(ActivityManager::DECK_OBJECT_BOARD, $changes, ActivityManager::SUBJECT_BOARD_UPDATE);
$this->changeHelper->boardChanged($board->getId());
return $board;
}
@@ -392,8 +400,8 @@ class BoardService {
* @param $share
* @param $manage
* @return \OCP\AppFramework\Db\Entity
* @throws \OCA\Deck\
* @throws BadRequestException
* @throws \OCA\Deck\NoPermissionException
*/
public function addAcl($boardId, $type, $participant, $edit, $share, $manage) {
@@ -436,6 +444,7 @@ class BoardService {
$newAcl = $this->aclMapper->insert($acl);
$this->activityManager->triggerEvent(ActivityManager::DECK_OBJECT_BOARD, $newAcl, ActivityManager::SUBJECT_BOARD_SHARE);
$this->boardMapper->mapAcl($newAcl);
$this->changeHelper->boardChanged($boardId);
return $newAcl;
}
@@ -475,7 +484,9 @@ class BoardService {
$acl->setPermissionShare($share);
$acl->setPermissionManage($manage);
$this->boardMapper->mapAcl($acl);
return $this->aclMapper->update($acl);
$board = $this->aclMapper->update($acl);
$this->changeHelper->boardChanged($acl->getBoardId());
return $board;
}
/**
@@ -503,6 +514,7 @@ class BoardService {
}
}
$this->activityManager->triggerEvent(ActivityManager::DECK_OBJECT_BOARD, $acl, ActivityManager::SUBJECT_BOARD_UNSHARE);
$this->changeHelper->boardChanged($acl->getBoardId());
return $this->aclMapper->delete($acl);
}

View File

@@ -56,6 +56,7 @@ class CardService {
private $activityManager;
private $commentsManager;
private $changeHelper;
private $userManager;
public function __construct(
CardMapper $cardMapper,
@@ -485,9 +486,10 @@ class CardService {
* @param $cardId
* @param $userId
* @return bool|null|\OCP\AppFramework\Db\Entity
* @throws BadRequestException
* @throws \OCA\Deck\NoPermissionException
* @throws \OCP\AppFramework\Db\DoesNotExistException
* @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException
* @throws BadRequestException
*/
public function assignUser($cardId, $userId) {
@@ -526,10 +528,11 @@ class CardService {
* @param $cardId
* @param $userId
* @return \OCP\AppFramework\Db\Entity
* @throws BadRequestException
* @throws NotFoundException
* @throws \OCA\Deck\NoPermissionException
* @throws \OCP\AppFramework\Db\DoesNotExistException
* @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException
* @throws BadRequestException
*/
public function unassignUser($cardId, $userId) {
$this->permissionService->checkPermission($this->cardMapper, $cardId, Acl::PERMISSION_EDIT);

View File

@@ -5,24 +5,25 @@
* @author Julius Härtl <jus@bitgrid.net>
*
* @license GNU AGPL version 3 or any later version
*
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
*
* This program 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 program. If not, see <http://www.gnu.org/licenses/>.
*
*
*/
namespace OCA\Deck\Service;
use OCA\Deck\Db\ChangeHelper;
use OCA\Deck\Db\Label;
use OCA\Deck\Db\Acl;
use OCA\Deck\Db\LabelMapper;
@@ -38,11 +39,14 @@ class LabelService {
private $permissionService;
/** @var BoardService */
private $boardService;
/** @var ChangeHelper */
private $changeHelper;
public function __construct(LabelMapper $labelMapper, PermissionService $permissionService, BoardService $boardService) {
public function __construct(LabelMapper $labelMapper, PermissionService $permissionService, BoardService $boardService, ChangeHelper $changeHelper) {
$this->labelMapper = $labelMapper;
$this->permissionService = $permissionService;
$this->boardService = $boardService;
$this->changeHelper = $changeHelper;
}
/**
@@ -94,6 +98,7 @@ class LabelService {
$label->setTitle($title);
$label->setColor($color);
$label->setBoardId($boardId);
$this->changeHelper->boardChanged($boardId);
return $this->labelMapper->insert($label);
}
@@ -116,7 +121,9 @@ class LabelService {
if ($this->boardService->isArchived($this->labelMapper, $id)) {
throw new StatusException('Operation not allowed. This board is archived.');
}
return $this->labelMapper->delete($this->find($id));
$label = $this->labelMapper->delete($this->find($id));
$this->changeHelper->boardChanged($label->getBoardId());
return $label;
}
/**
@@ -151,7 +158,8 @@ class LabelService {
$label = $this->find($id);
$label->setTitle($title);
$label->setColor($color);
$this->changeHelper->boardChanged($label->getBoardId());
return $this->labelMapper->update($label);
}
}
}

View File

@@ -28,6 +28,7 @@ use OCA\Deck\Activity\ChangeSet;
use OCA\Deck\Db\Acl;
use OCA\Deck\Db\CardMapper;
use OCA\Deck\Db\BoardMapper;
use OCA\Deck\Db\ChangeHelper;
use OCA\Deck\Db\LabelMapper;
use OCA\Deck\Db\AssignedUsersMapper;
use OCA\Deck\Db\Stack;
@@ -49,6 +50,7 @@ class StackService {
private $assignedUsersMapper;
private $attachmentService;
private $activityManager;
private $changeHelper;
public function __construct(
StackMapper $stackMapper,
@@ -60,7 +62,8 @@ class StackService {
CardService $cardService,
AssignedUsersMapper $assignedUsersMapper,
AttachmentService $attachmentService,
ActivityManager $activityManager
ActivityManager $activityManager,
ChangeHelper $changeHelper
) {
$this->stackMapper = $stackMapper;
$this->boardMapper = $boardMapper;
@@ -72,6 +75,7 @@ class StackService {
$this->assignedUsersMapper = $assignedUsersMapper;
$this->attachmentService = $attachmentService;
$this->activityManager = $activityManager;
$this->changeHelper = $changeHelper;
}
private function enrichStackWithCards($stack, $since = -1) {
@@ -203,6 +207,7 @@ class StackService {
$stack->setOrder($order);
$stack = $this->stackMapper->insert($stack);
$this->activityManager->triggerEvent(ActivityManager::DECK_OBJECT_BOARD, $stack, ActivityManager::SUBJECT_STACK_CREATE);
$this->changeHelper->boardChanged($boardId);
return $stack;
}
@@ -227,7 +232,7 @@ class StackService {
$stack = $this->stackMapper->update($stack);
$this->activityManager->triggerEvent(ActivityManager::DECK_OBJECT_BOARD, $stack, ActivityManager::SUBJECT_STACK_DELETE);
$this->changeHelper->boardChanged($stack->getBoardId());
$this->enrichStackWithCards($stack);
return $stack;
}
@@ -276,6 +281,7 @@ class StackService {
$changes->setAfter($stack);
$stack = $this->stackMapper->update($stack);
$this->activityManager->triggerUpdateEvents(ActivityManager::DECK_OBJECT_BOARD, $changes, ActivityManager::SUBJECT_STACK_UPDATE);
$this->changeHelper->boardChanged($stack->getBoardId());
return $stack;
}
@@ -318,7 +324,7 @@ class StackService {
$this->stackMapper->update($stack);
$result[$stack->getOrder()] = $stack;
}
$this->changeHelper->boardChanged($stackToSort->getBoardId());
return $result;
}
}

View File

@@ -26,6 +26,7 @@ class BoardTest extends TestCase {
'labels' => array(),
'permissions' => [],
'deletedAt' => 0,
'lastModified' => 0,
'acl' => array(),
'archived' => false,
'users' => ['user1', 'user2'],
@@ -43,6 +44,7 @@ class BoardTest extends TestCase {
'labels' => array("foo", "bar"),
'permissions' => [],
'deletedAt' => 0,
'lastModified' => 0,
'acl' => array(),
'archived' => false,
'users' => [],
@@ -67,10 +69,11 @@ class BoardTest extends TestCase {
'labels' => array(),
'permissions' => [],
'deletedAt' => 0,
'lastModified' => 0,
'acl' => array(),
'archived' => false,
'shared' => 1,
'users' => [],
], $board->jsonSerialize());
}
}
}

View File

@@ -39,7 +39,8 @@ class StackTest extends \Test\TestCase {
'title' => "My Stack",
'order' => 1,
'boardId' => 1,
'deletedAt' => 0
'deletedAt' => 0,
'lastModified' => 0,
], $board->jsonSerialize());
}
public function testJsonSerializeWithCards() {
@@ -52,7 +53,8 @@ class StackTest extends \Test\TestCase {
'order' => 1,
'boardId' => 1,
'cards' => array("foo", "bar"),
'deletedAt' => 0
'deletedAt' => 0,
'lastModified' => 0,
], $board->jsonSerialize());
}
}

View File

@@ -30,6 +30,7 @@ use OCA\Deck\Db\Acl;
use OCA\Deck\Db\Attachment;
use OCA\Deck\Db\AttachmentMapper;
use OCA\Deck\Db\CardMapper;
use OCA\Deck\Db\ChangeHelper;
use OCA\Deck\InvalidAttachmentType;
use OCP\AppFramework\Http\Response;
use OCP\AppFramework\IAppContainer;
@@ -73,6 +74,8 @@ class AttachmentServiceTest extends TestCase {
private $cache;
/** @var IL10N */
private $l10n;
/** @var ChangeHelper */
private $changeHelper;
/**
* @throws \OCP\AppFramework\QueryException
@@ -99,8 +102,9 @@ class AttachmentServiceTest extends TestCase {
->willReturn($this->appContainer);
$this->l10n = $this->createMock(IL10N::class);
$this->changeHelper = $this->createMock(ChangeHelper::class);
$this->attachmentService = new AttachmentService($this->attachmentMapper, $this->cardMapper, $this->permissionService, $this->application, $this->cacheFactory, $this->userId, $this->l10n, $this->activityManager);
$this->attachmentService = new AttachmentService($this->attachmentMapper, $this->cardMapper, $this->changeHelper, $this->permissionService, $this->application, $this->cacheFactory, $this->userId, $this->l10n, $this->activityManager);
}
public function testRegisterAttachmentService() {
@@ -112,7 +116,7 @@ class AttachmentServiceTest extends TestCase {
$application->expects($this->any())
->method('getContainer')
->willReturn($appContainer);
$attachmentService = new AttachmentService($this->attachmentMapper, $this->cardMapper, $this->permissionService, $application, $this->cacheFactory, $this->userId, $this->l10n, $this->activityManager);
$attachmentService = new AttachmentService($this->attachmentMapper, $this->cardMapper, $this->changeHelper, $this->permissionService, $application, $this->cacheFactory, $this->userId, $this->l10n, $this->activityManager);
$attachmentService->registerAttachmentService('custom', MyAttachmentService::class);
$this->assertEquals($fileServiceMock, $attachmentService->getService('deck_file'));
$this->assertEquals(MyAttachmentService::class, get_class($attachmentService->getService('custom')));
@@ -130,7 +134,7 @@ class AttachmentServiceTest extends TestCase {
$application->expects($this->any())
->method('getContainer')
->willReturn($appContainer);
$attachmentService = new AttachmentService($this->attachmentMapper, $this->cardMapper, $this->permissionService, $application, $this->cacheFactory, $this->userId, $this->l10n, $this->activityManager);
$attachmentService = new AttachmentService($this->attachmentMapper, $this->cardMapper, $this->changeHelper, $this->permissionService, $application, $this->cacheFactory, $this->userId, $this->l10n, $this->activityManager);
$attachmentService->registerAttachmentService('custom', MyAttachmentService::class);
$attachmentService->getService('deck_file_invalid');
}

View File

@@ -31,6 +31,7 @@ use OCA\Deck\Db\AssignedUsers;
use OCA\Deck\Db\AssignedUsersMapper;
use OCA\Deck\Db\Board;
use OCA\Deck\Db\BoardMapper;
use OCA\Deck\Db\ChangeHelper;
use OCA\Deck\Db\LabelMapper;
use OCA\Deck\Notification\NotificationHelper;
use OCP\IUser;
@@ -62,7 +63,8 @@ class BoardServiceTest extends TestCase {
private $groupManager;
/** @var ActivityManager */
private $activityManager;
/** @var ChangeHelper */
private $changeHelper;
private $userId = 'admin';
public function setUp() {
@@ -77,6 +79,7 @@ class BoardServiceTest extends TestCase {
$this->userManager = $this->createMock(IUserManager::class);
$this->groupManager = $this->createMock(IGroupManager::class);
$this->activityManager = $this->createMock(ActivityManager::class);
$this->changeHelper = $this->createMock(ChangeHelper::class);
$this->service = new BoardService(
$this->boardMapper,
@@ -89,6 +92,7 @@ class BoardServiceTest extends TestCase {
$this->userManager,
$this->groupManager,
$this->activityManager,
$this->changeHelper,
$this->userId
);

View File

@@ -29,6 +29,7 @@ use OCA\Deck\Db\AssignedUsers;
use OCA\Deck\Db\AssignedUsersMapper;
use OCA\Deck\Db\Card;
use OCA\Deck\Db\CardMapper;
use OCA\Deck\Db\ChangeHelper;
use OCA\Deck\Db\StackMapper;
use OCA\Deck\Db\BoardMapper;
use OCA\Deck\Db\LabelMapper;
@@ -69,6 +70,8 @@ class CardServiceTest extends TestCase {
private $commentsManager;
/** @var ICommentsManager|MockObject */
private $userManager;
/** @var ChangeHelper|MockObject */
private $changeHelper;
public function setUp() {
parent::setUp();
@@ -84,6 +87,7 @@ class CardServiceTest extends TestCase {
$this->activityManager = $this->createMock(ActivityManager::class);
$this->commentsManager = $this->createMock(ICommentsManager::class);
$this->userManager = $this->createMock(IUserManager::class);
$this->changeHelper = $this->createMock(ChangeHelper::class);
$this->cardService = new CardService(
$this->cardMapper,
$this->stackMapper,
@@ -97,6 +101,7 @@ class CardServiceTest extends TestCase {
$this->activityManager,
$this->commentsManager,
$this->userManager,
$this->changeHelper,
'user1'
);
}

View File

@@ -24,6 +24,7 @@
namespace OCA\Deck\Service;
use OCA\Deck\Db\ChangeHelper;
use OCA\Deck\Db\Label;
use OCA\Deck\Db\LabelMapper;
use Test\TestCase;
@@ -38,6 +39,8 @@ class LabelServiceTest extends TestCase {
private $labelService;
/** @var BoardService|\PHPUnit\Framework\MockObject\MockObject */
private $boardService;
/** @var ChangeHelper|\PHPUnit\Framework\MockObject\MockObject */
private $changeHelper;
public function setUp() {
parent::setUp();
@@ -46,10 +49,12 @@ class LabelServiceTest extends TestCase {
$this->permissionService = $this->getMockBuilder(PermissionService::class)
->disableOriginalConstructor()->getMock();
$this->boardService = $this->createMock(BoardService::class);
$this->changeHelper = $this->createMock(ChangeHelper::class);
$this->labelService = new LabelService(
$this->labelMapper,
$this->permissionService,
$this->boardService
$this->boardService,
$this->changeHelper
);
}
@@ -95,13 +100,15 @@ class LabelServiceTest extends TestCase {
}
public function testDelete() {
$label = new Label();
$label->setId(1);
$this->labelMapper->expects($this->once())
->method('find')
->willReturn(new Label());
->willReturn($label);
$this->labelMapper->expects($this->once())
->method('delete')
->willReturn(1);
$this->assertEquals(1, $this->labelService->delete(123));
->willReturn($label);
$this->assertEquals($label, $this->labelService->delete(1));
}
}
}

View File

@@ -30,6 +30,7 @@ use OCA\Deck\Db\AssignedUsersMapper;
use OCA\Deck\Db\Card;
use OCA\Deck\Db\CardMapper;
use OCA\Deck\Db\BoardMapper;
use OCA\Deck\Db\ChangeHelper;
use OCA\Deck\Db\Label;
use OCA\Deck\Db\LabelMapper;
use OCA\Deck\Db\Stack;
@@ -66,6 +67,8 @@ class StackServiceTest extends TestCase {
private $cardService;
/** @var ActivityManager|\PHPUnit\Framework\MockObject\MockObject */
private $activityManager;
/** @var ChangeHelper|\PHPUnit\Framework\MockObject\MockObject */
private $changeHelper;
public function setUp() {
parent::setUp();
@@ -79,6 +82,7 @@ class StackServiceTest extends TestCase {
$this->attachmentService = $this->createMock(AttachmentService::class);
$this->labelMapper = $this->createMock(LabelMapper::class);
$this->activityManager = $this->createMock(ActivityManager::class);
$this->changeHelper = $this->createMock(ChangeHelper::class);
$this->stackService = new StackService(
$this->stackMapper,
@@ -90,7 +94,8 @@ class StackServiceTest extends TestCase {
$this->cardService,
$this->assignedUsersMapper,
$this->attachmentService,
$this->activityManager
$this->activityManager,
$this->changeHelper
);
}
@@ -185,6 +190,7 @@ class StackServiceTest extends TestCase {
$stackToBeDeleted->setId(1);
$this->stackMapper->expects($this->once())->method('find')->willReturn($stackToBeDeleted);
$this->stackMapper->expects($this->once())->method('update')->willReturn($stackToBeDeleted);
$this->cardMapper->expects($this->once())->method('findAll')->willReturn([]);
$this->stackService->delete(123);
$this->assertTrue($stackToBeDeleted->getDeletedAt() <= time(), "deletedAt is in the past");
$this->assertTrue($stackToBeDeleted->getDeletedAt() > 0, "deletedAt is set");