[Pkg-owncloud-commits] [php-sabredav] 158/220: Better coverage in PDO CalDAV backend. fixed some bugs.
David Prévot
taffit at moszumanska.debian.org
Thu May 12 01:21:21 UTC 2016
This is an automated email from the git hooks/post-receive script.
taffit pushed a commit to branch master
in repository php-sabredav.
commit 31d7d6555baa9e63e4ca440be575fb82cf949ec9
Author: Evert Pot <me at evertpot.com>
Date: Sun Apr 17 18:24:18 2016 +0900
Better coverage in PDO CalDAV backend. fixed some bugs.
---
lib/CalDAV/Backend/PDO.php | 29 ++-
tests/Sabre/CalDAV/Backend/AbstractPDOTest.php | 308 +++++++++++++++++++++++++
2 files changed, 322 insertions(+), 15 deletions(-)
diff --git a/lib/CalDAV/Backend/PDO.php b/lib/CalDAV/Backend/PDO.php
index 9aa36ac..b62120d 100644
--- a/lib/CalDAV/Backend/PDO.php
+++ b/lib/CalDAV/Backend/PDO.php
@@ -194,14 +194,13 @@ SQL
'share-resource-uri' => '/ns/share/' . $row['calendarid'],
];
+ $calendar['share-access'] = (int)$row['access'];
// 1 = owner, 2 = readonly, 3 = readwrite
if ($row['access'] > 1) {
// We need to find more information about the original owner.
//$stmt2 = $this->pdo->prepare('SELECT principaluri FROM ' . $this->calendarInstancesTableName . ' WHERE access = 1 AND id = ?');
//$stmt2->execute([$row['id']]);
- $calendar['share-access'] = (int)$row['access'];
-
// read-only is for backwards compatbility. Might go away in
// the future.
$calendar['read-only'] = (int)$row['access'] === \Sabre\DAV\Sharing\Plugin::ACCESS_READ;
@@ -299,7 +298,7 @@ SQL
function updateCalendar($calendarId, \Sabre\DAV\PropPatch $propPatch) {
if (!is_array($calendarId)) {
- throw new \LogicException('The value passed to $calendarId is expected to be an array with a calendarId and an instanceId');
+ throw new \InvalidArgumentException('The value passed to $calendarId is expected to be an array with a calendarId and an instanceId');
}
list($calendarId, $instanceId) = $calendarId;
@@ -348,13 +347,13 @@ SQL
function deleteCalendar($calendarId) {
if (!is_array($calendarId)) {
- throw new \LogicException('The value passed to $calendarId is expected to be an array with a calendarId and an instanceId');
+ throw new \InvalidArgumentException('The value passed to $calendarId is expected to be an array with a calendarId and an instanceId');
}
list($calendarId, $instanceId) = $calendarId;
$stmt = $this->pdo->prepare('SELECT access FROM ' . $this->calendarInstancesTableName . ' where id = ?');
$stmt->execute([$instanceId]);
- $access = $stmt->fetchColumn();
+ $access = (int)$stmt->fetchColumn();
if ($access === \Sabre\DAV\Sharing\Plugin::ACCESS_SHAREDOWNER) {
@@ -422,7 +421,7 @@ SQL
function getCalendarObjects($calendarId) {
if (!is_array($calendarId)) {
- throw new \LogicException('The value passed to $calendarId is expected to be an array with a calendarId and an instanceId');
+ throw new \InvalidArgumentException('The value passed to $calendarId is expected to be an array with a calendarId and an instanceId');
}
list($calendarId, $instanceId) = $calendarId;
@@ -464,7 +463,7 @@ SQL
function getCalendarObject($calendarId, $objectUri) {
if (!is_array($calendarId)) {
- throw new \LogicException('The value passed to $calendarId is expected to be an array with a calendarId and an instanceId');
+ throw new \InvalidArgumentException('The value passed to $calendarId is expected to be an array with a calendarId and an instanceId');
}
list($calendarId, $instanceId) = $calendarId;
@@ -501,7 +500,7 @@ SQL
function getMultipleCalendarObjects($calendarId, array $uris) {
if (!is_array($calendarId)) {
- throw new \LogicException('The value passed to $calendarId is expected to be an array with a calendarId and an instanceId');
+ throw new \InvalidArgumentException('The value passed to $calendarId is expected to be an array with a calendarId and an instanceId');
}
list($calendarId, $instanceId) = $calendarId;
@@ -553,7 +552,7 @@ SQL
function createCalendarObject($calendarId, $objectUri, $calendarData) {
if (!is_array($calendarId)) {
- throw new \LogicException('The value passed to $calendarId is expected to be an array with a calendarId and an instanceId');
+ throw new \InvalidArgumentException('The value passed to $calendarId is expected to be an array with a calendarId and an instanceId');
}
list($calendarId, $instanceId) = $calendarId;
@@ -599,7 +598,7 @@ SQL
function updateCalendarObject($calendarId, $objectUri, $calendarData) {
if (!is_array($calendarId)) {
- throw new \LogicException('The value passed to $calendarId is expected to be an array with a calendarId and an instanceId');
+ throw new \InvalidArgumentException('The value passed to $calendarId is expected to be an array with a calendarId and an instanceId');
}
list($calendarId, $instanceId) = $calendarId;
@@ -708,7 +707,7 @@ SQL
function deleteCalendarObject($calendarId, $objectUri) {
if (!is_array($calendarId)) {
- throw new \LogicException('The value passed to $calendarId is expected to be an array with a calendarId and an instanceId');
+ throw new \InvalidArgumentException('The value passed to $calendarId is expected to be an array with a calendarId and an instanceId');
}
list($calendarId, $instanceId) = $calendarId;
@@ -774,7 +773,7 @@ SQL
function calendarQuery($calendarId, array $filters) {
if (!is_array($calendarId)) {
- throw new \LogicException('The value passed to $calendarId is expected to be an array with a calendarId and an instanceId');
+ throw new \InvalidArgumentException('The value passed to $calendarId is expected to be an array with a calendarId and an instanceId');
}
list($calendarId, $instanceId) = $calendarId;
@@ -953,7 +952,7 @@ SQL;
function getChangesForCalendar($calendarId, $syncToken, $syncLevel, $limit = null) {
if (!is_array($calendarId)) {
- throw new \LogicException('The value passed to $calendarId is expected to be an array with a calendarId and an instanceId');
+ throw new \InvalidArgumentException('The value passed to $calendarId is expected to be an array with a calendarId and an instanceId');
}
list($calendarId, $instanceId) = $calendarId;
@@ -1329,7 +1328,7 @@ SQL;
function updateInvites($calendarId, array $sharees) {
if (!is_array($calendarId)) {
- throw new \LogicException('The value passed to $calendarId is expected to be an array with a calendarId and an instanceId');
+ throw new \InvalidArgumentException('The value passed to $calendarId is expected to be an array with a calendarId and an instanceId');
}
$currentInvites = $this->getInvites($calendarId);
list($calendarId, $instanceId) = $calendarId;
@@ -1442,7 +1441,7 @@ INSERT INTO ' . $this->calendarInstancesTableName . '
function getInvites($calendarId) {
if (!is_array($calendarId)) {
- throw new \LogicException('The value passed to getInvites() is expected to be an array with a calendarId and an instanceId');
+ throw new \InvalidArgumentException('The value passed to getInvites() is expected to be an array with a calendarId and an instanceId');
}
list($calendarId, $instanceId) = $calendarId;
diff --git a/tests/Sabre/CalDAV/Backend/AbstractPDOTest.php b/tests/Sabre/CalDAV/Backend/AbstractPDOTest.php
index d8560cd..9cd1e70 100644
--- a/tests/Sabre/CalDAV/Backend/AbstractPDOTest.php
+++ b/tests/Sabre/CalDAV/Backend/AbstractPDOTest.php
@@ -47,6 +47,7 @@ abstract class AbstractPDOTest extends \PHPUnit_Framework_TestCase {
'{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 +111,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 +178,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() {;
@@ -237,6 +275,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
*/
@@ -277,6 +326,22 @@ abstract class AbstractPDOTest extends \PHPUnit_Framework_TestCase {
/**
* @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
*/
function testCreateCalendarObjectNoDTEND() {
@@ -414,8 +479,30 @@ abstract class AbstractPDOTest extends \PHPUnit_Framework_TestCase {
$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
*/
@@ -459,6 +546,17 @@ abstract class AbstractPDOTest extends \PHPUnit_Framework_TestCase {
}
/**
+ * @depends testUpdateCalendarObject
+ * @expectedException \InvalidArgumentException
+ */
+ function testUpdateCalendarObjectBadId() {
+
+ $backend = new PDO($this->pdo);
+ $backend->updateCalendarObject('bad-id', 'object-id', 'objectdata');
+
+ }
+
+ /**
* @depends testCreateCalendarObject
*/
function testDeleteCalendarObject() {
@@ -475,6 +573,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,6 +612,33 @@ abstract class AbstractPDOTest extends \PHPUnit_Framework_TestCase {
}
+ /**
+ * @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);
@@ -690,6 +830,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 = [
@@ -899,6 +1055,22 @@ abstract class AbstractPDOTest extends \PHPUnit_Framework_TestCase {
}
/**
+ * @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() {
@@ -1035,4 +1207,140 @@ abstract class AbstractPDOTest extends \PHPUnit_Framework_TestCase {
}
+ /**
+ * @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 at 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 at 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);
+
+ }
+
+ /**
+ * @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 at 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);
+
+ }
+
}
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-php/php-sabredav.git
More information about the Pkg-owncloud-commits
mailing list