2019-03-16 18:19:25 +03:00
|
|
|
<?php
|
2019-12-03 21:57:53 +03:00
|
|
|
|
2019-08-12 14:20:03 +03:00
|
|
|
declare(strict_types=1);
|
2019-12-03 21:57:53 +03:00
|
|
|
|
2019-03-16 18:19:25 +03:00
|
|
|
/**
|
2019-08-12 14:20:03 +03:00
|
|
|
* @copyright Copyright (c) 2019, Thomas Citharel
|
|
|
|
* @copyright Copyright (c) 2019, Georg Ehrke
|
2019-03-16 18:19:25 +03:00
|
|
|
*
|
2019-08-12 14:20:03 +03:00
|
|
|
* @author Georg Ehrke <oc.list@georgehrke.com>
|
2019-12-03 21:57:53 +03:00
|
|
|
* @author Roeland Jago Douma <roeland@famdouma.nl>
|
2020-03-31 11:49:10 +03:00
|
|
|
* @author Thomas Citharel <nextcloud@tcit.fr>
|
2019-03-16 18:19:25 +03:00
|
|
|
*
|
2019-12-03 21:57:53 +03:00
|
|
|
* @license GNU AGPL version 3 or any later version
|
2019-03-16 18:19:25 +03:00
|
|
|
*
|
2019-12-03 21:57:53 +03:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License as
|
|
|
|
* published by the Free Software Foundation, either version 3 of the
|
|
|
|
* License, or (at your option) any later version.
|
2019-03-16 18:19:25 +03:00
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2019-12-03 21:57:53 +03:00
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2019-03-16 18:19:25 +03:00
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
2019-12-03 21:57:53 +03:00
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2019-03-16 18:19:25 +03:00
|
|
|
*
|
|
|
|
*/
|
2019-11-22 22:52:10 +03:00
|
|
|
|
2019-03-16 18:19:25 +03:00
|
|
|
namespace OCA\DAV\Tests\unit\CalDAV\Reminder;
|
|
|
|
|
|
|
|
use OCA\DAV\CalDAV\Reminder\Backend as ReminderBackend;
|
2019-11-22 22:52:10 +03:00
|
|
|
use OCP\AppFramework\Utility\ITimeFactory;
|
2019-03-16 18:19:25 +03:00
|
|
|
use Test\TestCase;
|
|
|
|
|
|
|
|
class BackendTest extends TestCase {
|
|
|
|
|
2019-08-12 14:20:03 +03:00
|
|
|
/**
|
|
|
|
* Reminder Backend
|
|
|
|
*
|
|
|
|
* @var ReminderBackend|\PHPUnit\Framework\MockObject\MockObject
|
|
|
|
*/
|
|
|
|
private $reminderBackend;
|
2019-03-16 18:19:25 +03:00
|
|
|
|
|
|
|
/** @var ITimeFactory|\PHPUnit\Framework\MockObject\MockObject */
|
2019-08-12 14:20:03 +03:00
|
|
|
private $timeFactory;
|
2019-03-16 18:19:25 +03:00
|
|
|
|
2019-11-27 17:27:18 +03:00
|
|
|
protected function setUp(): void {
|
2019-03-16 18:19:25 +03:00
|
|
|
parent::setUp();
|
|
|
|
|
2019-08-12 14:20:03 +03:00
|
|
|
$query = self::$realDatabase->getQueryBuilder();
|
|
|
|
$query->delete('calendar_reminders')->execute();
|
|
|
|
$query->delete('calendarobjects')->execute();
|
|
|
|
$query->delete('calendars')->execute();
|
|
|
|
|
2019-03-16 18:19:25 +03:00
|
|
|
$this->timeFactory = $this->createMock(ITimeFactory::class);
|
2019-08-12 14:20:03 +03:00
|
|
|
$this->reminderBackend = new ReminderBackend(self::$realDatabase, $this->timeFactory);
|
2019-03-16 18:19:25 +03:00
|
|
|
|
2019-08-12 14:20:03 +03:00
|
|
|
$this->createRemindersTestSet();
|
2019-03-16 18:19:25 +03:00
|
|
|
}
|
|
|
|
|
2019-11-21 18:40:38 +03:00
|
|
|
protected function tearDown(): void {
|
2019-08-12 14:20:03 +03:00
|
|
|
$query = self::$realDatabase->getQueryBuilder();
|
|
|
|
$query->delete('calendar_reminders')->execute();
|
|
|
|
$query->delete('calendarobjects')->execute();
|
|
|
|
$query->delete('calendars')->execute();
|
|
|
|
}
|
2019-03-16 18:19:25 +03:00
|
|
|
|
|
|
|
|
2019-08-12 14:20:03 +03:00
|
|
|
public function testCleanRemindersForEvent(): void {
|
|
|
|
$query = self::$realDatabase->getQueryBuilder();
|
|
|
|
$rows = $query->select('*')
|
|
|
|
->from('calendar_reminders')
|
|
|
|
->execute()
|
|
|
|
->fetchAll();
|
|
|
|
|
|
|
|
$this->assertCount(4, $rows);
|
|
|
|
|
|
|
|
$this->reminderBackend->cleanRemindersForEvent(1);
|
|
|
|
|
|
|
|
$query = self::$realDatabase->getQueryBuilder();
|
|
|
|
$rows = $query->select('*')
|
|
|
|
->from('calendar_reminders')
|
|
|
|
->execute()
|
|
|
|
->fetchAll();
|
|
|
|
|
|
|
|
$this->assertCount(2, $rows);
|
2019-03-16 18:19:25 +03:00
|
|
|
}
|
|
|
|
|
2019-08-12 14:20:03 +03:00
|
|
|
public function testCleanRemindersForCalendar(): void {
|
|
|
|
$query = self::$realDatabase->getQueryBuilder();
|
|
|
|
$rows = $query->select('*')
|
|
|
|
->from('calendar_reminders')
|
|
|
|
->execute()
|
|
|
|
->fetchAll();
|
2019-03-16 18:19:25 +03:00
|
|
|
|
2019-08-12 14:20:03 +03:00
|
|
|
$this->assertCount(4, $rows);
|
|
|
|
|
|
|
|
$this->reminderBackend->cleanRemindersForCalendar(1);
|
2019-03-16 18:19:25 +03:00
|
|
|
|
2019-08-12 14:20:03 +03:00
|
|
|
$query = self::$realDatabase->getQueryBuilder();
|
|
|
|
$rows = $query->select('*')
|
|
|
|
->from('calendar_reminders')
|
|
|
|
->execute()
|
|
|
|
->fetchAll();
|
|
|
|
|
|
|
|
$this->assertCount(1, $rows);
|
2019-03-16 18:19:25 +03:00
|
|
|
}
|
|
|
|
|
2019-08-12 14:20:03 +03:00
|
|
|
public function testRemoveReminder(): void {
|
|
|
|
$query = self::$realDatabase->getQueryBuilder();
|
|
|
|
$rows = $query->select('*')
|
|
|
|
->from('calendar_reminders')
|
|
|
|
->execute()
|
|
|
|
->fetchAll();
|
|
|
|
|
|
|
|
$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))
|
2019-03-16 18:19:25 +03:00
|
|
|
->method('getTime')
|
|
|
|
->with()
|
2019-08-12 14:20:03 +03:00
|
|
|
->willReturn(123457);
|
|
|
|
|
|
|
|
$rows = $this->reminderBackend->getRemindersToProcess();
|
|
|
|
|
|
|
|
$this->assertCount(2, $rows);
|
|
|
|
unset($rows[0]['id']);
|
|
|
|
unset($rows[1]['id']);
|
|
|
|
|
|
|
|
$this->assertEquals($rows[0], [
|
|
|
|
'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' => 'EMAIL',
|
|
|
|
'is_relative' => true,
|
|
|
|
'notification_date' => 123456,
|
|
|
|
'is_repeat_based' => false,
|
|
|
|
'calendardata' => 'Calendar data 123',
|
|
|
|
'displayname' => 'Displayname 123',
|
|
|
|
'principaluri' => 'principals/users/user001',
|
|
|
|
]);
|
|
|
|
$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,
|
|
|
|
'calendardata' => 'Calendar data 123',
|
|
|
|
'displayname' => 'Displayname 123',
|
|
|
|
'principaluri' => 'principals/users/user001',
|
|
|
|
]);
|
|
|
|
}
|
2019-03-16 18:19:25 +03:00
|
|
|
|
2019-08-12 14:20:03 +03:00
|
|
|
public function testGetAllScheduledRemindersForEvent(): void {
|
|
|
|
$rows = $this->reminderBackend->getAllScheduledRemindersForEvent(1);
|
|
|
|
|
|
|
|
$this->assertCount(2, $rows);
|
|
|
|
unset($rows[0]['id']);
|
|
|
|
unset($rows[1]['id']);
|
|
|
|
|
|
|
|
$this->assertEquals($rows[0], [
|
|
|
|
'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' => '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,
|
|
|
|
]);
|
|
|
|
}
|
2019-03-16 18:19:25 +03:00
|
|
|
|
2019-08-12 14:20:03 +03:00
|
|
|
public function testInsertReminder(): void {
|
|
|
|
$query = self::$realDatabase->getQueryBuilder();
|
|
|
|
$rows = $query->select('*')
|
|
|
|
->from('calendar_reminders')
|
|
|
|
->execute()
|
|
|
|
->fetchAll();
|
|
|
|
|
|
|
|
$this->assertCount(4, $rows);
|
|
|
|
|
|
|
|
$this->reminderBackend->insertReminder(42, 1337, 'uid99', true, 12345678,
|
|
|
|
true, 'hash99', 'hash42', 'AUDIO', false, 12345670, false);
|
|
|
|
|
|
|
|
$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',
|
|
|
|
]);
|
|
|
|
}
|
2019-03-16 18:19:25 +03:00
|
|
|
|
2019-08-12 14:20:03 +03:00
|
|
|
public function testUpdateReminder() {
|
|
|
|
$query = self::$realDatabase->getQueryBuilder();
|
|
|
|
$rows = $query->select('*')
|
|
|
|
->from('calendar_reminders')
|
|
|
|
->execute()
|
|
|
|
->fetchAll();
|
|
|
|
|
|
|
|
$this->assertCount(4, $rows);
|
2019-03-16 18:19:25 +03:00
|
|
|
|
2019-08-12 14:20:03 +03:00
|
|
|
$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);
|
2019-03-16 18:19:25 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-08-12 14:20:03 +03:00
|
|
|
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'),
|
2019-03-16 18:19:25 +03:00
|
|
|
])
|
2019-08-12 14:20:03 +03:00
|
|
|
->execute();
|
|
|
|
|
|
|
|
$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();
|
|
|
|
}
|
2019-03-16 18:19:25 +03:00
|
|
|
}
|