|
41 | 41 | use OCP\Notification\INotification; |
42 | 42 | use PHPUnit\Framework\MockObject\MockObject; |
43 | 43 |
|
| 44 | +class DummyUser extends \OC\User\User { |
| 45 | + |
| 46 | + private $uid; |
| 47 | + |
| 48 | + public function __construct($uid) { |
| 49 | + $this->uid = $uid; |
| 50 | + } |
| 51 | + |
| 52 | + public function getUID() { |
| 53 | + return $this->uid; |
| 54 | + } |
| 55 | +} |
| 56 | + |
44 | 57 | class NotificationHelperTest extends \Test\TestCase { |
45 | 58 |
|
46 | 59 | /** @var CardMapper|MockObject */ |
@@ -115,34 +128,19 @@ public function testSendCardDuedate() { |
115 | 128 | ->with('asd', 'deck', 'board:234:notify-due', ConfigService::SETTING_BOARD_NOTIFICATION_DUE_ASSIGNED) |
116 | 129 | ->willReturn(ConfigService::SETTING_BOARD_NOTIFICATION_DUE_ALL); |
117 | 130 |
|
118 | | - $card = $this->createMock(Card::class); |
119 | | - $card->expects($this->at(0)) |
120 | | - ->method('__call') |
121 | | - ->with('getNotified', []) |
122 | | - ->willReturn(false); |
123 | | - $card->expects($this->at(1)) |
124 | | - ->method('__call') |
125 | | - ->with('getId', []) |
126 | | - ->willReturn(123); |
127 | | - for ($i=0; $i<3; $i++) { |
128 | | - $card->expects($this->at($i*3+2)) |
129 | | - ->method('__call') |
130 | | - ->with('getId', []) |
131 | | - ->willReturn(123); |
132 | | - $card->expects($this->at($i*3+3)) |
133 | | - ->method('__call', []) |
134 | | - ->with('getTitle') |
135 | | - ->willReturn('MyCardTitle'); |
136 | | - } |
| 131 | + $card = Card::fromParams([ |
| 132 | + 'notified' => false, |
| 133 | + 'id' => 123, |
| 134 | + 'title' => 'MyCardTitle' |
| 135 | + ]); |
137 | 136 | $this->cardMapper->expects($this->once()) |
138 | 137 | ->method('findBoardId') |
139 | 138 | ->with(123) |
140 | 139 | ->willReturn(234); |
141 | | - $board = $this->createMock(Board::class); |
142 | | - $board->expects($this->any()) |
143 | | - ->method('__call') |
144 | | - ->with('getTitle', []) |
145 | | - ->willReturn('MyBoardTitle'); |
| 140 | + $board = Board::fromParams([ |
| 141 | + 'id' => 123, |
| 142 | + 'title' => 'MyBoardTitle' |
| 143 | + ]); |
146 | 144 | $this->boardMapper->expects($this->once()) |
147 | 145 | ->method('find') |
148 | 146 | ->with(234) |
@@ -208,6 +206,188 @@ public function testSendCardDuedate() { |
208 | 206 | $this->notificationHelper->sendCardDuedate($card); |
209 | 207 | } |
210 | 208 |
|
| 209 | + public function testSendCardDuedateAssigned() { |
| 210 | + $this->config->expects($this->at(0)) |
| 211 | + ->method('getUserValue') |
| 212 | + ->with('foo', 'deck', 'board:234:notify-due', ConfigService::SETTING_BOARD_NOTIFICATION_DUE_ASSIGNED) |
| 213 | + ->willReturn(ConfigService::SETTING_BOARD_NOTIFICATION_DUE_ASSIGNED); |
| 214 | + $this->config->expects($this->at(1)) |
| 215 | + ->method('getUserValue') |
| 216 | + ->with('bar', 'deck', 'board:234:notify-due', ConfigService::SETTING_BOARD_NOTIFICATION_DUE_ASSIGNED) |
| 217 | + ->willReturn(ConfigService::SETTING_BOARD_NOTIFICATION_DUE_ASSIGNED); |
| 218 | + $this->config->expects($this->at(2)) |
| 219 | + ->method('getUserValue') |
| 220 | + ->with('asd', 'deck', 'board:234:notify-due', ConfigService::SETTING_BOARD_NOTIFICATION_DUE_ASSIGNED) |
| 221 | + ->willReturn(ConfigService::SETTING_BOARD_NOTIFICATION_DUE_ASSIGNED); |
| 222 | + |
| 223 | + $users = [ |
| 224 | + new DummyUser('foo'), new DummyUser('bar'), new DummyUser('asd') |
| 225 | + ]; |
| 226 | + $card = Card::fromParams([ |
| 227 | + 'notified' => false, |
| 228 | + 'id' => 123, |
| 229 | + 'title' => 'MyCardTitle' |
| 230 | + ]); |
| 231 | + $card->setAssignedUsers([ |
| 232 | + new User($users[0]) |
| 233 | + ]); |
| 234 | + $this->cardMapper->expects($this->once()) |
| 235 | + ->method('findBoardId') |
| 236 | + ->with(123) |
| 237 | + ->willReturn(234); |
| 238 | + $board = Board::fromParams([ |
| 239 | + 'id' => 123, |
| 240 | + 'title' => 'MyBoardTitle' |
| 241 | + ]); |
| 242 | + $this->boardMapper->expects($this->once()) |
| 243 | + ->method('find') |
| 244 | + ->with(234) |
| 245 | + ->willReturn($board); |
| 246 | + |
| 247 | + |
| 248 | + $this->permissionService->expects($this->once()) |
| 249 | + ->method('findUsers') |
| 250 | + ->with(234) |
| 251 | + ->willReturn($users); |
| 252 | + |
| 253 | + $this->assignedUsersMapper->expects($this->exactly(3)) |
| 254 | + ->method('isUserAssigned') |
| 255 | + ->willReturn(true); |
| 256 | + |
| 257 | + |
| 258 | + $n1 = $this->createMock(INotification::class); |
| 259 | + $n2 = $this->createMock(INotification::class); |
| 260 | + $n3 = $this->createMock(INotification::class); |
| 261 | + |
| 262 | + $n1->expects($this->once())->method('setApp')->with('deck')->willReturn($n1); |
| 263 | + $n1->expects($this->once())->method('setUser')->with('foo')->willReturn($n1); |
| 264 | + $n1->expects($this->once())->method('setObject')->with('card', 123)->willReturn($n1); |
| 265 | + $n1->expects($this->once())->method('setSubject')->with('card-overdue', ['MyCardTitle', 'MyBoardTitle'])->willReturn($n1); |
| 266 | + $n1->expects($this->once())->method('setDateTime')->willReturn($n1); |
| 267 | + |
| 268 | + $n2->expects($this->once())->method('setApp')->with('deck')->willReturn($n2); |
| 269 | + $n2->expects($this->once())->method('setUser')->with('bar')->willReturn($n2); |
| 270 | + $n2->expects($this->once())->method('setObject')->with('card', 123)->willReturn($n2); |
| 271 | + $n2->expects($this->once())->method('setSubject')->with('card-overdue', ['MyCardTitle', 'MyBoardTitle'])->willReturn($n2); |
| 272 | + $n2->expects($this->once())->method('setDateTime')->willReturn($n2); |
| 273 | + |
| 274 | + $n3->expects($this->once())->method('setApp')->with('deck')->willReturn($n3); |
| 275 | + $n3->expects($this->once())->method('setUser')->with('asd')->willReturn($n3); |
| 276 | + $n3->expects($this->once())->method('setObject')->with('card', 123)->willReturn($n3); |
| 277 | + $n3->expects($this->once())->method('setSubject')->with('card-overdue', ['MyCardTitle', 'MyBoardTitle'])->willReturn($n3); |
| 278 | + $n3->expects($this->once())->method('setDateTime')->willReturn($n3); |
| 279 | + |
| 280 | + $this->notificationManager->expects($this->at(0)) |
| 281 | + ->method('createNotification') |
| 282 | + ->willReturn($n1); |
| 283 | + $this->notificationManager->expects($this->at(1)) |
| 284 | + ->method('notify') |
| 285 | + ->with($n1); |
| 286 | + $this->notificationManager->expects($this->at(2)) |
| 287 | + ->method('createNotification') |
| 288 | + ->willReturn($n2); |
| 289 | + $this->notificationManager->expects($this->at(3)) |
| 290 | + ->method('notify') |
| 291 | + ->with($n2); |
| 292 | + $this->notificationManager->expects($this->at(4)) |
| 293 | + ->method('createNotification') |
| 294 | + ->willReturn($n3); |
| 295 | + $this->notificationManager->expects($this->at(5)) |
| 296 | + ->method('notify') |
| 297 | + ->with($n3); |
| 298 | + |
| 299 | + $this->cardMapper->expects($this->once()) |
| 300 | + ->method('markNotified') |
| 301 | + ->with($card); |
| 302 | + |
| 303 | + $this->notificationHelper->sendCardDuedate($card); |
| 304 | + } |
| 305 | + |
| 306 | + |
| 307 | + public function testSendCardDuedateNever() { |
| 308 | + $this->config->expects($this->at(0)) |
| 309 | + ->method('getUserValue') |
| 310 | + ->with('foo', 'deck', 'board:234:notify-due', ConfigService::SETTING_BOARD_NOTIFICATION_DUE_ASSIGNED) |
| 311 | + ->willReturn(ConfigService::SETTING_BOARD_NOTIFICATION_DUE_ASSIGNED); |
| 312 | + $this->config->expects($this->at(1)) |
| 313 | + ->method('getUserValue') |
| 314 | + ->with('bar', 'deck', 'board:234:notify-due', ConfigService::SETTING_BOARD_NOTIFICATION_DUE_ASSIGNED) |
| 315 | + ->willReturn(ConfigService::SETTING_BOARD_NOTIFICATION_DUE_ASSIGNED); |
| 316 | + $this->config->expects($this->at(2)) |
| 317 | + ->method('getUserValue') |
| 318 | + ->with('asd', 'deck', 'board:234:notify-due', ConfigService::SETTING_BOARD_NOTIFICATION_DUE_ASSIGNED) |
| 319 | + ->willReturn(ConfigService::SETTING_BOARD_NOTIFICATION_DUE_OFF); |
| 320 | + |
| 321 | + $users = [ |
| 322 | + new DummyUser('foo'), new DummyUser('bar'), new DummyUser('asd') |
| 323 | + ]; |
| 324 | + $card = Card::fromParams([ |
| 325 | + 'notified' => false, |
| 326 | + 'id' => 123, |
| 327 | + 'title' => 'MyCardTitle' |
| 328 | + ]); |
| 329 | + $card->setAssignedUsers([ |
| 330 | + new User($users[0]) |
| 331 | + ]); |
| 332 | + $this->cardMapper->expects($this->once()) |
| 333 | + ->method('findBoardId') |
| 334 | + ->with(123) |
| 335 | + ->willReturn(234); |
| 336 | + $board = Board::fromParams([ |
| 337 | + 'id' => 123, |
| 338 | + 'title' => 'MyBoardTitle' |
| 339 | + ]); |
| 340 | + $this->boardMapper->expects($this->once()) |
| 341 | + ->method('find') |
| 342 | + ->with(234) |
| 343 | + ->willReturn($board); |
| 344 | + |
| 345 | + |
| 346 | + $this->permissionService->expects($this->once()) |
| 347 | + ->method('findUsers') |
| 348 | + ->with(234) |
| 349 | + ->willReturn($users); |
| 350 | + |
| 351 | + $this->assignedUsersMapper->expects($this->exactly(2)) |
| 352 | + ->method('isUserAssigned') |
| 353 | + ->willReturn(true); |
| 354 | + |
| 355 | + |
| 356 | + $n1 = $this->createMock(INotification::class); |
| 357 | + $n2 = $this->createMock(INotification::class); |
| 358 | + |
| 359 | + $n1->expects($this->once())->method('setApp')->with('deck')->willReturn($n1); |
| 360 | + $n1->expects($this->once())->method('setUser')->with('foo')->willReturn($n1); |
| 361 | + $n1->expects($this->once())->method('setObject')->with('card', 123)->willReturn($n1); |
| 362 | + $n1->expects($this->once())->method('setSubject')->with('card-overdue', ['MyCardTitle', 'MyBoardTitle'])->willReturn($n1); |
| 363 | + $n1->expects($this->once())->method('setDateTime')->willReturn($n1); |
| 364 | + |
| 365 | + $n2->expects($this->once())->method('setApp')->with('deck')->willReturn($n2); |
| 366 | + $n2->expects($this->once())->method('setUser')->with('bar')->willReturn($n2); |
| 367 | + $n2->expects($this->once())->method('setObject')->with('card', 123)->willReturn($n2); |
| 368 | + $n2->expects($this->once())->method('setSubject')->with('card-overdue', ['MyCardTitle', 'MyBoardTitle'])->willReturn($n2); |
| 369 | + $n2->expects($this->once())->method('setDateTime')->willReturn($n2); |
| 370 | + |
| 371 | + $this->notificationManager->expects($this->at(0)) |
| 372 | + ->method('createNotification') |
| 373 | + ->willReturn($n1); |
| 374 | + $this->notificationManager->expects($this->at(1)) |
| 375 | + ->method('notify') |
| 376 | + ->with($n1); |
| 377 | + $this->notificationManager->expects($this->at(2)) |
| 378 | + ->method('createNotification') |
| 379 | + ->willReturn($n2); |
| 380 | + $this->notificationManager->expects($this->at(3)) |
| 381 | + ->method('notify') |
| 382 | + ->with($n2); |
| 383 | + |
| 384 | + $this->cardMapper->expects($this->once()) |
| 385 | + ->method('markNotified') |
| 386 | + ->with($card); |
| 387 | + |
| 388 | + $this->notificationHelper->sendCardDuedate($card); |
| 389 | + } |
| 390 | + |
211 | 391 | public function testSendCardAssignedUser() { |
212 | 392 | $board = new Board(); |
213 | 393 | $board->setId(123); |
|
0 commit comments