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