From 154d390c02b55f6e59dcdfb21780d9f178a1ef1c Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sat, 24 May 2025 23:00:05 +0200 Subject: test: Migrate CalDAV tests to PHPUnit10 Signed-off-by: Joas Schilling --- apps/dav/tests/unit/AppInfo/ApplicationTest.php | 1 + apps/dav/tests/unit/AppInfo/PluginManagerTest.php | 2 + apps/dav/tests/unit/Avatars/AvatarHomeTest.php | 18 +- apps/dav/tests/unit/Avatars/AvatarNodeTest.php | 6 +- .../CleanupInvitationTokenJobTest.php | 12 +- .../CleanupOrphanedChildrenJobTest.php | 31 +- .../unit/BackgroundJob/EventReminderJobTest.php | 29 +- .../GenerateBirthdayCalendarBackgroundJobTest.php | 16 +- .../OutOfOfficeEventDispatcherJobTest.php | 20 +- .../PruneOutdatedSyncTokensJobTest.php | 22 +- .../unit/BackgroundJob/RefreshWebcalJobTest.php | 22 +- .../RegisterRegenerateBirthdayCalendarsTest.php | 48 +- ...dateCalendarResourcesRoomsBackgroundJobTest.php | 12 +- .../BackgroundJob/UserStatusAutomationTest.php | 19 +- .../tests/unit/CalDAV/AbstractCalDavBackend.php | 20 +- .../dav/tests/unit/CalDAV/Activity/BackendTest.php | 57 +-- .../unit/CalDAV/Activity/Filter/CalendarTest.php | 15 +- .../unit/CalDAV/Activity/Filter/GenericTest.php | 25 +- .../tests/unit/CalDAV/Activity/Filter/TodoTest.php | 15 +- .../unit/CalDAV/Activity/Provider/BaseTest.php | 42 +- .../unit/CalDAV/Activity/Provider/EventTest.php | 54 +- .../unit/CalDAV/Activity/Setting/GenericTest.php | 28 +- .../unit/CalDAV/AppCalendar/AppCalendarTest.php | 17 +- .../unit/CalDAV/AppCalendar/CalendarObjectTest.php | 7 +- .../CalDAV/BirthdayCalendar/EnablePluginTest.php | 23 +- .../unit/CalDAV/CachedSubscriptionImplTest.php | 5 +- .../unit/CalDAV/CachedSubscriptionObjectTest.php | 6 +- .../unit/CalDAV/CachedSubscriptionProviderTest.php | 3 +- .../tests/unit/CalDAV/CachedSubscriptionTest.php | 48 +- apps/dav/tests/unit/CalDAV/CalDavBackendTest.php | 14 +- apps/dav/tests/unit/CalDAV/CalendarHomeTest.php | 28 +- apps/dav/tests/unit/CalDAV/CalendarImplTest.php | 11 +- apps/dav/tests/unit/CalDAV/CalendarManagerTest.php | 23 +- apps/dav/tests/unit/CalDAV/CalendarTest.php | 57 +-- .../unit/CalDAV/EventComparisonServiceTest.php | 3 +- .../tests/unit/CalDAV/Export/ExportServiceTest.php | 9 +- .../CalDAV/Integration/ExternalCalendarTest.php | 9 +- .../Listener/CalendarPublicationListenerTest.php | 19 +- .../Listener/CalendarShareUpdateListenerTest.php | 15 +- .../CalDAV/Listener/SubscriptionListenerTest.php | 27 +- apps/dav/tests/unit/CalDAV/OutboxTest.php | 11 +- apps/dav/tests/unit/CalDAV/PluginTest.php | 12 +- .../tests/unit/CalDAV/PublicCalendarRootTest.php | 39 +- apps/dav/tests/unit/CalDAV/PublicCalendarTest.php | 22 +- .../tests/unit/CalDAV/Publishing/PublisherTest.php | 8 +- .../unit/CalDAV/Publishing/PublishingTest.php | 27 +- .../dav/tests/unit/CalDAV/Reminder/BackendTest.php | 49 +- .../AbstractNotificationProviderTest.php | 75 --- .../AbstractNotificationProviderTestCase.php | 52 ++ .../NotificationProvider/EmailProviderTest.php | 82 +-- .../NotificationProvider/PushProviderTest.php | 25 +- .../Reminder/NotificationProviderManagerTest.php | 4 +- .../tests/unit/CalDAV/Reminder/NotifierTest.php | 36 +- .../unit/CalDAV/Reminder/ReminderServiceTest.php | 202 ++++---- .../AbstractPrincipalBackendTest.php | 569 --------------------- .../AbstractPrincipalBackendTestCase.php | 558 ++++++++++++++++++++ .../ResourcePrincipalBackendTest.php | 4 +- .../ResourceBooking/RoomPrincipalBackendTest.php | 4 +- .../tests/unit/CalDAV/Schedule/IMipPluginTest.php | 66 +-- .../tests/unit/CalDAV/Schedule/IMipServiceTest.php | 86 ++-- apps/dav/tests/unit/CalDAV/Schedule/PluginTest.php | 66 ++- .../Search/Request/CalendarSearchReportTest.php | 14 +- .../tests/unit/CalDAV/Search/SearchPluginTest.php | 2 + .../CalDAV/Security/RateLimitingPluginTest.php | 10 +- .../tests/unit/CalDAV/Status/StatusServiceTest.php | 18 +- apps/dav/tests/unit/CalDAV/TimeZoneFactoryTest.php | 1 - apps/dav/tests/unit/CalDAV/TimezoneServiceTest.php | 12 +- apps/dav/tests/unit/CalDAV/TipBrokerTest.php | 14 +- .../CalDAV/Validation/CalDavValidatePluginTest.php | 14 +- .../unit/CalDAV/WebcalCaching/ConnectionTest.php | 7 +- .../tests/unit/CalDAV/WebcalCaching/PluginTest.php | 2 + .../WebcalCaching/RefreshWebcalServiceTest.php | 34 +- apps/dav/tests/unit/Upload/AssemblyStreamTest.php | 73 +-- 73 files changed, 1374 insertions(+), 1662 deletions(-) delete mode 100644 apps/dav/tests/unit/CalDAV/Reminder/NotificationProvider/AbstractNotificationProviderTest.php create mode 100644 apps/dav/tests/unit/CalDAV/Reminder/NotificationProvider/AbstractNotificationProviderTestCase.php delete mode 100644 apps/dav/tests/unit/CalDAV/ResourceBooking/AbstractPrincipalBackendTest.php create mode 100644 apps/dav/tests/unit/CalDAV/ResourceBooking/AbstractPrincipalBackendTestCase.php diff --git a/apps/dav/tests/unit/AppInfo/ApplicationTest.php b/apps/dav/tests/unit/AppInfo/ApplicationTest.php index f8ddd9bb821..336f487e0b8 100644 --- a/apps/dav/tests/unit/AppInfo/ApplicationTest.php +++ b/apps/dav/tests/unit/AppInfo/ApplicationTest.php @@ -1,5 +1,6 @@ home->$method(''); } - public function providesForbiddenMethods() { + public static function providesForbiddenMethods(): array { return [ ['createFile'], ['createDirectory'], @@ -52,7 +50,7 @@ class AvatarHomeTest extends TestCase { self::assertEquals('admin', $n); } - public function providesTestGetChild() { + public static function providesTestGetChild(): array { return [ [MethodNotAllowed::class, false, ''], [MethodNotAllowed::class, false, 'bla.foo'], @@ -65,7 +63,7 @@ class AvatarHomeTest extends TestCase { /** * @dataProvider providesTestGetChild */ - public function testGetChild($expectedException, $hasAvatar, $path): void { + public function testGetChild(?string $expectedException, bool $hasAvatar, string $path): void { if ($expectedException !== null) { $this->expectException($expectedException); } @@ -92,7 +90,7 @@ class AvatarHomeTest extends TestCase { /** * @dataProvider providesTestGetChild */ - public function testChildExists($expectedException, $hasAvatar, $path): void { + public function testChildExists(?string $expectedException, bool $hasAvatar, string $path): void { $avatar = $this->createMock(IAvatar::class); $avatar->method('exists')->willReturn($hasAvatar); diff --git a/apps/dav/tests/unit/Avatars/AvatarNodeTest.php b/apps/dav/tests/unit/Avatars/AvatarNodeTest.php index 92c02e17ff8..01634e77ed6 100644 --- a/apps/dav/tests/unit/Avatars/AvatarNodeTest.php +++ b/apps/dav/tests/unit/Avatars/AvatarNodeTest.php @@ -1,5 +1,6 @@ createMock(IAvatar::class); $n = new AvatarNode(1024, 'png', $a); $this->assertEquals('1024.png', $n->getName()); } public function testGetContentType(): void { - /** @var IAvatar | \PHPUnit\Framework\MockObject\MockObject $a */ + /** @var IAvatar&MockObject $a */ $a = $this->createMock(IAvatar::class); $n = new AvatarNode(1024, 'png', $a); $this->assertEquals('image/png', $n->getContentType()); diff --git a/apps/dav/tests/unit/BackgroundJob/CleanupInvitationTokenJobTest.php b/apps/dav/tests/unit/BackgroundJob/CleanupInvitationTokenJobTest.php index 21e999d34be..b2199e3e657 100644 --- a/apps/dav/tests/unit/BackgroundJob/CleanupInvitationTokenJobTest.php +++ b/apps/dav/tests/unit/BackgroundJob/CleanupInvitationTokenJobTest.php @@ -13,17 +13,13 @@ use OCP\AppFramework\Utility\ITimeFactory; use OCP\DB\QueryBuilder\IExpressionBuilder; use OCP\DB\QueryBuilder\IQueryBuilder; use OCP\IDBConnection; +use PHPUnit\Framework\MockObject\MockObject; use Test\TestCase; class CleanupInvitationTokenJobTest extends TestCase { - /** @var IDBConnection | \PHPUnit\Framework\MockObject\MockObject */ - private $dbConnection; - - /** @var ITimeFactory | \PHPUnit\Framework\MockObject\MockObject */ - private $timeFactory; - - /** @var CleanupInvitationTokenJob */ - private $backgroundJob; + private IDBConnection&MockObject $dbConnection; + private ITimeFactory&MockObject $timeFactory; + private CleanupInvitationTokenJob $backgroundJob; protected function setUp(): void { parent::setUp(); diff --git a/apps/dav/tests/unit/BackgroundJob/CleanupOrphanedChildrenJobTest.php b/apps/dav/tests/unit/BackgroundJob/CleanupOrphanedChildrenJobTest.php index fe05616d609..2065b8fe946 100644 --- a/apps/dav/tests/unit/BackgroundJob/CleanupOrphanedChildrenJobTest.php +++ b/apps/dav/tests/unit/BackgroundJob/CleanupOrphanedChildrenJobTest.php @@ -103,14 +103,13 @@ class CleanupOrphanedChildrenJobTest extends TestCase { $deleteQb = $this->getMockQueryBuilder(); $result = $this->createMock(IResult::class); - $qbInvocationCount = self::exactly(2); - $this->connection->expects($qbInvocationCount) - ->method('getQueryBuilder') - ->willReturnCallback(function () use ($qbInvocationCount, $selectQb, $deleteQb) { - return match ($qbInvocationCount->getInvocationCount()) { - 1 => $selectQb, - 2 => $deleteQb, - }; + $calls = [ + $selectQb, + $deleteQb, + ]; + $this->connection->method('getQueryBuilder') + ->willReturnCallback(function () use (&$calls) { + return array_shift($calls); }); $selectQb->expects(self::once()) ->method('executeQuery') @@ -140,15 +139,15 @@ class CleanupOrphanedChildrenJobTest extends TestCase { $deleteQb = $this->getMockQueryBuilder(); $result = $this->createMock(IResult::class); - $qbInvocationCount = self::exactly(2); - $this->connection->expects($qbInvocationCount) - ->method('getQueryBuilder') - ->willReturnCallback(function () use ($qbInvocationCount, $selectQb, $deleteQb) { - return match ($qbInvocationCount->getInvocationCount()) { - 1 => $selectQb, - 2 => $deleteQb, - }; + $calls = [ + $selectQb, + $deleteQb, + ]; + $this->connection->method('getQueryBuilder') + ->willReturnCallback(function () use (&$calls) { + return array_shift($calls); }); + $selectQb->expects(self::once()) ->method('executeQuery') ->willReturn($result); diff --git a/apps/dav/tests/unit/BackgroundJob/EventReminderJobTest.php b/apps/dav/tests/unit/BackgroundJob/EventReminderJobTest.php index 1173e516a22..1f70869f211 100644 --- a/apps/dav/tests/unit/BackgroundJob/EventReminderJobTest.php +++ b/apps/dav/tests/unit/BackgroundJob/EventReminderJobTest.php @@ -16,17 +16,10 @@ use PHPUnit\Framework\MockObject\MockObject; use Test\TestCase; class EventReminderJobTest extends TestCase { - /** @var ITimeFactory|MockObject */ - private $time; - - /** @var ReminderService|MockObject */ - private $reminderService; - - /** @var IConfig|MockObject */ - private $config; - - /** @var EventReminderJob|MockObject */ - private $backgroundJob; + private ITimeFactory&MockObject $time; + private ReminderService&MockObject $reminderService; + private IConfig&MockObject $config; + private EventReminderJob $backgroundJob; protected function setUp(): void { parent::setUp(); @@ -42,7 +35,7 @@ class EventReminderJobTest extends TestCase { ); } - public function data(): array { + public static function data(): array { return [ [true, true, true], [true, false, false], @@ -61,14 +54,10 @@ class EventReminderJobTest extends TestCase { public function testRun(bool $sendEventReminders, bool $sendEventRemindersMode, bool $expectCall): void { $this->config->expects($this->exactly($sendEventReminders ? 2 : 1)) ->method('getAppValue') - ->withConsecutive( - ['dav', 'sendEventReminders', 'yes'], - ['dav', 'sendEventRemindersMode', 'backgroundjob'], - ) - ->willReturnOnConsecutiveCalls( - $sendEventReminders ? 'yes' : 'no', - $sendEventRemindersMode ? 'backgroundjob' : 'cron' - ); + ->willReturnMap([ + ['dav', 'sendEventReminders', 'yes', ($sendEventReminders ? 'yes' : 'no')], + ['dav', 'sendEventRemindersMode', 'backgroundjob', ($sendEventRemindersMode ? 'backgroundjob' : 'cron')], + ]); if ($expectCall) { $this->reminderService->expects($this->once()) diff --git a/apps/dav/tests/unit/BackgroundJob/GenerateBirthdayCalendarBackgroundJobTest.php b/apps/dav/tests/unit/BackgroundJob/GenerateBirthdayCalendarBackgroundJobTest.php index 82d2251f17a..88a76ae1332 100644 --- a/apps/dav/tests/unit/BackgroundJob/GenerateBirthdayCalendarBackgroundJobTest.php +++ b/apps/dav/tests/unit/BackgroundJob/GenerateBirthdayCalendarBackgroundJobTest.php @@ -16,18 +16,10 @@ use PHPUnit\Framework\MockObject\MockObject; use Test\TestCase; class GenerateBirthdayCalendarBackgroundJobTest extends TestCase { - - /** @var ITimeFactory|MockObject */ - private $time; - - /** @var BirthdayService | MockObject */ - private $birthdayService; - - /** @var IConfig | MockObject */ - private $config; - - /** @var GenerateBirthdayCalendarBackgroundJob */ - private $backgroundJob; + private ITimeFactory&MockObject $time; + private BirthdayService&MockObject $birthdayService; + private IConfig&MockObject $config; + private GenerateBirthdayCalendarBackgroundJob $backgroundJob; protected function setUp(): void { parent::setUp(); diff --git a/apps/dav/tests/unit/BackgroundJob/OutOfOfficeEventDispatcherJobTest.php b/apps/dav/tests/unit/BackgroundJob/OutOfOfficeEventDispatcherJobTest.php index 5ddd9eba6f8..6135fd00fdc 100644 --- a/apps/dav/tests/unit/BackgroundJob/OutOfOfficeEventDispatcherJobTest.php +++ b/apps/dav/tests/unit/BackgroundJob/OutOfOfficeEventDispatcherJobTest.php @@ -25,21 +25,11 @@ use Test\TestCase; class OutOfOfficeEventDispatcherJobTest extends TestCase { private OutOfOfficeEventDispatcherJob $job; - - /** @var MockObject|ITimeFactory */ - private $timeFactory; - - /** @var MockObject|AbsenceMapper */ - private $absenceMapper; - - /** @var MockObject|LoggerInterface */ - private $logger; - - /** @var MockObject|IEventDispatcher */ - private $eventDispatcher; - - /** @var MockObject|IUserManager */ - private $userManager; + private ITimeFactory&MockObject $timeFactory; + private AbsenceMapper&MockObject $absenceMapper; + private LoggerInterface&MockObject $logger; + private IEventDispatcher&MockObject $eventDispatcher; + private IUserManager&MockObject $userManager; private MockObject|TimezoneService $timezoneService; protected function setUp(): void { diff --git a/apps/dav/tests/unit/BackgroundJob/PruneOutdatedSyncTokensJobTest.php b/apps/dav/tests/unit/BackgroundJob/PruneOutdatedSyncTokensJobTest.php index d08d0fd4496..eb471189c24 100644 --- a/apps/dav/tests/unit/BackgroundJob/PruneOutdatedSyncTokensJobTest.php +++ b/apps/dav/tests/unit/BackgroundJob/PruneOutdatedSyncTokensJobTest.php @@ -20,21 +20,11 @@ use Psr\Log\LoggerInterface; use Test\TestCase; class PruneOutdatedSyncTokensJobTest extends TestCase { - /** @var ITimeFactory | MockObject */ - private $timeFactory; - - /** @var CalDavBackend | MockObject */ - private $calDavBackend; - - /** @var CardDavBackend | MockObject */ - private $cardDavBackend; - - /** @var IConfig|MockObject */ - private $config; - - /** @var LoggerInterface|MockObject */ - private $logger; - + private ITimeFactory&MockObject $timeFactory; + private CalDavBackend&MockObject $calDavBackend; + private CardDavBackend&MockObject $cardDavBackend; + private IConfig&MockObject $config; + private LoggerInterface&MockObject $logger; private PruneOutdatedSyncTokensJob $backgroundJob; protected function setUp(): void { @@ -84,7 +74,7 @@ class PruneOutdatedSyncTokensJobTest extends TestCase { $this->backgroundJob->run(null); } - public function dataForTestRun(): array { + public static function dataForTestRun(): array { return [ ['100', '2', 100, 7 * 24 * 3600, 2, 3], ['100', '14', 100, 14 * 24 * 3600, 2, 3], diff --git a/apps/dav/tests/unit/BackgroundJob/RefreshWebcalJobTest.php b/apps/dav/tests/unit/BackgroundJob/RefreshWebcalJobTest.php index 2b11223210e..0cdeb6436e2 100644 --- a/apps/dav/tests/unit/BackgroundJob/RefreshWebcalJobTest.php +++ b/apps/dav/tests/unit/BackgroundJob/RefreshWebcalJobTest.php @@ -19,20 +19,11 @@ use Psr\Log\LoggerInterface; use Test\TestCase; class RefreshWebcalJobTest extends TestCase { - - /** @var RefreshWebcalService | MockObject */ - private $refreshWebcalService; - - /** @var IConfig | MockObject */ - private $config; - + private RefreshWebcalService&MockObject $refreshWebcalService; + private IConfig&MockObject $config; private LoggerInterface $logger; - - /** @var ITimeFactory | MockObject */ - private $timeFactory; - - /** @var IJobList | MockObject */ - private $jobList; + private ITimeFactory&MockObject $timeFactory; + private IJobList&MockObject $jobList; protected function setUp(): void { parent::setUp(); @@ -97,10 +88,7 @@ class RefreshWebcalJobTest extends TestCase { $backgroundJob->start($this->jobList); } - /** - * @return array - */ - public function runDataProvider():array { + public static function runDataProvider():array { return [ [0, 100000, true], [100000, 100000, false] diff --git a/apps/dav/tests/unit/BackgroundJob/RegisterRegenerateBirthdayCalendarsTest.php b/apps/dav/tests/unit/BackgroundJob/RegisterRegenerateBirthdayCalendarsTest.php index 88493d91d9b..6c9214d0268 100644 --- a/apps/dav/tests/unit/BackgroundJob/RegisterRegenerateBirthdayCalendarsTest.php +++ b/apps/dav/tests/unit/BackgroundJob/RegisterRegenerateBirthdayCalendarsTest.php @@ -14,20 +14,14 @@ use OCP\AppFramework\Utility\ITimeFactory; use OCP\BackgroundJob\IJobList; use OCP\IUser; use OCP\IUserManager; +use PHPUnit\Framework\MockObject\MockObject; use Test\TestCase; class RegisterRegenerateBirthdayCalendarsTest extends TestCase { - /** @var ITimeFactory | \PHPUnit\Framework\MockObject\MockObject */ - private $time; - - /** @var IUserManager | \PHPUnit\Framework\MockObject\MockObject */ - private $userManager; - - /** @var IJobList | \PHPUnit\Framework\MockObject\MockObject */ - private $jobList; - - /** @var RegisterRegenerateBirthdayCalendars */ - private $backgroundJob; + private ITimeFactory&MockObject $time; + private IUserManager&MockObject $userManager; + private IJobList&MockObject $jobList; + private RegisterRegenerateBirthdayCalendars $backgroundJob; protected function setUp(): void { parent::setUp(); @@ -59,22 +53,26 @@ class RegisterRegenerateBirthdayCalendarsTest extends TestCase { $closure($user3); }); + $calls = [ + 'uid1', + 'uid2', + 'uid3', + ]; $this->jobList->expects($this->exactly(3)) ->method('add') - ->withConsecutive( - [GenerateBirthdayCalendarBackgroundJob::class, [ - 'userId' => 'uid1', - 'purgeBeforeGenerating' => true - ]], - [GenerateBirthdayCalendarBackgroundJob::class, [ - 'userId' => 'uid2', - 'purgeBeforeGenerating' => true - ]], - [GenerateBirthdayCalendarBackgroundJob::class, [ - 'userId' => 'uid3', - 'purgeBeforeGenerating' => true - ]], - ); + ->willReturnCallback(function () use (&$calls): void { + $expected = array_shift($calls); + $this->assertEquals( + [ + GenerateBirthdayCalendarBackgroundJob::class, + [ + 'userId' => $expected, + 'purgeBeforeGenerating' => true + ] + ], + func_get_args() + ); + }); $this->backgroundJob->run([]); } diff --git a/apps/dav/tests/unit/BackgroundJob/UpdateCalendarResourcesRoomsBackgroundJobTest.php b/apps/dav/tests/unit/BackgroundJob/UpdateCalendarResourcesRoomsBackgroundJobTest.php index 18ee0c5c61d..38a981787cd 100644 --- a/apps/dav/tests/unit/BackgroundJob/UpdateCalendarResourcesRoomsBackgroundJobTest.php +++ b/apps/dav/tests/unit/BackgroundJob/UpdateCalendarResourcesRoomsBackgroundJobTest.php @@ -18,15 +18,9 @@ use Test\TestCase; class UpdateCalendarResourcesRoomsBackgroundJobTest extends TestCase { private UpdateCalendarResourcesRoomsBackgroundJob $backgroundJob; - - /** @var ITimeFactory|MockObject */ - private $time; - - /** @var IResourceManager|MockObject */ - private $resourceManager; - - /** @var IRoomManager|MockObject */ - private $roomManager; + private ITimeFactory&MockObject $time; + private IResourceManager&MockObject $resourceManager; + private IRoomManager&MockObject $roomManager; protected function setUp(): void { parent::setUp(); diff --git a/apps/dav/tests/unit/BackgroundJob/UserStatusAutomationTest.php b/apps/dav/tests/unit/BackgroundJob/UserStatusAutomationTest.php index ce3871aa400..369242ad488 100644 --- a/apps/dav/tests/unit/BackgroundJob/UserStatusAutomationTest.php +++ b/apps/dav/tests/unit/BackgroundJob/UserStatusAutomationTest.php @@ -29,14 +29,13 @@ use Test\TestCase; * @group DB */ class UserStatusAutomationTest extends TestCase { - - protected MockObject|ITimeFactory $time; - protected MockObject|IJobList $jobList; - protected MockObject|LoggerInterface $logger; - protected MockObject|IManager $statusManager; - protected MockObject|IConfig $config; - private IAvailabilityCoordinator|MockObject $coordinator; - private IUserManager|MockObject $userManager; + protected ITimeFactory&MockObject $time; + protected IJobList&MockObject $jobList; + protected LoggerInterface&MockObject $logger; + protected IManager&MockObject $statusManager; + protected IConfig&MockObject $config; + private IAvailabilityCoordinator&MockObject $coordinator; + private IUserManager&MockObject $userManager; protected function setUp(): void { parent::setUp(); @@ -76,11 +75,11 @@ class UserStatusAutomationTest extends TestCase { $this->coordinator, $this->userManager, ]) - ->setMethods($methods) + ->onlyMethods($methods) ->getMock(); } - public function dataRun(): array { + public static function dataRun(): array { return [ ['20230217', '2023-02-24 10:49:36.613834', true], ['20230224', '2023-02-24 10:49:36.613834', true], diff --git a/apps/dav/tests/unit/CalDAV/AbstractCalDavBackend.php b/apps/dav/tests/unit/CalDAV/AbstractCalDavBackend.php index c1d8e8609b6..45937d86873 100644 --- a/apps/dav/tests/unit/CalDAV/AbstractCalDavBackend.php +++ b/apps/dav/tests/unit/CalDAV/AbstractCalDavBackend.php @@ -44,12 +44,12 @@ abstract class AbstractCalDavBackend extends TestCase { protected CalDavBackend $backend; - protected Principal|MockObject $principal; - protected IUserManager|MockObject $userManager; - protected IGroupManager|MockObject $groupManager; - protected IEventDispatcher|MockObject $dispatcher; - private LoggerInterface|MockObject $logger; - private IConfig|MockObject $config; + protected Principal&MockObject $principal; + protected IUserManager&MockObject $userManager; + protected IGroupManager&MockObject $groupManager; + protected IEventDispatcher&MockObject $dispatcher; + private LoggerInterface&MockObject $logger; + private IConfig&MockObject $config; private ISecureRandom $random; protected SharingBackend $sharingBackend; protected IDBConnection $db; @@ -77,7 +77,7 @@ abstract class AbstractCalDavBackend extends TestCase { $this->createMock(IConfig::class), $this->createMock(IFactory::class) ]) - ->setMethods(['getPrincipalByPath', 'getGroupMembership', 'findByUri']) + ->onlyMethods(['getPrincipalByPath', 'getGroupMembership', 'findByUri']) ->getMock(); $this->principal->expects($this->any())->method('getPrincipalByPath') ->willReturn([ @@ -143,7 +143,7 @@ abstract class AbstractCalDavBackend extends TestCase { } } - protected function createTestCalendar() { + protected function createTestCalendar(): int { $this->dispatcher->expects(self::any()) ->method('dispatchTyped'); @@ -160,9 +160,7 @@ abstract class AbstractCalDavBackend extends TestCase { $this->assertEquals('#1C4587FF', $color); $this->assertEquals('Example', $calendars[0]['uri']); $this->assertEquals('Example', $calendars[0]['{DAV:}displayname']); - $calendarId = $calendars[0]['id']; - - return $calendarId; + return (int)$calendars[0]['id']; } protected function createTestSubscription() { diff --git a/apps/dav/tests/unit/CalDAV/Activity/BackendTest.php b/apps/dav/tests/unit/CalDAV/Activity/BackendTest.php index 6ace633b072..ebe989ad815 100644 --- a/apps/dav/tests/unit/CalDAV/Activity/BackendTest.php +++ b/apps/dav/tests/unit/CalDAV/Activity/BackendTest.php @@ -1,4 +1,6 @@ activityManager, @@ -71,7 +62,7 @@ class BackendTest extends TestCase { } } - public function dataCallTriggerCalendarActivity() { + public static function dataCallTriggerCalendarActivity(): array { return [ ['onCalendarAdd', [['data']], Calendar::SUBJECT_ADD, [['data'], [], []]], ['onCalendarUpdate', [['data'], ['shares'], ['changed-properties']], Calendar::SUBJECT_UPDATE, [['data'], ['shares'], ['changed-properties']]], @@ -82,13 +73,8 @@ class BackendTest extends TestCase { /** * @dataProvider dataCallTriggerCalendarActivity - * - * @param string $method - * @param array $payload - * @param string $expectedSubject - * @param array $expectedPayload */ - public function testCallTriggerCalendarActivity($method, array $payload, $expectedSubject, array $expectedPayload): void { + public function testCallTriggerCalendarActivity(string $method, array $payload, string $expectedSubject, array $expectedPayload): void { $backend = $this->getBackend(['triggerCalendarActivity']); $backend->expects($this->once()) ->method('triggerCalendarActivity') @@ -101,7 +87,7 @@ class BackendTest extends TestCase { call_user_func_array([$backend, $method], $payload); } - public function dataTriggerCalendarActivity() { + public static function dataTriggerCalendarActivity(): array { return [ // Add calendar [Calendar::SUBJECT_ADD, [], [], [], '', '', null, []], @@ -184,16 +170,8 @@ class BackendTest extends TestCase { /** * @dataProvider dataTriggerCalendarActivity - * @param string $action - * @param array $data - * @param array $shares - * @param array $changedProperties - * @param string $currentUser - * @param string $author - * @param string[]|null $shareUsers - * @param string[] $users */ - public function testTriggerCalendarActivity($action, array $data, array $shares, array $changedProperties, $currentUser, $author, $shareUsers, array $users): void { + public function testTriggerCalendarActivity(string $action, array $data, array $shares, array $changedProperties, string $currentUser, string $author, ?array $shareUsers, array $users): void { $backend = $this->getBackend(['getUsersForShares']); if ($shareUsers === null) { @@ -278,7 +256,7 @@ class BackendTest extends TestCase { ], [], []]); } - public function dataGetUsersForShares() { + public static function dataGetUsersForShares(): array { return [ [ [], @@ -323,9 +301,6 @@ class BackendTest extends TestCase { /** * @dataProvider dataGetUsersForShares - * @param array $shares - * @param array $groups - * @param array $expected */ public function testGetUsersForShares(array $shares, array $groups, array $expected): void { $backend = $this->getBackend(); @@ -356,7 +331,7 @@ class BackendTest extends TestCase { /** * @param string[] $users - * @return IUser[]|MockObject[] + * @return IUser[]&MockObject[] */ protected function getUsers(array $users) { $list = []; @@ -368,7 +343,7 @@ class BackendTest extends TestCase { /** * @param string $uid - * @return IUser|MockObject + * @return IUser&MockObject */ protected function getUserMock($uid) { $user = $this->createMock(IUser::class); diff --git a/apps/dav/tests/unit/CalDAV/Activity/Filter/CalendarTest.php b/apps/dav/tests/unit/CalDAV/Activity/Filter/CalendarTest.php index a7c84260f21..a31907b4b0a 100644 --- a/apps/dav/tests/unit/CalDAV/Activity/Filter/CalendarTest.php +++ b/apps/dav/tests/unit/CalDAV/Activity/Filter/CalendarTest.php @@ -1,4 +1,6 @@ assertEquals('absolute-path-to-icon', $this->filter->getIcon()); } - public function dataFilterTypes() { + public static function dataFilterTypes(): array { return [ [[], []], [['calendar', 'calendar_event'], ['calendar', 'calendar_event']], @@ -62,7 +61,7 @@ class CalendarTest extends TestCase { * @param string[] $types * @param string[] $expected */ - public function testFilterTypes($types, $expected): void { + public function testFilterTypes(array $types, array $expected): void { $this->assertEquals($expected, $this->filter->filterTypes($types)); } } diff --git a/apps/dav/tests/unit/CalDAV/Activity/Filter/GenericTest.php b/apps/dav/tests/unit/CalDAV/Activity/Filter/GenericTest.php index 392759206ed..468dd15f480 100644 --- a/apps/dav/tests/unit/CalDAV/Activity/Filter/GenericTest.php +++ b/apps/dav/tests/unit/CalDAV/Activity/Filter/GenericTest.php @@ -1,4 +1,6 @@ assertInstanceOf(IFilter::class, $filter); } /** * @dataProvider dataFilters - * @param string $filterClass */ - public function testGetIdentifier($filterClass): void { + public function testGetIdentifier(string $filterClass): void { /** @var IFilter $filter */ $filter = Server::get($filterClass); $this->assertIsString($filter->getIdentifier()); @@ -43,9 +43,8 @@ class GenericTest extends TestCase { /** * @dataProvider dataFilters - * @param string $filterClass */ - public function testGetName($filterClass): void { + public function testGetName(string $filterClass): void { /** @var IFilter $filter */ $filter = Server::get($filterClass); $this->assertIsString($filter->getName()); @@ -53,9 +52,8 @@ class GenericTest extends TestCase { /** * @dataProvider dataFilters - * @param string $filterClass */ - public function testGetPriority($filterClass): void { + public function testGetPriority(string $filterClass): void { /** @var IFilter $filter */ $filter = Server::get($filterClass); $priority = $filter->getPriority(); @@ -66,9 +64,8 @@ class GenericTest extends TestCase { /** * @dataProvider dataFilters - * @param string $filterClass */ - public function testGetIcon($filterClass): void { + public function testGetIcon(string $filterClass): void { /** @var IFilter $filter */ $filter = Server::get($filterClass); $this->assertIsString($filter->getIcon()); @@ -77,9 +74,8 @@ class GenericTest extends TestCase { /** * @dataProvider dataFilters - * @param string $filterClass */ - public function testFilterTypes($filterClass): void { + public function testFilterTypes(string $filterClass): void { /** @var IFilter $filter */ $filter = Server::get($filterClass); $this->assertIsArray($filter->filterTypes([])); @@ -87,9 +83,8 @@ class GenericTest extends TestCase { /** * @dataProvider dataFilters - * @param string $filterClass */ - public function testAllowedApps($filterClass): void { + public function testAllowedApps(string $filterClass): void { /** @var IFilter $filter */ $filter = Server::get($filterClass); $this->assertIsArray($filter->allowedApps()); diff --git a/apps/dav/tests/unit/CalDAV/Activity/Filter/TodoTest.php b/apps/dav/tests/unit/CalDAV/Activity/Filter/TodoTest.php index 6aa47f33750..6ef7289e156 100644 --- a/apps/dav/tests/unit/CalDAV/Activity/Filter/TodoTest.php +++ b/apps/dav/tests/unit/CalDAV/Activity/Filter/TodoTest.php @@ -1,4 +1,6 @@ assertEquals('absolute-path-to-icon', $this->filter->getIcon()); } - public function dataFilterTypes() { + public static function dataFilterTypes(): array { return [ [[], []], [['calendar_todo'], ['calendar_todo']], @@ -62,7 +61,7 @@ class TodoTest extends TestCase { * @param string[] $types * @param string[] $expected */ - public function testFilterTypes($types, $expected): void { + public function testFilterTypes(array $types, array $expected): void { $this->assertEquals($expected, $this->filter->filterTypes($types)); } } diff --git a/apps/dav/tests/unit/CalDAV/Activity/Provider/BaseTest.php b/apps/dav/tests/unit/CalDAV/Activity/Provider/BaseTest.php index ba97c888b0c..113af7ed240 100644 --- a/apps/dav/tests/unit/CalDAV/Activity/Provider/BaseTest.php +++ b/apps/dav/tests/unit/CalDAV/Activity/Provider/BaseTest.php @@ -1,4 +1,6 @@ groupManager, $this->url, ]) - ->setMethods(['parse']) + ->onlyMethods(['parse']) ->getMock(); } - public function dataSetSubjects() { + public static function dataSetSubjects(): array { return [ - ['abc', [], 'abc'], - ['{actor} created {calendar}', ['actor' => ['name' => 'abc'], 'calendar' => ['name' => 'xyz']], 'abc created xyz'], + ['abc', []], + ['{actor} created {calendar}', ['actor' => ['name' => 'abc'], 'calendar' => ['name' => 'xyz']]], ]; } /** * @dataProvider dataSetSubjects - * @param string $subject - * @param array $parameters - * @param string $parsedSubject */ - public function testSetSubjects(string $subject, array $parameters, string $parsedSubject): void { + public function testSetSubjects(string $subject, array $parameters): void { $event = $this->createMock(IEvent::class); $event->expects($this->once()) ->method('setRichSubject') @@ -68,7 +59,7 @@ class BaseTest extends TestCase { $this->invokePrivate($this->provider, 'setSubjects', [$event, $subject, $parameters]); } - public function dataGenerateCalendarParameter() { + public static function dataGenerateCalendarParameter(): array { return [ [['id' => 23, 'uri' => 'foo', 'name' => 'bar'], 'bar'], [['id' => 42, 'uri' => 'foo', 'name' => 'Personal'], 'Personal'], @@ -79,8 +70,6 @@ class BaseTest extends TestCase { /** * @dataProvider dataGenerateCalendarParameter - * @param array $data - * @param string $name */ public function testGenerateCalendarParameter(array $data, string $name): void { $l = $this->createMock(IL10N::class); @@ -97,7 +86,7 @@ class BaseTest extends TestCase { ], $this->invokePrivate($this->provider, 'generateCalendarParameter', [$data, $l])); } - public function dataGenerateLegacyCalendarParameter() { + public static function dataGenerateLegacyCalendarParameter(): array { return [ [23, 'c1'], [42, 'c2'], @@ -106,8 +95,6 @@ class BaseTest extends TestCase { /** * @dataProvider dataGenerateLegacyCalendarParameter - * @param int $id - * @param string $name */ public function testGenerateLegacyCalendarParameter(int $id, string $name): void { $this->assertEquals([ @@ -117,7 +104,7 @@ class BaseTest extends TestCase { ], $this->invokePrivate($this->provider, 'generateLegacyCalendarParameter', [$id, $name])); } - public function dataGenerateGroupParameter() { + public static function dataGenerateGroupParameter(): array { return [ ['g1'], ['g2'], @@ -126,7 +113,6 @@ class BaseTest extends TestCase { /** * @dataProvider dataGenerateGroupParameter - * @param string $gid */ public function testGenerateGroupParameter(string $gid): void { $this->assertEquals([ diff --git a/apps/dav/tests/unit/CalDAV/Activity/Provider/EventTest.php b/apps/dav/tests/unit/CalDAV/Activity/Provider/EventTest.php index ec237825731..748360adf79 100644 --- a/apps/dav/tests/unit/CalDAV/Activity/Provider/EventTest.php +++ b/apps/dav/tests/unit/CalDAV/Activity/Provider/EventTest.php @@ -1,4 +1,6 @@ eventMerger, $this->appManager ]) - ->setMethods(['parse']) + ->onlyMethods(['parse']) ->getMock(); } - public function dataGenerateObjectParameter() { + public static function dataGenerateObjectParameter(): array { $link = [ 'object_uri' => 'someuuid.ics', 'calendar_uri' => 'personal', @@ -85,10 +69,6 @@ class EventTest extends TestCase { /** * @dataProvider dataGenerateObjectParameter - * @param int $id - * @param string $name - * @param array|null $link - * @param bool $calendarAppEnabled */ public function testGenerateObjectParameter(int $id, string $name, ?array $link, bool $calendarAppEnabled = true): void { $affectedUser = 'otheruser'; @@ -174,7 +154,9 @@ class EventTest extends TestCase { ]; } - /** @dataProvider generateObjectParameterLinkEncodingDataProvider */ + /** + * @dataProvider generateObjectParameterLinkEncodingDataProvider + */ public function testGenerateObjectParameterLinkEncoding(array $link, string $objectId): void { $generatedLink = [ 'view' => 'dayGridMonth', @@ -203,7 +185,7 @@ class EventTest extends TestCase { $this->assertEquals($result, $this->invokePrivate($this->provider, 'generateObjectParameter', [$objectParameter, 'sharee'])); } - public function dataGenerateObjectParameterThrows() { + public static function dataGenerateObjectParameterThrows(): array { return [ ['event', TypeError::class], [['name' => 'event']], @@ -213,10 +195,8 @@ class EventTest extends TestCase { /** * @dataProvider dataGenerateObjectParameterThrows - * @param mixed $eventData - * @param string $exception */ - public function testGenerateObjectParameterThrows($eventData, string $exception = InvalidArgumentException::class): void { + public function testGenerateObjectParameterThrows(string|array $eventData, string $exception = InvalidArgumentException::class): void { $this->expectException($exception); $this->invokePrivate($this->provider, 'generateObjectParameter', [$eventData, 'no_user']); diff --git a/apps/dav/tests/unit/CalDAV/Activity/Setting/GenericTest.php b/apps/dav/tests/unit/CalDAV/Activity/Setting/GenericTest.php index 42b565b9d8b..2ed3bab02e6 100644 --- a/apps/dav/tests/unit/CalDAV/Activity/Setting/GenericTest.php +++ b/apps/dav/tests/unit/CalDAV/Activity/Setting/GenericTest.php @@ -1,4 +1,6 @@ assertInstanceOf(ISetting::class, $setting); } /** * @dataProvider dataSettings - * @param string $settingClass */ - public function testGetIdentifier($settingClass): void { + public function testGetIdentifier(string $settingClass): void { /** @var ISetting $setting */ $setting = Server::get($settingClass); $this->assertIsString($setting->getIdentifier()); @@ -42,9 +42,8 @@ class GenericTest extends TestCase { /** * @dataProvider dataSettings - * @param string $settingClass */ - public function testGetName($settingClass): void { + public function testGetName(string $settingClass): void { /** @var ISetting $setting */ $setting = Server::get($settingClass); $this->assertIsString($setting->getName()); @@ -52,9 +51,8 @@ class GenericTest extends TestCase { /** * @dataProvider dataSettings - * @param string $settingClass */ - public function testGetPriority($settingClass): void { + public function testGetPriority(string $settingClass): void { /** @var ISetting $setting */ $setting = Server::get($settingClass); $priority = $setting->getPriority(); @@ -65,9 +63,8 @@ class GenericTest extends TestCase { /** * @dataProvider dataSettings - * @param string $settingClass */ - public function testCanChangeStream($settingClass): void { + public function testCanChangeStream(string $settingClass): void { /** @var ISetting $setting */ $setting = Server::get($settingClass); $this->assertIsBool($setting->canChangeStream()); @@ -75,9 +72,8 @@ class GenericTest extends TestCase { /** * @dataProvider dataSettings - * @param string $settingClass */ - public function testIsDefaultEnabledStream($settingClass): void { + public function testIsDefaultEnabledStream(string $settingClass): void { /** @var ISetting $setting */ $setting = Server::get($settingClass); $this->assertIsBool($setting->isDefaultEnabledStream()); @@ -85,9 +81,8 @@ class GenericTest extends TestCase { /** * @dataProvider dataSettings - * @param string $settingClass */ - public function testCanChangeMail($settingClass): void { + public function testCanChangeMail(string $settingClass): void { /** @var ISetting $setting */ $setting = Server::get($settingClass); $this->assertIsBool($setting->canChangeMail()); @@ -95,9 +90,8 @@ class GenericTest extends TestCase { /** * @dataProvider dataSettings - * @param string $settingClass */ - public function testIsDefaultEnabledMail($settingClass): void { + public function testIsDefaultEnabledMail(string $settingClass): void { /** @var ISetting $setting */ $setting = Server::get($settingClass); $this->assertIsBool($setting->isDefaultEnabledMail()); diff --git a/apps/dav/tests/unit/CalDAV/AppCalendar/AppCalendarTest.php b/apps/dav/tests/unit/CalDAV/AppCalendar/AppCalendarTest.php index f7fa114ff28..bac2094f734 100644 --- a/apps/dav/tests/unit/CalDAV/AppCalendar/AppCalendarTest.php +++ b/apps/dav/tests/unit/CalDAV/AppCalendar/AppCalendarTest.php @@ -1,5 +1,6 @@ writeableCalendar->expects($this->exactly(3)) ->method('createFromString') - ->withConsecutive(['some-name', 'data'], ['other-name', ''], ['name', 'some data']); + ->willReturnCallback(function () use (&$calls) { + $expected = array_shift($calls); + $this->assertEquals($expected, func_get_args()); + }); // pass data $this->assertNull($this->writeableAppCalendar->createFile('some-name', 'data')); diff --git a/apps/dav/tests/unit/CalDAV/AppCalendar/CalendarObjectTest.php b/apps/dav/tests/unit/CalDAV/AppCalendar/CalendarObjectTest.php index a913c2dde6f..3d72d5c97b8 100644 --- a/apps/dav/tests/unit/CalDAV/AppCalendar/CalendarObjectTest.php +++ b/apps/dav/tests/unit/CalDAV/AppCalendar/CalendarObjectTest.php @@ -1,5 +1,6 @@ assertEquals('BEGIN...', $calendarObject->get()); } - + public function testPut(): void { $this->expectException(\Sabre\DAV\Exception\MethodNotAllowed::class); $this->expectExceptionMessage('Creating objects in a cached subscription is not allowed'); @@ -52,7 +54,7 @@ class CachedSubscriptionObjectTest extends \Test\TestCase { $calendarObject->put(''); } - + public function testDelete(): void { $this->expectException(\Sabre\DAV\Exception\MethodNotAllowed::class); $this->expectExceptionMessage('Deleting objects in a cached subscription is not allowed'); diff --git a/apps/dav/tests/unit/CalDAV/CachedSubscriptionProviderTest.php b/apps/dav/tests/unit/CalDAV/CachedSubscriptionProviderTest.php index be47b2bf640..58d5ca7835c 100644 --- a/apps/dav/tests/unit/CalDAV/CachedSubscriptionProviderTest.php +++ b/apps/dav/tests/unit/CalDAV/CachedSubscriptionProviderTest.php @@ -12,11 +12,12 @@ namespace OCA\DAV\Tests\unit\CalDAV; use OCA\DAV\CalDAV\CachedSubscriptionImpl; use OCA\DAV\CalDAV\CachedSubscriptionProvider; use OCA\DAV\CalDAV\CalDavBackend; +use PHPUnit\Framework\MockObject\MockObject; use Test\TestCase; class CachedSubscriptionProviderTest extends TestCase { - private CalDavBackend $backend; + private CalDavBackend&MockObject $backend; private CachedSubscriptionProvider $provider; protected function setUp(): void { diff --git a/apps/dav/tests/unit/CalDAV/CachedSubscriptionTest.php b/apps/dav/tests/unit/CalDAV/CachedSubscriptionTest.php index e1d22bc3e7b..091ee7a341f 100644 --- a/apps/dav/tests/unit/CalDAV/CachedSubscriptionTest.php +++ b/apps/dav/tests/unit/CalDAV/CachedSubscriptionTest.php @@ -140,19 +140,21 @@ class CachedSubscriptionTest extends \Test\TestCase { 'uri' => 'cal', ]; + $calls = [ + [666, 'foo1', 1, [ + 'id' => 99, + 'uri' => 'foo1' + ]], + [666, 'foo2', 1, null], + ]; $backend->expects($this->exactly(2)) ->method('getCalendarObject') - ->withConsecutive( - [666, 'foo1', 1], - [666, 'foo2', 1], - ) - ->willReturnOnConsecutiveCalls( - [ - 'id' => 99, - 'uri' => 'foo1' - ], - null - ); + ->willReturnCallback(function () use (&$calls) { + $expected = array_shift($calls); + $return = array_pop($expected); + $this->assertEquals($expected, func_get_args()); + return $return; + }); $calendar = new CachedSubscription($backend, $calendarInfo); @@ -250,19 +252,21 @@ class CachedSubscriptionTest extends \Test\TestCase { 'uri' => 'cal', ]; + $calls = [ + [666, 'foo1', 1, [ + 'id' => 99, + 'uri' => 'foo1' + ]], + [666, 'foo2', 1, null], + ]; $backend->expects($this->exactly(2)) ->method('getCalendarObject') - ->withConsecutive( - [666, 'foo1', 1], - [666, 'foo2', 1], - ) - ->willReturnOnConsecutiveCalls( - [ - 'id' => 99, - 'uri' => 'foo1' - ], - null - ); + ->willReturnCallback(function () use (&$calls) { + $expected = array_shift($calls); + $return = array_pop($expected); + $this->assertEquals($expected, func_get_args()); + return $return; + }); $calendar = new CachedSubscription($backend, $calendarInfo); diff --git a/apps/dav/tests/unit/CalDAV/CalDavBackendTest.php b/apps/dav/tests/unit/CalDAV/CalDavBackendTest.php index 825d798e7e1..f8368660626 100644 --- a/apps/dav/tests/unit/CalDAV/CalDavBackendTest.php +++ b/apps/dav/tests/unit/CalDAV/CalDavBackendTest.php @@ -1,4 +1,6 @@ assertNotNull($co); } - public function providesCalendarQueryParameters() { + public static function providesCalendarQueryParameters(): array { return [ 'all' => [[0, 1, 2, 3], [], []], 'only-todos' => [[], ['name' => 'VTODO'], []], @@ -619,7 +619,7 @@ EOD; $this->assertCount(0, $subscriptions); } - public function providesSchedulingData() { + public static function providesSchedulingData(): array { $data = << [0, 'firstOccurence', "BEGIN:VCALENDAR\r\nVERSION:2.0\r\nPRODID:-//Sabre//Sabre VObject 4.1.1//EN\r\nCALSCALE:GREGORIAN\r\nBEGIN:VEVENT\r\nUID:413F269B-B51B-46B1-AFB6-40055C53A4DC\r\nDTSTAMP:20160309T095056Z\r\nDTSTART;VALUE=DATE:16040222\r\nDTEND;VALUE=DATE:16040223\r\nRRULE:FREQ=YEARLY\r\nSUMMARY:SUMMARY\r\nTRANSP:TRANSPARENT\r\nEND:VEVENT\r\nEND:VCALENDAR\r\n"], 'no first occurrence because yearly' => [null, 'firstOccurence', "BEGIN:VCALENDAR\r\nVERSION:2.0\r\nPRODID:-//Sabre//Sabre VObject 4.1.1//EN\r\nCALSCALE:GREGORIAN\r\nBEGIN:VEVENT\r\nUID:413F269B-B51B-46B1-AFB6-40055C53A4DC\r\nDTSTAMP:20160309T095056Z\r\nRRULE:FREQ=YEARLY\r\nSUMMARY:SUMMARY\r\nTRANSP:TRANSPARENT\r\nEND:VEVENT\r\nEND:VCALENDAR\r\n"], @@ -980,7 +980,7 @@ EOD; $this->assertCount($count, $result); } - public function searchDataProvider() { + public static function searchDataProvider(): array { return [ [false, [], 4], [true, ['timerange' => ['start' => new DateTime('2013-09-12 13:00:00'), 'end' => new DateTime('2013-09-12 14:00:00')]], 2], diff --git a/apps/dav/tests/unit/CalDAV/CalendarHomeTest.php b/apps/dav/tests/unit/CalDAV/CalendarHomeTest.php index 9956c17fff3..e25cc099bd6 100644 --- a/apps/dav/tests/unit/CalDAV/CalendarHomeTest.php +++ b/apps/dav/tests/unit/CalDAV/CalendarHomeTest.php @@ -1,4 +1,6 @@ createMock(MkCol::class); $mkCol->method('getResourceType') @@ -82,7 +74,7 @@ class CalendarHomeTest extends TestCase { $this->expectException(\Sabre\DAV\Exception\MethodNotAllowed::class); $this->expectExceptionMessage('The resource you tried to create has a reserved name'); - /** @var MkCol | MockObject $mkCol */ + /** @var MkCol&MockObject $mkCol */ $mkCol = $this->createMock(MkCol::class); $this->calendarHome->createExtendedCollection('contact_birthdays', $mkCol); @@ -92,7 +84,7 @@ class CalendarHomeTest extends TestCase { $this->expectException(\Sabre\DAV\Exception\MethodNotAllowed::class); $this->expectExceptionMessage('The resource you tried to create has a reserved name'); - /** @var MkCol | MockObject $mkCol */ + /** @var MkCol&MockObject $mkCol */ $mkCol = $this->createMock(MkCol::class); $this->calendarHome->createExtendedCollection('app-generated--example--foo-1', $mkCol); diff --git a/apps/dav/tests/unit/CalDAV/CalendarImplTest.php b/apps/dav/tests/unit/CalDAV/CalendarImplTest.php index 0d5223739f3..88b04326cc9 100644 --- a/apps/dav/tests/unit/CalDAV/CalendarImplTest.php +++ b/apps/dav/tests/unit/CalDAV/CalendarImplTest.php @@ -1,4 +1,6 @@ calendarImpl->export(null) as $entry) { $exported[] = $entry; } - + // Assert $this->assertCount(1, $exported, 'Invalid exported items count'); } diff --git a/apps/dav/tests/unit/CalDAV/CalendarManagerTest.php b/apps/dav/tests/unit/CalDAV/CalendarManagerTest.php index 63d92dff40d..e8159ffe07c 100644 --- a/apps/dav/tests/unit/CalDAV/CalendarManagerTest.php +++ b/apps/dav/tests/unit/CalDAV/CalendarManagerTest.php @@ -1,4 +1,6 @@ 456, 'uri' => 'blablub2'], ]); - /** @var IManager | MockObject $calendarManager */ + /** @var IManager&MockObject $calendarManager */ $calendarManager = $this->createMock(Manager::class); $registeredIds = []; $calendarManager->expects($this->exactly(2)) diff --git a/apps/dav/tests/unit/CalDAV/CalendarTest.php b/apps/dav/tests/unit/CalDAV/CalendarTest.php index 7f2d0052162..0eff72c5c3d 100644 --- a/apps/dav/tests/unit/CalDAV/CalendarTest.php +++ b/apps/dav/tests/unit/CalDAV/CalendarTest.php @@ -1,4 +1,6 @@ l10n = $this->getMockBuilder(IL10N::class) - ->disableOriginalConstructor()->getMock(); + $this->l10n = $this->createMock(IL10N::class); $this->config = $this->createMock(IConfig::class); $this->logger = $this->createMock(LoggerInterface::class); $this->l10n @@ -80,7 +75,7 @@ class CalendarTest extends TestCase { } public function testDeleteOwn(): void { - /** @var MockObject | CalDavBackend $backend */ + /** @var CalDavBackend&MockObject $backend */ $backend = $this->createMock(CalDavBackend::class); $backend->expects($this->never())->method('updateShares'); $backend->expects($this->never())->method('getShares'); @@ -101,7 +96,7 @@ class CalendarTest extends TestCase { } public function testDeleteBirthdayCalendar(): void { - /** @var MockObject | CalDavBackend $backend */ + /** @var CalDavBackend&MockObject $backend */ $backend = $this->createMock(CalDavBackend::class); $backend->expects($this->once())->method('deleteCalendar') ->with(666); @@ -122,7 +117,7 @@ class CalendarTest extends TestCase { $c->delete(); } - public function dataPropPatch() { + public static function dataPropPatch(): array { return [ ['user1', 'user2', [], true], ['user1', 'user2', [ @@ -152,9 +147,9 @@ class CalendarTest extends TestCase { /** * @dataProvider dataPropPatch */ - public function testPropPatch($ownerPrincipal, $principalUri, $mutations, $shared): void { - /** @var MockObject | CalDavBackend $backend */ - $backend = $this->getMockBuilder(CalDavBackend::class)->disableOriginalConstructor()->getMock(); + public function testPropPatch(string $ownerPrincipal, string $principalUri, array $mutations, bool $shared): void { + /** @var CalDavBackend&MockObject $backend */ + $backend = $this->createMock(CalDavBackend::class); $calendarInfo = [ '{http://owncloud.org/ns}owner-principal' => $ownerPrincipal, 'principaluri' => $principalUri, @@ -177,8 +172,8 @@ class CalendarTest extends TestCase { * @dataProvider providesReadOnlyInfo */ public function testAcl($expectsWrite, $readOnlyValue, $hasOwnerSet, $uri = 'default'): void { - /** @var MockObject | CalDavBackend $backend */ - $backend = $this->getMockBuilder(CalDavBackend::class)->disableOriginalConstructor()->getMock(); + /** @var CalDavBackend&MockObject $backend */ + $backend = $this->createMock(CalDavBackend::class); $backend->expects($this->any())->method('applyShareAcl')->willReturnArgument(1); $calendarInfo = [ 'principaluri' => 'user2', @@ -263,7 +258,7 @@ class CalendarTest extends TestCase { $this->assertEquals($expectedAcl, $childAcl); } - public function providesReadOnlyInfo() { + public static function providesReadOnlyInfo(): array { return [ 'read-only property not set' => [true, null, true], 'read-only property is false' => [true, false, true], @@ -277,16 +272,14 @@ class CalendarTest extends TestCase { /** * @dataProvider providesConfidentialClassificationData - * @param int $expectedChildren - * @param bool $isShared */ - public function testPrivateClassification($expectedChildren, $isShared): void { + public function testPrivateClassification(int $expectedChildren, bool $isShared): void { $calObject0 = ['uri' => 'event-0', 'classification' => CalDavBackend::CLASSIFICATION_PUBLIC]; $calObject1 = ['uri' => 'event-1', 'classification' => CalDavBackend::CLASSIFICATION_CONFIDENTIAL]; $calObject2 = ['uri' => 'event-2', 'classification' => CalDavBackend::CLASSIFICATION_PRIVATE]; - /** @var MockObject | CalDavBackend $backend */ - $backend = $this->getMockBuilder(CalDavBackend::class)->disableOriginalConstructor()->getMock(); + /** @var CalDavBackend&MockObject $backend */ + $backend = $this->createMock(CalDavBackend::class); $backend->expects($this->any())->method('getCalendarObjects')->willReturn([ $calObject0, $calObject1, $calObject2 ]); @@ -319,10 +312,8 @@ class CalendarTest extends TestCase { /** * @dataProvider providesConfidentialClassificationData - * @param int $expectedChildren - * @param bool $isShared */ - public function testConfidentialClassification($expectedChildren, $isShared): void { + public function testConfidentialClassification(int $expectedChildren, bool $isShared): void { $start = '20160609'; $end = '20160610'; @@ -372,8 +363,8 @@ EOD; $calObject1 = ['uri' => 'event-1', 'classification' => CalDavBackend::CLASSIFICATION_CONFIDENTIAL, 'calendardata' => $calData]; $calObject2 = ['uri' => 'event-2', 'classification' => CalDavBackend::CLASSIFICATION_PRIVATE]; - /** @var MockObject | CalDavBackend $backend */ - $backend = $this->getMockBuilder(CalDavBackend::class)->disableOriginalConstructor()->getMock(); + /** @var CalDavBackend&MockObject $backend */ + $backend = $this->createMock(CalDavBackend::class); $backend->expects($this->any())->method('getCalendarObjects')->willReturn([ $calObject0, $calObject1, $calObject2 ]); @@ -437,7 +428,7 @@ EOD; } } - public function providesConfidentialClassificationData() { + public static function providesConfidentialClassificationData(): array { return [ [3, false], [2, true] @@ -540,7 +531,7 @@ EOD; 'classification' => CalDavBackend::CLASSIFICATION_CONFIDENTIAL, 'calendardata' => $confidentialObjectData]; - /** @var MockObject | CalDavBackend $backend */ + /** @var CalDavBackend&MockObject $backend */ $backend = $this->createMock(CalDavBackend::class); $backend->expects($this->any()) ->method('getCalendarObjects') @@ -619,7 +610,7 @@ EOD; $this->fixLinebreak($confidentialObjectCleaned)); } - private function fixLinebreak($str) { + private function fixLinebreak(string $str): string { return preg_replace('~(*BSR_ANYCRLF)\R~', "\r\n", $str); } } diff --git a/apps/dav/tests/unit/CalDAV/EventComparisonServiceTest.php b/apps/dav/tests/unit/CalDAV/EventComparisonServiceTest.php index 43a7180647f..90b6f9ec0db 100644 --- a/apps/dav/tests/unit/CalDAV/EventComparisonServiceTest.php +++ b/apps/dav/tests/unit/CalDAV/EventComparisonServiceTest.php @@ -14,8 +14,7 @@ use Sabre\VObject\Component\VCalendar; use Test\TestCase; class EventComparisonServiceTest extends TestCase { - /** @var EventComparisonService */ - private $eventComparisonService; + private EventComparisonService $eventComparisonService; protected function setUp(): void { $this->eventComparisonService = new EventComparisonService(); diff --git a/apps/dav/tests/unit/CalDAV/Export/ExportServiceTest.php b/apps/dav/tests/unit/CalDAV/Export/ExportServiceTest.php index f1e049c4a80..838dfc18f2f 100644 --- a/apps/dav/tests/unit/CalDAV/Export/ExportServiceTest.php +++ b/apps/dav/tests/unit/CalDAV/Export/ExportServiceTest.php @@ -1,4 +1,6 @@ abstractExternalCalendar->setName('other-name'); } - public function createDirectory():void { + public function createDirectory(): void { // Check that the method is final and can't be overridden by other classes $reflectionMethod = new \ReflectionMethod(ExternalCalendar::class, 'createDirectory'); $this->assertTrue($reflectionMethod->isFinal()); @@ -73,7 +76,7 @@ class ExternalCalendarTest extends TestCase { ExternalCalendar::splitAppGeneratedCalendarUri($name); } - public function splitAppGeneratedCalendarUriDataProvider():array { + public static function splitAppGeneratedCalendarUriDataProvider():array { return [ ['personal'], ['foo_shared_by_admin'], diff --git a/apps/dav/tests/unit/CalDAV/Listener/CalendarPublicationListenerTest.php b/apps/dav/tests/unit/CalDAV/Listener/CalendarPublicationListenerTest.php index b55359cd208..3ba0b832593 100644 --- a/apps/dav/tests/unit/CalDAV/Listener/CalendarPublicationListenerTest.php +++ b/apps/dav/tests/unit/CalDAV/Listener/CalendarPublicationListenerTest.php @@ -1,4 +1,6 @@ plugin = new Plugin(); } - public function linkProvider() { + public static function linkProvider(): array { return [ [ 'principals/users/MyUserName', @@ -37,11 +38,8 @@ class PluginTest extends TestCase { /** * @dataProvider linkProvider - * - * @param $input - * @param $expected */ - public function testGetCalendarHomeForPrincipal($input, $expected): void { + public function testGetCalendarHomeForPrincipal(string $input, string $expected): void { $this->assertSame($expected, $this->plugin->getCalendarHomeForPrincipal($input)); } diff --git a/apps/dav/tests/unit/CalDAV/PublicCalendarRootTest.php b/apps/dav/tests/unit/CalDAV/PublicCalendarRootTest.php index 075681eff7f..6acceed6f64 100644 --- a/apps/dav/tests/unit/CalDAV/PublicCalendarRootTest.php +++ b/apps/dav/tests/unit/CalDAV/PublicCalendarRootTest.php @@ -1,4 +1,6 @@ l10n = $this->getMockBuilder(IL10N::class) - ->disableOriginalConstructor()->getMock(); + $this->l10n = $this->createMock(IL10N::class); $this->config = $this->createMock(IConfig::class); $this->publicCalendarRoot = new PublicCalendarRoot($this->backend, @@ -134,10 +126,7 @@ class PublicCalendarRootTest extends TestCase { $this->assertSame([], $calendarResults); } - /** - * @return Calendar - */ - protected function createPublicCalendar() { + protected function createPublicCalendar(): Calendar { $this->backend->createCalendar(self::UNIT_TEST_USER, 'Example', []); $calendarInfo = $this->backend->getCalendarsForUser(self::UNIT_TEST_USER)[0]; diff --git a/apps/dav/tests/unit/CalDAV/PublicCalendarTest.php b/apps/dav/tests/unit/CalDAV/PublicCalendarTest.php index 0609892c279..7e8f714ef42 100644 --- a/apps/dav/tests/unit/CalDAV/PublicCalendarTest.php +++ b/apps/dav/tests/unit/CalDAV/PublicCalendarTest.php @@ -1,4 +1,6 @@ 'event-0', 'classification' => CalDavBackend::CLASSIFICATION_PUBLIC]; $calObject1 = ['uri' => 'event-1', 'classification' => CalDavBackend::CLASSIFICATION_CONFIDENTIAL]; $calObject2 = ['uri' => 'event-2', 'classification' => CalDavBackend::CLASSIFICATION_PRIVATE]; - /** @var MockObject | CalDavBackend $backend */ + /** @var CalDavBackend&MockObject $backend */ $backend = $this->getMockBuilder(CalDavBackend::class)->disableOriginalConstructor()->getMock(); $backend->expects($this->any())->method('getCalendarObjects')->willReturn([ $calObject0, $calObject1, $calObject2 @@ -44,9 +44,9 @@ class PublicCalendarTest extends CalendarTest { 'id' => 666, 'uri' => 'cal', ]; - /** @var MockObject | IConfig $config */ + /** @var IConfig&MockObject $config */ $config = $this->createMock(IConfig::class); - /** @var MockObject | LoggerInterface $logger */ + /** @var LoggerInterface&MockObject $logger */ $logger = $this->createMock(LoggerInterface::class); $c = new PublicCalendar($backend, $calendarInfo, $this->l10n, $config, $logger); $children = $c->getChildren(); @@ -59,10 +59,8 @@ class PublicCalendarTest extends CalendarTest { /** * @dataProvider providesConfidentialClassificationData - * @param int $expectedChildren - * @param bool $isShared */ - public function testConfidentialClassification($expectedChildren, $isShared): void { + public function testConfidentialClassification(int $expectedChildren, bool $isShared): void { $start = '20160609'; $end = '20160610'; @@ -112,7 +110,7 @@ EOD; $calObject1 = ['uri' => 'event-1', 'classification' => CalDavBackend::CLASSIFICATION_CONFIDENTIAL, 'calendardata' => $calData]; $calObject2 = ['uri' => 'event-2', 'classification' => CalDavBackend::CLASSIFICATION_PRIVATE]; - /** @var MockObject | CalDavBackend $backend */ + /** @var CalDavBackend&MockObject $backend */ $backend = $this->getMockBuilder(CalDavBackend::class)->disableOriginalConstructor()->getMock(); $backend->expects($this->any())->method('getCalendarObjects')->willReturn([ $calObject0, $calObject1, $calObject2 @@ -132,9 +130,9 @@ EOD; 'id' => 666, 'uri' => 'cal', ]; - /** @var MockObject | IConfig $config */ + /** @var IConfig&MockObject $config */ $config = $this->createMock(IConfig::class); - /** @var MockObject | LoggerInterface $logger */ + /** @var LoggerInterface&MockObject $logger */ $logger = $this->createMock(LoggerInterface::class); $c = new PublicCalendar($backend, $calendarInfo, $this->l10n, $config, $logger); diff --git a/apps/dav/tests/unit/CalDAV/Publishing/PublisherTest.php b/apps/dav/tests/unit/CalDAV/Publishing/PublisherTest.php index 769e1537646..5344ec5d7cd 100644 --- a/apps/dav/tests/unit/CalDAV/Publishing/PublisherTest.php +++ b/apps/dav/tests/unit/CalDAV/Publishing/PublisherTest.php @@ -1,4 +1,6 @@ 'd']; - protected $contextUri = '/'; + protected array $elementMap = []; + protected array $namespaceMap = ['DAV:' => 'd']; + protected string $contextUri = '/'; private function write($input) { $writer = new Writer(); diff --git a/apps/dav/tests/unit/CalDAV/Publishing/PublishingTest.php b/apps/dav/tests/unit/CalDAV/Publishing/PublishingTest.php index 8aecdf7f0dd..c66a3639040 100644 --- a/apps/dav/tests/unit/CalDAV/Publishing/PublishingTest.php +++ b/apps/dav/tests/unit/CalDAV/Publishing/PublishingTest.php @@ -1,4 +1,6 @@ config = $this->getMockBuilder(IConfig::class)-> - disableOriginalConstructor()-> - getMock(); + $this->config = $this->createMock(IConfig::class); $this->config->expects($this->any())->method('getSystemValue') ->with($this->equalTo('secret')) ->willReturn('mysecret'); - $this->urlGenerator = $this->getMockBuilder(IURLGenerator::class)-> - disableOriginalConstructor()-> - getMock(); + $this->urlGenerator = $this->createMock(IURLGenerator::class); /** @var IRequest $request */ $this->plugin = new PublishPlugin($this->config, $this->urlGenerator); diff --git a/apps/dav/tests/unit/CalDAV/Reminder/BackendTest.php b/apps/dav/tests/unit/CalDAV/Reminder/BackendTest.php index e1a0485f8a9..356acf2dd7f 100644 --- a/apps/dav/tests/unit/CalDAV/Reminder/BackendTest.php +++ b/apps/dav/tests/unit/CalDAV/Reminder/BackendTest.php @@ -10,27 +10,20 @@ namespace OCA\DAV\Tests\unit\CalDAV\Reminder; use OCA\DAV\CalDAV\Reminder\Backend as ReminderBackend; use OCP\AppFramework\Utility\ITimeFactory; +use PHPUnit\Framework\MockObject\MockObject; use Test\TestCase; class BackendTest extends TestCase { - - /** - * Reminder Backend - * - * @var ReminderBackend|\PHPUnit\Framework\MockObject\MockObject - */ - private $reminderBackend; - - /** @var ITimeFactory|\PHPUnit\Framework\MockObject\MockObject */ - private $timeFactory; + private ReminderBackend $reminderBackend; + private ITimeFactory&MockObject $timeFactory; protected function setUp(): void { parent::setUp(); $query = self::$realDatabase->getQueryBuilder(); - $query->delete('calendar_reminders')->execute(); - $query->delete('calendarobjects')->execute(); - $query->delete('calendars')->execute(); + $query->delete('calendar_reminders')->executeStatement(); + $query->delete('calendarobjects')->executeStatement(); + $query->delete('calendars')->executeStatement(); $this->timeFactory = $this->createMock(ITimeFactory::class); $this->reminderBackend = new ReminderBackend(self::$realDatabase, $this->timeFactory); @@ -40,9 +33,11 @@ class BackendTest extends TestCase { protected function tearDown(): void { $query = self::$realDatabase->getQueryBuilder(); - $query->delete('calendar_reminders')->execute(); - $query->delete('calendarobjects')->execute(); - $query->delete('calendars')->execute(); + $query->delete('calendar_reminders')->executeStatement(); + $query->delete('calendarobjects')->executeStatement(); + $query->delete('calendars')->executeStatement(); + + parent::tearDown(); } @@ -235,7 +230,7 @@ class BackendTest extends TestCase { $query = self::$realDatabase->getQueryBuilder(); $rows = $query->select('*') ->from('calendar_reminders') - ->execute() + ->executeQuery() ->fetchAll(); $this->assertCount(4, $rows); @@ -251,7 +246,7 @@ class BackendTest extends TestCase { $row = $query->select('notification_date') ->from('calendar_reminders') ->where($query->expr()->eq('id', $query->createNamedParameter($reminderId))) - ->execute() + ->executeQuery() ->fetch(); $this->assertEquals((int)$row['notification_date'], 123700); @@ -266,7 +261,7 @@ class BackendTest extends TestCase { 'principaluri' => $query->createNamedParameter('principals/users/user001'), 'displayname' => $query->createNamedParameter('Displayname 123'), ]) - ->execute(); + ->executeStatement(); $query = self::$realDatabase->getQueryBuilder(); $query->insert('calendars') @@ -275,7 +270,7 @@ class BackendTest extends TestCase { 'principaluri' => $query->createNamedParameter('principals/users/user002'), 'displayname' => $query->createNamedParameter('Displayname 99'), ]) - ->execute(); + ->executeStatement(); $query = self::$realDatabase->getQueryBuilder(); $query->insert('calendarobjects') @@ -285,7 +280,7 @@ class BackendTest extends TestCase { 'calendarid' => $query->createNamedParameter(1), 'size' => $query->createNamedParameter(42), ]) - ->execute(); + ->executeStatement(); $query = self::$realDatabase->getQueryBuilder(); $query->insert('calendarobjects') @@ -295,7 +290,7 @@ class BackendTest extends TestCase { 'calendarid' => $query->createNamedParameter(1), 'size' => $query->createNamedParameter(42), ]) - ->execute(); + ->executeStatement(); $query = self::$realDatabase->getQueryBuilder(); $query->insert('calendarobjects') @@ -305,7 +300,7 @@ class BackendTest extends TestCase { 'calendarid' => $query->createNamedParameter(99), 'size' => $query->createNamedParameter(42), ]) - ->execute(); + ->executeStatement(); $query = self::$realDatabase->getQueryBuilder(); $query->insert('calendar_reminders') @@ -323,7 +318,7 @@ class BackendTest extends TestCase { 'notification_date' => $query->createNamedParameter(123456), 'is_repeat_based' => $query->createNamedParameter(0), ]) - ->execute(); + ->executeStatement(); $query = self::$realDatabase->getQueryBuilder(); $query->insert('calendar_reminders') @@ -341,7 +336,7 @@ class BackendTest extends TestCase { 'notification_date' => $query->createNamedParameter(123456), 'is_repeat_based' => $query->createNamedParameter(0), ]) - ->execute(); + ->executeStatement(); $query = self::$realDatabase->getQueryBuilder(); $query->insert('calendar_reminders') @@ -359,7 +354,7 @@ class BackendTest extends TestCase { 'notification_date' => $query->createNamedParameter(123499), 'is_repeat_based' => $query->createNamedParameter(0), ]) - ->execute(); + ->executeStatement(); $query = self::$realDatabase->getQueryBuilder(); $query->insert('calendar_reminders') @@ -377,6 +372,6 @@ class BackendTest extends TestCase { 'notification_date' => $query->createNamedParameter(123600), 'is_repeat_based' => $query->createNamedParameter(0), ]) - ->execute(); + ->executeStatement(); } } diff --git a/apps/dav/tests/unit/CalDAV/Reminder/NotificationProvider/AbstractNotificationProviderTest.php b/apps/dav/tests/unit/CalDAV/Reminder/NotificationProvider/AbstractNotificationProviderTest.php deleted file mode 100644 index 60ef1df43d5..00000000000 --- a/apps/dav/tests/unit/CalDAV/Reminder/NotificationProvider/AbstractNotificationProviderTest.php +++ /dev/null @@ -1,75 +0,0 @@ -logger = $this->createMock(LoggerInterface::class); - $this->l10nFactory = $this->createMock(L10NFactory::class); - $this->l10n = $this->createMock(IL10N::class); - $this->urlGenerator = $this->createMock(IURLGenerator::class); - $this->config = $this->createMock(IConfig::class); - - $this->vcalendar = new VCalendar(); - $this->vcalendar->add('VEVENT', [ - 'SUMMARY' => 'Fellowship meeting', - 'DTSTART' => new \DateTime('2017-01-01 00:00:00+00:00'), // 1483228800, - 'UID' => 'uid1234', - ]); - $this->calendarDisplayName = 'Personal'; - - $this->user = $this->createMock(IUser::class); - } -} diff --git a/apps/dav/tests/unit/CalDAV/Reminder/NotificationProvider/AbstractNotificationProviderTestCase.php b/apps/dav/tests/unit/CalDAV/Reminder/NotificationProvider/AbstractNotificationProviderTestCase.php new file mode 100644 index 00000000000..70b374298ea --- /dev/null +++ b/apps/dav/tests/unit/CalDAV/Reminder/NotificationProvider/AbstractNotificationProviderTestCase.php @@ -0,0 +1,52 @@ +logger = $this->createMock(LoggerInterface::class); + $this->l10nFactory = $this->createMock(L10NFactory::class); + $this->l10n = $this->createMock(IL10N::class); + $this->urlGenerator = $this->createMock(IURLGenerator::class); + $this->config = $this->createMock(IConfig::class); + + $this->vcalendar = new VCalendar(); + $this->vcalendar->add('VEVENT', [ + 'SUMMARY' => 'Fellowship meeting', + 'DTSTART' => new \DateTime('2017-01-01 00:00:00+00:00'), // 1483228800, + 'UID' => 'uid1234', + ]); + $this->calendarDisplayName = 'Personal'; + + $this->user = $this->createMock(IUser::class); + } +} diff --git a/apps/dav/tests/unit/CalDAV/Reminder/NotificationProvider/EmailProviderTest.php b/apps/dav/tests/unit/CalDAV/Reminder/NotificationProvider/EmailProviderTest.php index 42eb0b0faa3..f7fbac2c407 100644 --- a/apps/dav/tests/unit/CalDAV/Reminder/NotificationProvider/EmailProviderTest.php +++ b/apps/dav/tests/unit/CalDAV/Reminder/NotificationProvider/EmailProviderTest.php @@ -18,11 +18,9 @@ use OCP\Util; use PHPUnit\Framework\MockObject\MockObject; use Sabre\VObject\Component\VCalendar; -class EmailProviderTest extends AbstractNotificationProviderTest { +class EmailProviderTest extends AbstractNotificationProviderTestCase { public const USER_EMAIL = 'frodo@hobb.it'; - - /** @var IMailer|MockObject */ - private $mailer; + private IMailer&MockObject $mailer; protected function setUp(): void { parent::setUp(); @@ -97,18 +95,12 @@ class EmailProviderTest extends AbstractNotificationProviderTest { $this->mailer->expects($this->exactly(4)) ->method('validateMailAddress') - ->withConsecutive( - ['uid1@example.com'], - ['uid2@example.com'], - ['uid3@example.com'], - ['invalid'], - ) - ->willReturnOnConsecutiveCalls( - true, - true, - true, - false, - ); + ->willReturnMap([ + ['uid1@example.com', true], + ['uid2@example.com', true], + ['uid3@example.com', true], + ['invalid', false], + ]); $this->mailer->expects($this->exactly(3)) ->method('createMessage') @@ -119,14 +111,18 @@ class EmailProviderTest extends AbstractNotificationProviderTest { $message22 ); - $this->mailer->expects($this->exactly(3)) + $calls = [ + [$message11], + [$message21], + [$message22], + ]; + $this->mailer->expects($this->exactly(count($calls))) ->method('send') - ->withConsecutive( - [$message11], - [$message21], - [$message22], - ) - ->willReturn([]); + ->willReturnCallback(function () use (&$calls) { + $expected = array_shift($calls); + $this->assertEquals($expected, func_get_args()); + return []; + }); $this->setupURLGeneratorMock(2); @@ -215,16 +211,22 @@ class EmailProviderTest extends AbstractNotificationProviderTest { $message22, $message23, ); - $this->mailer->expects($this->exactly(6)) + + $calls = [ + [$message11], + [$message12], + [$message13], + [$message21], + [$message22], + [$message23], + ]; + $this->mailer->expects($this->exactly(count($calls))) ->method('send') - ->withConsecutive( - [$message11], - [$message12], - [$message13], - [$message21], - [$message22], - [$message23], - )->willReturn([]); + ->willReturnCallback(function () use (&$calls) { + $expected = array_shift($calls); + $this->assertEquals($expected, func_get_args()); + return []; + }); $this->setupURLGeneratorMock(2); $vcalendar = $this->getAttendeeVCalendar(); @@ -293,12 +295,18 @@ class EmailProviderTest extends AbstractNotificationProviderTest { $message12, $message13, ); - $this->mailer->expects($this->exactly(2)) + + $calls = [ + [$message12], + [$message13], + ]; + $this->mailer->expects($this->exactly(count($calls))) ->method('send') - ->withConsecutive( - [$message12], - [$message13], - )->willReturn([]); + ->willReturnCallback(function () use (&$calls) { + $expected = array_shift($calls); + $this->assertEquals($expected, func_get_args()); + return []; + }); $this->setupURLGeneratorMock(1); $vcalendar = $this->getAttendeeVCalendar(); diff --git a/apps/dav/tests/unit/CalDAV/Reminder/NotificationProvider/PushProviderTest.php b/apps/dav/tests/unit/CalDAV/Reminder/NotificationProvider/PushProviderTest.php index b090fa0e5e7..c601463363b 100644 --- a/apps/dav/tests/unit/CalDAV/Reminder/NotificationProvider/PushProviderTest.php +++ b/apps/dav/tests/unit/CalDAV/Reminder/NotificationProvider/PushProviderTest.php @@ -13,13 +13,11 @@ use OCP\AppFramework\Utility\ITimeFactory; use OCP\IUser; use OCP\Notification\IManager; use OCP\Notification\INotification; +use PHPUnit\Framework\MockObject\MockObject; -class PushProviderTest extends AbstractNotificationProviderTest { - /** @var IManager|\PHPUnit\Framework\MockObject\MockObject */ - private $manager; - - /** @var ITimeFactory|\PHPUnit\Framework\MockObject\MockObject */ - private $timeFactory; +class PushProviderTest extends AbstractNotificationProviderTestCase { + private IManager&MockObject $manager; + private ITimeFactory&MockObject $timeFactory; protected function setUp(): void { parent::setUp(); @@ -96,20 +94,23 @@ class PushProviderTest extends AbstractNotificationProviderTest { $this->manager->expects($this->exactly(3)) ->method('createNotification') - ->with() ->willReturnOnConsecutiveCalls( $notification1, $notification2, $notification3 ); + $calls = [ + $notification1, + $notification2, + $notification3, + ]; $this->manager->expects($this->exactly(3)) ->method('notify') - ->withConsecutive( - [$notification1], - [$notification2], - [$notification3], - ); + ->willReturnCallback(function ($notification) use (&$calls) { + $expected = array_shift($calls); + $this->assertEquals($expected, $notification); + }); $this->provider->send($this->vcalendar->VEVENT, $this->calendarDisplayName, [], $users); } diff --git a/apps/dav/tests/unit/CalDAV/Reminder/NotificationProviderManagerTest.php b/apps/dav/tests/unit/CalDAV/Reminder/NotificationProviderManagerTest.php index 6d0e62f505b..6b813ed0228 100644 --- a/apps/dav/tests/unit/CalDAV/Reminder/NotificationProviderManagerTest.php +++ b/apps/dav/tests/unit/CalDAV/Reminder/NotificationProviderManagerTest.php @@ -21,9 +21,7 @@ use Test\TestCase; * @group DB */ class NotificationProviderManagerTest extends TestCase { - - /** @var NotificationProviderManager|\PHPUnit\Framework\MockObject\MockObject */ - private $providerManager; + private NotificationProviderManager $providerManager; /** * @throws QueryException diff --git a/apps/dav/tests/unit/CalDAV/Reminder/NotifierTest.php b/apps/dav/tests/unit/CalDAV/Reminder/NotifierTest.php index dcf11a1a6b8..147446152d8 100644 --- a/apps/dav/tests/unit/CalDAV/Reminder/NotifierTest.php +++ b/apps/dav/tests/unit/CalDAV/Reminder/NotifierTest.php @@ -21,20 +21,11 @@ use PHPUnit\Framework\MockObject\MockObject; use Test\TestCase; class NotifierTest extends TestCase { - /** @var Notifier */ - protected $notifier; - - /** @var IFactory|MockObject */ - protected $factory; - - /** @var IURLGenerator|MockObject */ - protected $urlGenerator; - - /** @var IL10N|MockObject */ - protected $l10n; - - /** @var ITimeFactory|MockObject */ - protected $timeFactory; + protected IFactory&MockObject $factory; + protected IURLGenerator&MockObject $urlGenerator; + protected IL10N&MockObject $l10n; + protected ITimeFactory&MockObject $timeFactory; + protected Notifier $notifier; protected function setUp(): void { parent::setUp(); @@ -92,7 +83,7 @@ class NotifierTest extends TestCase { $this->expectException(UnknownNotificationException::class); $this->expectExceptionMessage('Notification not from this app'); - /** @var INotification|MockObject $notification */ + /** @var INotification&MockObject $notification */ $notification = $this->createMock(INotification::class); $notification->expects($this->once()) @@ -109,7 +100,7 @@ class NotifierTest extends TestCase { $this->expectException(UnknownNotificationException::class); $this->expectExceptionMessage('Unknown subject'); - /** @var INotification|MockObject $notification */ + /** @var INotification&MockObject $notification */ $notification = $this->createMock(INotification::class); $notification->expects($this->once()) @@ -130,7 +121,7 @@ class NotifierTest extends TestCase { return $d1->diff($d2)->y < 0; } - public function dataPrepare(): array { + public static function dataPrepare(): array { return [ [ 'calendar_reminder', @@ -181,16 +172,9 @@ class NotifierTest extends TestCase { /** * @dataProvider dataPrepare - * - * @param string $subjectType - * @param array $subjectParams - * @param string $subject - * @param array $messageParams - * @param string $message - * @throws \Exception */ public function testPrepare(string $subjectType, array $subjectParams, string $subject, array $messageParams, string $message): void { - /** @var INotification|MockObject $notification */ + /** @var INotification&MockObject $notification */ $notification = $this->createMock(INotification::class); $notification->expects($this->once()) @@ -235,7 +219,7 @@ class NotifierTest extends TestCase { } public function testPassedEvent(): void { - /** @var INotification|MockObject $notification */ + /** @var INotification&MockObject $notification */ $notification = $this->createMock(INotification::class); $notification->expects($this->once()) diff --git a/apps/dav/tests/unit/CalDAV/Reminder/ReminderServiceTest.php b/apps/dav/tests/unit/CalDAV/Reminder/ReminderServiceTest.php index 198c8d97b12..4b6735ee297 100644 --- a/apps/dav/tests/unit/CalDAV/Reminder/ReminderServiceTest.php +++ b/apps/dav/tests/unit/CalDAV/Reminder/ReminderServiceTest.php @@ -26,35 +26,16 @@ use Psr\Log\LoggerInterface; use Test\TestCase; class ReminderServiceTest extends TestCase { - /** @var Backend|MockObject */ - private $backend; - - /** @var NotificationProviderManager|MockObject */ - private $notificationProviderManager; - - /** @var IUserManager|MockObject */ - private $userManager; - - /** @var IGroupManager|MockObject */ - private $groupManager; - - /** @var CalDavBackend|MockObject */ - private $caldavBackend; - - /** @var ITimeFactory|MockObject */ - private $timeFactory; - - /** @var IConfig|MockObject */ - private $config; - - /** @var ReminderService */ - private $reminderService; - - /** @var MockObject|LoggerInterface */ - private $logger; - - /** @var MockObject|Principal */ - private $principalConnector; + private Backend&MockObject $backend; + private NotificationProviderManager&MockObject $notificationProviderManager; + private IUserManager&MockObject $userManager; + private IGroupManager&MockObject $groupManager; + private CalDavBackend&MockObject $caldavBackend; + private ITimeFactory&MockObject $timeFactory; + private IConfig&MockObject $config; + private LoggerInterface&MockObject $logger; + private Principal&MockObject $principalConnector; + private ReminderService $reminderService; public const CALENDAR_DATA = << 'vevent', ]; - $this->backend->expects($this->exactly(2)) + $calls = [ + [1337, 42, 'wej2z68l9h', false, 1465430400, false, '5c70531aab15c92b52518ae10a2f78a4', 'de919af7429d3b5c11e8b9d289b411a6', 'EMAIL', true, 1465429500, false], + [1337, 42, 'wej2z68l9h', false, 1465430400, false, '5c70531aab15c92b52518ae10a2f78a4', '35b3eae8e792aa2209f0b4e1a302f105', 'DISPLAY', false, 1465344000, false] + ]; + $this->backend->expects($this->exactly(count($calls))) ->method('insertReminder') - ->withConsecutive( - [1337, 42, 'wej2z68l9h', false, 1465430400, false, '5c70531aab15c92b52518ae10a2f78a4', 'de919af7429d3b5c11e8b9d289b411a6', 'EMAIL', true, 1465429500, false], - [1337, 42, 'wej2z68l9h', false, 1465430400, false, '5c70531aab15c92b52518ae10a2f78a4', '35b3eae8e792aa2209f0b4e1a302f105', 'DISPLAY', false, 1465344000, false] - ) - ->willReturn(1); + ->willReturnCallback(function () use (&$calls) { + $expected = array_shift($calls); + $this->assertEquals($expected, func_get_args()); + return 1; + }); $this->timeFactory->expects($this->once()) ->method('getDateTime') @@ -353,12 +336,7 @@ EOD; ]; $this->backend->expects($this->never()) - ->method('insertReminder') - ->withConsecutive( - [1337, 42, 'wej2z68l9h', false, null, false, '5c70531aab15c92b52518ae10a2f78a4', 'de919af7429d3b5c11e8b9d289b411a6', 'EMAIL', true, 1465429500, false], - [1337, 42, 'wej2z68l9h', false, null, false, '5c70531aab15c92b52518ae10a2f78a4', '35b3eae8e792aa2209f0b4e1a302f105', 'DISPLAY', false, 1465344000, false] - ) - ->willReturn(1); + ->method('insertReminder'); $this->reminderService->onCalendarObjectCreate($objectData); } @@ -371,16 +349,20 @@ EOD; 'component' => 'vevent', ]; - $this->backend->expects($this->exactly(5)) + $calls = [ + [1337, 42, 'wej2z68l9h', false, 1465430400, false, '5c70531aab15c92b52518ae10a2f78a4', 'ecacbf07d413c3c78d1ac7ad8c469602', 'EMAIL', true, 1465429500, false], + [1337, 42, 'wej2z68l9h', false, 1465430400, false, '5c70531aab15c92b52518ae10a2f78a4', 'ecacbf07d413c3c78d1ac7ad8c469602', 'EMAIL', true, 1465429620, true], + [1337, 42, 'wej2z68l9h', false, 1465430400, false, '5c70531aab15c92b52518ae10a2f78a4', 'ecacbf07d413c3c78d1ac7ad8c469602', 'EMAIL', true, 1465429740, true], + [1337, 42, 'wej2z68l9h', false, 1465430400, false, '5c70531aab15c92b52518ae10a2f78a4', 'ecacbf07d413c3c78d1ac7ad8c469602', 'EMAIL', true, 1465429860, true], + [1337, 42, 'wej2z68l9h', false, 1465430400, false, '5c70531aab15c92b52518ae10a2f78a4', 'ecacbf07d413c3c78d1ac7ad8c469602', 'EMAIL', true, 1465429980, true] + ]; + $this->backend->expects($this->exactly(count($calls))) ->method('insertReminder') - ->withConsecutive( - [1337, 42, 'wej2z68l9h', false, 1465430400, false, '5c70531aab15c92b52518ae10a2f78a4', 'ecacbf07d413c3c78d1ac7ad8c469602', 'EMAIL', true, 1465429500, false], - [1337, 42, 'wej2z68l9h', false, 1465430400, false, '5c70531aab15c92b52518ae10a2f78a4', 'ecacbf07d413c3c78d1ac7ad8c469602', 'EMAIL', true, 1465429620, true], - [1337, 42, 'wej2z68l9h', false, 1465430400, false, '5c70531aab15c92b52518ae10a2f78a4', 'ecacbf07d413c3c78d1ac7ad8c469602', 'EMAIL', true, 1465429740, true], - [1337, 42, 'wej2z68l9h', false, 1465430400, false, '5c70531aab15c92b52518ae10a2f78a4', 'ecacbf07d413c3c78d1ac7ad8c469602', 'EMAIL', true, 1465429860, true], - [1337, 42, 'wej2z68l9h', false, 1465430400, false, '5c70531aab15c92b52518ae10a2f78a4', 'ecacbf07d413c3c78d1ac7ad8c469602', 'EMAIL', true, 1465429980, true] - ) - ->willReturn(1); + ->willReturnCallback(function () use (&$calls) { + $expected = array_shift($calls); + $this->assertEquals($expected, func_get_args()); + return 1; + }); $this->timeFactory->expects($this->once()) ->method('getDateTime') @@ -398,13 +380,17 @@ EOD; 'component' => 'vevent', ]; - $this->backend->expects($this->exactly(2)) + $calls = [ + [1337, 42, 'wej2z68l9h', true, 1467244800, false, 'fbdb2726bc0f7dfacac1d881c1453e20', 'de919af7429d3b5c11e8b9d289b411a6', 'EMAIL', true, 1467243900, false], + [1337, 42, 'wej2z68l9h', true, 1467849600, false, 'fbdb2726bc0f7dfacac1d881c1453e20', '8996992118817f9f311ac5cc56d1cc97', 'EMAIL', true, 1467158400, false] + ]; + $this->backend->expects($this->exactly(count($calls))) ->method('insertReminder') - ->withConsecutive( - [1337, 42, 'wej2z68l9h', true, 1467244800, false, 'fbdb2726bc0f7dfacac1d881c1453e20', 'de919af7429d3b5c11e8b9d289b411a6', 'EMAIL', true, 1467243900, false], - [1337, 42, 'wej2z68l9h', true, 1467849600, false, 'fbdb2726bc0f7dfacac1d881c1453e20', '8996992118817f9f311ac5cc56d1cc97', 'EMAIL', true, 1467158400, false] - ) - ->willReturn(1); + ->willReturnCallback(function () use (&$calls) { + $expected = array_shift($calls); + $this->assertEquals($expected, func_get_args()); + return 1; + }); $this->timeFactory->expects($this->once()) ->method('getDateTime') @@ -521,17 +507,23 @@ EOD; ->willReturn([ '{urn:ietf:params:xml:ns:caldav}calendar-timezone' => null, ]); - $this->backend->expects($this->exactly(6)) + + $calls = [ + [1337, 42, 'wej2z68l9h', true, 1467244800, false, 'fbdb2726bc0f7dfacac1d881c1453e20', 'ecacbf07d413c3c78d1ac7ad8c469602', 'EMAIL', true, 1467243900, false], + [1337, 42, 'wej2z68l9h', true, 1467244800, false, 'fbdb2726bc0f7dfacac1d881c1453e20', 'ecacbf07d413c3c78d1ac7ad8c469602', 'EMAIL', true, 1467244020, true], + [1337, 42, 'wej2z68l9h', true, 1467244800, false, 'fbdb2726bc0f7dfacac1d881c1453e20', 'ecacbf07d413c3c78d1ac7ad8c469602', 'EMAIL', true, 1467244140, true], + [1337, 42, 'wej2z68l9h', true, 1467244800, false, 'fbdb2726bc0f7dfacac1d881c1453e20', 'ecacbf07d413c3c78d1ac7ad8c469602', 'EMAIL', true, 1467244260, true], + [1337, 42, 'wej2z68l9h', true, 1467244800, false, 'fbdb2726bc0f7dfacac1d881c1453e20', 'ecacbf07d413c3c78d1ac7ad8c469602', 'EMAIL', true, 1467244380, true], + [1337, 42, 'wej2z68l9h', true, 1467849600, false, 'fbdb2726bc0f7dfacac1d881c1453e20', '8996992118817f9f311ac5cc56d1cc97', 'EMAIL', true, 1467158400, false] + ]; + $this->backend->expects($this->exactly(count($calls))) ->method('insertReminder') - ->withConsecutive( - [1337, 42, 'wej2z68l9h', true, 1467244800, false, 'fbdb2726bc0f7dfacac1d881c1453e20', 'ecacbf07d413c3c78d1ac7ad8c469602', 'EMAIL', true, 1467243900, false], - [1337, 42, 'wej2z68l9h', true, 1467244800, false, 'fbdb2726bc0f7dfacac1d881c1453e20', 'ecacbf07d413c3c78d1ac7ad8c469602', 'EMAIL', true, 1467244020, true], - [1337, 42, 'wej2z68l9h', true, 1467244800, false, 'fbdb2726bc0f7dfacac1d881c1453e20', 'ecacbf07d413c3c78d1ac7ad8c469602', 'EMAIL', true, 1467244140, true], - [1337, 42, 'wej2z68l9h', true, 1467244800, false, 'fbdb2726bc0f7dfacac1d881c1453e20', 'ecacbf07d413c3c78d1ac7ad8c469602', 'EMAIL', true, 1467244260, true], - [1337, 42, 'wej2z68l9h', true, 1467244800, false, 'fbdb2726bc0f7dfacac1d881c1453e20', 'ecacbf07d413c3c78d1ac7ad8c469602', 'EMAIL', true, 1467244380, true], - [1337, 42, 'wej2z68l9h', true, 1467849600, false, 'fbdb2726bc0f7dfacac1d881c1453e20', '8996992118817f9f311ac5cc56d1cc97', 'EMAIL', true, 1467158400, false] - ) - ->willReturn(1); + ->willReturnCallback(function () use (&$calls) { + $expected = array_shift($calls); + $this->assertEquals($expected, func_get_args()); + return 1; + }); + $this->timeFactory->expects($this->once()) ->method('getDateTime') ->with() @@ -556,9 +548,7 @@ EOD; $expectedReminderTimstamp = (new DateTime('2023-02-04T08:00:00', new DateTimeZone('Europe/Vienna')))->getTimestamp(); $this->backend->expects(self::once()) ->method('insertReminder') - ->withConsecutive( - [1337, 42, self::anything(), false, self::anything(), false, self::anything(), self::anything(), self::anything(), true, $expectedReminderTimstamp, false], - ) + ->with(1337, 42, self::anything(), false, self::anything(), false, self::anything(), self::anything(), self::anything(), true, $expectedReminderTimstamp, false) ->willReturn(1); $this->caldavBackend->expects(self::once()) ->method('getCalendarById') @@ -684,22 +674,22 @@ EOD; $provider3 = $this->createMock(INotificationProvider::class); $provider4 = $this->createMock(INotificationProvider::class); $provider5 = $this->createMock(INotificationProvider::class); - $this->notificationProviderManager->expects($this->exactly(5)) + + $getProviderCalls = [ + ['EMAIL', $provider1], + ['EMAIL', $provider2], + ['DISPLAY', $provider3], + ['EMAIL', $provider4], + ['EMAIL', $provider5], + ]; + $this->notificationProviderManager->expects($this->exactly(count($getProviderCalls))) ->method('getProvider') - ->withConsecutive( - ['EMAIL'], - ['EMAIL'], - ['DISPLAY'], - ['EMAIL'], - ['EMAIL'], - ) - ->willReturnOnConsecutiveCalls( - $provider1, - $provider2, - $provider3, - $provider4, - $provider5, - ); + ->willReturnCallback(function () use (&$getProviderCalls) { + $expected = array_shift($getProviderCalls); + $return = array_pop($expected); + $this->assertEquals($expected, func_get_args()); + return $return; + }); $user = $this->createMock(IUser::class); $this->userManager->expects($this->exactly(5)) @@ -748,20 +738,36 @@ EOD; return true; }, 'Displayname 123', $user)); + $removeReminderCalls = [ + [1], + [2], + [3], + [4], + [5], + ]; $this->backend->expects($this->exactly(5)) ->method('removeReminder') - ->withConsecutive([1], [2], [3], [4], [5]); - $this->backend->expects($this->exactly(6)) + ->willReturnCallback(function () use (&$removeReminderCalls) { + $expected = array_shift($removeReminderCalls); + $this->assertEquals($expected, func_get_args()); + }); + + + $insertReminderCalls = [ + [1337, 42, 'wej2z68l9h', true, 1467849600, false, 'fbdb2726bc0f7dfacac1d881c1453e20', 'ecacbf07d413c3c78d1ac7ad8c469602', 'EMAIL', true, 1467848700, false], + [1337, 42, 'wej2z68l9h', true, 1467849600, false, 'fbdb2726bc0f7dfacac1d881c1453e20', 'ecacbf07d413c3c78d1ac7ad8c469602', 'EMAIL', true, 1467848820, true], + [1337, 42, 'wej2z68l9h', true, 1467849600, false, 'fbdb2726bc0f7dfacac1d881c1453e20', 'ecacbf07d413c3c78d1ac7ad8c469602', 'EMAIL', true, 1467848940, true], + [1337, 42, 'wej2z68l9h', true, 1467849600, false, 'fbdb2726bc0f7dfacac1d881c1453e20', 'ecacbf07d413c3c78d1ac7ad8c469602', 'EMAIL', true, 1467849060, true], + [1337, 42, 'wej2z68l9h', true, 1467849600, false, 'fbdb2726bc0f7dfacac1d881c1453e20', 'ecacbf07d413c3c78d1ac7ad8c469602', 'EMAIL', true, 1467849180, true], + [1337, 42, 'wej2z68l9h', true, 1468454400, false, 'fbdb2726bc0f7dfacac1d881c1453e20', '8996992118817f9f311ac5cc56d1cc97', 'EMAIL', true, 1467763200, false], + ]; + $this->backend->expects($this->exactly(count($insertReminderCalls))) ->method('insertReminder') - ->withConsecutive( - [1337, 42, 'wej2z68l9h', true, 1467849600, false, 'fbdb2726bc0f7dfacac1d881c1453e20', 'ecacbf07d413c3c78d1ac7ad8c469602', 'EMAIL', true, 1467848700, false], - [1337, 42, 'wej2z68l9h', true, 1467849600, false, 'fbdb2726bc0f7dfacac1d881c1453e20', 'ecacbf07d413c3c78d1ac7ad8c469602', 'EMAIL', true, 1467848820, true], - [1337, 42, 'wej2z68l9h', true, 1467849600, false, 'fbdb2726bc0f7dfacac1d881c1453e20', 'ecacbf07d413c3c78d1ac7ad8c469602', 'EMAIL', true, 1467848940, true], - [1337, 42, 'wej2z68l9h', true, 1467849600, false, 'fbdb2726bc0f7dfacac1d881c1453e20', 'ecacbf07d413c3c78d1ac7ad8c469602', 'EMAIL', true, 1467849060, true], - [1337, 42, 'wej2z68l9h', true, 1467849600, false, 'fbdb2726bc0f7dfacac1d881c1453e20', 'ecacbf07d413c3c78d1ac7ad8c469602', 'EMAIL', true, 1467849180, true], - [1337, 42, 'wej2z68l9h', true, 1468454400, false, 'fbdb2726bc0f7dfacac1d881c1453e20', '8996992118817f9f311ac5cc56d1cc97', 'EMAIL', true, 1467763200, false], - ) - ->willReturn(99); + ->willReturnCallback(function () use (&$insertReminderCalls) { + $expected = array_shift($insertReminderCalls); + $this->assertEquals($expected, func_get_args()); + return 99; + }); $this->timeFactory->method('getDateTime') ->willReturn(DateTime::createFromFormat(DateTime::ATOM, '2016-06-08T00:00:00+00:00')); diff --git a/apps/dav/tests/unit/CalDAV/ResourceBooking/AbstractPrincipalBackendTest.php b/apps/dav/tests/unit/CalDAV/ResourceBooking/AbstractPrincipalBackendTest.php deleted file mode 100644 index b2fd9cfb93f..00000000000 --- a/apps/dav/tests/unit/CalDAV/ResourceBooking/AbstractPrincipalBackendTest.php +++ /dev/null @@ -1,569 +0,0 @@ -userSession = $this->createMock(IUserSession::class); - $this->groupManager = $this->createMock(IGroupManager::class); - $this->logger = $this->createMock(LoggerInterface::class); - $this->proxyMapper = $this->createMock(ProxyMapper::class); - } - - protected function tearDown(): void { - $query = self::$realDatabase->getQueryBuilder(); - - $query->delete('calendar_resources')->execute(); - $query->delete('calendar_resources_md')->execute(); - $query->delete('calendar_rooms')->execute(); - $query->delete('calendar_rooms_md')->execute(); - } - - public function testGetPrincipalsByPrefix(): void { - $actual = $this->principalBackend->getPrincipalsByPrefix($this->principalPrefix); - - $this->assertEquals([ - [ - 'uri' => $this->principalPrefix . '/backend1-res1', - '{DAV:}displayname' => 'Beamer1', - '{http://sabredav.org/ns}email-address' => 'res1@foo.bar', - '{urn:ietf:params:xml:ns:caldav}calendar-user-type' => $this->expectedCUType, - ], - [ - 'uri' => $this->principalPrefix . '/backend1-res2', - '{DAV:}displayname' => 'TV1', - '{http://sabredav.org/ns}email-address' => 'res2@foo.bar', - '{urn:ietf:params:xml:ns:caldav}calendar-user-type' => $this->expectedCUType, - ], - [ - 'uri' => $this->principalPrefix . '/backend2-res3', - '{DAV:}displayname' => 'Beamer2', - '{http://sabredav.org/ns}email-address' => 'res3@foo.bar', - '{urn:ietf:params:xml:ns:caldav}calendar-user-type' => $this->expectedCUType, - '{http://nextcloud.com/ns}foo' => 'value1', - '{http://nextcloud.com/ns}meta2' => 'value2', - ], - [ - 'uri' => $this->principalPrefix . '/backend2-res4', - '{DAV:}displayname' => 'TV2', - '{http://sabredav.org/ns}email-address' => 'res4@foo.bar', - '{urn:ietf:params:xml:ns:caldav}calendar-user-type' => $this->expectedCUType, - '{http://nextcloud.com/ns}meta1' => 'value1', - '{http://nextcloud.com/ns}meta3' => 'value3-old', - ], - [ - 'uri' => $this->principalPrefix . '/backend3-res5', - '{DAV:}displayname' => 'Beamer3', - '{http://sabredav.org/ns}email-address' => 'res5@foo.bar', - '{urn:ietf:params:xml:ns:caldav}calendar-user-type' => $this->expectedCUType, - ], - [ - 'uri' => $this->principalPrefix . '/backend3-res6', - '{DAV:}displayname' => 'Pointer', - '{http://sabredav.org/ns}email-address' => 'res6@foo.bar', - '{urn:ietf:params:xml:ns:caldav}calendar-user-type' => $this->expectedCUType, - '{http://nextcloud.com/ns}meta99' => 'value99' - ] - ], $actual); - } - - public function testGetNoPrincipalsByPrefixForWrongPrincipalPrefix(): void { - $actual = $this->principalBackend->getPrincipalsByPrefix('principals/users'); - $this->assertEquals([], $actual); - } - - public function testGetPrincipalByPath(): void { - $actual = $this->principalBackend->getPrincipalByPath($this->principalPrefix . '/backend2-res3'); - $this->assertEquals([ - 'uri' => $this->principalPrefix . '/backend2-res3', - '{DAV:}displayname' => 'Beamer2', - '{http://sabredav.org/ns}email-address' => 'res3@foo.bar', - '{urn:ietf:params:xml:ns:caldav}calendar-user-type' => $this->expectedCUType, - '{http://nextcloud.com/ns}foo' => 'value1', - '{http://nextcloud.com/ns}meta2' => 'value2', - ], $actual); - } - - public function testGetPrincipalByPathNotFound(): void { - $actual = $this->principalBackend->getPrincipalByPath($this->principalPrefix . '/db-123'); - $this->assertEquals(null, $actual); - } - - public function testGetPrincipalByPathWrongPrefix(): void { - $actual = $this->principalBackend->getPrincipalByPath('principals/users/foo-bar'); - $this->assertEquals(null, $actual); - } - - public function testGetGroupMemberSet(): void { - $actual = $this->principalBackend->getGroupMemberSet($this->principalPrefix . '/backend1-res1'); - $this->assertEquals([], $actual); - } - - public function testGetGroupMemberSetProxyRead(): void { - $proxy1 = new Proxy(); - $proxy1->setProxyId('proxyId1'); - $proxy1->setPermissions(1); - - $proxy2 = new Proxy(); - $proxy2->setProxyId('proxyId2'); - $proxy2->setPermissions(3); - - $proxy3 = new Proxy(); - $proxy3->setProxyId('proxyId3'); - $proxy3->setPermissions(3); - - $this->proxyMapper->expects($this->once()) - ->method('getProxiesOf') - ->with($this->principalPrefix . '/backend1-res1') - ->willReturn([$proxy1, $proxy2, $proxy3]); - - $actual = $this->principalBackend->getGroupMemberSet($this->principalPrefix . '/backend1-res1/calendar-proxy-read'); - $this->assertEquals(['proxyId1'], $actual); - } - - public function testGetGroupMemberSetProxyWrite(): void { - $proxy1 = new Proxy(); - $proxy1->setProxyId('proxyId1'); - $proxy1->setPermissions(1); - - $proxy2 = new Proxy(); - $proxy2->setProxyId('proxyId2'); - $proxy2->setPermissions(3); - - $proxy3 = new Proxy(); - $proxy3->setProxyId('proxyId3'); - $proxy3->setPermissions(3); - - $this->proxyMapper->expects($this->once()) - ->method('getProxiesOf') - ->with($this->principalPrefix . '/backend1-res1') - ->willReturn([$proxy1, $proxy2, $proxy3]); - - $actual = $this->principalBackend->getGroupMemberSet($this->principalPrefix . '/backend1-res1/calendar-proxy-write'); - $this->assertEquals(['proxyId2', 'proxyId3'], $actual); - } - - public function testGetGroupMembership(): void { - $proxy1 = new Proxy(); - $proxy1->setOwnerId('proxyId1'); - $proxy1->setPermissions(1); - - $proxy2 = new Proxy(); - $proxy2->setOwnerId('proxyId2'); - $proxy2->setPermissions(3); - - $this->proxyMapper->expects($this->once()) - ->method('getProxiesFor') - ->with($this->principalPrefix . '/backend1-res1') - ->willReturn([$proxy1, $proxy2]); - - $actual = $this->principalBackend->getGroupMembership($this->principalPrefix . '/backend1-res1'); - - $this->assertEquals(['proxyId1/calendar-proxy-read', 'proxyId2/calendar-proxy-write'], $actual); - } - - public function testSetGroupMemberSet(): void { - $this->proxyMapper->expects($this->once()) - ->method('getProxiesOf') - ->with($this->principalPrefix . '/backend1-res1') - ->willReturn([]); - - $this->proxyMapper->expects($this->exactly(2)) - ->method('insert') - ->withConsecutive( - [$this->callback(function ($proxy) { - /** @var Proxy $proxy */ - if ($proxy->getOwnerId() !== $this->principalPrefix . '/backend1-res1') { - return false; - } - if ($proxy->getProxyId() !== $this->principalPrefix . '/backend1-res2') { - return false; - } - if ($proxy->getPermissions() !== 3) { - return false; - } - - return true; - })], - [$this->callback(function ($proxy) { - /** @var Proxy $proxy */ - if ($proxy->getOwnerId() !== $this->principalPrefix . '/backend1-res1') { - return false; - } - if ($proxy->getProxyId() !== $this->principalPrefix . '/backend2-res3') { - return false; - } - if ($proxy->getPermissions() !== 3) { - return false; - } - - return true; - })], - ); - - $this->principalBackend->setGroupMemberSet($this->principalPrefix . '/backend1-res1/calendar-proxy-write', [$this->principalPrefix . '/backend1-res2', $this->principalPrefix . '/backend2-res3']); - } - - public function testUpdatePrincipal(): void { - $propPatch = $this->createMock(PropPatch::class); - $actual = $this->principalBackend->updatePrincipal($this->principalPrefix . '/foo-bar', $propPatch); - - $this->assertEquals(0, $actual); - } - - /** - * @dataProvider dataSearchPrincipals - */ - public function testSearchPrincipals($expected, $test): void { - $user = $this->createMock(IUser::class); - $this->userSession->expects($this->once()) - ->method('getUser') - ->with() - ->willReturn($user); - $this->groupManager->expects($this->once()) - ->method('getUserGroupIds') - ->with($user) - ->willReturn(['group1', 'group2']); - - $actual = $this->principalBackend->searchPrincipals($this->principalPrefix, [ - '{http://sabredav.org/ns}email-address' => 'foo', - '{DAV:}displayname' => 'Beamer', - ], $test); - - $this->assertEquals( - str_replace('%prefix%', $this->principalPrefix, $expected), - $actual); - } - - public function dataSearchPrincipals() { - // data providers are called before we subclass - // this class, $this->principalPrefix is null - // at that point, so we need this hack - return [ - [[ - '%prefix%/backend1-res1', - '%prefix%/backend2-res3', - ], 'allof'], - [[ - '%prefix%/backend1-res1', - '%prefix%/backend1-res2', - '%prefix%/backend2-res3', - '%prefix%/backend2-res4', - '%prefix%/backend3-res6', - ], 'anyof'], - ]; - } - - public function testSearchPrincipalsByMetadataKey(): void { - $user = $this->createMock(IUser::class); - $this->userSession->expects($this->once()) - ->method('getUser') - ->with() - ->willReturn($user); - $this->groupManager->expects($this->once()) - ->method('getUserGroupIds') - ->with($user) - ->willReturn(['group1', 'group2']); - - $actual = $this->principalBackend->searchPrincipals($this->principalPrefix, [ - '{http://nextcloud.com/ns}meta3' => 'value', - ]); - - $this->assertEquals([ - $this->principalPrefix . '/backend2-res4', - ], $actual); - } - - public function testSearchPrincipalsByCalendarUserAddressSet(): void { - $user = $this->createMock(IUser::class); - $this->userSession->method('getUser') - ->with() - ->willReturn($user); - $this->groupManager->method('getUserGroupIds') - ->with($user) - ->willReturn(['group1', 'group2']); - - $actual = $this->principalBackend->searchPrincipals($this->principalPrefix, [ - '{urn:ietf:params:xml:ns:caldav}calendar-user-address-set' => 'res2@foo.bar', - ]); - - $this->assertEquals( - str_replace('%prefix%', $this->principalPrefix, [ - '%prefix%/backend1-res2', - ]), - $actual); - } - - public function testSearchPrincipalsEmptySearchProperties(): void { - $this->userSession->expects($this->never()) - ->method('getUser'); - $this->groupManager->expects($this->never()) - ->method('getUserGroupIds'); - - $this->principalBackend->searchPrincipals($this->principalPrefix, []); - } - - public function testSearchPrincipalsWrongPrincipalPrefix(): void { - $this->userSession->expects($this->never()) - ->method('getUser'); - $this->groupManager->expects($this->never()) - ->method('getUserGroupIds'); - - $this->principalBackend->searchPrincipals('principals/users', [ - '{http://sabredav.org/ns}email-address' => 'foo' - ]); - } - - public function testFindByUriByEmail(): void { - $user = $this->createMock(IUser::class); - $this->userSession->expects($this->once()) - ->method('getUser') - ->with() - ->willReturn($user); - $this->groupManager->expects($this->once()) - ->method('getUserGroupIds') - ->with($user) - ->willReturn(['group1', 'group2']); - - $actual = $this->principalBackend->findByUri('mailto:res1@foo.bar', $this->principalPrefix); - $this->assertEquals($this->principalPrefix . '/backend1-res1', $actual); - } - - public function testFindByUriByEmailForbiddenResource(): void { - $user = $this->createMock(IUser::class); - $this->userSession->expects($this->once()) - ->method('getUser') - ->with() - ->willReturn($user); - $this->groupManager->expects($this->once()) - ->method('getUserGroupIds') - ->with($user) - ->willReturn(['group1', 'group2']); - - $actual = $this->principalBackend->findByUri('mailto:res5@foo.bar', $this->principalPrefix); - $this->assertEquals(null, $actual); - } - - public function testFindByUriByEmailNotFound(): void { - $user = $this->createMock(IUser::class); - $this->userSession->expects($this->once()) - ->method('getUser') - ->with() - ->willReturn($user); - $this->groupManager->expects($this->once()) - ->method('getUserGroupIds') - ->with($user) - ->willReturn(['group1', 'group2']); - - $actual = $this->principalBackend->findByUri('mailto:res99@foo.bar', $this->principalPrefix); - $this->assertEquals(null, $actual); - } - - public function testFindByUriByPrincipal(): void { - $user = $this->createMock(IUser::class); - $this->userSession->expects($this->once()) - ->method('getUser') - ->with() - ->willReturn($user); - $this->groupManager->expects($this->once()) - ->method('getUserGroupIds') - ->with($user) - ->willReturn(['group1', 'group2']); - - $actual = $this->principalBackend->findByUri('mailto:res6@foo.bar', $this->principalPrefix); - $this->assertEquals($this->principalPrefix . '/backend3-res6', $actual); - } - - public function testFindByUriByPrincipalForbiddenResource(): void { - $user = $this->createMock(IUser::class); - $this->userSession->expects($this->once()) - ->method('getUser') - ->with() - ->willReturn($user); - $this->groupManager->expects($this->once()) - ->method('getUserGroupIds') - ->with($user) - ->willReturn(['group1', 'group2']); - - $actual = $this->principalBackend->findByUri('principal:' . $this->principalPrefix . '/backend3-res5', $this->principalPrefix); - $this->assertEquals(null, $actual); - } - - public function testFindByUriByPrincipalNotFound(): void { - $user = $this->createMock(IUser::class); - $this->userSession->expects($this->once()) - ->method('getUser') - ->with() - ->willReturn($user); - $this->groupManager->expects($this->once()) - ->method('getUserGroupIds') - ->with($user) - ->willReturn(['group1', 'group2']); - - $actual = $this->principalBackend->findByUri('principal:' . $this->principalPrefix . '/db-123', $this->principalPrefix); - $this->assertEquals(null, $actual); - } - - public function testFindByUriByUnknownUri(): void { - $user = $this->createMock(IUser::class); - $this->userSession->expects($this->once()) - ->method('getUser') - ->with() - ->willReturn($user); - $this->groupManager->expects($this->once()) - ->method('getUserGroupIds') - ->with($user) - ->willReturn(['group1', 'group2']); - - $actual = $this->principalBackend->findByUri('foobar:blub', $this->principalPrefix); - $this->assertEquals(null, $actual); - } - - protected function createTestDatasetInDb() { - $query = self::$realDatabase->getQueryBuilder(); - $query->insert($this->mainDbTable) - ->values([ - 'backend_id' => $query->createNamedParameter('backend1'), - 'resource_id' => $query->createNamedParameter('res1'), - 'email' => $query->createNamedParameter('res1@foo.bar'), - 'displayname' => $query->createNamedParameter('Beamer1'), - 'group_restrictions' => $query->createNamedParameter('[]'), - ]) - ->execute(); - - $query->insert($this->mainDbTable) - ->values([ - 'backend_id' => $query->createNamedParameter('backend1'), - 'resource_id' => $query->createNamedParameter('res2'), - 'email' => $query->createNamedParameter('res2@foo.bar'), - 'displayname' => $query->createNamedParameter('TV1'), - 'group_restrictions' => $query->createNamedParameter('[]'), - ]) - ->execute(); - - $query->insert($this->mainDbTable) - ->values([ - 'backend_id' => $query->createNamedParameter('backend2'), - 'resource_id' => $query->createNamedParameter('res3'), - 'email' => $query->createNamedParameter('res3@foo.bar'), - 'displayname' => $query->createNamedParameter('Beamer2'), - 'group_restrictions' => $query->createNamedParameter('[]'), - ]) - ->execute(); - $id3 = $query->getLastInsertId(); - - $query->insert($this->mainDbTable) - ->values([ - 'backend_id' => $query->createNamedParameter('backend2'), - 'resource_id' => $query->createNamedParameter('res4'), - 'email' => $query->createNamedParameter('res4@foo.bar'), - 'displayname' => $query->createNamedParameter('TV2'), - 'group_restrictions' => $query->createNamedParameter('[]'), - ]) - ->execute(); - $id4 = $query->getLastInsertId(); - - $query->insert($this->mainDbTable) - ->values([ - 'backend_id' => $query->createNamedParameter('backend3'), - 'resource_id' => $query->createNamedParameter('res5'), - 'email' => $query->createNamedParameter('res5@foo.bar'), - 'displayname' => $query->createNamedParameter('Beamer3'), - 'group_restrictions' => $query->createNamedParameter('["foo", "bar"]'), - ]) - ->execute(); - - $query->insert($this->mainDbTable) - ->values([ - 'backend_id' => $query->createNamedParameter('backend3'), - 'resource_id' => $query->createNamedParameter('res6'), - 'email' => $query->createNamedParameter('res6@foo.bar'), - 'displayname' => $query->createNamedParameter('Pointer'), - 'group_restrictions' => $query->createNamedParameter('["group1", "bar"]'), - ]) - ->execute(); - $id6 = $query->getLastInsertId(); - - $query->insert($this->metadataDbTable) - ->values([ - $this->foreignKey => $query->createNamedParameter($id3), - 'key' => $query->createNamedParameter('{http://nextcloud.com/ns}foo'), - 'value' => $query->createNamedParameter('value1') - ]) - ->execute(); - $query->insert($this->metadataDbTable) - ->values([ - $this->foreignKey => $query->createNamedParameter($id3), - 'key' => $query->createNamedParameter('{http://nextcloud.com/ns}meta2'), - 'value' => $query->createNamedParameter('value2') - ]) - ->execute(); - $query->insert($this->metadataDbTable) - ->values([ - $this->foreignKey => $query->createNamedParameter($id4), - 'key' => $query->createNamedParameter('{http://nextcloud.com/ns}meta1'), - 'value' => $query->createNamedParameter('value1') - ]) - ->execute(); - $query->insert($this->metadataDbTable) - ->values([ - $this->foreignKey => $query->createNamedParameter($id4), - 'key' => $query->createNamedParameter('{http://nextcloud.com/ns}meta3'), - 'value' => $query->createNamedParameter('value3-old') - ]) - ->execute(); - $query->insert($this->metadataDbTable) - ->values([ - $this->foreignKey => $query->createNamedParameter($id6), - 'key' => $query->createNamedParameter('{http://nextcloud.com/ns}meta99'), - 'value' => $query->createNamedParameter('value99') - ]) - ->execute(); - } -} diff --git a/apps/dav/tests/unit/CalDAV/ResourceBooking/AbstractPrincipalBackendTestCase.php b/apps/dav/tests/unit/CalDAV/ResourceBooking/AbstractPrincipalBackendTestCase.php new file mode 100644 index 00000000000..26dbcc0f38c --- /dev/null +++ b/apps/dav/tests/unit/CalDAV/ResourceBooking/AbstractPrincipalBackendTestCase.php @@ -0,0 +1,558 @@ +userSession = $this->createMock(IUserSession::class); + $this->groupManager = $this->createMock(IGroupManager::class); + $this->logger = $this->createMock(LoggerInterface::class); + $this->proxyMapper = $this->createMock(ProxyMapper::class); + } + + protected function tearDown(): void { + $query = self::$realDatabase->getQueryBuilder(); + + $query->delete('calendar_resources')->executeStatement(); + $query->delete('calendar_resources_md')->executeStatement(); + $query->delete('calendar_rooms')->executeStatement(); + $query->delete('calendar_rooms_md')->executeStatement(); + } + + public function testGetPrincipalsByPrefix(): void { + $actual = $this->principalBackend->getPrincipalsByPrefix($this->principalPrefix); + + $this->assertEquals([ + [ + 'uri' => $this->principalPrefix . '/backend1-res1', + '{DAV:}displayname' => 'Beamer1', + '{http://sabredav.org/ns}email-address' => 'res1@foo.bar', + '{urn:ietf:params:xml:ns:caldav}calendar-user-type' => $this->expectedCUType, + ], + [ + 'uri' => $this->principalPrefix . '/backend1-res2', + '{DAV:}displayname' => 'TV1', + '{http://sabredav.org/ns}email-address' => 'res2@foo.bar', + '{urn:ietf:params:xml:ns:caldav}calendar-user-type' => $this->expectedCUType, + ], + [ + 'uri' => $this->principalPrefix . '/backend2-res3', + '{DAV:}displayname' => 'Beamer2', + '{http://sabredav.org/ns}email-address' => 'res3@foo.bar', + '{urn:ietf:params:xml:ns:caldav}calendar-user-type' => $this->expectedCUType, + '{http://nextcloud.com/ns}foo' => 'value1', + '{http://nextcloud.com/ns}meta2' => 'value2', + ], + [ + 'uri' => $this->principalPrefix . '/backend2-res4', + '{DAV:}displayname' => 'TV2', + '{http://sabredav.org/ns}email-address' => 'res4@foo.bar', + '{urn:ietf:params:xml:ns:caldav}calendar-user-type' => $this->expectedCUType, + '{http://nextcloud.com/ns}meta1' => 'value1', + '{http://nextcloud.com/ns}meta3' => 'value3-old', + ], + [ + 'uri' => $this->principalPrefix . '/backend3-res5', + '{DAV:}displayname' => 'Beamer3', + '{http://sabredav.org/ns}email-address' => 'res5@foo.bar', + '{urn:ietf:params:xml:ns:caldav}calendar-user-type' => $this->expectedCUType, + ], + [ + 'uri' => $this->principalPrefix . '/backend3-res6', + '{DAV:}displayname' => 'Pointer', + '{http://sabredav.org/ns}email-address' => 'res6@foo.bar', + '{urn:ietf:params:xml:ns:caldav}calendar-user-type' => $this->expectedCUType, + '{http://nextcloud.com/ns}meta99' => 'value99' + ] + ], $actual); + } + + public function testGetNoPrincipalsByPrefixForWrongPrincipalPrefix(): void { + $actual = $this->principalBackend->getPrincipalsByPrefix('principals/users'); + $this->assertEquals([], $actual); + } + + public function testGetPrincipalByPath(): void { + $actual = $this->principalBackend->getPrincipalByPath($this->principalPrefix . '/backend2-res3'); + $this->assertEquals([ + 'uri' => $this->principalPrefix . '/backend2-res3', + '{DAV:}displayname' => 'Beamer2', + '{http://sabredav.org/ns}email-address' => 'res3@foo.bar', + '{urn:ietf:params:xml:ns:caldav}calendar-user-type' => $this->expectedCUType, + '{http://nextcloud.com/ns}foo' => 'value1', + '{http://nextcloud.com/ns}meta2' => 'value2', + ], $actual); + } + + public function testGetPrincipalByPathNotFound(): void { + $actual = $this->principalBackend->getPrincipalByPath($this->principalPrefix . '/db-123'); + $this->assertEquals(null, $actual); + } + + public function testGetPrincipalByPathWrongPrefix(): void { + $actual = $this->principalBackend->getPrincipalByPath('principals/users/foo-bar'); + $this->assertEquals(null, $actual); + } + + public function testGetGroupMemberSet(): void { + $actual = $this->principalBackend->getGroupMemberSet($this->principalPrefix . '/backend1-res1'); + $this->assertEquals([], $actual); + } + + public function testGetGroupMemberSetProxyRead(): void { + $proxy1 = new Proxy(); + $proxy1->setProxyId('proxyId1'); + $proxy1->setPermissions(1); + + $proxy2 = new Proxy(); + $proxy2->setProxyId('proxyId2'); + $proxy2->setPermissions(3); + + $proxy3 = new Proxy(); + $proxy3->setProxyId('proxyId3'); + $proxy3->setPermissions(3); + + $this->proxyMapper->expects($this->once()) + ->method('getProxiesOf') + ->with($this->principalPrefix . '/backend1-res1') + ->willReturn([$proxy1, $proxy2, $proxy3]); + + $actual = $this->principalBackend->getGroupMemberSet($this->principalPrefix . '/backend1-res1/calendar-proxy-read'); + $this->assertEquals(['proxyId1'], $actual); + } + + public function testGetGroupMemberSetProxyWrite(): void { + $proxy1 = new Proxy(); + $proxy1->setProxyId('proxyId1'); + $proxy1->setPermissions(1); + + $proxy2 = new Proxy(); + $proxy2->setProxyId('proxyId2'); + $proxy2->setPermissions(3); + + $proxy3 = new Proxy(); + $proxy3->setProxyId('proxyId3'); + $proxy3->setPermissions(3); + + $this->proxyMapper->expects($this->once()) + ->method('getProxiesOf') + ->with($this->principalPrefix . '/backend1-res1') + ->willReturn([$proxy1, $proxy2, $proxy3]); + + $actual = $this->principalBackend->getGroupMemberSet($this->principalPrefix . '/backend1-res1/calendar-proxy-write'); + $this->assertEquals(['proxyId2', 'proxyId3'], $actual); + } + + public function testGetGroupMembership(): void { + $proxy1 = new Proxy(); + $proxy1->setOwnerId('proxyId1'); + $proxy1->setPermissions(1); + + $proxy2 = new Proxy(); + $proxy2->setOwnerId('proxyId2'); + $proxy2->setPermissions(3); + + $this->proxyMapper->expects($this->once()) + ->method('getProxiesFor') + ->with($this->principalPrefix . '/backend1-res1') + ->willReturn([$proxy1, $proxy2]); + + $actual = $this->principalBackend->getGroupMembership($this->principalPrefix . '/backend1-res1'); + + $this->assertEquals(['proxyId1/calendar-proxy-read', 'proxyId2/calendar-proxy-write'], $actual); + } + + public function testSetGroupMemberSet(): void { + $this->proxyMapper->expects($this->once()) + ->method('getProxiesOf') + ->with($this->principalPrefix . '/backend1-res1') + ->willReturn([]); + + $calls = [ + function ($proxy) { + /** @var Proxy $proxy */ + if ($proxy->getOwnerId() !== $this->principalPrefix . '/backend1-res1') { + return false; + } + if ($proxy->getProxyId() !== $this->principalPrefix . '/backend1-res2') { + return false; + } + if ($proxy->getPermissions() !== 3) { + return false; + } + + return true; + }, + function ($proxy) { + /** @var Proxy $proxy */ + if ($proxy->getOwnerId() !== $this->principalPrefix . '/backend1-res1') { + return false; + } + if ($proxy->getProxyId() !== $this->principalPrefix . '/backend2-res3') { + return false; + } + if ($proxy->getPermissions() !== 3) { + return false; + } + + return true; + } + ]; + $this->proxyMapper->expects($this->exactly(2)) + ->method('insert') + ->willReturnCallback(function ($proxy) use (&$calls) { + $expected = array_shift($calls); + $this->assertTrue($expected($proxy)); + return $proxy; + }); + + $this->principalBackend->setGroupMemberSet($this->principalPrefix . '/backend1-res1/calendar-proxy-write', [$this->principalPrefix . '/backend1-res2', $this->principalPrefix . '/backend2-res3']); + } + + public function testUpdatePrincipal(): void { + $propPatch = $this->createMock(PropPatch::class); + $actual = $this->principalBackend->updatePrincipal($this->principalPrefix . '/foo-bar', $propPatch); + + $this->assertEquals(0, $actual); + } + + /** + * @dataProvider dataSearchPrincipals + */ + public function testSearchPrincipals($expected, $test): void { + $user = $this->createMock(IUser::class); + $this->userSession->expects($this->once()) + ->method('getUser') + ->with() + ->willReturn($user); + $this->groupManager->expects($this->once()) + ->method('getUserGroupIds') + ->with($user) + ->willReturn(['group1', 'group2']); + + $actual = $this->principalBackend->searchPrincipals($this->principalPrefix, [ + '{http://sabredav.org/ns}email-address' => 'foo', + '{DAV:}displayname' => 'Beamer', + ], $test); + + $this->assertEquals( + str_replace('%prefix%', $this->principalPrefix, $expected), + $actual); + } + + public static function dataSearchPrincipals(): array { + // data providers are called before we subclass + // this class, $this->principalPrefix is null + // at that point, so we need this hack + return [ + [[ + '%prefix%/backend1-res1', + '%prefix%/backend2-res3', + ], 'allof'], + [[ + '%prefix%/backend1-res1', + '%prefix%/backend1-res2', + '%prefix%/backend2-res3', + '%prefix%/backend2-res4', + '%prefix%/backend3-res6', + ], 'anyof'], + ]; + } + + public function testSearchPrincipalsByMetadataKey(): void { + $user = $this->createMock(IUser::class); + $this->userSession->expects($this->once()) + ->method('getUser') + ->with() + ->willReturn($user); + $this->groupManager->expects($this->once()) + ->method('getUserGroupIds') + ->with($user) + ->willReturn(['group1', 'group2']); + + $actual = $this->principalBackend->searchPrincipals($this->principalPrefix, [ + '{http://nextcloud.com/ns}meta3' => 'value', + ]); + + $this->assertEquals([ + $this->principalPrefix . '/backend2-res4', + ], $actual); + } + + public function testSearchPrincipalsByCalendarUserAddressSet(): void { + $user = $this->createMock(IUser::class); + $this->userSession->method('getUser') + ->with() + ->willReturn($user); + $this->groupManager->method('getUserGroupIds') + ->with($user) + ->willReturn(['group1', 'group2']); + + $actual = $this->principalBackend->searchPrincipals($this->principalPrefix, [ + '{urn:ietf:params:xml:ns:caldav}calendar-user-address-set' => 'res2@foo.bar', + ]); + + $this->assertEquals( + str_replace('%prefix%', $this->principalPrefix, [ + '%prefix%/backend1-res2', + ]), + $actual); + } + + public function testSearchPrincipalsEmptySearchProperties(): void { + $this->userSession->expects($this->never()) + ->method('getUser'); + $this->groupManager->expects($this->never()) + ->method('getUserGroupIds'); + + $this->principalBackend->searchPrincipals($this->principalPrefix, []); + } + + public function testSearchPrincipalsWrongPrincipalPrefix(): void { + $this->userSession->expects($this->never()) + ->method('getUser'); + $this->groupManager->expects($this->never()) + ->method('getUserGroupIds'); + + $this->principalBackend->searchPrincipals('principals/users', [ + '{http://sabredav.org/ns}email-address' => 'foo' + ]); + } + + public function testFindByUriByEmail(): void { + $user = $this->createMock(IUser::class); + $this->userSession->expects($this->once()) + ->method('getUser') + ->with() + ->willReturn($user); + $this->groupManager->expects($this->once()) + ->method('getUserGroupIds') + ->with($user) + ->willReturn(['group1', 'group2']); + + $actual = $this->principalBackend->findByUri('mailto:res1@foo.bar', $this->principalPrefix); + $this->assertEquals($this->principalPrefix . '/backend1-res1', $actual); + } + + public function testFindByUriByEmailForbiddenResource(): void { + $user = $this->createMock(IUser::class); + $this->userSession->expects($this->once()) + ->method('getUser') + ->with() + ->willReturn($user); + $this->groupManager->expects($this->once()) + ->method('getUserGroupIds') + ->with($user) + ->willReturn(['group1', 'group2']); + + $actual = $this->principalBackend->findByUri('mailto:res5@foo.bar', $this->principalPrefix); + $this->assertEquals(null, $actual); + } + + public function testFindByUriByEmailNotFound(): void { + $user = $this->createMock(IUser::class); + $this->userSession->expects($this->once()) + ->method('getUser') + ->with() + ->willReturn($user); + $this->groupManager->expects($this->once()) + ->method('getUserGroupIds') + ->with($user) + ->willReturn(['group1', 'group2']); + + $actual = $this->principalBackend->findByUri('mailto:res99@foo.bar', $this->principalPrefix); + $this->assertEquals(null, $actual); + } + + public function testFindByUriByPrincipal(): void { + $user = $this->createMock(IUser::class); + $this->userSession->expects($this->once()) + ->method('getUser') + ->with() + ->willReturn($user); + $this->groupManager->expects($this->once()) + ->method('getUserGroupIds') + ->with($user) + ->willReturn(['group1', 'group2']); + + $actual = $this->principalBackend->findByUri('mailto:res6@foo.bar', $this->principalPrefix); + $this->assertEquals($this->principalPrefix . '/backend3-res6', $actual); + } + + public function testFindByUriByPrincipalForbiddenResource(): void { + $user = $this->createMock(IUser::class); + $this->userSession->expects($this->once()) + ->method('getUser') + ->with() + ->willReturn($user); + $this->groupManager->expects($this->once()) + ->method('getUserGroupIds') + ->with($user) + ->willReturn(['group1', 'group2']); + + $actual = $this->principalBackend->findByUri('principal:' . $this->principalPrefix . '/backend3-res5', $this->principalPrefix); + $this->assertEquals(null, $actual); + } + + public function testFindByUriByPrincipalNotFound(): void { + $user = $this->createMock(IUser::class); + $this->userSession->expects($this->once()) + ->method('getUser') + ->with() + ->willReturn($user); + $this->groupManager->expects($this->once()) + ->method('getUserGroupIds') + ->with($user) + ->willReturn(['group1', 'group2']); + + $actual = $this->principalBackend->findByUri('principal:' . $this->principalPrefix . '/db-123', $this->principalPrefix); + $this->assertEquals(null, $actual); + } + + public function testFindByUriByUnknownUri(): void { + $user = $this->createMock(IUser::class); + $this->userSession->expects($this->once()) + ->method('getUser') + ->with() + ->willReturn($user); + $this->groupManager->expects($this->once()) + ->method('getUserGroupIds') + ->with($user) + ->willReturn(['group1', 'group2']); + + $actual = $this->principalBackend->findByUri('foobar:blub', $this->principalPrefix); + $this->assertEquals(null, $actual); + } + + protected function createTestDatasetInDb() { + $query = self::$realDatabase->getQueryBuilder(); + $query->insert($this->mainDbTable) + ->values([ + 'backend_id' => $query->createNamedParameter('backend1'), + 'resource_id' => $query->createNamedParameter('res1'), + 'email' => $query->createNamedParameter('res1@foo.bar'), + 'displayname' => $query->createNamedParameter('Beamer1'), + 'group_restrictions' => $query->createNamedParameter('[]'), + ]) + ->execute(); + + $query->insert($this->mainDbTable) + ->values([ + 'backend_id' => $query->createNamedParameter('backend1'), + 'resource_id' => $query->createNamedParameter('res2'), + 'email' => $query->createNamedParameter('res2@foo.bar'), + 'displayname' => $query->createNamedParameter('TV1'), + 'group_restrictions' => $query->createNamedParameter('[]'), + ]) + ->execute(); + + $query->insert($this->mainDbTable) + ->values([ + 'backend_id' => $query->createNamedParameter('backend2'), + 'resource_id' => $query->createNamedParameter('res3'), + 'email' => $query->createNamedParameter('res3@foo.bar'), + 'displayname' => $query->createNamedParameter('Beamer2'), + 'group_restrictions' => $query->createNamedParameter('[]'), + ]) + ->execute(); + $id3 = $query->getLastInsertId(); + + $query->insert($this->mainDbTable) + ->values([ + 'backend_id' => $query->createNamedParameter('backend2'), + 'resource_id' => $query->createNamedParameter('res4'), + 'email' => $query->createNamedParameter('res4@foo.bar'), + 'displayname' => $query->createNamedParameter('TV2'), + 'group_restrictions' => $query->createNamedParameter('[]'), + ]) + ->execute(); + $id4 = $query->getLastInsertId(); + + $query->insert($this->mainDbTable) + ->values([ + 'backend_id' => $query->createNamedParameter('backend3'), + 'resource_id' => $query->createNamedParameter('res5'), + 'email' => $query->createNamedParameter('res5@foo.bar'), + 'displayname' => $query->createNamedParameter('Beamer3'), + 'group_restrictions' => $query->createNamedParameter('["foo", "bar"]'), + ]) + ->execute(); + + $query->insert($this->mainDbTable) + ->values([ + 'backend_id' => $query->createNamedParameter('backend3'), + 'resource_id' => $query->createNamedParameter('res6'), + 'email' => $query->createNamedParameter('res6@foo.bar'), + 'displayname' => $query->createNamedParameter('Pointer'), + 'group_restrictions' => $query->createNamedParameter('["group1", "bar"]'), + ]) + ->execute(); + $id6 = $query->getLastInsertId(); + + $query->insert($this->metadataDbTable) + ->values([ + $this->foreignKey => $query->createNamedParameter($id3), + 'key' => $query->createNamedParameter('{http://nextcloud.com/ns}foo'), + 'value' => $query->createNamedParameter('value1') + ]) + ->execute(); + $query->insert($this->metadataDbTable) + ->values([ + $this->foreignKey => $query->createNamedParameter($id3), + 'key' => $query->createNamedParameter('{http://nextcloud.com/ns}meta2'), + 'value' => $query->createNamedParameter('value2') + ]) + ->execute(); + $query->insert($this->metadataDbTable) + ->values([ + $this->foreignKey => $query->createNamedParameter($id4), + 'key' => $query->createNamedParameter('{http://nextcloud.com/ns}meta1'), + 'value' => $query->createNamedParameter('value1') + ]) + ->execute(); + $query->insert($this->metadataDbTable) + ->values([ + $this->foreignKey => $query->createNamedParameter($id4), + 'key' => $query->createNamedParameter('{http://nextcloud.com/ns}meta3'), + 'value' => $query->createNamedParameter('value3-old') + ]) + ->execute(); + $query->insert($this->metadataDbTable) + ->values([ + $this->foreignKey => $query->createNamedParameter($id6), + 'key' => $query->createNamedParameter('{http://nextcloud.com/ns}meta99'), + 'value' => $query->createNamedParameter('value99') + ]) + ->execute(); + } +} diff --git a/apps/dav/tests/unit/CalDAV/ResourceBooking/ResourcePrincipalBackendTest.php b/apps/dav/tests/unit/CalDAV/ResourceBooking/ResourcePrincipalBackendTest.php index d430afb0b01..168e21c3a91 100644 --- a/apps/dav/tests/unit/CalDAV/ResourceBooking/ResourcePrincipalBackendTest.php +++ b/apps/dav/tests/unit/CalDAV/ResourceBooking/ResourcePrincipalBackendTest.php @@ -1,4 +1,6 @@ mailMessage = $this->createMock(IMessage::class); diff --git a/apps/dav/tests/unit/CalDAV/Schedule/IMipServiceTest.php b/apps/dav/tests/unit/CalDAV/Schedule/IMipServiceTest.php index abf8cfe3177..2be6a1cf8b1 100644 --- a/apps/dav/tests/unit/CalDAV/Schedule/IMipServiceTest.php +++ b/apps/dav/tests/unit/CalDAV/Schedule/IMipServiceTest.php @@ -1,5 +1,6 @@ urlGenerator = $this->createMock(URLGenerator::class); $this->config = $this->createMock(IConfig::class); $this->db = $this->createMock(IDBConnection::class); $this->random = $this->createMock(ISecureRandom::class); - $this->l10nFactory = $this->createMock(L10NFactory::class); - $this->l10n = $this->createMock(LazyL10N::class); + $this->l10nFactory = $this->createMock(IFactory::class); + $this->l10n = $this->createMock(IL10N::class); $this->timeFactory = $this->createMock(ITimeFactory::class); $this->l10nFactory->expects(self::once()) ->method('findGenericLanguage') @@ -170,7 +154,7 @@ class IMipServiceTest extends TestCase { } public function testBuildBodyDataCreated(): void { - + // construct l10n return(s) $this->l10n->method('l')->willReturnCallback( function ($v1, $v2, $v3) { @@ -218,7 +202,7 @@ class IMipServiceTest extends TestCase { } public function testBuildBodyDataUpdate(): void { - + // construct l10n return(s) $this->l10n->method('l')->willReturnCallback( function ($v1, $v2, $v3) { @@ -349,7 +333,7 @@ class IMipServiceTest extends TestCase { } public function testGenerateWhenStringSingular(): void { - + // construct l10n return(s) $this->l10n->method('l')->willReturnCallback( function ($v1, $v2, $v3) { @@ -802,7 +786,7 @@ class IMipServiceTest extends TestCase { 'In 2 months on July 1, 2024 for the entire day', $this->service->generateWhenString($eventReader) ); - + /** test patrial day event in 1 year*/ $vCalendar = clone $this->vCalendar1a; // construct event reader @@ -846,7 +830,7 @@ class IMipServiceTest extends TestCase { } public function testGenerateWhenStringRecurringDaily(): void { - + // construct l10n return maps $this->l10n->method('l')->willReturnCallback( function ($v1, $v2, $v3) { @@ -960,7 +944,7 @@ class IMipServiceTest extends TestCase { } public function testGenerateWhenStringRecurringWeekly(): void { - + // construct l10n return maps $this->l10n->method('l')->willReturnCallback( function ($v1, $v2, $v3) { @@ -1077,7 +1061,7 @@ class IMipServiceTest extends TestCase { } public function testGenerateWhenStringRecurringMonthly(): void { - + // construct l10n return maps $this->l10n->method('l')->willReturnCallback( function ($v1, $v2, $v3) { @@ -1290,7 +1274,7 @@ class IMipServiceTest extends TestCase { } public function testGenerateWhenStringRecurringYearly(): void { - + // construct l10n return maps $this->l10n->method('l')->willReturnCallback( function ($v1, $v2, $v3) { @@ -1504,7 +1488,7 @@ class IMipServiceTest extends TestCase { } public function testGenerateWhenStringRecurringFixed(): void { - + // construct l10n return maps $this->l10n->method('l')->willReturnCallback( function ($v1, $v2, $v3) { @@ -1545,7 +1529,7 @@ class IMipServiceTest extends TestCase { } public function testGenerateOccurringStringWithRrule(): void { - + // construct l10n return(s) $this->l10n->method('l')->willReturnCallback( function ($v1, $v2, $v3) { @@ -1602,7 +1586,7 @@ class IMipServiceTest extends TestCase { 'In 2 days on July 1, 2024 then on July 3, 2024 and July 5, 2024' ], ]); - + // construct time factory return(s) $this->timeFactory->method('getDateTime')->willReturnOnConsecutiveCalls( (new \DateTime('20240629T170000', (new \DateTimeZone('America/Toronto')))), @@ -1687,7 +1671,7 @@ class IMipServiceTest extends TestCase { } public function testGenerateOccurringStringWithRdate(): void { - + // construct l10n return(s) $this->l10n->method('l')->willReturnCallback( function ($v1, $v2, $v3) { @@ -1838,7 +1822,7 @@ class IMipServiceTest extends TestCase { } public function testGenerateOccurringStringWithOneExdate(): void { - + // construct l10n return(s) $this->l10n->method('l')->willReturnCallback( function ($v1, $v2, $v3) { @@ -2022,7 +2006,7 @@ class IMipServiceTest extends TestCase { } public function testGenerateOccurringStringWithTwoExdate(): void { - + // construct l10n return(s) $this->l10n->method('l')->willReturnCallback( function ($v1, $v2, $v3) { diff --git a/apps/dav/tests/unit/CalDAV/Schedule/PluginTest.php b/apps/dav/tests/unit/CalDAV/Schedule/PluginTest.php index f656a0fa33c..5dadb753a79 100644 --- a/apps/dav/tests/unit/CalDAV/Schedule/PluginTest.php +++ b/apps/dav/tests/unit/CalDAV/Schedule/PluginTest.php @@ -1,5 +1,6 @@ calendarValidator = new DefaultCalendarValidator(); $this->server = $this->createMock(Server::class); - $this->server->httpResponse = $this->getMockBuilder(ResponseInterface::class) - ->disableOriginalConstructor() - ->getMock(); + $this->server->httpResponse = $this->createMock(ResponseInterface::class); $this->server->xml = new Service(); $this->plugin = new Plugin($this->config, $this->logger, $this->calendarValidator); @@ -69,23 +58,26 @@ class PluginTest extends TestCase { } public function testInitialize(): void { - - $this->server->expects($this->exactly(10)) + $calls = [ + // Sabre\CalDAV\Schedule\Plugin events + ['method:POST', [$this->plugin, 'httpPost'], 100], + ['propFind', [$this->plugin, 'propFind'], 100], + ['propPatch', [$this->plugin, 'propPatch'], 100], + ['calendarObjectChange', [$this->plugin, 'calendarObjectChange'], 100], + ['beforeUnbind', [$this->plugin, 'beforeUnbind'], 100], + ['schedule', [$this->plugin, 'scheduleLocalDelivery'], 100], + ['getSupportedPrivilegeSet', [$this->plugin, 'getSupportedPrivilegeSet'], 100], + // OCA\DAV\CalDAV\Schedule\Plugin events + ['propFind', [$this->plugin, 'propFindDefaultCalendarUrl'], 90], + ['afterWriteContent', [$this->plugin, 'dispatchSchedulingResponses'], 100], + ['afterCreateFile', [$this->plugin, 'dispatchSchedulingResponses'], 100], + ]; + $this->server->expects($this->exactly(count($calls))) ->method('on') - ->withConsecutive( - // Sabre\CalDAV\Schedule\Plugin events - ['method:POST', [$this->plugin, 'httpPost']], - ['propFind', [$this->plugin, 'propFind']], - ['propPatch', [$this->plugin, 'propPatch']], - ['calendarObjectChange', [$this->plugin, 'calendarObjectChange']], - ['beforeUnbind', [$this->plugin, 'beforeUnbind']], - ['schedule', [$this->plugin, 'scheduleLocalDelivery']], - ['getSupportedPrivilegeSet', [$this->plugin, 'getSupportedPrivilegeSet']], - // OCA\DAV\CalDAV\Schedule\Plugin events - ['propFind', [$this->plugin, 'propFindDefaultCalendarUrl'], 90], - ['afterWriteContent', [$this->plugin, 'dispatchSchedulingResponses']], - ['afterCreateFile', [$this->plugin, 'dispatchSchedulingResponses']] - ); + ->willReturnCallback(function () use (&$calls) { + $expected = array_shift($calls); + $this->assertEquals($expected, func_get_args()); + }); $this->plugin->initialize($this->server); } @@ -168,7 +160,7 @@ class PluginTest extends TestCase { $this->assertFalse($this->invokePrivate($this->plugin, 'getAttendeeRSVP', [$property3])); } - public function propFindDefaultCalendarUrlProvider(): array { + public static function propFindDefaultCalendarUrlProvider(): array { return [ [ 'principals/users/myuser', @@ -270,7 +262,7 @@ class PluginTest extends TestCase { ], 0 ); - /** @var IPrincipal|MockObject $node */ + /** @var IPrincipal&MockObject $node */ $node = $this->getMockBuilder(IPrincipal::class) ->disableOriginalConstructor() ->getMock(); @@ -367,7 +359,7 @@ class PluginTest extends TestCase { } } - /** @var Tree|MockObject $tree */ + /** @var Tree&MockObject $tree */ $tree = $this->createMock(Tree::class); $tree->expects($this->once()) ->method('getNodeForPath') diff --git a/apps/dav/tests/unit/CalDAV/Search/Request/CalendarSearchReportTest.php b/apps/dav/tests/unit/CalDAV/Search/Request/CalendarSearchReportTest.php index cbfd4639ed7..a7ca6eb8945 100644 --- a/apps/dav/tests/unit/CalDAV/Search/Request/CalendarSearchReportTest.php +++ b/apps/dav/tests/unit/CalDAV/Search/Request/CalendarSearchReportTest.php @@ -1,4 +1,6 @@ 'OCA\\DAV\\CalDAV\\Search\\Xml\\Request\\CalendarSearchReport', ]; @@ -112,7 +114,7 @@ XML; ); } - + public function testRequiresCompFilter(): void { $this->expectException(\Sabre\DAV\Exception\BadRequest::class); $this->expectExceptionMessage('{http://nextcloud.com/ns}prop-filter or {http://nextcloud.com/ns}param-filter given without any {http://nextcloud.com/ns}comp-filter'); @@ -139,7 +141,7 @@ XML; $this->parse($xml); } - + public function testRequiresFilter(): void { $this->expectException(\Sabre\DAV\Exception\BadRequest::class); $this->expectExceptionMessage('The {http://nextcloud.com/ns}filter element is required for this request'); @@ -157,7 +159,7 @@ XML; $this->parse($xml); } - + public function testNoSearchTerm(): void { $this->expectException(\Sabre\DAV\Exception\BadRequest::class); $this->expectExceptionMessage('{http://nextcloud.com/ns}search-term is required for this request'); @@ -185,7 +187,7 @@ XML; $this->parse($xml); } - + public function testCompOnly(): void { $this->expectException(\Sabre\DAV\Exception\BadRequest::class); $this->expectExceptionMessage('At least one{http://nextcloud.com/ns}prop-filter or {http://nextcloud.com/ns}param-filter is required for this request'); @@ -313,7 +315,7 @@ XML; ); } - private function parse($xml, array $elementMap = []) { + private function parse(string $xml, array $elementMap = []): array { $reader = new Reader(); $reader->elementMap = array_merge($this->elementMap, $elementMap); $reader->xml($xml); diff --git a/apps/dav/tests/unit/CalDAV/Search/SearchPluginTest.php b/apps/dav/tests/unit/CalDAV/Search/SearchPluginTest.php index 0da971dc36b..e576fbae34c 100644 --- a/apps/dav/tests/unit/CalDAV/Search/SearchPluginTest.php +++ b/apps/dav/tests/unit/CalDAV/Search/SearchPluginTest.php @@ -1,4 +1,6 @@ vCalendar1a; $previousEventInfo = [ @@ -61,7 +63,7 @@ class TipBrokerTest extends TestCase { } public function testParseEventForOrganizerOnModify(): void { - + // construct calendar and generate event info for modified event with one attendee $calendar = clone $this->vCalendar1a; $previousEventInfo = $this->invokePrivate($this->broker, 'parseEventInfo', [$calendar]); @@ -79,7 +81,7 @@ class TipBrokerTest extends TestCase { } public function testParseEventForOrganizerOnDelete(): void { - + // construct calendar and generate event info for modified event with one attendee $calendar = clone $this->vCalendar1a; $previousEventInfo = $this->invokePrivate($this->broker, 'parseEventInfo', [$calendar]); @@ -96,7 +98,7 @@ class TipBrokerTest extends TestCase { } public function testParseEventForOrganizerOnStatusCancelled(): void { - + // construct calendar and generate event info for modified event with one attendee $calendar = clone $this->vCalendar1a; $previousEventInfo = $this->invokePrivate($this->broker, 'parseEventInfo', [$calendar]); @@ -114,7 +116,7 @@ class TipBrokerTest extends TestCase { } public function testParseEventForOrganizerOnAddAttendee(): void { - + // construct calendar and generate event info for modified event with two attendees $calendar = clone $this->vCalendar1a; $previousEventInfo = $this->invokePrivate($this->broker, 'parseEventInfo', [$calendar]); @@ -141,7 +143,7 @@ class TipBrokerTest extends TestCase { } public function testParseEventForOrganizerOnRemoveAttendee(): void { - + // construct calendar and generate event info for modified event with two attendees $calendar = clone $this->vCalendar1a; $calendar->VEVENT->add('ATTENDEE', 'mailto:attendee2@testing.com', [ diff --git a/apps/dav/tests/unit/CalDAV/Validation/CalDavValidatePluginTest.php b/apps/dav/tests/unit/CalDAV/Validation/CalDavValidatePluginTest.php index 0329279af09..74fb4b5e94e 100644 --- a/apps/dav/tests/unit/CalDAV/Validation/CalDavValidatePluginTest.php +++ b/apps/dav/tests/unit/CalDAV/Validation/CalDavValidatePluginTest.php @@ -18,11 +18,11 @@ use Sabre\HTTP\ResponseInterface; use Test\TestCase; class CalDavValidatePluginTest extends TestCase { + private IAppConfig&MockObject $config; + private RequestInterface&MockObject $request; + private ResponseInterface&MockObject $response; private CalDavValidatePlugin $plugin; - private IAppConfig|MockObject $config; - private RequestInterface|MockObject $request; - private ResponseInterface|MockObject $response; protected function setUp(): void { parent::setUp(); @@ -36,7 +36,7 @@ class CalDavValidatePluginTest extends TestCase { } public function testPutSizeLessThenLimit(): void { - + // construct method responses $this->config ->method('getValueInt') @@ -50,11 +50,11 @@ class CalDavValidatePluginTest extends TestCase { $this->assertTrue( $this->plugin->beforePut($this->request, $this->response) ); - + } public function testPutSizeMoreThenLimit(): void { - + // construct method responses $this->config ->method('getValueInt') @@ -67,7 +67,7 @@ class CalDavValidatePluginTest extends TestCase { $this->expectException(Forbidden::class); // test condition $this->plugin->beforePut($this->request, $this->response); - + } } diff --git a/apps/dav/tests/unit/CalDAV/WebcalCaching/ConnectionTest.php b/apps/dav/tests/unit/CalDAV/WebcalCaching/ConnectionTest.php index 5e9caaaeb44..35afc4d7ca7 100644 --- a/apps/dav/tests/unit/CalDAV/WebcalCaching/ConnectionTest.php +++ b/apps/dav/tests/unit/CalDAV/WebcalCaching/ConnectionTest.php @@ -13,7 +13,6 @@ use OCP\Http\Client\IClientService; use OCP\Http\Client\IResponse; use OCP\Http\Client\LocalServerException; use OCP\IAppConfig; -use OCP\IConfig; use PHPUnit\Framework\MockObject\MockObject; use Psr\Log\LoggerInterface; @@ -21,9 +20,9 @@ use Test\TestCase; class ConnectionTest extends TestCase { - private IClientService|MockObject $clientService; - private IConfig|MockObject $config; - private LoggerInterface|MockObject $logger; + private IClientService&MockObject $clientService; + private IAppConfig&MockObject $config; + private LoggerInterface&MockObject $logger; private Connection $connection; public function setUp(): void { diff --git a/apps/dav/tests/unit/CalDAV/WebcalCaching/PluginTest.php b/apps/dav/tests/unit/CalDAV/WebcalCaching/PluginTest.php index 82c03c5cf68..804af021d5a 100644 --- a/apps/dav/tests/unit/CalDAV/WebcalCaching/PluginTest.php +++ b/apps/dav/tests/unit/CalDAV/WebcalCaching/PluginTest.php @@ -1,4 +1,6 @@ refreshSubscription('principals/users/testuser', 'sub123'); } - /** - * @return array - */ - public static function identicalDataProvider():array { + public static function identicalDataProvider(): array { return [ [ '12345', @@ -330,10 +311,7 @@ class RefreshWebcalServiceTest extends TestCase { ]; } - /** - * @return array - */ - public function runDataProvider():array { + public static function runDataProvider(): array { return [ [ "BEGIN:VCALENDAR\r\nVERSION:2.0\r\nPRODID:-//Sabre//Sabre VObject 4.1.1//EN\r\nCALSCALE:GREGORIAN\r\nBEGIN:VEVENT\r\nUID:12345\r\nDTSTAMP:20160218T133704Z\r\nDTSTART;VALUE=DATE:19000101\r\nDTEND;VALUE=DATE:19000102\r\nRRULE:FREQ=YEARLY\r\nSUMMARY:12345's Birthday (1900)\r\nTRANSP:TRANSPARENT\r\nEND:VEVENT\r\nEND:VCALENDAR\r\n", diff --git a/apps/dav/tests/unit/Upload/AssemblyStreamTest.php b/apps/dav/tests/unit/Upload/AssemblyStreamTest.php index 854d02bfc10..e0bc3c589bc 100644 --- a/apps/dav/tests/unit/Upload/AssemblyStreamTest.php +++ b/apps/dav/tests/unit/Upload/AssemblyStreamTest.php @@ -15,7 +15,11 @@ class AssemblyStreamTest extends \Test\TestCase { /** * @dataProvider providesNodes() */ - public function testGetContents($expected, $nodes): void { + public function testGetContents(string $expected, array $nodeData): void { + $nodes = []; + foreach ($nodeData as $data) { + $nodes[] = $this->buildNode(...$data); + } $stream = AssemblyStream::wrap($nodes); $content = stream_get_contents($stream); @@ -25,7 +29,11 @@ class AssemblyStreamTest extends \Test\TestCase { /** * @dataProvider providesNodes() */ - public function testGetContentsFread($expected, $nodes, $chunkLength = 3): void { + public function testGetContentsFread(string $expected, array $nodeData, int $chunkLength = 3): void { + $nodes = []; + foreach ($nodeData as $data) { + $nodes[] = $this->buildNode(...$data); + } $stream = AssemblyStream::wrap($nodes); $content = ''; @@ -43,7 +51,12 @@ class AssemblyStreamTest extends \Test\TestCase { /** * @dataProvider providesNodes() */ - public function testSeek($expected, $nodes): void { + public function testSeek(string $expected, array $nodeData): void { + $nodes = []; + foreach ($nodeData as $data) { + $nodes[] = $this->buildNode(...$data); + } + $stream = AssemblyStream::wrap($nodes); $offset = floor(strlen($expected) * 0.6); @@ -55,75 +68,75 @@ class AssemblyStreamTest extends \Test\TestCase { $this->assertEquals(substr($expected, $offset), $content); } - public function providesNodes() { - $data8k = $this->makeData(8192); - $dataLess8k = $this->makeData(8191); + public static function providesNodes(): array { + $data8k = self::makeData(8192); + $dataLess8k = self::makeData(8191); $tonofnodes = []; $tonofdata = ''; for ($i = 0; $i < 101; $i++) { $thisdata = random_int(0, 100); // variable length and content $tonofdata .= $thisdata; - $tonofnodes[] = $this->buildNode((string)$i, (string)$thisdata); + $tonofnodes[] = [(string)$i, (string)$thisdata]; } return[ 'one node zero bytes' => [ '', [ - $this->buildNode('0', '') + ['0', ''], ]], 'one node only' => [ '1234567890', [ - $this->buildNode('0', '1234567890') + ['0', '1234567890'], ]], 'one node buffer boundary' => [ $data8k, [ - $this->buildNode('0', $data8k) + ['0', $data8k], ]], 'two nodes' => [ '1234567890', [ - $this->buildNode('1', '67890'), - $this->buildNode('0', '12345') + ['1', '67890'], + ['0', '12345'], ]], 'two nodes end on buffer boundary' => [ $data8k . $data8k, [ - $this->buildNode('1', $data8k), - $this->buildNode('0', $data8k) + ['1', $data8k], + ['0', $data8k], ]], 'two nodes with one on buffer boundary' => [ $data8k . $dataLess8k, [ - $this->buildNode('1', $dataLess8k), - $this->buildNode('0', $data8k) + ['1', $dataLess8k], + ['0', $data8k], ]], 'two nodes on buffer boundary plus one byte' => [ $data8k . 'X' . $data8k, [ - $this->buildNode('1', $data8k), - $this->buildNode('0', $data8k . 'X') + ['1', $data8k], + ['0', $data8k . 'X'], ]], 'two nodes on buffer boundary plus one byte at the end' => [ $data8k . $data8k . 'X', [ - $this->buildNode('1', $data8k . 'X'), - $this->buildNode('0', $data8k) + ['1', $data8k . 'X'], + ['0', $data8k], ]], 'a ton of nodes' => [ $tonofdata, $tonofnodes ], 'one read over multiple nodes' => [ '1234567890', [ - $this->buildNode('0', '1234'), - $this->buildNode('1', '5678'), - $this->buildNode('2', '90'), + ['0', '1234'], + ['1', '5678'], + ['2', '90'], ], 10], 'two reads over multiple nodes' => [ '1234567890', [ - $this->buildNode('0', '1234'), - $this->buildNode('1', '5678'), - $this->buildNode('2', '90'), + ['0', '1234'], + ['1', '5678'], + ['2', '90'], ], 5], ]; } - private function makeData($count) { + private static function makeData(int $count): string { $data = ''; $base = '1234567890'; $j = 0; @@ -137,10 +150,10 @@ class AssemblyStreamTest extends \Test\TestCase { return $data; } - private function buildNode($name, $data) { + private function buildNode(string $name, string $data) { $node = $this->getMockBuilder(File::class) - ->setMethods(['getName', 'get', 'getSize']) - ->getMockForAbstractClass(); + ->onlyMethods(['getName', 'get', 'getSize']) + ->getMock(); $node->expects($this->any()) ->method('getName') -- cgit v1.2.3