ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
JCalTransformTest.php
Go to the documentation of this file.
1<?php
2
3namespace Sabre\CalDAV;
4
7
9
10 use VObject\PHPUnitAssertions;
11
12 protected $setupCalDAV = true;
13 protected $caldavCalendars = [
14 [
15 'id' => 1,
16 'principaluri' => 'principals/user1',
17 'uri' => 'foo',
18 ]
19 ];
21 1 => [
22 'bar.ics' => [
23 'uri' => 'bar.ics',
24 'calendarid' => 1,
25 'calendardata' => "BEGIN:VCALENDAR\r\nBEGIN:VEVENT\r\nEND:VEVENT\r\nEND:VCALENDAR\r\n",
26 'lastmodified' => null
27 ]
28 ],
29 ];
30
31 function testGet() {
32
33 $headers = [
34 'Accept' => 'application/calendar+json',
35 ];
36 $request = new Request('GET', '/calendars/user1/foo/bar.ics', $headers);
37
38 $response = $this->request($request);
39
40 $body = $response->getBodyAsString();
41 $this->assertEquals(200, $response->getStatus(), "Incorrect status code: " . $body);
42
43 $response = json_decode($body, true);
44 if (json_last_error() !== JSON_ERROR_NONE) {
45 $this->fail('Json decoding error: ' . json_last_error_msg());
46 }
47 $this->assertEquals(
48 [
49 'vcalendar',
50 [],
51 [
52 [
53 'vevent',
54 [],
55 [],
56 ],
57 ],
58 ],
60 );
61
62 }
63
64 function testMultiGet() {
65
66 $xml = <<<XML
67<?xml version="1.0"?>
68<c:calendar-multiget xmlns:c="urn:ietf:params:xml:ns:caldav" xmlns:d="DAV:">
69 <d:prop>
70 <c:calendar-data content-type="application/calendar+json" />
71 </d:prop>
72 <d:href>/calendars/user1/foo/bar.ics</d:href>
73</c:calendar-multiget>
74XML;
75
76 $headers = [];
77 $request = new Request('REPORT', '/calendars/user1/foo', $headers, $xml);
78
79 $response = $this->request($request);
80
81 $this->assertEquals(207, $response->getStatus(), 'Full rsponse: ' . $response->getBodyAsString());
82
83 $multiStatus = $this->server->xml->parse(
84 $response->getBodyAsString()
85 );
86
87 $responses = $multiStatus->getResponses();
88 $this->assertEquals(1, count($responses));
89
90 $response = $responses[0]->getResponseProperties()[200]["{urn:ietf:params:xml:ns:caldav}calendar-data"];
91
92 $jresponse = json_decode($response, true);
93 if (json_last_error()) {
94 $this->fail('Json decoding error: ' . json_last_error_msg() . '. Full response: ' . $response);
95 }
96 $this->assertEquals(
97 [
98 'vcalendar',
99 [],
100 [
101 [
102 'vevent',
103 [],
104 [],
105 ],
106 ],
107 ],
108 $jresponse
109 );
110
111 }
112
114
115 $xml = <<<XML
116<?xml version="1.0"?>
117<c:calendar-query xmlns:c="urn:ietf:params:xml:ns:caldav" xmlns:d="DAV:">
118 <d:prop>
119 <c:calendar-data content-type="application/calendar+json" />
120 </d:prop>
121 <c:filter>
122 <c:comp-filter name="VCALENDAR" />
123 </c:filter>
124</c:calendar-query>
125XML;
126
127 $headers = [
128 'Depth' => '1',
129 ];
130 $request = new Request('REPORT', '/calendars/user1/foo', $headers, $xml);
131
132 $response = $this->request($request);
133
134 $this->assertEquals(207, $response->getStatus(), "Invalid response code. Full body: " . $response->getBodyAsString());
135
136 $multiStatus = $this->server->xml->parse(
137 $response->getBodyAsString()
138 );
139
140 $responses = $multiStatus->getResponses();
141
142 $this->assertEquals(1, count($responses));
143
144 $response = $responses[0]->getResponseProperties()[200]["{urn:ietf:params:xml:ns:caldav}calendar-data"];
145 $response = json_decode($response, true);
146 if (json_last_error()) {
147 $this->fail('Json decoding error: ' . json_last_error_msg());
148 }
149 $this->assertEquals(
150 [
151 'vcalendar',
152 [],
153 [
154 [
155 'vevent',
156 [],
157 [],
158 ],
159 ],
160 ],
162 );
163
164 }
165
167
168 $xml = <<<XML
169<?xml version="1.0"?>
170<c:calendar-query xmlns:c="urn:ietf:params:xml:ns:caldav" xmlns:d="DAV:">
171 <d:prop>
172 <c:calendar-data content-type="application/calendar+json" />
173 </d:prop>
174 <c:filter>
175 <c:comp-filter name="VCALENDAR" />
176 </c:filter>
177</c:calendar-query>
178XML;
179
180 $headers = [
181 'Depth' => '0',
182 ];
183 $request = new Request('REPORT', '/calendars/user1/foo/bar.ics', $headers, $xml);
184
185 $response = $this->request($request);
186
187 $this->assertEquals(207, $response->getStatus(), "Invalid response code. Full body: " . $response->getBodyAsString());
188
189 $multiStatus = $this->server->xml->parse(
190 $response->getBodyAsString()
191 );
192
193 $responses = $multiStatus->getResponses();
194
195 $this->assertEquals(1, count($responses));
196
197 $response = $responses[0]->getResponseProperties()[200]["{urn:ietf:params:xml:ns:caldav}calendar-data"];
198 $response = json_decode($response, true);
199 if (json_last_error()) {
200 $this->fail('Json decoding error: ' . json_last_error_msg());
201 }
202 $this->assertEquals(
203 [
204 'vcalendar',
205 [],
206 [
207 [
208 'vevent',
209 [],
210 [],
211 ],
212 ],
213 ],
215 );
216
217 }
218
220
221 $input = [
222 'vcalendar',
223 [],
224 [
225 [
226 'vevent',
227 [
228 ['uid', (object)[], 'text', 'foo'],
229 ['dtstart', (object)[], 'date', '2016-04-06'],
230 ],
231 [],
232 ],
233 ],
234 ];
235 $input = json_encode($input);
236 $this->caldavPlugin->beforeWriteContent(
237 'calendars/user1/foo/bar.ics',
238 $this->server->tree->getNodeForPath('calendars/user1/foo/bar.ics'),
239 $input,
240 $modified
241 );
242
243
244 $expected = <<<ICS
245BEGIN:VCALENDAR
246VERSION:2.0
247BEGIN:VEVENT
248UID:foo
249DTSTART;VALUE=DATE:20160406
250DTSTAMP:**ANY**
251END:VEVENT
252END:VCALENDAR
253ICS;
254
255 $this->assertVObjectEqualsVObject(
256 $expected,
257 $input
258 );
259
260 }
261
262}
foreach($paths as $path) $request
Definition: asyncclient.php:32
An exception for terminatinating execution or to throw for unit testing.
This class may be used as a basis for other webdav-related unittests.
request($request, $expectedStatus=null)
Makes a request, and returns a response object.
The Request class represents a single HTTP request.
Definition: Request.php:18
$response
$this data['403_header']