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,235 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* SPDX-FileCopyrightText: 2017 Nextcloud GmbH and Nextcloud contributors
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
*/
|
||||
|
||||
namespace OCA\Talk\Tests\php\Activity\Provider;
|
||||
|
||||
use OCA\Talk\Activity\Provider\Base;
|
||||
use OCA\Talk\Config;
|
||||
use OCA\Talk\Manager;
|
||||
use OCA\Talk\Room;
|
||||
use OCA\Talk\Service\AvatarService;
|
||||
use OCA\Talk\Service\ParticipantService;
|
||||
use OCP\Activity\Exceptions\UnknownActivityException;
|
||||
use OCP\Activity\IEvent;
|
||||
use OCP\Activity\IManager;
|
||||
use OCP\Federation\ICloudIdManager;
|
||||
use OCP\IURLGenerator;
|
||||
use OCP\IUser;
|
||||
use OCP\IUserManager;
|
||||
use OCP\L10N\IFactory;
|
||||
use PHPUnit\Framework\Attributes\DataProvider;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use Test\TestCase;
|
||||
|
||||
/**
|
||||
* Class BaseTest
|
||||
*
|
||||
* @package OCA\Talk\Tests\php\Activity
|
||||
*/
|
||||
class BaseTest extends TestCase {
|
||||
protected IFactory&MockObject $l10nFactory;
|
||||
protected IURLGenerator&MockObject $url;
|
||||
protected Config&MockObject $config;
|
||||
protected IManager&MockObject $activityManager;
|
||||
protected IUserManager&MockObject $userManager;
|
||||
protected ICloudIdManager&MockObject $cloudIdManager;
|
||||
protected ParticipantService&MockObject $participantService;
|
||||
protected AvatarService&MockObject $avatarService;
|
||||
protected Manager&MockObject $manager;
|
||||
|
||||
public function setUp(): void {
|
||||
parent::setUp();
|
||||
|
||||
$this->l10nFactory = $this->createMock(IFactory::class);
|
||||
$this->url = $this->createMock(IURLGenerator::class);
|
||||
$this->config = $this->createMock(Config::class);
|
||||
$this->activityManager = $this->createMock(IManager::class);
|
||||
$this->userManager = $this->createMock(IUserManager::class);
|
||||
$this->cloudIdManager = $this->createMock(ICloudIdManager::class);
|
||||
$this->participantService = $this->createMock(ParticipantService::class);
|
||||
$this->avatarService = $this->createMock(AvatarService::class);
|
||||
$this->manager = $this->createMock(Manager::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string[] $methods
|
||||
*/
|
||||
protected function getProvider(array $methods = []): Base&MockObject {
|
||||
$methods[] = 'parse';
|
||||
return $this->getMockBuilder(Base::class)
|
||||
->setConstructorArgs([
|
||||
$this->l10nFactory,
|
||||
$this->url,
|
||||
$this->config,
|
||||
$this->activityManager,
|
||||
$this->userManager,
|
||||
$this->cloudIdManager,
|
||||
$this->participantService,
|
||||
$this->avatarService,
|
||||
$this->manager,
|
||||
])
|
||||
->onlyMethods($methods)
|
||||
->getMock();
|
||||
}
|
||||
|
||||
|
||||
public static function dataPreParse(): array {
|
||||
return [
|
||||
['other', false, true, true],
|
||||
['spreed', false, true, true],
|
||||
['spreed', true, true, true],
|
||||
['spreed', true, false, false],
|
||||
];
|
||||
}
|
||||
|
||||
#[DataProvider('dataPreParse')]
|
||||
public function testPreParse(string $appId, bool $hasUser, bool $disabledForUser, bool $willThrowException): void {
|
||||
$user = $hasUser ? $this->createMock(IUser::class) : null;
|
||||
|
||||
/** @var IEvent&MockObject $event */
|
||||
$event = $this->createMock(IEvent::class);
|
||||
$event->expects($this->once())
|
||||
->method('getApp')
|
||||
->willReturn($appId);
|
||||
|
||||
if ($willThrowException) {
|
||||
$this->expectException(UnknownActivityException::class);
|
||||
}
|
||||
$event->expects($this->exactly($willThrowException ? 0 : 1))
|
||||
->method('setIcon')
|
||||
->willReturnSelf();
|
||||
|
||||
if ($user) {
|
||||
$this->config
|
||||
->method('isDisabledForUser')
|
||||
->with($user)
|
||||
->willReturn($disabledForUser);
|
||||
$this->userManager
|
||||
->method('get')
|
||||
->with('user')
|
||||
->willReturn($user);
|
||||
$event->expects($this->once())
|
||||
->method('getAffectedUser')
|
||||
->willReturn('user');
|
||||
}
|
||||
|
||||
$provider = $this->getProvider();
|
||||
static::invokePrivate($provider, 'preParse', [$event]);
|
||||
}
|
||||
|
||||
public function testPreParseThrows(): void {
|
||||
/** @var IEvent&MockObject $event */
|
||||
$event = $this->createMock(IEvent::class);
|
||||
$event->expects($this->once())
|
||||
->method('getApp')
|
||||
->willReturn('activity');
|
||||
$provider = $this->getProvider();
|
||||
$this->expectException(UnknownActivityException::class);
|
||||
static::invokePrivate($provider, 'preParse', [$event]);
|
||||
}
|
||||
|
||||
public static function dataSetSubject(): array {
|
||||
return [
|
||||
['No placeholder', [], 'No placeholder'],
|
||||
['This has one {placeholder}', ['placeholder' => ['name' => 'foobar']], 'This has one foobar'],
|
||||
['This has {number} {placeholders}', ['number' => ['name' => 'two'], 'placeholders' => ['name' => 'foobars']], 'This has two foobars'],
|
||||
];
|
||||
}
|
||||
|
||||
#[DataProvider('dataSetSubject')]
|
||||
public function testSetSubject(string $subject, array $parameters, string $parsedSubject): void {
|
||||
$provider = $this->getProvider();
|
||||
|
||||
$event = $this->createMock(IEvent::class);
|
||||
$event->expects($this->once())
|
||||
->method('setParsedSubject')
|
||||
->with($parsedSubject)
|
||||
->willReturnSelf();
|
||||
$event->expects($this->once())
|
||||
->method('setRichSubject')
|
||||
->with($subject, $parameters)
|
||||
->willReturnSelf();
|
||||
|
||||
self::invokePrivate($provider, 'setSubjects', [$event, $subject, $parameters]);
|
||||
}
|
||||
|
||||
public static function dataGetRoom(): array {
|
||||
return [
|
||||
[Room::TYPE_ONE_TO_ONE, 23, 'private-call', 'private-call', 'one2one'],
|
||||
[Room::TYPE_GROUP, 42, 'group-call', 'group-call', 'group'],
|
||||
[Room::TYPE_PUBLIC, 128, 'public-call', 'public-call', 'public'],
|
||||
[Room::TYPE_ONE_TO_ONE, 23, '', 'a conversation', 'one2one'],
|
||||
[Room::TYPE_GROUP, 42, '', 'a conversation', 'group'],
|
||||
[Room::TYPE_PUBLIC, 128, '', 'a conversation', 'public'],
|
||||
];
|
||||
}
|
||||
|
||||
#[DataProvider('dataGetRoom')]
|
||||
public function testGetRoom(int $type, int $id, string $name, string $expectedName, string $expectedType): void {
|
||||
$provider = $this->getProvider();
|
||||
|
||||
$room = $this->createMock(Room::class);
|
||||
$room->expects($this->once())
|
||||
->method('getType')
|
||||
->willReturn($type);
|
||||
$room->expects($this->once())
|
||||
->method('getId')
|
||||
->willReturn($id);
|
||||
$room->expects($this->once())
|
||||
->method('getDisplayName')
|
||||
->with('user')
|
||||
->willReturn($expectedName);
|
||||
$room->expects($this->once())
|
||||
->method('getToken')
|
||||
->willReturn('token');
|
||||
|
||||
$this->url->expects($this->once())
|
||||
->method('linkToRouteAbsolute')
|
||||
->with('spreed.Page.showCall', ['token' => 'token'])
|
||||
->willReturn('url');
|
||||
|
||||
$this->assertEquals([
|
||||
'type' => 'call',
|
||||
'id' => $id,
|
||||
'name' => $expectedName,
|
||||
'call-type' => $expectedType,
|
||||
'link' => 'url',
|
||||
'icon-url' => '',
|
||||
], self::invokePrivate($provider, 'getRoom', [$room, 'user']));
|
||||
}
|
||||
|
||||
public static function dataGetUser(): array {
|
||||
return [
|
||||
['test', true, 'Test'],
|
||||
['foo', false, 'foo'],
|
||||
];
|
||||
}
|
||||
|
||||
#[DataProvider('dataGetUser')]
|
||||
public function testGetUser(string $uid, bool $validUser, string $name): void {
|
||||
$provider = $this->getProvider();
|
||||
|
||||
if ($validUser) {
|
||||
$this->userManager->expects($this->once())
|
||||
->method('getDisplayName')
|
||||
->with($uid)
|
||||
->willReturn($name);
|
||||
} else {
|
||||
$this->userManager->expects($this->once())
|
||||
->method('getDisplayName')
|
||||
->with($uid)
|
||||
->willReturn(null);
|
||||
}
|
||||
|
||||
$this->assertSame([
|
||||
'type' => 'user',
|
||||
'id' => $uid,
|
||||
'name' => $name,
|
||||
], self::invokePrivate($provider, 'getUser', [$uid]));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,215 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* SPDX-FileCopyrightText: 2017 Nextcloud GmbH and Nextcloud contributors
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
*/
|
||||
|
||||
namespace OCA\Talk\Tests\php\Activity\Provider;
|
||||
|
||||
use OCA\Talk\Activity\Provider\Invitation;
|
||||
use OCA\Talk\Config;
|
||||
use OCA\Talk\Exceptions\RoomNotFoundException;
|
||||
use OCA\Talk\Manager;
|
||||
use OCA\Talk\Room;
|
||||
use OCA\Talk\Service\AvatarService;
|
||||
use OCA\Talk\Service\ParticipantService;
|
||||
use OCP\Activity\Exceptions\UnknownActivityException;
|
||||
use OCP\Activity\IEvent;
|
||||
use OCP\Activity\IManager;
|
||||
use OCP\Federation\ICloudIdManager;
|
||||
use OCP\IL10N;
|
||||
use OCP\IURLGenerator;
|
||||
use OCP\IUser;
|
||||
use OCP\IUserManager;
|
||||
use OCP\L10N\IFactory;
|
||||
use PHPUnit\Framework\Attributes\DataProvider;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use Test\TestCase;
|
||||
|
||||
/**
|
||||
* Class InvitationTest
|
||||
*
|
||||
* @package OCA\Talk\Tests\php\Activity
|
||||
*/
|
||||
class InvitationTest extends TestCase {
|
||||
protected IFactory&MockObject $l10nFactory;
|
||||
protected IURLGenerator&MockObject $url;
|
||||
protected Config&MockObject $config;
|
||||
protected IManager&MockObject $activityManager;
|
||||
protected IUserManager&MockObject $userManager;
|
||||
protected ICloudIdManager&MockObject $cloudIdManager;
|
||||
protected ParticipantService&MockObject $participantService;
|
||||
protected AvatarService&MockObject $avatarService;
|
||||
protected Manager&MockObject $manager;
|
||||
|
||||
public function setUp(): void {
|
||||
parent::setUp();
|
||||
|
||||
$this->l10nFactory = $this->createMock(IFactory::class);
|
||||
$this->url = $this->createMock(IURLGenerator::class);
|
||||
$this->config = $this->createMock(Config::class);
|
||||
$this->activityManager = $this->createMock(IManager::class);
|
||||
$this->userManager = $this->createMock(IUserManager::class);
|
||||
$this->cloudIdManager = $this->createMock(ICloudIdManager::class);
|
||||
$this->participantService = $this->createMock(ParticipantService::class);
|
||||
$this->avatarService = $this->createMock(AvatarService::class);
|
||||
$this->manager = $this->createMock(Manager::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string[] $methods
|
||||
* @return Invitation|MockObject
|
||||
*/
|
||||
protected function getProvider(array $methods = []) {
|
||||
if (!empty($methods)) {
|
||||
return $this->getMockBuilder(Invitation::class)
|
||||
->setConstructorArgs([
|
||||
$this->l10nFactory,
|
||||
$this->url,
|
||||
$this->config,
|
||||
$this->activityManager,
|
||||
$this->userManager,
|
||||
$this->cloudIdManager,
|
||||
$this->participantService,
|
||||
$this->avatarService,
|
||||
$this->manager,
|
||||
])
|
||||
->onlyMethods($methods)
|
||||
->getMock();
|
||||
}
|
||||
return new Invitation(
|
||||
$this->l10nFactory,
|
||||
$this->url,
|
||||
$this->config,
|
||||
$this->activityManager,
|
||||
$this->userManager,
|
||||
$this->cloudIdManager,
|
||||
$this->participantService,
|
||||
$this->avatarService,
|
||||
$this->manager
|
||||
);
|
||||
}
|
||||
|
||||
public function testParseThrowsWrongSubject(): void {
|
||||
/** @var IEvent&MockObject $event */
|
||||
$event = $this->createMock(IEvent::class);
|
||||
$event->expects($this->once())
|
||||
->method('getApp')
|
||||
->willReturn('spreed');
|
||||
$event->expects($this->once())
|
||||
->method('getSubject')
|
||||
->willReturn('call');
|
||||
$event->expects($this->once())
|
||||
->method('getAffectedUser')
|
||||
->willReturn('user');
|
||||
|
||||
$user = $this->createMock(IUser::class);
|
||||
$this->userManager->expects($this->once())
|
||||
->method('get')
|
||||
->with('user')
|
||||
->willReturn($user);
|
||||
$this->config->expects($this->once())
|
||||
->method('isDisabledForUser')
|
||||
->with($user)
|
||||
->willReturn(false);
|
||||
|
||||
$provider = $this->getProvider();
|
||||
$this->expectException(UnknownActivityException::class);
|
||||
$provider->parse('en', $event);
|
||||
}
|
||||
|
||||
public static function dataParse(): array {
|
||||
return [
|
||||
['en', true, ['room' => 23, 'user' => 'test1'], ['actor' => ['actor-data'], 'call' => ['call-data']]],
|
||||
['de', false, ['room' => 42, 'user' => 'test2'], ['actor' => ['actor-data'], 'call' => ['call-unknown']]],
|
||||
];
|
||||
}
|
||||
|
||||
#[DataProvider('dataParse')]
|
||||
public function testParse(string $lang, bool $roomExists, array $params, array $expectedParams): void {
|
||||
$provider = $this->getProvider(['setSubjects', 'getUser', 'getRoom', 'getFormerRoom']);
|
||||
|
||||
/** @var IL10N&MockObject $l */
|
||||
$l = $this->createMock(IL10N::class);
|
||||
$l->expects($this->any())
|
||||
->method('t')
|
||||
->willReturnCallback(function ($text, $parameters = []) {
|
||||
return vsprintf($text, $parameters);
|
||||
});
|
||||
|
||||
/** @var IEvent&MockObject $event */
|
||||
$event = $this->createMock(IEvent::class);
|
||||
$event->expects($this->once())
|
||||
->method('getApp')
|
||||
->willReturn('spreed');
|
||||
$event->expects($this->once())
|
||||
->method('getSubject')
|
||||
->willReturn('invitation');
|
||||
$event->expects($this->once())
|
||||
->method('getSubjectParameters')
|
||||
->willReturn($params);
|
||||
$event->expects($this->exactly($roomExists ? 2 : 1))
|
||||
->method('getAffectedUser')
|
||||
->willReturn('user');
|
||||
|
||||
$user = $this->createMock(IUser::class);
|
||||
$this->userManager->expects($this->once())
|
||||
->method('get')
|
||||
->with('user')
|
||||
->willReturn($user);
|
||||
$this->config->expects($this->once())
|
||||
->method('isDisabledForUser')
|
||||
->with($user)
|
||||
->willReturn(false);
|
||||
|
||||
if ($roomExists) {
|
||||
/** @var Room&MockObject $room */
|
||||
$room = $this->createMock(Room::class);
|
||||
|
||||
$this->manager->expects($this->once())
|
||||
->method('getRoomById')
|
||||
->with($params['room'])
|
||||
->willReturn($room);
|
||||
|
||||
$provider->expects($this->once())
|
||||
->method('getRoom')
|
||||
->with($room, 'user')
|
||||
->willReturn(['call-data']);
|
||||
$provider->expects($this->never())
|
||||
->method('getFormerRoom');
|
||||
} else {
|
||||
$this->manager->expects($this->once())
|
||||
->method('getRoomById')
|
||||
->with($params['room'])
|
||||
->willThrowException(new RoomNotFoundException());
|
||||
|
||||
$provider->expects($this->never())
|
||||
->method('getRoom');
|
||||
$provider->expects($this->once())
|
||||
->method('getFormerRoom')
|
||||
->with($l)
|
||||
->willReturn(['call-unknown']);
|
||||
}
|
||||
|
||||
$this->l10nFactory->expects($this->once())
|
||||
->method('get')
|
||||
->with('spreed', $lang)
|
||||
->willReturn($l);
|
||||
|
||||
$provider->expects($this->once())
|
||||
->method('getUser')
|
||||
->with($params['user'])
|
||||
->willReturn(['actor-data']);
|
||||
$provider->expects($this->once())
|
||||
->method('setSubjects')
|
||||
->with($event, '{actor} invited you to {call}', $expectedParams);
|
||||
$provider->expects($this->once())
|
||||
->method('getUser')
|
||||
->with($params['user'])
|
||||
->willReturn(['actor-data']);
|
||||
|
||||
$provider->parse($lang, $event);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* SPDX-FileCopyrightText: 2017 Nextcloud GmbH and Nextcloud contributors
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
*/
|
||||
|
||||
namespace OCA\Talk\Tests\php\Activity;
|
||||
|
||||
use OCA\Talk\Activity\Setting;
|
||||
use OCP\Activity\ISetting;
|
||||
use PHPUnit\Framework\Attributes\DataProvider;
|
||||
use Test\TestCase;
|
||||
|
||||
class SettingTest extends TestCase {
|
||||
public static function dataSettings(): array {
|
||||
return [
|
||||
[Setting::class],
|
||||
];
|
||||
}
|
||||
|
||||
#[DataProvider('dataSettings')]
|
||||
public function testImplementsInterface(string $settingClass): void {
|
||||
$setting = \OCP\Server::get($settingClass);
|
||||
$this->assertInstanceOf(ISetting::class, $setting);
|
||||
}
|
||||
|
||||
#[DataProvider('dataSettings')]
|
||||
public function testGetIdentifier(string $settingClass): void {
|
||||
/** @var ISetting $setting */
|
||||
$setting = \OCP\Server::get($settingClass);
|
||||
$this->assertIsString($setting->getIdentifier());
|
||||
}
|
||||
|
||||
#[DataProvider('dataSettings')]
|
||||
public function testGetName(string $settingClass): void {
|
||||
/** @var ISetting $setting */
|
||||
$setting = \OCP\Server::get($settingClass);
|
||||
$this->assertIsString($setting->getName());
|
||||
}
|
||||
|
||||
#[DataProvider('dataSettings')]
|
||||
public function testGetPriority(string $settingClass): void {
|
||||
/** @var ISetting $setting */
|
||||
$setting = \OCP\Server::get($settingClass);
|
||||
$priority = $setting->getPriority();
|
||||
$this->assertIsInt($setting->getPriority());
|
||||
$this->assertGreaterThanOrEqual(0, $priority);
|
||||
$this->assertLessThanOrEqual(100, $priority);
|
||||
}
|
||||
|
||||
#[DataProvider('dataSettings')]
|
||||
public function testCanChangeStream(string $settingClass): void {
|
||||
/** @var ISetting $setting */
|
||||
$setting = \OCP\Server::get($settingClass);
|
||||
$this->assertIsBool($setting->canChangeStream());
|
||||
}
|
||||
|
||||
#[DataProvider('dataSettings')]
|
||||
public function testIsDefaultEnabledStream(string $settingClass): void {
|
||||
/** @var ISetting $setting */
|
||||
$setting = \OCP\Server::get($settingClass);
|
||||
$this->assertIsBool($setting->isDefaultEnabledStream());
|
||||
}
|
||||
|
||||
#[DataProvider('dataSettings')]
|
||||
public function testCanChangeMail(string $settingClass): void {
|
||||
/** @var ISetting $setting */
|
||||
$setting = \OCP\Server::get($settingClass);
|
||||
$this->assertIsBool($setting->canChangeMail());
|
||||
}
|
||||
|
||||
#[DataProvider('dataSettings')]
|
||||
public function testIsDefaultEnabledMail(string $settingClass): void {
|
||||
/** @var ISetting $setting */
|
||||
$setting = \OCP\Server::get($settingClass);
|
||||
$this->assertIsBool($setting->isDefaultEnabledMail());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user