diff options
Diffstat (limited to 'tests/lib/User/AvailabilityCoordinatorTest.php')
-rw-r--r-- | tests/lib/User/AvailabilityCoordinatorTest.php | 48 |
1 files changed, 25 insertions, 23 deletions
diff --git a/tests/lib/User/AvailabilityCoordinatorTest.php b/tests/lib/User/AvailabilityCoordinatorTest.php index b41b1fbac2a..09c1528912b 100644 --- a/tests/lib/User/AvailabilityCoordinatorTest.php +++ b/tests/lib/User/AvailabilityCoordinatorTest.php @@ -3,25 +3,8 @@ declare(strict_types=1); /** - * @copyright Copyright (c) 2023 Richard Steinmetz <richard@steinmetz.cloud> - * - * @author Richard Steinmetz <richard@steinmetz.cloud> - * - * @license AGPL-3.0-or-later - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU 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 General Public License for more details. - * - * You should have received a copy of the GNU 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 Test\User; @@ -90,6 +73,8 @@ class AvailabilityCoordinatorTest extends TestCase { $absence->setLastDay('2023-10-08'); $absence->setStatus('Vacation'); $absence->setMessage('On vacation'); + $absence->setReplacementUserId('batman'); + $absence->setReplacementUserDisplayName('Bruce Wayne'); $this->timezoneService->method('getUserTimezone')->with('user')->willReturn('Europe/Berlin'); $user = $this->createMock(IUser::class); @@ -103,10 +88,17 @@ class AvailabilityCoordinatorTest extends TestCase { ->method('getAbsence') ->with($user->getUID()) ->willReturn($absence); + + $calls = [ + [$user->getUID() . '_timezone', 'Europe/Berlin', 3600], + [$user->getUID(), '{"id":"420","startDate":1696111200,"endDate":1696802340,"shortMessage":"Vacation","message":"On vacation","replacementUserId":"batman","replacementUserDisplayName":"Bruce Wayne"}', 300], + ]; $this->cache->expects(self::exactly(2)) ->method('set') - ->withConsecutive([$user->getUID() . '_timezone', 'Europe/Berlin', 3600], - [$user->getUID(), '{"id":"420","startDate":1696111200,"endDate":1696802340,"shortMessage":"Vacation","message":"On vacation"}', 300]); + ->willReturnCallback(static function () use (&$calls): void { + $expected = array_shift($calls); + self::assertEquals($expected, func_get_args()); + }); $expected = new OutOfOfficeData( '420', @@ -115,6 +107,8 @@ class AvailabilityCoordinatorTest extends TestCase { 1696802340, 'Vacation', 'On vacation', + 'batman', + 'Bruce Wayne', ); $actual = $this->availabilityCoordinator->getCurrentOutOfOfficeData($user); self::assertEquals($expected, $actual); @@ -128,6 +122,8 @@ class AvailabilityCoordinatorTest extends TestCase { $absence->setLastDay('2023-10-08'); $absence->setStatus('Vacation'); $absence->setMessage('On vacation'); + $absence->setReplacementUserId('batman'); + $absence->setReplacementUserDisplayName('Bruce Wayne'); $user = $this->createMock(IUser::class); $user->method('getUID') @@ -135,7 +131,7 @@ class AvailabilityCoordinatorTest extends TestCase { $this->cache->expects(self::exactly(2)) ->method('get') - ->willReturnOnConsecutiveCalls('UTC', '{"id":"420","startDate":1696118400,"endDate":1696809540,"shortMessage":"Vacation","message":"On vacation"}'); + ->willReturnOnConsecutiveCalls('UTC', '{"id":"420","startDate":1696118400,"endDate":1696809540,"shortMessage":"Vacation","message":"On vacation","replacementUserId":"batman","replacementUserDisplayName":"Bruce Wayne"}'); $this->absenceService->expects(self::never()) ->method('getAbsence'); $this->cache->expects(self::exactly(1)) @@ -148,6 +144,8 @@ class AvailabilityCoordinatorTest extends TestCase { 1696809540, 'Vacation', 'On vacation', + 'batman', + 'Bruce Wayne' ); $actual = $this->availabilityCoordinator->getCurrentOutOfOfficeData($user); self::assertEquals($expected, $actual); @@ -187,6 +185,8 @@ class AvailabilityCoordinatorTest extends TestCase { $absence->setLastDay('2023-10-08'); $absence->setStatus('Vacation'); $absence->setMessage('On vacation'); + $absence->setReplacementUserId('batman'); + $absence->setReplacementUserDisplayName('Bruce Wayne'); $this->timezoneService->method('getUserTimezone')->with('user')->willReturn('Europe/Berlin'); $user = $this->createMock(IUser::class); @@ -202,7 +202,7 @@ class AvailabilityCoordinatorTest extends TestCase { ->willReturn($absence); $this->cache->expects(self::once()) ->method('set') - ->with('user', '{"id":"420","startDate":1696118400,"endDate":1696809540,"shortMessage":"Vacation","message":"On vacation"}', 300); + ->with('user', '{"id":"420","startDate":1696118400,"endDate":1696809540,"shortMessage":"Vacation","message":"On vacation","replacementUserId":"batman","replacementUserDisplayName":"Bruce Wayne"}', 300); $expected = new OutOfOfficeData( '420', @@ -211,6 +211,8 @@ class AvailabilityCoordinatorTest extends TestCase { 1696809540, 'Vacation', 'On vacation', + 'batman', + 'Bruce Wayne' ); $actual = $this->availabilityCoordinator->getCurrentOutOfOfficeData($user); self::assertEquals($expected, $actual); |