Introduce a RoomService to handle creation of Rooms

Signed-off-by: Joas Schilling <coding@schilljs.com>
This commit is contained in:
Joas Schilling 2020-06-17 16:26:02 +02:00
parent 49921c0ac1
commit 31c20949b4
No known key found for this signature in database
GPG key ID: 7076EA9751AACDDA
17 changed files with 246 additions and 143 deletions

View file

@ -27,6 +27,7 @@ namespace OCA\Talk\Command\Room;
use InvalidArgumentException;
use OC\Core\Command\Base;
use OCA\Talk\Room;
use Stecman\Component\Symfony\Console\BashCompletion\CompletionContext;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
@ -98,7 +99,8 @@ class Create extends Base {
return 1;
}
$room = $public ? $this->manager->createPublicRoom($name): $this->manager->createGroupRoom($name);
$roomType = $public ? Room::PUBLIC_CALL : Room::GROUP_CALL;
$room = $this->roomService->createConversation($roomType, $name);
try {
$this->setRoomReadOnly($room, $readonly);

View file

@ -31,6 +31,7 @@ use OCA\Talk\Exceptions\RoomNotFoundException;
use OCA\Talk\Manager;
use OCA\Talk\Participant;
use OCA\Talk\Room;
use OCA\Talk\Service\RoomService;
use OCP\IGroup;
use OCP\IGroupManager;
use OCP\IUser;
@ -42,6 +43,8 @@ use Symfony\Component\Console\Input\InputDefinition;
trait TRoomCommand {
/** @var Manager */
protected $manager;
/** @var RoomService */
protected $roomService;
/** @var IUserManager */
protected $userManager;
@ -49,17 +52,15 @@ trait TRoomCommand {
/** @var IGroupManager */
protected $groupManager;
/**
* TRoomCommand constructor.
*
* @param Manager $manager
* @param IUserManager $userManager
* @param IGroupManager $groupManager
*/
public function __construct(Manager $manager, IUserManager $userManager, IGroupManager $groupManager) {
public function __construct(Manager $manager,
RoomService $roomService,
IUserManager $userManager,
IGroupManager $groupManager) {
parent::__construct();
$this->manager = $manager;
$this->roomService = $roomService;
$this->userManager = $userManager;
$this->groupManager = $groupManager;
}

View file

@ -27,6 +27,8 @@ namespace OCA\Talk\Controller;
use OCA\Talk\Exceptions\RoomNotFoundException;
use OCA\Talk\Files\Util;
use OCA\Talk\Manager;
use OCA\Talk\Room;
use OCA\Talk\Service\RoomService;
use OCA\Talk\TalkSession;
use OCP\AppFramework\Http;
use OCP\AppFramework\Http\DataResponse;
@ -49,6 +51,8 @@ class FilesIntegrationController extends OCSController {
/** @var Manager */
private $manager;
/** @var RoomService */
private $roomService;
/** @var IShareManager */
private $shareManager;
/** @var ISession */
@ -68,6 +72,7 @@ class FilesIntegrationController extends OCSController {
string $appName,
IRequest $request,
Manager $manager,
RoomService $roomService,
IShareManager $shareManager,
ISession $session,
IUserSession $userSession,
@ -78,6 +83,7 @@ class FilesIntegrationController extends OCSController {
) {
parent::__construct($appName, $request);
$this->manager = $manager;
$this->roomService = $roomService;
$this->shareManager = $shareManager;
$this->session = $session;
$this->userSession = $userSession;
@ -149,7 +155,7 @@ class FilesIntegrationController extends OCSController {
} else {
$name = $groupFolder->getName();
}
$room = $this->manager->createPublicRoom($name, 'file', $fileId);
$room = $this->roomService->createConversation(Room::PUBLIC_CALL, $name, null, 'file', $fileId);
}
return new DataResponse([
@ -218,7 +224,7 @@ class FilesIntegrationController extends OCSController {
$room = $this->manager->getRoomByObject('file', $fileId);
} catch (RoomNotFoundException $e) {
$name = $share->getNode()->getName();
$room = $this->manager->createPublicRoom($name, 'file', $fileId);
$room = $this->roomService->createConversation(Room::PUBLIC_CALL, $name, null, 'file', $fileId);
}
} catch (NotFoundException $e) {
return new DataResponse([], Http::STATUS_NOT_FOUND);

View file

@ -24,8 +24,8 @@ declare(strict_types=1);
namespace OCA\Talk\Controller;
use OCA\Talk\Manager;
use OCA\Talk\Participant;
use OCA\Talk\Room;
use OCA\Talk\Service\RoomService;
use OCP\AppFramework\Http;
use OCP\AppFramework\Http\DataResponse;
use OCP\AppFramework\OCSController;
@ -45,8 +45,8 @@ class PublicShareAuthController extends OCSController {
private $shareManager;
/** @var IUserSession */
private $userSession;
/** @var Manager */
private $manager;
/** @var RoomService */
private $roomService;
public function __construct(
string $appName,
@ -54,13 +54,13 @@ class PublicShareAuthController extends OCSController {
IUserManager $userManager,
IShareManager $shareManager,
IUserSession $userSession,
Manager $manager
RoomService $roomService
) {
parent::__construct($appName, $request);
$this->userManager = $userManager;
$this->shareManager = $shareManager;
$this->userSession = $userSession;
$this->manager = $manager;
$this->roomService = $roomService;
}
/**
@ -106,11 +106,7 @@ class PublicShareAuthController extends OCSController {
}
// Create the room
$room = $this->manager->createPublicRoom($roomName, 'share:password', $shareToken);
$room->addUsers([
'userId' => $sharerUser->getUID(),
'participantType' => Participant::OWNER,
]);
$room = $this->roomService->createConversation(Room::PUBLIC_CALL, $roomName, $sharerUser, 'share:password', $shareToken);
$user = $this->userSession->getUser();
$userId = $user instanceof IUser ? $user->getUID() : '';

View file

@ -41,6 +41,7 @@ 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 OCA\Talk\Webinary;
use OCP\App\IAppManager;
@ -72,6 +73,8 @@ class RoomController extends AEnvironmentAwareController {
protected $groupManager;
/** @var Manager */
protected $manager;
/** @var RoomService */
protected $roomService;
/** @var GuestManager */
protected $guestManager;
/** @var ChatManager */
@ -97,6 +100,7 @@ class RoomController extends AEnvironmentAwareController {
IUserManager $userManager,
IGroupManager $groupManager,
Manager $manager,
RoomService $roomService,
GuestManager $guestManager,
ChatManager $chatManager,
IEventDispatcher $dispatcher,
@ -112,6 +116,7 @@ class RoomController extends AEnvironmentAwareController {
$this->userManager = $userManager;
$this->groupManager = $groupManager;
$this->manager = $manager;
$this->roomService = $roomService;
$this->guestManager = $guestManager;
$this->chatManager = $chatManager;
$this->dispatcher = $dispatcher;
@ -581,40 +586,28 @@ class RoomController extends AEnvironmentAwareController {
*
* @NoAdminRequired
*
* @param string $targetUserName
* @param string $targetUserId
* @return DataResponse
*/
protected function createOneToOneRoom(string $targetUserName): DataResponse {
protected function createOneToOneRoom(string $targetUserId): DataResponse {
$currentUser = $this->userManager->get($this->userId);
if (!$currentUser instanceof IUser) {
return new DataResponse([], Http::STATUS_NOT_FOUND);
}
$targetUser = $this->userManager->get($targetUserName);
$targetUser = $this->userManager->get($targetUserId);
if (!$targetUser instanceof IUser) {
return new DataResponse([], Http::STATUS_NOT_FOUND);
}
if ($this->userId === $targetUserName) {
return new DataResponse([], Http::STATUS_FORBIDDEN);
}
// If room exists: Reuse that one, otherwise create a new one.
try {
$room = $this->manager->getOne2OneRoom($this->userId, $targetUser->getUID());
$room->ensureOneToOneRoomIsFilled();
$room = $this->roomService->createOneToOneConversation($currentUser, $targetUser);
return new DataResponse($this->formatRoom($room, $room->getParticipant($currentUser->getUID())), Http::STATUS_OK);
} catch (\InvalidArgumentException $e) {
// Same current and target user
return new DataResponse([], Http::STATUS_FORBIDDEN);
} catch (RoomNotFoundException $e) {
$room = $this->manager->createOne2OneRoom();
$room->addUsers([
'userId' => $currentUser->getUID(),
'participantType' => Participant::OWNER,
], [
'userId' => $targetUser->getUID(),
'participantType' => Participant::OWNER,
]);
return new DataResponse($this->formatRoom($room, $room->getParticipant($currentUser->getUID())), Http::STATUS_CREATED);
return new DataResponse([], Http::STATUS_FORBIDDEN);
}
}
@ -627,23 +620,18 @@ class RoomController extends AEnvironmentAwareController {
* @return DataResponse
*/
protected function createGroupRoom(string $targetGroupName): DataResponse {
$targetGroup = $this->groupManager->get($targetGroupName);
$currentUser = $this->userManager->get($this->userId);
if (!$targetGroup instanceof IGroup) {
return new DataResponse([], Http::STATUS_NOT_FOUND);
}
if (!$currentUser instanceof IUser) {
return new DataResponse([], Http::STATUS_NOT_FOUND);
}
$targetGroup = $this->groupManager->get($targetGroupName);
if (!$targetGroup instanceof IGroup) {
return new DataResponse([], Http::STATUS_NOT_FOUND);
}
// Create the room
$room = $this->manager->createGroupRoom($targetGroup->getGID());
$room->addUsers([
'userId' => $currentUser->getUID(),
'participantType' => Participant::OWNER,
]);
$room = $this->roomService->createConversation(Room::GROUP_CALL, $targetGroup->getDisplayName(), $currentUser);
$usersInGroup = $targetGroup->getUsers();
$participants = [];
@ -676,24 +664,20 @@ class RoomController extends AEnvironmentAwareController {
return new DataResponse([], Http::STATUS_BAD_REQUEST);
}
$currentUser = $this->userManager->get($this->userId);
if (!$currentUser instanceof IUser) {
return new DataResponse([], Http::STATUS_NOT_FOUND);
}
/** @var Circles $circlesApi */
try {
$circle = Circles::detailsCircle($targetCircleId);
} catch (\Exception $e) {
return new DataResponse([], Http::STATUS_NOT_FOUND);
}
$currentUser = $this->userManager->get($this->userId);
if (!$currentUser instanceof IUser) {
return new DataResponse([], Http::STATUS_NOT_FOUND);
}
// Create the room
$room = $this->manager->createGroupRoom($circle->getName());
$room->addUsers([
'userId' => $currentUser->getUID(),
'participantType' => Participant::OWNER,
]);
$room = $this->roomService->createConversation(Room::GROUP_CALL, $circle->getName(), $currentUser);
$participants = [];
foreach ($circle->getMembers() as $member) {
@ -744,14 +728,10 @@ class RoomController extends AEnvironmentAwareController {
// Create the room
if ($public) {
$room = $this->manager->createPublicRoom($roomName);
$room = $this->roomService->createConversation(Room::PUBLIC_CALL, $roomName, $currentUser);
} else {
$room = $this->manager->createGroupRoom($roomName);
$room = $this->roomService->createConversation(Room::GROUP_CALL, $roomName, $currentUser);
}
$room->addUsers([
'userId' => $currentUser->getUID(),
'participantType' => Participant::OWNER,
]);
return new DataResponse($this->formatRoom($room, $room->getParticipant($currentUser->getUID())), Http::STATUS_CREATED);
}

View file

@ -585,35 +585,6 @@ class Manager {
return $this->createRoomObject($row);
}
/**
* @param string $objectType
* @param string $objectId
* @return Room
*/
public function createOne2OneRoom(string $objectType = '', string $objectId = ''): Room {
return $this->createRoom(Room::ONE_TO_ONE_CALL, '', $objectType, $objectId);
}
/**
* @param string $name
* @param string $objectType
* @param string $objectId
* @return Room
*/
public function createGroupRoom(string $name = '', string $objectType = '', string $objectId = ''): Room {
return $this->createRoom(Room::GROUP_CALL, $name, $objectType, $objectId);
}
/**
* @param string $name
* @param string $objectType
* @param string $objectId
* @return Room
*/
public function createPublicRoom(string $name = '', string $objectType = '', string $objectId = ''): Room {
return $this->createRoom(Room::PUBLIC_CALL, $name, $objectType, $objectId);
}
/**
* Makes sure the user is part of a changelog room and returns it
*
@ -656,7 +627,7 @@ class Manager {
* @param string $objectId
* @return Room
*/
private function createRoom(int $type, string $name = '', string $objectType = '', string $objectId = ''): Room {
public function createRoom(int $type, string $name = '', string $objectType = '', string $objectId = ''): Room {
$token = $this->getNewToken();
$query = $this->db->getQueryBuilder();

View file

@ -0,0 +1,87 @@
<?php
declare(strict_types=1);
/**
* @copyright Copyright (c) 2020 Joas Schilling <coding@schilljs.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\Service;
use OCA\Talk\Exceptions\ParticipantNotFoundException;
use OCA\Talk\Exceptions\RoomNotFoundException;
use OCA\Talk\Manager;
use OCA\Talk\Participant;
use OCA\Talk\Room;
use OCP\IUser;
class RoomService {
/** @var Manager */
protected $manager;
public function __construct(Manager $manager) {
$this->manager = $manager;
}
/**
* @param IUser $actor
* @param IUser $targetUser
* @return Room
* @throws InvalidArgumentException when both users are the same
*/
public function createOneToOneConversation(IUser $actor, IUser $targetUser): Room {
if ($actor->getUID() === $targetUser->getUID()) {
throw new \InvalidArgumentException('invalid_invitee');
}
try {
// If room exists: Reuse that one, otherwise create a new one.
$room = $this->manager->getOne2OneRoom($actor->getUID(), $targetUser->getUID());
$room->ensureOneToOneRoomIsFilled();
} catch (RoomNotFoundException $e) {
$room = $this->manager->createRoom(Room::ONE_TO_ONE_CALL);
$room->addUsers([
'userId' => $actor->getUID(),
'participantType' => Participant::OWNER,
], [
'userId' => $targetUser->getUID(),
'participantType' => Participant::OWNER,
]);
}
return $room;
}
public function createConversation(int $type, string $name, ?IUser $owner = null, string $objectType = '', string $objectId = ''): Room {
if ($name === '' || isset($name[255])) {
throw new \InvalidArgumentException('name');
}
$room = $this->manager->createRoom($type, $name, $objectType, $objectId);
if ($owner instanceof IUser) {
$room->addUsers([
'userId' => $owner->getUID(),
'participantType' => Participant::OWNER,
]);
}
return $room;
}
}

View file

@ -30,6 +30,7 @@ use OCA\Talk\Exceptions\RoomNotFoundException;
use OCA\Talk\Manager;
use OCA\Talk\Participant;
use OCA\Talk\Room;
use OCA\Talk\Service\RoomService;
use PHPUnit\Framework\MockObject\MockObject;
use Symfony\Component\Console\Exception\RuntimeException as ConsoleRuntimeException;
use Symfony\Component\Console\Tester\CommandTester;
@ -44,6 +45,9 @@ class AddTest extends TestCase {
/** @var Manager|MockObject */
private $manager;
/** @var RoomService|MockObject */
private $roomService;
/** @var RoomMockContainer */
private $roomMockContainer;
@ -54,7 +58,13 @@ class AddTest extends TestCase {
$this->registerGroupManagerMock();
$this->manager = $this->createMock(Manager::class);
$this->command = new Add($this->manager, $this->userManager, $this->groupManager);
$this->roomService = $this->createMock(RoomService::class);
$this->command = new Add(
$this->manager,
$this->roomService,
$this->userManager,
$this->groupManager
);
$this->roomMockContainer = new RoomMockContainer($this);

View file

@ -29,6 +29,7 @@ use OCA\Talk\Command\Room\Create;
use OCA\Talk\Manager;
use OCA\Talk\Participant;
use OCA\Talk\Room;
use OCA\Talk\Service\RoomService;
use PHPUnit\Framework\MockObject\MockObject;
use Symfony\Component\Console\Exception\RuntimeException as ConsoleRuntimeException;
use Symfony\Component\Console\Tester\CommandTester;
@ -43,6 +44,9 @@ class CreateTest extends TestCase {
/** @var Manager|MockObject */
private $manager;
/** @var RoomService|MockObject */
private $roomService;
/** @var RoomMockContainer */
private $roomMockContainer;
@ -53,7 +57,13 @@ class CreateTest extends TestCase {
$this->registerGroupManagerMock();
$this->manager = $this->createMock(Manager::class);
$this->command = new Create($this->manager, $this->userManager, $this->groupManager);
$this->roomService = $this->createMock(RoomService::class);
$this->command = new Create(
$this->manager,
$this->roomService,
$this->userManager,
$this->groupManager
);
$this->roomMockContainer = new RoomMockContainer($this);
@ -62,11 +72,8 @@ class CreateTest extends TestCase {
}
public function testMissingArguments(): void {
$this->manager->expects($this->never())
->method('createGroupRoom');
$this->manager->expects($this->never())
->method('createPublicRoom');
$this->roomService->expects($this->never())
->method('createConversation');
$this->expectException(ConsoleRuntimeException::class);
$this->expectExceptionMessage('Not enough arguments (missing: "name").');
@ -79,16 +86,10 @@ class CreateTest extends TestCase {
* @dataProvider validProvider
*/
public function testValid(array $input, array $expectedRoomData): void {
$this->manager
->method('createGroupRoom')
->willReturnCallback(function (string $name = ''): Room {
return $this->roomMockContainer->create(['name' => $name, 'type' => Room::GROUP_CALL]);
});
$this->manager
->method('createPublicRoom')
->willReturnCallback(function (string $name = ''): Room {
return $this->roomMockContainer->create(['name' => $name, 'type' => Room::PUBLIC_CALL]);
$this->roomService
->method('createConversation')
->willReturnCallback(function (int $type, string $name): Room {
return $this->roomMockContainer->create(['name' => $name, 'type' => $type]);
});
$tester = new CommandTester($this->command);
@ -286,16 +287,10 @@ class CreateTest extends TestCase {
* @dataProvider invalidProvider
*/
public function testInvalid(array $input, string $expectedOutput): void {
$this->manager
->method('createGroupRoom')
->willReturnCallback(function (string $name = ''): Room {
return $this->roomMockContainer->create(['name' => $name, 'type' => Room::GROUP_CALL]);
});
$this->manager
->method('createPublicRoom')
->willReturnCallback(function (string $name = ''): Room {
return $this->roomMockContainer->create(['name' => $name, 'type' => Room::PUBLIC_CALL]);
$this->roomService
->method('createConversation')
->willReturnCallback(function (int $type, string $name): Room {
return $this->roomMockContainer->create(['name' => $name, 'type' => $type]);
});
$this->roomMockContainer->registerCallback(function (object $room) {

View file

@ -29,6 +29,7 @@ use OCA\Talk\Command\Room\Delete;
use OCA\Talk\Exceptions\RoomNotFoundException;
use OCA\Talk\Manager;
use OCA\Talk\Room;
use OCA\Talk\Service\RoomService;
use PHPUnit\Framework\MockObject\MockObject;
use Symfony\Component\Console\Exception\RuntimeException as ConsoleRuntimeException;
use Symfony\Component\Console\Tester\CommandTester;
@ -43,6 +44,9 @@ class DeleteTest extends TestCase {
/** @var Manager|MockObject */
private $manager;
/** @var RoomService|MockObject */
private $roomService;
/** @var RoomMockContainer */
private $roomMockContainer;
@ -53,7 +57,13 @@ class DeleteTest extends TestCase {
$this->registerGroupManagerMock();
$this->manager = $this->createMock(Manager::class);
$this->command = new Delete($this->manager, $this->userManager, $this->groupManager);
$this->roomService = $this->createMock(RoomService::class);
$this->command = new Delete(
$this->manager,
$this->roomService,
$this->userManager,
$this->groupManager
);
$this->roomMockContainer = new RoomMockContainer($this);
}

View file

@ -30,6 +30,7 @@ use OCA\Talk\Exceptions\RoomNotFoundException;
use OCA\Talk\Manager;
use OCA\Talk\Participant;
use OCA\Talk\Room;
use OCA\Talk\Service\RoomService;
use PHPUnit\Framework\MockObject\MockObject;
use Symfony\Component\Console\Exception\RuntimeException as ConsoleRuntimeException;
use Symfony\Component\Console\Tester\CommandTester;
@ -44,6 +45,9 @@ class DemoteTest extends TestCase {
/** @var Manager|MockObject */
private $manager;
/** @var RoomService|MockObject */
private $roomService;
/** @var RoomMockContainer */
private $roomMockContainer;
@ -54,7 +58,13 @@ class DemoteTest extends TestCase {
$this->registerGroupManagerMock();
$this->manager = $this->createMock(Manager::class);
$this->command = new Demote($this->manager, $this->userManager, $this->groupManager);
$this->roomService = $this->createMock(RoomService::class);
$this->command = new Demote(
$this->manager,
$this->roomService,
$this->userManager,
$this->groupManager
);
$this->roomMockContainer = new RoomMockContainer($this);

View file

@ -30,6 +30,7 @@ use OCA\Talk\Exceptions\RoomNotFoundException;
use OCA\Talk\Manager;
use OCA\Talk\Participant;
use OCA\Talk\Room;
use OCA\Talk\Service\RoomService;
use PHPUnit\Framework\MockObject\MockObject;
use Symfony\Component\Console\Exception\RuntimeException as ConsoleRuntimeException;
use Symfony\Component\Console\Tester\CommandTester;
@ -44,6 +45,9 @@ class PromoteTest extends TestCase {
/** @var Manager|MockObject */
private $manager;
/** @var RoomService|MockObject */
private $roomService;
/** @var RoomMockContainer */
private $roomMockContainer;
@ -54,7 +58,13 @@ class PromoteTest extends TestCase {
$this->registerGroupManagerMock();
$this->manager = $this->createMock(Manager::class);
$this->command = new Promote($this->manager, $this->userManager, $this->groupManager);
$this->roomService = $this->createMock(RoomService::class);
$this->command = new Promote(
$this->manager,
$this->roomService,
$this->userManager,
$this->groupManager
);
$this->roomMockContainer = new RoomMockContainer($this);

View file

@ -30,6 +30,7 @@ use OCA\Talk\Exceptions\RoomNotFoundException;
use OCA\Talk\Manager;
use OCA\Talk\Participant;
use OCA\Talk\Room;
use OCA\Talk\Service\RoomService;
use PHPUnit\Framework\MockObject\MockObject;
use Symfony\Component\Console\Exception\RuntimeException as ConsoleRuntimeException;
use Symfony\Component\Console\Tester\CommandTester;
@ -44,6 +45,9 @@ class RemoveTest extends TestCase {
/** @var Manager|MockObject */
private $manager;
/** @var RoomService|MockObject */
private $roomService;
/** @var RoomMockContainer */
private $roomMockContainer;
@ -54,7 +58,13 @@ class RemoveTest extends TestCase {
$this->registerGroupManagerMock();
$this->manager = $this->createMock(Manager::class);
$this->command = new Remove($this->manager, $this->userManager, $this->groupManager);
$this->roomService = $this->createMock(RoomService::class);
$this->command = new Remove(
$this->manager,
$this->roomService,
$this->userManager,
$this->groupManager
);
$this->roomMockContainer = new RoomMockContainer($this);

View file

@ -30,6 +30,7 @@ use OCA\Talk\Exceptions\RoomNotFoundException;
use OCA\Talk\Manager;
use OCA\Talk\Participant;
use OCA\Talk\Room;
use OCA\Talk\Service\RoomService;
use PHPUnit\Framework\MockObject\MockObject;
use Symfony\Component\Console\Exception\RuntimeException as ConsoleRuntimeException;
use Symfony\Component\Console\Tester\CommandTester;
@ -44,6 +45,9 @@ class UpdateTest extends TestCase {
/** @var Manager|MockObject */
private $manager;
/** @var RoomService|MockObject */
private $roomService;
/** @var RoomMockContainer */
private $roomMockContainer;
@ -54,7 +58,13 @@ class UpdateTest extends TestCase {
$this->registerGroupManagerMock();
$this->manager = $this->createMock(Manager::class);
$this->command = new Update($this->manager, $this->userManager, $this->groupManager);
$this->roomService = $this->createMock(RoomService::class);
$this->command = new Update(
$this->manager,
$this->roomService,
$this->userManager,
$this->groupManager
);
$this->roomMockContainer = new RoomMockContainer($this);

View file

@ -31,6 +31,7 @@ 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;
@ -59,6 +60,8 @@ class RoomControllerTest extends TestCase {
protected $groupManager;
/** @var Manager|MockObject */
protected $manager;
/** @var RoomService|MockObject */
protected $roomService;
/** @var ChatManager|MockObject */
protected $chatManager;
/** @var GuestManager|MockObject */
@ -86,6 +89,7 @@ class RoomControllerTest extends TestCase {
$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->chatManager = $this->createMock(ChatManager::class);
$this->dispatcher = $this->createMock(IEventDispatcher::class);
@ -111,6 +115,7 @@ class RoomControllerTest extends TestCase {
$this->userManager,
$this->groupManager,
$this->manager,
$this->roomService,
$this->guestManager,
$this->chatManager,
$this->dispatcher,

View file

@ -888,7 +888,7 @@ class SignalingControllerTest extends \Test\TestCase {
->method('getUID')
->willReturn($this->userId);
$room = $this->manager->createPublicRoom();
$room = $this->manager->createRoom(Room::PUBLIC_CALL);
// The user joined the room.
$oldSessionId = $room->joinRoom($testUser, '');

View file

@ -206,7 +206,7 @@ class BackendNotifierTest extends \Test\TestCase {
}
public function testRoomInvite() {
$room = $this->manager->createPublicRoom();
$room = $this->manager->createRoom(Room::PUBLIC_CALL);
$room->addUsers([
'userId' => $this->userId,
]);
@ -233,7 +233,7 @@ class BackendNotifierTest extends \Test\TestCase {
}
public function testRoomDisinvite() {
$room = $this->manager->createPublicRoom();
$room = $this->manager->createRoom(Room::PUBLIC_CALL);
$room->addUsers([
'userId' => $this->userId,
]);
@ -266,7 +266,7 @@ class BackendNotifierTest extends \Test\TestCase {
}
public function testRoomNameChanged() {
$room = $this->manager->createPublicRoom();
$room = $this->manager->createRoom(Room::PUBLIC_CALL);
$room->setName('Test room');
$this->assertMessageWasSent($room, [
@ -287,7 +287,7 @@ class BackendNotifierTest extends \Test\TestCase {
}
public function testRoomPasswordChanged() {
$room = $this->manager->createPublicRoom();
$room = $this->manager->createRoom(Room::PUBLIC_CALL);
$room->setPassword('password');
$this->assertMessageWasSent($room, [
@ -308,7 +308,7 @@ class BackendNotifierTest extends \Test\TestCase {
}
public function testRoomTypeChanged() {
$room = $this->manager->createPublicRoom();
$room = $this->manager->createRoom(Room::PUBLIC_CALL);
$room->setType(Room::GROUP_CALL);
$this->assertMessageWasSent($room, [
@ -329,7 +329,7 @@ class BackendNotifierTest extends \Test\TestCase {
}
public function testRoomReadOnlyChanged() {
$room = $this->manager->createPublicRoom();
$room = $this->manager->createRoom(Room::PUBLIC_CALL);
$room->setReadOnly(Room::READ_ONLY);
$this->assertMessageWasSent($room, [
@ -350,7 +350,7 @@ class BackendNotifierTest extends \Test\TestCase {
}
public function testRoomLobbyStateChanged() {
$room = $this->manager->createPublicRoom();
$room = $this->manager->createRoom(Room::PUBLIC_CALL);
$room->setLobby(Webinary::LOBBY_NON_MODERATORS, null);
$this->assertMessageWasSent($room, [
@ -371,7 +371,7 @@ class BackendNotifierTest extends \Test\TestCase {
}
public function testRoomDelete() {
$room = $this->manager->createPublicRoom();
$room = $this->manager->createRoom(Room::PUBLIC_CALL);
$room->addUsers([
'userId' => $this->userId,
]);
@ -388,7 +388,7 @@ class BackendNotifierTest extends \Test\TestCase {
}
public function testRoomInCallChanged() {
$room = $this->manager->createPublicRoom();
$room = $this->manager->createRoom(Room::PUBLIC_CALL);
$userSession = 'user-session';
$room->addUsers([
'userId' => $this->userId,
@ -494,7 +494,7 @@ class BackendNotifierTest extends \Test\TestCase {
$this->dispatcher->addListener(Room::EVENT_BEFORE_SIGNALING_PROPERTIES, $listener);
$room = $this->manager->createPublicRoom();
$room = $this->manager->createRoom(Room::PUBLIC_CALL);
$this->controller->clearRequests();
$room->setName('Test room');
@ -518,7 +518,7 @@ class BackendNotifierTest extends \Test\TestCase {
}
public function testParticipantsTypeChanged() {
$room = $this->manager->createPublicRoom();
$room = $this->manager->createRoom(Room::PUBLIC_CALL);
$userSession = 'user-session';
$room->addUsers([
'userId' => $this->userId,