|
|
|
@ -1,4 +1,5 @@
|
|
|
|
|
<?php
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
/**
|
|
|
|
|
* @copyright Copyright (c) 2019, Thomas Citharel
|
|
|
|
|
*
|
|
|
|
@ -21,12 +22,15 @@
|
|
|
|
|
*/
|
|
|
|
|
namespace OCA\DAV\Tests\unit\CalDAV\Reminder;
|
|
|
|
|
|
|
|
|
|
use OCA\DAV\CalDAV\CalDavBackend;
|
|
|
|
|
use OCA\DAV\CalDAV\Reminder\AbstractNotificationProvider;
|
|
|
|
|
use OCA\DAV\CalDAV\Reminder\Backend;
|
|
|
|
|
use OCA\DAV\CalDAV\Reminder\INotificationProvider;
|
|
|
|
|
use OCA\DAV\CalDAV\Reminder\NotificationProviderManager;
|
|
|
|
|
use OCA\DAV\CalDAV\Reminder\NotificationProvider\EmailProvider;
|
|
|
|
|
use OCA\DAV\CalDAV\Reminder\NotificationProvider\PushProvider;
|
|
|
|
|
use OCA\DAV\CalDAV\Reminder\ReminderService;
|
|
|
|
|
use OCP\AppFramework\Utility\ITimeFactory;
|
|
|
|
|
use OCP\IGroup;
|
|
|
|
|
use OCP\IGroupManager;
|
|
|
|
|
use OCP\IUser;
|
|
|
|
@ -51,6 +55,15 @@ class ReminderServiceTest extends TestCase {
|
|
|
|
|
/** @var IUserSession|\PHPUnit\Framework\MockObject\MockObject */
|
|
|
|
|
private $userSession;
|
|
|
|
|
|
|
|
|
|
/** @var CalDavBackend|\PHPUnit\Framework\MockObject\MockObject */
|
|
|
|
|
private $caldavBackend;
|
|
|
|
|
|
|
|
|
|
/** @var ITimeFactory|\PHPUnit\Framework\MockObject\MockObject */
|
|
|
|
|
private $timeFactory;
|
|
|
|
|
|
|
|
|
|
/** @var ReminderService */
|
|
|
|
|
private $reminderService;
|
|
|
|
|
|
|
|
|
|
public const CALENDAR_DATA = <<<EOD
|
|
|
|
|
BEGIN:VCALENDAR
|
|
|
|
|
PRODID:-//Nextcloud calendar v1.6.4
|
|
|
|
@ -68,6 +81,87 @@ BEGIN:VALARM
|
|
|
|
|
ACTION:EMAIL
|
|
|
|
|
TRIGGER:-PT15M
|
|
|
|
|
END:VALARM
|
|
|
|
|
BEGIN:VALARM
|
|
|
|
|
ACTION:DISPLAY
|
|
|
|
|
TRIGGER;VALUE=DATE-TIME:20160608T000000Z
|
|
|
|
|
END:VALARM
|
|
|
|
|
END:VEVENT
|
|
|
|
|
END:VCALENDAR
|
|
|
|
|
EOD;
|
|
|
|
|
|
|
|
|
|
public const CALENDAR_DATA_REPEAT = <<<EOD
|
|
|
|
|
BEGIN:VCALENDAR
|
|
|
|
|
PRODID:-//Nextcloud calendar v1.6.4
|
|
|
|
|
BEGIN:VEVENT
|
|
|
|
|
CREATED:20160602T133732
|
|
|
|
|
DTSTAMP:20160602T133732
|
|
|
|
|
LAST-MODIFIED:20160602T133732
|
|
|
|
|
UID:wej2z68l9h
|
|
|
|
|
SUMMARY:Test Event
|
|
|
|
|
LOCATION:Somewhere ...
|
|
|
|
|
DESCRIPTION:maybe ....
|
|
|
|
|
DTSTART;TZID=Europe/Berlin;VALUE=DATE:20160609
|
|
|
|
|
DTEND;TZID=Europe/Berlin;VALUE=DATE:20160610
|
|
|
|
|
BEGIN:VALARM
|
|
|
|
|
ACTION:EMAIL
|
|
|
|
|
TRIGGER:-PT15M
|
|
|
|
|
REPEAT:4
|
|
|
|
|
DURATION:PT2M
|
|
|
|
|
END:VALARM
|
|
|
|
|
END:VEVENT
|
|
|
|
|
END:VCALENDAR
|
|
|
|
|
EOD;
|
|
|
|
|
|
|
|
|
|
public const CALENDAR_DATA_RECURRING = <<<EOD
|
|
|
|
|
BEGIN:VCALENDAR
|
|
|
|
|
PRODID:-//Nextcloud calendar v1.6.4
|
|
|
|
|
BEGIN:VEVENT
|
|
|
|
|
CREATED:20160602T133732
|
|
|
|
|
DTSTAMP:20160602T133732
|
|
|
|
|
LAST-MODIFIED:20160602T133732
|
|
|
|
|
UID:wej2z68l9h
|
|
|
|
|
SUMMARY:Test Event
|
|
|
|
|
LOCATION:Somewhere ...
|
|
|
|
|
DESCRIPTION:maybe ....
|
|
|
|
|
DTSTART;TZID=Europe/Berlin;VALUE=DATE:20160609
|
|
|
|
|
DTEND;TZID=Europe/Berlin;VALUE=DATE:20160610
|
|
|
|
|
RRULE:FREQ=WEEKLY
|
|
|
|
|
BEGIN:VALARM
|
|
|
|
|
ACTION:EMAIL
|
|
|
|
|
TRIGGER:-PT15M
|
|
|
|
|
END:VALARM
|
|
|
|
|
BEGIN:VALARM
|
|
|
|
|
ACTION:EMAIL
|
|
|
|
|
TRIGGER:-P8D
|
|
|
|
|
END:VALARM
|
|
|
|
|
END:VEVENT
|
|
|
|
|
END:VCALENDAR
|
|
|
|
|
EOD;
|
|
|
|
|
|
|
|
|
|
public const CALENDAR_DATA_RECURRING_REPEAT = <<<EOD
|
|
|
|
|
BEGIN:VCALENDAR
|
|
|
|
|
PRODID:-//Nextcloud calendar v1.6.4
|
|
|
|
|
BEGIN:VEVENT
|
|
|
|
|
CREATED:20160602T133732
|
|
|
|
|
DTSTAMP:20160602T133732
|
|
|
|
|
LAST-MODIFIED:20160602T133732
|
|
|
|
|
UID:wej2z68l9h
|
|
|
|
|
SUMMARY:Test Event
|
|
|
|
|
LOCATION:Somewhere ...
|
|
|
|
|
DESCRIPTION:maybe ....
|
|
|
|
|
DTSTART;TZID=Europe/Berlin;VALUE=DATE:20160609
|
|
|
|
|
DTEND;TZID=Europe/Berlin;VALUE=DATE:20160610
|
|
|
|
|
RRULE:FREQ=WEEKLY
|
|
|
|
|
BEGIN:VALARM
|
|
|
|
|
ACTION:EMAIL
|
|
|
|
|
TRIGGER:-PT15M
|
|
|
|
|
REPEAT:4
|
|
|
|
|
DURATION:PT2M
|
|
|
|
|
END:VALARM
|
|
|
|
|
BEGIN:VALARM
|
|
|
|
|
ACTION:EMAIL
|
|
|
|
|
TRIGGER:-P8D
|
|
|
|
|
END:VALARM
|
|
|
|
|
END:VEVENT
|
|
|
|
|
END:VCALENDAR
|
|
|
|
|
EOD;
|
|
|
|
@ -79,198 +173,383 @@ EOD;
|
|
|
|
|
$this->notificationProviderManager = $this->createMock(NotificationProviderManager::class);
|
|
|
|
|
$this->userManager = $this->createMock(IUserManager::class);
|
|
|
|
|
$this->groupManager = $this->createMock(IGroupManager::class);
|
|
|
|
|
$this->userSession = $this->createMock(IUserSession::class);
|
|
|
|
|
}
|
|
|
|
|
$this->caldavBackend = $this->createMock(CalDavBackend::class);
|
|
|
|
|
$this->timeFactory = $this->createMock(ITimeFactory::class);
|
|
|
|
|
|
|
|
|
|
public function dataTestProcessReminders(): array
|
|
|
|
|
{
|
|
|
|
|
return [
|
|
|
|
|
[
|
|
|
|
|
[], null
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
[
|
|
|
|
|
[
|
|
|
|
|
'calendardata' => self::CALENDAR_DATA,
|
|
|
|
|
'displayname' => 'Personal',
|
|
|
|
|
'type' => 'EMAIL',
|
|
|
|
|
'uid' => 1,
|
|
|
|
|
'id' => 1,
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
$this->createMock(EmailProvider::class),
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
[
|
|
|
|
|
[
|
|
|
|
|
'calendardata' => self::CALENDAR_DATA,
|
|
|
|
|
'displayname' => 'Personal',
|
|
|
|
|
'type' => 'DISPLAY',
|
|
|
|
|
'uid' => 1,
|
|
|
|
|
'id' => 1,
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
$this->createMock(PushProvider::class),
|
|
|
|
|
]
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
$this->caldavBackend->method('getShares')->willReturn([]);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @dataProvider dataTestProcessReminders
|
|
|
|
|
* @param array $reminders
|
|
|
|
|
* @param AbstractNotificationProvider|null $notificationProvider
|
|
|
|
|
* @throws \OCA\DAV\CalDAV\Reminder\NotificationProvider\ProviderNotAvailableException
|
|
|
|
|
* @throws \OCA\DAV\CalDAV\Reminder\NotificationTypeDoesNotExistException
|
|
|
|
|
* @throws \OC\User\NoUserException
|
|
|
|
|
*/
|
|
|
|
|
public function testProcessReminders(array $reminders, ?AbstractNotificationProvider $notificationProvider): void
|
|
|
|
|
{
|
|
|
|
|
$user = $this->createMock(IUser::class);
|
|
|
|
|
|
|
|
|
|
$this->backend->expects($this->once())->method('getRemindersToProcess')->willReturn($reminders);
|
|
|
|
|
if (count($reminders) > 0) {
|
|
|
|
|
$this->userManager->expects($this->exactly(count($reminders)))->method('get')->willReturn($user);
|
|
|
|
|
$this->backend->expects($this->exactly(count($reminders)))->method('removeReminder');
|
|
|
|
|
$this->notificationProviderManager->expects($this->exactly(count($reminders)))->method('getProvider')->willReturn($notificationProvider);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$reminderService = new ReminderService($this->backend, $this->notificationProviderManager, $this->userManager, $this->groupManager, $this->userSession);
|
|
|
|
|
$reminderService->processReminders();
|
|
|
|
|
$this->reminderService = new ReminderService($this->backend,
|
|
|
|
|
$this->notificationProviderManager,
|
|
|
|
|
$this->userManager,
|
|
|
|
|
$this->groupManager,
|
|
|
|
|
$this->caldavBackend,
|
|
|
|
|
$this->timeFactory);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @expectedException OC\User\NoUserException
|
|
|
|
|
*/
|
|
|
|
|
public function testProcessReminderWithBadUser(): void
|
|
|
|
|
{
|
|
|
|
|
$this->backend->expects($this->once())->method('getRemindersToProcess')->willReturn([
|
|
|
|
|
[
|
|
|
|
|
'calendardata' => self::CALENDAR_DATA,
|
|
|
|
|
'type' => 'DISPLAY',
|
|
|
|
|
'uid' => 1,
|
|
|
|
|
'id' => 1,
|
|
|
|
|
]
|
|
|
|
|
]);
|
|
|
|
|
$this->userManager->expects($this->once())->method('get')->with(1)->willReturn(null);
|
|
|
|
|
$reminderService = new ReminderService($this->backend, $this->notificationProviderManager, $this->userManager, $this->groupManager, $this->userSession);
|
|
|
|
|
$reminderService->processReminders();
|
|
|
|
|
public function testOnCalendarObjectDelete():void {
|
|
|
|
|
$this->backend->expects($this->once())
|
|
|
|
|
->method('cleanRemindersForEvent')
|
|
|
|
|
->with(44);
|
|
|
|
|
|
|
|
|
|
$action = '\OCA\DAV\CalDAV\CalDavBackend::deleteCalendarObject';
|
|
|
|
|
$objectData = [
|
|
|
|
|
'id' => '44',
|
|
|
|
|
'component' => 'vevent',
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
$this->reminderService->onTouchCalendarObject($action, $objectData);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function providesTouchCalendarObject(): array
|
|
|
|
|
{
|
|
|
|
|
return [
|
|
|
|
|
[
|
|
|
|
|
'\OCA\DAV\CalDAV\CalDavBackend::deleteCalendarObject',
|
|
|
|
|
[
|
|
|
|
|
'principaluri' => 'principals/users/personal'
|
|
|
|
|
],
|
|
|
|
|
[],
|
|
|
|
|
[
|
|
|
|
|
'calendarid' => 1,
|
|
|
|
|
'uri' => 'something.ics',
|
|
|
|
|
],
|
|
|
|
|
0
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
'\OCA\DAV\CalDAV\CalDavBackend::createCalendarObject',
|
|
|
|
|
[
|
|
|
|
|
'principaluri' => 'principals/users/personal'
|
|
|
|
|
],
|
|
|
|
|
[],
|
|
|
|
|
[
|
|
|
|
|
'calendarid' => 1,
|
|
|
|
|
'uri' => 'something.ics',
|
|
|
|
|
'calendardata' => self::CALENDAR_DATA
|
|
|
|
|
],
|
|
|
|
|
0
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
'\OCA\DAV\CalDAV\CalDavBackend::updateCalendarObject',
|
|
|
|
|
[
|
|
|
|
|
'principaluri' => 'principals/users/someone',
|
|
|
|
|
'uri' => 'personal'
|
|
|
|
|
],
|
|
|
|
|
public function testOnCalendarObjectCreateSingleEntry():void {
|
|
|
|
|
$action = '\OCA\DAV\CalDAV\CalDavBackend::createCalendarObject';
|
|
|
|
|
$objectData = [
|
|
|
|
|
'calendardata' => self::CALENDAR_DATA,
|
|
|
|
|
'id' => '42',
|
|
|
|
|
'calendarid' => '1337',
|
|
|
|
|
'component' => 'vevent',
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
$this->backend->expects($this->exactly(2))
|
|
|
|
|
->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);
|
|
|
|
|
|
|
|
|
|
$this->timeFactory->expects($this->once())
|
|
|
|
|
->method('getDateTime')
|
|
|
|
|
->with()
|
|
|
|
|
->willReturn(\DateTime::createFromFormat(\DateTime::ATOM, '2016-06-08T00:00:00+00:00'));
|
|
|
|
|
|
|
|
|
|
$this->reminderService->onTouchCalendarObject($action, $objectData);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testOnCalendarObjectCreateSingleEntryWithRepeat(): void {
|
|
|
|
|
$action = '\OCA\DAV\CalDAV\CalDavBackend::createCalendarObject';
|
|
|
|
|
$objectData = [
|
|
|
|
|
'calendardata' => self::CALENDAR_DATA_REPEAT,
|
|
|
|
|
'id' => '42',
|
|
|
|
|
'calendarid' => '1337',
|
|
|
|
|
'component' => 'vevent',
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
$this->backend->expects($this->exactly(5))
|
|
|
|
|
->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);
|
|
|
|
|
|
|
|
|
|
$this->timeFactory->expects($this->once())
|
|
|
|
|
->method('getDateTime')
|
|
|
|
|
->with()
|
|
|
|
|
->willReturn(\DateTime::createFromFormat(\DateTime::ATOM, '2016-06-08T00:00:00+00:00'));
|
|
|
|
|
|
|
|
|
|
$this->reminderService->onTouchCalendarObject($action, $objectData);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testOnCalendarObjectCreateRecurringEntry(): void {
|
|
|
|
|
$action = '\OCA\DAV\CalDAV\CalDavBackend::createCalendarObject';
|
|
|
|
|
$objectData = [
|
|
|
|
|
'calendardata' => self::CALENDAR_DATA_RECURRING,
|
|
|
|
|
'id' => '42',
|
|
|
|
|
'calendarid' => '1337',
|
|
|
|
|
'component' => 'vevent',
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
$this->backend->expects($this->exactly(2))
|
|
|
|
|
->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);
|
|
|
|
|
|
|
|
|
|
$this->timeFactory->expects($this->once())
|
|
|
|
|
->method('getDateTime')
|
|
|
|
|
->with()
|
|
|
|
|
->willReturn(\DateTime::createFromFormat(\DateTime::ATOM, '2016-06-29T00:00:00+00:00'));
|
|
|
|
|
|
|
|
|
|
$this->reminderService->onTouchCalendarObject($action, $objectData);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testOnCalendarObjectCreateRecurringEntryWithRepeat():void {
|
|
|
|
|
$action = '\OCA\DAV\CalDAV\CalDavBackend::createCalendarObject';
|
|
|
|
|
$objectData = [
|
|
|
|
|
'calendardata' => self::CALENDAR_DATA_RECURRING_REPEAT,
|
|
|
|
|
'id' => '42',
|
|
|
|
|
'calendarid' => '1337',
|
|
|
|
|
'component' => 'vevent',
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
$this->backend->expects($this->exactly(6))
|
|
|
|
|
->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);
|
|
|
|
|
|
|
|
|
|
$this->timeFactory->expects($this->once())
|
|
|
|
|
->method('getDateTime')
|
|
|
|
|
->with()
|
|
|
|
|
->willReturn(\DateTime::createFromFormat(\DateTime::ATOM, '2016-06-29T00:00:00+00:00'));
|
|
|
|
|
|
|
|
|
|
$this->reminderService->onTouchCalendarObject($action, $objectData);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testProcessReminders():void {
|
|
|
|
|
$this->backend->expects($this->at(0))
|
|
|
|
|
->method('getRemindersToProcess')
|
|
|
|
|
->with()
|
|
|
|
|
->willReturn([
|
|
|
|
|
[
|
|
|
|
|
[
|
|
|
|
|
'{http://owncloud.org/ns}principal' => 'principals/users/someone'
|
|
|
|
|
]
|
|
|
|
|
'id' => 1,
|
|
|
|
|
'calendar_id' => 1337,
|
|
|
|
|
'object_id' => 42,
|
|
|
|
|
'uid' => 'wej2z68l9h',
|
|
|
|
|
'is_recurring' => false,
|
|
|
|
|
'recurrence_id' => 1465430400,
|
|
|
|
|
'is_recurrence_exception' => false,
|
|
|
|
|
'event_hash' => '5c70531aab15c92b52518ae10a2f78a4',
|
|
|
|
|
'alarm_hash' => 'de919af7429d3b5c11e8b9d289b411a6',
|
|
|
|
|
'type' => 'EMAIL',
|
|
|
|
|
'is_relative' => true,
|
|
|
|
|
'notification_date' => 1465429500,
|
|
|
|
|
'is_repeat_based' => false,
|
|
|
|
|
'calendardata' => self::CALENDAR_DATA,
|
|
|
|
|
'displayname' => 'Displayname 123',
|
|
|
|
|
'principaluri' => 'principals/users/user001',
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
'calendarid' => 1,
|
|
|
|
|
'uri' => 'something.ics',
|
|
|
|
|
'calendardata' => self::CALENDAR_DATA
|
|
|
|
|
'id' => 2,
|
|
|
|
|
'calendar_id' => 1337,
|
|
|
|
|
'object_id' => 42,
|
|
|
|
|
'uid' => 'wej2z68l9h',
|
|
|
|
|
'is_recurring' => false,
|
|
|
|
|
'recurrence_id' => 1465430400,
|
|
|
|
|
'is_recurrence_exception' => false,
|
|
|
|
|
'event_hash' => '5c70531aab15c92b52518ae10a2f78a4',
|
|
|
|
|
'alarm_hash' => 'ecacbf07d413c3c78d1ac7ad8c469602',
|
|
|
|
|
'type' => 'EMAIL',
|
|
|
|
|
'is_relative' => true,
|
|
|
|
|
'notification_date' => 1465429740,
|
|
|
|
|
'is_repeat_based' => true,
|
|
|
|
|
'calendardata' => self::CALENDAR_DATA_REPEAT,
|
|
|
|
|
'displayname' => 'Displayname 123',
|
|
|
|
|
'principaluri' => 'principals/users/user001',
|
|
|
|
|
],
|
|
|
|
|
0
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
'\OCA\DAV\CalDAV\CalDavBackend::createCalendarObject',
|
|
|
|
|
[
|
|
|
|
|
'principaluri' => 'principals/users/someone',
|
|
|
|
|
'uri' => 'personal'
|
|
|
|
|
'id' => 3,
|
|
|
|
|
'calendar_id' => 1337,
|
|
|
|
|
'object_id' => 42,
|
|
|
|
|
'uid' => 'wej2z68l9h',
|
|
|
|
|
'is_recurring' => false,
|
|
|
|
|
'recurrence_id' => 1465430400,
|
|
|
|
|
'is_recurrence_exception' => false,
|
|
|
|
|
'event_hash' => '5c70531aab15c92b52518ae10a2f78a4',
|
|
|
|
|
'alarm_hash' => '35b3eae8e792aa2209f0b4e1a302f105',
|
|
|
|
|
'type' => 'DISPLAY',
|
|
|
|
|
'is_relative' => false,
|
|
|
|
|
'notification_date' => 1465344000,
|
|
|
|
|
'is_repeat_based' => false,
|
|
|
|
|
'calendardata' => self::CALENDAR_DATA,
|
|
|
|
|
'displayname' => 'Displayname 123',
|
|
|
|
|
'principaluri' => 'principals/users/user001',
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
[
|
|
|
|
|
'{http://owncloud.org/ns}principal' => 'principals/groups/somegroup'
|
|
|
|
|
]
|
|
|
|
|
'id' => 4,
|
|
|
|
|
'calendar_id' => 1337,
|
|
|
|
|
'object_id' => 42,
|
|
|
|
|
'uid' => 'wej2z68l9h',
|
|
|
|
|
'is_recurring' => true,
|
|
|
|
|
'recurrence_id' => 1467244800,
|
|
|
|
|
'is_recurrence_exception' => false,
|
|
|
|
|
'event_hash' => 'fbdb2726bc0f7dfacac1d881c1453e20',
|
|
|
|
|
'alarm_hash' => 'ecacbf07d413c3c78d1ac7ad8c469602',
|
|
|
|
|
'type' => 'EMAIL',
|
|
|
|
|
'is_relative' => true,
|
|
|
|
|
'notification_date' => 1467243900,
|
|
|
|
|
'is_repeat_based' => false,
|
|
|
|
|
'calendardata' => self::CALENDAR_DATA_RECURRING_REPEAT,
|
|
|
|
|
'displayname' => 'Displayname 123',
|
|
|
|
|
'principaluri' => 'principals/users/user001',
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
'calendarid' => 1,
|
|
|
|
|
'uri' => 'something.ics',
|
|
|
|
|
'calendardata' => self::CALENDAR_DATA
|
|
|
|
|
],
|
|
|
|
|
1
|
|
|
|
|
]
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
'id' => 5,
|
|
|
|
|
'calendar_id' => 1337,
|
|
|
|
|
'object_id' => 42,
|
|
|
|
|
'uid' => 'wej2z68l9h',
|
|
|
|
|
'is_recurring' => true,
|
|
|
|
|
'recurrence_id' => 1467849600,
|
|
|
|
|
'is_recurrence_exception' => false,
|
|
|
|
|
'event_hash' => 'fbdb2726bc0f7dfacac1d881c1453e20',
|
|
|
|
|
'alarm_hash' => '8996992118817f9f311ac5cc56d1cc97',
|
|
|
|
|
'type' => 'EMAIL',
|
|
|
|
|
'is_relative' => true,
|
|
|
|
|
'notification_date' => 1467158400,
|
|
|
|
|
'is_repeat_based' => false,
|
|
|
|
|
'calendardata' => self::CALENDAR_DATA_RECURRING,
|
|
|
|
|
'displayname' => 'Displayname 123',
|
|
|
|
|
'principaluri' => 'principals/users/user001',
|
|
|
|
|
]
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @dataProvider providesTouchCalendarObject
|
|
|
|
|
* @param string $action
|
|
|
|
|
* @param array $calendarData
|
|
|
|
|
* @param array $shares
|
|
|
|
|
* @param array $objectData
|
|
|
|
|
* @param int $numberOfGroups
|
|
|
|
|
* @throws \OC\User\NoUserException
|
|
|
|
|
* @throws \Sabre\VObject\InvalidDataException
|
|
|
|
|
*/
|
|
|
|
|
public function testOnTouchCalendarObject(string $action, array $calendarData, array $shares, array $objectData, int $numberOfGroups): void
|
|
|
|
|
{
|
|
|
|
|
$this->backend->expects($this->once())->method('cleanRemindersForEvent')->with($objectData['calendarid'], $objectData['uri']);
|
|
|
|
|
|
|
|
|
|
if ($action !== '\OCA\DAV\CalDAV\CalDavBackend::deleteCalendarObject') {
|
|
|
|
|
$user = $this->createMock(IUser::class);
|
|
|
|
|
$user->expects($this->once())->method('getUID')->willReturn('user');
|
|
|
|
|
|
|
|
|
|
$this->userSession->expects($this->once())->method('getUser')->willReturn($user);
|
|
|
|
|
if ($numberOfGroups === 0) {
|
|
|
|
|
$this->backend->expects($this->exactly(count($shares) + 1))->method('insertReminder');
|
|
|
|
|
} else {
|
|
|
|
|
$group = $this->createMock(IGroup::class);
|
|
|
|
|
$groupUser = $this->createMock(IUser::class);
|
|
|
|
|
$groupUser->expects($this->once())->method('getUID')->willReturn('groupuser');
|
|
|
|
|
$group->expects($this->once())->method('getUsers')->willReturn([$groupUser]);
|
|
|
|
|
$this->groupManager->expects($this->exactly($numberOfGroups))->method('get')->willReturn($group);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
$reminderService = new ReminderService($this->backend, $this->notificationProviderManager, $this->userManager, $this->groupManager, $this->userSession);
|
|
|
|
|
$reminderService->onTouchCalendarObject($action, $calendarData, $shares, $objectData);
|
|
|
|
|
}
|
|
|
|
|
$this->notificationProviderManager->expects($this->at(0))
|
|
|
|
|
->method('hasProvider')
|
|
|
|
|
->with('EMAIL')
|
|
|
|
|
->willReturn(true);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @expectedException OC\User\NoUserException
|
|
|
|
|
*/
|
|
|
|
|
public function testOnTouchCalendarObjectWithNoSession(): void
|
|
|
|
|
{
|
|
|
|
|
$this->backend->expects($this->once())->method('cleanRemindersForEvent');
|
|
|
|
|
$this->userSession->expects($this->once())->method('getUser')->willReturn(null);
|
|
|
|
|
$provider1 = $this->createMock(INotificationProvider::class);
|
|
|
|
|
$this->notificationProviderManager->expects($this->at(1))
|
|
|
|
|
->method('getProvider')
|
|
|
|
|
->with('EMAIL')
|
|
|
|
|
->willReturn($provider1);
|
|
|
|
|
|
|
|
|
|
$reminderService = new ReminderService($this->backend, $this->notificationProviderManager, $this->userManager, $this->groupManager, $this->userSession);
|
|
|
|
|
$reminderService->onTouchCalendarObject('', ['principaluri' => 'foo'], [], ['calendarid' => 1, 'uri' => 'bar']);
|
|
|
|
|
}
|
|
|
|
|
$this->notificationProviderManager->expects($this->at(2))
|
|
|
|
|
->method('hasProvider')
|
|
|
|
|
->with('EMAIL')
|
|
|
|
|
->willReturn(true);
|
|
|
|
|
|
|
|
|
|
$provider2 = $this->createMock(INotificationProvider::class);
|
|
|
|
|
$this->notificationProviderManager->expects($this->at(3))
|
|
|
|
|
->method('getProvider')
|
|
|
|
|
->with('EMAIL')
|
|
|
|
|
->willReturn($provider2);
|
|
|
|
|
|
|
|
|
|
$this->notificationProviderManager->expects($this->at(4))
|
|
|
|
|
->method('hasProvider')
|
|
|
|
|
->with('DISPLAY')
|
|
|
|
|
->willReturn(true);
|
|
|
|
|
|
|
|
|
|
$provider3 = $this->createMock(INotificationProvider::class);
|
|
|
|
|
$this->notificationProviderManager->expects($this->at(5))
|
|
|
|
|
->method('getProvider')
|
|
|
|
|
->with('DISPLAY')
|
|
|
|
|
->willReturn($provider3);
|
|
|
|
|
|
|
|
|
|
$this->notificationProviderManager->expects($this->at(6))
|
|
|
|
|
->method('hasProvider')
|
|
|
|
|
->with('EMAIL')
|
|
|
|
|
->willReturn(true);
|
|
|
|
|
|
|
|
|
|
$provider4 = $this->createMock(INotificationProvider::class);
|
|
|
|
|
$this->notificationProviderManager->expects($this->at(7))
|
|
|
|
|
->method('getProvider')
|
|
|
|
|
->with('EMAIL')
|
|
|
|
|
->willReturn($provider4);
|
|
|
|
|
|
|
|
|
|
$this->notificationProviderManager->expects($this->at(8))
|
|
|
|
|
->method('hasProvider')
|
|
|
|
|
->with('EMAIL')
|
|
|
|
|
->willReturn(true);
|
|
|
|
|
|
|
|
|
|
$provider5 = $this->createMock(INotificationProvider::class);
|
|
|
|
|
$this->notificationProviderManager->expects($this->at(9))
|
|
|
|
|
->method('getProvider')
|
|
|
|
|
->with('EMAIL')
|
|
|
|
|
->willReturn($provider5);
|
|
|
|
|
|
|
|
|
|
$user = $this->createMock(IUser::class);
|
|
|
|
|
$this->userManager->expects($this->exactly(5))
|
|
|
|
|
->method('get')
|
|
|
|
|
->with('user001')
|
|
|
|
|
->willReturn($user);
|
|
|
|
|
|
|
|
|
|
$provider1->expects($this->once())
|
|
|
|
|
->method('send')
|
|
|
|
|
->with($this->callback(function($vevent) {
|
|
|
|
|
if ($vevent->DTSTART->getDateTime()->format(\DateTime::ATOM) !== '2016-06-09T00:00:00+00:00') {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}, 'Displayname 123', $user));
|
|
|
|
|
$provider2->expects($this->once())
|
|
|
|
|
->method('send')
|
|
|
|
|
->with($this->callback(function($vevent) {
|
|
|
|
|
if ($vevent->DTSTART->getDateTime()->format(\DateTime::ATOM) !== '2016-06-09T00:00:00+00:00') {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}, 'Displayname 123', $user));
|
|
|
|
|
$provider3->expects($this->once())
|
|
|
|
|
->method('send')
|
|
|
|
|
->with($this->callback(function($vevent) {
|
|
|
|
|
if ($vevent->DTSTART->getDateTime()->format(\DateTime::ATOM) !== '2016-06-09T00:00:00+00:00') {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}, 'Displayname 123', $user));
|
|
|
|
|
$provider4->expects($this->once())
|
|
|
|
|
->method('send')
|
|
|
|
|
->with($this->callback(function($vevent) {
|
|
|
|
|
if ($vevent->DTSTART->getDateTime()->format(\DateTime::ATOM) !== '2016-06-30T00:00:00+00:00') {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}, 'Displayname 123', $user));
|
|
|
|
|
$provider5->expects($this->once())
|
|
|
|
|
->method('send')
|
|
|
|
|
->with($this->callback(function($vevent) {
|
|
|
|
|
if ($vevent->DTSTART->getDateTime()->format(\DateTime::ATOM) !== '2016-07-07T00:00:00+00:00') {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}, 'Displayname 123', $user));
|
|
|
|
|
|
|
|
|
|
$this->backend->expects($this->at(1))
|
|
|
|
|
->method('removeReminder')
|
|
|
|
|
->with(1);
|
|
|
|
|
$this->backend->expects($this->at(2))
|
|
|
|
|
->method('removeReminder')
|
|
|
|
|
->with(2);
|
|
|
|
|
$this->backend->expects($this->at(3))
|
|
|
|
|
->method('removeReminder')
|
|
|
|
|
->with(3);
|
|
|
|
|
$this->backend->expects($this->at(4))
|
|
|
|
|
->method('removeReminder')
|
|
|
|
|
->with(4);
|
|
|
|
|
$this->backend->expects($this->at(5))
|
|
|
|
|
->method('insertReminder')
|
|
|
|
|
->with(1337, 42, 'wej2z68l9h', true, 1467849600, false, 'fbdb2726bc0f7dfacac1d881c1453e20', 'ecacbf07d413c3c78d1ac7ad8c469602', 'EMAIL', true, 1467848700, false)
|
|
|
|
|
->willReturn(99);
|
|
|
|
|
|
|
|
|
|
$this->backend->expects($this->at(6))
|
|
|
|
|
->method('insertReminder')
|
|
|
|
|
->with(1337, 42, 'wej2z68l9h', true, 1467849600, false, 'fbdb2726bc0f7dfacac1d881c1453e20', 'ecacbf07d413c3c78d1ac7ad8c469602', 'EMAIL', true, 1467848820, true)
|
|
|
|
|
->willReturn(99);
|
|
|
|
|
$this->backend->expects($this->at(7))
|
|
|
|
|
->method('insertReminder')
|
|
|
|
|
->with(1337, 42, 'wej2z68l9h', true, 1467849600, false, 'fbdb2726bc0f7dfacac1d881c1453e20', 'ecacbf07d413c3c78d1ac7ad8c469602', 'EMAIL', true, 1467848940, true)
|
|
|
|
|
->willReturn(99);
|
|
|
|
|
$this->backend->expects($this->at(8))
|
|
|
|
|
->method('insertReminder')
|
|
|
|
|
->with(1337, 42, 'wej2z68l9h', true, 1467849600, false, 'fbdb2726bc0f7dfacac1d881c1453e20', 'ecacbf07d413c3c78d1ac7ad8c469602', 'EMAIL', true, 1467849060, true)
|
|
|
|
|
->willReturn(99);
|
|
|
|
|
$this->backend->expects($this->at(9))
|
|
|
|
|
->method('insertReminder')
|
|
|
|
|
->with(1337, 42, 'wej2z68l9h', true, 1467849600, false, 'fbdb2726bc0f7dfacac1d881c1453e20', 'ecacbf07d413c3c78d1ac7ad8c469602', 'EMAIL', true, 1467849180, true)
|
|
|
|
|
->willReturn(99);
|
|
|
|
|
$this->backend->expects($this->at(10))
|
|
|
|
|
->method('removeReminder')
|
|
|
|
|
->with(5);
|
|
|
|
|
$this->backend->expects($this->at(11))
|
|
|
|
|
->method('insertReminder')
|
|
|
|
|
->with(1337, 42, 'wej2z68l9h', true, 1468454400, false, 'fbdb2726bc0f7dfacac1d881c1453e20', '8996992118817f9f311ac5cc56d1cc97', 'EMAIL', true, 1467763200, false)
|
|
|
|
|
->willReturn(99);
|
|
|
|
|
|
|
|
|
|
$this->timeFactory->method('getDateTime')
|
|
|
|
|
->willReturn(\DateTime::createFromFormat(\DateTime::ATOM, '2016-06-08T00:00:00+00:00'));
|
|
|
|
|
|
|
|
|
|
public function testOnTouchCalendarObjectWithNoCalendarURI(): void
|
|
|
|
|
{
|
|
|
|
|
$reminderService = new ReminderService($this->backend, $this->notificationProviderManager, $this->userManager, $this->groupManager, $this->userSession);
|
|
|
|
|
$this->assertNull($reminderService->onTouchCalendarObject('', [], [], []));
|
|
|
|
|
$this->reminderService->processReminders();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|