1<?php
2
3namespace Sabre\CalDAV;
4
5use Sabre\HTTP;
6use Sabre\VObject;
7
8/**
9 * This unittests is created to find out why certain events show up twice.
10 *
11 * Hopefully, by the time I'm done with this, I've both found the problem, and
12 * fixed it :)
13 *
14 * @copyright Copyright (C) 2007-2015 fruux GmbH (https://fruux.com/).
15 * @author Evert Pot (http://evertpot.com/)
16 * @license http://sabre.io/license/ Modified BSD License
17 */
18class ExpandEventsDoubleEventsTest extends \Sabre\DAVServerTest {
19
20    protected $setupCalDAV = true;
21
22    protected $caldavCalendars = array(
23        array(
24            'id' => 1,
25            'name' => 'Calendar',
26            'principaluri' => 'principals/user1',
27            'uri' => 'calendar1',
28        )
29    );
30
31    protected $caldavCalendarObjects = array(
32        1 => array(
33           'event.ics' => array(
34                'calendardata' => 'BEGIN:VCALENDAR
35VERSION:2.0
36BEGIN:VEVENT
37UID:foobar
38DTEND;TZID=Europe/Berlin:20120207T191500
39RRULE:FREQ=DAILY;INTERVAL=1;COUNT=3
40SUMMARY:RecurringEvents 3 times
41DTSTART;TZID=Europe/Berlin:20120207T181500
42END:VEVENT
43BEGIN:VEVENT
44CREATED:20120207T111900Z
45UID:foobar
46DTEND;TZID=Europe/Berlin:20120208T191500
47SUMMARY:RecurringEvents 3 times OVERWRITTEN
48DTSTART;TZID=Europe/Berlin:20120208T181500
49RECURRENCE-ID;TZID=Europe/Berlin:20120208T181500
50END:VEVENT
51END:VCALENDAR
52',
53            ),
54        ),
55    );
56
57    function testExpand() {
58
59        $request = HTTP\Sapi::createFromServerArray([
60            'REQUEST_METHOD' => 'REPORT',
61            'HTTP_CONTENT_TYPE' => 'application/xml',
62            'REQUEST_URI' => '/calendars/user1/calendar1',
63            'HTTP_DEPTH' => '1',
64        ]);
65
66        $request->setBody('<?xml version="1.0" encoding="utf-8" ?>
67<C:calendar-query xmlns:D="DAV:" xmlns:C="urn:ietf:params:xml:ns:caldav">
68    <D:prop>
69        <C:calendar-data>
70            <C:expand start="20120205T230000Z" end="20120212T225959Z"/>
71        </C:calendar-data>
72        <D:getetag/>
73    </D:prop>
74    <C:filter>
75        <C:comp-filter name="VCALENDAR">
76            <C:comp-filter name="VEVENT">
77                <C:time-range start="20120205T230000Z" end="20120212T225959Z"/>
78            </C:comp-filter>
79        </C:comp-filter>
80    </C:filter>
81</C:calendar-query>');
82
83        $response = $this->request($request);
84
85        // Everts super awesome xml parser.
86        $body = substr(
87            $response->body,
88            $start = strpos($response->body, 'BEGIN:VCALENDAR'),
89            strpos($response->body, 'END:VCALENDAR') - $start + 13
90        );
91        $body = str_replace('&#13;','',$body);
92
93        $vObject = VObject\Reader::read($body);
94
95        // We only expect 3 events
96        $this->assertEquals(3, count($vObject->VEVENT),'We got 6 events instead of 3. Output: ' . $body);
97
98        // TZID should be gone
99        $this->assertFalse(isset($vObject->VEVENT->DTSTART['TZID']));
100
101    }
102
103}
104
105