You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

IMipPluginTest.php 20KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. * @copyright Copyright (c) 2017, Georg Ehrke
  5. *
  6. * @author brad2014 <brad2014@users.noreply.github.com>
  7. * @author Brad Rubenstein <brad@wbr.tech>
  8. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  9. * @author Georg Ehrke <oc.list@georgehrke.com>
  10. * @author Joas Schilling <coding@schilljs.com>
  11. * @author Morris Jobke <hey@morrisjobke.de>
  12. * @author Thomas Citharel <nextcloud@tcit.fr>
  13. * @author Thomas Müller <thomas.mueller@tmit.eu>
  14. *
  15. * @license AGPL-3.0
  16. *
  17. * This code is free software: you can redistribute it and/or modify
  18. * it under the terms of the GNU Affero General Public License, version 3,
  19. * as published by the Free Software Foundation.
  20. *
  21. * This program is distributed in the hope that it will be useful,
  22. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  23. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  24. * GNU Affero General Public License for more details.
  25. *
  26. * You should have received a copy of the GNU Affero General Public License, version 3,
  27. * along with this program. If not, see <http://www.gnu.org/licenses/>
  28. *
  29. */
  30. namespace OCA\DAV\Tests\unit\CalDAV\Schedule;
  31. use OCA\DAV\CalDAV\EventComparisonService;
  32. use OCA\DAV\CalDAV\Schedule\IMipPlugin;
  33. use OCA\DAV\CalDAV\Schedule\IMipService;
  34. use OCP\AppFramework\Utility\ITimeFactory;
  35. use OCP\Defaults;
  36. use OCP\IConfig;
  37. use OCP\IUserManager;
  38. use OCP\Mail\IAttachment;
  39. use OCP\Mail\IEMailTemplate;
  40. use OCP\Mail\IMailer;
  41. use OCP\Mail\IMessage;
  42. use PHPUnit\Framework\MockObject\MockObject;
  43. use Psr\Log\LoggerInterface;
  44. use Sabre\VObject\Component\VCalendar;
  45. use Sabre\VObject\Component\VEvent;
  46. use Sabre\VObject\ITip\Message;
  47. use Test\TestCase;
  48. use function array_merge;
  49. class IMipPluginTest extends TestCase {
  50. /** @var IMessage|MockObject */
  51. private $mailMessage;
  52. /** @var IMailer|MockObject */
  53. private $mailer;
  54. /** @var IEMailTemplate|MockObject */
  55. private $emailTemplate;
  56. /** @var IAttachment|MockObject */
  57. private $emailAttachment;
  58. /** @var ITimeFactory|MockObject */
  59. private $timeFactory;
  60. /** @var IConfig|MockObject */
  61. private $config;
  62. /** @var IUserManager|MockObject */
  63. private $userManager;
  64. /** @var IMipPlugin */
  65. private $plugin;
  66. /** @var IMipService|MockObject */
  67. private $service;
  68. /** @var Defaults|MockObject */
  69. private $defaults;
  70. /** @var LoggerInterface|MockObject */
  71. private $logger;
  72. /** @var EventComparisonService|MockObject */
  73. private $eventComparisonService;
  74. protected function setUp(): void {
  75. $this->mailMessage = $this->createMock(IMessage::class);
  76. $this->mailMessage->method('setFrom')->willReturn($this->mailMessage);
  77. $this->mailMessage->method('setReplyTo')->willReturn($this->mailMessage);
  78. $this->mailMessage->method('setTo')->willReturn($this->mailMessage);
  79. $this->mailer = $this->createMock(IMailer::class);
  80. $this->mailer->method('createMessage')->willReturn($this->mailMessage);
  81. $this->emailTemplate = $this->createMock(IEMailTemplate::class);
  82. $this->mailer->method('createEMailTemplate')->willReturn($this->emailTemplate);
  83. $this->emailAttachment = $this->createMock(IAttachment::class);
  84. $this->mailer->method('createAttachment')->willReturn($this->emailAttachment);
  85. $this->logger = $this->createMock(LoggerInterface::class);
  86. $this->timeFactory = $this->createMock(ITimeFactory::class);
  87. $this->timeFactory->method('getTime')->willReturn(1496912528); // 2017-01-01
  88. $this->config = $this->createMock(IConfig::class);
  89. $this->userManager = $this->createMock(IUserManager::class);
  90. $this->defaults = $this->createMock(Defaults::class);
  91. $this->defaults->method('getName')
  92. ->willReturn('Instance Name 123');
  93. $this->service = $this->createMock(IMipService::class);
  94. $this->eventComparisonService = $this->createMock(EventComparisonService::class);
  95. $this->plugin = new IMipPlugin(
  96. $this->config,
  97. $this->mailer,
  98. $this->logger,
  99. $this->timeFactory,
  100. $this->defaults,
  101. $this->userManager,
  102. 'user123',
  103. $this->service,
  104. $this->eventComparisonService
  105. );
  106. }
  107. public function testDeliveryNoSignificantChange(): void {
  108. $message = new Message();
  109. $message->method = 'REQUEST';
  110. $message->message = new VCalendar();
  111. $message->message->add('VEVENT', array_merge([
  112. 'UID' => 'uid-1234',
  113. 'SEQUENCE' => 0,
  114. 'SUMMARY' => 'Fellowship meeting',
  115. 'DTSTART' => new \DateTime('2016-01-01 00:00:00')
  116. ], []));
  117. $message->message->VEVENT->add('ORGANIZER', 'mailto:gandalf@wiz.ard');
  118. $message->message->VEVENT->add('ATTENDEE', 'mailto:' . 'frodo@hobb.it', ['RSVP' => 'TRUE']);
  119. $message->sender = 'mailto:gandalf@wiz.ard';
  120. $message->senderName = 'Mr. Wizard';
  121. $message->recipient = 'mailto:' . 'frodo@hobb.it';
  122. $message->significantChange = false;
  123. $this->plugin->schedule($message);
  124. $this->assertEquals('1.0', $message->getScheduleStatus());
  125. }
  126. public function testParsingSingle(): void {
  127. $message = new Message();
  128. $message->method = 'REQUEST';
  129. $newVCalendar = new VCalendar();
  130. $newVevent = new VEvent($newVCalendar, 'one', array_merge([
  131. 'UID' => 'uid-1234',
  132. 'SEQUENCE' => 1,
  133. 'SUMMARY' => 'Fellowship meeting without (!) Boromir',
  134. 'DTSTART' => new \DateTime('2016-01-01 00:00:00')
  135. ], []));
  136. $newVevent->add('ORGANIZER', 'mailto:gandalf@wiz.ard');
  137. $newVevent->add('ATTENDEE', 'mailto:' . 'frodo@hobb.it', ['RSVP' => 'TRUE', 'CN' => 'Frodo']);
  138. $message->message = $newVCalendar;
  139. $message->sender = 'mailto:gandalf@wiz.ard';
  140. $message->senderName = 'Mr. Wizard';
  141. $message->recipient = 'mailto:' . 'frodo@hobb.it';
  142. // save the old copy in the plugin
  143. $oldVCalendar = new VCalendar();
  144. $oldVEvent = new VEvent($oldVCalendar, 'one', [
  145. 'UID' => 'uid-1234',
  146. 'SEQUENCE' => 0,
  147. 'SUMMARY' => 'Fellowship meeting',
  148. 'DTSTART' => new \DateTime('2016-01-01 00:00:00')
  149. ]);
  150. $oldVEvent->add('ORGANIZER', 'mailto:gandalf@wiz.ard');
  151. $oldVEvent->add('ATTENDEE', 'mailto:' . 'frodo@hobb.it', ['RSVP' => 'TRUE', 'CN' => 'Frodo']);
  152. $oldVEvent->add('ATTENDEE', 'mailto:' . 'boromir@tra.it.or', ['RSVP' => 'TRUE']);
  153. $oldVCalendar->add($oldVEvent);
  154. $data = ['invitee_name' => 'Mr. Wizard',
  155. 'meeting_title' => 'Fellowship meeting without (!) Boromir',
  156. 'attendee_name' => 'frodo@hobb.it'
  157. ];
  158. $this->plugin->setVCalendar($oldVCalendar);
  159. $this->service->expects(self::once())
  160. ->method('getLastOccurrence')
  161. ->willReturn('1496912700');
  162. $this->mailer->expects(self::once())
  163. ->method('validateMailAddress')
  164. ->with('frodo@hobb.it')
  165. ->willReturn(true);
  166. $this->eventComparisonService->expects(self::once())
  167. ->method('findModified')
  168. ->willReturn(['new' => [$newVevent], 'old' => [$oldVEvent]]);
  169. $this->service->expects(self::once())
  170. ->method('buildBodyData')
  171. ->with($newVevent, $oldVEvent)
  172. ->willReturn($data);
  173. $this->userManager->expects(self::never())
  174. ->method('getDisplayName');
  175. $this->service->expects(self::once())
  176. ->method('getFrom');
  177. $this->service->expects(self::once())
  178. ->method('addSubjectAndHeading')
  179. ->with($this->emailTemplate, 'request', 'Mr. Wizard', 'Fellowship meeting without (!) Boromir');
  180. $this->service->expects(self::once())
  181. ->method('addBulletList')
  182. ->with($this->emailTemplate, $newVevent, $data);
  183. $this->service->expects(self::once())
  184. ->method('getAttendeeRsvpOrReqForParticipant')
  185. ->willReturn(true);
  186. $this->config->expects(self::once())
  187. ->method('getAppValue')
  188. ->with('dav', 'invitation_link_recipients', 'yes')
  189. ->willReturn('yes');
  190. $this->service->expects(self::once())
  191. ->method('createInvitationToken')
  192. ->with($message,$newVevent, '1496912700')
  193. ->willReturn('token');
  194. $this->service->expects(self::once())
  195. ->method('addResponseButtons')
  196. ->with($this->emailTemplate, 'token');
  197. $this->service->expects(self::once())
  198. ->method('addMoreOptionsButton')
  199. ->with($this->emailTemplate, 'token');
  200. $this->mailer->expects(self::once())
  201. ->method('send')
  202. ->willReturn([]);
  203. $this->plugin->schedule($message);
  204. $this->assertEquals('1.1', $message->getScheduleStatus());
  205. }
  206. public function testParsingRecurrence(): void {
  207. $message = new Message();
  208. $message->method = 'REQUEST';
  209. $newVCalendar = new VCalendar();
  210. $newVevent = new VEvent($newVCalendar, 'one', [
  211. 'UID' => 'uid-1234',
  212. 'LAST-MODIFIED' => 123456,
  213. 'SEQUENCE' => 2,
  214. 'SUMMARY' => 'Fellowship meeting',
  215. 'DTSTART' => new \DateTime('2016-01-01 00:00:00'),
  216. 'RRULE' => 'FREQ=DAILY;INTERVAL=1;UNTIL=20160201T000000Z'
  217. ]);
  218. $newVevent->add('ORGANIZER', 'mailto:gandalf@wiz.ard');
  219. $newVevent->add('ATTENDEE', 'mailto:' . 'frodo@hobb.it', ['RSVP' => 'TRUE', 'CN' => 'Frodo']);
  220. $newvEvent2 = new VEvent($newVCalendar, 'two', [
  221. 'UID' => 'uid-1234',
  222. 'SEQUENCE' => 1,
  223. 'SUMMARY' => 'Elevenses',
  224. 'DTSTART' => new \DateTime('2016-01-01 00:00:00'),
  225. 'RECURRENCE-ID' => new \DateTime('2016-01-01 00:00:00')
  226. ]);
  227. $newvEvent2->add('ORGANIZER', 'mailto:gandalf@wiz.ard');
  228. $newvEvent2->add('ATTENDEE', 'mailto:' . 'frodo@hobb.it', ['RSVP' => 'TRUE', 'CN' => 'Frodo']);
  229. $message->message = $newVCalendar;
  230. $message->sender = 'mailto:gandalf@wiz.ard';
  231. $message->recipient = 'mailto:' . 'frodo@hobb.it';
  232. // save the old copy in the plugin
  233. $oldVCalendar = new VCalendar();
  234. $oldVEvent = new VEvent($oldVCalendar, 'one', [
  235. 'UID' => 'uid-1234',
  236. 'LAST-MODIFIED' => 123456,
  237. 'SEQUENCE' => 2,
  238. 'SUMMARY' => 'Fellowship meeting',
  239. 'DTSTART' => new \DateTime('2016-01-01 00:00:00'),
  240. 'RRULE' => 'FREQ=DAILY;INTERVAL=1;UNTIL=20160201T000000Z'
  241. ]);
  242. $oldVEvent->add('ORGANIZER', 'mailto:gandalf@wiz.ard');
  243. $oldVEvent->add('ATTENDEE', 'mailto:' . 'frodo@hobb.it', ['RSVP' => 'TRUE', 'CN' => 'Frodo']);
  244. $data = ['invitee_name' => 'Mr. Wizard',
  245. 'meeting_title' => 'Elevenses',
  246. 'attendee_name' => 'frodo@hobb.it'
  247. ];
  248. $this->plugin->setVCalendar($oldVCalendar);
  249. $this->service->expects(self::once())
  250. ->method('getLastOccurrence')
  251. ->willReturn('1496912700');
  252. $this->mailer->expects(self::once())
  253. ->method('validateMailAddress')
  254. ->with('frodo@hobb.it')
  255. ->willReturn(true);
  256. $this->eventComparisonService->expects(self::once())
  257. ->method('findModified')
  258. ->willReturn(['old' => [] ,'new' => [$newVevent]]);
  259. $this->service->expects(self::once())
  260. ->method('buildBodyData')
  261. ->with($newVevent, null)
  262. ->willReturn($data);
  263. $this->userManager->expects(self::once())
  264. ->method('getDisplayName')
  265. ->willReturn('Mr. Wizard');
  266. $this->service->expects(self::once())
  267. ->method('getFrom');
  268. $this->service->expects(self::once())
  269. ->method('addSubjectAndHeading')
  270. ->with($this->emailTemplate, 'request', 'Mr. Wizard', 'Elevenses');
  271. $this->service->expects(self::once())
  272. ->method('addBulletList')
  273. ->with($this->emailTemplate, $newVevent, $data);
  274. $this->service->expects(self::once())
  275. ->method('getAttendeeRsvpOrReqForParticipant')
  276. ->willReturn(true);
  277. $this->config->expects(self::once())
  278. ->method('getAppValue')
  279. ->with('dav', 'invitation_link_recipients', 'yes')
  280. ->willReturn('yes');
  281. $this->service->expects(self::once())
  282. ->method('createInvitationToken')
  283. ->with($message, $newVevent, '1496912700')
  284. ->willReturn('token');
  285. $this->service->expects(self::once())
  286. ->method('addResponseButtons')
  287. ->with($this->emailTemplate, 'token');
  288. $this->service->expects(self::once())
  289. ->method('addMoreOptionsButton')
  290. ->with($this->emailTemplate, 'token');
  291. $this->mailer->expects(self::once())
  292. ->method('send')
  293. ->willReturn([]);
  294. $this->plugin->schedule($message);
  295. $this->assertEquals('1.1', $message->getScheduleStatus());
  296. }
  297. public function testEmailValidationFailed() {
  298. $message = new Message();
  299. $message->method = 'REQUEST';
  300. $message->message = new VCalendar();
  301. $message->message->add('VEVENT', array_merge([
  302. 'UID' => 'uid-1234',
  303. 'SEQUENCE' => 0,
  304. 'SUMMARY' => 'Fellowship meeting',
  305. 'DTSTART' => new \DateTime('2016-01-01 00:00:00')
  306. ], []));
  307. $message->message->VEVENT->add('ORGANIZER', 'mailto:gandalf@wiz.ard');
  308. $message->message->VEVENT->add('ATTENDEE', 'mailto:' . 'frodo@hobb.it', ['RSVP' => 'TRUE']);
  309. $message->sender = 'mailto:gandalf@wiz.ard';
  310. $message->senderName = 'Mr. Wizard';
  311. $message->recipient = 'mailto:' . 'frodo@hobb.it';
  312. $this->service->expects(self::once())
  313. ->method('getLastOccurrence')
  314. ->willReturn('1496912700');
  315. $this->mailer->expects(self::once())
  316. ->method('validateMailAddress')
  317. ->with('frodo@hobb.it')
  318. ->willReturn(false);
  319. $this->plugin->schedule($message);
  320. $this->assertEquals('5.0', $message->getScheduleStatus());
  321. }
  322. public function testFailedDelivery(): void {
  323. $message = new Message();
  324. $message->method = 'REQUEST';
  325. $newVcalendar = new VCalendar();
  326. $newVevent = new VEvent($newVcalendar, 'one', array_merge([
  327. 'UID' => 'uid-1234',
  328. 'SEQUENCE' => 1,
  329. 'SUMMARY' => 'Fellowship meeting without (!) Boromir',
  330. 'DTSTART' => new \DateTime('2016-01-01 00:00:00')
  331. ], []));
  332. $newVevent->add('ORGANIZER', 'mailto:gandalf@wiz.ard');
  333. $newVevent->add('ATTENDEE', 'mailto:' . 'frodo@hobb.it', ['RSVP' => 'TRUE', 'CN' => 'Frodo']);
  334. $message->message = $newVcalendar;
  335. $message->sender = 'mailto:gandalf@wiz.ard';
  336. $message->senderName = 'Mr. Wizard';
  337. $message->recipient = 'mailto:' . 'frodo@hobb.it';
  338. // save the old copy in the plugin
  339. $oldVcalendar = new VCalendar();
  340. $oldVevent = new VEvent($oldVcalendar, 'one', [
  341. 'UID' => 'uid-1234',
  342. 'SEQUENCE' => 0,
  343. 'SUMMARY' => 'Fellowship meeting',
  344. 'DTSTART' => new \DateTime('2016-01-01 00:00:00')
  345. ]);
  346. $oldVevent->add('ORGANIZER', 'mailto:gandalf@wiz.ard');
  347. $oldVevent->add('ATTENDEE', 'mailto:' . 'frodo@hobb.it', ['RSVP' => 'TRUE', 'CN' => 'Frodo']);
  348. $oldVevent->add('ATTENDEE', 'mailto:' . 'boromir@tra.it.or', ['RSVP' => 'TRUE']);
  349. $oldVcalendar->add($oldVevent);
  350. $data = ['invitee_name' => 'Mr. Wizard',
  351. 'meeting_title' => 'Fellowship meeting without (!) Boromir',
  352. 'attendee_name' => 'frodo@hobb.it'
  353. ];
  354. $this->plugin->setVCalendar($oldVcalendar);
  355. $this->service->expects(self::once())
  356. ->method('getLastOccurrence')
  357. ->willReturn('1496912700');
  358. $this->mailer->expects(self::once())
  359. ->method('validateMailAddress')
  360. ->with('frodo@hobb.it')
  361. ->willReturn(true);
  362. $this->eventComparisonService->expects(self::once())
  363. ->method('findModified')
  364. ->willReturn(['old' => [] ,'new' => [$newVevent]]);
  365. $this->service->expects(self::once())
  366. ->method('buildBodyData')
  367. ->with($newVevent, null)
  368. ->willReturn($data);
  369. $this->userManager->expects(self::never())
  370. ->method('getDisplayName');
  371. $this->service->expects(self::once())
  372. ->method('getFrom');
  373. $this->service->expects(self::once())
  374. ->method('addSubjectAndHeading')
  375. ->with($this->emailTemplate, 'request', 'Mr. Wizard', 'Fellowship meeting without (!) Boromir');
  376. $this->service->expects(self::once())
  377. ->method('addBulletList')
  378. ->with($this->emailTemplate, $newVevent, $data);
  379. $this->service->expects(self::once())
  380. ->method('getAttendeeRsvpOrReqForParticipant')
  381. ->willReturn(true);
  382. $this->config->expects(self::once())
  383. ->method('getAppValue')
  384. ->with('dav', 'invitation_link_recipients', 'yes')
  385. ->willReturn('yes');
  386. $this->service->expects(self::once())
  387. ->method('createInvitationToken')
  388. ->with($message, $newVevent, '1496912700')
  389. ->willReturn('token');
  390. $this->service->expects(self::once())
  391. ->method('addResponseButtons')
  392. ->with($this->emailTemplate, 'token');
  393. $this->service->expects(self::once())
  394. ->method('addMoreOptionsButton')
  395. ->with($this->emailTemplate, 'token');
  396. $this->mailer->expects(self::once())
  397. ->method('send')
  398. ->willReturn([]);
  399. $this->mailer
  400. ->method('send')
  401. ->willThrowException(new \Exception());
  402. $this->logger->expects(self::once())
  403. ->method('error');
  404. $this->plugin->schedule($message);
  405. $this->assertEquals('5.0', $message->getScheduleStatus());
  406. }
  407. public function testNoOldEvent(): void {
  408. $message = new Message();
  409. $message->method = 'REQUEST';
  410. $newVCalendar = new VCalendar();
  411. $newVevent = new VEvent($newVCalendar, 'VEVENT', array_merge([
  412. 'UID' => 'uid-1234',
  413. 'SEQUENCE' => 1,
  414. 'SUMMARY' => 'Fellowship meeting',
  415. 'DTSTART' => new \DateTime('2016-01-01 00:00:00')
  416. ], []));
  417. $newVevent->add('ORGANIZER', 'mailto:gandalf@wiz.ard');
  418. $newVevent->add('ATTENDEE', 'mailto:' . 'frodo@hobb.it', ['RSVP' => 'TRUE', 'CN' => 'Frodo']);
  419. $message->message = $newVCalendar;
  420. $message->sender = 'mailto:gandalf@wiz.ard';
  421. $message->senderName = 'Mr. Wizard';
  422. $message->recipient = 'mailto:' . 'frodo@hobb.it';
  423. $data = ['invitee_name' => 'Mr. Wizard',
  424. 'meeting_title' => 'Fellowship meeting',
  425. 'attendee_name' => 'frodo@hobb.it'
  426. ];
  427. $this->service->expects(self::once())
  428. ->method('getLastOccurrence')
  429. ->willReturn('1496912700');
  430. $this->mailer->expects(self::once())
  431. ->method('validateMailAddress')
  432. ->with('frodo@hobb.it')
  433. ->willReturn(true);
  434. $this->eventComparisonService->expects(self::once())
  435. ->method('findModified')
  436. ->with($newVCalendar, null)
  437. ->willReturn(['old' => [] ,'new' => [$newVevent]]);
  438. $this->service->expects(self::once())
  439. ->method('buildBodyData')
  440. ->with($newVevent, null)
  441. ->willReturn($data);
  442. $this->userManager->expects(self::never())
  443. ->method('getDisplayName');
  444. $this->service->expects(self::once())
  445. ->method('getFrom');
  446. $this->service->expects(self::once())
  447. ->method('addSubjectAndHeading')
  448. ->with($this->emailTemplate, 'request', 'Mr. Wizard', 'Fellowship meeting');
  449. $this->service->expects(self::once())
  450. ->method('addBulletList')
  451. ->with($this->emailTemplate, $newVevent, $data);
  452. $this->service->expects(self::once())
  453. ->method('getAttendeeRsvpOrReqForParticipant')
  454. ->willReturn(true);
  455. $this->config->expects(self::once())
  456. ->method('getAppValue')
  457. ->with('dav', 'invitation_link_recipients', 'yes')
  458. ->willReturn('yes');
  459. $this->service->expects(self::once())
  460. ->method('createInvitationToken')
  461. ->with($message, $newVevent, '1496912700')
  462. ->willReturn('token');
  463. $this->service->expects(self::once())
  464. ->method('addResponseButtons')
  465. ->with($this->emailTemplate, 'token');
  466. $this->service->expects(self::once())
  467. ->method('addMoreOptionsButton')
  468. ->with($this->emailTemplate, 'token');
  469. $this->mailer->expects(self::once())
  470. ->method('send')
  471. ->willReturn([]);
  472. $this->mailer
  473. ->method('send')
  474. ->willReturn([]);
  475. $this->plugin->schedule($message);
  476. $this->assertEquals('1.1', $message->getScheduleStatus());
  477. }
  478. public function testNoButtons(): void {
  479. $message = new Message();
  480. $message->method = 'REQUEST';
  481. $newVCalendar = new VCalendar();
  482. $newVevent = new VEvent($newVCalendar, 'VEVENT', array_merge([
  483. 'UID' => 'uid-1234',
  484. 'SEQUENCE' => 1,
  485. 'SUMMARY' => 'Fellowship meeting',
  486. 'DTSTART' => new \DateTime('2016-01-01 00:00:00')
  487. ], []));
  488. $newVevent->add('ORGANIZER', 'mailto:gandalf@wiz.ard');
  489. $newVevent->add('ATTENDEE', 'mailto:' . 'frodo@hobb.it', ['RSVP' => 'TRUE', 'CN' => 'Frodo']);
  490. $message->message = $newVCalendar;
  491. $message->sender = 'mailto:gandalf@wiz.ard';
  492. $message->recipient = 'mailto:' . 'frodo@hobb.it';
  493. $data = ['invitee_name' => 'Mr. Wizard',
  494. 'meeting_title' => 'Fellowship meeting',
  495. 'attendee_name' => 'frodo@hobb.it'
  496. ];
  497. $this->service->expects(self::once())
  498. ->method('getLastOccurrence')
  499. ->willReturn('1496912700');
  500. $this->mailer->expects(self::once())
  501. ->method('validateMailAddress')
  502. ->with('frodo@hobb.it')
  503. ->willReturn(true);
  504. $this->eventComparisonService->expects(self::once())
  505. ->method('findModified')
  506. ->with($newVCalendar, null)
  507. ->willReturn(['old' => [] ,'new' => [$newVevent]]);
  508. $this->service->expects(self::once())
  509. ->method('buildBodyData')
  510. ->with($newVevent, null)
  511. ->willReturn($data);
  512. $this->userManager->expects(self::once())
  513. ->method('getDisplayName')
  514. ->willReturn('Mr. Wizard');
  515. $this->service->expects(self::once())
  516. ->method('getFrom');
  517. $this->service->expects(self::once())
  518. ->method('addSubjectAndHeading')
  519. ->with($this->emailTemplate, 'request', 'Mr. Wizard', 'Fellowship meeting');
  520. $this->service->expects(self::once())
  521. ->method('addBulletList')
  522. ->with($this->emailTemplate, $newVevent, $data);
  523. $this->service->expects(self::once())
  524. ->method('getAttendeeRsvpOrReqForParticipant')
  525. ->willReturn(true);
  526. $this->config->expects(self::once())
  527. ->method('getAppValue')
  528. ->with('dav', 'invitation_link_recipients', 'yes')
  529. ->willReturn('no');
  530. $this->service->expects(self::never())
  531. ->method('createInvitationToken');
  532. $this->service->expects(self::never())
  533. ->method('addResponseButtons');
  534. $this->service->expects(self::never())
  535. ->method('addMoreOptionsButton');
  536. $this->mailer->expects(self::once())
  537. ->method('send')
  538. ->willReturn([]);
  539. $this->mailer
  540. ->method('send')
  541. ->willReturn([]);
  542. $this->plugin->schedule($message);
  543. $this->assertEquals('1.1', $message->getScheduleStatus());
  544. }
  545. }