UPSTREAM BASELINE: nextcloud/spreed v22.0.12 (без изменений)
Type checking / changes (push) Has been cancelled
Type checking / test (push) Has been cancelled
Type checking / typescript-summary (push) Has been cancelled
Node tests / changes (push) Has been cancelled
Node tests / test (push) Has been cancelled
Node tests / test-summary (push) Has been cancelled
Type checking / changes (push) Has been cancelled
Type checking / test (push) Has been cancelled
Type checking / typescript-summary (push) Has been cancelled
Node tests / changes (push) Has been cancelled
Node tests / test (push) Has been cancelled
Node tests / test-summary (push) Has been cancelled
Источник: https://github.com/nextcloud/spreed/archive/refs/tags/v22.0.12.tar.gz С этого коммита ветка официального Nextcloud Talk отрезана (решение владельца 2026-07-06). Все дальнейшие изменения — только наши; версии релизов: 22.0.12-f7.N.
This commit is contained in:
@@ -0,0 +1,200 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* SPDX-FileCopyrightText: 2020 Nextcloud GmbH and Nextcloud contributors
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
*/
|
||||
|
||||
namespace OCA\Talk\Tests\BackgroundJob;
|
||||
|
||||
use OCA\Talk\BackgroundJob\CheckHostedSignalingServer;
|
||||
use OCA\Talk\Config;
|
||||
use OCA\Talk\Service\HostedSignalingServerService;
|
||||
use OCP\AppFramework\Utility\ITimeFactory;
|
||||
use OCP\IConfig;
|
||||
use OCP\IGroup;
|
||||
use OCP\IGroupManager;
|
||||
use OCP\IURLGenerator;
|
||||
use OCP\Notification\IManager;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Test\TestCase;
|
||||
|
||||
class CheckHostedSignalingServerTest extends TestCase {
|
||||
protected ITimeFactory&MockObject $timeFactory;
|
||||
protected HostedSignalingServerService&MockObject $hostedSignalingServerService;
|
||||
protected IConfig&MockObject $config;
|
||||
protected IManager&MockObject $notificationManager;
|
||||
protected IGroupManager&MockObject $groupManager;
|
||||
protected IURLGenerator&MockObject $urlGenerator;
|
||||
protected LoggerInterface&MockObject $logger;
|
||||
protected Config&MockObject $talkConfig;
|
||||
|
||||
public function setUp(): void {
|
||||
parent::setUp();
|
||||
|
||||
$this->timeFactory = $this->createMock(ITimeFactory::class);
|
||||
$this->hostedSignalingServerService = $this->createMock(HostedSignalingServerService::class);
|
||||
$this->config = $this->createMock(IConfig::class);
|
||||
$this->notificationManager = $this->createMock(IManager::class);
|
||||
$this->groupManager = $this->createMock(IGroupManager::class);
|
||||
$this->urlGenerator = $this->createMock(IURLGenerator::class);
|
||||
$this->logger = $this->createMock(LoggerInterface::class);
|
||||
$this->talkConfig = $this->createMock(Config::class);
|
||||
}
|
||||
|
||||
public function getBackgroundJob(): CheckHostedSignalingServer {
|
||||
return new CheckHostedSignalingServer(
|
||||
$this->timeFactory,
|
||||
$this->hostedSignalingServerService,
|
||||
$this->config,
|
||||
$this->notificationManager,
|
||||
$this->groupManager,
|
||||
$this->urlGenerator,
|
||||
$this->logger,
|
||||
$this->talkConfig
|
||||
);
|
||||
}
|
||||
|
||||
public function testRunWithNoChange(): void {
|
||||
$backgroundJob = $this->getBackgroundJob();
|
||||
|
||||
$this->config
|
||||
->method('getAppValue')
|
||||
->willReturnMap([
|
||||
['spreed', 'hosted-signaling-server-account-id', '', 'my-account-id'],
|
||||
['spreed', 'hosted-signaling-server-account', '{}', '{"status": "pending"}']
|
||||
]);
|
||||
|
||||
$this->hostedSignalingServerService->expects($this->once())
|
||||
->method('fetchAccountInfo')
|
||||
->willReturn(['status' => 'pending']);
|
||||
|
||||
self::invokePrivate($backgroundJob, 'run', ['']);
|
||||
}
|
||||
|
||||
public function testRunWithPendingToActiveChange(): void {
|
||||
$backgroundJob = $this->getBackgroundJob();
|
||||
$newStatus = [
|
||||
'status' => 'active',
|
||||
'signaling' => [
|
||||
'url' => 'signaling-url',
|
||||
'secret' => 'signaling-secret',
|
||||
],
|
||||
];
|
||||
|
||||
$this->config
|
||||
->method('getAppValue')
|
||||
->willReturnMap([
|
||||
['spreed', 'hosted-signaling-server-account-id', '', 'my-account-id'],
|
||||
['spreed', 'hosted-signaling-server-account', '{}', '{"status": "pending"}']
|
||||
]);
|
||||
$this->config->expects($this->once())
|
||||
->method('deleteAppValue')
|
||||
->with('spreed', 'signaling_mode');
|
||||
|
||||
$expectedCalls = [
|
||||
['spreed', 'signaling_servers', '{"servers":[{"server":"signaling-url","verify":true}],"secret":"signaling-secret"}'],
|
||||
['spreed', 'hosted-signaling-server-account', json_encode($newStatus)],
|
||||
];
|
||||
|
||||
$i = 0;
|
||||
$this->config->expects($this->exactly(count($expectedCalls)))
|
||||
->method('setAppValue')
|
||||
->willReturnCallback(function () use ($expectedCalls, &$i): void {
|
||||
$this->assertArrayHasKey($i, $expectedCalls);
|
||||
$this->assertSame($expectedCalls[$i], func_get_args());
|
||||
$i++;
|
||||
});
|
||||
|
||||
$group = $this->createMock(IGroup::class);
|
||||
$this->groupManager->expects($this->once())
|
||||
->method('get')
|
||||
->with('admin')
|
||||
->willReturn($group);
|
||||
$group->expects($this->once())
|
||||
->method('getUsers')
|
||||
->willReturn([]);
|
||||
|
||||
$this->hostedSignalingServerService->expects($this->once())
|
||||
->method('fetchAccountInfo')
|
||||
->willReturn($newStatus);
|
||||
|
||||
self::invokePrivate($backgroundJob, 'run', ['']);
|
||||
}
|
||||
|
||||
public function testRunWithPendingToActiveIncludingStunAndTurn(): void {
|
||||
$backgroundJob = $this->getBackgroundJob();
|
||||
$newStatus = [
|
||||
'status' => 'active',
|
||||
'signaling' => [
|
||||
'url' => 'signaling-url',
|
||||
'secret' => 'signaling-secret',
|
||||
],
|
||||
'stun' => [
|
||||
'servers' => [
|
||||
'stun.domain.invalid:443',
|
||||
'stun.domain.invalid:3478',
|
||||
],
|
||||
],
|
||||
'turn' => [
|
||||
'servers' => [
|
||||
[
|
||||
'server' => 'turn1.domain.invalid:443',
|
||||
'secret' => 'turn-secret',
|
||||
'schemes' => ['turns', 'turn'],
|
||||
'protocols' => ['tcp', 'udp'],
|
||||
],
|
||||
[
|
||||
'server' => 'turn2.domain.invalid:443',
|
||||
'secret' => 'other-turn-secret',
|
||||
'schemes' => ['turns'],
|
||||
'protocols' => ['tcp'],
|
||||
],
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
$this->config
|
||||
->method('getAppValue')
|
||||
->willReturnMap([
|
||||
['spreed', 'hosted-signaling-server-account-id', '', 'my-account-id'],
|
||||
['spreed', 'hosted-signaling-server-account', '{}', '{"status": "pending"}']
|
||||
]);
|
||||
$this->config->expects($this->once())
|
||||
->method('deleteAppValue')
|
||||
->with('spreed', 'signaling_mode');
|
||||
|
||||
$expectedCalls = [
|
||||
['spreed', 'signaling_servers', '{"servers":[{"server":"signaling-url","verify":true}],"secret":"signaling-secret"}'],
|
||||
['spreed', 'stun_servers', '["stun.domain.invalid:443","stun.domain.invalid:3478"]'],
|
||||
['spreed', 'turn_servers', '[{"server":"turn1.domain.invalid:443","secret":"turn-secret","schemes":"turn,turns","protocols":"udp,tcp"},{"server":"turn2.domain.invalid:443","secret":"other-turn-secret","schemes":"turns","protocols":"tcp"}]'],
|
||||
['spreed', 'hosted-signaling-server-account', json_encode($newStatus)],
|
||||
];
|
||||
|
||||
$i = 0;
|
||||
$this->config->expects($this->exactly(count($expectedCalls)))
|
||||
->method('setAppValue')
|
||||
->willReturnCallback(function () use ($expectedCalls, &$i): void {
|
||||
$this->assertArrayHasKey($i, $expectedCalls);
|
||||
$this->assertSame($expectedCalls[$i], func_get_args());
|
||||
$i++;
|
||||
});
|
||||
|
||||
$group = $this->createMock(IGroup::class);
|
||||
$this->groupManager->expects($this->once())
|
||||
->method('get')
|
||||
->with('admin')
|
||||
->willReturn($group);
|
||||
$group->expects($this->once())
|
||||
->method('getUsers')
|
||||
->willReturn([]);
|
||||
|
||||
$this->hostedSignalingServerService->expects($this->once())
|
||||
->method('fetchAccountInfo')
|
||||
->willReturn($newStatus);
|
||||
|
||||
self::invokePrivate($backgroundJob, 'run', ['']);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,153 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
*/
|
||||
|
||||
namespace OCA\Talk\Tests\BackgroundJob;
|
||||
|
||||
use OCA\Talk\BackgroundJob\LockInactiveRooms;
|
||||
use OCA\Talk\Config;
|
||||
use OCA\Talk\Room;
|
||||
use OCA\Talk\Service\RoomService;
|
||||
use OCP\AppFramework\Utility\ITimeFactory;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Test\TestCase;
|
||||
|
||||
class LockInactiveRoomsTest extends TestCase {
|
||||
protected ITimeFactory&MockObject $timeFactory;
|
||||
protected RoomService&MockObject $roomService;
|
||||
private Config&MockObject $appConfig;
|
||||
protected LoggerInterface&MockObject $logger;
|
||||
private LockInactiveRooms $job;
|
||||
|
||||
public function setUp(): void {
|
||||
parent::setUp();
|
||||
|
||||
$this->timeFactory = $this->createMock(ITimeFactory::class);
|
||||
$this->roomService = $this->createMock(RoomService::class);
|
||||
$this->appConfig = $this->createMock(Config::class);
|
||||
$this->logger = $this->createMock(LoggerInterface::class);
|
||||
$this->job = new LockInactiveRooms($this->timeFactory,
|
||||
$this->roomService,
|
||||
$this->appConfig,
|
||||
$this->logger
|
||||
);
|
||||
}
|
||||
|
||||
public function testNotEnabled(): void {
|
||||
$this->appConfig->expects(self::once())
|
||||
->method('getInactiveLockTime')
|
||||
->willReturn(0);
|
||||
$this->appConfig->expects(self::once())
|
||||
->method('enableLobbyOnLockedRooms')
|
||||
->willReturn(false);
|
||||
$this->timeFactory->expects(self::never())
|
||||
->method(self::anything());
|
||||
$this->roomService->expects(self::never())
|
||||
->method(self::anything());
|
||||
$this->logger->expects(self::never())
|
||||
->method(self::anything());
|
||||
|
||||
$this->job->run('t');
|
||||
}
|
||||
|
||||
public function testNoRooms(): void {
|
||||
$this->appConfig->expects(self::once())
|
||||
->method('getInactiveLockTime')
|
||||
->willReturn(123);
|
||||
$this->appConfig->expects(self::once())
|
||||
->method('enableLobbyOnLockedRooms')
|
||||
->willReturn(false);
|
||||
$this->timeFactory->expects(self::once())
|
||||
->method('getTime');
|
||||
$this->timeFactory->expects(self::once())
|
||||
->method('getDateTime');
|
||||
$this->roomService->expects(self::once())
|
||||
->method('getInactiveRooms')
|
||||
->willReturn([]);
|
||||
$this->roomService->expects(self::never())
|
||||
->method('setReadOnly');
|
||||
$this->roomService->expects(self::never())
|
||||
->method('setLobby');
|
||||
$this->logger->expects(self::never())
|
||||
->method(self::anything());
|
||||
|
||||
$this->job->run('t');
|
||||
|
||||
}
|
||||
|
||||
public function testLockRooms(): void {
|
||||
$rooms = [
|
||||
$this->createConfiguredMock(Room::class, [
|
||||
'getReadOnly' => 0,
|
||||
'getType' => Room::TYPE_PUBLIC,
|
||||
]),
|
||||
$this->createConfiguredMock(Room::class, [
|
||||
'getReadOnly' => 0,
|
||||
'getType' => Room::TYPE_GROUP,
|
||||
]),
|
||||
];
|
||||
|
||||
$this->appConfig->expects(self::once())
|
||||
->method('getInactiveLockTime')
|
||||
->willReturn(123);
|
||||
$this->appConfig->expects(self::once())
|
||||
->method('enableLobbyOnLockedRooms')
|
||||
->willReturn(false);
|
||||
$this->timeFactory->expects(self::once())
|
||||
->method('getTime');
|
||||
$this->timeFactory->expects(self::once())
|
||||
->method('getDateTime');
|
||||
$this->roomService->expects(self::once())
|
||||
->method('getInactiveRooms')
|
||||
->willReturn($rooms);
|
||||
$this->roomService->expects(self::exactly(2))
|
||||
->method('setReadOnly');
|
||||
$this->roomService->expects(self::never())
|
||||
->method('setLobby');
|
||||
$this->logger->expects(self::exactly(2))
|
||||
->method('debug');
|
||||
|
||||
$this->job->run('t');
|
||||
|
||||
}
|
||||
|
||||
public function testLockRoomsAndEnableLobby(): void {
|
||||
$rooms = [
|
||||
$this->createConfiguredMock(Room::class, [
|
||||
'getReadOnly' => 0,
|
||||
'getType' => Room::TYPE_PUBLIC,
|
||||
]),
|
||||
$this->createConfiguredMock(Room::class, [
|
||||
'getReadOnly' => 0,
|
||||
'getType' => Room::TYPE_GROUP,
|
||||
]),
|
||||
];
|
||||
|
||||
$this->appConfig->expects(self::once())
|
||||
->method('getInactiveLockTime')
|
||||
->willReturn(123);
|
||||
$this->appConfig->expects(self::once())
|
||||
->method('enableLobbyOnLockedRooms')
|
||||
->willReturn(true);
|
||||
$this->timeFactory->expects(self::once())
|
||||
->method('getTime');
|
||||
$this->timeFactory->expects(self::any())
|
||||
->method('getDateTime');
|
||||
$this->roomService->expects(self::once())
|
||||
->method('getInactiveRooms')
|
||||
->willReturn($rooms);
|
||||
$this->roomService->expects(self::exactly(2))
|
||||
->method('setReadOnly');
|
||||
$this->roomService->expects(self::exactly(2))
|
||||
->method('setLobby');
|
||||
$this->logger->expects(self::exactly(4))
|
||||
->method('debug');
|
||||
|
||||
$this->job->run('t');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,163 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* SPDX-FileCopyrightText: 2021 Nextcloud GmbH and Nextcloud contributors
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
*/
|
||||
|
||||
namespace OCA\Talk\Tests\BackgroundJob;
|
||||
|
||||
use OCA\Talk\BackgroundJob\RemoveEmptyRooms;
|
||||
use OCA\Talk\Federation\FederationManager;
|
||||
use OCA\Talk\Manager;
|
||||
use OCA\Talk\Room;
|
||||
use OCA\Talk\Service\ParticipantService;
|
||||
use OCA\Talk\Service\RoomService;
|
||||
use OCP\AppFramework\Utility\ITimeFactory;
|
||||
use OCP\Files\Config\IUserMountCache;
|
||||
use PHPUnit\Framework\Attributes\DataProvider;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Test\TestCase;
|
||||
|
||||
class RemoveEmptyRoomsTest extends TestCase {
|
||||
protected ITimeFactory&MockObject $timeFactory;
|
||||
protected Manager&MockObject $manager;
|
||||
protected RoomService&MockObject $roomService;
|
||||
protected ParticipantService&MockObject $participantService;
|
||||
protected FederationManager&MockObject $federationManager;
|
||||
protected LoggerInterface&MockObject $loggerInterface;
|
||||
protected IUserMountCache&MockObject $userMountCache;
|
||||
|
||||
public function setUp(): void {
|
||||
parent::setUp();
|
||||
|
||||
$this->timeFactory = $this->createMock(ITimeFactory::class);
|
||||
$this->manager = $this->createMock(Manager::class);
|
||||
$this->roomService = $this->createMock(RoomService::class);
|
||||
$this->participantService = $this->createMock(ParticipantService::class);
|
||||
$this->federationManager = $this->createMock(FederationManager::class);
|
||||
$this->loggerInterface = $this->createMock(LoggerInterface::class);
|
||||
$this->userMountCache = $this->createMock(IUserMountCache::class);
|
||||
}
|
||||
|
||||
public function getBackgroundJob(): RemoveEmptyRooms {
|
||||
return new RemoveEmptyRooms(
|
||||
$this->timeFactory,
|
||||
$this->manager,
|
||||
$this->roomService,
|
||||
$this->participantService,
|
||||
$this->federationManager,
|
||||
$this->loggerInterface,
|
||||
$this->userMountCache,
|
||||
);
|
||||
}
|
||||
|
||||
public function testDoDeleteRoom(): void {
|
||||
$backgroundJob = $this->getBackgroundJob();
|
||||
|
||||
$room = $this->createMock(Room::class);
|
||||
$room->method('getType')
|
||||
->willReturn(Room::TYPE_GROUP);
|
||||
$numDeletedRooms = self::invokePrivate($backgroundJob, 'numDeletedRooms');
|
||||
$this->assertEquals(0, $numDeletedRooms, 'Invalid default quantity of rooms');
|
||||
|
||||
self::invokePrivate($backgroundJob, 'doDeleteRoom', [$room]);
|
||||
|
||||
$numDeletedRooms = self::invokePrivate($backgroundJob, 'numDeletedRooms');
|
||||
$this->assertEquals(1, $numDeletedRooms, 'Invalid final quantity of rooms');
|
||||
}
|
||||
|
||||
public static function dataDeleteIfFileIsRemoved(): array {
|
||||
return [
|
||||
['', [], 0],
|
||||
['email', [], 0],
|
||||
['file', ['fileExists'], 0],
|
||||
['file', [], 1],
|
||||
];
|
||||
}
|
||||
|
||||
#[DataProvider('dataDeleteIfFileIsRemoved')]
|
||||
public function testDeleteIfFileIsRemoved(string $objectType, array $fileList, int $numDeletedRoomsExpected): void {
|
||||
$backgroundJob = $this->getBackgroundJob();
|
||||
|
||||
$numDeletedRoomsActual = self::invokePrivate($backgroundJob, 'numDeletedRooms');
|
||||
$this->assertEquals(0, $numDeletedRoomsActual, 'Invalid default quantity of rooms');
|
||||
|
||||
$room = $this->createMock(Room::class);
|
||||
$room->method('getType')
|
||||
->willReturn(Room::TYPE_GROUP);
|
||||
$room->method('getObjectType')
|
||||
->willReturn($objectType);
|
||||
|
||||
$userMountCache = self::invokePrivate($backgroundJob, 'userMountCache');
|
||||
$userMountCache->method('getMountsForFileId')
|
||||
->willReturn($fileList);
|
||||
|
||||
self::invokePrivate($backgroundJob, 'deleteIfFileIsRemoved', [$room]);
|
||||
|
||||
$numDeletedRoomsActual = self::invokePrivate($backgroundJob, 'numDeletedRooms');
|
||||
$this->assertEquals($numDeletedRoomsExpected, $numDeletedRoomsActual, 'Invalid final quantity of rooms');
|
||||
}
|
||||
|
||||
public static function dataDeleteIfIsEmpty(): array {
|
||||
return [
|
||||
'room with user' => ['', 1, 0, 0],
|
||||
'room with fed invite' => ['', 0, 1, 0],
|
||||
'room to delete' => ['', 0, 0, 1],
|
||||
'file room with user' => ['file', 1, 0, 0],
|
||||
'email room with user' => ['email', 1, 0, 0],
|
||||
'email room without user' => ['email', 0, 0, 1]
|
||||
];
|
||||
}
|
||||
|
||||
#[DataProvider('dataDeleteIfIsEmpty')]
|
||||
public function testDeleteIfIsEmpty(string $objectType, int $actorsCount, int $inviteCount, int $numDeletedRoomsExpected): void {
|
||||
$backgroundJob = $this->getBackgroundJob();
|
||||
|
||||
$numDeletedRoomsActual = self::invokePrivate($backgroundJob, 'numDeletedRooms');
|
||||
$this->assertEquals(0, $numDeletedRoomsActual, 'Invalid default quantity of rooms');
|
||||
|
||||
$room = $this->createMock(Room::class);
|
||||
$room->method('getType')
|
||||
->willReturn(Room::TYPE_GROUP);
|
||||
$room->method('getObjectType')
|
||||
->willReturn($objectType);
|
||||
$room->method('isFederatedConversation')
|
||||
->willReturn($inviteCount > 0);
|
||||
|
||||
$this->federationManager->method('getNumberOfInvitations')
|
||||
->with($room)
|
||||
->willReturn($inviteCount);
|
||||
|
||||
$participantService = self::invokePrivate($backgroundJob, 'participantService');
|
||||
$participantService->method('getNumberOfActors')
|
||||
->willReturn($actorsCount);
|
||||
|
||||
self::invokePrivate($backgroundJob, 'deleteIfIsEmpty', [$room]);
|
||||
|
||||
$numDeletedRoomsActual = self::invokePrivate($backgroundJob, 'numDeletedRooms');
|
||||
$this->assertEquals($numDeletedRoomsExpected, $numDeletedRoomsActual, 'Invalid final quantity of rooms');
|
||||
}
|
||||
|
||||
#[DataProvider('dataCallback')]
|
||||
public function testCallback(int $roomType, string $objectType, int $numDeletedRoomsExpected): void {
|
||||
$backgroundJob = $this->getBackgroundJob();
|
||||
$room = $this->createMock(Room::class);
|
||||
$room->method('getType')
|
||||
->willReturn($roomType);
|
||||
$room->method('getObjectType')
|
||||
->willReturn($objectType);
|
||||
$backgroundJob->callback($room);
|
||||
$numDeletedRoomsActual = self::invokePrivate($backgroundJob, 'numDeletedRooms');
|
||||
$this->assertEquals($numDeletedRoomsExpected, $numDeletedRoomsActual, 'Invalid final quantity of rooms');
|
||||
}
|
||||
|
||||
public static function dataCallback(): array {
|
||||
return [
|
||||
[Room::TYPE_CHANGELOG, '', 0],
|
||||
[Room::TYPE_GROUP, 'file', 1],
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user