Merge pull request #3664 from nextcloud/backport/stable23/2496

[stable23] Transfer ownership
This commit is contained in:
Julius Härtl
2022-04-11 18:29:14 +02:00
committed by GitHub
27 changed files with 1863 additions and 1074 deletions

View File

@@ -0,0 +1,314 @@
<?php
namespace OCA\Deck\Service;
use OCA\Deck\Db\Acl;
use OCA\Deck\Db\Assignment;
use OCA\Deck\Db\AssignmentMapper;
use OCA\Deck\Db\Board;
use OCA\Deck\Db\Card;
/**
* @group DB
* @coversDefaultClass \OCA\Deck\Service\BoardService
*/
class TransferOwnershipTest extends \Test\TestCase {
private const TEST_USER_1 = 'test-share-user1';
private const TEST_USER_2 = 'test-user2';
private const TEST_USER_3 = 'test-user3';
private const TEST_GROUP = 'test-share-user1';
/** @var BoardService */
protected $boardService;
/** @var CardService */
protected $cardService;
/** @var StackService */
protected $stackService;
/** @var AssignmentMapper */
protected $assignmentMapper;
/** @var AssignmentService */
private $assignmentService;
/** @var Board */
private $board;
private $cards;
private $stacks;
public static function setUpBeforeClass(): void {
parent::setUpBeforeClass();
$backend = new \Test\Util\User\Dummy();
\OC_User::useBackend($backend);
\OC::$server->getUserManager()->registerBackend($backend);
$backend->createUser(self::TEST_USER_1, self::TEST_USER_1);
$backend->createUser(self::TEST_USER_2, self::TEST_USER_2);
$backend->createUser(self::TEST_USER_3, self::TEST_USER_3);
// create group
$groupBackend = new \Test\Util\Group\Dummy();
$groupBackend->createGroup(self::TEST_GROUP);
$groupBackend->addToGroup(self::TEST_USER_1, self::TEST_GROUP);
\OC::$server->getGroupManager()->addBackend($groupBackend);
}
public function setUp(): void {
parent::setUp();
\OC::$server->getUserSession()->login(self::TEST_USER_1, self::TEST_USER_1);
$this->boardService = \OC::$server->query(BoardService::class);
$this->stackService = \OC::$server->query(StackService::class);
$this->cardService = \OC::$server->query(CardService::class);
$this->assignmentService = \OC::$server->query(AssignmentService::class);
$this->assignmentMapper = \OC::$server->query(AssignmentMapper::class);
$this->createBoardWithExampleData();
}
public function createBoardWithExampleData() {
$stacks = [];
$board = $this->boardService->create('Test', self::TEST_USER_1, '000000');
$id = $board->getId();
$this->boardService->addAcl($id, Acl::PERMISSION_TYPE_GROUP, self::TEST_GROUP, true, true, true);
$this->boardService->addAcl($id, Acl::PERMISSION_TYPE_USER, self::TEST_USER_3, false, true, false);
$stacks[] = $this->stackService->create('Stack A', $id, 1);
$stacks[] = $this->stackService->create('Stack B', $id, 1);
$stacks[] = $this->stackService->create('Stack C', $id, 1);
$cards[] = $this->cardService->create('Card 1', $stacks[0]->getId(), 'text', 0, self::TEST_USER_1);
$cards[] = $this->cardService->create('Card 2', $stacks[0]->getId(), 'text', 0, self::TEST_USER_1);
$this->assignmentService->assignUser($cards[0]->getId(), self::TEST_USER_1);
$this->board = $board;
$this->cards = $cards;
$this->stacks = $stacks;
}
/**
* @covers ::transferOwnership
*/
public function testTransferBoardOwnership() {
iterator_to_array($this->boardService->transferOwnership(self::TEST_USER_1, self::TEST_USER_2));
$board = $this->boardService->find($this->board->getId());
$boardOwner = $board->getOwner();
$this->assertEquals(self::TEST_USER_2, $boardOwner);
}
/**
* @covers ::transferOwnership
*/
public function testTransferBoardOwnershipWithData() {
iterator_to_array($this->boardService->transferOwnership(self::TEST_USER_1, self::TEST_USER_2));
$board = $this->boardService->find($this->board->getId());
$boardOwner = $board->getOwner();
$this->assertEquals(self::TEST_USER_2, $boardOwner);
$cards = $this->cards;
$newOwnerOwnsTheCards = (bool)array_product(array_filter($cards, function (Card $card) {
$cardUpdated = $this->cardService->find($card->getId());
return $cardUpdated->getOwner() === self::TEST_USER_2;
}));
$this->assertTrue($newOwnerOwnsTheCards);
}
/**
* @covers ::transferOwnership
*/
public function testTransferACLOwnership() {
iterator_to_array($this->boardService->transferOwnership(self::TEST_USER_1, self::TEST_USER_2, true));
$board = $this->boardService->find($this->board->getId());
$acl = $board->getAcl();
$this->assertBoardDoesNotHaveAclUser($board, self::TEST_USER_1);
}
/**
* @covers ::transferOwnership
*/
public function testTransferACLOwnershipPreserveOwner() {
iterator_to_array($this->boardService->transferOwnership(self::TEST_USER_1, self::TEST_USER_2, false));
$board = $this->boardService->find($this->board->getId());
$acl = $board->getAcl();
$this->assertBoardHasAclUser($board, self::TEST_USER_1);
}
/**
* @covers ::transferOwnership
*/
public function testNoTransferAclOwnershipIfGroupType() {
iterator_to_array($this->boardService->transferOwnership(self::TEST_USER_1, self::TEST_USER_2));
$board = $this->boardService->find($this->board->getId());
$acl = $board->getAcl();
$isGroupInAcl = (bool)array_filter($acl, function ($item) {
return $item->getParticipant() === self::TEST_GROUP && $item->getType() === Acl::PERMISSION_TYPE_GROUP;
});
$this->assertTrue($isGroupInAcl);
}
/**
* @covers ::transferOwnership
*/
public function testTransferCardOwnership() {
iterator_to_array($this->boardService->transferOwnership(self::TEST_USER_1, self::TEST_USER_2, true));
$card = $this->cardService->find($this->cards[0]->getId());
$cardOwner = $card->getOwner();
$this->assertEquals(self::TEST_USER_2, $cardOwner);
}
/**
* @covers ::transferOwnership
*/
public function testTransferPreserveCardOwnership() {
iterator_to_array($this->boardService->transferOwnership(self::TEST_USER_1, self::TEST_USER_2, false));
$card = $this->cardService->find($this->cards[0]->getId());
$cardOwner = $card->getOwner();
$this->assertEquals(self::TEST_USER_1, $cardOwner);
}
/**
* @covers ::transferOwnership
*/
public function testReassignCardToNewOwner() {
iterator_to_array($this->boardService->transferOwnership(self::TEST_USER_1, self::TEST_USER_2, true));
$participantsUIDs = array_map(function ($user) {
return $user->getParticipant();
}, $this->assignmentMapper->findAll($this->cards[0]->getId()));
$this->assertContains(self::TEST_USER_2, $participantsUIDs);
$this->assertNotContains(self::TEST_USER_1, $participantsUIDs);
}
/**
* @covers ::transferOwnership
*/
public function testNoReassignCardToNewOwner() {
iterator_to_array($this->boardService->transferOwnership(self::TEST_USER_1, self::TEST_USER_2, false));
$participantsUIDs = array_map(function ($user) {
return $user->getParticipant();
}, $this->assignmentMapper->findAll($this->cards[0]->getId()));
$this->assertContains(self::TEST_USER_1, $participantsUIDs);
$this->assertNotContains(self::TEST_USER_2, $participantsUIDs);
}
/**
* @covers ::transferOwnership
*/
public function testReassignCardToNewParticipantOnlyIfParticipantHasUserType() {
$this->assignmentService->assignUser($this->cards[1]->getId(), self::TEST_USER_1, Assignment::TYPE_GROUP);
iterator_to_array($this->boardService->transferOwnership(self::TEST_USER_1, self::TEST_USER_2));
$participantsUIDs = array_map(function ($user) {
return $user->getParticipant();
}, $this->assignmentMapper->findAll($this->cards[1]->getId()));
$this->assertContains(self::TEST_USER_1, $participantsUIDs);
$this->assertNotContains(self::TEST_USER_2, $participantsUIDs);
}
/**
* @covers ::transferOwnership
*/
public function testTargetAlreadyParticipantOfBoard() {
$this->expectNotToPerformAssertions();
iterator_to_array($this->boardService->transferOwnership(self::TEST_USER_1, self::TEST_USER_3));
}
private function assertBoardHasAclUser($board, $userId) {
$hasUser = (bool)array_filter($board->getAcl(), function ($item) use ($userId) {
return $item->getParticipant() === $userId && $item->getType() === Acl::PERMISSION_TYPE_USER;
});
self::assertTrue($hasUser, 'user ' . $userId . ' should be in the board acl list');
}
private function assertBoardDoesNotHaveAclUser($board, $userId) {
$hasUser = (bool)array_filter($board->getAcl(), function ($item) use ($userId) {
return $item->getParticipant() === $userId && $item->getType() === Acl::PERMISSION_TYPE_USER;
});
self::assertFalse($hasUser, 'user ' . $userId . ' should not be in the board acl list');
}
/**
* @covers ::transferOwnership
*/
public function testDontRemoveOldOwnerFromAcl() {
iterator_to_array($this->boardService->transferOwnership(self::TEST_USER_1, self::TEST_USER_2));
$board = $this->boardService->find($this->board->getId());
$this->assertBoardDoesNotHaveAclUser($board, self::TEST_USER_2);
$this->assertBoardHasAclUser($board, self::TEST_USER_3);
$this->assertBoardHasAclUser($board, self::TEST_USER_1);
}
/**
* @covers ::transferOwnership
*/
public function testRemoveOldOwnerFromAclForChange() {
iterator_to_array($this->boardService->transferOwnership(self::TEST_USER_1, self::TEST_USER_2, true));
$board = $this->boardService->find($this->board->getId());
$this->assertBoardDoesNotHaveAclUser($board, self::TEST_USER_2);
$this->assertBoardHasAclUser($board, self::TEST_USER_3);
$this->assertBoardDoesNotHaveAclUser($board, self::TEST_USER_1);
}
/**
* @covers ::transferOwnership
*/
public function testMergePermissions() {
$this->boardService->addAcl($this->board->getId(), Acl::PERMISSION_TYPE_USER, self::TEST_USER_2, true, false, true);
iterator_to_array($this->boardService->transferOwnership(self::TEST_USER_1, self::TEST_USER_3));
$board = $this->boardService->find($this->board->getId());
$acl = $board->getAcl();
$isMerged = (bool)array_filter($acl, function ($item) {
return $item->getParticipant() === self::TEST_USER_1
&& $item->getType() === Acl::PERMISSION_TYPE_USER
&& $item->getPermission(Acl::PERMISSION_EDIT)
&& $item->getPermission(Acl::PERMISSION_SHARE)
&& $item->getPermission(Acl::PERMISSION_MANAGE);
});
$this->assertTrue($isMerged);
}
/**
* @covers ::transferOwnership
*/
public function testTargetAlreadyParticipantOfCard() {
$this->expectNotToPerformAssertions();
$this->assignmentService->assignUser($this->cards[0]->getId(), self::TEST_USER_3, Assignment::TYPE_USER);
iterator_to_array($this->boardService->transferOwnership(self::TEST_USER_1, self::TEST_USER_3));
}
/**
* @covers ::transferOwnership
*/
public function testTransferSingleBoardAssignment() {
// Arrange separate board next to the one being transferred
$board = $this->boardService->create('Test 2', self::TEST_USER_1, '000000');
$id = $board->getId();
$this->boardService->addAcl($id, Acl::PERMISSION_TYPE_USER, self::TEST_USER_1, true, true, true);
$this->boardService->addAcl($id, Acl::PERMISSION_TYPE_GROUP, self::TEST_GROUP, true, true, true);
$this->boardService->addAcl($id, Acl::PERMISSION_TYPE_USER, self::TEST_USER_3, false, true, false);
$stacks[] = $this->stackService->create('Stack A', $id, 1);
$stacks[] = $this->stackService->create('Stack B', $id, 1);
$stacks[] = $this->stackService->create('Stack C', $id, 1);
$cards[] = $this->cardService->create('Card 1', $stacks[0]->getId(), 'text', 0, self::TEST_USER_1);
$cards[] = $this->cardService->create('Card 2', $stacks[0]->getId(), 'text', 0, self::TEST_USER_1);
$this->assignmentService->assignUser($cards[0]->getId(), self::TEST_USER_1);
// Act
$this->boardService->transferBoardOwnership($this->board->getId(), self::TEST_USER_2, true);
// Assert that the selected board was transferred
$card = $this->cardService->find($this->cards[0]->getId());
$this->assertEquals(self::TEST_USER_2, $card->getOwner());
$participantsUIDs = array_map(function ($assignment) {
return $assignment->getParticipant();
}, $this->assignmentMapper->findAll($this->cards[0]->getId()));
$this->assertContains(self::TEST_USER_2, $participantsUIDs);
$this->assertNotContains(self::TEST_USER_1, $participantsUIDs);
// Assert that other board remained unchanged
$card = $this->cardService->find($cards[0]->getId());
$this->assertEquals(self::TEST_USER_1, $card->getOwner());
$participantsUIDs = array_map(function ($assignment) {
return $assignment->getParticipant();
}, $this->assignmentMapper->findAll($cards[0]->getId()));
$this->assertContains(self::TEST_USER_1, $participantsUIDs);
$this->assertNotContains(self::TEST_USER_2, $participantsUIDs);
}
public function tearDown(): void {
$this->boardService->deleteForce($this->board->getId());
parent::tearDown();
}
}

View File

@@ -26,7 +26,7 @@ composer dump-autoload
if [ -z "$EXECUTOR_NUMBER" ]; then
EXECUTOR_NUMBER=0
fi
PORT=$((8080 + $EXECUTOR_NUMBER))
PORT=$((9090 + $EXECUTOR_NUMBER))
echo $PORT
php -S localhost:$PORT -t $OC_PATH &
PHPPID=$!

View File

@@ -169,18 +169,15 @@ class ActivityManagerTest extends TestCase {
$this->mockUser('user2'),
];
$event = $this->createMock(IEvent::class);
$event->expects($this->at(0))
$event->expects($this->once())
->method('getObjectType')
->willReturn($objectType);
$event->expects($this->at(0))
$event->expects($this->once())
->method('getObjectId')
->willReturn(1);
$event->expects($this->at(2))
$event->expects($this->exactly(2))
->method('setAffectedUser')
->with('user1');
$event->expects($this->at(3))
->method('setAffectedUser')
->with('user2');
->withConsecutive(['user1'], ['user2']);
$mapper = null;
switch ($objectType) {
case ActivityManager::DECK_OBJECT_BOARD:
@@ -196,10 +193,7 @@ class ActivityManagerTest extends TestCase {
$this->permissionService->expects($this->once())
->method('findUsers')
->willReturn($users);
$this->manager->expects($this->at(0))
->method('publish')
->with($event);
$this->manager->expects($this->at(1))
$this->manager->expects($this->exactly(2))
->method('publish')
->with($event);
$this->invokePrivate($this->activityManager, 'sendToUsers', [$event]);

View File

@@ -66,18 +66,14 @@ class DeleteCronTest extends \Test\TestCase {
$this->boardMapper->expects($this->once())
->method('findToDelete')
->willReturn($boards);
$this->boardMapper->expects($this->at(1))
$this->boardMapper->expects($this->exactly(count($boards)))
->method('delete')
->with($boards[0]);
$this->boardMapper->expects($this->at(2))
->method('delete')
->with($boards[1]);
$this->boardMapper->expects($this->at(3))
->method('delete')
->with($boards[2]);
$this->boardMapper->expects($this->at(4))
->method('delete')
->with($boards[3]);
->withConsecutive(
[$boards[0]],
[$boards[1]],
[$boards[2]],
[$boards[3]]
);
$attachment = new Attachment();
$attachment->setType('deck_file');

View File

@@ -54,10 +54,7 @@ class ScheduledNoificationsTest extends \Test\TestCase {
$this->cardMapper->expects($this->once())
->method('findOverdue')
->willReturn($cards);
$this->notificationHelper->expects($this->at(0))
->method('sendCardDuedate')
->with($c1);
$this->notificationHelper->expects($this->at(1))
$this->notificationHelper->expects($this->exactly(2))
->method('sendCardDuedate')
->with($c1);
$this->scheduledNotifications->run(null);

View File

@@ -114,17 +114,18 @@ class NotificationHelperTest extends \Test\TestCase {
}
public function testSendCardDuedate() {
$this->config->expects($this->at(0))
$param1 = ['foo', 'bar', 'asd'];
$param2 = 'deck';
$param3 = 'board:234:notify-due';
$DUE_ASSIGNED = ConfigService::SETTING_BOARD_NOTIFICATION_DUE_ASSIGNED;
$this->config->expects($this->exactly(3))
->method('getUserValue')
->with('foo', 'deck', 'board:234:notify-due', ConfigService::SETTING_BOARD_NOTIFICATION_DUE_ASSIGNED)
->willReturn(ConfigService::SETTING_BOARD_NOTIFICATION_DUE_ALL);
$this->config->expects($this->at(1))
->method('getUserValue')
->with('bar', 'deck', 'board:234:notify-due', ConfigService::SETTING_BOARD_NOTIFICATION_DUE_ASSIGNED)
->willReturn(ConfigService::SETTING_BOARD_NOTIFICATION_DUE_ALL);
$this->config->expects($this->at(2))
->method('getUserValue')
->with('asd', 'deck', 'board:234:notify-due', ConfigService::SETTING_BOARD_NOTIFICATION_DUE_ASSIGNED)
->withConsecutive(
[$param1[0], $param2, $param3, $DUE_ASSIGNED],
[$param1[1], $param2, $param3, $DUE_ASSIGNED],
[$param1[2], $param2, $param3, $DUE_ASSIGNED]
)
->willReturn(ConfigService::SETTING_BOARD_NOTIFICATION_DUE_ALL);
$card = Card::fromParams([
@@ -180,24 +181,12 @@ class NotificationHelperTest extends \Test\TestCase {
$n3->expects($this->once())->method('setSubject')->with('card-overdue', ['MyCardTitle', 'MyBoardTitle'])->willReturn($n3);
$n3->expects($this->once())->method('setDateTime')->willReturn($n3);
$this->notificationManager->expects($this->at(0))
$this->notificationManager->expects($this->exactly(3))
->method('createNotification')
->willReturn($n1);
$this->notificationManager->expects($this->at(1))
->willReturnOnConsecutiveCalls($n1, $n2, $n3);
$this->notificationManager->expects($this->exactly(3))
->method('notify')
->with($n1);
$this->notificationManager->expects($this->at(2))
->method('createNotification')
->willReturn($n2);
$this->notificationManager->expects($this->at(3))
->method('notify')
->with($n2);
$this->notificationManager->expects($this->at(4))
->method('createNotification')
->willReturn($n3);
$this->notificationManager->expects($this->at(5))
->method('notify')
->with($n3);
->withConsecutive([$n1], [$n2], [$n3]);
$this->cardMapper->expects($this->once())
->method('markNotified')
@@ -207,18 +196,19 @@ class NotificationHelperTest extends \Test\TestCase {
}
public function testSendCardDuedateAssigned() {
$this->config->expects($this->at(0))
$param1 = ['foo', 'bar', 'asd'];
$param2 = 'deck';
$param3 = 'board:234:notify-due';
$DUE_ASSIGNED = ConfigService::SETTING_BOARD_NOTIFICATION_DUE_ASSIGNED;
$this->config->expects($this->exactly(3))
->method('getUserValue')
->with('foo', 'deck', 'board:234:notify-due', ConfigService::SETTING_BOARD_NOTIFICATION_DUE_ASSIGNED)
->willReturn(ConfigService::SETTING_BOARD_NOTIFICATION_DUE_ASSIGNED);
$this->config->expects($this->at(1))
->method('getUserValue')
->with('bar', 'deck', 'board:234:notify-due', ConfigService::SETTING_BOARD_NOTIFICATION_DUE_ASSIGNED)
->willReturn(ConfigService::SETTING_BOARD_NOTIFICATION_DUE_ASSIGNED);
$this->config->expects($this->at(2))
->method('getUserValue')
->with('asd', 'deck', 'board:234:notify-due', ConfigService::SETTING_BOARD_NOTIFICATION_DUE_ASSIGNED)
->willReturn(ConfigService::SETTING_BOARD_NOTIFICATION_DUE_ASSIGNED);
->withConsecutive(
[$param1[0], $param2, $param3, $DUE_ASSIGNED],
[$param1[1], $param2, $param3, $DUE_ASSIGNED],
[$param1[2], $param2, $param3, $DUE_ASSIGNED]
)
->willReturn($DUE_ASSIGNED);
$users = [
new DummyUser('foo'), new DummyUser('bar'), new DummyUser('asd')
@@ -278,24 +268,12 @@ class NotificationHelperTest extends \Test\TestCase {
$n3->expects($this->once())->method('setSubject')->with('card-overdue', ['MyCardTitle', 'MyBoardTitle'])->willReturn($n3);
$n3->expects($this->once())->method('setDateTime')->willReturn($n3);
$this->notificationManager->expects($this->at(0))
$this->notificationManager->expects($this->exactly(3))
->method('createNotification')
->willReturn($n1);
$this->notificationManager->expects($this->at(1))
->willReturnOnConsecutiveCalls($n1, $n2, $n3);
$this->notificationManager->expects($this->exactly(3))
->method('notify')
->with($n1);
$this->notificationManager->expects($this->at(2))
->method('createNotification')
->willReturn($n2);
$this->notificationManager->expects($this->at(3))
->method('notify')
->with($n2);
$this->notificationManager->expects($this->at(4))
->method('createNotification')
->willReturn($n3);
$this->notificationManager->expects($this->at(5))
->method('notify')
->with($n3);
->withConsecutive([$n1], [$n2], [$n3]);
$this->cardMapper->expects($this->once())
->method('markNotified')
@@ -306,18 +284,20 @@ class NotificationHelperTest extends \Test\TestCase {
public function testSendCardDuedateNever() {
$this->config->expects($this->at(0))
$param1 = ['foo', 'bar', 'asd'];
$param2 = 'deck';
$param3 = 'board:234:notify-due';
$DUE_ASSIGNED = ConfigService::SETTING_BOARD_NOTIFICATION_DUE_ASSIGNED;
$DUE_OFF = ConfigService::SETTING_BOARD_NOTIFICATION_DUE_OFF;
$this->config->expects($this->exactly(3))
->method('getUserValue')
->with('foo', 'deck', 'board:234:notify-due', ConfigService::SETTING_BOARD_NOTIFICATION_DUE_ASSIGNED)
->willReturn(ConfigService::SETTING_BOARD_NOTIFICATION_DUE_ASSIGNED);
$this->config->expects($this->at(1))
->method('getUserValue')
->with('bar', 'deck', 'board:234:notify-due', ConfigService::SETTING_BOARD_NOTIFICATION_DUE_ASSIGNED)
->willReturn(ConfigService::SETTING_BOARD_NOTIFICATION_DUE_ASSIGNED);
$this->config->expects($this->at(2))
->method('getUserValue')
->with('asd', 'deck', 'board:234:notify-due', ConfigService::SETTING_BOARD_NOTIFICATION_DUE_ASSIGNED)
->willReturn(ConfigService::SETTING_BOARD_NOTIFICATION_DUE_OFF);
->withConsecutive(
[$param1[0], $param2, $param3, $DUE_ASSIGNED],
[$param1[1], $param2, $param3, $DUE_ASSIGNED],
[$param1[2], $param2, $param3, $DUE_ASSIGNED]
)
->willReturnOnConsecutiveCalls($DUE_ASSIGNED, $DUE_ASSIGNED, $DUE_OFF);
$users = [
new DummyUser('foo'), new DummyUser('bar'), new DummyUser('asd')
@@ -370,18 +350,12 @@ class NotificationHelperTest extends \Test\TestCase {
$n2->expects($this->once())->method('setSubject')->with('card-overdue', ['MyCardTitle', 'MyBoardTitle'])->willReturn($n2);
$n2->expects($this->once())->method('setDateTime')->willReturn($n2);
$this->notificationManager->expects($this->at(0))
$this->notificationManager->expects($this->exactly(2))
->method('createNotification')
->willReturn($n1);
$this->notificationManager->expects($this->at(1))
->willReturnOnConsecutiveCalls($n1, $n2);
$this->notificationManager->expects($this->exactly(2))
->method('notify')
->with($n1);
$this->notificationManager->expects($this->at(2))
->method('createNotification')
->willReturn($n2);
$this->notificationManager->expects($this->at(3))
->method('notify')
->with($n2);
->withConsecutive([$n1], [$n2]);
$this->cardMapper->expects($this->once())
->method('markNotified')
@@ -423,10 +397,10 @@ class NotificationHelperTest extends \Test\TestCase {
$notification->expects($this->once())->method('setSubject')->with('card-assigned', ['MyCardTitle', 'MyBoardTitle', 'admin'])->willReturn($notification);
$notification->expects($this->once())->method('setDateTime')->willReturn($notification);
$this->notificationManager->expects($this->at(0))
$this->notificationManager->expects($this->once())
->method('createNotification')
->willReturn($notification);
$this->notificationManager->expects($this->at(1))
$this->notificationManager->expects($this->once())
->method('notify')
->with($notification);
@@ -451,10 +425,10 @@ class NotificationHelperTest extends \Test\TestCase {
$notification->expects($this->once())->method('setSubject')->with('board-shared', ['MyBoardTitle', 'admin'])->willReturn($notification);
$notification->expects($this->once())->method('setDateTime')->willReturn($notification);
$this->notificationManager->expects($this->at(0))
$this->notificationManager->expects($this->once())
->method('createNotification')
->willReturn($notification);
$this->notificationManager->expects($this->at(1))
$this->notificationManager->expects($this->once())
->method('notify')
->with($notification);
@@ -490,10 +464,10 @@ class NotificationHelperTest extends \Test\TestCase {
$notification->expects($this->once())->method('setSubject')->with('board-shared', ['MyBoardTitle', 'admin'])->willReturn($notification);
$notification->expects($this->once())->method('setDateTime')->willReturn($notification);
$this->notificationManager->expects($this->at(0))
$this->notificationManager->expects($this->once())
->method('createNotification')
->willReturn($notification);
$this->notificationManager->expects($this->at(1))
$this->notificationManager->expects($this->once())
->method('notify')
->with($notification);
@@ -540,19 +514,12 @@ class NotificationHelperTest extends \Test\TestCase {
$notification2->expects($this->once())->method('setSubject')->with('card-comment-mentioned', ['MyCard', 1, 'admin'])->willReturn($notification2);
$notification2->expects($this->once())->method('setDateTime')->willReturn($notification2);
$this->notificationManager->expects($this->at(0))
$this->notificationManager->expects($this->exactly(2))
->method('createNotification')
->willReturn($notification1);
$this->notificationManager->expects($this->at(1))
->willReturnOnConsecutiveCalls($notification1, $notification2);
$this->notificationManager->expects($this->exactly(2))
->method('notify')
->with($notification1);
$this->notificationManager->expects($this->at(2))
->method('createNotification')
->willReturn($notification2);
$this->notificationManager->expects($this->at(3))
->method('notify')
->with($notification2);
->withConsecutive([$notification1], [$notification2]);
$this->notificationHelper->sendMention($comment);
}

View File

@@ -110,8 +110,16 @@ class AttachmentServiceTest extends TestCase {
$this->cache = $this->createMock(ICache::class);
$this->cacheFactory->expects($this->any())->method('createDistributed')->willReturn($this->cache);
$this->appContainer->expects($this->at(0))->method('query')->with(FileService::class)->willReturn($this->attachmentServiceImpl);
$this->appContainer->expects($this->at(1))->method('query')->with(FilesAppService::class)->willReturn($this->filesAppServiceImpl);
$this->appContainer->expects($this->exactly(2))
->method('query')
->withConsecutive(
[FileService::class],
[FilesAppService::class]
)
->willReturnOnConsecutiveCalls(
$this->attachmentServiceImpl,
$this->filesAppServiceImpl
);
$this->application->expects($this->any())
->method('getContainer')
@@ -129,9 +137,18 @@ class AttachmentServiceTest extends TestCase {
$fileServiceMock = $this->createMock(FileService::class);
$fileAppServiceMock = $this->createMock(FilesAppService::class);
$appContainer->expects($this->at(0))->method('query')->with(FileService::class)->willReturn($fileServiceMock);
$appContainer->expects($this->at(1))->method('query')->with(FilesAppService::class)->willReturn($fileAppServiceMock);
$appContainer->expects($this->at(2))->method('query')->with(MyAttachmentService::class)->willReturn(new MyAttachmentService());
$appContainer->expects($this->exactly(3))
->method('query')
->withConsecutive(
[FileService::class],
[FilesAppService::class],
[MyAttachmentService::class]
)
->willReturnOnConsecutiveCalls(
$fileServiceMock,
$fileAppServiceMock,
new MyAttachmentService()
);
$application->expects($this->any())
->method('getContainer')
@@ -148,12 +165,24 @@ class AttachmentServiceTest extends TestCase {
$appContainer = $this->createMock(IAppContainer::class);
$fileServiceMock = $this->createMock(FileService::class);
$fileAppServiceMock = $this->createMock(FilesAppService::class);
$appContainer->expects($this->at(0))->method('query')->with(FileService::class)->willReturn($fileServiceMock);
$appContainer->expects($this->at(1))->method('query')->with(FilesAppService::class)->willReturn($fileAppServiceMock);
$appContainer->expects($this->at(2))->method('query')->with(MyAttachmentService::class)->willReturn(new MyAttachmentService());
$appContainer->expects($this->exactly(3))
->method('query')
->withConsecutive(
[FileService::class],
[FilesAppService::class],
[MyAttachmentService::class]
)
->willReturnOnConsecutiveCalls(
$fileServiceMock,
$fileAppServiceMock,
new MyAttachmentService()
);
$application->expects($this->any())
->method('getContainer')
->willReturn($appContainer);
$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');
@@ -185,12 +214,17 @@ class AttachmentServiceTest extends TestCase {
->with(123)
->willReturn($attachments);
$this->attachmentServiceImpl->expects($this->at(0))
$this->attachmentServiceImpl->expects($this->exactly(2))
->method('extendData')
->with($attachments[0]);
$this->attachmentServiceImpl->expects($this->at(1))
->method('extendData')
->with($attachments[1]);
->withConsecutive(
[$attachments[0]],
[$attachments[1]]
)
->willReturnOnConsecutiveCalls(
$attachments[0],
$attachments[1]
);
$this->assertEquals($attachments, $this->attachmentService->findAll(123, false));
}
@@ -215,12 +249,15 @@ class AttachmentServiceTest extends TestCase {
->with(123, false)
->willReturn($attachmentsDeleted);
$this->attachmentServiceImpl->expects($this->at(0))
$this->attachmentServiceImpl->expects($this->exactly(4))
->method('extendData')
->with($attachments[0]);
$this->attachmentServiceImpl->expects($this->at(1))
->method('extendData')
->with($attachments[1]);
->withConsecutive(
[$attachments[0]],
[$attachments[1]],
[$attachmentsDeleted[0]],
[$attachmentsDeleted[1]]
);
$this->assertEquals(array_merge($attachments, $attachmentsDeleted), $this->attachmentService->findAll(123, true));
}
@@ -396,5 +433,6 @@ class AttachmentServiceTest extends TestCase {
->method('allowUndo')
->willReturn(false);
$actual = $this->attachmentService->restore(1, 1);
$this->assertEquals($expected, $actual);
}
}

View File

@@ -31,6 +31,7 @@ use OCA\Deck\Db\Assignment;
use OCA\Deck\Db\AssignmentMapper;
use OCA\Deck\Db\Board;
use OCA\Deck\Db\BoardMapper;
use OCA\Deck\Db\CardMapper;
use OCA\Deck\Db\ChangeHelper;
use OCA\Deck\Db\LabelMapper;
use OCA\Deck\Db\StackMapper;
@@ -58,6 +59,8 @@ class BoardServiceTest extends TestCase {
private $boardMapper;
/** @var StackMapper */
private $stackMapper;
/** @var CardMapper */
private $cardMapper;
/** @var PermissionService */
private $permissionService;
/** @var NotificationHelper */
@@ -85,6 +88,7 @@ class BoardServiceTest extends TestCase {
$this->boardMapper = $this->createMock(BoardMapper::class);
$this->stackMapper = $this->createMock(StackMapper::class);
$this->config = $this->createMock(IConfig::class);
$this->cardMapper = $this->createMock(CardMapper::class);
$this->labelMapper = $this->createMock(LabelMapper::class);
$this->permissionService = $this->createMock(PermissionService::class);
$this->notificationHelper = $this->createMock(NotificationHelper::class);
@@ -106,6 +110,7 @@ class BoardServiceTest extends TestCase {
$this->permissionService,
$this->notificationHelper,
$this->assignedUsersMapper,
$this->cardMapper,
$this->userManager,
$this->groupManager,
$this->activityManager,
@@ -149,7 +154,7 @@ class BoardServiceTest extends TestCase {
->method('find')
->with(1)
->willReturn($b1);
$this->permissionService->expects($this->once())
$this->permissionService->expects($this->any())
->method('findUsers')
->willReturn([
'admin' => 'admin',
@@ -253,6 +258,14 @@ class BoardServiceTest extends TestCase {
->method('insert')
->with($acl)
->willReturn($acl);
$this->permissionService->expects($this->any())
->method('findUsers')
->willReturn([
'admin' => 'admin',
]);
$this->boardMapper->expects($this->once())
->method('find')
->willReturn(new Board());
$this->assertEquals($acl, $this->service->addAcl(
123, 'user', 'admin', true, true, true
));
@@ -295,30 +308,39 @@ class BoardServiceTest extends TestCase {
$existingAcl->setPermissionEdit($currentUserAcl[0]);
$existingAcl->setPermissionShare($currentUserAcl[1]);
$existingAcl->setPermissionManage($currentUserAcl[2]);
$this->permissionService->expects($this->at(0))
->method('checkPermission')
->with($this->boardMapper, 123, Acl::PERMISSION_SHARE, null);
if ($currentUserAcl[2]) {
$this->permissionService->expects($this->at(1))
$this->permissionService->expects($this->exactly(2))
->method('checkPermission')
->with($this->boardMapper, 123, Acl::PERMISSION_MANAGE, null);
->withConsecutive(
[$this->boardMapper, 123, Acl::PERMISSION_SHARE, null],
[$this->boardMapper, 123, Acl::PERMISSION_MANAGE, null]
);
} else {
$this->aclMapper->expects($this->once())
->method('findAll')
->willReturn([$existingAcl]);
$this->permissionService->expects($this->at(1))
$this->permissionService->expects($this->exactly(2))
->method('checkPermission')
->with($this->boardMapper, 123, Acl::PERMISSION_MANAGE, null)
->willThrowException(new NoPermissionException('No permission'));
$this->permissionService->expects($this->at(2))
->withConsecutive(
[$this->boardMapper, 123, Acl::PERMISSION_SHARE, null],
[$this->boardMapper, 123, Acl::PERMISSION_MANAGE, null]
)
->will(
$this->onConsecutiveCalls(
true,
$this->throwException(new NoPermissionException('No permission'))
)
);
$this->permissionService->expects($this->exactly(3))
->method('userCan')
->willReturn($currentUserAcl[0]);
$this->permissionService->expects($this->at(3))
->method('userCan')
->willReturn($currentUserAcl[1]);
$this->permissionService->expects($this->at(4))
->method('userCan')
->willReturn($currentUserAcl[2]);
->willReturnOnConsecutiveCalls(
$currentUserAcl[0],
$currentUserAcl[1],
$currentUserAcl[2]
);
}
$user = $this->createMock(IUser::class);
@@ -333,6 +355,14 @@ class BoardServiceTest extends TestCase {
$acl->resolveRelation('participant', function ($participant) use (&$user) {
return null;
});
$this->boardMapper->expects($this->once())
->method('find')
->willReturn(new Board());
$this->permissionService->expects($this->any())
->method('findUsers')
->willReturn([
'admin' => 'admin',
]);
$this->notificationHelper->expects($this->once())
->method('sendBoardShared');
$expected = clone $acl;

View File

@@ -139,13 +139,17 @@ class PermissionServiceTest extends \Test\TestCase {
}
public function testUserIsBoardOwner() {
$board = new Board();
$board->setOwner('admin');
$this->boardMapper->expects($this->at(0))->method('find')->with(123)->willReturn($board);
$adminBoard = new Board();
$adminBoard->setOwner('admin');
$userBoard = new Board();
$userBoard->setOwner('user1');
$this->boardMapper->expects($this->exactly(2))
->method('find')
->withConsecutive([123], [234])
->willReturnOnConsecutiveCalls($adminBoard, $userBoard);
$this->assertEquals(true, $this->service->userIsBoardOwner(123));
$board = new Board();
$board->setOwner('user1');
$this->boardMapper->expects($this->at(0))->method('find')->with(234)->willReturn($board);
$this->assertEquals(false, $this->service->userIsBoardOwner(234));
}
@@ -336,7 +340,7 @@ class PermissionServiceTest extends \Test\TestCase {
$aclGroup->setParticipant('group1');
$board = $this->createMock(Board::class);
$board->expects($this->at(0))
$board->expects($this->once())
->method('__call')
->with('getOwner', [])
->willReturn('user1');
@@ -348,14 +352,11 @@ class PermissionServiceTest extends \Test\TestCase {
->method('find')
->with(123)
->willReturn($board);
$this->userManager->expects($this->at(0))
$this->userManager->expects($this->exactly(2))
->method('get')
->with('user1')
->willReturn($user1);
$this->userManager->expects($this->at(1))
->method('get')
->with('user2')
->willReturn($user2);
->withConsecutive(['user1'], ['user2'])
->willReturnOnConsecutiveCalls($user1, $user2);
$group = $this->createMock(IGroup::class);
$group->expects($this->once())
->method('getUsers')