1<?php
2
3namespace Sabre\CalDAV;
4use Sabre\HTTP;
5use Sabre\VObject;
6
7/**
8 * This unittests is created to find out why recurring events have wrong DTSTART value
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 ExpandEventsDTSTARTandDTENDbyDayTest 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:foobar
34DTEND;TZID=Europe/Berlin:20120207T191500
35RRULE:FREQ=WEEKLY;INTERVAL=1;BYDAY=TU,TH
36SUMMARY:RecurringEvents on tuesday and thursday
37DTSTART;TZID=Europe/Berlin:20120207T181500
38END:VEVENT
39END:VCALENDAR
40',
41            ),
42        ),
43    );
44
45    function testExpandRecurringByDayEvent() {
46
47        $request = HTTP\Sapi::createFromServerArray(array(
48            'REQUEST_METHOD' => 'REPORT',
49            'HTTP_CONTENT_TYPE' => 'application/xml',
50            'REQUEST_URI' => '/calendars/user1/calendar1',
51            'HTTP_DEPTH' => '1',
52        ));
53
54        $request->setBody('<?xml version="1.0" encoding="utf-8" ?>
55<C:calendar-query xmlns:D="DAV:" xmlns:C="urn:ietf:params:xml:ns:caldav">
56    <D:prop>
57        <C:calendar-data>
58            <C:expand start="20120210T230000Z" end="20120217T225959Z"/>
59        </C:calendar-data>
60        <D:getetag/>
61    </D:prop>
62    <C:filter>
63        <C:comp-filter name="VCALENDAR">
64            <C:comp-filter name="VEVENT">
65                <C:time-range start="20120210T230000Z" end="20120217T225959Z"/>
66            </C:comp-filter>
67        </C:comp-filter>
68    </C:filter>
69</C:calendar-query>');
70
71        $response = $this->request($request);
72
73        // Everts super awesome xml parser.
74        $body = substr(
75            $response->body,
76            $start = strpos($response->body, 'BEGIN:VCALENDAR'),
77            strpos($response->body, 'END:VCALENDAR') - $start + 13
78        );
79        $body = str_replace('&#13;','',$body);
80
81        $vObject = VObject\Reader::read($body);
82
83        $this->assertEquals(2, count($vObject->VEVENT));
84
85        // check if DTSTARTs and DTENDs are correct
86        foreach ($vObject->VEVENT as $vevent) {
87            /** @var $vevent Sabre\VObject\Component\VEvent */
88            foreach ($vevent->children as $child) {
89                /** @var $child Sabre\VObject\Property */
90
91                if ($child->name == 'DTSTART') {
92                    // DTSTART has to be one of two valid values
93                    $this->assertContains($child->getValue(), array('20120214T171500Z', '20120216T171500Z'), 'DTSTART is not a valid value: '.$child->getValue());
94                } elseif ($child->name == 'DTEND') {
95                    // DTEND has to be one of two valid values
96                    $this->assertContains($child->getValue(), array('20120214T181500Z', '20120216T181500Z'), 'DTEND is not a valid value: '.$child->getValue());
97                }
98            }
99        }
100    }
101
102}
103
104