diff options
Diffstat (limited to 'vendor/sabre/dav/tests/Sabre/CalDAV/Backend')
5 files changed, 728 insertions, 478 deletions
diff --git a/vendor/sabre/dav/tests/Sabre/CalDAV/Backend/AbstractPDOTest.php b/vendor/sabre/dav/tests/Sabre/CalDAV/Backend/AbstractPDOTest.php index 2224f0b63..25f8b1794 100644 --- a/vendor/sabre/dav/tests/Sabre/CalDAV/Backend/AbstractPDOTest.php +++ b/vendor/sabre/dav/tests/Sabre/CalDAV/Backend/AbstractPDOTest.php @@ -1,8 +1,10 @@ <?php namespace Sabre\CalDAV\Backend; + use Sabre\CalDAV; use Sabre\DAV; +use Sabre\DAV\PropPatch; abstract class AbstractPDOTest extends \PHPUnit_Framework_TestCase { @@ -22,7 +24,7 @@ abstract class AbstractPDOTest extends \PHPUnit_Framework_TestCase { $backend = new PDO($this->pdo); $calendars = $backend->getCalendarsForUser('principals/user2'); - $this->assertEquals(array(),$calendars); + $this->assertEquals([], $calendars); } @@ -32,28 +34,28 @@ abstract class AbstractPDOTest extends \PHPUnit_Framework_TestCase { function testCreateCalendarAndFetch() { $backend = new PDO($this->pdo); - $returnedId = $backend->createCalendar('principals/user2','somerandomid',array( - '{urn:ietf:params:xml:ns:caldav}supported-calendar-component-set' => new CalDAV\Property\SupportedCalendarComponentSet(array('VEVENT')), - '{DAV:}displayname' => 'Hello!', - '{urn:ietf:params:xml:ns:caldav}schedule-calendar-transp' => new CalDAV\Property\ScheduleCalendarTransp('transparent'), - )); + $returnedId = $backend->createCalendar('principals/user2', 'somerandomid', [ + '{urn:ietf:params:xml:ns:caldav}supported-calendar-component-set' => new CalDAV\Xml\Property\SupportedCalendarComponentSet(['VEVENT']), + '{DAV:}displayname' => 'Hello!', + '{urn:ietf:params:xml:ns:caldav}schedule-calendar-transp' => new CalDAV\Xml\Property\ScheduleCalendarTransp('transparent'), + ]); $calendars = $backend->getCalendarsForUser('principals/user2'); - $elementCheck = array( - 'id' => $returnedId, - 'uri' => 'somerandomid', - '{DAV:}displayname' => 'Hello!', - '{urn:ietf:params:xml:ns:caldav}calendar-description' => '', - '{urn:ietf:params:xml:ns:caldav}schedule-calendar-transp' => new CalDAV\Property\ScheduleCalendarTransp('transparent'), - ); + $elementCheck = [ + 'id' => $returnedId, + 'uri' => 'somerandomid', + '{DAV:}displayname' => 'Hello!', + '{urn:ietf:params:xml:ns:caldav}calendar-description' => '', + '{urn:ietf:params:xml:ns:caldav}schedule-calendar-transp' => new CalDAV\Xml\Property\ScheduleCalendarTransp('transparent'), + ]; - $this->assertInternalType('array',$calendars); - $this->assertEquals(1,count($calendars)); + $this->assertInternalType('array', $calendars); + $this->assertEquals(1, count($calendars)); - foreach($elementCheck as $name=>$value) { + foreach ($elementCheck as $name => $value) { $this->assertArrayHasKey($name, $calendars[0]); - $this->assertEquals($value,$calendars[0][$name]); + $this->assertEquals($value, $calendars[0][$name]); } @@ -67,38 +69,41 @@ abstract class AbstractPDOTest extends \PHPUnit_Framework_TestCase { $backend = new PDO($this->pdo); //Creating a new calendar - $newId = $backend->createCalendar('principals/user2','somerandomid',array()); + $newId = $backend->createCalendar('principals/user2', 'somerandomid', []); + + $propPatch = new PropPatch([ + '{DAV:}displayname' => 'myCalendar', + '{urn:ietf:params:xml:ns:caldav}schedule-calendar-transp' => new CalDAV\Xml\Property\ScheduleCalendarTransp('transparent'), + ]); // Updating the calendar - $result = $backend->updateCalendar($newId,array( - '{DAV:}displayname' => 'myCalendar', - '{urn:ietf:params:xml:ns:caldav}schedule-calendar-transp' => new CalDAV\Property\ScheduleCalendarTransp('transparent'), - )); + $backend->updateCalendar($newId, $propPatch); + $result = $propPatch->commit(); // Verifying the result of the update - $this->assertEquals(true, $result); + $this->assertTrue($result); // Fetching all calendars from this user $calendars = $backend->getCalendarsForUser('principals/user2'); // Checking if all the information is still correct - $elementCheck = array( - 'id' => $newId, - 'uri' => 'somerandomid', - '{DAV:}displayname' => 'myCalendar', - '{urn:ietf:params:xml:ns:caldav}calendar-description' => '', - '{urn:ietf:params:xml:ns:caldav}calendar-timezone' => '', - '{http://calendarserver.org/ns/}getctag' => '2', - '{urn:ietf:params:xml:ns:caldav}schedule-calendar-transp' => new CalDAV\Property\ScheduleCalendarTransp('transparent'), - ); + $elementCheck = [ + 'id' => $newId, + 'uri' => 'somerandomid', + '{DAV:}displayname' => 'myCalendar', + '{urn:ietf:params:xml:ns:caldav}calendar-description' => '', + '{urn:ietf:params:xml:ns:caldav}calendar-timezone' => '', + '{http://calendarserver.org/ns/}getctag' => 'http://sabre.io/ns/sync/2', + '{urn:ietf:params:xml:ns:caldav}schedule-calendar-transp' => new CalDAV\Xml\Property\ScheduleCalendarTransp('transparent'), + ]; - $this->assertInternalType('array',$calendars); - $this->assertEquals(1,count($calendars)); + $this->assertInternalType('array', $calendars); + $this->assertEquals(1, count($calendars)); - foreach($elementCheck as $name=>$value) { + foreach ($elementCheck as $name => $value) { $this->assertArrayHasKey($name, $calendars[0]); - $this->assertEquals($value,$calendars[0][$name]); + $this->assertEquals($value, $calendars[0][$name]); } @@ -112,19 +117,22 @@ abstract class AbstractPDOTest extends \PHPUnit_Framework_TestCase { $backend = new PDO($this->pdo); //Creating a new calendar - $newId = $backend->createCalendar('principals/user2','somerandomid',array()); + $newId = $backend->createCalendar('principals/user2', 'somerandomid', []); - // Updating the calendar - $result = $backend->updateCalendar($newId,array( + $propPatch = new PropPatch([ '{DAV:}displayname' => 'myCalendar', '{DAV:}yourmom' => 'wittycomment', - )); + ]); + + // Updating the calendar + $backend->updateCalendar($newId, $propPatch); + $propPatch->commit(); // Verifying the result of the update - $this->assertEquals(array( - '403' => array('{DAV:}yourmom' => null), - '424' => array('{DAV:}displayname' => null), - ), $result); + $this->assertEquals([ + '{DAV:}yourmom' => 403, + '{DAV:}displayname' => 424, + ], $propPatch->getResult()); } @@ -134,15 +142,15 @@ abstract class AbstractPDOTest extends \PHPUnit_Framework_TestCase { function testDeleteCalendar() { $backend = new PDO($this->pdo); - $returnedId = $backend->createCalendar('principals/user2','somerandomid',array( - '{urn:ietf:params:xml:ns:caldav}supported-calendar-component-set' => new CalDAV\Property\SupportedCalendarComponentSet(array('VEVENT')), - '{DAV:}displayname' => 'Hello!', - )); + $returnedId = $backend->createCalendar('principals/user2', 'somerandomid', [ + '{urn:ietf:params:xml:ns:caldav}supported-calendar-component-set' => new CalDAV\Xml\Property\SupportedCalendarComponentSet(['VEVENT']), + '{DAV:}displayname' => 'Hello!', + ]); $backend->deleteCalendar($returnedId); $calendars = $backend->getCalendarsForUser('principals/user2'); - $this->assertEquals(array(),$calendars); + $this->assertEquals([], $calendars); } @@ -155,30 +163,78 @@ abstract class AbstractPDOTest extends \PHPUnit_Framework_TestCase { $backend = new PDO($this->pdo); //Creating a new calendar - $newId = $backend->createCalendar('principals/user2','somerandomid',array( + $newId = $backend->createCalendar('principals/user2', 'somerandomid', [ '{urn:ietf:params:xml:ns:caldav}supported-calendar-component-set' => 'blabla', - )); + ]); } function testCreateCalendarObject() { $backend = new PDO($this->pdo); - $returnedId = $backend->createCalendar('principals/user2','somerandomid',array()); + $returnedId = $backend->createCalendar('principals/user2', 'somerandomid', []); $object = "BEGIN:VCALENDAR\r\nBEGIN:VEVENT\r\nDTSTART;VALUE=DATE:20120101\r\nEND:VEVENT\r\nEND:VCALENDAR\r\n"; $backend->createCalendarObject($returnedId, 'random-id', $object); $result = $this->pdo->query('SELECT etag, size, calendardata, firstoccurence, lastoccurence, componenttype FROM calendarobjects WHERE uri = "random-id"'); - $this->assertEquals(array( - 'etag' => md5($object), - 'size' => strlen($object), - 'calendardata' => $object, + $this->assertEquals([ + 'etag' => md5($object), + 'size' => strlen($object), + 'calendardata' => $object, 'firstoccurence' => strtotime('20120101'), - 'lastoccurence' => strtotime('20120101')+(3600*24), - 'componenttype' => 'VEVENT', - ), $result->fetch(\PDO::FETCH_ASSOC)); + 'lastoccurence' => strtotime('20120101') + (3600 * 24), + 'componenttype' => 'VEVENT', + ], $result->fetch(\PDO::FETCH_ASSOC)); + + } + function testGetMultipleObjects() { + + $backend = new PDO($this->pdo); + $returnedId = $backend->createCalendar('principals/user2', 'somerandomid', []); + + $object = "BEGIN:VCALENDAR\r\nBEGIN:VEVENT\r\nDTSTART;VALUE=DATE:20120101\r\nEND:VEVENT\r\nEND:VCALENDAR\r\n"; + + $backend->createCalendarObject($returnedId, 'id-1', $object); + $backend->createCalendarObject($returnedId, 'id-2', $object); + + $check = [ + [ + 'id' => 1, + 'etag' => '"' . md5($object) . '"', + 'uri' => 'id-1', + 'size' => strlen($object), + 'calendardata' => $object, + 'lastmodified' => null, + 'calendarid' => $returnedId, + ], + [ + 'id' => 2, + 'etag' => '"' . md5($object) . '"', + 'uri' => 'id-2', + 'size' => strlen($object), + 'calendardata' => $object, + 'lastmodified' => null, + 'calendarid' => $returnedId, + ], + ]; + + $result = $backend->getMultipleCalendarObjects($returnedId, [ 'id-1', 'id-2' ]); + + foreach ($check as $index => $props) { + + foreach ($props as $key => $value) { + + if ($key !== 'lastmodified') { + $this->assertEquals($value, $result[$index][$key]); + } else { + $this->assertTrue(isset($result[$index][$key])); + } + + } + + } } @@ -189,7 +245,7 @@ abstract class AbstractPDOTest extends \PHPUnit_Framework_TestCase { function testCreateCalendarObjectNoComponent() { $backend = new PDO($this->pdo); - $returnedId = $backend->createCalendar('principals/user2','somerandomid',array()); + $returnedId = $backend->createCalendar('principals/user2', 'somerandomid', []); $object = "BEGIN:VCALENDAR\r\nBEGIN:VTIMEZONE\r\nEND:VTIMEZONE\r\nEND:VCALENDAR\r\n"; @@ -203,21 +259,21 @@ abstract class AbstractPDOTest extends \PHPUnit_Framework_TestCase { function testCreateCalendarObjectDuration() { $backend = new PDO($this->pdo); - $returnedId = $backend->createCalendar('principals/user2','somerandomid',array()); + $returnedId = $backend->createCalendar('principals/user2', 'somerandomid', []); $object = "BEGIN:VCALENDAR\r\nBEGIN:VEVENT\r\nDTSTART;VALUE=DATE:20120101\r\nDURATION:P2D\r\nEND:VEVENT\r\nEND:VCALENDAR\r\n"; $backend->createCalendarObject($returnedId, 'random-id', $object); $result = $this->pdo->query('SELECT etag, size, calendardata, firstoccurence, lastoccurence, componenttype FROM calendarobjects WHERE uri = "random-id"'); - $this->assertEquals(array( - 'etag' => md5($object), - 'size' => strlen($object), - 'calendardata' => $object, + $this->assertEquals([ + 'etag' => md5($object), + 'size' => strlen($object), + 'calendardata' => $object, 'firstoccurence' => strtotime('20120101'), - 'lastoccurence' => strtotime('20120101')+(3600*48), - 'componenttype' => 'VEVENT', - ), $result->fetch(\PDO::FETCH_ASSOC)); + 'lastoccurence' => strtotime('20120101') + (3600 * 48), + 'componenttype' => 'VEVENT', + ], $result->fetch(\PDO::FETCH_ASSOC)); } @@ -227,21 +283,45 @@ abstract class AbstractPDOTest extends \PHPUnit_Framework_TestCase { function testCreateCalendarObjectNoDTEND() { $backend = new PDO($this->pdo); - $returnedId = $backend->createCalendar('principals/user2','somerandomid',array()); + $returnedId = $backend->createCalendar('principals/user2', 'somerandomid', []); $object = "BEGIN:VCALENDAR\r\nBEGIN:VEVENT\r\nDTSTART;VALUE=DATE-TIME:20120101T100000Z\r\nEND:VEVENT\r\nEND:VCALENDAR\r\n"; $backend->createCalendarObject($returnedId, 'random-id', $object); $result = $this->pdo->query('SELECT etag, size, calendardata, firstoccurence, lastoccurence, componenttype FROM calendarobjects WHERE uri = "random-id"'); - $this->assertEquals(array( - 'etag' => md5($object), - 'size' => strlen($object), - 'calendardata' => $object, + $this->assertEquals([ + 'etag' => md5($object), + 'size' => strlen($object), + 'calendardata' => $object, 'firstoccurence' => strtotime('2012-01-01 10:00:00'), - 'lastoccurence' => strtotime('2012-01-01 10:00:00'), - 'componenttype' => 'VEVENT', - ), $result->fetch(\PDO::FETCH_ASSOC)); + 'lastoccurence' => strtotime('2012-01-01 10:00:00'), + 'componenttype' => 'VEVENT', + ], $result->fetch(\PDO::FETCH_ASSOC)); + + } + + /** + * @depends testCreateCalendarObject + */ + function testCreateCalendarObjectWithDTEND() { + + $backend = new PDO($this->pdo); + $returnedId = $backend->createCalendar('principals/user2', 'somerandomid', []); + + $object = "BEGIN:VCALENDAR\r\nBEGIN:VEVENT\r\nDTSTART;VALUE=DATE-TIME:20120101T100000Z\r\nDTEND:20120101T110000Z\r\nEND:VEVENT\r\nEND:VCALENDAR\r\n"; + + $backend->createCalendarObject($returnedId, 'random-id', $object); + + $result = $this->pdo->query('SELECT etag, size, calendardata, firstoccurence, lastoccurence, componenttype FROM calendarobjects WHERE uri = "random-id"'); + $this->assertEquals([ + 'etag' => md5($object), + 'size' => strlen($object), + 'calendardata' => $object, + 'firstoccurence' => strtotime('2012-01-01 10:00:00'), + 'lastoccurence' => strtotime('2012-01-01 11:00:00'), + 'componenttype' => 'VEVENT', + ], $result->fetch(\PDO::FETCH_ASSOC)); } @@ -251,21 +331,21 @@ abstract class AbstractPDOTest extends \PHPUnit_Framework_TestCase { function testCreateCalendarObjectInfiniteReccurence() { $backend = new PDO($this->pdo); - $returnedId = $backend->createCalendar('principals/user2','somerandomid',array()); + $returnedId = $backend->createCalendar('principals/user2', 'somerandomid', []); - $object = "BEGIN:VCALENDAR\r\nBEGIN:VEVENT\r\nDTSTART;VALUE=DATE-TIME:20120101T100000Z\r\nRRULE:FREQ=DAILY\r\nEND:VEVENT\r\nEND:VCALENDAR\r\n"; + $object = "BEGIN:VCALENDAR\r\nBEGIN:VEVENT\r\nDTSTART;VALUE=DATE-TIME:20120101T100000Z\r\nRRULE:FREQ=DAILY\r\nUID:foo\r\nEND:VEVENT\r\nEND:VCALENDAR\r\n"; $backend->createCalendarObject($returnedId, 'random-id', $object); $result = $this->pdo->query('SELECT etag, size, calendardata, firstoccurence, lastoccurence, componenttype FROM calendarobjects WHERE uri = "random-id"'); - $this->assertEquals(array( - 'etag' => md5($object), - 'size' => strlen($object), - 'calendardata' => $object, + $this->assertEquals([ + 'etag' => md5($object), + 'size' => strlen($object), + 'calendardata' => $object, 'firstoccurence' => strtotime('2012-01-01 10:00:00'), - 'lastoccurence' => strtotime(PDO::MAX_DATE), - 'componenttype' => 'VEVENT', - ), $result->fetch(\PDO::FETCH_ASSOC)); + 'lastoccurence' => strtotime(PDO::MAX_DATE), + 'componenttype' => 'VEVENT', + ], $result->fetch(\PDO::FETCH_ASSOC)); } @@ -275,21 +355,21 @@ abstract class AbstractPDOTest extends \PHPUnit_Framework_TestCase { function testCreateCalendarObjectEndingReccurence() { $backend = new PDO($this->pdo); - $returnedId = $backend->createCalendar('principals/user2','somerandomid',array()); + $returnedId = $backend->createCalendar('principals/user2', 'somerandomid', []); - $object = "BEGIN:VCALENDAR\r\nBEGIN:VEVENT\r\nDTSTART;VALUE=DATE-TIME:20120101T100000Z\r\nDTEND;VALUE=DATE-TIME:20120101T110000Z\r\nRRULE:FREQ=DAILY;COUNT=1000\r\nEND:VEVENT\r\nEND:VCALENDAR\r\n"; + $object = "BEGIN:VCALENDAR\r\nBEGIN:VEVENT\r\nDTSTART;VALUE=DATE-TIME:20120101T100000Z\r\nDTEND;VALUE=DATE-TIME:20120101T110000Z\r\nUID:foo\r\nRRULE:FREQ=DAILY;COUNT=1000\r\nEND:VEVENT\r\nEND:VCALENDAR\r\n"; $backend->createCalendarObject($returnedId, 'random-id', $object); $result = $this->pdo->query('SELECT etag, size, calendardata, firstoccurence, lastoccurence, componenttype FROM calendarobjects WHERE uri = "random-id"'); - $this->assertEquals(array( - 'etag' => md5($object), - 'size' => strlen($object), - 'calendardata' => $object, + $this->assertEquals([ + 'etag' => md5($object), + 'size' => strlen($object), + 'calendardata' => $object, 'firstoccurence' => strtotime('2012-01-01 10:00:00'), - 'lastoccurence' => strtotime('2012-01-01 11:00:00') + (3600 * 24 * 999), - 'componenttype' => 'VEVENT', - ), $result->fetch(\PDO::FETCH_ASSOC)); + 'lastoccurence' => strtotime('2012-01-01 11:00:00') + (3600 * 24 * 999), + 'componenttype' => 'VEVENT', + ], $result->fetch(\PDO::FETCH_ASSOC)); } @@ -299,21 +379,21 @@ abstract class AbstractPDOTest extends \PHPUnit_Framework_TestCase { function testCreateCalendarObjectTask() { $backend = new PDO($this->pdo); - $returnedId = $backend->createCalendar('principals/user2','somerandomid',array()); + $returnedId = $backend->createCalendar('principals/user2', 'somerandomid', []); $object = "BEGIN:VCALENDAR\r\nBEGIN:VTODO\r\nDUE;VALUE=DATE-TIME:20120101T100000Z\r\nEND:VTODO\r\nEND:VCALENDAR\r\n"; $backend->createCalendarObject($returnedId, 'random-id', $object); $result = $this->pdo->query('SELECT etag, size, calendardata, firstoccurence, lastoccurence, componenttype FROM calendarobjects WHERE uri = "random-id"'); - $this->assertEquals(array( - 'etag' => md5($object), - 'size' => strlen($object), - 'calendardata' => $object, + $this->assertEquals([ + 'etag' => md5($object), + 'size' => strlen($object), + 'calendardata' => $object, 'firstoccurence' => null, - 'lastoccurence' => null, - 'componenttype' => 'VTODO', - ), $result->fetch(\PDO::FETCH_ASSOC)); + 'lastoccurence' => null, + 'componenttype' => 'VTODO', + ], $result->fetch(\PDO::FETCH_ASSOC)); } @@ -323,22 +403,42 @@ abstract class AbstractPDOTest extends \PHPUnit_Framework_TestCase { function testGetCalendarObjects() { $backend = new PDO($this->pdo); - $returnedId = $backend->createCalendar('principals/user2','somerandomid',array()); + $returnedId = $backend->createCalendar('principals/user2', 'somerandomid', []); $object = "BEGIN:VCALENDAR\r\nBEGIN:VEVENT\r\nDTSTART;VALUE=DATE:20120101\r\nEND:VEVENT\r\nEND:VCALENDAR\r\n"; $backend->createCalendarObject($returnedId, 'random-id', $object); - $data = $backend->getCalendarObjects($returnedId,'random-id'); + $data = $backend->getCalendarObjects($returnedId, 'random-id'); $this->assertEquals(1, count($data)); $data = $data[0]; $this->assertEquals($returnedId, $data['calendarid']); $this->assertEquals('random-id', $data['uri']); - $this->assertEquals(strlen($object),$data['size']); + $this->assertEquals(strlen($object), $data['size']); } + /** + * @depends testCreateCalendarObject + */ + function testGetCalendarObjectByUID() { + + $backend = new PDO($this->pdo); + $returnedId = $backend->createCalendar('principals/user2', 'somerandomid', []); + + $object = "BEGIN:VCALENDAR\r\nBEGIN:VEVENT\r\nUID:foo\r\nDTSTART;VALUE=DATE:20120101\r\nEND:VEVENT\r\nEND:VCALENDAR\r\n"; + $backend->createCalendarObject($returnedId, 'random-id', $object); + + $this->assertNull( + $backend->getCalendarObjectByUID('principals/user2', 'bar') + ); + $this->assertEquals( + 'somerandomid/random-id', + $backend->getCalendarObjectByUID('principals/user2', 'foo') + ); + + } /** * @depends testCreateCalendarObject @@ -346,14 +446,14 @@ abstract class AbstractPDOTest extends \PHPUnit_Framework_TestCase { function testUpdateCalendarObject() { $backend = new PDO($this->pdo); - $returnedId = $backend->createCalendar('principals/user2','somerandomid',array()); + $returnedId = $backend->createCalendar('principals/user2', 'somerandomid', []); $object = "BEGIN:VCALENDAR\r\nBEGIN:VEVENT\r\nDTSTART;VALUE=DATE:20120101\r\nEND:VEVENT\r\nEND:VCALENDAR\r\n"; $object2 = "BEGIN:VCALENDAR\r\nBEGIN:VEVENT\r\nDTSTART;VALUE=DATE:20130101\r\nEND:VEVENT\r\nEND:VCALENDAR\r\n"; $backend->createCalendarObject($returnedId, 'random-id', $object); $backend->updateCalendarObject($returnedId, 'random-id', $object2); - $data = $backend->getCalendarObject($returnedId,'random-id'); + $data = $backend->getCalendarObject($returnedId, 'random-id'); $this->assertEquals($object2, $data['calendardata']); $this->assertEquals($returnedId, $data['calendarid']); @@ -368,13 +468,13 @@ abstract class AbstractPDOTest extends \PHPUnit_Framework_TestCase { function testDeleteCalendarObject() { $backend = new PDO($this->pdo); - $returnedId = $backend->createCalendar('principals/user2','somerandomid',array()); + $returnedId = $backend->createCalendar('principals/user2', 'somerandomid', []); $object = "BEGIN:VCALENDAR\r\nBEGIN:VEVENT\r\nDTSTART;VALUE=DATE:20120101\r\nEND:VEVENT\r\nEND:VCALENDAR\r\n"; $backend->createCalendarObject($returnedId, 'random-id', $object); $backend->deleteCalendarObject($returnedId, 'random-id'); - $data = $backend->getCalendarObject($returnedId,'random-id'); + $data = $backend->getCalendarObject($returnedId, 'random-id'); $this->assertNull($data); } @@ -382,24 +482,24 @@ abstract class AbstractPDOTest extends \PHPUnit_Framework_TestCase { function testCalendarQueryNoResult() { $abstract = new PDO($this->pdo); - $filters = array( - 'name' => 'VCALENDAR', - 'comp-filters' => array( - array( - 'name' => 'VJOURNAL', - 'comp-filters' => array(), - 'prop-filters' => array(), + $filters = [ + 'name' => 'VCALENDAR', + 'comp-filters' => [ + [ + 'name' => 'VJOURNAL', + 'comp-filters' => [], + 'prop-filters' => [], 'is-not-defined' => false, - 'time-range' => null, - ), - ), - 'prop-filters' => array(), + 'time-range' => null, + ], + ], + 'prop-filters' => [], 'is-not-defined' => false, - 'time-range' => null, - ); + 'time-range' => null, + ]; - $this->assertEquals(array( - ), $abstract->calendarQuery(1, $filters)); + $this->assertEquals([ + ], $abstract->calendarQuery(1, $filters)); } @@ -409,25 +509,25 @@ abstract class AbstractPDOTest extends \PHPUnit_Framework_TestCase { $backend->createCalendarObject(1, "todo", "BEGIN:VCALENDAR\r\nBEGIN:VTODO\r\nEND:VTODO\r\nEND:VCALENDAR\r\n"); $backend->createCalendarObject(1, "event", "BEGIN:VCALENDAR\r\nBEGIN:VEVENT\r\nDTSTART:20120101\r\nEND:VEVENT\r\nEND:VCALENDAR\r\n"); - $filters = array( - 'name' => 'VCALENDAR', - 'comp-filters' => array( - array( - 'name' => 'VTODO', - 'comp-filters' => array(), - 'prop-filters' => array(), + $filters = [ + 'name' => 'VCALENDAR', + 'comp-filters' => [ + [ + 'name' => 'VTODO', + 'comp-filters' => [], + 'prop-filters' => [], 'is-not-defined' => false, - 'time-range' => null, - ), - ), - 'prop-filters' => array(), + 'time-range' => null, + ], + ], + 'prop-filters' => [], 'is-not-defined' => false, - 'time-range' => null, - ); + 'time-range' => null, + ]; - $this->assertEquals(array( + $this->assertEquals([ "todo", - ), $backend->calendarQuery(1, $filters)); + ], $backend->calendarQuery(1, $filters)); } function testCalendarQueryTodoNotMatch() { @@ -436,32 +536,32 @@ abstract class AbstractPDOTest extends \PHPUnit_Framework_TestCase { $backend->createCalendarObject(1, "todo", "BEGIN:VCALENDAR\r\nBEGIN:VTODO\r\nEND:VTODO\r\nEND:VCALENDAR\r\n"); $backend->createCalendarObject(1, "event", "BEGIN:VCALENDAR\r\nBEGIN:VEVENT\r\nDTSTART:20120101\r\nEND:VEVENT\r\nEND:VCALENDAR\r\n"); - $filters = array( - 'name' => 'VCALENDAR', - 'comp-filters' => array( - array( - 'name' => 'VTODO', - 'comp-filters' => array(), - 'prop-filters' => array( - array( - 'name' => 'summary', - 'text-match' => null, - 'time-range' => null, - 'param-filters' => array(), + $filters = [ + 'name' => 'VCALENDAR', + 'comp-filters' => [ + [ + 'name' => 'VTODO', + 'comp-filters' => [], + 'prop-filters' => [ + [ + 'name' => 'summary', + 'text-match' => null, + 'time-range' => null, + 'param-filters' => [], 'is-not-defined' => false, - ), - ), + ], + ], 'is-not-defined' => false, - 'time-range' => null, - ), - ), - 'prop-filters' => array(), + 'time-range' => null, + ], + ], + 'prop-filters' => [], 'is-not-defined' => false, - 'time-range' => null, - ); + 'time-range' => null, + ]; - $this->assertEquals(array( - ), $backend->calendarQuery(1, $filters)); + $this->assertEquals([ + ], $backend->calendarQuery(1, $filters)); } @@ -471,13 +571,13 @@ abstract class AbstractPDOTest extends \PHPUnit_Framework_TestCase { $backend->createCalendarObject(1, "todo", "BEGIN:VCALENDAR\r\nBEGIN:VTODO\r\nEND:VTODO\r\nEND:VCALENDAR\r\n"); $backend->createCalendarObject(1, "event", "BEGIN:VCALENDAR\r\nBEGIN:VEVENT\r\nDTSTART:20120101\r\nEND:VEVENT\r\nEND:VCALENDAR\r\n"); - $filters = array( - 'name' => 'VCALENDAR', - 'comp-filters' => array(), - 'prop-filters' => array(), + $filters = [ + 'name' => 'VCALENDAR', + 'comp-filters' => [], + 'prop-filters' => [], 'is-not-defined' => false, - 'time-range' => null, - ); + 'time-range' => null, + ]; $result = $backend->calendarQuery(1, $filters); $this->assertTrue(in_array('todo', $result)); @@ -492,28 +592,28 @@ abstract class AbstractPDOTest extends \PHPUnit_Framework_TestCase { $backend->createCalendarObject(1, "event", "BEGIN:VCALENDAR\r\nBEGIN:VEVENT\r\nDTSTART;VALUE=DATE:20120101\r\nEND:VEVENT\r\nEND:VCALENDAR\r\n"); $backend->createCalendarObject(1, "event2", "BEGIN:VCALENDAR\r\nBEGIN:VEVENT\r\nDTSTART;VALUE=DATE:20120103\r\nEND:VEVENT\r\nEND:VCALENDAR\r\n"); - $filters = array( - 'name' => 'VCALENDAR', - 'comp-filters' => array( - array( - 'name' => 'VEVENT', - 'comp-filters' => array(), - 'prop-filters' => array(), + $filters = [ + 'name' => 'VCALENDAR', + 'comp-filters' => [ + [ + 'name' => 'VEVENT', + 'comp-filters' => [], + 'prop-filters' => [], 'is-not-defined' => false, - 'time-range' => array( + 'time-range' => [ 'start' => new \DateTime('20120103'), 'end' => new \DateTime('20120104'), - ), - ), - ), - 'prop-filters' => array(), + ], + ], + ], + 'prop-filters' => [], 'is-not-defined' => false, - 'time-range' => null, - ); + 'time-range' => null, + ]; - $this->assertEquals(array( + $this->assertEquals([ "event2", - ), $backend->calendarQuery(1, $filters)); + ], $backend->calendarQuery(1, $filters)); } function testCalendarQueryTimeRangeNoEnd() { @@ -523,28 +623,261 @@ abstract class AbstractPDOTest extends \PHPUnit_Framework_TestCase { $backend->createCalendarObject(1, "event", "BEGIN:VCALENDAR\r\nBEGIN:VEVENT\r\nDTSTART:20120101\r\nEND:VEVENT\r\nEND:VCALENDAR\r\n"); $backend->createCalendarObject(1, "event2", "BEGIN:VCALENDAR\r\nBEGIN:VEVENT\r\nDTSTART:20120103\r\nEND:VEVENT\r\nEND:VCALENDAR\r\n"); - $filters = array( - 'name' => 'VCALENDAR', - 'comp-filters' => array( - array( - 'name' => 'VEVENT', - 'comp-filters' => array(), - 'prop-filters' => array(), + $filters = [ + 'name' => 'VCALENDAR', + 'comp-filters' => [ + [ + 'name' => 'VEVENT', + 'comp-filters' => [], + 'prop-filters' => [], 'is-not-defined' => false, - 'time-range' => array( + 'time-range' => [ 'start' => new \DateTime('20120102'), - 'end' => null, - ), - ), - ), - 'prop-filters' => array(), + 'end' => null, + ], + ], + ], + 'prop-filters' => [], 'is-not-defined' => false, - 'time-range' => null, - ); + 'time-range' => null, + ]; - $this->assertEquals(array( + $this->assertEquals([ "event2", - ), $backend->calendarQuery(1, $filters)); + ], $backend->calendarQuery(1, $filters)); } + + function testGetChanges() { + + $backend = new PDO($this->pdo); + $id = $backend->createCalendar( + 'principals/user1', + 'bla', + [] + ); + $result = $backend->getChangesForCalendar($id, null, 1); + + $this->assertEquals([ + 'syncToken' => 1, + 'modified' => [], + 'deleted' => [], + 'added' => [], + ], $result); + + $currentToken = $result['syncToken']; + + $dummyTodo = "BEGIN:VCALENDAR\r\nBEGIN:VTODO\r\nEND:VTODO\r\nEND:VCALENDAR\r\n"; + + $backend->createCalendarObject($id, "todo1.ics", $dummyTodo); + $backend->createCalendarObject($id, "todo2.ics", $dummyTodo); + $backend->createCalendarObject($id, "todo3.ics", $dummyTodo); + $backend->updateCalendarObject($id, "todo1.ics", $dummyTodo); + $backend->deleteCalendarObject($id, "todo2.ics"); + + $result = $backend->getChangesForCalendar($id, $currentToken, 1); + + $this->assertEquals([ + 'syncToken' => 6, + 'modified' => ["todo1.ics"], + 'deleted' => ["todo2.ics"], + 'added' => ["todo3.ics"], + ], $result); + + $result = $backend->getChangesForCalendar($id, null, 1); + + $this->assertEquals([ + 'syncToken' => 6, + 'modified' => [], + 'deleted' => [], + 'added' => ["todo1.ics", "todo3.ics"], + ], $result); + } + + function testCreateSubscriptions() { + + $props = [ + '{http://calendarserver.org/ns/}source' => new \Sabre\DAV\Xml\Property\Href('http://example.org/cal.ics', false), + '{DAV:}displayname' => 'cal', + '{http://apple.com/ns/ical/}refreshrate' => 'P1W', + '{http://apple.com/ns/ical/}calendar-color' => '#FF00FFFF', + '{http://calendarserver.org/ns/}subscribed-strip-todos' => true, + //'{http://calendarserver.org/ns/}subscribed-strip-alarms' => true, + '{http://calendarserver.org/ns/}subscribed-strip-attachments' => true, + ]; + + $backend = new PDO($this->pdo); + $backend->createSubscription('principals/user1', 'sub1', $props); + + $subs = $backend->getSubscriptionsForUser('principals/user1'); + + $expected = $props; + $expected['id'] = 1; + $expected['uri'] = 'sub1'; + $expected['principaluri'] = 'principals/user1'; + + unset($expected['{http://calendarserver.org/ns/}source']); + $expected['source'] = 'http://example.org/cal.ics'; + + $this->assertEquals(1, count($subs)); + foreach ($expected as $k => $v) { + $this->assertEquals($subs[0][$k], $expected[$k]); + } + + } + + /** + * @expectedException \Sabre\DAV\Exception\Forbidden + */ + function testCreateSubscriptionFail() { + + $props = [ + ]; + + $backend = new PDO($this->pdo); + $backend->createSubscription('principals/user1', 'sub1', $props); + + } + + function testUpdateSubscriptions() { + + $props = [ + '{http://calendarserver.org/ns/}source' => new \Sabre\DAV\Xml\Property\Href('http://example.org/cal.ics', false), + '{DAV:}displayname' => 'cal', + '{http://apple.com/ns/ical/}refreshrate' => 'P1W', + '{http://apple.com/ns/ical/}calendar-color' => '#FF00FFFF', + '{http://calendarserver.org/ns/}subscribed-strip-todos' => true, + //'{http://calendarserver.org/ns/}subscribed-strip-alarms' => true, + '{http://calendarserver.org/ns/}subscribed-strip-attachments' => true, + ]; + + $backend = new PDO($this->pdo); + $backend->createSubscription('principals/user1', 'sub1', $props); + + $newProps = [ + '{DAV:}displayname' => 'new displayname', + '{http://calendarserver.org/ns/}source' => new \Sabre\DAV\Xml\Property\Href('http://example.org/cal2.ics', false), + ]; + + $propPatch = new DAV\PropPatch($newProps); + $backend->updateSubscription(1, $propPatch); + $result = $propPatch->commit(); + + $this->assertTrue($result); + + $subs = $backend->getSubscriptionsForUser('principals/user1'); + + $expected = array_merge($props, $newProps); + $expected['id'] = 1; + $expected['uri'] = 'sub1'; + $expected['principaluri'] = 'principals/user1'; + + unset($expected['{http://calendarserver.org/ns/}source']); + $expected['source'] = 'http://example.org/cal2.ics'; + + $this->assertEquals(1, count($subs)); + foreach ($expected as $k => $v) { + $this->assertEquals($subs[0][$k], $expected[$k]); + } + + } + + function testUpdateSubscriptionsFail() { + + $props = [ + '{http://calendarserver.org/ns/}source' => new \Sabre\DAV\Xml\Property\Href('http://example.org/cal.ics', false), + '{DAV:}displayname' => 'cal', + '{http://apple.com/ns/ical/}refreshrate' => 'P1W', + '{http://apple.com/ns/ical/}calendar-color' => '#FF00FFFF', + '{http://calendarserver.org/ns/}subscribed-strip-todos' => true, + //'{http://calendarserver.org/ns/}subscribed-strip-alarms' => true, + '{http://calendarserver.org/ns/}subscribed-strip-attachments' => true, + ]; + + $backend = new PDO($this->pdo); + $backend->createSubscription('principals/user1', 'sub1', $props); + + $propPatch = new DAV\PropPatch([ + '{DAV:}displayname' => 'new displayname', + '{http://calendarserver.org/ns/}source' => new \Sabre\DAV\Xml\Property\Href('http://example.org/cal2.ics', false), + '{DAV:}unknown' => 'foo', + ]); + + $backend->updateSubscription(1, $propPatch); + $propPatch->commit(); + + $this->assertEquals([ + '{DAV:}unknown' => 403, + '{DAV:}displayname' => 424, + '{http://calendarserver.org/ns/}source' => 424, + ], $propPatch->getResult()); + + } + + function testDeleteSubscriptions() { + + $props = [ + '{http://calendarserver.org/ns/}source' => new \Sabre\DAV\Xml\Property\Href('http://example.org/cal.ics', false), + '{DAV:}displayname' => 'cal', + '{http://apple.com/ns/ical/}refreshrate' => 'P1W', + '{http://apple.com/ns/ical/}calendar-color' => '#FF00FFFF', + '{http://calendarserver.org/ns/}subscribed-strip-todos' => true, + //'{http://calendarserver.org/ns/}subscribed-strip-alarms' => true, + '{http://calendarserver.org/ns/}subscribed-strip-attachments' => true, + ]; + + $backend = new PDO($this->pdo); + $backend->createSubscription('principals/user1', 'sub1', $props); + + $newProps = [ + '{DAV:}displayname' => 'new displayname', + '{http://calendarserver.org/ns/}source' => new \Sabre\DAV\Xml\Property\Href('http://example.org/cal2.ics', false), + ]; + + $backend->deleteSubscription(1); + + $subs = $backend->getSubscriptionsForUser('principals/user1'); + $this->assertEquals(0, count($subs)); + } + + function testSchedulingMethods() { + + $backend = new PDO($this->pdo); + + $calData = "BEGIN:VCALENDAR\r\nEND:VCALENDAR\r\n"; + + $backend->createSchedulingObject( + 'principals/user1', + 'schedule1.ics', + $calData + ); + + $expected = [ + 'calendardata' => $calData, + 'uri' => 'schedule1.ics', + 'etag' => '"' . md5($calData) . '"', + 'size' => strlen($calData) + ]; + + $result = $backend->getSchedulingObject('principals/user1', 'schedule1.ics'); + foreach ($expected as $k => $v) { + $this->assertArrayHasKey($k, $result); + $this->assertEquals($v, $result[$k]); + } + + $results = $backend->getSchedulingObjects('principals/user1'); + + $this->assertEquals(1, count($results)); + $result = $results[0]; + foreach ($expected as $k => $v) { + $this->assertEquals($v, $result[$k]); + } + + $backend->deleteSchedulingObject('principals/user1', 'schedule1.ics'); + $result = $backend->getSchedulingObject('principals/user1', 'schedule1.ics'); + + $this->assertNull($result); + + } + } diff --git a/vendor/sabre/dav/tests/Sabre/CalDAV/Backend/AbstractTest.php b/vendor/sabre/dav/tests/Sabre/CalDAV/Backend/AbstractTest.php index 04fb16df5..7f642efc9 100644 --- a/vendor/sabre/dav/tests/Sabre/CalDAV/Backend/AbstractTest.php +++ b/vendor/sabre/dav/tests/Sabre/CalDAV/Backend/AbstractTest.php @@ -2,37 +2,92 @@ namespace Sabre\CalDAV\Backend; +use + Sabre\DAV\PropPatch; + class AbstractTest extends \PHPUnit_Framework_TestCase { function testUpdateCalendar() { $abstract = new AbstractMock(); - $this->assertEquals(false, $abstract->updateCalendar('randomid', array('{DAV:}displayname' => 'anything'))); + $propPatch = new PropPatch(['{DAV:}displayname' => 'anything']); + + $abstract->updateCalendar('randomid', $propPatch); + $result = $propPatch->commit(); + + $this->assertFalse($result); } function testCalendarQuery() { $abstract = new AbstractMock(); - $filters = array( - 'name' => 'VCALENDAR', - 'comp-filters' => array( - array( - 'name' => 'VEVENT', - 'comp-filters' => array(), - 'prop-filters' => array(), + $filters = [ + 'name' => 'VCALENDAR', + 'comp-filters' => [ + [ + 'name' => 'VEVENT', + 'comp-filters' => [], + 'prop-filters' => [], 'is-not-defined' => false, - 'time-range' => null, - ), - ), - 'prop-filters' => array(), + 'time-range' => null, + ], + ], + 'prop-filters' => [], 'is-not-defined' => false, - 'time-range' => null, + 'time-range' => null, + ]; + + $this->assertEquals([ + 'event1.ics', + ], $abstract->calendarQuery(1, $filters)); + + } + + function testGetCalendarObjectByUID() { + + $abstract = new AbstractMock(); + $this->assertNull( + $abstract->getCalendarObjectByUID('principal1', 'zim') + ); + $this->assertEquals( + 'cal1/event1.ics', + $abstract->getCalendarObjectByUID('principal1', 'foo') + ); + $this->assertNull( + $abstract->getCalendarObjectByUID('principal3', 'foo') ); + $this->assertNull( + $abstract->getCalendarObjectByUID('principal1', 'shared') + ); + + } - $this->assertEquals(array( + function testGetMultipleCalendarObjects() { + + $abstract = new AbstractMock(); + $result = $abstract->getMultipleCalendarObjects(1, [ 'event1.ics', - ), $abstract->calendarQuery(1, $filters)); + 'task1.ics', + ]); + + $expected = [ + [ + 'id' => 1, + 'calendarid' => 1, + 'uri' => 'event1.ics', + 'calendardata' => "BEGIN:VCALENDAR\r\nBEGIN:VEVENT\r\nUID:foo\r\nEND:VEVENT\r\nEND:VCALENDAR\r\n", + ], + [ + 'id' => 2, + 'calendarid' => 1, + 'uri' => 'task1.ics', + 'calendardata' => "BEGIN:VCALENDAR\r\nBEGIN:VTODO\r\nEND:VTODO\r\nEND:VCALENDAR\r\n", + ], + ]; + + $this->assertEquals($expected, $result); + } @@ -40,49 +95,84 @@ class AbstractTest extends \PHPUnit_Framework_TestCase { class AbstractMock extends AbstractBackend { - function getCalendarsForUser($principalUri) { } - function createCalendar($principalUri,$calendarUri,array $properties) { } + function getCalendarsForUser($principalUri) { + + return [ + [ + 'id' => 1, + 'principaluri' => 'principal1', + 'uri' => 'cal1', + ], + [ + 'id' => 2, + 'principaluri' => 'principal1', + '{http://sabredav.org/ns}owner-principal' => 'principal2', + 'uri' => 'cal1', + ], + ]; + + } + function createCalendar($principalUri, $calendarUri, array $properties) { } function deleteCalendar($calendarId) { } - function getCalendarObjects($calendarId) { - - return array( - array( - 'id' => 1, - 'calendarid' => 1, - 'uri' => 'event1.ics', - ), - array( - 'id' => 2, - 'calendarid' => 1, - 'uri' => 'task1.ics', - ), - ); + function getCalendarObjects($calendarId) { + + switch ($calendarId) { + case 1: + return [ + [ + 'id' => 1, + 'calendarid' => 1, + 'uri' => 'event1.ics', + ], + [ + 'id' => 2, + 'calendarid' => 1, + 'uri' => 'task1.ics', + ], + ]; + case 2: + return [ + [ + 'id' => 3, + 'calendarid' => 2, + 'uri' => 'shared-event.ics', + ] + ]; + } } - function getCalendarObject($calendarId,$objectUri) { - switch($objectUri) { + function getCalendarObject($calendarId, $objectUri) { + + switch ($objectUri) { case 'event1.ics' : - return array( - 'id' => 1, - 'calendarid' => 1, - 'uri' => 'event1.ics', - 'calendardata' => "BEGIN:VCALENDAR\r\nBEGIN:VEVENT\r\nEND:VEVENT\r\nEND:VCALENDAR\r\n", - ); + return [ + 'id' => 1, + 'calendarid' => 1, + 'uri' => 'event1.ics', + 'calendardata' => "BEGIN:VCALENDAR\r\nBEGIN:VEVENT\r\nUID:foo\r\nEND:VEVENT\r\nEND:VCALENDAR\r\n", + ]; case 'task1.ics' : - return array( - 'id' => 1, - 'calendarid' => 1, - 'uri' => 'event1.ics', + return [ + 'id' => 2, + 'calendarid' => 1, + 'uri' => 'task1.ics', 'calendardata' => "BEGIN:VCALENDAR\r\nBEGIN:VTODO\r\nEND:VTODO\r\nEND:VCALENDAR\r\n", - ); + ]; + case 'shared-event.ics' : + return [ + 'id' => 3, + 'calendarid' => 2, + 'uri' => 'event1.ics', + 'calendardata' => "BEGIN:VCALENDAR\r\nBEGIN:VEVENT\r\nUID:shared\r\nEND:VEVENT\r\nEND:VCALENDAR\r\n", + ]; } } - function createCalendarObject($calendarId,$objectUri,$calendarData) { } - function updateCalendarObject($calendarId,$objectUri,$calendarData) { } - function deleteCalendarObject($calendarId,$objectUri) { } + function createCalendarObject($calendarId, $objectUri, $calendarData) { } + function updateCalendarObject($calendarId, $objectUri, $calendarData) { } + function deleteCalendarObject($calendarId, $objectUri) { } } diff --git a/vendor/sabre/dav/tests/Sabre/CalDAV/Backend/Mock.php b/vendor/sabre/dav/tests/Sabre/CalDAV/Backend/Mock.php index d196297f7..4412e5531 100644 --- a/vendor/sabre/dav/tests/Sabre/CalDAV/Backend/Mock.php +++ b/vendor/sabre/dav/tests/Sabre/CalDAV/Backend/Mock.php @@ -1,21 +1,25 @@ <?php namespace Sabre\CalDAV\Backend; + use Sabre\DAV; use Sabre\CalDAV; -class Mock extends AbstractBackend implements NotificationSupport, SharingSupport { +class Mock extends AbstractBackend { + + protected $calendarData; + protected $calendars; - private $calendarData; - private $calendars; - private $notifications; - private $shares = array(); + function __construct(array $calendars = [], array $calendarData = []) { - function __construct(array $calendars, array $calendarData, array $notifications = array()) { + foreach ($calendars as &$calendar) { + if (!isset($calendar['id'])) { + $calendar['id'] = DAV\UUIDUtil::getUUID(); + } + } $this->calendars = $calendars; $this->calendarData = $calendarData; - $this->notifications = $notifications; } @@ -38,8 +42,8 @@ class Mock extends AbstractBackend implements NotificationSupport, SharingSuppor */ function getCalendarsForUser($principalUri) { - $r = array(); - foreach($this->calendars as $row) { + $r = []; + foreach ($this->calendars as $row) { if ($row['principaluri'] == $principalUri) { $r[] = $row; } @@ -63,71 +67,29 @@ class Mock extends AbstractBackend implements NotificationSupport, SharingSuppor * @param array $properties * @return string|int */ - function createCalendar($principalUri,$calendarUri,array $properties) { + function createCalendar($principalUri, $calendarUri, array $properties) { $id = DAV\UUIDUtil::getUUID(); - $this->calendars[] = array_merge(array( - 'id' => $id, - 'principaluri' => $principalUri, - 'uri' => $calendarUri, - '{' . CalDAV\Plugin::NS_CALDAV . '}supported-calendar-component-set' => new CalDAV\Property\SupportedCalendarComponentSet(array('VEVENT','VTODO')), - ), $properties); + $this->calendars[] = array_merge([ + 'id' => $id, + 'principaluri' => $principalUri, + 'uri' => $calendarUri, + '{' . CalDAV\Plugin::NS_CALDAV . '}supported-calendar-component-set' => new CalDAV\Xml\Property\SupportedCalendarComponentSet(['VEVENT', 'VTODO']), + ], $properties); return $id; } /** - * Updates properties on this node, - * - * The properties array uses the propertyName in clark-notation as key, - * and the array value for the property value. In the case a property - * should be deleted, the property value will be null. - * - * This method must be atomic. If one property cannot be changed, the - * entire operation must fail. - * - * If the operation was successful, true can be returned. - * If the operation failed, false can be returned. - * - * Deletion of a non-existent property is always successful. - * - * Lastly, it is optional to return detailed information about any - * failures. In this case an array should be returned with the following - * structure: - * - * array( - * 403 => array( - * '{DAV:}displayname' => null, - * ), - * 424 => array( - * '{DAV:}owner' => null, - * ) - * ) - * - * In this example it was forbidden to update {DAV:}displayname. - * (403 Forbidden), which in turn also caused {DAV:}owner to fail - * (424 Failed Dependency) because the request needs to be atomic. - * - * @param string $calendarId - * @param array $properties - * @return bool|array - */ - public function updateCalendar($calendarId, array $properties) { - - return false; - - } - - /** * Delete a calendar and all it's objects * * @param string $calendarId * @return void */ - public function deleteCalendar($calendarId) { + function deleteCalendar($calendarId) { - foreach($this->calendars as $k=>$calendar) { + foreach ($this->calendars as $k => $calendar) { if ($calendar['id'] === $calendarId) { unset($this->calendars[$k]); } @@ -157,17 +119,17 @@ class Mock extends AbstractBackend implements NotificationSupport, SharingSuppor * @param string $calendarId * @return array */ - public function getCalendarObjects($calendarId) { + function getCalendarObjects($calendarId) { if (!isset($this->calendarData[$calendarId])) - return array(); + return []; $objects = $this->calendarData[$calendarId]; - foreach($objects as $uri => &$object) { + foreach ($objects as $uri => &$object) { $object['calendarid'] = $calendarId; $object['uri'] = $uri; - + $object['lastmodified'] = null; } return $objects; @@ -185,7 +147,7 @@ class Mock extends AbstractBackend implements NotificationSupport, SharingSuppor * @param string $objectUri * @return array */ - function getCalendarObject($calendarId,$objectUri) { + function getCalendarObject($calendarId, $objectUri) { if (!isset($this->calendarData[$calendarId][$objectUri])) { throw new DAV\Exception\NotFound('Object could not be found'); @@ -193,6 +155,7 @@ class Mock extends AbstractBackend implements NotificationSupport, SharingSuppor $object = $this->calendarData[$calendarId][$objectUri]; $object['calendarid'] = $calendarId; $object['uri'] = $objectUri; + $object['lastmodified'] = null; return $object; } @@ -205,13 +168,14 @@ class Mock extends AbstractBackend implements NotificationSupport, SharingSuppor * @param string $calendarData * @return void */ - function createCalendarObject($calendarId,$objectUri,$calendarData) { + function createCalendarObject($calendarId, $objectUri, $calendarData) { - $this->calendarData[$calendarId][$objectUri] = array( + $this->calendarData[$calendarId][$objectUri] = [ 'calendardata' => $calendarData, - 'calendarid' => $calendarId, - 'uri' => $objectUri, - ); + 'calendarid' => $calendarId, + 'uri' => $objectUri, + ]; + return '"' . md5($calendarData) . '"'; } @@ -223,13 +187,14 @@ class Mock extends AbstractBackend implements NotificationSupport, SharingSuppor * @param string $calendarData * @return void */ - function updateCalendarObject($calendarId,$objectUri,$calendarData) { + function updateCalendarObject($calendarId, $objectUri, $calendarData) { - $this->calendarData[$calendarId][$objectUri] = array( + $this->calendarData[$calendarId][$objectUri] = [ 'calendardata' => $calendarData, - 'calendarid' => $calendarId, - 'uri' => $objectUri, - ); + 'calendarid' => $calendarId, + 'uri' => $objectUri, + ]; + return '"' . md5($calendarData) . '"'; } @@ -240,161 +205,11 @@ class Mock extends AbstractBackend implements NotificationSupport, SharingSuppor * @param string $objectUri * @return void */ - function deleteCalendarObject($calendarId,$objectUri) { + function deleteCalendarObject($calendarId, $objectUri) { throw new Exception('Not implemented'); } - /** - * Returns a list of notifications for a given principal url. - * - * The returned array should only consist of implementations of - * Sabre\CalDAV\Notifications\INotificationType. - * - * @param string $principalUri - * @return array - */ - public function getNotificationsForPrincipal($principalUri) { - - if (isset($this->notifications[$principalUri])) { - return $this->notifications[$principalUri]; - } - return array(); - - } - - /** - * This deletes a specific notifcation. - * - * This may be called by a client once it deems a notification handled. - * - * @param string $principalUri - * @param Sabre\CalDAV\Notifications\INotificationType $notification - * @return void - */ - public function deleteNotification($principalUri, CalDAV\Notifications\INotificationType $notification) { - - foreach($this->notifications[$principalUri] as $key=>$value) { - if ($notification === $value) { - unset($this->notifications[$principalUri][$key]); - } - } - - } - - /** - * Updates the list of shares. - * - * The first array is a list of people that are to be added to the - * calendar. - * - * Every element in the add array has the following properties: - * * href - A url. Usually a mailto: address - * * commonName - Usually a first and last name, or false - * * summary - A description of the share, can also be false - * * readOnly - A boolean value - * - * Every element in the remove array is just the address string. - * - * Note that if the calendar is currently marked as 'not shared' by and - * this method is called, the calendar should be 'upgraded' to a shared - * calendar. - * - * @param mixed $calendarId - * @param array $add - * @param array $remove - * @return void - */ - public function updateShares($calendarId, array $add, array $remove) { - - if (!isset($this->shares[$calendarId])) { - $this->shares[$calendarId] = array(); - } - - foreach($add as $val) { - $val['status'] = CalDAV\SharingPlugin::STATUS_NORESPONSE; - $this->shares[$calendarId][] = $val; - } - - foreach($this->shares[$calendarId] as $k=>$share) { - - if (in_array($share['href'], $remove)) { - unset($this->shares[$calendarId][$k]); - } - - } - - // Re-numbering keys - $this->shares[$calendarId] = array_values($this->shares[$calendarId]); - - } - - /** - * Returns the list of people whom this calendar is shared with. - * - * Every element in this array should have the following properties: - * * href - Often a mailto: address - * * commonName - Optional, for example a first + last name - * * status - See the Sabre\CalDAV\SharingPlugin::STATUS_ constants. - * * readOnly - boolean - * * summary - Optional, a description for the share - * - * @param mixed $calendarId - * @return array - */ - public function getShares($calendarId) { - - if (!isset($this->shares[$calendarId])) { - return array(); - } - - return $this->shares[$calendarId]; - - } - - /** - * This method is called when a user replied to a request to share. - * - * @param string href The sharee who is replying (often a mailto: address) - * @param int status One of the SharingPlugin::STATUS_* constants - * @param string $calendarUri The url to the calendar thats being shared - * @param string $inReplyTo The unique id this message is a response to - * @param string $summary A description of the reply - * @return void - */ - public function shareReply($href, $status, $calendarUri, $inReplyTo, $summary = null) { - - // This operation basically doesn't do anything yet - if ($status === CalDAV\SharingPlugin::STATUS_ACCEPTED) { - return 'calendars/blabla/calendar'; - } - - } - - /** - * Publishes a calendar - * - * @param mixed $calendarId - * @param bool $value - * @return void - */ - public function setPublishStatus($calendarId, $value) { - - foreach($this->calendars as $k=>$cal) { - if ($cal['id'] === $calendarId) { - if (!$value) { - unset($cal['{http://calendarserver.org/ns/}publish-url']); - } else { - $cal['{http://calendarserver.org/ns/}publish-url'] = 'http://example.org/public/ ' . $calendarId . '.ics'; - } - return; - } - } - - throw new DAV\Exception('Calendar with id "' . $calendarId . '" not found'); - - } - } diff --git a/vendor/sabre/dav/tests/Sabre/CalDAV/Backend/PDOMySQLTest.php b/vendor/sabre/dav/tests/Sabre/CalDAV/Backend/PDOMySQLTest.php index 15c1d91fd..c215ca171 100644 --- a/vendor/sabre/dav/tests/Sabre/CalDAV/Backend/PDOMySQLTest.php +++ b/vendor/sabre/dav/tests/Sabre/CalDAV/Backend/PDOMySQLTest.php @@ -14,15 +14,15 @@ class PDOMySQLTest extends AbstractPDOTest { $pdo = \Sabre\TestUtil::getMySQLDB(); if (!$pdo) $this->markTestSkipped('Could not connect to mysql database'); - $pdo->query('DROP TABLE IF EXISTS calendarobjects, calendars'); + $pdo->query('DROP TABLE IF EXISTS calendarobjects, calendars, calendarchanges, calendarsubscriptions, schedulingobjects'); $queries = explode( ';', file_get_contents(__DIR__ . '/../../../../examples/sql/mysql.calendars.sql') ); - foreach($queries as $query) { - $query = trim($query," \r\n\t"); + foreach ($queries as $query) { + $query = trim($query, " \r\n\t"); if ($query) $pdo->exec($query); } diff --git a/vendor/sabre/dav/tests/Sabre/CalDAV/Backend/PDOSqliteTest.php b/vendor/sabre/dav/tests/Sabre/CalDAV/Backend/PDOSqliteTest.php index c50f06986..4074259f2 100644 --- a/vendor/sabre/dav/tests/Sabre/CalDAV/Backend/PDOSqliteTest.php +++ b/vendor/sabre/dav/tests/Sabre/CalDAV/Backend/PDOSqliteTest.php @@ -6,12 +6,24 @@ use Sabre\CalDAV; require_once 'Sabre/CalDAV/Backend/AbstractPDOTest.php'; -class PDOSQLiteTest extends AbstractPDOTest { +class PDOSqliteTest extends AbstractPDOTest { function setup() { if (!SABRE_HASSQLITE) $this->markTestSkipped('SQLite driver is not available'); - $this->pdo = CalDAV\TestUtil::getSQLiteDB(); + + if (file_exists(SABRE_TEMPDIR . '/testdb.sqlite')) + unlink(SABRE_TEMPDIR . '/testdb.sqlite'); + + $pdo = new \PDO('sqlite:' . SABRE_TEMPDIR . '/testdb.sqlite'); + $pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION); + + // Yup this is definitely not 'fool proof', but good enough for now. + $queries = explode(';', file_get_contents(__DIR__ . '/../../../../examples/sql/sqlite.calendars.sql')); + foreach ($queries as $query) { + $pdo->exec($query); + } + $this->pdo = $pdo; } |