]> git.mxchange.org Git - friendica-addons.git/blob - dav/SabreDAV/tests/Sabre/CalDAV/CalendarTest.php
Merge branch 'master' of git://github.com/friendica/friendica-addons
[friendica-addons.git] / dav / SabreDAV / tests / Sabre / CalDAV / CalendarTest.php
1 <?php
2
3 require_once 'Sabre/CalDAV/TestUtil.php';
4 require_once 'Sabre/DAVACL/MockPrincipalBackend.php';
5
6 class Sabre_CalDAV_CalendarTest extends PHPUnit_Framework_TestCase {
7
8     /**
9      * @var Sabre_CalDAV_Backend_PDO
10      */
11     protected $backend;
12     protected $principalBackend;
13     /**
14      * @var Sabre_CalDAV_Calendar
15      */
16     protected $calendar;
17     /**
18      * @var array
19      */
20     protected $calendars;
21
22     function setup() {
23
24         if (!SABRE_HASSQLITE) $this->markTestSkipped('SQLite driver is not available');
25         $this->backend = Sabre_CalDAV_TestUtil::getBackend();
26         $this->principalBackend = new Sabre_DAVACL_MockPrincipalBackend();
27
28         $this->calendars = $this->backend->getCalendarsForUser('principals/user1');
29         $this->assertEquals(2, count($this->calendars));
30         $this->calendar = new Sabre_CalDAV_Calendar($this->principalBackend, $this->backend, $this->calendars[0]);
31
32
33     }
34
35     function teardown() {
36
37         unset($this->backend);
38
39     }
40
41     function testSimple() {
42
43         $this->assertEquals($this->calendars[0]['uri'], $this->calendar->getName());
44
45     }
46
47     /**
48      * @depends testSimple
49      */
50     function testUpdateProperties() {
51
52         $result = $this->calendar->updateProperties(array(
53             '{DAV:}displayname' => 'NewName',
54         ));
55
56         $this->assertEquals(true, $result);
57
58         $calendars2 = $this->backend->getCalendarsForUser('principals/user1');
59         $this->assertEquals('NewName',$calendars2[0]['{DAV:}displayname']);
60
61     }
62
63     /**
64      * @depends testSimple
65      */
66     function testGetProperties() {
67
68         $question = array(
69             '{DAV:}owner',
70             '{urn:ietf:params:xml:ns:caldav}supported-calendar-component-set',
71             '{urn:ietf:params:xml:ns:caldav}supported-calendar-data',
72             '{urn:ietf:params:xml:ns:caldav}supported-collation-set',
73         );
74
75         $result = $this->calendar->getProperties($question);
76
77         foreach($question as $q) $this->assertArrayHasKey($q,$result);
78
79         $this->assertEquals(array('VEVENT','VTODO'), $result['{urn:ietf:params:xml:ns:caldav}supported-calendar-component-set']->getValue());
80
81         $this->assertTrue($result['{urn:ietf:params:xml:ns:caldav}supported-collation-set'] instanceof Sabre_CalDAV_Property_SupportedCollationSet);
82
83         $this->assertTrue($result['{DAV:}owner'] instanceof Sabre_DAVACL_Property_Principal);
84         $this->assertEquals('principals/user1', $result['{DAV:}owner']->getHref());
85
86     }
87
88     /**
89      * @expectedException Sabre_DAV_Exception_NotFound
90      * @depends testSimple
91      */
92     function testGetChildNotFound() {
93
94         $this->calendar->getChild('randomname');
95
96     }
97
98     /**
99      * @depends testSimple
100      */
101     function testGetChildren() {
102
103         $children = $this->calendar->getChildren();
104         $this->assertEquals(1,count($children));
105
106         $this->assertTrue($children[0] instanceof Sabre_CalDAV_CalendarObject);
107
108     }
109
110     /**
111      * @depends testGetChildren
112      */
113     function testChildExists() {
114
115         $this->assertFalse($this->calendar->childExists('foo'));
116
117         $children = $this->calendar->getChildren();
118         $this->assertTrue($this->calendar->childExists($children[0]->getName()));
119     }
120
121
122
123     /**
124      * @expectedException Sabre_DAV_Exception_MethodNotAllowed
125      */
126     function testCreateDirectory() {
127
128         $this->calendar->createDirectory('hello');
129
130     }
131
132     /**
133      * @expectedException Sabre_DAV_Exception_MethodNotAllowed
134      */
135     function testSetName() {
136
137         $this->calendar->setName('hello');
138
139     }
140
141     function testGetLastModified() {
142
143         $this->assertNull($this->calendar->getLastModified());
144
145     }
146
147     function testCreateFile() {
148
149         $file = fopen('php://memory','r+');
150         fwrite($file,Sabre_CalDAV_TestUtil::getTestCalendarData());
151         rewind($file);
152
153         $this->calendar->createFile('hello',$file);
154
155         $file = $this->calendar->getChild('hello');
156         $this->assertTrue($file instanceof Sabre_CalDAV_CalendarObject);
157
158     }
159
160     function testCreateFileNoSupportedComponents() {
161
162         $file = fopen('php://memory','r+');
163         fwrite($file,Sabre_CalDAV_TestUtil::getTestCalendarData());
164         rewind($file);
165
166         $calendar = new Sabre_CalDAV_Calendar($this->principalBackend, $this->backend, $this->calendars[1]);
167         $calendar->createFile('hello',$file);
168
169         $file = $calendar->getChild('hello');
170         $this->assertTrue($file instanceof Sabre_CalDAV_CalendarObject);
171
172     }
173
174     function testDelete() {
175
176         $this->calendar->delete();
177
178         $calendars = $this->backend->getCalendarsForUser('principals/user1');
179         $this->assertEquals(1, count($calendars));
180     }
181
182     function testGetOwner() {
183
184         $this->assertEquals('principals/user1',$this->calendar->getOwner());
185
186     }
187
188     function testGetGroup() {
189
190         $this->assertNull($this->calendar->getGroup());
191
192     }
193
194     function testGetACL() {
195
196         $expected = array(
197             array(
198                 'privilege' => '{DAV:}read',
199                 'principal' => 'principals/user1',
200                 'protected' => true,
201             ),
202             array(
203                 'privilege' => '{DAV:}write',
204                 'principal' => 'principals/user1',
205                 'protected' => true,
206             ),
207             array(
208                 'privilege' => '{DAV:}read',
209                 'principal' => 'principals/user1/calendar-proxy-write',
210                 'protected' => true,
211             ),
212             array(
213                 'privilege' => '{DAV:}write',
214                 'principal' => 'principals/user1/calendar-proxy-write',
215                 'protected' => true,
216             ),
217             array(
218                 'privilege' => '{DAV:}read',
219                 'principal' => 'principals/user1/calendar-proxy-read',
220                 'protected' => true,
221             ),
222             array(
223                 'privilege' => '{' . Sabre_CalDAV_Plugin::NS_CALDAV . '}read-free-busy',
224                 'principal' => '{DAV:}authenticated',
225                 'protected' => true,
226             ),
227         );
228         $this->assertEquals($expected, $this->calendar->getACL());
229
230     }
231
232     /**
233      * @expectedException Sabre_DAV_Exception_MethodNotAllowed
234      */
235     function testSetACL() {
236
237         $this->calendar->setACL(array());
238
239     }
240
241     function testGetSupportedPrivilegesSet() {
242
243         $result = $this->calendar->getSupportedPrivilegeSet();
244
245         $this->assertEquals(
246             '{' . Sabre_CalDAV_Plugin::NS_CALDAV . '}read-free-busy',
247             $result['aggregates'][0]['aggregates'][2]['privilege']
248         );
249
250     }
251
252
253 }