forked from nextcloud/spreed
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathParticipantServiceTest.php
More file actions
131 lines (118 loc) · 4.53 KB
/
ParticipantServiceTest.php
File metadata and controls
131 lines (118 loc) · 4.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
<?php
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2022 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\Talk\Tests\php\Service;
use OCA\Talk\Config;
use OCA\Talk\Federation\BackendNotifier;
use OCA\Talk\Model\Attendee;
use OCA\Talk\Model\AttendeeMapper;
use OCA\Talk\Model\Session;
use OCA\Talk\Model\SessionMapper;
use OCA\Talk\Participant;
use OCA\Talk\Room;
use OCA\Talk\Service\MembershipService;
use OCA\Talk\Service\ParticipantService;
use OCA\Talk\Service\SessionService;
use OCP\AppFramework\Db\DoesNotExistException;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\Federation\ICloudIdManager;
use OCP\ICacheFactory;
use OCP\IConfig;
use OCP\IDBConnection;
use OCP\IGroupManager;
use OCP\IUserManager;
use OCP\Security\ISecureRandom;
use OCP\UserStatus\IManager;
use PHPUnit\Framework\MockObject\MockObject;
use Test\TestCase;
/**
* @group DB
*/
class ParticipantServiceTest extends TestCase {
protected IConfig&MockObject $serverConfig;
protected Config&MockObject $talkConfig;
protected ?AttendeeMapper $attendeeMapper = null;
protected ?SessionMapper $sessionMapper = null;
protected SessionService&MockObject $sessionService;
protected ISecureRandom&MockObject $secureRandom;
protected IEventDispatcher&MockObject $dispatcher;
protected IUserManager&MockObject $userManager;
protected ICloudIdManager&MockObject $cloudIdManager;
protected IGroupManager&MockObject $groupManager;
protected MembershipService&MockObject $membershipService;
protected BackendNotifier&MockObject $federationBackendNotifier;
protected ITimeFactory&MockObject $time;
protected ICacheFactory&MockObject $cacheFactory;
protected IManager&MockObject $userStatusManager;
private ?ParticipantService $service = null;
public function setUp(): void {
parent::setUp();
$this->serverConfig = $this->createMock(IConfig::class);
$this->talkConfig = $this->createMock(Config::class);
$this->attendeeMapper = new AttendeeMapper(\OCP\Server::get(IDBConnection::class));
$this->sessionMapper = new SessionMapper(\OCP\Server::get(IDBConnection::class));
$this->sessionService = $this->createMock(SessionService::class);
$this->secureRandom = $this->createMock(ISecureRandom::class);
$this->dispatcher = $this->createMock(IEventDispatcher::class);
$this->userManager = $this->createMock(IUserManager::class);
$this->cloudIdManager = $this->createMock(ICloudIdManager::class);
$this->groupManager = $this->createMock(IGroupManager::class);
$this->membershipService = $this->createMock(MembershipService::class);
$this->federationBackendNotifier = $this->createMock(BackendNotifier::class);
$this->time = $this->createMock(ITimeFactory::class);
$this->cacheFactory = $this->createMock(ICacheFactory::class);
$this->userStatusManager = $this->createMock(IManager::class);
$this->service = new ParticipantService(
$this->serverConfig,
$this->talkConfig,
$this->attendeeMapper,
$this->sessionMapper,
$this->sessionService,
$this->secureRandom,
\OCP\Server::get(IDBConnection::class),
$this->dispatcher,
$this->userManager,
$this->cloudIdManager,
$this->groupManager,
$this->membershipService,
$this->federationBackendNotifier,
$this->time,
$this->cacheFactory,
$this->userStatusManager,
);
}
public function tearDown(): void {
try {
$attendee = $this->attendeeMapper->findByActor(123456789, Attendee::ACTOR_USERS, 'test');
$this->sessionMapper->deleteByAttendeeId($attendee->getId());
$this->attendeeMapper->delete($attendee);
} catch (DoesNotExistException $exception) {
}
parent::tearDown();
}
public function testGetParticipantsByNotificationLevel(): void {
$attendee = new Attendee();
$attendee->setActorType(Attendee::ACTOR_USERS);
$attendee->setActorId('test');
$attendee->setRoomId(123456789);
$attendee->setNotificationLevel(Participant::NOTIFY_MENTION);
$this->attendeeMapper->insert($attendee);
$session1 = new Session();
$session1->setAttendeeId($attendee->getId());
$session1->setSessionId(self::getUniqueID('session1'));
$this->sessionMapper->insert($session1);
$session2 = new Session();
$session2->setAttendeeId($attendee->getId());
$session2->setSessionId(self::getUniqueID('session2'));
$this->sessionMapper->insert($session2);
$room = $this->createMock(Room::class);
$room->method('getId')
->willReturn(123456789);
$participants = $this->service->getParticipantsByNotificationLevel($room, Participant::NOTIFY_MENTION);
self::assertCount(1, $participants);
}
}