@@ -23,6 +23,7 @@
|
||||
|
||||
namespace OCA\Deck\Cron;
|
||||
|
||||
use OCA\Deck\Db\Board;
|
||||
use OCA\Deck\Db\BoardMapper;
|
||||
|
||||
class DeleteCronTest extends \Test\TestCase {
|
||||
@@ -33,26 +34,39 @@ class DeleteCronTest extends \Test\TestCase {
|
||||
protected $deleteCron;
|
||||
|
||||
public function setUp() {
|
||||
parent::setUp();
|
||||
$this->boardMapper = $this->createMock(BoardMapper::class);
|
||||
$this->deleteCron = new DeleteCron($this->boardMapper);
|
||||
}
|
||||
|
||||
protected function getBoard($id) {
|
||||
$board = new Board();
|
||||
$board->setId($id);
|
||||
return $board;
|
||||
}
|
||||
|
||||
public function testDeleteCron() {
|
||||
$boards = [
|
||||
$this->getBoard(1),
|
||||
$this->getBoard(2),
|
||||
$this->getBoard(3),
|
||||
$this->getBoard(4),
|
||||
];
|
||||
$this->boardMapper->expects($this->once())
|
||||
->method('findToDelete')
|
||||
->willReturn([1, 2, 3, 4]);
|
||||
$this->boardMapper->expects($this->at(0))
|
||||
->method('delete')
|
||||
->with(1);
|
||||
->willReturn($boards);
|
||||
$this->boardMapper->expects($this->at(1))
|
||||
->method('delete')
|
||||
->with(2);
|
||||
->with($boards[0]);
|
||||
$this->boardMapper->expects($this->at(2))
|
||||
->method('delete')
|
||||
->with(3);
|
||||
->with($boards[1]);
|
||||
$this->boardMapper->expects($this->at(3))
|
||||
->method('delete')
|
||||
->with(4);
|
||||
$this->invokePrivate($this->deleteCron, 'run', null);
|
||||
->with($boards[2]);
|
||||
$this->boardMapper->expects($this->at(4))
|
||||
->method('delete')
|
||||
->with($boards[3]);
|
||||
$this->invokePrivate($this->deleteCron, 'run', [null]);
|
||||
}
|
||||
}
|
||||
@@ -23,6 +23,7 @@
|
||||
|
||||
namespace OCA\Deck\Db;
|
||||
|
||||
use OCP\IDBConnection;
|
||||
use OCP\IGroupManager;
|
||||
use OCP\IUserManager;
|
||||
use Test\AppFramework\Db\MapperTestUtility;
|
||||
@@ -32,10 +33,15 @@ use Test\AppFramework\Db\MapperTestUtility;
|
||||
*/
|
||||
class BoardMapperTest extends MapperTestUtility {
|
||||
|
||||
/** @var IDBConnection */
|
||||
private $dbConnection;
|
||||
/** @var AclMapper|\PHPUnit_Framework_MockObject_MockObject */
|
||||
private $aclMapper;
|
||||
/** @var BoardMapper */
|
||||
private $boardMapper;
|
||||
/** @var IUserManager|\PHPUnit_Framework_MockObject_MockObject */
|
||||
private $userManager;
|
||||
/** @var IGroupManager|\PHPUnit_Framework_MockObject_MockObject */
|
||||
private $groupManager;
|
||||
|
||||
// Data
|
||||
@@ -96,7 +102,6 @@ class BoardMapperTest extends MapperTestUtility {
|
||||
$board = new Board();
|
||||
$board->setTitle($title);
|
||||
$board->setOwner($owner);
|
||||
$board->setShared(1);
|
||||
return $board;
|
||||
}
|
||||
|
||||
@@ -122,11 +127,31 @@ class BoardMapperTest extends MapperTestUtility {
|
||||
}
|
||||
}
|
||||
|
||||
public function testFindAll() {
|
||||
$actual = $this->boardMapper->findAll();
|
||||
$this->assertAttributeEquals($this->boards[0]->getId(), 'id', $actual[0]);
|
||||
$this->assertAttributeEquals($this->boards[1]->getId(), 'id', $actual[1]);
|
||||
$this->assertAttributeEquals($this->boards[2]->getId(), 'id', $actual[2]);
|
||||
}
|
||||
|
||||
public function testFindAllToDelete() {
|
||||
$this->boards[0]->setDeletedAt(1);
|
||||
$this->boards[0] = $this->boardMapper->update($this->boards[0]);
|
||||
|
||||
$actual = $this->boardMapper->findToDelete();
|
||||
$this->boards[0]->resetUpdatedFields();
|
||||
$this->assertEquals([$this->boards[0]], $actual);
|
||||
|
||||
$this->boards[0]->setDeletedAt(0);
|
||||
$this->boardMapper->update($this->boards[0]);
|
||||
}
|
||||
|
||||
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 = [
|
||||
|
||||
@@ -2,7 +2,9 @@
|
||||
|
||||
namespace OCA\Deck\Db;
|
||||
|
||||
class BoardTest extends \PHPUnit_Framework_TestCase {
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class BoardTest extends TestCase {
|
||||
private function createBoard() {
|
||||
$board = new Board();
|
||||
$board->setId(1);
|
||||
|
||||
58
tests/unit/Db/GroupTest.php
Normal file
58
tests/unit/Db/GroupTest.php
Normal file
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
/**
|
||||
* @copyright Copyright (c) 2017 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\IGroup;
|
||||
|
||||
class GroupTest extends \Test\TestCase {
|
||||
|
||||
public function testGroupObjectSerialize() {
|
||||
/** @var IGroup $group */
|
||||
$group = $this->createMock(IGroup::class);
|
||||
$group->expects($this->any())
|
||||
->method('getGID')
|
||||
->willReturn('mygroup');
|
||||
$groupRelationalObject = new Group($group);
|
||||
$expected = [
|
||||
'uid' => 'mygroup',
|
||||
'displayname' => 'mygroup'
|
||||
];
|
||||
$this->assertEquals($expected, $groupRelationalObject->getObjectSerialization());
|
||||
}
|
||||
|
||||
public function testGroupJSONSerialize() {
|
||||
/** @var IGroup $group */
|
||||
$group = $this->createMock(IGroup::class);
|
||||
$group->expects($this->any())
|
||||
->method('getGID')
|
||||
->willReturn('mygroup');
|
||||
$groupRelationalObject = new Group($group);
|
||||
$expected = [
|
||||
'uid' => 'mygroup',
|
||||
'displayname' => 'mygroup',
|
||||
'primaryKey' => 'mygroup'
|
||||
];
|
||||
$this->assertEquals($expected, $groupRelationalObject->jsonSerialize());
|
||||
}
|
||||
}
|
||||
64
tests/unit/Db/UserTest.php
Normal file
64
tests/unit/Db/UserTest.php
Normal file
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
/**
|
||||
* @copyright Copyright (c) 2017 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\IUser;
|
||||
|
||||
class UserTest extends \Test\TestCase {
|
||||
|
||||
public function testGroupObjectSerialize() {
|
||||
/** @var IUser $user */
|
||||
$user = $this->createMock(IUser::class);
|
||||
$user->expects($this->any())
|
||||
->method('getUID')
|
||||
->willReturn('myuser');
|
||||
$user->expects($this->any())
|
||||
->method('getDisplayName')
|
||||
->willReturn('myuser displayname');
|
||||
$userRelationalObject = new User($user);
|
||||
$expected = [
|
||||
'uid' => 'myuser',
|
||||
'displayname' => 'myuser displayname'
|
||||
];
|
||||
$this->assertEquals($expected, $userRelationalObject->getObjectSerialization());
|
||||
}
|
||||
|
||||
public function testGroupJSONSerialize() {
|
||||
/** @var IUser $user */
|
||||
$user = $this->createMock(IUser::class);
|
||||
$user->expects($this->any())
|
||||
->method('getUID')
|
||||
->willReturn('myuser');
|
||||
$user->expects($this->any())
|
||||
->method('getDisplayName')
|
||||
->willReturn('myuser displayname');
|
||||
$userRelationalObject = new User($user);
|
||||
$expected = [
|
||||
'uid' => 'myuser',
|
||||
'displayname' => 'myuser displayname',
|
||||
'primaryKey' => 'myuser'
|
||||
];
|
||||
$this->assertEquals($expected, $userRelationalObject->jsonSerialize());
|
||||
}
|
||||
}
|
||||
128
tests/unit/Migration/UnknownUserTest.php
Normal file
128
tests/unit/Migration/UnknownUserTest.php
Normal file
@@ -0,0 +1,128 @@
|
||||
<?php
|
||||
/**
|
||||
* @copyright Copyright (c) 2017 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\Migration;
|
||||
|
||||
use OCA\Deck\Db\Acl;
|
||||
use OCA\Deck\Db\AclMapper;
|
||||
use OCA\Deck\Db\Board;
|
||||
use OCA\Deck\Db\BoardMapper;
|
||||
use OCP\IGroupManager;
|
||||
use OCP\IUserManager;
|
||||
use OCP\Migration\IOutput;
|
||||
|
||||
class UnknownUserTest extends \Test\TestCase {
|
||||
|
||||
/** @var IUserManager */
|
||||
private $userManager;
|
||||
/** @var IGroupManager */
|
||||
private $groupManager;
|
||||
/** @var AclMapper */
|
||||
private $aclMapper;
|
||||
/** @var BoardMapper */
|
||||
private $boardMapper;
|
||||
/** @var UnknownUsers */
|
||||
private $unknownUsers;
|
||||
|
||||
public function setUp() {
|
||||
parent::setUp();
|
||||
$this->userManager = $this->createMock(IUserManager::class);
|
||||
$this->groupManager = $this->createMock(IGroupManager::class);
|
||||
$this->aclMapper = $this->createMock(AclMapper::class);
|
||||
$this->boardMapper = $this->createMock(BoardMapper::class);
|
||||
$this->unknownUsers = new UnknownUsers($this->userManager, $this->groupManager, $this->aclMapper, $this->boardMapper);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function testGetName() {
|
||||
$this->assertEquals('Delete orphaned ACL rules', $this->unknownUsers->getName());
|
||||
}
|
||||
|
||||
public function testRun() {
|
||||
/** @var IOutput $output */
|
||||
$output = $this->createMock(IOutput::class);
|
||||
$boards = [
|
||||
$this->getBoard(1,'Test', 'admin'),
|
||||
];
|
||||
$acl = [
|
||||
$this->getAcl('user', 'existing', 1),
|
||||
$this->getAcl('user', 'not existing', 1),
|
||||
$this->getAcl('group', 'existing', 1),
|
||||
$this->getAcl('group', 'not existing', 1),
|
||||
];
|
||||
$this->aclMapper->expects($this->at(0))
|
||||
->method('findAll')
|
||||
->with(1)
|
||||
->willReturn($acl);
|
||||
|
||||
$this->userManager->expects($this->at(0))
|
||||
->method('get')
|
||||
->with('existing')
|
||||
->willReturn(true);
|
||||
$this->userManager->expects($this->at(1))
|
||||
->method('get')
|
||||
->with('not existing')
|
||||
->willReturn(null);
|
||||
$this->groupManager->expects($this->at(0))
|
||||
->method('get')
|
||||
->with('existing')
|
||||
->willReturn(true);
|
||||
$this->groupManager->expects($this->at(1))
|
||||
->method('get')
|
||||
->with('not existing')
|
||||
->willReturn(null);
|
||||
|
||||
$this->boardMapper->expects($this->once())
|
||||
->method('findAll')
|
||||
->willReturn($boards);
|
||||
|
||||
$this->aclMapper->expects($this->at(1))
|
||||
->method('delete')
|
||||
->with($acl[1]);
|
||||
$this->aclMapper->expects($this->at(2))
|
||||
->method('delete')
|
||||
->with($acl[3]);
|
||||
|
||||
$this->unknownUsers->run($output);
|
||||
}
|
||||
|
||||
|
||||
/** @return Acl */
|
||||
public function getAcl($type='user', $participant='admin', $boardId=123) {
|
||||
$acl = new Acl();
|
||||
$acl->setParticipant($participant);
|
||||
$acl->setType($type);
|
||||
$acl->setBoardId($boardId);
|
||||
return $acl;
|
||||
}
|
||||
|
||||
/** @return Board */
|
||||
public function getBoard($id, $title, $owner) {
|
||||
$board = new Board();
|
||||
$board->setId($id);
|
||||
$board->setTitle($title);
|
||||
$board->setOwner($owner);
|
||||
return $board;
|
||||
}
|
||||
}
|
||||
@@ -53,6 +53,7 @@ class BoardServiceTest extends \Test\TestCase {
|
||||
private $userId = 'admin';
|
||||
|
||||
public function setUp() {
|
||||
parent::setUp();
|
||||
$this->l10n = $this->createMock(L10N::class);
|
||||
$this->aclMapper = $this->createMock(AclMapper::class);
|
||||
$this->boardMapper = $this->createMock(BoardMapper::class);
|
||||
|
||||
@@ -44,6 +44,7 @@ class CardServiceTest extends TestCase {
|
||||
private $boardService;
|
||||
|
||||
public function setUp() {
|
||||
parent::setUp();
|
||||
$this->cardMapper = $this->getMockBuilder(CardMapper::class)
|
||||
->disableOriginalConstructor()->getMock();
|
||||
$this->stackMapper = $this->getMockBuilder(StackMapper::class)
|
||||
|
||||
@@ -40,6 +40,7 @@ class LabelServiceTest extends TestCase {
|
||||
private $boardService;
|
||||
|
||||
public function setUp() {
|
||||
parent::setUp();
|
||||
$this->labelMapper = $this->getMockBuilder(LabelMapper::class)
|
||||
->disableOriginalConstructor()->getMock();
|
||||
$this->permissionService = $this->getMockBuilder(PermissionService::class)
|
||||
|
||||
@@ -46,6 +46,7 @@ class PermissionServiceTest extends \PHPUnit_Framework_TestCase {
|
||||
private $userId = 'admin';
|
||||
|
||||
public function setUp() {
|
||||
parent::setUp();
|
||||
$this->logger = $this->request = $this->getMockBuilder(ILogger::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
@@ -49,6 +49,7 @@ class StackServiceTest extends TestCase {
|
||||
private $boardService;
|
||||
|
||||
public function setUp() {
|
||||
parent::setUp();
|
||||
$this->stackMapper = $this->getMockBuilder(StackMapper::class)
|
||||
->disableOriginalConstructor()->getMock();
|
||||
$this->cardMapper = $this->getMockBuilder(CardMapper::class)
|
||||
@@ -165,6 +166,9 @@ class StackServiceTest extends TestCase {
|
||||
$this->assertEquals($stack, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group DB
|
||||
*/
|
||||
public function testReorder() {
|
||||
$this->permissionService->expects($this->once())->method('checkPermission');
|
||||
$a = $this->createStack(1, 0);
|
||||
|
||||
@@ -120,6 +120,14 @@ class BoardControllerTest extends \PHPUnit_Framework_TestCase {
|
||||
$this->assertEquals(1, $this->controller->delete(123));
|
||||
}
|
||||
|
||||
public function testDeleteUndo() {
|
||||
$this->boardService->expects($this->once())
|
||||
->method('deleteUndo')
|
||||
->with(123)
|
||||
->willReturn(1);
|
||||
$this->assertEquals(1, $this->controller->deleteUndo(123));
|
||||
}
|
||||
|
||||
public function testGetUserPermissions() {
|
||||
$acl = [
|
||||
Acl::PERMISSION_READ => true,
|
||||
|
||||
Reference in New Issue
Block a user