diff options
Diffstat (limited to 'apps/user_status/tests/Unit/Db')
-rw-r--r-- | apps/user_status/tests/Unit/Db/UserStatusMapperTest.php | 67 |
1 files changed, 16 insertions, 51 deletions
diff --git a/apps/user_status/tests/Unit/Db/UserStatusMapperTest.php b/apps/user_status/tests/Unit/Db/UserStatusMapperTest.php index 0d9f1c1f718..ea4480489c7 100644 --- a/apps/user_status/tests/Unit/Db/UserStatusMapperTest.php +++ b/apps/user_status/tests/Unit/Db/UserStatusMapperTest.php @@ -3,38 +3,19 @@ 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; use OCA\UserStatus\Db\UserStatus; use OCA\UserStatus\Db\UserStatusMapper; +use OCP\AppFramework\Db\DoesNotExistException; use OCP\DB\Exception; use Test\TestCase; class UserStatusMapperTest extends TestCase { - - /** @var UserStatusMapper */ - private $mapper; + private UserStatusMapper $mapper; protected function setUp(): void { parent::setUp(); @@ -153,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', @@ -186,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], @@ -204,22 +178,16 @@ class UserStatusMapperTest extends TestCase { ]; } - public function testClearMessagesOlderThan(): void { + public function testClearOlderThanClearAt(): void { $this->insertSampleStatuses(); - $this->mapper->clearMessagesOlderThan(55000); + $this->mapper->clearOlderThanClearAt(55000); $allStatuses = $this->mapper->findAll(); - $this->assertCount(3, $allStatuses); + $this->assertCount(2, $allStatuses); - $user1Status = $this->mapper->findByUserId('user1'); - $this->assertEquals('user1', $user1Status->getUserId()); - $this->assertEquals('dnd', $user1Status->getStatus()); - $this->assertEquals(5000, $user1Status->getStatusTimestamp()); - $this->assertEquals(true, $user1Status->getIsUserDefined()); - $this->assertEquals(null, $user1Status->getCustomIcon()); - $this->assertEquals(null, $user1Status->getCustomMessage()); - $this->assertEquals(null, $user1Status->getClearAt()); + $this->expectException(DoesNotExistException::class); + $this->mapper->findByUserId('user1'); } private function insertSampleStatuses(): void { @@ -233,6 +201,7 @@ class UserStatusMapperTest extends TestCase { $userStatus2->setUserId('user1'); $userStatus2->setStatus('dnd'); $userStatus2->setStatusTimestamp(5000); + $userStatus2->setStatusMessageTimestamp(5000); $userStatus2->setIsUserDefined(true); $userStatus2->setCustomIcon('💩'); $userStatus2->setCustomMessage('Do not disturb'); @@ -242,6 +211,7 @@ class UserStatusMapperTest extends TestCase { $userStatus3->setUserId('user2'); $userStatus3->setStatus('away'); $userStatus3->setStatusTimestamp(6000); + $userStatus3->setStatusMessageTimestamp(6000); $userStatus3->setIsUserDefined(false); $userStatus3->setCustomIcon('🏝'); $userStatus3->setCustomMessage('On vacation'); @@ -252,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], @@ -261,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(); @@ -305,7 +270,7 @@ class UserStatusMapperTest extends TestCase { $this->assertEquals('_user1', $user1Status->getUserId()); $this->assertEquals(true, $user1Status->getIsBackup()); $this->assertEquals('Current', $user1Status->getCustomMessage()); - } else if ($hasBackup) { + } elseif ($hasBackup) { $user1Status = $this->mapper->findByUserId('user1', true); $this->assertEquals('_user1', $user1Status->getUserId()); $this->assertEquals(true, $user1Status->getIsBackup()); |