ReminderServiceTest.php 19 KB

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