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