Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/spreed.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorJoas Schilling <coding@schilljs.com>2020-10-27 17:31:32 +0300
committerJoas Schilling <coding@schilljs.com>2020-10-30 12:38:51 +0300
commitd24e52326931bf60fca1030185732817572735f9 (patch)
treef9152f803c7886302f7688187eff8ad3bcb58d6a /tests
parent164da758eef468523506b031c04a665dc7c3a084 (diff)
Fix the unit tests
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/php/Chat/AutoComplete/SearchPluginTest.php32
-rw-r--r--tests/php/Chat/ChatManagerTest.php5
-rw-r--r--tests/php/Chat/NotifierTest.php5
-rw-r--r--tests/php/Chat/Parser/SystemMessageTest.php56
-rw-r--r--tests/php/Collaboration/Resources/ConversationProviderTest.php23
-rw-r--r--tests/php/Controller/ChatControllerTest.php17
-rw-r--r--tests/php/Controller/RoomControllerTest.php167
-rw-r--r--tests/php/Controller/SignalingControllerTest.php65
-rw-r--r--tests/php/Notification/NotifierTest.php5
-rw-r--r--tests/php/RoomTest.php1
-rw-r--r--tests/php/Service/RoomServiceTest.php41
-rw-r--r--tests/php/Signaling/BackendNotifierTest.php124
12 files changed, 278 insertions, 263 deletions
diff --git a/tests/php/Chat/AutoComplete/SearchPluginTest.php b/tests/php/Chat/AutoComplete/SearchPluginTest.php
index 67e094f2f..e7cb50051 100644
--- a/tests/php/Chat/AutoComplete/SearchPluginTest.php
+++ b/tests/php/Chat/AutoComplete/SearchPluginTest.php
@@ -24,8 +24,11 @@ namespace OCA\Talk\Tests\php\Chat\AutoComplete;
use OCA\Talk\Chat\AutoComplete\SearchPlugin;
use OCA\Talk\Files\Util;
use OCA\Talk\GuestManager;
+use OCA\Talk\Model\Attendee;
+use OCA\Talk\Model\Session;
use OCA\Talk\Participant;
use OCA\Talk\Room;
+use OCA\Talk\Service\ParticipantService;
use OCA\Talk\TalkSession;
use OCP\Collaboration\Collaborators\ISearchResult;
use OCP\IL10N;
@@ -41,6 +44,8 @@ class SearchPluginTest extends \Test\TestCase {
protected $guestManager;
/** @var TalkSession|MockObject */
protected $talkSession;
+ /** @var ParticipantService|MockObject */
+ protected $participantService;
/** @var Util|MockObject */
protected $util;
/** @var IL10N|MockObject */
@@ -56,6 +61,7 @@ class SearchPluginTest extends \Test\TestCase {
$this->userManager = $this->createMock(IUserManager::class);
$this->guestManager = $this->createMock(GuestManager::class);
$this->talkSession = $this->createMock(TalkSession::class);
+ $this->participantService = $this->createMock(ParticipantService::class);
$this->util = $this->createMock(Util::class);
$this->userId = 'current';
$this->l = $this->createMock(IL10N::class);
@@ -76,6 +82,7 @@ class SearchPluginTest extends \Test\TestCase {
$this->userManager,
$this->guestManager,
$this->talkSession,
+ $this->participantService,
$this->util,
$this->userId,
$this->l
@@ -87,6 +94,7 @@ class SearchPluginTest extends \Test\TestCase {
$this->userManager,
$this->guestManager,
$this->talkSession,
+ $this->participantService,
$this->util,
$this->userId,
$this->l,
@@ -98,15 +106,24 @@ class SearchPluginTest extends \Test\TestCase {
protected function createParticipantMock(string $uid, string $session = ''): Participant {
/** @var Participant|MockObject $p */
$p = $this->createMock(Participant::class);
+ $a = Attendee::fromRow([
+ 'actor_type' => $uid ? 'users' : 'guests',
+ 'actor_id' => $uid ? $uid : sha1($session),
+ ]);
+ $s = Session::fromRow([
+ 'session_id' => $session,
+ ]);
$p->expects($this->any())
- ->method('getUser')
- ->willReturn($uid);
+ ->method('getAttendee')
+ ->willReturn($a);
+ $p->expects($this->any())
+ ->method('getSession')
+ ->willReturn($s);
+
$p->expects($this->any())
->method('isGuest')
->willReturn($uid === '');
- $p->expects($this->any())
- ->method('getSessionId')
- ->willReturn($session);
+
return $p;
}
@@ -114,8 +131,9 @@ class SearchPluginTest extends \Test\TestCase {
$result = $this->createMock(ISearchResult::class);
$room = $this->createMock(Room::class);
- $room->expects($this->once())
- ->method('getParticipants')
+ $this->participantService->expects($this->once())
+ ->method('getParticipantsForRoom')
+ ->with($room)
->willReturn([
$this->createParticipantMock('123'),
$this->createParticipantMock('foo'),
diff --git a/tests/php/Chat/ChatManagerTest.php b/tests/php/Chat/ChatManagerTest.php
index b3684e1ec..3cd63aefa 100644
--- a/tests/php/Chat/ChatManagerTest.php
+++ b/tests/php/Chat/ChatManagerTest.php
@@ -29,6 +29,7 @@ use OCA\Talk\Chat\CommentsManager;
use OCA\Talk\Chat\Notifier;
use OCA\Talk\Participant;
use OCA\Talk\Room;
+use OCA\Talk\Service\ParticipantService;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\Comments\IComment;
use OCP\Comments\ICommentsManager;
@@ -50,6 +51,8 @@ class ChatManagerTest extends TestCase {
protected $dispatcher;
/** @var INotificationManager|MockObject */
protected $notificationManager;
+ /** @var ParticipantService|MockObject */
+ protected $participantService;
/** @var Notifier|MockObject */
protected $notifier;
/** @var ITimeFactory|MockObject */
@@ -63,6 +66,7 @@ class ChatManagerTest extends TestCase {
$this->commentsManager = $this->createMock(CommentsManager::class);
$this->dispatcher = $this->createMock(IEventDispatcher::class);
$this->notificationManager = $this->createMock(INotificationManager::class);
+ $this->participantService = $this->createMock(ParticipantService::class);
$this->notifier = $this->createMock(Notifier::class);
$this->timeFactory = $this->createMock(ITimeFactory::class);
$cacheFactory = $this->createMock(ICacheFactory::class);
@@ -72,6 +76,7 @@ class ChatManagerTest extends TestCase {
$this->dispatcher,
\OC::$server->getDatabaseConnection(),
$this->notificationManager,
+ $this->participantService,
$this->notifier,
$cacheFactory,
$this->timeFactory
diff --git a/tests/php/Chat/NotifierTest.php b/tests/php/Chat/NotifierTest.php
index 8c5827e4a..d0214a305 100644
--- a/tests/php/Chat/NotifierTest.php
+++ b/tests/php/Chat/NotifierTest.php
@@ -29,6 +29,7 @@ use OCA\Talk\Files\Util;
use OCA\Talk\Manager;
use OCA\Talk\Participant;
use OCA\Talk\Room;
+use OCA\Talk\Service\ParticipantService;
use OCP\Comments\IComment;
use OCP\IConfig;
use OCP\Notification\IManager as INotificationManager;
@@ -43,6 +44,8 @@ class NotifierTest extends TestCase {
protected $notificationManager;
/** @var IUserManager|MockObject */
protected $userManager;
+ /** @var ParticipantService|MockObject */
+ protected $participantService;
/** @var Manager|MockObject */
protected $manager;
/** @var IConfig|MockObject */
@@ -65,6 +68,7 @@ class NotifierTest extends TestCase {
return $userId !== 'unknownUser';
});
+ $this->participantService = $this->createMock(ParticipantService::class);
$this->manager = $this->createMock(Manager::class);
$this->config = $this->createMock(IConfig::class);
$this->util = $this->createMock(Util::class);
@@ -72,6 +76,7 @@ class NotifierTest extends TestCase {
$this->notifier = new Notifier(
$this->notificationManager,
$this->userManager,
+ $this->participantService,
$this->manager,
$this->config,
$this->util
diff --git a/tests/php/Chat/Parser/SystemMessageTest.php b/tests/php/Chat/Parser/SystemMessageTest.php
index 3231c45c3..96c679b0e 100644
--- a/tests/php/Chat/Parser/SystemMessageTest.php
+++ b/tests/php/Chat/Parser/SystemMessageTest.php
@@ -24,7 +24,9 @@ namespace OCA\Talk\Tests\php\Chat\Parser;
use OCA\Talk\Chat\Parser\SystemMessage;
use OCA\Talk\Exceptions\ParticipantNotFoundException;
use OCA\Talk\GuestManager;
+use OCA\Talk\Model\Attendee;
use OCA\Talk\Model\Message;
+use OCA\Talk\Model\Session;
use OCA\Talk\Participant;
use OCA\Talk\Room;
use OCA\Talk\Share\RoomShareProvider;
@@ -312,20 +314,32 @@ class SystemMessageTest extends TestCase {
/** @var Participant|MockObject $participant */
$participant = $this->createMock(Participant::class);
if ($recipientId && strpos($recipientId, 'guest::') !== false) {
+ $attendee = Attendee::fromRow([
+ 'actor_type' => 'guests',
+ 'actor_id' => substr($recipientId, strlen('guest::')),
+ ]);
+ $session = Session::fromRow([
+ 'session_id' => substr($recipientId, strlen('guest::')),
+ ]);
$participant->expects($this->atLeastOnce())
->method('isGuest')
->willReturn(true);
- $participant->expects($this->atLeastOnce())
- ->method('getSessionId')
- ->willReturn(substr($recipientId, strlen('guest::')));
} else {
$participant->expects($this->atLeastOnce())
->method('isGuest')
->willReturn(false);
- $participant->expects($this->atLeastOnce())
- ->method('getUser')
- ->willReturn($recipientId);
+ $attendee = Attendee::fromRow([
+ 'actor_type' => 'users',
+ 'actor_id' => $recipientId,
+ ]);
+ $session = null;
}
+ $participant->expects($this->any())
+ ->method('getAttendee')
+ ->willReturn($attendee);
+ $participant->expects($this->any())
+ ->method('getSession')
+ ->willReturn($session);
/** @var IComment|MockObject $comment */
$comment = $this->createMock(IComment::class);
@@ -527,9 +541,13 @@ class SystemMessageTest extends TestCase {
$participant->expects($this->once())
->method('isGuest')
->willReturn(false);
- $participant->expects($this->once())
- ->method('getUser')
- ->willReturn('owner');
+ $attendee = Attendee::fromRow([
+ 'actor_type' => 'users',
+ 'actor_id' => 'owner',
+ ]);
+ $participant->expects($this->any())
+ ->method('getAttendee')
+ ->willReturn($attendee);
$parser = $this->getParser();
$this->assertSame([
@@ -568,9 +586,13 @@ class SystemMessageTest extends TestCase {
$participant->expects($this->once())
->method('isGuest')
->willReturn(false);
- $participant->expects($this->exactly(2))
- ->method('getUser')
- ->willReturn('user');
+ $attendee = Attendee::fromRow([
+ 'actor_type' => 'users',
+ 'actor_id' => 'user',
+ ]);
+ $participant->expects($this->any())
+ ->method('getAttendee')
+ ->willReturn($attendee);
$this->shareProvider->expects($this->once())
->method('getShareById')
@@ -642,9 +664,13 @@ class SystemMessageTest extends TestCase {
$participant->expects($this->once())
->method('isGuest')
->willReturn(false);
- $participant->expects($this->exactly(3))
- ->method('getUser')
- ->willReturn('user');
+ $attendee = Attendee::fromRow([
+ 'actor_type' => 'users',
+ 'actor_id' => 'user',
+ ]);
+ $participant->expects($this->any())
+ ->method('getAttendee')
+ ->willReturn($attendee);
$this->shareProvider->expects($this->once())
->method('getShareById')
diff --git a/tests/php/Collaboration/Resources/ConversationProviderTest.php b/tests/php/Collaboration/Resources/ConversationProviderTest.php
index 0080a6b6e..df80d82ed 100644
--- a/tests/php/Collaboration/Resources/ConversationProviderTest.php
+++ b/tests/php/Collaboration/Resources/ConversationProviderTest.php
@@ -27,6 +27,7 @@ use OCA\Talk\Collaboration\Resources\ConversationProvider;
use OCA\Talk\Exceptions\ParticipantNotFoundException;
use OCA\Talk\Exceptions\RoomNotFoundException;
use OCA\Talk\Manager;
+use OCA\Talk\Model\Attendee;
use OCA\Talk\Participant;
use OCA\Talk\Room;
use OCP\Collaboration\Resources\IResource;
@@ -124,9 +125,14 @@ class ConversationProviderTest extends TestCase {
->willReturn('token');
$participant = $this->createMock(Participant::class);
- $participant->expects($this->once())
- ->method('getParticipantType')
- ->willReturn(Participant::USER_SELF_JOINED);
+ $attendee = Attendee::fromRow([
+ 'actor_type' => 'users',
+ 'actor_id' => 'uid',
+ 'participant_type' => Participant::USER_SELF_JOINED,
+ ]);
+ $participant->expects($this->any())
+ ->method('getAttendee')
+ ->willReturn($attendee);
$room = $this->createMock(Room::class);
$room->expects($this->once())
->method('getParticipant')
@@ -164,9 +170,14 @@ class ConversationProviderTest extends TestCase {
->willReturn('token');
$participant = $this->createMock(Participant::class);
- $participant->expects($this->once())
- ->method('getParticipantType')
- ->willReturn($participantType);
+ $attendee = Attendee::fromRow([
+ 'actor_type' => 'users',
+ 'actor_id' => 'uid',
+ 'participant_type' => $participantType,
+ ]);
+ $participant->expects($this->any())
+ ->method('getAttendee')
+ ->willReturn($attendee);
$room = $this->createMock(Room::class);
$room->expects($this->once())
->method('getParticipant')
diff --git a/tests/php/Controller/ChatControllerTest.php b/tests/php/Controller/ChatControllerTest.php
index 1143546b1..ace37089a 100644
--- a/tests/php/Controller/ChatControllerTest.php
+++ b/tests/php/Controller/ChatControllerTest.php
@@ -28,9 +28,12 @@ use OCA\Talk\Chat\ChatManager;
use OCA\Talk\Chat\MessageParser;
use OCA\Talk\Controller\ChatController;
use OCA\Talk\GuestManager;
+use OCA\Talk\Model\AttendeeMapper;
use OCA\Talk\Model\Message;
use OCA\Talk\Participant;
use OCA\Talk\Room;
+use OCA\Talk\Service\ParticipantService;
+use OCA\Talk\Service\SessionService;
use OCA\Talk\TalkSession;
use OCP\App\IAppManager;
use OCP\AppFramework\Http;
@@ -61,6 +64,12 @@ class ChatControllerTest extends TestCase {
private $appManager;
/** @var ChatManager|MockObject */
protected $chatManager;
+ /** @var AttendeeMapper|MockObject */
+ protected $attendeeMapper;
+ /** @var ParticipantService|MockObject */
+ protected $participantService;
+ /** @var SessionService|MockObject */
+ protected $sessionService;
/** @var GuestManager|MockObject */
protected $guestManager;
/** @var MessageParser|MockObject */
@@ -97,6 +106,9 @@ class ChatControllerTest extends TestCase {
$this->session = $this->createMock(TalkSession::class);
$this->appManager = $this->createMock(IAppManager::class);
$this->chatManager = $this->createMock(ChatManager::class);
+ $this->attendeeMapper = $this->createMock(AttendeeMapper::class);
+ $this->participantService = $this->createMock(ParticipantService::class);
+ $this->sessionService = $this->createMock(SessionService::class);
$this->guestManager = $this->createMock(GuestManager::class);
$this->messageParser = $this->createMock(MessageParser::class);
$this->autoCompleteManager = $this->createMock(IManager::class);
@@ -128,14 +140,17 @@ class ChatControllerTest extends TestCase {
$this->session,
$this->appManager,
$this->chatManager,
+ $this->attendeeMapper,
+ $this->participantService,
+ $this->sessionService,
$this->guestManager,
$this->messageParser,
$this->autoCompleteManager,
$this->statusManager,
$this->searchPlugin,
$this->searchResult,
- $this->eventDispatcher,
$this->timeFactory,
+ $this->eventDispatcher,
$this->l
);
}
diff --git a/tests/php/Controller/RoomControllerTest.php b/tests/php/Controller/RoomControllerTest.php
deleted file mode 100644
index 06807707b..000000000
--- a/tests/php/Controller/RoomControllerTest.php
+++ /dev/null
@@ -1,167 +0,0 @@
-<?php
-
-/**
- *
- * @copyright Copyright (c) 2017, Daniel Calviño Sánchez (danxuliu@gmail.com)
- *
- * @license GNU AGPL version 3 or any later version
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
- */
-
-namespace OCA\Talk\Tests\php\Controller;
-
-use OCA\Talk\Chat\ChatManager;
-use OCA\Talk\Chat\MessageParser;
-use OCA\Talk\Config;
-use OCA\Talk\Controller\RoomController;
-use OCA\Talk\GuestManager;
-use OCA\Talk\Manager;
-use OCA\Talk\Participant;
-use OCA\Talk\Room;
-use OCA\Talk\Service\RoomService;
-use OCA\Talk\TalkSession;
-use OCP\App\IAppManager;
-use OCP\AppFramework\Http;
-use OCP\AppFramework\Http\DataResponse;
-use OCP\AppFramework\Utility\ITimeFactory;
-use OCP\EventDispatcher\IEventDispatcher;
-use OCP\IConfig;
-use OCP\IGroupManager;
-use OCP\IL10N;
-use OCP\IRequest;
-use OCP\IUserManager;
-use OCP\UserStatus\IManager as IUserStatusManager;
-use PHPUnit\Framework\MockObject\MockObject;
-use Test\TestCase;
-
-class RoomControllerTest extends TestCase {
-
- /** @var string */
- private $userId;
- /** @var IAppManager|MockObject */
- private $appManager;
- /** @var TalkSession|MockObject */
- private $talkSession;
- /** @var IUserManager|MockObject */
- protected $userManager;
- /** @var IGroupManager|MockObject */
- protected $groupManager;
- /** @var IUserStatusManager|MockObject */
- protected $statusManager;
- /** @var Manager|MockObject */
- protected $manager;
- /** @var RoomService|MockObject */
- protected $roomService;
- /** @var ChatManager|MockObject */
- protected $chatManager;
- /** @var GuestManager|MockObject */
- protected $guestManager;
- /** @var IEventDispatcher|MockObject */
- protected $dispatcher;
- /** @var MessageParser|MockObject */
- protected $messageParser;
- /** @var ITimeFactory|MockObject */
- protected $timeFactory;
- /** @var IL10N|MockObject */
- private $l;
- /** @var IConfig|MockObject */
- private $serverConfig;
- /** @var Config|MockObject */
- private $talkConfig;
-
-
- public function setUp(): void {
- parent::setUp();
-
- $this->userId = 'testUser';
- $this->appManager = $this->createMock(IAppManager::class);
- $this->talkSession = $this->createMock(TalkSession::class);
- $this->userManager = $this->createMock(IUserManager::class);
- $this->groupManager = $this->createMock(IGroupManager::class);
- $this->manager = $this->createMock(Manager::class);
- $this->roomService = $this->createMock(RoomService::class);
- $this->guestManager = $this->createMock(GuestManager::class);
- $this->statusManager = $this->createMock(IUserStatusManager::class);
- $this->chatManager = $this->createMock(ChatManager::class);
- $this->dispatcher = $this->createMock(IEventDispatcher::class);
- $this->messageParser = $this->createMock(MessageParser::class);
- $this->timeFactory = $this->createMock(ITimeFactory::class);
- $this->l = $this->createMock(IL10N::class);
- $this->serverConfig = $this->createMock(IConfig::class);
- $this->talkConfig = $this->createMock(Config::class);
- }
-
- /**
- * @param Room|MockObject $room
- * @param Participant|MockObject $participant
- * @return RoomController
- */
- private function getController(Room $room, Participant $participant): RoomController {
- $controller = new RoomController(
- 'spreed',
- $this->userId,
- $this->createMock(IRequest::class),
- $this->appManager,
- $this->talkSession,
- $this->userManager,
- $this->groupManager,
- $this->manager,
- $this->roomService,
- $this->guestManager,
- $this->statusManager,
- $this->chatManager,
- $this->dispatcher,
- $this->messageParser,
- $this->timeFactory,
- $this->l,
- $this->serverConfig,
- $this->talkConfig
- );
- $controller->setRoom($room);
- $controller->setParticipant($participant);
- return $controller;
- }
-
- public function dataSetNotificationLevel(): array {
- return [
- [Participant::NOTIFY_ALWAYS, true],
- [Participant::NOTIFY_MENTION, true],
- [Participant::NOTIFY_NEVER, true],
- [Participant::NOTIFY_DEFAULT, false, Http::STATUS_BAD_REQUEST],
- ];
- }
-
- /**
- * @dataProvider dataSetNotificationLevel
- * @param int $level
- * @param bool $validSet
- * @param int $status
- */
- public function testSetNotificationLevel(int $level, bool $validSet, int $status = Http::STATUS_OK) {
- $participant = $this->createMock(Participant::class);
- $participant->expects($this->once())
- ->method('setNotificationLevel')
- ->with($level)
- ->willReturn($validSet);
-
- $room = $this->createMock(Room::class);
-
- $controller = $this->getController($room, $participant);
- $expected = new DataResponse([], $status);
-
- $this->assertEquals($expected, $controller->setNotificationLevel($level));
- }
-}
diff --git a/tests/php/Controller/SignalingControllerTest.php b/tests/php/Controller/SignalingControllerTest.php
index 7b80df49b..e9da6f7f2 100644
--- a/tests/php/Controller/SignalingControllerTest.php
+++ b/tests/php/Controller/SignalingControllerTest.php
@@ -29,8 +29,12 @@ use OCA\Talk\Events\SignalingEvent;
use OCA\Talk\Exceptions\ParticipantNotFoundException;
use OCA\Talk\Exceptions\RoomNotFoundException;
use OCA\Talk\Manager;
+use OCA\Talk\Model\AttendeeMapper;
+use OCA\Talk\Model\SessionMapper;
use OCA\Talk\Participant;
use OCA\Talk\Room;
+use OCA\Talk\Service\ParticipantService;
+use OCA\Talk\Service\SessionService;
use OCA\Talk\Signaling\Messages;
use OCA\Talk\TalkSession;
use OCP\AppFramework\Utility\ITimeFactory;
@@ -70,6 +74,10 @@ class SignalingControllerTest extends \Test\TestCase {
private $signalingManager;
/** @var Manager|MockObject */
protected $manager;
+ /** @var ParticipantService|MockObject */
+ protected $participantService;
+ /** @var SessionService|MockObject */
+ protected $sessionService;
/** @var IDBConnection|MockObject */
protected $dbConnection;
/** @var Messages|MockObject */
@@ -108,6 +116,8 @@ class SignalingControllerTest extends \Test\TestCase {
$this->dbConnection = \OC::$server->getDatabaseConnection();
$this->signalingManager = $this->createMock(\OCA\Talk\Signaling\Manager::class);
$this->manager = $this->createMock(Manager::class);
+ $this->participantService = $this->createMock(ParticipantService::class);
+ $this->sessionService = $this->createMock(SessionService::class);
$this->messages = $this->createMock(Messages::class);
$this->userManager = $this->createMock(IUserManager::class);
$this->timeFactory = $this->createMock(ITimeFactory::class);
@@ -124,6 +134,8 @@ class SignalingControllerTest extends \Test\TestCase {
$this->signalingManager,
$this->session,
$this->manager,
+ $this->participantService,
+ $this->sessionService,
$this->dbConnection,
$this->messages,
$this->userManager,
@@ -580,8 +592,8 @@ class SignalingControllerTest extends \Test\TestCase {
$participant = $this->createMock(Participant::class);
$room->expects($this->once())
- ->method('getParticipant')
- ->with($this->userId)
+ ->method('getParticipantBySession')
+ ->with($sessionId)
->willThrowException(new ParticipantNotFoundException());
$room->expects($this->once())
->method('getParticipantBySession')
@@ -632,7 +644,6 @@ class SignalingControllerTest extends \Test\TestCase {
->with($roomToken)
->willReturn($room);
- $participant = $this->createMock(Participant::class);
$room->expects($this->once())
->method('getParticipantBySession')
->willThrowException(new ParticipantNotFoundException());
@@ -755,9 +766,12 @@ class SignalingControllerTest extends \Test\TestCase {
$room->expects($this->once())
->method('getToken')
->willReturn($roomToken);
- $room->expects($this->once())
- ->method('pingSessionIds')
- ->with([$sessionId]);
+
+ $this->timeFactory->method('getTime')
+ ->willReturn(123456);
+ $this->sessionService->expects($this->once())
+ ->method('updateMultipleLastPings')
+ ->with([$sessionId], 123456);
$result = $this->performBackendRequest([
'type' => 'ping',
@@ -791,9 +805,12 @@ class SignalingControllerTest extends \Test\TestCase {
$room->expects($this->once())
->method('getToken')
->willReturn($roomToken);
- $room->expects($this->once())
- ->method('pingSessionIds')
- ->with([$sessionId]);
+
+ $this->timeFactory->method('getTime')
+ ->willReturn(1234567);
+ $this->sessionService->expects($this->once())
+ ->method('updateMultipleLastPings')
+ ->with([$sessionId], 1234567);
$result = $this->performBackendRequest([
'type' => 'ping',
@@ -827,9 +844,12 @@ class SignalingControllerTest extends \Test\TestCase {
$room->expects($this->once())
->method('getToken')
->willReturn($roomToken);
- $room->expects($this->once())
- ->method('pingSessionIds')
- ->with([$sessionId . '1', $sessionId . '2']);
+
+ $this->timeFactory->method('getTime')
+ ->willReturn(234567);
+ $this->sessionService->expects($this->once())
+ ->method('updateMultipleLastPings')
+ ->with([$sessionId . '1', $sessionId . '2'], 234567);
$result = $this->performBackendRequest([
'type' => 'ping',
@@ -865,10 +885,17 @@ class SignalingControllerTest extends \Test\TestCase {
// Make sure that leaving a user with an old session id doesn't remove
// the current user from the room if he re-joined in the meantime.
$dbConnection = \OC::$server->getDatabaseConnection();
- $dispatcher = \OC::$server->query(IEventDispatcher::class);
+ $dispatcher = \OC::$server->get(IEventDispatcher::class);
+ /** @var ParticipantService $participantService */
+ $participantService = \OC::$server->get(ParticipantService::class);
+
$this->manager = new Manager(
$dbConnection,
\OC::$server->getConfig(),
+ $this->createMock(Config::class),
+ \OC::$server->get(AttendeeMapper::class),
+ \OC::$server->get(SessionMapper::class),
+ $participantService,
$this->secureRandom,
$this->createMock(IUserManager::class),
$this->createMock(CommentsManager::class),
@@ -891,7 +918,8 @@ class SignalingControllerTest extends \Test\TestCase {
$room = $this->manager->createRoom(Room::PUBLIC_CALL);
// The user joined the room.
- $oldSessionId = $room->joinRoom($testUser, '');
+ $oldParticipant = $participantService->joinRoom($room, $testUser, '');
+ $oldSessionId = $oldParticipant->getSession()->getSessionId();
$result = $this->performBackendRequest([
'type' => 'room',
'room' => [
@@ -902,11 +930,12 @@ class SignalingControllerTest extends \Test\TestCase {
],
]);
$participant = $room->getParticipant($this->userId);
- $this->assertEquals($oldSessionId, $participant->getSessionId());
+ $this->assertEquals($oldSessionId, $participant->getSession()->getSessionId());
// The user is reloading the browser which will join him with another
// session id.
- $newSessionId = $room->joinRoom($testUser, '');
+ $newParticipant = $participantService->joinRoom($room, $testUser, '');
+ $newSessionId = $newParticipant->getSession()->getSessionId();
$result = $this->performBackendRequest([
'type' => 'room',
'room' => [
@@ -919,7 +948,7 @@ class SignalingControllerTest extends \Test\TestCase {
// Now the new session id is stored in the database.
$participant = $room->getParticipant($this->userId);
- $this->assertEquals($newSessionId, $participant->getSessionId());
+ $this->assertEquals($newSessionId, $participant->getSession()->getSessionId());
// Leaving the old session id...
$result = $this->performBackendRequest([
@@ -934,6 +963,6 @@ class SignalingControllerTest extends \Test\TestCase {
// ...will keep the new session id in the database.
$participant = $room->getParticipant($this->userId);
- $this->assertEquals($newSessionId, $participant->getSessionId());
+ $this->assertEquals($newSessionId, $participant->getSession()->getSessionId());
}
}
diff --git a/tests/php/Notification/NotifierTest.php b/tests/php/Notification/NotifierTest.php
index b327e2d60..fddf8fceb 100644
--- a/tests/php/Notification/NotifierTest.php
+++ b/tests/php/Notification/NotifierTest.php
@@ -32,6 +32,7 @@ use OCA\Talk\Model\Message;
use OCA\Talk\Notification\Notifier;
use OCA\Talk\Participant;
use OCA\Talk\Room;
+use OCA\Talk\Service\ParticipantService;
use OCP\Comments\IComment;
use OCP\IL10N;
use OCP\IURLGenerator;
@@ -61,6 +62,8 @@ class NotifierTest extends \Test\TestCase {
protected $shareManager;
/** @var Manager|MockObject */
protected $manager;
+ /** @var ParticipantService|MockObject */
+ protected $participantService;
/** @var INotificationManager|MockObject */
protected $notificationManager;
/** @var CommentsManager|MockObject */
@@ -82,6 +85,7 @@ class NotifierTest extends \Test\TestCase {
$this->guestManager = $this->createMock(GuestManager::class);
$this->shareManager = $this->createMock(IShareManager::class);
$this->manager = $this->createMock(Manager::class);
+ $this->participantService = $this->createMock(ParticipantService::class);
$this->notificationManager = $this->createMock(INotificationManager::class);
$this->commentsManager = $this->createMock(CommentsManager::class);
$this->messageParser = $this->createMock(MessageParser::class);
@@ -95,6 +99,7 @@ class NotifierTest extends \Test\TestCase {
$this->guestManager,
$this->shareManager,
$this->manager,
+ $this->participantService,
$this->notificationManager,
$this->commentsManager,
$this->messageParser,
diff --git a/tests/php/RoomTest.php b/tests/php/RoomTest.php
index 3de765d1e..024138c92 100644
--- a/tests/php/RoomTest.php
+++ b/tests/php/RoomTest.php
@@ -64,6 +64,7 @@ class RoomTest extends TestCase {
Room::PUBLIC_CALL,
Room::READ_WRITE,
Webinary::LOBBY_NONE,
+ 0,
null,
'foobar',
'Test',
diff --git a/tests/php/Service/RoomServiceTest.php b/tests/php/Service/RoomServiceTest.php
index 4eba57d43..d223c4c3c 100644
--- a/tests/php/Service/RoomServiceTest.php
+++ b/tests/php/Service/RoomServiceTest.php
@@ -28,6 +28,7 @@ use OCA\Talk\Exceptions\RoomNotFoundException;
use OCA\Talk\Manager;
use OCA\Talk\Participant;
use OCA\Talk\Room;
+use OCA\Talk\Service\ParticipantService;
use OCA\Talk\Service\RoomService;
use OCP\IUser;
use PHPUnit\Framework\MockObject\MockObject;
@@ -37,6 +38,8 @@ class RoomServiceTest extends TestCase {
/** @var Manager|MockObject */
protected $manager;
+ /** @var ParticipantService|MockObject */
+ protected $participantService;
/** @var RoomService */
private $service;
@@ -45,8 +48,10 @@ class RoomServiceTest extends TestCase {
parent::setUp();
$this->manager = $this->createMock(Manager::class);
+ $this->participantService = $this->createMock(ParticipantService::class);
$this->service = new RoomService(
- $this->manager
+ $this->manager,
+ $this->participantService
);
}
@@ -69,8 +74,9 @@ class RoomServiceTest extends TestCase {
->willReturn('uid2');
$room = $this->createMock(Room::class);
- $room->expects($this->once())
- ->method('ensureOneToOneRoomIsFilled');
+ $this->participantService->expects($this->once())
+ ->method('ensureOneToOneRoomIsFilled')
+ ->with($room);
$this->manager->expects($this->once())
->method('getOne2OneRoom')
@@ -89,17 +95,21 @@ class RoomServiceTest extends TestCase {
->willReturn('uid2');
$room = $this->createMock(Room::class);
- $room->expects($this->never())
- ->method('ensureOneToOneRoomIsFilled');
- $room->expects($this->once())
+ $this->participantService->expects($this->once())
->method('addUsers')
- ->with([
- 'userId' => 'uid1',
+ ->with($room, [[
+ 'actorType' => 'users',
+ 'actorId' => 'uid1',
'participantType' => Participant::OWNER,
], [
- 'userId' => 'uid2',
+ 'actorType' => 'users',
+ 'actorId' => 'uid2',
'participantType' => Participant::OWNER,
- ]);
+ ]]);
+
+ $this->participantService->expects($this->never())
+ ->method('ensureOneToOneRoomIsFilled')
+ ->with($room);
$this->manager->expects($this->once())
->method('getOne2OneRoom')
@@ -204,15 +214,16 @@ class RoomServiceTest extends TestCase {
$owner->method('getUID')
->willReturn($ownerId);
- $room->expects($this->once())
+ $this->participantService->expects($this->once())
->method('addUsers')
- ->with([
- 'userId' => $ownerId,
+ ->with($room, [[
+ 'actorType' => 'users',
+ 'actorId' => $ownerId,
'participantType' => Participant::OWNER,
- ]);
+ ]]);
} else {
$owner = null;
- $room->expects($this->never())
+ $this->participantService->expects($this->never())
->method('addUsers');
}
diff --git a/tests/php/Signaling/BackendNotifierTest.php b/tests/php/Signaling/BackendNotifierTest.php
index c775b68c5..47777bbb7 100644
--- a/tests/php/Signaling/BackendNotifierTest.php
+++ b/tests/php/Signaling/BackendNotifierTest.php
@@ -27,8 +27,11 @@ use OCA\Talk\Chat\CommentsManager;
use OCA\Talk\Config;
use OCA\Talk\Events\SignalingRoomPropertiesEvent;
use OCA\Talk\Manager;
+use OCA\Talk\Model\AttendeeMapper;
+use OCA\Talk\Model\SessionMapper;
use OCA\Talk\Participant;
use OCA\Talk\Room;
+use OCA\Talk\Service\ParticipantService;
use OCA\Talk\Signaling\BackendNotifier;
use OCA\Talk\TalkSession;
use OCA\Talk\Webinary;
@@ -75,6 +78,8 @@ class BackendNotifierTest extends \Test\TestCase {
private $secureRandom;
/** @var ITimeFactory|MockObject */
private $timeFactory;
+ /** @var ParticipantService|MockObject */
+ private $participantService;
/** @var \OCA\Talk\Signaling\Manager|MockObject */
private $signalingManager;
/** @var IURLGenerator|MockObject */
@@ -119,6 +124,7 @@ class BackendNotifierTest extends \Test\TestCase {
],
]));
+ $this->participantService = \OC::$server->get(ParticipantService::class);
$this->signalingManager = $this->createMock(\OCA\Talk\Signaling\Manager::class);
$this->signalingManager->expects($this->any())
->method('getSignalingServerForConversation')
@@ -134,6 +140,10 @@ class BackendNotifierTest extends \Test\TestCase {
$this->manager = new Manager(
$dbConnection,
$config,
+ $this->config,
+ \OC::$server->get(AttendeeMapper::class),
+ \OC::$server->get(SessionMapper::class),
+ $this->participantService,
$this->secureRandom,
$this->createMock(IUserManager::class),
$this->createMock(CommentsManager::class),
@@ -159,6 +169,7 @@ class BackendNotifierTest extends \Test\TestCase {
$this->createMock(IClientService::class),
$this->secureRandom,
$this->signalingManager,
+ $this->participantService,
$this->urlGenerator
);
}
@@ -194,7 +205,7 @@ class BackendNotifierTest extends \Test\TestCase {
$bodies = array_map([$this, 'sortParticipantUsers'], $bodies);
$message = $this->sortParticipantUsers($message);
- $this->assertContains($message, $bodies);
+ $this->assertContains($message, $bodies, json_encode($bodies, JSON_PRETTY_PRINT));
}
private function sortParticipantUsers(array $message): array {
@@ -207,14 +218,24 @@ class BackendNotifierTest extends \Test\TestCase {
;
});
}
+ if ($message['type'] === 'incall') {
+ usort($message['incall']['users'], static function ($a, $b) {
+ return
+ [$a['userId'] ?? '', $a['participantType'], $a['sessionId'], $a['lastPing']]
+ <=>
+ [$b['userId'] ?? '', $b['participantType'], $b['sessionId'], $b['lastPing']]
+ ;
+ });
+ }
return $message;
}
public function testRoomInvite() {
$room = $this->manager->createRoom(Room::PUBLIC_CALL);
- $room->addUsers([
- 'userId' => $this->userId,
- ]);
+ $this->participantService->addUsers($room, [[
+ 'actorType' => 'users',
+ 'actorId' => $this->userId,
+ ]]);
$this->assertMessageWasSent($room, [
'type' => 'invite',
@@ -232,6 +253,7 @@ class BackendNotifierTest extends \Test\TestCase {
'lobby-timer' => null,
'read-only' => Room::READ_WRITE,
'active-since' => null,
+ 'sip-enabled' => 0,
],
],
]);
@@ -239,16 +261,17 @@ class BackendNotifierTest extends \Test\TestCase {
public function testRoomDisinvite() {
$room = $this->manager->createRoom(Room::PUBLIC_CALL);
- $room->addUsers([
- 'userId' => $this->userId,
- ]);
+ $this->participantService->addUsers($room, [[
+ 'actorType' => 'users',
+ 'actorId' => $this->userId,
+ ]]);
$this->controller->clearRequests();
/** @var IUser|MockObject $testUser */
$testUser = $this->createMock(IUser::class);
$testUser->expects($this->any())
->method('getUID')
->willReturn($this->userId);
- $room->removeUser($testUser, Room::PARTICIPANT_REMOVED);
+ $this->participantService->removeUser($room, $testUser, Room::PARTICIPANT_REMOVED);
$this->assertMessageWasSent($room, [
'type' => 'disinvite',
@@ -265,6 +288,7 @@ class BackendNotifierTest extends \Test\TestCase {
'lobby-timer' => null,
'read-only' => Room::READ_WRITE,
'active-since' => null,
+ 'sip-enabled' => 0,
],
],
]);
@@ -286,6 +310,7 @@ class BackendNotifierTest extends \Test\TestCase {
'lobby-timer' => null,
'read-only' => Room::READ_WRITE,
'active-since' => null,
+ 'sip-enabled' => 0,
],
],
]);
@@ -307,6 +332,7 @@ class BackendNotifierTest extends \Test\TestCase {
'lobby-timer' => null,
'read-only' => Room::READ_WRITE,
'active-since' => null,
+ 'sip-enabled' => 0,
],
],
]);
@@ -328,6 +354,7 @@ class BackendNotifierTest extends \Test\TestCase {
'lobby-timer' => null,
'read-only' => Room::READ_WRITE,
'active-since' => null,
+ 'sip-enabled' => 0,
],
],
]);
@@ -349,6 +376,7 @@ class BackendNotifierTest extends \Test\TestCase {
'lobby-timer' => null,
'read-only' => Room::READ_ONLY,
'active-since' => null,
+ 'sip-enabled' => 0,
],
],
]);
@@ -370,6 +398,7 @@ class BackendNotifierTest extends \Test\TestCase {
'lobby-timer' => null,
'read-only' => Room::READ_WRITE,
'active-since' => null,
+ 'sip-enabled' => 0,
],
],
]);
@@ -377,9 +406,10 @@ class BackendNotifierTest extends \Test\TestCase {
public function testRoomDelete() {
$room = $this->manager->createRoom(Room::PUBLIC_CALL);
- $room->addUsers([
- 'userId' => $this->userId,
- ]);
+ $this->participantService->addUsers($room, [[
+ 'actorType' => 'users',
+ 'actorId' => $this->userId,
+ ]]);
$room->deleteRoom();
$this->assertMessageWasSent($room, [
@@ -394,13 +424,22 @@ class BackendNotifierTest extends \Test\TestCase {
public function testRoomInCallChanged() {
$room = $this->manager->createRoom(Room::PUBLIC_CALL);
- $userSession = 'user-session';
- $room->addUsers([
- 'userId' => $this->userId,
- 'sessionId' => $userSession,
- ]);
+ $this->participantService->addUsers($room, [[
+ 'actorType' => 'users',
+ 'actorId' => $this->userId,
+ ]]);
+
+ /** @var IUser|MockObject $testUser */
+ $testUser = $this->createMock(IUser::class);
+ $testUser->expects($this->any())
+ ->method('getUID')
+ ->willReturn($this->userId);
+
+ $participant = $this->participantService->joinRoom($room, $testUser, '');
+ $userSession = $participant->getSession()->getSessionId();
$participant = $room->getParticipantBySession($userSession);
- $room->changeInCall($participant, Participant::FLAG_IN_CALL | Participant::FLAG_WITH_AUDIO | Participant::FLAG_WITH_VIDEO);
+
+ $this->participantService->changeInCall($room, $participant, Participant::FLAG_IN_CALL | Participant::FLAG_WITH_AUDIO | Participant::FLAG_WITH_VIDEO);
$this->assertMessageWasSent($room, [
'type' => 'incall',
@@ -428,9 +467,11 @@ class BackendNotifierTest extends \Test\TestCase {
]);
$this->controller->clearRequests();
- $guestSession = $room->joinRoomGuest('');
+
+ $guestParticipant = $this->participantService->joinRoomAsNewGuest($room, '');
+ $guestSession = $guestParticipant->getSession()->getSessionId();
$guestParticipant = $room->getParticipantBySession($guestSession);
- $room->changeInCall($guestParticipant, Participant::FLAG_IN_CALL);
+ $this->participantService->changeInCall($room, $guestParticipant, Participant::FLAG_IN_CALL);
$this->assertMessageWasSent($room, [
'type' => 'incall',
@@ -463,7 +504,7 @@ class BackendNotifierTest extends \Test\TestCase {
]);
$this->controller->clearRequests();
- $room->changeInCall($participant, Participant::FLAG_DISCONNECTED);
+ $this->participantService->changeInCall($room, $participant, Participant::FLAG_DISCONNECTED);
$this->assertMessageWasSent($room, [
'type' => 'incall',
@@ -515,6 +556,7 @@ class BackendNotifierTest extends \Test\TestCase {
'lobby-timer' => null,
'read-only' => Room::READ_WRITE,
'active-since' => null,
+ 'sip-enabled' => 0,
'foo' => 'bar',
'room' => $room->getToken(),
],
@@ -524,13 +566,22 @@ class BackendNotifierTest extends \Test\TestCase {
public function testParticipantsTypeChanged() {
$room = $this->manager->createRoom(Room::PUBLIC_CALL);
- $userSession = 'user-session';
- $room->addUsers([
- 'userId' => $this->userId,
- 'sessionId' => $userSession,
- ]);
+ $this->participantService->addUsers($room, [[
+ 'actorType' => 'users',
+ 'actorId' => $this->userId,
+ ]]);
+
+ /** @var IUser|MockObject $testUser */
+ $testUser = $this->createMock(IUser::class);
+ $testUser->expects($this->any())
+ ->method('getUID')
+ ->willReturn($this->userId);
+
+ $participant = $this->participantService->joinRoom($room, $testUser, '');
+ $userSession = $participant->getSession()->getSessionId();
$participant = $room->getParticipantBySession($userSession);
- $room->setParticipantType($participant, Participant::MODERATOR);
+
+ $this->participantService->updateParticipantType($room, $participant, Participant::MODERATOR);
$this->assertMessageWasSent($room, [
'type' => 'participants',
@@ -558,9 +609,12 @@ class BackendNotifierTest extends \Test\TestCase {
]);
$this->controller->clearRequests();
- $guestSession = $room->joinRoomGuest('');
+
+ $guestParticipant = $this->participantService->joinRoomAsNewGuest($room, '');
+ $guestSession = $guestParticipant->getSession()->getSessionId();
$guestParticipant = $room->getParticipantBySession($guestSession);
- $room->setParticipantType($guestParticipant, Participant::GUEST_MODERATOR);
+
+ $this->participantService->updateParticipantType($room, $guestParticipant, Participant::GUEST_MODERATOR);
$this->assertMessageWasSent($room, [
'type' => 'participants',
@@ -594,11 +648,13 @@ class BackendNotifierTest extends \Test\TestCase {
$this->controller->clearRequests();
$notJoinedUserId = 'not-joined-user-id';
- $room->addUsers([
- 'userId' => $notJoinedUserId,
- ]);
+ $this->participantService->addUsers($room, [[
+ 'actorType' => 'users',
+ 'actorId' => $notJoinedUserId,
+ ]]);
+
$notJoinedParticipant = $room->getParticipant($notJoinedUserId);
- $room->setParticipantType($notJoinedParticipant, Participant::MODERATOR);
+ $this->participantService->updateParticipantType($room, $notJoinedParticipant, Participant::MODERATOR);
$this->assertMessageWasSent($room, [
'type' => 'participants',
@@ -631,7 +687,7 @@ class BackendNotifierTest extends \Test\TestCase {
]);
$this->controller->clearRequests();
- $room->setParticipantType($participant, Participant::USER);
+ $this->participantService->updateParticipantType($room, $participant, Participant::USER);
$this->assertMessageWasSent($room, [
'type' => 'participants',
@@ -672,7 +728,7 @@ class BackendNotifierTest extends \Test\TestCase {
]);
$this->controller->clearRequests();
- $room->setParticipantType($guestParticipant, Participant::GUEST);
+ $this->participantService->updateParticipantType($room, $guestParticipant, Participant::GUEST);
$this->assertMessageWasSent($room, [
'type' => 'participants',