From 77472b978d49d4127a688b4bdd4d91e096a1ced1 Mon Sep 17 00:00:00 2001 From: Steav Date: Sun, 22 Jul 2018 13:41:56 +0200 Subject: [PATCH 1/8] Add notification on card assignment to user Signed-off-by: Steav --- l10n/de.js | 1 + l10n/de.json | 1 + l10n/de_DE.js | 1 + l10n/de_DE.json | 1 + lib/Notification/NotificationHelper.php | 18 ++++++++++++++++++ lib/Notification/Notifier.php | 12 ++++++++++++ lib/Service/CardService.php | 10 +++++++++- 7 files changed, 43 insertions(+), 1 deletion(-) diff --git a/l10n/de.js b/l10n/de.js index efc1010ce..93f055742 100644 --- a/l10n/de.js +++ b/l10n/de.js @@ -10,6 +10,7 @@ OC.L10N.register( "Are you sure you want to delete the stack with all of its data?" : "Möchtest du diesen Stapel mit allen Daten wirklich löschen?", "Personal" : "Persönlich", "The card \"%s\" on \"%s\" has reached its due date." : "Die Karte \"%s\" auf \"%s\" ist überfällig.", + "The card \"%s\" on \"%s\" has been assigned to you by %s." : "Die Karte \"%s\" wurde Dir auf \"%s\" von %s zugewiesen.", "The board \"%s\" has been shared with you by %s." : "Das Board \"%s\" wurde von %s mit Dir geteilt.", "{user} has shared the board %s with you." : "{user} hat das Board %s mit Dir geteilt.", "No data was provided to create an attachment." : "Es wurde keine Daten zum Erstellen eines Anhangs bereitgestellt.", diff --git a/l10n/de.json b/l10n/de.json index 95c7a2b55..5b19f15cc 100644 --- a/l10n/de.json +++ b/l10n/de.json @@ -8,6 +8,7 @@ "Are you sure you want to delete the stack with all of its data?" : "Möchtest du diesen Stapel mit allen Daten wirklich löschen?", "Personal" : "Persönlich", "The card \"%s\" on \"%s\" has reached its due date." : "Die Karte \"%s\" auf \"%s\" ist überfällig.", + "The card \"%s\" on \"%s\" has been assigned to you by %s." : "Die Karte \"%s\" wurde Dir auf \"%s\" von %s zugewiesen.", "The board \"%s\" has been shared with you by %s." : "Das Board \"%s\" wurde von %s mit Dir geteilt.", "{user} has shared the board %s with you." : "{user} hat das Board %s mit Dir geteilt.", "No data was provided to create an attachment." : "Es wurde keine Daten zum Erstellen eines Anhangs bereitgestellt.", diff --git a/l10n/de_DE.js b/l10n/de_DE.js index 1ee8a819c..86dec14bf 100644 --- a/l10n/de_DE.js +++ b/l10n/de_DE.js @@ -10,6 +10,7 @@ OC.L10N.register( "Are you sure you want to delete the stack with all of its data?" : "Möchten Sie diesen Stapel mit allen Daten wirklich löschen?", "Personal" : "Persönlich", "The card \"%s\" on \"%s\" has reached its due date." : "Die Karte \"%s\" auf \"%s\" ist überfällig.", + "The card \"%s\" on \"%s\" has been assigned to you by %s." : "Die Karte \"%s\" wurde Ihnen auf \"%s\" von %s zugewiesen.", "The board \"%s\" has been shared with you by %s." : "Das Board \"%s\" wurde von %s mit Ihnen geteilt.", "{user} has shared the board %s with you." : "{user} hat das Board %s mit Ihnen geteilt.", "No data was provided to create an attachment." : "Es wurde keine Daten zum Erstellen eines Anhangs bereitgestellt.", diff --git a/l10n/de_DE.json b/l10n/de_DE.json index b565c2a4c..a4c808953 100644 --- a/l10n/de_DE.json +++ b/l10n/de_DE.json @@ -9,6 +9,7 @@ "Personal" : "Persönlich", "The card \"%s\" on \"%s\" has reached its due date." : "Die Karte \"%s\" auf \"%s\" ist überfällig.", "The board \"%s\" has been shared with you by %s." : "Das Board \"%s\" wurde von %s mit Ihnen geteilt.", + "The card \"%s\" on \"%s\" has been assigned to you by %s." : "Die Karte \"%s\" wurde Ihnen auf \"%s\" von %s zugewiesen.", "{user} has shared the board %s with you." : "{user} hat das Board %s mit Ihnen geteilt.", "No data was provided to create an attachment." : "Es wurde keine Daten zum Erstellen eines Anhangs bereitgestellt.", "Finished" : "Abgeschlossen", diff --git a/lib/Notification/NotificationHelper.php b/lib/Notification/NotificationHelper.php index b2d0a9aa9..e4a6f21ee 100644 --- a/lib/Notification/NotificationHelper.php +++ b/lib/Notification/NotificationHelper.php @@ -94,6 +94,24 @@ public function sendCardDuedate($card) { $this->cardMapper->markNotified($card); } + public function sendCardAssigned($card, $userId) { + $boardId = $this->cardMapper->findBoardId($card->getId()); + $board = $this->getBoard($boardId); + + $notification = $this->notificationManager->createNotification(); + $notification + ->setApp('deck') + ->setUser((string) $userId) + ->setDateTime(new DateTime()) + ->setObject('card', $card->getId()) + ->setSubject('card-assigned', [ + $card->getTitle(), + $board->getTitle(), + $this->currentUser + ]); + $this->notificationManager->notify($notification); + } + /** * Send notifications that a board was shared with a user/group * diff --git a/lib/Notification/Notifier.php b/lib/Notification/Notifier.php index 1049a8201..84ac2c5c9 100644 --- a/lib/Notification/Notifier.php +++ b/lib/Notification/Notifier.php @@ -73,6 +73,18 @@ public function prepare(INotification $notification, $languageCode) { $params = $notification->getSubjectParameters(); switch ($notification->getSubject()) { + case 'card-assigned': + $cardId = $notification->getObjectId(); + $boardId = $this->cardMapper->findBoardId($cardId); + $initiator = $this->userManager->get($params[2]); + if ($initiator !== null) { + $params[2] = $initiator->getDisplayName(); + } + $notification->setParsedSubject( + (string) $l->t('The card "%s" on "%s" has been assigned to you by %s.', $params) + ); + $notification->setLink($this->url->linkToRouteAbsolute('deck.page.index') . '#!/board/' . $boardId . '//card/' . $cardId . ''); + break; case 'card-overdue': $cardId = $notification->getObjectId(); $boardId = $this->cardMapper->findBoardId($cardId); diff --git a/lib/Service/CardService.php b/lib/Service/CardService.php index 26fa3753c..83188de0b 100644 --- a/lib/Service/CardService.php +++ b/lib/Service/CardService.php @@ -29,6 +29,7 @@ use OCA\Deck\Db\CardMapper; use OCA\Deck\Db\Acl; use OCA\Deck\Db\StackMapper; +use OCA\Deck\Notification\NotificationHelper; use OCA\Deck\NotFoundException; use OCA\Deck\StatusException; @@ -39,14 +40,16 @@ class CardService { private $stackMapper; private $permissionService; private $boardService; + private $notificationHelper; private $assignedUsersMapper; private $attachmentService; - public function __construct(CardMapper $cardMapper, StackMapper $stackMapper, PermissionService $permissionService, BoardService $boardService, AssignedUsersMapper $assignedUsersMapper, AttachmentService $attachmentService) { + public function __construct(CardMapper $cardMapper, StackMapper $stackMapper, PermissionService $permissionService, BoardService $boardService, NotificationHelper $notificationHelper, AssignedUsersMapper $assignedUsersMapper, AttachmentService $attachmentService) { $this->cardMapper = $cardMapper; $this->stackMapper = $stackMapper; $this->permissionService = $permissionService; $this->boardService = $boardService; + $this->notificationHelper = $notificationHelper; $this->assignedUsersMapper = $assignedUsersMapper; $this->attachmentService = $attachmentService; } @@ -202,6 +205,11 @@ public function assignUser($cardId, $userId) { return false; } } + + /* Notify user about the card assignment */ + $card = $this->cardMapper->find($cardId); + $this->notificationHelper->sendCardAssigned($card, $userId); + $assignment = new AssignedUsers(); $assignment->setCardId($cardId); $assignment->setParticipant($userId); From 327c379ff3182e82ba02baed1fa7b5eadbe317ad Mon Sep 17 00:00:00 2001 From: Steav Date: Mon, 23 Jul 2018 19:53:57 +0200 Subject: [PATCH 2/8] Undo manual changes to l10n files Signed-off-by: Steav --- l10n/de.js | 1 - l10n/de.json | 1 - l10n/de_DE.js | 1 - l10n/de_DE.json | 1 - 4 files changed, 4 deletions(-) diff --git a/l10n/de.js b/l10n/de.js index 93f055742..efc1010ce 100644 --- a/l10n/de.js +++ b/l10n/de.js @@ -10,7 +10,6 @@ OC.L10N.register( "Are you sure you want to delete the stack with all of its data?" : "Möchtest du diesen Stapel mit allen Daten wirklich löschen?", "Personal" : "Persönlich", "The card \"%s\" on \"%s\" has reached its due date." : "Die Karte \"%s\" auf \"%s\" ist überfällig.", - "The card \"%s\" on \"%s\" has been assigned to you by %s." : "Die Karte \"%s\" wurde Dir auf \"%s\" von %s zugewiesen.", "The board \"%s\" has been shared with you by %s." : "Das Board \"%s\" wurde von %s mit Dir geteilt.", "{user} has shared the board %s with you." : "{user} hat das Board %s mit Dir geteilt.", "No data was provided to create an attachment." : "Es wurde keine Daten zum Erstellen eines Anhangs bereitgestellt.", diff --git a/l10n/de.json b/l10n/de.json index 5b19f15cc..95c7a2b55 100644 --- a/l10n/de.json +++ b/l10n/de.json @@ -8,7 +8,6 @@ "Are you sure you want to delete the stack with all of its data?" : "Möchtest du diesen Stapel mit allen Daten wirklich löschen?", "Personal" : "Persönlich", "The card \"%s\" on \"%s\" has reached its due date." : "Die Karte \"%s\" auf \"%s\" ist überfällig.", - "The card \"%s\" on \"%s\" has been assigned to you by %s." : "Die Karte \"%s\" wurde Dir auf \"%s\" von %s zugewiesen.", "The board \"%s\" has been shared with you by %s." : "Das Board \"%s\" wurde von %s mit Dir geteilt.", "{user} has shared the board %s with you." : "{user} hat das Board %s mit Dir geteilt.", "No data was provided to create an attachment." : "Es wurde keine Daten zum Erstellen eines Anhangs bereitgestellt.", diff --git a/l10n/de_DE.js b/l10n/de_DE.js index 86dec14bf..1ee8a819c 100644 --- a/l10n/de_DE.js +++ b/l10n/de_DE.js @@ -10,7 +10,6 @@ OC.L10N.register( "Are you sure you want to delete the stack with all of its data?" : "Möchten Sie diesen Stapel mit allen Daten wirklich löschen?", "Personal" : "Persönlich", "The card \"%s\" on \"%s\" has reached its due date." : "Die Karte \"%s\" auf \"%s\" ist überfällig.", - "The card \"%s\" on \"%s\" has been assigned to you by %s." : "Die Karte \"%s\" wurde Ihnen auf \"%s\" von %s zugewiesen.", "The board \"%s\" has been shared with you by %s." : "Das Board \"%s\" wurde von %s mit Ihnen geteilt.", "{user} has shared the board %s with you." : "{user} hat das Board %s mit Ihnen geteilt.", "No data was provided to create an attachment." : "Es wurde keine Daten zum Erstellen eines Anhangs bereitgestellt.", diff --git a/l10n/de_DE.json b/l10n/de_DE.json index a4c808953..b565c2a4c 100644 --- a/l10n/de_DE.json +++ b/l10n/de_DE.json @@ -9,7 +9,6 @@ "Personal" : "Persönlich", "The card \"%s\" on \"%s\" has reached its due date." : "Die Karte \"%s\" auf \"%s\" ist überfällig.", "The board \"%s\" has been shared with you by %s." : "Das Board \"%s\" wurde von %s mit Ihnen geteilt.", - "The card \"%s\" on \"%s\" has been assigned to you by %s." : "Die Karte \"%s\" wurde Ihnen auf \"%s\" von %s zugewiesen.", "{user} has shared the board %s with you." : "{user} hat das Board %s mit Ihnen geteilt.", "No data was provided to create an attachment." : "Es wurde keine Daten zum Erstellen eines Anhangs bereitgestellt.", "Finished" : "Abgeschlossen", From ed62a48ddd9ecfe7e7287f025c4aaa3a96d047f8 Mon Sep 17 00:00:00 2001 From: Steav Date: Mon, 23 Jul 2018 19:55:38 +0200 Subject: [PATCH 3/8] Add richsubject to notification on user assignment Signed-off-by: Steav --- lib/Notification/Notifier.php | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/lib/Notification/Notifier.php b/lib/Notification/Notifier.php index 84ac2c5c9..fd54fe88b 100644 --- a/lib/Notification/Notifier.php +++ b/lib/Notification/Notifier.php @@ -78,10 +78,22 @@ public function prepare(INotification $notification, $languageCode) { $boardId = $this->cardMapper->findBoardId($cardId); $initiator = $this->userManager->get($params[2]); if ($initiator !== null) { - $params[2] = $initiator->getDisplayName(); + $dn = $initiator->getDisplayName(); + } else { + $dn = $params[2]; } $notification->setParsedSubject( - (string) $l->t('The card "%s" on "%s" has been assigned to you by %s.', $params) + (string) $l->t('The card "%s" on "%s" has been assigned to you by %s.', [$params[0], $params[1], $dn]) + ); + $notification->setRichSubject( + (string) $l->t('{user} has assigned the card "%s" on "%s" to you.', [$params[0], $params[1]]), + [ + 'user' => [ + 'type' => 'user', + 'id' => $params[2], + 'name' => $dn, + ] + ] ); $notification->setLink($this->url->linkToRouteAbsolute('deck.page.index') . '#!/board/' . $boardId . '//card/' . $cardId . ''); break; From 1276dddc37384c4738f9456364365ed16c2e4dfa Mon Sep 17 00:00:00 2001 From: steav Date: Mon, 23 Jul 2018 23:45:56 +0200 Subject: [PATCH 4/8] Fix failing CardServiceTest Signed-off-by: steav --- tests/unit/Service/CardServiceTest.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/unit/Service/CardServiceTest.php b/tests/unit/Service/CardServiceTest.php index 0822bab3d..95de77e50 100644 --- a/tests/unit/Service/CardServiceTest.php +++ b/tests/unit/Service/CardServiceTest.php @@ -43,6 +43,8 @@ class CardServiceTest extends TestCase { private $stackMapper; /** @var PermissionService|\PHPUnit\Framework\MockObject\MockObject */ private $permissionService; + /** @var NotificationHelper */ + private $notificationHelper; /** @var AssignedUsersMapper|\PHPUnit\Framework\MockObject\MockObject */ private $assignedUsersMapper; /** @var BoardService|\PHPUnit\Framework\MockObject\MockObject */ @@ -54,9 +56,10 @@ public function setUp() { $this->stackMapper = $this->createMock(StackMapper::class); $this->permissionService = $this->createMock(PermissionService::class); $this->boardService = $this->createMock(BoardService::class); + $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->assignedUsersMapper, $this->attachmentService); + $this->cardService = new CardService($this->cardMapper, $this->stackMapper, $this->permissionService, $this->boardService, $this->notificationHelper, $this->assignedUsersMapper, $this->attachmentService); } public function testFind() { From fdc1f275c53ae71b38a9cd5e265cd1ec1fa98364 Mon Sep 17 00:00:00 2001 From: steav Date: Wed, 25 Jul 2018 23:20:09 +0200 Subject: [PATCH 5/8] Add tests for card assignment notification Signed-off-by: steav --- .../Notification/NotificationHelperTest.php | 33 +++++++++ tests/unit/Notification/NotifierTest.php | 71 +++++++++++++++++++ tests/unit/Service/CardServiceTest.php | 2 +- 3 files changed, 105 insertions(+), 1 deletion(-) 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 @@ public function testSendCardDuedate() { $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 @@ public function testPrepareCardOverdue() { } + 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 @@ public function setUp() { $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() { From 9595e00ae115ace59a48c1dc0b81410e8db659a8 Mon Sep 17 00:00:00 2001 From: steav Date: Wed, 25 Jul 2018 23:21:29 +0200 Subject: [PATCH 6/8] Do not send card assignment notifications to ourselves Signed-off-by: steav --- lib/Service/CardService.php | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/lib/Service/CardService.php b/lib/Service/CardService.php index 83188de0b..a9b7ae7a2 100644 --- a/lib/Service/CardService.php +++ b/lib/Service/CardService.php @@ -43,8 +43,9 @@ class CardService { private $notificationHelper; private $assignedUsersMapper; private $attachmentService; + private $currentUser; - public function __construct(CardMapper $cardMapper, StackMapper $stackMapper, PermissionService $permissionService, BoardService $boardService, NotificationHelper $notificationHelper, AssignedUsersMapper $assignedUsersMapper, AttachmentService $attachmentService) { + public function __construct(CardMapper $cardMapper, StackMapper $stackMapper, PermissionService $permissionService, BoardService $boardService, NotificationHelper $notificationHelper, AssignedUsersMapper $assignedUsersMapper, AttachmentService $attachmentService, $userId) { $this->cardMapper = $cardMapper; $this->stackMapper = $stackMapper; $this->permissionService = $permissionService; @@ -52,6 +53,7 @@ public function __construct(CardMapper $cardMapper, StackMapper $stackMapper, Pe $this->notificationHelper = $notificationHelper; $this->assignedUsersMapper = $assignedUsersMapper; $this->attachmentService = $attachmentService; + $this->currentUser = $userId; } public function find($cardId) { @@ -206,9 +208,11 @@ public function assignUser($cardId, $userId) { } } - /* Notify user about the card assignment */ - $card = $this->cardMapper->find($cardId); - $this->notificationHelper->sendCardAssigned($card, $userId); + if ($userId !== $this->currentUser) { + /* Notifyuser about the card assignment */ + $card = $this->cardMapper->find($cardId); + $this->notificationHelper->sendCardAssigned($card, $userId); + } $assignment = new AssignedUsers(); $assignment->setCardId($cardId); From 476b15ee9d22e68b3580a1f12b8d479898ee1cf2 Mon Sep 17 00:00:00 2001 From: steav Date: Wed, 25 Jul 2018 23:44:31 +0200 Subject: [PATCH 7/8] Fix tests for card assignment notification Signed-off-by: steav --- .../Notification/NotificationHelperTest.php | 24 +++++++++++++------ 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/tests/unit/Notification/NotificationHelperTest.php b/tests/unit/Notification/NotificationHelperTest.php index ba6958345..c9c11bc70 100644 --- a/tests/unit/Notification/NotificationHelperTest.php +++ b/tests/unit/Notification/NotificationHelperTest.php @@ -188,23 +188,33 @@ public function testSendCardAssignedUser() { $board = new Board(); $board->setId(123); $board->setTitle('MyBoardTitle'); + $this->boardMapper->expects($this->once()) + ->method('find') + ->with(123) + ->willReturn($board); + $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']); + $card->setOwner('admin'); + $card->setStackId(123); + $card->setOrder(999); + $card->setType('text'); + $card->setId(1337); + $card->setAssignedUsers(['userA']); + $this->cardMapper->expects($this->once()) + ->method('findBoardId') + ->with(1337) + ->willReturn(123); $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('setSubject')->with('card-assigned', ['MyCardTitle', 'MyBoardTitle', 'admin'])->willReturn($notification); $notification->expects($this->once())->method('setDateTime')->willReturn($notification); $this->notificationManager->expects($this->at(0)) From 1948c303f2dd6cf71d36c4fbab1edab17b53e899 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julius=20H=C3=A4rtl?= Date: Sat, 28 Jul 2018 12:25:23 +0200 Subject: [PATCH 8/8] Add missing import statement MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Julius Härtl --- tests/unit/Service/CardServiceTest.php | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/unit/Service/CardServiceTest.php b/tests/unit/Service/CardServiceTest.php index df87f4ece..0f850c006 100644 --- a/tests/unit/Service/CardServiceTest.php +++ b/tests/unit/Service/CardServiceTest.php @@ -30,6 +30,7 @@ use OCA\Deck\Db\CardMapper; use OCA\Deck\Db\StackMapper; use OCA\Deck\NotFoundException; +use OCA\Deck\Notification\NotificationHelper; use OCA\Deck\StatusException; use Test\TestCase;