Testing mapper on database
This commit is contained in:
@@ -21,7 +21,6 @@
|
||||
*
|
||||
*/
|
||||
|
||||
// db/author.php
|
||||
namespace OCA\Deck\Db;
|
||||
|
||||
use JsonSerializable;
|
||||
|
||||
@@ -115,9 +115,8 @@ class PermissionService {
|
||||
$board = $this->boardMapper->find($boardId);
|
||||
if ($board && $this->userId === $board->getOwner()) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
84
tests/integration/database/BoardDatabaseTest.php
Normal file
84
tests/integration/database/BoardDatabaseTest.php
Normal file
@@ -0,0 +1,84 @@
|
||||
<?php
|
||||
/**
|
||||
* @copyright Copyright (c) 2016 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/>.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* @group DB
|
||||
*/
|
||||
class BoardDatabaseTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
const TEST_USER1 = "test-share-user1";
|
||||
const TEST_USER2 = "test-share-user2";
|
||||
const TEST_USER3 = "test-share-user3";
|
||||
const TEST_USER4 = "test-share-user4";
|
||||
const TEST_GROUP1 = "test-share-group1";
|
||||
|
||||
/** @var \OCA\Deck\Service\BoardService */
|
||||
private $boardService;
|
||||
public static function setUpBeforeClass()
|
||||
{
|
||||
parent::setUpBeforeClass();
|
||||
|
||||
$backend = new \Test\Util\User\Dummy();
|
||||
\OC_User::useBackend($backend);
|
||||
$backend->createUser(self::TEST_USER1, self::TEST_USER1);
|
||||
$backend->createUser(self::TEST_USER2, self::TEST_USER2);
|
||||
$backend->createUser(self::TEST_USER3, self::TEST_USER3);
|
||||
$backend->createUser(self::TEST_USER4, self::TEST_USER4);
|
||||
// create group
|
||||
$groupBackend = new \Test\Util\Group\Dummy();
|
||||
$groupBackend->createGroup(self::TEST_GROUP1);
|
||||
$groupBackend->createGroup('group');
|
||||
$groupBackend->createGroup('group1');
|
||||
$groupBackend->createGroup('group2');
|
||||
$groupBackend->createGroup('group3');
|
||||
$groupBackend->addToGroup(self::TEST_USER1, 'group');
|
||||
$groupBackend->addToGroup(self::TEST_USER2, 'group');
|
||||
$groupBackend->addToGroup(self::TEST_USER3, 'group');
|
||||
$groupBackend->addToGroup(self::TEST_USER2, 'group1');
|
||||
$groupBackend->addToGroup(self::TEST_USER3, 'group2');
|
||||
$groupBackend->addToGroup(self::TEST_USER4, 'group3');
|
||||
$groupBackend->addToGroup(self::TEST_USER2, self::TEST_GROUP1);
|
||||
\OC_Group::useBackend($groupBackend);
|
||||
}
|
||||
public function setUp() {
|
||||
\OC::$server->getUserSession()->login(self::TEST_USER1, self::TEST_USER1);
|
||||
$this->boardService = \OC::$server->query("\OCA\Deck\Service\BoardService");
|
||||
}
|
||||
public function testCreate() {
|
||||
$board = new \OCA\Deck\Db\Board();
|
||||
$board->setTitle('Test');
|
||||
$board->setOwner(self::TEST_USER1);
|
||||
$board->setColor('000000');
|
||||
$board->setLabels([]);
|
||||
$created = $this->boardService->create('Test', self::TEST_USER1, '000000');
|
||||
$id = $created->getId();
|
||||
$actual = $this->boardService->find($id);
|
||||
$this->assertEquals($actual->getTitle(), $board->getTitle());
|
||||
$this->assertEquals($actual->getColor(), $board->getColor());
|
||||
$this->assertEquals($actual->getOwner(), $board->getOwner());
|
||||
$this->boardService->delete($id);
|
||||
}
|
||||
|
||||
public function tearDown() {
|
||||
}
|
||||
}
|
||||
@@ -26,24 +26,44 @@ namespace OCA\Deck\Db;
|
||||
use Test\AppFramework\Db\MapperTestUtility;
|
||||
|
||||
/**
|
||||
* Class AclMapperTest
|
||||
* @package OCA\Deck\Db
|
||||
* @group DB
|
||||
*/
|
||||
class AclMapperTest extends MapperTestUtility {
|
||||
|
||||
private $mapper;
|
||||
private $acl;
|
||||
private $dbConnection;
|
||||
private $aclMapper;
|
||||
private $boardMapper;
|
||||
|
||||
// Data
|
||||
private $acls;
|
||||
private $boards;
|
||||
|
||||
public function setup(){
|
||||
parent::setUp();
|
||||
|
||||
$this->dbConnection = \OC::$server->getDatabaseConnection();
|
||||
$this->mapper = new AclMapper($this->db);
|
||||
$this->mapperDatabase = new AclMapper($this->dbConnection);
|
||||
$this->aclMapper = new AclMapper($this->dbConnection);
|
||||
$this->boardMapper = new BoardMapper(
|
||||
$this->dbConnection,
|
||||
\OC::$server->query(LabelMapper::class),
|
||||
$this->aclMapper,
|
||||
\OC::$server->query(StackMapper::class));
|
||||
|
||||
//$acl = $this->getAcl('user','user1');
|
||||
//$this->mapperDatabase->insert($acl);
|
||||
$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();
|
||||
}
|
||||
}
|
||||
/** @return Acl */
|
||||
public function getAcl($type='user', $participant='admin', $write=false, $invite=false, $manage=false, $boardId=123) {
|
||||
@@ -57,23 +77,41 @@ class AclMapperTest extends MapperTestUtility {
|
||||
return $acl;
|
||||
}
|
||||
|
||||
public function testFindAll() {
|
||||
$acls = [];
|
||||
$acls[] = $this->getAcl('user','user1')->jsonSerialize();
|
||||
$acls[] = $this->getAcl('user','user2')->jsonSerialize();
|
||||
$acls[] = $this->getAcl('group','group1')->jsonSerialize();
|
||||
$acls[] = $this->getAcl('group','group2', true, true, true, 234)->jsonSerialize();
|
||||
/** @return Board */
|
||||
public function getBoard($title, $owner) {
|
||||
$board = new Board();
|
||||
$board->setTitle($title);
|
||||
$board->setOwner($owner);
|
||||
return $board;
|
||||
}
|
||||
|
||||
$sql = 'SELECT id, board_id, type, participant, permission_write, permission_invite, permission_manage FROM `*PREFIX*deck_board_acl` WHERE `board_id` = ? ';
|
||||
$params = [123];
|
||||
$rows = [
|
||||
$acls[0], $acls[1], $acls[2]
|
||||
];
|
||||
$this->setMapperResult($sql, $params, $rows);
|
||||
public function testFindAllDatabase() {
|
||||
$actual = $this->aclMapper->findAll($this->boards[0]->getId());
|
||||
$expected = [$this->acls[1], $this->acls[2]];
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
public function testIsOwnerDatabase() {
|
||||
$this->assertTrue($this->aclMapper->isOwner('user2', $this->acls[0]->getId()));
|
||||
$this->assertTrue($this->aclMapper->isOwner('user1', $this->acls[1]->getId()));
|
||||
$this->assertTrue($this->aclMapper->isOwner('user1', $this->acls[2]->getId()));
|
||||
$this->assertTrue($this->aclMapper->isOwner('user3', $this->acls[3]->getId()));
|
||||
$this->assertFalse($this->aclMapper->isOwner('user3', $this->acls[0]->getId()));
|
||||
$this->assertFalse($this->aclMapper->isOwner('user1', $this->acls[0]->getId()));
|
||||
}
|
||||
|
||||
$result = $this->mapper->findAll(123);
|
||||
//$this->assertEquals($rows, $result);
|
||||
public function testFindBoardIdDatabase() {
|
||||
$this->assertEquals($this->boards[0]->getId(), $this->aclMapper->findBoardId($this->acls[1]->getId()));
|
||||
}
|
||||
|
||||
|
||||
public function tearDown() {
|
||||
parent::tearDown();
|
||||
foreach ($this->acls as $acl) {
|
||||
$this->aclMapper->delete($acl);
|
||||
}
|
||||
foreach ($this->boards as $board) {
|
||||
$this->boardMapper->delete($board);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user