Final fixes

Signed-off-by: Georg Ehrke <developer@georgehrke.com>
This commit is contained in:
Georg Ehrke 2019-08-12 13:20:03 +02:00 committed by Roeland Jago Douma
parent 2d6473e79b
commit 4d28a4544e
No known key found for this signature in database
GPG Key ID: F941078878347C0C
19 changed files with 1625 additions and 834 deletions

@ -1 +1 @@
Subproject commit ef289bc27eae0cdfc3f74f419ace8dda8dd84ef0 Subproject commit 49ccfbb28661b9ef7743c1725cd2571259215929

View File

@ -23,7 +23,7 @@ declare(strict_types=1);
*/ */
namespace OCA\DAV\BackgroundJob; namespace OCA\DAV\BackgroundJob;
use OC\BackgroundJob\QueuedJob; use OCP\BackgroundJob\QueuedJob;
use OCA\DAV\CalDAV\Reminder\ReminderService; use OCA\DAV\CalDAV\Reminder\ReminderService;
use OCP\AppFramework\Utility\ITimeFactory; use OCP\AppFramework\Utility\ITimeFactory;
use OCP\BackgroundJob\IJobList; use OCP\BackgroundJob\IJobList;

View File

@ -63,7 +63,7 @@ class Backend {
$query = $this->db->getQueryBuilder(); $query = $this->db->getQueryBuilder();
$query->select(['cr.*', 'co.calendardata', 'c.displayname', 'c.principaluri']) $query->select(['cr.*', 'co.calendardata', 'c.displayname', 'c.principaluri'])
->from('calendar_reminders', 'cr') ->from('calendar_reminders', 'cr')
// ->where($query->expr()->lte('cr.notification_date', $query->createNamedParameter($this->timeFactory->getTime()))) ->where($query->expr()->lte('cr.notification_date', $query->createNamedParameter($this->timeFactory->getTime())))
->leftJoin('cr', 'calendarobjects', 'co', $query->expr()->eq('cr.object_id', 'co.id')) ->leftJoin('cr', 'calendarobjects', 'co', $query->expr()->eq('cr.object_id', 'co.id'))
->leftJoin('cr', 'calendars', 'c', $query->expr()->eq('cr.calendar_id', 'c.id')); ->leftJoin('cr', 'calendars', 'c', $query->expr()->eq('cr.calendar_id', 'c.id'));
$stmt = $query->execute(); $stmt = $query->execute();

View File

@ -25,8 +25,6 @@ declare(strict_types=1);
*/ */
namespace OCA\DAV\CalDAV\Reminder\NotificationProvider; namespace OCA\DAV\CalDAV\Reminder\NotificationProvider;
use \DateTime;
use \DateTimeImmutable;
use OCA\DAV\CalDAV\Reminder\INotificationProvider; use OCA\DAV\CalDAV\Reminder\INotificationProvider;
use OCP\IConfig; use OCP\IConfig;
use OCP\IL10N; use OCP\IL10N;
@ -36,7 +34,6 @@ use OCP\L10N\IFactory as L10NFactory;
use OCP\IUser; use OCP\IUser;
use Sabre\VObject\Component\VEvent; use Sabre\VObject\Component\VEvent;
use Sabre\VObject\DateTimeParser; use Sabre\VObject\DateTimeParser;
use Sabre\VObject\Parameter;
use Sabre\VObject\Property; use Sabre\VObject\Property;
/** /**

View File

@ -25,8 +25,7 @@ declare(strict_types=1);
*/ */
namespace OCA\DAV\CalDAV\Reminder\NotificationProvider; namespace OCA\DAV\CalDAV\Reminder\NotificationProvider;
use DateTime; use \DateTime;
use DateTimeImmutable;
use OCP\IConfig; use OCP\IConfig;
use OCP\IL10N; use OCP\IL10N;
use OCP\ILogger; use OCP\ILogger;
@ -97,27 +96,25 @@ class EmailProvider extends AbstractProvider {
$organizer = $this->getOrganizerEMailAndNameFromEvent($vevent); $organizer = $this->getOrganizerEMailAndNameFromEvent($vevent);
foreach($sortedByLanguage as $lang => $emailAddresses) { foreach($sortedByLanguage as $lang => $emailAddresses) {
if ($this->hasL10NForLang($lang)) { if (!$this->hasL10NForLang($lang)) {
$lang = $fallbackLanguage; $lang = $fallbackLanguage;
} }
$l10n = $this->getL10NForLang($lang); $l10n = $this->getL10NForLang($lang);
$fromEMail = \OCP\Util::getDefaultEmailAddress('reminders-noreply'); $fromEMail = \OCP\Util::getDefaultEmailAddress('reminders-noreply');
$template = $this->mailer->createEMailTemplate('dav.calendarReminder');
$template->addHeader();
$this->addSubjectAndHeading($template, $l10n, $vevent);
$this->addBulletList($template, $l10n, $calendarDisplayName, $vevent);
$template->addFooter();
foreach ($emailAddresses as $emailAddress) {
$message = $this->mailer->createMessage(); $message = $this->mailer->createMessage();
$message->setFrom([$fromEMail]); $message->setFrom([$fromEMail]);
if ($organizer) { if ($organizer) {
$message->setReplyTo($organizer); $message->setReplyTo($organizer);
} }
$message->setTo([]) $message->setTo([$emailAddress]);
->setBcc($emailAddresses);
$template = $this->mailer->createEMailTemplate('dav.calendarReminder');
$template->addHeader();
$this->addSubjectAndHeading($template, $l10n, $vevent);
$this->addBulletList($template, $l10n, $calendarDisplayName, $vevent);
$template->addFooter();
$message->useTemplate($template); $message->useTemplate($template);
try { try {
@ -130,6 +127,7 @@ class EmailProvider extends AbstractProvider {
} }
} }
} }
}
/** /**
* @param IEMailTemplate $template * @param IEMailTemplate $template
@ -201,35 +199,6 @@ class EmailProvider extends AbstractProvider {
return [$organizerEMail]; return [$organizerEMail];
} }
/**
* @param array $sortedByLanguage
* @param IUser[] $users
* @param string $defaultLanguage
*/
private function sortUsersByLanguage(array &$sortedByLanguage,
array $users,
string $defaultLanguage):void {
/**
* @var array $sortedByLanguage
* [
* 'de' => ['a@b.com', 'c@d.com'],
* ...
* ]
*/
foreach($users as $user) {
/** @var IUser $user */
$emailAddress = $user->getEMailAddress();
$lang = $this->config->getUserValue($user->getUID(),
'core', 'lang', $defaultLanguage);
if (!isset($sortedByLanguage[$lang])) {
$sortedByLanguage[$lang] = [];
}
$sortedByLanguage[$lang][] = $emailAddress;
}
}
/** /**
* @param array $emails * @param array $emails
* @param string $defaultLanguage * @param string $defaultLanguage
@ -386,7 +355,7 @@ class EmailProvider extends AbstractProvider {
} }
} }
return array_unique($emailAddresses); return $emailAddresses;
} }
/** /**
@ -415,7 +384,9 @@ class EmailProvider extends AbstractProvider {
$diff = $dtstartDt->diff($dtendDt); $diff = $dtstartDt->diff($dtendDt);
/** @phan-suppress-next-line PhanUndeclaredClassMethod */
$dtstartDt = new \DateTime($dtstartDt->format(\DateTime::ATOM)); $dtstartDt = new \DateTime($dtstartDt->format(\DateTime::ATOM));
/** @phan-suppress-next-line PhanUndeclaredClassMethod */
$dtendDt = new \DateTime($dtendDt->format(\DateTime::ATOM)); $dtendDt = new \DateTime($dtendDt->format(\DateTime::ATOM));
if ($isAllDay) { if ($isAllDay) {
@ -432,7 +403,9 @@ class EmailProvider extends AbstractProvider {
$startTimezone = $endTimezone = null; $startTimezone = $endTimezone = null;
if (!$vevent->DTSTART->isFloating()) { if (!$vevent->DTSTART->isFloating()) {
/** @phan-suppress-next-line PhanUndeclaredClassMethod */
$startTimezone = $vevent->DTSTART->getDateTime()->getTimezone()->getName(); $startTimezone = $vevent->DTSTART->getDateTime()->getTimezone()->getName();
/** @phan-suppress-next-line PhanUndeclaredClassMethod */
$endTimezone = $this->getDTEndFromEvent($vevent)->getDateTime()->getTimezone()->getName(); $endTimezone = $this->getDTEndFromEvent($vevent)->getDateTime()->getTimezone()->getName();
} }

View File

@ -124,11 +124,15 @@ class PushProvider extends AbstractProvider {
? ((string) $vevent->LOCATION) ? ((string) $vevent->LOCATION)
: null, : null,
'all_day' => $start instanceof Property\ICalendar\Date, 'all_day' => $start instanceof Property\ICalendar\Date,
/** @phan-suppress-next-line PhanUndeclaredClassMethod */
'start_atom' => $start->getDateTime()->format(\DateTime::ATOM), 'start_atom' => $start->getDateTime()->format(\DateTime::ATOM),
'start_is_floating' => $start->isFloating(), 'start_is_floating' => $start->isFloating(),
/** @phan-suppress-next-line PhanUndeclaredClassMethod */
'start_timezone' => $start->getDateTime()->getTimezone()->getName(), 'start_timezone' => $start->getDateTime()->getTimezone()->getName(),
/** @phan-suppress-next-line PhanUndeclaredClassMethod */
'end_atom' => $end->getDateTime()->format(\DateTime::ATOM), 'end_atom' => $end->getDateTime()->format(\DateTime::ATOM),
'end_is_floating' => $end->isFloating(), 'end_is_floating' => $end->isFloating(),
/** @phan-suppress-next-line PhanUndeclaredClassMethod */
'end_timezone' => $end->getDateTime()->getTimezone()->getName(), 'end_timezone' => $end->getDateTime()->getTimezone()->getName(),
]; ];
} }

View File

@ -25,7 +25,7 @@ declare(strict_types=1);
namespace OCA\DAV\CalDAV\Reminder; namespace OCA\DAV\CalDAV\Reminder;
use DateTime; use \DateTime;
use OCA\DAV\AppInfo\Application; use OCA\DAV\AppInfo\Application;
use OCP\AppFramework\Utility\ITimeFactory; use OCP\AppFramework\Utility\ITimeFactory;
use OCP\IL10N; use OCP\IL10N;
@ -85,10 +85,6 @@ class Notifier implements INotifier {
* @since 17.0.0 * @since 17.0.0
*/ */
public function getName():string { public function getName():string {
if ($this->l10n) {
return $this->l10n->t('Calendar');
}
return $this->l10nFactory->get('dav')->t('Calendar'); return $this->l10nFactory->get('dav')->t('Calendar');
} }
@ -143,7 +139,7 @@ class Notifier implements INotifier {
private function prepareNotificationSubject(INotification $notification): void { private function prepareNotificationSubject(INotification $notification): void {
$parameters = $notification->getSubjectParameters(); $parameters = $notification->getSubjectParameters();
$startTime = \DateTime::createFromFormat(\DateTimeInterface::ATOM, $parameters['start_atom']); $startTime = \DateTime::createFromFormat(\DateTime::ATOM, $parameters['start_atom']);
$now = $this->timeFactory->getDateTime(); $now = $this->timeFactory->getDateTime();
$title = $this->getTitleFromParameters($parameters); $title = $this->getTitleFromParameters($parameters);
@ -220,8 +216,8 @@ class Notifier implements INotifier {
* @throws \Exception * @throws \Exception
*/ */
private function generateDateString(array $parameters):string { private function generateDateString(array $parameters):string {
$startDateTime = DateTime::createFromFormat(DATE_ATOM, $parameters['start_atom']); $startDateTime = DateTime::createFromFormat(\DateTime::ATOM, $parameters['start_atom']);
$endDateTime = DateTime::createFromFormat(DATE_ATOM, $parameters['end_atom']); $endDateTime = DateTime::createFromFormat(\DateTime::ATOM, $parameters['end_atom']);
$isAllDay = $parameters['all_day']; $isAllDay = $parameters['all_day'];
$diff = $startDateTime->diff($endDateTime); $diff = $startDateTime->diff($endDateTime);

View File

@ -24,7 +24,7 @@ declare(strict_types=1);
*/ */
namespace OCA\DAV\CalDAV\Reminder; namespace OCA\DAV\CalDAV\Reminder;
use DateTimeImmutable; use \DateTimeImmutable;
use OCA\DAV\CalDAV\CalDavBackend; use OCA\DAV\CalDAV\CalDavBackend;
use OCP\AppFramework\Utility\ITimeFactory; use OCP\AppFramework\Utility\ITimeFactory;
use OCP\IGroup; use OCP\IGroup;
@ -343,7 +343,7 @@ class ReminderService {
'is_repeat_based' => false, 'is_repeat_based' => false,
]; ];
$repeat = $valarm->REPEAT ? (int) $valarm->REPEAT : 0; $repeat = isset($valarm->REPEAT) ? (int) $valarm->REPEAT->getValue() : 0;
for($i = 0; $i < $repeat; $i++) { for($i = 0; $i < $repeat; $i++) {
if ($valarm->DURATION === null) { if ($valarm->DURATION === null) {
continue; continue;
@ -671,7 +671,7 @@ class ReminderService {
return null; return null;
} }
if (strcasecmp($principalUri, 'principals/users/') !== 0) { if (stripos($principalUri, 'principals/users/') !== 0) {
return null; return null;
} }

View File

@ -324,7 +324,8 @@ class Version1004Date20170825134824 extends SimpleMigrationStep {
'length' => 1, 'length' => 1,
]); ]);
$table->addColumn('stripattachments', 'smallint', [ $table->addColumn('stripattachments', 'smallint', [
'notnull' => false,
'length' => 1,
]); ]);
$table->addColumn('lastmodified', 'integer', [ $table->addColumn('lastmodified', 'integer', [
'notnull' => false, 'notnull' => false,

View File

@ -51,17 +51,42 @@ class EventReminderJobTest extends TestCase {
public function data(): array public function data(): array
{ {
return [[true], [false]]; return [
[true, true, true],
[true, false, false],
[false, true, false],
[false, false, false],
];
} }
/** /**
* @dataProvider data * @dataProvider data
*
* @param bool $sendEventReminders * @param bool $sendEventReminders
* @param bool $sendEventRemindersMode
* @param bool $expectCall
*/ */
public function testRun(bool $sendEventReminders): void public function testRun(bool $sendEventReminders, bool $sendEventRemindersMode, bool $expectCall): void {
{ $this->config->expects($this->at(0))
$this->config->expects($this->once())->method('getAppValue')->with('dav', 'sendEventReminders', 'yes')->willReturn($sendEventReminders ? 'yes' : 'no'); ->method('getAppValue')
$this->reminderService->expects($this->exactly($sendEventReminders ? 1 : 0))->method('processReminders'); ->with('dav', 'sendEventReminders', 'yes')
->willReturn($sendEventReminders ? 'yes' : 'no');
if ($sendEventReminders) {
$this->config->expects($this->at(1))
->method('getAppValue')
->with('dav', 'sendEventRemindersMode', 'backgroundjob')
->willReturn($sendEventRemindersMode ? 'backgroundjob' : 'cron');
}
if ($expectCall) {
$this->reminderService->expects($this->once())
->method('processReminders');
} else {
$this->reminderService->expects($this->never())
->method('processReminders');
}
$this->backgroundJob->run([]); $this->backgroundJob->run([]);
} }

View File

@ -1,8 +1,11 @@
<?php <?php
declare(strict_types=1);
/** /**
* @copyright Copyright (c) 2018, Thomas Citharel * @copyright Copyright (c) 2019, Thomas Citharel
* @copyright Copyright (c) 2019, Georg Ehrke
* *
* @author Thomas Citharel <tcit@tcit.fr> * @author Thomas Citharel <tcit@tcit.fr>
* @author Georg Ehrke <oc.list@georgehrke.com>
* *
* @license AGPL-3.0 * @license AGPL-3.0
* *
@ -21,7 +24,6 @@
*/ */
namespace OCA\DAV\Tests\unit\CalDAV\Reminder; namespace OCA\DAV\Tests\unit\CalDAV\Reminder;
use OCP\IDBConnection;
use OCP\DB\QueryBuilder\IQueryBuilder; use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\AppFramework\Utility\ITimeFactory; use OCP\AppFramework\Utility\ITimeFactory;
use OCA\DAV\CalDAV\Reminder\Backend as ReminderBackend; use OCA\DAV\CalDAV\Reminder\Backend as ReminderBackend;
@ -36,278 +38,360 @@ class BackendTest extends TestCase {
*/ */
private $reminderBackend; private $reminderBackend;
/** @var IDBConnection|\PHPUnit\Framework\MockObject\MockObject */
private $dbConnection;
/** @var ITimeFactory|\PHPUnit\Framework\MockObject\MockObject */ /** @var ITimeFactory|\PHPUnit\Framework\MockObject\MockObject */
private $timeFactory; private $timeFactory;
public function setUp() { public function setUp() {
parent::setUp(); parent::setUp();
$this->dbConnection = $this->createMock(IDBConnection::class); $query = self::$realDatabase->getQueryBuilder();
$query->delete('calendar_reminders')->execute();
$query->delete('calendarobjects')->execute();
$query->delete('calendars')->execute();
$this->timeFactory = $this->createMock(ITimeFactory::class); $this->timeFactory = $this->createMock(ITimeFactory::class);
$this->reminderBackend = new ReminderBackend($this->dbConnection, $this->timeFactory); $this->reminderBackend = new ReminderBackend(self::$realDatabase, $this->timeFactory);
$this->createRemindersTestSet();
} }
public function testCleanRemindersForEvent(): void protected function tearDown() {
{ $query = self::$realDatabase->getQueryBuilder();
/** @var IQueryBuilder|\PHPUnit\Framework\MockObject\MockObject $queryBuilder */ $query->delete('calendar_reminders')->execute();
$queryBuilder = $this->createMock(IQueryBuilder::class); $query->delete('calendarobjects')->execute();
$stmt = $this->createMock(\Doctrine\DBAL\Driver\Statement::class); $query->delete('calendars')->execute();
$expr = $this->createMock(\OCP\DB\QueryBuilder\IExpressionBuilder::class);
$this->dbConnection->expects($this->once())
->method('getQueryBuilder')
->with()
->will($this->returnValue($queryBuilder));
$queryBuilder->method('expr')
->will($this->returnValue($expr));
$expr->method('eq')
->will($this->returnValueMap([
['calendarid', 'createNamedParameter-1', null, 'WHERE_CLAUSE_1'],
['objecturi', 'createNamedParameter-2', null, 'WHERE_CLAUSE_2'],
]));
$queryBuilder->method('createNamedParameter')
->will($this->returnValueMap([
[1, \PDO::PARAM_STR, null, 'createNamedParameter-1'],
['object.ics', \PDO::PARAM_STR, null, 'createNamedParameter-2'],
]));
$queryBuilder->expects($this->at(0))
->method('delete')
->with('calendar_reminders')
->willReturn($queryBuilder);
$queryBuilder->expects($this->at(3))
->method('where')
->with('WHERE_CLAUSE_1')
->will($this->returnValue($queryBuilder));
$queryBuilder->expects($this->at(6))
->method('andWhere')
->with('WHERE_CLAUSE_2')
->will($this->returnValue($queryBuilder));
$queryBuilder->expects($this->at(7))
->method('execute')
->with()
->willReturn($stmt);
$this->reminderBackend->cleanRemindersForEvent(1, 'object.ics');
} }
public function testCleanRemindersForCalendar(): void
{
/** @var IQueryBuilder|\PHPUnit\Framework\MockObject\MockObject $queryBuilder */
$queryBuilder = $this->createMock(IQueryBuilder::class);
$stmt = $this->createMock(\Doctrine\DBAL\Driver\Statement::class);
$expr = $this->createMock(\OCP\DB\QueryBuilder\IExpressionBuilder::class);
$this->dbConnection->expects($this->once()) public function testCleanRemindersForEvent(): void {
->method('getQueryBuilder') $query = self::$realDatabase->getQueryBuilder();
->with() $rows = $query->select('*')
->will($this->returnValue($queryBuilder)); ->from('calendar_reminders')
$queryBuilder->method('expr') ->execute()
->will($this->returnValue($expr)); ->fetchAll();
$expr->method('eq') $this->assertCount(4, $rows);
->will($this->returnValueMap([
['calendarid', 'createNamedParameter-1', null, 'WHERE_CLAUSE_1'],
]));
$queryBuilder->method('createNamedParameter')
->will($this->returnValueMap([
[1337, \PDO::PARAM_STR, null, 'createNamedParameter-1'],
]));
$queryBuilder->expects($this->at(0)) $this->reminderBackend->cleanRemindersForEvent(1);
->method('delete')
->with('calendar_reminders')
->willReturn($queryBuilder);
$queryBuilder->expects($this->at(3))
->method('where')
->with('WHERE_CLAUSE_1')
->will($this->returnValue($queryBuilder));
$queryBuilder->expects($this->at(4))
->method('execute')
->with()
->willReturn($stmt);
$this->reminderBackend->cleanRemindersForCalendar(1337); $query = self::$realDatabase->getQueryBuilder();
$rows = $query->select('*')
->from('calendar_reminders')
->execute()
->fetchAll();
$this->assertCount(2, $rows);
} }
public function testRemoveReminder(): void public function testCleanRemindersForCalendar(): void {
{ $query = self::$realDatabase->getQueryBuilder();
/** @var IQueryBuilder|\PHPUnit\Framework\MockObject\MockObject $queryBuilder */ $rows = $query->select('*')
$queryBuilder = $this->createMock(IQueryBuilder::class); ->from('calendar_reminders')
$stmt = $this->createMock(\Doctrine\DBAL\Driver\Statement::class); ->execute()
$expr = $this->createMock(\OCP\DB\QueryBuilder\IExpressionBuilder::class); ->fetchAll();
$this->dbConnection->expects($this->once()) $this->assertCount(4, $rows);
->method('getQueryBuilder')
->with()
->will($this->returnValue($queryBuilder));
$queryBuilder->method('expr')
->will($this->returnValue($expr));
$expr->method('eq') $this->reminderBackend->cleanRemindersForCalendar(1);
->will($this->returnValueMap([
['id', 'createNamedParameter-1', null, 'WHERE_CLAUSE_1'],
]));
$queryBuilder->method('createNamedParameter')
->will($this->returnValueMap([
[16, \PDO::PARAM_STR, null, 'createNamedParameter-1'],
]));
$queryBuilder->expects($this->at(0)) $query = self::$realDatabase->getQueryBuilder();
->method('delete') $rows = $query->select('*')
->with('calendar_reminders') ->from('calendar_reminders')
->willReturn($queryBuilder); ->execute()
$queryBuilder->expects($this->at(3)) ->fetchAll();
->method('where')
->with('WHERE_CLAUSE_1')
->will($this->returnValue($queryBuilder));
$queryBuilder->expects($this->at(4))
->method('execute')
->with()
->willReturn($stmt);
$this->reminderBackend->removeReminder(16); $this->assertCount(1, $rows);
} }
public function testGetRemindersToProcess(): void public function testRemoveReminder(): void {
{ $query = self::$realDatabase->getQueryBuilder();
$dbData = [[ $rows = $query->select('*')
'cr.id' => 30, ->from('calendar_reminders')
'cr.calendarid' => 3, ->execute()
'cr.objecturi' => 'object.ics', ->fetchAll();
'cr.type' => 'EMAIL',
'cr.notificationdate' => 1337,
'cr.uid' => 'user1',
'co.calendardata' => 'BEGIN:VCALENDAR',
'c.displayname' => 'My Calendar'
]];
$this->timeFactory->expects($this->exactly(2)) $this->assertCount(4, $rows);
$this->reminderBackend->removeReminder((int) $rows[3]['id']);
$query = self::$realDatabase->getQueryBuilder();
$rows = $query->select('*')
->from('calendar_reminders')
->execute()
->fetchAll();
$this->assertCount(3, $rows);
}
public function testGetRemindersToProcess(): void {
$this->timeFactory->expects($this->exactly(1))
->method('getTime') ->method('getTime')
->with() ->with()
->willReturn(1337); ->willReturn(123457);
/** @var IQueryBuilder|\PHPUnit\Framework\MockObject\MockObject $queryBuilder */ $rows = $this->reminderBackend->getRemindersToProcess();
$queryBuilder = $this->createMock(IQueryBuilder::class);
$stmt = $this->createMock(\Doctrine\DBAL\Driver\Statement::class);
$expr = $this->createMock(\OCP\DB\QueryBuilder\IExpressionBuilder::class);
$this->dbConnection->expects($this->once()) $this->assertCount(2, $rows);
->method('getQueryBuilder') unset($rows[0]['id']);
->with() unset($rows[1]['id']);
->willReturn($queryBuilder);
$queryBuilder->method('expr')
->willReturn($expr);
$expr->method('eq') $this->assertEquals($rows[0], [
->willReturnMap([ 'calendar_id' => 1,
['cr.calendarid', 'c.id', null, 'EQ_CLAUSE_1'], 'object_id' => 1,
['co.uri', 'cr.objecturi', null, 'EQ_CLAUSE_2'], 'uid' => 'asd',
'is_recurring' => false,
'recurrence_id' => 123458,
'is_recurrence_exception' => false,
'event_hash' => 'asd123',
'alarm_hash' => 'asd567',
'type' => 'EMAIL',
'is_relative' => true,
'notification_date' => 123456,
'is_repeat_based' => false,
'calendardata' => 'Calendar data 123',
'displayname' => 'Displayname 123',
'principaluri' => 'principals/users/user001',
]); ]);
$expr->method('andX') $this->assertEquals($rows[1], [
->willReturnMap([ 'calendar_id' => 1,
['EQ_CLAUSE_1', 'EQ_CLAUSE_2', 'ANDX_CLAUSE'], 'object_id' => 1,
'uid' => 'asd',
'is_recurring' => false,
'recurrence_id' => 123458,
'is_recurrence_exception' => false,
'event_hash' => 'asd123',
'alarm_hash' => 'asd567',
'type' => 'AUDIO',
'is_relative' => true,
'notification_date' => 123456,
'is_repeat_based' => false,
'calendardata' => 'Calendar data 123',
'displayname' => 'Displayname 123',
'principaluri' => 'principals/users/user001',
]); ]);
$expr->method('lte')
->with('cr.notificationdate', 'createNamedParameter-1', null)
->willReturn('LTE_CLAUSE_1');
$expr->method('gte')
->with('cr.eventstartdate', 'createNamedParameter-1', null)
->willReturn('GTE_CLAUSE_2');
$queryBuilder->method('createNamedParameter')
->willReturnMap([
[1337, \PDO::PARAM_STR, null, 'createNamedParameter-1'],
]);
$queryBuilder->expects($this->at(0))
->method('select')
->with(['cr.id', 'cr.calendarid', 'cr.objecturi', 'cr.type', 'cr.notificationdate', 'cr.uid', 'co.calendardata', 'c.displayname'])
->willReturn($queryBuilder);
$queryBuilder->expects($this->at(1))
->method('from')
->with('calendar_reminders', 'cr')
->willReturn($queryBuilder);
$queryBuilder->expects($this->at(4))
->method('where')
->with('LTE_CLAUSE_1')
->willReturn($queryBuilder);
$queryBuilder->expects($this->at(7))
->method('andWhere')
->with('GTE_CLAUSE_2')
->willReturn($queryBuilder);
$queryBuilder->expects($this->at(9))
->method('leftJoin')
->with('cr', 'calendars', 'c', 'EQ_CLAUSE_1')
->willReturn($queryBuilder);
$queryBuilder->expects($this->at(13))
->method('leftJoin')
->with('cr', 'calendarobjects', 'co', 'ANDX_CLAUSE')
->willReturn($queryBuilder);
$queryBuilder->expects($this->at(14))
->method('execute')
->with()
->willReturn($stmt);
$stmt->expects($this->once())
->method('fetchAll')
->with()
->willReturn($dbData);
$actual = $this->reminderBackend->getRemindersToProcess();
$this->assertEquals($dbData, $actual);
} }
public function testInsertReminder(): void public function testGetAllScheduledRemindersForEvent(): void {
{ $rows = $this->reminderBackend->getAllScheduledRemindersForEvent(1);
/** @var IQueryBuilder|\PHPUnit\Framework\MockObject\MockObject $queryBuilder */
$queryBuilder = $this->createMock(IQueryBuilder::class);
$stmt = $this->createMock(\Doctrine\DBAL\Driver\Statement::class);
$expr = $this->createMock(\OCP\DB\QueryBuilder\IExpressionBuilder::class);
$this->dbConnection->expects($this->once()) $this->assertCount(2, $rows);
->method('getQueryBuilder') unset($rows[0]['id']);
->with() unset($rows[1]['id']);
->will($this->returnValue($queryBuilder));
$queryBuilder->method('expr')
->will($this->returnValue($expr));
$queryBuilder->method('createNamedParameter') $this->assertEquals($rows[0], [
->will($this->returnValueMap([ 'calendar_id' => 1,
['user1', \PDO::PARAM_STR, null, 'createNamedParameter-1'], 'object_id' => 1,
['1', \PDO::PARAM_STR, null, 'createNamedParameter-2'], 'uid' => 'asd',
['object.ics', \PDO::PARAM_STR, null, 'createNamedParameter-3'], 'is_recurring' => false,
['EMAIL', \PDO::PARAM_STR, null, 'createNamedParameter-4'], 'recurrence_id' => 123458,
[1227, \PDO::PARAM_STR, null, 'createNamedParameter-5'], 'is_recurrence_exception' => false,
[1337, \PDO::PARAM_STR, null, 'createNamedParameter-6'], 'event_hash' => 'asd123',
])); 'alarm_hash' => 'asd567',
'type' => 'EMAIL',
'is_relative' => true,
'notification_date' => 123456,
'is_repeat_based' => false,
]);
$this->assertEquals($rows[1], [
'calendar_id' => 1,
'object_id' => 1,
'uid' => 'asd',
'is_recurring' => false,
'recurrence_id' => 123458,
'is_recurrence_exception' => false,
'event_hash' => 'asd123',
'alarm_hash' => 'asd567',
'type' => 'AUDIO',
'is_relative' => true,
'notification_date' => 123456,
'is_repeat_based' => false,
]);
}
$queryBuilder->expects($this->at(0)) public function testInsertReminder(): void {
->method('insert') $query = self::$realDatabase->getQueryBuilder();
->with('calendar_reminders') $rows = $query->select('*')
->willReturn($queryBuilder); ->from('calendar_reminders')
$queryBuilder->expects($this->at(7)) ->execute()
->method('values') ->fetchAll();
->with([
'uid' => 'createNamedParameter-1', $this->assertCount(4, $rows);
'calendarid' => 'createNamedParameter-2',
'objecturi' => 'createNamedParameter-3', $this->reminderBackend->insertReminder(42, 1337, 'uid99', true, 12345678,
'type' => 'createNamedParameter-4', true, 'hash99', 'hash42', 'AUDIO', false, 12345670, false);
'notificationdate' => 'createNamedParameter-5',
'eventstartdate' => 'createNamedParameter-6', $query = self::$realDatabase->getQueryBuilder();
$rows = $query->select('*')
->from('calendar_reminders')
->execute()
->fetchAll();
$this->assertCount(5, $rows);
unset($rows[4]['id']);
$this->assertEquals($rows[4], [
'calendar_id' => '42',
'object_id' => '1337',
'is_recurring' => '1',
'uid' => 'uid99',
'recurrence_id' => '12345678',
'is_recurrence_exception' => '1',
'event_hash' => 'hash99',
'alarm_hash' => 'hash42',
'type' => 'AUDIO',
'is_relative' => '0',
'notification_date' => '12345670',
'is_repeat_based' => '0',
]);
}
public function testUpdateReminder() {
$query = self::$realDatabase->getQueryBuilder();
$rows = $query->select('*')
->from('calendar_reminders')
->execute()
->fetchAll();
$this->assertCount(4, $rows);
$this->assertEquals($rows[3]['notification_date'], 123600);
$reminderId = (int) $rows[3]['id'];
$newNotificationDate = 123700;
$this->reminderBackend->updateReminder($reminderId, $newNotificationDate);
$query = self::$realDatabase->getQueryBuilder();
$row = $query->select('notification_date')
->from('calendar_reminders')
->where($query->expr()->eq('id', $query->createNamedParameter($reminderId)))
->execute()
->fetch();
$this->assertEquals((int) $row['notification_date'], 123700);
}
private function createRemindersTestSet(): void {
$query = self::$realDatabase->getQueryBuilder();
$query->insert('calendars')
->values([
'id' => $query->createNamedParameter(1),
'principaluri' => $query->createNamedParameter('principals/users/user001'),
'displayname' => $query->createNamedParameter('Displayname 123'),
]) ])
->willReturn($queryBuilder); ->execute();
$queryBuilder->expects($this->at(8))
->method('execute')
->with()
->willReturn($stmt);
$actual = $this->reminderBackend->insertReminder('user1', '1', 'object.ics', 'EMAIL', 1227, 1337); $query = self::$realDatabase->getQueryBuilder();
$query->insert('calendars')
->values([
'id' => $query->createNamedParameter(99),
'principaluri' => $query->createNamedParameter('principals/users/user002'),
'displayname' => $query->createNamedParameter('Displayname 99'),
])
->execute();
$query = self::$realDatabase->getQueryBuilder();
$query->insert('calendarobjects')
->values([
'id' => $query->createNamedParameter(1),
'calendardata' => $query->createNamedParameter('Calendar data 123'),
'calendarid' => $query->createNamedParameter(1),
'size' => $query->createNamedParameter(42),
])
->execute();
$query = self::$realDatabase->getQueryBuilder();
$query->insert('calendarobjects')
->values([
'id' => $query->createNamedParameter(2),
'calendardata' => $query->createNamedParameter('Calendar data 456'),
'calendarid' => $query->createNamedParameter(1),
'size' => $query->createNamedParameter(42),
])
->execute();
$query = self::$realDatabase->getQueryBuilder();
$query->insert('calendarobjects')
->values([
'id' => $query->createNamedParameter(10),
'calendardata' => $query->createNamedParameter('Calendar data 789'),
'calendarid' => $query->createNamedParameter(99),
'size' => $query->createNamedParameter(42),
])
->execute();
$query = self::$realDatabase->getQueryBuilder();
$query->insert('calendar_reminders')
->values([
'calendar_id' => $query->createNamedParameter(1),
'object_id' => $query->createNamedParameter(1),
'uid' => $query->createNamedParameter('asd'),
'is_recurring' => $query->createNamedParameter(0),
'recurrence_id' => $query->createNamedParameter(123458),
'is_recurrence_exception' => $query->createNamedParameter(0),
'event_hash' => $query->createNamedParameter('asd123'),
'alarm_hash' => $query->createNamedParameter('asd567'),
'type' => $query->createNamedParameter('EMAIL'),
'is_relative' => $query->createNamedParameter(1),
'notification_date' => $query->createNamedParameter(123456),
'is_repeat_based' => $query->createNamedParameter(0),
])
->execute();
$query = self::$realDatabase->getQueryBuilder();
$query->insert('calendar_reminders')
->values([
'calendar_id' => $query->createNamedParameter(1),
'object_id' => $query->createNamedParameter(1),
'uid' => $query->createNamedParameter('asd'),
'is_recurring' => $query->createNamedParameter(0),
'recurrence_id' => $query->createNamedParameter(123458),
'is_recurrence_exception' => $query->createNamedParameter(0),
'event_hash' => $query->createNamedParameter('asd123'),
'alarm_hash' => $query->createNamedParameter('asd567'),
'type' => $query->createNamedParameter('AUDIO'),
'is_relative' => $query->createNamedParameter(1),
'notification_date' => $query->createNamedParameter(123456),
'is_repeat_based' => $query->createNamedParameter(0),
])
->execute();
$query = self::$realDatabase->getQueryBuilder();
$query->insert('calendar_reminders')
->values([
'calendar_id' => $query->createNamedParameter(1),
'object_id' => $query->createNamedParameter(2),
'uid' => $query->createNamedParameter('asd'),
'is_recurring' => $query->createNamedParameter(0),
'recurrence_id' => $query->createNamedParameter(123900),
'is_recurrence_exception' => $query->createNamedParameter(0),
'event_hash' => $query->createNamedParameter('asd123'),
'alarm_hash' => $query->createNamedParameter('asd567'),
'type' => $query->createNamedParameter('EMAIL'),
'is_relative' => $query->createNamedParameter(1),
'notification_date' => $query->createNamedParameter(123499),
'is_repeat_based' => $query->createNamedParameter(0),
])
->execute();
$query = self::$realDatabase->getQueryBuilder();
$query->insert('calendar_reminders')
->values([
'calendar_id' => $query->createNamedParameter(99),
'object_id' => $query->createNamedParameter(10),
'uid' => $query->createNamedParameter('asd'),
'is_recurring' => $query->createNamedParameter(0),
'recurrence_id' => $query->createNamedParameter(123900),
'is_recurrence_exception' => $query->createNamedParameter(0),
'event_hash' => $query->createNamedParameter('asd123'),
'alarm_hash' => $query->createNamedParameter('asd567'),
'type' => $query->createNamedParameter('DISPLAY'),
'is_relative' => $query->createNamedParameter(1),
'notification_date' => $query->createNamedParameter(123600),
'is_repeat_based' => $query->createNamedParameter(0),
])
->execute();
} }
} }

View File

@ -1,4 +1,5 @@
<?php <?php
declare(strict_types=1);
/** /**
* @copyright Copyright (c) 2019, Thomas Citharel * @copyright Copyright (c) 2019, Thomas Citharel
* *
@ -19,9 +20,9 @@
* along with this program. If not, see <http://www.gnu.org/licenses/> * along with this program. If not, see <http://www.gnu.org/licenses/>
* *
*/ */
namespace OCA\DAV\Tests\unit\CalDAV\Reminder; namespace OCA\DAV\Tests\unit\CalDAV\Reminder\NotificationProvider;
use OCA\DAV\CalDAV\Reminder\AbstractNotificationProvider; use OCA\DAV\CalDAV\Reminder\NotificationProvider\AbstractProvider;
use OCP\IConfig; use OCP\IConfig;
use OCP\IL10N; use OCP\IL10N;
use OCP\ILogger; use OCP\ILogger;
@ -48,7 +49,7 @@ abstract class AbstractNotificationProviderTest extends TestCase {
/** @var IConfig|\PHPUnit\Framework\MockObject\MockObject */ /** @var IConfig|\PHPUnit\Framework\MockObject\MockObject */
protected $config; protected $config;
/** @var AbstractNotificationProvider|\PHPUnit\Framework\MockObject\MockObject */ /** @var AbstractProvider|\PHPUnit\Framework\MockObject\MockObject */
protected $provider; protected $provider;
/** /**
@ -78,7 +79,8 @@ abstract class AbstractNotificationProviderTest extends TestCase {
$this->vcalendar = new VCalendar(); $this->vcalendar = new VCalendar();
$this->vcalendar->add('VEVENT', [ $this->vcalendar->add('VEVENT', [
'SUMMARY' => 'Fellowship meeting', 'SUMMARY' => 'Fellowship meeting',
'DTSTART' => new \DateTime('2017-01-01 00:00:00') // 1483228800 'DTSTART' => new \DateTime('2017-01-01 00:00:00+00:00'), // 1483228800,
'UID' => 'uid1234',
]); ]);
$this->calendarDisplayName = 'Personal'; $this->calendarDisplayName = 'Personal';

View File

@ -0,0 +1,33 @@
<?php
declare(strict_types=1);
/**
* @copyright Copyright (c) 2019, Georg Ehrke
*
* @author Georg Ehrke <oc.list@georgehrke.com>
*
* @license AGPL-3.0
*
* This code is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License, version 3,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License, version 3,
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
*/
namespace OCA\DAV\Tests\unit\CalDAV\Reminder\NotificationProvider;
use OCA\DAV\CalDAV\Reminder\NotificationProvider\AudioProvider;
class AudioProviderTest extends PushProviderTest {
public function testNotificationType():void {
$this->assertEquals(AudioProvider::NOTIFICATION_TYPE, 'AUDIO');
}
}

View File

@ -1,8 +1,11 @@
<?php <?php
declare(strict_types=1);
/** /**
* @copyright Copyright (c) 2019, Thomas Citharel * @copyright Copyright (c) 2019, Thomas Citharel
* @copyright Copyright (c) 2019, Georg Ehrke
* *
* @author Thomas Citharel <tcit@tcit.fr> * @author Thomas Citharel <tcit@tcit.fr>
* @author Georg Ehrke <oc.list@georgehrke.com>
* *
* @license AGPL-3.0 * @license AGPL-3.0
* *
@ -22,7 +25,6 @@
namespace OCA\DAV\Tests\unit\CalDAV\Reminder\NotificationProvider; namespace OCA\DAV\Tests\unit\CalDAV\Reminder\NotificationProvider;
use OCA\DAV\CalDAV\Reminder\NotificationProvider\EmailProvider; use OCA\DAV\CalDAV\Reminder\NotificationProvider\EmailProvider;
use OCA\DAV\CalDAV\Reminder\AbstractNotificationProvider;
use OCP\IConfig; use OCP\IConfig;
use OCP\IL10N; use OCP\IL10N;
use OCP\ILogger; use OCP\ILogger;
@ -33,8 +35,8 @@ use OCP\Mail\IEMailTemplate;
use OCP\Mail\IMailer; use OCP\Mail\IMailer;
use OCP\Mail\IAttachment; use OCP\Mail\IAttachment;
use OCP\Mail\IMessage; use OCP\Mail\IMessage;
use Sabre\VObject\Component\VCalendar;
use Test\TestCase; use Test\TestCase;
use OCA\DAV\Tests\unit\CalDAV\Reminder\AbstractNotificationProviderTest;
class EmailProviderTest extends AbstractNotificationProviderTest { class EmailProviderTest extends AbstractNotificationProviderTest {
@ -72,155 +74,473 @@ class EmailProviderTest extends AbstractNotificationProviderTest {
); );
} }
public function testSendWithNoUserEmail(): void public function testSendWithoutAttendees():void {
{ $user1 = $this->createMock(IUser::class);
$this->user->expects($this->once()) $user1->method('getUID')
->method('getEMailAddress') ->willReturn('uid1');
->with() $user1->method('getEMailAddress')
->willReturn('uid1@example.com');
$user2 = $this->createMock(IUser::class);
$user2->method('getUID')
->willReturn('uid2');
$user2->method('getEMailAddress')
->willReturn('uid2@example.com');
$user3 = $this->createMock(IUser::class);
$user3->method('getUID')
->willReturn('uid3');
$user3->method('getEMailAddress')
->willReturn('uid3@example.com');
$user4 = $this->createMock(IUser::class);
$user4->method('getUID')
->willReturn('uid4');
$user4->method('getEMailAddress')
->willReturn(null); ->willReturn(null);
$this->mailer $users = [$user1, $user2, $user3, $user4];
->expects($this->never())
->method('send');
$this->provider->send($this->vcalendar, $this->calendarDisplayName, $this->user); $this->config->expects($this->at(0))
} ->method('getUserValue')
->with('uid1', 'core', 'lang', null)
->willReturn(null);
$this->config->expects($this->at(1))
->method('getUserValue')
->with('uid2', 'core', 'lang', null)
->willReturn('de');
$this->config->expects($this->at(2))
->method('getUserValue')
->with('uid3', 'core', 'lang', null)
->willReturn('de');
public function testSendWithFailedRecipients(): void $enL10N = $this->createMock(IL10N::class);
{ $enL10N->method('t')
$this->user->expects($this->exactly(2)) ->will($this->returnArgument(0));
->method('getEMailAddress') $enL10N->method('l')
->will($this->returnArgument(0));
$deL10N = $this->createMock(IL10N::class);
$deL10N->method('t')
->will($this->returnArgument(0));
$deL10N->method('l')
->will($this->returnArgument(0));
$this->l10nFactory->expects($this->at(0))
->method('findLanguage')
->with() ->with()
->willReturn(self::USER_EMAIL); ->willReturn('en');
$this->mailer $this->l10nFactory->expects($this->at(1))
->expects($this->once()) ->method('languageExists')
->method('send') ->with('dav', 'en')
->willReturn([self::USER_EMAIL]) ->willReturn(true);
;
$this->logger $this->l10nFactory->expects($this->at(2))
->expects($this->once())
->method('error');
$l10n = $this->createMock(IL10N::class);
$this->l10nFactory
->method('get') ->method('get')
->willReturn($l10n); ->with('dav', 'en')
->willReturn($enL10N);
$this->provider->send($this->vcalendar, $this->calendarDisplayName, $this->user); $this->l10nFactory->expects($this->at(3))
} ->method('languageExists')
->with('dav', 'de')
->willReturn(true);
public function testSendWithMailerFailure(): void $this->l10nFactory->expects($this->at(4))
{
$this->user->expects($this->exactly(2))
->method('getEMailAddress')
->with()
->willReturn(self::USER_EMAIL);
$ex = new \Exception();
$this->mailer
->expects($this->once())
->method('send')
->will($this->throwException($ex))
;
$this->logger
->expects($this->once())
->method('logException')
->with($ex, ['app' => 'dav']);
$l10n = $this->createMock(IL10N::class);
$this->l10nFactory
->method('get') ->method('get')
->willReturn($l10n); ->with('dav', 'de')
->willReturn($deL10N);
$this->provider->send($this->vcalendar, $this->calendarDisplayName, $this->user); $template1 = $this->getTemplateMock();
} $message11 = $this->getMessageMock('uid1@example.com', $template1);
$template2 = $this->getTemplateMock();
$message21 = $this->getMessageMock('uid2@example.com', $template2);
$message22 = $this->getMessageMock('uid3@example.com', $template2);
public function testSend(): void $this->mailer->expects($this->at(0))
{
$this->user->expects($this->exactly(2))
->method('getEMailAddress')
->with()
->willReturn(self::USER_EMAIL);
$this->user->expects($this->once())
->method('getDisplayName')
->with()
->willReturn('Frodo');
$this->urlGenerator
->expects($this->exactly(2))
->method('getAbsoluteURL');
$this->urlGenerator
->expects($this->exactly(2))
->method('imagePath');
$mailMessage = $this->createMock(IMessage::class);
$mailMessage->expects($this->once())
->method('setFrom')
->with([\OCP\Util::getDefaultEmailAddress('invitations-noreply') => 'Nextcloud'])
->willReturn($mailMessage);
$mailMessage->expects($this->once())
->method('setTo')
->with([self::USER_EMAIL => 'Frodo'])
->willReturn($mailMessage);
$mailMessage
->expects($this->never())
->method('setReplyTo')
->willReturn($mailMessage);
$emailTemplate = $this->createMock(IEMailTemplate::class);
$this->mailer
->expects($this->once())
->method('createEMailTemplate') ->method('createEMailTemplate')
->willReturn($emailTemplate); ->with('dav.calendarReminder')
->willReturn($template1);
$emailTemplate->expects($this->once()) $this->mailer->expects($this->at(1))
->method('setSubject')
->with('Notification: Fellowship meeting');
$emailTemplate->expects($this->once())
->method('addHeader');
$emailTemplate->expects($this->once())
->method('addHeading');
$emailTemplate->expects($this->exactly(2))
->method('addBodyListItem');
$emailTemplate->expects($this->once())
->method('addFooter');
$mailMessage->expects($this->once())
->method('useTemplate')
->with($emailTemplate);
$this->mailer
->expects($this->once())
->method('createMessage') ->method('createMessage')
->willReturn($mailMessage); ->with()
->willReturn($message11);
$this->mailer->expects($this->at(2))
->method('send')
->with($message11)
->willReturn([]);
$emailAttachment = $this->createMock(IAttachment::class); $this->mailer->expects($this->at(3))
$this->mailer ->method('createEMailTemplate')
->expects($this->once()) ->with('dav.calendarReminder')
->method('createAttachment') ->willReturn($template2);
->willReturn($emailAttachment);
$this->mailer $this->mailer->expects($this->at(4))
->expects($this->once()) ->method('createMessage')
->method('send'); ->with()
->willReturn($message21);
$this->mailer->expects($this->at(5))
->method('send')
->with($message21)
->willReturn([]);
$this->mailer->expects($this->at(6))
->method('createMessage')
->with()
->willReturn($message22);
$this->mailer->expects($this->at(7))
->method('send')
->with($message22)
->willReturn([]);
$l10n = $this->createMock(IL10N::class); $this->setupURLGeneratorMock(2);
$this->l10nFactory
$vcalendar = $this->getNoAttendeeVCalendar();
$this->provider->send($vcalendar->VEVENT, $this->calendarDisplayName, $users);
}
public function testSendWithAttendees(): void {
$user1 = $this->createMock(IUser::class);
$user1->method('getUID')
->willReturn('uid1');
$user1->method('getEMailAddress')
->willReturn('uid1@example.com');
$user2 = $this->createMock(IUser::class);
$user2->method('getUID')
->willReturn('uid2');
$user2->method('getEMailAddress')
->willReturn('uid2@example.com');
$user3 = $this->createMock(IUser::class);
$user3->method('getUID')
->willReturn('uid3');
$user3->method('getEMailAddress')
->willReturn('uid3@example.com');
$user4 = $this->createMock(IUser::class);
$user4->method('getUID')
->willReturn('uid4');
$user4->method('getEMailAddress')
->willReturn(null);
$users = [$user1, $user2, $user3, $user4];
$this->config->expects($this->at(0))
->method('getUserValue')
->with('uid1', 'core', 'lang', null)
->willReturn(null);
$this->config->expects($this->at(1))
->method('getUserValue')
->with('uid2', 'core', 'lang', null)
->willReturn('de');
$this->config->expects($this->at(2))
->method('getUserValue')
->with('uid3', 'core', 'lang', null)
->willReturn('de');
$enL10N = $this->createMock(IL10N::class);
$enL10N->method('t')
->will($this->returnArgument(0));
$enL10N->method('l')
->will($this->returnArgument(0));
$deL10N = $this->createMock(IL10N::class);
$deL10N->method('t')
->will($this->returnArgument(0));
$deL10N->method('l')
->will($this->returnArgument(0));
$this->l10nFactory->expects($this->at(0))
->method('findLanguage')
->with()
->willReturn('en');
$this->l10nFactory->expects($this->at(1))
->method('languageExists')
->with('dav', 'de')
->willReturn(true);
$this->l10nFactory->expects($this->at(2))
->method('get') ->method('get')
->willReturn($l10n); ->with('dav', 'de')
->willReturn($enL10N);
$this->provider->send($this->vcalendar, $this->calendarDisplayName, $this->user); $this->l10nFactory->expects($this->at(3))
->method('languageExists')
->with('dav', 'en')
->willReturn(true);
$this->l10nFactory->expects($this->at(4))
->method('get')
->with('dav', 'en')
->willReturn($deL10N);
$template1 = $this->getTemplateMock();
$message11 = $this->getMessageMock('foo1@example.org', $template1);
$message12 = $this->getMessageMock('uid2@example.com', $template1);
$message13 = $this->getMessageMock('uid3@example.com', $template1);
$template2 = $this->getTemplateMock();
$message21 = $this->getMessageMock('foo3@example.org', $template2);
$message22 = $this->getMessageMock('foo4@example.org', $template2);
$message23 = $this->getMessageMock('uid1@example.com', $template2);
$this->mailer->expects($this->at(0))
->method('createEMailTemplate')
->with('dav.calendarReminder')
->willReturn($template1);
$this->mailer->expects($this->at(1))
->method('createMessage')
->with()
->willReturn($message11);
$this->mailer->expects($this->at(2))
->method('send')
->with($message11)
->willReturn([]);
$this->mailer->expects($this->at(3))
->method('createMessage')
->with()
->willReturn($message12);
$this->mailer->expects($this->at(4))
->method('send')
->with($message12)
->willReturn([]);
$this->mailer->expects($this->at(5))
->method('createMessage')
->with()
->willReturn($message13);
$this->mailer->expects($this->at(6))
->method('send')
->with($message13)
->willReturn([]);
$this->mailer->expects($this->at(7))
->method('createEMailTemplate')
->with('dav.calendarReminder')
->willReturn($template2);
$this->mailer->expects($this->at(8))
->method('createMessage')
->with()
->willReturn($message21);
$this->mailer->expects($this->at(9))
->method('send')
->with($message21)
->willReturn([]);
$this->mailer->expects($this->at(10))
->method('createMessage')
->with()
->willReturn($message22);
$this->mailer->expects($this->at(11))
->method('send')
->with($message22)
->willReturn([]);
$this->mailer->expects($this->at(12))
->method('createMessage')
->with()
->willReturn($message23);
$this->mailer->expects($this->at(13))
->method('send')
->with($message23)
->willReturn([]);
$this->setupURLGeneratorMock(2);
$vcalendar = $this->getAttendeeVCalendar();
$this->provider->send($vcalendar->VEVENT, $this->calendarDisplayName, $users);
}
/**
* @return IEMailTemplate
*/
private function getTemplateMock():IEMailTemplate {
$template = $this->createMock(IEMailTemplate::class);
$template->expects($this->at(0))
->method('addHeader')
->with()
->willReturn($template);
$template->expects($this->at(1))
->method('setSubject')
->with()
->willReturn($template);
$template->expects($this->at(2))
->method('addHeading')
->with()
->willReturn($template);
$template->expects($this->at(3))
->method('addBodyListItem')
->with()
->willReturn($template);
$template->expects($this->at(4))
->method('addBodyListItem')
->with()
->willReturn($template);
$template->expects($this->at(5))
->method('addBodyListItem')
->with()
->willReturn($template);
$template->expects($this->at(6))
->method('addBodyListItem')
->with()
->willReturn($template);
$template->expects($this->at(7))
->method('addFooter')
->with()
->willReturn($template);
return $template;
}
/**
* @param array $toMail
* @param IEMailTemplate $templateMock
* @param array $replyTo
* @return IMessage
*/
private function getMessageMock(string $toMail, IEMailTemplate $templateMock, array $replyTo=null):IMessage {
$message = $this->createMock(IMessage::class);
$i = 0;
$message->expects($this->at($i++))
->method('setFrom')
->with([\OCP\Util::getDefaultEmailAddress('reminders-noreply')])
->willReturn($message);
if ($replyTo) {
$message->expects($this->at($i++))
->method('setReplyTo')
->with($replyTo)
->willReturn($message);
}
$message->expects($this->at($i++))
->method('setTo')
->with([$toMail])
->willReturn($message);
$message->expects($this->at($i++))
->method('useTemplate')
->with($templateMock)
->willReturn($message);
return $message;
}
private function getNoAttendeeVCalendar():VCalendar {
$vcalendar = new VCalendar();
$vcalendar->add('VEVENT', [
'SUMMARY' => 'Fellowship meeting',
'DTSTART' => new \DateTime('2017-01-01 00:00:00+00:00'), // 1483228800,
'UID' => 'uid1234',
'LOCATION' => 'Location 123',
'DESCRIPTION' => 'DESCRIPTION 456',
]);
return $vcalendar;
}
private function getAttendeeVCalendar():VCalendar {
$vcalendar = new VCalendar();
$vcalendar->add('VEVENT', [
'SUMMARY' => 'Fellowship meeting',
'DTSTART' => new \DateTime('2017-01-01 00:00:00+00:00'), // 1483228800,
'UID' => 'uid1234',
'LOCATION' => 'Location 123',
'DESCRIPTION' => 'DESCRIPTION 456',
]);
$vcalendar->VEVENT->add(
'ATTENDEE',
'mailto:foo1@example.org',
[
'LANG' => 'de',
'PARTSTAT' => 'NEEDS-ACTION',
]
);
$vcalendar->VEVENT->add(
'ATTENDEE',
'mailto:foo2@example.org',
[
'LANG' => 'de',
'PARTSTAT' => 'DECLINED',
]
);
$vcalendar->VEVENT->add(
'ATTENDEE',
'mailto:foo3@example.org',
[
'LANG' => 'en',
'PARTSTAT' => 'CONFIRMED',
]
);
$vcalendar->VEVENT->add(
'ATTENDEE',
'mailto:foo4@example.org'
);
$vcalendar->VEVENT->add(
'ATTENDEE',
'tomail:foo5@example.org'
);
return $vcalendar;
}
private function setupURLGeneratorMock(int $times=1):void {
for ($i = 0; $i < $times; $i++) {
$this->urlGenerator
->expects($this->at(8 * $i))
->method('imagePath')
->with('core', 'actions/info.svg')
->willReturn('imagePath1');
$this->urlGenerator
->expects($this->at(8 * $i + 1))
->method('getAbsoluteURL')
->with('imagePath1')
->willReturn('AbsURL1');
$this->urlGenerator
->expects($this->at(8 * $i + 2))
->method('imagePath')
->with('core', 'places/calendar.svg')
->willReturn('imagePath2');
$this->urlGenerator
->expects($this->at(8 * $i + 3))
->method('getAbsoluteURL')
->with('imagePath2')
->willReturn('AbsURL2');
$this->urlGenerator
->expects($this->at(8 * $i + 4))
->method('imagePath')
->with('core', 'actions/address.svg')
->willReturn('imagePath3');
$this->urlGenerator
->expects($this->at(8 * $i + 5))
->method('getAbsoluteURL')
->with('imagePath3')
->willReturn('AbsURL3');
$this->urlGenerator
->expects($this->at(8 * $i + 6))
->method('imagePath')
->with('core', 'actions/more.svg')
->willReturn('imagePath4');
$this->urlGenerator
->expects($this->at(8 * $i + 7))
->method('getAbsoluteURL')
->with('imagePath4')
->willReturn('AbsURL4');
}
} }
} }

View File

@ -1,8 +1,11 @@
<?php <?php
declare(strict_types=1);
/** /**
* @copyright Copyright (c) 2019, Thomas Citharel * @copyright Copyright (c) 2019, Thomas Citharel
* @copyright Copyright (c) 2019, Georg Ehrke
* *
* @author Thomas Citharel <tcit@tcit.fr> * @author Thomas Citharel <tcit@tcit.fr>
* @author Georg Ehrke <oc.list@georgehrke.com>
* *
* @license AGPL-3.0 * @license AGPL-3.0
* *
@ -23,7 +26,6 @@ namespace OCA\DAV\Tests\unit\CalDAV\Reminder\NotificationProvider;
use OCA\DAV\AppInfo\Application; use OCA\DAV\AppInfo\Application;
use OCA\DAV\CalDAV\Reminder\NotificationProvider\PushProvider; use OCA\DAV\CalDAV\Reminder\NotificationProvider\PushProvider;
use OCA\DAV\CalDAV\Reminder\AbstractNotificationProvider;
use OCP\IConfig; use OCP\IConfig;
use OCP\IL10N; use OCP\IL10N;
use OCP\ILogger; use OCP\ILogger;
@ -34,7 +36,6 @@ use OCP\Notification\IManager;
use OCP\Notification\INotification; use OCP\Notification\INotification;
use OCP\AppFramework\Utility\ITimeFactory; use OCP\AppFramework\Utility\ITimeFactory;
use Test\TestCase; use Test\TestCase;
use OCA\DAV\Tests\unit\CalDAV\Reminder\AbstractNotificationProviderTest;
class PushProviderTest extends AbstractNotificationProviderTest { class PushProviderTest extends AbstractNotificationProviderTest {
@ -75,65 +76,111 @@ class PushProviderTest extends AbstractNotificationProviderTest {
); );
} }
public function testSend(): void public function testNotificationType():void {
{ $this->assertEquals(PushProvider::NOTIFICATION_TYPE, 'DISPLAY');
}
public function testSend(): void {
$user1 = $this->createMock(IUser::class);
$user1->method('getUID')
->willReturn('uid1');
$user2 = $this->createMock(IUser::class);
$user2->method('getUID')
->willReturn('uid2');
$user3 = $this->createMock(IUser::class);
$user3->method('getUID')
->willReturn('uid3');
$users = [$user1, $user2, $user3];
$dateTime = new \DateTime('@946684800');
$this->timeFactory->method('getDateTime')
->with()
->willReturn($dateTime);
$notification1 = $this->createNotificationMock('uid1', $dateTime);
$notification2 = $this->createNotificationMock('uid2', $dateTime);
$notification3 = $this->createNotificationMock('uid3', $dateTime);
$this->manager->expects($this->at(0))
->method('createNotification')
->with()
->willReturn($notification1);
$this->manager->expects($this->at(2))
->method('createNotification')
->with()
->willReturn($notification2);
$this->manager->expects($this->at(4))
->method('createNotification')
->with()
->willReturn($notification3);
$this->manager->expects($this->at(1))
->method('notify')
->with($notification1);
$this->manager->expects($this->at(3))
->method('notify')
->with($notification2);
$this->manager->expects($this->at(5))
->method('notify')
->with($notification3);
$this->provider->send($this->vcalendar->VEVENT, $this->calendarDisplayName, $users);
}
/**
* @param string $uid
* @param \DateTime $dt
*/
private function createNotificationMock(string $uid, \DateTime $dt):INotification {
$notification = $this->createMock(INotification::class); $notification = $this->createMock(INotification::class);
$notification $notification
->expects($this->once()) ->expects($this->once())
->method('setApp') ->method('setApp')
->with(Application::APP_ID) ->with('dav')
->willReturn($notification); ->willReturn($notification);
$notification $notification->expects($this->once())
->expects($this->once())
->method('setUser') ->method('setUser')
->willReturn($notification) ->with($uid)
; ->willReturn($notification);
$notification $notification->expects($this->once())
->expects($this->once())
->method('setDateTime') ->method('setDateTime')
->willReturn($notification) ->with($dt)
; ->willReturn($notification);
$notification $notification->expects($this->once())
->expects($this->once())
->method('setObject') ->method('setObject')
->willReturn($notification) ->with('dav', 'uid1234')
; ->willReturn($notification);
$notification $notification->expects($this->once())
->expects($this->once())
->method('setSubject') ->method('setSubject')
->willReturn($notification) ->with('calendar_reminder', [
; 'title' => 'Fellowship meeting',
'start_atom' => '2017-01-01T00:00:00+00:00',
])
->willReturn($notification);
$notification $notification
->expects($this->once()) ->expects($this->once())
->method('setMessage') ->method('setMessage')
->willReturn($notification) ->with('calendar_reminder', [
; 'title' => 'Fellowship meeting',
'start_atom' => '2017-01-01T00:00:00+00:00',
$this->manager 'description' => null,
->expects($this->once()) 'location' => null,
->method('createNotification') 'all_day' => false,
'start_is_floating' => false,
'start_timezone' => 'UTC',
'end_atom' => '2017-01-01T00:00:00+00:00',
'end_is_floating' => false,
'end_timezone' => 'UTC',
'calendar_displayname' => 'Personal',
])
->willReturn($notification); ->willReturn($notification);
$this->manager return $notification;
->expects($this->once())
->method('notify')
->with($notification);
$l10n = $this->createMock(IL10N::class);
$this->l10nFactory
->method('get')
->willReturn($l10n);
$this->timeFactory->expects($this->once())
->method('getDateTime')
->with()
->willReturn(new \DateTime());
$this->provider->send($this->vcalendar, $this->calendarDisplayName, $this->user);
} }
} }

View File

@ -1,8 +1,11 @@
<?php <?php
declare(strict_types=1);
/** /**
* @copyright Copyright (c) 2019, Thomas Citharel * @copyright Copyright (c) 2019, Thomas Citharel
* @copyright Copyright (c) 2019, Georg Ehrke
* *
* @author Thomas Citharel <tcit@tcit.fr> * @author Thomas Citharel <tcit@tcit.fr>
* @author Georg Ehrke <oc.list@georgehrke.com>
* *
* @license AGPL-3.0 * @license AGPL-3.0
* *
@ -50,8 +53,7 @@ class NotificationProviderManagerTest extends TestCase {
* @throws ProviderNotAvailableException * @throws ProviderNotAvailableException
* @throws NotificationTypeDoesNotExistException * @throws NotificationTypeDoesNotExistException
*/ */
public function testGetProviderForUnknownType(): void public function testGetProviderForUnknownType(): void{
{
$this->providerManager->getProvider('NOT EXISTENT'); $this->providerManager->getProvider('NOT EXISTENT');
} }
@ -61,28 +63,16 @@ class NotificationProviderManagerTest extends TestCase {
* @throws NotificationTypeDoesNotExistException * @throws NotificationTypeDoesNotExistException
* @throws ProviderNotAvailableException * @throws ProviderNotAvailableException
*/ */
public function testGetProviderForUnRegisteredType(): void public function testGetProviderForUnRegisteredType(): void{
{
$this->providerManager->getProvider('AUDIO'); $this->providerManager->getProvider('AUDIO');
} }
/** public function testGetProvider(): void{
* @throws NotificationTypeDoesNotExistException
* @throws ProviderNotAvailableException
*/
public function testGetProvider(): void
{
$provider = $this->providerManager->getProvider('EMAIL'); $provider = $this->providerManager->getProvider('EMAIL');
$this->assertInstanceOf(EmailProvider::class, $provider); $this->assertInstanceOf(EmailProvider::class, $provider);
} }
/** public function testRegisterProvider(): void{
* @throws NotificationTypeDoesNotExistException
* @throws ProviderNotAvailableException
* @throws \OCP\AppFramework\QueryException
*/
public function testRegisterProvider(): void
{
$this->providerManager->registerProvider(PushProvider::class); $this->providerManager->registerProvider(PushProvider::class);
$provider = $this->providerManager->getProvider('DISPLAY'); $provider = $this->providerManager->getProvider('DISPLAY');
$this->assertInstanceOf(PushProvider::class, $provider); $this->assertInstanceOf(PushProvider::class, $provider);
@ -93,8 +83,12 @@ class NotificationProviderManagerTest extends TestCase {
* @expectedException \InvalidArgumentException * @expectedException \InvalidArgumentException
* @throws \OCP\AppFramework\QueryException * @throws \OCP\AppFramework\QueryException
*/ */
public function testRegisterBadProvider(): void public function testRegisterBadProvider(): void{
{
$this->providerManager->registerProvider(Capabilities::class); $this->providerManager->registerProvider(Capabilities::class);
} }
public function testHasProvider(): void {
$this->assertTrue($this->providerManager->hasProvider('EMAIL'));
$this->assertFalse($this->providerManager->hasProvider('EMAIL123'));
}
} }

View File

@ -1,8 +1,11 @@
<?php <?php
declare(strict_types=1);
/** /**
* @copyright Copyright (c) 2019 Thomas Citharel <tcit@tcit.fr> * @copyright Copyright (c) 2019, Thomas Citharel
* @copyright Copyright (c) 2019, Georg Ehrke
* *
* @author Thomas Citharel <tcit@tcit.fr> * @author Thomas Citharel <tcit@tcit.fr>
* @author Georg Ehrke <oc.list@georgehrke.com>
* *
* @license AGPL-3.0 * @license AGPL-3.0
* *
@ -24,6 +27,7 @@ namespace OCA\DAV\Tests\unit\CalDAV\Reminder;
use OCA\DAV\AppInfo\Application; use OCA\DAV\AppInfo\Application;
use OCA\DAV\CalDAV\Reminder\Notifier; use OCA\DAV\CalDAV\Reminder\Notifier;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\IL10N; use OCP\IL10N;
use OCP\IURLGenerator; use OCP\IURLGenerator;
use OCP\L10N\IFactory; use OCP\L10N\IFactory;
@ -36,22 +40,33 @@ class NotifierTest extends TestCase {
/** @var IFactory|\PHPUnit\Framework\MockObject\MockObject */ /** @var IFactory|\PHPUnit\Framework\MockObject\MockObject */
protected $factory; protected $factory;
/** @var IURLGenerator|\PHPUnit\Framework\MockObject\MockObject */ /** @var IURLGenerator|\PHPUnit\Framework\MockObject\MockObject */
protected $urlGenerator; protected $urlGenerator;
/** @var IL10N|\PHPUnit\Framework\MockObject\MockObject */ /** @var IL10N|\PHPUnit\Framework\MockObject\MockObject */
protected $l; protected $l10n;
/** @var ITimeFactory|\PHPUnit\Framework\MockObject\MockObject */
protected $timeFactory;
protected function setUp() { protected function setUp() {
parent::setUp(); parent::setUp();
$this->urlGenerator = $this->createMock(IURLGenerator::class); $this->urlGenerator = $this->createMock(IURLGenerator::class);
$this->l = $this->createMock(IL10N::class); $this->l10n = $this->createMock(IL10N::class);
$this->l->expects($this->any()) $this->l10n->expects($this->any())
->method('t') ->method('t')
->willReturnCallback(function($string, $args) { ->willReturnCallback(function($string, $args) {
return vsprintf($string, $args); return vsprintf($string, $args);
}); });
$this->l->expects($this->any()) $this->l10n->expects($this->any())
->method('l')
->willReturnCallback(function($string, $args) {
/** \DateTime $args */
return $args->format(\DateTime::ATOM);
});
$this->l10n->expects($this->any())
->method('n') ->method('n')
->willReturnCallback(function($textSingular, $textPlural, $count, $args) { ->willReturnCallback(function($textSingular, $textPlural, $count, $args) {
$text = $count === 1 ? $textSingular : $textPlural; $text = $count === 1 ? $textSingular : $textPlural;
@ -61,14 +76,28 @@ class NotifierTest extends TestCase {
$this->factory = $this->createMock(IFactory::class); $this->factory = $this->createMock(IFactory::class);
$this->factory->expects($this->any()) $this->factory->expects($this->any())
->method('get') ->method('get')
->willReturn($this->l); ->willReturn($this->l10n);
$this->timeFactory = $this->createMock(ITimeFactory::class);
$this->timeFactory
->method('getDateTime')
->willReturn(\DateTime::createFromFormat(\DateTime::ATOM, '2005-08-15T14:00:00+02:00'));
$this->notifier = new Notifier( $this->notifier = new Notifier(
$this->factory, $this->factory,
$this->urlGenerator $this->urlGenerator,
$this->timeFactory
); );
} }
public function testGetId():void {
$this->assertEquals($this->notifier->getID(), 'dav');
}
public function testGetName():void {
$this->assertEquals($this->notifier->getName(), 'Calendar');
}
/** /**
* @expectedException \InvalidArgumentException * @expectedException \InvalidArgumentException
* @expectedExceptionMessage Notification not from this app * @expectedExceptionMessage Notification not from this app
@ -111,17 +140,24 @@ class NotifierTest extends TestCase {
[ [
'calendar_reminder', 'calendar_reminder',
[ [
'title' => 'foo', 'title' => 'Title of this event',
'start' => time() - 60 * 60 * 24 'start_atom' => '2005-08-15T15:52:01+02:00'
], ],
'foo (one day ago)', 'Title of this event (in 1 hour, 52 minutes)',
[ [
'when' => 'foo', 'title' => 'Title of this event',
'description' => 'bar', 'description' => null,
'location' => 'NC Headquarters', 'location' => 'NC Headquarters',
'calendar' => 'Personal' 'all_day' => false,
'start_atom' => '2005-08-15T15:52:01+02:00',
'start_is_floating' => false,
'start_timezone' => 'Europe/Berlin',
'end_atom' => '2005-08-15T17:52:01+02:00',
'end_is_floating' => false,
'end_timezone' => 'Europe/Berlin',
'calendar_displayname' => 'Personal',
], ],
'Calendar: Personal<br>Date: foo<br>Description: bar<br>Where: NC Headquarters' "Calendar: Personal\r\nDate: 2005-08-15T15:52:01+02:00, 2005-08-15T15:52:01+02:00 - 2005-08-15T17:52:01+02:00 (Europe/Berlin)\r\nWhere: NC Headquarters"
], ],
]; ];
} }

View File

@ -1,4 +1,5 @@
<?php <?php
declare(strict_types=1);
/** /**
* @copyright Copyright (c) 2019, Thomas Citharel * @copyright Copyright (c) 2019, Thomas Citharel
* *
@ -21,12 +22,15 @@
*/ */
namespace OCA\DAV\Tests\unit\CalDAV\Reminder; namespace OCA\DAV\Tests\unit\CalDAV\Reminder;
use OCA\DAV\CalDAV\CalDavBackend;
use OCA\DAV\CalDAV\Reminder\AbstractNotificationProvider; use OCA\DAV\CalDAV\Reminder\AbstractNotificationProvider;
use OCA\DAV\CalDAV\Reminder\Backend; use OCA\DAV\CalDAV\Reminder\Backend;
use OCA\DAV\CalDAV\Reminder\INotificationProvider;
use OCA\DAV\CalDAV\Reminder\NotificationProviderManager; use OCA\DAV\CalDAV\Reminder\NotificationProviderManager;
use OCA\DAV\CalDAV\Reminder\NotificationProvider\EmailProvider; use OCA\DAV\CalDAV\Reminder\NotificationProvider\EmailProvider;
use OCA\DAV\CalDAV\Reminder\NotificationProvider\PushProvider; use OCA\DAV\CalDAV\Reminder\NotificationProvider\PushProvider;
use OCA\DAV\CalDAV\Reminder\ReminderService; use OCA\DAV\CalDAV\Reminder\ReminderService;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\IGroup; use OCP\IGroup;
use OCP\IGroupManager; use OCP\IGroupManager;
use OCP\IUser; use OCP\IUser;
@ -51,6 +55,15 @@ class ReminderServiceTest extends TestCase {
/** @var IUserSession|\PHPUnit\Framework\MockObject\MockObject */ /** @var IUserSession|\PHPUnit\Framework\MockObject\MockObject */
private $userSession; 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 public const CALENDAR_DATA = <<<EOD
BEGIN:VCALENDAR BEGIN:VCALENDAR
PRODID:-//Nextcloud calendar v1.6.4 PRODID:-//Nextcloud calendar v1.6.4
@ -68,6 +81,87 @@ BEGIN:VALARM
ACTION:EMAIL ACTION:EMAIL
TRIGGER:-PT15M TRIGGER:-PT15M
END:VALARM 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:VEVENT
END:VCALENDAR END:VCALENDAR
EOD; EOD;
@ -79,198 +173,383 @@ EOD;
$this->notificationProviderManager = $this->createMock(NotificationProviderManager::class); $this->notificationProviderManager = $this->createMock(NotificationProviderManager::class);
$this->userManager = $this->createMock(IUserManager::class); $this->userManager = $this->createMock(IUserManager::class);
$this->groupManager = $this->createMock(IGroupManager::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);
$this->caldavBackend->method('getShares')->willReturn([]);
$this->reminderService = new ReminderService($this->backend,
$this->notificationProviderManager,
$this->userManager,
$this->groupManager,
$this->caldavBackend,
$this->timeFactory);
} }
public function dataTestProcessReminders(): array public function testOnCalendarObjectDelete():void {
{ $this->backend->expects($this->once())
return [ ->method('cleanRemindersForEvent')
[ ->with(44);
[], null
], $action = '\OCA\DAV\CalDAV\CalDavBackend::deleteCalendarObject';
[ $objectData = [
[ 'id' => '44',
[ 'component' => 'vevent',
'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->reminderService->onTouchCalendarObject($action, $objectData);
} }
/** public function testOnCalendarObjectCreateSingleEntry():void {
* @dataProvider dataTestProcessReminders $action = '\OCA\DAV\CalDAV\CalDavBackend::createCalendarObject';
* @param array $reminders $objectData = [
* @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();
}
/**
* @expectedException OC\User\NoUserException
*/
public function testProcessReminderWithBadUser(): void
{
$this->backend->expects($this->once())->method('getRemindersToProcess')->willReturn([
[
'calendardata' => self::CALENDAR_DATA, 'calendardata' => self::CALENDAR_DATA,
'type' => 'DISPLAY', 'id' => '42',
'uid' => 1, '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([
[
'id' => 1, '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',
],
[
'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',
],
[
'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',
],
[
'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',
],
[
'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',
] ]
]); ]);
$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 providesTouchCalendarObject(): array $this->notificationProviderManager->expects($this->at(0))
{ ->method('hasProvider')
return [ ->with('EMAIL')
[ ->willReturn(true);
'\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'
],
[
[
'{http://owncloud.org/ns}principal' => 'principals/users/someone'
]
],
[
'calendarid' => 1,
'uri' => 'something.ics',
'calendardata' => self::CALENDAR_DATA
],
0
],
[
'\OCA\DAV\CalDAV\CalDavBackend::createCalendarObject',
[
'principaluri' => 'principals/users/someone',
'uri' => 'personal'
],
[
[
'{http://owncloud.org/ns}principal' => 'principals/groups/somegroup'
]
],
[
'calendarid' => 1,
'uri' => 'something.ics',
'calendardata' => self::CALENDAR_DATA
],
1
]
];
}
/** $provider1 = $this->createMock(INotificationProvider::class);
* @dataProvider providesTouchCalendarObject $this->notificationProviderManager->expects($this->at(1))
* @param string $action ->method('getProvider')
* @param array $calendarData ->with('EMAIL')
* @param array $shares ->willReturn($provider1);
* @param array $objectData
* @param int $numberOfGroups $this->notificationProviderManager->expects($this->at(2))
* @throws \OC\User\NoUserException ->method('hasProvider')
* @throws \Sabre\VObject\InvalidDataException ->with('EMAIL')
*/ ->willReturn(true);
public function testOnTouchCalendarObject(string $action, array $calendarData, array $shares, array $objectData, int $numberOfGroups): void
{ $provider2 = $this->createMock(INotificationProvider::class);
$this->backend->expects($this->once())->method('cleanRemindersForEvent')->with($objectData['calendarid'], $objectData['uri']); $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);
if ($action !== '\OCA\DAV\CalDAV\CalDavBackend::deleteCalendarObject') {
$user = $this->createMock(IUser::class); $user = $this->createMock(IUser::class);
$user->expects($this->once())->method('getUID')->willReturn('user'); $this->userManager->expects($this->exactly(5))
->method('get')
->with('user001')
->willReturn($user);
$this->userSession->expects($this->once())->method('getUser')->willReturn($user); $provider1->expects($this->once())
if ($numberOfGroups === 0) { ->method('send')
$this->backend->expects($this->exactly(count($shares) + 1))->method('insertReminder'); ->with($this->callback(function($vevent) {
} else { if ($vevent->DTSTART->getDateTime()->format(\DateTime::ATOM) !== '2016-06-09T00:00:00+00:00') {
$group = $this->createMock(IGroup::class); return false;
$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);
} }
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;
} }
$reminderService = new ReminderService($this->backend, $this->notificationProviderManager, $this->userManager, $this->groupManager, $this->userSession); return true;
$reminderService->onTouchCalendarObject($action, $calendarData, $shares, $objectData); }, '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))
* @expectedException OC\User\NoUserException ->method('removeReminder')
*/ ->with(1);
public function testOnTouchCalendarObjectWithNoSession(): void $this->backend->expects($this->at(2))
{ ->method('removeReminder')
$this->backend->expects($this->once())->method('cleanRemindersForEvent'); ->with(2);
$this->userSession->expects($this->once())->method('getUser')->willReturn(null); $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);
$reminderService = new ReminderService($this->backend, $this->notificationProviderManager, $this->userManager, $this->groupManager, $this->userSession); $this->backend->expects($this->at(6))
$reminderService->onTouchCalendarObject('', ['principaluri' => 'foo'], [], ['calendarid' => 1, 'uri' => 'bar']); ->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);
public function testOnTouchCalendarObjectWithNoCalendarURI(): void $this->timeFactory->method('getDateTime')
{ ->willReturn(\DateTime::createFromFormat(\DateTime::ATOM, '2016-06-08T00:00:00+00:00'));
$reminderService = new ReminderService($this->backend, $this->notificationProviderManager, $this->userManager, $this->groupManager, $this->userSession);
$this->assertNull($reminderService->onTouchCalendarObject('', [], [], [])); $this->reminderService->processReminders();
} }
} }