aboutsummaryrefslogtreecommitdiffstats
path: root/apps/user_status/tests
diff options
context:
space:
mode:
Diffstat (limited to 'apps/user_status/tests')
-rw-r--r--apps/user_status/tests/Integration/Service/StatusServiceIntegrationTest.php67
-rw-r--r--apps/user_status/tests/Unit/BackgroundJob/ClearOldStatusesBackgroundJobTest.php37
-rw-r--r--apps/user_status/tests/Unit/CapabilitiesTest.php39
-rw-r--r--apps/user_status/tests/Unit/Connector/UserStatusProviderTest.php30
-rw-r--r--apps/user_status/tests/Unit/Connector/UserStatusTest.php25
-rw-r--r--apps/user_status/tests/Unit/Controller/PredefinedStatusControllerTest.php35
-rw-r--r--apps/user_status/tests/Unit/Controller/StatusesControllerTest.php30
-rw-r--r--apps/user_status/tests/Unit/Controller/UserStatusControllerTest.php102
-rw-r--r--apps/user_status/tests/Unit/Dashboard/UserStatusWidgetTest.php56
-rw-r--r--apps/user_status/tests/Unit/Db/UserStatusMapperTest.php46
-rw-r--r--apps/user_status/tests/Unit/Listener/UserDeletedListenerTest.php30
-rw-r--r--apps/user_status/tests/Unit/Listener/UserLiveStatusListenerTest.php63
-rw-r--r--apps/user_status/tests/Unit/Service/PredefinedStatusServiceTest.php107
-rw-r--r--apps/user_status/tests/Unit/Service/StatusServiceTest.php184
-rw-r--r--apps/user_status/tests/bootstrap.php34
15 files changed, 261 insertions, 624 deletions
diff --git a/apps/user_status/tests/Integration/Service/StatusServiceIntegrationTest.php b/apps/user_status/tests/Integration/Service/StatusServiceIntegrationTest.php
index 9179f066fa8..8a21052b09f 100644
--- a/apps/user_status/tests/Integration/Service/StatusServiceIntegrationTest.php
+++ b/apps/user_status/tests/Integration/Service/StatusServiceIntegrationTest.php
@@ -3,27 +3,11 @@
declare(strict_types=1);
/**
- * @copyright 2023 Christoph Wurst <christoph@winzerhof-wurst.at>
- *
- * @author 2023 Christoph Wurst <christoph@winzerhof-wurst.at>
- *
- * @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/>.
+ * SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
*/
-namespace OCA\UserStatus\Tests\Integration\BackgroundJob;
+namespace OCA\UserStatus\Tests\Integration\Service;
use OCA\UserStatus\Service\StatusService;
use OCP\AppFramework\Db\DoesNotExistException;
@@ -58,17 +42,20 @@ class StatusServiceIntegrationTest extends TestCase {
}
public function testCustomStatusMessageTimestamp(): void {
+ $before = time();
$this->service->setCustomMessage(
'test123',
'🍕',
'Lunch',
null,
);
+ $after = time();
$status = $this->service->findByUserId('test123');
self::assertSame('Lunch', $status->getCustomMessage());
- self::assertGreaterThanOrEqual(time(), $status->getStatusMessageTimestamp());
+ self::assertGreaterThanOrEqual($before, $status->getStatusMessageTimestamp());
+ self::assertLessThanOrEqual($after, $status->getStatusMessageTimestamp());
}
public function testOnlineStatusKeepsMessageTimestamp(): void {
@@ -111,15 +98,29 @@ class StatusServiceIntegrationTest extends TestCase {
'meeting',
true,
);
+
self::assertSame(
'meeting',
$this->service->findByUserId('test123')->getMessageId(),
);
+ self::assertSame(
+ IUserStatus::ONLINE,
+ $this->service->findByUserId('_test123')->getStatus(),
+ );
- $this->service->revertUserStatus(
+ $revertedStatus = $this->service->revertUserStatus(
'test123',
'meeting',
);
+
+ self::assertNotNull($revertedStatus, 'Status should have been reverted');
+
+ try {
+ $this->service->findByUserId('_test123');
+ $this->fail('Expected DoesNotExistException() to be thrown when finding backup status after reverting');
+ } catch (DoesNotExistException) {
+ }
+
self::assertSame(
IUserStatus::ONLINE,
$this->service->findByUserId('test123')->getStatus(),
@@ -135,7 +136,7 @@ class StatusServiceIntegrationTest extends TestCase {
);
$this->service->setUserStatus(
'test123',
- IUserStatus::AWAY,
+ IUserStatus::BUSY,
IUserStatus::MESSAGE_CALENDAR_BUSY,
true,
);
@@ -146,12 +147,12 @@ class StatusServiceIntegrationTest extends TestCase {
$this->service->setUserStatus(
'test123',
- IUserStatus::AWAY,
+ IUserStatus::BUSY,
IUserStatus::MESSAGE_CALL,
true,
);
self::assertSame(
- IUserStatus::AWAY,
+ IUserStatus::BUSY,
$this->service->findByUserId('test123')->getStatus(),
);
@@ -170,32 +171,26 @@ class StatusServiceIntegrationTest extends TestCase {
);
$this->service->setUserStatus(
'test123',
- IUserStatus::AWAY,
- IUserStatus::MESSAGE_CALENDAR_BUSY,
+ IUserStatus::DND,
+ IUserStatus::MESSAGE_AVAILABILITY,
true,
);
self::assertSame(
- 'meeting',
+ 'availability',
$this->service->findByUserId('test123')->getMessageId(),
);
$nostatus = $this->service->setUserStatus(
'test123',
- IUserStatus::AWAY,
- IUserStatus::MESSAGE_AVAILABILITY,
+ IUserStatus::BUSY,
+ IUserStatus::MESSAGE_CALENDAR_BUSY,
true,
);
self::assertNull($nostatus);
self::assertSame(
- IUserStatus::MESSAGE_CALENDAR_BUSY,
+ IUserStatus::MESSAGE_AVAILABILITY,
$this->service->findByUserId('test123')->getMessageId(),
);
}
-
- public function testCi(): void {
- // TODO: remove if CI turns red
- self::assertTrue(false);
- }
-
}
diff --git a/apps/user_status/tests/Unit/BackgroundJob/ClearOldStatusesBackgroundJobTest.php b/apps/user_status/tests/Unit/BackgroundJob/ClearOldStatusesBackgroundJobTest.php
index da3b342f1a7..66142082343 100644
--- a/apps/user_status/tests/Unit/BackgroundJob/ClearOldStatusesBackgroundJobTest.php
+++ b/apps/user_status/tests/Unit/BackgroundJob/ClearOldStatusesBackgroundJobTest.php
@@ -3,44 +3,21 @@
declare(strict_types=1);
/**
- * @copyright Copyright (c) 2020, Georg Ehrke
- *
- * @author Georg Ehrke <oc.list@georgehrke.com>
- * @author 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/>.
- *
+ * SPDX-FileCopyrightText: 2020 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\UserStatus\Tests\BackgroundJob;
use OCA\UserStatus\BackgroundJob\ClearOldStatusesBackgroundJob;
use OCA\UserStatus\Db\UserStatusMapper;
use OCP\AppFramework\Utility\ITimeFactory;
+use PHPUnit\Framework\MockObject\MockObject;
use Test\TestCase;
class ClearOldStatusesBackgroundJobTest extends TestCase {
-
- /** @var ITimeFactory|\PHPUnit\Framework\MockObject\MockObject */
- private $time;
-
- /** @var UserStatusMapper|\PHPUnit\Framework\MockObject\MockObject */
- private $mapper;
-
- /** @var ClearOldStatusesBackgroundJob */
- private $job;
+ private ITimeFactory&MockObject $time;
+ private UserStatusMapper&MockObject $mapper;
+ private ClearOldStatusesBackgroundJob $job;
protected function setUp(): void {
parent::setUp();
@@ -51,7 +28,7 @@ class ClearOldStatusesBackgroundJobTest extends TestCase {
$this->job = new ClearOldStatusesBackgroundJob($this->time, $this->mapper);
}
- public function testRun() {
+ public function testRun(): void {
$this->mapper->expects($this->once())
->method('clearOlderThanClearAt')
->with(1337);
diff --git a/apps/user_status/tests/Unit/CapabilitiesTest.php b/apps/user_status/tests/Unit/CapabilitiesTest.php
index 89e87775312..601fb207df4 100644
--- a/apps/user_status/tests/Unit/CapabilitiesTest.php
+++ b/apps/user_status/tests/Unit/CapabilitiesTest.php
@@ -3,39 +3,19 @@
declare(strict_types=1);
/**
- * @copyright Copyright (c) 2020, Georg Ehrke
- *
- * @author Georg Ehrke <oc.list@georgehrke.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/>.
- *
+ * SPDX-FileCopyrightText: 2020 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\UserStatus\Tests;
use OCA\UserStatus\Capabilities;
use OCP\IEmojiHelper;
+use PHPUnit\Framework\MockObject\MockObject;
use Test\TestCase;
class CapabilitiesTest extends TestCase {
-
- /** @var IEmojiHelper|\PHPUnit\Framework\MockObject\MockObject */
- private $emojiHelper;
-
- /** @var Capabilities */
- private $capabilities;
+ private IEmojiHelper&MockObject $emojiHelper;
+ private Capabilities $capabilities;
protected function setUp(): void {
parent::setUp();
@@ -44,11 +24,7 @@ class CapabilitiesTest extends TestCase {
$this->capabilities = new Capabilities($this->emojiHelper);
}
- /**
- * @param bool $supportsEmojis
- *
- * @dataProvider getCapabilitiesDataProvider
- */
+ #[\PHPUnit\Framework\Attributes\DataProvider('getCapabilitiesDataProvider')]
public function testGetCapabilities(bool $supportsEmojis): void {
$this->emojiHelper->expects($this->once())
->method('doesPlatformSupportEmoji')
@@ -59,11 +35,12 @@ class CapabilitiesTest extends TestCase {
'enabled' => true,
'restore' => true,
'supports_emoji' => $supportsEmojis,
+ 'supports_busy' => true,
]
], $this->capabilities->getCapabilities());
}
- public function getCapabilitiesDataProvider(): array {
+ public static function getCapabilitiesDataProvider(): array {
return [
[true],
[false],
diff --git a/apps/user_status/tests/Unit/Connector/UserStatusProviderTest.php b/apps/user_status/tests/Unit/Connector/UserStatusProviderTest.php
index 2b126a7a5ea..df6c55488d5 100644
--- a/apps/user_status/tests/Unit/Connector/UserStatusProviderTest.php
+++ b/apps/user_status/tests/Unit/Connector/UserStatusProviderTest.php
@@ -3,40 +3,20 @@
declare(strict_types=1);
/**
- * @copyright Copyright (c) 2020, Georg Ehrke
- *
- * @author Georg Ehrke <oc.list@georgehrke.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/>.
- *
+ * SPDX-FileCopyrightText: 2020 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\UserStatus\Tests\Connector;
use OCA\UserStatus\Connector\UserStatusProvider;
use OCA\UserStatus\Db\UserStatus;
use OCA\UserStatus\Service\StatusService;
+use PHPUnit\Framework\MockObject\MockObject;
use Test\TestCase;
class UserStatusProviderTest extends TestCase {
-
- /** @var \PHPUnit\Framework\MockObject\MockObject */
- private $service;
-
- /** @var UserStatusProvider */
- private $provider;
+ private StatusService&MockObject $service;
+ private UserStatusProvider $provider;
protected function setUp(): void {
parent::setUp();
diff --git a/apps/user_status/tests/Unit/Connector/UserStatusTest.php b/apps/user_status/tests/Unit/Connector/UserStatusTest.php
index 4a43aede5c0..fee9b4e4b89 100644
--- a/apps/user_status/tests/Unit/Connector/UserStatusTest.php
+++ b/apps/user_status/tests/Unit/Connector/UserStatusTest.php
@@ -3,25 +3,8 @@
declare(strict_types=1);
/**
- * @copyright Copyright (c) 2020, Georg Ehrke
- *
- * @author Georg Ehrke <oc.list@georgehrke.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/>.
- *
+ * SPDX-FileCopyrightText: 2020 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\UserStatus\Tests\Connector;
@@ -30,7 +13,7 @@ use OCA\UserStatus\Db;
use Test\TestCase;
class UserStatusTest extends TestCase {
- public function testUserStatus() {
+ public function testUserStatus(): void {
$status = new Db\UserStatus();
$status->setUserId('user2');
$status->setStatus('away');
@@ -51,7 +34,7 @@ class UserStatusTest extends TestCase {
$this->assertEquals('60000', $dateTime->format('U'));
}
- public function testUserStatusInvisible() {
+ public function testUserStatusInvisible(): void {
$status = new Db\UserStatus();
$status->setUserId('user2');
$status->setStatus('invisible');
diff --git a/apps/user_status/tests/Unit/Controller/PredefinedStatusControllerTest.php b/apps/user_status/tests/Unit/Controller/PredefinedStatusControllerTest.php
index 81ad3b8e390..0f96f41a524 100644
--- a/apps/user_status/tests/Unit/Controller/PredefinedStatusControllerTest.php
+++ b/apps/user_status/tests/Unit/Controller/PredefinedStatusControllerTest.php
@@ -3,40 +3,20 @@
declare(strict_types=1);
/**
- * @copyright Copyright (c) 2020, Georg Ehrke
- *
- * @author Georg Ehrke <oc.list@georgehrke.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/>.
- *
+ * SPDX-FileCopyrightText: 2020 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\UserStatus\Tests\Controller;
use OCA\UserStatus\Controller\PredefinedStatusController;
use OCA\UserStatus\Service\PredefinedStatusService;
use OCP\IRequest;
+use PHPUnit\Framework\MockObject\MockObject;
use Test\TestCase;
class PredefinedStatusControllerTest extends TestCase {
-
- /** @var PredefinedStatusService|\PHPUnit\Framework\MockObject\MockObject */
- private $service;
-
- /** @var PredefinedStatusController */
- private $controller;
+ private PredefinedStatusService&MockObject $service;
+ private PredefinedStatusController $controller;
protected function setUp(): void {
parent::setUp();
@@ -44,11 +24,10 @@ class PredefinedStatusControllerTest extends TestCase {
$request = $this->createMock(IRequest::class);
$this->service = $this->createMock(PredefinedStatusService::class);
- $this->controller = new PredefinedStatusController('user_status', $request,
- $this->service);
+ $this->controller = new PredefinedStatusController('user_status', $request, $this->service);
}
- public function testFindAll() {
+ public function testFindAll(): void {
$this->service->expects($this->once())
->method('getDefaultStatuses')
->with()
diff --git a/apps/user_status/tests/Unit/Controller/StatusesControllerTest.php b/apps/user_status/tests/Unit/Controller/StatusesControllerTest.php
index 19c4bee076e..76d337879c3 100644
--- a/apps/user_status/tests/Unit/Controller/StatusesControllerTest.php
+++ b/apps/user_status/tests/Unit/Controller/StatusesControllerTest.php
@@ -3,25 +3,8 @@
declare(strict_types=1);
/**
- * @copyright Copyright (c) 2020, Georg Ehrke
- *
- * @author Georg Ehrke <oc.list@georgehrke.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/>.
- *
+ * SPDX-FileCopyrightText: 2020 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\UserStatus\Tests\Controller;
@@ -31,15 +14,12 @@ use OCA\UserStatus\Service\StatusService;
use OCP\AppFramework\Db\DoesNotExistException;
use OCP\AppFramework\OCS\OCSNotFoundException;
use OCP\IRequest;
+use PHPUnit\Framework\MockObject\MockObject;
use Test\TestCase;
class StatusesControllerTest extends TestCase {
-
- /** @var StatusService|\PHPUnit\Framework\MockObject\MockObject */
- private $service;
-
- /** @var StatusesController */
- private $controller;
+ private StatusService&MockObject $service;
+ private StatusesController $controller;
protected function setUp(): void {
parent::setUp();
diff --git a/apps/user_status/tests/Unit/Controller/UserStatusControllerTest.php b/apps/user_status/tests/Unit/Controller/UserStatusControllerTest.php
index d3b6d2002e0..e99290319ed 100644
--- a/apps/user_status/tests/Unit/Controller/UserStatusControllerTest.php
+++ b/apps/user_status/tests/Unit/Controller/UserStatusControllerTest.php
@@ -3,26 +3,8 @@
declare(strict_types=1);
/**
- * @copyright Copyright (c) 2020, Georg Ehrke
- *
- * @author Georg Ehrke <oc.list@georgehrke.com>
- * @author 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/>.
- *
+ * SPDX-FileCopyrightText: 2020 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\UserStatus\Tests\Controller;
@@ -39,22 +21,16 @@ use OCP\AppFramework\Db\DoesNotExistException;
use OCP\AppFramework\OCS\OCSBadRequestException;
use OCP\AppFramework\OCS\OCSNotFoundException;
use OCP\IRequest;
+use PHPUnit\Framework\MockObject\MockObject;
use Psr\Log\LoggerInterface;
use Test\TestCase;
use Throwable;
class UserStatusControllerTest extends TestCase {
- /** @var LoggerInterface|\PHPUnit\Framework\MockObject\MockObject */
- private $logger;
-
- /** @var StatusService|\PHPUnit\Framework\MockObject\MockObject */
- private $statusService;
-
- /** @var CalendarStatusService|\PHPUnit\Framework\MockObject\MockObject $calendarStatusService */
- private $calendarStatusService;
-
- /** @var UserStatusController */
- private $controller;
+ private LoggerInterface&MockObject $logger;
+ private StatusService&MockObject $statusService;
+ private CalendarStatusService&MockObject $calendarStatusService;
+ private UserStatusController $controller;
protected function setUp(): void {
parent::setUp();
@@ -111,20 +87,9 @@ class UserStatusControllerTest extends TestCase {
$this->controller->getStatus();
}
- /**
- * @param string $statusType
- * @param string|null $statusIcon
- * @param string|null $message
- * @param int|null $clearAt
- * @param bool $expectSuccess
- * @param bool $expectException
- * @param Throwable|null $exception
- * @param bool $expectLogger
- * @param string|null $expectedLogMessage
- *
- * @dataProvider setStatusDataProvider
- */
- public function testSetStatus(string $statusType,
+ #[\PHPUnit\Framework\Attributes\DataProvider('setStatusDataProvider')]
+ public function testSetStatus(
+ string $statusType,
?string $statusIcon,
?string $message,
?int $clearAt,
@@ -132,7 +97,8 @@ class UserStatusControllerTest extends TestCase {
bool $expectException,
?Throwable $exception,
bool $expectLogger,
- ?string $expectedLogMessage): void {
+ ?string $expectedLogMessage,
+ ): void {
$userStatus = $this->getUserStatus();
if ($expectException) {
@@ -173,7 +139,7 @@ class UserStatusControllerTest extends TestCase {
}
}
- public function setStatusDataProvider(): array {
+ public static function setStatusDataProvider(): array {
return [
['busy', '👨🏽‍💻', 'Busy developing the status feature', 500, true, false, null, false, null],
['busy', '👨🏽‍💻', 'Busy developing the status feature', 500, false, true, new InvalidStatusTypeException('Original exception message'), true,
@@ -181,24 +147,16 @@ class UserStatusControllerTest extends TestCase {
];
}
- /**
- * @param string $messageId
- * @param int|null $clearAt
- * @param bool $expectSuccess
- * @param bool $expectException
- * @param Throwable|null $exception
- * @param bool $expectLogger
- * @param string|null $expectedLogMessage
- *
- * @dataProvider setPredefinedMessageDataProvider
- */
- public function testSetPredefinedMessage(string $messageId,
+ #[\PHPUnit\Framework\Attributes\DataProvider('setPredefinedMessageDataProvider')]
+ public function testSetPredefinedMessage(
+ string $messageId,
?int $clearAt,
bool $expectSuccess,
bool $expectException,
?Throwable $exception,
bool $expectLogger,
- ?string $expectedLogMessage): void {
+ ?string $expectedLogMessage,
+ ): void {
$userStatus = $this->getUserStatus();
if ($expectException) {
@@ -239,7 +197,7 @@ class UserStatusControllerTest extends TestCase {
}
}
- public function setPredefinedMessageDataProvider(): array {
+ public static function setPredefinedMessageDataProvider(): array {
return [
['messageId-42', 500, true, false, null, false, null],
['messageId-42', 500, false, true, new InvalidClearAtException('Original exception message'), true,
@@ -249,20 +207,9 @@ class UserStatusControllerTest extends TestCase {
];
}
- /**
- * @param string|null $statusIcon
- * @param string $message
- * @param int|null $clearAt
- * @param bool $expectSuccess
- * @param bool $expectException
- * @param Throwable|null $exception
- * @param bool $expectLogger
- * @param string|null $expectedLogMessage
- * @param bool $expectSuccessAsReset
- *
- * @dataProvider setCustomMessageDataProvider
- */
- public function testSetCustomMessage(?string $statusIcon,
+ #[\PHPUnit\Framework\Attributes\DataProvider('setCustomMessageDataProvider')]
+ public function testSetCustomMessage(
+ ?string $statusIcon,
string $message,
?int $clearAt,
bool $expectSuccess,
@@ -270,7 +217,8 @@ class UserStatusControllerTest extends TestCase {
?Throwable $exception,
bool $expectLogger,
?string $expectedLogMessage,
- bool $expectSuccessAsReset = false): void {
+ bool $expectSuccessAsReset = false,
+ ): void {
$userStatus = $this->getUserStatus();
if ($expectException) {
@@ -326,7 +274,7 @@ class UserStatusControllerTest extends TestCase {
}
}
- public function setCustomMessageDataProvider(): array {
+ public static function setCustomMessageDataProvider(): array {
return [
['👨🏽‍💻', 'Busy developing the status feature', 500, true, false, null, false, null],
['👨🏽‍💻', '', 500, true, false, null, false, null, false],
diff --git a/apps/user_status/tests/Unit/Dashboard/UserStatusWidgetTest.php b/apps/user_status/tests/Unit/Dashboard/UserStatusWidgetTest.php
index 9e1c39f6858..8773b04c95f 100644
--- a/apps/user_status/tests/Unit/Dashboard/UserStatusWidgetTest.php
+++ b/apps/user_status/tests/Unit/Dashboard/UserStatusWidgetTest.php
@@ -3,27 +3,8 @@
declare(strict_types=1);
/**
- * @copyright Copyright (c) 2020, Georg Ehrke
- *
- * @author Christoph Wurst <christoph@winzerhof-wurst.at>
- * @author Georg Ehrke <oc.list@georgehrke.com>
- * @author Richard Steinmetz <richard@steinmetz.cloud>
- *
- * @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/>.
- *
+ * SPDX-FileCopyrightText: 2020 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\UserStatus\Tests\Dashboard;
@@ -35,33 +16,18 @@ use OCP\IL10N;
use OCP\IURLGenerator;
use OCP\IUserManager;
use OCP\IUserSession;
+use PHPUnit\Framework\MockObject\MockObject;
use Test\TestCase;
class UserStatusWidgetTest extends TestCase {
-
- /** @var IL10N|\PHPUnit\Framework\MockObject\MockObject */
- private $l10n;
-
- /** @var IDateTimeFormatter|\PHPUnit\Framework\MockObject\MockObject */
- private $dateTimeFormatter;
-
- /** @var IURLGenerator|\PHPUnit\Framework\MockObject\MockObject */
- private $urlGenerator;
-
- /** @var IInitialState|\PHPUnit\Framework\MockObject\MockObject */
- private $initialState;
-
- /** @var IUserManager|\PHPUnit\Framework\MockObject\MockObject */
- private $userManager;
-
- /** @var IUserSession|\PHPUnit\Framework\MockObject\MockObject */
- private $userSession;
-
- /** @var StatusService|\PHPUnit\Framework\MockObject\MockObject */
- private $service;
-
- /** @var UserStatusWidget */
- private $widget;
+ private IL10N&MockObject $l10n;
+ private IDateTimeFormatter&MockObject $dateTimeFormatter;
+ private IURLGenerator&MockObject $urlGenerator;
+ private IInitialState&MockObject $initialState;
+ private IUserManager&MockObject $userManager;
+ private IUserSession&MockObject $userSession;
+ private StatusService&MockObject $service;
+ private UserStatusWidget $widget;
protected function setUp(): void {
parent::setUp();
diff --git a/apps/user_status/tests/Unit/Db/UserStatusMapperTest.php b/apps/user_status/tests/Unit/Db/UserStatusMapperTest.php
index 58267aed5f4..ea4480489c7 100644
--- a/apps/user_status/tests/Unit/Db/UserStatusMapperTest.php
+++ b/apps/user_status/tests/Unit/Db/UserStatusMapperTest.php
@@ -3,26 +3,8 @@
declare(strict_types=1);
/**
- * @copyright Copyright (c) 2020, Georg Ehrke
- *
- * @author Christoph Wurst <christoph@winzerhof-wurst.at>
- * @author Georg Ehrke <oc.list@georgehrke.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/>.
- *
+ * SPDX-FileCopyrightText: 2020 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\UserStatus\Tests\Db;
@@ -33,9 +15,7 @@ use OCP\DB\Exception;
use Test\TestCase;
class UserStatusMapperTest extends TestCase {
-
- /** @var UserStatusMapper */
- private $mapper;
+ private UserStatusMapper $mapper;
protected function setUp(): void {
parent::setUp();
@@ -154,14 +134,7 @@ class UserStatusMapperTest extends TestCase {
$this->mapper->insert($userStatus2);
}
- /**
- * @param string $status
- * @param bool $isUserDefined
- * @param int $timestamp
- * @param bool $expectsClean
- *
- * @dataProvider clearStatusesOlderThanDataProvider
- */
+ #[\PHPUnit\Framework\Attributes\DataProvider('clearStatusesOlderThanDataProvider')]
public function testClearStatusesOlderThan(string $status, bool $isUserDefined, int $timestamp, bool $expectsClean): void {
$oldStatus = UserStatus::fromParams([
'userId' => 'john.doe',
@@ -187,7 +160,7 @@ class UserStatusMapperTest extends TestCase {
}
}
- public function clearStatusesOlderThanDataProvider(): array {
+ public static function clearStatusesOlderThanDataProvider(): array {
return [
['offline', false, 6000, false],
['online', true, 6000, false],
@@ -249,7 +222,7 @@ class UserStatusMapperTest extends TestCase {
$this->mapper->insert($userStatus3);
}
- public function dataCreateBackupStatus(): array {
+ public static function dataCreateBackupStatus(): array {
return [
[false, false, false],
[true, false, true],
@@ -258,12 +231,7 @@ class UserStatusMapperTest extends TestCase {
];
}
- /**
- * @dataProvider dataCreateBackupStatus
- * @param bool $hasStatus
- * @param bool $hasBackup
- * @param bool $backupCreated
- */
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataCreateBackupStatus')]
public function testCreateBackupStatus(bool $hasStatus, bool $hasBackup, bool $backupCreated): void {
if ($hasStatus) {
$userStatus1 = new UserStatus();
diff --git a/apps/user_status/tests/Unit/Listener/UserDeletedListenerTest.php b/apps/user_status/tests/Unit/Listener/UserDeletedListenerTest.php
index 883a06059f7..fbcea23338d 100644
--- a/apps/user_status/tests/Unit/Listener/UserDeletedListenerTest.php
+++ b/apps/user_status/tests/Unit/Listener/UserDeletedListenerTest.php
@@ -3,25 +3,8 @@
declare(strict_types=1);
/**
- * @copyright Copyright (c) 2020, Georg Ehrke
- *
- * @author Georg Ehrke <oc.list@georgehrke.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/>.
- *
+ * SPDX-FileCopyrightText: 2020 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\UserStatus\Tests\Listener;
@@ -30,15 +13,12 @@ use OCA\UserStatus\Service\StatusService;
use OCP\EventDispatcher\GenericEvent;
use OCP\IUser;
use OCP\User\Events\UserDeletedEvent;
+use PHPUnit\Framework\MockObject\MockObject;
use Test\TestCase;
class UserDeletedListenerTest extends TestCase {
-
- /** @var StatusService|\PHPUnit\Framework\MockObject\MockObject */
- private $service;
-
- /** @var UserDeletedListener */
- private $listener;
+ private StatusService&MockObject $service;
+ private UserDeletedListener $listener;
protected function setUp(): void {
parent::setUp();
diff --git a/apps/user_status/tests/Unit/Listener/UserLiveStatusListenerTest.php b/apps/user_status/tests/Unit/Listener/UserLiveStatusListenerTest.php
index 2bef6773702..c03eed0089e 100644
--- a/apps/user_status/tests/Unit/Listener/UserLiveStatusListenerTest.php
+++ b/apps/user_status/tests/Unit/Listener/UserLiveStatusListenerTest.php
@@ -3,33 +3,14 @@
declare(strict_types=1);
/**
- * @copyright Copyright (c) 2020, Georg Ehrke
- *
- * @author Daniel Kesselberg <mail@danielkesselberg.de>
- * @author Georg Ehrke <oc.list@georgehrke.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/>.
- *
+ * SPDX-FileCopyrightText: 2020 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\UserStatus\Tests\Listener;
use OCA\DAV\CalDAV\Status\StatusService as CalendarStatusService;
use OCA\UserStatus\Db\UserStatus;
use OCA\UserStatus\Db\UserStatusMapper;
-use OCA\UserStatus\Listener\UserDeletedListener;
use OCA\UserStatus\Listener\UserLiveStatusListener;
use OCA\UserStatus\Service\StatusService;
use OCP\AppFramework\Db\DoesNotExistException;
@@ -42,20 +23,13 @@ use Psr\Log\LoggerInterface;
use Test\TestCase;
class UserLiveStatusListenerTest extends TestCase {
+ private UserStatusMapper&MockObject $mapper;
+ private StatusService&MockObject $statusService;
+ private ITimeFactory&MockObject $timeFactory;
+ private CalendarStatusService&MockObject $calendarStatusService;
- /** @var UserStatusMapper|MockObject */
- private $mapper;
- /** @var StatusService|MockObject */
- private $statusService;
- /** @var ITimeFactory|MockObject */
- private $timeFactory;
-
- /** @var UserDeletedListener */
- private $listener;
-
- private CalendarStatusService|MockObject $calendarStatusService;
-
- private LoggerInterface|MockObject $logger;
+ private LoggerInterface&MockObject $logger;
+ private UserLiveStatusListener $listener;
protected function setUp(): void {
parent::setUp();
@@ -75,26 +49,17 @@ class UserLiveStatusListenerTest extends TestCase {
);
}
- /**
- * @param string $userId
- * @param string $previousStatus
- * @param int $previousTimestamp
- * @param bool $previousIsUserDefined
- * @param string $eventStatus
- * @param int $eventTimestamp
- * @param bool $expectExisting
- * @param bool $expectUpdate
- *
- * @dataProvider handleEventWithCorrectEventDataProvider
- */
- public function testHandleWithCorrectEvent(string $userId,
+ #[\PHPUnit\Framework\Attributes\DataProvider('handleEventWithCorrectEventDataProvider')]
+ public function testHandleWithCorrectEvent(
+ string $userId,
string $previousStatus,
int $previousTimestamp,
bool $previousIsUserDefined,
string $eventStatus,
int $eventTimestamp,
bool $expectExisting,
- bool $expectUpdate): void {
+ bool $expectUpdate,
+ ): void {
$userStatus = new UserStatus();
if ($expectExisting) {
@@ -161,7 +126,7 @@ class UserLiveStatusListenerTest extends TestCase {
}
}
- public function handleEventWithCorrectEventDataProvider(): array {
+ public static function handleEventWithCorrectEventDataProvider(): array {
return [
['john.doe', 'offline', 0, false, 'online', 5000, true, true],
['john.doe', 'offline', 0, false, 'online', 5000, false, true],
diff --git a/apps/user_status/tests/Unit/Service/PredefinedStatusServiceTest.php b/apps/user_status/tests/Unit/Service/PredefinedStatusServiceTest.php
index c6850621dd8..78e4a18d9f1 100644
--- a/apps/user_status/tests/Unit/Service/PredefinedStatusServiceTest.php
+++ b/apps/user_status/tests/Unit/Service/PredefinedStatusServiceTest.php
@@ -3,40 +3,19 @@
declare(strict_types=1);
/**
- * @copyright Copyright (c) 2020, Georg Ehrke
- *
- * @author Daniel Kesselberg <mail@danielkesselberg.de>
- * @author Georg Ehrke <oc.list@georgehrke.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/>.
- *
+ * SPDX-FileCopyrightText: 2020 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\UserStatus\Tests\Service;
use OCA\UserStatus\Service\PredefinedStatusService;
use OCP\IL10N;
+use PHPUnit\Framework\MockObject\MockObject;
use Test\TestCase;
class PredefinedStatusServiceTest extends TestCase {
-
- /** @var IL10N|\PHPUnit\Framework\MockObject\MockObject */
- protected $l10n;
-
- /** @var PredefinedStatusService */
- protected $service;
+ protected IL10N&MockObject $l10n;
+ protected PredefinedStatusService $service;
protected function setUp(): void {
parent::setUp();
@@ -47,17 +26,11 @@ class PredefinedStatusServiceTest extends TestCase {
}
public function testGetDefaultStatuses(): void {
- $this->l10n->expects($this->exactly(7))
+ $this->l10n->expects($this->exactly(8))
->method('t')
- ->withConsecutive(
- ['In a meeting'],
- ['Commuting'],
- ['Working remotely'],
- ['Out sick'],
- ['Vacationing'],
- ['In a call'],
- )
- ->willReturnArgument(0);
+ ->willReturnCallback(function ($text, $parameters = []) {
+ return vsprintf($text, $parameters);
+ });
$actual = $this->service->getDefaultStatuses();
$this->assertEquals([
@@ -80,6 +53,15 @@ class PredefinedStatusServiceTest extends TestCase {
],
],
[
+ 'id' => 'be-right-back',
+ 'icon' => '⏳',
+ 'message' => 'Be right back',
+ 'clearAt' => [
+ 'type' => 'period',
+ 'time' => 900,
+ ],
+ ],
+ [
'id' => 'remote-work',
'icon' => '🏡',
'message' => 'Working remotely',
@@ -120,38 +102,26 @@ class PredefinedStatusServiceTest extends TestCase {
], $actual);
}
- /**
- * @param string $id
- * @param string|null $expectedIcon
- *
- * @dataProvider getIconForIdDataProvider
- */
+ #[\PHPUnit\Framework\Attributes\DataProvider('getIconForIdDataProvider')]
public function testGetIconForId(string $id, ?string $expectedIcon): void {
$actual = $this->service->getIconForId($id);
$this->assertEquals($expectedIcon, $actual);
}
- /**
- * @return array
- */
- public function getIconForIdDataProvider(): array {
+ public static function getIconForIdDataProvider(): array {
return [
['meeting', '📅'],
['commuting', '🚌'],
['sick-leave', '🤒'],
['vacationing', '🌴'],
['remote-work', '🏡'],
+ ['be-right-back', '⏳'],
['call', '💬'],
['unknown-id', null],
];
}
- /**
- * @param string $id
- * @param string|null $expected
- *
- * @dataProvider getTranslatedStatusForIdDataProvider
- */
+ #[\PHPUnit\Framework\Attributes\DataProvider('getTranslatedStatusForIdDataProvider')]
public function testGetTranslatedStatusForId(string $id, ?string $expected): void {
$this->l10n->method('t')
->willReturnArgument(0);
@@ -160,59 +130,44 @@ class PredefinedStatusServiceTest extends TestCase {
$this->assertEquals($expected, $actual);
}
- /**
- * @return array
- */
- public function getTranslatedStatusForIdDataProvider(): array {
+ public static function getTranslatedStatusForIdDataProvider(): array {
return [
['meeting', 'In a meeting'],
['commuting', 'Commuting'],
['sick-leave', 'Out sick'],
['vacationing', 'Vacationing'],
['remote-work', 'Working remotely'],
+ ['be-right-back', 'Be right back'],
['call', 'In a call'],
['unknown-id', null],
];
}
- /**
- * @param string $id
- * @param bool $expected
- *
- * @dataProvider isValidIdDataProvider
- */
+ #[\PHPUnit\Framework\Attributes\DataProvider('isValidIdDataProvider')]
public function testIsValidId(string $id, bool $expected): void {
$actual = $this->service->isValidId($id);
$this->assertEquals($expected, $actual);
}
- /**
- * @return array
- */
- public function isValidIdDataProvider(): array {
+ public static function isValidIdDataProvider(): array {
return [
['meeting', true],
['commuting', true],
['sick-leave', true],
['vacationing', true],
['remote-work', true],
+ ['be-right-back', true],
['call', true],
['unknown-id', false],
];
}
public function testGetDefaultStatusById(): void {
- $this->l10n->expects($this->exactly(7))
+ $this->l10n->expects($this->exactly(8))
->method('t')
- ->withConsecutive(
- ['In a meeting'],
- ['Commuting'],
- ['Working remotely'],
- ['Out sick'],
- ['Vacationing'],
- ['In a call'],
- )
- ->willReturnArgument(0);
+ ->willReturnCallback(function ($text, $parameters = []) {
+ return vsprintf($text, $parameters);
+ });
$this->assertEquals([
'id' => 'call',
diff --git a/apps/user_status/tests/Unit/Service/StatusServiceTest.php b/apps/user_status/tests/Unit/Service/StatusServiceTest.php
index da11ec0943b..7dfa5b0d064 100644
--- a/apps/user_status/tests/Unit/Service/StatusServiceTest.php
+++ b/apps/user_status/tests/Unit/Service/StatusServiceTest.php
@@ -3,26 +3,8 @@
declare(strict_types=1);
/**
- * @copyright Copyright (c) 2020, Georg Ehrke
- *
- * @author Georg Ehrke <oc.list@georgehrke.com>
- * @author 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/>.
- *
+ * SPDX-FileCopyrightText: 2020 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\UserStatus\Tests\Service;
@@ -45,27 +27,17 @@ use OCP\IEmojiHelper;
use OCP\IUserManager;
use OCP\UserStatus\IUserStatus;
use PHPUnit\Framework\MockObject\MockObject;
+use Psr\Log\LoggerInterface;
use Test\TestCase;
class StatusServiceTest extends TestCase {
-
- /** @var UserStatusMapper|MockObject */
- private $mapper;
-
- /** @var ITimeFactory|MockObject */
- private $timeFactory;
-
- /** @var PredefinedStatusService|MockObject */
- private $predefinedStatusService;
-
- /** @var IEmojiHelper|MockObject */
- private $emojiHelper;
-
- /** @var IConfig|MockObject */
- private $config;
-
- /** @var IUserManager|MockObject */
- private $userManager;
+ private UserStatusMapper&MockObject $mapper;
+ private ITimeFactory&MockObject $timeFactory;
+ private PredefinedStatusService&MockObject $predefinedStatusService;
+ private IEmojiHelper&MockObject $emojiHelper;
+ private IConfig&MockObject $config;
+ private IUserManager&MockObject $userManager;
+ private LoggerInterface&MockObject $logger;
private StatusService $service;
@@ -78,6 +50,7 @@ class StatusServiceTest extends TestCase {
$this->emojiHelper = $this->createMock(IEmojiHelper::class);
$this->userManager = $this->createMock(IUserManager::class);
$this->config = $this->createMock(IConfig::class);
+ $this->logger = $this->createMock(LoggerInterface::class);
$this->config->method('getAppValue')
->willReturnMap([
@@ -90,7 +63,8 @@ class StatusServiceTest extends TestCase {
$this->predefinedStatusService,
$this->emojiHelper,
$this->config,
- $this->userManager
+ $this->userManager,
+ $this->logger,
);
}
@@ -146,7 +120,8 @@ class StatusServiceTest extends TestCase {
$this->predefinedStatusService,
$this->emojiHelper,
$this->config,
- $this->userManager
+ $this->userManager,
+ $this->logger,
);
$this->assertEquals([], $this->service->findAllRecentStatusChanges(20, 50));
@@ -165,7 +140,8 @@ class StatusServiceTest extends TestCase {
$this->predefinedStatusService,
$this->emojiHelper,
$this->config,
- $this->userManager
+ $this->userManager,
+ $this->logger,
);
$this->assertEquals([], $this->service->findAllRecentStatusChanges(20, 50));
@@ -245,21 +221,9 @@ class StatusServiceTest extends TestCase {
$this->assertNull($status->getMessageId());
}
- /**
- * @param string $userId
- * @param string $status
- * @param int|null $statusTimestamp
- * @param bool $isUserDefined
- * @param bool $expectExisting
- * @param bool $expectSuccess
- * @param bool $expectTimeFactory
- * @param bool $expectException
- * @param string|null $expectedExceptionClass
- * @param string|null $expectedExceptionMessage
- *
- * @dataProvider setStatusDataProvider
- */
- public function testSetStatus(string $userId,
+ #[\PHPUnit\Framework\Attributes\DataProvider('setStatusDataProvider')]
+ public function testSetStatus(
+ string $userId,
string $status,
?int $statusTimestamp,
bool $isUserDefined,
@@ -268,7 +232,8 @@ class StatusServiceTest extends TestCase {
bool $expectTimeFactory,
bool $expectException,
?string $expectedExceptionClass,
- ?string $expectedExceptionMessage): void {
+ ?string $expectedExceptionMessage,
+ ): void {
$userStatus = new UserStatus();
if ($expectExisting) {
@@ -319,7 +284,7 @@ class StatusServiceTest extends TestCase {
}
}
- public function setStatusDataProvider(): array {
+ public static function setStatusDataProvider(): array {
return [
['john.doe', 'online', 50, true, true, true, false, false, null, null],
['john.doe', 'online', 50, true, false, true, false, false, null, null],
@@ -377,20 +342,9 @@ class StatusServiceTest extends TestCase {
];
}
- /**
- * @param string $userId
- * @param string $messageId
- * @param bool $isValidMessageId
- * @param int|null $clearAt
- * @param bool $expectExisting
- * @param bool $expectSuccess
- * @param bool $expectException
- * @param string|null $expectedExceptionClass
- * @param string|null $expectedExceptionMessage
- *
- * @dataProvider setPredefinedMessageDataProvider
- */
- public function testSetPredefinedMessage(string $userId,
+ #[\PHPUnit\Framework\Attributes\DataProvider('setPredefinedMessageDataProvider')]
+ public function testSetPredefinedMessage(
+ string $userId,
string $messageId,
bool $isValidMessageId,
?int $clearAt,
@@ -398,7 +352,8 @@ class StatusServiceTest extends TestCase {
bool $expectSuccess,
bool $expectException,
?string $expectedExceptionClass,
- ?string $expectedExceptionMessage): void {
+ ?string $expectedExceptionMessage,
+ ): void {
$userStatus = new UserStatus();
if ($expectExisting) {
@@ -461,7 +416,7 @@ class StatusServiceTest extends TestCase {
}
}
- public function setPredefinedMessageDataProvider(): array {
+ public static function setPredefinedMessageDataProvider(): array {
return [
['john.doe', 'sick-leave', true, null, true, true, false, null, null],
['john.doe', 'sick-leave', true, null, false, true, false, null, null],
@@ -474,21 +429,9 @@ class StatusServiceTest extends TestCase {
];
}
- /**
- * @param string $userId
- * @param string|null $statusIcon
- * @param bool $supportsEmoji
- * @param string $message
- * @param int|null $clearAt
- * @param bool $expectExisting
- * @param bool $expectSuccess
- * @param bool $expectException
- * @param string|null $expectedExceptionClass
- * @param string|null $expectedExceptionMessage
- *
- * @dataProvider setCustomMessageDataProvider
- */
- public function testSetCustomMessage(string $userId,
+ #[\PHPUnit\Framework\Attributes\DataProvider('setCustomMessageDataProvider')]
+ public function testSetCustomMessage(
+ string $userId,
?string $statusIcon,
bool $supportsEmoji,
string $message,
@@ -497,7 +440,8 @@ class StatusServiceTest extends TestCase {
bool $expectSuccess,
bool $expectException,
?string $expectedExceptionClass,
- ?string $expectedExceptionMessage): void {
+ ?string $expectedExceptionMessage,
+ ): void {
$userStatus = new UserStatus();
if ($expectExisting) {
@@ -558,7 +502,7 @@ class StatusServiceTest extends TestCase {
}
}
- public function setCustomMessageDataProvider(): array {
+ public static function setCustomMessageDataProvider(): array {
return [
['john.doe', '😁', true, 'Custom message', null, true, true, false, null, null],
['john.doe', '😁', true, 'Custom message', null, false, true, false, null, null],
@@ -749,7 +693,6 @@ class StatusServiceTest extends TestCase {
}
public function testBackup(): void {
- $e = new Exception('', Exception::REASON_UNIQUE_CONSTRAINT_VIOLATION);
$this->mapper->expects($this->once())
->method('createBackupStatus')
->with('john')
@@ -825,4 +768,61 @@ class StatusServiceTest extends TestCase {
$this->service->revertMultipleUserStatus(['john', 'nobackup', 'backuponly', 'nobackupanddnd'], 'call');
}
+
+ public static function dataSetUserStatus(): array {
+ return [
+ [IUserStatus::MESSAGE_CALENDAR_BUSY, '', false],
+
+ // Call > Meeting
+ [IUserStatus::MESSAGE_CALENDAR_BUSY, IUserStatus::MESSAGE_CALL, false],
+ [IUserStatus::MESSAGE_CALL, IUserStatus::MESSAGE_CALENDAR_BUSY, true],
+
+ // Availability > Call&Meeting
+ [IUserStatus::MESSAGE_CALENDAR_BUSY, IUserStatus::MESSAGE_AVAILABILITY, false],
+ [IUserStatus::MESSAGE_CALL, IUserStatus::MESSAGE_AVAILABILITY, false],
+ [IUserStatus::MESSAGE_AVAILABILITY, IUserStatus::MESSAGE_CALENDAR_BUSY, true],
+ [IUserStatus::MESSAGE_AVAILABILITY, IUserStatus::MESSAGE_CALL, true],
+
+ // Out-of-office > Availability&Call&Meeting
+ [IUserStatus::MESSAGE_AVAILABILITY, IUserStatus::MESSAGE_OUT_OF_OFFICE, false],
+ [IUserStatus::MESSAGE_CALENDAR_BUSY, IUserStatus::MESSAGE_OUT_OF_OFFICE, false],
+ [IUserStatus::MESSAGE_CALL, IUserStatus::MESSAGE_OUT_OF_OFFICE, false],
+ [IUserStatus::MESSAGE_OUT_OF_OFFICE, IUserStatus::MESSAGE_AVAILABILITY, true],
+ [IUserStatus::MESSAGE_OUT_OF_OFFICE, IUserStatus::MESSAGE_CALENDAR_BUSY, true],
+ [IUserStatus::MESSAGE_OUT_OF_OFFICE, IUserStatus::MESSAGE_CALL, true],
+ ];
+ }
+
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataSetUserStatus')]
+ public function testSetUserStatus(string $messageId, string $oldMessageId, bool $expectedUpdateShortcut): void {
+ $previous = new UserStatus();
+ $previous->setId(1);
+ $previous->setStatus(IUserStatus::AWAY);
+ $previous->setStatusTimestamp(1337);
+ $previous->setIsUserDefined(false);
+ $previous->setMessageId($oldMessageId);
+ $previous->setUserId('john');
+ $previous->setIsBackup(false);
+
+ $this->mapper->expects($this->once())
+ ->method('findByUserId')
+ ->with('john')
+ ->willReturn($previous);
+
+ $e = DbalException::wrap($this->createMock(UniqueConstraintViolationException::class));
+ $this->mapper->expects($expectedUpdateShortcut ? $this->never() : $this->once())
+ ->method('createBackupStatus')
+ ->willThrowException($e);
+
+ $this->mapper->expects($this->any())
+ ->method('update')
+ ->willReturnArgument(0);
+
+ $this->predefinedStatusService->expects($this->once())
+ ->method('isValidId')
+ ->with($messageId)
+ ->willReturn(true);
+
+ $this->service->setUserStatus('john', IUserStatus::DND, $messageId, true);
+ }
}
diff --git a/apps/user_status/tests/bootstrap.php b/apps/user_status/tests/bootstrap.php
index b6d8fc06417..c98daca1dfc 100644
--- a/apps/user_status/tests/bootstrap.php
+++ b/apps/user_status/tests/bootstrap.php
@@ -3,34 +3,18 @@
declare(strict_types=1);
/**
- * @copyright Copyright (c) 2020, Georg Ehrke
- *
- * @author Georg Ehrke <oc.list@georgehrke.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/>.
- *
+ * SPDX-FileCopyrightText: 2020 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
*/
+
+use OCP\App\IAppManager;
+use OCP\Server;
+
if (!defined('PHPUNIT_RUN')) {
define('PHPUNIT_RUN', 1);
}
-require_once __DIR__.'/../../../lib/base.php';
-
-\OC::$composerAutoloader->addPsr4('Test\\', OC::$SERVERROOT . '/tests/lib/', true);
-
-\OC_App::loadApp('user_status');
+require_once __DIR__ . '/../../../lib/base.php';
+require_once __DIR__ . '/../../../tests/autoload.php';
-OC_Hook::clear();
+Server::get(IAppManager::class)->loadApp('user_status');