Skip to content

Commit 17fff4e

Browse files
committed
Revert "test: bulk activity unit tests"
This reverts commit 3183d84.
1 parent 3183d84 commit 17fff4e

2 files changed

Lines changed: 0 additions & 272 deletions

File tree

tests/ConsumerTest.php

Lines changed: 0 additions & 210 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
use OCP\Activity\ActivitySettings;
3232
use OCP\Activity\IEvent;
3333
use OCP\Activity\IManager;
34-
use OCP\Activity\ISetting;
3534
use OCP\Config\IUserConfig;
3635
use OCP\IDBConnection;
3736
use OCP\IL10N;
@@ -264,213 +263,4 @@ public function testBulkReceiveNotification(string $type, string $author, string
264263
$this->consumer->bulkReceive($this->event, $affectedUsers, $settings);
265264
}
266265

267-
public function testBulkReceiveEmail(): void {
268-
$time = time();
269-
$this->event->setApp('activity')
270-
->setType('type')
271-
->setAuthor('author')
272-
->setTimestamp($time)
273-
->setSubject('subject', ['subjectParam1'])
274-
->setMessage('message', ['messageParam1'])
275-
->setObject('', 0, 'file')
276-
->setLink('link');
277-
278-
$settings = $this->createMock(ActivitySettings::class);
279-
$settings->method('canChangeMail')->willReturn(true);
280-
$settings->method('isDefaultEnabledMail')->willReturn(true);
281-
$settings->method('canChangeNotification')->willReturn(false);
282-
283-
$this->data->expects($this->once())
284-
->method('bulkSend')
285-
->willReturn([1 => 'affectedUser', 2 => 'affectedUser2']);
286-
287-
$this->userConfig->method('getValuesByUsers')
288-
->willReturnCallback(function (string $app, string $key, mixed $type, array $users): array {
289-
if (str_contains($key, 'email')) {
290-
return array_fill_keys($users, true);
291-
}
292-
if (str_contains($key, 'batchtime')) {
293-
return array_fill_keys($users, 10);
294-
}
295-
return [];
296-
});
297-
298-
$this->data->expects($this->exactly(2))
299-
->method('storeMail');
300-
301-
$this->consumer->bulkReceive($this->event, ['affectedUser', 'affectedUser2'], $settings);
302-
}
303-
304-
public function testBulkReceiveNoMailWhenSettingDisabled(): void {
305-
$this->event->setApp('activity')
306-
->setType('type')
307-
->setAuthor('author')
308-
->setTimestamp(time())
309-
->setSubject('subject', ['subjectParam1'])
310-
->setMessage('message', ['messageParam1'])
311-
->setObject('', 0, 'file')
312-
->setLink('link');
313-
314-
$settings = $this->createMock(ActivitySettings::class);
315-
$settings->method('canChangeMail')->willReturn(false);
316-
$settings->method('isDefaultEnabledMail')->willReturn(false);
317-
$settings->method('canChangeNotification')->willReturn(false);
318-
319-
$this->data->expects($this->once())
320-
->method('bulkSend')
321-
->willReturn([1 => 'affectedUser']);
322-
323-
$this->data->expects($this->never())
324-
->method('storeMail');
325-
// Notification is still sent because $notificationSetting defaults to null
326-
// and null !== false, so the default is to send notifications
327-
$this->notificationGenerator->expects($this->once())
328-
->method('sendNotificationForEvent');
329-
330-
$this->consumer->bulkReceive($this->event, ['affectedUser'], $settings);
331-
}
332-
333-
public function testBulkReceiveDeferAndFlushNotifications(): void {
334-
$this->event->setApp('activity')
335-
->setType('type')
336-
->setAuthor('author')
337-
->setTimestamp(time())
338-
->setSubject('subject', ['subjectParam1'])
339-
->setMessage('message', ['messageParam1'])
340-
->setObject('', 0, 'file')
341-
->setLink('link');
342-
343-
$settings = $this->createMock(ActivitySettings::class);
344-
$settings->method('canChangeMail')->willReturn(false);
345-
$settings->method('isDefaultEnabledMail')->willReturn(false);
346-
$settings->method('canChangeNotification')->willReturn(true);
347-
348-
$this->data->expects($this->once())
349-
->method('bulkSend')
350-
->willReturn([1 => 'affectedUser']);
351-
352-
$this->userConfig->method('getValuesByUsers')
353-
->willReturnCallback(function (string $app, string $key, mixed $type, array $users): array {
354-
return array_fill_keys($users, true);
355-
});
356-
357-
$this->notificationGenerator->expects($this->once())
358-
->method('deferNotifications')
359-
->willReturn(true);
360-
$this->notificationGenerator->expects($this->once())
361-
->method('flushNotifications');
362-
$this->notificationGenerator->expects($this->once())
363-
->method('sendNotificationForEvent');
364-
365-
$this->consumer->bulkReceive($this->event, ['affectedUser'], $settings);
366-
}
367-
368-
public function testBulkReceiveNoFlushWhenDeferReturnsFalse(): void {
369-
$this->event->setApp('activity')
370-
->setType('type')
371-
->setAuthor('author')
372-
->setTimestamp(time())
373-
->setSubject('subject', ['subjectParam1'])
374-
->setMessage('message', ['messageParam1'])
375-
->setObject('', 0, 'file')
376-
->setLink('link');
377-
378-
$settings = $this->createMock(ActivitySettings::class);
379-
$settings->method('canChangeMail')->willReturn(false);
380-
$settings->method('isDefaultEnabledMail')->willReturn(false);
381-
$settings->method('canChangeNotification')->willReturn(true);
382-
383-
$this->data->expects($this->once())
384-
->method('bulkSend')
385-
->willReturn([1 => 'affectedUser']);
386-
387-
$this->userConfig->method('getValuesByUsers')
388-
->willReturnCallback(function (string $app, string $key, mixed $type, array $users): array {
389-
return array_fill_keys($users, true);
390-
});
391-
392-
$this->notificationGenerator->expects($this->once())
393-
->method('deferNotifications')
394-
->willReturn(false);
395-
$this->notificationGenerator->expects($this->never())
396-
->method('flushNotifications');
397-
398-
$this->consumer->bulkReceive($this->event, ['affectedUser'], $settings);
399-
}
400-
401-
public function testBulkReceiveMultipleUsersWithMixedSettings(): void {
402-
$time = time();
403-
$this->event->setApp('activity')
404-
->setType('type')
405-
->setAuthor('author')
406-
->setTimestamp($time)
407-
->setSubject('subject', ['subjectParam1'])
408-
->setMessage('message', ['messageParam1'])
409-
->setObject('', 0, 'file')
410-
->setLink('link');
411-
412-
$settings = $this->createMock(ActivitySettings::class);
413-
$settings->method('canChangeMail')->willReturn(true);
414-
$settings->method('isDefaultEnabledMail')->willReturn(true);
415-
$settings->method('canChangeNotification')->willReturn(true);
416-
417-
$this->data->expects($this->once())
418-
->method('bulkSend')
419-
->willReturn([1 => 'user1', 2 => 'user2', 3 => 'author']);
420-
421-
$this->userConfig->method('getValuesByUsers')
422-
->willReturnCallback(function (string $app, string $key, mixed $type, array $users): array {
423-
if (str_contains($key, 'notification')) {
424-
// Only user1 has notifications enabled
425-
return ['user1' => true];
426-
}
427-
if (str_contains($key, 'email')) {
428-
// Only user2 has email enabled
429-
return ['user2' => true];
430-
}
431-
if (str_contains($key, 'batchtime')) {
432-
return ['user2' => 15];
433-
}
434-
return [];
435-
});
436-
437-
// user1 and user2 get notifications (user2 has null setting which defaults to send), author is skipped
438-
$this->notificationGenerator->expects($this->exactly(2))
439-
->method('sendNotificationForEvent');
440-
// user2 gets email, author is skipped
441-
$this->data->expects($this->once())
442-
->method('storeMail')
443-
->with($this->event, $time + 15);
444-
445-
$this->consumer->bulkReceive($this->event, ['user1', 'user2', 'author'], $settings);
446-
}
447-
448-
public function testBulkReceiveWithISetting(): void {
449-
$this->event->setApp('activity')
450-
->setType('type')
451-
->setAuthor('author')
452-
->setTimestamp(time())
453-
->setSubject('subject', ['subjectParam1'])
454-
->setMessage('message', ['messageParam1'])
455-
->setObject('', 0, 'file')
456-
->setLink('link');
457-
458-
// ISetting (not ActivitySettings) — canChangeNotification is not available
459-
$settings = $this->createMock(ISetting::class);
460-
$settings->method('canChangeMail')->willReturn(false);
461-
462-
$this->data->expects($this->once())
463-
->method('bulkSend')
464-
->willReturn([1 => 'affectedUser']);
465-
466-
// Notification is still sent because $notificationSetting defaults to null (not false)
467-
// when ISetting is used (canChangeNotification not available), and null !== false
468-
$this->notificationGenerator->expects($this->once())
469-
->method('sendNotificationForEvent');
470-
$this->data->expects($this->never())
471-
->method('storeMail');
472-
473-
$this->consumer->bulkReceive($this->event, ['affectedUser'], $settings);
474-
}
475-
476266
}

tests/DataTest.php

Lines changed: 0 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -154,68 +154,6 @@ public function testStoreMail(string $actionUser, string $affectedUser, string $
154154
$this->deleteTestMails();
155155
}
156156

157-
public function testBulkSend(): void {
158-
$this->deleteTestActivities();
159-
160-
$event = $this->realActivityManager->generateEvent();
161-
$event->setApp('test')
162-
->setType('type')
163-
->setAuthor('author')
164-
->setTimestamp(time())
165-
->setSubject('subject', ['param1'])
166-
->setMessage('message', ['msgParam1'])
167-
->setObject('files', 42, 'file.txt')
168-
->setLink('https://example.com');
169-
170-
$affectedUsers = ['user1', 'user2', 'user3'];
171-
$activityIds = $this->data->bulkSend($event, $affectedUsers);
172-
173-
$this->assertCount(3, $activityIds);
174-
// Values should be the affected user strings
175-
$this->assertEqualsCanonicalizing($affectedUsers, array_values($activityIds));
176-
// Keys should be positive integer IDs
177-
foreach (array_keys($activityIds) as $id) {
178-
$this->assertGreaterThan(0, $id);
179-
}
180-
181-
// Verify rows in DB
182-
$qb = $this->dbConnection->getQueryBuilder();
183-
$query = $qb->select('user', 'affecteduser', 'app', 'subject', 'object_type', 'object_id')
184-
->from('activity')
185-
->where($qb->expr()->eq('app', $qb->createNamedParameter('test')))
186-
->orderBy('activity_id', 'ASC');
187-
$result = $query->executeQuery();
188-
$rows = $result->fetchAll();
189-
190-
$this->assertCount(3, $rows);
191-
foreach ($rows as $i => $row) {
192-
$this->assertSame('author', $row['user']);
193-
$this->assertSame($affectedUsers[$i], $row['affecteduser']);
194-
$this->assertSame('test', $row['app']);
195-
$this->assertSame('subject', $row['subject']);
196-
$this->assertSame('files', $row['object_type']);
197-
$this->assertEquals(42, $row['object_id']);
198-
}
199-
200-
$this->deleteTestActivities();
201-
}
202-
203-
public function testBulkSendEmptyUsers(): void {
204-
$this->deleteTestActivities();
205-
206-
$event = $this->realActivityManager->generateEvent();
207-
$event->setApp('test')
208-
->setType('type')
209-
->setAuthor('author')
210-
->setTimestamp(time())
211-
->setSubject('subject');
212-
213-
$activityIds = $this->data->bulkSend($event, []);
214-
$this->assertEmpty($activityIds);
215-
216-
$this->deleteTestActivities();
217-
}
218-
219157
public static function dataSetOffsetFromSince(): array {
220158
return [
221159
['ASC', '`timestamp` >= \'123465789\'', '`activity_id` > \'{id}\'', null, null, null],

0 commit comments

Comments
 (0)