ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
CalendarTest.php
Go to the documentation of this file.
1<?php
2
3namespace Sabre\CalDAV;
4
6
7require_once 'Sabre/CalDAV/TestUtil.php';
8
10
14 protected $backend;
19 protected $calendar;
23 protected $calendars;
24
25 function setup() {
26
27 $this->backend = TestUtil::getBackend();
28
29 $this->calendars = $this->backend->getCalendarsForUser('principals/user1');
30 $this->assertEquals(2, count($this->calendars));
31 $this->calendar = new Calendar($this->backend, $this->calendars[0]);
32
33
34 }
35
36 function teardown() {
37
38 unset($this->backend);
39
40 }
41
42 function testSimple() {
43
44 $this->assertEquals($this->calendars[0]['uri'], $this->calendar->getName());
45
46 }
47
52
53 $propPatch = new PropPatch([
54 '{DAV:}displayname' => 'NewName',
55 ]);
56
57 $result = $this->calendar->propPatch($propPatch);
58 $result = $propPatch->commit();
59
60 $this->assertEquals(true, $result);
61
62 $calendars2 = $this->backend->getCalendarsForUser('principals/user1');
63 $this->assertEquals('NewName', $calendars2[0]['{DAV:}displayname']);
64
65 }
66
70 function testGetProperties() {
71
72 $question = [
73 '{urn:ietf:params:xml:ns:caldav}supported-calendar-component-set',
74 ];
75
76 $result = $this->calendar->getProperties($question);
77
78 foreach ($question as $q) $this->assertArrayHasKey($q, $result);
79
80 $this->assertEquals(['VEVENT', 'VTODO'], $result['{urn:ietf:params:xml:ns:caldav}supported-calendar-component-set']->getValue());
81
82 }
83
89
90 $this->calendar->getChild('randomname');
91
92 }
93
97 function testGetChildren() {
98
99 $children = $this->calendar->getChildren();
100 $this->assertEquals(1, count($children));
101
102 $this->assertTrue($children[0] instanceof CalendarObject);
103
104 }
105
109 function testChildExists() {
110
111 $this->assertFalse($this->calendar->childExists('foo'));
112
113 $children = $this->calendar->getChildren();
114 $this->assertTrue($this->calendar->childExists($children[0]->getName()));
115 }
116
117
118
123
124 $this->calendar->createDirectory('hello');
125
126 }
127
131 function testSetName() {
132
133 $this->calendar->setName('hello');
134
135 }
136
138
139 $this->assertNull($this->calendar->getLastModified());
140
141 }
142
143 function testCreateFile() {
144
145 $file = fopen('php://memory', 'r+');
146 fwrite($file, TestUtil::getTestCalendarData());
147 rewind($file);
148
149 $this->calendar->createFile('hello', $file);
150
151 $file = $this->calendar->getChild('hello');
152 $this->assertTrue($file instanceof CalendarObject);
153
154 }
155
157
158 $file = fopen('php://memory', 'r+');
159 fwrite($file, TestUtil::getTestCalendarData());
160 rewind($file);
161
162 $calendar = new Calendar($this->backend, $this->calendars[1]);
163 $calendar->createFile('hello', $file);
164
165 $file = $calendar->getChild('hello');
166 $this->assertTrue($file instanceof CalendarObject);
167
168 }
169
170 function testDelete() {
171
172 $this->calendar->delete();
173
174 $calendars = $this->backend->getCalendarsForUser('principals/user1');
175 $this->assertEquals(1, count($calendars));
176 }
177
178 function testGetOwner() {
179
180 $this->assertEquals('principals/user1', $this->calendar->getOwner());
181
182 }
183
184 function testGetGroup() {
185
186 $this->assertNull($this->calendar->getGroup());
187
188 }
189
190 function testGetACL() {
191
192 $expected = [
193 [
194 'privilege' => '{DAV:}read',
195 'principal' => 'principals/user1',
196 'protected' => true,
197 ],
198 [
199 'privilege' => '{DAV:}read',
200 'principal' => 'principals/user1/calendar-proxy-write',
201 'protected' => true,
202 ],
203 [
204 'privilege' => '{DAV:}read',
205 'principal' => 'principals/user1/calendar-proxy-read',
206 'protected' => true,
207 ],
208 [
209 'privilege' => '{' . Plugin::NS_CALDAV . '}read-free-busy',
210 'principal' => '{DAV:}authenticated',
211 'protected' => true,
212 ],
213 [
214 'privilege' => '{DAV:}write',
215 'principal' => 'principals/user1',
216 'protected' => true,
217 ],
218 [
219 'privilege' => '{DAV:}write',
220 'principal' => 'principals/user1/calendar-proxy-write',
221 'protected' => true,
222 ],
223 ];
224 $this->assertEquals($expected, $this->calendar->getACL());
225
226 }
227
231 function testSetACL() {
232
233 $this->calendar->setACL([]);
234
235 }
236
237 function testGetSyncToken() {
238
239 $this->assertNull($this->calendar->getSyncToken());
240
241 }
242
244
245 $calendar = new Calendar(new Backend\Mock([], []), []);
246 $this->assertNull($calendar->getSyncToken());
247
248 }
249
250 function testGetChanges() {
251
252 $this->assertNull($this->calendar->getChanges(1, 1));
253
254 }
255
256}
$result
An exception for terminatinating execution or to throw for unit testing.
The CalendarObject represents a single VEVENT or VTODO within a Calendar.
testGetChildren()
@depends testSimple
testUpdateProperties()
@depends testSimple
testSetName()
@expectedException Sabre\DAV\Exception\MethodNotAllowed
testSetACL()
@expectedException \Sabre\DAV\Exception\Forbidden
testChildExists()
@depends testGetChildren
testGetChildNotFound()
@expectedException Sabre\DAV\Exception\NotFound @depends testSimple
testCreateDirectory()
@expectedException Sabre\DAV\Exception\MethodNotAllowed
testGetProperties()
@depends testSimple
This object represents a CalDAV calendar.
Definition: Calendar.php:19
const NS_CALDAV
This is the official CalDAV namespace.
Definition: Plugin.php:33
static getTestCalendarData($type=1)
Definition: TestUtil.php:35
static getBackend()
Definition: TestUtil.php:7
This class represents a set of properties that are going to be updated.
Definition: PropPatch.php:20