[Pkg-owncloud-commits] [php-sabredav] 122/275: Testing hooks into node creation/update/deletes.
David Prévot
taffit at moszumanska.debian.org
Thu Sep 25 14:55:59 UTC 2014
This is an automated email from the git hooks/post-receive script.
taffit pushed a commit to branch master
in repository php-sabredav.
commit 08917f651b0b04f4a115bff927343b76e4b2cdc5
Author: Evert Pot <me at evertpot.com>
Date: Thu Jul 31 18:12:28 2014 -0400
Testing hooks into node creation/update/deletes.
---
tests/Sabre/CalDAV/Backend/Mock.php | 6 +
tests/Sabre/CalDAV/Backend/MockScheduling.php | 1 +
.../Sabre/CalDAV/Schedule/PluginPropertiesTest.php | 7 +-
.../Sabre/CalDAV/Schedule/ScheduleDeliverTest.php | 208 +++++++++++++++++++++
tests/Sabre/DAVServerTest.php | 5 +
5 files changed, 226 insertions(+), 1 deletion(-)
diff --git a/tests/Sabre/CalDAV/Backend/Mock.php b/tests/Sabre/CalDAV/Backend/Mock.php
index 32c8fe7..30502d4 100644
--- a/tests/Sabre/CalDAV/Backend/Mock.php
+++ b/tests/Sabre/CalDAV/Backend/Mock.php
@@ -13,6 +13,12 @@ class Mock extends AbstractBackend implements NotificationSupport, SharingSuppor
function __construct(array $calendars = [], array $calendarData = [], array $notifications = []) {
+ foreach($calendars as &$calendar) {
+ if (!isset($calendar['id'])) {
+ $calendar['id'] = DAV\UUIDUtil::getUUID();
+ }
+ }
+
$this->calendars = $calendars;
$this->calendarData = $calendarData;
$this->notifications = $notifications;
diff --git a/tests/Sabre/CalDAV/Backend/MockScheduling.php b/tests/Sabre/CalDAV/Backend/MockScheduling.php
index 3c7d849..020ad5b 100644
--- a/tests/Sabre/CalDAV/Backend/MockScheduling.php
+++ b/tests/Sabre/CalDAV/Backend/MockScheduling.php
@@ -48,6 +48,7 @@ class MockScheduling extends Mock implements SchedulingSupport {
if (isset($this->schedulingObjects[$principalUri])) {
return array_values($this->schedulingObjects[$principalUri]);
}
+ return [];
}
diff --git a/tests/Sabre/CalDAV/Schedule/PluginPropertiesTest.php b/tests/Sabre/CalDAV/Schedule/PluginPropertiesTest.php
index eb8aa45..191d089 100644
--- a/tests/Sabre/CalDAV/Schedule/PluginPropertiesTest.php
+++ b/tests/Sabre/CalDAV/Schedule/PluginPropertiesTest.php
@@ -17,6 +17,8 @@ class PluginPropertiesTest extends \Sabre\DAVServerTest {
'{urn:ietf:params:xml:ns:caldav}schedule-inbox-URL',
'{urn:ietf:params:xml:ns:caldav}schedule-outbox-URL',
'{urn:ietf:params:xml:ns:caldav}calendar-user-address-set',
+ '{urn:ietf:params:xml:ns:caldav}calendar-user-type',
+ '{urn:ietf:params:xml:ns:caldav}schedule-default-calendar-URL',
));
$this->assertArrayHasKey(0,$props);
@@ -32,12 +34,15 @@ class PluginPropertiesTest extends \Sabre\DAVServerTest {
$this->assertTrue($prop instanceof DAV\Property\Href);
$this->assertEquals('calendars/user1/inbox',$prop->getHref());
-
$this->assertArrayHasKey('{urn:ietf:params:xml:ns:caldav}calendar-user-address-set',$props[0][200]);
$prop = $props[0][200]['{urn:ietf:params:xml:ns:caldav}calendar-user-address-set'];
$this->assertTrue($prop instanceof DAV\Property\HrefList);
$this->assertEquals(array('mailto:user1.sabredav at sabredav.org','/principals/user1/'),$prop->getHrefs());
+ $this->assertArrayHasKey('{urn:ietf:params:xml:ns:caldav}calendar-user-type',$props[0][200]);
+ $prop = $props[0][200]['{urn:ietf:params:xml:ns:caldav}calendar-user-type'];
+ $this->assertEquals('INDIVIDUAL',$prop);
+
}
}
diff --git a/tests/Sabre/CalDAV/Schedule/ScheduleDeliverTest.php b/tests/Sabre/CalDAV/Schedule/ScheduleDeliverTest.php
new file mode 100644
index 0000000..208cb90
--- /dev/null
+++ b/tests/Sabre/CalDAV/Schedule/ScheduleDeliverTest.php
@@ -0,0 +1,208 @@
+<?php
+
+namespace Sabre\CalDAV\Schedule;
+
+use Sabre\HTTP\Request;
+
+class ScheduleDeliverTest extends \Sabre\DAVServerTest {
+
+ public $setupCalDAV = true;
+ public $setupCalDAVScheduling = true;
+ public $setupACL = true;
+ public $autoLogin = 'user1';
+
+ public $caldavCalendars = [
+ [
+ 'principaluri' => 'principals/user1',
+ 'uri' => 'cal',
+ ],
+ [
+ 'principaluri' => 'principals/user2',
+ 'uri' => 'cal',
+ ],
+ ];
+
+ function setUp() {
+
+ $this->calendarObjectUri = '/calendars/user1/cal/object.ics';
+
+ parent::setUp();
+
+ }
+
+ function testNewInvite() {
+
+ $newObject = <<<ICS
+BEGIN:VCALENDAR
+BEGIN:VEVENT
+UID:foo
+ORGANIZER:mailto:user1.sabredav at sabredav.org
+ATTENDEE:mailto:user2.sabredav at sabredav.org
+END:VEVENT
+END:VCALENDAR
+ICS;
+
+ $this->deliver(null, $newObject);
+ $this->assertItemsInInbox('user2', 1);
+
+ }
+ function testNewOnWrongCollection() {
+
+ $newObject = <<<ICS
+BEGIN:VCALENDAR
+BEGIN:VEVENT
+UID:foo
+ORGANIZER:mailto:user1.sabredav at sabredav.org
+ATTENDEE:mailto:user2.sabredav at sabredav.org
+END:VEVENT
+END:VCALENDAR
+ICS;
+
+ $this->calendarObjectUri = '/calendars/user1/object.ics';
+ $this->deliver(null, $newObject);
+ $this->assertItemsInInbox('user2', 0);
+
+ }
+ function testUpdatedInvite() {
+
+ $newObject = <<<ICS
+BEGIN:VCALENDAR
+BEGIN:VEVENT
+UID:foo
+ORGANIZER:mailto:user1.sabredav at sabredav.org
+ATTENDEE:mailto:user2.sabredav at sabredav.org
+END:VEVENT
+END:VCALENDAR
+ICS;
+ $oldObject = <<<ICS
+BEGIN:VCALENDAR
+BEGIN:VEVENT
+UID:foo
+ORGANIZER:mailto:user1.sabredav at sabredav.org
+END:VEVENT
+END:VCALENDAR
+ICS;
+
+ $this->deliver($oldObject, $newObject);
+ $this->assertItemsInInbox('user2', 1);
+
+ }
+
+ function testUpdatedInviteWrongPath() {
+
+ $newObject = <<<ICS
+BEGIN:VCALENDAR
+BEGIN:VEVENT
+UID:foo
+ORGANIZER:mailto:user1.sabredav at sabredav.org
+ATTENDEE:mailto:user2.sabredav at sabredav.org
+END:VEVENT
+END:VCALENDAR
+ICS;
+ $oldObject = <<<ICS
+BEGIN:VCALENDAR
+BEGIN:VEVENT
+UID:foo
+ORGANIZER:mailto:user1.sabredav at sabredav.org
+END:VEVENT
+END:VCALENDAR
+ICS;
+
+ $this->calendarObjectUri = '/calendars/user1/inbox/foo.ics';
+ $this->deliver($oldObject, $newObject);
+ $this->assertItemsInInbox('user2', 0);
+
+ }
+
+ function testDeletedInvite() {
+
+ $newObject = null;
+
+ $oldObject = <<<ICS
+BEGIN:VCALENDAR
+BEGIN:VEVENT
+UID:foo
+ORGANIZER:mailto:user1.sabredav at sabredav.org
+ATTENDEE:mailto:user2.sabredav at sabredav.org
+END:VEVENT
+END:VCALENDAR
+ICS;
+
+ $this->deliver($oldObject, $newObject);
+ $this->assertItemsInInbox('user2', 1);
+
+ }
+ function testDeletedInviteWrongUrl() {
+
+ $newObject = null;
+
+ $oldObject = <<<ICS
+BEGIN:VCALENDAR
+BEGIN:VEVENT
+UID:foo
+ORGANIZER:mailto:user1.sabredav at sabredav.org
+ATTENDEE:mailto:user2.sabredav at sabredav.org
+END:VEVENT
+END:VCALENDAR
+ICS;
+
+ $this->calendarObjectUri = '/calendars/user1/inbox/foo.ics';
+ $this->deliver($oldObject, $newObject);
+ $this->assertItemsInInbox('user2', 0);
+
+ }
+
+ protected $calendarObjectUri;
+
+ function deliver($oldObject, $newObject) {
+
+ if ($oldObject && $newObject) {
+ // update
+ $parent = $this->server->tree->getNodeForPath(dirname($this->calendarObjectUri));
+ $parent->createFile(basename($this->calendarObjectUri), $oldObject);
+
+ $stream = fopen('php://memory','r+');
+ fwrite($stream, $newObject);
+ rewind($stream);
+ $modified = false;
+
+ $this->caldavSchedulePlugin->beforeWriteContent(
+ $this->calendarObjectUri,
+ $this->server->tree->getNodeForPath($this->calendarObjectUri),
+ $stream,
+ $modified
+ );
+
+ } elseif ($oldObject && !$newObject) {
+ // delete
+ $parent = $this->server->tree->getNodeForPath(dirname($this->calendarObjectUri));
+ $parent->createFile(basename($this->calendarObjectUri), $oldObject);
+
+ $this->caldavSchedulePlugin->beforeUnbind(
+ $this->calendarObjectUri
+ );
+ } else {
+ // create
+ $stream = fopen('php://memory','r+');
+ fwrite($stream, $newObject);
+ rewind($stream);
+ $modified = false;
+ $this->caldavSchedulePlugin->beforeCreateFile(
+ $this->calendarObjectUri,
+ $stream,
+ $this->server->tree->getNodeForPath(dirname($this->calendarObjectUri)),
+ $modified
+ );
+ }
+
+ }
+
+ function assertItemsInInbox($user, $count) {
+
+ $inboxNode = $this->server->tree->getNodeForPath('calendars/'.$user.'/inbox');
+ $this->assertEquals($count, count($inboxNode->getChildren()));
+
+ }
+
+}
+
diff --git a/tests/Sabre/DAVServerTest.php b/tests/Sabre/DAVServerTest.php
index d42121b..26d8633 100644
--- a/tests/Sabre/DAVServerTest.php
+++ b/tests/Sabre/DAVServerTest.php
@@ -26,6 +26,11 @@ abstract class DAVServerTest extends \PHPUnit_Framework_TestCase {
protected $setupCalDAVScheduling = false;
protected $setupCalDAVSubscriptions = false;
+ /**
+ * An array with calendars. Every calendar should have
+ * - principaluri
+ * - uri
+ */
protected $caldavCalendars = array();
protected $caldavCalendarObjects = array();
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/php-sabredav.git
More information about the Pkg-owncloud-commits
mailing list