1<?php
2
3namespace Sabre\CalDAV\Schedule;
4
5use
6    Sabre\HTTP\Request,
7    Sabre\VObject;
8
9class DeliverNewEventTest extends \Sabre\DAVServerTest {
10
11    public $setupCalDAV = true;
12    public $setupCalDAVScheduling = true;
13    public $setupACL = true;
14    public $autoLogin = 'user1';
15
16    function setUp() {
17
18        parent::setUp();
19        $this->caldavBackend->createCalendar(
20            'principals/user1',
21            'default',
22            [
23
24            ]
25        );
26        $this->caldavBackend->createCalendar(
27            'principals/user2',
28            'default',
29            [
30
31            ]
32        );
33
34    }
35
36    function testDelivery() {
37
38        $request = new Request('PUT', '/calendars/user1/default/foo.ics');
39        $request->setBody(<<<ICS
40BEGIN:VCALENDAR
41VERSION:2.0
42PRODID:-//Apple Inc.//Mac OS X 10.9.1//EN
43CALSCALE:GREGORIAN
44BEGIN:VEVENT
45CREATED:20140109T204404Z
46UID:AADC6438-18CF-4B52-8DD2-EF9AD75ADE83
47DTEND;TZID=America/Toronto:20140107T110000
48TRANSP:OPAQUE
49ATTENDEE;CN="Adminstrator";CUTYPE=INDIVIDUAL;PARTSTAT=ACCEPTED:mailto:user1.sabredav@sabredav.org
50ATTENDEE;CN="Roxy Kesh";CUTYPE=INDIVIDUAL;EMAIL="user2.sabredav@sabrdav.org";
51 PARTSTAT=NEEDS-ACTION;ROLE=REQ-PARTICIPANT;RSVP=TRUE:mailto:user2.sabredav@sabredav.org
52SUMMARY:Just testing!
53DTSTART;TZID=America/Toronto:20140107T100000
54DTSTAMP:20140109T204422Z
55ORGANIZER;CN="Administrator":mailto:user1.sabredav@sabredav.org
56SEQUENCE:4
57END:VEVENT
58END:VCALENDAR
59ICS
60    );
61
62        $messages = [];
63        $this->server->on('schedule', function($message) use (&$messages) {
64            $messages[] = $message;
65        });
66
67        $response = $this->request($request);
68
69        $this->assertEquals(201, $response->getStatus(), 'Incorrect status code received. Response body:' . $response->getBodyAsString());
70
71        $result = $this->request(new Request('GET', '/calendars/user1/default/foo.ics'))->getBody();
72        $resultVObj = VObject\Reader::read($result);
73
74        $this->assertEquals(
75            '1.2',
76            $resultVObj->VEVENT->ATTENDEE[1]['SCHEDULE-STATUS']->getValue()
77        );
78
79        $this->assertEquals(1, count($messages));
80        $message = $messages[0];
81
82        $this->assertInstanceOf('\Sabre\VObject\ITip\Message', $message);
83        $this->assertEquals('mailto:user2.sabredav@sabredav.org', $message->recipient);
84        $this->assertEquals('Roxy Kesh', $message->recipientName);
85        $this->assertEquals('mailto:user1.sabredav@sabredav.org', $message->sender);
86        $this->assertEquals('Administrator', $message->senderName);
87        $this->assertEquals('REQUEST', $message->method);
88
89        $this->assertEquals('REQUEST', $message->message->METHOD->getValue());
90
91    }
92
93}
94