ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
FreeBusyReportTest.php
Go to the documentation of this file.
1<?php
2
3namespace Sabre\CalDAV;
4
5use Sabre\DAV;
6use Sabre\HTTP;
7
8require_once 'Sabre/CalDAV/Backend/Mock.php';
9require_once 'Sabre/HTTP/ResponseMock.php';
10
12
16 protected $plugin;
20 protected $server;
21
22 function setUp() {
23
24 $obj1 = <<<ics
25BEGIN:VCALENDAR
26BEGIN:VEVENT
27DTSTART:20111005T120000Z
28DURATION:PT1H
29END:VEVENT
30END:VCALENDAR
31ics;
32
33 $obj2 = fopen('php://memory', 'r+');
34 fwrite($obj2, <<<ics
35BEGIN:VCALENDAR
36BEGIN:VEVENT
37DTSTART:20121005T120000Z
38DURATION:PT1H
39END:VEVENT
40END:VCALENDAR
41ics
42 );
43 rewind($obj2);
44
45 $obj3 = <<<ics
46BEGIN:VCALENDAR
47BEGIN:VEVENT
48DTSTART:20111006T120000
49DURATION:PT1H
50END:VEVENT
51END:VCALENDAR
52ics;
53
54 $calendarData = [
55 1 => [
56 'obj1' => [
57 'calendarid' => 1,
58 'uri' => 'event1.ics',
59 'calendardata' => $obj1,
60 ],
61 'obj2' => [
62 'calendarid' => 1,
63 'uri' => 'event2.ics',
64 'calendardata' => $obj2
65 ],
66 'obj3' => [
67 'calendarid' => 1,
68 'uri' => 'event3.ics',
69 'calendardata' => $obj3
70 ]
71 ],
72 ];
73
74
75 $caldavBackend = new Backend\Mock([], $calendarData);
76
78 'id' => 1,
79 'uri' => 'calendar',
80 'principaluri' => 'principals/user1',
81 '{' . Plugin::NS_CALDAV . '}calendar-timezone' => "BEGIN:VCALENDAR\r\nBEGIN:VTIMEZONE\r\nTZID:Europe/Berlin\r\nEND:VTIMEZONE\r\nEND:VCALENDAR",
82 ]);
83
84 $this->server = new DAV\Server([$calendar]);
85
87 'REQUEST_URI' => '/calendar',
88 ]);
89 $this->server->httpRequest = $request;
90 $this->server->httpResponse = new HTTP\ResponseMock();
91
92 $this->plugin = new Plugin();
93 $this->server->addPlugin($this->plugin);
94
95 }
96
97 function testFreeBusyReport() {
98
99 $reportXML = <<<XML
100<?xml version="1.0"?>
101<c:free-busy-query xmlns:c="urn:ietf:params:xml:ns:caldav">
102 <c:time-range start="20111001T000000Z" end="20111101T000000Z" />
103</c:free-busy-query>
104XML;
105
106 $report = $this->server->xml->parse($reportXML, null, $rootElem);
107 $this->plugin->report($rootElem, $report, null);
108
109 $this->assertEquals(200, $this->server->httpResponse->status);
110 $this->assertEquals('text/calendar', $this->server->httpResponse->getHeader('Content-Type'));
111 $this->assertTrue(strpos($this->server->httpResponse->body, 'BEGIN:VFREEBUSY') !== false);
112 $this->assertTrue(strpos($this->server->httpResponse->body, '20111005T120000Z/20111005T130000Z') !== false);
113 $this->assertTrue(strpos($this->server->httpResponse->body, '20111006T100000Z/20111006T110000Z') !== false);
114
115 }
116
121
122 $reportXML = <<<XML
123<?xml version="1.0"?>
124<c:free-busy-query xmlns:c="urn:ietf:params:xml:ns:caldav">
125</c:free-busy-query>
126XML;
127
128 $report = $this->server->xml->parse($reportXML, null, $rootElem);
129
130 }
131
136
138 'REQUEST_URI' => '/',
139 ]);
140 $this->server->httpRequest = $request;
141
142 $reportXML = <<<XML
143<?xml version="1.0"?>
144<c:free-busy-query xmlns:c="urn:ietf:params:xml:ns:caldav">
145 <c:time-range start="20111001T000000Z" end="20111101T000000Z" />
146</c:free-busy-query>
147XML;
148
149 $report = $this->server->xml->parse($reportXML, null, $rootElem);
150 $this->plugin->report($rootElem, $report, null);
151
152 }
153
158
159 $this->server = new DAV\Server();
160 $this->plugin = new Plugin();
161 $this->server->addPlugin($this->plugin);
162
163 $reportXML = <<<XML
164<?xml version="1.0"?>
165<c:free-busy-query xmlns:c="urn:ietf:params:xml:ns:caldav">
166 <c:time-range start="20111001T000000Z" end="20111101T000000Z" />
167</c:free-busy-query>
168XML;
169
170 $report = $this->server->xml->parse($reportXML, null, $rootElem);
171 $this->plugin->report($rootElem, $report, null);
172
173 }
174}
foreach($paths as $path) $request
Definition: asyncclient.php:32
An exception for terminatinating execution or to throw for unit testing.
This object represents a CalDAV calendar.
Definition: Calendar.php:19
testFreeBusyReportNoTimeRange()
@expectedException Sabre\DAV\Exception\BadRequest
testFreeBusyReportNoACLPlugin()
@expectedException Sabre\DAV\Exception
testFreeBusyReportWrongNode()
@expectedException Sabre\DAV\Exception\NotImplemented
CalDAV plugin.
Definition: Plugin.php:28
const NS_CALDAV
This is the official CalDAV namespace.
Definition: Plugin.php:33
Main DAV server class.
Definition: Server.php:23
static createFromServerArray(array $serverArray)
This static method will create a new Request object, based on a PHP $_SERVER array.
Definition: Sapi.php:107
$caldavBackend