ReminderServiceTest.php 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * @copyright Copyright (c) 2019, Thomas Citharel
  5. *
  6. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  7. * @author Georg Ehrke <oc.list@georgehrke.com>
  8. * @author Roeland Jago Douma <roeland@famdouma.nl>
  9. * @author Thomas Citharel <nextcloud@tcit.fr>
  10. * @author Richard Steinmetz <richard@steinmetz.cloud>
  11. *
  12. * @license GNU AGPL version 3 or any later version
  13. *
  14. * This program is free software: you can redistribute it and/or modify
  15. * it under the terms of the GNU Affero General Public License as
  16. * published by the Free Software Foundation, either version 3 of the
  17. * License, or (at your option) any later version.
  18. *
  19. * This program is distributed in the hope that it will be useful,
  20. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  21. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  22. * GNU Affero General Public License for more details.
  23. *
  24. * You should have received a copy of the GNU Affero General Public License
  25. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  26. *
  27. */
  28. namespace OCA\DAV\Tests\unit\CalDAV\Reminder;
  29. use OCA\DAV\CalDAV\CalDavBackend;
  30. use OCA\DAV\CalDAV\Reminder\Backend;
  31. use OCA\DAV\CalDAV\Reminder\INotificationProvider;
  32. use OCA\DAV\CalDAV\Reminder\NotificationProviderManager;
  33. use OCA\DAV\CalDAV\Reminder\ReminderService;
  34. use OCA\DAV\Connector\Sabre\Principal;
  35. use OCP\AppFramework\Utility\ITimeFactory;
  36. use OCP\IConfig;
  37. use OCP\IGroupManager;
  38. use OCP\IUser;
  39. use OCP\IUserManager;
  40. use OCP\IUserSession;
  41. use PHPUnit\Framework\MockObject\MockObject;
  42. use Psr\Log\LoggerInterface;
  43. use Test\TestCase;
  44. class ReminderServiceTest extends TestCase {
  45. /** @var Backend|MockObject */
  46. private $backend;
  47. /** @var NotificationProviderManager|MockObject */
  48. private $notificationProviderManager;
  49. /** @var IUserManager|MockObject */
  50. private $userManager;
  51. /** @var IGroupManager|MockObject*/
  52. private $groupManager;
  53. /** @var CalDavBackend|MockObject */
  54. private $caldavBackend;
  55. /** @var ITimeFactory|MockObject */
  56. private $timeFactory;
  57. /** @var IConfig|MockObject */
  58. private $config;
  59. /** @var ReminderService */
  60. private $reminderService;
  61. /** @var MockObject|LoggerInterface */
  62. private $logger;
  63. public const CALENDAR_DATA = <<<EOD
  64. BEGIN:VCALENDAR
  65. PRODID:-//Nextcloud calendar v1.6.4
  66. BEGIN:VEVENT
  67. CREATED:20160602T133732
  68. DTSTAMP:20160602T133732
  69. LAST-MODIFIED:20160602T133732
  70. UID:wej2z68l9h
  71. SUMMARY:Test Event
  72. LOCATION:Somewhere ...
  73. DESCRIPTION:maybe ....
  74. DTSTART;TZID=Europe/Berlin;VALUE=DATE:20160609
  75. DTEND;TZID=Europe/Berlin;VALUE=DATE:20160610
  76. BEGIN:VALARM
  77. ACTION:EMAIL
  78. TRIGGER:-PT15M
  79. END:VALARM
  80. BEGIN:VALARM
  81. ACTION:DISPLAY
  82. TRIGGER;VALUE=DATE-TIME:20160608T000000Z
  83. END:VALARM
  84. END:VEVENT
  85. END:VCALENDAR
  86. EOD;
  87. public const CALENDAR_DATA_REPEAT = <<<EOD
  88. BEGIN:VCALENDAR
  89. PRODID:-//Nextcloud calendar v1.6.4
  90. BEGIN:VEVENT
  91. CREATED:20160602T133732
  92. DTSTAMP:20160602T133732
  93. LAST-MODIFIED:20160602T133732
  94. UID:wej2z68l9h
  95. SUMMARY:Test Event
  96. LOCATION:Somewhere ...
  97. DESCRIPTION:maybe ....
  98. DTSTART;TZID=Europe/Berlin;VALUE=DATE:20160609
  99. DTEND;TZID=Europe/Berlin;VALUE=DATE:20160610
  100. BEGIN:VALARM
  101. ACTION:EMAIL
  102. TRIGGER:-PT15M
  103. REPEAT:4
  104. DURATION:PT2M
  105. END:VALARM
  106. END:VEVENT
  107. END:VCALENDAR
  108. EOD;
  109. public const CALENDAR_DATA_RECURRING = <<<EOD
  110. BEGIN:VCALENDAR
  111. PRODID:-//Nextcloud calendar v1.6.4
  112. BEGIN:VEVENT
  113. CREATED:20160602T133732
  114. DTSTAMP:20160602T133732
  115. LAST-MODIFIED:20160602T133732
  116. UID:wej2z68l9h
  117. SUMMARY:Test Event
  118. LOCATION:Somewhere ...
  119. DESCRIPTION:maybe ....
  120. DTSTART;TZID=Europe/Berlin;VALUE=DATE:20160609
  121. DTEND;TZID=Europe/Berlin;VALUE=DATE:20160610
  122. RRULE:FREQ=WEEKLY
  123. BEGIN:VALARM
  124. ACTION:EMAIL
  125. TRIGGER:-PT15M
  126. END:VALARM
  127. BEGIN:VALARM
  128. ACTION:EMAIL
  129. TRIGGER:-P8D
  130. END:VALARM
  131. END:VEVENT
  132. END:VCALENDAR
  133. EOD;
  134. public const CALENDAR_DATA_RECURRING_REPEAT = <<<EOD
  135. BEGIN:VCALENDAR
  136. PRODID:-//Nextcloud calendar v1.6.4
  137. BEGIN:VEVENT
  138. CREATED:20160602T133732
  139. DTSTAMP:20160602T133732
  140. LAST-MODIFIED:20160602T133732
  141. UID:wej2z68l9h
  142. SUMMARY:Test Event
  143. LOCATION:Somewhere ...
  144. DESCRIPTION:maybe ....
  145. DTSTART;TZID=Europe/Berlin;VALUE=DATE:20160609
  146. DTEND;TZID=Europe/Berlin;VALUE=DATE:20160610
  147. RRULE:FREQ=WEEKLY
  148. BEGIN:VALARM
  149. ACTION:EMAIL
  150. TRIGGER:-PT15M
  151. REPEAT:4
  152. DURATION:PT2M
  153. END:VALARM
  154. BEGIN:VALARM
  155. ACTION:EMAIL
  156. TRIGGER:-P8D
  157. END:VALARM
  158. END:VEVENT
  159. END:VCALENDAR
  160. EOD;
  161. public const CALENDAR_DATA_NO_ALARM = <<<EOD
  162. BEGIN:VCALENDAR
  163. PRODID:-//Nextcloud calendar v1.6.4
  164. BEGIN:VEVENT
  165. CREATED:20160602T133732
  166. DTSTAMP:20160602T133732
  167. LAST-MODIFIED:20160602T133732
  168. UID:wej2z68l9h
  169. SUMMARY:Test Event
  170. LOCATION:Somewhere ...
  171. DESCRIPTION:maybe ....
  172. DTSTART;TZID=Europe/Berlin;VALUE=DATE:20160609
  173. DTEND;TZID=Europe/Berlin;VALUE=DATE:20160610
  174. END:VEVENT
  175. END:VCALENDAR
  176. EOD;
  177. protected function setUp(): void {
  178. parent::setUp();
  179. $this->backend = $this->createMock(Backend::class);
  180. $this->notificationProviderManager = $this->createMock(NotificationProviderManager::class);
  181. $this->userManager = $this->createMock(IUserManager::class);
  182. $this->groupManager = $this->createMock(IGroupManager::class);
  183. $this->caldavBackend = $this->createMock(CalDavBackend::class);
  184. $this->timeFactory = $this->createMock(ITimeFactory::class);
  185. $this->config = $this->createMock(IConfig::class);
  186. $this->logger = $this->createMock(LoggerInterface::class);
  187. $this->principalConnector = $this->createMock(Principal::class);
  188. $this->caldavBackend->method('getShares')->willReturn([]);
  189. $this->reminderService = new ReminderService(
  190. $this->backend,
  191. $this->notificationProviderManager,
  192. $this->userManager,
  193. $this->groupManager,
  194. $this->caldavBackend,
  195. $this->timeFactory,
  196. $this->config,
  197. $this->logger,
  198. $this->principalConnector,
  199. );
  200. }
  201. public function testOnCalendarObjectDelete():void {
  202. $this->backend->expects($this->once())
  203. ->method('cleanRemindersForEvent')
  204. ->with(44);
  205. $objectData = [
  206. 'id' => '44',
  207. 'component' => 'vevent',
  208. ];
  209. $this->reminderService->onCalendarObjectDelete($objectData);
  210. }
  211. public function testOnCalendarObjectCreateSingleEntry():void {
  212. $objectData = [
  213. 'calendardata' => self::CALENDAR_DATA,
  214. 'id' => '42',
  215. 'calendarid' => '1337',
  216. 'component' => 'vevent',
  217. ];
  218. $this->backend->expects($this->exactly(2))
  219. ->method('insertReminder')
  220. ->withConsecutive(
  221. [1337, 42, 'wej2z68l9h', false, 1465430400, false, '5c70531aab15c92b52518ae10a2f78a4', 'de919af7429d3b5c11e8b9d289b411a6', 'EMAIL', true, 1465429500, false],
  222. [1337, 42, 'wej2z68l9h', false, 1465430400, false, '5c70531aab15c92b52518ae10a2f78a4', '35b3eae8e792aa2209f0b4e1a302f105', 'DISPLAY', false, 1465344000, false]
  223. )
  224. ->willReturn(1);
  225. $this->timeFactory->expects($this->once())
  226. ->method('getDateTime')
  227. ->with()
  228. ->willReturn(\DateTime::createFromFormat(\DateTime::ATOM, '2016-06-08T00:00:00+00:00'));
  229. $this->reminderService->onCalendarObjectCreate($objectData);
  230. }
  231. public function testOnCalendarObjectCreateSingleEntryWithRepeat(): void {
  232. $objectData = [
  233. 'calendardata' => self::CALENDAR_DATA_REPEAT,
  234. 'id' => '42',
  235. 'calendarid' => '1337',
  236. 'component' => 'vevent',
  237. ];
  238. $this->backend->expects($this->exactly(5))
  239. ->method('insertReminder')
  240. ->withConsecutive(
  241. [1337, 42, 'wej2z68l9h', false, 1465430400, false, '5c70531aab15c92b52518ae10a2f78a4', 'ecacbf07d413c3c78d1ac7ad8c469602', 'EMAIL', true, 1465429500, false],
  242. [1337, 42, 'wej2z68l9h', false, 1465430400, false, '5c70531aab15c92b52518ae10a2f78a4', 'ecacbf07d413c3c78d1ac7ad8c469602', 'EMAIL', true, 1465429620, true],
  243. [1337, 42, 'wej2z68l9h', false, 1465430400, false, '5c70531aab15c92b52518ae10a2f78a4', 'ecacbf07d413c3c78d1ac7ad8c469602', 'EMAIL', true, 1465429740, true],
  244. [1337, 42, 'wej2z68l9h', false, 1465430400, false, '5c70531aab15c92b52518ae10a2f78a4', 'ecacbf07d413c3c78d1ac7ad8c469602', 'EMAIL', true, 1465429860, true],
  245. [1337, 42, 'wej2z68l9h', false, 1465430400, false, '5c70531aab15c92b52518ae10a2f78a4', 'ecacbf07d413c3c78d1ac7ad8c469602', 'EMAIL', true, 1465429980, true]
  246. )
  247. ->willReturn(1);
  248. $this->timeFactory->expects($this->once())
  249. ->method('getDateTime')
  250. ->with()
  251. ->willReturn(\DateTime::createFromFormat(\DateTime::ATOM, '2016-06-08T00:00:00+00:00'));
  252. $this->reminderService->onCalendarObjectCreate($objectData);
  253. }
  254. public function testOnCalendarObjectCreateRecurringEntry(): void {
  255. $objectData = [
  256. 'calendardata' => self::CALENDAR_DATA_RECURRING,
  257. 'id' => '42',
  258. 'calendarid' => '1337',
  259. 'component' => 'vevent',
  260. ];
  261. $this->backend->expects($this->exactly(2))
  262. ->method('insertReminder')
  263. ->withConsecutive(
  264. [1337, 42, 'wej2z68l9h', true, 1467244800, false, 'fbdb2726bc0f7dfacac1d881c1453e20', 'de919af7429d3b5c11e8b9d289b411a6', 'EMAIL', true, 1467243900, false],
  265. [1337, 42, 'wej2z68l9h', true, 1467849600, false, 'fbdb2726bc0f7dfacac1d881c1453e20', '8996992118817f9f311ac5cc56d1cc97', 'EMAIL', true, 1467158400, false]
  266. )
  267. ->willReturn(1);
  268. $this->timeFactory->expects($this->once())
  269. ->method('getDateTime')
  270. ->with()
  271. ->willReturn(\DateTime::createFromFormat(\DateTime::ATOM, '2016-06-29T00:00:00+00:00'));
  272. $this->reminderService->onCalendarObjectCreate($objectData);
  273. }
  274. public function testOnCalendarObjectCreateEmpty():void {
  275. $objectData = [
  276. 'calendardata' => self::CALENDAR_DATA_NO_ALARM,
  277. 'id' => '42',
  278. 'calendarid' => '1337',
  279. 'component' => 'vevent',
  280. ];
  281. $this->backend->expects($this->never())
  282. ->method('insertReminder');
  283. $this->reminderService->onCalendarObjectCreate($objectData);
  284. }
  285. public function testOnCalendarObjectCreateRecurringEntryWithRepeat():void {
  286. $objectData = [
  287. 'calendardata' => self::CALENDAR_DATA_RECURRING_REPEAT,
  288. 'id' => '42',
  289. 'calendarid' => '1337',
  290. 'component' => 'vevent',
  291. ];
  292. $this->backend->expects($this->exactly(6))
  293. ->method('insertReminder')
  294. ->withConsecutive(
  295. [1337, 42, 'wej2z68l9h', true, 1467244800, false, 'fbdb2726bc0f7dfacac1d881c1453e20', 'ecacbf07d413c3c78d1ac7ad8c469602', 'EMAIL', true, 1467243900, false],
  296. [1337, 42, 'wej2z68l9h', true, 1467244800, false, 'fbdb2726bc0f7dfacac1d881c1453e20', 'ecacbf07d413c3c78d1ac7ad8c469602', 'EMAIL', true, 1467244020, true],
  297. [1337, 42, 'wej2z68l9h', true, 1467244800, false, 'fbdb2726bc0f7dfacac1d881c1453e20', 'ecacbf07d413c3c78d1ac7ad8c469602', 'EMAIL', true, 1467244140, true],
  298. [1337, 42, 'wej2z68l9h', true, 1467244800, false, 'fbdb2726bc0f7dfacac1d881c1453e20', 'ecacbf07d413c3c78d1ac7ad8c469602', 'EMAIL', true, 1467244260, true],
  299. [1337, 42, 'wej2z68l9h', true, 1467244800, false, 'fbdb2726bc0f7dfacac1d881c1453e20', 'ecacbf07d413c3c78d1ac7ad8c469602', 'EMAIL', true, 1467244380, true],
  300. [1337, 42, 'wej2z68l9h', true, 1467849600, false, 'fbdb2726bc0f7dfacac1d881c1453e20', '8996992118817f9f311ac5cc56d1cc97', 'EMAIL', true, 1467158400, false]
  301. )
  302. ->willReturn(1);
  303. $this->timeFactory->expects($this->once())
  304. ->method('getDateTime')
  305. ->with()
  306. ->willReturn(\DateTime::createFromFormat(\DateTime::ATOM, '2016-06-29T00:00:00+00:00'));
  307. $this->reminderService->onCalendarObjectCreate($objectData);
  308. }
  309. public function testProcessReminders():void {
  310. $this->backend->expects($this->at(0))
  311. ->method('getRemindersToProcess')
  312. ->with()
  313. ->willReturn([
  314. [
  315. 'id' => 1,
  316. 'calendar_id' => 1337,
  317. 'object_id' => 42,
  318. 'uid' => 'wej2z68l9h',
  319. 'is_recurring' => false,
  320. 'recurrence_id' => 1465430400,
  321. 'is_recurrence_exception' => false,
  322. 'event_hash' => '5c70531aab15c92b52518ae10a2f78a4',
  323. 'alarm_hash' => 'de919af7429d3b5c11e8b9d289b411a6',
  324. 'type' => 'EMAIL',
  325. 'is_relative' => true,
  326. 'notification_date' => 1465429500,
  327. 'is_repeat_based' => false,
  328. 'calendardata' => self::CALENDAR_DATA,
  329. 'displayname' => 'Displayname 123',
  330. 'principaluri' => 'principals/users/user001',
  331. ],
  332. [
  333. 'id' => 2,
  334. 'calendar_id' => 1337,
  335. 'object_id' => 42,
  336. 'uid' => 'wej2z68l9h',
  337. 'is_recurring' => false,
  338. 'recurrence_id' => 1465430400,
  339. 'is_recurrence_exception' => false,
  340. 'event_hash' => '5c70531aab15c92b52518ae10a2f78a4',
  341. 'alarm_hash' => 'ecacbf07d413c3c78d1ac7ad8c469602',
  342. 'type' => 'EMAIL',
  343. 'is_relative' => true,
  344. 'notification_date' => 1465429740,
  345. 'is_repeat_based' => true,
  346. 'calendardata' => self::CALENDAR_DATA_REPEAT,
  347. 'displayname' => 'Displayname 123',
  348. 'principaluri' => 'principals/users/user001',
  349. ],
  350. [
  351. 'id' => 3,
  352. 'calendar_id' => 1337,
  353. 'object_id' => 42,
  354. 'uid' => 'wej2z68l9h',
  355. 'is_recurring' => false,
  356. 'recurrence_id' => 1465430400,
  357. 'is_recurrence_exception' => false,
  358. 'event_hash' => '5c70531aab15c92b52518ae10a2f78a4',
  359. 'alarm_hash' => '35b3eae8e792aa2209f0b4e1a302f105',
  360. 'type' => 'DISPLAY',
  361. 'is_relative' => false,
  362. 'notification_date' => 1465344000,
  363. 'is_repeat_based' => false,
  364. 'calendardata' => self::CALENDAR_DATA,
  365. 'displayname' => 'Displayname 123',
  366. 'principaluri' => 'principals/users/user001',
  367. ],
  368. [
  369. 'id' => 4,
  370. 'calendar_id' => 1337,
  371. 'object_id' => 42,
  372. 'uid' => 'wej2z68l9h',
  373. 'is_recurring' => true,
  374. 'recurrence_id' => 1467244800,
  375. 'is_recurrence_exception' => false,
  376. 'event_hash' => 'fbdb2726bc0f7dfacac1d881c1453e20',
  377. 'alarm_hash' => 'ecacbf07d413c3c78d1ac7ad8c469602',
  378. 'type' => 'EMAIL',
  379. 'is_relative' => true,
  380. 'notification_date' => 1467243900,
  381. 'is_repeat_based' => false,
  382. 'calendardata' => self::CALENDAR_DATA_RECURRING_REPEAT,
  383. 'displayname' => 'Displayname 123',
  384. 'principaluri' => 'principals/users/user001',
  385. ],
  386. [
  387. 'id' => 5,
  388. 'calendar_id' => 1337,
  389. 'object_id' => 42,
  390. 'uid' => 'wej2z68l9h',
  391. 'is_recurring' => true,
  392. 'recurrence_id' => 1467849600,
  393. 'is_recurrence_exception' => false,
  394. 'event_hash' => 'fbdb2726bc0f7dfacac1d881c1453e20',
  395. 'alarm_hash' => '8996992118817f9f311ac5cc56d1cc97',
  396. 'type' => 'EMAIL',
  397. 'is_relative' => true,
  398. 'notification_date' => 1467158400,
  399. 'is_repeat_based' => false,
  400. 'calendardata' => self::CALENDAR_DATA_RECURRING,
  401. 'displayname' => 'Displayname 123',
  402. 'principaluri' => 'principals/users/user001',
  403. ]
  404. ]);
  405. $this->notificationProviderManager->expects($this->at(0))
  406. ->method('hasProvider')
  407. ->with('EMAIL')
  408. ->willReturn(true);
  409. $provider1 = $this->createMock(INotificationProvider::class);
  410. $this->notificationProviderManager->expects($this->at(1))
  411. ->method('getProvider')
  412. ->with('EMAIL')
  413. ->willReturn($provider1);
  414. $this->notificationProviderManager->expects($this->at(2))
  415. ->method('hasProvider')
  416. ->with('EMAIL')
  417. ->willReturn(true);
  418. $provider2 = $this->createMock(INotificationProvider::class);
  419. $this->notificationProviderManager->expects($this->at(3))
  420. ->method('getProvider')
  421. ->with('EMAIL')
  422. ->willReturn($provider2);
  423. $this->notificationProviderManager->expects($this->at(4))
  424. ->method('hasProvider')
  425. ->with('DISPLAY')
  426. ->willReturn(true);
  427. $provider3 = $this->createMock(INotificationProvider::class);
  428. $this->notificationProviderManager->expects($this->at(5))
  429. ->method('getProvider')
  430. ->with('DISPLAY')
  431. ->willReturn($provider3);
  432. $this->notificationProviderManager->expects($this->at(6))
  433. ->method('hasProvider')
  434. ->with('EMAIL')
  435. ->willReturn(true);
  436. $provider4 = $this->createMock(INotificationProvider::class);
  437. $this->notificationProviderManager->expects($this->at(7))
  438. ->method('getProvider')
  439. ->with('EMAIL')
  440. ->willReturn($provider4);
  441. $this->notificationProviderManager->expects($this->at(8))
  442. ->method('hasProvider')
  443. ->with('EMAIL')
  444. ->willReturn(true);
  445. $provider5 = $this->createMock(INotificationProvider::class);
  446. $this->notificationProviderManager->expects($this->at(9))
  447. ->method('getProvider')
  448. ->with('EMAIL')
  449. ->willReturn($provider5);
  450. $user = $this->createMock(IUser::class);
  451. $this->userManager->expects($this->exactly(5))
  452. ->method('get')
  453. ->with('user001')
  454. ->willReturn($user);
  455. $provider1->expects($this->once())
  456. ->method('send')
  457. ->with($this->callback(function ($vevent) {
  458. if ($vevent->DTSTART->getDateTime()->format(\DateTime::ATOM) !== '2016-06-09T00:00:00+00:00') {
  459. return false;
  460. }
  461. return true;
  462. }, 'Displayname 123', $user));
  463. $provider2->expects($this->once())
  464. ->method('send')
  465. ->with($this->callback(function ($vevent) {
  466. if ($vevent->DTSTART->getDateTime()->format(\DateTime::ATOM) !== '2016-06-09T00:00:00+00:00') {
  467. return false;
  468. }
  469. return true;
  470. }, 'Displayname 123', $user));
  471. $provider3->expects($this->once())
  472. ->method('send')
  473. ->with($this->callback(function ($vevent) {
  474. if ($vevent->DTSTART->getDateTime()->format(\DateTime::ATOM) !== '2016-06-09T00:00:00+00:00') {
  475. return false;
  476. }
  477. return true;
  478. }, 'Displayname 123', $user));
  479. $provider4->expects($this->once())
  480. ->method('send')
  481. ->with($this->callback(function ($vevent) {
  482. if ($vevent->DTSTART->getDateTime()->format(\DateTime::ATOM) !== '2016-06-30T00:00:00+00:00') {
  483. return false;
  484. }
  485. return true;
  486. }, 'Displayname 123', $user));
  487. $provider5->expects($this->once())
  488. ->method('send')
  489. ->with($this->callback(function ($vevent) {
  490. if ($vevent->DTSTART->getDateTime()->format(\DateTime::ATOM) !== '2016-07-07T00:00:00+00:00') {
  491. return false;
  492. }
  493. return true;
  494. }, 'Displayname 123', $user));
  495. $this->backend->expects($this->at(1))
  496. ->method('removeReminder')
  497. ->with(1);
  498. $this->backend->expects($this->at(2))
  499. ->method('removeReminder')
  500. ->with(2);
  501. $this->backend->expects($this->at(3))
  502. ->method('removeReminder')
  503. ->with(3);
  504. $this->backend->expects($this->at(4))
  505. ->method('removeReminder')
  506. ->with(4);
  507. $this->backend->expects($this->at(5))
  508. ->method('insertReminder')
  509. ->with(1337, 42, 'wej2z68l9h', true, 1467849600, false, 'fbdb2726bc0f7dfacac1d881c1453e20', 'ecacbf07d413c3c78d1ac7ad8c469602', 'EMAIL', true, 1467848700, false)
  510. ->willReturn(99);
  511. $this->backend->expects($this->at(6))
  512. ->method('insertReminder')
  513. ->with(1337, 42, 'wej2z68l9h', true, 1467849600, false, 'fbdb2726bc0f7dfacac1d881c1453e20', 'ecacbf07d413c3c78d1ac7ad8c469602', 'EMAIL', true, 1467848820, true)
  514. ->willReturn(99);
  515. $this->backend->expects($this->at(7))
  516. ->method('insertReminder')
  517. ->with(1337, 42, 'wej2z68l9h', true, 1467849600, false, 'fbdb2726bc0f7dfacac1d881c1453e20', 'ecacbf07d413c3c78d1ac7ad8c469602', 'EMAIL', true, 1467848940, true)
  518. ->willReturn(99);
  519. $this->backend->expects($this->at(8))
  520. ->method('insertReminder')
  521. ->with(1337, 42, 'wej2z68l9h', true, 1467849600, false, 'fbdb2726bc0f7dfacac1d881c1453e20', 'ecacbf07d413c3c78d1ac7ad8c469602', 'EMAIL', true, 1467849060, true)
  522. ->willReturn(99);
  523. $this->backend->expects($this->at(9))
  524. ->method('insertReminder')
  525. ->with(1337, 42, 'wej2z68l9h', true, 1467849600, false, 'fbdb2726bc0f7dfacac1d881c1453e20', 'ecacbf07d413c3c78d1ac7ad8c469602', 'EMAIL', true, 1467849180, true)
  526. ->willReturn(99);
  527. $this->backend->expects($this->at(10))
  528. ->method('removeReminder')
  529. ->with(5);
  530. $this->backend->expects($this->at(11))
  531. ->method('insertReminder')
  532. ->with(1337, 42, 'wej2z68l9h', true, 1468454400, false, 'fbdb2726bc0f7dfacac1d881c1453e20', '8996992118817f9f311ac5cc56d1cc97', 'EMAIL', true, 1467763200, false)
  533. ->willReturn(99);
  534. $this->timeFactory->method('getDateTime')
  535. ->willReturn(\DateTime::createFromFormat(\DateTime::ATOM, '2016-06-08T00:00:00+00:00'));
  536. $this->reminderService->processReminders();
  537. }
  538. }