3 require_once 'Sabre/CalDAV/TestUtil.php';
4 require_once 'Sabre/DAVACL/MockPrincipalBackend.php';
6 class Sabre_CalDAV_CalendarTest extends PHPUnit_Framework_TestCase {
9 * @var Sabre_CalDAV_Backend_PDO
12 protected $principalBackend;
14 * @var Sabre_CalDAV_Calendar
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();
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]);
37 unset($this->backend);
41 function testSimple() {
43 $this->assertEquals($this->calendars[0]['uri'], $this->calendar->getName());
50 function testUpdateProperties() {
52 $result = $this->calendar->updateProperties(array(
53 '{DAV:}displayname' => 'NewName',
56 $this->assertEquals(true, $result);
58 $calendars2 = $this->backend->getCalendarsForUser('principals/user1');
59 $this->assertEquals('NewName',$calendars2[0]['{DAV:}displayname']);
66 function testGetProperties() {
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',
75 $result = $this->calendar->getProperties($question);
77 foreach($question as $q) $this->assertArrayHasKey($q,$result);
79 $this->assertEquals(array('VEVENT','VTODO'), $result['{urn:ietf:params:xml:ns:caldav}supported-calendar-component-set']->getValue());
81 $this->assertTrue($result['{urn:ietf:params:xml:ns:caldav}supported-collation-set'] instanceof Sabre_CalDAV_Property_SupportedCollationSet);
83 $this->assertTrue($result['{DAV:}owner'] instanceof Sabre_DAVACL_Property_Principal);
84 $this->assertEquals('principals/user1', $result['{DAV:}owner']->getHref());
89 * @expectedException Sabre_DAV_Exception_NotFound
92 function testGetChildNotFound() {
94 $this->calendar->getChild('randomname');
101 function testGetChildren() {
103 $children = $this->calendar->getChildren();
104 $this->assertEquals(1,count($children));
106 $this->assertTrue($children[0] instanceof Sabre_CalDAV_CalendarObject);
111 * @depends testGetChildren
113 function testChildExists() {
115 $this->assertFalse($this->calendar->childExists('foo'));
117 $children = $this->calendar->getChildren();
118 $this->assertTrue($this->calendar->childExists($children[0]->getName()));
124 * @expectedException Sabre_DAV_Exception_MethodNotAllowed
126 function testCreateDirectory() {
128 $this->calendar->createDirectory('hello');
133 * @expectedException Sabre_DAV_Exception_MethodNotAllowed
135 function testSetName() {
137 $this->calendar->setName('hello');
141 function testGetLastModified() {
143 $this->assertNull($this->calendar->getLastModified());
147 function testCreateFile() {
149 $file = fopen('php://memory','r+');
150 fwrite($file,Sabre_CalDAV_TestUtil::getTestCalendarData());
153 $this->calendar->createFile('hello',$file);
155 $file = $this->calendar->getChild('hello');
156 $this->assertTrue($file instanceof Sabre_CalDAV_CalendarObject);
160 function testCreateFileNoSupportedComponents() {
162 $file = fopen('php://memory','r+');
163 fwrite($file,Sabre_CalDAV_TestUtil::getTestCalendarData());
166 $calendar = new Sabre_CalDAV_Calendar($this->principalBackend, $this->backend, $this->calendars[1]);
167 $calendar->createFile('hello',$file);
169 $file = $calendar->getChild('hello');
170 $this->assertTrue($file instanceof Sabre_CalDAV_CalendarObject);
174 function testDelete() {
176 $this->calendar->delete();
178 $calendars = $this->backend->getCalendarsForUser('principals/user1');
179 $this->assertEquals(1, count($calendars));
182 function testGetOwner() {
184 $this->assertEquals('principals/user1',$this->calendar->getOwner());
188 function testGetGroup() {
190 $this->assertNull($this->calendar->getGroup());
194 function testGetACL() {
198 'privilege' => '{DAV:}read',
199 'principal' => 'principals/user1',
203 'privilege' => '{DAV:}write',
204 'principal' => 'principals/user1',
208 'privilege' => '{DAV:}read',
209 'principal' => 'principals/user1/calendar-proxy-write',
213 'privilege' => '{DAV:}write',
214 'principal' => 'principals/user1/calendar-proxy-write',
218 'privilege' => '{DAV:}read',
219 'principal' => 'principals/user1/calendar-proxy-read',
223 'privilege' => '{' . Sabre_CalDAV_Plugin::NS_CALDAV . '}read-free-busy',
224 'principal' => '{DAV:}authenticated',
228 $this->assertEquals($expected, $this->calendar->getACL());
233 * @expectedException Sabre_DAV_Exception_MethodNotAllowed
235 function testSetACL() {
237 $this->calendar->setACL(array());
241 function testGetSupportedPrivilegesSet() {
243 $result = $this->calendar->getSupportedPrivilegeSet();
246 '{' . Sabre_CalDAV_Plugin::NS_CALDAV . '}read-free-busy',
247 $result['aggregates'][0]['aggregates'][2]['privilege']