xref: /plugin/davcal/vendor/sabre/dav/tests/Sabre/CalDAV/GetEventsByTimerangeTest.php (revision a1a3b6794e0e143a4a8b51d3185ce2d339be61ab)
1*a1a3b679SAndreas Boehler<?php
2*a1a3b679SAndreas Boehler
3*a1a3b679SAndreas Boehlernamespace Sabre\CalDAV;
4*a1a3b679SAndreas Boehleruse Sabre\HTTP;
5*a1a3b679SAndreas Boehleruse Sabre\VObject;
6*a1a3b679SAndreas Boehler
7*a1a3b679SAndreas Boehler/**
8*a1a3b679SAndreas Boehler * This unittest is created to check if queries for time-range include the start timestamp or not
9*a1a3b679SAndreas Boehler *
10*a1a3b679SAndreas Boehler * @copyright Copyright (C) 2007-2015 fruux GmbH (https://fruux.com/).
11*a1a3b679SAndreas Boehler * @author Evert Pot (http://evertpot.com/)
12*a1a3b679SAndreas Boehler * @license http://sabre.io/license/ Modified BSD License
13*a1a3b679SAndreas Boehler */
14*a1a3b679SAndreas Boehlerclass GetEventsByTimerangeTest extends \Sabre\DAVServerTest {
15*a1a3b679SAndreas Boehler
16*a1a3b679SAndreas Boehler    protected $setupCalDAV = true;
17*a1a3b679SAndreas Boehler
18*a1a3b679SAndreas Boehler    protected $caldavCalendars = array(
19*a1a3b679SAndreas Boehler        array(
20*a1a3b679SAndreas Boehler            'id' => 1,
21*a1a3b679SAndreas Boehler            'name' => 'Calendar',
22*a1a3b679SAndreas Boehler            'principaluri' => 'principals/user1',
23*a1a3b679SAndreas Boehler            'uri' => 'calendar1',
24*a1a3b679SAndreas Boehler        )
25*a1a3b679SAndreas Boehler    );
26*a1a3b679SAndreas Boehler
27*a1a3b679SAndreas Boehler    protected $caldavCalendarObjects = array(
28*a1a3b679SAndreas Boehler        1 => array(
29*a1a3b679SAndreas Boehler           'event.ics' => array(
30*a1a3b679SAndreas Boehler                'calendardata' => 'BEGIN:VCALENDAR
31*a1a3b679SAndreas BoehlerVERSION:2.0
32*a1a3b679SAndreas BoehlerBEGIN:VEVENT
33*a1a3b679SAndreas BoehlerCREATED:20120313T142342Z
34*a1a3b679SAndreas BoehlerUID:171EBEFC-C951-499D-B234-7BA7D677B45D
35*a1a3b679SAndreas BoehlerDTEND;TZID=Europe/Berlin:20120227T010000
36*a1a3b679SAndreas BoehlerTRANSP:OPAQUE
37*a1a3b679SAndreas BoehlerSUMMARY:Monday 0h
38*a1a3b679SAndreas BoehlerDTSTART;TZID=Europe/Berlin:20120227T000000
39*a1a3b679SAndreas BoehlerDTSTAMP:20120313T142416Z
40*a1a3b679SAndreas BoehlerSEQUENCE:4
41*a1a3b679SAndreas BoehlerEND:VEVENT
42*a1a3b679SAndreas BoehlerEND:VCALENDAR
43*a1a3b679SAndreas Boehler',
44*a1a3b679SAndreas Boehler            ),
45*a1a3b679SAndreas Boehler        ),
46*a1a3b679SAndreas Boehler    );
47*a1a3b679SAndreas Boehler
48*a1a3b679SAndreas Boehler    function testQueryTimerange() {
49*a1a3b679SAndreas Boehler
50*a1a3b679SAndreas Boehler        $request = new HTTP\Request(
51*a1a3b679SAndreas Boehler            'REPORT',
52*a1a3b679SAndreas Boehler            '/calendars/user1/calendar1',
53*a1a3b679SAndreas Boehler            [
54*a1a3b679SAndreas Boehler                'Content-Type' => 'application/xml',
55*a1a3b679SAndreas Boehler                'Depth'        => '1',
56*a1a3b679SAndreas Boehler            ]
57*a1a3b679SAndreas Boehler        );
58*a1a3b679SAndreas Boehler
59*a1a3b679SAndreas Boehler        $request->setBody('<?xml version="1.0" encoding="utf-8" ?>
60*a1a3b679SAndreas Boehler<C:calendar-query xmlns:D="DAV:" xmlns:C="urn:ietf:params:xml:ns:caldav">
61*a1a3b679SAndreas Boehler    <D:prop>
62*a1a3b679SAndreas Boehler        <C:calendar-data>
63*a1a3b679SAndreas Boehler            <C:expand start="20120226T220000Z" end="20120228T225959Z"/>
64*a1a3b679SAndreas Boehler        </C:calendar-data>
65*a1a3b679SAndreas Boehler        <D:getetag/>
66*a1a3b679SAndreas Boehler    </D:prop>
67*a1a3b679SAndreas Boehler    <C:filter>
68*a1a3b679SAndreas Boehler        <C:comp-filter name="VCALENDAR">
69*a1a3b679SAndreas Boehler            <C:comp-filter name="VEVENT">
70*a1a3b679SAndreas Boehler                <C:time-range start="20120226T220000Z" end="20120228T225959Z"/>
71*a1a3b679SAndreas Boehler            </C:comp-filter>
72*a1a3b679SAndreas Boehler        </C:comp-filter>
73*a1a3b679SAndreas Boehler    </C:filter>
74*a1a3b679SAndreas Boehler</C:calendar-query>');
75*a1a3b679SAndreas Boehler
76*a1a3b679SAndreas Boehler        $response = $this->request($request);
77*a1a3b679SAndreas Boehler
78*a1a3b679SAndreas Boehler        if (strpos($response->body, 'BEGIN:VCALENDAR') === false) {
79*a1a3b679SAndreas Boehler            $this->fail('Got no events instead of 1. Output: '.$response->body);
80*a1a3b679SAndreas Boehler        }
81*a1a3b679SAndreas Boehler
82*a1a3b679SAndreas Boehler        // Everts super awesome xml parser.
83*a1a3b679SAndreas Boehler        $body = substr(
84*a1a3b679SAndreas Boehler            $response->body,
85*a1a3b679SAndreas Boehler            $start = strpos($response->body, 'BEGIN:VCALENDAR'),
86*a1a3b679SAndreas Boehler            strpos($response->body, 'END:VCALENDAR') - $start + 13
87*a1a3b679SAndreas Boehler        );
88*a1a3b679SAndreas Boehler        $body = str_replace('&#13;','',$body);
89*a1a3b679SAndreas Boehler
90*a1a3b679SAndreas Boehler        $vObject = VObject\Reader::read($body);
91*a1a3b679SAndreas Boehler
92*a1a3b679SAndreas Boehler        // We expect 1 event
93*a1a3b679SAndreas Boehler        $this->assertEquals(1, count($vObject->VEVENT), 'We got 0 events instead of 1. Output: ' . $body);
94*a1a3b679SAndreas Boehler
95*a1a3b679SAndreas Boehler    }
96*a1a3b679SAndreas Boehler
97*a1a3b679SAndreas Boehler}
98*a1a3b679SAndreas Boehler
99