Skip to content

Commit 2712901

Browse files
committed
fix unit tests
Signed-off-by: Christian Hartmann <chris-hartmann@gmx.de>
1 parent 9168318 commit 2712901

2 files changed

Lines changed: 52 additions & 27 deletions

File tree

‎tests/Unit/Activity/ActivityManagerTest.php‎

Lines changed: 16 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -247,48 +247,38 @@ public function testPublishNewSharedSubmission(int $shareType, string $shareWith
247247
$form->setOwnerId('formOwner');
248248
$submitterId = 'submittingUser';
249249

250-
if ($shareType === IShare::TYPE_CIRCLE) {
251-
$this->circlesService->expects($this->once())
252-
->method('getCircleUsers')
253-
->with('sharedCircle')
254-
->willReturn($sharedUsers);
255-
} elseif ($shareType === IShare::TYPE_GROUP) {
256-
$users = array_map(function ($name) {
257-
$user = $this->createMock(IUser::class);
258-
$user->expects($this->once())->method('getUID')->willReturn($name);
259-
return $user;
260-
}, $sharedUsers);
261-
$group = $this->createMock(IGroup::class);
262-
$group->expects($this->once())->method('getUsers')->willReturn($users);
263-
$this->groupManager->expects($this->once())->method('get')->willReturn($group);
264-
}
265-
266250
$event = $this->createMock(IEvent::class);
267-
$this->manager->expects($this->exactly(count($expected)))
251+
$expectedCount = count($sharedUsers ?? []);
252+
253+
$this->manager->expects($this->exactly($expectedCount))
268254
->method('generateEvent')
269255
->willReturn($event);
270-
$event->expects($this->exactly(count($expected)))->method('setApp')->with('forms')->willReturn($event);
271-
$event->expects($this->exactly(count($expected)))->method('setType')->with('forms_newsharedsubmission')->willReturn($event);
272-
$event->expects($this->exactly(count($expected)))->method('setAuthor')->with('submittingUser')->willReturn($event);
273-
$event->expects($this->exactly(count($expected)))->method('setObject')->with('form', 5)->willReturn($event);
274-
$event->expects($this->exactly(count($expected)))->method('setSubject')->with('newsubmission', [
256+
$event->expects($this->exactly($expectedCount))->method('setApp')->with('forms')->willReturn($event);
257+
$event->expects($this->exactly($expectedCount))->method('setType')->with('forms_newsharedsubmission')->willReturn($event);
258+
$event->expects($this->exactly($expectedCount))->method('setAuthor')->with('submittingUser')->willReturn($event);
259+
$event->expects($this->exactly($expectedCount))->method('setObject')->with('form', 5)->willReturn($event);
260+
$event->expects($this->exactly($expectedCount))->method('setSubject')->with('newsubmission', [
275261
'userId' => 'submittingUser',
276262
'formTitle' => 'TestForm-Title',
277263
'formHash' => 'abcdefg12345'
278264
])->willReturn($event);
279265
$affectedUsers = [];
280-
$event->expects($this->exactly(count($sharedUsers)))
266+
$event->expects($this->exactly($expectedCount))
281267
->method('setAffectedUser')
282268
->willReturnCallback(function (string $userId) use (&$affectedUsers, &$event) {
283269
$affectedUsers[] = $userId;
284270
return $event;
285271
});
286272

287-
$this->manager->expects($this->exactly(count($expected)))
273+
$this->manager->expects($this->exactly($expectedCount))
288274
->method('publish')
289275
->with($event);
290276

291-
$this->activityManager->publishNewSharedSubmission($form, $shareType, $shareWith, $submitterId);
292-
$this->assertEquals($sharedUsers, $affectedUsers);
277+
// Call per-user publisher for each expected shared user (new API)
278+
foreach ($sharedUsers ?? [] as $userId) {
279+
$this->activityManager->publishNewSharedSubmission($form, $userId, $submitterId);
280+
}
281+
282+
$this->assertEquals($sharedUsers ?? [], $affectedUsers);
293283
}
294284
}

‎tests/Unit/Service/FormsServiceTest.php‎

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1165,9 +1165,26 @@ public static function dataNotifyNewSubmission() {
11651165
'shareWith' => 'user2',
11661166
'shareType' => IShare::TYPE_USER,
11671167
'permissions' => [ Constants::PERMISSION_RESULTS ]
1168-
]],
1168+
]
1169+
],
11691170
1
11701171
],
1172+
'group-share' => [
1173+
[[
1174+
'shareWith' => 'sharedGroup',
1175+
'shareType' => IShare::TYPE_GROUP,
1176+
'permissions' => [ Constants::PERMISSION_RESULTS ]
1177+
]],
1178+
2
1179+
],
1180+
'circle-share' => [
1181+
[[
1182+
'shareWith' => 'sharedCircle',
1183+
'shareType' => IShare::TYPE_CIRCLE,
1184+
'permissions' => [ Constants::PERMISSION_RESULTS ]
1185+
]],
1186+
2
1187+
],
11711188
];
11721189
}
11731190

@@ -1217,6 +1234,24 @@ public function testNotifyNewSubmission($shares, $shareNotifications) {
12171234
->method('publishNewSubmission')
12181235
->with($form, $submitter);
12191236

1237+
// If shares contain group or circle entries, mock resolution to user ids
1238+
foreach ($shares as $share) {
1239+
if (($share['shareType'] ?? null) === IShare::TYPE_GROUP) {
1240+
$sharedUsers = ['user1', 'user2'];
1241+
$users = array_map(function ($name) {
1242+
$user = $this->createMock(IUser::class);
1243+
$user->method('getUID')->willReturn($name);
1244+
return $user;
1245+
}, $sharedUsers);
1246+
$group = $this->createMock(IGroup::class);
1247+
$group->method('getUsers')->willReturn($users);
1248+
$this->groupManager->expects($this->once())->method('get')->with($share['shareWith'])->willReturn($group);
1249+
}
1250+
if (($share['shareType'] ?? null) === IShare::TYPE_CIRCLE) {
1251+
$this->circlesService->expects($this->once())->method('getCircleUsers')->with($share['shareWith'])->willReturn(['user1', 'user2']);
1252+
}
1253+
}
1254+
12201255
$this->activityManager->expects($this->exactly($shareNotifications))
12211256
->method('publishNewSharedSubmission');
12221257

0 commit comments

Comments
 (0)