1<?php 2 3namespace Sabre\CalDAV; 4 5use 6 Sabre\DAV, 7 Sabre\DAV\MkCol, 8 Sabre\DAVACL; 9 10 11class CalendarHomeTest extends \PHPUnit_Framework_TestCase { 12 13 /** 14 * @var Sabre\CalDAV\CalendarHome 15 */ 16 protected $usercalendars; 17 /** 18 * @var Sabre\CalDAV\Backend\PDO 19 */ 20 protected $backend; 21 22 function setup() { 23 24 if (!SABRE_HASSQLITE) $this->markTestSkipped('SQLite driver is not available'); 25 $this->backend = TestUtil::getBackend(); 26 $this->usercalendars = new CalendarHome($this->backend, array( 27 'uri' => 'principals/user1' 28 )); 29 30 } 31 32 function testSimple() { 33 34 $this->assertEquals('user1',$this->usercalendars->getName()); 35 36 } 37 38 /** 39 * @expectedException Sabre\DAV\Exception\NotFound 40 * @depends testSimple 41 */ 42 function testGetChildNotFound() { 43 44 $this->usercalendars->getChild('randomname'); 45 46 } 47 48 function testChildExists() { 49 50 $this->assertFalse($this->usercalendars->childExists('foo')); 51 $this->assertTrue($this->usercalendars->childExists('UUID-123467')); 52 53 } 54 55 function testGetOwner() { 56 57 $this->assertEquals('principals/user1', $this->usercalendars->getOwner()); 58 59 } 60 61 function testGetGroup() { 62 63 $this->assertNull($this->usercalendars->getGroup()); 64 65 } 66 67 function testGetACL() { 68 69 $expected = array( 70 array( 71 'privilege' => '{DAV:}read', 72 'principal' => 'principals/user1', 73 'protected' => true, 74 ), 75 array( 76 'privilege' => '{DAV:}write', 77 'principal' => 'principals/user1', 78 'protected' => true, 79 ), 80 array( 81 'privilege' => '{DAV:}read', 82 'principal' => 'principals/user1/calendar-proxy-write', 83 'protected' => true, 84 ), 85 array( 86 'privilege' => '{DAV:}write', 87 'principal' => 'principals/user1/calendar-proxy-write', 88 'protected' => true, 89 ), 90 array( 91 'privilege' => '{DAV:}read', 92 'principal' => 'principals/user1/calendar-proxy-read', 93 'protected' => true, 94 ), 95 ); 96 $this->assertEquals($expected, $this->usercalendars->getACL()); 97 98 } 99 100 /** 101 * @expectedException Sabre\DAV\Exception\MethodNotAllowed 102 */ 103 function testSetACL() { 104 105 $this->usercalendars->setACL(array()); 106 107 } 108 109 /** 110 * @expectedException Sabre\DAV\Exception\Forbidden 111 * @depends testSimple 112 */ 113 function testSetName() { 114 115 $this->usercalendars->setName('bla'); 116 117 } 118 119 /** 120 * @expectedException Sabre\DAV\Exception\Forbidden 121 * @depends testSimple 122 */ 123 function testDelete() { 124 125 $this->usercalendars->delete(); 126 127 } 128 129 /** 130 * @depends testSimple 131 */ 132 function testGetLastModified() { 133 134 $this->assertNull($this->usercalendars->getLastModified()); 135 136 } 137 138 /** 139 * @expectedException Sabre\DAV\Exception\MethodNotAllowed 140 * @depends testSimple 141 */ 142 function testCreateFile() { 143 144 $this->usercalendars->createFile('bla'); 145 146 } 147 148 149 /** 150 * @expectedException Sabre\DAV\Exception\MethodNotAllowed 151 * @depends testSimple 152 */ 153 function testCreateDirectory() { 154 155 $this->usercalendars->createDirectory('bla'); 156 157 } 158 159 /** 160 * @depends testSimple 161 */ 162 function testCreateExtendedCollection() { 163 164 $mkCol = new MkCol( 165 ['{DAV:}collection', '{urn:ietf:params:xml:ns:caldav}calendar'], 166 [] 167 ); 168 $result = $this->usercalendars->createExtendedCollection('newcalendar', $mkCol); 169 $this->assertNull($result); 170 $cals = $this->backend->getCalendarsForUser('principals/user1'); 171 $this->assertEquals(3,count($cals)); 172 173 } 174 175 /** 176 * @expectedException Sabre\DAV\Exception\InvalidResourceType 177 * @depends testSimple 178 */ 179 function testCreateExtendedCollectionBadResourceType() { 180 181 $mkCol = new MkCol( 182 ['{DAV:}collection', '{DAV:}blabla'], 183 [] 184 ); 185 $this->usercalendars->createExtendedCollection('newcalendar', $mkCol); 186 187 } 188 189 /** 190 * @expectedException Sabre\DAV\Exception\InvalidResourceType 191 * @depends testSimple 192 */ 193 function testCreateExtendedCollectionNotACalendar() { 194 195 $mkCol = new MkCol( 196 ['{DAV:}collection'], 197 [] 198 ); 199 $this->usercalendars->createExtendedCollection('newcalendar', $mkCol); 200 201 } 202 203 function testGetSupportedPrivilegesSet() { 204 205 $this->assertNull($this->usercalendars->getSupportedPrivilegeSet()); 206 207 } 208 209 /** 210 * @expectedException Sabre\DAV\Exception\NotImplemented 211 */ 212 function testShareReplyFail() { 213 214 $this->usercalendars->shareReply('uri', SharingPlugin::STATUS_DECLINED, 'curi', '1'); 215 216 } 217 218} 219