1<?php
2
3namespace Sabre\CalDAV;
4use Sabre\HTTP;
5use Sabre\VObject;
6
7/**
8 * This unittest is created to check if queries for time-range include the start timestamp or not
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 GetEventsByTimerangeTest 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
33CREATED:20120313T142342Z
34UID:171EBEFC-C951-499D-B234-7BA7D677B45D
35DTEND;TZID=Europe/Berlin:20120227T010000
36TRANSP:OPAQUE
37SUMMARY:Monday 0h
38DTSTART;TZID=Europe/Berlin:20120227T000000
39DTSTAMP:20120313T142416Z
40SEQUENCE:4
41END:VEVENT
42END:VCALENDAR
43',
44            ),
45        ),
46    );
47
48    function testQueryTimerange() {
49
50        $request = new HTTP\Request(
51            'REPORT',
52            '/calendars/user1/calendar1',
53            [
54                'Content-Type' => 'application/xml',
55                'Depth'        => '1',
56            ]
57        );
58
59        $request->setBody('<?xml version="1.0" encoding="utf-8" ?>
60<C:calendar-query xmlns:D="DAV:" xmlns:C="urn:ietf:params:xml:ns:caldav">
61    <D:prop>
62        <C:calendar-data>
63            <C:expand start="20120226T220000Z" end="20120228T225959Z"/>
64        </C:calendar-data>
65        <D:getetag/>
66    </D:prop>
67    <C:filter>
68        <C:comp-filter name="VCALENDAR">
69            <C:comp-filter name="VEVENT">
70                <C:time-range start="20120226T220000Z" end="20120228T225959Z"/>
71            </C:comp-filter>
72        </C:comp-filter>
73    </C:filter>
74</C:calendar-query>');
75
76        $response = $this->request($request);
77
78        if (strpos($response->body, 'BEGIN:VCALENDAR') === false) {
79            $this->fail('Got no events instead of 1. Output: '.$response->body);
80        }
81
82        // Everts super awesome xml parser.
83        $body = substr(
84            $response->body,
85            $start = strpos($response->body, 'BEGIN:VCALENDAR'),
86            strpos($response->body, 'END:VCALENDAR') - $start + 13
87        );
88        $body = str_replace('&#13;','',$body);
89
90        $vObject = VObject\Reader::read($body);
91
92        // We expect 1 event
93        $this->assertEquals(1, count($vObject->VEVENT), 'We got 0 events instead of 1. Output: ' . $body);
94
95    }
96
97}
98
99