BrokerNewEventTest.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528
  1. <?php
  2. namespace Sabre\VObject\ITip;
  3. class BrokerNewEventTest extends \PHPUnit_Framework_TestCase {
  4. function testNoAttendee() {
  5. $message = <<<ICS
  6. BEGIN:VCALENDAR
  7. BEGIN:VEVENT
  8. UID:foobar
  9. DTSTART:20140811T220000Z
  10. DTEND:20140811T230000Z
  11. END:VEVENT
  12. END:VCALENDAR
  13. ICS;
  14. $result = $this->parse($message);
  15. }
  16. function testVTODO() {
  17. $message = <<<ICS
  18. BEGIN:VCALENDAR
  19. BEGIN:VTODO
  20. UID:foobar
  21. END:VTODO
  22. END:VCALENDAR
  23. ICS;
  24. $result = $this->parse($message);
  25. }
  26. function testSimpleInvite() {
  27. $message = <<<ICS
  28. BEGIN:VCALENDAR
  29. VERSION:2.0
  30. BEGIN:VEVENT
  31. UID:foobar
  32. DTSTART:20140811T220000Z
  33. DTEND:20140811T230000Z
  34. ORGANIZER;CN=Strunk:mailto:strunk@example.org
  35. ATTENDEE;CN=White:mailto:white@example.org
  36. END:VEVENT
  37. END:VCALENDAR
  38. ICS;
  39. $version = \Sabre\VObject\Version::VERSION;
  40. $expectedMessage = <<<ICS
  41. BEGIN:VCALENDAR
  42. VERSION:2.0
  43. PRODID:-//Sabre//Sabre VObject $version//EN
  44. CALSCALE:GREGORIAN
  45. METHOD:REQUEST
  46. BEGIN:VEVENT
  47. UID:foobar
  48. DTSTART:20140811T220000Z
  49. DTEND:20140811T230000Z
  50. ORGANIZER;CN=Strunk:mailto:strunk@example.org
  51. ATTENDEE;CN=White;PARTSTAT=NEEDS-ACTION:mailto:white@example.org
  52. END:VEVENT
  53. END:VCALENDAR
  54. ICS;
  55. $expected = array(
  56. array(
  57. 'uid' => 'foobar',
  58. 'method' => 'REQUEST',
  59. 'component' => 'VEVENT',
  60. 'sender' => 'mailto:strunk@example.org',
  61. 'senderName' => 'Strunk',
  62. 'recipient' => 'mailto:white@example.org',
  63. 'recipientName' => 'White',
  64. 'message' => $expectedMessage,
  65. ),
  66. );
  67. $result = $this->parse($message, $expected);
  68. }
  69. /**
  70. * @expectedException \Sabre\VObject\ITip\ITipException
  71. */
  72. function testBrokenEventUIDMisMatch() {
  73. $message = <<<ICS
  74. BEGIN:VCALENDAR
  75. VERSION:2.0
  76. BEGIN:VEVENT
  77. UID:foobar
  78. ORGANIZER;CN=Strunk:mailto:strunk@example.org
  79. ATTENDEE;CN=White:mailto:white@example.org
  80. END:VEVENT
  81. BEGIN:VEVENT
  82. UID:foobar2
  83. ORGANIZER;CN=Strunk:mailto:strunk@example.org
  84. ATTENDEE;CN=White:mailto:white@example.org
  85. END:VEVENT
  86. END:VCALENDAR
  87. ICS;
  88. $expected = array();
  89. $this->parse($message, array());
  90. }
  91. /**
  92. * @expectedException \Sabre\VObject\ITip\ITipException
  93. */
  94. function testBrokenEventOrganizerMisMatch() {
  95. $message = <<<ICS
  96. BEGIN:VCALENDAR
  97. VERSION:2.0
  98. BEGIN:VEVENT
  99. UID:foobar
  100. ORGANIZER;CN=Strunk:mailto:strunk@example.org
  101. ATTENDEE;CN=White:mailto:white@example.org
  102. END:VEVENT
  103. BEGIN:VEVENT
  104. UID:foobar
  105. ORGANIZER:mailto:foo@example.org
  106. ATTENDEE;CN=White:mailto:white@example.org
  107. END:VEVENT
  108. END:VCALENDAR
  109. ICS;
  110. $expected = array();
  111. $this->parse($message, array());
  112. }
  113. function testRecurrenceInvite() {
  114. $message = <<<ICS
  115. BEGIN:VCALENDAR
  116. VERSION:2.0
  117. BEGIN:VEVENT
  118. UID:foobar
  119. ORGANIZER;CN=Strunk:mailto:strunk@example.org
  120. ATTENDEE;CN=One:mailto:one@example.org
  121. ATTENDEE;CN=Two:mailto:two@example.org
  122. DTSTART:20140716T120000Z
  123. DURATION:PT1H
  124. RRULE:FREQ=DAILY
  125. EXDATE:20140717T120000Z
  126. END:VEVENT
  127. BEGIN:VEVENT
  128. UID:foobar
  129. RECURRENCE-ID:20140718T120000Z
  130. ORGANIZER;CN=Strunk:mailto:strunk@example.org
  131. ATTENDEE;CN=Two:mailto:two@example.org
  132. ATTENDEE;CN=Three:mailto:three@example.org
  133. DTSTART:20140718T120000Z
  134. DURATION:PT1H
  135. END:VEVENT
  136. END:VCALENDAR
  137. ICS;
  138. $version = \Sabre\VObject\Version::VERSION;
  139. $expected = array(
  140. array(
  141. 'uid' => 'foobar',
  142. 'method' => 'REQUEST',
  143. 'component' => 'VEVENT',
  144. 'sender' => 'mailto:strunk@example.org',
  145. 'senderName' => 'Strunk',
  146. 'recipient' => 'mailto:one@example.org',
  147. 'recipientName' => 'One',
  148. 'message' => <<<ICS
  149. BEGIN:VCALENDAR
  150. VERSION:2.0
  151. PRODID:-//Sabre//Sabre VObject $version//EN
  152. CALSCALE:GREGORIAN
  153. METHOD:REQUEST
  154. BEGIN:VEVENT
  155. UID:foobar
  156. ORGANIZER;CN=Strunk:mailto:strunk@example.org
  157. ATTENDEE;CN=One;PARTSTAT=NEEDS-ACTION:mailto:one@example.org
  158. ATTENDEE;CN=Two;PARTSTAT=NEEDS-ACTION:mailto:two@example.org
  159. DTSTART:20140716T120000Z
  160. DURATION:PT1H
  161. RRULE:FREQ=DAILY
  162. EXDATE:20140717T120000Z,20140718T120000Z
  163. END:VEVENT
  164. END:VCALENDAR
  165. ICS
  166. ),
  167. array(
  168. 'uid' => 'foobar',
  169. 'method' => 'REQUEST',
  170. 'component' => 'VEVENT',
  171. 'sender' => 'mailto:strunk@example.org',
  172. 'senderName' => 'Strunk',
  173. 'recipient' => 'mailto:two@example.org',
  174. 'recipientName' => 'Two',
  175. 'message' => <<<ICS
  176. BEGIN:VCALENDAR
  177. VERSION:2.0
  178. PRODID:-//Sabre//Sabre VObject $version//EN
  179. CALSCALE:GREGORIAN
  180. METHOD:REQUEST
  181. BEGIN:VEVENT
  182. UID:foobar
  183. ORGANIZER;CN=Strunk:mailto:strunk@example.org
  184. ATTENDEE;CN=One;PARTSTAT=NEEDS-ACTION:mailto:one@example.org
  185. ATTENDEE;CN=Two;PARTSTAT=NEEDS-ACTION:mailto:two@example.org
  186. DTSTART:20140716T120000Z
  187. DURATION:PT1H
  188. RRULE:FREQ=DAILY
  189. EXDATE:20140717T120000Z
  190. END:VEVENT
  191. BEGIN:VEVENT
  192. UID:foobar
  193. RECURRENCE-ID:20140718T120000Z
  194. ORGANIZER;CN=Strunk:mailto:strunk@example.org
  195. ATTENDEE;CN=Two:mailto:two@example.org
  196. ATTENDEE;CN=Three:mailto:three@example.org
  197. DTSTART:20140718T120000Z
  198. DURATION:PT1H
  199. END:VEVENT
  200. END:VCALENDAR
  201. ICS
  202. ),
  203. array(
  204. 'uid' => 'foobar',
  205. 'method' => 'REQUEST',
  206. 'component' => 'VEVENT',
  207. 'sender' => 'mailto:strunk@example.org',
  208. 'senderName' => 'Strunk',
  209. 'recipient' => 'mailto:three@example.org',
  210. 'recipientName' => 'Three',
  211. 'message' => <<<ICS
  212. BEGIN:VCALENDAR
  213. VERSION:2.0
  214. PRODID:-//Sabre//Sabre VObject $version//EN
  215. CALSCALE:GREGORIAN
  216. METHOD:REQUEST
  217. BEGIN:VEVENT
  218. UID:foobar
  219. RECURRENCE-ID:20140718T120000Z
  220. ORGANIZER;CN=Strunk:mailto:strunk@example.org
  221. ATTENDEE;CN=Two:mailto:two@example.org
  222. ATTENDEE;CN=Three:mailto:three@example.org
  223. DTSTART:20140718T120000Z
  224. DURATION:PT1H
  225. END:VEVENT
  226. END:VCALENDAR
  227. ICS
  228. ),
  229. );
  230. $result = $this->parse($message, $expected);
  231. }
  232. function testRecurrenceInvite2() {
  233. // This method tests a nearly identical path, but in this case the
  234. // master event does not have an EXDATE.
  235. $message = <<<ICS
  236. BEGIN:VCALENDAR
  237. VERSION:2.0
  238. BEGIN:VEVENT
  239. UID:foobar
  240. ORGANIZER;CN=Strunk:mailto:strunk@example.org
  241. ATTENDEE;CN=One:mailto:one@example.org
  242. ATTENDEE;CN=Two:mailto:two@example.org
  243. DTSTART:20140716T120000Z
  244. DTEND:20140716T130000Z
  245. RRULE:FREQ=DAILY
  246. END:VEVENT
  247. BEGIN:VEVENT
  248. UID:foobar
  249. RECURRENCE-ID:20140718T120000Z
  250. ORGANIZER;CN=Strunk:mailto:strunk@example.org
  251. ATTENDEE;CN=Two:mailto:two@example.org
  252. ATTENDEE;CN=Three:mailto:three@example.org
  253. DTSTART:20140718T120000Z
  254. DTEND:20140718T130000Z
  255. END:VEVENT
  256. END:VCALENDAR
  257. ICS;
  258. $version = \Sabre\VObject\Version::VERSION;
  259. $expected = array(
  260. array(
  261. 'uid' => 'foobar',
  262. 'method' => 'REQUEST',
  263. 'component' => 'VEVENT',
  264. 'sender' => 'mailto:strunk@example.org',
  265. 'senderName' => 'Strunk',
  266. 'recipient' => 'mailto:one@example.org',
  267. 'recipientName' => 'One',
  268. 'message' => <<<ICS
  269. BEGIN:VCALENDAR
  270. VERSION:2.0
  271. PRODID:-//Sabre//Sabre VObject $version//EN
  272. CALSCALE:GREGORIAN
  273. METHOD:REQUEST
  274. BEGIN:VEVENT
  275. UID:foobar
  276. ORGANIZER;CN=Strunk:mailto:strunk@example.org
  277. ATTENDEE;CN=One;PARTSTAT=NEEDS-ACTION:mailto:one@example.org
  278. ATTENDEE;CN=Two;PARTSTAT=NEEDS-ACTION:mailto:two@example.org
  279. DTSTART:20140716T120000Z
  280. DTEND:20140716T130000Z
  281. RRULE:FREQ=DAILY
  282. EXDATE:20140718T120000Z
  283. END:VEVENT
  284. END:VCALENDAR
  285. ICS
  286. ),
  287. array(
  288. 'uid' => 'foobar',
  289. 'method' => 'REQUEST',
  290. 'component' => 'VEVENT',
  291. 'sender' => 'mailto:strunk@example.org',
  292. 'senderName' => 'Strunk',
  293. 'recipient' => 'mailto:two@example.org',
  294. 'recipientName' => 'Two',
  295. 'message' => <<<ICS
  296. BEGIN:VCALENDAR
  297. VERSION:2.0
  298. PRODID:-//Sabre//Sabre VObject $version//EN
  299. CALSCALE:GREGORIAN
  300. METHOD:REQUEST
  301. BEGIN:VEVENT
  302. UID:foobar
  303. ORGANIZER;CN=Strunk:mailto:strunk@example.org
  304. ATTENDEE;CN=One;PARTSTAT=NEEDS-ACTION:mailto:one@example.org
  305. ATTENDEE;CN=Two;PARTSTAT=NEEDS-ACTION:mailto:two@example.org
  306. DTSTART:20140716T120000Z
  307. DTEND:20140716T130000Z
  308. RRULE:FREQ=DAILY
  309. END:VEVENT
  310. BEGIN:VEVENT
  311. UID:foobar
  312. RECURRENCE-ID:20140718T120000Z
  313. ORGANIZER;CN=Strunk:mailto:strunk@example.org
  314. ATTENDEE;CN=Two:mailto:two@example.org
  315. ATTENDEE;CN=Three:mailto:three@example.org
  316. DTSTART:20140718T120000Z
  317. DTEND:20140718T130000Z
  318. END:VEVENT
  319. END:VCALENDAR
  320. ICS
  321. ),
  322. array(
  323. 'uid' => 'foobar',
  324. 'method' => 'REQUEST',
  325. 'component' => 'VEVENT',
  326. 'sender' => 'mailto:strunk@example.org',
  327. 'senderName' => 'Strunk',
  328. 'recipient' => 'mailto:three@example.org',
  329. 'recipientName' => 'Three',
  330. 'message' => <<<ICS
  331. BEGIN:VCALENDAR
  332. VERSION:2.0
  333. PRODID:-//Sabre//Sabre VObject $version//EN
  334. CALSCALE:GREGORIAN
  335. METHOD:REQUEST
  336. BEGIN:VEVENT
  337. UID:foobar
  338. RECURRENCE-ID:20140718T120000Z
  339. ORGANIZER;CN=Strunk:mailto:strunk@example.org
  340. ATTENDEE;CN=Two:mailto:two@example.org
  341. ATTENDEE;CN=Three:mailto:three@example.org
  342. DTSTART:20140718T120000Z
  343. DTEND:20140718T130000Z
  344. END:VEVENT
  345. END:VCALENDAR
  346. ICS
  347. ),
  348. );
  349. $result = $this->parse($message, $expected);
  350. }
  351. function testScheduleAgentClient() {
  352. $message = <<<ICS
  353. BEGIN:VCALENDAR
  354. VERSION:2.0
  355. BEGIN:VEVENT
  356. UID:foobar
  357. DTSTART:20140811T220000Z
  358. DTEND:20140811T230000Z
  359. ORGANIZER;CN=Strunk:mailto:strunk@example.org
  360. ATTENDEE;CN=White;SCHEDULE-AGENT=CLIENT:mailto:white@example.org
  361. END:VEVENT
  362. END:VCALENDAR
  363. ICS;
  364. $version = \Sabre\VObject\Version::VERSION;
  365. $expected = array();
  366. $result = $this->parse($message, $expected);
  367. }
  368. /**
  369. * @expectedException Sabre\VObject\ITip\ITipException
  370. */
  371. function testMultipleUID() {
  372. $message = <<<ICS
  373. BEGIN:VCALENDAR
  374. VERSION:2.0
  375. BEGIN:VEVENT
  376. UID:foobar
  377. ORGANIZER;CN=Strunk:mailto:strunk@example.org
  378. ATTENDEE;CN=One:mailto:one@example.org
  379. ATTENDEE;CN=Two:mailto:two@example.org
  380. DTSTART:20140716T120000Z
  381. DTEND:20140716T130000Z
  382. RRULE:FREQ=DAILY
  383. END:VEVENT
  384. BEGIN:VEVENT
  385. UID:foobar2
  386. RECURRENCE-ID:20140718T120000Z
  387. ORGANIZER;CN=Strunk:mailto:strunk@example.org
  388. ATTENDEE;CN=Two:mailto:two@example.org
  389. ATTENDEE;CN=Three:mailto:three@example.org
  390. DTSTART:20140718T120000Z
  391. DTEND:20140718T130000Z
  392. END:VEVENT
  393. END:VCALENDAR
  394. ICS;
  395. $version = \Sabre\VObject\Version::VERSION;
  396. $result = $this->parse($message, array());
  397. }
  398. /**
  399. * @expectedException Sabre\VObject\ITip\SameOrganizerForAllComponentsException
  400. *
  401. */
  402. function testChangingOrganizers() {
  403. $message = <<<ICS
  404. BEGIN:VCALENDAR
  405. VERSION:2.0
  406. BEGIN:VEVENT
  407. UID:foobar
  408. ORGANIZER;CN=Strunk:mailto:strunk@example.org
  409. ATTENDEE;CN=One:mailto:one@example.org
  410. ATTENDEE;CN=Two:mailto:two@example.org
  411. DTSTART:20140716T120000Z
  412. DTEND:20140716T130000Z
  413. RRULE:FREQ=DAILY
  414. END:VEVENT
  415. BEGIN:VEVENT
  416. UID:foobar
  417. RECURRENCE-ID:20140718T120000Z
  418. ORGANIZER;CN=Strunk:mailto:ew@example.org
  419. ATTENDEE;CN=Two:mailto:two@example.org
  420. ATTENDEE;CN=Three:mailto:three@example.org
  421. DTSTART:20140718T120000Z
  422. DTEND:20140718T130000Z
  423. END:VEVENT
  424. END:VCALENDAR
  425. ICS;
  426. $version = \Sabre\VObject\Version::VERSION;
  427. $result = $this->parse($message, array());
  428. }
  429. function testNoOrganizerHasAttendee() {
  430. $message = <<<ICS
  431. BEGIN:VCALENDAR
  432. BEGIN:VEVENT
  433. UID:foobar
  434. DTSTART:20140811T220000Z
  435. DTEND:20140811T230000Z
  436. ATTENDEE;CN=Two:mailto:two@example.org
  437. END:VEVENT
  438. END:VCALENDAR
  439. ICS;
  440. $this->parse($message, array());
  441. }
  442. function parse($message, $expected = array()) {
  443. $broker = new Broker();
  444. $result = $broker->parseEvent($message, 'mailto:strunk@example.org');
  445. $this->assertEquals(count($expected), count($result));
  446. foreach($expected as $index=>$ex) {
  447. $message = $result[$index];
  448. foreach($ex as $key=>$val) {
  449. if ($key==='message') {
  450. $this->assertEquals(
  451. str_replace("\n", "\r\n", $val),
  452. rtrim($message->message->serialize(), "\r\n")
  453. );
  454. } else {
  455. $this->assertEquals($val, $message->$key);
  456. }
  457. }
  458. }
  459. }
  460. }