Tests: Add tests for sharing a board notifications

Signed-off-by: Julius Härtl <jus@bitgrid.net>
This commit is contained in:
Julius Härtl
2017-10-03 19:39:29 +02:00
committed by Julius Härtl
parent ac1b1e826f
commit d9c3aa44b9
2 changed files with 77 additions and 1 deletions

View File

@@ -38,4 +38,12 @@ class User extends RelationalObject {
'displayname' => $this->object->getDisplayName() 'displayname' => $this->object->getDisplayName()
]; ];
} }
public function getUID() {
return $this->object->getUID();
}
public function getDisplayName() {
return $this->object->getDisplayName();
}
} }

View File

@@ -24,13 +24,16 @@
namespace OCA\Deck\Notification; namespace OCA\Deck\Notification;
use OCA\Deck\Db\Acl;
use OCA\Deck\Db\Board; use OCA\Deck\Db\Board;
use OCA\Deck\Db\BoardMapper; use OCA\Deck\Db\BoardMapper;
use OCA\Deck\Db\Card; use OCA\Deck\Db\Card;
use OCA\Deck\Db\CardMapper; use OCA\Deck\Db\CardMapper;
use OCA\Deck\Db\User; use OCA\Deck\Db\User;
use OCA\Deck\Service\PermissionService; use OCA\Deck\Service\PermissionService;
use OCP\IGroup;
use OCP\IGroupManager; use OCP\IGroupManager;
use OCP\IUser;
use OCP\Notification\IManager; use OCP\Notification\IManager;
use OCP\Notification\INotification; use OCP\Notification\INotification;
@@ -179,9 +182,74 @@ class NotificationHelperTest extends \Test\TestCase {
->with($card); ->with($card);
$this->notificationHelper->sendCardDuedate($card); $this->notificationHelper->sendCardDuedate($card);
}
public function testSendBoardSharedUser() {
$board = new Board();
$board->setId(123);
$board->setTitle('MyBoardTitle');
$acl = new Acl();
$acl->setParticipant('userA');
$acl->setType(Acl::PERMISSION_TYPE_USER);
$this->boardMapper->expects($this->once())
->method('find')
->with(123)
->willReturn($board);
$notification = $this->createMock(INotification::class);
$notification->expects($this->once())->method('setApp')->with('deck')->willReturn($notification);
$notification->expects($this->once())->method('setUser')->with('userA')->willReturn($notification);
$notification->expects($this->once())->method('setObject')->with('board', 123)->willReturn($notification);
$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))
->method('createNotification')
->willReturn($notification);
$this->notificationManager->expects($this->at(1))
->method('notify')
->with($notification);
$this->notificationHelper->sendBoardShared(123, $acl);
}
public function testSendBoardSharedGroup() {
$board = new Board();
$board->setId(123);
$board->setTitle('MyBoardTitle');
$acl = new Acl();
$acl->setParticipant('groupA');
$acl->setType(Acl::PERMISSION_TYPE_GROUP);
$this->boardMapper->expects($this->once())
->method('find')
->with(123)
->willReturn($board);
$user = $this->createMock(IUser::class);
$user->expects($this->once())
->method('getUID')
->willReturn('userA');
$group = $this->createMock(IGroup::class);
$group->expects($this->once())
->method('getUsers')
->willReturn([$user]);
$this->groupManager->expects($this->once())
->method('get')
->willReturn($group);
$notification = $this->createMock(INotification::class);
$notification->expects($this->once())->method('setApp')->with('deck')->willReturn($notification);
$notification->expects($this->once())->method('setUser')->with('userA')->willReturn($notification);
$notification->expects($this->once())->method('setObject')->with('board', 123)->willReturn($notification);
$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))
->method('createNotification')
->willReturn($notification);
$this->notificationManager->expects($this->at(1))
->method('notify')
->with($notification);
$this->notificationHelper->sendBoardShared(123, $acl);
} }
} }