From 140c860944b0ee459b8dd1f0b4e00baaa9032ae3 Mon Sep 17 00:00:00 2001 From: Julius Haertl Date: Wed, 18 Jan 2017 14:43:00 +0100 Subject: [PATCH] Testing BoardMapper --- lib/Controller/StackController.php | 9 -- lib/Db/Board.php | 3 +- tests/unit/Db/BoardMapperTest.php | 122 ++++++++++++++++++ tests/unit/controller/StackControllerTest.php | 4 - 4 files changed, 124 insertions(+), 14 deletions(-) create mode 100644 tests/unit/Db/BoardMapperTest.php diff --git a/lib/Controller/StackController.php b/lib/Controller/StackController.php index 2cb84c1dd..a2fbbe56e 100644 --- a/lib/Controller/StackController.php +++ b/lib/Controller/StackController.php @@ -57,15 +57,6 @@ class StackController extends Controller { return $this->stackService->findAllArchived($boardId); } - /** - * @NoAdminRequired - * @param $boardId - * @return - */ - public function read($boardId) { - return $this->stackService->find($this->userId, $boardId); - } - /** * @NoAdminRequired * @param $title diff --git a/lib/Db/Board.php b/lib/Db/Board.php index 29ac40312..cac026e30 100644 --- a/lib/Db/Board.php +++ b/lib/Db/Board.php @@ -31,7 +31,7 @@ class Board extends Entity implements JsonSerializable { protected $title; protected $owner; protected $color; - protected $archived; + protected $archived = false; protected $labels; protected $acl; protected $shared; @@ -39,6 +39,7 @@ class Board extends Entity implements JsonSerializable { public function __construct() { $this->addType('id','integer'); $this->addType('shared','integer'); + $this->addType('archived','boolean'); $this->addRelation('labels'); $this->addRelation('acl'); $this->addRelation('shared'); diff --git a/tests/unit/Db/BoardMapperTest.php b/tests/unit/Db/BoardMapperTest.php new file mode 100644 index 000000000..29aa7fa8f --- /dev/null +++ b/tests/unit/Db/BoardMapperTest.php @@ -0,0 +1,122 @@ + + * + * @author Julius Härtl + * + * @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 . + * + */ + +namespace OCA\Deck\Db; + +use Test\AppFramework\Db\MapperTestUtility; + +/** + * @group DB + */ +class BoardMapperTest extends MapperTestUtility { + + private $dbConnection; + private $aclMapper; + private $boardMapper; + + // Data + private $acls; + private $boards; + + public function setup(){ + parent::setUp(); + + $this->dbConnection = \OC::$server->getDatabaseConnection(); + $this->boardMapper = new BoardMapper( + $this->dbConnection, + \OC::$server->query(LabelMapper::class), + \OC::$server->query(AclMapper::class), + \OC::$server->query(StackMapper::class) + ); + $this->aclMapper = \OC::$server->query(AclMapper::class); + $this->labelMapper = \OC::$server->query(LabelMapper::class); + + $this->boards = [ + $this->boardMapper->insert($this->getBoard('MyBoard 1', 'user1')), + $this->boardMapper->insert($this->getBoard('MyBoard 2', 'user2')), + $this->boardMapper->insert($this->getBoard('MyBoard 3', 'user3')) + ]; + $this->acls = [ + $this->aclMapper->insert($this->getAcl('user','user1', false, false, false, $this->boards[1]->getId())), + $this->aclMapper->insert($this->getAcl('user','user2', true, false, false, $this->boards[0]->getId())), + $this->aclMapper->insert($this->getAcl('user','user3', true, true, false, $this->boards[0]->getId())), + $this->aclMapper->insert($this->getAcl('user','user1', false, false, false, $this->boards[2]->getId())) + ]; + + foreach ($this->acls as $acl) { + $acl->resetUpdatedFields(); + } + foreach ($this->boards as $board) { + $board->resetUpdatedFields(); + } + } + /** @return Acl */ + public function getAcl($type='user', $participant='admin', $write=false, $invite=false, $manage=false, $boardId=123) { + $acl = new Acl(); + $acl->setParticipant($participant); + $acl->setType('user'); + $acl->setPermissionWrite($write); + $acl->setPermissionInvite($invite); + $acl->setPermissionManage($manage); + $acl->setBoardId($boardId); + return $acl; + } + + /** @return Board */ + public function getBoard($title, $owner) { + $board = new Board(); + $board->setTitle($title); + $board->setOwner($owner); + return $board; + } + + public function testFind() { + $actual = $this->boardMapper->find($this->boards[0]->getId()); + $expected = $this->boards[0]; + $this->assertEquals($expected, $actual); + } + public function testFindWithLabels() { + $actual = $this->boardMapper->find($this->boards[0]->getId(), true, false); + $expected = $this->boards[0]; + $this->assertEquals($expected, $actual); + } + public function testFindWithAcl() { + $actual = $this->boardMapper->find($this->boards[0]->getId(), false, true); + $expected = [ + $this->acls[1]->getId() => $this->acls[1], + $this->acls[2]->getId() => $this->acls[2] + ]; + $this->assertEquals($expected, $actual->getAcl()); + } + + public function tearDown() { + parent::tearDown(); + foreach ($this->acls as $acl) { + $this->aclMapper->delete($acl); + } + foreach ($this->boards as $board) { + $this->boardMapper->delete($board); + } + } + +} \ No newline at end of file diff --git a/tests/unit/controller/StackControllerTest.php b/tests/unit/controller/StackControllerTest.php index b10e7f02b..6b287df33 100644 --- a/tests/unit/controller/StackControllerTest.php +++ b/tests/unit/controller/StackControllerTest.php @@ -68,10 +68,6 @@ class StackControllerTest extends \PHPUnit_Framework_TestCase { $this->controller->archived(1); } - public function testRead() { - $this->stackService->expects($this->once())->method('find'); - $this->controller->read(1); - } public function testCreate() { $this->stackService->expects($this->once()) ->method('create')