]> git.mxchange.org Git - friendica-addons.git/blob - dav/SabreDAV/tests/Sabre/CalDAV/UserCalendarsTest.php
Merge branch '3.6-release'
[friendica-addons.git] / dav / SabreDAV / tests / Sabre / CalDAV / UserCalendarsTest.php
1 <?php
2
3 require_once 'Sabre/CalDAV/TestUtil.php';
4 require_once 'Sabre/DAVACL/MockPrincipalBackend.php';
5
6 /**
7  * @covers Sabre_CalDAV_UserCalendars
8  */
9 class Sabre_CalDAV_UserCalendarsTest extends PHPUnit_Framework_TestCase {
10
11     /**
12      * @var Sabre_CalDAV_UserCalendars
13      */
14     protected $usercalendars;
15     /**
16      * @var Sabre_CalDAV_Backend_PDO
17      */
18     protected $backend;
19     protected $principalBackend;
20
21     function setup() {
22
23         if (!SABRE_HASSQLITE) $this->markTestSkipped('SQLite driver is not available');
24         $this->backend = Sabre_CalDAV_TestUtil::getBackend();
25         $this->principalBackend = new Sabre_DAVACL_MockPrincipalBackend('realm');
26         $this->usercalendars = new Sabre_CalDAV_UserCalendars($this->principalBackend, $this->backend, 'principals/user1');
27
28     }
29
30     function testSimple() {
31
32         $this->assertEquals('user1',$this->usercalendars->getName());
33
34     }
35
36     /**
37      * @expectedException Sabre_DAV_Exception_NotFound
38      * @depends testSimple
39      */
40     function testGetChildNotFound() {
41
42         $this->usercalendars->getChild('randomname');
43
44     }
45
46     function testChildExists() {
47
48         $this->assertFalse($this->usercalendars->childExists('foo'));
49         $this->assertTrue($this->usercalendars->childExists('UUID-123467'));
50
51     }
52
53     function testGetOwner() {
54
55         $this->assertEquals('principals/user1', $this->usercalendars->getOwner());
56
57     }
58
59     function testGetGroup() {
60
61         $this->assertNull($this->usercalendars->getGroup());
62
63     }
64
65     function testGetACL() {
66
67         $expected = array(
68             array(
69                 'privilege' => '{DAV:}read',
70                 'principal' => 'principals/user1',
71                 'protected' => true,
72             ),
73             array(
74                 'privilege' => '{DAV:}write',
75                 'principal' => 'principals/user1',
76                 'protected' => true,
77             ),
78             array(
79                 'privilege' => '{DAV:}read',
80                 'principal' => 'principals/user1/calendar-proxy-write',
81                 'protected' => true,
82             ),
83             array(
84                 'privilege' => '{DAV:}write',
85                 'principal' => 'principals/user1/calendar-proxy-write',
86                 'protected' => true,
87             ),
88             array(
89                 'privilege' => '{DAV:}read',
90                 'principal' => 'principals/user1/calendar-proxy-read',
91                 'protected' => true,
92             ),
93         );
94         $this->assertEquals($expected, $this->usercalendars->getACL());
95
96     }
97
98     /**
99      * @expectedException Sabre_DAV_Exception_MethodNotAllowed
100      */
101     function testSetACL() {
102
103         $this->usercalendars->setACL(array());
104
105     }
106
107     /**
108      * @expectedException Sabre_DAV_Exception_Forbidden
109      * @depends testSimple
110      */
111     function testSetName() {
112
113         $this->usercalendars->setName('bla');
114
115     }
116
117     /**
118      * @expectedException Sabre_DAV_Exception_Forbidden
119      * @depends testSimple
120      */
121     function testDelete() {
122
123         $this->usercalendars->delete();
124
125     }
126
127     /**
128      * @depends testSimple
129      */
130     function testGetLastModified() {
131
132         $this->assertNull($this->usercalendars->getLastModified());
133
134     }
135
136     /**
137      * @expectedException Sabre_DAV_Exception_MethodNotAllowed
138      * @depends testSimple
139      */
140     function testCreateFile() {
141
142         $this->usercalendars->createFile('bla');
143
144     }
145
146
147     /**
148      * @expectedException Sabre_DAV_Exception_MethodNotAllowed
149      * @depends testSimple
150      */
151     function testCreateDirectory() {
152
153         $this->usercalendars->createDirectory('bla');
154
155     }
156
157     /**
158      * @depends testSimple
159      */
160     function testCreateExtendedCollection() {
161
162         $result = $this->usercalendars->createExtendedCollection('newcalendar', array('{DAV:}collection', '{urn:ietf:params:xml:ns:caldav}calendar'), array());
163         $this->assertNull($result);
164         $cals = $this->backend->getCalendarsForUser('principals/user1');
165         $this->assertEquals(3,count($cals));
166
167     }
168
169     /**
170      * @expectedException Sabre_DAV_Exception_InvalidResourceType
171      * @depends testSimple
172      */
173     function testCreateExtendedCollectionBadResourceType() {
174
175         $this->usercalendars->createExtendedCollection('newcalendar', array('{DAV:}collection','{DAV:}blabla'), array());
176
177     }
178
179     function testGetSupportedPrivilegesSet() {
180
181         $this->assertNull($this->usercalendars->getSupportedPrivilegeSet());
182
183     }
184
185 }