diff --git a/tests/unit/Notification/NotificationHelperTest.php b/tests/unit/Notification/NotificationHelperTest.php index c6625777a..ba6958345 100644 --- a/tests/unit/Notification/NotificationHelperTest.php +++ b/tests/unit/Notification/NotificationHelperTest.php @@ -184,6 +184,39 @@ class NotificationHelperTest extends \Test\TestCase { $this->notificationHelper->sendCardDuedate($card); } + public function testSendCardAssignedUser() { + $board = new Board(); + $board->setId(123); + $board->setTitle('MyBoardTitle'); + $acl = new Acl(); + $acl->setParticipant('admin'); + $acl->setType(Acl::PERMISSION_TYPE_USER); + $card = new Card(); + $card->setTitle('MyCardTitle'); + $card->setOwner('admin'); + $card->setStackId(123); + $card->setOrder(999); + $card->setType('text'); + $card->setId(1337); + $card->setAssignedUsers(['userA']); + + $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('card', 1337)->willReturn($notification); + $notification->expects($this->once())->method('setSubject')->with('card-assigned', ['MyCardTitle', 'userA', '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->sendCardAssigned($card, 'userA'); + } + public function testSendBoardSharedUser() { $board = new Board(); $board->setId(123); diff --git a/tests/unit/Notification/NotifierTest.php b/tests/unit/Notification/NotifierTest.php index 406196221..3d8992cdd 100644 --- a/tests/unit/Notification/NotifierTest.php +++ b/tests/unit/Notification/NotifierTest.php @@ -129,11 +129,82 @@ class UnknownUserTest extends \Test\TestCase { } + public function dataPrepareCardAssigned() { + return [ + [true], [false] + ]; + } + + /** @dataProvider dataPrepareCardAssigned */ + public function testPrepareCardAssigned($withUserFound = true) { + /** @var INotification $notification */ + $notification = $this->createMock(INotification::class); + $notification->expects($this->once()) + ->method('getApp') + ->willReturn('deck'); + + $notification->expects($this->once()) + ->method('getSubjectParameters') + ->willReturn(['Card title','Board title', 'otheruser']); + + $notification->expects($this->once()) + ->method('getSubject') + ->willReturn('card-assigned'); + $notification->expects($this->once()) + ->method('getObjectId') + ->willReturn('123'); + if ($withUserFound) { + $user = $this->createMock(IUser::class); + $user->expects($this->any()) + ->method('getDisplayName') + ->willReturn('Other User'); + $dn = 'Other User'; + } else { + $user = null; + $dn = 'otheruser'; + } + $this->userManager->expects($this->once()) + ->method('get') + ->with('otheruser') + ->willReturn($user); + + $expectedMessage = 'The card "Card title" on "Board title" has been assigned to you by '.$dn.'.'; + $notification->expects($this->once()) + ->method('setParsedSubject') + ->with($expectedMessage); + $notification->expects($this->once()) + ->method('setRichSubject') + ->with('{user} has assigned the card "Card title" on "Board title" to you.', [ + 'user' => [ + 'type' => 'user', + 'id' => 'otheruser', + 'name' => $dn, + ] + ]); + + $this->url->expects($this->once()) + ->method('imagePath') + ->with('deck', 'deck-dark.svg') + ->willReturn('deck-dark.svg'); + $this->url->expects($this->once()) + ->method('getAbsoluteURL') + ->with('deck-dark.svg') + ->willReturn('/absolute/deck-dark.svg'); + $notification->expects($this->once()) + ->method('setIcon') + ->with('/absolute/deck-dark.svg'); + + $actualNotification = $this->notifier->prepare($notification, 'en_US'); + + $this->assertEquals($notification, $actualNotification); + } + public function dataPrepareBoardShared() { return [ [true], [false] ]; } + /** @dataProvider dataPrepareBoardShared */ public function testPrepareBoardShared($withUserFound = true) { /** @var INotification $notification */ diff --git a/tests/unit/Service/CardServiceTest.php b/tests/unit/Service/CardServiceTest.php index 95de77e50..df87f4ece 100644 --- a/tests/unit/Service/CardServiceTest.php +++ b/tests/unit/Service/CardServiceTest.php @@ -59,7 +59,7 @@ class CardServiceTest extends TestCase { $this->notificationHelper = $this->createMock(NotificationHelper::class); $this->assignedUsersMapper = $this->createMock(AssignedUsersMapper::class); $this->attachmentService = $this->createMock(AttachmentService::class); - $this->cardService = new CardService($this->cardMapper, $this->stackMapper, $this->permissionService, $this->boardService, $this->notificationHelper, $this->assignedUsersMapper, $this->attachmentService); + $this->cardService = new CardService($this->cardMapper, $this->stackMapper, $this->permissionService, $this->boardService, $this->notificationHelper, $this->assignedUsersMapper, $this->attachmentService, 'userXY'); } public function testFind() {