3 require_once 'Sabre/CalDAV/TestUtil.php';
4 require_once 'Sabre/DAV/Auth/MockBackend.php';
5 require_once 'Sabre/DAVACL/MockPrincipalBackend.php';
6 require_once 'Sabre/CalDAV/Backend/Mock.php';
8 class Sabre_CalDAV_CalendarObjectTest extends PHPUnit_Framework_TestCase {
11 * @var Sabre_CalDAV_Backend_PDO
15 * @var Sabre_CalDAV_Calendar
18 protected $principalBackend;
22 if (!SABRE_HASSQLITE) $this->markTestSkipped('SQLite driver is not available');
23 $this->backend = Sabre_CalDAV_TestUtil::getBackend();
24 $this->principalBackend = new Sabre_DAVACL_MockPrincipalBackend;
26 $calendars = $this->backend->getCalendarsForUser('principals/user1');
27 $this->assertEquals(2,count($calendars));
28 $this->calendar = new Sabre_CalDAV_Calendar($this->principalBackend,$this->backend, $calendars[0]);
34 unset($this->calendar);
35 unset($this->backend);
39 function testSetup() {
41 $children = $this->calendar->getChildren();
42 $this->assertTrue($children[0] instanceof Sabre_CalDAV_CalendarObject);
44 $this->assertInternalType('string',$children[0]->getName());
45 $this->assertInternalType('string',$children[0]->get());
46 $this->assertInternalType('string',$children[0]->getETag());
47 $this->assertEquals('text/calendar; charset=utf-8', $children[0]->getContentType());
52 * @expectedException InvalidArgumentException
54 function testInvalidArg1() {
56 $obj = new Sabre_CalDAV_CalendarObject(
57 new Sabre_CalDAV_Backend_Mock(array(),array()),
65 * @expectedException InvalidArgumentException
67 function testInvalidArg2() {
69 $obj = new Sabre_CalDAV_CalendarObject(
70 new Sabre_CalDAV_Backend_Mock(array(),array()),
72 array('calendarid' => '1')
82 $children = $this->calendar->getChildren();
83 $this->assertTrue($children[0] instanceof Sabre_CalDAV_CalendarObject);
84 $newData = Sabre_CalDAV_TestUtil::getTestCalendarData();
86 $children[0]->put($newData);
87 $this->assertEquals($newData, $children[0]->get());
94 function testPutStream() {
96 $children = $this->calendar->getChildren();
97 $this->assertTrue($children[0] instanceof Sabre_CalDAV_CalendarObject);
98 $newData = Sabre_CalDAV_TestUtil::getTestCalendarData();
100 $stream = fopen('php://temp','r+');
101 fwrite($stream, $newData);
103 $children[0]->put($stream);
104 $this->assertEquals($newData, $children[0]->get());
112 function testDelete() {
114 $children = $this->calendar->getChildren();
115 $this->assertTrue($children[0] instanceof Sabre_CalDAV_CalendarObject);
120 $children2 = $this->calendar->getChildren();
121 $this->assertEquals(count($children)-1, count($children2));
128 function testGetLastModified() {
130 $children = $this->calendar->getChildren();
131 $this->assertTrue($children[0] instanceof Sabre_CalDAV_CalendarObject);
135 $lastMod = $obj->getLastModified();
136 $this->assertTrue(is_int($lastMod) || ctype_digit($lastMod));
143 function testGetSize() {
145 $children = $this->calendar->getChildren();
146 $this->assertTrue($children[0] instanceof Sabre_CalDAV_CalendarObject);
150 $size = $obj->getSize();
151 $this->assertInternalType('int', $size);
155 function testGetOwner() {
157 $children = $this->calendar->getChildren();
158 $this->assertTrue($children[0] instanceof Sabre_CalDAV_CalendarObject);
161 $this->assertEquals('principals/user1', $obj->getOwner());
165 function testGetGroup() {
167 $children = $this->calendar->getChildren();
168 $this->assertTrue($children[0] instanceof Sabre_CalDAV_CalendarObject);
171 $this->assertNull($obj->getGroup());
175 function testGetACL() {
179 'privilege' => '{DAV:}read',
180 'principal' => 'principals/user1',
184 'privilege' => '{DAV:}write',
185 'principal' => 'principals/user1',
189 'privilege' => '{DAV:}read',
190 'principal' => 'principals/user1/calendar-proxy-write',
194 'privilege' => '{DAV:}write',
195 'principal' => 'principals/user1/calendar-proxy-write',
199 'privilege' => '{DAV:}read',
200 'principal' => 'principals/user1/calendar-proxy-read',
205 $children = $this->calendar->getChildren();
206 $this->assertTrue($children[0] instanceof Sabre_CalDAV_CalendarObject);
209 $this->assertEquals($expected, $obj->getACL());
214 * @expectedException Sabre_DAV_Exception_MethodNotAllowed
216 function testSetACL() {
218 $children = $this->calendar->getChildren();
219 $this->assertTrue($children[0] instanceof Sabre_CalDAV_CalendarObject);
222 $obj->setACL(array());
228 $children = $this->calendar->getChildren();
229 $this->assertTrue($children[0] instanceof Sabre_CalDAV_CalendarObject);
233 $expected = "BEGIN:VCALENDAR
235 PRODID:-//Apple Inc.//iCal 4.0.1//EN
241 RRULE:FREQ=YEARLY;UNTIL=19880507T150000Z;BYMONTH=5;BYDAY=2SU
242 DTSTART:19870510T000000
248 DTSTART:19881009T000000
254 CREATED:20100225T154229Z
255 UID:39A6B5ED-DD51-4AFE-A683-C35EE3749627
257 SUMMARY:Something here
258 DTSTAMP:20100228T130202Z
259 DTSTART;TZID=Asia/Seoul:20100223T060000
260 DTEND;TZID=Asia/Seoul:20100223T070000
261 ATTENDEE;PARTSTAT=NEEDS-ACTION:mailto:lisa@example.com
268 $this->assertEquals($expected, $obj->get());
272 function testGetRefetch() {
274 $backend = new Sabre_CalDAV_Backend_Mock(array(), array(
277 'calendardata' => 'foo',
282 $obj = new Sabre_CalDAV_CalendarObject($backend, array(), array('calendarid' => 1, 'uri' => 'foo'));
284 $this->assertEquals('foo', $obj->get());
288 function testGetEtag1() {
291 'calendardata' => 'foo',
297 $backend = new Sabre_CalDAV_Backend_Mock(array(), array());
298 $obj = new Sabre_CalDAV_CalendarObject($backend, array(), $objectInfo);
300 $this->assertEquals('bar', $obj->getETag());
304 function testGetEtag2() {
307 'calendardata' => 'foo',
312 $backend = new Sabre_CalDAV_Backend_Mock(array(), array());
313 $obj = new Sabre_CalDAV_CalendarObject($backend, array(), $objectInfo);
315 $this->assertEquals('"' . md5('foo') . '"', $obj->getETag());
319 function testGetSupportedPrivilegesSet() {
322 'calendardata' => 'foo',
327 $backend = new Sabre_CalDAV_Backend_Mock(array(), array());
328 $obj = new Sabre_CalDAV_CalendarObject($backend, array(), $objectInfo);
329 $this->assertNull($obj->getSupportedPrivilegeSet());
333 function testGetSize1() {
336 'calendardata' => 'foo',
341 $backend = new Sabre_CalDAV_Backend_Mock(array(), array());
342 $obj = new Sabre_CalDAV_CalendarObject($backend, array(), $objectInfo);
343 $this->assertEquals(3, $obj->getSize());
347 function testGetSize2() {
355 $backend = new Sabre_CalDAV_Backend_Mock(array(), array());
356 $obj = new Sabre_CalDAV_CalendarObject($backend, array(), $objectInfo);
357 $this->assertEquals(4, $obj->getSize());