ReminderServiceTest.php 19 KB

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