From 66effbfe0827fc61fff6d248797a894213ad20d6 Mon Sep 17 00:00:00 2001 From: Mario Vavti Date: Sat, 28 May 2016 17:46:24 +0200 Subject: upgrade to sabre32 --- .../dav/tests/Sabre/CalDAV/SharingPluginTest.php | 215 +++++++++++---------- 1 file changed, 111 insertions(+), 104 deletions(-) (limited to 'vendor/sabre/dav/tests/Sabre/CalDAV/SharingPluginTest.php') diff --git a/vendor/sabre/dav/tests/Sabre/CalDAV/SharingPluginTest.php b/vendor/sabre/dav/tests/Sabre/CalDAV/SharingPluginTest.php index b4270da7d..6e9e88419 100644 --- a/vendor/sabre/dav/tests/Sabre/CalDAV/SharingPluginTest.php +++ b/vendor/sabre/dav/tests/Sabre/CalDAV/SharingPluginTest.php @@ -3,6 +3,7 @@ namespace Sabre\CalDAV; use Sabre\DAV; +use Sabre\DAV\Xml\Element\Sharee; use Sabre\HTTP; class SharingPluginTest extends \Sabre\DAVServerTest { @@ -14,31 +15,28 @@ class SharingPluginTest extends \Sabre\DAVServerTest { function setUp() { - $this->caldavCalendars = array( - array( + $this->caldavCalendars = [ + [ 'principaluri' => 'principals/user1', - 'id' => 1, - 'uri' => 'cal1', - ), - array( + 'id' => 1, + 'uri' => 'cal1', + ], + [ 'principaluri' => 'principals/user1', - 'id' => 2, - 'uri' => 'cal2', - '{' . Plugin::NS_CALENDARSERVER . '}shared-url' => 'calendars/user1/cal2', - '{http://sabredav.org/ns}owner-principal' => 'principals/user2', - '{http://sabredav.org/ns}read-only' => 'true', - ), - array( + 'id' => 2, + 'uri' => 'cal2', + 'share-access' => \Sabre\DAV\Sharing\Plugin::ACCESS_READWRITE, + ], + [ 'principaluri' => 'principals/user1', - 'id' => 3, - 'uri' => 'cal3', - ), - ); + 'id' => 3, + 'uri' => 'cal3', + ], + ]; parent::setUp(); // Making the logged in user an admin, for full access: - $this->aclPlugin->adminPrincipals[] = 'principals/user1'; $this->aclPlugin->adminPrincipals[] = 'principals/user2'; } @@ -53,9 +51,21 @@ class SharingPluginTest extends \Sabre\DAVServerTest { } + /** + * @expectedException \LogicException + */ + function testSetupWithoutCoreSharingPlugin() { + + $server = new DAV\Server(); + $server->addPlugin( + new SharingPlugin() + ); + + } + function testGetFeatures() { - $this->assertEquals(array('calendarserver-sharing'), $this->caldavSharingPlugin->getFeatures()); + $this->assertEquals(['calendarserver-sharing'], $this->caldavSharingPlugin->getFeatures()); } @@ -63,10 +73,10 @@ class SharingPluginTest extends \Sabre\DAVServerTest { // Forcing the server to authenticate: $this->authPlugin->beforeMethod(new HTTP\Request(), new HTTP\Response()); - $props = $this->server->getProperties('calendars/user1/cal1', array( + $props = $this->server->getProperties('calendars/user1/cal1', [ '{' . Plugin::NS_CALENDARSERVER . '}invite', '{' . Plugin::NS_CALENDARSERVER . '}allowed-sharing-modes', - )); + ]); $this->assertInstanceOf('Sabre\\CalDAV\\Xml\\Property\\Invite', $props['{' . Plugin::NS_CALENDARSERVER . '}invite']); $this->assertInstanceOf('Sabre\\CalDAV\\Xml\\Property\\AllowedSharingModes', $props['{' . Plugin::NS_CALENDARSERVER . '}allowed-sharing-modes']); @@ -75,56 +85,55 @@ class SharingPluginTest extends \Sabre\DAVServerTest { function testBeforeGetSharedCalendar() { - $props = $this->server->getProperties('calendars/user1/cal2', array( + $props = $this->server->getProperties('calendars/user1/cal2', [ '{' . Plugin::NS_CALENDARSERVER . '}shared-url', '{' . Plugin::NS_CALENDARSERVER . '}invite', - )); + ]); $this->assertInstanceOf('Sabre\\CalDAV\\Xml\\Property\\Invite', $props['{' . Plugin::NS_CALENDARSERVER . '}invite']); - $this->assertInstanceOf('Sabre\\DAV\\Xml\\Property\\Href', $props['{' . Plugin::NS_CALENDARSERVER . '}shared-url']); + //$this->assertInstanceOf('Sabre\\DAV\\Xml\\Property\\Href', $props['{' . Plugin::NS_CALENDARSERVER . '}shared-url']); } - function testUpdateProperties() { + function testUpdateResourceType() { - $this->caldavBackend->updateShares(1, - array( - array( + $this->caldavBackend->updateInvites(1, + [ + new Sharee([ 'href' => 'mailto:joe@example.org', - ), - ), - array() + ]) + ] ); - $result = $this->server->updateProperties('calendars/user1/cal1', array( + $result = $this->server->updateProperties('calendars/user1/cal1', [ '{DAV:}resourcetype' => new DAV\Xml\Property\ResourceType(['{DAV:}collection']) - )); + ]); $this->assertEquals([ '{DAV:}resourcetype' => 200 ], $result); - $this->assertEquals(0, count($this->caldavBackend->getShares(1))); + $this->assertEquals(0, count($this->caldavBackend->getInvites(1))); } function testUpdatePropertiesPassThru() { - $result = $this->server->updateProperties('calendars/user1/cal3', array( + $result = $this->server->updateProperties('calendars/user1/cal3', [ '{DAV:}foo' => 'bar', - )); + ]); - $this->assertEquals(array( - '{DAV:}foo' => 403, - ), $result); + $this->assertEquals([ + '{DAV:}foo' => 200, + ], $result); } function testUnknownMethodNoPOST() { - $request = HTTP\Sapi::createFromServerArray(array( + $request = HTTP\Sapi::createFromServerArray([ 'REQUEST_METHOD' => 'PATCH', 'REQUEST_URI' => '/', - )); + ]); $response = $this->request($request); @@ -134,11 +143,11 @@ class SharingPluginTest extends \Sabre\DAVServerTest { function testUnknownMethodNoXML() { - $request = HTTP\Sapi::createFromServerArray(array( + $request = HTTP\Sapi::createFromServerArray([ 'REQUEST_METHOD' => 'POST', 'REQUEST_URI' => '/', 'CONTENT_TYPE' => 'text/plain', - )); + ]); $response = $this->request($request); @@ -148,11 +157,11 @@ class SharingPluginTest extends \Sabre\DAVServerTest { function testUnknownMethodNoNode() { - $request = HTTP\Sapi::createFromServerArray(array( + $request = HTTP\Sapi::createFromServerArray([ 'REQUEST_METHOD' => 'POST', 'REQUEST_URI' => '/foo', 'CONTENT_TYPE' => 'text/xml', - )); + ]); $response = $this->request($request); @@ -162,11 +171,7 @@ class SharingPluginTest extends \Sabre\DAVServerTest { function testShareRequest() { - $request = HTTP\Sapi::createFromServerArray(array( - 'REQUEST_METHOD' => 'POST', - 'REQUEST_URI' => '/calendars/user1/cal1', - 'CONTENT_TYPE' => 'text/xml', - )); + $request = new HTTP\Request('POST', '/calendars/user1/cal1', ['Content-Type' => 'text/xml']); $xml = << @@ -184,19 +189,28 @@ RRR; $request->setBody($xml); - $response = $this->request($request); - $this->assertEquals(200, $response->status, $response->body); + $response = $this->request($request, 200); + + $this->assertEquals( + [ + new Sharee([ + 'href' => 'mailto:joe@example.org', + 'properties' => [ + '{DAV:}displayname' => 'Joe Shmoe', + ], + 'access' => \Sabre\DAV\Sharing\Plugin::ACCESS_READWRITE, + 'inviteStatus' => \Sabre\DAV\Sharing\Plugin::INVITE_NORESPONSE, + 'comment' => '', + ]), + ], + $this->caldavBackend->getInvites(1) + ); - $this->assertEquals(array(array( - 'href' => 'mailto:joe@example.org', - 'commonName' => 'Joe Shmoe', - 'readOnly' => false, - 'status' => SharingPlugin::STATUS_NORESPONSE, - 'summary' => '', - )), $this->caldavBackend->getShares(1)); + // Wiping out tree cache + $this->server->tree->markDirty(''); // Verifying that the calendar is now marked shared. - $props = $this->server->getProperties('calendars/user1/cal1', array('{DAV:}resourcetype')); + $props = $this->server->getProperties('calendars/user1/cal1', ['{DAV:}resourcetype']); $this->assertTrue( $props['{DAV:}resourcetype']->is('{http://calendarserver.org/ns/}shared-owner') ); @@ -205,11 +219,11 @@ RRR; function testShareRequestNoShareableCalendar() { - $request = HTTP\Sapi::createFromServerArray(array( - 'REQUEST_METHOD' => 'POST', - 'REQUEST_URI' => '/calendars/user1/cal2', - 'CONTENT_TYPE' => 'text/xml', - )); + $request = new HTTP\Request( + 'POST', + '/calendars/user1/cal2', + ['Content-Type' => 'text/xml'] + ); $xml = ' @@ -226,18 +240,17 @@ RRR; $request->setBody($xml); - $response = $this->request($request); - $this->assertEquals(501, $response->status, $response->body); + $response = $this->request($request, 403); } function testInviteReply() { - $request = HTTP\Sapi::createFromServerArray(array( + $request = HTTP\Sapi::createFromServerArray([ 'REQUEST_METHOD' => 'POST', 'REQUEST_URI' => '/calendars/user1', 'CONTENT_TYPE' => 'text/xml', - )); + ]); $xml = ' @@ -254,11 +267,11 @@ RRR; function testInviteBadXML() { - $request = HTTP\Sapi::createFromServerArray(array( + $request = HTTP\Sapi::createFromServerArray([ 'REQUEST_METHOD' => 'POST', 'REQUEST_URI' => '/calendars/user1', 'CONTENT_TYPE' => 'text/xml', - )); + ]); $xml = ' @@ -272,11 +285,11 @@ RRR; function testInviteWrongUrl() { - $request = HTTP\Sapi::createFromServerArray(array( + $request = HTTP\Sapi::createFromServerArray([ 'REQUEST_METHOD' => 'POST', 'REQUEST_URI' => '/calendars/user1/cal1', 'CONTENT_TYPE' => 'text/xml', - )); + ]); $xml = ' @@ -295,11 +308,7 @@ RRR; function testPublish() { - $request = HTTP\Sapi::createFromServerArray(array( - 'REQUEST_METHOD' => 'POST', - 'REQUEST_URI' => '/calendars/user1/cal1', - 'CONTENT_TYPE' => 'text/xml', - )); + $request = new HTTP\Request('POST', '/calendars/user1/cal1', ['Content-Type' => 'text/xml']); $xml = ' @@ -312,13 +321,14 @@ RRR; } + function testUnpublish() { - $request = HTTP\Sapi::createFromServerArray(array( - 'REQUEST_METHOD' => 'POST', - 'REQUEST_URI' => '/calendars/user1/cal1', - 'CONTENT_TYPE' => 'text/xml', - )); + $request = new HTTP\Request( + 'POST', + '/calendars/user1/cal1', + ['Content-Type' => 'text/xml'] + ); $xml = ' @@ -333,49 +343,46 @@ RRR; function testPublishWrongUrl() { - $request = HTTP\Sapi::createFromServerArray(array( - 'REQUEST_METHOD' => 'POST', - 'REQUEST_URI' => '/calendars/user1/cal2', - 'CONTENT_TYPE' => 'text/xml', - )); + $request = new HTTP\Request( + 'POST', + '/calendars/user1', + ['Content-Type' => 'text/xml'] + ); $xml = ' '; $request->setBody($xml); - - $response = $this->request($request); - $this->assertEquals(501, $response->status, $response->body); + $this->request($request, 501); } function testUnpublishWrongUrl() { - $request = HTTP\Sapi::createFromServerArray(array( - 'REQUEST_METHOD' => 'POST', - 'REQUEST_URI' => '/calendars/user1/cal2', - 'CONTENT_TYPE' => 'text/xml', - )); - + $request = new HTTP\Request( + 'POST', + '/calendars/user1', + ['Content-Type' => 'text/xml'] + ); $xml = ' '; $request->setBody($xml); - $response = $this->request($request); - $this->assertEquals(501, $response->status, $response->body); + $this->request($request, 501); } function testUnknownXmlDoc() { - $request = HTTP\Sapi::createFromServerArray(array( - 'REQUEST_METHOD' => 'POST', - 'REQUEST_URI' => '/calendars/user1/cal2', - 'CONTENT_TYPE' => 'text/xml', - )); + + $request = new HTTP\Request( + 'POST', + '/calendars/user1/cal2', + ['Content-Type' => 'text/xml'] + ); $xml = ' '; -- cgit v1.2.3