1<?php
2
3namespace Sabre\CalDAV;
4use Sabre\HTTP;
5use Sabre\VObject;
6
7/**
8 * This unittest is created to find out why an overwritten DAILY event has wrong DTSTART, DTEND, SUMMARY and RECURRENCEID
9 *
10 * @copyright Copyright (C) 2007-2015 fruux GmbH (https://fruux.com/).
11 * @author Evert Pot (http://evertpot.com/)
12 * @license http://sabre.io/license/ Modified BSD License
13 */
14class Issue203Test extends \Sabre\DAVServerTest {
15
16    protected $setupCalDAV = true;
17
18    protected $caldavCalendars = array(
19        array(
20            'id' => 1,
21            'name' => 'Calendar',
22            'principaluri' => 'principals/user1',
23            'uri' => 'calendar1',
24        )
25    );
26
27    protected $caldavCalendarObjects = array(
28        1 => array(
29            'event.ics' => array(
30                'calendardata' => 'BEGIN:VCALENDAR
31VERSION:2.0
32BEGIN:VEVENT
33UID:20120330T155305CEST-6585fBUVgV
34DTSTAMP:20120330T135305Z
35DTSTART;TZID=Europe/Berlin:20120326T155200
36DTEND;TZID=Europe/Berlin:20120326T165200
37RRULE:FREQ=DAILY;COUNT=2;INTERVAL=1
38SUMMARY:original summary
39TRANSP:OPAQUE
40END:VEVENT
41BEGIN:VEVENT
42UID:20120330T155305CEST-6585fBUVgV
43DTSTAMP:20120330T135352Z
44DESCRIPTION:
45DTSTART;TZID=Europe/Berlin:20120328T155200
46DTEND;TZID=Europe/Berlin:20120328T165200
47RECURRENCE-ID;TZID=Europe/Berlin:20120327T155200
48SEQUENCE:1
49SUMMARY:overwritten summary
50TRANSP:OPAQUE
51END:VEVENT
52END:VCALENDAR
53',
54            ),
55        ),
56    );
57
58    function testIssue203() {
59
60        $request = HTTP\Sapi::createFromServerArray(array(
61            'REQUEST_METHOD' => 'REPORT',
62            'HTTP_CONTENT_TYPE' => 'application/xml',
63            'REQUEST_URI' => '/calendars/user1/calendar1',
64            'HTTP_DEPTH' => '1',
65        ));
66
67        $request->setBody('<?xml version="1.0" encoding="utf-8" ?>
68<C:calendar-query xmlns:D="DAV:" xmlns:C="urn:ietf:params:xml:ns:caldav">
69    <D:prop>
70        <C:calendar-data>
71            <C:expand start="20120325T220000Z" end="20120401T215959Z"/>
72        </C:calendar-data>
73        <D:getetag/>
74    </D:prop>
75    <C:filter>
76        <C:comp-filter name="VCALENDAR">
77            <C:comp-filter name="VEVENT">
78                <C:time-range start="20120325T220000Z" end="20120401T215959Z"/>
79            </C:comp-filter>
80        </C:comp-filter>
81    </C:filter>
82</C:calendar-query>');
83
84        $response = $this->request($request);
85
86        // Everts super awesome xml parser.
87        $body = substr(
88            $response->body,
89            $start = strpos($response->body, 'BEGIN:VCALENDAR'),
90            strpos($response->body, 'END:VCALENDAR') - $start + 13
91        );
92        $body = str_replace('&#13;','',$body);
93
94        $vObject = VObject\Reader::read($body);
95
96        $this->assertEquals(2, count($vObject->VEVENT));
97
98
99        $expectedEvents = array(
100            array(
101                'DTSTART' => '20120326T135200Z',
102                'DTEND'   => '20120326T145200Z',
103                'SUMMARY' => 'original summary',
104            ),
105            array(
106                'DTSTART'       => '20120328T135200Z',
107                'DTEND'         => '20120328T145200Z',
108                'SUMMARY'       => 'overwritten summary',
109                'RECURRENCE-ID' => '20120327T135200Z',
110            )
111        );
112
113        // try to match agains $expectedEvents array
114        foreach ($expectedEvents as $expectedEvent) {
115
116            $matching = false;
117
118            foreach ($vObject->VEVENT as $vevent) {
119                /** @var $vevent Sabre\VObject\Component\VEvent */
120
121                foreach ($vevent->children as $child) {
122                    /** @var $child Sabre\VObject\Property */
123
124                    if (isset($expectedEvent[$child->name])) {
125                        if ($expectedEvent[$child->name] != $child->getValue()) {
126                            continue 2;
127                        }
128                    }
129                }
130
131                $matching = true;
132                break;
133            }
134
135            $this->assertTrue($matching, 'Did not find the following event in the response: '.var_export($expectedEvent, true));
136        }
137    }
138}
139