Complete BoardServiceTest
This commit is contained in:
@@ -5,20 +5,20 @@
|
|||||||
* @author Julius Härtl <jus@bitgrid.net>
|
* @author Julius Härtl <jus@bitgrid.net>
|
||||||
*
|
*
|
||||||
* @license GNU AGPL version 3 or any later version
|
* @license GNU AGPL version 3 or any later version
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU Affero General Public License as
|
* it under the terms of the GNU Affero General Public License as
|
||||||
* published by the Free Software Foundation, either version 3 of the
|
* published by the Free Software Foundation, either version 3 of the
|
||||||
* License, or (at your option) any later version.
|
* License, or (at your option) any later version.
|
||||||
*
|
*
|
||||||
* This program is distributed in the hope that it will be useful,
|
* This program is distributed in the hope that it will be useful,
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
* GNU Affero General Public License for more details.
|
* GNU Affero General Public License for more details.
|
||||||
*
|
*
|
||||||
* You should have received a copy of the GNU Affero General Public License
|
* 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/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace OCA\Deck\Service;
|
namespace OCA\Deck\Service;
|
||||||
@@ -37,96 +37,98 @@ use \OCA\Deck\Db\LabelMapper;
|
|||||||
|
|
||||||
class BoardService {
|
class BoardService {
|
||||||
|
|
||||||
private $boardMapper;
|
private $boardMapper;
|
||||||
private $aclMapper;
|
private $aclMapper;
|
||||||
private $labelMapper;
|
private $labelMapper;
|
||||||
private $logger;
|
private $logger;
|
||||||
private $l10n;
|
private $l10n;
|
||||||
|
|
||||||
public function __construct(BoardMapper $boardMapper,
|
public function __construct(
|
||||||
ILogger $logger,
|
BoardMapper $boardMapper,
|
||||||
IL10N $l10n,
|
ILogger $logger,
|
||||||
LabelMapper $labelMapper,
|
IL10N $l10n,
|
||||||
AclMapper $aclMapper,
|
LabelMapper $labelMapper,
|
||||||
IGroupManager $groupManager) {
|
AclMapper $aclMapper,
|
||||||
$this->boardMapper = $boardMapper;
|
IGroupManager $groupManager
|
||||||
$this->labelMapper = $labelMapper;
|
) {
|
||||||
$this->aclMapper = $aclMapper;
|
$this->boardMapper = $boardMapper;
|
||||||
$this->logger = $logger;
|
$this->labelMapper = $labelMapper;
|
||||||
$this->l10n = $l10n;
|
$this->aclMapper = $aclMapper;
|
||||||
|
$this->logger = $logger;
|
||||||
|
$this->l10n = $l10n;
|
||||||
$this->groupManager = $groupManager;
|
$this->groupManager = $groupManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function findAll($userInfo) {
|
public function findAll($userInfo) {
|
||||||
$userBoards = $this->boardMapper->findAllByUser($userInfo['user']);
|
$userBoards = $this->boardMapper->findAllByUser($userInfo['user']);
|
||||||
$groupBoards = $this->boardMapper->findAllByGroups($userInfo['user'], $userInfo['groups']);
|
$groupBoards = $this->boardMapper->findAllByGroups($userInfo['user'], $userInfo['groups']);
|
||||||
return array_unique(array_merge($userBoards, $groupBoards));
|
return array_unique(array_merge($userBoards, $groupBoards));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function find($boardId) {
|
public function find($boardId) {
|
||||||
return $this->boardMapper->find($boardId, true, true);
|
return $this->boardMapper->find($boardId, true, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function create($title, $userId, $color) {
|
public function create($title, $userId, $color) {
|
||||||
$board = new Board();
|
$board = new Board();
|
||||||
$board->setTitle($title);
|
$board->setTitle($title);
|
||||||
$board->setOwner($userId);
|
$board->setOwner($userId);
|
||||||
$board->setColor($color);
|
$board->setColor($color);
|
||||||
$new_board = $this->boardMapper->insert($board);
|
$new_board = $this->boardMapper->insert($board);
|
||||||
|
|
||||||
// create new labels
|
// create new labels
|
||||||
$default_labels = [
|
$default_labels = [
|
||||||
'31CC7C' => $this->l10n->t('Finished'),
|
'31CC7C' => $this->l10n->t('Finished'),
|
||||||
'317CCC' => $this->l10n->t('To review'),
|
'317CCC' => $this->l10n->t('To review'),
|
||||||
'FF7A66' => $this->l10n->t('Action needed'),
|
'FF7A66' => $this->l10n->t('Action needed'),
|
||||||
'F1DB50' => $this->l10n->t('Later')];
|
'F1DB50' => $this->l10n->t('Later')];
|
||||||
$labels = [];
|
$labels = [];
|
||||||
foreach ($default_labels as $color=>$title) {
|
foreach ($default_labels as $color => $title) {
|
||||||
$label = new Label();
|
$label = new Label();
|
||||||
$label->setColor($color);
|
$label->setColor($color);
|
||||||
$label->setTitle($title);
|
$label->setTitle($title);
|
||||||
$label->setBoardId($new_board->getId());
|
$label->setBoardId($new_board->getId());
|
||||||
$labels[] = $this->labelMapper->insert($label);
|
$labels[] = $this->labelMapper->insert($label);
|
||||||
}
|
}
|
||||||
$new_board->setLabels($labels);
|
$new_board->setLabels($labels);
|
||||||
return $new_board;
|
return $new_board;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function delete($id) {
|
public function delete($id) {
|
||||||
return $this->boardMapper->delete($this->find($id));
|
return $this->boardMapper->delete($this->find($id));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function update($id, $title, $color) {
|
public function update($id, $title, $color) {
|
||||||
$board = $this->find($id);
|
$board = $this->find($id);
|
||||||
$board->setTitle($title);
|
$board->setTitle($title);
|
||||||
$board->setColor($color);
|
$board->setColor($color);
|
||||||
return $this->boardMapper->update($board);
|
return $this->boardMapper->update($board);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function addAcl($boardId, $type, $participant, $write, $invite, $manage) {
|
|
||||||
$acl = new Acl();
|
|
||||||
$acl->setBoardId($boardId);
|
|
||||||
$acl->setType($type);
|
|
||||||
$acl->setParticipant($participant);
|
|
||||||
$acl->setPermissionWrite($write);
|
|
||||||
$acl->setPermissionInvite($invite);
|
|
||||||
$acl->setPermissionManage($manage);
|
|
||||||
return $this->aclMapper->insert($acl);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function updateAcl($id, $write, $invite, $manage) {
|
public function addAcl($boardId, $type, $participant, $write, $invite, $manage) {
|
||||||
$acl = $this->aclMapper->find($id);
|
$acl = new Acl();
|
||||||
$acl->setPermissionWrite($write);
|
$acl->setBoardId($boardId);
|
||||||
$acl->setPermissionInvite($invite);
|
$acl->setType($type);
|
||||||
$acl->setPermissionManage($manage);
|
$acl->setParticipant($participant);
|
||||||
return $this->aclMapper->update($acl);
|
$acl->setPermissionWrite($write);
|
||||||
}
|
$acl->setPermissionInvite($invite);
|
||||||
|
$acl->setPermissionManage($manage);
|
||||||
|
return $this->aclMapper->insert($acl);
|
||||||
|
}
|
||||||
|
|
||||||
public function deleteAcl($id) {
|
public function updateAcl($id, $write, $invite, $manage) {
|
||||||
$acl = $this->aclMapper->find($id);
|
$acl = $this->aclMapper->find($id);
|
||||||
return $this->aclMapper->delete($acl);
|
$acl->setPermissionWrite($write);
|
||||||
}
|
$acl->setPermissionInvite($invite);
|
||||||
|
$acl->setPermissionManage($manage);
|
||||||
|
return $this->aclMapper->update($acl);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function deleteAcl($id) {
|
||||||
|
$acl = $this->aclMapper->find($id);
|
||||||
|
return $this->aclMapper->delete($acl);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -112,6 +112,26 @@ class BoardServiceTest extends \PHPUnit_Framework_TestCase {
|
|||||||
$this->assertCount(4, $b->getLabels());
|
$this->assertCount(4, $b->getLabels());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testUpdate() {
|
||||||
|
$board = new Board();
|
||||||
|
$board->setTitle('MyBoard');
|
||||||
|
$board->setOwner('admin');
|
||||||
|
$board->setColor('00ff00');
|
||||||
|
$this->boardMapper->expects($this->once())
|
||||||
|
->method('find')
|
||||||
|
->with(123)
|
||||||
|
->willReturn($board);
|
||||||
|
$this->boardMapper->expects($this->once())
|
||||||
|
->method('update')
|
||||||
|
->with($board)
|
||||||
|
->willReturn($board);
|
||||||
|
$b = $this->service->update(123, 'MyNewNameBoard', 'ffffff');
|
||||||
|
|
||||||
|
$this->assertEquals($b->getTitle(), 'MyNewNameBoard');
|
||||||
|
$this->assertEquals($b->getOwner(), 'admin');
|
||||||
|
$this->assertEquals($b->getColor(), 'ffffff');
|
||||||
|
}
|
||||||
|
|
||||||
public function testDelete() {
|
public function testDelete() {
|
||||||
$this->boardMapper->expects($this->once())
|
$this->boardMapper->expects($this->once())
|
||||||
->method('find')
|
->method('find')
|
||||||
|
|||||||
Reference in New Issue
Block a user