mimeTypeDetector = \OCP\Server::get(IMimeTypeDetector::class); $this->participantService = $this->createMock(ParticipantService::class); $this->rootFolder = $this->createMock(IRootFolder::class); $this->notificationManager = $this->createMock(IManager::class); $this->roomManager = $this->createMock(Manager::class); $this->timeFactory = $this->createMock(ITimeFactory::class); $this->config = $this->createMock(Config::class); $this->serverConfig = $this->createMock(IConfig::class); $this->appConfig = $this->createMock(IAppConfig::class); $this->roomService = $this->createMock(RoomService::class); $this->shareManager = $this->createMock(ShareManager::class); $this->chatManager = $this->createMock(ChatManager::class); $this->logger = $this->createMock(LoggerInterface::class); $this->backendNotifier = $this->createMock(BackendNotifier::class); $this->taskProcessingManager = $this->createMock(ITaskProcessingManager::class); $this->l10nFactory = $this->createMock(IFactory::class); $this->userManager = $this->createMock(IUserManager::class); $this->recordingService = new RecordingService( $this->mimeTypeDetector, $this->participantService, $this->rootFolder, $this->notificationManager, $this->roomManager, $this->timeFactory, $this->config, $this->serverConfig, $this->appConfig, $this->roomService, $this->shareManager, $this->chatManager, $this->logger, $this->backendNotifier, $this->taskProcessingManager, $this->l10nFactory, $this->userManager, ); } public static function dataValidateFileFormat(): array { return [ # file_invalid_path ['', '', 'file_invalid_path'], # file_mimetype ['', realpath(__DIR__ . '/../../../img/app.svg'), 'file_mimetype'], ['name.ogg', realpath(__DIR__ . '/../../../img/app.svg'), 'file_mimetype'], # file_extension ['', realpath(__DIR__ . '/../../../img/join_call.ogg'), 'file_extension'], ['name', realpath(__DIR__ . '/../../../img/join_call.ogg'), 'file_extension'], ['name.mp3', realpath(__DIR__ . '/../../../img/join_call.ogg'), 'file_extension'], # Success ['name.ogg', realpath(__DIR__ . '/../../../img/join_call.ogg'), ''], ]; } #[DataProvider('dataValidateFileFormat')] public function testValidateFileFormat(string $fileName, string $fileRealPath, string $exceptionMessage): void { if ($exceptionMessage) { $this->expectExceptionMessage($exceptionMessage); } else { $this->expectNotToPerformAssertions(); } $this->recordingService->validateFileFormat($fileName, $fileRealPath); } public static function dataGetResourceFromFileArray(): array { $fileWithContent = tempnam(sys_get_temp_dir(), 'txt'); file_put_contents($fileWithContent, 'bla'); return [ [['error' => 1, 'tmp_name' => ''], '', 'invalid_file'], [['error' => 1, 'tmp_name' => 'a'], '', 'invalid_file'], # Empty file [['error' => 0, 'tmp_name' => tempnam(sys_get_temp_dir(), 'txt')], '', 'empty_file'], # file with content [['error' => 0, 'tmp_name' => $fileWithContent], 'bla', ''], ]; } #[DataProvider('dataGetResourceFromFileArray')] public function testGetResourceFromFileArray(array $file, string $expected, string $exceptionMessage): void { if ($exceptionMessage) { $this->expectExceptionMessage($exceptionMessage); } $room = $this->createMock(Room::class); $attendee = Attendee::fromRow([ 'actor_type' => Attendee::ACTOR_USERS, 'actor_id' => 'participant1', ]); $participant = new Participant($room, $attendee, null); $actual = stream_get_contents($this->recordingService->getResourceFromFileArray($file, $room, $participant)); $this->assertEquals($expected, $actual); } }