summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorJoas Schilling <213943+nickvergessen@users.noreply.github.com>2023-09-25 09:43:28 +0200
committerGitHub <noreply@github.com>2023-09-25 09:43:28 +0200
commitc581c49e2c37b791314a83a8c1f4a48cd3cbe170 (patch)
tree07f19282853a70e1b9e420738934e87762a4ad43 /tests
parent6c5dccb5b5a440a6a03aeceefba713eba90f1e29 (diff)
parent379addd25209c0aeb9adab54be741eb181127161 (diff)
Merge pull request #10571 from nextcloud/techdebt/noid/prepare-phpunit-10
techdebt(CI): Prepare unit tests for PHPUnit 10
Diffstat (limited to 'tests')
-rw-r--r--tests/php/Activity/Provider/BaseTest.php24
-rw-r--r--tests/php/Activity/Provider/InvitationTest.php2
-rw-r--r--tests/php/Activity/SettingTest.php2
-rw-r--r--tests/php/BackgroundJob/CheckHostedSignalingServerTest.php27
-rw-r--r--tests/php/BackgroundJob/RemoveEmptyRoomsTest.php6
-rw-r--r--tests/php/CapabilitiesTest.php4
-rw-r--r--tests/php/Chat/AutoComplete/SearchPluginTest.php12
-rw-r--r--tests/php/Chat/AutoComplete/SorterTest.php24
-rw-r--r--tests/php/Chat/ChatManagerTest.php10
-rw-r--r--tests/php/Chat/Command/ExecutorTest.php4
-rw-r--r--tests/php/Chat/Command/ShellExecutorTest.php4
-rw-r--r--tests/php/Chat/NotifierTest.php14
-rw-r--r--tests/php/Chat/Parser/SystemMessageTest.php22
-rw-r--r--tests/php/Chat/Parser/UserMentionTest.php44
-rw-r--r--tests/php/Chat/SystemMessage/ListenerTest.php80
-rw-r--r--tests/php/Collaboration/Collaborators/RoomPluginTest.php52
-rw-r--r--tests/php/Collaboration/Reference/TalkReferenceProviderTest.php2
-rw-r--r--tests/php/Collaboration/Resources/ConversationProviderTest.php2
-rw-r--r--tests/php/ConfigTest.php4
-rw-r--r--tests/php/Controller/ChatControllerTest.php93
-rw-r--r--tests/php/Controller/SignalingControllerTest.php2
-rw-r--r--tests/php/Listener/RestrictStartingCallsTest.php2
-rw-r--r--tests/php/Model/AttendeeMapperTest.php2
-rw-r--r--tests/php/Notification/NotifierTest.php18
-rw-r--r--tests/php/Service/AvatarServiceTest.php4
-rw-r--r--tests/php/Service/BreakoutRoomServiceTest.php2
-rw-r--r--tests/php/Service/ChecksumVerificationServiceTest.php2
-rw-r--r--tests/php/Service/RecordingServiceTest.php4
-rw-r--r--tests/php/Service/RoomServiceTest.php10
-rw-r--r--tests/php/Settings/Admin/AdminSettingsTest.php15
-rw-r--r--tests/php/TalkSessionTest.php6
31 files changed, 271 insertions, 228 deletions
diff --git a/tests/php/Activity/Provider/BaseTest.php b/tests/php/Activity/Provider/BaseTest.php
index a2875081c..b80824bcb 100644
--- a/tests/php/Activity/Provider/BaseTest.php
+++ b/tests/php/Activity/Provider/BaseTest.php
@@ -89,23 +89,21 @@ class BaseTest extends TestCase {
}
- public function dataPreParse(): array {
- $user = $this->createMock(IUser::class);
+ public static function dataPreParse(): array {
return [
- ['other', null, true, true],
- ['spreed', null, true, true],
- ['spreed', $user, true, true],
- ['spreed', $user, false, false],
+ ['other', false, true, true],
+ ['spreed', false, true, true],
+ ['spreed', true, true, true],
+ ['spreed', true, false, false],
];
}
/**
* @dataProvider dataPreParse
- *
- * @param bool $validUser
- * @param bool $disabledForUser
*/
- public function testPreParse(string $appId, ?IUser $user, bool $disabledForUser, bool $willThrowException): void {
+ 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())
@@ -148,7 +146,7 @@ class BaseTest extends TestCase {
static::invokePrivate($provider, 'preParse', [$event]);
}
- public function dataSetSubject() {
+ public static function dataSetSubject() {
return [
['No placeholder', [], 'No placeholder'],
['This has one {placeholder}', ['placeholder' => ['name' => 'foobar']], 'This has one foobar'],
@@ -179,7 +177,7 @@ class BaseTest extends TestCase {
self::invokePrivate($provider, 'setSubjects', [$event, $subject, $parameters]);
}
- public function dataGetRoom() {
+ public static function dataGetRoom() {
return [
[Room::TYPE_ONE_TO_ONE, 23, 'private-call', 'private-call', 'one2one'],
[Room::TYPE_GROUP, 42, 'group-call', 'group-call', 'group'],
@@ -232,7 +230,7 @@ class BaseTest extends TestCase {
], self::invokePrivate($provider, 'getRoom', [$room, 'user']));
}
- public function dataGetUser(): array {
+ public static function dataGetUser(): array {
return [
['test', true, 'Test'],
['foo', false, 'foo'],
diff --git a/tests/php/Activity/Provider/InvitationTest.php b/tests/php/Activity/Provider/InvitationTest.php
index 21e17b337..f6edb1c18 100644
--- a/tests/php/Activity/Provider/InvitationTest.php
+++ b/tests/php/Activity/Provider/InvitationTest.php
@@ -128,7 +128,7 @@ class InvitationTest extends TestCase {
$provider->parse('en', $event);
}
- public function dataParse() {
+ public static function dataParse() {
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']]],
diff --git a/tests/php/Activity/SettingTest.php b/tests/php/Activity/SettingTest.php
index 04d6c35cc..22df7e1e2 100644
--- a/tests/php/Activity/SettingTest.php
+++ b/tests/php/Activity/SettingTest.php
@@ -26,7 +26,7 @@ use OCP\Activity\ISetting;
use Test\TestCase;
class SettingTest extends TestCase {
- public function dataSettings() {
+ public static function dataSettings() {
return [
[Setting::class],
];
diff --git a/tests/php/BackgroundJob/CheckHostedSignalingServerTest.php b/tests/php/BackgroundJob/CheckHostedSignalingServerTest.php
index 06e5edd6b..eba49ff91 100644
--- a/tests/php/BackgroundJob/CheckHostedSignalingServerTest.php
+++ b/tests/php/BackgroundJob/CheckHostedSignalingServerTest.php
@@ -33,6 +33,7 @@ use OCP\IGroup;
use OCP\IGroupManager;
use OCP\IURLGenerator;
use OCP\Notification\IManager;
+use PHPUnit\Framework\Assert;
use PHPUnit\Framework\MockObject\MockObject;
use Psr\Log\LoggerInterface;
use Test\TestCase;
@@ -106,21 +107,27 @@ class CheckHostedSignalingServerTest extends TestCase {
$this->config
->method('getAppValue')
- ->will($this->returnValueMap([
+ ->willReturnMap([
['spreed', 'hosted-signaling-server-account-id', '', 'my-account-id'],
['spreed', 'hosted-signaling-server-account', '{}', '{"status": "pending"}']
- ]));
+ ]);
$this->config->expects($this->once())
->method('deleteAppValue')
- ->withConsecutive(
- ['spreed', 'signaling_mode'],
- );
- $this->config->expects($this->exactly(2))
+ ->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')
- ->withConsecutive(
- ['spreed', 'signaling_servers', '{"servers":[{"server":"signaling-url","verify":true}],"secret":"signaling-secret"}'],
- ['spreed', 'hosted-signaling-server-account', json_encode($newStatus)]
- );
+ ->willReturnCallback(function () use ($expectedCalls, &$i) {
+ Assert::assertArrayHasKey($i, $expectedCalls);
+ Assert::assertSame($expectedCalls[$i], func_get_args());
+ $i++;
+ });
$group = $this->createMock(IGroup::class);
$this->groupManager->expects($this->once())
diff --git a/tests/php/BackgroundJob/RemoveEmptyRoomsTest.php b/tests/php/BackgroundJob/RemoveEmptyRoomsTest.php
index 8198f321f..33749630b 100644
--- a/tests/php/BackgroundJob/RemoveEmptyRoomsTest.php
+++ b/tests/php/BackgroundJob/RemoveEmptyRoomsTest.php
@@ -111,7 +111,7 @@ class RemoveEmptyRoomsTest extends TestCase {
$this->assertEquals($numDeletedRoomsExpected, $numDeletedRoomsActual, 'Invalid final quantity of rooms');
}
- public function dataDeleteIfFileIsRemoved(): array {
+ public static function dataDeleteIfFileIsRemoved(): array {
return [
['', [], 0],
['email', [], 0],
@@ -145,7 +145,7 @@ class RemoveEmptyRoomsTest extends TestCase {
$this->assertEquals($numDeletedRoomsExpected, $numDeletedRoomsActual, 'Invalid final quantity of rooms');
}
- public function dataDeleteIfIsEmpty(): array {
+ public static function dataDeleteIfIsEmpty(): array {
return [
['', 1, 0],
['file', 1, 0],
@@ -169,7 +169,7 @@ class RemoveEmptyRoomsTest extends TestCase {
$this->assertEquals($numDeletedRoomsExpected, $numDeletedRoomsActual, 'Invalid final quantity of rooms');
}
- public function dataCallback(): array {
+ public static function dataCallback(): array {
return [
[Room::TYPE_CHANGELOG, '', 0],
[Room::TYPE_GROUP, 'file', 1],
diff --git a/tests/php/CapabilitiesTest.php b/tests/php/CapabilitiesTest.php
index ccb457121..cfd53dc6c 100644
--- a/tests/php/CapabilitiesTest.php
+++ b/tests/php/CapabilitiesTest.php
@@ -223,7 +223,7 @@ class CapabilitiesTest extends TestCase {
], $capabilities->getCapabilities());
}
- public function dataGetCapabilitiesUserAllowed(): array {
+ public static function dataGetCapabilitiesUserAllowed(): array {
return [
[true, false, 'none', true, Participant::PRIVACY_PRIVATE],
[false, true, '1 MB', true, Participant::PRIVACY_PUBLIC],
@@ -428,7 +428,7 @@ class CapabilitiesTest extends TestCase {
$this->assertEquals($data['spreed']['config']['call']['recording'], $enabled);
}
- public function dataTestConfigRecording(): array {
+ public static function dataTestConfigRecording(): array {
return [
[true],
[false],
diff --git a/tests/php/Chat/AutoComplete/SearchPluginTest.php b/tests/php/Chat/AutoComplete/SearchPluginTest.php
index 441007e10..b09dca0df 100644
--- a/tests/php/Chat/AutoComplete/SearchPluginTest.php
+++ b/tests/php/Chat/AutoComplete/SearchPluginTest.php
@@ -105,7 +105,7 @@ class SearchPluginTest extends TestCase {
$this->userId,
$this->l,
])
- ->setMethods($methods)
+ ->onlyMethods($methods)
->getMock();
}
@@ -170,7 +170,7 @@ class SearchPluginTest extends TestCase {
$plugin->search('fo', 10, 0, $result);
}
- public function dataSearchUsers() {
+ public static function dataSearchUsers() {
return [
['test', [], [], [], []],
['test', ['current', 'foo', 'test', 'test1'], [
@@ -216,7 +216,7 @@ class SearchPluginTest extends TestCase {
self::invokePrivate($plugin, 'searchUsers', [$search, $userIds, $result]);
}
- public function dataSearchGuests() {
+ public static function dataSearchGuests() {
return [
['test', [], [], []],
['', ['abcdef' => ''], [['abcdef' => 'Guest']], []],
@@ -269,7 +269,7 @@ class SearchPluginTest extends TestCase {
return $user;
}
- public function dataCreateResult() {
+ public static function dataCreateResult() {
return [
['user', 'foo', 'bar', '', ['label' => 'bar', 'value' => ['shareType' => 'user', 'shareWith' => 'foo']]],
['user', 'test', 'Test', '', ['label' => 'Test', 'value' => ['shareType' => 'user', 'shareWith' => 'test']]],
@@ -304,7 +304,7 @@ class SearchPluginTest extends TestCase {
}
- public function dataCreateGuestResult(): array {
+ public static function dataCreateGuestResult(): array {
return [
['1234', 'foo', ['label' => 'foo', 'value' => ['shareType' => 'guest', 'shareWith' => 'guest/1234']]],
['abcd', 'bar', ['label' => 'bar', 'value' => ['shareType' => 'guest', 'shareWith' => 'guest/abcd']]],
@@ -359,7 +359,7 @@ class SearchPluginTest extends TestCase {
$this->assertCount($totalExactMatches, $actual['exact']['groups']);
}
- public function dataSearchGroups(): array {
+ public static function dataSearchGroups(): array {
return [
// $search, $groupIds, $isGroup, $displayName, $totalMatches, $totalExactMatches
['', ['groupid'], true, 'group', 1, 0],
diff --git a/tests/php/Chat/AutoComplete/SorterTest.php b/tests/php/Chat/AutoComplete/SorterTest.php
index f627a089b..3946bb199 100644
--- a/tests/php/Chat/AutoComplete/SorterTest.php
+++ b/tests/php/Chat/AutoComplete/SorterTest.php
@@ -21,7 +21,7 @@ declare(strict_types=1);
*
*/
-namespace OCA\Talk\Tests\php\Chat;
+namespace OCA\Talk\Tests\php\Chat\AutoComplete;
use OCA\Talk\Chat\AutoComplete\Sorter;
use OCA\Talk\Chat\CommentsManager;
@@ -36,7 +36,7 @@ class SorterTest extends TestCase {
protected ?Sorter $sorter = null;
- protected array $user1 = [
+ protected static array $user1 = [
'label' => 'Seattle',
'value' => [
'shareType' => 'user',
@@ -44,7 +44,7 @@ class SorterTest extends TestCase {
],
];
- protected array $user2 = [
+ protected static array $user2 = [
'label' => 'New York',
'value' => [
'shareType' => 'user',
@@ -52,7 +52,7 @@ class SorterTest extends TestCase {
],
];
- protected array $user3 = [
+ protected static array $user3 = [
'label' => 'ttle Sea',
'value' => [
'shareType' => 'user',
@@ -71,15 +71,15 @@ class SorterTest extends TestCase {
$this->assertSame('talk_chat_participants', $this->sorter->getId());
}
- public function dataSort(): array {
+ public static function dataSort(): array {
return [
- 'no user posted' => ['', ['users' => [$this->user1, $this->user2]], [], ['users' => [$this->user1, $this->user2]]],
- 'second user posted' => ['', ['users' => [$this->user1, $this->user2]], ['new_york' => new \DateTime('2000-01-01')], ['users' => [$this->user2, $this->user1]]],
- 'second user posted later' => ['', ['users' => [$this->user1, $this->user2]], ['seattle' => new \DateTime('2017-01-01'), 'new_york' => new \DateTime('2018-01-01')], ['users' => [$this->user2, $this->user1]]],
- 'second user posted earlier' => ['', ['users' => [$this->user1, $this->user2]], ['seattle' => new \DateTime('2018-01-01'), 'new_york' => new \DateTime('2017-01-01')], ['users' => [$this->user1, $this->user2]]],
- 'starting match first1' => ['Sea', ['users' => [$this->user1, $this->user3]], [], ['users' => [$this->user1, $this->user3]]],
- 'starting match first2' => ['Sea', ['users' => [$this->user3, $this->user1]], [], ['users' => [$this->user1, $this->user3]]],
- 'no users' => ['', ['groups' => [$this->user1, $this->user2]], [], ['groups' => [$this->user1, $this->user2]]],
+ 'no user posted' => ['', ['users' => [self::$user1, self::$user2]], [], ['users' => [self::$user1, self::$user2]]],
+ 'second user posted' => ['', ['users' => [self::$user1, self::$user2]], ['new_york' => new \DateTime('2000-01-01')], ['users' => [self::$user2, self::$user1]]],
+ 'second user posted later' => ['', ['users' => [self::$user1, self::$user2]], ['seattle' => new \DateTime('2017-01-01'), 'new_york' => new \DateTime('2018-01-01')], ['users' => [self::$user2, self::$user1]]],
+ 'second user posted earlier' => ['', ['users' => [self::$user1, self::$user2]], ['seattle' => new \DateTime('2018-01-01'), 'new_york' => new \DateTime('2017-01-01')], ['users' => [self::$user1, self::$user2]]],
+ 'starting match first1' => ['Sea', ['users' => [self::$user1, self::$user3]], [], ['users' => [self::$user1, self::$user3]]],
+ 'starting match first2' => ['Sea', ['users' => [self::$user3, self::$user1]], [], ['users' => [self::$user1, self::$user3]]],
+ 'no users' => ['', ['groups' => [self::$user1, self::$user2]], [], ['groups' => [self::$user1, self::$user2]]],
];
}
diff --git a/tests/php/Chat/ChatManagerTest.php b/tests/php/Chat/ChatManagerTest.php
index ae953d131..cf7cae591 100644
--- a/tests/php/Chat/ChatManagerTest.php
+++ b/tests/php/Chat/ChatManagerTest.php
@@ -210,7 +210,7 @@ class ChatManagerTest extends TestCase {
]);
}
- public function dataSendMessage(): array {
+ public static function dataSendMessage(): array {
return [
'simple message' => ['testUser1', 'testMessage1', '', '0'],
'reference id' => ['testUser2', 'testMessage2', 'referenceId2', '0'],
@@ -654,7 +654,7 @@ class ChatManagerTest extends TestCase {
$manager->clearHistory($chat, 'users', 'admin');
}
- public function dataSearchIsPartOfConversationNameOrAtAll(): array {
+ public static function dataSearchIsPartOfConversationNameOrAtAll(): array {
return [
'found a in all' => [
'a', 'room', true
@@ -697,7 +697,7 @@ class ChatManagerTest extends TestCase {
$this->assertEquals($expected, $actual);
}
- public function dataAddConversationNotify(): array {
+ public static function dataAddConversationNotify(): array {
return [
[
'',
@@ -765,7 +765,7 @@ class ChatManagerTest extends TestCase {
$this->assertEquals($expected, $actual);
}
- public function dataIsSharedFile(): array {
+ public static function dataIsSharedFile(): array {
return [
['', false],
[json_encode([]), false],
@@ -802,7 +802,7 @@ class ChatManagerTest extends TestCase {
$this->assertCount($expectedCount, $result);
}
- public function dataFilterCommentsWithNonExistingFiles(): array {
+ public static function dataFilterCommentsWithNonExistingFiles(): array {
return [
[[], 0],
[[json_encode(['parameters' => ['not a shared file']])], 1],
diff --git a/tests/php/Chat/Command/ExecutorTest.php b/tests/php/Chat/Command/ExecutorTest.php
index 31c53b567..12027c7c7 100644
--- a/tests/php/Chat/Command/ExecutorTest.php
+++ b/tests/php/Chat/Command/ExecutorTest.php
@@ -71,7 +71,7 @@ class ExecutorTest extends TestCase {
);
}
- public function dataExecApp(): array {
+ public static function dataExecApp(): array {
return [
['arguments1', ''],
['arguments2', "output from\nevent"],
@@ -115,7 +115,7 @@ class ExecutorTest extends TestCase {
$this->assertSame($expected, self::invokePrivate($executor, 'execApp', [$room, $message, $command, $arguments]));
}
- public function dataExecShell(): array {
+ public static function dataExecShell(): array {
return [
['admin', 'token', '', '', ''],
['admin', 'token', '/var/www/nextcloud/script.sh {USER} {ROOM} {ARGUMENTS}', 'foo bar "hello bear"', 'output1'],
diff --git a/tests/php/Chat/Command/ShellExecutorTest.php b/tests/php/Chat/Command/ShellExecutorTest.php
index 2f1920bc5..4d26bb3c9 100644
--- a/tests/php/Chat/Command/Sh