aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/sabre/dav/tests/Sabre/CalDAV/Backend
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/sabre/dav/tests/Sabre/CalDAV/Backend')
-rw-r--r--vendor/sabre/dav/tests/Sabre/CalDAV/Backend/AbstractPDOTest.php624
-rw-r--r--vendor/sabre/dav/tests/Sabre/CalDAV/Backend/Mock.php53
-rw-r--r--vendor/sabre/dav/tests/Sabre/CalDAV/Backend/PDOMySQLTest.php32
-rw-r--r--vendor/sabre/dav/tests/Sabre/CalDAV/Backend/PDOSqliteTest.php30
4 files changed, 631 insertions, 108 deletions
diff --git a/vendor/sabre/dav/tests/Sabre/CalDAV/Backend/AbstractPDOTest.php b/vendor/sabre/dav/tests/Sabre/CalDAV/Backend/AbstractPDOTest.php
index 25f8b1794..35d6da353 100644
--- a/vendor/sabre/dav/tests/Sabre/CalDAV/Backend/AbstractPDOTest.php
+++ b/vendor/sabre/dav/tests/Sabre/CalDAV/Backend/AbstractPDOTest.php
@@ -5,11 +5,30 @@ namespace Sabre\CalDAV\Backend;
use Sabre\CalDAV;
use Sabre\DAV;
use Sabre\DAV\PropPatch;
+use Sabre\DAV\Xml\Element\Sharee;
abstract class AbstractPDOTest extends \PHPUnit_Framework_TestCase {
+ use DAV\DbTestHelperTrait;
+
protected $pdo;
+ function setUp() {
+
+ $this->dropTables([
+ 'calendarobjects',
+ 'calendars',
+ 'calendarinstances',
+ 'calendarchanges',
+ 'calendarsubscriptions',
+ 'schedulingobjects',
+ ]);
+ $this->createSchema('calendars');
+
+ $this->pdo = $this->getDb();
+
+ }
+
function testConstruct() {
$backend = new PDO($this->pdo);
@@ -42,11 +61,11 @@ abstract class AbstractPDOTest extends \PHPUnit_Framework_TestCase {
$calendars = $backend->getCalendarsForUser('principals/user2');
$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'),
+ 'share-access' => \Sabre\DAV\Sharing\Plugin::ACCESS_SHAREDOWNER,
];
$this->assertInternalType('array', $calendars);
@@ -110,6 +129,27 @@ abstract class AbstractPDOTest extends \PHPUnit_Framework_TestCase {
}
/**
+ * @depends testConstruct
+ * @expectedException \InvalidArgumentException
+ */
+ function testUpdateCalendarBadId() {
+
+ $backend = new PDO($this->pdo);
+
+ //Creating a new calendar
+ $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
+ $backend->updateCalendar('raaaa', $propPatch);
+
+ }
+
+ /**
* @depends testUpdateCalendarAndFetch
*/
function testUpdateCalendarUnknownProperty() {
@@ -156,6 +196,22 @@ abstract class AbstractPDOTest extends \PHPUnit_Framework_TestCase {
/**
* @depends testCreateCalendarAndFetch
+ * @expectedException \InvalidArgumentException
+ */
+ function testDeleteCalendarBadID() {
+
+ $backend = new PDO($this->pdo);
+ $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('bad-id');
+
+ }
+
+ /**
+ * @depends testCreateCalendarAndFetch
* @expectedException \Sabre\DAV\Exception
*/
function testCreateCalendarIncorrectComponentSet() {;
@@ -178,7 +234,13 @@ abstract class AbstractPDOTest extends \PHPUnit_Framework_TestCase {
$backend->createCalendarObject($returnedId, 'random-id', $object);
- $result = $this->pdo->query('SELECT etag, size, calendardata, firstoccurence, lastoccurence, componenttype FROM calendarobjects WHERE uri = "random-id"');
+ $result = $this->pdo->query('SELECT etag, size, calendardata, firstoccurence, lastoccurence, componenttype FROM calendarobjects WHERE uri = \'random-id\'');
+
+ $row = $result->fetch(\PDO::FETCH_ASSOC);
+ if (is_resource($row['calendardata'])) {
+ $row['calendardata'] = stream_get_contents($row['calendardata']);
+ }
+
$this->assertEquals([
'etag' => md5($object),
'size' => strlen($object),
@@ -186,7 +248,7 @@ abstract class AbstractPDOTest extends \PHPUnit_Framework_TestCase {
'firstoccurence' => strtotime('20120101'),
'lastoccurence' => strtotime('20120101') + (3600 * 24),
'componenttype' => 'VEVENT',
- ], $result->fetch(\PDO::FETCH_ASSOC));
+ ], $row);
}
function testGetMultipleObjects() {
@@ -207,7 +269,6 @@ abstract class AbstractPDOTest extends \PHPUnit_Framework_TestCase {
'size' => strlen($object),
'calendardata' => $object,
'lastmodified' => null,
- 'calendarid' => $returnedId,
],
[
'id' => 2,
@@ -216,7 +277,6 @@ abstract class AbstractPDOTest extends \PHPUnit_Framework_TestCase {
'size' => strlen($object),
'calendardata' => $object,
'lastmodified' => null,
- 'calendarid' => $returnedId,
],
];
@@ -224,12 +284,22 @@ abstract class AbstractPDOTest extends \PHPUnit_Framework_TestCase {
foreach ($check as $index => $props) {
- foreach ($props as $key => $value) {
+ foreach ($props as $key => $expected) {
+
+ $actual = $result[$index][$key];
+
+ switch ($key) {
+ case 'lastmodified' :
+ $this->assertInternalType('int', $actual);
+ break;
+ case 'calendardata' :
+ if (is_resource($actual)) {
+ $actual = stream_get_contents($actual);
+ }
+ // no break intentional
+ default :
+ $this->assertEquals($expected, $actual);
- if ($key !== 'lastmodified') {
- $this->assertEquals($value, $result[$index][$key]);
- } else {
- $this->assertTrue(isset($result[$index][$key]));
}
}
@@ -239,6 +309,17 @@ abstract class AbstractPDOTest extends \PHPUnit_Framework_TestCase {
}
/**
+ * @depends testGetMultipleObjects
+ * @expectedException \InvalidArgumentException
+ */
+ function testGetMultipleObjectsBadId() {
+
+ $backend = new PDO($this->pdo);
+ $backend->getMultipleCalendarObjects('bad-id', ['foo-bar']);
+
+ }
+
+ /**
* @expectedException Sabre\DAV\Exception\BadRequest
* @depends testCreateCalendarObject
*/
@@ -265,7 +346,13 @@ abstract class AbstractPDOTest extends \PHPUnit_Framework_TestCase {
$backend->createCalendarObject($returnedId, 'random-id', $object);
- $result = $this->pdo->query('SELECT etag, size, calendardata, firstoccurence, lastoccurence, componenttype FROM calendarobjects WHERE uri = "random-id"');
+ $result = $this->pdo->query('SELECT etag, size, calendardata, firstoccurence, lastoccurence, componenttype FROM calendarobjects WHERE uri = \'random-id\'');
+
+ $row = $result->fetch(\PDO::FETCH_ASSOC);
+ if (is_resource($row['calendardata'])) {
+ $row['calendardata'] = stream_get_contents($row['calendardata']);
+ }
+
$this->assertEquals([
'etag' => md5($object),
'size' => strlen($object),
@@ -273,10 +360,26 @@ abstract class AbstractPDOTest extends \PHPUnit_Framework_TestCase {
'firstoccurence' => strtotime('20120101'),
'lastoccurence' => strtotime('20120101') + (3600 * 48),
'componenttype' => 'VEVENT',
- ], $result->fetch(\PDO::FETCH_ASSOC));
+ ], $row);
+
+ }
+
+ /**
+ * @depends testCreateCalendarObject
+ * @expectedException \InvalidArgumentException
+ */
+ function testCreateCalendarObjectBadId() {
+
+ $backend = new PDO($this->pdo);
+ $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('bad-id', 'random-id', $object);
}
+
/**
* @depends testCreateCalendarObject
*/
@@ -289,7 +392,12 @@ abstract class AbstractPDOTest extends \PHPUnit_Framework_TestCase {
$backend->createCalendarObject($returnedId, 'random-id', $object);
- $result = $this->pdo->query('SELECT etag, size, calendardata, firstoccurence, lastoccurence, componenttype FROM calendarobjects WHERE uri = "random-id"');
+ $result = $this->pdo->query('SELECT etag, size, calendardata, firstoccurence, lastoccurence, componenttype FROM calendarobjects WHERE uri = \'random-id\'');
+ $row = $result->fetch(\PDO::FETCH_ASSOC);
+ if (is_resource($row['calendardata'])) {
+ $row['calendardata'] = stream_get_contents($row['calendardata']);
+ }
+
$this->assertEquals([
'etag' => md5($object),
'size' => strlen($object),
@@ -297,7 +405,7 @@ abstract class AbstractPDOTest extends \PHPUnit_Framework_TestCase {
'firstoccurence' => strtotime('2012-01-01 10:00:00'),
'lastoccurence' => strtotime('2012-01-01 10:00:00'),
'componenttype' => 'VEVENT',
- ], $result->fetch(\PDO::FETCH_ASSOC));
+ ], $row);
}
@@ -313,7 +421,12 @@ abstract class AbstractPDOTest extends \PHPUnit_Framework_TestCase {
$backend->createCalendarObject($returnedId, 'random-id', $object);
- $result = $this->pdo->query('SELECT etag, size, calendardata, firstoccurence, lastoccurence, componenttype FROM calendarobjects WHERE uri = "random-id"');
+ $result = $this->pdo->query('SELECT etag, size, calendardata, firstoccurence, lastoccurence, componenttype FROM calendarobjects WHERE uri = \'random-id\'');
+ $row = $result->fetch(\PDO::FETCH_ASSOC);
+ if (is_resource($row['calendardata'])) {
+ $row['calendardata'] = stream_get_contents($row['calendardata']);
+ }
+
$this->assertEquals([
'etag' => md5($object),
'size' => strlen($object),
@@ -321,7 +434,7 @@ abstract class AbstractPDOTest extends \PHPUnit_Framework_TestCase {
'firstoccurence' => strtotime('2012-01-01 10:00:00'),
'lastoccurence' => strtotime('2012-01-01 11:00:00'),
'componenttype' => 'VEVENT',
- ], $result->fetch(\PDO::FETCH_ASSOC));
+ ], $row);
}
@@ -337,7 +450,12 @@ abstract class AbstractPDOTest extends \PHPUnit_Framework_TestCase {
$backend->createCalendarObject($returnedId, 'random-id', $object);
- $result = $this->pdo->query('SELECT etag, size, calendardata, firstoccurence, lastoccurence, componenttype FROM calendarobjects WHERE uri = "random-id"');
+ $result = $this->pdo->query('SELECT etag, size, calendardata, firstoccurence, lastoccurence, componenttype FROM calendarobjects WHERE uri = \'random-id\'');
+ $row = $result->fetch(\PDO::FETCH_ASSOC);
+ if (is_resource($row['calendardata'])) {
+ $row['calendardata'] = stream_get_contents($row['calendardata']);
+ }
+
$this->assertEquals([
'etag' => md5($object),
'size' => strlen($object),
@@ -345,7 +463,7 @@ abstract class AbstractPDOTest extends \PHPUnit_Framework_TestCase {
'firstoccurence' => strtotime('2012-01-01 10:00:00'),
'lastoccurence' => strtotime(PDO::MAX_DATE),
'componenttype' => 'VEVENT',
- ], $result->fetch(\PDO::FETCH_ASSOC));
+ ], $row);
}
@@ -361,7 +479,12 @@ abstract class AbstractPDOTest extends \PHPUnit_Framework_TestCase {
$backend->createCalendarObject($returnedId, 'random-id', $object);
- $result = $this->pdo->query('SELECT etag, size, calendardata, firstoccurence, lastoccurence, componenttype FROM calendarobjects WHERE uri = "random-id"');
+ $result = $this->pdo->query('SELECT etag, size, calendardata, firstoccurence, lastoccurence, componenttype FROM calendarobjects WHERE uri = \'random-id\'');
+ $row = $result->fetch(\PDO::FETCH_ASSOC);
+ if (is_resource($row['calendardata'])) {
+ $row['calendardata'] = stream_get_contents($row['calendardata']);
+ }
+
$this->assertEquals([
'etag' => md5($object),
'size' => strlen($object),
@@ -369,7 +492,7 @@ abstract class AbstractPDOTest extends \PHPUnit_Framework_TestCase {
'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));
+ ], $row);
}
@@ -385,7 +508,12 @@ abstract class AbstractPDOTest extends \PHPUnit_Framework_TestCase {
$backend->createCalendarObject($returnedId, 'random-id', $object);
- $result = $this->pdo->query('SELECT etag, size, calendardata, firstoccurence, lastoccurence, componenttype FROM calendarobjects WHERE uri = "random-id"');
+ $result = $this->pdo->query('SELECT etag, size, calendardata, firstoccurence, lastoccurence, componenttype FROM calendarobjects WHERE uri = \'random-id\'');
+ $row = $result->fetch(\PDO::FETCH_ASSOC);
+ if (is_resource($row['calendardata'])) {
+ $row['calendardata'] = stream_get_contents($row['calendardata']);
+ }
+
$this->assertEquals([
'etag' => md5($object),
'size' => strlen($object),
@@ -393,7 +521,7 @@ abstract class AbstractPDOTest extends \PHPUnit_Framework_TestCase {
'firstoccurence' => null,
'lastoccurence' => null,
'componenttype' => 'VTODO',
- ], $result->fetch(\PDO::FETCH_ASSOC));
+ ], $row);
}
@@ -408,17 +536,38 @@ abstract class AbstractPDOTest extends \PHPUnit_Framework_TestCase {
$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);
$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']);
+ }
+
+ /**
+ * @depends testGetCalendarObjects
+ * @expectedException \InvalidArgumentException
+ */
+ function testGetCalendarObjectsBadId() {
+
+ $backend = new PDO($this->pdo);
+ $backend->getCalendarObjects('bad-id');
}
+
+ /**
+ * @depends testGetCalendarObjects
+ * @expectedException \InvalidArgumentException
+ */
+ function testGetCalendarObjectBadId() {
+
+ $backend = new PDO($this->pdo);
+ $backend->getCalendarObject('bad-id', 'foo-bar');
+
+ }
+
/**
* @depends testCreateCalendarObject
*/
@@ -455,14 +604,28 @@ abstract class AbstractPDOTest extends \PHPUnit_Framework_TestCase {
$data = $backend->getCalendarObject($returnedId, 'random-id');
+ if (is_resource($data['calendardata'])) {
+ $data['calendardata'] = stream_get_contents($data['calendardata']);
+ }
+
$this->assertEquals($object2, $data['calendardata']);
- $this->assertEquals($returnedId, $data['calendarid']);
$this->assertEquals('random-id', $data['uri']);
}
/**
+ * @depends testUpdateCalendarObject
+ * @expectedException \InvalidArgumentException
+ */
+ function testUpdateCalendarObjectBadId() {
+
+ $backend = new PDO($this->pdo);
+ $backend->updateCalendarObject('bad-id', 'object-id', 'objectdata');
+
+ }
+
+ /**
* @depends testCreateCalendarObject
*/
function testDeleteCalendarObject() {
@@ -479,6 +642,21 @@ abstract class AbstractPDOTest extends \PHPUnit_Framework_TestCase {
}
+ /**
+ * @depends testDeleteCalendarObject
+ * @expectedException \InvalidArgumentException
+ */
+ function testDeleteCalendarObjectBadId() {
+
+ $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, 'random-id', $object);
+ $backend->deleteCalendarObject('bad-id', 'random-id');
+
+ }
+
function testCalendarQueryNoResult() {
$abstract = new PDO($this->pdo);
@@ -499,15 +677,42 @@ abstract class AbstractPDOTest extends \PHPUnit_Framework_TestCase {
];
$this->assertEquals([
- ], $abstract->calendarQuery(1, $filters));
+ ], $abstract->calendarQuery([1, 1], $filters));
+
+ }
+
+ /**
+ * @expectedException \InvalidArgumentException
+ * @depends testCalendarQueryNoResult
+ */
+ function testCalendarQueryBadId() {
+
+ $abstract = new PDO($this->pdo);
+ $filters = [
+ 'name' => 'VCALENDAR',
+ 'comp-filters' => [
+ [
+ 'name' => 'VJOURNAL',
+ 'comp-filters' => [],
+ 'prop-filters' => [],
+ 'is-not-defined' => false,
+ 'time-range' => null,
+ ],
+ ],
+ 'prop-filters' => [],
+ 'is-not-defined' => false,
+ 'time-range' => null,
+ ];
+
+ $abstract->calendarQuery('bad-id', $filters);
}
function testCalendarQueryTodo() {
$backend = new PDO($this->pdo);
- $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");
+ $backend->createCalendarObject([1, 1], "todo", "BEGIN:VCALENDAR\r\nBEGIN:VTODO\r\nEND:VTODO\r\nEND:VCALENDAR\r\n");
+ $backend->createCalendarObject([1, 1], "event", "BEGIN:VCALENDAR\r\nBEGIN:VEVENT\r\nDTSTART:20120101\r\nEND:VEVENT\r\nEND:VCALENDAR\r\n");
$filters = [
'name' => 'VCALENDAR',
@@ -527,14 +732,14 @@ abstract class AbstractPDOTest extends \PHPUnit_Framework_TestCase {
$this->assertEquals([
"todo",
- ], $backend->calendarQuery(1, $filters));
+ ], $backend->calendarQuery([1, 1], $filters));
}
function testCalendarQueryTodoNotMatch() {
$backend = new PDO($this->pdo);
- $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");
+ $backend->createCalendarObject([1, 1], "todo", "BEGIN:VCALENDAR\r\nBEGIN:VTODO\r\nEND:VTODO\r\nEND:VCALENDAR\r\n");
+ $backend->createCalendarObject([1, 1], "event", "BEGIN:VCALENDAR\r\nBEGIN:VEVENT\r\nDTSTART:20120101\r\nEND:VEVENT\r\nEND:VCALENDAR\r\n");
$filters = [
'name' => 'VCALENDAR',
@@ -561,15 +766,15 @@ abstract class AbstractPDOTest extends \PHPUnit_Framework_TestCase {
];
$this->assertEquals([
- ], $backend->calendarQuery(1, $filters));
+ ], $backend->calendarQuery([1, 1], $filters));
}
function testCalendarQueryNoFilter() {
$backend = new PDO($this->pdo);
- $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");
+ $backend->createCalendarObject([1, 1], "todo", "BEGIN:VCALENDAR\r\nBEGIN:VTODO\r\nEND:VTODO\r\nEND:VCALENDAR\r\n");
+ $backend->createCalendarObject([1, 1], "event", "BEGIN:VCALENDAR\r\nBEGIN:VEVENT\r\nDTSTART:20120101\r\nEND:VEVENT\r\nEND:VCALENDAR\r\n");
$filters = [
'name' => 'VCALENDAR',
@@ -579,7 +784,7 @@ abstract class AbstractPDOTest extends \PHPUnit_Framework_TestCase {
'time-range' => null,
];
- $result = $backend->calendarQuery(1, $filters);
+ $result = $backend->calendarQuery([1, 1], $filters);
$this->assertTrue(in_array('todo', $result));
$this->assertTrue(in_array('event', $result));
@@ -588,9 +793,9 @@ abstract class AbstractPDOTest extends \PHPUnit_Framework_TestCase {
function testCalendarQueryTimeRange() {
$backend = new PDO($this->pdo);
- $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;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");
+ $backend->createCalendarObject([1, 1], "todo", "BEGIN:VCALENDAR\r\nBEGIN:VTODO\r\nEND:VTODO\r\nEND:VCALENDAR\r\n");
+ $backend->createCalendarObject([1, 1], "event", "BEGIN:VCALENDAR\r\nBEGIN:VEVENT\r\nDTSTART;VALUE=DATE:20120101\r\nEND:VEVENT\r\nEND:VCALENDAR\r\n");
+ $backend->createCalendarObject([1, 1], "event2", "BEGIN:VCALENDAR\r\nBEGIN:VEVENT\r\nDTSTART;VALUE=DATE:20120103\r\nEND:VEVENT\r\nEND:VCALENDAR\r\n");
$filters = [
'name' => 'VCALENDAR',
@@ -613,15 +818,15 @@ abstract class AbstractPDOTest extends \PHPUnit_Framework_TestCase {
$this->assertEquals([
"event2",
- ], $backend->calendarQuery(1, $filters));
+ ], $backend->calendarQuery([1, 1], $filters));
}
function testCalendarQueryTimeRangeNoEnd() {
$backend = new PDO($this->pdo);
- $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");
- $backend->createCalendarObject(1, "event2", "BEGIN:VCALENDAR\r\nBEGIN:VEVENT\r\nDTSTART:20120103\r\nEND:VEVENT\r\nEND:VCALENDAR\r\n");
+ $backend->createCalendarObject([1, 1], "todo", "BEGIN:VCALENDAR\r\nBEGIN:VTODO\r\nEND:VTODO\r\nEND:VCALENDAR\r\n");
+ $backend->createCalendarObject([1, 1], "event", "BEGIN:VCALENDAR\r\nBEGIN:VEVENT\r\nDTSTART:20120101\r\nEND:VEVENT\r\nEND:VCALENDAR\r\n");
+ $backend->createCalendarObject([1, 1], "event2", "BEGIN:VCALENDAR\r\nBEGIN:VEVENT\r\nDTSTART:20120103\r\nEND:VEVENT\r\nEND:VCALENDAR\r\n");
$filters = [
'name' => 'VCALENDAR',
@@ -644,7 +849,7 @@ abstract class AbstractPDOTest extends \PHPUnit_Framework_TestCase {
$this->assertEquals([
"event2",
- ], $backend->calendarQuery(1, $filters));
+ ], $backend->calendarQuery([1, 1], $filters));
}
@@ -694,6 +899,22 @@ abstract class AbstractPDOTest extends \PHPUnit_Framework_TestCase {
], $result);
}
+ /**
+ * @depends testGetChanges
+ * @expectedException \InvalidArgumentException
+ */
+ function testGetChangesBadId() {
+
+ $backend = new PDO($this->pdo);
+ $id = $backend->createCalendar(
+ 'principals/user1',
+ 'bla',
+ []
+ );
+ $backend->getChangesForCalendar('bad-id', null, 1);
+
+ }
+
function testCreateSubscriptions() {
$props = [
@@ -862,6 +1083,9 @@ abstract class AbstractPDOTest extends \PHPUnit_Framework_TestCase {
$result = $backend->getSchedulingObject('principals/user1', 'schedule1.ics');
foreach ($expected as $k => $v) {
$this->assertArrayHasKey($k, $result);
+ if (is_resource($result[$k])) {
+ $result[$k] = stream_get_contents($result[$k]);
+ }
$this->assertEquals($v, $result[$k]);
}
@@ -870,6 +1094,9 @@ abstract class AbstractPDOTest extends \PHPUnit_Framework_TestCase {
$this->assertEquals(1, count($results));
$result = $results[0];
foreach ($expected as $k => $v) {
+ if (is_resource($result[$k])) {
+ $result[$k] = stream_get_contents($result[$k]);
+ }
$this->assertEquals($v, $result[$k]);
}
@@ -880,4 +1107,315 @@ abstract class AbstractPDOTest extends \PHPUnit_Framework_TestCase {
}
+ function testGetInvites() {
+
+ $backend = new PDO($this->pdo);
+
+ // creating a new calendar
+ $backend->createCalendar('principals/user1', 'somerandomid', []);
+ $calendar = $backend->getCalendarsForUser('principals/user1')[0];
+
+ $result = $backend->getInvites($calendar['id']);
+ $expected = [
+ new Sharee([
+ 'href' => 'principals/user1',
+ 'principal' => 'principals/user1',
+ 'access' => \Sabre\DAV\Sharing\Plugin::ACCESS_SHAREDOWNER,
+ 'inviteStatus' => \Sabre\DAV\Sharing\Plugin::INVITE_ACCEPTED,
+ ])
+ ];
+
+ $this->assertEquals($expected, $result);
+
+ }
+
+ /**
+ * @depends testGetInvites
+ * @expectedException \InvalidArgumentException
+ */
+ function testGetInvitesBadId() {
+
+ $backend = new PDO($this->pdo);
+
+ // creating a new calendar
+ $backend->createCalendar('principals/user1', 'somerandomid', []);
+ $calendar = $backend->getCalendarsForUser('principals/user1')[0];
+
+ $backend->getInvites('bad-id');
+
+ }
+
+ /**
+ * @depends testCreateCalendarAndFetch
+ */
+ function testUpdateInvites() {
+
+ $backend = new PDO($this->pdo);
+
+ // creating a new calendar
+ $backend->createCalendar('principals/user1', 'somerandomid', []);
+ $calendar = $backend->getCalendarsForUser('principals/user1')[0];
+
+ $ownerSharee = new Sharee([
+ 'href' => 'principals/user1',
+ 'principal' => 'principals/user1',
+ 'access' => \Sabre\DAV\Sharing\Plugin::ACCESS_SHAREDOWNER,
+ 'inviteStatus' => \Sabre\DAV\Sharing\Plugin::INVITE_ACCEPTED,
+ ]);
+
+ // Add a new invite
+ $backend->updateInvites(
+ $calendar['id'],
+ [
+ new Sharee([
+ 'href' => 'mailto:user@example.org',
+ 'principal' => 'principals/user2',
+ 'access' => \Sabre\DAV\Sharing\Plugin::ACCESS_READ,
+ 'inviteStatus' => \Sabre\DAV\Sharing\Plugin::INVITE_ACCEPTED,
+ 'properties' => ['{DAV:}displayname' => 'User 2'],
+ ])
+ ]
+ );
+
+ $result = $backend->getInvites($calendar['id']);
+ $expected = [
+ $ownerSharee,
+ new Sharee([
+ 'href' => 'mailto:user@example.org',
+ 'principal' => 'principals/user2',
+ 'access' => \Sabre\DAV\Sharing\Plugin::ACCESS_READ,
+ 'inviteStatus' => \Sabre\DAV\Sharing\Plugin::INVITE_ACCEPTED,
+ 'properties' => [
+ '{DAV:}displayname' => 'User 2',
+ ],
+ ])
+ ];
+ $this->assertEquals($expected, $result);
+
+ // Checking calendar_instances too
+ $expectedCalendar = [
+ 'id' => [1,2],
+ 'principaluri' => 'principals/user2',
+ '{http://calendarserver.org/ns/}getctag' => 'http://sabre.io/ns/sync/1',
+ '{http://sabredav.org/ns}sync-token' => '1',
+ 'share-access' => \Sabre\DAV\Sharing\Plugin::ACCESS_READ,
+ 'read-only' => true,
+ 'share-resource-uri' => '/ns/share/1',
+ ];
+ $calendars = $backend->getCalendarsForUser('principals/user2');
+
+ foreach ($expectedCalendar as $k => $v) {
+ $this->assertEquals(
+ $v,
+ $calendars[0][$k],
+ "Key " . $k . " in calendars array did not have the expected value."
+ );
+ }
+
+
+ // Updating an invite
+ $backend->updateInvites(
+ $calendar['id'],
+ [
+ new Sharee([
+ 'href' => 'mailto:user@example.org',
+ 'principal' => 'principals/user2',
+ 'access' => \Sabre\DAV\Sharing\Plugin::ACCESS_READWRITE,
+ 'inviteStatus' => \Sabre\DAV\Sharing\Plugin::INVITE_ACCEPTED,
+ ])
+ ]
+ );
+
+ $result = $backend->getInvites($calendar['id']);
+ $expected = [
+ $ownerSharee,
+ new Sharee([
+ 'href' => 'mailto:user@example.org',
+ 'principal' => 'principals/user2',
+ 'access' => \Sabre\DAV\Sharing\Plugin::ACCESS_READWRITE,
+ 'inviteStatus' => \Sabre\DAV\Sharing\Plugin::INVITE_ACCEPTED,
+ 'properties' => [
+ '{DAV:}displayname' => 'User 2',
+ ],
+ ])
+ ];
+ $this->assertEquals($expected, $result);
+
+ // Removing an invite
+ $backend->updateInvites(
+ $calendar['id'],
+ [
+ new Sharee([
+ 'href' => 'mailto:user@example.org',
+ 'access' => \Sabre\DAV\Sharing\Plugin::ACCESS_NOACCESS,
+ ])
+ ]
+ );
+
+ $result = $backend->getInvites($calendar['id']);
+ $expected = [
+ $ownerSharee
+ ];
+ $this->assertEquals($expected, $result);
+
+ // Preventing the owner share from being removed
+ $backend->updateInvites(
+ $calendar['id'],
+ [
+ new Sharee([
+ 'href' => 'principals/user2',
+ 'access' => \Sabre\DAV\Sharing\Plugin::ACCESS_NOACCESS,
+ ])
+ ]
+ );
+
+ $result = $backend->getInvites($calendar['id']);
+ $expected = [
+ new Sharee([
+ 'href' => 'principals/user1',
+ 'principal' => 'principals/user1',
+ 'access' => \Sabre\DAV\Sharing\Plugin::ACCESS_SHAREDOWNER,
+ 'inviteStatus' => \Sabre\DAV\Sharing\Plugin::INVITE_ACCEPTED,
+ ]),
+ ];
+ $this->assertEquals($expected, $result);
+
+ }
+
+ /**
+ * @depends testUpdateInvites
+ * @expectedException \InvalidArgumentException
+ */
+ function testUpdateInvitesBadId() {
+
+ $backend = new PDO($this->pdo);
+ // Add a new invite
+ $backend->updateInvites(
+ 'bad-id',
+ []
+ );
+
+ }
+
+ /**
+ * @depends testUpdateInvites
+ */
+ function testUpdateInvitesNoPrincipal() {
+
+ $backend = new PDO($this->pdo);
+
+ // creating a new calendar
+ $backend->createCalendar('principals/user1', 'somerandomid', []);
+ $calendar = $backend->getCalendarsForUser('principals/user1')[0];
+
+ $ownerSharee = new Sharee([
+ 'href' => 'principals/user1',
+ 'principal' => 'principals/user1',
+ 'access' => \Sabre\DAV\Sharing\Plugin::ACCESS_SHAREDOWNER,
+ 'inviteStatus' => \Sabre\DAV\Sharing\Plugin::INVITE_ACCEPTED,
+ ]);
+
+ // Add a new invite
+ $backend->updateInvites(
+ $calendar['id'],
+ [
+ new Sharee([
+ 'href' => 'mailto:user@example.org',
+ 'principal' => null,
+ 'access' => \Sabre\DAV\Sharing\Plugin::ACCESS_READ,
+ 'inviteStatus' => \Sabre\DAV\Sharing\Plugin::INVITE_ACCEPTED,
+ 'properties' => ['{DAV:}displayname' => 'User 2'],
+ ])
+ ]
+ );
+
+ $result = $backend->getInvites($calendar['id']);
+ $expected = [
+ $ownerSharee,
+ new Sharee([
+ 'href' => 'mailto:user@example.org',
+ 'principal' => null,
+ 'access' => \Sabre\DAV\Sharing\Plugin::ACCESS_READ,
+ 'inviteStatus' => \Sabre\DAV\Sharing\Plugin::INVITE_INVALID,
+ 'properties' => [
+ '{DAV:}displayname' => 'User 2',
+ ],
+ ])
+ ];
+ $this->assertEquals($expected, $result, null, 0.0, 10, true); // Last argument is $canonicalize = true, which allows us to compare, ignoring the order, because it's different between MySQL and Sqlite.
+
+ }
+
+ /**
+ * @depends testUpdateInvites
+ */
+ function testDeleteSharedCalendar() {
+
+ $backend = new PDO($this->pdo);
+
+ // creating a new calendar
+ $backend->createCalendar('principals/user1', 'somerandomid', []);
+ $calendar = $backend->getCalendarsForUser('principals/user1')[0];
+
+ $ownerSharee = new Sharee([
+ 'href' => 'principals/user1',
+ 'principal' => 'principals/user1',
+ 'access' => \Sabre\DAV\Sharing\Plugin::ACCESS_SHAREDOWNER,
+ 'inviteStatus' => \Sabre\DAV\Sharing\Plugin::INVITE_ACCEPTED,
+ ]);
+
+ // Add a new invite
+ $backend->updateInvites(
+ $calendar['id'],
+ [
+ new Sharee([
+ 'href' => 'mailto:user@example.org',
+ 'principal' => 'principals/user2',
+ 'access' => \Sabre\DAV\Sharing\Plugin::ACCESS_READ,
+ 'inviteStatus' => \Sabre\DAV\Sharing\Plugin::INVITE_ACCEPTED,
+ 'properties' => ['{DAV:}displayname' => 'User 2'],
+ ])
+ ]
+ );
+
+ $expectedCalendar = [
+ 'id' => [1,2],
+ 'principaluri' => 'principals/user2',
+ '{http://calendarserver.org/ns/}getctag' => 'http://sabre.io/ns/sync/1',
+ '{http://sabredav.org/ns}sync-token' => '1',
+ 'share-access' => \Sabre\DAV\Sharing\Plugin::ACCESS_READ,
+ 'read-only' => true,
+ 'share-resource-uri' => '/ns/share/1',
+ ];
+ $calendars = $backend->getCalendarsForUser('principals/user2');
+
+ foreach ($expectedCalendar as $k => $v) {
+ $this->assertEquals(
+ $v,
+ $calendars[0][$k],
+ "Key " . $k . " in calendars array did not have the expected value."
+ );
+ }
+
+ // Removing the shared calendar.
+ $backend->deleteCalendar($calendars[0]['id']);
+
+ $this->assertEquals(
+ [],
+ $backend->getCalendarsForUser('principals/user2')
+ );
+
+ $result = $backend->getInvites($calendar['id']);
+ $expected = [
+ new Sharee([
+ 'href' => 'principals/user1',
+ 'principal' => 'principals/user1',
+ 'access' => \Sabre\DAV\Sharing\Plugin::ACCESS_SHAREDOWNER,
+ 'inviteStatus' => \Sabre\DAV\Sharing\Plugin::INVITE_ACCEPTED,
+ ]),
+ ];
+ $this->assertEquals($expected, $result);
+
+ }
+
}
diff --git a/vendor/sabre/dav/tests/Sabre/CalDAV/Backend/Mock.php b/vendor/sabre/dav/tests/Sabre/CalDAV/Backend/Mock.php
index 4412e5531..d4dcc07dc 100644
--- a/vendor/sabre/dav/tests/Sabre/CalDAV/Backend/Mock.php
+++ b/vendor/sabre/dav/tests/Sabre/CalDAV/Backend/Mock.php
@@ -82,6 +82,46 @@ class Mock extends AbstractBackend {
}
/**
+ * Updates properties for a calendar.
+ *
+ * The list of mutations is stored in a Sabre\DAV\PropPatch object.
+ * To do the actual updates, you must tell this object which properties
+ * you're going to process with the handle() method.
+ *
+ * Calling the handle method is like telling the PropPatch object "I
+ * promise I can handle updating this property".
+ *
+ * Read the PropPatch documentation for more info and examples.
+ *
+ * @param mixed $calendarId
+ * @param \Sabre\DAV\PropPatch $propPatch
+ * @return void
+ */
+ function updateCalendar($calendarId, \Sabre\DAV\PropPatch $propPatch) {
+
+ $propPatch->handleRemaining(function($props) use ($calendarId) {
+
+ foreach ($this->calendars as $k => $calendar) {
+
+ if ($calendar['id'] === $calendarId) {
+ foreach ($props as $propName => $propValue) {
+ if (is_null($propValue)) {
+ unset($this->calendars[$k][$propName]);
+ } else {
+ $this->calendars[$k][$propName] = $propValue;
+ }
+ }
+ return true;
+
+ }
+
+ }
+
+ });
+
+ }
+
+ /**
* Delete a calendar and all it's objects
*
* @param string $calendarId
@@ -139,18 +179,22 @@ class Mock extends AbstractBackend {
* Returns information from a single calendar object, based on it's object
* uri.
*
+ * The object uri is only the basename, or filename and not a full path.
+ *
* The returned array must have the same keys as getCalendarObjects. The
* 'calendardata' object is required here though, while it's not required
* for getCalendarObjects.
*
- * @param string $calendarId
+ * This method must return null if the object did not exist.
+ *
+ * @param mixed $calendarId
* @param string $objectUri
- * @return array
+ * @return array|null
*/
function getCalendarObject($calendarId, $objectUri) {
if (!isset($this->calendarData[$calendarId][$objectUri])) {
- throw new DAV\Exception\NotFound('Object could not be found');
+ return null;
}
$object = $this->calendarData[$calendarId][$objectUri];
$object['calendarid'] = $calendarId;
@@ -207,8 +251,7 @@ class Mock extends AbstractBackend {
*/
function deleteCalendarObject($calendarId, $objectUri) {
- throw new Exception('Not implemented');
-
+ unset($this->calendarData[$calendarId][$objectUri]);
}
diff --git a/vendor/sabre/dav/tests/Sabre/CalDAV/Backend/PDOMySQLTest.php b/vendor/sabre/dav/tests/Sabre/CalDAV/Backend/PDOMySQLTest.php
index c215ca171..e068ff1e7 100644
--- a/vendor/sabre/dav/tests/Sabre/CalDAV/Backend/PDOMySQLTest.php
+++ b/vendor/sabre/dav/tests/Sabre/CalDAV/Backend/PDOMySQLTest.php
@@ -2,38 +2,8 @@
namespace Sabre\CalDAV\Backend;
-require_once 'Sabre/TestUtil.php';
-require_once 'Sabre/CalDAV/TestUtil.php';
-require_once 'Sabre/CalDAV/Backend/AbstractPDOTest.php';
-
class PDOMySQLTest extends AbstractPDOTest {
- function setup() {
-
- if (!SABRE_HASMYSQL) $this->markTestSkipped('MySQL driver is not available, or not properly configured');
- $pdo = \Sabre\TestUtil::getMySQLDB();
- if (!$pdo) $this->markTestSkipped('Could not connect to mysql database');
-
- $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");
- if ($query)
- $pdo->exec($query);
- }
- $this->pdo = $pdo;
-
- }
-
- function teardown() {
-
- $this->pdo = null;
-
- }
+ public $driver = 'mysql';
}
diff --git a/vendor/sabre/dav/tests/Sabre/CalDAV/Backend/PDOSqliteTest.php b/vendor/sabre/dav/tests/Sabre/CalDAV/Backend/PDOSqliteTest.php
index 4074259f2..90ad5a171 100644
--- a/vendor/sabre/dav/tests/Sabre/CalDAV/Backend/PDOSqliteTest.php
+++ b/vendor/sabre/dav/tests/Sabre/CalDAV/Backend/PDOSqliteTest.php
@@ -2,36 +2,8 @@
namespace Sabre\CalDAV\Backend;
-use Sabre\CalDAV;
-
-require_once 'Sabre/CalDAV/Backend/AbstractPDOTest.php';
-
class PDOSqliteTest extends AbstractPDOTest {
- function setup() {
-
- if (!SABRE_HASSQLITE) $this->markTestSkipped('SQLite driver is not available');
-
- 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;
-
- }
-
- function teardown() {
-
- $this->pdo = null;
- unlink(SABRE_TEMPDIR . '/testdb.sqlite');
-
- }
+ public $driver = 'sqlite';
}