From 0b02a6d123b2014705998c94ddf3d460948d3eac Mon Sep 17 00:00:00 2001 From: redmatrix Date: Tue, 10 May 2016 17:26:44 -0700 Subject: initial sabre upgrade (needs lots of work - to wit: authentication, redo the browser interface, and rework event export/import) --- .../tests/Sabre/CalDAV/Backend/AbstractPDOTest.php | 733 ++++++++++---- .../tests/Sabre/CalDAV/Backend/AbstractTest.php | 184 +++- .../sabre/dav/tests/Sabre/CalDAV/Backend/Mock.php | 267 +---- .../tests/Sabre/CalDAV/Backend/PDOMySQLTest.php | 6 +- .../tests/Sabre/CalDAV/Backend/PDOSqliteTest.php | 16 +- .../dav/tests/Sabre/CalDAV/CalendarObjectTest.php | 50 +- .../tests/Sabre/CalDAV/CalendarQueryParserTest.php | 540 ---------- .../Sabre/CalDAV/CalendarQueryValidatorTest.php | 70 +- .../sabre/dav/tests/Sabre/CalDAV/CalendarTest.php | 74 +- .../CalDAV/ExpandEventsDTSTARTandDTENDTest.php | 55 +- .../ExpandEventsDTSTARTandDTENDbyDayTest.php | 49 +- .../Sabre/CalDAV/ExpandEventsDoubleEventsTest.php | 6 +- .../dav/tests/Sabre/CalDAV/FreeBusyReportTest.php | 71 +- .../dav/tests/Sabre/CalDAV/FreeBusyRequestTest.php | 282 ------ .../Sabre/CalDAV/GetEventsByTimerangeTest.php | 68 +- .../dav/tests/Sabre/CalDAV/ICSExportPluginTest.php | 544 +++++++++- .../sabre/dav/tests/Sabre/CalDAV/Issue203Test.php | 60 +- .../sabre/dav/tests/Sabre/CalDAV/Issue205Test.php | 4 +- .../sabre/dav/tests/Sabre/CalDAV/Issue211Test.php | 4 +- .../sabre/dav/tests/Sabre/CalDAV/Issue220Test.php | 6 +- .../sabre/dav/tests/Sabre/CalDAV/Issue228Test.php | 4 +- .../Sabre/CalDAV/Notifications/CollectionTest.php | 4 +- .../tests/Sabre/CalDAV/Notifications/NodeTest.php | 10 +- .../Notifications/Notification/InviteReplyTest.php | 134 --- .../Notifications/Notification/InviteTest.php | 230 ----- .../Notification/SystemStatusTest.php | 61 -- .../dav/tests/Sabre/CalDAV/OutboxPostTest.php | 545 ---------- vendor/sabre/dav/tests/Sabre/CalDAV/PluginTest.php | 869 ++++++++-------- .../dav/tests/Sabre/CalDAV/Principal/UserTest.php | 2 +- .../CalDAV/Property/AllowedSharingModesTest.php | 46 - .../dav/tests/Sabre/CalDAV/Property/InviteTest.php | 196 ---- .../CalDAV/Property/ScheduleCalendarTranspTest.php | 99 -- .../Property/SupportedCalendarComponentSetTest.php | 67 -- .../CalDAV/Property/SupportedCalendarDataTest.php | 44 - .../CalDAV/Property/SupportedCollationSetTest.php | 46 - .../dav/tests/Sabre/CalDAV/Schedule/IMip/Mock.php | 50 - .../dav/tests/Sabre/CalDAV/Schedule/OutboxTest.php | 21 + .../tests/Sabre/CalDAV/ShareableCalendarTest.php | 10 +- .../dav/tests/Sabre/CalDAV/SharedCalendarTest.php | 91 +- .../dav/tests/Sabre/CalDAV/SharingPluginTest.php | 84 +- .../CalDAV/UserCalendarsSharedCalendarsTest.php | 93 -- .../dav/tests/Sabre/CalDAV/UserCalendarsTest.php | 207 ---- .../dav/tests/Sabre/CalDAV/ValidateICalTest.php | 91 +- .../sabre/dav/tests/Sabre/CalDAV/VersionTest.php | 17 - .../dav/tests/Sabre/CardDAV/AbstractPluginTest.php | 2 + .../Sabre/CardDAV/AddressBookQueryParserTest.php | 329 ------ .../tests/Sabre/CardDAV/AddressBookQueryTest.php | 134 ++- .../tests/Sabre/CardDAV/AddressBookRootTest.php | 2 +- .../dav/tests/Sabre/CardDAV/AddressBookTest.php | 56 +- .../Sabre/CardDAV/Backend/AbstractPDOTest.php | 129 ++- .../sabre/dav/tests/Sabre/CardDAV/Backend/Mock.php | 30 +- .../tests/Sabre/CardDAV/Backend/PDOMySQLTest.php | 48 +- .../tests/Sabre/CardDAV/Backend/PDOSqliteTest.php | 57 +- vendor/sabre/dav/tests/Sabre/CardDAV/CardTest.php | 33 +- .../sabre/dav/tests/Sabre/CardDAV/MultiGetTest.php | 50 +- .../sabre/dav/tests/Sabre/CardDAV/PluginTest.php | 96 +- .../CardDAV/Property/SupportedAddressDataTest.php | 44 - .../Sabre/CardDAV/SogoStripContentTypeTest.php | 17 +- vendor/sabre/dav/tests/Sabre/CardDAV/TestUtil.php | 18 +- .../tests/Sabre/CardDAV/UserAddressBooksTest.php | 162 --- .../dav/tests/Sabre/CardDAV/VCFExportTest.php | 25 +- .../dav/tests/Sabre/CardDAV/ValidateVCardTest.php | 47 +- .../sabre/dav/tests/Sabre/CardDAV/VersionTest.php | 17 - .../sabre/dav/tests/Sabre/DAV/AbstractServer.php | 3 +- .../Sabre/DAV/Auth/Backend/AbstractBasicTest.php | 69 +- .../Sabre/DAV/Auth/Backend/AbstractDigestTest.php | 124 ++- .../tests/Sabre/DAV/Auth/Backend/ApacheTest.php | 53 +- .../dav/tests/Sabre/DAV/Auth/Backend/FileTest.php | 2 +- .../dav/tests/Sabre/DAV/Auth/Backend/Mock.php | 82 +- .../tests/Sabre/DAV/Auth/Backend/PDOMySQLTest.php | 18 +- .../sabre/dav/tests/Sabre/DAV/Auth/PluginTest.php | 94 +- vendor/sabre/dav/tests/Sabre/DAV/BasicNodeTest.php | 1 + .../Sabre/DAV/Browser/GuessContentTypeTest.php | 10 +- .../Sabre/DAV/Browser/MapGetToPropFindTest.php | 14 +- .../dav/tests/Sabre/DAV/Browser/PluginTest.php | 154 ++- vendor/sabre/dav/tests/Sabre/DAV/ClientMock.php | 18 +- vendor/sabre/dav/tests/Sabre/DAV/ClientTest.php | 1071 ++++---------------- .../sabre/dav/tests/Sabre/DAV/FSExt/FileTest.php | 73 +- .../sabre/dav/tests/Sabre/DAV/FSExt/NodeTest.php | 178 ---- .../sabre/dav/tests/Sabre/DAV/FSExt/ServerTest.php | 236 +++-- .../dav/tests/Sabre/DAV/HTTPPreferParsingTest.php | 146 ++- .../sabre/dav/tests/Sabre/DAV/HttpDeleteTest.php | 90 +- vendor/sabre/dav/tests/Sabre/DAV/HttpPutTest.php | 273 +++-- vendor/sabre/dav/tests/Sabre/DAV/Issue33Test.php | 11 +- .../dav/tests/Sabre/DAV/Locks/Backend/FSTest.php | 31 - .../tests/Sabre/DAV/Locks/GetIfConditionsTest.php | 375 ------- .../sabre/dav/tests/Sabre/DAV/Locks/MSWordTest.php | 31 +- .../sabre/dav/tests/Sabre/DAV/Locks/PluginTest.php | 501 ++++----- .../sabre/dav/tests/Sabre/DAV/Mock/Collection.php | 61 +- vendor/sabre/dav/tests/Sabre/DAV/Mock/File.php | 46 +- .../sabre/dav/tests/Sabre/DAV/Mount/PluginTest.php | 10 +- .../sabre/dav/tests/Sabre/DAV/ObjectTreeTest.php | 2 +- .../dav/tests/Sabre/DAV/PartialUpdate/FileMock.php | 54 +- .../tests/Sabre/DAV/PartialUpdate/PluginTest.php | 119 +-- .../Sabre/DAV/PartialUpdate/SpecificationTest.php | 38 +- .../Sabre/DAV/Property/GetLastModifiedTest.php | 75 -- .../dav/tests/Sabre/DAV/Property/HrefListTest.php | 91 -- .../dav/tests/Sabre/DAV/Property/HrefTest.php | 119 --- .../tests/Sabre/DAV/Property/ResourceTypeTest.php | 111 -- .../tests/Sabre/DAV/Property/ResponseListTest.php | 19 - .../dav/tests/Sabre/DAV/Property/ResponseTest.php | 230 ----- .../Sabre/DAV/Property/SupportedReportSetTest.php | 128 --- .../dav/tests/Sabre/DAV/ServerCopyMoveTest.php | 268 ----- .../sabre/dav/tests/Sabre/DAV/ServerEventsTest.php | 74 +- .../sabre/dav/tests/Sabre/DAV/ServerMKCOLTest.php | 159 ++- .../sabre/dav/tests/Sabre/DAV/ServerPluginTest.php | 37 +- .../dav/tests/Sabre/DAV/ServerPreconditionTest.php | 227 ++--- .../sabre/dav/tests/Sabre/DAV/ServerPropsTest.php | 342 ++----- .../sabre/dav/tests/Sabre/DAV/ServerRangeTest.php | 350 +++---- .../sabre/dav/tests/Sabre/DAV/ServerSimpleTest.php | 454 +++------ .../tests/Sabre/DAV/ServerUpdatePropertiesTest.php | 75 +- .../sabre/dav/tests/Sabre/DAV/SimpleFileTest.php | 4 +- .../tests/Sabre/DAV/TemporaryFileFilterTest.php | 159 +-- vendor/sabre/dav/tests/Sabre/DAV/TestPlugin.php | 14 +- .../dav/tests/Sabre/DAV/Tree/FilesystemTest.php | 88 -- vendor/sabre/dav/tests/Sabre/DAV/TreeTest.php | 104 +- vendor/sabre/dav/tests/Sabre/DAV/URLUtilTest.php | 131 --- vendor/sabre/dav/tests/Sabre/DAV/XMLUtilTest.php | 284 ------ .../sabre/dav/tests/Sabre/DAVACL/ACLMethodTest.php | 55 +- .../dav/tests/Sabre/DAVACL/AllowAccessTest.php | 92 +- .../dav/tests/Sabre/DAVACL/BlockAccessTest.php | 100 +- .../tests/Sabre/DAVACL/ExpandPropertiesTest.php | 102 +- .../dav/tests/Sabre/DAVACL/PluginAdminTest.php | 49 +- .../tests/Sabre/DAVACL/PluginPropertiesTest.php | 335 +++--- .../Sabre/DAVACL/PluginUpdatePropertiesTest.php | 64 +- .../DAVACL/PrincipalBackend/AbstractPDOTest.php | 50 +- .../tests/Sabre/DAVACL/PrincipalBackend/Mock.php | 144 ++- .../Sabre/DAVACL/PrincipalBackend/PDOMySQLTest.php | 33 +- .../DAVACL/PrincipalBackend/PDOSqliteTest.php | 23 +- .../tests/Sabre/DAVACL/PrincipalCollectionTest.php | 9 + .../Sabre/DAVACL/PrincipalPropertySearchTest.php | 192 +++- .../DAVACL/PrincipalSearchPropertySetTest.php | 32 +- .../sabre/dav/tests/Sabre/DAVACL/PrincipalTest.php | 10 +- .../Sabre/DAVACL/Property/ACLRestrictionsTest.php | 35 - .../dav/tests/Sabre/DAVACL/Property/ACLTest.php | 335 ------ .../Property/CurrentUserPrivilegeSetTest.php | 68 -- .../tests/Sabre/DAVACL/Property/PrincipalTest.php | 181 ---- .../DAVACL/Property/SupportedPrivilegeSetTest.php | 106 -- .../dav/tests/Sabre/DAVACL/SimplePluginTest.php | 51 +- .../sabre/dav/tests/Sabre/DAVACL/VersionTest.php | 17 - vendor/sabre/dav/tests/Sabre/DAVServerTest.php | 120 ++- vendor/sabre/dav/tests/Sabre/HTTP/AWSAuthTest.php | 242 ----- .../sabre/dav/tests/Sabre/HTTP/BasicAuthTest.php | 132 --- .../sabre/dav/tests/Sabre/HTTP/DigestAuthTest.php | 228 ----- vendor/sabre/dav/tests/Sabre/HTTP/RequestTest.php | 150 --- vendor/sabre/dav/tests/Sabre/HTTP/ResponseMock.php | 35 +- vendor/sabre/dav/tests/Sabre/HTTP/ResponseTest.php | 70 -- vendor/sabre/dav/tests/Sabre/HTTP/UtilTest.php | 78 -- vendor/sabre/dav/tests/Sabre/HTTP/VersionTest.php | 17 - vendor/sabre/dav/tests/Sabre/TestUtil.php | 7 + 150 files changed, 5826 insertions(+), 12273 deletions(-) delete mode 100644 vendor/sabre/dav/tests/Sabre/CalDAV/CalendarQueryParserTest.php delete mode 100644 vendor/sabre/dav/tests/Sabre/CalDAV/FreeBusyRequestTest.php delete mode 100644 vendor/sabre/dav/tests/Sabre/CalDAV/Notifications/Notification/InviteReplyTest.php delete mode 100644 vendor/sabre/dav/tests/Sabre/CalDAV/Notifications/Notification/InviteTest.php delete mode 100644 vendor/sabre/dav/tests/Sabre/CalDAV/Notifications/Notification/SystemStatusTest.php delete mode 100644 vendor/sabre/dav/tests/Sabre/CalDAV/OutboxPostTest.php delete mode 100644 vendor/sabre/dav/tests/Sabre/CalDAV/Property/AllowedSharingModesTest.php delete mode 100644 vendor/sabre/dav/tests/Sabre/CalDAV/Property/InviteTest.php delete mode 100644 vendor/sabre/dav/tests/Sabre/CalDAV/Property/ScheduleCalendarTranspTest.php delete mode 100644 vendor/sabre/dav/tests/Sabre/CalDAV/Property/SupportedCalendarComponentSetTest.php delete mode 100644 vendor/sabre/dav/tests/Sabre/CalDAV/Property/SupportedCalendarDataTest.php delete mode 100644 vendor/sabre/dav/tests/Sabre/CalDAV/Property/SupportedCollationSetTest.php delete mode 100644 vendor/sabre/dav/tests/Sabre/CalDAV/Schedule/IMip/Mock.php delete mode 100644 vendor/sabre/dav/tests/Sabre/CalDAV/UserCalendarsSharedCalendarsTest.php delete mode 100644 vendor/sabre/dav/tests/Sabre/CalDAV/UserCalendarsTest.php delete mode 100644 vendor/sabre/dav/tests/Sabre/CalDAV/VersionTest.php delete mode 100644 vendor/sabre/dav/tests/Sabre/CardDAV/AddressBookQueryParserTest.php delete mode 100644 vendor/sabre/dav/tests/Sabre/CardDAV/Property/SupportedAddressDataTest.php delete mode 100644 vendor/sabre/dav/tests/Sabre/CardDAV/UserAddressBooksTest.php delete mode 100644 vendor/sabre/dav/tests/Sabre/CardDAV/VersionTest.php delete mode 100644 vendor/sabre/dav/tests/Sabre/DAV/FSExt/NodeTest.php delete mode 100644 vendor/sabre/dav/tests/Sabre/DAV/Locks/Backend/FSTest.php delete mode 100644 vendor/sabre/dav/tests/Sabre/DAV/Locks/GetIfConditionsTest.php delete mode 100644 vendor/sabre/dav/tests/Sabre/DAV/Property/GetLastModifiedTest.php delete mode 100644 vendor/sabre/dav/tests/Sabre/DAV/Property/HrefListTest.php delete mode 100644 vendor/sabre/dav/tests/Sabre/DAV/Property/HrefTest.php delete mode 100644 vendor/sabre/dav/tests/Sabre/DAV/Property/ResourceTypeTest.php delete mode 100644 vendor/sabre/dav/tests/Sabre/DAV/Property/ResponseListTest.php delete mode 100644 vendor/sabre/dav/tests/Sabre/DAV/Property/ResponseTest.php delete mode 100644 vendor/sabre/dav/tests/Sabre/DAV/Property/SupportedReportSetTest.php delete mode 100644 vendor/sabre/dav/tests/Sabre/DAV/ServerCopyMoveTest.php delete mode 100644 vendor/sabre/dav/tests/Sabre/DAV/Tree/FilesystemTest.php delete mode 100644 vendor/sabre/dav/tests/Sabre/DAV/URLUtilTest.php delete mode 100644 vendor/sabre/dav/tests/Sabre/DAV/XMLUtilTest.php delete mode 100644 vendor/sabre/dav/tests/Sabre/DAVACL/Property/ACLRestrictionsTest.php delete mode 100644 vendor/sabre/dav/tests/Sabre/DAVACL/Property/ACLTest.php delete mode 100644 vendor/sabre/dav/tests/Sabre/DAVACL/Property/CurrentUserPrivilegeSetTest.php delete mode 100644 vendor/sabre/dav/tests/Sabre/DAVACL/Property/PrincipalTest.php delete mode 100644 vendor/sabre/dav/tests/Sabre/DAVACL/Property/SupportedPrivilegeSetTest.php delete mode 100644 vendor/sabre/dav/tests/Sabre/DAVACL/VersionTest.php delete mode 100644 vendor/sabre/dav/tests/Sabre/HTTP/AWSAuthTest.php delete mode 100644 vendor/sabre/dav/tests/Sabre/HTTP/BasicAuthTest.php delete mode 100644 vendor/sabre/dav/tests/Sabre/HTTP/DigestAuthTest.php delete mode 100644 vendor/sabre/dav/tests/Sabre/HTTP/RequestTest.php delete mode 100644 vendor/sabre/dav/tests/Sabre/HTTP/ResponseTest.php delete mode 100644 vendor/sabre/dav/tests/Sabre/HTTP/UtilTest.php delete mode 100644 vendor/sabre/dav/tests/Sabre/HTTP/VersionTest.php (limited to 'vendor/sabre/dav/tests/Sabre') 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 @@ 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,21 +403,41 @@ 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') + ); + } /** @@ -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 @@ 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; } diff --git a/vendor/sabre/dav/tests/Sabre/CalDAV/CalendarObjectTest.php b/vendor/sabre/dav/tests/Sabre/CalDAV/CalendarObjectTest.php index eab10eae7..9fc1eee4c 100644 --- a/vendor/sabre/dav/tests/Sabre/CalDAV/CalendarObjectTest.php +++ b/vendor/sabre/dav/tests/Sabre/CalDAV/CalendarObjectTest.php @@ -43,7 +43,7 @@ class CalendarObjectTest extends \PHPUnit_Framework_TestCase { $this->assertInternalType('string',$children[0]->getName()); $this->assertInternalType('string',$children[0]->get()); $this->assertInternalType('string',$children[0]->getETag()); - $this->assertEquals('text/calendar; charset=utf-8', $children[0]->getContentType()); + $this->assertEquals('text/calendar; charset=utf-8; component=vevent', $children[0]->getContentType()); } @@ -173,6 +173,46 @@ class CalendarObjectTest extends \PHPUnit_Framework_TestCase { function testGetACL() { + $expected = array( + array( + 'privilege' => '{DAV:}read', + 'principal' => 'principals/user1', + 'protected' => true, + ), + array( + 'privilege' => '{DAV:}read', + 'principal' => 'principals/user1/calendar-proxy-write', + 'protected' => true, + ), + array( + 'privilege' => '{DAV:}read', + 'principal' => 'principals/user1/calendar-proxy-read', + 'protected' => true, + ), + array( + 'privilege' => '{DAV:}write', + 'principal' => 'principals/user1', + 'protected' => true, + ), + array( + 'privilege' => '{DAV:}write', + 'principal' => 'principals/user1/calendar-proxy-write', + 'protected' => true, + ), + ); + + $children = $this->calendar->getChildren(); + $this->assertTrue($children[0] instanceof CalendarObject); + + $obj = $children[0]; + $this->assertEquals($expected, $obj->getACL()); + + } + + function testDefaultACL() { + + $backend = new Backend\Mock([], []); + $calendarObject = new CalendarObject($backend, ['principaluri' => 'principals/user1'], ['calendarid' => 1, 'uri' => 'foo']); $expected = array( array( 'privilege' => '{DAV:}read', @@ -200,12 +240,8 @@ class CalendarObjectTest extends \PHPUnit_Framework_TestCase { 'protected' => true, ), ); + $this->assertEquals($expected, $calendarObject->getACL()); - $children = $this->calendar->getChildren(); - $this->assertTrue($children[0] instanceof CalendarObject); - - $obj = $children[0]; - $this->assertEquals($expected, $obj->getACL()); } @@ -278,7 +314,7 @@ END:VCALENDAR"; ), ) )); - $obj = new CalendarObject($backend, array(), array('calendarid' => 1, 'uri' => 'foo')); + $obj = new CalendarObject($backend, array('id' => 1), array('uri' => 'foo')); $this->assertEquals('foo', $obj->get()); diff --git a/vendor/sabre/dav/tests/Sabre/CalDAV/CalendarQueryParserTest.php b/vendor/sabre/dav/tests/Sabre/CalDAV/CalendarQueryParserTest.php deleted file mode 100644 index fdfe4de89..000000000 --- a/vendor/sabre/dav/tests/Sabre/CalDAV/CalendarQueryParserTest.php +++ /dev/null @@ -1,540 +0,0 @@ - - -' . implode("\n", $xml) . ' -'; - - $dom = DAV\XMLUtil::loadDOMDocument($xml); - - $q = new CalendarQueryParser($dom); - $q->parse(); - return $q->filters; - - } - - /** - * @expectedException Sabre\DAV\Exception\BadRequest - */ - function testNoFilter() { - - $xml = array(); - $this->parse($xml); - - } - - /** - * @expectedException Sabre\DAV\Exception\BadRequest - */ - function testTwoCompFilter() { - - $xml = array( - '', - ' ', - ' ', - '' - ); - $this->parse($xml); - - } - - function testBasicFilter() { - - $xml = array( - '', - ' ', - '' - ); - $result = $this->parse($xml); - - $expected = array( - 'name' => 'VCALENDAR', - 'comp-filters' => array(), - 'prop-filters' => array(), - 'is-not-defined' => false, - 'time-range' => false - ); - - $this->assertEquals( - $expected, - $result - ); - - } - - function testCompIsNotDefined() { - - $xml = array( - '', - ' ', - ' ', - ' ', - ' ', - ' ', - '' - ); - $result = $this->parse($xml); - - $expected = array( - 'name' => 'VCALENDAR', - 'comp-filters' => array( - array( - 'name' => 'VEVENT', - 'comp-filters' => array(), - 'prop-filters' => array(), - 'is-not-defined' => true, - 'time-range' => false - ), - ), - 'prop-filters' => array(), - 'is-not-defined' => false, - 'time-range' => false - ); - - $this->assertEquals( - $expected, - $result - ); - - } - - /** - * @expectedException Sabre\DAV\Exception\BadRequest - */ - function testCompTimeRangeOnVCALENDAR() { - - $xml = array( - '', - ' ', - ' ', - ' ', - '' - ); - $result = $this->parse($xml); - - } - - function testCompTimeRange() { - - $xml = array( - '', - ' ', - ' ', - ' ', - ' ', - ' ', - ' ', - ' ', - ' ', - ' ', - ' ', - ' ', - '' - ); - $result = $this->parse($xml); - - $expected = array( - 'name' => 'VCALENDAR', - 'comp-filters' => array( - array( - 'name' => 'VEVENT', - 'comp-filters' => array(), - 'prop-filters' => array(), - 'is-not-defined' => false, - 'time-range' => array( - 'start' => new \DateTime('2011-01-01 00:00:00', new \DateTimeZone('GMT')), - 'end' => new \DateTime('2011-12-31 23:59:59', new \DateTimeZone('GMT')), - ), - ), - array( - 'name' => 'VTODO', - 'comp-filters' => array(), - 'prop-filters' => array(), - 'is-not-defined' => false, - 'time-range' => array( - 'start' => new \DateTime('2011-01-01 00:00:00', new \DateTimeZone('GMT')), - 'end' => null, - ), - ), - array( - 'name' => 'VJOURNAL', - 'comp-filters' => array(), - 'prop-filters' => array(), - 'is-not-defined' => false, - 'time-range' => array( - 'start' => null, - 'end' => new \DateTime('2011-12-31 23:59:59', new \DateTimeZone('GMT')), - ), - ), - ), - 'prop-filters' => array(), - 'is-not-defined' => false, - 'time-range' => false - ); - - $this->assertEquals( - $expected, - $result - ); - - } - - /** - * @expectedException Sabre\DAV\Exception\BadRequest - */ - function testCompTimeRangeBadRange() { - - $xml = array( - '', - ' ', - ' ', - ' ', - ' ', - ' ', - '' - ); - $this->parse($xml); - - } - - function testProp() { - - $xml = array( - '', - ' ', - ' ', - ' ', - ' vacation', - ' ', - ' ', - ' ', - '' - ); - $result = $this->parse($xml); - - $expected = array( - 'name' => 'VCALENDAR', - 'comp-filters' => array( - array( - 'name' => 'VEVENT', - 'is-not-defined' => false, - 'comp-filters' => array(), - 'prop-filters' => array( - array( - 'name' => 'SUMMARY', - 'is-not-defined' => false, - 'param-filters' => array(), - 'text-match' => array( - 'negate-condition' => false, - 'collation' => 'i;ascii-casemap', - 'value' => 'vacation', - ), - 'time-range' => null, - ), - ), - 'time-range' => null, - ), - ), - 'prop-filters' => array(), - 'is-not-defined' => false, - 'time-range' => false - ); - - $this->assertEquals( - $expected, - $result - ); - - } - - function testComplex() { - - $xml = array( - '', - ' ', - ' ', - ' ', - ' vacation', - ' ', - ' ', - ' ', - ' ', - ' ', - ' ', - ' ', - ' ', - ' ', - ' DATE', - ' ', - ' ', - ' ', - ' ', - '' - ); - $result = $this->parse($xml); - - $expected = array( - 'name' => 'VCALENDAR', - 'comp-filters' => array( - array( - 'name' => 'VEVENT', - 'is-not-defined' => false, - 'comp-filters' => array(), - 'prop-filters' => array( - array( - 'name' => 'SUMMARY', - 'is-not-defined' => false, - 'param-filters' => array(), - 'text-match' => array( - 'negate-condition' => false, - 'collation' => 'i;unicode-casemap', - 'value' => 'vacation', - ), - 'time-range' => null, - ), - array( - 'name' => 'DTSTAMP', - 'is-not-defined' => false, - 'param-filters' => array(), - 'text-match' => null, - 'time-range' => array( - 'start' => new \DateTime('2011-07-04 00:00:00', new \DateTimeZone('GMT')), - 'end' => null, - ), - ), - array( - 'name' => 'ORGANIZER', - 'is-not-defined' => true, - 'param-filters' => array(), - 'text-match' => null, - 'time-range' => null, - ), - array( - 'name' => 'DTSTART', - 'is-not-defined' => false, - 'param-filters' => array( - array( - 'name' => 'VALUE', - 'is-not-defined' => false, - 'text-match' => array( - 'negate-condition' => true, - 'value' => 'DATE', - 'collation' => 'i;ascii-casemap', - ), - ), - ), - 'text-match' => null, - 'time-range' => null, - ), - ), - 'time-range' => null, - ), - ), - 'prop-filters' => array(), - 'is-not-defined' => false, - 'time-range' => false - ); - - $this->assertEquals( - $expected, - $result - ); - - } - - function testOther1() { - - // This body was exactly sent to us from the sabredav mailing list. Checking if this parses correctly. - - $body = << - - - - - - - - - - - - - -BLA; - - $dom = DAV\XMLUtil::loadDOMDocument($body); - - $q = new CalendarQueryParser($dom); - $q->parse(); - - $this->assertEquals(array( - '{urn:ietf:params:xml:ns:caldav}calendar-data', - '{DAV:}getetag', - ), $q->requestedProperties); - - $expectedFilters = array( - 'name' => 'VCALENDAR', - 'comp-filters' => array( - array( - 'name' => 'VEVENT', - 'comp-filters' => array(), - 'prop-filters' => array(), - 'time-range' => array( - 'start' => new \DateTime('2009-01-01 00:00:00', new \DateTimeZone('UTC')), - 'end' => new \DateTime('2012-12-02 00:00:00', new \DateTimeZone('UTC')), - ), - 'is-not-defined' => false, - ), - ), - 'prop-filters' => array(), - 'time-range' => null, - 'is-not-defined' => false, - ); - - $this->assertEquals($expectedFilters, $q->filters); - - } - - function testExpand() { - - $xml = array( - '', - ' ', - ' ', - ' ', - '', - '', - ' ', - '' - ); - - $xml = -' - -' . implode("\n", $xml) . ' -'; - - $dom = DAV\XMLUtil::loadDOMDocument($xml); - $q = new CalendarQueryParser($dom); - $q->parse(); - - - $expected = array( - 'name' => 'VCALENDAR', - 'comp-filters' => array(), - 'prop-filters' => array(), - 'is-not-defined' => false, - 'time-range' => false - ); - - $this->assertEquals( - $expected, - $q->filters - ); - - $this->assertEquals(array( - '{urn:ietf:params:xml:ns:caldav}calendar-data', - ), $q->requestedProperties); - - $this->assertEquals( - array( - 'start' => new \DateTime('2011-01-01 00:00:00', new \DateTimeZone('UTC')), - 'end' => new \DateTime('2012-01-01 00:00:00', new \DateTimeZone('UTC')), - ), - $q->expand - ); - - } - - /** - * @expectedException Sabre\DAV\Exception\BadRequest - */ - function testExpandNoStart() { - - $xml = array( - '', - ' ', - ' ', - ' ', - '', - '', - ' ', - '' - ); - - $xml = -' - -' . implode("\n", $xml) . ' -'; - - $dom = DAV\XMLUtil::loadDOMDocument($xml); - $q = new CalendarQueryParser($dom); - $q->parse(); - - } - /** - * @expectedException Sabre\DAV\Exception\BadRequest - */ - function testExpandNoEnd() { - - $xml = array( - '', - ' ', - ' ', - ' ', - '', - '', - ' ', - '' - ); - - $xml = -' - -' . implode("\n", $xml) . ' -'; - - $dom = DAV\XMLUtil::loadDOMDocument($xml); - $q = new CalendarQueryParser($dom); - $q->parse(); - - } - /** - * @expectedException Sabre\DAV\Exception\BadRequest - */ - function testExpandBadTimes() { - - $xml = array( - '', - ' ', - ' ', - ' ', - '', - '', - ' ', - '' - ); - - $xml = -' - -' . implode("\n", $xml) . ' -'; - - $dom = DAV\XMLUtil::loadDOMDocument($xml); - $q = new CalendarQueryParser($dom); - $q->parse(); - - } -} diff --git a/vendor/sabre/dav/tests/Sabre/CalDAV/CalendarQueryValidatorTest.php b/vendor/sabre/dav/tests/Sabre/CalDAV/CalendarQueryValidatorTest.php index deb70d205..9822e82e2 100644 --- a/vendor/sabre/dav/tests/Sabre/CalDAV/CalendarQueryValidatorTest.php +++ b/vendor/sabre/dav/tests/Sabre/CalDAV/CalendarQueryValidatorTest.php @@ -6,6 +6,20 @@ use Sabre\DAV; class CalendarQueryValidatorTest extends \PHPUnit_Framework_TestCase { + function testTopLevelFail() { + + $validator = new CalendarQueryValidator(); + $vcal = <<assertFalse($validator->validate($vcal, ['name' => 'VFOO'])); + + } + /** * @dataProvider provider */ @@ -35,10 +49,14 @@ class CalendarQueryValidatorTest extends \PHPUnit_Framework_TestCase { case -1 : try { $validator->validate($vObject, $filters); - } catch (DAV\Exception $e) { - // Success - } catch (\LogicException $e) { - // Success + $this->fail('This test was supposed to fail'); + } catch (\Exception $e) { + // We need to test something to be valid for phpunit strict + // mode. + $this->assertTrue(true); + } catch (\Throwable $e) { + // PHP7 + $this->assertTrue(true); } break; @@ -334,6 +352,7 @@ yow; $blob31 = <<calendar->updateProperties(array( + $propPatch = new PropPatch([ '{DAV:}displayname' => 'NewName', - )); + ]); + + $result = $this->calendar->propPatch($propPatch); + $result = $propPatch->commit(); $this->assertEquals(true, $result); @@ -69,9 +74,6 @@ class CalendarTest extends \PHPUnit_Framework_TestCase { $question = array( '{urn:ietf:params:xml:ns:caldav}supported-calendar-component-set', - '{urn:ietf:params:xml:ns:caldav}supported-calendar-data', - '{urn:ietf:params:xml:ns:caldav}supported-collation-set', - '{DAV:}owner', ); $result = $this->calendar->getProperties($question); @@ -80,11 +82,6 @@ class CalendarTest extends \PHPUnit_Framework_TestCase { $this->assertEquals(array('VEVENT','VTODO'), $result['{urn:ietf:params:xml:ns:caldav}supported-calendar-component-set']->getValue()); - $this->assertTrue($result['{urn:ietf:params:xml:ns:caldav}supported-collation-set'] instanceof Property\SupportedCollationSet); - - $this->assertTrue($result['{DAV:}owner'] instanceof DAVACL\Property\Principal); - $this->assertEquals('principals/user1', $result['{DAV:}owner']->getHref()); - } /** @@ -202,28 +199,28 @@ class CalendarTest extends \PHPUnit_Framework_TestCase { 'protected' => true, ), array( - 'privilege' => '{DAV:}write', - 'principal' => 'principals/user1', + 'privilege' => '{DAV:}read', + 'principal' => 'principals/user1/calendar-proxy-write', 'protected' => true, ), array( 'privilege' => '{DAV:}read', - 'principal' => 'principals/user1/calendar-proxy-write', + 'principal' => 'principals/user1/calendar-proxy-read', 'protected' => true, ), array( - 'privilege' => '{DAV:}write', - 'principal' => 'principals/user1/calendar-proxy-write', + 'privilege' => '{' . Plugin::NS_CALDAV . '}read-free-busy', + 'principal' => '{DAV:}authenticated', 'protected' => true, ), array( - 'privilege' => '{DAV:}read', - 'principal' => 'principals/user1/calendar-proxy-read', + 'privilege' => '{DAV:}write', + 'principal' => 'principals/user1', 'protected' => true, ), array( - 'privilege' => '{' . Plugin::NS_CALDAV . '}read-free-busy', - 'principal' => '{DAV:}authenticated', + 'privilege' => '{DAV:}write', + 'principal' => 'principals/user1/calendar-proxy-write', 'protected' => true, ), ); @@ -251,5 +248,42 @@ class CalendarTest extends \PHPUnit_Framework_TestCase { } + function testGetSyncToken() { + + $this->assertEquals(2, $this->calendar->getSyncToken()); + + } + function testGetSyncToken2() { + + $calendar = new Calendar(new Backend\Mock([],[]), [ + '{DAV:}sync-token' => 2 + ]); + $this->assertEquals(2, $this->calendar->getSyncToken()); + + } + + function testGetSyncTokenNoSyncSupport() { + + $calendar = new Calendar(new Backend\Mock([],[]), []); + $this->assertNull($calendar->getSyncToken()); + } + + function testGetChanges() { + + $this->assertEquals([ + 'syncToken' => 2, + 'modified' => [], + 'deleted' => [], + 'added' => ['UUID-2345'], + ], $this->calendar->getChanges(1, 1)); + + } + + function testGetChangesNoSyncSupport() { + + $calendar = new Calendar(new Backend\Mock([],[]), []); + $this->assertNull($calendar->getChanges(1,null)); + + } } diff --git a/vendor/sabre/dav/tests/Sabre/CalDAV/ExpandEventsDTSTARTandDTENDTest.php b/vendor/sabre/dav/tests/Sabre/CalDAV/ExpandEventsDTSTARTandDTENDTest.php index 2767b5f8d..9a3d47828 100644 --- a/vendor/sabre/dav/tests/Sabre/CalDAV/ExpandEventsDTSTARTandDTENDTest.php +++ b/vendor/sabre/dav/tests/Sabre/CalDAV/ExpandEventsDTSTARTandDTENDTest.php @@ -1,6 +1,7 @@ 1, - 'name' => 'Calendar', + protected $caldavCalendars = [ + [ + 'id' => 1, + 'name' => 'Calendar', 'principaluri' => 'principals/user1', - 'uri' => 'calendar1', - ) - ); + 'uri' => 'calendar1', + ] + ]; - protected $caldavCalendarObjects = array( - 1 => array( - 'event.ics' => array( + protected $caldavCalendarObjects = [ + 1 => [ + 'event.ics' => [ 'calendardata' => 'BEGIN:VCALENDAR VERSION:2.0 BEGIN:VEVENT @@ -47,18 +48,18 @@ RECURRENCE-ID;TZID=Europe/Berlin:20120208T181500 END:VEVENT END:VCALENDAR ', - ), - ), - ); + ], + ], + ]; function testExpand() { - $request = new HTTP\Request(array( - 'REQUEST_METHOD' => 'REPORT', + $request = HTTP\Sapi::createFromServerArray([ + 'REQUEST_METHOD' => 'REPORT', 'HTTP_CONTENT_TYPE' => 'application/xml', - 'REQUEST_URI' => '/calendars/user1/calendar1', - 'HTTP_DEPTH' => '1', - )); + 'REQUEST_URI' => '/calendars/user1/calendar1', + 'HTTP_DEPTH' => '1', + ]); $request->setBody(' @@ -85,26 +86,28 @@ END:VCALENDAR $start = strpos($response->body, 'BEGIN:VCALENDAR'), strpos($response->body, 'END:VCALENDAR') - $start + 13 ); - $body = str_replace(' ','',$body); + $body = str_replace(' ', '', $body); - $vObject = VObject\Reader::read($body); + try { + $vObject = VObject\Reader::read($body); + } catch (VObject\ParseException $e) { + $this->fail('Could not parse object. Error:' . $e->getMessage() . ' full object: ' . $response->getBodyAsString()); + } // check if DTSTARTs and DTENDs are correct foreach ($vObject->VEVENT as $vevent) { /** @var $vevent Sabre\VObject\Component\VEvent */ - foreach ($vevent->children as $child) { + foreach ($vevent->children() as $child) { /** @var $child Sabre\VObject\Property */ - if ($child->name == 'DTSTART') { // DTSTART has to be one of three valid values - $this->assertContains($child->getValue(), array('20120207T171500Z', '20120208T171500Z', '20120209T171500Z'), 'DTSTART is not a valid value: '.$child->getValue()); + $this->assertContains($child->getValue(), ['20120207T171500Z', '20120208T171500Z', '20120209T171500Z'], 'DTSTART is not a valid value: ' . $child->getValue()); } elseif ($child->name == 'DTEND') { // DTEND has to be one of three valid values - $this->assertContains($child->getValue(), array('20120207T181500Z', '20120208T181500Z', '20120209T181500Z'), 'DTEND is not a valid value: '.$child->getValue()); + $this->assertContains($child->getValue(), ['20120207T181500Z', '20120208T181500Z', '20120209T181500Z'], 'DTEND is not a valid value: ' . $child->getValue()); } } } } } - diff --git a/vendor/sabre/dav/tests/Sabre/CalDAV/ExpandEventsDTSTARTandDTENDbyDayTest.php b/vendor/sabre/dav/tests/Sabre/CalDAV/ExpandEventsDTSTARTandDTENDbyDayTest.php index 3793cadc7..efc49673f 100644 --- a/vendor/sabre/dav/tests/Sabre/CalDAV/ExpandEventsDTSTARTandDTENDbyDayTest.php +++ b/vendor/sabre/dav/tests/Sabre/CalDAV/ExpandEventsDTSTARTandDTENDbyDayTest.php @@ -1,13 +1,14 @@ 1, - 'name' => 'Calendar', + protected $caldavCalendars = [ + [ + 'id' => 1, + 'name' => 'Calendar', 'principaluri' => 'principals/user1', - 'uri' => 'calendar1', - ) - ); + 'uri' => 'calendar1', + ] + ]; - protected $caldavCalendarObjects = array( - 1 => array( - 'event.ics' => array( + protected $caldavCalendarObjects = [ + 1 => [ + 'event.ics' => [ 'calendardata' => 'BEGIN:VCALENDAR VERSION:2.0 BEGIN:VEVENT @@ -38,18 +39,18 @@ DTSTART;TZID=Europe/Berlin:20120207T181500 END:VEVENT END:VCALENDAR ', - ), - ), - ); + ], + ], + ]; function testExpandRecurringByDayEvent() { - $request = new HTTP\Request(array( - 'REQUEST_METHOD' => 'REPORT', + $request = HTTP\Sapi::createFromServerArray([ + 'REQUEST_METHOD' => 'REPORT', 'HTTP_CONTENT_TYPE' => 'application/xml', - 'REQUEST_URI' => '/calendars/user1/calendar1', - 'HTTP_DEPTH' => '1', - )); + 'REQUEST_URI' => '/calendars/user1/calendar1', + 'HTTP_DEPTH' => '1', + ]); $request->setBody(' @@ -76,7 +77,7 @@ END:VCALENDAR $start = strpos($response->body, 'BEGIN:VCALENDAR'), strpos($response->body, 'END:VCALENDAR') - $start + 13 ); - $body = str_replace(' ','',$body); + $body = str_replace(' ', '', $body); $vObject = VObject\Reader::read($body); @@ -85,19 +86,17 @@ END:VCALENDAR // check if DTSTARTs and DTENDs are correct foreach ($vObject->VEVENT as $vevent) { /** @var $vevent Sabre\VObject\Component\VEvent */ - foreach ($vevent->children as $child) { + foreach ($vevent->children() as $child) { /** @var $child Sabre\VObject\Property */ - if ($child->name == 'DTSTART') { // DTSTART has to be one of two valid values - $this->assertContains($child->getValue(), array('20120214T171500Z', '20120216T171500Z'), 'DTSTART is not a valid value: '.$child->getValue()); + $this->assertContains($child->getValue(), ['20120214T171500Z', '20120216T171500Z'], 'DTSTART is not a valid value: ' . $child->getValue()); } elseif ($child->name == 'DTEND') { // DTEND has to be one of two valid values - $this->assertContains($child->getValue(), array('20120214T181500Z', '20120216T181500Z'), 'DTEND is not a valid value: '.$child->getValue()); + $this->assertContains($child->getValue(), ['20120214T181500Z', '20120216T181500Z'], 'DTEND is not a valid value: ' . $child->getValue()); } } } } } - diff --git a/vendor/sabre/dav/tests/Sabre/CalDAV/ExpandEventsDoubleEventsTest.php b/vendor/sabre/dav/tests/Sabre/CalDAV/ExpandEventsDoubleEventsTest.php index 09eea5276..b64fb122a 100644 --- a/vendor/sabre/dav/tests/Sabre/CalDAV/ExpandEventsDoubleEventsTest.php +++ b/vendor/sabre/dav/tests/Sabre/CalDAV/ExpandEventsDoubleEventsTest.php @@ -11,7 +11,7 @@ use Sabre\VObject; * Hopefully, by the time I'm done with this, I've both found the problem, and * fixed it :) * - * @copyright Copyright (C) 2007-2014 fruux GmbH (https://fruux.com/). + * @copyright Copyright (C) fruux GmbH (https://fruux.com/) * @author Evert Pot (http://evertpot.com/) * @license http://sabre.io/license/ Modified BSD License */ @@ -56,12 +56,12 @@ END:VCALENDAR function testExpand() { - $request = new HTTP\Request(array( + $request = HTTP\Sapi::createFromServerArray([ 'REQUEST_METHOD' => 'REPORT', 'HTTP_CONTENT_TYPE' => 'application/xml', 'REQUEST_URI' => '/calendars/user1/calendar1', 'HTTP_DEPTH' => '1', - )); + ]); $request->setBody(' diff --git a/vendor/sabre/dav/tests/Sabre/CalDAV/FreeBusyReportTest.php b/vendor/sabre/dav/tests/Sabre/CalDAV/FreeBusyReportTest.php index 93eca9ee9..84f05f3c0 100644 --- a/vendor/sabre/dav/tests/Sabre/CalDAV/FreeBusyReportTest.php +++ b/vendor/sabre/dav/tests/Sabre/CalDAV/FreeBusyReportTest.php @@ -30,6 +30,7 @@ DURATION:PT1H END:VEVENT END:VCALENDAR ics; + $obj2 = fopen('php://memory','r+'); fwrite($obj2,<< array( - 'obj1' => array( + $obj3 = << [ + 'obj1' => [ 'calendarid' => 1, 'uri' => 'event1.ics', 'calendardata' => $obj1, - ), - 'obj2' => array( + ], + 'obj2' => [ 'calendarid' => 1, 'uri' => 'event2.ics', 'calendardata' => $obj2 - ) - ), - ); + ], + 'obj3' => [ + 'calendarid' => 1, + 'uri' => 'event3.ics', + 'calendardata' => $obj3 + ] + ], + ]; - $caldavBackend = new Backend\Mock(array(), $calendarData); + $caldavBackend = new Backend\Mock([], $calendarData); - $calendar = new Calendar($caldavBackend, array( + $calendar = new Calendar($caldavBackend, [ 'id' => 1, 'uri' => 'calendar', 'principaluri' => 'principals/user1', - )); + '{' . Plugin::NS_CALDAV . '}calendar-timezone' => "BEGIN:VCALENDAR\r\nBEGIN:VTIMEZONE\r\nTZID:Europe/Berlin\r\nEND:VTIMEZONE\r\nEND:VCALENDAR", + ]); - $this->server = new DAV\Server(array($calendar)); + $this->server = new DAV\Server([$calendar]); - $request = new HTTP\Request(array( + $request = HTTP\Sapi::createFromServerArray([ 'REQUEST_URI' => '/calendar', - )); + ]); $this->server->httpRequest = $request; $this->server->httpResponse = new HTTP\ResponseMock(); $this->plugin = new Plugin(); $this->server->addPlugin($this->plugin); - $this->server->addPlugin(new DAVACL\Plugin()); } @@ -89,12 +104,14 @@ ics XML; - $dom = DAV\XMLUtil::loadDOMDocument($reportXML); - $this->plugin->report('{urn:ietf:params:xml:ns:caldav}free-busy-query', $dom); + $report = $this->server->xml->parse($reportXML, null, $rootElem); + $this->plugin->report($rootElem, $report); - $this->assertEquals('HTTP/1.1 200 OK', $this->server->httpResponse->status); - $this->assertEquals('text/calendar', $this->server->httpResponse->headers['Content-Type']); - $this->assertTrue(strpos($this->server->httpResponse->body,'BEGIN:VFREEBUSY')!==false); + $this->assertEquals(200, $this->server->httpResponse->status); + $this->assertEquals('text/calendar', $this->server->httpResponse->getHeader('Content-Type')); + $this->assertTrue(strpos($this->server->httpResponse->body, 'BEGIN:VFREEBUSY')!==false); + $this->assertTrue(strpos($this->server->httpResponse->body, '20111005T120000Z/20111005T130000Z')!==false); + $this->assertTrue(strpos($this->server->httpResponse->body, '20111006T100000Z/20111006T110000Z')!==false); } @@ -109,8 +126,8 @@ XML; XML; - $dom = DAV\XMLUtil::loadDOMDocument($reportXML); - $this->plugin->report('{urn:ietf:params:xml:ns:caldav}free-busy-query', $dom); + $report = $this->server->xml->parse($reportXML, null, $rootElem); + $this->plugin->report($rootElem, $report); } @@ -119,7 +136,7 @@ XML; */ function testFreeBusyReportWrongNode() { - $request = new HTTP\Request(array( + $request = HTTP\Sapi::createFromServerArray(array( 'REQUEST_URI' => '/', )); $this->server->httpRequest = $request; @@ -131,8 +148,8 @@ XML; XML; - $dom = DAV\XMLUtil::loadDOMDocument($reportXML); - $this->plugin->report('{urn:ietf:params:xml:ns:caldav}free-busy-query', $dom); + $report = $this->server->xml->parse($reportXML, null, $rootElem); + $this->plugin->report($rootElem, $report); } @@ -152,8 +169,8 @@ XML; XML; - $dom = DAV\XMLUtil::loadDOMDocument($reportXML); - $this->plugin->report('{urn:ietf:params:xml:ns:caldav}free-busy-query', $dom); + $report = $this->server->xml->parse($reportXML, null, $rootElem); + $this->plugin->report($rootElem, $report); } } diff --git a/vendor/sabre/dav/tests/Sabre/CalDAV/FreeBusyRequestTest.php b/vendor/sabre/dav/tests/Sabre/CalDAV/FreeBusyRequestTest.php deleted file mode 100644 index 62252e6a1..000000000 --- a/vendor/sabre/dav/tests/Sabre/CalDAV/FreeBusyRequestTest.php +++ /dev/null @@ -1,282 +0,0 @@ - 'principals/user2', - 'id' => 1, - 'uri' => 'calendar1', - ), - ); - $calendarobjects = array( - 1 => array( '1.ics' => array( - 'uri' => '1.ics', - 'calendardata' => 'BEGIN:VCALENDAR -BEGIN:VEVENT -DTSTART:20110101T130000 -DURATION:PT1H -END:VEVENT -END:VCALENDAR', - 'calendarid' => 1, - )) - - ); - - $principalBackend = new DAVACL\PrincipalBackend\Mock(); - $caldavBackend = new Backend\Mock($calendars, $calendarobjects); - - $tree = array( - new DAVACL\PrincipalCollection($principalBackend), - new CalendarRootNode($principalBackend, $caldavBackend), - ); - - $this->request = new HTTP\Request(array( - 'CONTENT_TYPE' => 'text/calendar', - )); - $this->response = new HTTP\ResponseMock(); - - $this->server = new DAV\Server($tree); - $this->server->httpRequest = $this->request; - $this->server->httpResponse = $this->response; - - $this->aclPlugin = new DAVACL\Plugin(); - $this->server->addPlugin($this->aclPlugin); - - $authBackend = new DAV\Auth\Backend\Mock(); - $authBackend->setCurrentUser('user1'); - $this->authPlugin = new DAV\Auth\Plugin($authBackend,'SabreDAV'); - $this->server->addPlugin($this->authPlugin); - - $this->plugin = new Plugin(); - $this->server->addPlugin($this->plugin); - - } - - function testWrongMethod() { - - $this->assertNull( - $this->plugin->unknownMethod('PUT','calendars/user1/outbox') - ); - - } - - function testWrongContentType() { - - $this->server->httpRequest = new HTTP\Request(array( - 'CONTENT_TYPE' => 'text/plain', - )); - - $this->assertNull( - $this->plugin->unknownMethod('POST','calendars/user1/outbox') - ); - - } - - function testNotFound() { - - $this->assertNull( - $this->plugin->unknownMethod('POST','calendars/user1/blabla') - ); - - } - - function testNotOutbox() { - - $this->assertNull( - $this->plugin->unknownMethod('POST','calendars/user1/inbox') - ); - - } - - /** - * @expectedException Sabre\DAV\Exception\BadRequest - */ - function testNoItipMethod() { - - $body = <<request->setBody($body); - $this->plugin->unknownMethod('POST','calendars/user1/outbox'); - - } - - /** - * @expectedException Sabre\DAV\Exception\BadRequest - */ - function testNoVFreeBusy() { - - $body = <<request->setBody($body); - $this->plugin->unknownMethod('POST','calendars/user1/outbox'); - - } - - /** - * @expectedException Sabre\DAV\Exception\Forbidden - */ - function testIncorrectOrganizer() { - - $body = <<request->setBody($body); - $this->plugin->unknownMethod('POST','calendars/user1/outbox'); - - } - - /** - * @expectedException Sabre\DAV\Exception\BadRequest - */ - function testNoAttendees() { - - $body = <<request->setBody($body); - $this->plugin->unknownMethod('POST','calendars/user1/outbox'); - - } - - /** - * @expectedException Sabre\DAV\Exception\BadRequest - */ - function testNoDTStart() { - - $body = <<request->setBody($body); - $this->plugin->unknownMethod('POST','calendars/user1/outbox'); - - } - - function testSucceed() { - - $body = <<aclPlugin->adminPrincipals[] = 'principals/user1'; - - $this->request->setBody($body); - $this->assertFalse($this->plugin->unknownMethod('POST','calendars/user1/outbox')); - - $this->assertEquals('HTTP/1.1 200 OK' , $this->response->status); - $this->assertEquals(array( - 'Content-Type' => 'application/xml', - ), $this->response->headers); - - $strings = array( - 'mailto:user2.sabredav@sabredav.org', - 'mailto:user3.sabredav@sabredav.org', - '2.0;Success', - '3.7;Could not find principal', - 'FREEBUSY;FBTYPE=BUSY:20110101T130000Z/20110101T140000Z', - ); - - foreach($strings as $string) { - $this->assertTrue( - strpos($this->response->body, $string)!==false, - 'The response body did not contain: ' . $string .'Full response: ' . $this->response->body - ); - } - - - } - - function testNoPrivilege() { - - $body = <<request->setBody($body); - $this->assertFalse($this->plugin->unknownMethod('POST','calendars/user1/outbox')); - - $this->assertEquals('HTTP/1.1 200 OK' , $this->response->status); - $this->assertEquals(array( - 'Content-Type' => 'application/xml', - ), $this->response->headers); - - $strings = array( - 'mailto:user2.sabredav@sabredav.org', - '3.7;No calendar-home-set property found', - ); - - foreach($strings as $string) { - $this->assertTrue( - strpos($this->response->body, $string)!==false, - 'The response body did not contain: ' . $string .'Full response: ' . $this->response->body - ); - } - - - } - -} diff --git a/vendor/sabre/dav/tests/Sabre/CalDAV/GetEventsByTimerangeTest.php b/vendor/sabre/dav/tests/Sabre/CalDAV/GetEventsByTimerangeTest.php index 6c9a09905..c3c97e8f6 100644 --- a/vendor/sabre/dav/tests/Sabre/CalDAV/GetEventsByTimerangeTest.php +++ b/vendor/sabre/dav/tests/Sabre/CalDAV/GetEventsByTimerangeTest.php @@ -1,13 +1,13 @@ 1, - 'name' => 'Calendar', + protected $caldavCalendars = [ + [ + 'id' => 1, + 'name' => 'Calendar', 'principaluri' => 'principals/user1', - 'uri' => 'calendar1', - ) - ); + 'uri' => 'calendar1', + ] + ]; - protected $caldavCalendarObjects = array( - 1 => array( - 'event.ics' => array( + protected $caldavCalendarObjects = [ + 1 => [ + 'event.ics' => [ 'calendardata' => 'BEGIN:VCALENDAR VERSION:2.0 BEGIN:VEVENT CREATED:20120313T142342Z UID:171EBEFC-C951-499D-B234-7BA7D677B45D -DTEND;TZID=Europe/Berlin:20120227T000000 +DTEND;TZID=Europe/Berlin:20120227T010000 TRANSP:OPAQUE SUMMARY:Monday 0h DTSTART;TZID=Europe/Berlin:20120227T000000 @@ -41,31 +41,33 @@ SEQUENCE:4 END:VEVENT END:VCALENDAR ', - ), - ), - ); + ], + ], + ]; function testQueryTimerange() { - $request = new HTTP\Request(array( - 'REQUEST_METHOD' => 'REPORT', - 'HTTP_CONTENT_TYPE' => 'application/xml', - 'REQUEST_URI' => '/calendars/user1/calendar1', - 'HTTP_DEPTH' => '1', - )); + $request = new HTTP\Request( + 'REPORT', + '/calendars/user1/calendar1', + [ + 'Content-Type' => 'application/xml', + 'Depth' => '1', + ] + ); $request->setBody(' - + - + @@ -73,24 +75,8 @@ END:VCALENDAR $response = $this->request($request); - if (strpos($response->body, 'BEGIN:VCALENDAR') === false) { - $this->fail('Got no events instead of 1. Output: '.$response->body); - } - - // Everts super awesome xml parser. - $body = substr( - $response->body, - $start = strpos($response->body, 'BEGIN:VCALENDAR'), - strpos($response->body, 'END:VCALENDAR') - $start + 13 - ); - $body = str_replace(' ','',$body); - - $vObject = VObject\Reader::read($body); - - // We expect 1 event - $this->assertEquals(1, count($vObject->VEVENT), 'We got 0 events instead of 1. Output: ' . $body); + $this->assertTrue(strpos($response->body, 'BEGIN:VCALENDAR')!==false); } } - diff --git a/vendor/sabre/dav/tests/Sabre/CalDAV/ICSExportPluginTest.php b/vendor/sabre/dav/tests/Sabre/CalDAV/ICSExportPluginTest.php index be21796dd..c123bd0c1 100644 --- a/vendor/sabre/dav/tests/Sabre/CalDAV/ICSExportPluginTest.php +++ b/vendor/sabre/dav/tests/Sabre/CalDAV/ICSExportPluginTest.php @@ -12,27 +12,36 @@ require_once 'Sabre/HTTP/ResponseMock.php'; class ICSExportPluginTest extends \PHPUnit_Framework_TestCase { + function setUp() { + + if (!SABRE_HASSQLITE) $this->markTestSkipped('SQLite driver is not available'); + + } + function testInit() { $p = new ICSExportPlugin(); $s = new DAV\Server(); $s->addPlugin($p); + $this->assertEquals($p, $s->getPlugin('ics-export')); + $this->assertEquals('ics-export', $p->getPluginInfo()['name']); } function testBeforeMethod() { - if (!SABRE_HASSQLITE) $this->markTestSkipped('SQLite driver is not available'); $cbackend = TestUtil::getBackend(); - $props = array( + $props = [ 'uri'=>'UUID-123467', 'principaluri' => 'admin', 'id' => 1, - ); - $tree = array( + '{DAV:}displayname' => 'Hello!', + '{http://apple.com/ns/ical/}calendar-color' => '#AA0000FF', + ]; + $tree = [ new Calendar($cbackend,$props), - ); + ]; $p = new ICSExportPlugin(); @@ -40,29 +49,32 @@ class ICSExportPluginTest extends \PHPUnit_Framework_TestCase { $s->addPlugin($p); $s->addPlugin(new Plugin()); - $h = new HTTP\Request(array( - 'QUERY_STRING' => 'export', - )); + $h = HTTP\Sapi::createFromServerArray([ + 'REQUEST_URI' => '/UUID-123467?export', + 'REQUEST_METHOD' => 'GET', + ]); $s->httpRequest = $h; $s->httpResponse = new HTTP\ResponseMock(); - $this->assertFalse($p->beforeMethod('GET','UUID-123467?export')); + $this->assertFalse($p->httpGet($h, $s->httpResponse)); - $this->assertEquals('HTTP/1.1 200 OK',$s->httpResponse->status); - $this->assertEquals(array( - 'Content-Type' => 'text/calendar', - ), $s->httpResponse->headers); + $this->assertEquals(200, $s->httpResponse->status); + $this->assertEquals([ + 'Content-Type' => ['text/calendar'], + ], $s->httpResponse->getHeaders()); $obj = VObject\Reader::read($s->httpResponse->body); - $this->assertEquals(5,count($obj->children())); + $this->assertEquals(7,count($obj->children())); $this->assertEquals(1,count($obj->VERSION)); $this->assertEquals(1,count($obj->CALSCALE)); $this->assertEquals(1,count($obj->PRODID)); $this->assertTrue(strpos((string)$obj->PRODID, DAV\Version::VERSION)!==false); $this->assertEquals(1,count($obj->VTIMEZONE)); $this->assertEquals(1,count($obj->VEVENT)); + $this->assertEquals("Hello!", $obj->{"X-WR-CALNAME"}); + $this->assertEquals("#AA0000FF", $obj->{"X-APPLE-CALENDAR-COLOR"}); } function testBeforeMethodNoVersion() { @@ -70,14 +82,14 @@ class ICSExportPluginTest extends \PHPUnit_Framework_TestCase { if (!SABRE_HASSQLITE) $this->markTestSkipped('SQLite driver is not available'); $cbackend = TestUtil::getBackend(); - $props = array( + $props = [ 'uri'=>'UUID-123467', 'principaluri' => 'admin', 'id' => 1, - ); - $tree = array( + ]; + $tree = [ new Calendar($cbackend,$props), - ); + ]; $p = new ICSExportPlugin(); @@ -86,21 +98,22 @@ class ICSExportPluginTest extends \PHPUnit_Framework_TestCase { $s->addPlugin($p); $s->addPlugin(new Plugin()); - $h = new HTTP\Request(array( - 'QUERY_STRING' => 'export', - )); + $h = HTTP\Sapi::createFromServerArray([ + 'REQUEST_URI' => '/UUID-123467?export', + 'REQUEST_METHOD' => 'GET', + ]); $s->httpRequest = $h; $s->httpResponse = new HTTP\ResponseMock(); DAV\Server::$exposeVersion = false; - $this->assertFalse($p->beforeMethod('GET','UUID-123467?export')); + $this->assertFalse($p->httpGet($h, $s->httpResponse)); DAV\Server::$exposeVersion = true; - $this->assertEquals('HTTP/1.1 200 OK',$s->httpResponse->status); - $this->assertEquals(array( - 'Content-Type' => 'text/calendar', - ), $s->httpResponse->headers); + $this->assertEquals(200, $s->httpResponse->status); + $this->assertEquals([ + 'Content-Type' => ['text/calendar'], + ], $s->httpResponse->getHeaders()); $obj = VObject\Reader::read($s->httpResponse->body); @@ -114,17 +127,6 @@ class ICSExportPluginTest extends \PHPUnit_Framework_TestCase { } - function testBeforeMethodNoGET() { - - $p = new ICSExportPlugin(); - - $s = new DAV\Server(); - $s->addPlugin($p); - - $this->assertNull($p->beforeMethod('POST','UUID-123467?export')); - - } - function testBeforeMethodNoExport() { $p = new ICSExportPlugin(); @@ -132,16 +134,16 @@ class ICSExportPluginTest extends \PHPUnit_Framework_TestCase { $s = new DAV\Server(); $s->addPlugin($p); - $this->assertNull($p->beforeMethod('GET','UUID-123467')); + $h = HTTP\Sapi::createFromServerArray([ + 'REQUEST_URI' => '/UUID-123467', + 'REQUEST_METHOD' => 'GET', + ]); + $this->assertNull($p->httpGet($h, $s->httpResponse)); } - /** - * @expectedException Sabre\DAVACL\Exception\NeedPrivileges - */ function testACLIntegrationBlocked() { - if (!SABRE_HASSQLITE) $this->markTestSkipped('SQLite driver is not available'); $cbackend = TestUtil::getBackend(); $props = array( @@ -160,20 +162,24 @@ class ICSExportPluginTest extends \PHPUnit_Framework_TestCase { $s->addPlugin(new Plugin()); $s->addPlugin(new DAVACL\Plugin()); - $h = new HTTP\Request(array( - 'QUERY_STRING' => 'export', - )); + $h = HTTP\Sapi::createFromServerArray([ + 'REQUEST_URI' => '/UUID-123467?export', + ]); $s->httpRequest = $h; $s->httpResponse = new HTTP\ResponseMock(); - $p->beforeMethod('GET','UUID-123467?export'); + $p->httpGet($h, $s->httpResponse); + + // If the ACL system blocked this request, the effect will be that + // there's no response, because the calendar information could not be + // fetched. + $this->assertNull($s->httpResponse->getStatus()); } function testACLIntegrationNotBlocked() { - if (!SABRE_HASSQLITE) $this->markTestSkipped('SQLite driver is not available'); $cbackend = TestUtil::getBackend(); $pbackend = new DAVACL\PrincipalBackend\Mock(); @@ -190,6 +196,7 @@ class ICSExportPluginTest extends \PHPUnit_Framework_TestCase { $p = new ICSExportPlugin(); $s = new DAV\Server($tree); + $s->sapi = new HTTP\SapiMock(); $s->addPlugin($p); $s->addPlugin(new Plugin()); $s->addPlugin(new DAVACL\Plugin()); @@ -198,21 +205,22 @@ class ICSExportPluginTest extends \PHPUnit_Framework_TestCase { // Forcing login $s->getPlugin('acl')->adminPrincipals = array('principals/admin'); - $h = new HTTP\Request(array( - 'QUERY_STRING' => 'export', - 'REQUEST_URI' => '/UUID-123467', + + $h = HTTP\Sapi::createFromServerArray([ + 'REQUEST_URI' => '/UUID-123467?export', 'REQUEST_METHOD' => 'GET', - )); + ]); $s->httpRequest = $h; $s->httpResponse = new HTTP\ResponseMock(); $s->exec(); - $this->assertEquals('HTTP/1.1 200 OK',$s->httpResponse->status,'Invalid status received. Response body: '. $s->httpResponse->body); + $this->assertEquals(200, $s->httpResponse->status,'Invalid status received. Response body: '. $s->httpResponse->body); $this->assertEquals(array( - 'Content-Type' => 'text/calendar', - ), $s->httpResponse->headers); + 'X-Sabre-Version' => [DAV\Version::VERSION], + 'Content-Type' => ['text/calendar'], + ), $s->httpResponse->getHeaders()); $obj = VObject\Reader::read($s->httpResponse->body); @@ -224,4 +232,432 @@ class ICSExportPluginTest extends \PHPUnit_Framework_TestCase { $this->assertEquals(1,count($obj->VEVENT)); } + + function testBadStartParam() { + + $cbackend = TestUtil::getBackend(); + $pbackend = new DAVACL\PrincipalBackend\Mock(); + + $props = array( + 'uri'=>'UUID-123467', + 'principaluri' => 'admin', + 'id' => 1, + ); + $tree = array( + new Calendar($cbackend,$props), + new DAVACL\PrincipalCollection($pbackend), + ); + + $p = new ICSExportPlugin(); + + $s = new DAV\Server($tree); + $s->sapi = new HTTP\SapiMock(); + $s->addPlugin($p); + $s->addPlugin(new Plugin()); + + $h = HTTP\Sapi::createFromServerArray([ + 'REQUEST_URI' => '/UUID-123467?export&start=foo', + 'REQUEST_METHOD' => 'GET', + ]); + + $s->httpRequest = $h; + $s->httpResponse = new HTTP\ResponseMock(); + + $s->exec(); + + $this->assertEquals(400, $s->httpResponse->status,'Invalid status received. Response body: '. $s->httpResponse->body); + + } + + function testBadEndParam() { + + $cbackend = TestUtil::getBackend(); + $pbackend = new DAVACL\PrincipalBackend\Mock(); + + $props = array( + 'uri'=>'UUID-123467', + 'principaluri' => 'admin', + 'id' => 1, + ); + $tree = array( + new Calendar($cbackend,$props), + new DAVACL\PrincipalCollection($pbackend), + ); + + $p = new ICSExportPlugin(); + + $s = new DAV\Server($tree); + $s->sapi = new HTTP\SapiMock(); + $s->addPlugin($p); + $s->addPlugin(new Plugin()); + + $h = HTTP\Sapi::createFromServerArray([ + 'REQUEST_URI' => '/UUID-123467?export&end=foo', + 'REQUEST_METHOD' => 'GET', + ]); + + $s->httpRequest = $h; + $s->httpResponse = new HTTP\ResponseMock(); + + $s->exec(); + + $this->assertEquals(400, $s->httpResponse->status,'Invalid status received. Response body: '. $s->httpResponse->body); + + } + + function testFilterStartEnd() { + + $cbackend = TestUtil::getBackend(); + $pbackend = new DAVACL\PrincipalBackend\Mock(); + + $props = array( + 'uri'=>'UUID-123467', + 'principaluri' => 'admin', + 'id' => 1, + ); + $tree = array( + new Calendar($cbackend,$props), + new DAVACL\PrincipalCollection($pbackend), + ); + + $p = new ICSExportPlugin(); + + $s = new DAV\Server($tree); + $s->sapi = new HTTP\SapiMock(); + $s->addPlugin($p); + $s->addPlugin(new Plugin()); + + $h = HTTP\Sapi::createFromServerArray([ + 'REQUEST_URI' => '/UUID-123467?export&start=1&end=2', + 'REQUEST_METHOD' => 'GET', + ]); + + $s->httpRequest = $h; + $s->httpResponse = new HTTP\ResponseMock(); + + $s->exec(); + + $this->assertEquals(200, $s->httpResponse->status,'Invalid status received. Response body: '. $s->httpResponse->body); + $obj = VObject\Reader::read($s->httpResponse->body); + + $this->assertEquals(0,count($obj->VTIMEZONE)); + $this->assertEquals(0,count($obj->VEVENT)); + + } + + function testExpandNoStart() { + + $cbackend = TestUtil::getBackend(); + $pbackend = new DAVACL\PrincipalBackend\Mock(); + + $props = array( + 'uri'=>'UUID-123467', + 'principaluri' => 'admin', + 'id' => 1, + ); + $tree = array( + new Calendar($cbackend,$props), + new DAVACL\PrincipalCollection($pbackend), + ); + + $p = new ICSExportPlugin(); + + $s = new DAV\Server($tree); + $s->sapi = new HTTP\SapiMock(); + $s->addPlugin($p); + $s->addPlugin(new Plugin()); + + $h = HTTP\Sapi::createFromServerArray([ + 'REQUEST_URI' => '/UUID-123467?export&expand=1&end=1', + 'REQUEST_METHOD' => 'GET', + ]); + + $s->httpRequest = $h; + $s->httpResponse = new HTTP\ResponseMock(); + + $s->exec(); + + $this->assertEquals(400, $s->httpResponse->status,'Invalid status received. Response body: '. $s->httpResponse->body); + + } + + function testExpand() { + + $cbackend = TestUtil::getBackend(); + $pbackend = new DAVACL\PrincipalBackend\Mock(); + + $props = array( + 'uri'=>'UUID-123467', + 'principaluri' => 'admin', + 'id' => 1, + ); + $tree = array( + new Calendar($cbackend,$props), + new DAVACL\PrincipalCollection($pbackend), + ); + + $p = new ICSExportPlugin(); + + $s = new DAV\Server($tree); + $s->sapi = new HTTP\SapiMock(); + $s->addPlugin($p); + $s->addPlugin(new Plugin()); + + $h = HTTP\Sapi::createFromServerArray([ + 'REQUEST_URI' => '/UUID-123467?export&start=1&end=2000000000&expand=1', + 'REQUEST_METHOD' => 'GET', + ]); + + $s->httpRequest = $h; + $s->httpResponse = new HTTP\ResponseMock(); + + $s->exec(); + + $this->assertEquals(200, $s->httpResponse->status,'Invalid status received. Response body: '. $s->httpResponse->body); + $obj = VObject\Reader::read($s->httpResponse->body); + + $this->assertEquals(0,count($obj->VTIMEZONE)); + $this->assertEquals(1,count($obj->VEVENT)); + + } + + function testJCal() { + + $cbackend = TestUtil::getBackend(); + $pbackend = new DAVACL\PrincipalBackend\Mock(); + + $props = array( + 'uri'=>'UUID-123467', + 'principaluri' => 'admin', + 'id' => 1, + ); + $tree = array( + new Calendar($cbackend,$props), + new DAVACL\PrincipalCollection($pbackend), + ); + + $p = new ICSExportPlugin(); + + $s = new DAV\Server($tree); + $s->sapi = new HTTP\SapiMock(); + $s->addPlugin($p); + $s->addPlugin(new Plugin()); + + $h = HTTP\Sapi::createFromServerArray([ + 'REQUEST_URI' => '/UUID-123467?export', + 'REQUEST_METHOD' => 'GET', + 'HTTP_ACCEPT' => 'application/calendar+json', + ]); + + $s->httpRequest = $h; + $s->httpResponse = new HTTP\ResponseMock(); + + $s->exec(); + + $this->assertEquals(200, $s->httpResponse->status,'Invalid status received. Response body: '. $s->httpResponse->body); + $this->assertEquals('application/calendar+json', $s->httpResponse->getHeader('Content-Type')); + + } + + function testJCalInUrl() { + + $cbackend = TestUtil::getBackend(); + $pbackend = new DAVACL\PrincipalBackend\Mock(); + + $props = array( + 'uri'=>'UUID-123467', + 'principaluri' => 'admin', + 'id' => 1, + ); + $tree = array( + new Calendar($cbackend,$props), + new DAVACL\PrincipalCollection($pbackend), + ); + + $p = new ICSExportPlugin(); + + $s = new DAV\Server($tree); + $s->sapi = new HTTP\SapiMock(); + $s->addPlugin($p); + $s->addPlugin(new Plugin()); + + $h = HTTP\Sapi::createFromServerArray([ + 'REQUEST_URI' => '/UUID-123467?export&accept=jcal', + 'REQUEST_METHOD' => 'GET', + ]); + + $s->httpRequest = $h; + $s->httpResponse = new HTTP\ResponseMock(); + + $s->exec(); + + $this->assertEquals(200, $s->httpResponse->status,'Invalid status received. Response body: '. $s->httpResponse->body); + $this->assertEquals('application/calendar+json', $s->httpResponse->getHeader('Content-Type')); + + } + + function testNegotiateDefault() { + + $cbackend = TestUtil::getBackend(); + $pbackend = new DAVACL\PrincipalBackend\Mock(); + + $props = array( + 'uri'=>'UUID-123467', + 'principaluri' => 'admin', + 'id' => 1, + ); + $tree = array( + new Calendar($cbackend,$props), + new DAVACL\PrincipalCollection($pbackend), + ); + + $p = new ICSExportPlugin(); + + $s = new DAV\Server($tree); + $s->sapi = new HTTP\SapiMock(); + $s->addPlugin($p); + $s->addPlugin(new Plugin()); + + $h = HTTP\Sapi::createFromServerArray([ + 'REQUEST_URI' => '/UUID-123467?export', + 'REQUEST_METHOD' => 'GET', + 'HTTP_ACCEPT' => 'text/plain', + ]); + + $s->httpRequest = $h; + $s->httpResponse = new HTTP\ResponseMock(); + + $s->exec(); + + $this->assertEquals(200, $s->httpResponse->status,'Invalid status received. Response body: '. $s->httpResponse->body); + $this->assertEquals('text/calendar', $s->httpResponse->getHeader('Content-Type')); + + } + + function testFilterComponentVEVENT() { + + $cbackend = TestUtil::getBackend(); + $pbackend = new DAVACL\PrincipalBackend\Mock(); + + $props = array( + 'uri'=>'UUID-123467', + 'principaluri' => 'admin', + 'id' => 1, + ); + // add a todo to the calendar (see /tests/Sabre/TestUtil) + $cbackend->createCalendarObject(1, 'UUID-3456', TestUtil::getTestTODO()); + + $tree = array( + new Calendar($cbackend,$props), + new DAVACL\PrincipalCollection($pbackend), + ); + + $p = new ICSExportPlugin(); + + $s = new DAV\Server($tree); + $s->sapi = new HTTP\SapiMock(); + $s->addPlugin($p); + $s->addPlugin(new Plugin()); + + $h = HTTP\Sapi::createFromServerArray([ + 'REQUEST_URI' => '/UUID-123467?export&componentType=VEVENT', + 'REQUEST_METHOD' => 'GET', + ]); + + $s->httpRequest = $h; + $s->httpResponse = new HTTP\ResponseMock(); + + $s->exec(); + + $this->assertEquals(200, $s->httpResponse->status,'Invalid status received. Response body: '. $s->httpResponse->body); + $obj = VObject\Reader::read($s->httpResponse->body); + + $this->assertEquals(1,count($obj->VTIMEZONE)); + $this->assertEquals(1,count($obj->VEVENT)); + $this->assertEquals(0,count($obj->VTODO)); + + } + + function testFilterComponentVTODO() { + + $cbackend = TestUtil::getBackend(); + $pbackend = new DAVACL\PrincipalBackend\Mock(); + + $props = [ + 'uri'=>'UUID-123467', + 'principaluri' => 'admin', + 'id' => 1, + ]; + // add a todo to the calendar (see /tests/Sabre/TestUtil) + $cbackend->createCalendarObject(1, 'UUID-3456', TestUtil::getTestTODO()); + + $tree = [ + new Calendar($cbackend,$props), + new DAVACL\PrincipalCollection($pbackend), + ]; + + $p = new ICSExportPlugin(); + + $s = new DAV\Server($tree); + $s->sapi = new HTTP\SapiMock(); + $s->addPlugin($p); + $s->addPlugin(new Plugin()); + + $h = HTTP\Sapi::createFromServerArray([ + 'REQUEST_URI' => '/UUID-123467?export&componentType=VTODO', + 'REQUEST_METHOD' => 'GET', + ]); + + $s->httpRequest = $h; + $s->httpResponse = new HTTP\ResponseMock(); + + $s->exec(); + + $this->assertEquals(200, $s->httpResponse->status,'Invalid status received. Response body: '. $s->httpResponse->body); + $obj = VObject\Reader::read($s->httpResponse->body); + + $this->assertEquals(0,count($obj->VTIMEZONE)); + $this->assertEquals(0,count($obj->VEVENT)); + $this->assertEquals(1,count($obj->VTODO)); + + } + + function testFilterComponentBadComponent() { + + $cbackend = TestUtil::getBackend(); + $pbackend = new DAVACL\PrincipalBackend\Mock(); + + $props = [ + 'uri'=>'UUID-123467', + 'principaluri' => 'admin', + 'id' => 1, + ]; + // add a todo to the calendar (see /tests/Sabre/TestUtil) + $cbackend->createCalendarObject(1, 'UUID-3456', TestUtil::getTestTODO()); + + $tree = [ + new Calendar($cbackend,$props), + new DAVACL\PrincipalCollection($pbackend), + ]; + + $p = new ICSExportPlugin(); + + $s = new DAV\Server($tree); + $s->sapi = new HTTP\SapiMock(); + $s->addPlugin($p); + $s->addPlugin(new Plugin()); + + $h = HTTP\Sapi::createFromServerArray([ + 'REQUEST_URI' => '/UUID-123467?export&componentType=VVOODOO', + 'REQUEST_METHOD' => 'GET', + ]); + + $s->httpRequest = $h; + $s->httpResponse = new HTTP\ResponseMock(); + + $s->exec(); + + $this->assertEquals(400, $s->httpResponse->status,'Invalid status received. Response body: '. $s->httpResponse->body); + + } } diff --git a/vendor/sabre/dav/tests/Sabre/CalDAV/Issue203Test.php b/vendor/sabre/dav/tests/Sabre/CalDAV/Issue203Test.php index 21ee2f550..369e9a70c 100644 --- a/vendor/sabre/dav/tests/Sabre/CalDAV/Issue203Test.php +++ b/vendor/sabre/dav/tests/Sabre/CalDAV/Issue203Test.php @@ -1,14 +1,14 @@ 1, - 'name' => 'Calendar', + protected $caldavCalendars = [ + [ + 'id' => 1, + 'name' => 'Calendar', 'principaluri' => 'principals/user1', - 'uri' => 'calendar1', - ) - ); + 'uri' => 'calendar1', + ] + ]; - protected $caldavCalendarObjects = array( - 1 => array( - 'event.ics' => array( + protected $caldavCalendarObjects = [ + 1 => [ + 'event.ics' => [ 'calendardata' => 'BEGIN:VCALENDAR VERSION:2.0 BEGIN:VEVENT @@ -52,18 +52,18 @@ TRANSP:OPAQUE END:VEVENT END:VCALENDAR ', - ), - ), - ); + ], + ], + ]; function testIssue203() { - $request = new HTTP\Request(array( - 'REQUEST_METHOD' => 'REPORT', + $request = HTTP\Sapi::createFromServerArray([ + 'REQUEST_METHOD' => 'REPORT', 'HTTP_CONTENT_TYPE' => 'application/xml', - 'REQUEST_URI' => '/calendars/user1/calendar1', - 'HTTP_DEPTH' => '1', - )); + 'REQUEST_URI' => '/calendars/user1/calendar1', + 'HTTP_DEPTH' => '1', + ]); $request->setBody(' @@ -90,26 +90,26 @@ END:VCALENDAR $start = strpos($response->body, 'BEGIN:VCALENDAR'), strpos($response->body, 'END:VCALENDAR') - $start + 13 ); - $body = str_replace(' ','',$body); + $body = str_replace(' ', '', $body); $vObject = VObject\Reader::read($body); $this->assertEquals(2, count($vObject->VEVENT)); - $expectedEvents = array( - array( + $expectedEvents = [ + [ 'DTSTART' => '20120326T135200Z', 'DTEND' => '20120326T145200Z', 'SUMMARY' => 'original summary', - ), - array( + ], + [ 'DTSTART' => '20120328T135200Z', 'DTEND' => '20120328T145200Z', 'SUMMARY' => 'overwritten summary', 'RECURRENCE-ID' => '20120327T135200Z', - ) - ); + ] + ]; // try to match agains $expectedEvents array foreach ($expectedEvents as $expectedEvent) { @@ -118,10 +118,8 @@ END:VCALENDAR foreach ($vObject->VEVENT as $vevent) { /** @var $vevent Sabre\VObject\Component\VEvent */ - - foreach ($vevent->children as $child) { + foreach ($vevent->children() as $child) { /** @var $child Sabre\VObject\Property */ - if (isset($expectedEvent[$child->name])) { if ($expectedEvent[$child->name] != $child->getValue()) { continue 2; @@ -133,7 +131,7 @@ END:VCALENDAR break; } - $this->assertTrue($matching, 'Did not find the following event in the response: '.var_export($expectedEvent, true)); + $this->assertTrue($matching, 'Did not find the following event in the response: ' . var_export($expectedEvent, true)); } } } diff --git a/vendor/sabre/dav/tests/Sabre/CalDAV/Issue205Test.php b/vendor/sabre/dav/tests/Sabre/CalDAV/Issue205Test.php index cd6820b57..4a53fcbe2 100644 --- a/vendor/sabre/dav/tests/Sabre/CalDAV/Issue205Test.php +++ b/vendor/sabre/dav/tests/Sabre/CalDAV/Issue205Test.php @@ -7,7 +7,7 @@ use Sabre\VObject; /** * This unittest is created to check if a VALARM TRIGGER of PT0S is supported * - * @copyright Copyright (C) 2007-2014 fruux GmbH (https://fruux.com/). + * @copyright Copyright (C) fruux GmbH (https://fruux.com/) * @author Evert Pot (http://evertpot.com/) * @license http://sabre.io/license/ Modified BSD License */ @@ -50,7 +50,7 @@ END:VCALENDAR function testIssue205() { - $request = new HTTP\Request(array( + $request = HTTP\Sapi::createFromServerArray(array( 'REQUEST_METHOD' => 'REPORT', 'HTTP_CONTENT_TYPE' => 'application/xml', 'REQUEST_URI' => '/calendars/user1/calendar1', diff --git a/vendor/sabre/dav/tests/Sabre/CalDAV/Issue211Test.php b/vendor/sabre/dav/tests/Sabre/CalDAV/Issue211Test.php index cc700e50d..f291e5e57 100644 --- a/vendor/sabre/dav/tests/Sabre/CalDAV/Issue211Test.php +++ b/vendor/sabre/dav/tests/Sabre/CalDAV/Issue211Test.php @@ -7,7 +7,7 @@ use Sabre\VObject; /** * This unittest is created to check for an endless loop in Sabre\CalDAV\CalendarQueryValidator * - * @copyright Copyright (C) 2007-2014 fruux GmbH (https://fruux.com/). + * @copyright Copyright (C) fruux GmbH (https://fruux.com/) * @author Evert Pot (http://evertpot.com/) * @license http://sabre.io/license/ Modified BSD License */ @@ -55,7 +55,7 @@ END:VCALENDAR function testIssue211() { - $request = new HTTP\Request(array( + $request = HTTP\Sapi::createFromServerArray(array( 'REQUEST_METHOD' => 'REPORT', 'HTTP_CONTENT_TYPE' => 'application/xml', 'REQUEST_URI' => '/calendars/user1/calendar1', diff --git a/vendor/sabre/dav/tests/Sabre/CalDAV/Issue220Test.php b/vendor/sabre/dav/tests/Sabre/CalDAV/Issue220Test.php index ce66b6a5f..7b5dbfe63 100644 --- a/vendor/sabre/dav/tests/Sabre/CalDAV/Issue220Test.php +++ b/vendor/sabre/dav/tests/Sabre/CalDAV/Issue220Test.php @@ -7,7 +7,7 @@ use Sabre\HTTP; /** * This unittest is created to check for an endless loop in CalendarQueryValidator * - * @copyright Copyright (C) 2007-2014 fruux GmbH (https://fruux.com/). + * @copyright Copyright (C) fruux GmbH (https://fruux.com/) * @author Evert Pot (http://evertpot.com/) * @license http://sabre.io/license/ Modified BSD License */ @@ -65,7 +65,7 @@ END:VCALENDAR function testIssue220() { - $request = new HTTP\Request(array( + $request = HTTP\Sapi::createFromServerArray(array( 'REQUEST_METHOD' => 'REPORT', 'HTTP_CONTENT_TYPE' => 'application/xml', 'REQUEST_URI' => '/calendars/user1/calendar1', @@ -94,6 +94,6 @@ END:VCALENDAR $this->assertFalse(strpos($response->body, 'PHPUnit_Framework_Error_Warning'), 'Error Warning occurred: ' . $response->body); $this->assertFalse(strpos($response->body, 'Invalid argument supplied for foreach()'), 'Invalid argument supplied for foreach(): ' . $response->body); - $this->assertEquals('HTTP/1.1 207 Multi-Status', $response->status); + $this->assertEquals(207, $response->status); } } diff --git a/vendor/sabre/dav/tests/Sabre/CalDAV/Issue228Test.php b/vendor/sabre/dav/tests/Sabre/CalDAV/Issue228Test.php index 23371a054..ccc6b303a 100644 --- a/vendor/sabre/dav/tests/Sabre/CalDAV/Issue228Test.php +++ b/vendor/sabre/dav/tests/Sabre/CalDAV/Issue228Test.php @@ -6,7 +6,7 @@ use Sabre\HTTP; /** * This unittest is created to check if the time-range filter is working correctly with all-day-events * - * @copyright Copyright (C) 2007-2014 fruux GmbH (https://fruux.com/). + * @copyright Copyright (C) fruux GmbH (https://fruux.com/) * @author Evert Pot (http://evertpot.com/) * @license http://sabre.io/license/ Modified BSD License */ @@ -44,7 +44,7 @@ END:VCALENDAR function testIssue228() { - $request = new HTTP\Request(array( + $request = HTTP\Sapi::createFromServerArray(array( 'REQUEST_METHOD' => 'REPORT', 'HTTP_CONTENT_TYPE' => 'application/xml', 'REQUEST_URI' => '/calendars/user1/calendar1', diff --git a/vendor/sabre/dav/tests/Sabre/CalDAV/Notifications/CollectionTest.php b/vendor/sabre/dav/tests/Sabre/CalDAV/Notifications/CollectionTest.php index eaed4f503..68035184f 100644 --- a/vendor/sabre/dav/tests/Sabre/CalDAV/Notifications/CollectionTest.php +++ b/vendor/sabre/dav/tests/Sabre/CalDAV/Notifications/CollectionTest.php @@ -14,9 +14,9 @@ class CollectionTest extends \PHPUnit_Framework_TestCase { $this->principalUri = 'principals/user1'; - $this->notification = new Notification\SystemStatus(1,'"1"'); + $this->notification = new CalDAV\Xml\Notification\SystemStatus(1,'"1"'); - $this->caldavBackend = new CalDAV\Backend\Mock(array(),array(), array( + $this->caldavBackend = new CalDAV\Backend\MockSharing(array(),array(), array( 'principals/user1' => array( $this->notification ) diff --git a/vendor/sabre/dav/tests/Sabre/CalDAV/Notifications/NodeTest.php b/vendor/sabre/dav/tests/Sabre/CalDAV/Notifications/NodeTest.php index 28e43ce08..d546116fc 100644 --- a/vendor/sabre/dav/tests/Sabre/CalDAV/Notifications/NodeTest.php +++ b/vendor/sabre/dav/tests/Sabre/CalDAV/Notifications/NodeTest.php @@ -13,13 +13,13 @@ class NodeTest extends \PHPUnit_Framework_TestCase { $principalUri = 'principals/user1'; - $this->systemStatus = new Notification\SystemStatus(1,'"1"'); + $this->systemStatus = new CalDAV\Xml\Notification\SystemStatus(1,'"1"'); - $this->caldavBackend = new CalDAV\Backend\Mock(array(),array(), array( - 'principals/user1' => array( + $this->caldavBackend = new CalDAV\Backend\MockSharing([], [], [ + 'principals/user1' => [ $this->systemStatus - ) - )); + ] + ]); $node = new Node($this->caldavBackend, 'principals/user1', $this->systemStatus); return $node; diff --git a/vendor/sabre/dav/tests/Sabre/CalDAV/Notifications/Notification/InviteReplyTest.php b/vendor/sabre/dav/tests/Sabre/CalDAV/Notifications/Notification/InviteReplyTest.php deleted file mode 100644 index c53f68cee..000000000 --- a/vendor/sabre/dav/tests/Sabre/CalDAV/Notifications/Notification/InviteReplyTest.php +++ /dev/null @@ -1,134 +0,0 @@ -assertEquals('foo', $notification->getId()); - $this->assertEquals('"1"', $notification->getETag()); - - $simpleExpected = '' . "\n" . '' . "\n"; - - $dom = new \DOMDocument('1.0','UTF-8'); - $elem = $dom->createElement('cs:root'); - $elem->setAttribute('xmlns:cs',CalDAV\Plugin::NS_CALENDARSERVER); - $dom->appendChild($elem); - $notification->serialize(new DAV\Server(), $elem); - $this->assertEquals($simpleExpected, $dom->saveXML()); - - $dom = new \DOMDocument('1.0','UTF-8'); - $dom->formatOutput = true; - $elem = $dom->createElement('cs:root'); - $elem->setAttribute('xmlns:cs',CalDAV\Plugin::NS_CALENDARSERVER); - $elem->setAttribute('xmlns:d','DAV:'); - $dom->appendChild($elem); - $notification->serializeBody(new DAV\Server(), $elem); - $this->assertEquals($expected, $dom->saveXML()); - - - } - - function dataProvider() { - - $dtStamp = new \DateTime('2012-01-01 00:00:00 GMT'); - return array( - array( - array( - 'id' => 'foo', - 'dtStamp' => $dtStamp, - 'etag' => '"1"', - 'inReplyTo' => 'bar', - 'href' => 'mailto:foo@example.org', - 'type' => CalDAV\SharingPlugin::STATUS_ACCEPTED, - 'hostUrl' => 'calendar' - ), -<< - - 20120101T000000Z - - foo - bar - mailto:foo@example.org - - - /calendar - - - - -FOO - ), - array( - array( - 'id' => 'foo', - 'dtStamp' => $dtStamp, - 'etag' => '"1"', - 'inReplyTo' => 'bar', - 'href' => 'mailto:foo@example.org', - 'type' => CalDAV\SharingPlugin::STATUS_DECLINED, - 'hostUrl' => 'calendar', - 'summary' => 'Summary!' - ), -<< - - 20120101T000000Z - - foo - bar - mailto:foo@example.org - - - /calendar - - Summary! - - - -FOO - ), - - ); - - } - - /** - * @expectedException InvalidArgumentException - */ - function testMissingArg() { - - new InviteReply(array()); - - } - - /** - * @expectedException InvalidArgumentException - */ - function testUnknownArg() { - - new InviteReply(array( - 'foo-i-will-break' => true, - - 'id' => 1, - 'etag' => '"bla"', - 'href' => 'abc', - 'dtStamp' => 'def', - 'inReplyTo' => 'qrs', - 'type' => 'ghi', - 'hostUrl' => 'jkl', - )); - - } - -} diff --git a/vendor/sabre/dav/tests/Sabre/CalDAV/Notifications/Notification/InviteTest.php b/vendor/sabre/dav/tests/Sabre/CalDAV/Notifications/Notification/InviteTest.php deleted file mode 100644 index d2c114f4c..000000000 --- a/vendor/sabre/dav/tests/Sabre/CalDAV/Notifications/Notification/InviteTest.php +++ /dev/null @@ -1,230 +0,0 @@ -assertEquals('foo', $notification->getId()); - $this->assertEquals('"1"', $notification->getETag()); - - $simpleExpected = '' . "\n" . '' . "\n"; - - $dom = new \DOMDocument('1.0','UTF-8'); - $elem = $dom->createElement('cs:root'); - $elem->setAttribute('xmlns:cs',CalDAV\Plugin::NS_CALENDARSERVER); - $dom->appendChild($elem); - $notification->serialize(new DAV\Server(), $elem); - $this->assertEquals($simpleExpected, $dom->saveXML()); - - $dom = new \DOMDocument('1.0','UTF-8'); - $dom->formatOutput = true; - $elem = $dom->createElement('cs:root'); - $elem->setAttribute('xmlns:cs',CalDAV\Plugin::NS_CALENDARSERVER); - $elem->setAttribute('xmlns:d','DAV:'); - $elem->setAttribute('xmlns:cal',CalDAV\Plugin::NS_CALDAV); - $dom->appendChild($elem); - $notification->serializeBody(new DAV\Server(), $elem); - $this->assertEquals($expected, $dom->saveXML()); - - - } - - function dataProvider() { - - $dtStamp = new \DateTime('2012-01-01 00:00:00', new \DateTimeZone('GMT')); - return array( - array( - array( - 'id' => 'foo', - 'dtStamp' => $dtStamp, - 'etag' => '"1"', - 'href' => 'mailto:foo@example.org', - 'type' => CalDAV\SharingPlugin::STATUS_ACCEPTED, - 'readOnly' => true, - 'hostUrl' => 'calendar', - 'organizer' => 'principal/user1', - 'commonName' => 'John Doe', - 'summary' => 'Awesome stuff!' - ), -<< - - 20120101T000000Z - - foo - mailto:foo@example.org - - - /calendar - - - - - John Doe - - /principal/user1 - John Doe - - Awesome stuff! - - - -FOO - ), - array( - array( - 'id' => 'foo', - 'dtStamp' => $dtStamp, - 'etag' => '"1"', - 'href' => 'mailto:foo@example.org', - 'type' => CalDAV\SharingPlugin::STATUS_DECLINED, - 'readOnly' => true, - 'hostUrl' => 'calendar', - 'organizer' => 'principal/user1', - 'commonName' => 'John Doe', - ), -<< - - 20120101T000000Z - - foo - mailto:foo@example.org - - - /calendar - - - - - John Doe - - /principal/user1 - John Doe - - - - -FOO - ), - array( - array( - 'id' => 'foo', - 'dtStamp' => $dtStamp, - 'etag' => '"1"', - 'href' => 'mailto:foo@example.org', - 'type' => CalDAV\SharingPlugin::STATUS_NORESPONSE, - 'readOnly' => true, - 'hostUrl' => 'calendar', - 'organizer' => 'principal/user1', - 'firstName' => 'Foo', - 'lastName' => 'Bar', - ), -<< - - 20120101T000000Z - - foo - mailto:foo@example.org - - - /calendar - - - - - Foo - Bar - - /principal/user1 - Foo - Bar - - - - -FOO - ), - array( - array( - 'id' => 'foo', - 'dtStamp' => $dtStamp, - 'etag' => '"1"', - 'href' => 'mailto:foo@example.org', - 'type' => CalDAV\SharingPlugin::STATUS_DELETED, - 'readOnly' => false, - 'hostUrl' => 'calendar', - 'organizer' => 'mailto:user1@fruux.com', - 'supportedComponents' => new CalDAV\Property\SupportedCalendarComponentSet(array('VEVENT','VTODO')), - ), -<< - - 20120101T000000Z - - foo - mailto:foo@example.org - - - /calendar - - - - - - mailto:user1@fruux.com - - - - - - - - -FOO - ), - - ); - - } - - /** - * @expectedException InvalidArgumentException - */ - function testMissingArg() { - - new Invite(array()); - - } - - /** - * @expectedException InvalidArgumentException - */ - function testUnknownArg() { - - new Invite(array( - 'foo-i-will-break' => true, - - 'id' => 1, - 'etag' => '"bla"', - 'href' => 'abc', - 'dtStamp' => 'def', - 'type' => 'ghi', - 'readOnly' => true, - 'hostUrl' => 'jkl', - 'organizer' => 'mno', - )); - - } -} diff --git a/vendor/sabre/dav/tests/Sabre/CalDAV/Notifications/Notification/SystemStatusTest.php b/vendor/sabre/dav/tests/Sabre/CalDAV/Notifications/Notification/SystemStatusTest.php deleted file mode 100644 index 8dc494932..000000000 --- a/vendor/sabre/dav/tests/Sabre/CalDAV/Notifications/Notification/SystemStatusTest.php +++ /dev/null @@ -1,61 +0,0 @@ -assertEquals('foo', $notification->getId()); - $this->assertEquals('"1"', $notification->getETag()); - - - $dom = new \DOMDocument('1.0','UTF-8'); - $elem = $dom->createElement('cs:root'); - $elem->setAttribute('xmlns:cs',CalDAV\Plugin::NS_CALENDARSERVER); - $dom->appendChild($elem); - $notification->serialize(new DAV\Server(), $elem); - $this->assertEquals($expected1, $dom->saveXML()); - - $dom = new \DOMDocument('1.0','UTF-8'); - $elem = $dom->createElement('cs:root'); - $elem->setAttribute('xmlns:cs',CalDAV\Plugin::NS_CALENDARSERVER); - $dom->appendChild($elem); - $notification->serializeBody(new DAV\Server(), $elem); - $this->assertEquals($expected2, $dom->saveXML()); - - - } - - function dataProvider() { - - return array( - - array( - new SystemStatus('foo', '"1"'), - '' . "\n" . '' . "\n", - '' . "\n" . '' . "\n", - ), - - array( - new SystemStatus('foo', '"1"', SystemStatus::TYPE_MEDIUM,'bar'), - '' . "\n" . '' . "\n", - '' . "\n" . 'bar' . "\n", - ), - - array( - new SystemStatus('foo', '"1"', SystemStatus::TYPE_LOW,null,'http://example.org/'), - '' . "\n" . '' . "\n", - '' . "\n" . 'http://example.org/' . "\n", - ) - ); - - } - -} diff --git a/vendor/sabre/dav/tests/Sabre/CalDAV/OutboxPostTest.php b/vendor/sabre/dav/tests/Sabre/CalDAV/OutboxPostTest.php deleted file mode 100644 index 5a5a4e75c..000000000 --- a/vendor/sabre/dav/tests/Sabre/CalDAV/OutboxPostTest.php +++ /dev/null @@ -1,545 +0,0 @@ - 'POST', - 'REQUEST_URI' => '/notfound', - 'HTTP_CONTENT_TYPE' => 'text/calendar', - )); - - $this->assertHTTPStatus(501, $req); - - } - - function testPostPassThruNotTextCalendar() { - - $req = new HTTP\Request(array( - 'REQUEST_METHOD' => 'POST', - 'REQUEST_URI' => '/calendars/admin/outbox', - )); - - $this->assertHTTPStatus(501, $req); - - } - - function testPostPassThruNoOutBox() { - - $req = new HTTP\Request(array( - 'REQUEST_METHOD' => 'POST', - 'REQUEST_URI' => '/calendars', - 'HTTP_CONTENT_TYPE' => 'text/calendar', - )); - - $this->assertHTTPStatus(501, $req); - - } - - function testNoOriginator() { - - $req = new HTTP\Request(array( - 'REQUEST_METHOD' => 'POST', - 'REQUEST_URI' => '/calendars/admin/outbox', - 'HTTP_CONTENT_TYPE' => 'text/calendar', - )); - $body = array( - 'BEGIN:VCALENDAR', - 'METHOD:REQUEST', - 'BEGIN:VEVENT', - 'END:VEVENT', - 'END:VCALENDAR', - ); - $req->setBody(implode("\r\n",$body)); - - $this->assertHTTPStatus(400, $req); - - } - - function testNoRecipient() { - - $req = new HTTP\Request(array( - 'REQUEST_METHOD' => 'POST', - 'REQUEST_URI' => '/calendars/admin/outbox', - 'HTTP_ORIGINATOR' => 'mailto:orig@example.org', - 'HTTP_CONTENT_TYPE' => 'text/calendar', - )); - $body = array( - 'BEGIN:VCALENDAR', - 'METHOD:REQUEST', - 'BEGIN:VEVENT', - 'END:VEVENT', - 'END:VCALENDAR', - ); - $req->setBody(implode("\r\n",$body)); - - $this->assertHTTPStatus(400, $req); - - } - - function testBadOriginator() { - - $req = new HTTP\Request(array( - 'REQUEST_METHOD' => 'POST', - 'REQUEST_URI' => '/calendars/admin/outbox', - 'HTTP_ORIGINATOR' => 'nomailto:orig@example.org', - 'HTTP_RECIPIENT' => 'mailto:user1@example.org', - 'HTTP_CONTENT_TYPE' => 'text/calendar', - )); - $body = array( - 'BEGIN:VCALENDAR', - 'METHOD:REQUEST', - 'BEGIN:VEVENT', - 'END:VEVENT', - 'END:VCALENDAR', - ); - $req->setBody(implode("\r\n",$body)); - - $this->assertHTTPStatus(403, $req); - - } - - function testBadRecipient() { - - $req = new HTTP\Request(array( - 'REQUEST_METHOD' => 'POST', - 'REQUEST_URI' => '/calendars/admin/outbox', - 'HTTP_ORIGINATOR' => 'mailto:orig@example.org', - 'HTTP_RECIPIENT' => 'http://user1@example.org, mailto:user2@example.org', - 'HTTP_CONTENT_TYPE' => 'text/calendar', - )); - $body = array( - 'BEGIN:VCALENDAR', - 'METHOD:REQUEST', - 'BEGIN:VEVENT', - 'END:VEVENT', - 'END:VCALENDAR', - ); - $req->setBody(implode("\r\n",$body)); - - $this->assertHTTPStatus(400, $req); - - } - - function testIncorrectOriginator() { - - $req = new HTTP\Request(array( - 'REQUEST_METHOD' => 'POST', - 'REQUEST_URI' => '/calendars/admin/outbox', - 'HTTP_ORIGINATOR' => 'mailto:orig@example.org', - 'HTTP_RECIPIENT' => 'mailto:user1@example.org, mailto:user2@example.org', - 'HTTP_CONTENT_TYPE' => 'text/calendar', - )); - $body = array( - 'BEGIN:VCALENDAR', - 'METHOD:REQUEST', - 'BEGIN:VEVENT', - 'END:VEVENT', - 'END:VCALENDAR', - ); - $req->setBody(implode("\r\n",$body)); - - $this->assertHTTPStatus(403, $req); - - } - - function testInvalidIcalBody() { - - $req = new HTTP\Request(array( - 'REQUEST_METHOD' => 'POST', - 'REQUEST_URI' => '/calendars/user1/outbox', - 'HTTP_ORIGINATOR' => 'mailto:user1.sabredav@sabredav.org', - 'HTTP_RECIPIENT' => 'mailto:user2@example.org', - 'HTTP_CONTENT_TYPE' => 'text/calendar', - )); - $req->setBody('foo'); - - $this->assertHTTPStatus(400, $req); - - } - - function testNoVEVENT() { - - $req = new HTTP\Request(array( - 'REQUEST_METHOD' => 'POST', - 'REQUEST_URI' => '/calendars/user1/outbox', - 'HTTP_ORIGINATOR' => 'mailto:user1.sabredav@sabredav.org', - 'HTTP_RECIPIENT' => 'mailto:user2@example.org', - 'HTTP_CONTENT_TYPE' => 'text/calendar', - )); - - $body = array( - 'BEGIN:VCALENDAR', - 'BEGIN:VTIMEZONE', - 'END:VTIMEZONE', - 'END:VCALENDAR', - ); - - $req->setBody(implode("\r\n",$body)); - - $this->assertHTTPStatus(400, $req); - - } - - function testNoMETHOD() { - - $req = new HTTP\Request(array( - 'REQUEST_METHOD' => 'POST', - 'REQUEST_URI' => '/calendars/user1/outbox', - 'HTTP_ORIGINATOR' => 'mailto:user1.sabredav@sabredav.org', - 'HTTP_RECIPIENT' => 'mailto:user2@example.org', - 'HTTP_CONTENT_TYPE' => 'text/calendar', - )); - - $body = array( - 'BEGIN:VCALENDAR', - 'BEGIN:VEVENT', - 'END:VEVENT', - 'END:VCALENDAR', - ); - - $req->setBody(implode("\r\n",$body)); - - $this->assertHTTPStatus(400, $req); - - } - - function testUnsupportedMethod() { - - $req = new HTTP\Request(array( - 'REQUEST_METHOD' => 'POST', - 'REQUEST_URI' => '/calendars/user1/outbox', - 'HTTP_ORIGINATOR' => 'mailto:user1.sabredav@sabredav.org', - 'HTTP_RECIPIENT' => 'mailto:user2@example.org', - 'HTTP_CONTENT_TYPE' => 'text/calendar', - )); - - $body = array( - 'BEGIN:VCALENDAR', - 'METHOD:PUBLISH', - 'BEGIN:VEVENT', - 'END:VEVENT', - 'END:VCALENDAR', - ); - - $req->setBody(implode("\r\n",$body)); - - $this->assertHTTPStatus(501, $req); - - } - - function testNoIMIPHandler() { - - $req = new HTTP\Request(array( - 'REQUEST_METHOD' => 'POST', - 'REQUEST_URI' => '/calendars/user1/outbox', - 'HTTP_ORIGINATOR' => 'mailto:user1.sabredav@sabredav.org', - 'HTTP_RECIPIENT' => 'mailto:user2@example.org', - 'HTTP_CONTENT_TYPE' => 'text/calendar', - )); - - $body = array( - 'BEGIN:VCALENDAR', - 'METHOD:REQUEST', - 'BEGIN:VEVENT', - 'END:VEVENT', - 'END:VCALENDAR', - ); - - $req->setBody(implode("\r\n",$body)); - - - $response = $this->request($req); - $this->assertEquals('HTTP/1.1 200 OK', $response->status); - $this->assertEquals(array( - 'Content-Type' => 'application/xml', - ), $response->headers); - - // Lazily checking the body for a few expected values. - $this->assertTrue(strpos($response->body, '5.2;')!==false); - $this->assertTrue(strpos($response->body,'user2@example.org')!==false); - - - } - - function testSuccessRequest() { - - $req = new HTTP\Request(array( - 'REQUEST_METHOD' => 'POST', - 'REQUEST_URI' => '/calendars/user1/outbox', - 'HTTP_ORIGINATOR' => 'mailto:user1.sabredav@sabredav.org', - 'HTTP_RECIPIENT' => 'mailto:user2@example.org', - 'HTTP_CONTENT_TYPE' => 'text/calendar', - )); - - $body = array( - 'BEGIN:VCALENDAR', - 'METHOD:REQUEST', - 'BEGIN:VEVENT', - 'SUMMARY:An invitation', - 'END:VEVENT', - 'END:VCALENDAR', - ); - - $req->setBody(implode("\r\n",$body)); - - $handler = new Schedule\IMip\Mock('server@example.org'); - - $this->caldavPlugin->setIMIPhandler($handler); - - $response = $this->request($req); - $this->assertEquals('HTTP/1.1 200 OK', $response->status); - $this->assertEquals(array( - 'Content-Type' => 'application/xml', - ), $response->headers); - - // Lazily checking the body for a few expected values. - $this->assertTrue(strpos($response->body, '2.0;')!==false); - $this->assertTrue(strpos($response->body,'user2@example.org')!==false); - - $this->assertEquals(array( - array( - 'to' => 'user2@example.org', - 'subject' => 'Invitation for: An invitation', - 'body' => implode("\r\n", $body) . "\r\n", - 'headers' => array( - 'Reply-To: user1.sabredav@sabredav.org', - 'From: server@example.org', - 'Content-Type: text/calendar; method=REQUEST; charset=utf-8', - 'X-Sabre-Version: ' . DAV\Version::VERSION . '-' . DAV\Version::STABILITY, - ), - ) - ), $handler->getSentEmails()); - - } - - function testSuccessRequestUseRelativePrincipal() { - - $req = new HTTP\Request(array( - 'REQUEST_METHOD' => 'POST', - 'REQUEST_URI' => '/calendars/user1/outbox', - 'HTTP_ORIGINATOR' => '/principals/user1/', - 'HTTP_RECIPIENT' => 'mailto:user2@example.org', - 'HTTP_CONTENT_TYPE' => 'text/calendar', - )); - - $body = array( - 'BEGIN:VCALENDAR', - 'METHOD:REQUEST', - 'BEGIN:VEVENT', - 'SUMMARY:An invitation', - 'ORGANIZER:mailto:user1.sabredav@sabredav.org', - 'END:VEVENT', - 'END:VCALENDAR', - ); - - $req->setBody(implode("\r\n",$body)); - - $handler = new Schedule\IMip\Mock('server@example.org'); - - $this->caldavPlugin->setIMIPhandler($handler); - - $response = $this->request($req); - $this->assertEquals('HTTP/1.1 200 OK', $response->status, 'Full body: ' . $response->body); - $this->assertEquals(array( - 'Content-Type' => 'application/xml', - ), $response->headers); - - // Lazily checking the body for a few expected values. - $this->assertTrue(strpos($response->body, '2.0;')!==false); - $this->assertTrue(strpos($response->body,'user2@example.org')!==false); - - $this->assertEquals(array( - array( - 'to' => 'user2@example.org', - 'subject' => 'Invitation for: An invitation', - 'body' => implode("\r\n", $body) . "\r\n", - 'headers' => array( - 'Reply-To: user1.sabredav@sabredav.org', - 'From: server@example.org', - 'Content-Type: text/calendar; method=REQUEST; charset=utf-8', - 'X-Sabre-Version: ' . DAV\Version::VERSION . '-' . DAV\Version::STABILITY, - ), - ) - ), $handler->getSentEmails()); - - } - - function testSuccessRequestUpperCased() { - - $req = new HTTP\Request(array( - 'REQUEST_METHOD' => 'POST', - 'REQUEST_URI' => '/calendars/user1/outbox', - 'HTTP_ORIGINATOR' => 'MAILTO:user1.sabredav@sabredav.org', - 'HTTP_RECIPIENT' => 'MAILTO:user2@example.org', - 'HTTP_CONTENT_TYPE' => 'text/calendar', - )); - - $body = array( - 'BEGIN:VCALENDAR', - 'METHOD:REQUEST', - 'BEGIN:VEVENT', - 'SUMMARY:An invitation', - 'END:VEVENT', - 'END:VCALENDAR', - ); - - $req->setBody(implode("\r\n",$body)); - - $handler = new Schedule\IMip\Mock('server@example.org'); - - $this->caldavPlugin->setIMIPhandler($handler); - - $response = $this->request($req); - $this->assertEquals('HTTP/1.1 200 OK', $response->status); - $this->assertEquals(array( - 'Content-Type' => 'application/xml', - ), $response->headers); - - // Lazily checking the body for a few expected values. - $this->assertTrue(strpos($response->body, '2.0;')!==false); - $this->assertTrue(strpos($response->body,'user2@example.org')!==false); - - $this->assertEquals(array( - array( - 'to' => 'user2@example.org', - 'subject' => 'Invitation for: An invitation', - 'body' => implode("\r\n", $body) . "\r\n", - 'headers' => array( - 'Reply-To: user1.sabredav@sabredav.org', - 'From: server@example.org', - 'Content-Type: text/calendar; method=REQUEST; charset=utf-8', - 'X-Sabre-Version: ' . DAV\Version::VERSION . '-' . DAV\Version::STABILITY, - ), - ) - ), $handler->getSentEmails()); - - } - - function testSuccessReply() { - - $req = new HTTP\Request(array( - 'REQUEST_METHOD' => 'POST', - 'REQUEST_URI' => '/calendars/user1/outbox', - 'HTTP_ORIGINATOR' => 'mailto:user1.sabredav@sabredav.org', - 'HTTP_RECIPIENT' => 'mailto:user2@example.org', - 'HTTP_CONTENT_TYPE' => 'text/calendar', - )); - - $body = array( - 'BEGIN:VCALENDAR', - 'METHOD:REPLY', - 'BEGIN:VEVENT', - 'SUMMARY:An invitation', - 'END:VEVENT', - 'END:VCALENDAR', - ); - - $req->setBody(implode("\r\n",$body)); - - $handler = new Schedule\IMip\Mock('server@example.org'); - - $this->caldavPlugin->setIMIPhandler($handler); - $this->assertHTTPStatus(200, $req); - - $this->assertEquals(array( - array( - 'to' => 'user2@example.org', - 'subject' => 'Response for: An invitation', - 'body' => implode("\r\n", $body) . "\r\n", - 'headers' => array( - 'Reply-To: user1.sabredav@sabredav.org', - 'From: server@example.org', - 'Content-Type: text/calendar; method=REPLY; charset=utf-8', - 'X-Sabre-Version: ' . DAV\Version::VERSION . '-' . DAV\Version::STABILITY, - ), - ) - ), $handler->getSentEmails()); - - } - - function testSuccessCancel() { - - $req = new HTTP\Request(array( - 'REQUEST_METHOD' => 'POST', - 'REQUEST_URI' => '/calendars/user1/outbox', - 'HTTP_ORIGINATOR' => 'mailto:user1.sabredav@sabredav.org', - 'HTTP_RECIPIENT' => 'mailto:user2@example.org', - 'HTTP_CONTENT_TYPE' => 'text/calendar', - )); - - $body = array( - 'BEGIN:VCALENDAR', - 'METHOD:CANCEL', - 'BEGIN:VEVENT', - 'SUMMARY:An invitation', - 'END:VEVENT', - 'END:VCALENDAR', - ); - - $req->setBody(implode("\r\n",$body)); - - $handler = new Schedule\IMip\Mock('server@example.org'); - - $this->caldavPlugin->setIMIPhandler($handler); - $this->assertHTTPStatus(200, $req); - - $this->assertEquals(array( - array( - 'to' => 'user2@example.org', - 'subject' => 'Cancelled event: An invitation', - 'body' => implode("\r\n", $body) . "\r\n", - 'headers' => array( - 'Reply-To: user1.sabredav@sabredav.org', - 'From: server@example.org', - 'Content-Type: text/calendar; method=CANCEL; charset=utf-8', - 'X-Sabre-Version: ' . DAV\Version::VERSION . '-' . DAV\Version::STABILITY, - ), - ) - ), $handler->getSentEmails()); - - - } - - function testUseRelativePrincipalNoFallback() { - - $req = new HTTP\Request(array( - 'REQUEST_METHOD' => 'POST', - 'REQUEST_URI' => '/calendars/user1/outbox', - 'HTTP_ORIGINATOR' => '/principals/user1/', - 'HTTP_RECIPIENT' => 'mailto:user2@example.org', - 'HTTP_CONTENT_TYPE' => 'text/calendar', - )); - - $body = array( - 'BEGIN:VCALENDAR', - 'METHOD:REQUEST', - 'BEGIN:VEVENT', - 'SUMMARY:An invitation', - 'ORGANIZER:rrrrrr', - 'END:VEVENT', - 'END:VCALENDAR', - ); - - $req->setBody(implode("\r\n",$body)); - - $handler = new Schedule\IMip\Mock('server@example.org'); - - $this->caldavPlugin->setIMIPhandler($handler); - - $response = $this->request($req); - $this->assertEquals('HTTP/1.1 403 Forbidden', $response->status, 'Full body: ' . $response->body); - - } -} diff --git a/vendor/sabre/dav/tests/Sabre/CalDAV/PluginTest.php b/vendor/sabre/dav/tests/Sabre/CalDAV/PluginTest.php index fb7dc316a..138012ffa 100644 --- a/vendor/sabre/dav/tests/Sabre/CalDAV/PluginTest.php +++ b/vendor/sabre/dav/tests/Sabre/CalDAV/PluginTest.php @@ -1,78 +1,80 @@ caldavBackend = new Backend\Mock(array( - array( - 'id' => 1, - 'uri' => 'UUID-123467', - 'principaluri' => 'principals/user1', - '{DAV:}displayname' => 'user1 calendar', - '{urn:ietf:params:xml:ns:caldav}calendar-description' => 'Calendar description', - '{http://apple.com/ns/ical/}calendar-order' => '1', - '{http://apple.com/ns/ical/}calendar-color' => '#FF0000', - '{urn:ietf:params:xml:ns:caldav}supported-calendar-component-set' => new Property\SupportedCalendarComponentSet(array('VEVENT','VTODO')), - ), - array( - 'id' => 2, - 'uri' => 'UUID-123468', - 'principaluri' => 'principals/user1', - '{DAV:}displayname' => 'user1 calendar2', - '{urn:ietf:params:xml:ns:caldav}calendar-description' => 'Calendar description', - '{http://apple.com/ns/ical/}calendar-order' => '1', - '{http://apple.com/ns/ical/}calendar-color' => '#FF0000', - '{urn:ietf:params:xml:ns:caldav}supported-calendar-component-set' => new Property\SupportedCalendarComponentSet(array('VEVENT','VTODO')), - ) - ), array( - 1 => array( - 'UUID-2345' => array( + $caldavNS = '{urn:ietf:params:xml:ns:caldav}'; + + $this->caldavBackend = new Backend\Mock([ + [ + 'id' => 1, + 'uri' => 'UUID-123467', + 'principaluri' => 'principals/user1', + '{DAV:}displayname' => 'user1 calendar', + $caldavNS . 'calendar-description' => 'Calendar description', + '{http://apple.com/ns/ical/}calendar-order' => '1', + '{http://apple.com/ns/ical/}calendar-color' => '#FF0000', + $caldavNS . 'supported-calendar-component-set' => new Xml\Property\SupportedCalendarComponentSet(['VEVENT', 'VTODO']), + ], + [ + 'id' => 2, + 'uri' => 'UUID-123468', + 'principaluri' => 'principals/user1', + '{DAV:}displayname' => 'user1 calendar2', + $caldavNS . 'calendar-description' => 'Calendar description', + '{http://apple.com/ns/ical/}calendar-order' => '1', + '{http://apple.com/ns/ical/}calendar-color' => '#FF0000', + $caldavNS . 'supported-calendar-component-set' => new Xml\Property\SupportedCalendarComponentSet(['VEVENT', 'VTODO']), + ] + ], [ + 1 => [ + 'UUID-2345' => [ 'calendardata' => TestUtil::getTestCalendarData(), - ) - ) - )); + ] + ] + ]); $principalBackend = new DAVACL\PrincipalBackend\Mock(); - $principalBackend->setGroupMemberSet('principals/admin/calendar-proxy-read',array('principals/user1')); - $principalBackend->setGroupMemberSet('principals/admin/calendar-proxy-write',array('principals/user1')); - $principalBackend->addPrincipal(array( + $principalBackend->setGroupMemberSet('principals/admin/calendar-proxy-read', ['principals/user1']); + $principalBackend->setGroupMemberSet('principals/admin/calendar-proxy-write', ['principals/user1']); + $principalBackend->addPrincipal([ 'uri' => 'principals/admin/calendar-proxy-read', - )); - $principalBackend->addPrincipal(array( + ]); + $principalBackend->addPrincipal([ 'uri' => 'principals/admin/calendar-proxy-write', - )); + ]); - $calendars = new CalendarRootNode($principalBackend,$this->caldavBackend); + $calendars = new CalendarRoot($principalBackend, $this->caldavBackend); $principals = new Principal\Collection($principalBackend); $root = new DAV\SimpleCollection('root'); $root->addChild($calendars); $root->addChild($principals); - $objectTree = new DAV\ObjectTree($root); - $this->server = new DAV\Server($objectTree); + $this->server = new DAV\Server($root); + $this->server->sapi = new HTTP\SapiMock(); $this->server->debugExceptions = true; $this->server->setBaseUri('/'); $this->plugin = new Plugin(); @@ -83,11 +85,13 @@ class PluginTest extends \PHPUnit_Framework_TestCase { // Adding Auth plugin, and ensuring that we are logged in. $authBackend = new DAV\Auth\Backend\Mock(); - $authBackend->defaultUser = 'user1'; + $authBackend->setPrincipal('principals/user1'); $authPlugin = new DAV\Auth\Plugin($authBackend, 'SabreDAV'); + $authPlugin->beforeMethod(new \Sabre\HTTP\Request(), new \Sabre\HTTP\Response()); $this->server->addPlugin($authPlugin); - $authPlugin->beforeMethod('GET', '/'); + // This forces a login + $authPlugin->beforeMethod(new HTTP\Request(), new HTTP\Response()); $this->response = new HTTP\ResponseMock(); $this->server->httpResponse = $this->response; @@ -96,48 +100,41 @@ class PluginTest extends \PHPUnit_Framework_TestCase { function testSimple() { - $this->assertEquals(array('MKCALENDAR'), $this->plugin->getHTTPMethods('calendars/user1/randomnewcalendar')); - $this->assertEquals(array('calendar-access','calendar-proxy'), $this->plugin->getFeatures()); - $this->assertArrayHasKey('urn:ietf:params:xml:ns:caldav', $this->server->xmlNamespaces); + $this->assertEquals(['MKCALENDAR'], $this->plugin->getHTTPMethods('calendars/user1/randomnewcalendar')); + $this->assertEquals(['calendar-access', 'calendar-proxy'], $this->plugin->getFeatures()); + $this->assertEquals( + 'caldav', + $this->plugin->getPluginInfo()['name'] + ); } function testUnknownMethodPassThrough() { - $request = new HTTP\Request(array( - 'REQUEST_METHOD' => 'MKBREAKFAST', - 'REQUEST_URI' => '/', - )); + $request = new HTTP\Request('MKBREAKFAST', '/'); $this->server->httpRequest = $request; $this->server->exec(); - $this->assertEquals('HTTP/1.1 501 Not Implemented', $this->response->status,'Incorrect status returned. Full response body:' . $this->response->body); + $this->assertEquals(501, $this->response->status, 'Incorrect status returned. Full response body:' . $this->response->body); } function testReportPassThrough() { - $request = new HTTP\Request(array( - 'REQUEST_METHOD' => 'REPORT', - 'HTTP_CONTENT_TYPE' => 'application/xml', - 'REQUEST_URI' => '/', - )); + $request = new HTTP\Request('REPORT', '/', ['Content-Type' => 'application/xml']); $request->setBody(''); $this->server->httpRequest = $request; $this->server->exec(); - $this->assertEquals('HTTP/1.1 403 Forbidden', $this->response->status); + $this->assertEquals(415, $this->response->status); } function testMkCalendarBadLocation() { - $request = new HTTP\Request(array( - 'REQUEST_METHOD' => 'MKCALENDAR', - 'REQUEST_URI' => '/blabla', - )); + $request = new HTTP\Request('MKCALENDAR', '/blabla'); $body = ' server->httpRequest = $request; $this->server->exec(); - $this->assertEquals('HTTP/1.1 403 Forbidden', $this->response->status); + $this->assertEquals(403, $this->response->status); } function testMkCalendarNoParentNode() { - $request = new HTTP\Request(array( - 'REQUEST_METHOD' => 'MKCALENDAR', - 'REQUEST_URI' => '/doesntexist/calendar', - )); + $request = new HTTP\Request('MKCALENDAR', '/doesntexist/calendar'); $body = ' server->httpRequest = $request; $this->server->exec(); - $this->assertEquals('HTTP/1.1 409 Conflict', $this->response->status); + $this->assertEquals(409, $this->response->status); } function testMkCalendarExistingCalendar() { - $request = new HTTP\Request(array( + $request = HTTP\Sapi::createFromServerArray([ 'REQUEST_METHOD' => 'MKCALENDAR', 'REQUEST_URI' => '/calendars/user1/UUID-123467', - )); + ]); $body = ' server->httpRequest = $request; $this->server->exec(); - $this->assertEquals('HTTP/1.1 405 Method Not Allowed', $this->response->status); + $this->assertEquals(405, $this->response->status); } function testMkCalendarSucceed() { - $request = new HTTP\Request(array( - 'REQUEST_METHOD' => 'MKCALENDAR', - 'REQUEST_URI' => '/calendars/user1/NEWCALENDAR', - )); + $request = new HTTP\Request('MKCALENDAR', '/calendars/user1/NEWCALENDAR'); $timezone = 'BEGIN:VCALENDAR PRODID:-//Example Corp.//CalDAV Client//EN @@ -341,31 +332,31 @@ END:VCALENDAR'; $this->server->httpRequest = $request; $this->server->exec(); - $this->assertEquals('HTTP/1.1 201 Created', $this->response->status,'Invalid response code received. Full response body: ' .$this->response->body); + $this->assertEquals(201, $this->response->status, 'Invalid response code received. Full response body: ' . $this->response->body); $calendars = $this->caldavBackend->getCalendarsForUser('principals/user1'); $this->assertEquals(3, count($calendars)); $newCalendar = null; - foreach($calendars as $calendar) { + foreach ($calendars as $calendar) { if ($calendar['uri'] === 'NEWCALENDAR') { $newCalendar = $calendar; break; } } - $this->assertInternalType('array',$newCalendar); + $this->assertInternalType('array', $newCalendar); - $keys = array( - 'uri' => 'NEWCALENDAR', - 'id' => null, - '{urn:ietf:params:xml:ns:caldav}calendar-description' => 'Calendar restricted to events.', - '{urn:ietf:params:xml:ns:caldav}calendar-timezone' => $timezone, - '{DAV:}displayname' => 'Lisa\'s Events', + $keys = [ + 'uri' => 'NEWCALENDAR', + 'id' => null, + '{urn:ietf:params:xml:ns:caldav}calendar-description' => 'Calendar restricted to events.', + '{urn:ietf:params:xml:ns:caldav}calendar-timezone' => $timezone, + '{DAV:}displayname' => 'Lisa\'s Events', '{urn:ietf:params:xml:ns:caldav}supported-calendar-component-set' => null, - ); + ]; - foreach($keys as $key=>$value) { + foreach ($keys as $key => $value) { $this->assertArrayHasKey($key, $newCalendar); @@ -374,44 +365,41 @@ END:VCALENDAR'; } $sccs = '{urn:ietf:params:xml:ns:caldav}supported-calendar-component-set'; - $this->assertTrue($newCalendar[$sccs] instanceof Property\SupportedCalendarComponentSet); - $this->assertEquals(array('VEVENT'),$newCalendar[$sccs]->getValue()); + $this->assertTrue($newCalendar[$sccs] instanceof Xml\Property\SupportedCalendarComponentSet); + $this->assertEquals(['VEVENT'], $newCalendar[$sccs]->getValue()); } function testMkCalendarEmptyBodySucceed() { - $request = new HTTP\Request(array( - 'REQUEST_METHOD' => 'MKCALENDAR', - 'REQUEST_URI' => '/calendars/user1/NEWCALENDAR', - )); + $request = new HTTP\Request('MKCALENDAR', '/calendars/user1/NEWCALENDAR'); $request->setBody(''); $this->server->httpRequest = $request; $this->server->exec(); - $this->assertEquals('HTTP/1.1 201 Created', $this->response->status,'Invalid response code received. Full response body: ' .$this->response->body); + $this->assertEquals(201, $this->response->status, 'Invalid response code received. Full response body: ' . $this->response->body); $calendars = $this->caldavBackend->getCalendarsForUser('principals/user1'); $this->assertEquals(3, count($calendars)); $newCalendar = null; - foreach($calendars as $calendar) { + foreach ($calendars as $calendar) { if ($calendar['uri'] === 'NEWCALENDAR') { $newCalendar = $calendar; break; } } - $this->assertInternalType('array',$newCalendar); + $this->assertInternalType('array', $newCalendar); - $keys = array( - 'uri' => 'NEWCALENDAR', - 'id' => null, + $keys = [ + 'uri' => 'NEWCALENDAR', + 'id' => null, '{urn:ietf:params:xml:ns:caldav}supported-calendar-component-set' => null, - ); + ]; - foreach($keys as $key=>$value) { + foreach ($keys as $key => $value) { $this->assertArrayHasKey($key, $newCalendar); @@ -420,84 +408,82 @@ END:VCALENDAR'; } $sccs = '{urn:ietf:params:xml:ns:caldav}supported-calendar-component-set'; - $this->assertTrue($newCalendar[$sccs] instanceof Property\SupportedCalendarComponentSet); - $this->assertEquals(array('VEVENT','VTODO'),$newCalendar[$sccs]->getValue()); + $this->assertTrue($newCalendar[$sccs] instanceof Xml\Property\SupportedCalendarComponentSet); + $this->assertEquals(['VEVENT', 'VTODO'], $newCalendar[$sccs]->getValue()); + + } + + function testMkCalendarBadXml() { + + $request = new HTTP\Request('MKCALENDAR', '/blabla'); + $body = 'This is not xml'; + + $request->setBody($body); + $this->server->httpRequest = $request; + $this->server->exec(); + + $this->assertEquals(400, $this->response->status); } function testPrincipalProperties() { - $httpRequest = new HTTP\Request(array( - 'HTTP_HOST' => 'sabredav.org', - )); + $httpRequest = new HTTP\Request('FOO', '/blabla', ['Host' => 'sabredav.org']); $this->server->httpRequest = $httpRequest; - $props = $this->server->getPropertiesForPath('/principals/user1',array( - '{urn:ietf:params:xml:ns:caldav}calendar-home-set', - '{urn:ietf:params:xml:ns:caldav}schedule-outbox-URL', - '{urn:ietf:params:xml:ns:caldav}calendar-user-address-set', + $props = $this->server->getPropertiesForPath('/principals/user1', [ + '{' . Plugin::NS_CALDAV . '}calendar-home-set', '{' . Plugin::NS_CALENDARSERVER . '}calendar-proxy-read-for', '{' . Plugin::NS_CALENDARSERVER . '}calendar-proxy-write-for', '{' . Plugin::NS_CALENDARSERVER . '}notification-URL', - )); + '{' . Plugin::NS_CALENDARSERVER . '}email-address-set', + ]); - $this->assertArrayHasKey(0,$props); - $this->assertArrayHasKey(200,$props[0]); + $this->assertArrayHasKey(0, $props); + $this->assertArrayHasKey(200, $props[0]); - $this->assertArrayHasKey('{urn:ietf:params:xml:ns:caldav}calendar-home-set',$props[0][200]); + $this->assertArrayHasKey('{urn:ietf:params:xml:ns:caldav}calendar-home-set', $props[0][200]); $prop = $props[0][200]['{urn:ietf:params:xml:ns:caldav}calendar-home-set']; - $this->assertTrue($prop instanceof DAV\Property\Href); - $this->assertEquals('calendars/user1/',$prop->getHref()); - - $this->assertArrayHasKey('{urn:ietf:params:xml:ns:caldav}schedule-outbox-URL',$props[0][200]); - $prop = $props[0][200]['{urn:ietf:params:xml:ns:caldav}schedule-outbox-URL']; - $this->assertTrue($prop instanceof DAV\Property\Href); - $this->assertEquals('calendars/user1/outbox',$prop->getHref()); - - $this->assertArrayHasKey('{'.Plugin::NS_CALENDARSERVER .'}notification-URL',$props[0][200]); - $prop = $props[0][200]['{'.Plugin::NS_CALENDARSERVER .'}notification-URL']; - $this->assertTrue($prop instanceof DAV\Property\Href); - $this->assertEquals('calendars/user1/notifications/',$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@sabredav.org','/principals/user1/'),$prop->getHrefs()); + $this->assertInstanceOf('Sabre\\DAV\\Xml\\Property\\Href', $prop); + $this->assertEquals('calendars/user1/', $prop->getHref()); $this->assertArrayHasKey('{http://calendarserver.org/ns/}calendar-proxy-read-for', $props[0][200]); $prop = $props[0][200]['{http://calendarserver.org/ns/}calendar-proxy-read-for']; - $this->assertInstanceOf('Sabre\\DAV\\Property\\HrefList', $prop); - $this->assertEquals(array('principals/admin'), $prop->getHrefs()); + $this->assertInstanceOf('Sabre\\DAV\\Xml\\Property\\Href', $prop); + $this->assertEquals(['principals/admin/'], $prop->getHrefs()); $this->assertArrayHasKey('{http://calendarserver.org/ns/}calendar-proxy-write-for', $props[0][200]); $prop = $props[0][200]['{http://calendarserver.org/ns/}calendar-proxy-write-for']; - $this->assertInstanceOf('Sabre\\DAV\\Property\\HrefList', $prop); - $this->assertEquals(array('principals/admin'), $prop->getHrefs()); + $this->assertInstanceOf('Sabre\\DAV\\Xml\\Property\\Href', $prop); + $this->assertEquals(['principals/admin/'], $prop->getHrefs()); + $this->assertArrayHasKey('{' . Plugin::NS_CALENDARSERVER . '}email-address-set', $props[0][200]); + $prop = $props[0][200]['{' . Plugin::NS_CALENDARSERVER . '}email-address-set']; + $this->assertInstanceOf('Sabre\\CalDAV\\Xml\\Property\\EmailAddressSet', $prop); + $this->assertEquals(['user1.sabredav@sabredav.org'], $prop->getValue()); } function testSupportedReportSetPropertyNonCalendar() { - $props = $this->server->getPropertiesForPath('/calendars/user1',array( + $props = $this->server->getPropertiesForPath('/calendars/user1', [ '{DAV:}supported-report-set', - )); + ]); - $this->assertArrayHasKey(0,$props); - $this->assertArrayHasKey(200,$props[0]); - $this->assertArrayHasKey('{DAV:}supported-report-set',$props[0][200]); + $this->assertArrayHasKey(0, $props); + $this->assertArrayHasKey(200, $props[0]); + $this->assertArrayHasKey('{DAV:}supported-report-set', $props[0][200]); $prop = $props[0][200]['{DAV:}supported-report-set']; - $this->assertInstanceOf('\\Sabre\\DAV\\Property\\SupportedReportSet', $prop); - $value = array( + $this->assertInstanceOf('\\Sabre\\DAV\\Xml\\Property\\SupportedReportSet', $prop); + $value = [ '{DAV:}expand-property', '{DAV:}principal-property-search', '{DAV:}principal-search-property-set' - ); - $this->assertEquals($value,$prop->getValue()); + ]; + $this->assertEquals($value, $prop->getValue()); } @@ -506,26 +492,51 @@ END:VCALENDAR'; */ function testSupportedReportSetProperty() { - $props = $this->server->getPropertiesForPath('/calendars/user1/UUID-123467',array( + $props = $this->server->getPropertiesForPath('/calendars/user1/UUID-123467', [ '{DAV:}supported-report-set', - )); + ]); - $this->assertArrayHasKey(0,$props); - $this->assertArrayHasKey(200,$props[0]); - $this->assertArrayHasKey('{DAV:}supported-report-set',$props[0][200]); + $this->assertArrayHasKey(0, $props); + $this->assertArrayHasKey(200, $props[0]); + $this->assertArrayHasKey('{DAV:}supported-report-set', $props[0][200]); $prop = $props[0][200]['{DAV:}supported-report-set']; - $this->assertTrue($prop instanceof \Sabre\DAV\Property\SupportedReportSet); - $value = array( + $this->assertInstanceOf('\\Sabre\\DAV\\Xml\\Property\\SupportedReportSet', $prop); + $value = [ '{urn:ietf:params:xml:ns:caldav}calendar-multiget', '{urn:ietf:params:xml:ns:caldav}calendar-query', '{urn:ietf:params:xml:ns:caldav}free-busy-query', '{DAV:}expand-property', '{DAV:}principal-property-search', '{DAV:}principal-search-property-set' - ); - $this->assertEquals($value,$prop->getValue()); + ]; + $this->assertEquals($value, $prop->getValue()); + + } + + function testSupportedReportSetUserCalendars() { + + $this->server->addPlugin(new \Sabre\DAV\Sync\Plugin()); + + $props = $this->server->getPropertiesForPath('/calendars/user1', [ + '{DAV:}supported-report-set', + ]); + + $this->assertArrayHasKey(0, $props); + $this->assertArrayHasKey(200, $props[0]); + $this->assertArrayHasKey('{DAV:}supported-report-set', $props[0][200]); + + $prop = $props[0][200]['{DAV:}supported-report-set']; + + $this->assertInstanceOf('\\Sabre\\DAV\\Xml\\Property\\SupportedReportSet', $prop); + $value = [ + '{DAV:}sync-collection', + '{DAV:}expand-property', + '{DAV:}principal-property-search', + '{DAV:}principal-search-property-set', + ]; + $this->assertEquals($value, $prop->getValue()); } @@ -544,48 +555,33 @@ END:VCALENDAR'; '/calendars/user1/UUID-123467/UUID-2345' . ''; - $request = new HTTP\Request(array( - 'REQUEST_METHOD' => 'REPORT', - 'REQUEST_URI' => '/calendars/user1', - 'HTTP_DEPTH' => '1', - )); + $request = new HTTP\Request('REPORT', '/calendars/user1', ['Depth' => '1']); $request->setBody($body); $this->server->httpRequest = $request; $this->server->exec(); - $this->assertEquals('HTTP/1.1 207 Multi-Status',$this->response->status,'Invalid HTTP status received. Full response body: ' . $this->response->body); - - $xml = simplexml_load_string(DAV\XMLUtil::convertDAVNamespace($this->response->body)); + $this->assertEquals(207, $this->response->status, 'Invalid HTTP status received. Full response body'); - $xml->registerXPathNamespace('d','urn:DAV'); - $xml->registerXPathNamespace('c','urn:ietf:params:xml:ns:caldav'); + $expectedIcal = TestUtil::getTestCalendarData(); - $check = array( - '/d:multistatus', - '/d:multistatus/d:response', - '/d:multistatus/d:response/d:href', - '/d:multistatus/d:response/d:propstat', - '/d:multistatus/d:response/d:propstat/d:prop', - '/d:multistatus/d:response/d:propstat/d:prop/d:getetag', - '/d:multistatus/d:response/d:propstat/d:prop/c:calendar-data', - '/d:multistatus/d:response/d:propstat/d:status' => 'HTTP/1.1 200 OK', - ); + $expected = << + + + /calendars/user1/UUID-123467/UUID-2345 + + + $expectedIcal + "e207e33c10e5fb9c12cfb35b5d9116e1" + + HTTP/1.1 200 OK + + + +XML; - foreach($check as $v1=>$v2) { - - $xpath = is_int($v1)?$v2:$v1; - - $result = $xml->xpath($xpath); - $this->assertEquals(1,count($result)); - - if (!is_int($v1)) $this->assertEquals($v2,(string)$result[0]); - - } - - // The response object should have a reference to the Asia/Seoul - // timezone. - $this->assertTrue(strpos($this->response->body,'Asia/Seoul')!==false); + $this->assertXmlStringEqualsXmlString($expected, $this->response->getBodyAsString()); } @@ -606,46 +602,39 @@ END:VCALENDAR'; '/calendars/user1/UUID-123467/UUID-2345' . ''; - $request = new HTTP\Request(array( - 'REQUEST_METHOD' => 'REPORT', - 'REQUEST_URI' => '/calendars/user1', - 'HTTP_DEPTH' => '1', - )); + $request = new HTTP\Request('REPORT', '/calendars/user1', ['Depth' => '1']); $request->setBody($body); $this->server->httpRequest = $request; $this->server->exec(); - $this->assertEquals('HTTP/1.1 207 Multi-Status',$this->response->status,'Invalid HTTP status received. Full response body: ' . $this->response->body); - - $xml = simplexml_load_string(DAV\XMLUtil::convertDAVNamespace($this->response->body)); - - $xml->registerXPathNamespace('d','urn:DAV'); - $xml->registerXPathNamespace('c','urn:ietf:params:xml:ns:caldav'); + $this->assertEquals(207, $this->response->status, 'Invalid HTTP status received. Full response body: ' . $this->response->body); - $check = array( - '/d:multistatus', - '/d:multistatus/d:response', - '/d:multistatus/d:response/d:href', - '/d:multistatus/d:response/d:propstat', - '/d:multistatus/d:response/d:propstat/d:prop', - '/d:multistatus/d:response/d:propstat/d:prop/d:getetag', - '/d:multistatus/d:response/d:propstat/d:prop/c:calendar-data', - '/d:multistatus/d:response/d:propstat/d:status' => 'HTTP/1.1 200 OK', + $expectedIcal = TestUtil::getTestCalendarData(); + $expectedIcal = \Sabre\VObject\Reader::read($expectedIcal); + $expectedIcal = $expectedIcal->expand( + new DateTime('2011-01-01 00:00:00', new DateTimeZone('UTC')), + new DateTime('2011-12-31 23:59:59', new DateTimeZone('UTC')) ); - - foreach($check as $v1=>$v2) { - - $xpath = is_int($v1)?$v2:$v1; - - $result = $xml->xpath($xpath); - $this->assertEquals(1,count($result)); - - if (!is_int($v1)) $this->assertEquals($v2,(string)$result[0]); - - } - // The response object should no longer hold references to timezones. - $this->assertTrue(strpos($this->response->body,'Asia/Seoul')===false); + $expectedIcal = str_replace("\r\n", " \n", $expectedIcal->serialize()); + + $expected = << + + + /calendars/user1/UUID-123467/UUID-2345 + + + $expectedIcal + "e207e33c10e5fb9c12cfb35b5d9116e1" + + HTTP/1.1 200 OK + + + +XML; + + $this->assertXmlStringEqualsXmlString($expected, $this->response->getBodyAsString()); } @@ -671,56 +660,117 @@ END:VCALENDAR'; '' . ''; - $request = new HTTP\Request(array( - 'REQUEST_METHOD' => 'REPORT', - 'REQUEST_URI' => '/calendars/user1/UUID-123467', - 'HTTP_DEPTH' => '1', - )); + $request = new HTTP\Request('REPORT', '/calendars/user1/UUID-123467', ['Depth' => '1']); $request->setBody($body); $this->server->httpRequest = $request; $this->server->exec(); - $this->assertEquals('HTTP/1.1 207 Multi-Status',$this->response->status,'Received an unexpected status. Full response body: ' . $this->response->body); + $this->assertEquals(207, $this->response->status, 'Received an unexpected status. Full response body: ' . $this->response->body); - $xml = simplexml_load_string(DAV\XMLUtil::convertDAVNamespace($this->response->body)); + $expectedIcal = TestUtil::getTestCalendarData(); + $expectedIcal = \Sabre\VObject\Reader::read($expectedIcal); + $expectedIcal = $expectedIcal->expand( + new DateTime('2000-01-01 00:00:00', new DateTimeZone('UTC')), + new DateTime('2010-12-31 23:59:59', new DateTimeZone('UTC')) + ); + $expectedIcal = str_replace("\r\n", " \n", $expectedIcal->serialize()); + + $expected = << + + + /calendars/user1/UUID-123467/UUID-2345 + + + $expectedIcal + "e207e33c10e5fb9c12cfb35b5d9116e1" + + HTTP/1.1 200 OK + + + +XML; + + $this->assertXmlStringEqualsXmlString($expected, $this->response->getBodyAsString()); - $xml->registerXPathNamespace('d','urn:DAV'); - $xml->registerXPathNamespace('c','urn:ietf:params:xml:ns:caldav'); + } - $check = array( - '/d:multistatus', - '/d:multistatus/d:response', - '/d:multistatus/d:response/d:href', - '/d:multistatus/d:response/d:propstat', - '/d:multistatus/d:response/d:propstat/d:prop', - '/d:multistatus/d:response/d:propstat/d:prop/d:getetag', - '/d:multistatus/d:response/d:propstat/d:prop/c:calendar-data', - '/d:multistatus/d:response/d:propstat/d:status' => 'HTTP/1.1 200 OK', - ); + /** + * @depends testSupportedReportSetProperty + * @depends testCalendarMultiGetReport + */ + function testCalendarQueryReportWindowsPhone() { - foreach($check as $v1=>$v2) { + $body = + '' . + '' . + '' . + ' ' . + ' ' . + ' ' . + ' ' . + '' . + '' . + ' ' . + ' ' . + ' ' . + '' . + ''; - $xpath = is_int($v1)?$v2:$v1; + $request = new HTTP\Request('REPORT', '/calendars/user1/UUID-123467', [ + 'Depth' => '0', + 'User-Agent' => 'MSFT-WP/8.10.14219 (gzip)', + ]); - $result = $xml->xpath($xpath); - $this->assertEquals(1,count($result), 'We expected 1 ' . $xpath . ' elements. We\'ve found ' . count($result) . '. Full result: ' . $this->response->body); + $request->setBody($body); - if (!is_int($v1)) $this->assertEquals($v2,(string)$result[0]); + $this->server->httpRequest = $request; + $this->server->exec(); - } + $this->assertEquals(207, $this->response->status, 'Received an unexpected status. Full response body: ' . $this->response->body); + + $expectedIcal = TestUtil::getTestCalendarData(); + $expectedIcal = \Sabre\VObject\Reader::read($expectedIcal); + $expectedIcal = $expectedIcal->expand( + new DateTime('2000-01-01 00:00:00', new DateTimeZone('UTC')), + new DateTime('2010-12-31 23:59:59', new DateTimeZone('UTC')) + ); + $expectedIcal = str_replace("\r\n", " \n", $expectedIcal->serialize()); + + $expected = << + + + /calendars/user1/UUID-123467/UUID-2345 + + + $expectedIcal + "e207e33c10e5fb9c12cfb35b5d9116e1" + + HTTP/1.1 200 OK + + + +XML; + + $this->assertXmlStringEqualsXmlString($expected, $this->response->getBodyAsString()); } /** - * @depends testCalendarQueryReport + * @depends testSupportedReportSetProperty + * @depends testCalendarMultiGetReport */ - function testCalendarQueryReportNoCalData() { + function testCalendarQueryReportBadDepth() { $body = '' . '' . '' . + ' ' . + ' ' . + ' ' . ' ' . '' . '' . @@ -730,43 +780,62 @@ END:VCALENDAR'; '' . ''; - $request = new HTTP\Request(array( - 'REQUEST_METHOD' => 'REPORT', - 'REQUEST_URI' => '/calendars/user1//UUID-123467', - 'HTTP_DEPTH' => '1', - )); + $request = new HTTP\Request('REPORT', '/calendars/user1/UUID-123467', [ + 'Depth' => '0', + ]); $request->setBody($body); $this->server->httpRequest = $request; $this->server->exec(); - $this->assertEquals('HTTP/1.1 207 Multi-Status',$this->response->status,'Received an unexpected status. Full response body: ' . $this->response->body); - - $xml = simplexml_load_string(DAV\XMLUtil::convertDAVNamespace($this->response->body)); + $this->assertEquals(400, $this->response->status, 'Received an unexpected status. Full response body: ' . $this->response->body); - $xml->registerXPathNamespace('d','urn:DAV'); - $xml->registerXPathNamespace('c','urn:ietf:params:xml:ns:caldav'); - - $check = array( - '/d:multistatus', - '/d:multistatus/d:response', - '/d:multistatus/d:response/d:href', - '/d:multistatus/d:response/d:propstat', - '/d:multistatus/d:response/d:propstat/d:prop', - '/d:multistatus/d:response/d:propstat/d:prop/d:getetag', - '/d:multistatus/d:response/d:propstat/d:status' => 'HTTP/1.1 200 OK', - ); + } - foreach($check as $v1=>$v2) { + /** + * @depends testCalendarQueryReport + */ + function testCalendarQueryReportNoCalData() { - $xpath = is_int($v1)?$v2:$v1; + $body = + '' . + '' . + '' . + ' ' . + '' . + '' . + ' ' . + ' ' . + ' ' . + '' . + ''; - $result = $xml->xpath($xpath); - $this->assertEquals(1,count($result), 'We expected 1 ' . $xpath . ' elements. We\'ve found ' . count($result) . '. Full result: ' . $this->response->body); + $request = new HTTP\Request('REPORT', '/calendars/user1/UUID-123467', [ + 'Depth' => '1', + ]); + $request->setBody($body); - if (!is_int($v1)) $this->assertEquals($v2,(string)$result[0]); + $this->server->httpRequest = $request; + $this->server->exec(); - } + $this->assertEquals(207, $this->response->status, 'Received an unexpected status. Full response body: ' . $this->response->body); + + $expected = << + + + /calendars/user1/UUID-123467/UUID-2345 + + + "e207e33c10e5fb9c12cfb35b5d9116e1" + + HTTP/1.1 200 OK + + + +XML; + + $this->assertXmlStringEqualsXmlString($expected, $this->response->getBodyAsString()); } @@ -784,16 +853,13 @@ END:VCALENDAR'; '' . ''; - $request = new HTTP\Request(array( - 'REQUEST_METHOD' => 'REPORT', - 'REQUEST_URI' => '/calendars/user1//UUID-123467', - )); + $request = new HTTP\Request('REPORT', '/calendars/user1/UUID-123467'); $request->setBody($body); $this->server->httpRequest = $request; $this->server->exec(); - $this->assertEquals('HTTP/1.1 400 Bad request',$this->response->status,'Received an unexpected status. Full response body: ' . $this->response->body); + $this->assertEquals(400, $this->response->status, 'Received an unexpected status. Full response body: ' . $this->response->body); } @@ -819,44 +885,39 @@ END:VCALENDAR'; '' . ''; - $request = new HTTP\Request(array( - 'REQUEST_METHOD' => 'REPORT', - 'REQUEST_URI' => '/calendars/user1/UUID-123467/UUID-2345', - 'HTTP_DEPTH' => '0', - )); + $request = new HTTP\Request('REPORT', '/calendars/user1/UUID-123467/UUID-2345', ['Depth' => '0']); $request->setBody($body); $this->server->httpRequest = $request; $this->server->exec(); - $this->assertEquals('HTTP/1.1 207 Multi-Status',$this->response->status,'Received an unexpected status. Full response body: ' . $this->response->body); - - $xml = simplexml_load_string(DAV\XMLUtil::convertDAVNamespace($this->response->body)); - - $xml->registerXPathNamespace('d','urn:DAV'); - $xml->registerXPathNamespace('c','urn:ietf:params:xml:ns:caldav'); + $this->assertEquals(207, $this->response->status, 'Received an unexpected status. Full response body: ' . $this->response->body); - $check = array( - '/d:multistatus', - '/d:multistatus/d:response', - '/d:multistatus/d:response/d:href', - '/d:multistatus/d:response/d:propstat', - '/d:multistatus/d:response/d:propstat/d:prop', - '/d:multistatus/d:response/d:propstat/d:prop/d:getetag', - '/d:multistatus/d:response/d:propstat/d:prop/c:calendar-data', - '/d:multistatus/d:response/d:propstat/d:status' => 'HTTP/1.1 200 OK', + $expectedIcal = TestUtil::getTestCalendarData(); + $expectedIcal = \Sabre\VObject\Reader::read($expectedIcal); + $expectedIcal = $expectedIcal->expand( + new DateTime('2000-01-01 00:00:00', new DateTimeZone('UTC')), + new DateTime('2010-12-31 23:59:59', new DateTimeZone('UTC')) ); - - foreach($check as $v1=>$v2) { - - $xpath = is_int($v1)?$v2:$v1; - - $result = $xml->xpath($xpath); - $this->assertEquals(1,count($result), 'We expected 1 ' . $xpath . ' elements. We\'ve found ' . count($result) . '. Full result: ' . $this->response->body); - - if (!is_int($v1)) $this->assertEquals($v2,(string)$result[0]); - - } + $expectedIcal = str_replace("\r\n", " \n", $expectedIcal->serialize()); + + $expected = << + + + /calendars/user1/UUID-123467/UUID-2345 + + + $expectedIcal + "e207e33c10e5fb9c12cfb35b5d9116e1" + + HTTP/1.1 200 OK + + + +XML; + + $this->assertXmlStringEqualsXmlString($expected, $this->response->getBodyAsString()); } @@ -879,77 +940,40 @@ END:VCALENDAR'; '' . ''; - $request = new HTTP\Request(array( - 'REQUEST_METHOD' => 'REPORT', - 'REQUEST_URI' => '/calendars/user1/UUID-123467/UUID-2345', - 'HTTP_DEPTH' => '0', - )); + $request = new HTTP\Request('REPORT', '/calendars/user1/UUID-123467/UUID-2345', ['Depth' => '0']); $request->setBody($body); $this->server->httpRequest = $request; $this->server->exec(); - $this->assertEquals('HTTP/1.1 207 Multi-Status',$this->response->status,'Received an unexpected status. Full response body: ' . $this->response->body); - - $xml = simplexml_load_string(DAV\XMLUtil::convertDAVNamespace($this->response->body)); - - $xml->registerXPathNamespace('d','urn:DAV'); - $xml->registerXPathNamespace('c','urn:ietf:params:xml:ns:caldav'); - - $check = array( - '/d:multistatus', - '/d:multistatus/d:response', - '/d:multistatus/d:response/d:href', - '/d:multistatus/d:response/d:propstat', - '/d:multistatus/d:response/d:propstat/d:prop', - '/d:multistatus/d:response/d:propstat/d:prop/d:getetag', - '/d:multistatus/d:response/d:propstat/d:status' => 'HTTP/1.1 200 OK', - ); - - foreach($check as $v1=>$v2) { - - $xpath = is_int($v1)?$v2:$v1; - - $result = $xml->xpath($xpath); - $this->assertEquals(1,count($result), 'We expected 1 ' . $xpath . ' elements. We\'ve found ' . count($result) . '. Full result: ' . $this->response->body); - - if (!is_int($v1)) $this->assertEquals($v2,(string)$result[0]); - - } + $this->assertEquals(207, $this->response->status, 'Received an unexpected status. Full response body: ' . $this->response->body); + + $expected = << + + + /calendars/user1/UUID-123467/UUID-2345 + + + "e207e33c10e5fb9c12cfb35b5d9116e1" + + HTTP/1.1 200 OK + + + +XML; + + $this->assertXmlStringEqualsXmlString($expected, $this->response->getBodyAsString()); } function testHTMLActionsPanel() { $output = ''; - $r = $this->server->broadcastEvent('onHTMLActionsPanel', array($this->server->tree->getNodeForPath('calendars/user1'), &$output)); + $r = $this->server->emit('onHTMLActionsPanel', [$this->server->tree->getNodeForPath('calendars/user1'), &$output]); $this->assertFalse($r); - $this->assertTrue(!!strpos($output,'Display name')); - - } - - function testBrowserPostAction() { - - $r = $this->server->broadcastEvent('onBrowserPostAction', array('calendars/user1', 'mkcalendar', array( - 'name' => 'NEWCALENDAR', - '{DAV:}displayname' => 'foo', - ))); - $this->assertFalse($r); - - $calendars = $this->caldavBackend->getCalendarsForUser('principals/user1'); - $this->assertEquals(3, count($calendars)); - - $newCalendar = null; - foreach($calendars as $calendar) { - if ($calendar['uri'] === 'NEWCALENDAR') { - $newCalendar = $calendar; - break; - } - } - if (!$newCalendar) - $this->fail('Could not find newly created calendar'); - + $this->assertTrue(!!strpos($output, 'Display name')); } @@ -970,17 +994,13 @@ END:VCALENDAR'; '/calendars/user1/UUID-123467/UUID-2345' . ''; - $request = new HTTP\Request(array( - 'REQUEST_METHOD' => 'REPORT', - 'REQUEST_URI' => '/calendars/user1', - 'HTTP_DEPTH' => '1', - )); + $request = new HTTP\Request('REPORT', '/calendars/user1', ['Depth' => '1']); $request->setBody($body); $this->server->httpRequest = $request; $this->server->exec(); - $this->assertEquals('HTTP/1.1 400 Bad request',$this->response->status,'Invalid HTTP status received. Full response body: ' . $this->response->body); + $this->assertEquals(400, $this->response->status, 'Invalid HTTP status received. Full response body: ' . $this->response->body); } @@ -1001,17 +1021,13 @@ END:VCALENDAR'; '/calendars/user1/UUID-123467/UUID-2345' . ''; - $request = new HTTP\Request(array( - 'REQUEST_METHOD' => 'REPORT', - 'REQUEST_URI' => '/calendars/user1', - 'HTTP_DEPTH' => '1', - )); + $request = new HTTP\Request('REPORT', '/calendars/user1', ['Depth' => '1']); $request->setBody($body); $this->server->httpRequest = $request; $this->server->exec(); - $this->assertEquals('HTTP/1.1 400 Bad request',$this->response->status,'Invalid HTTP status received. Full response body: ' . $this->response->body); + $this->assertEquals(400, $this->response->status, 'Invalid HTTP status received. Full response body: ' . $this->response->body); } @@ -1032,95 +1048,34 @@ END:VCALENDAR'; '/calendars/user1/UUID-123467/UUID-2345' . ''; - $request = new HTTP\Request(array( - 'REQUEST_METHOD' => 'REPORT', - 'REQUEST_URI' => '/calendars/user1', - 'HTTP_DEPTH' => '1', - )); + $request = new HTTP\Request('REPORT', '/calendars/user1', ['Depth' => '1']); $request->setBody($body); $this->server->httpRequest = $request; $this->server->exec(); - $this->assertEquals('HTTP/1.1 400 Bad request',$this->response->status,'Invalid HTTP status received. Full response body: ' . $this->response->body); + $this->assertEquals(400, $this->response->status, 'Invalid HTTP status received. Full response body: ' . $this->response->body); } - function testNotificationProperties() { - - $request = array( - '{' . Plugin::NS_CALENDARSERVER . '}notificationtype', - ); - $result = array(); - $notification = new Notifications\Node( - $this->caldavBackend, - 'principals/user1', - new Notifications\Notification\SystemStatus('foo','"1"') - ); - $this->plugin->beforeGetProperties('foo', $notification, $request, $result); - - $this->assertEquals( - array( - 200 => array( - '{' . Plugin::NS_CALENDARSERVER . '}notificationtype' => $notification->getNotificationType() - ) - ), $result); - - } - - function testNotificationGet() { - - $notification = new Notifications\Node( - $this->caldavBackend, - 'principals/user1', - new Notifications\Notification\SystemStatus('foo','"1"') - ); - - $server = new DAV\Server(array($notification)); - $caldav = new Plugin(); - - $server->httpRequest = new HTTP\Request(array( - 'REQUEST_URI' => '/foo.xml', - )); - $httpResponse = new HTTP\ResponseMock(); - $server->httpResponse = $httpResponse; - - $server->addPlugin($caldav); - - $caldav->beforeMethod('GET','foo.xml'); - - $this->assertEquals('HTTP/1.1 200 OK', $httpResponse->status); - $this->assertEquals(array( - 'Content-Type' => 'application/xml', - 'ETag' => '"1"', - ), $httpResponse->headers); - - $expected = -' - - - -'; - - $this->assertEquals($expected, $httpResponse->body); - - } - - function testGETPassthrough() { - - $server = new DAV\Server(); - $caldav = new Plugin(); - - $httpResponse = new HTTP\ResponseMock(); - $server->httpResponse = $httpResponse; - - $server->addPlugin($caldav); + /** + * @depends testSupportedReportSetPropertyNonCalendar + */ + function testCalendarProperties() { - $caldav->beforeMethod('GET','foo'); + $ns = '{urn:ietf:params:xml:ns:caldav}'; + $props = $this->server->getProperties('calendars/user1/UUID-123467', [ + $ns . 'max-resource-size', + $ns . 'supported-calendar-data', + $ns . 'supported-collation-set', + ]); - $this->assertNull($caldav->beforeMethod('GET','foozz')); + $this->assertEquals([ + $ns . 'max-resource-size' => 10000000, + $ns . 'supported-calendar-data' => new Xml\Property\SupportedCalendarData(), + $ns . 'supported-collation-set' => new Xml\Property\SupportedCollationSet(), + ], $props); } - } diff --git a/vendor/sabre/dav/tests/Sabre/CalDAV/Principal/UserTest.php b/vendor/sabre/dav/tests/Sabre/CalDAV/Principal/UserTest.php index d41692f2a..37b5eae97 100644 --- a/vendor/sabre/dav/tests/Sabre/CalDAV/Principal/UserTest.php +++ b/vendor/sabre/dav/tests/Sabre/CalDAV/Principal/UserTest.php @@ -103,7 +103,7 @@ class UserTest extends \PHPUnit_Framework_TestCase { $expected = array( array( 'privilege' => '{DAV:}read', - 'principal' => 'principals/user', + 'principal' => '{DAV:}authenticated', 'protected' => true, ), array( diff --git a/vendor/sabre/dav/tests/Sabre/CalDAV/Property/AllowedSharingModesTest.php b/vendor/sabre/dav/tests/Sabre/CalDAV/Property/AllowedSharingModesTest.php deleted file mode 100644 index 733ea1108..000000000 --- a/vendor/sabre/dav/tests/Sabre/CalDAV/Property/AllowedSharingModesTest.php +++ /dev/null @@ -1,46 +0,0 @@ -createElement('d:root'); - $root->setAttribute('xmlns:d','DAV:'); - $root->setAttribute('xmlns:cal',CalDAV\Plugin::NS_CALDAV); - $root->setAttribute('xmlns:cs',CalDAV\Plugin::NS_CALENDARSERVER); - - $doc->appendChild($root); - $server = new DAV\Server(); - - $property->serialize($server, $root); - - $xml = $doc->saveXML(); - - $this->assertEquals( -' -' . -'' . -'' . -' -', $xml); - - } - -} diff --git a/vendor/sabre/dav/tests/Sabre/CalDAV/Property/InviteTest.php b/vendor/sabre/dav/tests/Sabre/CalDAV/Property/InviteTest.php deleted file mode 100644 index 349a6e080..000000000 --- a/vendor/sabre/dav/tests/Sabre/CalDAV/Property/InviteTest.php +++ /dev/null @@ -1,196 +0,0 @@ - 'mailto:user1@example.org', - 'status' => CalDAV\SharingPlugin::STATUS_ACCEPTED, - 'readOnly' => false, - ), - array( - 'href' => 'mailto:user2@example.org', - 'commonName' => 'John Doe', - 'status' => CalDAV\SharingPlugin::STATUS_DECLINED, - 'readOnly' => true, - ), - array( - 'href' => 'mailto:user3@example.org', - 'commonName' => 'Joe Shmoe', - 'status' => CalDAV\SharingPlugin::STATUS_NORESPONSE, - 'readOnly' => true, - 'summary' => 'Something, something', - ), - array( - 'href' => 'mailto:user4@example.org', - 'commonName' => 'Hoe Boe', - 'status' => CalDAV\SharingPlugin::STATUS_INVALID, - 'readOnly' => true, - ), - ), array( - 'href' => 'mailto:thedoctor@example.org', - 'commonName' => 'The Doctor', - 'firstName' => 'The', - 'lastName' => 'Doctor', - )); - - $doc = new \DOMDocument(); - $doc->formatOutput = true; - $root = $doc->createElement('d:root'); - $root->setAttribute('xmlns:d','DAV:'); - $root->setAttribute('xmlns:cal',CalDAV\Plugin::NS_CALDAV); - $root->setAttribute('xmlns:cs',CalDAV\Plugin::NS_CALENDARSERVER); - - $doc->appendChild($root); - $server = new DAV\Server(); - - $property->serialize($server, $root); - - $xml = $doc->saveXML(); - - $this->assertEquals( -' - - - mailto:thedoctor@example.org - The Doctor - The - Doctor - - - mailto:user1@example.org - - - - - - - mailto:user2@example.org - John Doe - - - - - - - mailto:user3@example.org - Joe Shmoe - - - - - Something, something - - - mailto:user4@example.org - Hoe Boe - - - - - - -', $xml); - - } - - /** - * @depends testSerialize - */ - public function testUnserialize() { - - $input = array( - array( - 'href' => 'mailto:user1@example.org', - 'status' => CalDAV\SharingPlugin::STATUS_ACCEPTED, - 'readOnly' => false, - 'commonName' => '', - 'summary' => '', - ), - array( - 'href' => 'mailto:user2@example.org', - 'commonName' => 'John Doe', - 'status' => CalDAV\SharingPlugin::STATUS_DECLINED, - 'readOnly' => true, - 'summary' => '', - ), - array( - 'href' => 'mailto:user3@example.org', - 'commonName' => 'Joe Shmoe', - 'status' => CalDAV\SharingPlugin::STATUS_NORESPONSE, - 'readOnly' => true, - 'summary' => 'Something, something', - ), - array( - 'href' => 'mailto:user4@example.org', - 'commonName' => 'Hoe Boe', - 'status' => CalDAV\SharingPlugin::STATUS_INVALID, - 'readOnly' => true, - 'summary' => '', - ), - ); - - // Creating the xml - $doc = new \DOMDocument(); - $doc->formatOutput = true; - $root = $doc->createElement('d:root'); - $root->setAttribute('xmlns:d','DAV:'); - $root->setAttribute('xmlns:cal',CalDAV\Plugin::NS_CALDAV); - $root->setAttribute('xmlns:cs',CalDAV\Plugin::NS_CALENDARSERVER); - - $doc->appendChild($root); - $server = new DAV\Server(); - - $inputProperty = new Invite($input); - $inputProperty->serialize($server, $root); - - $xml = $doc->saveXML(); - - // Parsing it again - - $doc2 = DAV\XMLUtil::loadDOMDocument($xml); - - $outputProperty = Invite::unserialize($doc2->firstChild); - - $this->assertEquals($input, $outputProperty->getValue()); - - } - - /** - * @expectedException Sabre\DAV\Exception - */ - function testUnserializeNoStatus() { - -$xml = ' - - - mailto:user1@example.org - - - - - -'; - - $doc2 = DAV\XMLUtil::loadDOMDocument($xml); - $outputProperty = Invite::unserialize($doc2->firstChild); - - } - -} diff --git a/vendor/sabre/dav/tests/Sabre/CalDAV/Property/ScheduleCalendarTranspTest.php b/vendor/sabre/dav/tests/Sabre/CalDAV/Property/ScheduleCalendarTranspTest.php deleted file mode 100644 index 1ace0b18f..000000000 --- a/vendor/sabre/dav/tests/Sabre/CalDAV/Property/ScheduleCalendarTranspTest.php +++ /dev/null @@ -1,99 +0,0 @@ -assertEquals('transparent', $sccs->getValue()); - - } - - /** - * @expectedException InvalidArgumentException - */ - function testBadArg() { - - $sccs = new ScheduleCalendarTransp('foo'); - - } - - function values() { - - return array( - array('transparent'), - array('opaque'), - ); - - } - - /** - * @depends testSimple - * @dataProvider values - */ - function testSerialize($value) { - - $property = new ScheduleCalendarTransp($value); - - $doc = new \DOMDocument(); - $root = $doc->createElement('d:root'); - $root->setAttribute('xmlns:d','DAV:'); - $root->setAttribute('xmlns:cal',CalDAV\Plugin::NS_CALDAV); - - $doc->appendChild($root); - $server = new DAV\Server(); - - $property->serialize($server, $root); - - $xml = $doc->saveXML(); - - $this->assertEquals( -' -' . -'' . -' -', $xml); - - } - - /** - * @depends testSimple - * @dataProvider values - */ - function testUnserializer($value) { - - $xml = ' -' . -'' . -''; - - $dom = DAV\XMLUtil::loadDOMDocument($xml); - - $property = ScheduleCalendarTransp::unserialize($dom->firstChild); - - $this->assertTrue($property instanceof ScheduleCalendarTransp); - $this->assertEquals($value, $property->getValue()); - - } - - /** - * @depends testSimple - */ - function testUnserializerBadData() { - - $xml = ' -' . -'' . -''; - - $dom = DAV\XMLUtil::loadDOMDocument($xml); - - $this->assertNull(ScheduleCalendarTransp::unserialize($dom->firstChild)); - - } -} diff --git a/vendor/sabre/dav/tests/Sabre/CalDAV/Property/SupportedCalendarComponentSetTest.php b/vendor/sabre/dav/tests/Sabre/CalDAV/Property/SupportedCalendarComponentSetTest.php deleted file mode 100644 index 3e5d5f5fc..000000000 --- a/vendor/sabre/dav/tests/Sabre/CalDAV/Property/SupportedCalendarComponentSetTest.php +++ /dev/null @@ -1,67 +0,0 @@ -assertEquals(array('VEVENT'), $sccs->getValue()); - - } - - /** - * @depends testSimple - */ - function testSerialize() { - - $property = new SupportedCalendarComponentSet(array('VEVENT','VJOURNAL')); - - $doc = new \DOMDocument(); - $root = $doc->createElement('d:root'); - $root->setAttribute('xmlns:d','DAV:'); - $root->setAttribute('xmlns:cal',\Sabre\CalDAV\Plugin::NS_CALDAV); - - $doc->appendChild($root); - $server = new \Sabre\DAV\Server(); - - $property->serialize($server, $root); - - $xml = $doc->saveXML(); - - $this->assertEquals( -' -' . -'' . -'' . -' -', $xml); - - } - - /** - * @depends testSimple - */ - function testUnserializer() { - - $xml = ' -' . -'' . -'' . -''; - - $dom = \Sabre\DAV\XMLUtil::loadDOMDocument($xml); - - $property = SupportedCalendarComponentSet::unserialize($dom->firstChild); - - $this->assertTrue($property instanceof SupportedCalendarComponentSet); - $this->assertEquals(array( - 'VEVENT', - 'VJOURNAL', - ), - $property->getValue()); - - } - -} diff --git a/vendor/sabre/dav/tests/Sabre/CalDAV/Property/SupportedCalendarDataTest.php b/vendor/sabre/dav/tests/Sabre/CalDAV/Property/SupportedCalendarDataTest.php deleted file mode 100644 index 3e016368c..000000000 --- a/vendor/sabre/dav/tests/Sabre/CalDAV/Property/SupportedCalendarDataTest.php +++ /dev/null @@ -1,44 +0,0 @@ -createElement('d:root'); - $root->setAttribute('xmlns:d','DAV:'); - $root->setAttribute('xmlns:cal',CalDAV\Plugin::NS_CALDAV); - - $doc->appendChild($root); - $server = new DAV\Server(); - - $property->serialize($server, $root); - - $xml = $doc->saveXML(); - - $this->assertEquals( -' -' . -'' . -' -', $xml); - - } - -} diff --git a/vendor/sabre/dav/tests/Sabre/CalDAV/Property/SupportedCollationSetTest.php b/vendor/sabre/dav/tests/Sabre/CalDAV/Property/SupportedCollationSetTest.php deleted file mode 100644 index 669e31553..000000000 --- a/vendor/sabre/dav/tests/Sabre/CalDAV/Property/SupportedCollationSetTest.php +++ /dev/null @@ -1,46 +0,0 @@ -createElement('d:root'); - $root->setAttribute('xmlns:d','DAV:'); - $root->setAttribute('xmlns:cal',CalDAV\Plugin::NS_CALDAV); - - $doc->appendChild($root); - $server = new DAV\Server(); - - $property->serialize($server, $root); - - $xml = $doc->saveXML(); - - $this->assertEquals( -' -' . -'i;ascii-casemap' . -'i;octet' . -'i;unicode-casemap' . -' -', $xml); - - } - -} diff --git a/vendor/sabre/dav/tests/Sabre/CalDAV/Schedule/IMip/Mock.php b/vendor/sabre/dav/tests/Sabre/CalDAV/Schedule/IMip/Mock.php deleted file mode 100644 index ce0946dc8..000000000 --- a/vendor/sabre/dav/tests/Sabre/CalDAV/Schedule/IMip/Mock.php +++ /dev/null @@ -1,50 +0,0 @@ -emails[] = array( - 'to' => $to, - 'subject' => $subject, - 'body' => $body, - 'headers' => $headers, - ); - - } - - public function getSentEmails() { - - return $this->emails; - - } - - -} diff --git a/vendor/sabre/dav/tests/Sabre/CalDAV/Schedule/OutboxTest.php b/vendor/sabre/dav/tests/Sabre/CalDAV/Schedule/OutboxTest.php index 60ce9a2ad..933c7157b 100644 --- a/vendor/sabre/dav/tests/Sabre/CalDAV/Schedule/OutboxTest.php +++ b/vendor/sabre/dav/tests/Sabre/CalDAV/Schedule/OutboxTest.php @@ -20,6 +20,7 @@ class OutboxTest extends \PHPUnit_Framework_TestCase { 'principal' => 'principals/user1', 'protected' => true, ), + array( 'privilege' => '{' . CalDAV\Plugin::NS_CALDAV . '}schedule-post-vevent', 'principal' => 'principals/user1', @@ -30,6 +31,26 @@ class OutboxTest extends \PHPUnit_Framework_TestCase { 'principal' => 'principals/user1', 'protected' => true, ), + array( + 'privilege' => '{' . CalDAV\Plugin::NS_CALDAV . '}schedule-query-freebusy', + 'principal' => 'principals/user1/calendar-proxy-write', + 'protected' => true, + ), + array( + 'privilege' => '{' . CalDAV\Plugin::NS_CALDAV . '}schedule-post-vevent', + 'principal' => 'principals/user1/calendar-proxy-write', + 'protected' => true, + ), + array( + 'privilege' => '{DAV:}read', + 'principal' => 'principals/user1/calendar-proxy-read', + 'protected' => true, + ), + array( + 'privilege' => '{DAV:}read', + 'principal' => 'principals/user1/calendar-proxy-write', + 'protected' => true, + ), ), $outbox->getACL()); $ok = false; diff --git a/vendor/sabre/dav/tests/Sabre/CalDAV/ShareableCalendarTest.php b/vendor/sabre/dav/tests/Sabre/CalDAV/ShareableCalendarTest.php index 2f79351f1..15b869d50 100644 --- a/vendor/sabre/dav/tests/Sabre/CalDAV/ShareableCalendarTest.php +++ b/vendor/sabre/dav/tests/Sabre/CalDAV/ShareableCalendarTest.php @@ -15,10 +15,8 @@ class ShareableCalendarTest extends \PHPUnit_Framework_TestCase { 'id' => 1, ); - $this->backend = new Backend\Mock( - array($props), - array(), - array() + $this->backend = new Backend\MockSharing( + array($props) ); $this->backend->updateShares(1, array( array( @@ -55,8 +53,8 @@ class ShareableCalendarTest extends \PHPUnit_Framework_TestCase { function testPublish() { - $this->instance->setPublishStatus(true); - $this->instance->setPublishStatus(false); + $this->assertNull($this->instance->setPublishStatus(true)); + $this->assertNull($this->instance->setPublishStatus(false)); } } diff --git a/vendor/sabre/dav/tests/Sabre/CalDAV/SharedCalendarTest.php b/vendor/sabre/dav/tests/Sabre/CalDAV/SharedCalendarTest.php index 955831917..337b658f4 100644 --- a/vendor/sabre/dav/tests/Sabre/CalDAV/SharedCalendarTest.php +++ b/vendor/sabre/dav/tests/Sabre/CalDAV/SharedCalendarTest.php @@ -20,7 +20,7 @@ class SharedCalendarTest extends \PHPUnit_Framework_TestCase { ); } - $this->backend = new Backend\Mock( + $this->backend = new Backend\MockSharing( array($props), array(), array() @@ -64,18 +64,58 @@ class SharedCalendarTest extends \PHPUnit_Framework_TestCase { 'principal' => 'principals/owner', 'protected' => true, ), + + array( + 'privilege' => '{DAV:}read', + 'principal' => 'principals/owner/calendar-proxy-write', + 'protected' => true, + ), + array( + 'privilege' => '{DAV:}read', + 'principal' => 'principals/owner/calendar-proxy-read', + 'protected' => true, + ), + array( + 'privilege' => '{' . Plugin::NS_CALDAV . '}read-free-busy', + 'principal' => '{DAV:}authenticated', + 'protected' => true, + ), array( 'privilege' => '{DAV:}write', 'principal' => 'principals/owner', 'protected' => true, ), array( - 'privilege' => '{DAV:}read', + 'privilege' => '{DAV:}write', 'principal' => 'principals/owner/calendar-proxy-write', 'protected' => true, ), + array( + 'privilege' => '{DAV:}read', + 'principal' => 'principals/sharee', + 'protected' => true, + ), array( 'privilege' => '{DAV:}write', + 'principal' => 'principals/sharee', + 'protected' => true, + ), + ); + + $this->assertEquals($expected, $this->getInstance()->getACL()); + + } + + function testGetChildACL() { + + $expected = array( + array( + 'privilege' => '{DAV:}read', + 'principal' => 'principals/owner', + 'protected' => true, + ), + array( + 'privilege' => '{DAV:}read', 'principal' => 'principals/owner/calendar-proxy-write', 'protected' => true, ), @@ -85,8 +125,13 @@ class SharedCalendarTest extends \PHPUnit_Framework_TestCase { 'protected' => true, ), array( - 'privilege' => '{' . Plugin::NS_CALDAV . '}read-free-busy', - 'principal' => '{DAV:}authenticated', + 'privilege' => '{DAV:}write', + 'principal' => 'principals/owner', + 'protected' => true, + ), + array( + 'privilege' => '{DAV:}write', + 'principal' => 'principals/owner/calendar-proxy-write', 'protected' => true, ), array( @@ -101,7 +146,43 @@ class SharedCalendarTest extends \PHPUnit_Framework_TestCase { ), ); - $this->assertEquals($expected, $this->getInstance()->getACL()); + $this->assertEquals($expected, $this->getInstance()->getChildACL()); + + } + + function testGetChildACLReadOnly() { + + $expected = array( + array( + 'privilege' => '{DAV:}read', + 'principal' => 'principals/owner', + 'protected' => true, + ), + array( + 'privilege' => '{DAV:}read', + 'principal' => 'principals/owner/calendar-proxy-write', + 'protected' => true, + ), + array( + 'privilege' => '{DAV:}read', + 'principal' => 'principals/owner/calendar-proxy-read', + 'protected' => true, + ), + array( + 'privilege' => '{DAV:}read', + 'principal' => 'principals/sharee', + 'protected' => true, + ), + ); + + $props = array( + 'id' => 1, + '{http://calendarserver.org/ns/}shared-url' => 'calendars/owner/original', + '{http://sabredav.org/ns}owner-principal' => 'principals/owner', + '{http://sabredav.org/ns}read-only' => true, + 'principaluri' => 'principals/sharee', + ); + $this->assertEquals($expected, $this->getInstance($props)->getChildACL()); } diff --git a/vendor/sabre/dav/tests/Sabre/CalDAV/SharingPluginTest.php b/vendor/sabre/dav/tests/Sabre/CalDAV/SharingPluginTest.php index 60a71fd7f..b4270da7d 100644 --- a/vendor/sabre/dav/tests/Sabre/CalDAV/SharingPluginTest.php +++ b/vendor/sabre/dav/tests/Sabre/CalDAV/SharingPluginTest.php @@ -33,7 +33,7 @@ class SharingPluginTest extends \Sabre\DAVServerTest { 'id' => 3, 'uri' => 'cal3', ), - ); + ); parent::setUp(); @@ -46,6 +46,10 @@ class SharingPluginTest extends \Sabre\DAVServerTest { function testSimple() { $this->assertInstanceOf('Sabre\\CalDAV\\SharingPlugin', $this->server->getPlugin('caldav-sharing')); + $this->assertEquals( + 'caldav-sharing', + $this->caldavSharingPlugin->getPluginInfo()['name'] + ); } @@ -58,14 +62,14 @@ class SharingPluginTest extends \Sabre\DAVServerTest { function testBeforeGetShareableCalendar() { // Forcing the server to authenticate: - $this->authPlugin->beforeMethod('GET',''); + $this->authPlugin->beforeMethod(new HTTP\Request(), new HTTP\Response()); $props = $this->server->getProperties('calendars/user1/cal1', array( '{' . Plugin::NS_CALENDARSERVER . '}invite', '{' . Plugin::NS_CALENDARSERVER . '}allowed-sharing-modes', )); - $this->assertInstanceOf('Sabre\\CalDAV\\Property\\Invite', $props['{' . Plugin::NS_CALENDARSERVER . '}invite']); - $this->assertInstanceOf('Sabre\\CalDAV\\Property\\AllowedSharingModes', $props['{' . 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']); } @@ -76,8 +80,8 @@ class SharingPluginTest extends \Sabre\DAVServerTest { '{' . Plugin::NS_CALENDARSERVER . '}invite', )); - $this->assertInstanceOf('Sabre\\CalDAV\\Property\\Invite', $props['{' . Plugin::NS_CALENDARSERVER . '}invite']); - $this->assertInstanceOf('Sabre\\DAV\\Property\\IHref', $props['{' . Plugin::NS_CALENDARSERVER . '}shared-url']); + $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']); } @@ -92,15 +96,12 @@ class SharingPluginTest extends \Sabre\DAVServerTest { array() ); $result = $this->server->updateProperties('calendars/user1/cal1', array( - '{DAV:}resourcetype' => new DAV\Property\ResourceType(array('{DAV:}collection')) + '{DAV:}resourcetype' => new DAV\Xml\Property\ResourceType(['{DAV:}collection']) )); - $this->assertEquals(array( - 200 => array( - '{DAV:}resourcetype' => null, - ), - 'href' => 'calendars/user1/cal1', - ), $result); + $this->assertEquals([ + '{DAV:}resourcetype' => 200 + ], $result); $this->assertEquals(0, count($this->caldavBackend->getShares(1))); @@ -113,30 +114,27 @@ class SharingPluginTest extends \Sabre\DAVServerTest { )); $this->assertEquals(array( - 403 => array( - '{DAV:}foo' => null, - ), - 'href' => 'calendars/user1/cal3', + '{DAV:}foo' => 403, ), $result); } function testUnknownMethodNoPOST() { - $request = new HTTP\Request(array( + $request = HTTP\Sapi::createFromServerArray(array( 'REQUEST_METHOD' => 'PATCH', 'REQUEST_URI' => '/', )); $response = $this->request($request); - $this->assertEquals('HTTP/1.1 501 Not Implemented', $response->status, $response->body); + $this->assertEquals(501, $response->status, $response->body); } function testUnknownMethodNoXML() { - $request = new HTTP\Request(array( + $request = HTTP\Sapi::createFromServerArray(array( 'REQUEST_METHOD' => 'POST', 'REQUEST_URI' => '/', 'CONTENT_TYPE' => 'text/plain', @@ -144,13 +142,13 @@ class SharingPluginTest extends \Sabre\DAVServerTest { $response = $this->request($request); - $this->assertEquals('HTTP/1.1 501 Not Implemented', $response->status, $response->body); + $this->assertEquals(501, $response->status, $response->body); } function testUnknownMethodNoNode() { - $request = new HTTP\Request(array( + $request = HTTP\Sapi::createFromServerArray(array( 'REQUEST_METHOD' => 'POST', 'REQUEST_URI' => '/foo', 'CONTENT_TYPE' => 'text/xml', @@ -158,13 +156,13 @@ class SharingPluginTest extends \Sabre\DAVServerTest { $response = $this->request($request); - $this->assertEquals('HTTP/1.1 501 Not Implemented', $response->status, $response->body); + $this->assertEquals(501, $response->status, $response->body); } function testShareRequest() { - $request = new HTTP\Request(array( + $request = HTTP\Sapi::createFromServerArray(array( 'REQUEST_METHOD' => 'POST', 'REQUEST_URI' => '/calendars/user1/cal1', 'CONTENT_TYPE' => 'text/xml', @@ -187,7 +185,7 @@ RRR; $request->setBody($xml); $response = $this->request($request); - $this->assertEquals('HTTP/1.1 200 OK', $response->status, $response->body); + $this->assertEquals(200, $response->status, $response->body); $this->assertEquals(array(array( 'href' => 'mailto:joe@example.org', @@ -207,7 +205,7 @@ RRR; function testShareRequestNoShareableCalendar() { - $request = new HTTP\Request(array( + $request = HTTP\Sapi::createFromServerArray(array( 'REQUEST_METHOD' => 'POST', 'REQUEST_URI' => '/calendars/user1/cal2', 'CONTENT_TYPE' => 'text/xml', @@ -229,13 +227,13 @@ RRR; $request->setBody($xml); $response = $this->request($request); - $this->assertEquals('HTTP/1.1 501 Not Implemented', $response->status, $response->body); + $this->assertEquals(501, $response->status, $response->body); } function testInviteReply() { - $request = new HTTP\Request(array( + $request = HTTP\Sapi::createFromServerArray(array( 'REQUEST_METHOD' => 'POST', 'REQUEST_URI' => '/calendars/user1', 'CONTENT_TYPE' => 'text/xml', @@ -250,13 +248,13 @@ RRR; $request->setBody($xml); $response = $this->request($request); - $this->assertEquals('HTTP/1.1 200 OK', $response->status, $response->body); + $this->assertEquals(200, $response->status, $response->body); } function testInviteBadXML() { - $request = new HTTP\Request(array( + $request = HTTP\Sapi::createFromServerArray(array( 'REQUEST_METHOD' => 'POST', 'REQUEST_URI' => '/calendars/user1', 'CONTENT_TYPE' => 'text/xml', @@ -268,13 +266,13 @@ RRR; '; $request->setBody($xml); $response = $this->request($request); - $this->assertEquals('HTTP/1.1 400 Bad request', $response->status, $response->body); + $this->assertEquals(400, $response->status, $response->body); } function testInviteWrongUrl() { - $request = new HTTP\Request(array( + $request = HTTP\Sapi::createFromServerArray(array( 'REQUEST_METHOD' => 'POST', 'REQUEST_URI' => '/calendars/user1/cal1', 'CONTENT_TYPE' => 'text/xml', @@ -287,7 +285,7 @@ RRR; '; $request->setBody($xml); $response = $this->request($request); - $this->assertEquals('HTTP/1.1 501 Not Implemented', $response->status, $response->body); + $this->assertEquals(501, $response->status, $response->body); // If the plugin did not handle this request, it must ensure that the // body is still accessible by other plugins. @@ -297,7 +295,7 @@ RRR; function testPublish() { - $request = new HTTP\Request(array( + $request = HTTP\Sapi::createFromServerArray(array( 'REQUEST_METHOD' => 'POST', 'REQUEST_URI' => '/calendars/user1/cal1', 'CONTENT_TYPE' => 'text/xml', @@ -310,13 +308,13 @@ RRR; $request->setBody($xml); $response = $this->request($request); - $this->assertEquals('HTTP/1.1 202 Accepted', $response->status, $response->body); + $this->assertEquals(202, $response->status, $response->body); } function testUnpublish() { - $request = new HTTP\Request(array( + $request = HTTP\Sapi::createFromServerArray(array( 'REQUEST_METHOD' => 'POST', 'REQUEST_URI' => '/calendars/user1/cal1', 'CONTENT_TYPE' => 'text/xml', @@ -329,13 +327,13 @@ RRR; $request->setBody($xml); $response = $this->request($request); - $this->assertEquals('HTTP/1.1 200 OK', $response->status, $response->body); + $this->assertEquals(200, $response->status, $response->body); } function testPublishWrongUrl() { - $request = new HTTP\Request(array( + $request = HTTP\Sapi::createFromServerArray(array( 'REQUEST_METHOD' => 'POST', 'REQUEST_URI' => '/calendars/user1/cal2', 'CONTENT_TYPE' => 'text/xml', @@ -348,13 +346,13 @@ RRR; $request->setBody($xml); $response = $this->request($request); - $this->assertEquals('HTTP/1.1 501 Not Implemented', $response->status, $response->body); + $this->assertEquals(501, $response->status, $response->body); } function testUnpublishWrongUrl() { - $request = new HTTP\Request(array( + $request = HTTP\Sapi::createFromServerArray(array( 'REQUEST_METHOD' => 'POST', 'REQUEST_URI' => '/calendars/user1/cal2', 'CONTENT_TYPE' => 'text/xml', @@ -367,13 +365,13 @@ RRR; $request->setBody($xml); $response = $this->request($request); - $this->assertEquals('HTTP/1.1 501 Not Implemented', $response->status, $response->body); + $this->assertEquals(501, $response->status, $response->body); } function testUnknownXmlDoc() { - $request = new HTTP\Request(array( + $request = HTTP\Sapi::createFromServerArray(array( 'REQUEST_METHOD' => 'POST', 'REQUEST_URI' => '/calendars/user1/cal2', 'CONTENT_TYPE' => 'text/xml', @@ -385,7 +383,7 @@ RRR; $request->setBody($xml); $response = $this->request($request); - $this->assertEquals('HTTP/1.1 501 Not Implemented', $response->status, $response->body); + $this->assertEquals(501, $response->status, $response->body); } } diff --git a/vendor/sabre/dav/tests/Sabre/CalDAV/UserCalendarsSharedCalendarsTest.php b/vendor/sabre/dav/tests/Sabre/CalDAV/UserCalendarsSharedCalendarsTest.php deleted file mode 100644 index 4c3bae3a4..000000000 --- a/vendor/sabre/dav/tests/Sabre/CalDAV/UserCalendarsSharedCalendarsTest.php +++ /dev/null @@ -1,93 +0,0 @@ - 1, - 'principaluri' => 'principals/user1', - ), - array( - 'id' => 2, - '{http://calendarserver.org/ns/}shared-url' => 'calendars/owner/cal1', - '{http://sabredav.org/ns}owner-principal' => 'principal/owner', - '{http://sabredav.org/ns}read-only' => false, - 'principaluri' => 'principals/user1', - ), - ); - - $this->backend = new Backend\Mock( - $calendars, - array(), - array() - ); - - return new UserCalendars($this->backend, array( - 'uri' => 'principals/user1' - )); - - } - - function testSimple() { - - $instance = $this->getInstance(); - $this->assertEquals('user1', $instance->getName()); - - } - - function testGetChildren() { - - $instance = $this->getInstance(); - $children = $instance->getChildren(); - $this->assertEquals(4, count($children)); - - // Testing if we got all the objects back. - $hasShareable = false; - $hasShared = false; - $hasOutbox = false; - $hasNotifications = false; - - foreach($children as $child) { - - if ($child instanceof IShareableCalendar) { - $hasShareable = true; - } - if ($child instanceof ISharedCalendar) { - $hasShared = true; - } - if ($child instanceof Schedule\IOutbox) { - $hasOutbox = true; - } - if ($child instanceof Notifications\ICollection) { - $hasNotifications = true; - } - - } - if (!$hasShareable) $this->fail('Missing node!'); - if (!$hasShared) $this->fail('Missing node!'); - if (!$hasOutbox) $this->fail('Missing node!'); - if (!$hasNotifications) $this->fail('Missing node!'); - - } - - function testShareReply() { - - $instance = $this->getInstance(); - $instance->shareReply('uri', SharingPlugin::STATUS_DECLINED, 'curi', '1'); - - } - -} diff --git a/vendor/sabre/dav/tests/Sabre/CalDAV/UserCalendarsTest.php b/vendor/sabre/dav/tests/Sabre/CalDAV/UserCalendarsTest.php deleted file mode 100644 index 453c872e5..000000000 --- a/vendor/sabre/dav/tests/Sabre/CalDAV/UserCalendarsTest.php +++ /dev/null @@ -1,207 +0,0 @@ -markTestSkipped('SQLite driver is not available'); - $this->backend = TestUtil::getBackend(); - $this->usercalendars = new UserCalendars($this->backend, array( - 'uri' => 'principals/user1' - )); - - } - - function testSimple() { - - $this->assertEquals('user1',$this->usercalendars->getName()); - - } - - /** - * @expectedException Sabre\DAV\Exception\NotFound - * @depends testSimple - */ - function testGetChildNotFound() { - - $this->usercalendars->getChild('randomname'); - - } - - function testChildExists() { - - $this->assertFalse($this->usercalendars->childExists('foo')); - $this->assertTrue($this->usercalendars->childExists('UUID-123467')); - - } - - function testGetOwner() { - - $this->assertEquals('principals/user1', $this->usercalendars->getOwner()); - - } - - function testGetGroup() { - - $this->assertNull($this->usercalendars->getGroup()); - - } - - function testGetACL() { - - $expected = array( - array( - 'privilege' => '{DAV:}read', - 'principal' => 'principals/user1', - 'protected' => true, - ), - array( - 'privilege' => '{DAV:}write', - 'principal' => 'principals/user1', - 'protected' => true, - ), - array( - 'privilege' => '{DAV:}read', - 'principal' => 'principals/user1/calendar-proxy-write', - 'protected' => true, - ), - array( - 'privilege' => '{DAV:}write', - 'principal' => 'principals/user1/calendar-proxy-write', - 'protected' => true, - ), - array( - 'privilege' => '{DAV:}read', - 'principal' => 'principals/user1/calendar-proxy-read', - 'protected' => true, - ), - ); - $this->assertEquals($expected, $this->usercalendars->getACL()); - - } - - /** - * @expectedException Sabre\DAV\Exception\MethodNotAllowed - */ - function testSetACL() { - - $this->usercalendars->setACL(array()); - - } - - /** - * @expectedException Sabre\DAV\Exception\Forbidden - * @depends testSimple - */ - function testSetName() { - - $this->usercalendars->setName('bla'); - - } - - /** - * @expectedException Sabre\DAV\Exception\Forbidden - * @depends testSimple - */ - function testDelete() { - - $this->usercalendars->delete(); - - } - - /** - * @depends testSimple - */ - function testGetLastModified() { - - $this->assertNull($this->usercalendars->getLastModified()); - - } - - /** - * @expectedException Sabre\DAV\Exception\MethodNotAllowed - * @depends testSimple - */ - function testCreateFile() { - - $this->usercalendars->createFile('bla'); - - } - - - /** - * @expectedException Sabre\DAV\Exception\MethodNotAllowed - * @depends testSimple - */ - function testCreateDirectory() { - - $this->usercalendars->createDirectory('bla'); - - } - - /** - * @depends testSimple - */ - function testCreateExtendedCollection() { - - $result = $this->usercalendars->createExtendedCollection('newcalendar', array('{DAV:}collection', '{urn:ietf:params:xml:ns:caldav}calendar'), array()); - $this->assertNull($result); - $cals = $this->backend->getCalendarsForUser('principals/user1'); - $this->assertEquals(3,count($cals)); - - } - - /** - * @expectedException Sabre\DAV\Exception\InvalidResourceType - * @depends testSimple - */ - function testCreateExtendedCollectionBadResourceType() { - - $this->usercalendars->createExtendedCollection('newcalendar', array('{DAV:}collection','{DAV:}blabla'), array()); - - } - - /** - * @expectedException Sabre\DAV\Exception\InvalidResourceType - * @depends testSimple - */ - function testCreateExtendedCollectionNotACalendar() { - - $this->usercalendars->createExtendedCollection('newcalendar', array('{DAV:}collection'), array()); - - } - - function testGetSupportedPrivilegesSet() { - - $this->assertNull($this->usercalendars->getSupportedPrivilegeSet()); - - } - - /** - * @expectedException Sabre\DAV\Exception\NotImplemented - */ - function testShareReplyFail() { - - $this->usercalendars->shareReply('uri', SharingPlugin::STATUS_DECLINED, 'curi', '1'); - - } - -} diff --git a/vendor/sabre/dav/tests/Sabre/CalDAV/ValidateICalTest.php b/vendor/sabre/dav/tests/Sabre/CalDAV/ValidateICalTest.php index 6634b9c3b..be166d9e6 100644 --- a/vendor/sabre/dav/tests/Sabre/CalDAV/ValidateICalTest.php +++ b/vendor/sabre/dav/tests/Sabre/CalDAV/ValidateICalTest.php @@ -26,24 +26,25 @@ class ValidateICalTest extends \PHPUnit_Framework_TestCase { 'id' => 'calendar1', 'principaluri' => 'principals/admin', 'uri' => 'calendar1', - '{urn:ietf:params:xml:ns:caldav}supported-calendar-component-set' => new Property\SupportedCalendarComponentSet( array('VEVENT','VTODO','VJOURNAL') ), + '{urn:ietf:params:xml:ns:caldav}supported-calendar-component-set' => new Xml\Property\SupportedCalendarComponentSet( ['VEVENT','VTODO','VJOURNAL'] ), ), array( 'id' => 'calendar2', 'principaluri' => 'principals/admin', 'uri' => 'calendar2', - '{urn:ietf:params:xml:ns:caldav}supported-calendar-component-set' => new Property\SupportedCalendarComponentSet( array('VTODO','VJOURNAL') ), + '{urn:ietf:params:xml:ns:caldav}supported-calendar-component-set' => new Xml\Property\SupportedCalendarComponentSet( ['VTODO','VJOURNAL'] ), ) ); - $this->calBackend = new Backend\Mock($calendars,array()); + $this->calBackend = new Backend\Mock($calendars, []); $principalBackend = new DAVACL\PrincipalBackend\Mock(); - $tree = array( - new CalendarRootNode($principalBackend, $this->calBackend), - ); + $tree = [ + new CalendarRoot($principalBackend, $this->calBackend), + ]; $this->server = new DAV\Server($tree); + $this->server->sapi = new HTTP\SapiMock(); $this->server->debugExceptions = true; $plugin = new Plugin(); @@ -65,20 +66,20 @@ class ValidateICalTest extends \PHPUnit_Framework_TestCase { function testCreateFile() { - $request = new HTTP\Request(array( + $request = HTTP\Sapi::createFromServerArray(array( 'REQUEST_METHOD' => 'PUT', 'REQUEST_URI' => '/calendars/admin/calendar1/blabla.ics', )); $response = $this->request($request); - $this->assertEquals('HTTP/1.1 415 Unsupported Media Type', $response->status); + $this->assertEquals(415, $response->status); } function testCreateFileValid() { - $request = new HTTP\Request(array( + $request = HTTP\Sapi::createFromServerArray(array( 'REQUEST_METHOD' => 'PUT', 'REQUEST_URI' => '/calendars/admin/calendar1/blabla.ics', )); @@ -86,11 +87,18 @@ class ValidateICalTest extends \PHPUnit_Framework_TestCase { $response = $this->request($request); - $this->assertEquals('HTTP/1.1 201 Created', $response->status, 'Incorrect status returned! Full response body: ' . $response->body); + $this->assertEquals(201, $response->status, 'Incorrect status returned! Full response body: ' . $response->body); + $this->assertEquals(array( + 'X-Sabre-Version' => [DAV\Version::VERSION], + 'Content-Length' => ['0'], + 'ETag' => ['"' . md5("BEGIN:VCALENDAR\r\nBEGIN:VEVENT\r\nUID:foo\r\nEND:VEVENT\r\nEND:VCALENDAR\r\n") . '"'], + ), $response->getHeaders()); + $expected = array( 'uri' => 'blabla.ics', 'calendardata' => "BEGIN:VCALENDAR\r\nBEGIN:VEVENT\r\nUID:foo\r\nEND:VEVENT\r\nEND:VCALENDAR\r\n", 'calendarid' => 'calendar1', + 'lastmodified' => null, ); $this->assertEquals($expected, $this->calBackend->getCalendarObject('calendar1','blabla.ics')); @@ -99,7 +107,7 @@ class ValidateICalTest extends \PHPUnit_Framework_TestCase { function testCreateFileNoComponents() { - $request = new HTTP\Request(array( + $request = HTTP\Sapi::createFromServerArray(array( 'REQUEST_METHOD' => 'PUT', 'REQUEST_URI' => '/calendars/admin/calendar1/blabla.ics', )); @@ -107,13 +115,13 @@ class ValidateICalTest extends \PHPUnit_Framework_TestCase { $response = $this->request($request); - $this->assertEquals('HTTP/1.1 400 Bad request', $response->status, 'Incorrect status returned! Full response body: ' . $response->body); + $this->assertEquals(400, $response->status, 'Incorrect status returned! Full response body: ' . $response->body); } function testCreateFileNoUID() { - $request = new HTTP\Request(array( + $request = HTTP\Sapi::createFromServerArray(array( 'REQUEST_METHOD' => 'PUT', 'REQUEST_URI' => '/calendars/admin/calendar1/blabla.ics', )); @@ -121,13 +129,13 @@ class ValidateICalTest extends \PHPUnit_Framework_TestCase { $response = $this->request($request); - $this->assertEquals('HTTP/1.1 400 Bad request', $response->status, 'Incorrect status returned! Full response body: ' . $response->body); + $this->assertEquals(400, $response->status, 'Incorrect status returned! Full response body: ' . $response->body); } function testCreateFileVCard() { - $request = new HTTP\Request(array( + $request = HTTP\Sapi::createFromServerArray(array( 'REQUEST_METHOD' => 'PUT', 'REQUEST_URI' => '/calendars/admin/calendar1/blabla.ics', )); @@ -135,13 +143,13 @@ class ValidateICalTest extends \PHPUnit_Framework_TestCase { $response = $this->request($request); - $this->assertEquals('HTTP/1.1 415 Unsupported Media Type', $response->status, 'Incorrect status returned! Full response body: ' . $response->body); + $this->assertEquals(415, $response->status, 'Incorrect status returned! Full response body: ' . $response->body); } function testCreateFile2Components() { - $request = new HTTP\Request(array( + $request = HTTP\Sapi::createFromServerArray(array( 'REQUEST_METHOD' => 'PUT', 'REQUEST_URI' => '/calendars/admin/calendar1/blabla.ics', )); @@ -149,13 +157,13 @@ class ValidateICalTest extends \PHPUnit_Framework_TestCase { $response = $this->request($request); - $this->assertEquals('HTTP/1.1 400 Bad request', $response->status, 'Incorrect status returned! Full response body: ' . $response->body); + $this->assertEquals(400, $response->status, 'Incorrect status returned! Full response body: ' . $response->body); } function testCreateFile2UIDS() { - $request = new HTTP\Request(array( + $request = HTTP\Sapi::createFromServerArray(array( 'REQUEST_METHOD' => 'PUT', 'REQUEST_URI' => '/calendars/admin/calendar1/blabla.ics', )); @@ -163,13 +171,13 @@ class ValidateICalTest extends \PHPUnit_Framework_TestCase { $response = $this->request($request); - $this->assertEquals('HTTP/1.1 400 Bad request', $response->status, 'Incorrect status returned! Full response body: ' . $response->body); + $this->assertEquals(400, $response->status, 'Incorrect status returned! Full response body: ' . $response->body); } function testCreateFileWrongComponent() { - $request = new HTTP\Request(array( + $request = HTTP\Sapi::createFromServerArray(array( 'REQUEST_METHOD' => 'PUT', 'REQUEST_URI' => '/calendars/admin/calendar1/blabla.ics', )); @@ -177,28 +185,28 @@ class ValidateICalTest extends \PHPUnit_Framework_TestCase { $response = $this->request($request); - $this->assertEquals('HTTP/1.1 400 Bad request', $response->status, 'Incorrect status returned! Full response body: ' . $response->body); + $this->assertEquals(400, $response->status, 'Incorrect status returned! Full response body: ' . $response->body); } function testUpdateFile() { $this->calBackend->createCalendarObject('calendar1','blabla.ics','foo'); - $request = new HTTP\Request(array( + $request = HTTP\Sapi::createFromServerArray(array( 'REQUEST_METHOD' => 'PUT', 'REQUEST_URI' => '/calendars/admin/calendar1/blabla.ics', )); $response = $this->request($request); - $this->assertEquals('HTTP/1.1 415 Unsupported Media Type', $response->status); + $this->assertEquals(415, $response->status); } function testUpdateFileParsableBody() { $this->calBackend->createCalendarObject('calendar1','blabla.ics','foo'); - $request = new HTTP\Request(array( + $request = HTTP\Sapi::createFromServerArray(array( 'REQUEST_METHOD' => 'PUT', 'REQUEST_URI' => '/calendars/admin/calendar1/blabla.ics', )); @@ -207,12 +215,13 @@ class ValidateICalTest extends \PHPUnit_Framework_TestCase { $response = $this->request($request); - $this->assertEquals('HTTP/1.1 204 No Content', $response->status); + $this->assertEquals(204, $response->status); $expected = array( 'uri' => 'blabla.ics', 'calendardata' => $body, 'calendarid' => 'calendar1', + 'lastmodified' => null, ); $this->assertEquals($expected, $this->calBackend->getCalendarObject('calendar1','blabla.ics')); @@ -221,7 +230,7 @@ class ValidateICalTest extends \PHPUnit_Framework_TestCase { function testCreateFileInvalidComponent() { - $request = new HTTP\Request(array( + $request = HTTP\Sapi::createFromServerArray(array( 'REQUEST_METHOD' => 'PUT', 'REQUEST_URI' => '/calendars/admin/calendar2/blabla.ics', )); @@ -229,14 +238,14 @@ class ValidateICalTest extends \PHPUnit_Framework_TestCase { $response = $this->request($request); - $this->assertEquals('HTTP/1.1 403 Forbidden', $response->status, 'Incorrect status returned! Full response body: ' . $response->body); + $this->assertEquals(403, $response->status, 'Incorrect status returned! Full response body: ' . $response->body); } function testUpdateFileInvalidComponent() { $this->calBackend->createCalendarObject('calendar2','blabla.ics','foo'); - $request = new HTTP\Request(array( + $request = HTTP\Sapi::createFromServerArray(array( 'REQUEST_METHOD' => 'PUT', 'REQUEST_URI' => '/calendars/admin/calendar2/blabla.ics', )); @@ -244,7 +253,29 @@ class ValidateICalTest extends \PHPUnit_Framework_TestCase { $response = $this->request($request); - $this->assertEquals('HTTP/1.1 403 Forbidden', $response->status, 'Incorrect status returned! Full response body: ' . $response->body); + $this->assertEquals(403, $response->status, 'Incorrect status returned! Full response body: ' . $response->body); + + } + + /** + * What we are testing here, is if we send in a latin1 character, the + * server should automatically transform this into UTF-8. + * + * More importantly. If any transformation happens, the etag must no longer + * be returned by the server. + */ + function testCreateFileModified() { + + $request = HTTP\Sapi::createFromServerArray(array( + 'REQUEST_METHOD' => 'PUT', + 'REQUEST_URI' => '/calendars/admin/calendar1/blabla.ics', + )); + $request->setBody("BEGIN:VCALENDAR\r\nBEGIN:VEVENT\r\nUID:foo\r\nSUMMARY:Meeting in M\xfcnster\r\nEND:VEVENT\r\nEND:VCALENDAR\r\n"); + + $response = $this->request($request); + + $this->assertEquals(201, $response->status, 'Incorrect status returned! Full response body: ' . $response->body); + $this->assertNull($response->getHeader('ETag')); } } diff --git a/vendor/sabre/dav/tests/Sabre/CalDAV/VersionTest.php b/vendor/sabre/dav/tests/Sabre/CalDAV/VersionTest.php deleted file mode 100644 index a4e093e35..000000000 --- a/vendor/sabre/dav/tests/Sabre/CalDAV/VersionTest.php +++ /dev/null @@ -1,17 +0,0 @@ -assertEquals(-1, version_compare('1.0.0',$v)); - - $s = Version::STABILITY; - $this->assertTrue($s == 'alpha' || $s == 'beta' || $s =='stable'); - - } - -} diff --git a/vendor/sabre/dav/tests/Sabre/CardDAV/AbstractPluginTest.php b/vendor/sabre/dav/tests/Sabre/CardDAV/AbstractPluginTest.php index 94081fc8b..a123099a0 100644 --- a/vendor/sabre/dav/tests/Sabre/CardDAV/AbstractPluginTest.php +++ b/vendor/sabre/dav/tests/Sabre/CardDAV/AbstractPluginTest.php @@ -4,6 +4,7 @@ namespace Sabre\CardDAV; use Sabre\DAV; use Sabre\DAVACL; +use Sabre\HTTP; abstract class AbstractPluginTest extends \PHPUnit_Framework_TestCase { @@ -33,6 +34,7 @@ abstract class AbstractPluginTest extends \PHPUnit_Framework_TestCase { $this->plugin = new Plugin(); $this->plugin->directories = array('directory'); $this->server = new DAV\Server($tree); + $this->server->sapi = new HTTP\SapiMock(); $this->server->addPlugin($this->plugin); $this->server->debugExceptions = true; diff --git a/vendor/sabre/dav/tests/Sabre/CardDAV/AddressBookQueryParserTest.php b/vendor/sabre/dav/tests/Sabre/CardDAV/AddressBookQueryParserTest.php deleted file mode 100644 index 51bea6c6c..000000000 --- a/vendor/sabre/dav/tests/Sabre/CardDAV/AddressBookQueryParserTest.php +++ /dev/null @@ -1,329 +0,0 @@ -parse(); - return $q; - - } - - function testFilterBasic() { - - $xml = array( - '', - '', - ' ', - ' ', - ' ', - ' ', - ' ', - ' ', - '' - ); - - $q = $this->parse($xml); - - $this->assertEquals( - array('{DAV:}foo'), - $q->requestedProperties - ); - - $this->assertEquals( - array( - array( - 'name' => 'NICKNAME', - 'test' => 'anyof', - 'is-not-defined' => false, - 'param-filters' => array(), - 'text-matches' => array(), - ), - ), - $q->filters - ); - - $this->assertNull($q->limit); - $this->assertEquals('anyof', $q->test); - - } - - function testNoFilter() { - - // This is non-standard, but helps working around a KDE bug - $xml = array( - '', - '', - ' ', - ' ', - ' ', - '' - ); - - $q = $this->parse($xml); - - $this->assertEquals( - array('{DAV:}foo'), - $q->requestedProperties - ); - - $this->assertEquals( - array(), - $q->filters - ); - - $this->assertNull($q->limit); - $this->assertEquals('anyof', $q->test); - - } - - /** - * @expectedException Sabre\DAV\Exception\BadRequest - */ - function testFilterDoubleFilter() { - - $xml = array( - '', - '', - ' ', - ' ', - ' ', - ' ', - ' ', - ' ', - ' ', - ' ', - ' ', - '' - ); - - $q = $this->parse($xml); - - } - /** - * @expectedException Sabre\DAV\Exception\BadRequest - */ - function testFilterCorruptTest() { - - $xml = array( - '', - '', - ' ', - ' ', - ' ', - ' ', - ' ', - ' ', - '' - ); - - $q = $this->parse($xml); - - } - - function testPropFilter() { - - $xml = array( - '', - '', - ' ', - ' ', - ' ', - ' ', - ' ', - ' ', - ' ', - ' ', - ' ', - ' ', - ' 4', - '' - ); - - $q = $this->parse($xml); - - $this->assertEquals( - array( - array( - 'name' => 'NICKNAME', - 'test' => 'anyof', - 'is-not-defined' => false, - 'param-filters' => array(), - 'text-matches' => array(), - ), - array( - 'name' => 'EMAIL', - 'test' => 'allof', - 'is-not-defined' => false, - 'param-filters' => array(), - 'text-matches' => array(), - ), - array( - 'name' => 'FN', - 'test' => 'anyof', - 'is-not-defined' => true, - 'param-filters' => array(), - 'text-matches' => array(), - ), - ), - $q->filters - ); - - $this->assertEquals(4,$q->limit); - $this->assertEquals('allof', $q->test); - - } - - function testParamFilter() { - - $xml = array( - '', - '', - ' ', - ' ', - ' ', - ' ', - ' ', - ' ', - ' ', - ' ', - ' ', - ' ', - ' ', - '' - ); - - $q = $this->parse($xml); - - $this->assertEquals( - array( - array( - 'name' => 'NICKNAME', - 'test' => 'anyof', - 'is-not-defined' => false, - 'param-filters' => array( - array( - 'name' => 'BLA', - 'is-not-defined' => false, - 'text-match' => null - ), - array( - 'name' => 'BLA2', - 'is-not-defined' => true, - 'text-match' => null - ), - ), - 'text-matches' => array(), - ), - ), - $q->filters - ); - - } - - function testTextMatch() { - - $xml = array( - '', - '', - ' ', - ' ', - ' ', - ' ', - ' ', - ' evert', - ' evert', - ' rene', - ' e', - ' ', - ' foo', - ' ', - ' ', - ' ', - '' - ); - - $q = $this->parse($xml); - - $this->assertEquals( - array( - array( - 'name' => 'NICKNAME', - 'test' => 'anyof', - 'is-not-defined' => false, - 'param-filters' => array( - array( - 'name' => 'BLA', - 'is-not-defined' => false, - 'text-match' => array( - 'negate-condition' => false, - 'collation' => 'i;unicode-casemap', - 'match-type' => 'contains', - 'value' => 'foo', - ), - ), - ), - 'text-matches' => array( - array( - 'negate-condition' => false, - 'collation' => 'i;unicode-casemap', - 'match-type' => 'contains', - 'value' => 'evert', - ), - array( - 'negate-condition' => false, - 'collation' => 'i;octet', - 'match-type' => 'contains', - 'value' => 'evert', - ), - array( - 'negate-condition' => true, - 'collation' => 'i;unicode-casemap', - 'match-type' => 'contains', - 'value' => 'rene', - ), - array( - 'negate-condition' => false, - 'collation' => 'i;unicode-casemap', - 'match-type' => 'starts-with', - 'value' => 'e', - ), - ), - ), - ), - $q->filters - ); - - } - - /** - * @expectedException Sabre\DAV\Exception\BadRequest - */ - function testBadTextMatch() { - - $xml = array( - '', - '', - ' ', - ' ', - ' ', - ' ', - ' ', - ' evert', - ' ', - ' ', - '' - ); - - $q = $this->parse($xml); - - } -} diff --git a/vendor/sabre/dav/tests/Sabre/CardDAV/AddressBookQueryTest.php b/vendor/sabre/dav/tests/Sabre/CardDAV/AddressBookQueryTest.php index c79f7e877..478f6beb5 100644 --- a/vendor/sabre/dav/tests/Sabre/CardDAV/AddressBookQueryTest.php +++ b/vendor/sabre/dav/tests/Sabre/CardDAV/AddressBookQueryTest.php @@ -12,7 +12,7 @@ class AddressBookQueryTest extends AbstractPluginTest { function testQuery() { - $request = new HTTP\Request(array( + $request = HTTP\Sapi::createFromServerArray(array( 'REQUEST_METHOD' => 'REPORT', 'REQUEST_URI' => '/addressbooks/user1/book1', 'HTTP_DEPTH' => '1', @@ -37,7 +37,7 @@ class AddressBookQueryTest extends AbstractPluginTest { $this->server->exec(); - $this->assertEquals('HTTP/1.1 207 Multi-Status', $response->status, 'Incorrect status code. Full response body:' . $response->body); + $this->assertEquals(207, $response->status, 'Incorrect status code. Full response body:' . $response->body); // using the client for parsing $client = new DAV\Client(array('baseUri'=>'/')); @@ -62,7 +62,7 @@ class AddressBookQueryTest extends AbstractPluginTest { function testQueryDepth0() { - $request = new HTTP\Request(array( + $request = HTTP\Sapi::createFromServerArray(array( 'REQUEST_METHOD' => 'REPORT', 'REQUEST_URI' => '/addressbooks/user1/book1/card1', 'HTTP_DEPTH' => '0', @@ -87,7 +87,7 @@ class AddressBookQueryTest extends AbstractPluginTest { $this->server->exec(); - $this->assertEquals('HTTP/1.1 207 Multi-Status', $response->status, 'Incorrect status code. Full response body:' . $response->body); + $this->assertEquals(207, $response->status, 'Incorrect status code. Full response body:' . $response->body); // using the client for parsing $client = new DAV\Client(array('baseUri'=>'/')); @@ -107,7 +107,7 @@ class AddressBookQueryTest extends AbstractPluginTest { function testQueryNoMatch() { - $request = new HTTP\Request(array( + $request = HTTP\Sapi::createFromServerArray(array( 'REQUEST_METHOD' => 'REPORT', 'REQUEST_URI' => '/addressbooks/user1/book1', 'HTTP_DEPTH' => '1', @@ -132,7 +132,7 @@ class AddressBookQueryTest extends AbstractPluginTest { $this->server->exec(); - $this->assertEquals('HTTP/1.1 207 Multi-Status', $response->status, 'Incorrect status code. Full response body:' . $response->body); + $this->assertEquals(207, $response->status, 'Incorrect status code. Full response body:' . $response->body); // using the client for parsing $client = new DAV\Client(array('baseUri'=>'/')); @@ -145,7 +145,7 @@ class AddressBookQueryTest extends AbstractPluginTest { function testQueryLimit() { - $request = new HTTP\Request(array( + $request = HTTP\Sapi::createFromServerArray(array( 'REQUEST_METHOD' => 'REPORT', 'REQUEST_URI' => '/addressbooks/user1/book1', 'HTTP_DEPTH' => '1', @@ -171,7 +171,7 @@ class AddressBookQueryTest extends AbstractPluginTest { $this->server->exec(); - $this->assertEquals('HTTP/1.1 207 Multi-Status', $response->status, 'Incorrect status code. Full response body:' . $response->body); + $this->assertEquals(207, $response->status, 'Incorrect status code. Full response body:' . $response->body); // using the client for parsing $client = new DAV\Client(array('baseUri'=>'/')); @@ -189,4 +189,122 @@ class AddressBookQueryTest extends AbstractPluginTest { } + function testJson() { + + $request = new HTTP\Request( + 'REPORT', + '/addressbooks/user1/book1/card1', + ['Depth' => '0'] + ); + + $request->setBody( +' + + + + + +' + ); + + $response = new HTTP\ResponseMock(); + + $this->server->httpRequest = $request; + $this->server->httpResponse = $response; + + $this->server->exec(); + + $this->assertEquals(207, $response->status, 'Incorrect status code. Full response body:' . $response->body); + + // using the client for parsing + $client = new DAV\Client(array('baseUri'=>'/')); + + $result = $client->parseMultiStatus($response->body); + + $vobjVersion = \Sabre\VObject\Version::VERSION; + + $this->assertEquals(array( + '/addressbooks/user1/book1/card1' => array( + 200 => array( + '{DAV:}getetag' => '"' . md5("BEGIN:VCARD\nVERSION:3.0\nUID:12345\nEND:VCARD"). '"', + '{urn:ietf:params:xml:ns:carddav}address-data' => '["vcard",[["version",{},"text","4.0"],["prodid",{},"text","-\/\/Sabre\/\/Sabre VObject ' . $vobjVersion . '\/\/EN"],["uid",{},"text","12345"]]]', + ), + ), + ), $result); + + } + + function testVCard4() { + + $request = new HTTP\Request( + 'REPORT', + '/addressbooks/user1/book1/card1', + ['Depth' => '0'] + ); + + $request->setBody( +' + + + + + +' + ); + + $response = new HTTP\ResponseMock(); + + $this->server->httpRequest = $request; + $this->server->httpResponse = $response; + + $this->server->exec(); + + $this->assertEquals(207, $response->status, 'Incorrect status code. Full response body:' . $response->body); + + // using the client for parsing + $client = new DAV\Client(array('baseUri'=>'/')); + + $result = $client->parseMultiStatus($response->body); + + $vobjVersion = \Sabre\VObject\Version::VERSION; + + $this->assertEquals(array( + '/addressbooks/user1/book1/card1' => array( + 200 => array( + '{DAV:}getetag' => '"' . md5("BEGIN:VCARD\nVERSION:3.0\nUID:12345\nEND:VCARD"). '"', + '{urn:ietf:params:xml:ns:carddav}address-data' => "BEGIN:VCARD\r\nVERSION:4.0\r\nPRODID:-//Sabre//Sabre VObject $vobjVersion//EN\r\nUID:12345\r\nEND:VCARD\r\n", + ), + ), + ), $result); + + } + + function testAddressBookDepth0() { + + $request = new HTTP\Request( + 'REPORT', + '/addressbooks/user1/book1', + ['Depth' => '0'] + ); + + $request->setBody( +' + + + + + +' + ); + + $response = new HTTP\ResponseMock(); + + $this->server->httpRequest = $request; + $this->server->httpResponse = $response; + + $this->server->exec(); + + $this->assertEquals(415, $response->status, 'Incorrect status code. Full response body:' . $response->body); + + } } diff --git a/vendor/sabre/dav/tests/Sabre/CardDAV/AddressBookRootTest.php b/vendor/sabre/dav/tests/Sabre/CardDAV/AddressBookRootTest.php index 6eaff5db0..fc20480f2 100644 --- a/vendor/sabre/dav/tests/Sabre/CardDAV/AddressBookRootTest.php +++ b/vendor/sabre/dav/tests/Sabre/CardDAV/AddressBookRootTest.php @@ -24,7 +24,7 @@ class AddressBookRootTest extends \PHPUnit_Framework_TestCase { $children = $root->getChildren(); $this->assertEquals(3, count($children)); - $this->assertInstanceOf('Sabre\\CardDAV\\UserAddressBooks', $children[0]); + $this->assertInstanceOf('Sabre\\CardDAV\\AddressBookHome', $children[0]); $this->assertEquals('user1', $children[0]->getName()); } diff --git a/vendor/sabre/dav/tests/Sabre/CardDAV/AddressBookTest.php b/vendor/sabre/dav/tests/Sabre/CardDAV/AddressBookTest.php index aac749b37..fe8ba9025 100644 --- a/vendor/sabre/dav/tests/Sabre/CardDAV/AddressBookTest.php +++ b/vendor/sabre/dav/tests/Sabre/CardDAV/AddressBookTest.php @@ -2,6 +2,7 @@ namespace Sabre\CardDAV; +use Sabre\DAV\PropPatch; require_once 'Sabre/CardDAV/Backend/Mock.php'; @@ -105,9 +106,11 @@ class AddressBookTest extends \PHPUnit_Framework_TestCase { function testUpdateProperties() { - $this->assertTrue( - $this->ab->updateProperties(array('{DAV:}displayname' => 'barrr')) - ); + $propPatch = new PropPatch([ + '{DAV:}displayname' => 'barrr', + ]); + $this->ab->propPatch($propPatch); + $this->assertTrue($propPatch->commit()); $this->assertEquals('barrr', $this->backend->addressBooks[0]['{DAV:}displayname']); @@ -158,5 +161,52 @@ class AddressBookTest extends \PHPUnit_Framework_TestCase { } + function testGetSyncTokenNoSyncSupport() { + + $this->assertNull($this->ab->getSyncToken()); + + } + function testGetChangesNoSyncSupport() { + + $this->assertNull($this->ab->getChanges(1,null)); + + } + + function testGetSyncToken() { + + if (!SABRE_HASSQLITE) { + $this->markTestSkipped('Sqlite is required for this test to run'); + } + $ab = new AddressBook(TestUtil::getBackend(), [ 'id' => 1, '{DAV:}sync-token' => 2]); + $this->assertEquals(2, $ab->getSyncToken()); + TestUtil::deleteSQLiteDB(); + } + + function testGetSyncToken2() { + + if (!SABRE_HASSQLITE) { + $this->markTestSkipped('Sqlite is required for this test to run'); + } + $ab = new AddressBook(TestUtil::getBackend(), [ 'id' => 1, '{http://sabredav.org/ns}sync-token' => 2]); + $this->assertEquals(2, $ab->getSyncToken()); + TestUtil::deleteSQLiteDB(); + } + + function testGetChanges() { + + if (!SABRE_HASSQLITE) { + $this->markTestSkipped('Sqlite is required for this test to run'); + } + $ab = new AddressBook(TestUtil::getBackend(), [ 'id' => 1, '{DAV:}sync-token' => 2]); + $this->assertEquals([ + 'syncToken' => 2, + 'modified' => [], + 'deleted' => [], + 'added' => ['UUID-2345'], + ], $ab->getChanges(1, 1)); + TestUtil::deleteSQLiteDB(); + + } + } diff --git a/vendor/sabre/dav/tests/Sabre/CardDAV/Backend/AbstractPDOTest.php b/vendor/sabre/dav/tests/Sabre/CardDAV/Backend/AbstractPDOTest.php index 623188d32..d2ec278be 100644 --- a/vendor/sabre/dav/tests/Sabre/CardDAV/Backend/AbstractPDOTest.php +++ b/vendor/sabre/dav/tests/Sabre/CardDAV/Backend/AbstractPDOTest.php @@ -3,6 +3,7 @@ namespace Sabre\CardDAV\Backend; use Sabre\CardDAV; +use Sabre\DAV\PropPatch; abstract class AbstractPDOTest extends \PHPUnit_Framework_TestCase { @@ -19,7 +20,10 @@ abstract class AbstractPDOTest extends \PHPUnit_Framework_TestCase { public function setUp() { - $this->backend = new PDO($this->getPDO()); + $pdo = $this->getPDO(); + $this->backend = new PDO($pdo); + $pdo->exec('INSERT INTO addressbooks (principaluri, displayname, uri, description, synctoken) VALUES ("principals/user1", "book1", "book1", "addressbook 1", 1)'); + $pdo->exec('INSERT INTO cards (addressbookid, carddata, uri, lastmodified, etag, size) VALUES (1, "card1", "card1", 0, "' . md5('card1') . '", 5)'); } @@ -35,7 +39,7 @@ abstract class AbstractPDOTest extends \PHPUnit_Framework_TestCase { '{DAV:}displayname' => 'book1', '{' . CardDAV\Plugin::NS_CARDDAV . '}addressbook-description' => 'addressbook 1', '{http://calendarserver.org/ns/}getctag' => 1, - '{' . CardDAV\Plugin::NS_CARDDAV . '}supported-address-data' => new CardDAV\Property\SupportedAddressData(), + '{http://sabredav.org/ns}sync-token' => 1 ) ); @@ -45,11 +49,14 @@ abstract class AbstractPDOTest extends \PHPUnit_Framework_TestCase { public function testUpdateAddressBookInvalidProp() { - $result = $this->backend->updateAddressBook(1, array( + $propPatch = new PropPatch([ '{DAV:}displayname' => 'updated', '{' . CardDAV\Plugin::NS_CARDDAV . '}addressbook-description' => 'updated', '{DAV:}foo' => 'bar', - )); + ]); + + $this->backend->updateAddressBook(1, $propPatch); + $result = $propPatch->commit(); $this->assertFalse($result); @@ -63,7 +70,7 @@ abstract class AbstractPDOTest extends \PHPUnit_Framework_TestCase { '{DAV:}displayname' => 'book1', '{' . CardDAV\Plugin::NS_CARDDAV . '}addressbook-description' => 'addressbook 1', '{http://calendarserver.org/ns/}getctag' => 1, - '{' . CardDAV\Plugin::NS_CARDDAV . '}supported-address-data' => new CardDAV\Property\SupportedAddressData(), + '{http://sabredav.org/ns}sync-token' => 1 ) ); @@ -73,9 +80,12 @@ abstract class AbstractPDOTest extends \PHPUnit_Framework_TestCase { public function testUpdateAddressBookNoProps() { - $result = $this->backend->updateAddressBook(1, array()); + $propPatch = new PropPatch([ + ]); - $this->assertFalse($result); + $this->backend->updateAddressBook(1, $propPatch); + $result = $propPatch->commit(); + $this->assertTrue($result); $result = $this->backend->getAddressBooksForUser('principals/user1'); @@ -87,7 +97,7 @@ abstract class AbstractPDOTest extends \PHPUnit_Framework_TestCase { '{DAV:}displayname' => 'book1', '{' . CardDAV\Plugin::NS_CARDDAV . '}addressbook-description' => 'addressbook 1', '{http://calendarserver.org/ns/}getctag' => 1, - '{' . CardDAV\Plugin::NS_CARDDAV . '}supported-address-data' => new CardDAV\Property\SupportedAddressData(), + '{http://sabredav.org/ns}sync-token' => 1 ) ); @@ -98,10 +108,13 @@ abstract class AbstractPDOTest extends \PHPUnit_Framework_TestCase { public function testUpdateAddressBookSuccess() { - $result = $this->backend->updateAddressBook(1, array( + $propPatch = new PropPatch([ '{DAV:}displayname' => 'updated', '{' . CardDAV\Plugin::NS_CARDDAV . '}addressbook-description' => 'updated', - )); + ]); + + $this->backend->updateAddressBook(1, $propPatch); + $result = $propPatch->commit(); $this->assertTrue($result); @@ -115,7 +128,7 @@ abstract class AbstractPDOTest extends \PHPUnit_Framework_TestCase { '{DAV:}displayname' => 'updated', '{' . CardDAV\Plugin::NS_CARDDAV . '}addressbook-description' => 'updated', '{http://calendarserver.org/ns/}getctag' => 2, - '{' . CardDAV\Plugin::NS_CARDDAV . '}supported-address-data' => new CardDAV\Property\SupportedAddressData(), + '{http://sabredav.org/ns}sync-token' => 2 ) ); @@ -158,7 +171,7 @@ abstract class AbstractPDOTest extends \PHPUnit_Framework_TestCase { '{DAV:}displayname' => 'book1', '{' . CardDAV\Plugin::NS_CARDDAV . '}addressbook-description' => 'addressbook 1', '{http://calendarserver.org/ns/}getctag' => 1, - '{' . CardDAV\Plugin::NS_CARDDAV . '}supported-address-data' => new CardDAV\Property\SupportedAddressData(), + '{http://sabredav.org/ns}sync-token' => 1, ), array( 'id' => 2, @@ -167,7 +180,7 @@ abstract class AbstractPDOTest extends \PHPUnit_Framework_TestCase { '{DAV:}displayname' => 'book2', '{' . CardDAV\Plugin::NS_CARDDAV . '}addressbook-description' => 'addressbook 2', '{http://calendarserver.org/ns/}getctag' => 1, - '{' . CardDAV\Plugin::NS_CARDDAV . '}supported-address-data' => new CardDAV\Property\SupportedAddressData(), + '{http://sabredav.org/ns}sync-token' => 1, ) ); $result = $this->backend->getAddressBooksForUser('principals/user1'); @@ -183,8 +196,9 @@ abstract class AbstractPDOTest extends \PHPUnit_Framework_TestCase { array( 'id' => 1, 'uri' => 'card1', - 'carddata' => 'card1', 'lastmodified' => 0, + 'etag' => '"' . md5('card1') . '"', + 'size' => 5 ) ); @@ -201,6 +215,8 @@ abstract class AbstractPDOTest extends \PHPUnit_Framework_TestCase { 'uri' => 'card1', 'carddata' => 'card1', 'lastmodified' => 0, + 'etag' => '"' . md5('card1') . '"', + 'size' => 5 ); $this->assertEquals($expected, $result); @@ -221,6 +237,53 @@ abstract class AbstractPDOTest extends \PHPUnit_Framework_TestCase { } + /** + * @depends testCreateCard + */ + public function testGetMultiple() { + + $result = $this->backend->createCard(1, 'card2', 'data2'); + $result = $this->backend->createCard(1, 'card3', 'data3'); + $check = [ + [ + 'id' => 1, + 'uri' => 'card1', + 'carddata' => 'card1', + 'lastmodified' => 0, + ], + [ + 'id' => 2, + 'uri' => 'card2', + 'carddata' => 'data2', + 'lastmodified' => time(), + ], + [ + 'id' => 3, + 'uri' => 'card3', + 'carddata' => 'data3', + 'lastmodified' => time(), + ], + ]; + + $result = $this->backend->getMultipleCards(1, ['card1','card2','card3']); + + foreach($check as $index=>$node) { + + foreach($node as $k=>$v) { + + if ($k!=='lastmodified') { + $this->assertEquals($v, $result[$index][$k]); + } else { + $this->assertTrue(isset($result[$index][$k])); + } + + } + + } + + + } + /** * @depends testGetCard */ @@ -245,5 +308,43 @@ abstract class AbstractPDOTest extends \PHPUnit_Framework_TestCase { $this->assertFalse($result); } + + function testGetChanges() { + + $backend = $this->backend; + $id = $backend->createAddressBook( + 'principals/user1', + 'bla', + [] + ); + $result = $backend->getChangesForAddressBook($id, null, 1); + + $this->assertEquals([ + 'syncToken' => 1, + "added" => [], + 'modified' => [], + 'deleted' => [], + ], $result); + + $currentToken = $result['syncToken']; + + $dummyCard = "BEGIN:VCARD\r\nEND:VCARD\r\n"; + + $backend->createCard($id, "card1.ics", $dummyCard); + $backend->createCard($id, "card2.ics", $dummyCard); + $backend->createCard($id, "card3.ics", $dummyCard); + $backend->updateCard($id, "card1.ics", $dummyCard); + $backend->deleteCard($id, "card2.ics"); + + $result = $backend->getChangesForAddressBook($id, $currentToken, 1); + + $this->assertEquals([ + 'syncToken' => 6, + 'modified' => ["card1.ics"], + 'deleted' => ["card2.ics"], + "added" => ["card3.ics"], + ], $result); + + } } diff --git a/vendor/sabre/dav/tests/Sabre/CardDAV/Backend/Mock.php b/vendor/sabre/dav/tests/Sabre/CardDAV/Backend/Mock.php index ab7ac4e6a..3f96d3c5d 100644 --- a/vendor/sabre/dav/tests/Sabre/CardDAV/Backend/Mock.php +++ b/vendor/sabre/dav/tests/Sabre/CardDAV/Backend/Mock.php @@ -48,18 +48,36 @@ class Mock extends AbstractBackend { } - function updateAddressBook($addressBookId, array $mutations) { + /** + * Updates properties for an address book. + * + * 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 documenation for more info and examples. + * + * @param string $addressBookId + * @param \Sabre\DAV\PropPatch $propPatch + * @return void + */ + public function updateAddressBook($addressBookId, \Sabre\DAV\PropPatch $propPatch) { foreach($this->addressBooks as &$book) { if ($book['id'] !== $addressBookId) continue; - foreach($mutations as $key=>$value) { - $book[$key] = $value; - } - return true; + $propPatch->handleRemaining(function($mutations) use (&$book) { + foreach($mutations as $key=>$value) { + $book[$key] = $value; + } + return true; + }); + } - return false; } diff --git a/vendor/sabre/dav/tests/Sabre/CardDAV/Backend/PDOMySQLTest.php b/vendor/sabre/dav/tests/Sabre/CardDAV/Backend/PDOMySQLTest.php index b2f871f6e..38cb655d0 100644 --- a/vendor/sabre/dav/tests/Sabre/CardDAV/Backend/PDOMySQLTest.php +++ b/vendor/sabre/dav/tests/Sabre/CardDAV/Backend/PDOMySQLTest.php @@ -16,42 +16,18 @@ class PDOMySQLTest extends AbstractPDOTest { $pdo = \Sabre\TestUtil::getMySQLDB(); if (!$pdo) $this->markTestSkipped('Could not connect to MySQL database'); - $pdo->query("DROP TABLE IF EXISTS addressbooks"); - $pdo->query("DROP TABLE IF EXISTS cards"); - $pdo->query(" -CREATE TABLE addressbooks ( - id INT(11) UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT, - principaluri VARCHAR(255), - displayname VARCHAR(255), - uri VARCHAR(100), - description TEXT, - ctag INT(11) UNSIGNED NOT NULL DEFAULT '1' -); -"); - - $pdo->query(" -INSERT INTO addressbooks - (principaluri, displayname, uri, description, ctag) -VALUES - ('principals/user1', 'book1', 'book1', 'addressbook 1', 1); -"); - - $pdo->query(" -CREATE TABLE cards ( - id INT(11) UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT, - addressbookid INT(11) UNSIGNED NOT NULL, - carddata TEXT, - uri VARCHAR(100), - lastmodified INT(11) UNSIGNED -); -"); - - $pdo->query(" -INSERT INTO cards - (addressbookid, carddata, uri, lastmodified) -VALUES - (1, 'card1', 'card1', 0); -"); + $pdo->query("DROP TABLE IF EXISTS addressbooks, cards, addressbookchanges"); + + $queries = explode( + ';', + file_get_contents(__DIR__ . '/../../../../examples/sql/mysql.addressbook.sql') + ); + + foreach($queries as $query) { + $query = trim($query," \r\n\t"); + if ($query) + $pdo->exec($query); + } return $pdo; } diff --git a/vendor/sabre/dav/tests/Sabre/CardDAV/Backend/PDOSqliteTest.php b/vendor/sabre/dav/tests/Sabre/CardDAV/Backend/PDOSqliteTest.php index a9bbb0bd1..5a4a7a327 100644 --- a/vendor/sabre/dav/tests/Sabre/CardDAV/Backend/PDOSqliteTest.php +++ b/vendor/sabre/dav/tests/Sabre/CardDAV/Backend/PDOSqliteTest.php @@ -18,48 +18,33 @@ class PDOSqliteTest extends AbstractPDOTest { */ function getPDO() { + return self::getSQLite(); + + } + + /** + * @return PDO + */ + static function getSQLite() { + if (!SABRE_HASSQLITE) $this->markTestSkipped('SQLite driver is not available'); $pdo = new \PDO('sqlite:'.SABRE_TEMPDIR.'/pdobackend'); $pdo->setAttribute(\PDO::ATTR_ERRMODE,\PDO::ERRMODE_EXCEPTION); $pdo->query("DROP TABLE IF EXISTS addressbooks"); + $pdo->query("DROP TABLE IF EXISTS addressbookchanges"); $pdo->query("DROP TABLE IF EXISTS cards"); - $pdo->query(" -CREATE TABLE addressbooks ( - id integer primary key asc, - principaluri text, - displayname text, - uri text, - description text, - ctag integer -); - -"); - - $pdo->query(" -INSERT INTO addressbooks - (principaluri, displayname, uri, description, ctag) -VALUES - ('principals/user1', 'book1', 'book1', 'addressbook 1', 1); -"); - - $pdo->query(" - -CREATE TABLE cards ( - id integer primary key asc, - addressbookid integer, - carddata text, - uri text, - lastmodified integer -); - -"); - $pdo->query(" -INSERT INTO cards - (addressbookid, carddata, uri, lastmodified) -VALUES - (1, 'card1', 'card1', 0); -"); + + $queries = explode( + ';', + file_get_contents(__DIR__ . '/../../../../examples/sql/sqlite.addressbooks.sql') + ); + + foreach($queries as $query) { + $query = trim($query," \r\n\t"); + if ($query) + $pdo->exec($query); + } return $pdo; diff --git a/vendor/sabre/dav/tests/Sabre/CardDAV/CardTest.php b/vendor/sabre/dav/tests/Sabre/CardDAV/CardTest.php index 438bd2ea5..cf8dbab0c 100644 --- a/vendor/sabre/dav/tests/Sabre/CardDAV/CardTest.php +++ b/vendor/sabre/dav/tests/Sabre/CardDAV/CardTest.php @@ -82,7 +82,7 @@ class CardTest extends \PHPUnit_Framework_TestCase { function testGetContentType() { - $this->assertEquals('text/x-vcard; charset=utf-8', $this->card->getContentType()); + $this->assertEquals('text/vcard; charset=utf-8', $this->card->getContentType()); } @@ -162,6 +162,37 @@ class CardTest extends \PHPUnit_Framework_TestCase { ), ), $this->card->getACL()); + } + function testOverrideACL() { + + $card = new Card( + $this->backend, + array( + 'uri' => 'book1', + 'id' => 'foo', + 'principaluri' => 'principals/user1', + ), + array( + 'uri' => 'card1', + 'addressbookid' => 'foo', + 'carddata' => 'card', + 'acl' => array( + array( + 'privilege' => '{DAV:}read', + 'principal' => 'principals/user1', + 'protected' => true, + ), + ), + ) + ); + $this->assertEquals(array( + array( + 'privilege' => '{DAV:}read', + 'principal' => 'principals/user1', + 'protected' => true, + ), + ), $card->getACL()); + } /** diff --git a/vendor/sabre/dav/tests/Sabre/CardDAV/MultiGetTest.php b/vendor/sabre/dav/tests/Sabre/CardDAV/MultiGetTest.php index 12922c6fd..b0ee45880 100644 --- a/vendor/sabre/dav/tests/Sabre/CardDAV/MultiGetTest.php +++ b/vendor/sabre/dav/tests/Sabre/CardDAV/MultiGetTest.php @@ -11,7 +11,7 @@ class MultiGetTest extends AbstractPluginTest { function testMultiGet() { - $request = new HTTP\Request(array( + $request = HTTP\Sapi::createFromServerArray(array( 'REQUEST_METHOD' => 'REPORT', 'REQUEST_URI' => '/addressbooks/user1/book1', )); @@ -34,7 +34,7 @@ class MultiGetTest extends AbstractPluginTest { $this->server->exec(); - $this->assertEquals('HTTP/1.1 207 Multi-Status', $response->status, 'Incorrect status code. Full response body:' . $response->body); + $this->assertEquals(207, $response->status, 'Incorrect status code. Full response body:' . $response->body); // using the client for parsing $client = new DAV\Client(array('baseUri'=>'/')); @@ -45,11 +45,55 @@ class MultiGetTest extends AbstractPluginTest { '/addressbooks/user1/book1/card1' => array( 200 => array( '{DAV:}getetag' => '"' . md5("BEGIN:VCARD\nVERSION:3.0\nUID:12345\nEND:VCARD") . '"', - '{urn:ietf:params:xml:ns:carddav}address-data' => "BEGIN:VCARD\nVERSION:3.0\nUID:12345\nEND:VCARD", + '{urn:ietf:params:xml:ns:carddav}address-data' => "BEGIN:VCARD\r\nVERSION:3.0\r\nUID:12345\r\nEND:VCARD\r\n", ) ) ), $result); } + function testMultiGetVCard4() { + + $request = HTTP\Sapi::createFromServerArray(array( + 'REQUEST_METHOD' => 'REPORT', + 'REQUEST_URI' => '/addressbooks/user1/book1', + )); + + $request->setBody( +' + + + + + + /addressbooks/user1/book1/card1 +' + ); + + $response = new HTTP\ResponseMock(); + + $this->server->httpRequest = $request; + $this->server->httpResponse = $response; + + $this->server->exec(); + + $this->assertEquals(207, $response->status, 'Incorrect status code. Full response body:' . $response->body); + + // using the client for parsing + $client = new DAV\Client(array('baseUri'=>'/')); + + $result = $client->parseMultiStatus($response->body); + + $prodId = "PRODID:-//Sabre//Sabre VObject " . \Sabre\VObject\Version::VERSION . "//EN"; + + $this->assertEquals(array( + '/addressbooks/user1/book1/card1' => array( + 200 => array( + '{DAV:}getetag' => '"' . md5("BEGIN:VCARD\nVERSION:3.0\nUID:12345\nEND:VCARD") . '"', + '{urn:ietf:params:xml:ns:carddav}address-data' => "BEGIN:VCARD\r\nVERSION:4.0\r\n$prodId\r\nUID:12345\r\nEND:VCARD\r\n", + ) + ) + ), $result); + + } } diff --git a/vendor/sabre/dav/tests/Sabre/CardDAV/PluginTest.php b/vendor/sabre/dav/tests/Sabre/CardDAV/PluginTest.php index 297ebf496..9c916350e 100644 --- a/vendor/sabre/dav/tests/Sabre/CardDAV/PluginTest.php +++ b/vendor/sabre/dav/tests/Sabre/CardDAV/PluginTest.php @@ -3,17 +3,16 @@ namespace Sabre\CardDAV; use Sabre\DAV; - -require_once 'Sabre/CardDAV/AbstractPluginTest.php'; +use Sabre\DAV\Xml\Property\Href; class PluginTest extends AbstractPluginTest { function testConstruct() { - $this->assertEquals('card', $this->server->xmlNamespaces[Plugin::NS_CARDDAV]); $this->assertEquals('{' . Plugin::NS_CARDDAV . '}addressbook', $this->server->resourceTypeMapping['Sabre\\CardDAV\\IAddressBook']); $this->assertTrue(in_array('addressbook', $this->plugin->getFeatures())); + $this->assertEquals('carddav', $this->plugin->getPluginInfo()['name']); } @@ -43,25 +42,6 @@ class PluginTest extends AbstractPluginTest { } - function testMeCardTest() { - - $result = $this->server->getProperties( - 'addressbooks/user1', - array( - '{http://calendarserver.org/ns/}me-card', - ) - ); - - $this->assertEquals( - array( - '{http://calendarserver.org/ns/}me-card' => - new DAV\Property\Href('addressbooks/user1/book1/vcard1.vcf') - ), - $result - ); - - } - function testDirectoryGateway() { $result = $this->server->getProperties('principals/user1', array('{' . Plugin::NS_CARDDAV . '}directory-gateway')); @@ -74,76 +54,50 @@ class PluginTest extends AbstractPluginTest { function testReportPassThrough() { - $this->assertNull($this->plugin->report('{DAV:}foo', new \DomDocument())); + $this->assertNull($this->plugin->report('{DAV:}foo', new \DomDocument(), '')); } function testHTMLActionsPanel() { $output = ''; - $r = $this->server->broadcastEvent('onHTMLActionsPanel', array($this->server->tree->getNodeForPath('addressbooks/user1'), &$output)); + $r = $this->server->emit('onHTMLActionsPanel', [$this->server->tree->getNodeForPath('addressbooks/user1'), &$output]); $this->assertFalse($r); $this->assertTrue(!!strpos($output,'Display name')); } - function testBrowserPostAction() { + function testAddressbookPluginProperties() { - $r = $this->server->broadcastEvent('onBrowserPostAction', array('addressbooks/user1', 'mkaddressbook', array( - 'name' => 'NEWADDRESSBOOK', - '{DAV:}displayname' => 'foo', - ))); - $this->assertFalse($r); + $ns = '{' . Plugin::NS_CARDDAV . '}'; + $propFind = new DAV\PropFind('addressbooks/user1/book1', [ + $ns . 'supported-address-data', + $ns . 'supported-collation-set', + ]); + $node = $this->server->tree->getNodeForPath('addressbooks/user1/book1'); + $this->plugin->propFindEarly($propFind, $node); - $addressbooks = $this->backend->getAddressBooksforUser('principals/user1'); - $this->assertEquals(2, count($addressbooks)); + $this->assertInstanceOf( + 'Sabre\\CardDAV\\Xml\\Property\\SupportedAddressData', + $propFind->get($ns . 'supported-address-data') + ); + $this->assertInstanceOf( + 'Sabre\\CardDAV\\Xml\\Property\\SupportedCollationSet', + $propFind->get($ns . 'supported-collation-set') + ); - $newAddressBook = null; - foreach($addressbooks as $addressbook) { - if ($addressbook['uri'] === 'NEWADDRESSBOOK') { - $newAddressBook = $addressbook; - break; - } - } - if (!$newAddressBook) - $this->fail('Could not find newly created addressbook'); } - function testUpdatePropertiesMeCard() { + function testGetTransform() { - $result = $this->server->updateProperties('addressbooks/user1', array( - '{http://calendarserver.org/ns/}me-card' => new DAV\Property\Href('/addressbooks/user1/book1/vcard2',true), - )); + $request = new \Sabre\HTTP\Request('GET', '/addressbooks/user1/book1/card1', ['Accept: application/vcard+json']); + $response = new \Sabre\HTTP\ResponseMock(); + $this->server->invokeMethod($request, $response); - $this->assertEquals( - array( - 'href' => 'addressbooks/user1', - 200 => array( - '{http://calendarserver.org/ns/}me-card' => null, - ), - ), - $result - ); + $this->assertEquals(200, $response->getStatus()); } - function testUpdatePropertiesMeCardBadValue() { - - $result = $this->server->updateProperties('addressbooks/user1', array( - '{http://calendarserver.org/ns/}me-card' => new DAV\Property\HrefList(array()), - )); - - $this->assertEquals( - array( - 'href' => 'addressbooks/user1', - 400 => array( - '{http://calendarserver.org/ns/}me-card' => null, - ), - ), - $result - ); - - } } diff --git a/vendor/sabre/dav/tests/Sabre/CardDAV/Property/SupportedAddressDataTest.php b/vendor/sabre/dav/tests/Sabre/CardDAV/Property/SupportedAddressDataTest.php deleted file mode 100644 index a0e4130d5..000000000 --- a/vendor/sabre/dav/tests/Sabre/CardDAV/Property/SupportedAddressDataTest.php +++ /dev/null @@ -1,44 +0,0 @@ -createElementNS(CardDAV\Plugin::NS_CARDDAV, 'card:root'); - $root->setAttribute('xmlns:d','DAV:'); - - $doc->appendChild($root); - $server = new DAV\Server(); - - $property->serialize($server, $root); - - $xml = $doc->saveXML(); - - $this->assertEquals( -' -' . -'' . -//'' . -' -', $xml); - - } - -} diff --git a/vendor/sabre/dav/tests/Sabre/CardDAV/SogoStripContentTypeTest.php b/vendor/sabre/dav/tests/Sabre/CardDAV/SogoStripContentTypeTest.php index 2a62bd2f9..f828cc25b 100644 --- a/vendor/sabre/dav/tests/Sabre/CardDAV/SogoStripContentTypeTest.php +++ b/vendor/sabre/dav/tests/Sabre/CardDAV/SogoStripContentTypeTest.php @@ -3,6 +3,7 @@ namespace Sabre\CardDAV; use Sabre\HTTP; +use Sabre\DAV\PropFind; class SogoStripContentType extends \Sabre\DAVServerTest { @@ -24,13 +25,13 @@ class SogoStripContentType extends \Sabre\DAVServerTest { $result = $this->server->getProperties('addressbooks/user1/book1/card1.vcf',array('{DAV:}getcontenttype')); $this->assertEquals(array( - '{DAV:}getcontenttype' => 'text/x-vcard; charset=utf-8' + '{DAV:}getcontenttype' => 'text/vcard; charset=utf-8' ), $result); } function testStrip() { - $this->server->httpRequest = new HTTP\Request(array( + $this->server->httpRequest = HTTP\Sapi::createFromServerArray(array( 'HTTP_USER_AGENT' => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:10.0.2) Gecko/20120216 Thunderbird/10.0.2 Lightning/1.2.1', )); $result = $this->server->getProperties('addressbooks/user1/book1/card1.vcf',array('{DAV:}getcontenttype')); @@ -39,5 +40,17 @@ class SogoStripContentType extends \Sabre\DAVServerTest { ), $result); } + function testDontTouchOtherMimeTypes() { + + $this->server->httpRequest = new HTTP\Request('GET','/addressbooks/user1/book1/card1.vcf', [ + 'User-Agent' => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:10.0.2) Gecko/20120216 Thunderbird/10.0.2 Lightning/1.2.1', + ]); + + $propFind = new PropFind('hello', ['{DAV:}getcontenttype']); + $propFind->set('{DAV:}getcontenttype', 'text/plain'); + $this->carddavPlugin->propFindLate($propFind, new \Sabre\DAV\SimpleCollection('foo')); + $this->assertEquals('text/plain', $propFind->get('{DAV:}getcontenttype')); + + } } diff --git a/vendor/sabre/dav/tests/Sabre/CardDAV/TestUtil.php b/vendor/sabre/dav/tests/Sabre/CardDAV/TestUtil.php index 9f84566af..c9cc10d35 100644 --- a/vendor/sabre/dav/tests/Sabre/CardDAV/TestUtil.php +++ b/vendor/sabre/dav/tests/Sabre/CardDAV/TestUtil.php @@ -15,17 +15,8 @@ class TestUtil { static function getSQLiteDB() { - if (file_exists(SABRE_TEMPDIR . '/testdb.sqlite')) - unlink(SABRE_TEMPDIR . '/testdb.sqlite'); + $pdo = Backend\PDOSqliteTest::getSQLite(); - $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.addressbooks.sql')); - foreach($queries as $query) { - $pdo->exec($query); - } // Inserting events through a backend class. $backend = new Backend\PDO($pdo); $addressbookId = $backend->createAddressBook( @@ -49,7 +40,12 @@ class TestUtil { } - static function getTestCardData($type = 1) { + static function deleteSQLiteDB() { + $sqliteTest = new Backend\PDOSqliteTest(); + $pdo = $sqliteTest->tearDown(); + } + + static function getTestCardData() { $addressbookData = 'BEGIN:VCARD VERSION:3.0 diff --git a/vendor/sabre/dav/tests/Sabre/CardDAV/UserAddressBooksTest.php b/vendor/sabre/dav/tests/Sabre/CardDAV/UserAddressBooksTest.php deleted file mode 100644 index a6ecf3e47..000000000 --- a/vendor/sabre/dav/tests/Sabre/CardDAV/UserAddressBooksTest.php +++ /dev/null @@ -1,162 +0,0 @@ -backend = new Backend\Mock(); - $this->s = new UserAddressBooks( - $this->backend, - 'principals/user1' - ); - - } - - function testGetName() { - - $this->assertEquals('user1', $this->s->getName()); - - } - - /** - * @expectedException Sabre\DAV\Exception\MethodNotAllowed - */ - function testSetName() { - - $this->s->setName('user2'); - - } - - /** - * @expectedException Sabre\DAV\Exception\MethodNotAllowed - */ - function testDelete() { - - $this->s->delete(); - - } - - function testGetLastModified() { - - $this->assertNull($this->s->getLastModified()); - - } - - /** - * @expectedException Sabre\DAV\Exception\MethodNotAllowed - */ - function testCreateFile() { - - $this->s->createFile('bla'); - - } - - /** - * @expectedException Sabre\DAV\Exception\MethodNotAllowed - */ - function testCreateDirectory() { - - $this->s->createDirectory('bla'); - - } - - function testGetChild() { - - $child = $this->s->getChild('book1'); - $this->assertInstanceOf('Sabre\\CardDAV\\AddressBook', $child); - $this->assertEquals('book1', $child->getName()); - - } - - /** - * @expectedException Sabre\DAV\Exception\NotFound - */ - function testGetChild404() { - - $this->s->getChild('book2'); - - } - - function testGetChildren() { - - $children = $this->s->getChildren(); - $this->assertEquals(1, count($children)); - $this->assertInstanceOf('Sabre\\CardDAV\\AddressBook', $children[0]); - $this->assertEquals('book1', $children[0]->getName()); - - } - - function testCreateExtendedCollection() { - - $resourceType = array( - '{' . Plugin::NS_CARDDAV . '}addressbook', - '{DAV:}collection', - ); - $this->s->createExtendedCollection('book2', $resourceType, array('{DAV:}displayname' => 'a-book 2')); - - $this->assertEquals(array( - 'id' => 'book2', - 'uri' => 'book2', - '{DAV:}displayname' => 'a-book 2', - 'principaluri' => 'principals/user1', - ), $this->backend->addressBooks[1]); - - } - - /** - * @expectedException Sabre\DAV\Exception\InvalidResourceType - */ - function testCreateExtendedCollectionInvalid() { - - $resourceType = array( - '{DAV:}collection', - ); - $this->s->createExtendedCollection('book2', $resourceType, array('{DAV:}displayname' => 'a-book 2')); - - } - - - function testACLMethods() { - - $this->assertEquals('principals/user1', $this->s->getOwner()); - $this->assertNull($this->s->getGroup()); - $this->assertEquals(array( - array( - 'privilege' => '{DAV:}read', - 'principal' => 'principals/user1', - 'protected' => true, - ), - array( - 'privilege' => '{DAV:}write', - 'principal' => 'principals/user1', - 'protected' => true, - ), - ), $this->s->getACL()); - - } - - /** - * @expectedException Sabre\DAV\Exception\MethodNotAllowed - */ - function testSetACL() { - - $this->s->setACL(array()); - - } - - function testGetSupportedPrivilegeSet() { - - $this->assertNull( - $this->s->getSupportedPrivilegeSet() - ); - - } -} diff --git a/vendor/sabre/dav/tests/Sabre/CardDAV/VCFExportTest.php b/vendor/sabre/dav/tests/Sabre/CardDAV/VCFExportTest.php index 84da59311..71fde719d 100644 --- a/vendor/sabre/dav/tests/Sabre/CardDAV/VCFExportTest.php +++ b/vendor/sabre/dav/tests/Sabre/CardDAV/VCFExportTest.php @@ -29,28 +29,35 @@ class VCFExportTest extends \Sabre\DAVServerTest { function setUp() { parent::setUp(); + $plugin = new VCFExportPlugin(); $this->server->addPlugin( - new VCFExportPlugin() + $plugin ); } function testSimple() { - $this->assertInstanceOf('Sabre\\CardDAV\\VCFExportPlugin', $this->server->getPlugin('Sabre\\CardDAV\\VCFExportPlugin')); + $plugin = $this->server->getPlugin('vcf-export'); + $this->assertInstanceOf('Sabre\\CardDAV\\VCFExportPlugin', $plugin); + + $this->assertEquals( + 'vcf-export', + $plugin->getPluginInfo()['name'] + ); } function testExport() { - $request = new HTTP\Request(array( + $request = HTTP\Sapi::createFromServerArray(array( 'REQUEST_URI' => '/addressbooks/user1/book1?export', 'QUERY_STRING' => 'export', 'REQUEST_METHOD' => 'GET', )); $response = $this->request($request); - $this->assertEquals('HTTP/1.1 200 OK', $response->status, $response->body); + $this->assertEquals(200, $response->status, $response->body); $expected = "BEGIN:VCARD FN:Person1 @@ -72,4 +79,14 @@ END:VCARD } + function testBrowserIntegration() { + + $plugin = $this->server->getPlugin('vcf-export'); + $actions = ''; + $addressbook = new AddressBook($this->carddavBackend, []); + $this->server->emit('browserButtonActions', ['/foo', $addressbook, &$actions]); + $this->assertContains('/foo?export', $actions); + + } + } diff --git a/vendor/sabre/dav/tests/Sabre/CardDAV/ValidateVCardTest.php b/vendor/sabre/dav/tests/Sabre/CardDAV/ValidateVCardTest.php index 1f52f30a7..ad8495c13 100644 --- a/vendor/sabre/dav/tests/Sabre/CardDAV/ValidateVCardTest.php +++ b/vendor/sabre/dav/tests/Sabre/CardDAV/ValidateVCardTest.php @@ -31,6 +31,7 @@ class ValidateVCardTest extends \PHPUnit_Framework_TestCase { ); $this->server = new DAV\Server($tree); + $this->server->sapi = new HTTP\SapiMock(); $this->server->debugExceptions = true; $plugin = new Plugin(); @@ -52,20 +53,20 @@ class ValidateVCardTest extends \PHPUnit_Framework_TestCase { function testCreateFile() { - $request = new HTTP\Request(array( + $request = HTTP\Sapi::createFromServerArray(array( 'REQUEST_METHOD' => 'PUT', 'REQUEST_URI' => '/addressbooks/admin/addressbook1/blabla.vcf', )); $response = $this->request($request); - $this->assertEquals('HTTP/1.1 415 Unsupported Media Type', $response->status); + $this->assertEquals(415, $response->status); } function testCreateFileValid() { - $request = new HTTP\Request(array( + $request = HTTP\Sapi::createFromServerArray(array( 'REQUEST_METHOD' => 'PUT', 'REQUEST_URI' => '/addressbooks/admin/addressbook1/blabla.vcf', )); @@ -73,7 +74,7 @@ class ValidateVCardTest extends \PHPUnit_Framework_TestCase { $response = $this->request($request); - $this->assertEquals('HTTP/1.1 201 Created', $response->status, 'Incorrect status returned! Full response body: ' . $response->body); + $this->assertEquals(201, $response->status, 'Incorrect status returned! Full response body: ' . $response->body); $expected = array( 'uri' => 'blabla.vcf', 'carddata' => "BEGIN:VCARD\r\nUID:foo\r\nEND:VCARD\r\n", @@ -85,24 +86,40 @@ class ValidateVCardTest extends \PHPUnit_Framework_TestCase { function testCreateFileNoUID() { - $request = new HTTP\Request(array( - 'REQUEST_METHOD' => 'PUT', - 'REQUEST_URI' => '/addressbooks/admin/addressbook1/blabla.vcf', - )); + $request = new HTTP\Request( + 'PUT', + '/addressbooks/admin/addressbook1/blabla.vcf' + ); $request->setBody("BEGIN:VCARD\r\nEND:VCARD\r\n"); $response = $this->request($request); - $this->assertEquals('HTTP/1.1 201 Created', $response->status, 'Incorrect status returned! Full response body: ' . $response->body); + $this->assertEquals(201, $response->status, 'Incorrect status returned! Full response body: ' . $response->body); $foo = $this->cardBackend->getCard('addressbook1','blabla.vcf'); $this->assertTrue(strpos($foo['carddata'],'UID')!==false); } + function testCreateFileJson() { + + $request = new HTTP\Request( + 'PUT', + '/addressbooks/admin/addressbook1/blabla.vcf' + ); + $request->setBody('[ "vcard" , [ [ "UID" , {}, "text", "foo" ] ] ]'); + + $response = $this->request($request); + + $this->assertEquals(201, $response->status, 'Incorrect status returned! Full response body: ' . $response->body); + + $foo = $this->cardBackend->getCard('addressbook1','blabla.vcf'); + $this->assertEquals("BEGIN:VCARD\r\nUID:foo\r\nEND:VCARD\r\n", $foo['carddata']); + + } function testCreateFileVCalendar() { - $request = new HTTP\Request(array( + $request = HTTP\Sapi::createFromServerArray(array( 'REQUEST_METHOD' => 'PUT', 'REQUEST_URI' => '/addressbooks/admin/addressbook1/blabla.vcf', )); @@ -110,28 +127,28 @@ class ValidateVCardTest extends \PHPUnit_Framework_TestCase { $response = $this->request($request); - $this->assertEquals('HTTP/1.1 415 Unsupported Media Type', $response->status, 'Incorrect status returned! Full response body: ' . $response->body); + $this->assertEquals(415, $response->status, 'Incorrect status returned! Full response body: ' . $response->body); } function testUpdateFile() { $this->cardBackend->createCard('addressbook1','blabla.vcf','foo'); - $request = new HTTP\Request(array( + $request = HTTP\Sapi::createFromServerArray(array( 'REQUEST_METHOD' => 'PUT', 'REQUEST_URI' => '/addressbooks/admin/addressbook1/blabla.vcf', )); $response = $this->request($request); - $this->assertEquals('HTTP/1.1 415 Unsupported Media Type', $response->status); + $this->assertEquals(415, $response->status); } function testUpdateFileParsableBody() { $this->cardBackend->createCard('addressbook1','blabla.vcf','foo'); - $request = new HTTP\Request(array( + $request = HTTP\Sapi::createFromServerArray(array( 'REQUEST_METHOD' => 'PUT', 'REQUEST_URI' => '/addressbooks/admin/addressbook1/blabla.vcf', )); @@ -140,7 +157,7 @@ class ValidateVCardTest extends \PHPUnit_Framework_TestCase { $response = $this->request($request); - $this->assertEquals('HTTP/1.1 204 No Content', $response->status); + $this->assertEquals(204, $response->status); $expected = array( 'uri' => 'blabla.vcf', diff --git a/vendor/sabre/dav/tests/Sabre/CardDAV/VersionTest.php b/vendor/sabre/dav/tests/Sabre/CardDAV/VersionTest.php deleted file mode 100644 index 02943b2d3..000000000 --- a/vendor/sabre/dav/tests/Sabre/CardDAV/VersionTest.php +++ /dev/null @@ -1,17 +0,0 @@ -assertEquals(-1, version_compare('0.1',$v)); - - $s = Version::STABILITY; - $this->assertTrue($s == 'alpha' || $s == 'beta' || $s =='stable'); - - } - -} diff --git a/vendor/sabre/dav/tests/Sabre/DAV/AbstractServer.php b/vendor/sabre/dav/tests/Sabre/DAV/AbstractServer.php index 4bf5b343e..b5b8d64ee 100644 --- a/vendor/sabre/dav/tests/Sabre/DAV/AbstractServer.php +++ b/vendor/sabre/dav/tests/Sabre/DAV/AbstractServer.php @@ -4,8 +4,6 @@ namespace Sabre\DAV; use Sabre\HTTP; -require_once 'Sabre/HTTP/ResponseMock.php'; - abstract class AbstractServer extends \PHPUnit_Framework_TestCase { /** @@ -23,6 +21,7 @@ abstract class AbstractServer extends \PHPUnit_Framework_TestCase { $this->response = new HTTP\ResponseMock(); $this->server = new Server($this->getRootNode()); + $this->server->sapi = new HTTP\SapiMock(); $this->server->httpResponse = $this->response; $this->server->debugExceptions = true; $this->deleteTree(SABRE_TEMPDIR,false); diff --git a/vendor/sabre/dav/tests/Sabre/DAV/Auth/Backend/AbstractBasicTest.php b/vendor/sabre/dav/tests/Sabre/DAV/Auth/Backend/AbstractBasicTest.php index 36d23c5c0..7d7a59898 100644 --- a/vendor/sabre/dav/tests/Sabre/DAV/Auth/Backend/AbstractBasicTest.php +++ b/vendor/sabre/dav/tests/Sabre/DAV/Auth/Backend/AbstractBasicTest.php @@ -5,67 +5,68 @@ namespace Sabre\DAV\Auth\Backend; use Sabre\DAV; use Sabre\HTTP; -require_once 'Sabre/HTTP/ResponseMock.php'; - class AbstractBasicTest extends \PHPUnit_Framework_TestCase { - /** - * @expectedException Sabre\DAV\Exception\NotAuthenticated - */ - public function testAuthenticateNoHeaders() { + function testCheckNoHeaders() { - $response = new HTTP\ResponseMock(); - $server = new DAV\Server(); - $server->httpResponse = $response; + $request = new HTTP\Request(); + $response = new HTTP\Response(); $backend = new AbstractBasicMock(); - $backend->authenticate($server,'myRealm'); - } + $this->assertFalse( + $backend->check($request, $response)[0] + ); - /** - * @expectedException Sabre\DAV\Exception\NotAuthenticated - */ - public function testAuthenticateUnknownUser() { + } - $response = new HTTP\ResponseMock(); - $tree = new DAV\ObjectTree(new DAV\SimpleCollection('bla')); - $server = new DAV\Server($tree); - $server->httpResponse = $response; + function testCheckUnknownUser() { - $request = new HTTP\Request(array( + $request = HTTP\Sapi::createFromServerArray(array( 'PHP_AUTH_USER' => 'username', 'PHP_AUTH_PW' => 'wrongpassword', )); - $server->httpRequest = $request; + $response = new HTTP\Response(); $backend = new AbstractBasicMock(); - $backend->authenticate($server,'myRealm'); - } + $this->assertFalse( + $backend->check($request, $response)[0] + ); - public function testAuthenticate() { + } - $response = new HTTP\ResponseMock(); - $tree = new DAV\ObjectTree(new DAV\SimpleCollection('bla')); - $server = new DAV\Server($tree); - $server->httpResponse = $response; + function testCheckSuccess() { - $request = new HTTP\Request(array( + $request = HTTP\Sapi::createFromServerArray(array( 'PHP_AUTH_USER' => 'username', 'PHP_AUTH_PW' => 'password', )); - $server->httpRequest = $request; + $response = new HTTP\Response(); $backend = new AbstractBasicMock(); - $this->assertTrue($backend->authenticate($server,'myRealm')); + $this->assertEquals( + [true, 'principals/username'], + $backend->check($request, $response) + ); - $result = $backend->getCurrentUser(); + } - $this->assertEquals('username', $result); + function testRequireAuth() { - } + $request = new HTTP\Request(); + $response = new HTTP\Response(); + $backend = new AbstractBasicMock(); + $backend->setRealm('writing unittests on a saturday night'); + $backend->challenge($request, $response); + + $this->assertEquals( + 'Basic realm="writing unittests on a saturday night"', + $response->getHeader('WWW-Authenticate') + ); + + } } diff --git a/vendor/sabre/dav/tests/Sabre/DAV/Auth/Backend/AbstractDigestTest.php b/vendor/sabre/dav/tests/Sabre/DAV/Auth/Backend/AbstractDigestTest.php index 495690c4e..8ef416c37 100644 --- a/vendor/sabre/dav/tests/Sabre/DAV/Auth/Backend/AbstractDigestTest.php +++ b/vendor/sabre/dav/tests/Sabre/DAV/Auth/Backend/AbstractDigestTest.php @@ -5,130 +5,120 @@ namespace Sabre\DAV\Auth\Backend; use Sabre\DAV; use Sabre\HTTP; -require_once 'Sabre/HTTP/ResponseMock.php'; - class AbstractDigestTest extends \PHPUnit_Framework_TestCase { - /** - * @expectedException Sabre\DAV\Exception\NotAuthenticated - */ - public function testAuthenticateNoHeaders() { + function testCheckNoHeaders() { - $response = new HTTP\ResponseMock(); - $server = new DAV\Server(); - $server->httpResponse = $response; + $request = new HTTP\Request(); + $response = new HTTP\Response(); $backend = new AbstractDigestMock(); - $backend->authenticate($server,'myRealm'); + $this->assertFalse( + $backend->check($request, $response)[0] + ); } - /** - * @expectedException Sabre\DAV\Exception - */ - public function testAuthenticateBadGetUserInfoResponse() { - - $response = new HTTP\ResponseMock(); - $server = new DAV\Server(); - $server->httpResponse = $response; + function testCheckBadGetUserInfoResponse() { $header = 'username=null, realm=myRealm, nonce=12345, uri=/, response=HASH, opaque=1, qop=auth, nc=1, cnonce=1'; - $request = new HTTP\Request(array( + $request = HTTP\Sapi::createFromServerArray([ 'PHP_AUTH_DIGEST' => $header, - )); - $server->httpRequest = $request; + ]); + $response = new HTTP\Response(); $backend = new AbstractDigestMock(); - $backend->authenticate($server,'myRealm'); + $this->assertFalse( + $backend->check($request, $response)[0] + ); } /** * @expectedException Sabre\DAV\Exception */ - public function testAuthenticateBadGetUserInfoResponse2() { - - $response = new HTTP\ResponseMock(); - $server = new DAV\Server(); - $server->httpResponse = $response; + function testCheckBadGetUserInfoResponse2() { $header = 'username=array, realm=myRealm, nonce=12345, uri=/, response=HASH, opaque=1, qop=auth, nc=1, cnonce=1'; - $request = new HTTP\Request(array( + $request = HTTP\Sapi::createFromServerArray([ 'PHP_AUTH_DIGEST' => $header, - )); - $server->httpRequest = $request; + ]); + + $response = new HTTP\Response(); $backend = new AbstractDigestMock(); - $backend->authenticate($server,'myRealm'); + $backend->check($request, $response); } - /** - * @expectedException Sabre\DAV\Exception\NotAuthenticated - */ - public function testAuthenticateUnknownUser() { - - $response = new HTTP\ResponseMock(); - $server = new DAV\Server(); - $server->httpResponse = $response; + function testCheckUnknownUser() { $header = 'username=false, realm=myRealm, nonce=12345, uri=/, response=HASH, opaque=1, qop=auth, nc=1, cnonce=1'; - $request = new HTTP\Request(array( + $request = HTTP\Sapi::createFromServerArray([ 'PHP_AUTH_DIGEST' => $header, - )); - $server->httpRequest = $request; + ]); + + $response = new HTTP\Response(); $backend = new AbstractDigestMock(); - $backend->authenticate($server,'myRealm'); + $this->assertFalse( + $backend->check($request, $response)[0] + ); } - /** - * @expectedException Sabre\DAV\Exception\NotAuthenticated - */ - public function testAuthenticateBadPassword() { - - $response = new HTTP\ResponseMock(); - $server = new DAV\Server(); - $server->httpResponse = $response; + function testCheckBadPassword() { $header = 'username=user, realm=myRealm, nonce=12345, uri=/, response=HASH, opaque=1, qop=auth, nc=1, cnonce=1'; - $request = new HTTP\Request(array( + $request = HTTP\Sapi::createFromServerArray([ 'PHP_AUTH_DIGEST' => $header, 'REQUEST_METHOD' => 'PUT', - )); - $server->httpRequest = $request; + ]); + + $response = new HTTP\Response(); $backend = new AbstractDigestMock(); - $backend->authenticate($server,'myRealm'); + $this->assertFalse( + $backend->check($request, $response)[0] + ); } - public function testAuthenticate() { - - $response = new HTTP\ResponseMock(); - $server = new DAV\Server(); - $server->httpResponse = $response; + function testCheck() { $digestHash = md5('HELLO:12345:1:1:auth:' . md5('GET:/')); $header = 'username=user, realm=myRealm, nonce=12345, uri=/, response='.$digestHash.', opaque=1, qop=auth, nc=1, cnonce=1'; - $request = new HTTP\Request(array( + $request = HTTP\Sapi::createFromServerArray(array( 'REQUEST_METHOD' => 'GET', 'PHP_AUTH_DIGEST' => $header, 'REQUEST_URI' => '/', )); - $server->httpRequest = $request; + + $response = new HTTP\Response(); $backend = new AbstractDigestMock(); - $this->assertTrue($backend->authenticate($server,'myRealm')); + $this->assertEquals( + [true, 'principals/user'], + $backend->check($request, $response) + ); - $result = $backend->getCurrentUser(); + } - $this->assertEquals('user', $result); - $this->assertEquals('HELLO', $backend->getDigestHash('myRealm', $result)); + function testRequireAuth() { - } + $request = new HTTP\Request(); + $response = new HTTP\Response(); + $backend = new AbstractDigestMock(); + $backend->setRealm('writing unittests on a saturday night'); + $backend->challenge($request, $response); + + $this->assertStringStartsWith( + 'Digest realm="writing unittests on a saturday night"', + $response->getHeader('WWW-Authenticate') + ); + + } } diff --git a/vendor/sabre/dav/tests/Sabre/DAV/Auth/Backend/ApacheTest.php b/vendor/sabre/dav/tests/Sabre/DAV/Auth/Backend/ApacheTest.php index b1ed555d4..697b593db 100644 --- a/vendor/sabre/dav/tests/Sabre/DAV/Auth/Backend/ApacheTest.php +++ b/vendor/sabre/dav/tests/Sabre/DAV/Auth/Backend/ApacheTest.php @@ -10,36 +10,63 @@ class ApacheTest extends \PHPUnit_Framework_TestCase { function testConstruct() { $backend = new Apache(); + $this->assertInstanceOf('Sabre\DAV\Auth\Backend\Apache', $backend); } - /** - * @expectedException Sabre\DAV\Exception - */ function testNoHeader() { - $server = new DAV\Server(); + $request = new HTTP\Request(); + $response = new HTTP\Response(); $backend = new Apache(); - $backend->authenticate($server,'Realm'); + + $this->assertFalse( + $backend->check($request, $response)[0] + ); } function testRemoteUser() { + $request = HTTP\Sapi::createFromServerArray([ + 'REMOTE_USER' => 'username', + ]); + $response = new HTTP\Response(); $backend = new Apache(); - $server = new DAV\Server(); - $request = new HTTP\Request(array( - 'REMOTE_USER' => 'username', - )); - $server->httpRequest = $request; + $this->assertEquals( + [true, 'principals/username'], + $backend->check($request, $response) + ); - $this->assertTrue($backend->authenticate($server, 'Realm')); + } + + function testRedirectRemoteUser() { - $userInfo = 'username'; + $request = HTTP\Sapi::createFromServerArray([ + 'REDIRECT_REMOTE_USER' => 'username', + ]); + $response = new HTTP\Response(); + $backend = new Apache(); - $this->assertEquals($userInfo, $backend->getCurrentUser()); + $this->assertEquals( + [true, 'principals/username'], + $backend->check($request, $response) + ); } + function testRequireAuth() { + + $request = new HTTP\Request(); + $response = new HTTP\Response(); + + $backend = new Apache(); + $backend->challenge($request, $response); + + $this->assertNull( + $response->getHeader('WWW-Authenticate') + ); + + } } diff --git a/vendor/sabre/dav/tests/Sabre/DAV/Auth/Backend/FileTest.php b/vendor/sabre/dav/tests/Sabre/DAV/Auth/Backend/FileTest.php index 72f150ab6..d2e5fe49b 100644 --- a/vendor/sabre/dav/tests/Sabre/DAV/Auth/Backend/FileTest.php +++ b/vendor/sabre/dav/tests/Sabre/DAV/Auth/Backend/FileTest.php @@ -35,7 +35,7 @@ class FileTest extends \PHPUnit_Framework_TestCase { $file->loadFile(SABRE_TEMPDIR . '/backend'); $this->assertFalse($file->getDigestHash('realm','blabla')); - $this->assertEquals(md5('user:realm:password'), $file->getDigesthash('realm','user')); + $this->assertEquals(md5('user:realm:password'), $file->getDigestHash('realm','user')); } diff --git a/vendor/sabre/dav/tests/Sabre/DAV/Auth/Backend/Mock.php b/vendor/sabre/dav/tests/Sabre/DAV/Auth/Backend/Mock.php index fdad8a605..a782cb74d 100644 --- a/vendor/sabre/dav/tests/Sabre/DAV/Auth/Backend/Mock.php +++ b/vendor/sabre/dav/tests/Sabre/DAV/Auth/Backend/Mock.php @@ -2,35 +2,85 @@ namespace Sabre\DAV\Auth\Backend; -use Sabre\DAV; +use + Sabre\DAV, + Sabre\HTTP\RequestInterface, + Sabre\HTTP\ResponseInterface; class Mock implements BackendInterface { - protected $currentUser; + public $fail = false; - public $defaultUser = 'admin'; + public $invalidCheckResponse = false; - /** - * @param Sabre\DAV\Server $server - * @param string $realm - * @throws Sabre\DAV\Exception\NotAuthenticated - */ - function authenticate(DAV\Server $server, $realm) { + public $principal = 'principals/admin'; - if ($realm=='failme') throw new DAV\Exception\NotAuthenticated('deliberate fail'); - $this->currentUser = $this->defaultUser; + function setPrincipal($principal) { + + $this->principal = $principal; } - function setCurrentUser($user) { + /** + * When this method is called, the backend must check if authentication was + * successful. + * + * The returned value must be one of the following + * + * [true, "principals/username"] + * [false, "reason for failure"] + * + * If authentication was successful, it's expected that the authentication + * backend returns a so-called principal url. + * + * Examples of a principal url: + * + * principals/admin + * principals/user1 + * principals/users/joe + * principals/uid/123457 + * + * If you don't use WebDAV ACL (RFC3744) we recommend that you simply + * return a string such as: + * + * principals/users/[username] + * + * @param RequestInterface $request + * @param ResponseInterface $response + * @return array + */ + function check(RequestInterface $request, ResponseInterface $response) { - $this->currentUser = $user; + if ($this->invalidCheckResponse) { + return 'incorrect!'; + } + if ($this->fail) { + return [false, "fail!"]; + } + return [true, $this->principal]; } - function getCurrentUser() { - - return $this->currentUser; + /** + * This method is called when a user could not be authenticated, and + * authentication was required for the current request. + * + * This gives you the oppurtunity to set authentication headers. The 401 + * status code will already be set. + * + * In this case of Basic Auth, this would for example mean that the + * following header needs to be set: + * + * $response->addHeader('WWW-Authenticate', 'Basic realm=SabreDAV'); + * + * Keep in mind that in the case of multiple authentication backends, other + * WWW-Authenticate headers may already have been set, and you'll want to + * append your own WWW-Authenticate header instead of overwriting the + * existing one. + * + * @return void + */ + function challenge(RequestInterface $request, ResponseInterface $response) { } diff --git a/vendor/sabre/dav/tests/Sabre/DAV/Auth/Backend/PDOMySQLTest.php b/vendor/sabre/dav/tests/Sabre/DAV/Auth/Backend/PDOMySQLTest.php index ede432de2..8de2be667 100644 --- a/vendor/sabre/dav/tests/Sabre/DAV/Auth/Backend/PDOMySQLTest.php +++ b/vendor/sabre/dav/tests/Sabre/DAV/Auth/Backend/PDOMySQLTest.php @@ -12,15 +12,17 @@ class PDOMySQLTest extends AbstractPDOTest { $pdo = \Sabre\TestUtil::getMySQLDB(); if (!$pdo) $this->markTestSkipped('Could not connect to MySQL database'); $pdo->query("DROP TABLE IF EXISTS users"); - $pdo->query(" + $pdo->query(<<query("INSERT INTO users (username,digesta1,email,displayname) VALUES ('user','hash','user@example.org','User')"); diff --git a/vendor/sabre/dav/tests/Sabre/DAV/Auth/PluginTest.php b/vendor/sabre/dav/tests/Sabre/DAV/Auth/PluginTest.php index 2096a04d7..0ac9e0613 100644 --- a/vendor/sabre/dav/tests/Sabre/DAV/Auth/PluginTest.php +++ b/vendor/sabre/dav/tests/Sabre/DAV/Auth/PluginTest.php @@ -12,10 +12,11 @@ class PluginTest extends \PHPUnit_Framework_TestCase { function testInit() { $fakeServer = new DAV\Server( new DAV\SimpleCollection('bla')); - $plugin = new Plugin(new Backend\Mock(),'realm'); + $plugin = new Plugin(new Backend\Mock()); $this->assertTrue($plugin instanceof Plugin); $fakeServer->addPlugin($plugin); $this->assertEquals($plugin, $fakeServer->getPlugin('auth')); + $this->assertInternalType('array', $plugin->getPluginInfo()); } @@ -25,14 +26,14 @@ class PluginTest extends \PHPUnit_Framework_TestCase { function testAuthenticate() { $fakeServer = new DAV\Server( new DAV\SimpleCollection('bla')); - $plugin = new Plugin(new Backend\Mock(),'realm'); + $plugin = new Plugin(new Backend\Mock()); $fakeServer->addPlugin($plugin); - $fakeServer->broadCastEvent('beforeMethod',array('GET','/')); + $this->assertTrue( + $fakeServer->emit('beforeMethod', [new HTTP\Request(), new HTTP\Response()]) + ); } - - /** * @depends testInit * @expectedException Sabre\DAV\Exception\NotAuthenticated @@ -40,42 +41,87 @@ class PluginTest extends \PHPUnit_Framework_TestCase { function testAuthenticateFail() { $fakeServer = new DAV\Server( new DAV\SimpleCollection('bla')); - $plugin = new Plugin(new Backend\Mock(),'failme'); + $backend = new Backend\Mock(); + $backend->fail = true; + + $plugin = new Plugin($backend); $fakeServer->addPlugin($plugin); - $fakeServer->broadCastEvent('beforeMethod',array('GET','/')); + $fakeServer->emit('beforeMethod', [new HTTP\Request(), new HTTP\Response()]); } - function testReportPassThrough() { + /** + * @depends testAuthenticate + */ + function testMultipleBackend() { - $fakeServer = new DAV\Server(new DAV\SimpleCollection('bla')); - $plugin = new Plugin(new Backend\Mock(),'realm'); - $fakeServer->addPlugin($plugin); + $fakeServer = new DAV\Server( new DAV\SimpleCollection('bla')); + $backend1 = new Backend\Mock(); + $backend2 = new Backend\Mock(); + $backend2->fail = true; - $request = new HTTP\Request(array( - 'REQUEST_METHOD' => 'REPORT', - 'HTTP_CONTENT_TYPE' => 'application/xml', - 'REQUEST_URI' => '/', - )); - $request->setBody(''); + $plugin = new Plugin(); + $plugin->addBackend($backend1); + $plugin->addBackend($backend2); - $fakeServer->httpRequest = $request; - $fakeServer->httpResponse = new HTTP\ResponseMock(); - $fakeServer->exec(); + $fakeServer->addPlugin($plugin); + $fakeServer->emit('beforeMethod', [new HTTP\Request(), new HTTP\Response()]); - $this->assertEquals('HTTP/1.1 403 Forbidden', $fakeServer->httpResponse->status); + $this->assertEquals('principals/admin', $plugin->getCurrentPrincipal()); } /** * @depends testInit + * @expectedException Sabre\DAV\Exception + */ + function testNoAuthBackend() { + + $fakeServer = new DAV\Server( new DAV\SimpleCollection('bla')); + + $plugin = new Plugin(); + $fakeServer->addPlugin($plugin); + $fakeServer->emit('beforeMethod', [new HTTP\Request(), new HTTP\Response()]); + + } + /** + * @depends testInit + * @expectedException Sabre\DAV\Exception + */ + function testInvalidCheckResponse() { + + $fakeServer = new DAV\Server( new DAV\SimpleCollection('bla')); + $backend = new Backend\Mock(); + $backend->invalidCheckResponse = true; + + $plugin = new Plugin($backend); + $fakeServer->addPlugin($plugin); + $fakeServer->emit('beforeMethod', [new HTTP\Request(), new HTTP\Response()]); + + } + + /** + * @depends testAuthenticate + */ + function testGetCurrentPrincipal() { + + $fakeServer = new DAV\Server( new DAV\SimpleCollection('bla')); + $plugin = new Plugin(new Backend\Mock()); + $fakeServer->addPlugin($plugin); + $fakeServer->emit('beforeMethod', [new HTTP\Request(), new HTTP\Response()]); + $this->assertEquals('principals/admin', $plugin->getCurrentPrincipal()); + + } + + /** + * @depends testAuthenticate */ - function testGetCurrentUserPrincipal() { + function testGetCurrentUser() { $fakeServer = new DAV\Server( new DAV\SimpleCollection('bla')); - $plugin = new Plugin(new Backend\Mock(),'realm'); + $plugin = new Plugin(new Backend\Mock()); $fakeServer->addPlugin($plugin); - $fakeServer->broadCastEvent('beforeMethod',array('GET','/')); + $fakeServer->emit('beforeMethod', [new HTTP\Request(), new HTTP\Response()]); $this->assertEquals('admin', $plugin->getCurrentUser()); } diff --git a/vendor/sabre/dav/tests/Sabre/DAV/BasicNodeTest.php b/vendor/sabre/dav/tests/Sabre/DAV/BasicNodeTest.php index fdc2403db..155c785f8 100644 --- a/vendor/sabre/dav/tests/Sabre/DAV/BasicNodeTest.php +++ b/vendor/sabre/dav/tests/Sabre/DAV/BasicNodeTest.php @@ -131,6 +131,7 @@ class BasicNodeTest extends \PHPUnit_Framework_TestCase { public function testSimpleDirectoryConstruct() { $dir = new SimpleCollection('simpledir',array()); + $this->assertInstanceOf('Sabre\DAV\SimpleCollection', $dir); } diff --git a/vendor/sabre/dav/tests/Sabre/DAV/Browser/GuessContentTypeTest.php b/vendor/sabre/dav/tests/Sabre/DAV/Browser/GuessContentTypeTest.php index 6fc65f9e8..157c2170a 100644 --- a/vendor/sabre/dav/tests/Sabre/DAV/Browser/GuessContentTypeTest.php +++ b/vendor/sabre/dav/tests/Sabre/DAV/Browser/GuessContentTypeTest.php @@ -10,6 +10,7 @@ class GuessContentTypeTest extends DAV\AbstractServer { function setUp() { parent::setUp(); + \Sabre\TestUtil::clearTempDir(); file_put_contents(SABRE_TEMPDIR . '/somefile.jpg','blabla'); file_put_contents(SABRE_TEMPDIR . '/somefile.hoi','blabla'); @@ -17,7 +18,7 @@ class GuessContentTypeTest extends DAV\AbstractServer { function tearDown() { - unlink(SABRE_TEMPDIR . '/somefile.jpg'); + \Sabre\TestUtil::clearTempDir(); parent::tearDown(); } @@ -44,7 +45,7 @@ class GuessContentTypeTest extends DAV\AbstractServer { ); $result = $this->server->getPropertiesForPath('/somefile.jpg',$properties); $this->assertArrayHasKey(0,$result); - $this->assertArrayHasKey(200,$result[0]); + $this->assertArrayHasKey(200,$result[0], 'We received: ' . print_r($result,true)); $this->assertArrayHasKey('{DAV:}getcontenttype',$result[0][200]); $this->assertEquals('image/jpeg',$result[0][200]['{DAV:}getcontenttype']); @@ -61,8 +62,9 @@ class GuessContentTypeTest extends DAV\AbstractServer { ); $result = $this->server->getPropertiesForPath('/somefile.hoi',$properties); $this->assertArrayHasKey(0,$result); - $this->assertArrayHasKey(404,$result[0]); - $this->assertArrayHasKey('{DAV:}getcontenttype',$result[0][404]); + $this->assertArrayHasKey(200,$result[0]); + $this->assertArrayHasKey('{DAV:}getcontenttype',$result[0][200]); + $this->assertEquals('application/octet-stream',$result[0][200]['{DAV:}getcontenttype']); } } diff --git a/vendor/sabre/dav/tests/Sabre/DAV/Browser/MapGetToPropFindTest.php b/vendor/sabre/dav/tests/Sabre/DAV/Browser/MapGetToPropFindTest.php index 169675e7e..9d9fbb319 100644 --- a/vendor/sabre/dav/tests/Sabre/DAV/Browser/MapGetToPropFindTest.php +++ b/vendor/sabre/dav/tests/Sabre/DAV/Browser/MapGetToPropFindTest.php @@ -23,21 +23,21 @@ class MapGetToPropFindTest extends DAV\AbstractServer { 'REQUEST_METHOD' => 'GET', ); - $request = new HTTP\Request($serverVars); + $request = HTTP\Sapi::createFromServerArray($serverVars); $request->setBody(''); $this->server->httpRequest = ($request); $this->server->exec(); + $this->assertEquals(207, $this->response->status,'Incorrect status response received. Full response body: ' . $this->response->body); $this->assertEquals(array( - 'Content-Type' => 'application/xml; charset=utf-8', - 'DAV' => '1, 3, extended-mkcol', - 'Vary' => 'Brief,Prefer', + 'X-Sabre-Version' => [DAV\Version::VERSION], + 'Content-Type' => ['application/xml; charset=utf-8'], + 'DAV' => ['1, 3, extended-mkcol'], + 'Vary' => ['Brief,Prefer'], ), - $this->response->headers + $this->response->getHeaders() ); - $this->assertEquals('HTTP/1.1 207 Multi-Status',$this->response->status,'Incorrect status response received. Full response body: ' . $this->response->body); - } diff --git a/vendor/sabre/dav/tests/Sabre/DAV/Browser/PluginTest.php b/vendor/sabre/dav/tests/Sabre/DAV/Browser/PluginTest.php index c3c4bdebb..00beea9f2 100644 --- a/vendor/sabre/dav/tests/Sabre/DAV/Browser/PluginTest.php +++ b/vendor/sabre/dav/tests/Sabre/DAV/Browser/PluginTest.php @@ -9,80 +9,114 @@ require_once 'Sabre/DAV/AbstractServer.php'; class PluginTest extends DAV\AbstractServer{ + protected $plugin; + function setUp() { parent::setUp(); - $this->server->addPlugin(new Plugin()); + $this->server->addPlugin($this->plugin = new Plugin()); + $this->server->tree->getNodeForPath('')->createDirectory('dir2'); } function testCollectionGet() { - $serverVars = array( - 'REQUEST_URI' => '/dir', - 'REQUEST_METHOD' => 'GET', - ); - - $request = new HTTP\Request($serverVars); - $this->server->httpRequest = ($request); + $request = new HTTP\Request('GET', '/dir'); + $this->server->httpRequest = $request; $this->server->exec(); - $this->assertEquals('HTTP/1.1 200 OK',$this->response->status); - $this->assertEquals(array( - 'Content-Type' => 'text/html; charset=utf-8', - ), - $this->response->headers + $this->assertEquals(200, $this->response->getStatus(), "Incorrect status received. Full response body: " . $this->response->getBodyAsString()); + $this->assertEquals( + [ + 'X-Sabre-Version' => [DAV\Version::VERSION], + 'Content-Type' => ['text/html; charset=utf-8'], + 'Content-Security-Policy' => ["img-src 'self'; style-src 'self';"] + ], + $this->response->getHeaders() ); - $this->assertTrue(strpos($this->response->body, 'Index for dir/') !== false); - $this->assertTrue(strpos($this->response->body, '')!==false); + $body = $this->response->getBodyAsString(); + $this->assertTrue(strpos($body, 'dir') !== false, $body); + $this->assertTrue(strpos($body, '<a href="/dir/child.txt">')!==false); } - function testNotFound() { + /** + * Adding the If-None-Match should have 0 effect, but it threw an error. + */ + function testCollectionGetIfNoneMatch() { - $serverVars = array( - 'REQUEST_URI' => '/random', - 'REQUEST_METHOD' => 'GET', + $request = new HTTP\Request('GET', '/dir'); + $request->setHeader('If-None-Match', '"foo-bar"'); + $this->server->httpRequest = $request; + $this->server->exec(); + + $this->assertEquals(200, $this->response->getStatus(), "Incorrect status received. Full response body: " . $this->response->getBodyAsString()); + $this->assertEquals( + [ + 'X-Sabre-Version' => [DAV\Version::VERSION], + 'Content-Type' => ['text/html; charset=utf-8'], + 'Content-Security-Policy' => ["img-src 'self'; style-src 'self';"] + ], + $this->response->getHeaders() ); - $request = new HTTP\Request($serverVars); + $body = $this->response->getBodyAsString(); + $this->assertTrue(strpos($body, '<title>dir') !== false, $body); + $this->assertTrue(strpos($body, '<a href="/dir/child.txt">')!==false); + + } + function testCollectionGetRoot() { + + $request = new HTTP\Request('GET', '/'); $this->server->httpRequest = ($request); $this->server->exec(); - $this->assertEquals('HTTP/1.1 404 Not Found',$this->response->status); + $this->assertEquals(200, $this->response->status, "Incorrect status received. Full response body: " . $this->response->getBodyAsString()); + $this->assertEquals( + [ + 'X-Sabre-Version' => [DAV\Version::VERSION], + 'Content-Type' => ['text/html; charset=utf-8'], + 'Content-Security-Policy' => ["img-src 'self'; style-src 'self';"] + ], + $this->response->getHeaders() + ); + + $body = $this->response->getBodyAsString(); + $this->assertTrue(strpos($body, '<title>/') !== false, $body); + $this->assertTrue(strpos($body, '<a href="/dir/">')!==false); + $this->assertTrue(strpos($body, '<span class="btn disabled">')!==false); } - function testPostOtherContentType() { + function testGETPassthru() { - $serverVars = array( - 'REQUEST_URI' => '/', - 'REQUEST_METHOD' => 'POST', - 'CONTENT_TYPE' => 'text/xml', + $request = new HTTP\Request('GET', '/random'); + $response = new HTTP\Response(); + $this->assertNull( + $this->plugin->httpGet($request, $response) ); - $request = new HTTP\Request($serverVars); + + } + + function testPostOtherContentType() { + + $request = new HTTP\Request('POST', '/', ['Content-Type' => 'text/xml']); $this->server->httpRequest = $request; $this->server->exec(); - $this->assertEquals('HTTP/1.1 501 Not Implemented', $this->response->status); + $this->assertEquals(501, $this->response->status); } function testPostNoSabreAction() { - $serverVars = array( - 'REQUEST_URI' => '/', - 'REQUEST_METHOD' => 'POST', - 'CONTENT_TYPE' => 'application/x-www-form-urlencoded', - ); - $postVars = array(); - - $request = new HTTP\Request($serverVars,$postVars); + $request = new HTTP\Request('POST', '/', ['Content-Type' => 'application/x-www-form-urlencoded']); + $request->setPostData([]); $this->server->httpRequest = $request; $this->server->exec(); - $this->assertEquals('HTTP/1.1 501 Not Implemented', $this->response->status); + $this->assertEquals(501, $this->response->status); } @@ -98,17 +132,55 @@ class PluginTest extends DAV\AbstractServer{ 'name' => 'new_collection', ); - $request = new HTTP\Request($serverVars,$postVars); + $request = HTTP\Sapi::createFromServerArray($serverVars); + $request->setPostData($postVars); $this->server->httpRequest = $request; $this->server->exec(); - $this->assertEquals('HTTP/1.1 302 Found', $this->response->status); + $this->assertEquals(302, $this->response->status); $this->assertEquals(array( - 'Location' => '/', - ), $this->response->headers); + 'X-Sabre-Version' => [DAV\Version::VERSION], + 'Location' => ['/'], + ), $this->response->getHeaders()); $this->assertTrue(is_dir(SABRE_TEMPDIR . '/new_collection')); } + function testGetAsset() { + + $request = new HTTP\Request('GET', '/?sabreAction=asset&assetName=favicon.ico'); + $this->server->httpRequest = $request; + $this->server->exec(); + + $this->assertEquals(200, $this->response->getStatus(), 'Error: ' . $this->response->body); + $this->assertEquals([ + 'X-Sabre-Version' => [DAV\Version::VERSION], + 'Content-Type' => ['image/vnd.microsoft.icon'], + 'Content-Length' => ['4286'], + 'Cache-Control' => ['public, max-age=1209600'], + 'Content-Security-Policy' => ["img-src 'self'; style-src 'self';"] + ], $this->response->getHeaders()); + + } + + function testGetAsset404() { + + $request = new HTTP\Request('GET', '/?sabreAction=asset&assetName=flavicon.ico'); + $this->server->httpRequest = $request; + $this->server->exec(); + + $this->assertEquals(404, $this->response->getStatus(), 'Error: ' . $this->response->body); + + } + + function testGetAssetEscapeBasePath() { + + $request = new HTTP\Request('GET', '/?sabreAction=asset&assetName=./../assets/favicon.ico'); + $this->server->httpRequest = $request; + $this->server->exec(); + + $this->assertEquals(404, $this->response->getStatus(), 'Error: ' . $this->response->body); + + } } diff --git a/vendor/sabre/dav/tests/Sabre/DAV/ClientMock.php b/vendor/sabre/dav/tests/Sabre/DAV/ClientMock.php index 6e74e6ec0..d8b53a5a1 100644 --- a/vendor/sabre/dav/tests/Sabre/DAV/ClientMock.php +++ b/vendor/sabre/dav/tests/Sabre/DAV/ClientMock.php @@ -2,21 +2,16 @@ namespace Sabre\DAV; +use Sabre\HTTP\RequestInterface; + class ClientMock extends Client { + public $request; public $response; public $url; public $curlSettings; - protected function curlRequest($url, $curlSettings) { - - $this->url = $url; - $this->curlSettings = $curlSettings; - return $this->response; - - } - /** * Just making this method public * @@ -29,4 +24,11 @@ class ClientMock extends Client { } + public function doRequest(RequestInterface $request) { + + $this->request = $request; + return $this->response; + + } + } diff --git a/vendor/sabre/dav/tests/Sabre/DAV/ClientTest.php b/vendor/sabre/dav/tests/Sabre/DAV/ClientTest.php index 9c3532a47..4cf27dfaa 100644 --- a/vendor/sabre/dav/tests/Sabre/DAV/ClientTest.php +++ b/vendor/sabre/dav/tests/Sabre/DAV/ClientTest.php @@ -2,15 +2,27 @@ namespace Sabre\DAV; +use Sabre\HTTP\Request; +use Sabre\HTTP\Response; + require_once 'Sabre/DAV/ClientMock.php'; class ClientTest extends \PHPUnit_Framework_TestCase { + function setUp() { + + if (!function_exists('curl_init')) { + $this->markTestSkipped('CURL must be installed to test the client'); + } + + } + function testConstruct() { - $client = new ClientMock(array( + $client = new ClientMock([ 'baseUri' => '/', - )); + ]); + $this->assertInstanceOf('Sabre\DAV\ClientMock', $client); } @@ -19,931 +31,276 @@ class ClientTest extends \PHPUnit_Framework_TestCase { */ function testConstructNoBaseUri() { - $client = new ClientMock(array()); + $client = new ClientMock([]); } - function testRequest() { - - $client = new ClientMock(array( - 'baseUri' => 'http://example.org/foo/bar/', - )); - - $responseBlob = array( - "HTTP/1.1 200 OK", - "Content-Type: text/plain", - "", - "Hello there!" - ); - - $client->response = array( - implode("\r\n", $responseBlob), - array( - 'header_size' => 45, - 'http_code' => 200, - ), - 0, - "" - ); - - $result = $client->request('POST', 'baz', 'sillybody', array('Content-Type' => 'text/plain')); - - $this->assertEquals('http://example.org/foo/bar/baz', $client->url); - $this->assertEquals(array( - CURLOPT_RETURNTRANSFER => true, - CURLOPT_FOLLOWLOCATION => true, - CURLOPT_MAXREDIRS => 5, - CURLOPT_CUSTOMREQUEST => 'POST', - CURLOPT_POSTFIELDS => 'sillybody', - CURLOPT_HEADER => true, - CURLOPT_HTTPHEADER => array('Content-Type: text/plain'), - ), $client->curlSettings); + function testAuth() { - $this->assertEquals(array( - 'statusCode' => 200, - 'headers' => array( - 'content-type' => 'text/plain', - ), - 'body' => 'Hello there!' - ), $result); + $client = new ClientMock([ + 'baseUri' => '/', + 'userName' => 'foo', + 'password' => 'bar', + ]); + $this->assertEquals("foo:bar", $client->curlSettings[CURLOPT_USERPWD]); + $this->assertEquals(CURLAUTH_BASIC | CURLAUTH_DIGEST, $client->curlSettings[CURLOPT_HTTPAUTH]); } + function testBasicAuth() { - function testRequestProxy() { + $client = new ClientMock([ + 'baseUri' => '/', + 'userName' => 'foo', + 'password' => 'bar', + 'authType' => Client::AUTH_BASIC + ]); - $client = new ClientMock(array( - 'baseUri' => 'http://example.org/foo/bar/', - 'proxy' => 'http://localhost:8000/', - )); - - $responseBlob = array( - "HTTP/1.1 200 OK", - "Content-Type: text/plain", - "", - "Hello there!" - ); - - $client->response = array( - implode("\r\n", $responseBlob), - array( - 'header_size' => 45, - 'http_code' => 200, - ), - 0, - "" - ); - - $result = $client->request('POST', 'baz', 'sillybody', array('Content-Type' => 'text/plain')); - - $this->assertEquals('http://example.org/foo/bar/baz', $client->url); - $this->assertEquals(array( - CURLOPT_RETURNTRANSFER => true, - CURLOPT_FOLLOWLOCATION => true, - CURLOPT_MAXREDIRS => 5, - CURLOPT_CUSTOMREQUEST => 'POST', - CURLOPT_POSTFIELDS => 'sillybody', - CURLOPT_HEADER => true, - CURLOPT_HTTPHEADER => array('Content-Type: text/plain'), - CURLOPT_PROXY => 'http://localhost:8000/', - ), $client->curlSettings); - - $this->assertEquals(array( - 'statusCode' => 200, - 'headers' => array( - 'content-type' => 'text/plain', - ), - 'body' => 'Hello there!' - ), $result); + $this->assertEquals("foo:bar", $client->curlSettings[CURLOPT_USERPWD]); + $this->assertEquals(CURLAUTH_BASIC, $client->curlSettings[CURLOPT_HTTPAUTH]); } - function testRequestCAInfo() { - - $client = new ClientMock(array( - 'baseUri' => 'http://example.org/foo/bar/', - )); + function testDigestAuth() { - $responseBlob = array( - "HTTP/1.1 200 OK", - "Content-Type: text/plain", - "", - "Hello there!" - ); - - $client->response = array( - implode("\r\n", $responseBlob), - array( - 'header_size' => 45, - 'http_code' => 200, - ), - 0, - "" - ); + $client = new ClientMock([ + 'baseUri' => '/', + 'userName' => 'foo', + 'password' => 'bar', + 'authType' => Client::AUTH_DIGEST + ]); - $client->addTrustedCertificates('bla'); - - $result = $client->request('POST', 'baz', 'sillybody', array('Content-Type' => 'text/plain')); - - $this->assertEquals('http://example.org/foo/bar/baz', $client->url); - $this->assertEquals(array( - CURLOPT_RETURNTRANSFER => true, - CURLOPT_FOLLOWLOCATION => true, - CURLOPT_MAXREDIRS => 5, - CURLOPT_CUSTOMREQUEST => 'POST', - CURLOPT_POSTFIELDS => 'sillybody', - CURLOPT_HEADER => true, - CURLOPT_CAINFO => 'bla', - CURLOPT_HTTPHEADER => array('Content-Type: text/plain'), - ), $client->curlSettings); + $this->assertEquals("foo:bar", $client->curlSettings[CURLOPT_USERPWD]); + $this->assertEquals(CURLAUTH_DIGEST, $client->curlSettings[CURLOPT_HTTPAUTH]); } - function testRequestSslPeer() { + function testNTLMAuth() { - $client = new ClientMock(array( - 'baseUri' => 'http://example.org/foo/bar/', - )); + $client = new ClientMock([ + 'baseUri' => '/', + 'userName' => 'foo', + 'password' => 'bar', + 'authType' => Client::AUTH_NTLM + ]); - $responseBlob = array( - "HTTP/1.1 200 OK", - "Content-Type: text/plain", - "", - "Hello there!" - ); - - $client->response = array( - implode("\r\n", $responseBlob), - array( - 'header_size' => 45, - 'http_code' => 200, - ), - 0, - "" - ); - - $client->setVerifyPeer(true); - - $result = $client->request('POST', 'baz', 'sillybody', array('Content-Type' => 'text/plain')); - - $this->assertEquals('http://example.org/foo/bar/baz', $client->url); - $this->assertEquals(array( - CURLOPT_RETURNTRANSFER => true, - CURLOPT_FOLLOWLOCATION => true, - CURLOPT_MAXREDIRS => 5, - CURLOPT_CUSTOMREQUEST => 'POST', - CURLOPT_POSTFIELDS => 'sillybody', - CURLOPT_HEADER => true, - CURLOPT_HTTPHEADER => array('Content-Type: text/plain'), - CURLOPT_SSL_VERIFYPEER => true - ), $client->curlSettings); - - } - - function testRequestAuth() { - - $client = new ClientMock(array( - 'baseUri' => 'http://example.org/foo/bar/', - 'userName' => 'user', - 'password' => 'password', - )); - - $responseBlob = array( - "HTTP/1.1 200 OK", - "Content-Type: text/plain", - "", - "Hello there!" - ); - - $client->response = array( - implode("\r\n", $responseBlob), - array( - 'header_size' => 45, - 'http_code' => 200, - ), - 0, - "" - ); - - $result = $client->request('POST', 'baz', 'sillybody', array('Content-Type' => 'text/plain')); - - $this->assertEquals('http://example.org/foo/bar/baz', $client->url); - $this->assertEquals(array( - CURLOPT_RETURNTRANSFER => true, - CURLOPT_FOLLOWLOCATION => true, - CURLOPT_MAXREDIRS => 5, - CURLOPT_CUSTOMREQUEST => 'POST', - CURLOPT_POSTFIELDS => 'sillybody', - CURLOPT_HEADER => true, - CURLOPT_HTTPHEADER => array('Content-Type: text/plain'), - CURLOPT_HTTPAUTH => CURLAUTH_BASIC | CURLAUTH_DIGEST, - CURLOPT_USERPWD => 'user:password' - ), $client->curlSettings); - - $this->assertEquals(array( - 'statusCode' => 200, - 'headers' => array( - 'content-type' => 'text/plain', - ), - 'body' => 'Hello there!' - ), $result); - - } - - function testRequestAuthBasic() { - - $client = new ClientMock(array( - 'baseUri' => 'http://example.org/foo/bar/', - 'userName' => 'user', - 'password' => 'password', - 'authType' => Client::AUTH_BASIC, - )); - - $responseBlob = array( - "HTTP/1.1 200 OK", - "Content-Type: text/plain", - "", - "Hello there!" - ); - - $client->response = array( - implode("\r\n", $responseBlob), - array( - 'header_size' => 45, - 'http_code' => 200, - ), - 0, - "" - ); - - $result = $client->request('POST', 'baz', 'sillybody', array('Content-Type' => 'text/plain')); - - $this->assertEquals('http://example.org/foo/bar/baz', $client->url); - $this->assertEquals(array( - CURLOPT_RETURNTRANSFER => true, - CURLOPT_FOLLOWLOCATION => true, - CURLOPT_MAXREDIRS => 5, - CURLOPT_CUSTOMREQUEST => 'POST', - CURLOPT_POSTFIELDS => 'sillybody', - CURLOPT_HEADER => true, - CURLOPT_HTTPHEADER => array('Content-Type: text/plain'), - CURLOPT_HTTPAUTH => CURLAUTH_BASIC, - CURLOPT_USERPWD => 'user:password' - ), $client->curlSettings); - - $this->assertEquals(array( - 'statusCode' => 200, - 'headers' => array( - 'content-type' => 'text/plain', - ), - 'body' => 'Hello there!' - ), $result); + $this->assertEquals("foo:bar", $client->curlSettings[CURLOPT_USERPWD]); + $this->assertEquals(CURLAUTH_NTLM, $client->curlSettings[CURLOPT_HTTPAUTH]); } - function testRequestAuthDigest() { - - $client = new ClientMock(array( - 'baseUri' => 'http://example.org/foo/bar/', - 'userName' => 'user', - 'password' => 'password', - 'authType' => Client::AUTH_DIGEST, - )); + function testProxy() { - $responseBlob = array( - "HTTP/1.1 200 OK", - "Content-Type: text/plain", - "", - "Hello there!" - ); - - $client->response = array( - implode("\r\n", $responseBlob), - array( - 'header_size' => 45, - 'http_code' => 200, - ), - 0, - "" - ); - - $result = $client->request('POST', 'baz', 'sillybody', array('Content-Type' => 'text/plain')); - - $this->assertEquals('http://example.org/foo/bar/baz', $client->url); - $this->assertEquals(array( - CURLOPT_RETURNTRANSFER => true, - CURLOPT_FOLLOWLOCATION => true, - CURLOPT_MAXREDIRS => 5, - CURLOPT_CUSTOMREQUEST => 'POST', - CURLOPT_POSTFIELDS => 'sillybody', - CURLOPT_HEADER => true, - CURLOPT_HTTPHEADER => array('Content-Type: text/plain'), - CURLOPT_HTTPAUTH => CURLAUTH_DIGEST, - CURLOPT_USERPWD => 'user:password' - ), $client->curlSettings); - - $this->assertEquals(array( - 'statusCode' => 200, - 'headers' => array( - 'content-type' => 'text/plain', - ), - 'body' => 'Hello there!' - ), $result); - - } - function testRequestError() { - - $client = new ClientMock(array( - 'baseUri' => 'http://example.org/foo/bar/', - )); - - $responseBlob = array( - "HTTP/1.1 200 OK", - "Content-Type: text/plain", - "", - "Hello there!" - ); - - $client->response = array( - implode("\r\n", $responseBlob), - array( - 'header_size' => 45, - 'http_code' => 200, - ), - CURLE_COULDNT_CONNECT, - "Could not connect, or something" - ); + $client = new ClientMock([ + 'baseUri' => '/', + 'proxy' => 'localhost:8888', + ]); - $caught = false; - try { - $client->request('POST', 'baz', 'sillybody', array('Content-Type' => 'text/plain')); - } catch (Exception $e) { - $caught = true; - } - if (!$caught) { - $this->markTestFailed('Exception was not thrown'); - } + $this->assertEquals("localhost:8888", $client->curlSettings[CURLOPT_PROXY]); } - function testRequestHTTPError() { - - $client = new ClientMock(array( - 'baseUri' => 'http://example.org/foo/bar/', - )); + function testEncoding() { - $responseBlob = array( - "HTTP/1.1 400 Bad Request", - "Content-Type: text/plain", - "", - "Hello there!" - ); - - $client->response = array( - implode("\r\n", $responseBlob), - array( - 'header_size' => 45, - 'http_code' => 400, - ), - 0, - "" - ); + $client = new ClientMock([ + 'baseUri' => '/', + 'encoding' => Client::ENCODING_IDENTITY | Client::ENCODING_GZIP | Client::ENCODING_DEFLATE, + ]); - $caught = false; - try { - $client->request('POST', 'baz', 'sillybody', array('Content-Type' => 'text/plain')); - } catch (Exception $e) { - $caught = true; - } - if (!$caught) { - $this->fail('Exception was not thrown'); - } + $this->assertEquals("identity,deflate,gzip", $client->curlSettings[CURLOPT_ENCODING]); } - function testRequestHTTP404() { - - $client = new ClientMock(array( - 'baseUri' => 'http://example.org/foo/bar/', - )); - - $responseBlob = array( - "HTTP/1.1 404 Not Found", - "Content-Type: text/plain", - "", - "Hello there!" - ); - - $client->response = array( - implode("\r\n", $responseBlob), - array( - 'header_size' => 45, - 'http_code' => 404, - ), - 0, - "" - ); + function testPropFind() { - $caught = false; - try { - $client->request('POST', 'baz', 'sillybody', array('Content-Type' => 'text/plain')); - } catch (Exception\NotFound $e) { - $caught = true; - } - if (!$caught) { - $this->fail('Exception was not thrown'); - } + $client = new ClientMock([ + 'baseUri' => '/', + ]); + + $responseBody = <<<XML +<?xml version="1.0"?> +<multistatus xmlns="DAV:"> + <response> + <href>/foo</href> + <propstat> + <prop> + <displayname>bar</displayname> + </prop> + <status>HTTP/1.1 200 OK</status> + </propstat> + </response> +</multistatus> +XML; + + $client->response = new Response(207, [], $responseBody); + $result = $client->propFind('foo', ['{DAV:}displayname', '{urn:zim}gir']); + + $this->assertEquals(['{DAV:}displayname' => 'bar'], $result); + + $request = $client->request; + $this->assertEquals('PROPFIND', $request->getMethod()); + $this->assertEquals('/foo', $request->getUrl()); + $this->assertEquals([ + 'Depth' => ['0'], + 'Content-Type' => ['application/xml'], + ], $request->getHeaders()); } /** - * @dataProvider supportedHTTPCodes + * @expectedException \Sabre\HTTP\ClientHttpException */ - function testSpecificHTTPErrors($error) { - - $client = new ClientMock(array( - 'baseUri' => 'http://example.org/foo/bar/', - )); - - $responseBlob = array( - "HTTP/1.1 $error blabla", - "Content-Type: text/plain", - "", - "Hello there!" - ); - - $client->response = array( - implode("\r\n", $responseBlob), - array( - 'header_size' => 42, - 'http_code' => $error, - ), - 0, - "" - ); - - try { - $client->request('POST', 'baz', 'sillybody', array('Content-Type' => 'text/plain')); - $this->fail('Exception was not thrown'); - } catch (Exception $e) { - $this->assertEquals($e->getHTTPCode(), $error); - } - - - } - - public function supportedHTTPCodes() { - - return array( - array(400), - array(401), - array(402), - array(403), - array(404), - array(405), - array(409), - array(412), - array(416), - array(500), - array(501), - array(507), - ); - - } - - function testUnsupportedHTTPError() { - - $client = new ClientMock(array( - 'baseUri' => 'http://example.org/foo/bar/', - )); - - $responseBlob = array( - "HTTP/1.1 580 blabla", - "Content-Type: text/plain", - "", - "Hello there!" - ); - - $client->response = array( - implode("\r\n", $responseBlob), - array( - 'header_size' => 42, - 'http_code' => "580" - ), - 0, - "" - ); - - try { - $client->request('POST', 'baz', 'sillybody', array('Content-Type' => 'text/plain')); - $this->fail('Exception was not thrown'); - } catch (Exception $e) { - $this->assertEquals(500, $e->getHTTPCode()); - } - - - } - - function testGetAbsoluteUrl() { + function testPropFindError() { - $client = new ClientMock(array( - 'baseUri' => 'http://example.org/foo/', - )); - - $this->assertEquals( - 'http://example.org/foo/bar', - $client->getAbsoluteUrl('bar') - ); - - $this->assertEquals( - 'http://example.org/bar', - $client->getAbsoluteUrl('/bar') - ); + $client = new ClientMock([ + 'baseUri' => '/', + ]); - $this->assertEquals( - 'http://example.com/bar', - $client->getAbsoluteUrl('http://example.com/bar') - ); + $client->response = new Response(405, []); + $client->propFind('foo', ['{DAV:}displayname', '{urn:zim}gir']); } - function testOptions() { - - $client = new ClientMock(array( - 'baseUri' => 'http://example.org/foo/bar/', - )); - - $responseBlob = array( - "HTTP/1.1 200 OK", - "DAV: feature1, feature2", - "", - ); - - $client->response = array( - implode("\r\n", $responseBlob), - array( - 'header_size' => 40, - 'http_code' => 200, - ), - 0, - "" - ); + function testPropFindDepth1() { - $result = $client->options(); - $this->assertEquals( - array('feature1', 'feature2'), - $result - ); + $client = new ClientMock([ + 'baseUri' => '/', + ]); + + $responseBody = <<<XML +<?xml version="1.0"?> +<multistatus xmlns="DAV:"> + <response> + <href>/foo</href> + <propstat> + <prop> + <displayname>bar</displayname> + </prop> + <status>HTTP/1.1 200 OK</status> + </propstat> + </response> +</multistatus> +XML; + + $client->response = new Response(207, [], $responseBody); + $result = $client->propFind('foo', ['{DAV:}displayname', '{urn:zim}gir'], 1); + + $this->assertEquals([ + '/foo' => [ + '{DAV:}displayname' => 'bar' + ], + ], $result); + + $request = $client->request; + $this->assertEquals('PROPFIND', $request->getMethod()); + $this->assertEquals('/foo', $request->getUrl()); + $this->assertEquals([ + 'Depth' => ['1'], + 'Content-Type' => ['application/xml'], + ], $request->getHeaders()); } - function testOptionsNoDav() { - - $client = new ClientMock(array( - 'baseUri' => 'http://example.org/foo/bar/', - )); - - $responseBlob = array( - "HTTP/1.1 200 OK", - "", - ); - - $client->response = array( - implode("\r\n", $responseBlob), - array( - 'header_size' => 20, - 'http_code' => 200, - ), - 0, - "" - ); + function testPropPatch() { - $result = $client->options(); - $this->assertEquals( - array(), - $result - ); + $client = new ClientMock([ + 'baseUri' => '/', + ]); + + $responseBody = <<<XML +<?xml version="1.0"?> +<multistatus xmlns="DAV:"> + <response> + <href>/foo</href> + <propstat> + <prop> + <displayname>bar</displayname> + </prop> + <status>HTTP/1.1 200 OK</status> + </propstat> + </response> +</multistatus> +XML; + + $client->response = new Response(207, [], $responseBody); + $result = $client->propPatch('foo', ['{DAV:}displayname' => 'hi', '{urn:zim}gir' => null], 1); + $this->assertTrue($result); + $request = $client->request; + $this->assertEquals('PROPPATCH', $request->getMethod()); + $this->assertEquals('/foo', $request->getUrl()); + $this->assertEquals([ + 'Content-Type' => ['application/xml'], + ], $request->getHeaders()); } /** - * @expectedException InvalidArgumentException + * @depends testPropPatch + * @expectedException \Sabre\HTTP\ClientHttpException */ - function testPropFindNoXML() { - - $client = new ClientMock(array( - 'baseUri' => 'http://example.org/foo/bar/', - )); - - $responseBlob = array( - "HTTP/1.1 200 OK", - "", - ); - - $client->response = array( - implode("\r\n", $responseBlob), - array( - 'header_size' => 20, - 'http_code' => 200, - ), - 0, - "" - ); + function testPropPatchHTTPError() { - $client->propfind('', array('{DAV:}foo','{DAV:}bar')); - - } - - function testPropFind() { - - $client = new ClientMock(array( - 'baseUri' => 'http://example.org/foo/bar/', - )); - - $responseBlob = array( - "HTTP/1.1 200 OK", - "", - "<?xml version=\"1.0\"?>", - "<d:multistatus xmlns:d=\"DAV:\">", - " <d:response>", - " <d:href>/foo/bar/</d:href>", - " <d:propstat>", - " <d:prop>", - " <d:foo>hello</d:foo>", - " </d:prop>", - " <d:status>HTTP/1.1 200 OK</d:status>", - " </d:propstat>", - " <d:propstat>", - " <d:prop>", - " <d:bar />", - " </d:prop>", - " <d:status>HTTP/1.1 404 Not Found</d:status>", - " </d:propstat>", - " </d:response>", - "</d:multistatus>", - ); - - $client->response = array( - implode("\r\n", $responseBlob), - array( - 'header_size' => 19, - 'http_code' => 200, - ), - 0, - "" - ); - - $result = $client->propfind('', array('{DAV:}foo','{DAV:}bar')); - - $this->assertEquals(array( - '{DAV:}foo' => 'hello', - ), $result); - - $requestBody = array( - '<?xml version="1.0"?>', - '<d:propfind xmlns:d="DAV:">', - ' <d:prop>', - ' <d:foo />', - ' <d:bar />', - ' </d:prop>', - '</d:propfind>' - ); - $requestBody = implode("\n", $requestBody); + $client = new ClientMock([ + 'baseUri' => '/', + ]); - $this->assertEquals($requestBody, $client->curlSettings[CURLOPT_POSTFIELDS]); + $client->response = new Response(403, [], ''); + $client->propPatch('foo', ['{DAV:}displayname' => 'hi', '{urn:zim}gir' => null], 1); } /** - * This was reported in Issue 235. - * - * If no '200 Ok' properties are returned, the client will throw an - * E_NOTICE. + * @depends testPropPatch + * @expectedException Sabre\HTTP\ClientException */ - function testPropFindNo200s() { - - $client = new ClientMock(array( - 'baseUri' => 'http://example.org/foo/bar/', - )); - - $responseBlob = array( - "HTTP/1.1 200 OK", - "", - "<?xml version=\"1.0\"?>", - "<d:multistatus xmlns:d=\"DAV:\">", - " <d:response>", - " <d:href>/foo/bar/</d:href>", - " <d:propstat>", - " <d:prop>", - " <d:bar />", - " </d:prop>", - " <d:status>HTTP/1.1 404 Not Found</d:status>", - " </d:propstat>", - " </d:response>", - "</d:multistatus>", - ); - - $client->response = array( - implode("\r\n", $responseBlob), - array( - 'header_size' => 19, - 'http_code' => 200, - ), - 0, - "" - ); - - $result = $client->propfind('', array('{DAV:}foo','{DAV:}bar')); - - $this->assertEquals(array( - ), $result); - - } - - function testPropFindDepth1CustomProp() { - - $client = new ClientMock(array( - 'baseUri' => 'http://example.org/foo/bar/', - )); - - $responseBlob = array( - "HTTP/1.1 200 OK", - "", - "<?xml version=\"1.0\"?>", - "<d:multistatus xmlns:d=\"DAV:\" xmlns:x=\"urn:custom\">", - " <d:response>", - " <d:href>/foo/bar/</d:href>", - " <d:propstat>", - " <d:prop>", - " <d:foo>hello</d:foo>", - " <x:bar>world</x:bar>", - " </d:prop>", - " <d:status>HTTP/1.1 200 OK</d:status>", - " </d:propstat>", - " </d:response>", - "</d:multistatus>", - ); - - $client->response = array( - implode("\r\n", $responseBlob), - array( - 'header_size' => 19, - 'http_code' => 200, - ), - 0, - "" - ); - - $result = $client->propfind('', array('{DAV:}foo','{urn:custom}bar'),1); - - $this->assertEquals(array( - "/foo/bar/" => array( - '{DAV:}foo' => 'hello', - '{urn:custom}bar' => 'world', - ), - ), $result); - - $requestBody = array( - '<?xml version="1.0"?>', - '<d:propfind xmlns:d="DAV:">', - ' <d:prop>', - ' <d:foo />', - ' <x:bar xmlns:x="urn:custom"/>', - ' </d:prop>', - '</d:propfind>' - ); - $requestBody = implode("\n", $requestBody); - - $this->assertEquals($requestBody, $client->curlSettings[CURLOPT_POSTFIELDS]); - - } - - function testPropPatch() { - - $client = new ClientMock(array( - 'baseUri' => 'http://example.org/foo/bar/', - )); - - $responseBlob = array( - "HTTP/1.1 200 OK", - "", - ); - - $client->response = array( - implode("\r\n", $responseBlob), - array( - 'header_size' => 20, - 'http_code' => 200, - ), - 0, - "" - ); - - $client->proppatch('', array( - '{DAV:}foo' => 'newvalue', - '{urn:custom}foo' => 'newvalue2', - '{DAV:}bar' => null, - '{urn:custom}bar' => null, - )); - - $requestBody = array( - '<?xml version="1.0"?>', - '<d:propertyupdate xmlns:d="DAV:">', - '<d:set><d:prop>', - ' <d:foo>newvalue</d:foo>', - '</d:prop></d:set>', - '<d:set><d:prop>', - ' <x:foo xmlns:x="urn:custom">newvalue2</x:foo>', - '</d:prop></d:set>', - '<d:remove><d:prop>', - ' <d:bar />', - '</d:prop></d:remove>', - '<d:remove><d:prop>', - ' <x:bar xmlns:x="urn:custom"/>', - '</d:prop></d:remove>', - '</d:propertyupdate>' - ); - $requestBody = implode("\n", $requestBody); - - $this->assertEquals($requestBody, $client->curlSettings[CURLOPT_POSTFIELDS]); - - } - - function testHEADRequest() { + function testPropPatchMultiStatusError() { - $client = new ClientMock(array( - 'baseUri' => 'http://example.org/foo/bar/', - )); - - $responseBlob = array( - "HTTP/1.1 200 OK", - "Content-Type: text/plain", - "", - "Hello there!" - ); - - $client->response = array( - implode("\r\n", $responseBlob), - array( - 'header_size' => 45, - 'http_code' => 200, - ), - 0, - "" - ); - - $result = $client->request('HEAD', 'baz'); - - $this->assertEquals('http://example.org/foo/bar/baz', $client->url); - $this->assertEquals(array( - CURLOPT_RETURNTRANSFER => true, - CURLOPT_FOLLOWLOCATION => true, - CURLOPT_MAXREDIRS => 5, - CURLOPT_CUSTOMREQUEST => 'HEAD', - CURLOPT_NOBODY => true, - CURLOPT_HEADER => true, - CURLOPT_HTTPHEADER => array(), - CURLOPT_POSTFIELDS => null, - ), $client->curlSettings); + $client = new ClientMock([ + 'baseUri' => '/', + ]); + + $responseBody = <<<XML +<?xml version="1.0"?> +<multistatus xmlns="DAV:"> +<response> + <href>/foo</href> + <propstat> + <prop> + <displayname /> + </prop> + <status>HTTP/1.1 403 Forbidden</status> + </propstat> +</response> +</multistatus> +XML; + + $client->response = new Response(207, [], $responseBody); + $client->propPatch('foo', ['{DAV:}displayname' => 'hi', '{urn:zim}gir' => null], 1); } - function testPUTRequest() { + function testOPTIONS() { - $client = new ClientMock(array( - 'baseUri' => 'http://example.org/foo/bar/', - )); + $client = new ClientMock([ + 'baseUri' => '/', + ]); - $responseBlob = array( - "HTTP/1.1 200 OK", - "Content-Type: text/plain", - "", - "Hello there!" - ); + $client->response = new Response(207, [ + 'DAV' => 'calendar-access, extended-mkcol', + ]); + $result = $client->options(); - $client->response = array( - implode("\r\n", $responseBlob), - array( - 'header_size' => 45, - 'http_code' => 200, - ), - 0, - "" + $this->assertEquals( + ['calendar-access', 'extended-mkcol'], + $result ); - $result = $client->request('PUT', 'bar','newcontent'); - - $this->assertEquals('http://example.org/foo/bar/bar', $client->url); - $this->assertEquals(array( - CURLOPT_RETURNTRANSFER => true, - CURLOPT_FOLLOWLOCATION => true, - CURLOPT_MAXREDIRS => 5, - CURLOPT_CUSTOMREQUEST => "PUT", - CURLOPT_POSTFIELDS => 'newcontent', - CURLOPT_HEADER => true, - CURLOPT_HTTPHEADER => array(), - ), $client->curlSettings); + $request = $client->request; + $this->assertEquals('OPTIONS', $request->getMethod()); + $this->assertEquals('/', $request->getUrl()); + $this->assertEquals([ + ], $request->getHeaders()); } } diff --git a/vendor/sabre/dav/tests/Sabre/DAV/FSExt/FileTest.php b/vendor/sabre/dav/tests/Sabre/DAV/FSExt/FileTest.php index 8947c6688..3708594e0 100644 --- a/vendor/sabre/dav/tests/Sabre/DAV/FSExt/FileTest.php +++ b/vendor/sabre/dav/tests/Sabre/DAV/FSExt/FileTest.php @@ -22,73 +22,90 @@ class FileTest extends \PHPUnit_Framework_TestCase { function testPut() { - $file = new File(SABRE_TEMPDIR . '/file.txt'); - $result = $file->put('New contents'); - - $this->assertEquals('New contents',file_get_contents(SABRE_TEMPDIR . '/file.txt')); - $this->assertEquals('"' . md5('New contents') . '"', $result); + $filename = SABRE_TEMPDIR . '/file.txt'; + $file = new File($filename); + $result = $file->put('New contents'); + + $this->assertEquals('New contents',file_get_contents(SABRE_TEMPDIR . '/file.txt')); + $this->assertEquals( + '"' . + sha1( + fileinode($filename) . + filesize($filename ) . + filemtime($filename) + ) . '"', + $result + ); } function testRange() { - $file = new File(SABRE_TEMPDIR . '/file.txt'); - $file->put('0000000'); - $file->patch('111', 2, 3); + $file = new File(SABRE_TEMPDIR . '/file.txt'); + $file->put('0000000'); + $file->patch('111', 2, 3); - $this->assertEquals('0001110',file_get_contents(SABRE_TEMPDIR . '/file.txt')); + $this->assertEquals('0001110',file_get_contents(SABRE_TEMPDIR . '/file.txt')); } function testRangeStream() { - $stream = fopen('php://memory','r+'); - fwrite($stream, "222"); - rewind($stream); + $stream = fopen('php://memory','r+'); + fwrite($stream, "222"); + rewind($stream); - $file = new File(SABRE_TEMPDIR . '/file.txt'); - $file->put('0000000'); - $file->patch($stream, 2, 3); + $file = new File(SABRE_TEMPDIR . '/file.txt'); + $file->put('0000000'); + $file->patch($stream, 2, 3); - $this->assertEquals('0002220',file_get_contents(SABRE_TEMPDIR . '/file.txt')); + $this->assertEquals('0002220',file_get_contents(SABRE_TEMPDIR . '/file.txt')); } function testGet() { - $file = new File(SABRE_TEMPDIR . '/file.txt'); - $this->assertEquals('Contents',stream_get_contents($file->get())); + $file = new File(SABRE_TEMPDIR . '/file.txt'); + $this->assertEquals('Contents',stream_get_contents($file->get())); } function testDelete() { - $file = new File(SABRE_TEMPDIR . '/file.txt'); - $file->delete(); + $file = new File(SABRE_TEMPDIR . '/file.txt'); + $file->delete(); - $this->assertFalse(file_exists(SABRE_TEMPDIR . '/file.txt')); + $this->assertFalse(file_exists(SABRE_TEMPDIR . '/file.txt')); } function testGetETag() { - $file = new File(SABRE_TEMPDIR . '/file.txt'); - $this->assertEquals('"' . md5('Contents') . '"',$file->getETag()); - + $filename = SABRE_TEMPDIR . '/file.txt'; + $file = new File($filename); + $this->assertEquals( + '"' . + sha1( + fileinode($filename) . + filesize($filename ) . + filemtime($filename) + ) . '"', + $file->getETag() + ); } function testGetContentType() { - $file = new File(SABRE_TEMPDIR . '/file.txt'); - $this->assertNull($file->getContentType()); + $file = new File(SABRE_TEMPDIR . '/file.txt'); + $this->assertNull($file->getContentType()); } function testGetSize() { - $file = new File(SABRE_TEMPDIR . '/file.txt'); - $this->assertEquals(8,$file->getSize()); + $file = new File(SABRE_TEMPDIR . '/file.txt'); + $this->assertEquals(8,$file->getSize()); } diff --git a/vendor/sabre/dav/tests/Sabre/DAV/FSExt/NodeTest.php b/vendor/sabre/dav/tests/Sabre/DAV/FSExt/NodeTest.php deleted file mode 100644 index 275075b4c..000000000 --- a/vendor/sabre/dav/tests/Sabre/DAV/FSExt/NodeTest.php +++ /dev/null @@ -1,178 +0,0 @@ -<?php - -namespace Sabre\DAV\FSExt; -use Sabre\DAV; - -require_once 'Sabre/TestUtil.php'; - -class NodeTest extends \PHPUnit_Framework_TestCase { - - function setUp() { - - mkdir(SABRE_TEMPDIR . '/dir'); - file_put_contents(SABRE_TEMPDIR . '/dir/file.txt', 'Contents'); - file_put_contents(SABRE_TEMPDIR . '/dir/file2.txt', 'Contents2'); - - } - - function tearDown() { - - \Sabre\TestUtil::clearTempDir(); - - } - - function testUpdateProperties() { - - $file = new File(SABRE_TEMPDIR . '/dir/file.txt'); - $properties = array( - '{http://sabredav.org/NS/2010}test1' => 'foo', - '{http://sabredav.org/NS/2010}test2' => 'bar', - ); - - $result = $file->updateProperties($properties); - $expected = true; - - $this->assertEquals($expected, $result); - - $getProperties = $file->getProperties(array_keys($properties)); - - $this->assertEquals($properties, $getProperties); - - } - - /** - * @depends testUpdateProperties - */ - function testUpdatePropertiesAgain() { - - $file = new File(SABRE_TEMPDIR . '/dir/file.txt'); - $mutations = array( - '{http://sabredav.org/NS/2010}test1' => 'foo', - '{http://sabredav.org/NS/2010}test2' => 'bar', - ); - - $result = $file->updateProperties($mutations); - - $this->assertEquals(true, $result); - - $mutations = array( - '{http://sabredav.org/NS/2010}test1' => 'foo', - '{http://sabredav.org/NS/2010}test3' => 'baz', - ); - - $result = $file->updateProperties($mutations); - - $this->assertEquals(true, $result); - } - - /** - * @depends testUpdateProperties - */ - function testUpdatePropertiesDelete() { - - $file = new File(SABRE_TEMPDIR . '/dir/file.txt'); - - $mutations = array( - '{http://sabredav.org/NS/2010}test1' => 'foo', - '{http://sabredav.org/NS/2010}test2' => 'bar', - ); - - $result = $file->updateProperties($mutations); - - $this->assertEquals(true, $result); - - $mutations = array( - '{http://sabredav.org/NS/2010}test1' => null, - '{http://sabredav.org/NS/2010}test3' => null - ); - - $result = $file->updateProperties($mutations); - - $this->assertEquals(true, $result); - - $properties = $file->getProperties(array('http://sabredav.org/NS/2010}test1','{http://sabredav.org/NS/2010}test2','{http://sabredav.org/NS/2010}test3')); - - $this->assertEquals(array( - '{http://sabredav.org/NS/2010}test2' => 'bar', - ), $properties); - } - - /** - * @depends testUpdateProperties - */ - function testUpdatePropertiesMove() { - - $file = new File(SABRE_TEMPDIR . '/dir/file.txt'); - - $mutations = array( - '{http://sabredav.org/NS/2010}test1' => 'foo', - '{http://sabredav.org/NS/2010}test2' => 'bar', - ); - - $result = $file->updateProperties($mutations); - - $this->assertEquals(true, $result); - - $properties = $file->getProperties(array('{http://sabredav.org/NS/2010}test1','{http://sabredav.org/NS/2010}test2','{http://sabredav.org/NS/2010}test3')); - - $this->assertEquals(array( - '{http://sabredav.org/NS/2010}test1' => 'foo', - '{http://sabredav.org/NS/2010}test2' => 'bar', - ), $properties); - - // Renaming - $file->setName('file3.txt'); - - $this->assertFalse(file_exists(SABRE_TEMPDIR . '/dir/file.txt')); - $this->assertTrue(file_exists(SABRE_TEMPDIR . '/dir/file3.txt')); - $this->assertEquals('file3.txt',$file->getName()); - - $newFile = new File(SABRE_TEMPDIR . '/dir/file3.txt'); - $this->assertEquals('file3.txt',$newFile->getName()); - - $properties = $newFile->getProperties(array('{http://sabredav.org/NS/2010}test1','{http://sabredav.org/NS/2010}test2','{http://sabredav.org/NS/2010}test3')); - - $this->assertEquals(array( - '{http://sabredav.org/NS/2010}test1' => 'foo', - '{http://sabredav.org/NS/2010}test2' => 'bar', - ), $properties); - } - - /** - * @depends testUpdatePropertiesMove - */ - function testUpdatePropertiesDeleteBleed() { - - $file = new File(SABRE_TEMPDIR . '/dir/file.txt'); - $mutations = array( - '{http://sabredav.org/NS/2010}test1' => 'foo', - '{http://sabredav.org/NS/2010}test2' => 'bar', - ); - - $result = $file->updateProperties($mutations); - - $this->assertEquals(true, $result); - - $properties = $file->getProperties(array('{http://sabredav.org/NS/2010}test1','{http://sabredav.org/NS/2010}test2','{http://sabredav.org/NS/2010}test3')); - - $this->assertEquals(array( - '{http://sabredav.org/NS/2010}test1' => 'foo', - '{http://sabredav.org/NS/2010}test2' => 'bar', - ), $properties); - - // Deleting - $file->delete(); - - $this->assertFalse(file_exists(SABRE_TEMPDIR . '/dir/file.txt')); - - // Creating it again - file_put_contents(SABRE_TEMPDIR . '/dir/file.txt','New Contents'); - $file = new File(SABRE_TEMPDIR . '/dir/file.txt'); - - $properties = $file->getProperties(array('http://sabredav.org/NS/2010}test1','{http://sabredav.org/NS/2010}test2','{http://sabredav.org/NS/2010}test3')); - - $this->assertEquals(array(), $properties); - - } - -} diff --git a/vendor/sabre/dav/tests/Sabre/DAV/FSExt/ServerTest.php b/vendor/sabre/dav/tests/Sabre/DAV/FSExt/ServerTest.php index 907ede40b..63d858de1 100644 --- a/vendor/sabre/dav/tests/Sabre/DAV/FSExt/ServerTest.php +++ b/vendor/sabre/dav/tests/Sabre/DAV/FSExt/ServerTest.php @@ -17,116 +17,98 @@ class ServerTest extends DAV\AbstractServer{ function testGet() { - $serverVars = array( - 'REQUEST_URI' => '/test.txt', - 'REQUEST_METHOD' => 'GET', - ); - - $request = new HTTP\Request($serverVars); - $this->server->httpRequest = ($request); + $request = new HTTP\Request('GET', '/test.txt'); + $filename = $this->tempDir . '/test.txt'; + $this->server->httpRequest = $request; $this->server->exec(); - $this->assertEquals(array( - 'Content-Type' => 'application/octet-stream', - 'Content-Length' => 13, - 'Last-Modified' => HTTP\Util::toHTTPDate(new \DateTime('@' . filemtime($this->tempDir . '/test.txt'))), - 'ETag' => '"' .md5_file($this->tempDir . '/test.txt') . '"', - ), - $this->response->headers + $this->assertEquals(200, $this->response->getStatus(), 'Invalid status code received.'); + $this->assertEquals([ + 'X-Sabre-Version' => [DAV\Version::VERSION], + 'Content-Type' => ['application/octet-stream'], + 'Content-Length' => [13], + 'Last-Modified' => [HTTP\Util::toHTTPDate(new \DateTime('@' . filemtime($filename)))], + 'ETag' => ['"' . sha1(fileinode($filename ) . filesize($filename) . filemtime($filename)) . '"'], + ], + $this->response->getHeaders() ); - $this->assertEquals('HTTP/1.1 200 OK',$this->response->status); + $this->assertEquals('Test contents', stream_get_contents($this->response->body)); } function testHEAD() { - $serverVars = array( - 'REQUEST_URI' => '/test.txt', - 'REQUEST_METHOD' => 'HEAD', - ); - - $request = new HTTP\Request($serverVars); + $request = new HTTP\Request('HEAD', '/test.txt'); + $filename = $this->tempDir . '/test.txt'; $this->server->httpRequest = ($request); $this->server->exec(); - $this->assertEquals(array( - 'Content-Type' => 'application/octet-stream', - 'Content-Length' => 13, - 'Last-Modified' => HTTP\Util::toHTTPDate(new \DateTime('@' . filemtime($this->tempDir . '/test.txt'))), - 'ETag' => '"' . md5_file($this->tempDir . '/test.txt') . '"', - ), - $this->response->headers + $this->assertEquals([ + 'X-Sabre-Version' => [DAV\Version::VERSION], + 'Content-Type' => ['application/octet-stream'], + 'Content-Length' => [13], + 'Last-Modified' => [HTTP\Util::toHTTPDate(new \DateTime('@' . filemtime($this->tempDir . '/test.txt')))], + 'ETag' => ['"' . sha1(fileinode($filename ) . filesize($filename) . filemtime($filename)) . '"'], + ], + $this->response->getHeaders() ); - $this->assertEquals('HTTP/1.1 200 OK',$this->response->status); + $this->assertEquals(200,$this->response->status); $this->assertEquals('', $this->response->body); } function testPut() { - $serverVars = array( - 'REQUEST_URI' => '/testput.txt', - 'REQUEST_METHOD' => 'PUT', - ); - - $request = new HTTP\Request($serverVars); + $request = new HTTP\Request('PUT', '/testput.txt'); + $filename = $this->tempDir . '/testput.txt'; $request->setBody('Testing new file'); $this->server->httpRequest = ($request); $this->server->exec(); - $this->assertEquals(array( - 'Content-Length' => 0, - 'ETag' => '"' . md5('Testing new file') . '"', - ), $this->response->headers); + $this->assertEquals([ + 'X-Sabre-Version' => [DAV\Version::VERSION], + 'Content-Length' => ['0'], + 'ETag' => ['"' . sha1(fileinode($filename ) . filesize($filename) . filemtime($filename)) . '"'], + ], $this->response->getHeaders()); - $this->assertEquals('HTTP/1.1 201 Created',$this->response->status); + $this->assertEquals(201, $this->response->status); $this->assertEquals('', $this->response->body); - $this->assertEquals('Testing new file',file_get_contents($this->tempDir . '/testput.txt')); + $this->assertEquals('Testing new file',file_get_contents($filename)); } function testPutAlreadyExists() { - $serverVars = array( - 'REQUEST_URI' => '/test.txt', - 'REQUEST_METHOD' => 'PUT', - 'HTTP_IF_NONE_MATCH' => '*', - ); - - $request = new HTTP\Request($serverVars); + $request = new HTTP\Request('PUT', '/test.txt', ['If-None-Match' => '*']); $request->setBody('Testing new file'); $this->server->httpRequest = ($request); $this->server->exec(); - $this->assertEquals(array( - 'Content-Type' => 'application/xml; charset=utf-8', - ),$this->response->headers); + $this->assertEquals([ + 'X-Sabre-Version' => [DAV\Version::VERSION], + 'Content-Type' => ['application/xml; charset=utf-8'], + ],$this->response->getHeaders()); - $this->assertEquals('HTTP/1.1 412 Precondition failed',$this->response->status); + $this->assertEquals(412, $this->response->status); $this->assertNotEquals('Testing new file',file_get_contents($this->tempDir . '/test.txt')); } function testMkcol() { - $serverVars = array( - 'REQUEST_URI' => '/testcol', - 'REQUEST_METHOD' => 'MKCOL', - ); - - $request = new HTTP\Request($serverVars); - $request->setBody(""); + $request = new HTTP\Request('MKCOL', '/testcol'); $this->server->httpRequest = ($request); $this->server->exec(); - $this->assertEquals(array( - 'Content-Length' => '0', - ),$this->response->headers); + $this->assertEquals([ + 'X-Sabre-Version' => [DAV\Version::VERSION], + 'Content-Length' => ['0'], + ],$this->response->getHeaders()); - $this->assertEquals('HTTP/1.1 201 Created',$this->response->status); + $this->assertEquals(201, $this->response->status); $this->assertEquals('', $this->response->body); $this->assertTrue(is_dir($this->tempDir . '/testcol')); @@ -134,19 +116,14 @@ class ServerTest extends DAV\AbstractServer{ function testPutUpdate() { - $serverVars = array( - 'REQUEST_URI' => '/test.txt', - 'REQUEST_METHOD' => 'PUT', - ); - - $request = new HTTP\Request($serverVars); + $request = new HTTP\Request('PUT', '/test.txt'); $request->setBody('Testing updated file'); $this->server->httpRequest = ($request); $this->server->exec(); - $this->assertEquals('0', $this->response->headers['Content-Length']); + $this->assertEquals('0', $this->response->getHeader('Content-Length')); - $this->assertEquals('HTTP/1.1 204 No Content',$this->response->status); + $this->assertEquals(204, $this->response->status); $this->assertEquals('', $this->response->body); $this->assertEquals('Testing updated file',file_get_contents($this->tempDir . '/test.txt')); @@ -154,20 +131,16 @@ class ServerTest extends DAV\AbstractServer{ function testDelete() { - $serverVars = array( - 'REQUEST_URI' => '/test.txt', - 'REQUEST_METHOD' => 'DELETE', - ); - - $request = new HTTP\Request($serverVars); + $request = new HTTP\Request('DELETE', '/test.txt'); $this->server->httpRequest = ($request); $this->server->exec(); - $this->assertEquals(array( - 'Content-Length' => '0', - ),$this->response->headers); + $this->assertEquals([ + 'X-Sabre-Version' => [DAV\Version::VERSION], + 'Content-Length' => ['0'], + ],$this->response->getHeaders()); - $this->assertEquals('HTTP/1.1 204 No Content',$this->response->status); + $this->assertEquals(204, $this->response->status); $this->assertEquals('', $this->response->body); $this->assertFalse(file_exists($this->tempDir . '/test.txt')); @@ -175,50 +148,99 @@ class ServerTest extends DAV\AbstractServer{ function testDeleteDirectory() { - $serverVars = array( - 'REQUEST_URI' => '/testcol', - 'REQUEST_METHOD' => 'DELETE', - ); - mkdir($this->tempDir.'/testcol'); file_put_contents($this->tempDir.'/testcol/test.txt','Hi! I\'m a file with a short lifespan'); - $request = new HTTP\Request($serverVars); + $request = new HTTP\Request('DELETE', '/testcol'); $this->server->httpRequest = ($request); $this->server->exec(); - $this->assertEquals(array( - 'Content-Length' => '0', - ),$this->response->headers); - $this->assertEquals('HTTP/1.1 204 No Content',$this->response->status); + $this->assertEquals([ + 'X-Sabre-Version' => [DAV\Version::VERSION], + 'Content-Length' => ['0'], + ],$this->response->getHeaders()); + $this->assertEquals(204, $this->response->status); $this->assertEquals('', $this->response->body); - $this->assertFalse(file_exists($this->tempDir . '/col')); + $this->assertFalse(file_exists($this->tempDir . '/testcol')); } function testOptions() { - $serverVars = array( - 'REQUEST_URI' => '/', - 'REQUEST_METHOD' => 'OPTIONS', - ); - - $request = new HTTP\Request($serverVars); + $request = new HTTP\Request('OPTIONS', '/'); $this->server->httpRequest = ($request); $this->server->exec(); - $this->assertEquals(array( - 'DAV' => '1, 3, extended-mkcol', - 'MS-Author-Via' => 'DAV', - 'Allow' => 'OPTIONS, GET, HEAD, DELETE, PROPFIND, PUT, PROPPATCH, COPY, MOVE, REPORT', - 'Accept-Ranges' => 'bytes', - 'Content-Length' => '0', - 'X-Sabre-Version'=> DAV\Version::VERSION, - ),$this->response->headers); + $this->assertEquals([ + 'DAV' => ['1, 3, extended-mkcol'], + 'MS-Author-Via' => ['DAV'], + 'Allow' => ['OPTIONS, GET, HEAD, DELETE, PROPFIND, PUT, PROPPATCH, COPY, MOVE, REPORT'], + 'Accept-Ranges' => ['bytes'], + 'Content-Length' => ['0'], + 'X-Sabre-Version'=> [DAV\Version::VERSION], + ], $this->response->getHeaders()); - $this->assertEquals('HTTP/1.1 200 OK',$this->response->status); + $this->assertEquals(200, $this->response->status); $this->assertEquals('', $this->response->body); } + function testMove() { + + mkdir($this->tempDir.'/testcol'); + + $request = new HTTP\Request('MOVE', '/test.txt', ['Destination' => '/testcol/test2.txt']); + $this->server->httpRequest = ($request); + $this->server->exec(); + + $this->assertEquals(201, $this->response->status); + $this->assertEquals('', $this->response->body); + + $this->assertEquals([ + 'Content-Length' => ['0'], + 'X-Sabre-Version'=> [DAV\Version::VERSION], + ],$this->response->getHeaders()); + + $this->assertTrue( + is_file($this->tempDir . '/testcol/test2.txt') + ); + + + } + + /** + * This test checks if it's possible to move a non-FSExt collection into a + * FSExt collection. + * + * The moveInto function *should* ignore the object and let sabredav itself + * execute the slow move. + */ + function testMoveOtherObject() { + + mkdir($this->tempDir.'/tree1'); + mkdir($this->tempDir.'/tree2'); + + $tree = new DAV\Tree(new DAV\SimpleCollection('root', [ + new DAV\FS\Directory($this->tempDir . '/tree1'), + new DAV\FSExt\Directory($this->tempDir . '/tree2'), + ])); + $this->server->tree = $tree; + + $request = new HTTP\Request('MOVE', '/tree1', ['Destination' => '/tree2/tree1']); + $this->server->httpRequest = ($request); + $this->server->exec(); + + $this->assertEquals(201, $this->response->status); + $this->assertEquals('', $this->response->body); + + $this->assertEquals([ + 'Content-Length' => ['0'], + 'X-Sabre-Version'=> [DAV\Version::VERSION], + ],$this->response->getHeaders()); + + $this->assertTrue( + is_dir($this->tempDir . '/tree2/tree1') + ); + + } } diff --git a/vendor/sabre/dav/tests/Sabre/DAV/HTTPPreferParsingTest.php b/vendor/sabre/dav/tests/Sabre/DAV/HTTPPreferParsingTest.php index 45865b2a1..cd8bee968 100644 --- a/vendor/sabre/dav/tests/Sabre/DAV/HTTPPreferParsingTest.php +++ b/vendor/sabre/dav/tests/Sabre/DAV/HTTPPreferParsingTest.php @@ -4,105 +4,96 @@ namespace Sabre\DAV; use Sabre\HTTP; -class HTTPPReferParsingTest extends \Sabre\DAVServerTest { +class HTTPPreferParsingTest extends \Sabre\DAVServerTest { function testParseSimple() { - $httpRequest = new HTTP\Request(array( + $httpRequest = HTTP\Sapi::createFromServerArray([ 'HTTP_PREFER' => 'return-asynch', - )); + ]); $server = new Server(); $server->httpRequest = $httpRequest; - $this->assertEquals(array( - 'return-asynch' => true, - 'return-minimal' => false, - 'return-representation' => false, - 'strict' => false, - 'lenient' => false, - 'wait' => null, - ), $server->getHTTPPrefer()); + $this->assertEquals([ + 'respond-async' => true, + 'return' => null, + 'handling' => null, + 'wait' => null, + ], $server->getHTTPPrefer()); } function testParseValue() { - $httpRequest = new HTTP\Request(array( + $httpRequest = HTTP\Sapi::createFromServerArray([ 'HTTP_PREFER' => 'wait=10', - )); + ]); $server = new Server(); $server->httpRequest = $httpRequest; - $this->assertEquals(array( - 'return-asynch' => false, - 'return-minimal' => false, - 'return-representation' => false, - 'strict' => false, - 'lenient' => false, - 'wait' => 10, - ), $server->getHTTPPrefer()); + $this->assertEquals([ + 'respond-async' => false, + 'return' => null, + 'handling' => null, + 'wait' => '10', + ], $server->getHTTPPrefer()); } function testParseMultiple() { - $httpRequest = new HTTP\Request(array( + $httpRequest = HTTP\Sapi::createFromServerArray([ 'HTTP_PREFER' => 'return-minimal, strict,lenient', - )); + ]); $server = new Server(); $server->httpRequest = $httpRequest; - $this->assertEquals(array( - 'return-asynch' => false, - 'return-minimal' => true, - 'return-representation' => false, - 'strict' => true, - 'lenient' => true, - 'wait' => null, - ), $server->getHTTPPrefer()); + $this->assertEquals([ + 'respond-async' => false, + 'return' => 'minimal', + 'handling' => 'lenient', + 'wait' => null, + ], $server->getHTTPPrefer()); } function testParseWeirdValue() { - $httpRequest = new HTTP\Request(array( + $httpRequest = HTTP\Sapi::createFromServerArray([ 'HTTP_PREFER' => 'BOOOH', - )); + ]); $server = new Server(); $server->httpRequest = $httpRequest; - $this->assertEquals(array( - 'strict' => false, - 'lenient' => false, - 'wait' => null, - 'return-asynch' => false, - 'return-minimal' => false, - 'return-representation' => false, - ), $server->getHTTPPrefer()); + $this->assertEquals([ + 'respond-async' => false, + 'return' => null, + 'handling' => null, + 'wait' => null, + 'boooh' => true, + ], $server->getHTTPPrefer()); } function testBrief() { - $httpRequest = new HTTP\Request(array( + $httpRequest = HTTP\Sapi::createFromServerArray([ 'HTTP_BRIEF' => 't', - )); + ]); $server = new Server(); $server->httpRequest = $httpRequest; - $this->assertEquals(array( - 'strict' => false, - 'lenient' => false, - 'wait' => null, - 'return-asynch' => false, - 'return-minimal' => true, - 'return-representation' => false, - ), $server->getHTTPPrefer()); + $this->assertEquals([ + 'respond-async' => false, + 'return' => 'minimal', + 'handling' => null, + 'wait' => null, + ], $server->getHTTPPrefer()); } @@ -113,11 +104,11 @@ class HTTPPReferParsingTest extends \Sabre\DAVServerTest { */ function testpropfindMinimal() { - $request = new HTTP\Request(array( + $request = HTTP\Sapi::createFromServerArray([ 'REQUEST_METHOD' => 'PROPFIND', 'REQUEST_URI' => '/', - 'HTTP_PREFER' => 'return-minimal', - )); + 'HTTP_PREFER' => 'return-minimal', + ]); $request->setBody(<<<BLA <?xml version="1.0"?> <d:propfind xmlns:d="DAV:"> @@ -131,70 +122,67 @@ BLA $response = $this->request($request); - $this->assertTrue(strpos($response->body, 'resourcetype')!==false); - $this->assertTrue(strpos($response->body, 'something')===false); + $body = $response->getBodyAsString(); + + $this->assertEquals(207, $response->getStatus(), $body); + + $this->assertTrue(strpos($body, 'resourcetype') !== false, $body); + $this->assertTrue(strpos($body, 'something') === false, $body); } function testproppatchMinimal() { - $request = new HTTP\Request(array( - 'REQUEST_METHOD' => 'PROPPATCH', - 'REQUEST_URI' => '/', - 'HTTP_PREFER' => 'return-minimal', - )); + $request = new HTTP\Request('PROPPATCH', '/', ['Prefer' => 'return-minimal']); $request->setBody(<<<BLA <?xml version="1.0"?> -<d:proppatch xmlns:d="DAV:"> +<d:propertyupdate xmlns:d="DAV:"> <d:set> <d:prop> <d:something>nope!</d:something> </d:prop> </d:set> -</d:proppatch> +</d:propertyupdate> BLA ); - $this->server->subscribeEvent('updateProperties', function(&$props, &$result) { + $this->server->on('propPatch', function($path, PropPatch $propPatch) { - if (isset($props['{DAV:}something'])) { - unset($props['{DAV:}something']); - $result[200]['{DAV:}something'] = null; - } + $propPatch->handle('{DAV:}something', function($props) { + return true; + }); }); $response = $this->request($request); $this->assertEquals(0, strlen($response->body), 'Expected empty body: ' . $response->body); - $this->assertEquals('HTTP/1.1 204 No Content', $response->status); + $this->assertEquals(204, $response->status); } function testproppatchMinimalError() { - $request = new HTTP\Request(array( - 'REQUEST_METHOD' => 'PROPPATCH', - 'REQUEST_URI' => '/', - 'HTTP_PREFER' => 'return-minimal', - )); + $request = new HTTP\Request('PROPPATCH', '/', ['Prefer' => 'return-minimal']); $request->setBody(<<<BLA <?xml version="1.0"?> -<d:proppatch xmlns:d="DAV:"> +<d:propertyupdate xmlns:d="DAV:"> <d:set> <d:prop> <d:something>nope!</d:something> </d:prop> </d:set> -</d:proppatch> +</d:propertyupdate> BLA ); $response = $this->request($request); - $this->assertEquals('HTTP/1.1 207 Multi-Status', $response->status); - $this->assertTrue(strpos($response->body, 'something')!==false); - $this->assertTrue(strpos($response->body, 'HTTP/1.1 403 Forbidden')!==false); + $body = $response->getBodyAsString(); + + $this->assertEquals(207, $response->status); + $this->assertTrue(strpos($body, 'something') !== false); + $this->assertTrue(strpos($body, '403 Forbidden') !== false, $body); } } diff --git a/vendor/sabre/dav/tests/Sabre/DAV/HttpDeleteTest.php b/vendor/sabre/dav/tests/Sabre/DAV/HttpDeleteTest.php index da28b6979..6c10afa9f 100644 --- a/vendor/sabre/dav/tests/Sabre/DAV/HttpDeleteTest.php +++ b/vendor/sabre/dav/tests/Sabre/DAV/HttpDeleteTest.php @@ -8,7 +8,7 @@ use Sabre\HTTP; /** * Tests related to the PUT request. * - * @copyright Copyright (C) 2007-2014 fruux GmbH. All rights reserved. + * @copyright Copyright (C) fruux GmbH (https://fruux.com/) * @author Evert Pot (http://evertpot.com/) * @license http://sabre.io/license/ Modified BSD License */ @@ -21,13 +21,13 @@ class HttpDeleteTest extends DAVServerTest { */ public function setUpTree() { - $this->tree = new Mock\Collection('root', array( + $this->tree = new Mock\Collection('root', [ 'file1' => 'foo', - 'dir' => array( + 'dir' => [ 'subfile' => 'bar', 'subfile2' => 'baz', - ), - )); + ], + ]); } @@ -36,24 +36,22 @@ class HttpDeleteTest extends DAVServerTest { */ public function testDelete() { - $request = new HTTP\Request(array( - 'REQUEST_URI' => '/file1', - 'REQUEST_METHOD' => 'DELETE', - )); + $request = new HTTP\Request('DELETE', '/file1'); $response = $this->request($request); $this->assertEquals( - 'HTTP/1.1 204 No Content', - $response->status, - "Incorrect status code. Response body: " . $response->body + 204, + $response->getStatus(), + "Incorrect status code. Response body: " . $response->getBodyAsString() ); $this->assertEquals( - array( - 'Content-Length' => '0', - ), - $response->headers + [ + 'X-Sabre-Version' => [Version::VERSION], + 'Content-Length' => ['0'], + ], + $response->getHeaders() ); } @@ -63,24 +61,22 @@ class HttpDeleteTest extends DAVServerTest { */ public function testDeleteDirectory() { - $request = new HTTP\Request(array( - 'REQUEST_URI' => '/dir', - 'REQUEST_METHOD' => 'DELETE', - )); + $request = new HTTP\Request('DELETE', '/dir'); $response = $this->request($request); $this->assertEquals( - 'HTTP/1.1 204 No Content', - $response->status, - "Incorrect status code. Response body: " . $response->body + 204, + $response->getStatus(), + "Incorrect status code. Response body: " . $response->getBodyAsString() ); $this->assertEquals( - array( - 'Content-Length' => '0', - ), - $response->headers + [ + 'X-Sabre-Version' => [Version::VERSION], + 'Content-Length' => ['0'], + ], + $response->getHeaders() ); } @@ -90,17 +86,13 @@ class HttpDeleteTest extends DAVServerTest { */ public function testDeleteNotFound() { - $request = new HTTP\Request(array( - 'REQUEST_URI' => '/file2', - 'REQUEST_METHOD' => 'DELETE', - )); - + $request = new HTTP\Request('DELETE', '/file2'); $response = $this->request($request); $this->assertEquals( - 'HTTP/1.1 404 Not Found', - $response->status, - "Incorrect status code. Response body: " . $response->body + 404, + $response->getStatus(), + "Incorrect status code. Response body: " . $response->getBodyAsString() ); } @@ -110,18 +102,16 @@ class HttpDeleteTest extends DAVServerTest { */ public function testDeletePreconditions() { - $request = new HTTP\Request(array( - 'REQUEST_URI' => '/file1', - 'REQUEST_METHOD' => 'DELETE', - 'HTTP_IF_MATCH' => '"' . md5('foo') . '"', - )); + $request = new HTTP\Request('DELETE', '/file1', [ + 'If-Match' => '"' . md5('foo') . '"', + ]); $response = $this->request($request); $this->assertEquals( - 'HTTP/1.1 204 No Content', - $response->status, - "Incorrect status code. Response body: " . $response->body + 204, + $response->getStatus(), + "Incorrect status code. Response body: " . $response->getBodyAsString() ); } @@ -131,18 +121,16 @@ class HttpDeleteTest extends DAVServerTest { */ public function testDeletePreconditionsFailed() { - $request = new HTTP\Request(array( - 'REQUEST_URI' => '/file1', - 'REQUEST_METHOD' => 'DELETE', - 'HTTP_IF_MATCH' => '"' . md5('bar') . '"', - )); + $request = new HTTP\Request('DELETE', '/file1', [ + 'If-Match' => '"' . md5('bar') . '"', + ]); $response = $this->request($request); $this->assertEquals( - 'HTTP/1.1 412 Precondition failed', - $response->status, - "Incorrect status code. Response body: " . $response->body + 412, + $response->getStatus(), + "Incorrect status code. Response body: " . $response->getBodyAsString() ); } diff --git a/vendor/sabre/dav/tests/Sabre/DAV/HttpPutTest.php b/vendor/sabre/dav/tests/Sabre/DAV/HttpPutTest.php index b14554595..eddaf3f22 100644 --- a/vendor/sabre/dav/tests/Sabre/DAV/HttpPutTest.php +++ b/vendor/sabre/dav/tests/Sabre/DAV/HttpPutTest.php @@ -8,12 +8,9 @@ use Sabre\HTTP; /** * Tests related to the PUT request. * - * @copyright Copyright (C) 2007-2014 fruux GmbH. All rights reserved. + * @copyright Copyright (C) fruux GmbH (https://fruux.com/) * @author Evert Pot (http://evertpot.com/) * @license http://sabre.io/license/ Modified BSD License - * @covers Sabre\DAV\Server::httpPut - * @covers Sabre\DAV\Server::createFile - * @covers Sabre\DAV\Server::checkPreconditions */ class HttpPutTest extends DAVServerTest { @@ -22,28 +19,24 @@ class HttpPutTest extends DAVServerTest { * * @return void */ - public function setUpTree() { + function setUpTree() { - $this->tree = new Mock\Collection('root', array( + $this->tree = new Mock\Collection('root', [ 'file1' => 'foo', - )); + ]); } /** * A successful PUT of a new file. */ - public function testPut() { + function testPut() { - $request = new HTTP\Request(array( - 'REQUEST_URI' => '/file2', - 'REQUEST_METHOD' => 'PUT', - )); - $request->setBody('hello'); + $request = new HTTP\Request('PUT', '/file2', [], 'hello'); $response = $this->request($request); - $this->assertEquals('HTTP/1.1 201 Created', $response->status); + $this->assertEquals(201, $response->getStatus(), 'Incorrect status code received. Full response body:' . $response->getBodyAsString()); $this->assertEquals( 'hello', @@ -51,11 +44,12 @@ class HttpPutTest extends DAVServerTest { ); $this->assertEquals( - array( - 'Content-Length' => '0', - 'ETag' => '"' . md5('hello') . '"' - ), - $response->headers + [ + 'X-Sabre-Version' => [Version::VERSION], + 'Content-Length' => ['0'], + 'ETag' => ['"' . md5('hello') . '"'] + ], + $response->getHeaders() ); } @@ -65,17 +59,13 @@ class HttpPutTest extends DAVServerTest { * * @depends testPut */ - public function testPutExisting() { + function testPutExisting() { - $request = new HTTP\Request(array( - 'REQUEST_URI' => '/file1', - 'REQUEST_METHOD' => 'PUT', - )); - $request->setBody('bar'); + $request = new HTTP\Request('PUT', '/file1', [], 'bar'); $response = $this->request($request); - $this->assertEquals('HTTP/1.1 204 No Content', $response->status); + $this->assertEquals(204, $response->getStatus()); $this->assertEquals( 'bar', @@ -83,11 +73,12 @@ class HttpPutTest extends DAVServerTest { ); $this->assertEquals( - array( - 'Content-Length' => '0', - 'ETag' => '"' . md5('bar') . '"' - ), - $response->headers + [ + 'X-Sabre-Version' => [Version::VERSION], + 'Content-Length' => ['0'], + 'ETag' => ['"' . md5('bar') . '"'] + ], + $response->getHeaders() ); } @@ -97,18 +88,18 @@ class HttpPutTest extends DAVServerTest { * * @depends testPutExisting */ - public function testPutExistingIfMatchStar() { + function testPutExistingIfMatchStar() { - $request = new HTTP\Request(array( - 'REQUEST_URI' => '/file1', - 'REQUEST_METHOD' => 'PUT', - 'HTTP_IF_MATCH' => '*', - )); - $request->setBody('hello'); + $request = new HTTP\Request( + 'PUT', + '/file1', + ['If-Match' => '*'], + 'hello' + ); $response = $this->request($request); - $this->assertEquals('HTTP/1.1 204 No Content', $response->status); + $this->assertEquals(204, $response->getStatus()); $this->assertEquals( 'hello', @@ -116,11 +107,12 @@ class HttpPutTest extends DAVServerTest { ); $this->assertEquals( - array( - 'Content-Length' => '0', - 'ETag' => '"' . md5('hello') . '"' - ), - $response->headers + [ + 'X-Sabre-Version' => [Version::VERSION], + 'Content-Length' => ['0'], + 'ETag' => ['"' . md5('hello') . '"'] + ], + $response->getHeaders() ); } @@ -130,18 +122,18 @@ class HttpPutTest extends DAVServerTest { * * @depends testPutExisting */ - public function testPutExistingIfMatchCorrect() { + function testPutExistingIfMatchCorrect() { - $request = new HTTP\Request(array( - 'REQUEST_URI' => '/file1', - 'REQUEST_METHOD' => 'PUT', - 'HTTP_IF_MATCH' => '"' . md5('foo') . '"', - )); - $request->setBody('hello'); + $request = new HTTP\Request( + 'PUT', + '/file1', + ['If-Match' => '"' . md5('foo') . '"'], + 'hello' + ); $response = $this->request($request); - $this->assertEquals('HTTP/1.1 204 No Content', $response->status); + $this->assertEquals(204, $response->status); $this->assertEquals( 'hello', @@ -149,11 +141,12 @@ class HttpPutTest extends DAVServerTest { ); $this->assertEquals( - array( - 'Content-Length' => '0', - 'ETag' => '"' . md5('hello') . '"' - ), - $response->headers + [ + 'X-Sabre-Version' => [Version::VERSION], + 'Content-Length' => ['0'], + 'ETag' => ['"' . md5('hello') . '"'], + ], + $response->getHeaders() ); } @@ -163,17 +156,17 @@ class HttpPutTest extends DAVServerTest { * * @depends testPut */ - public function testPutContentRange() { + function testPutContentRange() { - $request = new HTTP\Request(array( - 'REQUEST_URI' => '/file2', - 'REQUEST_METHOD' => 'PUT', - 'HTTP_CONTENT_RANGE' => 'bytes/100-200', - )); - $request->setBody('hello'); + $request = new HTTP\Request( + 'PUT', + '/file2', + ['Content-Range' => 'bytes/100-200'], + 'hello' + ); $response = $this->request($request); - $this->assertEquals('HTTP/1.1 501 Not Implemented', $response->status); + $this->assertEquals(400, $response->getStatus()); } @@ -182,18 +175,18 @@ class HttpPutTest extends DAVServerTest { * * @depends testPut */ - public function testPutIfNoneMatchStar() { + function testPutIfNoneMatchStar() { - $request = new HTTP\Request(array( - 'REQUEST_URI' => '/file2', - 'REQUEST_METHOD' => 'PUT', - 'HTTP_IF_NONE_MATCH' => '*', - )); - $request->setBody('hello'); + $request = new HTTP\Request( + 'PUT', + '/file2', + ['If-None-Match' => '*'], + 'hello' + ); $response = $this->request($request); - $this->assertEquals('HTTP/1.1 201 Created', $response->status); + $this->assertEquals(201, $response->getStatus()); $this->assertEquals( 'hello', @@ -201,11 +194,12 @@ class HttpPutTest extends DAVServerTest { ); $this->assertEquals( - array( - 'Content-Length' => '0', - 'ETag' => '"' . md5('hello') . '"' - ), - $response->headers + [ + 'X-Sabre-Version' => [Version::VERSION], + 'Content-Length' => ['0'], + 'ETag' => ['"' . md5('hello') . '"'] + ], + $response->getHeaders() ); } @@ -215,18 +209,18 @@ class HttpPutTest extends DAVServerTest { * * @depends testPut */ - public function testPutIfMatchStar() { + function testPutIfMatchStar() { - $request = new HTTP\Request(array( - 'REQUEST_URI' => '/file2', - 'REQUEST_METHOD' => 'PUT', - 'HTTP_IF_MATCH' => '*', - )); - $request->setBody('hello'); + $request = new HTTP\Request( + 'PUT', + '/file2', + ['If-Match' => '*'], + 'hello' + ); $response = $this->request($request); - $this->assertEquals('HTTP/1.1 412 Precondition failed', $response->status); + $this->assertEquals(412, $response->getStatus()); } @@ -235,18 +229,19 @@ class HttpPutTest extends DAVServerTest { * * @depends testPut */ - public function testPutExistingIfNoneMatchStar() { + function testPutExistingIfNoneMatchStar() { - $request = new HTTP\Request(array( - 'REQUEST_URI' => '/file1', - 'REQUEST_METHOD' => 'PUT', - 'HTTP_IF_NONE_MATCH' => '*', - )); + $request = new HTTP\Request( + 'PUT', + '/file1', + ['If-None-Match' => '*'], + 'hello' + ); $request->setBody('hello'); $response = $this->request($request); - $this->assertEquals('HTTP/1.1 412 Precondition failed', $response->status); + $this->assertEquals(412, $response->getStatus()); } @@ -255,16 +250,17 @@ class HttpPutTest extends DAVServerTest { * * @depends testPut */ - public function testPutNoParent() { + function testPutNoParent() { - $request = new HTTP\Request(array( - 'REQUEST_URI' => '/file1/file2', - 'REQUEST_METHOD' => 'PUT', - )); - $request->setBody('hello'); + $request = new HTTP\Request( + 'PUT', + '/file1/file2', + [], + 'hello' + ); $response = $this->request($request); - $this->assertEquals('HTTP/1.1 409 Conflict', $response->status); + $this->assertEquals(409, $response->getStatus()); } @@ -275,18 +271,17 @@ class HttpPutTest extends DAVServerTest { * * @depends testPut */ - public function testFinderPutSuccess() { - - $request = new HTTP\Request(array( - 'REQUEST_URI' => '/file2', - 'REQUEST_METHOD' => 'PUT', - 'HTTP_X_EXPECTED_ENTITY_LENGTH' => '5', - )); - $request->setBody('hello'); + function testFinderPutSuccess() { + $request = new HTTP\Request( + 'PUT', + '/file2', + ['X-Expected-Entity-Length' => '5'], + 'hello' + ); $response = $this->request($request); - $this->assertEquals('HTTP/1.1 201 Created', $response->status); + $this->assertEquals(201, $response->getStatus()); $this->assertEquals( 'hello', @@ -294,11 +289,12 @@ class HttpPutTest extends DAVServerTest { ); $this->assertEquals( - array( - 'Content-Length' => '0', - 'ETag' => '"' . md5('hello') . '"' - ), - $response->headers + [ + 'X-Sabre-Version' => [Version::VERSION], + 'Content-Length' => ['0'], + 'ETag' => ['"' . md5('hello') . '"'], + ], + $response->getHeaders() ); } @@ -308,54 +304,45 @@ class HttpPutTest extends DAVServerTest { * * @depends testFinderPutSuccess */ - public function testFinderPutFail() { + function testFinderPutFail() { - $request = new HTTP\Request(array( - 'REQUEST_URI' => '/file2', - 'REQUEST_METHOD' => 'PUT', - 'HTTP_X_EXPECTED_ENTITY_LENGTH' => '5', - )); - $request->setBody(''); + $request = new HTTP\Request( + 'PUT', + '/file2', + ['X-Expected-Entity-Length' => '5'], + '' + ); $response = $this->request($request); - $this->assertEquals('HTTP/1.1 403 Forbidden', $response->status); + $this->assertEquals(403, $response->getStatus()); } /** * Plugins can intercept PUT. We need to make sure that works. + * + * @depends testPut */ - public function testPutIntercept() { - - $this->server->subscribeEvent('beforeBind', array($this, 'beforeBind')); + function testPutIntercept() { - $request = new HTTP\Request(array( - 'REQUEST_URI' => '/file2', - 'REQUEST_METHOD' => 'PUT', - )); - $request->setBody('hello'); + $this->server->on('beforeBind', function($uri) { + $this->server->httpResponse->setStatus(418); + return false; + }); + $request = new HTTP\Request('PUT', '/file2', [], 'hello'); $response = $this->request($request); - $this->assertEquals('HTTP/1.1 418 I\'m a teapot', $response->status); + $this->assertEquals(418, $response->getStatus(), 'Incorrect status code received. Full response body: ' .$response->getBodyAsString()); $this->assertFalse( $this->server->tree->nodeExists('file2') ); - $this->assertEquals( - array( - ), - $response->headers - ); - - } - - public function beforeBind() { - - $this->server->httpResponse->sendStatus(418); - return false; + $this->assertEquals([ + 'X-Sabre-Version' => [Version::VERSION], + ], $response->getHeaders()); } diff --git a/vendor/sabre/dav/tests/Sabre/DAV/Issue33Test.php b/vendor/sabre/dav/tests/Sabre/DAV/Issue33Test.php index c3fba4aae..4ccb42fbb 100644 --- a/vendor/sabre/dav/tests/Sabre/DAV/Issue33Test.php +++ b/vendor/sabre/dav/tests/Sabre/DAV/Issue33Test.php @@ -28,11 +28,11 @@ class Issue33Test extends \PHPUnit_Framework_TestCase { 'HTTP_OVERWRITE' => 'F', ); - $request = new HTTP\Request($serverVars); + $request = HTTP\Sapi::createFromServerArray($serverVars); $server->httpRequest = $request; - $info = $server->getCopyAndMoveInfo(); + $info = $server->getCopyAndMoveInfo($request); $this->assertEquals('%C3%A0fo%C3%B3', urlencode($info['destination'])); $this->assertFalse($info['destinationExists']); @@ -47,7 +47,7 @@ class Issue33Test extends \PHPUnit_Framework_TestCase { $dir->createDirectory('bar'); - $tree = new ObjectTree($dir); + $tree = new Tree($dir); $tree->move('bar',urldecode('%C3%A0fo%C3%B3')); $node = $tree->getNodeForPath(urldecode('%C3%A0fo%C3%B3')); @@ -78,7 +78,7 @@ class Issue33Test extends \PHPUnit_Framework_TestCase { 'HTTP_OVERWRITE' => 'F', ); - $request = new HTTP\Request($serverVars); + $request = HTTP\Sapi::createFromServerArray($serverVars); $request->setBody(''); $response = new HTTP\ResponseMock(); @@ -89,13 +89,14 @@ class Issue33Test extends \PHPUnit_Framework_TestCase { $dir->createDirectory('bar'); - $tree = new ObjectTree($dir); + $tree = new Tree($dir); $server = new Server($tree); $server->setBaseUri('/webdav/'); $server->httpRequest = $request; $server->httpResponse = $response; + $server->sapi = new HTTP\SapiMock(); $server->exec(); $this->assertTrue(file_exists(SABRE_TEMPDIR . '/issue33/' . urldecode('%C3%A0fo%C3%B3'))); diff --git a/vendor/sabre/dav/tests/Sabre/DAV/Locks/Backend/FSTest.php b/vendor/sabre/dav/tests/Sabre/DAV/Locks/Backend/FSTest.php deleted file mode 100644 index 651abf786..000000000 --- a/vendor/sabre/dav/tests/Sabre/DAV/Locks/Backend/FSTest.php +++ /dev/null @@ -1,31 +0,0 @@ -<?php - -namespace Sabre\DAV\Locks\Backend; - -require_once 'Sabre/TestUtil.php'; - -class FSTest extends AbstractTest { - - function getBackend() { - - \Sabre\TestUtil::clearTempDir(); - mkdir(SABRE_TEMPDIR . '/locks'); - $backend = new FS(SABRE_TEMPDIR . '/locks/'); - return $backend; - - } - - function tearDown() { - - \Sabre\TestUtil::clearTempDir(); - - } - - function testGetLocksChildren() { - - // We're skipping this test. This doesn't work, and it will - // never. The class is deprecated anyway. - - } - -} diff --git a/vendor/sabre/dav/tests/Sabre/DAV/Locks/GetIfConditionsTest.php b/vendor/sabre/dav/tests/Sabre/DAV/Locks/GetIfConditionsTest.php deleted file mode 100644 index 7b2cd0db0..000000000 --- a/vendor/sabre/dav/tests/Sabre/DAV/Locks/GetIfConditionsTest.php +++ /dev/null @@ -1,375 +0,0 @@ -<?php - -namespace Sabre\DAV\Locks; - -use Sabre\DAV; -use Sabre\HTTP; - -require_once 'Sabre/HTTP/ResponseMock.php'; -require_once 'Sabre/DAV/AbstractServer.php'; - -class GetIfConditionsTest extends DAV\AbstractServer { - - /** - * @var Sabre\DAV\Locks\Plugin - */ - protected $locksPlugin; - - function setUp() { - - parent::setUp(); - $locksPlugin = new Plugin(); - $this->server->addPlugin($locksPlugin); - $this->locksPlugin = $locksPlugin; - - } - - function testNoConditions() { - - $serverVars = array( - ); - - $request = new HTTP\Request($serverVars); - $this->server->httpRequest = ($request); - - $conditions = $this->locksPlugin->getIfConditions(); - $this->assertEquals(array(),$conditions); - - } - - function testLockToken() { - - $serverVars = array( - 'HTTP_IF' => '(<opaquelocktoken:token1>)', - ); - - $request = new HTTP\Request($serverVars); - $this->server->httpRequest = ($request); - - $conditions = $this->locksPlugin->getIfConditions(); - - $compare = array( - - array( - 'uri' => '', - 'tokens' => array( - array( - 1, - 'opaquelocktoken:token1', - '', - ), - ), - - ), - - ); - - $this->assertEquals($compare,$conditions); - - } - - function testNotLockToken() { - - $serverVars = array( - 'HTTP_IF' => '(Not <opaquelocktoken:token1>)', - ); - - $request = new HTTP\Request($serverVars); - $this->server->httpRequest = ($request); - - $conditions = $this->locksPlugin->getIfConditions(); - - $compare = array( - - array( - 'uri' => '', - 'tokens' => array( - array( - 0, - 'opaquelocktoken:token1', - '', - ), - ), - - ), - - ); - $this->assertEquals($compare,$conditions); - - } - - function testLockTokenUrl() { - - $serverVars = array( - 'HTTP_IF' => '<http://www.example.com/> (<opaquelocktoken:token1>)', - ); - - $request = new HTTP\Request($serverVars); - $this->server->httpRequest = ($request); - - $conditions = $this->locksPlugin->getIfConditions(); - - $compare = array( - - array( - 'uri' => 'http://www.example.com/', - 'tokens' => array( - array( - 1, - 'opaquelocktoken:token1', - '', - ), - ), - - ), - - ); - $this->assertEquals($compare,$conditions); - - } - - function test2LockTokens() { - - $serverVars = array( - 'HTTP_IF' => '(<opaquelocktoken:token1>) (Not <opaquelocktoken:token2>)', - ); - - $request = new HTTP\Request($serverVars); - $this->server->httpRequest = ($request); - - $conditions = $this->locksPlugin->getIfConditions(); - - $compare = array( - - array( - 'uri' => '', - 'tokens' => array( - array( - 1, - 'opaquelocktoken:token1', - '', - ), - array( - 0, - 'opaquelocktoken:token2', - '', - ), - ), - - ), - - ); - $this->assertEquals($compare,$conditions); - - } - - function test2UriLockTokens() { - - $serverVars = array( - 'HTTP_IF' => '<http://www.example.org/node1> (<opaquelocktoken:token1>) <http://www.example.org/node2> (Not <opaquelocktoken:token2>)', - ); - - $request = new HTTP\Request($serverVars); - $this->server->httpRequest = ($request); - - $conditions = $this->locksPlugin->getIfConditions(); - - $compare = array( - - array( - 'uri' => 'http://www.example.org/node1', - 'tokens' => array( - array( - 1, - 'opaquelocktoken:token1', - '', - ), - ), - ), - array( - 'uri' => 'http://www.example.org/node2', - 'tokens' => array( - array( - 0, - 'opaquelocktoken:token2', - '', - ), - ), - - ), - - ); - $this->assertEquals($compare,$conditions); - - } - - function test2UriMultiLockTokens() { - - $serverVars = array( - 'HTTP_IF' => '<http://www.example.org/node1> (<opaquelocktoken:token1>) (<opaquelocktoken:token2>) <http://www.example.org/node2> (Not <opaquelocktoken:token3>)', - ); - - $request = new HTTP\Request($serverVars); - $this->server->httpRequest = ($request); - - $conditions = $this->locksPlugin->getIfConditions(); - - $compare = array( - - array( - 'uri' => 'http://www.example.org/node1', - 'tokens' => array( - array( - 1, - 'opaquelocktoken:token1', - '', - ), - array( - 1, - 'opaquelocktoken:token2', - '', - ), - ), - ), - array( - 'uri' => 'http://www.example.org/node2', - 'tokens' => array( - array( - 0, - 'opaquelocktoken:token3', - '', - ), - ), - - ), - - ); - $this->assertEquals($compare,$conditions); - - } - - function testEtag() { - - $serverVars = array( - 'HTTP_IF' => '([etag1])', - ); - - $request = new HTTP\Request($serverVars); - $this->server->httpRequest = ($request); - - $conditions = $this->locksPlugin->getIfConditions(); - - $compare = array( - - array( - 'uri' => '', - 'tokens' => array( - array( - 1, - '', - 'etag1', - ), - ), - ), - - ); - $this->assertEquals($compare,$conditions); - - } - - function test2Etags() { - - $serverVars = array( - 'HTTP_IF' => '<http://www.example.org/> ([etag1]) ([etag2])', - ); - - $request = new HTTP\Request($serverVars); - $this->server->httpRequest = ($request); - - $conditions = $this->locksPlugin->getIfConditions(); - - $compare = array( - - array( - 'uri' => 'http://www.example.org/', - 'tokens' => array( - array( - 1, - '', - 'etag1', - ), - array( - 1, - '', - 'etag2', - ), - ), - ), - - ); - $this->assertEquals($compare,$conditions); - - } - - function testComplexIf() { - - $serverVars = array( - 'HTTP_IF' => '<http://www.example.org/node1> (<opaquelocktoken:token1> [etag1]) ' . - '(Not <opaquelocktoken:token2>) ([etag2]) <http://www.example.org/node2> ' . - '(<opaquelocktoken:token3>) (Not <opaquelocktoken:token4>) ([etag3])', - ); - - $request = new HTTP\Request($serverVars); - $this->server->httpRequest = ($request); - - $conditions = $this->locksPlugin->getIfConditions(); - - $compare = array( - - array( - 'uri' => 'http://www.example.org/node1', - 'tokens' => array( - array( - 1, - 'opaquelocktoken:token1', - 'etag1', - ), - array( - 0, - 'opaquelocktoken:token2', - '', - ), - array( - 1, - '', - 'etag2', - ), - ), - ), - array( - 'uri' => 'http://www.example.org/node2', - 'tokens' => array( - array( - 1, - 'opaquelocktoken:token3', - '', - ), - array( - 0, - 'opaquelocktoken:token4', - '', - ), - array( - 1, - '', - 'etag3', - ), - ), - ), - - ); - $this->assertEquals($compare,$conditions); - - } - -} diff --git a/vendor/sabre/dav/tests/Sabre/DAV/Locks/MSWordTest.php b/vendor/sabre/dav/tests/Sabre/DAV/Locks/MSWordTest.php index b3d7d447b..23f283796 100644 --- a/vendor/sabre/dav/tests/Sabre/DAV/Locks/MSWordTest.php +++ b/vendor/sabre/dav/tests/Sabre/DAV/Locks/MSWordTest.php @@ -10,6 +10,12 @@ require_once 'Sabre/TestUtil.php'; class MSWordTest extends \PHPUnit_Framework_TestCase { + function tearDown() { + + \Sabre\TestUtil::clearTempDir(); + + } + function testLockEtc() { mkdir(SABRE_TEMPDIR . '/mstest'); @@ -25,11 +31,12 @@ class MSWordTest extends \PHPUnit_Framework_TestCase { $server->httpRequest = $this->getLockRequest(); $server->httpResponse = $response1; + $server->sapi = new HTTP\SapiMock(); $server->exec(); - $this->assertEquals('HTTP/1.1 201 Created', $server->httpResponse->status); - $this->assertTrue(isset($server->httpResponse->headers['Lock-Token'])); - $lockToken = $server->httpResponse->headers['Lock-Token']; + $this->assertEquals(201, $server->httpResponse->getStatus(), 'Full response body:' . $response1->getBodyAsString()); + $this->assertTrue(!!$server->httpResponse->getHeaders('Lock-Token')); + $lockToken = $server->httpResponse->getHeader('Lock-Token'); //sleep(10); @@ -39,8 +46,8 @@ class MSWordTest extends \PHPUnit_Framework_TestCase { $server->httpResponse = $response2; $server->exec(); - $this->assertEquals('HTTP/1.1 201 Created', $server->httpResponse->status); - $this->assertTrue(isset($server->httpResponse->headers['Lock-Token'])); + $this->assertEquals(201, $server->httpResponse->status); + $this->assertTrue(!!$server->httpResponse->getHeaders('Lock-Token')); //sleep(10); @@ -49,19 +56,13 @@ class MSWordTest extends \PHPUnit_Framework_TestCase { $server->httpResponse = $response3; $server->exec(); - $this->assertEquals('HTTP/1.1 204 No Content', $server->httpResponse->status); - - } - - function tearDown() { - - \Sabre\TestUtil::clearTempDir(); + $this->assertEquals(204, $server->httpResponse->status); } function getLockRequest() { - $request = new HTTP\Request(array( + $request = HTTP\Sapi::createFromServerArray(array( 'REQUEST_METHOD' => 'LOCK', 'HTTP_CONTENT_TYPE' => 'application/xml', 'HTTP_TIMEOUT' => 'Second-3600', @@ -85,7 +86,7 @@ class MSWordTest extends \PHPUnit_Framework_TestCase { } function getLockRequest2() { - $request = new HTTP\Request(array( + $request = HTTP\Sapi::createFromServerArray(array( 'REQUEST_METHOD' => 'LOCK', 'HTTP_CONTENT_TYPE' => 'application/xml', 'HTTP_TIMEOUT' => 'Second-3600', @@ -110,7 +111,7 @@ class MSWordTest extends \PHPUnit_Framework_TestCase { function getPutRequest($lockToken) { - $request = new HTTP\Request(array( + $request = HTTP\Sapi::createFromServerArray(array( 'REQUEST_METHOD' => 'PUT', 'REQUEST_URI' => '/Nouveau%20Microsoft%20Office%20Excel%20Worksheet.xlsx', 'HTTP_IF' => 'If: ('.$lockToken.')', diff --git a/vendor/sabre/dav/tests/Sabre/DAV/Locks/PluginTest.php b/vendor/sabre/dav/tests/Sabre/DAV/Locks/PluginTest.php index caa1d0118..ef0e473ae 100644 --- a/vendor/sabre/dav/tests/Sabre/DAV/Locks/PluginTest.php +++ b/vendor/sabre/dav/tests/Sabre/DAV/Locks/PluginTest.php @@ -10,7 +10,7 @@ require_once 'Sabre/DAV/AbstractServer.php'; class PluginTest extends DAV\AbstractServer { /** - * @var Sabre\DAV\Locks\Plugin + * @var Plugin */ protected $locksPlugin; @@ -24,62 +24,47 @@ class PluginTest extends DAV\AbstractServer { } - function testGetFeatures() { - - $this->assertEquals(array(2),$this->locksPlugin->getFeatures()); - - } + function testGetInfo() { - function testGetHTTPMethods() { - - $this->assertEquals(array('LOCK','UNLOCK'),$this->locksPlugin->getHTTPMethods('')); + $this->assertArrayHasKey( + 'name', + $this->locksPlugin->getPluginInfo() + ); } - function testGetHTTPMethodsNoBackend() { + function testGetFeatures() { - $locksPlugin = new Plugin(); - $this->server->addPlugin($locksPlugin); - $this->assertEquals(array(),$locksPlugin->getHTTPMethods('')); + $this->assertEquals(array(2),$this->locksPlugin->getFeatures()); } - function testUnknownMethodPassthough() { + function testGetHTTPMethods() { - $this->assertNull($this->locksPlugin->unknownMethod('BLA','/')); + $this->assertEquals(array('LOCK','UNLOCK'),$this->locksPlugin->getHTTPMethods('')); } function testLockNoBody() { - $serverVars = array( - 'REQUEST_URI' => '/test.txt', - 'REQUEST_METHOD' => 'LOCK', - ); - - $request = new HTTP\Request($serverVars); - $request->setBody(''); - $this->server->httpRequest = ($request); + $request = new HTTP\Request('LOCK', '/test.txt'); + $this->server->httpRequest = $request; $this->server->exec(); $this->assertEquals(array( - 'Content-Type' => 'application/xml; charset=utf-8', + 'X-Sabre-Version' => [DAV\Version::VERSION], + 'Content-Type' => ['application/xml; charset=utf-8'], ), - $this->response->headers + $this->response->getHeaders() ); - $this->assertEquals('HTTP/1.1 400 Bad request',$this->response->status); + $this->assertEquals(400, $this->response->status); } function testLock() { - $serverVars = array( - 'REQUEST_URI' => '/test.txt', - 'REQUEST_METHOD' => 'LOCK', - ); - - $request = new HTTP\Request($serverVars); + $request = new HTTP\Request('LOCK', '/test.txt'); $request->setBody('<?xml version="1.0"?> <D:lockinfo xmlns:D="DAV:"> <D:lockscope><D:exclusive/></D:lockscope> @@ -92,10 +77,10 @@ class PluginTest extends DAV\AbstractServer { $this->server->httpRequest = $request; $this->server->exec(); - $this->assertEquals('application/xml; charset=utf-8',$this->response->headers['Content-Type']); - $this->assertTrue(preg_match('/^<opaquelocktoken:(.*)>$/',$this->response->headers['Lock-Token'])===1,'We did not get a valid Locktoken back (' . $this->response->headers['Lock-Token'] . ')'); + $this->assertEquals('application/xml; charset=utf-8',$this->response->getHeader('Content-Type')); + $this->assertTrue(preg_match('/^<opaquelocktoken:(.*)>$/',$this->response->getHeader('Lock-Token'))===1,'We did not get a valid Locktoken back (' . $this->response->getHeader('Lock-Token') . ')'); - $this->assertEquals('HTTP/1.1 200 OK',$this->response->status,'Got an incorrect status back. Response body: ' . $this->response->body); + $this->assertEquals(200, $this->response->status,'Got an incorrect status back. Response body: ' . $this->response->body); $body = preg_replace("/xmlns(:[A-Za-z0-9_])?=(\"|\')DAV:(\"|\')/","xmlns\\1=\"urn:DAV\"",$this->response->body); $xml = simplexml_load_string($body); @@ -127,7 +112,7 @@ class PluginTest extends DAV\AbstractServer { $this->assertEquals('infinity',(string)$depth[0]); $token = $xml->xpath('/d:prop/d:lockdiscovery/d:activelock/d:locktoken/d:href'); - $this->assertEquals($this->response->headers['Lock-Token'],'<' . (string)$token[0] . '>','Token in response body didn\'t match token in response header.'); + $this->assertEquals($this->response->getHeader('Lock-Token'),'<' . (string)$token[0] . '>','Token in response body didn\'t match token in response header.'); } @@ -136,12 +121,7 @@ class PluginTest extends DAV\AbstractServer { */ function testDoubleLock() { - $serverVars = array( - 'REQUEST_URI' => '/test.txt', - 'REQUEST_METHOD' => 'LOCK', - ); - - $request = new HTTP\Request($serverVars); + $request = new HTTP\Request('LOCK', '/test.txt'); $request->setBody('<?xml version="1.0"?> <D:lockinfo xmlns:D="DAV:"> <D:lockscope><D:exclusive/></D:lockscope> @@ -159,9 +139,9 @@ class PluginTest extends DAV\AbstractServer { $this->server->exec(); - $this->assertEquals('application/xml; charset=utf-8',$this->response->headers['Content-Type']); + $this->assertEquals('application/xml; charset=utf-8',$this->response->getHeader('Content-Type')); - $this->assertEquals('HTTP/1.1 423 Locked',$this->response->status); + $this->assertEquals(423, $this->response->status, 'Full response: ' . $this->response->body); } @@ -170,12 +150,7 @@ class PluginTest extends DAV\AbstractServer { */ function testLockRefresh() { - $serverVars = array( - 'REQUEST_URI' => '/test.txt', - 'REQUEST_METHOD' => 'LOCK', - ); - - $request = new HTTP\Request($serverVars); + $request = new HTTP\Request('LOCK', '/test.txt'); $request->setBody('<?xml version="1.0"?> <D:lockinfo xmlns:D="DAV:"> <D:lockscope><D:exclusive/></D:lockscope> @@ -188,25 +163,55 @@ class PluginTest extends DAV\AbstractServer { $this->server->httpRequest = $request; $this->server->exec(); - $lockToken = $this->response->headers['Lock-Token']; + $lockToken = $this->response->getHeader('Lock-Token'); $this->response = new HTTP\ResponseMock(); $this->server->httpResponse = $this->response; - $serverVars = array( - 'REQUEST_URI' => '/test.txt', - 'REQUEST_METHOD' => 'LOCK', - 'HTTP_IF' => '(' . $lockToken . ')', - ); - $request = new HTTP\Request($serverVars); + $request = new HTTP\Request('LOCK', '/test.txt', ['If' => '(' . $lockToken . ')' ]); $request->setBody(''); + + $this->server->httpRequest = $request; + $this->server->exec(); + + $this->assertEquals('application/xml; charset=utf-8',$this->response->getHeader('Content-Type')); + + $this->assertEquals(200, $this->response->status,'We received an incorrect status code. Full response body: ' . $this->response->getBody()); + + } + + /** + * @depends testLock + */ + function testLockRefreshBadToken() { + + $request = new HTTP\Request('LOCK', '/test.txt'); + $request->setBody('<?xml version="1.0"?> +<D:lockinfo xmlns:D="DAV:"> + <D:lockscope><D:exclusive/></D:lockscope> + <D:locktype><D:write/></D:locktype> + <D:owner> + <D:href>http://example.org/~ejw/contact.html</D:href> + </D:owner> +</D:lockinfo>'); + $this->server->httpRequest = $request; + $this->server->exec(); + + $lockToken = $this->response->getHeader('Lock-Token'); + $this->response = new HTTP\ResponseMock(); + $this->server->httpResponse = $this->response; + + $request = new HTTP\Request('LOCK', '/test.txt', ['If' => '(' . $lockToken . 'foobar) (<opaquelocktoken:anotherbadtoken>)' ]); + $request->setBody(''); + + $this->server->httpRequest = $request; $this->server->exec(); - $this->assertEquals('application/xml; charset=utf-8',$this->response->headers['Content-Type']); + $this->assertEquals('application/xml; charset=utf-8',$this->response->getHeader('Content-Type')); - $this->assertEquals('HTTP/1.1 200 OK',$this->response->status,'We received an incorrect status code. Full response body: ' . $this->response->body); + $this->assertEquals(423, $this->response->getStatus(),'We received an incorrect status code. Full response body: ' . $this->response->getBody()); } @@ -215,12 +220,7 @@ class PluginTest extends DAV\AbstractServer { */ function testLockNoFile() { - $serverVars = array( - 'REQUEST_URI' => '/notfound.txt', - 'REQUEST_METHOD' => 'LOCK', - ); - - $request = new HTTP\Request($serverVars); + $request = new HTTP\Request('LOCK', '/notfound.txt'); $request->setBody('<?xml version="1.0"?> <D:lockinfo xmlns:D="DAV:"> <D:lockscope><D:exclusive/></D:lockscope> @@ -233,10 +233,10 @@ class PluginTest extends DAV\AbstractServer { $this->server->httpRequest = $request; $this->server->exec(); - $this->assertEquals('application/xml; charset=utf-8',$this->response->headers['Content-Type']); - $this->assertTrue(preg_match('/^<opaquelocktoken:(.*)>$/',$this->response->headers['Lock-Token'])===1,'We did not get a valid Locktoken back (' . $this->response->headers['Lock-Token'] . ')'); + $this->assertEquals('application/xml; charset=utf-8',$this->response->getHeader('Content-Type')); + $this->assertTrue(preg_match('/^<opaquelocktoken:(.*)>$/',$this->response->getHeader('Lock-Token'))===1,'We did not get a valid Locktoken back (' . $this->response->getHeader('Lock-Token') . ')'); - $this->assertEquals('HTTP/1.1 201 Created',$this->response->status); + $this->assertEquals(201, $this->response->status); } @@ -245,22 +245,18 @@ class PluginTest extends DAV\AbstractServer { */ function testUnlockNoToken() { - $serverVars = array( - 'REQUEST_URI' => '/test.txt', - 'REQUEST_METHOD' => 'UNLOCK', - ); - - $request = new HTTP\Request($serverVars); - $this->server->httpRequest = ($request); + $request = new HTTP\Request('UNLOCK', '/test.txt'); + $this->server->httpRequest = $request; $this->server->exec(); - $this->assertEquals(array( - 'Content-Type' => 'application/xml; charset=utf-8', - ), - $this->response->headers + $this->assertEquals([ + 'X-Sabre-Version' => [DAV\Version::VERSION], + 'Content-Type' => ['application/xml; charset=utf-8'], + ], + $this->response->getHeaders() ); - $this->assertEquals('HTTP/1.1 400 Bad request',$this->response->status); + $this->assertEquals(400, $this->response->status); } @@ -269,23 +265,18 @@ class PluginTest extends DAV\AbstractServer { */ function testUnlockBadToken() { - $serverVars = array( - 'REQUEST_URI' => '/test.txt', - 'REQUEST_METHOD' => 'UNLOCK', - 'HTTP_LOCK_TOKEN' => '<opaquelocktoken:blablabla>', - ); - - $request = new HTTP\Request($serverVars); - $this->server->httpRequest = ($request); + $request = new HTTP\Request('UNLOCK', '/test.txt', ['Lock-Token' => '<opaquelocktoken:blablabla>']); + $this->server->httpRequest = $request; $this->server->exec(); - $this->assertEquals(array( - 'Content-Type' => 'application/xml; charset=utf-8', - ), - $this->response->headers + $this->assertEquals([ + 'X-Sabre-Version' => [DAV\Version::VERSION], + 'Content-Type' => ['application/xml; charset=utf-8'], + ], + $this->response->getHeaders() ); - $this->assertEquals('HTTP/1.1 409 Conflict',$this->response->status,'Got an incorrect status code. Full response body: ' . $this->response->body); + $this->assertEquals(409, $this->response->status, 'Got an incorrect status code. Full response body: ' . $this->response->body); } @@ -294,12 +285,7 @@ class PluginTest extends DAV\AbstractServer { */ function testLockPutNoToken() { - $serverVars = array( - 'REQUEST_URI' => '/test.txt', - 'REQUEST_METHOD' => 'LOCK', - ); - - $request = new HTTP\Request($serverVars); + $request = new HTTP\Request('LOCK', '/test.txt'); $request->setBody('<?xml version="1.0"?> <D:lockinfo xmlns:D="DAV:"> <D:lockscope><D:exclusive/></D:lockscope> @@ -312,25 +298,20 @@ class PluginTest extends DAV\AbstractServer { $this->server->httpRequest = $request; $this->server->exec(); - $this->assertEquals('application/xml; charset=utf-8',$this->response->headers['Content-Type']); - $this->assertTrue(preg_match('/^<opaquelocktoken:(.*)>$/',$this->response->headers['Lock-Token'])===1,'We did not get a valid Locktoken back (' . $this->response->headers['Lock-Token'] . ')'); + $this->assertEquals('application/xml; charset=utf-8',$this->response->getHeader('Content-Type')); + $this->assertTrue(preg_match('/^<opaquelocktoken:(.*)>$/',$this->response->getHeader('Lock-Token'))===1,'We did not get a valid Locktoken back (' . $this->response->getHeader('Lock-Token') . ')'); - $this->assertEquals('HTTP/1.1 200 OK',$this->response->status); + $this->assertEquals(200, $this->response->status); - $serverVars = array( - 'REQUEST_URI' => '/test.txt', - 'REQUEST_METHOD' => 'PUT', - ); - - $request = new HTTP\Request($serverVars); + $request = new HTTP\Request('PUT', '/test.txt'); $request->setBody('newbody'); $this->server->httpRequest = $request; $this->server->exec(); - $this->assertEquals('application/xml; charset=utf-8',$this->response->headers['Content-Type']); - $this->assertTrue(preg_match('/^<opaquelocktoken:(.*)>$/',$this->response->headers['Lock-Token'])===1,'We did not get a valid Locktoken back (' . $this->response->headers['Lock-Token'] . ')'); + $this->assertEquals('application/xml; charset=utf-8',$this->response->getHeader('Content-Type')); + $this->assertTrue(preg_match('/^<opaquelocktoken:(.*)>$/',$this->response->getHeader('Lock-Token'))===1,'We did not get a valid Locktoken back (' . $this->response->getHeader('Lock-Token') . ')'); - $this->assertEquals('HTTP/1.1 423 Locked',$this->response->status); + $this->assertEquals(423, $this->response->status); } @@ -339,7 +320,7 @@ class PluginTest extends DAV\AbstractServer { */ function testUnlock() { - $request = new HTTP\Request(array()); + $request = new HTTP\Request('LOCK', '/test.txt'); $this->server->httpRequest = $request; $request->setBody('<?xml version="1.0"?> @@ -351,23 +332,20 @@ class PluginTest extends DAV\AbstractServer { </D:owner> </D:lockinfo>'); - $this->server->invokeMethod('LOCK','test.txt'); - $lockToken = $this->server->httpResponse->headers['Lock-Token']; - - $serverVars = array( - 'HTTP_LOCK_TOKEN' => $lockToken, - ); + $this->server->invokeMethod($request, $this->server->httpResponse); + $lockToken = $this->server->httpResponse->getHeader('Lock-Token'); - $request = new HTTP\Request($serverVars); - $this->server->httpRequest = ($request); + $request = new HTTP\Request('UNLOCK', '/test.txt', ['Lock-Token' => $lockToken]); + $this->server->httpRequest = $request; $this->server->httpResponse = new HTTP\ResponseMock(); - $this->server->invokeMethod('UNLOCK', 'test.txt'); - - $this->assertEquals('HTTP/1.1 204 No Content',$this->server->httpResponse->status,'Got an incorrect status code. Full response body: ' . $this->response->body); - $this->assertEquals(array( - 'Content-Length' => '0', - ), - $this->server->httpResponse->headers + $this->server->invokeMethod($request, $this->server->httpResponse); + + $this->assertEquals(204,$this->server->httpResponse->status,'Got an incorrect status code. Full response body: ' . $this->response->body); + $this->assertEquals([ + 'X-Sabre-Version' => [DAV\Version::VERSION], + 'Content-Length' => ['0'], + ], + $this->server->httpResponse->getHeaders() ); @@ -378,7 +356,7 @@ class PluginTest extends DAV\AbstractServer { */ function testUnlockWindowsBug() { - $request = new HTTP\Request(array()); + $request = new HTTP\Request('LOCK', '/test.txt'); $this->server->httpRequest = $request; $request->setBody('<?xml version="1.0"?> @@ -390,26 +368,23 @@ class PluginTest extends DAV\AbstractServer { </D:owner> </D:lockinfo>'); - $this->server->invokeMethod('LOCK','test.txt'); - $lockToken = $this->server->httpResponse->headers['Lock-Token']; + $this->server->invokeMethod($request, $this->server->httpResponse); + $lockToken = $this->server->httpResponse->getHeader('Lock-Token'); // See Issue 123 $lockToken = trim($lockToken,'<>'); - $serverVars = array( - 'HTTP_LOCK_TOKEN' => $lockToken, - ); - - $request = new HTTP\Request($serverVars); - $this->server->httpRequest = ($request); + $request = new HTTP\Request('UNLOCK', '/test.txt', ['Lock-Token' => $lockToken]); + $this->server->httpRequest = $request; $this->server->httpResponse = new HTTP\ResponseMock(); - $this->server->invokeMethod('UNLOCK', 'test.txt'); - - $this->assertEquals('HTTP/1.1 204 No Content',$this->server->httpResponse->status,'Got an incorrect status code. Full response body: ' . $this->response->body); - $this->assertEquals(array( - 'Content-Length' => '0', - ), - $this->server->httpResponse->headers + $this->server->invokeMethod($request, $this->server->httpResponse); + + $this->assertEquals(204, $this->server->httpResponse->status,'Got an incorrect status code. Full response body: ' . $this->response->body); + $this->assertEquals([ + 'X-Sabre-Version' => [DAV\Version::VERSION], + 'Content-Length' => ['0'], + ], + $this->server->httpResponse->getHeaders() ); @@ -420,7 +395,10 @@ class PluginTest extends DAV\AbstractServer { */ function testLockRetainOwner() { - $request = new HTTP\Request(array()); + $request = HTTP\Sapi::createFromServerArray([ + 'REQUEST_URI' => '/test.txt', + 'REQUEST_METHOD' => 'LOCK', + ]); $this->server->httpRequest = $request; $request->setBody('<?xml version="1.0"?> @@ -430,8 +408,8 @@ class PluginTest extends DAV\AbstractServer { <D:owner>Evert</D:owner> </D:lockinfo>'); - $this->server->invokeMethod('LOCK','test.txt'); - $lockToken = $this->server->httpResponse->headers['Lock-Token']; + $this->server->invokeMethod($request, $this->server->httpResponse); + $lockToken = $this->server->httpResponse->getHeader('Lock-Token'); $locks = $this->locksPlugin->getLocks('test.txt'); $this->assertEquals(1,count($locks)); @@ -450,7 +428,7 @@ class PluginTest extends DAV\AbstractServer { 'REQUEST_METHOD' => 'LOCK', ); - $request = new HTTP\Request($serverVars); + $request = HTTP\Sapi::createFromServerArray($serverVars); $request->setBody('<?xml version="1.0"?> <D:lockinfo xmlns:D="DAV:"> <D:lockscope><D:exclusive/></D:lockscope> @@ -463,10 +441,10 @@ class PluginTest extends DAV\AbstractServer { $this->server->httpRequest = $request; $this->server->exec(); - $this->assertEquals('application/xml; charset=utf-8',$this->response->headers['Content-Type']); - $this->assertTrue(preg_match('/^<opaquelocktoken:(.*)>$/',$this->response->headers['Lock-Token'])===1,'We did not get a valid Locktoken back (' . $this->response->headers['Lock-Token'] . ')'); + $this->assertEquals('application/xml; charset=utf-8',$this->response->getHeader('Content-Type')); + $this->assertTrue(preg_match('/^<opaquelocktoken:(.*)>$/',$this->response->getHeader('Lock-Token'))===1,'We did not get a valid Locktoken back (' . $this->response->getHeader('Lock-Token') . ')'); - $this->assertEquals('HTTP/1.1 200 OK',$this->response->status); + $this->assertEquals(200, $this->response->status); $serverVars = array( 'REQUEST_URI' => '/test.txt', @@ -474,15 +452,16 @@ class PluginTest extends DAV\AbstractServer { 'HTTP_IF' => '(<opaquelocktoken:token1>)', ); - $request = new HTTP\Request($serverVars); + $request = HTTP\Sapi::createFromServerArray($serverVars); $request->setBody('newbody'); $this->server->httpRequest = $request; $this->server->exec(); - $this->assertEquals('application/xml; charset=utf-8',$this->response->headers['Content-Type']); - $this->assertTrue(preg_match('/^<opaquelocktoken:(.*)>$/',$this->response->headers['Lock-Token'])===1,'We did not get a valid Locktoken back (' . $this->response->headers['Lock-Token'] . ')'); + $this->assertEquals('application/xml; charset=utf-8',$this->response->getHeader('Content-Type')); + $this->assertTrue(preg_match('/^<opaquelocktoken:(.*)>$/',$this->response->getHeader('Lock-Token'))===1,'We did not get a valid Locktoken back (' . $this->response->getHeader('Lock-Token') . ')'); - $this->assertEquals('HTTP/1.1 412 Precondition failed',$this->response->status); + // $this->assertEquals('412 Precondition failed',$this->response->status); + $this->assertEquals(423, $this->response->status); } @@ -496,7 +475,7 @@ class PluginTest extends DAV\AbstractServer { 'REQUEST_METHOD' => 'LOCK', ); - $request = new HTTP\Request($serverVars); + $request = HTTP\Sapi::createFromServerArray($serverVars); $request->setBody('<?xml version="1.0"?> <D:lockinfo xmlns:D="DAV:"> <D:lockscope><D:exclusive/></D:lockscope> @@ -509,22 +488,22 @@ class PluginTest extends DAV\AbstractServer { $this->server->httpRequest = $request; $this->server->exec(); - $this->assertEquals('application/xml; charset=utf-8',$this->response->headers['Content-Type']); - $this->assertTrue(preg_match('/^<opaquelocktoken:(.*)>$/',$this->response->headers['Lock-Token'])===1,'We did not get a valid Locktoken back (' . $this->response->headers['Lock-Token'] . ')'); + $this->assertEquals('application/xml; charset=utf-8',$this->response->getHeader('Content-Type')); + $this->assertTrue(preg_match('/^<opaquelocktoken:(.*)>$/',$this->response->getHeader('Lock-Token'))===1,'We did not get a valid Locktoken back (' . $this->response->getHeader('Lock-Token') . ')'); - $this->assertEquals('HTTP/1.1 200 OK',$this->response->status); + $this->assertEquals(200, $this->response->status); $serverVars = array( 'REQUEST_URI' => '/dir', 'REQUEST_METHOD' => 'DELETE', ); - $request = new HTTP\Request($serverVars); + $request = HTTP\Sapi::createFromServerArray($serverVars); $this->server->httpRequest = $request; $this->server->exec(); - $this->assertEquals('HTTP/1.1 423 Locked',$this->response->status); - $this->assertEquals('application/xml; charset=utf-8',$this->response->headers['Content-Type']); + $this->assertEquals(423, $this->response->status); + $this->assertEquals('application/xml; charset=utf-8',$this->response->getHeader('Content-Type')); } /** @@ -537,7 +516,7 @@ class PluginTest extends DAV\AbstractServer { 'REQUEST_METHOD' => 'LOCK', ); - $request = new HTTP\Request($serverVars); + $request = HTTP\Sapi::createFromServerArray($serverVars); $request->setBody('<?xml version="1.0"?> <D:lockinfo xmlns:D="DAV:"> <D:lockscope><D:exclusive/></D:lockscope> @@ -550,23 +529,23 @@ class PluginTest extends DAV\AbstractServer { $this->server->httpRequest = $request; $this->server->exec(); - $this->assertEquals('application/xml; charset=utf-8',$this->response->headers['Content-Type']); - $this->assertTrue(preg_match('/^<opaquelocktoken:(.*)>$/',$this->response->headers['Lock-Token'])===1,'We did not get a valid Locktoken back (' . $this->response->headers['Lock-Token'] . ')'); + $this->assertEquals('application/xml; charset=utf-8',$this->response->getHeader('Content-Type')); + $this->assertTrue(preg_match('/^<opaquelocktoken:(.*)>$/',$this->response->getHeader('Lock-Token'))===1,'We did not get a valid Locktoken back (' . $this->response->getHeader('Lock-Token') . ')'); - $this->assertEquals('HTTP/1.1 200 OK',$this->response->status); + $this->assertEquals(200, $this->response->status); $serverVars = array( 'REQUEST_URI' => '/dir/child.txt', 'REQUEST_METHOD' => 'DELETE', - 'HTTP_IF' => '(' . $this->response->headers['Lock-Token'] . ')', + 'HTTP_IF' => '(' . $this->response->getHeader('Lock-Token') . ')', ); - $request = new HTTP\Request($serverVars); + $request = HTTP\Sapi::createFromServerArray($serverVars); $this->server->httpRequest = $request; $this->server->exec(); - $this->assertEquals('HTTP/1.1 204 No Content',$this->response->status); - $this->assertEquals('application/xml; charset=utf-8',$this->response->headers['Content-Type']); + $this->assertEquals(204, $this->response->status); + $this->assertEquals('application/xml; charset=utf-8',$this->response->getHeader('Content-Type')); } @@ -580,7 +559,7 @@ class PluginTest extends DAV\AbstractServer { 'REQUEST_METHOD' => 'LOCK', ); - $request = new HTTP\Request($serverVars); + $request = HTTP\Sapi::createFromServerArray($serverVars); $request->setBody('<?xml version="1.0"?> <D:lockinfo xmlns:D="DAV:"> <D:lockscope><D:exclusive/></D:lockscope> @@ -593,10 +572,10 @@ class PluginTest extends DAV\AbstractServer { $this->server->httpRequest = $request; $this->server->exec(); - $this->assertEquals('application/xml; charset=utf-8',$this->response->headers['Content-Type']); - $this->assertTrue(preg_match('/^<opaquelocktoken:(.*)>$/',$this->response->headers['Lock-Token'])===1,'We did not get a valid Locktoken back (' . $this->response->headers['Lock-Token'] . ')'); + $this->assertEquals('application/xml; charset=utf-8',$this->response->getHeader('Content-Type')); + $this->assertTrue(preg_match('/^<opaquelocktoken:(.*)>$/',$this->response->getHeader('Lock-Token'))===1,'We did not get a valid Locktoken back (' . $this->response->getHeader('Lock-Token') . ')'); - $this->assertEquals('HTTP/1.1 200 OK',$this->response->status); + $this->assertEquals(200, $this->response->status); $serverVars = array( 'REQUEST_URI' => '/dir/child.txt', @@ -604,12 +583,12 @@ class PluginTest extends DAV\AbstractServer { 'HTTP_DESTINATION' => '/dir/child2.txt', ); - $request = new HTTP\Request($serverVars); + $request = HTTP\Sapi::createFromServerArray($serverVars); $this->server->httpRequest = $request; $this->server->exec(); - $this->assertEquals('HTTP/1.1 201 Created',$this->response->status,'Copy must succeed if only the source is locked, but not the destination'); - $this->assertEquals('application/xml; charset=utf-8',$this->response->headers['Content-Type']); + $this->assertEquals(201, $this->response->status,'Copy must succeed if only the source is locked, but not the destination'); + $this->assertEquals('application/xml; charset=utf-8',$this->response->getHeader('Content-Type')); } /** @@ -622,7 +601,7 @@ class PluginTest extends DAV\AbstractServer { 'REQUEST_METHOD' => 'LOCK', ); - $request = new HTTP\Request($serverVars); + $request = HTTP\Sapi::createFromServerArray($serverVars); $request->setBody('<?xml version="1.0"?> <D:lockinfo xmlns:D="DAV:"> <D:lockscope><D:exclusive/></D:lockscope> @@ -635,10 +614,10 @@ class PluginTest extends DAV\AbstractServer { $this->server->httpRequest = $request; $this->server->exec(); - $this->assertEquals('application/xml; charset=utf-8',$this->response->headers['Content-Type']); - $this->assertTrue(preg_match('/^<opaquelocktoken:(.*)>$/',$this->response->headers['Lock-Token'])===1,'We did not get a valid Locktoken back (' . $this->response->headers['Lock-Token'] . ')'); + $this->assertEquals('application/xml; charset=utf-8',$this->response->getHeader('Content-Type')); + $this->assertTrue(preg_match('/^<opaquelocktoken:(.*)>$/',$this->response->getHeader('Lock-Token'))===1,'We did not get a valid Locktoken back (' . $this->response->getHeader('Lock-Token') . ')'); - $this->assertEquals('HTTP/1.1 201 Created',$this->response->status); + $this->assertEquals(201, $this->response->status); $serverVars = array( 'REQUEST_URI' => '/dir/child.txt', @@ -646,12 +625,12 @@ class PluginTest extends DAV\AbstractServer { 'HTTP_DESTINATION' => '/dir/child2.txt', ); - $request = new HTTP\Request($serverVars); + $request = HTTP\Sapi::createFromServerArray($serverVars); $this->server->httpRequest = $request; $this->server->exec(); - $this->assertEquals('HTTP/1.1 423 Locked',$this->response->status,'Copy must succeed if only the source is locked, but not the destination'); - $this->assertEquals('application/xml; charset=utf-8',$this->response->headers['Content-Type']); + $this->assertEquals(423, $this->response->status,'Copy must succeed if only the source is locked, but not the destination'); + $this->assertEquals('application/xml; charset=utf-8',$this->response->getHeader('Content-Type')); } @@ -665,7 +644,7 @@ class PluginTest extends DAV\AbstractServer { 'REQUEST_METHOD' => 'LOCK', ); - $request = new HTTP\Request($serverVars); + $request = HTTP\Sapi::createFromServerArray($serverVars); $request->setBody('<?xml version="1.0"?> <D:lockinfo xmlns:D="DAV:"> <D:lockscope><D:exclusive/></D:lockscope> @@ -678,10 +657,10 @@ class PluginTest extends DAV\AbstractServer { $this->server->httpRequest = $request; $this->server->exec(); - $this->assertEquals('application/xml; charset=utf-8',$this->response->headers['Content-Type']); - $this->assertTrue(preg_match('/^<opaquelocktoken:(.*)>$/',$this->response->headers['Lock-Token'])===1,'We did not get a valid Locktoken back (' . $this->response->headers['Lock-Token'] . ')'); + $this->assertEquals('application/xml; charset=utf-8',$this->response->getHeader('Content-Type')); + $this->assertTrue(preg_match('/^<opaquelocktoken:(.*)>$/',$this->response->getHeader('Lock-Token'))===1,'We did not get a valid Locktoken back (' . $this->response->getHeader('Lock-Token') . ')'); - $this->assertEquals('HTTP/1.1 200 OK',$this->response->status); + $this->assertEquals(200, $this->response->status); $serverVars = array( 'REQUEST_URI' => '/dir/child.txt', @@ -689,12 +668,12 @@ class PluginTest extends DAV\AbstractServer { 'HTTP_DESTINATION' => '/dir/child2.txt', ); - $request = new HTTP\Request($serverVars); + $request = HTTP\Sapi::createFromServerArray($serverVars); $this->server->httpRequest = $request; $this->server->exec(); - $this->assertEquals('HTTP/1.1 423 Locked',$this->response->status,'Copy must succeed if only the source is locked, but not the destination'); - $this->assertEquals('application/xml; charset=utf-8',$this->response->headers['Content-Type']); + $this->assertEquals(423, $this->response->status,'Copy must succeed if only the source is locked, but not the destination'); + $this->assertEquals('application/xml; charset=utf-8',$this->response->getHeader('Content-Type')); } @@ -708,7 +687,7 @@ class PluginTest extends DAV\AbstractServer { 'REQUEST_METHOD' => 'LOCK', ); - $request = new HTTP\Request($serverVars); + $request = HTTP\Sapi::createFromServerArray($serverVars); $request->setBody('<?xml version="1.0"?> <D:lockinfo xmlns:D="DAV:"> <D:lockscope><D:exclusive/></D:lockscope> @@ -721,23 +700,23 @@ class PluginTest extends DAV\AbstractServer { $this->server->httpRequest = $request; $this->server->exec(); - $this->assertEquals('application/xml; charset=utf-8',$this->response->headers['Content-Type']); - $this->assertTrue(preg_match('/^<opaquelocktoken:(.*)>$/',$this->response->headers['Lock-Token'])===1,'We did not get a valid Locktoken back (' . $this->response->headers['Lock-Token'] . ')'); + $this->assertEquals('application/xml; charset=utf-8',$this->response->getHeader('Content-Type')); + $this->assertTrue(preg_match('/^<opaquelocktoken:(.*)>$/',$this->response->getHeader('Lock-Token'))===1,'We did not get a valid Locktoken back (' . $this->response->getHeader('Lock-Token') . ')'); - $this->assertEquals('HTTP/1.1 200 OK',$this->response->status); + $this->assertEquals(200, $this->response->status); $serverVars = array( 'REQUEST_URI' => '/dir/child.txt', 'REQUEST_METHOD' => 'MOVE', 'HTTP_DESTINATION' => '/dir/child2.txt', - 'HTTP_IF' => '(' . $this->response->headers['Lock-Token'] . ')', + 'HTTP_IF' => '(' . $this->response->getHeader('Lock-Token') . ')', ); - $request = new HTTP\Request($serverVars); + $request = HTTP\Sapi::createFromServerArray($serverVars); $this->server->httpRequest = $request; $this->server->exec(); - $this->assertEquals('HTTP/1.1 201 Created',$this->response->status,'A valid lock-token was provided for the source, so this MOVE operation must succeed. Full response body: ' . $this->response->body); + $this->assertEquals(201, $this->response->status,'A valid lock-token was provided for the source, so this MOVE operation must succeed. Full response body: ' . $this->response->body); } @@ -751,7 +730,7 @@ class PluginTest extends DAV\AbstractServer { 'REQUEST_METHOD' => 'LOCK', ); - $request = new HTTP\Request($serverVars); + $request = HTTP\Sapi::createFromServerArray($serverVars); $request->setBody('<?xml version="1.0"?> <D:lockinfo xmlns:D="DAV:"> <D:lockscope><D:exclusive/></D:lockscope> @@ -764,10 +743,10 @@ class PluginTest extends DAV\AbstractServer { $this->server->httpRequest = $request; $this->server->exec(); - $this->assertEquals('application/xml; charset=utf-8',$this->response->headers['Content-Type']); - $this->assertTrue(preg_match('/^<opaquelocktoken:(.*)>$/',$this->response->headers['Lock-Token'])===1,'We did not get a valid Locktoken back (' . $this->response->headers['Lock-Token'] . ')'); + $this->assertEquals('application/xml; charset=utf-8',$this->response->getHeader('Content-Type')); + $this->assertTrue(preg_match('/^<opaquelocktoken:(.*)>$/',$this->response->getHeader('Lock-Token'))===1,'We did not get a valid Locktoken back (' . $this->response->getHeader('Lock-Token') . ')'); - $this->assertEquals('HTTP/1.1 201 Created',$this->response->status); + $this->assertEquals(201, $this->response->status); $serverVars = array( 'REQUEST_URI' => '/dir/child.txt', @@ -775,12 +754,12 @@ class PluginTest extends DAV\AbstractServer { 'HTTP_DESTINATION' => '/dir/child2.txt', ); - $request = new HTTP\Request($serverVars); + $request = HTTP\Sapi::createFromServerArray($serverVars); $this->server->httpRequest = $request; $this->server->exec(); - $this->assertEquals('HTTP/1.1 423 Locked',$this->response->status,'Copy must succeed if only the source is locked, but not the destination'); - $this->assertEquals('application/xml; charset=utf-8',$this->response->headers['Content-Type']); + $this->assertEquals(423, $this->response->status,'Copy must succeed if only the source is locked, but not the destination'); + $this->assertEquals('application/xml; charset=utf-8',$this->response->getHeader('Content-Type')); } /** @@ -794,7 +773,7 @@ class PluginTest extends DAV\AbstractServer { 'HTTP_DEPTH' => 'infinite', ); - $request = new HTTP\Request($serverVars); + $request = HTTP\Sapi::createFromServerArray($serverVars); $request->setBody('<?xml version="1.0"?> <D:lockinfo xmlns:D="DAV:"> <D:lockscope><D:exclusive/></D:lockscope> @@ -807,24 +786,24 @@ class PluginTest extends DAV\AbstractServer { $this->server->httpRequest = $request; $this->server->exec(); - $this->assertEquals('application/xml; charset=utf-8',$this->response->headers['Content-Type']); - $this->assertTrue(preg_match('/^<opaquelocktoken:(.*)>$/',$this->response->headers['Lock-Token'])===1,'We did not get a valid Locktoken back (' . $this->response->headers['Lock-Token'] . ')'); + $this->assertEquals('application/xml; charset=utf-8',$this->response->getHeader('Content-Type')); + $this->assertTrue(preg_match('/^<opaquelocktoken:(.*)>$/',$this->response->getHeader('Lock-Token'))===1,'We did not get a valid Locktoken back (' . $this->response->getHeader('Lock-Token') . ')'); - $this->assertEquals('HTTP/1.1 200 OK',$this->response->status); + $this->assertEquals(200,$this->response->status); $serverVars = array( 'REQUEST_URI' => '/dir/child.txt', 'REQUEST_METHOD' => 'MOVE', 'HTTP_DESTINATION' => '/dir/child2.txt', - 'HTTP_IF' => '</dir> (' . $this->response->headers['Lock-Token'] . ')', + 'HTTP_IF' => '</dir> (' . $this->response->getHeader('Lock-Token') . ')', ); - $request = new HTTP\Request($serverVars); + $request = HTTP\Sapi::createFromServerArray($serverVars); $this->server->httpRequest = $request; $this->server->exec(); - $this->assertEquals('HTTP/1.1 201 Created',$this->response->status,'We locked the parent of both the source and destination, but the move didn\'t succeed.'); - $this->assertEquals('application/xml; charset=utf-8',$this->response->headers['Content-Type']); + $this->assertEquals(201, $this->response->status,'We locked the parent of both the source and destination, but the move didn\'t succeed.'); + $this->assertEquals('application/xml; charset=utf-8',$this->response->getHeader('Content-Type')); } @@ -838,7 +817,7 @@ class PluginTest extends DAV\AbstractServer { 'REQUEST_METHOD' => 'LOCK', ); - $request = new HTTP\Request($serverVars); + $request = HTTP\Sapi::createFromServerArray($serverVars); $request->setBody('<?xml version="1.0"?> <D:lockinfo xmlns:D="DAV:"> <D:lockscope><D:exclusive/></D:lockscope> @@ -851,26 +830,65 @@ class PluginTest extends DAV\AbstractServer { $this->server->httpRequest = $request; $this->server->exec(); - $this->assertEquals('application/xml; charset=utf-8',$this->response->headers['Content-Type']); - $this->assertTrue(preg_match('/^<opaquelocktoken:(.*)>$/',$this->response->headers['Lock-Token'])===1,'We did not get a valid Locktoken back (' . $this->response->headers['Lock-Token'] . ')'); + $this->assertEquals('application/xml; charset=utf-8',$this->response->getHeader('Content-Type')); + $this->assertTrue(preg_match('/^<opaquelocktoken:(.*)>$/',$this->response->getHeader('Lock-Token'))===1,'We did not get a valid Locktoken back (' . $this->response->getHeader('Lock-Token') . ')'); - $this->assertEquals('HTTP/1.1 200 OK',$this->response->status); + $this->assertEquals(200, $this->response->status); $serverVars = array( 'REQUEST_URI' => '/test.txt', 'REQUEST_METHOD' => 'PUT', - 'HTTP_IF' => '('.$this->response->headers['Lock-Token'].')', + 'HTTP_IF' => '('.$this->response->getHeader('Lock-Token').')', ); - $request = new HTTP\Request($serverVars); + $request = HTTP\Sapi::createFromServerArray($serverVars); $request->setBody('newbody'); $this->server->httpRequest = $request; $this->server->exec(); - $this->assertEquals('application/xml; charset=utf-8',$this->response->headers['Content-Type']); - $this->assertTrue(preg_match('/^<opaquelocktoken:(.*)>$/',$this->response->headers['Lock-Token'])===1,'We did not get a valid Locktoken back (' . $this->response->headers['Lock-Token'] . ')'); + $this->assertEquals('application/xml; charset=utf-8',$this->response->getHeader('Content-Type')); + $this->assertTrue(preg_match('/^<opaquelocktoken:(.*)>$/',$this->response->getHeader('Lock-Token'))===1,'We did not get a valid Locktoken back (' . $this->response->getHeader('Lock-Token') . ')'); - $this->assertEquals('HTTP/1.1 204 No Content',$this->response->status); + $this->assertEquals(204, $this->response->status); + + } + + /** + * @depends testLock + */ + function testLockPutUnrelatedToken() { + + $request = new HTTP\Request('LOCK', '/unrelated.txt'); + $request->setBody('<?xml version="1.0"?> +<D:lockinfo xmlns:D="DAV:"> + <D:lockscope><D:exclusive/></D:lockscope> + <D:locktype><D:write/></D:locktype> + <D:owner> + <D:href>http://example.org/~ejw/contact.html</D:href> + </D:owner> +</D:lockinfo>'); + + $this->server->httpRequest = $request; + $this->server->exec(); + + $this->assertEquals('application/xml; charset=utf-8',$this->response->getHeader('Content-Type')); + $this->assertTrue(preg_match('/^<opaquelocktoken:(.*)>$/',$this->response->getHeader('Lock-Token'))===1,'We did not get a valid Locktoken back (' . $this->response->getHeader('Lock-Token') . ')'); + + $this->assertEquals(201, $this->response->getStatus()); + + $request = new HTTP\Request( + 'PUT', + '/test.txt', + ['If' => '</unrelated.txt> ('.$this->response->getHeader('Lock-Token').')'] + ); + $request->setBody('newbody'); + $this->server->httpRequest = $request; + $this->server->exec(); + + $this->assertEquals('application/xml; charset=utf-8',$this->response->getHeader('Content-Type')); + $this->assertTrue(preg_match('/^<opaquelocktoken:(.*)>$/',$this->response->getHeader('Lock-Token'))===1,'We did not get a valid Locktoken back (' . $this->response->getHeader('Lock-Token') . ')'); + + $this->assertEquals(204, $this->response->status); } @@ -882,11 +900,11 @@ class PluginTest extends DAV\AbstractServer { 'HTTP_IF' => '(["etag1"])', ); - $request = new HTTP\Request($serverVars); + $request = HTTP\Sapi::createFromServerArray($serverVars); $request->setBody('newbody'); $this->server->httpRequest = $request; $this->server->exec(); - $this->assertEquals('HTTP/1.1 412 Precondition failed',$this->response->status); + $this->assertEquals(412, $this->response->status); } @@ -895,22 +913,27 @@ class PluginTest extends DAV\AbstractServer { */ function testPutWithCorrectETag() { - // We need an etag-enabled file node. - $tree = new DAV\ObjectTree(new DAV\FSExt\Directory(SABRE_TEMPDIR)); + // We need an ETag-enabled file node. + $tree = new DAV\Tree(new DAV\FSExt\Directory(SABRE_TEMPDIR)); $this->server->tree = $tree; - $etag = md5(file_get_contents(SABRE_TEMPDIR . '/test.txt')); + $filename = SABRE_TEMPDIR . '/test.txt'; + $etag = sha1( + fileinode($filename) . + filesize($filename ) . + filemtime($filename) + ); $serverVars = array( 'REQUEST_URI' => '/test.txt', 'REQUEST_METHOD' => 'PUT', 'HTTP_IF' => '(["'.$etag.'"])', ); - $request = new HTTP\Request($serverVars); + $request = HTTP\Sapi::createFromServerArray($serverVars); $request->setBody('newbody'); $this->server->httpRequest = $request; $this->server->exec(); - $this->assertEquals('HTTP/1.1 204 No Content',$this->response->status, 'Incorrect status received. Full response body:' . $this->response->body); + $this->assertEquals(204, $this->response->status, 'Incorrect status received. Full response body:' . $this->response->body); } @@ -921,18 +944,17 @@ class PluginTest extends DAV\AbstractServer { 'REQUEST_METHOD' => 'DELETE', 'HTTP_IF' => '(["etag1"])', ); + $request = HTTP\Sapi::createFromServerArray($serverVars); - $request = new HTTP\Request($serverVars); - $request->setBody('newbody'); $this->server->httpRequest = $request; $this->server->exec(); - $this->assertEquals('HTTP/1.1 412 Precondition failed',$this->response->status); + $this->assertEquals(412, $this->response->status); } function testGetTimeoutHeader() { - $request = new HTTP\Request(array( + $request = HTTP\Sapi::createFromServerArray(array( 'HTTP_TIMEOUT' => 'second-100', )); @@ -941,22 +963,21 @@ class PluginTest extends DAV\AbstractServer { } + function testGetTimeoutHeaderTwoItems() { - function testGetTimeoutHeaderNotSet() { - - $request = new HTTP\Request(array( + $request = HTTP\Sapi::createFromServerArray(array( + 'HTTP_TIMEOUT' => 'second-5, infinite', )); $this->server->httpRequest = $request; - $this->assertEquals(0, $this->locksPlugin->getTimeoutHeader()); + $this->assertEquals(5, $this->locksPlugin->getTimeoutHeader()); } - function testGetTimeoutHeaderInfinite() { - $request = new HTTP\Request(array( - 'HTTP_TIMEOUT' => 'infinite', + $request = HTTP\Sapi::createFromServerArray(array( + 'HTTP_TIMEOUT' => 'infinite, second-5', )); $this->server->httpRequest = $request; @@ -969,7 +990,7 @@ class PluginTest extends DAV\AbstractServer { */ function testGetTimeoutHeaderInvalid() { - $request = new HTTP\Request(array( + $request = HTTP\Sapi::createFromServerArray(array( 'HTTP_TIMEOUT' => 'yourmom', )); diff --git a/vendor/sabre/dav/tests/Sabre/DAV/Mock/Collection.php b/vendor/sabre/dav/tests/Sabre/DAV/Mock/Collection.php index b2613ec9f..6ccab4f66 100644 --- a/vendor/sabre/dav/tests/Sabre/DAV/Mock/Collection.php +++ b/vendor/sabre/dav/tests/Sabre/DAV/Mock/Collection.php @@ -15,7 +15,7 @@ use Sabre\DAV; * * a string, for a file * * An instance of \Sabre\DAV\INode. * - * @copyright Copyright (C) 2007-2014 fruux GmbH. All rights reserved. + * @copyright Copyright (C) fruux GmbH (https://fruux.com/) * @author Evert Pot (http://evertpot.com/) * @license http://sabre.io/license/ Modified BSD License */ @@ -32,10 +32,20 @@ class Collection extends DAV\Collection { * @param array $children * @return void */ - public function __construct($name, array $children = array(), Collection $parent = null) { + function __construct($name, array $children = [], Collection $parent = null) { $this->name = $name; - $this->children = $children; + foreach ($children as $key => $value) { + if (is_string($value)) { + $this->children[] = new File($key, $value, $this); + } elseif (is_array($value)) { + $this->children[] = new self($key, $value, $this); + } elseif ($value instanceof \Sabre\DAV\INode) { + $this->children[] = $value; + } else { + throw new \InvalidArgumentException('Unknown value passed in $children'); + } + } $this->parent = $parent; } @@ -47,7 +57,7 @@ class Collection extends DAV\Collection { * * @return string */ - public function getName() { + function getName() { return $this->name; @@ -77,12 +87,12 @@ class Collection extends DAV\Collection { * @param resource|string $data Initial payload * @return null|string */ - public function createFile($name, $data = null) { + function createFile($name, $data = null) { if (is_resource($data)) { $data = stream_get_contents($data); } - $this->children[$name] = $data; + $this->children[] = new File($name, $data, $this); return '"' . md5($data) . '"'; } @@ -93,9 +103,9 @@ class Collection extends DAV\Collection { * @param string $name * @return void */ - public function createDirectory($name) { + function createDirectory($name) { - $this->children[$name] = array(); + $this->children[] = new self($name); } @@ -104,22 +114,18 @@ class Collection extends DAV\Collection { * * @return \Sabre\DAV\INode[] */ - public function getChildren() { + function getChildren() { - $result = array(); - foreach($this->children as $key=>$value) { + return $this->children; - if ($value instanceof DAV\INode) { - $result[] = $value; - } elseif (is_array($value)) { - $result[] = new Collection($key, $value, $this); - } else { - $result[] = new File($key, $value, $this); - } + } - } + /** + * Adds an already existing node to this collection. + */ + function addNode(\Sabre\DAV\INode $node) { - return $result; + $this->children[] = $node; } @@ -129,16 +135,11 @@ class Collection extends DAV\Collection { * @param string $name * @return void */ - public function deleteChild($name) { + function deleteChild($name) { - foreach($this->children as $key=>$value) { + foreach ($this->children as $key => $value) { - if ($value instanceof DAV\INode) { - if ($value->getName() == $name) { - unset($this->children[$key]); - return; - } - } elseif ($key === $name) { + if ($value->getName() == $name) { unset($this->children[$key]); return; } @@ -152,9 +153,9 @@ class Collection extends DAV\Collection { * * @return void */ - public function delete() { + function delete() { - foreach($this->getChildren() as $child) { + foreach ($this->getChildren() as $child) { $this->deleteChild($child->getName()); } $this->parent->deleteChild($this->getName()); diff --git a/vendor/sabre/dav/tests/Sabre/DAV/Mock/File.php b/vendor/sabre/dav/tests/Sabre/DAV/Mock/File.php index 2b25bbb88..23855e3c5 100644 --- a/vendor/sabre/dav/tests/Sabre/DAV/Mock/File.php +++ b/vendor/sabre/dav/tests/Sabre/DAV/Mock/File.php @@ -9,7 +9,7 @@ use Sabre\DAV; * * See the Collection in this directory for more details. * - * @copyright Copyright (C) 2007-2014 fruux GmbH. All rights reserved. + * @copyright Copyright (C) fruux GmbH (https://fruux.com/) * @author Evert Pot (http://evertpot.com/) * @license http://sabre.io/license/ Modified BSD License */ @@ -18,6 +18,7 @@ class File extends DAV\File { protected $name; protected $contents; protected $parent; + protected $lastModified; /** * Creates the object @@ -26,12 +27,18 @@ class File extends DAV\File { * @param array $children * @return void */ - public function __construct($name, $contents, Collection $parent) { + function __construct($name, $contents, Collection $parent = null, $lastModified = -1) { $this->name = $name; $this->put($contents); $this->parent = $parent; + if ($lastModified === -1) { + $lastModified = time(); + } + + $this->lastModified = $lastModified; + } /** @@ -41,12 +48,23 @@ class File extends DAV\File { * * @return string */ - public function getName() { + function getName() { return $this->name; } + /** + * Changes the name of the node. + * + * @return void + */ + function setName($name) { + + $this->name = $name; + + } + /** * Updates the data * @@ -67,7 +85,7 @@ class File extends DAV\File { * @param resource $data * @return string|null */ - public function put($data) { + function put($data) { if (is_resource($data)) { $data = stream_get_contents($data); @@ -84,7 +102,7 @@ class File extends DAV\File { * * @return mixed */ - public function get() { + function get() { return $this->contents; @@ -99,7 +117,7 @@ class File extends DAV\File { * * @return void */ - public function getETag() { + function getETag() { return '"' . md5($this->contents) . '"'; @@ -110,7 +128,7 @@ class File extends DAV\File { * * @return int */ - public function getSize() { + function getSize() { return strlen($this->contents); @@ -121,10 +139,22 @@ class File extends DAV\File { * * @return void */ - public function delete() { + function delete() { $this->parent->deleteChild($this->name); } + /** + * Returns the last modification time as a unix timestamp. + * If the information is not available, return null. + * + * @return int + */ + function getLastModified() { + + return $this->lastModified; + + } + } diff --git a/vendor/sabre/dav/tests/Sabre/DAV/Mount/PluginTest.php b/vendor/sabre/dav/tests/Sabre/DAV/Mount/PluginTest.php index e818fe043..e6415792c 100644 --- a/vendor/sabre/dav/tests/Sabre/DAV/Mount/PluginTest.php +++ b/vendor/sabre/dav/tests/Sabre/DAV/Mount/PluginTest.php @@ -23,11 +23,11 @@ class PluginTest extends DAV\AbstractServer { 'REQUEST_METHOD' => 'GET', ); - $request = new HTTP\Request($serverVars); + $request = HTTP\Sapi::createFromServerArray($serverVars); $this->server->httpRequest = ($request); $this->server->exec(); - $this->assertEquals('HTTP/1.1 501 Not Implemented',$this->response->status,'We expected GET to not be implemented for Directories. Response body: ' . $this->response->body); + $this->assertEquals(501, $this->response->status,'We expected GET to not be implemented for Directories. Response body: ' . $this->response->body); } @@ -40,14 +40,14 @@ class PluginTest extends DAV\AbstractServer { 'HTTP_HOST' => 'example.org', ); - $request = new HTTP\Request($serverVars); + $request = HTTP\Sapi::createFromServerArray($serverVars); $this->server->httpRequest = ($request); $this->server->exec(); - $this->assertEquals('HTTP/1.1 200 OK',$this->response->status); + $this->assertEquals(200, $this->response->status); $xml = simplexml_load_string($this->response->body); - $this->assertTrue($xml==true,'Response was not a valid xml document'); + $this->assertInstanceOf('SimpleXMLElement',$xml, 'Response was not a valid xml document. The list of errors:' . print_r(libxml_get_errors(),true) . '. xml body: ' . $this->response->body . '. What type we got: ' . gettype($xml) . ' class, if object: ' . get_class($xml)); $xml->registerXPathNamespace('dm','http://purl.org/NET/webdav/mount'); $url = $xml->xpath('//dm:url'); diff --git a/vendor/sabre/dav/tests/Sabre/DAV/ObjectTreeTest.php b/vendor/sabre/dav/tests/Sabre/DAV/ObjectTreeTest.php index 330058b6d..9b7eeb90c 100644 --- a/vendor/sabre/dav/tests/Sabre/DAV/ObjectTreeTest.php +++ b/vendor/sabre/dav/tests/Sabre/DAV/ObjectTreeTest.php @@ -16,7 +16,7 @@ class ObjectTreeTest extends \PHPUnit_Framework_TestCase { file_put_contents(SABRE_TEMPDIR . '/root/file.txt','contents'); file_put_contents(SABRE_TEMPDIR . '/root/subdir/subfile.txt','subcontents'); $rootNode = new FSExt\Directory(SABRE_TEMPDIR . '/root'); - $this->tree = new ObjectTree($rootNode); + $this->tree = new Tree($rootNode); } diff --git a/vendor/sabre/dav/tests/Sabre/DAV/PartialUpdate/FileMock.php b/vendor/sabre/dav/tests/Sabre/DAV/PartialUpdate/FileMock.php index e8cdc1666..d6cc406be 100644 --- a/vendor/sabre/dav/tests/Sabre/DAV/PartialUpdate/FileMock.php +++ b/vendor/sabre/dav/tests/Sabre/DAV/PartialUpdate/FileMock.php @@ -3,7 +3,7 @@ namespace Sabre\DAV\PartialUpdate; use Sabre\DAV; -class FileMock implements IFile { +class FileMock implements IPatchSupport { protected $data = ''; @@ -16,14 +16,56 @@ class FileMock implements IFile { } - function putRange($str,$start) { - - if (is_resource($str)) { - $str = stream_get_contents($str); + /** + * Updates the file based on a range specification. + * + * The first argument is the data, which is either a readable stream + * resource or a string. + * + * The second argument is the type of update we're doing. + * This is either: + * * 1. append + * * 2. update based on a start byte + * * 3. update based on an end byte + *; + * The third argument is the start or end byte. + * + * After a successful put operation, you may choose to return an ETag. The + * etag must always be surrounded by double-quotes. These quotes must + * appear in the actual string you're returning. + * + * Clients may use the ETag from a PUT request to later on make sure that + * when they update the file, the contents haven't changed in the mean + * time. + * + * @param resource|string $data + * @param int $rangeType + * @param int $offset + * @return string|null + */ + function patch($data, $rangeType, $offset = null) { + + if (is_resource($data)) { + $data = stream_get_contents($data); } - $this->data = substr($this->data, 0, $start) . $str . substr($this->data, $start + strlen($str)); + switch($rangeType) { + + case 1 : + $this->data.=$data; + break; + case 3 : + // Turn the offset into an offset-offset. + $offset = strlen($this->data) - $offset; + // No break is intentional + case 2 : + $this->data = + substr($this->data, 0, $offset) . + $data . + substr($this->data, $offset + strlen($data)); + break; + } } diff --git a/vendor/sabre/dav/tests/Sabre/DAV/PartialUpdate/PluginTest.php b/vendor/sabre/dav/tests/Sabre/DAV/PartialUpdate/PluginTest.php index 32f7e4e2c..5bd696416 100644 --- a/vendor/sabre/dav/tests/Sabre/DAV/PartialUpdate/PluginTest.php +++ b/vendor/sabre/dav/tests/Sabre/DAV/PartialUpdate/PluginTest.php @@ -12,7 +12,7 @@ class PluginTest extends \Sabre\DAVServerTest { protected $node; protected $plugin; - public function setUp() { + function setUp() { $this->node = new FileMock(); $this->tree[] = $this->node; @@ -26,124 +26,109 @@ class PluginTest extends \Sabre\DAVServerTest { } - public function testInit() { + function testInit() { $this->assertEquals('partialupdate', $this->plugin->getPluginName()); - $this->assertEquals(array('sabredav-partialupdate'), $this->plugin->getFeatures()); - $this->assertEquals(array( + $this->assertEquals(['sabredav-partialupdate'], $this->plugin->getFeatures()); + $this->assertEquals([ 'PATCH' - ), $this->plugin->getHTTPMethods('partial')); - $this->assertEquals(array( - ), $this->plugin->getHTTPMethods('')); - - $this->assertNull($this->plugin->unknownMethod('FOO','partial')); + ], $this->plugin->getHTTPMethods('partial')); + $this->assertEquals([ + ], $this->plugin->getHTTPMethods('')); } - public function testPatchNoRange() { + function testPatchNoRange() { - $this->node->put('00000000'); - $request = new HTTP\Request(array( + $this->node->put('aaaaaaaa'); + $request = HTTP\Sapi::createFromServerArray([ 'REQUEST_METHOD' => 'PATCH', 'REQUEST_URI' => '/partial', - )); + ]); $response = $this->request($request); - $this->assertEquals('HTTP/1.1 400 Bad request', $response->status, 'Full response body:' . $response->body); + $this->assertEquals(400, $response->status, 'Full response body:' . $response->body); } - public function testPatchNotSupported() { - - $this->node->put('00000000'); - $request = new HTTP\Request(array( - 'REQUEST_METHOD' => 'PATCH', - 'REQUEST_URI' => '/', - 'X_UPDATE_RANGE' => '3-4', + function testPatchNotSupported() { - )); + $this->node->put('aaaaaaaa'); + $request = new HTTP\Request('PATCH', '/', ['X-Update-Range' => '3-4']); $request->setBody( - '111' + 'bbb' ); $response = $this->request($request); - $this->assertEquals('HTTP/1.1 405 Method Not Allowed', $response->status, 'Full response body:' . $response->body); + $this->assertEquals(405, $response->status, 'Full response body:' . $response->body); } - public function testPatchNoContentType() { + function testPatchNoContentType() { - $this->node->put('00000000'); - $request = new HTTP\Request(array( - 'REQUEST_METHOD' => 'PATCH', - 'REQUEST_URI' => '/partial', - 'HTTP_X_UPDATE_RANGE' => 'bytes=3-4', + $this->node->put('aaaaaaaa'); + $request = new HTTP\Request('PATCH', '/partial', ['X-Update-Range' => 'bytes=3-4']); + $request->setBody( + 'bbb' + ); + $response = $this->request($request); - )); + $this->assertEquals(415, $response->status, 'Full response body:' . $response->body); + + } + + function testPatchBadRange() { + + $this->node->put('aaaaaaaa'); + $request = new HTTP\Request('PATCH', '/partial', ['X-Update-Range' => 'bytes=3-4', 'Content-Type' => 'application/x-sabredav-partialupdate', 'Content-Length' => '3']); $request->setBody( - '111' + 'bbb' ); $response = $this->request($request); - $this->assertEquals('HTTP/1.1 415 Unsupported Media Type', $response->status, 'Full response body:' . $response->body); + $this->assertEquals(416, $response->status, 'Full response body:' . $response->body); } - public function testPatchBadRange() { + function testPatchNoLength() { - $this->node->put('00000000'); - $request = new HTTP\Request(array( - 'REQUEST_METHOD' => 'PATCH', - 'REQUEST_URI' => '/partial', - 'HTTP_X_UPDATE_RANGE' => 'bytes=3-4', - 'HTTP_CONTENT_TYPE' => 'application/x-sabredav-partialupdate', - )); + $this->node->put('aaaaaaaa'); + $request = new HTTP\Request('PATCH', '/partial', ['X-Update-Range' => 'bytes=3-5', 'Content-Type' => 'application/x-sabredav-partialupdate']); $request->setBody( - '111' + 'bbb' ); $response = $this->request($request); - $this->assertEquals('HTTP/1.1 411 Length Required', $response->status, 'Full response body:' . $response->body); + $this->assertEquals(411, $response->status, 'Full response body:' . $response->body); } - public function testPatchSuccess() { + function testPatchSuccess() { - $this->node->put('00000000'); - $request = new HTTP\Request(array( - 'REQUEST_METHOD' => 'PATCH', - 'REQUEST_URI' => '/partial', - 'HTTP_X_UPDATE_RANGE' => 'bytes=3-5', - 'HTTP_CONTENT_TYPE' => 'application/x-sabredav-partialupdate', - 'HTTP_CONTENT_LENGTH' => 3, - )); + $this->node->put('aaaaaaaa'); + $request = new HTTP\Request('PATCH', '/partial', ['X-Update-Range' => 'bytes=3-5', 'Content-Type' => 'application/x-sabredav-partialupdate', 'Content-Length' => 3]); $request->setBody( - '111' + 'bbb' ); $response = $this->request($request); - $this->assertEquals('HTTP/1.1 204 No Content', $response->status, 'Full response body:' . $response->body); - $this->assertEquals('00011100', $this->node->get()); + $this->assertEquals(204, $response->status, 'Full response body:' . $response->body); + $this->assertEquals('aaabbbaa', $this->node->get()); } - public function testPatchNoEndRange() { + function testPatchNoEndRange() { - $this->node->put('00000'); - $request = new HTTP\Request(array( - 'REQUEST_METHOD' => 'PATCH', - 'REQUEST_URI' => '/partial', - 'HTTP_X_UPDATE_RANGE' => 'bytes=3-', - 'HTTP_CONTENT_TYPE' => 'application/x-sabredav-partialupdate', - 'HTTP_CONTENT_LENGTH' => 3, - )); + $this->node->put('aaaaa'); + $request = new HTTP\Request('PATCH', '/partial', ['X-Update-Range' => 'bytes=3-', 'Content-Type' => 'application/x-sabredav-partialupdate', 'Content-Length' => '3']); $request->setBody( - '111' + 'bbb' ); + $response = $this->request($request); - $this->assertEquals('HTTP/1.1 204 No Content', $response->status, 'Full response body:' . $response->body); - $this->assertEquals('00111', $this->node->get()); + $this->assertEquals(204, $response->getStatus(), 'Full response body:' . $response->getBodyAsString()); + $this->assertEquals('aaabbb', $this->node->get()); } diff --git a/vendor/sabre/dav/tests/Sabre/DAV/PartialUpdate/SpecificationTest.php b/vendor/sabre/dav/tests/Sabre/DAV/PartialUpdate/SpecificationTest.php index 7abe69c55..31be2a1b1 100644 --- a/vendor/sabre/dav/tests/Sabre/DAV/PartialUpdate/SpecificationTest.php +++ b/vendor/sabre/dav/tests/Sabre/DAV/PartialUpdate/SpecificationTest.php @@ -42,21 +42,21 @@ class SpecificationTest extends \PHPUnit_Framework_TestCase { */ public function testUpdateRange($headerValue, $httpStatus, $endResult, $contentLength = 4) { - $vars = array( - 'REQUEST_METHOD' => 'PATCH', - 'HTTP_CONTENT_TYPE' => 'application/x-sabredav-partialupdate', - 'HTTP_X_UPDATE_RANGE' => $headerValue, - 'REQUEST_URI' => '/foobar.txt', - ); + $headers = [ + 'Content-Type' => 'application/x-sabredav-partialupdate', + 'X-Update-Range' => $headerValue, + ]; + if ($contentLength) { - $vars['HTTP_CONTENT_LENGTH'] = (string)$contentLength; + $headers['Content-Length'] = (string)$contentLength; } - $request = new HTTP\Request($vars); + $request = new HTTP\Request('PATCH', '/foobar.txt', $headers, '----'); $request->setBody('----'); $this->server->httpRequest = $request; $this->server->httpResponse = new HTTP\ResponseMock(); + $this->server->sapi = new HTTP\SapiMock(); $this->server->exec(); $this->assertEquals($httpStatus, $this->server->httpResponse->status, 'Incorrect http status received: ' . $this->server->httpResponse->body); @@ -70,17 +70,17 @@ class SpecificationTest extends \PHPUnit_Framework_TestCase { return array( // Problems - array('foo', 'HTTP/1.1 400 Bad request', null), - array('bytes=0-3', 'HTTP/1.1 411 Length Required', null, 0), - array('bytes=4-1', 'HTTP/1.1 416 Requested Range Not Satisfiable', null), - - array('bytes=0-3', 'HTTP/1.1 204 No Content', '----567890'), - array('bytes=1-4', 'HTTP/1.1 204 No Content', '1----67890'), - array('bytes=0-', 'HTTP/1.1 204 No Content', '----567890'), - array('bytes=-4', 'HTTP/1.1 204 No Content', '123456----'), - array('bytes=-2', 'HTTP/1.1 204 No Content', '12345678----'), - array('bytes=2-', 'HTTP/1.1 204 No Content', '12----7890'), - array('append', 'HTTP/1.1 204 No Content', '1234567890----'), + array('foo', 400, null), + array('bytes=0-3', 411, null, 0), + array('bytes=4-1', 416, null), + + array('bytes=0-3', 204, '----567890'), + array('bytes=1-4', 204, '1----67890'), + array('bytes=0-', 204, '----567890'), + array('bytes=-4', 204, '123456----'), + array('bytes=-2', 204, '12345678----'), + array('bytes=2-', 204, '12----7890'), + array('append', 204, '1234567890----'), ); diff --git a/vendor/sabre/dav/tests/Sabre/DAV/Property/GetLastModifiedTest.php b/vendor/sabre/dav/tests/Sabre/DAV/Property/GetLastModifiedTest.php deleted file mode 100644 index de8ca1283..000000000 --- a/vendor/sabre/dav/tests/Sabre/DAV/Property/GetLastModifiedTest.php +++ /dev/null @@ -1,75 +0,0 @@ -<?php - -namespace Sabre\DAV\Property; - -use Sabre\DAV; -use Sabre\HTTP; - -class GetLastModifiedTest extends \PHPUnit_Framework_TestCase { - - function testConstructDateTime() { - - $dt = new \DateTime('2010-03-14 16:35', new \DateTimeZone('UTC')); - $lastMod = new GetLastModified($dt); - $this->assertEquals($dt->format(\DateTime::ATOM), $lastMod->getTime()->format(\DateTime::ATOM)); - - } - - function testConstructString() { - - $dt = new \DateTime('2010-03-14 16:35', new \DateTimeZone('UTC')); - $lastMod = new GetLastModified('2010-03-14 16:35'); - $this->assertEquals($dt->format(\DateTime::ATOM), $lastMod->getTime()->format(\DateTime::ATOM)); - - } - - function testConstructInt() { - - $dt = new \DateTime('2010-03-14 16:35', new \DateTimeZone('UTC')); - $lastMod = new GetLastModified((int)$dt->format('U')); - $this->assertEquals($dt->format(\DateTime::ATOM), $lastMod->getTime()->format(\DateTime::ATOM)); - - } - - function testSerialize() { - - $dt = new \DateTime('2010-03-14 16:35', new \DateTimeZone('UTC')); - $lastMod = new GetLastModified($dt); - - $doc = new \DOMDocument(); - $root = $doc->createElement('d:getlastmodified'); - $root->setAttribute('xmlns:d','DAV:'); - - $doc->appendChild($root); - $server = new DAV\Server(); - - $lastMod->serialize($server, $root); - - $xml = $doc->saveXML(); - - /* - $this->assertEquals( -'<?xml version="1.0"?> -<d:getlastmodified xmlns:d="DAV:" xmlns:b="urn:uuid:c2f41010-65b3-11d1-a29f-00aa00c14882/" b:dt="dateTime.rfc1123">' . -HTTP\Util::toHTTPDate($dt) . -'</d:getlastmodified> -', $xml); - */ - $this->assertEquals( -'<?xml version="1.0"?> -<d:getlastmodified xmlns:d="DAV:">' . -HTTP\Util::toHTTPDate($dt) . -'</d:getlastmodified> -', $xml); - - $ok = false; - try { - GetLastModified::unserialize(DAV\XMLUtil::loadDOMDocument($xml)->firstChild); - } catch (DAV\Exception $e) { - $ok = true; - } - if (!$ok) $this->markTestFailed('Unserialize should not be supported'); - - } - -} diff --git a/vendor/sabre/dav/tests/Sabre/DAV/Property/HrefListTest.php b/vendor/sabre/dav/tests/Sabre/DAV/Property/HrefListTest.php deleted file mode 100644 index fe2bc81f9..000000000 --- a/vendor/sabre/dav/tests/Sabre/DAV/Property/HrefListTest.php +++ /dev/null @@ -1,91 +0,0 @@ -<?php - -namespace Sabre\DAV\Property; -use Sabre\DAV; - -class HrefListTest extends \PHPUnit_Framework_TestCase { - - function testConstruct() { - - $href = new HrefList(array('foo','bar')); - $this->assertEquals(array('foo','bar'),$href->getHrefs()); - - } - - function testSerialize() { - - $href = new HrefList(array('foo','bar')); - $this->assertEquals(array('foo','bar'),$href->getHrefs()); - - $doc = new \DOMDocument(); - $root = $doc->createElement('d:anything'); - $root->setAttribute('xmlns:d','DAV:'); - - $doc->appendChild($root); - $server = new DAV\Server(); - $server->setBaseUri('/bla/'); - - $href->serialize($server, $root); - - $xml = $doc->saveXML(); - - $this->assertEquals( -'<?xml version="1.0"?> -<d:anything xmlns:d="DAV:"><d:href>/bla/foo</d:href><d:href>/bla/bar</d:href></d:anything> -', $xml); - - } - - function testSerializeNoPrefix() { - - $href = new HrefList(array('foo','bar'), false); - $this->assertEquals(array('foo','bar'),$href->getHrefs()); - - $doc = new \DOMDocument(); - $root = $doc->createElement('d:anything'); - $root->setAttribute('xmlns:d','DAV:'); - - $doc->appendChild($root); - $server = new DAV\Server(); - $server->setBaseUri('/bla/'); - - $href->serialize($server, $root); - - $xml = $doc->saveXML(); - - $this->assertEquals( -'<?xml version="1.0"?> -<d:anything xmlns:d="DAV:"><d:href>foo</d:href><d:href>bar</d:href></d:anything> -', $xml); - - } - - function testUnserialize() { - - $xml = '<?xml version="1.0"?> -<d:anything xmlns:d="urn:DAV"><d:href>/bla/foo</d:href><d:href>/bla/bar</d:href></d:anything> -'; - - $dom = new \DOMDocument(); - $dom->loadXML($xml); - - $href = HrefList::unserialize($dom->firstChild); - $this->assertEquals(array('/bla/foo','/bla/bar'),$href->getHrefs()); - - } - - function testUnserializeIncompatible() { - - $xml = '<?xml version="1.0"?> -<d:anything xmlns:d="urn:DAV"><d:href2>/bla/foo</d:href2></d:anything> -'; - - $dom = new \DOMDocument(); - $dom->loadXML($xml); - - $href = HrefList::unserialize($dom->firstChild); - $this->assertEquals(array(), $href->getHrefs()); - - } - -} diff --git a/vendor/sabre/dav/tests/Sabre/DAV/Property/HrefTest.php b/vendor/sabre/dav/tests/Sabre/DAV/Property/HrefTest.php deleted file mode 100644 index e5607f51b..000000000 --- a/vendor/sabre/dav/tests/Sabre/DAV/Property/HrefTest.php +++ /dev/null @@ -1,119 +0,0 @@ -<?php - -namespace Sabre\DAV\Property; - -use Sabre\DAV; - -class HrefTest extends \PHPUnit_Framework_TestCase { - - function testConstruct() { - - $href = new Href('path'); - $this->assertEquals('path',$href->getHref()); - - } - - function testSerialize() { - - $href = new Href('path'); - $this->assertEquals('path',$href->getHref()); - - $doc = new \DOMDocument(); - $root = $doc->createElement('d:anything'); - $root->setAttribute('xmlns:d','DAV:'); - - $doc->appendChild($root); - $server = new DAV\Server(); - $server->setBaseUri('/bla/'); - - $href->serialize($server, $root); - - $xml = $doc->saveXML(); - - $this->assertEquals( -'<?xml version="1.0"?> -<d:anything xmlns:d="DAV:"><d:href>/bla/path</d:href></d:anything> -', $xml); - - } - - function testSerializeNoPrefix() { - - $href = new Href('path',false); - $this->assertEquals('path',$href->getHref()); - - $doc = new \DOMDocument(); - $root = $doc->createElement('d:anything'); - $root->setAttribute('xmlns:d','DAV:'); - - $doc->appendChild($root); - $server = new DAV\Server(); - $server->setBaseUri('/bla/'); - - $href->serialize($server, $root); - - $xml = $doc->saveXML(); - - $this->assertEquals( -'<?xml version="1.0"?> -<d:anything xmlns:d="DAV:"><d:href>path</d:href></d:anything> -', $xml); - - } - - function testUnserialize() { - - $xml = '<?xml version="1.0"?> -<d:anything xmlns:d="urn:DAV"><d:href>/bla/path</d:href></d:anything> -'; - - $dom = new \DOMDocument(); - $dom->loadXML($xml); - - $href = Href::unserialize($dom->firstChild); - $this->assertEquals('/bla/path',$href->getHref()); - - } - - function testUnserializeIncompatible() { - - $xml = '<?xml version="1.0"?> -<d:anything xmlns:d="urn:DAV"><d:href2>/bla/path</d:href2></d:anything> -'; - - $dom = new \DOMDocument(); - $dom->loadXML($xml); - - $href = Href::unserialize($dom->firstChild); - $this->assertNull($href); - - } - - /** - * This method tests if hrefs containing & are correctly encoded. - */ - function testSerializeEntity() { - - $href = new Href('http://example.org/?a&b', false); - $this->assertEquals('http://example.org/?a&b',$href->getHref()); - - $doc = new \DOMDocument(); - $root = $doc->createElement('d:anything'); - $root->setAttribute('xmlns:d','DAV:'); - - $doc->appendChild($root); - $server = new DAV\Server(); - $server->setBaseUri('/bla/'); - - $href->serialize($server, $root); - - $xml = $doc->saveXML(); - - $this->assertEquals( -'<?xml version="1.0"?> -<d:anything xmlns:d="DAV:"><d:href>http://example.org/?a&b</d:href></d:anything> -', $xml); - - } - -} diff --git a/vendor/sabre/dav/tests/Sabre/DAV/Property/ResourceTypeTest.php b/vendor/sabre/dav/tests/Sabre/DAV/Property/ResourceTypeTest.php deleted file mode 100644 index 8a579baec..000000000 --- a/vendor/sabre/dav/tests/Sabre/DAV/Property/ResourceTypeTest.php +++ /dev/null @@ -1,111 +0,0 @@ -<?php - -namespace Sabre\DAV\Property; - -use Sabre\DAV; - -class ResourceTypeTest extends \PHPUnit_Framework_TestCase { - - function testConstruct() { - - $resourceType = new ResourceType(array('{DAV:}collection')); - $this->assertEquals(array('{DAV:}collection'),$resourceType->getValue()); - - $resourceType = new ResourceType(DAV\Server::NODE_FILE); - $this->assertEquals(array(),$resourceType->getValue()); - - $resourceType = new ResourceType(DAV\Server::NODE_DIRECTORY); - $this->assertEquals(array('{DAV:}collection'),$resourceType->getValue()); - - $resourceType = new ResourceType('{DAV:}principal'); - $this->assertEquals(array('{DAV:}principal'),$resourceType->getValue()); - - } - - /** - * @depends testConstruct - */ - function testSerialize() { - - $resourceType = new ResourceType(array('{DAV:}collection','{DAV:}principal')); - - $doc = new \DOMDocument(); - $root = $doc->createElement('d:anything'); - $root->setAttribute('xmlns:d','DAV:'); - - $doc->appendChild($root); - $server = new DAV\Server(); - $resourceType->serialize($server, $root); - - $xml = $doc->saveXML(); - - $this->assertEquals( -'<?xml version="1.0"?> -<d:anything xmlns:d="DAV:"><d:collection/><d:principal/></d:anything> -', $xml); - - } - - /** - * @depends testSerialize - */ - function testSerializeCustomNS() { - - $resourceType = new ResourceType(array('{http://example.org/NS}article')); - - $doc = new \DOMDocument(); - $root = $doc->createElement('d:anything'); - $root->setAttribute('xmlns:d','DAV:'); - - $doc->appendChild($root); - $server = new DAV\Server(); - $resourceType->serialize($server, $root); - - $xml = $doc->saveXML(); - - $this->assertEquals( -'<?xml version="1.0"?> -<d:anything xmlns:d="DAV:"><custom:article xmlns:custom="http://example.org/NS"/></d:anything> -', $xml); - - } - - /** - * @depends testConstruct - */ - function testIs() { - - $resourceType = new ResourceType(array('{DAV:}collection','{DAV:}principal')); - $this->assertTrue($resourceType->is('{DAV:}collection')); - $this->assertFalse($resourceType->is('{DAV:}blabla')); - - } - - /** - * @depends testConstruct - */ - function testAdd() { - - $resourceType = new ResourceType(array('{DAV:}collection','{DAV:}principal')); - $resourceType->add('{DAV:}foo'); - $this->assertEquals(array('{DAV:}collection','{DAV:}principal','{DAV:}foo'), $resourceType->getValue()); - - } - - /** - * @depends testConstruct - */ - function testUnserialize() { - - $xml ='<?xml version="1.0"?> -<d:anything xmlns:d="DAV:"><d:collection/><d:principal/></d:anything> -'; - - $dom = DAV\XMLUtil::loadDOMDocument($xml); - - $resourceType = ResourceType::unserialize($dom->firstChild); - $this->assertEquals(array('{DAV:}collection','{DAV:}principal'),$resourceType->getValue()); - - } - -} diff --git a/vendor/sabre/dav/tests/Sabre/DAV/Property/ResponseListTest.php b/vendor/sabre/dav/tests/Sabre/DAV/Property/ResponseListTest.php deleted file mode 100644 index d13066b80..000000000 --- a/vendor/sabre/dav/tests/Sabre/DAV/Property/ResponseListTest.php +++ /dev/null @@ -1,19 +0,0 @@ -<?php - -namespace Sabre\DAV\Property; - -class ResponseListTest extends \PHPUnit_Framework_TestCase { - - /** - * This was the only part not yet covered by other tests, so I'm going to - * be lazy and (for now) only test this case. - * - * @expectedException InvalidArgumentException - */ - public function testInvalidArg() { - - $response = new ResponseList(array(1,2)); - - } - -} diff --git a/vendor/sabre/dav/tests/Sabre/DAV/Property/ResponseTest.php b/vendor/sabre/dav/tests/Sabre/DAV/Property/ResponseTest.php deleted file mode 100644 index 073cbb2ce..000000000 --- a/vendor/sabre/dav/tests/Sabre/DAV/Property/ResponseTest.php +++ /dev/null @@ -1,230 +0,0 @@ -<?php - -namespace Sabre\DAV\Property; - -use Sabre\DAV; - -class ResponseTest extends \PHPUnit_Framework_TestCase { - - function testSimple() { - - $innerProps = array( - 200 => array( - '{DAV:}displayname' => 'my file', - ), - 404 => array( - '{DAV:}owner' => null, - ) - ); - - $property = new Response('uri',$innerProps); - - $this->assertEquals('uri',$property->getHref()); - $this->assertEquals($innerProps,$property->getResponseProperties()); - - - } - - /** - * @depends testSimple - */ - function testSerialize() { - - $innerProps = array( - 200 => array( - '{DAV:}displayname' => 'my file', - ), - 404 => array( - '{DAV:}owner' => null, - ) - ); - - $property = new Response('uri',$innerProps); - - $doc = new \DOMDocument(); - $root = $doc->createElement('d:root'); - $root->setAttribute('xmlns:d','DAV:'); - - $doc->appendChild($root); - $server = new DAV\Server(); - - $property->serialize($server, $root); - - $xml = $doc->saveXML(); - - $this->assertEquals( -'<?xml version="1.0"?> -<d:root xmlns:d="DAV:">' . -'<d:response>' . -'<d:href>/uri</d:href>' . -'<d:propstat>' . -'<d:prop>' . -'<d:displayname>my file</d:displayname>' . -'</d:prop>' . -'<d:status>HTTP/1.1 200 OK</d:status>' . -'</d:propstat>' . -'<d:propstat>' . -'<d:prop>' . -'<d:owner/>' . -'</d:prop>' . -'<d:status>HTTP/1.1 404 Not Found</d:status>' . -'</d:propstat>' . -'</d:response>' . -'</d:root> -', $xml); - - } - - /** - * This one is specifically for testing properties with no namespaces, which is legal xml - * - * @depends testSerialize - */ - function testSerializeEmptyNamespace() { - - $innerProps = array( - 200 => array( - '{}propertyname' => 'value', - ), - ); - - $property = new Response('uri',$innerProps); - - $doc = new \DOMDocument(); - $root = $doc->createElement('d:root'); - $root->setAttribute('xmlns:d','DAV:'); - - $doc->appendChild($root); - $server = new DAV\Server(); - - $property->serialize($server, $root); - - $xml = $doc->saveXML(); - - $this->assertEquals( -'<?xml version="1.0"?> -<d:root xmlns:d="DAV:">' . -'<d:response>' . -'<d:href>/uri</d:href>' . -'<d:propstat>' . -'<d:prop>' . -'<propertyname xmlns="">value</propertyname>' . -'</d:prop>' . -'<d:status>HTTP/1.1 200 OK</d:status>' . -'</d:propstat>' . -'</d:response>' . -'</d:root> -', $xml); - - } - - /** - * This one is specifically for testing properties with no namespaces, which is legal xml - * - * @depends testSerialize - */ - function testSerializeCustomNamespace() { - - $innerProps = array( - 200 => array( - '{http://sabredav.org/NS/example}propertyname' => 'value', - ), - ); - - $property = new Response('uri',$innerProps); - - $doc = new \DOMDocument(); - $root = $doc->createElement('d:root'); - $root->setAttribute('xmlns:d','DAV:'); - - $doc->appendChild($root); - $server = new DAV\Server(); - - $property->serialize($server, $root); - - $xml = $doc->saveXML(); - - $this->assertEquals( -'<?xml version="1.0"?> -<d:root xmlns:d="DAV:">' . -'<d:response>' . -'<d:href>/uri</d:href>' . -'<d:propstat>' . -'<d:prop>' . -'<x2:propertyname xmlns:x2="http://sabredav.org/NS/example">value</x2:propertyname>' . -'</d:prop>' . -'<d:status>HTTP/1.1 200 OK</d:status>' . -'</d:propstat>' . -'</d:response>' . -'</d:root> -', $xml); - - } - - /** - * @depends testSerialize - */ - function testSerializeComplexProperty() { - - $innerProps = array( - 200 => array( - '{DAV:}link' => new Href('http://sabredav.org/', false) - ), - ); - - $property = new Response('uri',$innerProps); - - $doc = new \DOMDocument(); - $root = $doc->createElement('d:root'); - $root->setAttribute('xmlns:d','DAV:'); - - $doc->appendChild($root); - $server = new DAV\Server(); - - $property->serialize($server, $root); - - $xml = $doc->saveXML(); - - $this->assertEquals( -'<?xml version="1.0"?> -<d:root xmlns:d="DAV:">' . -'<d:response>' . -'<d:href>/uri</d:href>' . -'<d:propstat>' . -'<d:prop>' . -'<d:link><d:href>http://sabredav.org/</d:href></d:link>' . -'</d:prop>' . -'<d:status>HTTP/1.1 200 OK</d:status>' . -'</d:propstat>' . -'</d:response>' . -'</d:root> -', $xml); - - } - - /** - * @depends testSerialize - * @expectedException Sabre\DAV\Exception - */ - function testSerializeBreak() { - - $innerProps = array( - 200 => array( - '{DAV:}link' => new \STDClass() - ), - ); - - $property = new Response('uri',$innerProps); - - $doc = new \DOMDocument(); - $root = $doc->createElement('d:root'); - $root->setAttribute('xmlns:d','DAV:'); - - $doc->appendChild($root); - $server = new DAV\Server(); - - $property->serialize($server, $root); - - } - -} diff --git a/vendor/sabre/dav/tests/Sabre/DAV/Property/SupportedReportSetTest.php b/vendor/sabre/dav/tests/Sabre/DAV/Property/SupportedReportSetTest.php deleted file mode 100644 index 445e22ab3..000000000 --- a/vendor/sabre/dav/tests/Sabre/DAV/Property/SupportedReportSetTest.php +++ /dev/null @@ -1,128 +0,0 @@ -<?php - -namespace Sabre\DAV\Property; - -use Sabre\DAV; -use Sabre\HTTP; - -require_once 'Sabre/HTTP/ResponseMock.php'; -require_once 'Sabre/DAV/AbstractServer.php'; - -class SupportedReportSetTest extends DAV\AbstractServer { - - public function sendPROPFIND($body) { - - $serverVars = array( - 'REQUEST_URI' => '/', - 'REQUEST_METHOD' => 'PROPFIND', - 'HTTP_DEPTH' => '0', - ); - - $request = new HTTP\Request($serverVars); - $request->setBody($body); - - $this->server->httpRequest = ($request); - $this->server->exec(); - - } - - /** - * @covers Sabre\DAV\Property\SupportedReportSet - */ - function testNoReports() { - - $xml = '<?xml version="1.0"?> -<d:propfind xmlns:d="DAV:"> - <d:prop> - <d:supported-report-set /> - </d:prop> -</d:propfind>'; - - $this->sendPROPFIND($xml); - - $this->assertEquals('HTTP/1.1 207 Multi-Status',$this->response->status,'We expected a multi-status response. Full response body: ' . $this->response->body); - - $body = preg_replace("/xmlns(:[A-Za-z0-9_])?=(\"|\')DAV:(\"|\')/","xmlns\\1=\"urn:DAV\"",$this->response->body); - $xml = simplexml_load_string($body); - $xml->registerXPathNamespace('d','urn:DAV'); - - $data = $xml->xpath('/d:multistatus/d:response/d:propstat/d:prop'); - $this->assertEquals(1,count($data),'We expected 1 \'d:prop\' element'); - - $data = $xml->xpath('/d:multistatus/d:response/d:propstat/d:prop/d:supported-report-set'); - $this->assertEquals(1,count($data),'We expected 1 \'d:supported-report-set\' element'); - - $data = $xml->xpath('/d:multistatus/d:response/d:propstat/d:status'); - $this->assertEquals(1,count($data),'We expected 1 \'d:status\' element'); - - $this->assertEquals('HTTP/1.1 200 OK',(string)$data[0],'The status for this property should have been 200'); - - } - - /** - * @covers Sabre\DAV\Property\SupportedReportSet - * @depends testNoReports - */ - function testCustomReport() { - - // Intercepting the report property - $this->server->subscribeEvent('afterGetProperties',array($this,'addProp')); - - $xml = '<?xml version="1.0"?> -<d:propfind xmlns:d="DAV:"> - <d:prop> - <d:supported-report-set /> - </d:prop> -</d:propfind>'; - - $this->sendPROPFIND($xml); - - $this->assertEquals('HTTP/1.1 207 Multi-Status',$this->response->status,'We expected a multi-status response. Full response body: ' . $this->response->body); - - $body = preg_replace("/xmlns(:[A-Za-z0-9_])?=(\"|\')DAV:(\"|\')/","xmlns\\1=\"urn:DAV\"",$this->response->body); - $xml = simplexml_load_string($body); - $xml->registerXPathNamespace('d','urn:DAV'); - $xml->registerXPathNamespace('x','http://www.rooftopsolutions.nl/testnamespace'); - - $data = $xml->xpath('/d:multistatus/d:response/d:propstat/d:prop'); - $this->assertEquals(1,count($data),'We expected 1 \'d:prop\' element'); - - $data = $xml->xpath('/d:multistatus/d:response/d:propstat/d:prop/d:supported-report-set'); - $this->assertEquals(1,count($data),'We expected 1 \'d:supported-report-set\' element'); - - $data = $xml->xpath('/d:multistatus/d:response/d:propstat/d:prop/d:supported-report-set/d:supported-report'); - $this->assertEquals(2,count($data),'We expected 2 \'d:supported-report\' elements'); - - $data = $xml->xpath('/d:multistatus/d:response/d:propstat/d:prop/d:supported-report-set/d:supported-report/d:report'); - $this->assertEquals(2,count($data),'We expected 2 \'d:report\' elements'); - - $data = $xml->xpath('/d:multistatus/d:response/d:propstat/d:prop/d:supported-report-set/d:supported-report/d:report/x:myreport'); - $this->assertEquals(1,count($data),'We expected 1 \'x:myreport\' element. Full body: ' . $this->response->body); - - $data = $xml->xpath('/d:multistatus/d:response/d:propstat/d:prop/d:supported-report-set/d:supported-report/d:report/d:anotherreport'); - $this->assertEquals(1,count($data),'We expected 1 \'d:anotherreport\' element. Full body: ' . $this->response->body); - - $data = $xml->xpath('/d:multistatus/d:response/d:propstat/d:status'); - $this->assertEquals(1,count($data),'We expected 1 \'d:status\' element'); - - $this->assertEquals('HTTP/1.1 200 OK',(string)$data[0],'The status for this property should have been 200'); - - } - - /** - * This method is used as a callback for afterGetProperties - */ - function addProp($path, &$properties) { - - if (isset($properties[200]['{DAV:}supported-report-set'])) { - $properties[200]['{DAV:}supported-report-set']->addReport('{http://www.rooftopsolutions.nl/testnamespace}myreport'); - $properties[200]['{DAV:}supported-report-set']->addReport('{DAV:}anotherreport'); - } - - } - - - -} - -?> diff --git a/vendor/sabre/dav/tests/Sabre/DAV/ServerCopyMoveTest.php b/vendor/sabre/dav/tests/Sabre/DAV/ServerCopyMoveTest.php deleted file mode 100644 index 88e107c19..000000000 --- a/vendor/sabre/dav/tests/Sabre/DAV/ServerCopyMoveTest.php +++ /dev/null @@ -1,268 +0,0 @@ -<?php - -namespace Sabre\DAV; - -use Sabre\HTTP; - -require_once 'Sabre/HTTP/ResponseMock.php'; - -class ServerCopyMoveTest extends \PHPUnit_Framework_TestCase { - - private $response; - /** - * @var Server - */ - private $server; - - function setUp() { - - $this->response = new HTTP\ResponseMock(); - $dir = new FS\Directory(SABRE_TEMPDIR); - $tree = new ObjectTree($dir); - $this->server = new Server($tree); - $this->server->debugExceptions = true; - $this->server->httpResponse = $this->response; - file_put_contents(SABRE_TEMPDIR . '/test.txt', 'Test contents'); - file_put_contents(SABRE_TEMPDIR . '/test2.txt', 'Test contents2'); - mkdir(SABRE_TEMPDIR . '/col'); - file_put_contents(SABRE_TEMPDIR . 'col/test.txt', 'Test contents'); - - } - - function tearDown() { - - $cleanUp = array('test.txt','testput.txt','testcol','test2.txt','test3.txt','col/test.txt','col','col2/test.txt','col2'); - foreach($cleanUp as $file) { - $tmpFile = SABRE_TEMPDIR . '/' . $file; - if (file_exists($tmpFile)) { - - if (is_dir($tmpFile)) { - rmdir($tmpFile); - } else { - unlink($tmpFile); - } - - } - } - - } - - - function testCopyOverWrite() { - - $serverVars = array( - 'REQUEST_URI' => '/test.txt', - 'REQUEST_METHOD' => 'COPY', - 'HTTP_DESTINATION' => '/test2.txt', - ); - - $request = new HTTP\Request($serverVars); - $this->server->httpRequest = ($request); - $this->server->exec(); - - $this->assertEquals('HTTP/1.1 204 No Content',$this->response->status,'Received an incorrect HTTP status. Full body inspection: ' . $this->response->body); - $this->assertEquals(array( - 'Content-Length' => '0', - ), - $this->response->headers - ); - - $this->assertEquals('Test contents',file_get_contents(SABRE_TEMPDIR. '/test2.txt')); - - } - - function testCopyToSelf() { - - $serverVars = array( - 'REQUEST_URI' => '/test.txt', - 'REQUEST_METHOD' => 'COPY', - 'HTTP_DESTINATION' => '/test.txt', - ); - - $request = new HTTP\Request($serverVars); - $this->server->httpRequest = ($request); - $this->server->exec(); - - $this->assertEquals('HTTP/1.1 403 Forbidden',$this->response->status,'Received an incorrect HTTP status. Full body inspection: ' . $this->response->body); - $this->assertEquals('Test contents',file_get_contents(SABRE_TEMPDIR. '/test.txt')); - - } - - function testMoveToSelf() { - - $serverVars = array( - 'REQUEST_URI' => '/test.txt', - 'REQUEST_METHOD' => 'MOVE', - 'HTTP_DESTINATION' => '/test.txt', - ); - - $request = new HTTP\Request($serverVars); - $this->server->httpRequest = ($request); - $this->server->exec(); - - $this->assertEquals('HTTP/1.1 403 Forbidden',$this->response->status,'Received an incorrect HTTP status. Full body inspection: ' . $this->response->body); - $this->assertEquals('Test contents',file_get_contents(SABRE_TEMPDIR. '/test.txt')); - - } - - function testMoveOverWrite() { - - $serverVars = array( - 'REQUEST_URI' => '/test.txt', - 'REQUEST_METHOD' => 'MOVE', - 'HTTP_DESTINATION' => '/test2.txt', - ); - - $request = new HTTP\Request($serverVars); - $this->server->httpRequest = ($request); - $this->server->exec(); - - $this->assertEquals(array( - 'Content-Length' => 0, - ), - $this->response->headers - ); - - $this->assertEquals('HTTP/1.1 204 No Content',$this->response->status); - $this->assertEquals('Test contents',file_get_contents(SABRE_TEMPDIR . '/test2.txt')); - $this->assertFalse(file_exists(SABRE_TEMPDIR . '/test.txt'),'The sourcefile test.txt should no longer exist at this point'); - - } - - function testBlockedOverWrite() { - - $serverVars = array( - 'REQUEST_URI' => '/test.txt', - 'REQUEST_METHOD' => 'COPY', - 'HTTP_DESTINATION' => '/test2.txt', - 'HTTP_OVERWRITE' => 'F', - ); - - $request = new HTTP\Request($serverVars); - $this->server->httpRequest = ($request); - $this->server->exec(); - - $this->assertEquals(array( - 'Content-Type' => 'application/xml; charset=utf-8', - ), - $this->response->headers - ); - - $this->assertEquals('HTTP/1.1 412 Precondition failed',$this->response->status); - $this->assertEquals('Test contents2',file_get_contents(SABRE_TEMPDIR . '/test2.txt')); - - - } - - function testNonExistantParent() { - - $serverVars = array( - 'REQUEST_URI' => '/test.txt', - 'REQUEST_METHOD' => 'COPY', - 'HTTP_DESTINATION' => '/testcol2/test2.txt', - 'HTTP_OVERWRITE' => 'F', - ); - - $request = new HTTP\Request($serverVars); - $this->server->httpRequest = ($request); - $this->server->exec(); - - $this->assertEquals(array( - 'Content-Type' => 'application/xml; charset=utf-8', - ), - $this->response->headers - ); - - $this->assertEquals('HTTP/1.1 409 Conflict',$this->response->status); - - } - - function testRandomOverwriteHeader() { - - $serverVars = array( - 'REQUEST_URI' => '/test.txt', - 'REQUEST_METHOD' => 'COPY', - 'HTTP_DESTINATION' => '/testcol2/test2.txt', - 'HTTP_OVERWRITE' => 'SURE!', - ); - - $request = new HTTP\Request($serverVars); - $this->server->httpRequest = ($request); - $this->server->exec(); - - $this->assertEquals('HTTP/1.1 400 Bad request',$this->response->status); - - } - - function testCopyDirectory() { - - $serverVars = array( - 'REQUEST_URI' => '/col', - 'REQUEST_METHOD' => 'COPY', - 'HTTP_DESTINATION' => '/col2', - ); - - $request = new HTTP\Request($serverVars); - $this->server->httpRequest = ($request); - $this->server->exec(); - - $this->assertEquals(array( - 'Content-Length' => '0', - ), - $this->response->headers - ); - - $this->assertEquals('HTTP/1.1 201 Created',$this->response->status); - $this->assertEquals('Test contents',file_get_contents(SABRE_TEMPDIR . '/col2/test.txt')); - - } - - function testSimpleCopyFile() { - - $serverVars = array( - 'REQUEST_URI' => '/test.txt', - 'REQUEST_METHOD' => 'COPY', - 'HTTP_DESTINATION' => '/test3.txt', - ); - - $request = new HTTP\Request($serverVars); - $this->server->httpRequest = ($request); - $this->server->exec(); - - $this->assertEquals(array( - 'Content-Length' => '0', - ), - $this->response->headers - ); - - $this->assertEquals('HTTP/1.1 201 Created',$this->response->status); - $this->assertEquals('Test contents',file_get_contents(SABRE_TEMPDIR . '/test3.txt')); - - } - - function testSimpleCopyCollection() { - - $serverVars = array( - 'REQUEST_URI' => '/col', - 'REQUEST_METHOD' => 'COPY', - 'HTTP_DESTINATION' => '/col2', - ); - - $request = new HTTP\Request($serverVars); - $this->server->httpRequest = ($request); - $this->server->exec(); - - $this->assertEquals('HTTP/1.1 201 Created',$this->response->status,'Incorrect status received. Full response body: ' . $this->response->body); - - $this->assertEquals(array( - 'Content-Length' => '0', - ), - $this->response->headers - ); - - - $this->assertEquals('Test contents',file_get_contents(SABRE_TEMPDIR . '/col2/test.txt')); - - } - -} diff --git a/vendor/sabre/dav/tests/Sabre/DAV/ServerEventsTest.php b/vendor/sabre/dav/tests/Sabre/DAV/ServerEventsTest.php index 2c7a074df..6ac20d2da 100644 --- a/vendor/sabre/dav/tests/Sabre/DAV/ServerEventsTest.php +++ b/vendor/sabre/dav/tests/Sabre/DAV/ServerEventsTest.php @@ -1,6 +1,7 @@ <?php namespace Sabre\DAV; + use Sabre\HTTP; require_once 'Sabre/DAV/AbstractServer.php'; @@ -13,11 +14,11 @@ class ServerEventsTest extends AbstractServer { function testAfterBind() { - $this->server->subscribeEvent('afterBind',array($this,'afterBindHandler')); + $this->server->on('afterBind', [$this, 'afterBindHandler']); $newPath = 'afterBind'; $this->tempPath = ''; - $this->server->createFile($newPath,'body'); + $this->server->createFile($newPath, 'body'); $this->assertEquals($newPath, $this->tempPath); } @@ -28,25 +29,41 @@ class ServerEventsTest extends AbstractServer { } + function testAfterResponse() { + + $mock = $this->getMock('stdClass', ['afterResponseCallback']); + $mock->expects($this->once())->method('afterResponseCallback'); + + $this->server->on('afterResponse', [$mock, 'afterResponseCallback']); + + $this->server->httpRequest = HTTP\Sapi::createFromServerArray([ + 'REQUEST_METHOD' => 'GET', + 'REQUEST_URI' => '/test.txt', + ]); + + $this->server->exec(); + + } + function testBeforeBindCancel() { - $this->server->subscribeEvent('beforeBind', array($this,'beforeBindCancelHandler')); - $this->assertFalse($this->server->createFile('bla','body')); + $this->server->on('beforeBind', [$this, 'beforeBindCancelHandler']); + $this->assertFalse($this->server->createFile('bla', 'body')); // Also testing put() - $req = new HTTP\Request(array( + $req = HTTP\Sapi::createFromServerArray([ 'REQUEST_METHOD' => 'PUT', - 'REQUEST_URI' => '/barbar', - )); + 'REQUEST_URI' => '/barbar', + ]); $this->server->httpRequest = $req; $this->server->exec(); - $this->assertEquals('',$this->server->httpResponse->status); + $this->assertEquals(500, $this->server->httpResponse->getStatus()); } - function beforeBindCancelHandler() { + function beforeBindCancelHandler($path) { return false; @@ -54,12 +71,12 @@ class ServerEventsTest extends AbstractServer { function testException() { - $this->server->subscribeEvent('exception', array($this, 'exceptionHandler')); + $this->server->on('exception', [$this, 'exceptionHandler']); - $req = new HTTP\Request(array( + $req = HTTP\Sapi::createFromServerArray([ 'REQUEST_METHOD' => 'GET', - 'REQUEST_URI' => '/not/exisitng', - )); + 'REQUEST_URI' => '/not/exisitng', + ]); $this->server->httpRequest = $req; $this->server->exec(); @@ -73,4 +90,35 @@ class ServerEventsTest extends AbstractServer { } + function testMethod() { + + $k = 1; + $this->server->on('method', function($request, $response) use (&$k) { + + $k += 1; + + return false; + + }); + $this->server->on('method', function($request, $response) use (&$k) { + + $k += 2; + + return false; + + }); + + try { + $this->server->invokeMethod( + new HTTP\Request('BLABLA', '/'), + new HTTP\Response(), + false + ); + } catch (Exception $e) {} + + $this->assertEquals(2, $k); + + + } + } diff --git a/vendor/sabre/dav/tests/Sabre/DAV/ServerMKCOLTest.php b/vendor/sabre/dav/tests/Sabre/DAV/ServerMKCOLTest.php index 34b084dcd..e35189ec3 100644 --- a/vendor/sabre/dav/tests/Sabre/DAV/ServerMKCOLTest.php +++ b/vendor/sabre/dav/tests/Sabre/DAV/ServerMKCOLTest.php @@ -4,10 +4,6 @@ namespace Sabre\DAV; use Sabre\HTTP; -require_once 'Sabre/HTTP/ResponseMock.php'; -require_once 'Sabre/DAV/AbstractServer.php'; -require_once 'Sabre/DAV/Exception.php'; - class ServerMKCOLTest extends AbstractServer { function testMkcol() { @@ -17,16 +13,17 @@ class ServerMKCOLTest extends AbstractServer { 'REQUEST_METHOD' => 'MKCOL', ); - $request = new HTTP\Request($serverVars); + $request = HTTP\Sapi::createFromServerArray($serverVars); $request->setBody(""); $this->server->httpRequest = ($request); $this->server->exec(); $this->assertEquals(array( - 'Content-Length' => '0', - ),$this->response->headers); + 'X-Sabre-Version' => [Version::VERSION], + 'Content-Length' => ['0'], + ),$this->response->getHeaders()); - $this->assertEquals('HTTP/1.1 201 Created',$this->response->status); + $this->assertEquals(201, $this->response->status); $this->assertEquals('', $this->response->body); $this->assertTrue(is_dir($this->tempDir . '/testcol')); @@ -42,16 +39,17 @@ class ServerMKCOLTest extends AbstractServer { 'REQUEST_METHOD' => 'MKCOL', ); - $request = new HTTP\Request($serverVars); + $request = HTTP\Sapi::createFromServerArray($serverVars); $request->setBody("Hello"); $this->server->httpRequest = ($request); $this->server->exec(); $this->assertEquals(array( - 'Content-Type' => 'application/xml; charset=utf-8', - ),$this->response->headers); + 'X-Sabre-Version' => [Version::VERSION], + 'Content-Type' => ['application/xml; charset=utf-8'], + ),$this->response->getHeaders()); - $this->assertEquals('HTTP/1.1 415 Unsupported Media Type',$this->response->status); + $this->assertEquals(415, $this->response->status); } @@ -66,16 +64,17 @@ class ServerMKCOLTest extends AbstractServer { 'HTTP_CONTENT_TYPE' => 'application/xml', ); - $request = new HTTP\Request($serverVars); + $request = HTTP\Sapi::createFromServerArray($serverVars); $request->setBody("Hello"); $this->server->httpRequest = ($request); $this->server->exec(); $this->assertEquals(array( - 'Content-Type' => 'application/xml; charset=utf-8', - ),$this->response->headers); + 'X-Sabre-Version' => [Version::VERSION], + 'Content-Type' => ['application/xml; charset=utf-8'], + ),$this->response->getHeaders()); - $this->assertEquals('HTTP/1.1 400 Bad request',$this->response->status); + $this->assertEquals(400, $this->response->getStatus(), $this->response->getBodyAsString() ); } @@ -90,16 +89,17 @@ class ServerMKCOLTest extends AbstractServer { 'HTTP_CONTENT_TYPE' => 'application/xml', ); - $request = new HTTP\Request($serverVars); + $request = HTTP\Sapi::createFromServerArray($serverVars); $request->setBody('<?xml version="1.0"?><html></html>'); $this->server->httpRequest = ($request); $this->server->exec(); $this->assertEquals(array( - 'Content-Type' => 'application/xml; charset=utf-8', - ),$this->response->headers); + 'X-Sabre-Version' => [Version::VERSION], + 'Content-Type' => ['application/xml; charset=utf-8'], + ),$this->response->getHeaders()); - $this->assertEquals('HTTP/1.1 415 Unsupported Media Type',$this->response->status); + $this->assertEquals(400, $this->response->getStatus()); } @@ -114,7 +114,7 @@ class ServerMKCOLTest extends AbstractServer { 'HTTP_CONTENT_TYPE' => 'application/xml', ); - $request = new HTTP\Request($serverVars); + $request = HTTP\Sapi::createFromServerArray($serverVars); $request->setBody('<?xml version="1.0"?> <mkcol xmlns="DAV:"> <set> @@ -127,15 +127,16 @@ class ServerMKCOLTest extends AbstractServer { $this->server->exec(); $this->assertEquals(array( - 'Content-Type' => 'application/xml; charset=utf-8', - ),$this->response->headers); + 'X-Sabre-Version' => [Version::VERSION], + 'Content-Type' => ['application/xml; charset=utf-8'], + ),$this->response->getHeaders()); - $this->assertEquals('HTTP/1.1 400 Bad request',$this->response->status,'Wrong statuscode received. Full response body: ' .$this->response->body); + $this->assertEquals(400, $this->response->status, 'Wrong statuscode received. Full response body: ' .$this->response->body); } /** - * @depends testMKCOLNoResourceType + * @depends testMkcol */ function testMKCOLIncorrectResourceType() { @@ -145,38 +146,7 @@ class ServerMKCOLTest extends AbstractServer { 'HTTP_CONTENT_TYPE' => 'application/xml', ); - $request = new HTTP\Request($serverVars); - $request->setBody('<?xml version="1.0"?> -<mkcol xmlns="DAV:"> - <set> - <prop> - <resourcetype><blabla /></resourcetype> - </prop> - </set> -</mkcol>'); - $this->server->httpRequest = ($request); - $this->server->exec(); - - $this->assertEquals(array( - 'Content-Type' => 'application/xml; charset=utf-8', - ),$this->response->headers); - - $this->assertEquals('HTTP/1.1 403 Forbidden',$this->response->status,'Wrong statuscode received. Full response body: ' .$this->response->body); - - } - - /** - * @depends testMKCOLIncorrectResourceType - */ - function testMKCOLIncorrectResourceType2() { - - $serverVars = array( - 'REQUEST_URI' => '/testcol', - 'REQUEST_METHOD' => 'MKCOL', - 'HTTP_CONTENT_TYPE' => 'application/xml', - ); - - $request = new HTTP\Request($serverVars); + $request = HTTP\Sapi::createFromServerArray($serverVars); $request->setBody('<?xml version="1.0"?> <mkcol xmlns="DAV:"> <set> @@ -189,15 +159,16 @@ class ServerMKCOLTest extends AbstractServer { $this->server->exec(); $this->assertEquals(array( - 'Content-Type' => 'application/xml; charset=utf-8', - ),$this->response->headers); + 'X-Sabre-Version' => [Version::VERSION], + 'Content-Type' => ['application/xml; charset=utf-8'], + ),$this->response->getHeaders()); - $this->assertEquals('HTTP/1.1 403 Forbidden',$this->response->status,'Wrong statuscode received. Full response body: ' .$this->response->body); + $this->assertEquals(403, $this->response->status, 'Wrong statuscode received. Full response body: ' .$this->response->body); } /** - * @depends testMKCOLIncorrectResourceType2 + * @depends testMKCOLIncorrectResourceType */ function testMKCOLSuccess() { @@ -207,7 +178,7 @@ class ServerMKCOLTest extends AbstractServer { 'HTTP_CONTENT_TYPE' => 'application/xml', ); - $request = new HTTP\Request($serverVars); + $request = HTTP\Sapi::createFromServerArray($serverVars); $request->setBody('<?xml version="1.0"?> <mkcol xmlns="DAV:"> <set> @@ -220,15 +191,16 @@ class ServerMKCOLTest extends AbstractServer { $this->server->exec(); $this->assertEquals(array( - 'Content-Length' => '0', - ),$this->response->headers); + 'X-Sabre-Version' => [Version::VERSION], + 'Content-Length' => ['0'], + ),$this->response->getHeaders()); - $this->assertEquals('HTTP/1.1 201 Created',$this->response->status,'Wrong statuscode received. Full response body: ' .$this->response->body); + $this->assertEquals(201, $this->response->status, 'Wrong statuscode received. Full response body: ' .$this->response->body); } /** - * @depends testMKCOLIncorrectResourceType2 + * @depends testMKCOLIncorrectResourceType */ function testMKCOLWhiteSpaceResourceType() { @@ -238,7 +210,7 @@ class ServerMKCOLTest extends AbstractServer { 'HTTP_CONTENT_TYPE' => 'application/xml', ); - $request = new HTTP\Request($serverVars); + $request = HTTP\Sapi::createFromServerArray($serverVars); $request->setBody('<?xml version="1.0"?> <mkcol xmlns="DAV:"> <set> @@ -253,15 +225,16 @@ class ServerMKCOLTest extends AbstractServer { $this->server->exec(); $this->assertEquals(array( - 'Content-Length' => '0', - ),$this->response->headers); + 'X-Sabre-Version' => [Version::VERSION], + 'Content-Length' => ['0'], + ),$this->response->getHeaders()); - $this->assertEquals('HTTP/1.1 201 Created',$this->response->status,'Wrong statuscode received. Full response body: ' .$this->response->body); + $this->assertEquals(201, $this->response->status, 'Wrong statuscode received. Full response body: ' .$this->response->body); } /** - * @depends testMKCOLIncorrectResourceType2 + * @depends testMKCOLIncorrectResourceType */ function testMKCOLNoParent() { @@ -270,22 +243,23 @@ class ServerMKCOLTest extends AbstractServer { 'REQUEST_METHOD' => 'MKCOL', ); - $request = new HTTP\Request($serverVars); + $request = HTTP\Sapi::createFromServerArray($serverVars); $request->setBody(''); $this->server->httpRequest = ($request); $this->server->exec(); $this->assertEquals(array( - 'Content-Type' => 'application/xml; charset=utf-8', - ),$this->response->headers); + 'X-Sabre-Version' => [Version::VERSION], + 'Content-Type' => ['application/xml; charset=utf-8'], + ),$this->response->getHeaders()); - $this->assertEquals('HTTP/1.1 409 Conflict',$this->response->status,'Wrong statuscode received. Full response body: ' .$this->response->body); + $this->assertEquals(409, $this->response->status, 'Wrong statuscode received. Full response body: ' .$this->response->body); } /** - * @depends testMKCOLIncorrectResourceType2 + * @depends testMKCOLIncorrectResourceType */ function testMKCOLParentIsNoCollection() { @@ -294,22 +268,23 @@ class ServerMKCOLTest extends AbstractServer { 'REQUEST_METHOD' => 'MKCOL', ); - $request = new HTTP\Request($serverVars); + $request = HTTP\Sapi::createFromServerArray($serverVars); $request->setBody(''); $this->server->httpRequest = ($request); $this->server->exec(); $this->assertEquals(array( - 'Content-Type' => 'application/xml; charset=utf-8', - ),$this->response->headers); + 'X-Sabre-Version' => [Version::VERSION], + 'Content-Type' => ['application/xml; charset=utf-8'], + ),$this->response->getHeaders()); - $this->assertEquals('HTTP/1.1 409 Conflict',$this->response->status,'Wrong statuscode received. Full response body: ' .$this->response->body); + $this->assertEquals(409, $this->response->status, 'Wrong statuscode received. Full response body: ' .$this->response->body); } /** - * @depends testMKCOLIncorrectResourceType2 + * @depends testMKCOLIncorrectResourceType */ function testMKCOLAlreadyExists() { @@ -318,18 +293,19 @@ class ServerMKCOLTest extends AbstractServer { 'REQUEST_METHOD' => 'MKCOL', ); - $request = new HTTP\Request($serverVars); + $request = HTTP\Sapi::createFromServerArray($serverVars); $request->setBody(''); $this->server->httpRequest = ($request); $this->server->exec(); $this->assertEquals(array( - 'Content-Type' => 'application/xml; charset=utf-8', - 'Allow' => 'OPTIONS, GET, HEAD, DELETE, PROPFIND, PUT, PROPPATCH, COPY, MOVE, REPORT', - ),$this->response->headers); + 'X-Sabre-Version' => [Version::VERSION], + 'Content-Type' => ['application/xml; charset=utf-8'], + 'Allow' => ['OPTIONS, GET, HEAD, DELETE, PROPFIND, PUT, PROPPATCH, COPY, MOVE, REPORT'], + ),$this->response->getHeaders()); - $this->assertEquals('HTTP/1.1 405 Method Not Allowed',$this->response->status,'Wrong statuscode received. Full response body: ' .$this->response->body); + $this->assertEquals(405, $this->response->status, 'Wrong statuscode received. Full response body: ' .$this->response->body); } @@ -345,7 +321,7 @@ class ServerMKCOLTest extends AbstractServer { 'HTTP_CONTENT_TYPE' => 'application/xml', ); - $request = new HTTP\Request($serverVars); + $request = HTTP\Sapi::createFromServerArray($serverVars); $request->setBody('<?xml version="1.0"?> <mkcol xmlns="DAV:"> <set> @@ -358,13 +334,12 @@ class ServerMKCOLTest extends AbstractServer { $this->server->httpRequest = ($request); $this->server->exec(); - $this->assertEquals('HTTP/1.1 207 Multi-Status',$this->response->status,'Wrong statuscode received. Full response body: ' .$this->response->body); + $this->assertEquals(207, $this->response->status, 'Wrong statuscode received. Full response body: ' .$this->response->body); $this->assertEquals(array( - 'Content-Type' => 'application/xml; charset=utf-8', - ),$this->response->headers); - - + 'X-Sabre-Version' => [Version::VERSION], + 'Content-Type' => ['application/xml; charset=utf-8'], + ),$this->response->getHeaders()); } diff --git a/vendor/sabre/dav/tests/Sabre/DAV/ServerPluginTest.php b/vendor/sabre/dav/tests/Sabre/DAV/ServerPluginTest.php index 8f1451b49..ab0ad295e 100644 --- a/vendor/sabre/dav/tests/Sabre/DAV/ServerPluginTest.php +++ b/vendor/sabre/dav/tests/Sabre/DAV/ServerPluginTest.php @@ -24,13 +24,19 @@ class ServerPluginTest extends AbstractServer { } /** - * @covers \Sabre\DAV\ServerPlugin */ function testBaseClass() { $p = new ServerPluginMock(); - $this->assertEquals(array(),$p->getFeatures()); - $this->assertEquals(array(),$p->getHTTPMethods('')); + $this->assertEquals([],$p->getFeatures()); + $this->assertEquals([],$p->getHTTPMethods('')); + $this->assertEquals( + [ + 'name' => 'Sabre\DAV\ServerPluginMock', + 'description' => null, + 'link' => null + ], $p->getPluginInfo() + ); } @@ -41,20 +47,20 @@ class ServerPluginTest extends AbstractServer { 'REQUEST_METHOD' => 'OPTIONS', ); - $request = new HTTP\Request($serverVars); + $request = HTTP\Sapi::createFromServerArray($serverVars); $this->server->httpRequest = ($request); $this->server->exec(); $this->assertEquals(array( - 'DAV' => '1, 3, extended-mkcol, drinking', - 'MS-Author-Via' => 'DAV', - 'Allow' => 'OPTIONS, GET, HEAD, DELETE, PROPFIND, PUT, PROPPATCH, COPY, MOVE, REPORT, BEER, WINE', - 'Accept-Ranges' => 'bytes', - 'Content-Length' => '0', - 'X-Sabre-Version' => Version::VERSION, - ),$this->response->headers); - - $this->assertEquals('HTTP/1.1 200 OK',$this->response->status); + 'DAV' => ['1, 3, extended-mkcol, drinking'], + 'MS-Author-Via' => ['DAV'], + 'Allow' => ['OPTIONS, GET, HEAD, DELETE, PROPFIND, PUT, PROPPATCH, COPY, MOVE, REPORT, BEER, WINE'], + 'Accept-Ranges' => ['bytes'], + 'Content-Length' => ['0'], + 'X-Sabre-Version' => [Version::VERSION], + ),$this->response->getHeaders()); + + $this->assertEquals(200, $this->response->status); $this->assertEquals('', $this->response->body); $this->assertEquals('OPTIONS',$this->testPlugin->beforeMethod); @@ -82,7 +88,10 @@ class ServerPluginTest extends AbstractServer { function testGetPlugins() { $this->assertEquals( - array(get_class($this->testPlugin) => $this->testPlugin), + array( + get_class($this->testPlugin) => $this->testPlugin, + 'core' => $this->server->getPlugin('core'), + ), $this->server->getPlugins() ); diff --git a/vendor/sabre/dav/tests/Sabre/DAV/ServerPreconditionTest.php b/vendor/sabre/dav/tests/Sabre/DAV/ServerPreconditionTest.php index ea09852a7..1dc8d8a37 100644 --- a/vendor/sabre/dav/tests/Sabre/DAV/ServerPreconditionTest.php +++ b/vendor/sabre/dav/tests/Sabre/DAV/ServerPreconditionTest.php @@ -9,362 +9,311 @@ require_once 'Sabre/HTTP/ResponseMock.php'; class ServerPreconditionsTest extends \PHPUnit_Framework_TestCase { /** - * @covers Sabre\DAV\Server::checkPreconditions * @expectedException Sabre\DAV\Exception\PreconditionFailed */ function testIfMatchNoNode() { $root = new SimpleCollection('root',array(new ServerPreconditionsNode())); $server = new Server($root); - $httpRequest = new HTTP\Request(array( - 'HTTP_IF_MATCH' => '*', - 'REQUEST_URI' => '/bar' - )); - $server->httpRequest = $httpRequest; - - $server->checkPreconditions(); + $httpRequest = new HTTP\Request('GET', '/bar', ['If-Match' => '*']); + $httpResponse = new HTTP\Response(); + $server->checkPreconditions($httpRequest, $httpResponse); } /** - * @covers \Sabre\DAV\Server::checkPreconditions */ function testIfMatchHasNode() { $root = new SimpleCollection('root',array(new ServerPreconditionsNode())); $server = new Server($root); - $httpRequest = new HTTP\Request(array( - 'HTTP_IF_MATCH' => '*', - 'REQUEST_URI' => '/foo' - )); - $server->httpRequest = $httpRequest; - - $this->assertTrue($server->checkPreconditions()); + $httpRequest = new HTTP\Request('GET', '/foo', ['If-Match' => '*']); + $httpResponse = new HTTP\Response(); + $this->assertTrue($server->checkPreconditions($httpRequest, $httpResponse)); } /** - * @covers \Sabre\DAV\Server::checkPreconditions * @expectedException Sabre\DAV\Exception\PreconditionFailed */ function testIfMatchWrongEtag() { $root = new SimpleCollection('root',array(new ServerPreconditionsNode())); $server = new Server($root); - $httpRequest = new HTTP\Request(array( - 'HTTP_IF_MATCH' => '1234', - 'REQUEST_URI' => '/foo' - )); - $server->httpRequest = $httpRequest; - - $server->checkPreconditions(); + $httpRequest = new HTTP\Request('GET', '/foo', ['If-Match' => '1234']); + $httpResponse = new HTTP\Response(); + $server->checkPreconditions($httpRequest, $httpResponse); } /** - * @covers \Sabre\DAV\Server::checkPreconditions */ function testIfMatchCorrectEtag() { $root = new SimpleCollection('root',array(new ServerPreconditionsNode())); $server = new Server($root); - $httpRequest = new HTTP\Request(array( - 'HTTP_IF_MATCH' => '"abc123"', - 'REQUEST_URI' => '/foo' - )); - $server->httpRequest = $httpRequest; - - $this->assertTrue($server->checkPreconditions()); + $httpRequest = new HTTP\Request('GET', '/foo', ['If-Match' => '"abc123"']); + $httpResponse = new HTTP\Response(); + $this->assertTrue($server->checkPreconditions($httpRequest, $httpResponse)); } /** * Evolution sometimes uses \" instead of " for If-Match headers. * - * @covers \Sabre\DAV\Server::checkPreconditions * @depends testIfMatchCorrectEtag */ function testIfMatchEvolutionEtag() { $root = new SimpleCollection('root',array(new ServerPreconditionsNode())); $server = new Server($root); - $httpRequest = new HTTP\Request(array( - 'HTTP_IF_MATCH' => '\\"abc123\\"', - 'REQUEST_URI' => '/foo' - )); - $server->httpRequest = $httpRequest; - - $this->assertTrue($server->checkPreconditions()); + $httpRequest = new HTTP\Request('GET', '/foo', ['If-Match' => '\\"abc123\\"']); + $httpResponse = new HTTP\Response(); + $this->assertTrue($server->checkPreconditions($httpRequest, $httpResponse)); } /** - * @covers \Sabre\DAV\Server::checkPreconditions */ function testIfMatchMultiple() { $root = new SimpleCollection('root',array(new ServerPreconditionsNode())); $server = new Server($root); - $httpRequest = new HTTP\Request(array( - 'HTTP_IF_MATCH' => '"hellothere", "abc123"', - 'REQUEST_URI' => '/foo' - )); - $server->httpRequest = $httpRequest; - - $this->assertTrue($server->checkPreconditions()); + $httpRequest = new HTTP\Request('GET', '/foo', ['If-Match' => '"hellothere", "abc123"']); + $httpResponse = new HTTP\Response(); + $this->assertTrue($server->checkPreconditions($httpRequest, $httpResponse)); } /** - * @covers \Sabre\DAV\Server::checkPreconditions */ function testIfNoneMatchNoNode() { $root = new SimpleCollection('root',array(new ServerPreconditionsNode())); $server = new Server($root); - $httpRequest = new HTTP\Request(array( - 'HTTP_IF_NONE_MATCH' => '*', - 'REQUEST_URI' => '/bar' - )); - $server->httpRequest = $httpRequest; - - $this->assertTrue($server->checkPreconditions()); + $httpRequest = new HTTP\Request('GET', '/bar', ['If-None-Match' => '*']); + $httpResponse = new HTTP\Response(); + $this->assertTrue($server->checkPreconditions($httpRequest, $httpResponse)); } /** - * @covers \Sabre\DAV\Server::checkPreconditions * @expectedException Sabre\DAV\Exception\PreconditionFailed */ function testIfNoneMatchHasNode() { $root = new SimpleCollection('root',array(new ServerPreconditionsNode())); $server = new Server($root); - $httpRequest = new HTTP\Request(array( - 'HTTP_IF_NONE_MATCH' => '*', - 'REQUEST_URI' => '/foo' - )); - $server->httpRequest = $httpRequest; - - $server->checkPreconditions(); + $httpRequest = new HTTP\Request('POST', '/foo', ['If-None-Match' => '*']); + $httpResponse = new HTTP\Response(); + $server->checkPreconditions($httpRequest, $httpResponse); } /** - * @covers \Sabre\DAV\Server::checkPreconditions */ function testIfNoneMatchWrongEtag() { $root = new SimpleCollection('root',array(new ServerPreconditionsNode())); $server = new Server($root); - $httpRequest = new HTTP\Request(array( - 'HTTP_IF_NONE_MATCH' => '"1234"', - 'REQUEST_URI' => '/foo' - )); - $server->httpRequest = $httpRequest; - - $this->assertTrue($server->checkPreconditions()); + $httpRequest = new HTTP\Request('POST', '/foo', ['If-None-Match' => '"1234"']); + $httpResponse = new HTTP\Response(); + $this->assertTrue($server->checkPreconditions($httpRequest, $httpResponse)); } /** - * @covers \Sabre\DAV\Server::checkPreconditions */ function testIfNoneMatchWrongEtagMultiple() { $root = new SimpleCollection('root',array(new ServerPreconditionsNode())); $server = new Server($root); - $httpRequest = new HTTP\Request(array( - 'HTTP_IF_NONE_MATCH' => '"1234", "5678"', - 'REQUEST_URI' => '/foo' - )); - $server->httpRequest = $httpRequest; - - $this->assertTrue($server->checkPreconditions()); + $httpRequest = new HTTP\Request('POST', '/foo', ['If-None-Match' => '"1234", "5678"']); + $httpResponse = new HTTP\Response(); + $this->assertTrue($server->checkPreconditions($httpRequest, $httpResponse)); } /** - * @covers \Sabre\DAV\Server::checkPreconditions * @expectedException Sabre\DAV\Exception\PreconditionFailed */ public function testIfNoneMatchCorrectEtag() { $root = new SimpleCollection('root',array(new ServerPreconditionsNode())); $server = new Server($root); - $httpRequest = new HTTP\Request(array( - 'HTTP_IF_NONE_MATCH' => '"abc123"', - 'REQUEST_URI' => '/foo' - )); - $server->httpRequest = $httpRequest; - - $server->checkPreconditions(); + $httpRequest = new HTTP\Request('POST', '/foo', ['If-None-Match' => '"abc123"']); + $httpResponse = new HTTP\Response(); + $server->checkPreconditions($httpRequest, $httpResponse); } /** - * @covers \Sabre\DAV\Server::checkPreconditions * @expectedException Sabre\DAV\Exception\PreconditionFailed */ public function testIfNoneMatchCorrectEtagMultiple() { $root = new SimpleCollection('root',array(new ServerPreconditionsNode())); $server = new Server($root); - $httpRequest = new HTTP\Request(array( - 'HTTP_IF_NONE_MATCH' => '"1234", "abc123"', - 'REQUEST_URI' => '/foo' - )); - $server->httpRequest = $httpRequest; - - $server->checkPreconditions(); + $httpRequest = new HTTP\Request('POST', '/foo', ['If-None-Match' => '"1234, "abc123"']); + $httpResponse = new HTTP\Response(); + $server->checkPreconditions($httpRequest, $httpResponse); } /** - * @covers \Sabre\DAV\Server::checkPreconditions */ public function testIfNoneMatchCorrectEtagAsGet() { $root = new SimpleCollection('root',array(new ServerPreconditionsNode())); $server = new Server($root); - $httpRequest = new HTTP\Request(array( - 'HTTP_IF_NONE_MATCH' => '"abc123"', - 'REQUEST_URI' => '/foo' - )); + $httpRequest = new HTTP\Request('GET', '/foo', ['If-None-Match' => '"abc123"']); + $server->httpResponse = new HTTP\ResponseMock(); + + $this->assertFalse($server->checkPreconditions($httpRequest, $server->httpResponse)); + $this->assertEquals(304, $server->httpResponse->getStatus()); + $this->assertEquals(['ETag' => ['"abc123"']], $server->httpResponse->getHeaders()); + + } + + /** + * This was a test written for issue #515. + */ + public function testNoneMatchCorrectEtagEnsureSapiSent() { + + $root = new SimpleCollection('root',array(new ServerPreconditionsNode())); + $server = new Server($root); + $server->sapi = new HTTP\SapiMock(); + HTTP\SapiMock::$sent = 0; + $httpRequest = new HTTP\Request('GET', '/foo', ['If-None-Match' => '"abc123"']); $server->httpRequest = $httpRequest; $server->httpResponse = new HTTP\ResponseMock(); - $this->assertFalse($server->checkPreconditions(true)); - $this->assertEquals('HTTP/1.1 304 Not Modified',$server->httpResponse->status); + $server->exec(); + + $this->assertFalse($server->checkPreconditions($httpRequest, $server->httpResponse)); + $this->assertEquals(304, $server->httpResponse->getStatus()); + $this->assertEquals([ + 'ETag' => ['"abc123"'], + 'X-Sabre-Version' => [Version::VERSION], + ], $server->httpResponse->getHeaders()); + $this->assertEquals(1, HTTP\SapiMock::$sent); } /** - * @covers \Sabre\DAV\Server::checkPreconditions */ public function testIfModifiedSinceUnModified() { $root = new SimpleCollection('root',array(new ServerPreconditionsNode())); $server = new Server($root); - $httpRequest = new HTTP\Request(array( + $httpRequest = HTTP\Sapi::createFromServerArray(array( 'HTTP_IF_MODIFIED_SINCE' => 'Sun, 06 Nov 1994 08:49:37 GMT', 'REQUEST_URI' => '/foo' )); - $server->httpRequest = $httpRequest; $server->httpResponse = new HTTP\ResponseMock(); - $this->assertFalse($server->checkPreconditions()); + $this->assertFalse($server->checkPreconditions($httpRequest, $server->httpResponse)); - $this->assertEquals('HTTP/1.1 304 Not Modified',$server->httpResponse->status); + $this->assertEquals(304, $server->httpResponse->status); $this->assertEquals(array( - 'Last-Modified' => 'Sat, 06 Apr 1985 23:30:00 GMT', - ), $server->httpResponse->headers); + 'Last-Modified' => ['Sat, 06 Apr 1985 23:30:00 GMT'], + ), $server->httpResponse->getHeaders()); } /** - * @covers \Sabre\DAV\Server::checkPreconditions */ public function testIfModifiedSinceModified() { $root = new SimpleCollection('root',array(new ServerPreconditionsNode())); $server = new Server($root); - $httpRequest = new HTTP\Request(array( + $httpRequest = HTTP\Sapi::createFromServerArray(array( 'HTTP_IF_MODIFIED_SINCE' => 'Tue, 06 Nov 1984 08:49:37 GMT', 'REQUEST_URI' => '/foo' )); - $server->httpRequest = $httpRequest; - $server->httpResponse = new HTTP\ResponseMock(); - $this->assertTrue($server->checkPreconditions()); + + $httpResponse = new HTTP\ResponseMock(); + $this->assertTrue($server->checkPreconditions($httpRequest, $httpResponse)); } /** - * @covers \Sabre\DAV\Server::checkPreconditions */ public function testIfModifiedSinceInvalidDate() { $root = new SimpleCollection('root',array(new ServerPreconditionsNode())); $server = new Server($root); - $httpRequest = new HTTP\Request(array( + $httpRequest = HTTP\Sapi::createFromServerArray(array( 'HTTP_IF_MODIFIED_SINCE' => 'Your mother', 'REQUEST_URI' => '/foo' )); - $server->httpRequest = $httpRequest; - $server->httpResponse = new HTTP\ResponseMock(); + $httpResponse = new HTTP\ResponseMock(); // Invalid dates must be ignored, so this should return true - $this->assertTrue($server->checkPreconditions()); + $this->assertTrue($server->checkPreconditions($httpRequest, $httpResponse)); } /** - * @covers \Sabre\DAV\Server::checkPreconditions */ public function testIfModifiedSinceInvalidDate2() { $root = new SimpleCollection('root',array(new ServerPreconditionsNode())); $server = new Server($root); - $httpRequest = new HTTP\Request(array( + $httpRequest = HTTP\Sapi::createFromServerArray(array( 'HTTP_IF_MODIFIED_SINCE' => 'Sun, 06 Nov 1994 08:49:37 EST', 'REQUEST_URI' => '/foo' )); - $server->httpRequest = $httpRequest; - $server->httpResponse = new HTTP\ResponseMock(); - $this->assertTrue($server->checkPreconditions()); + $httpResponse = new HTTP\ResponseMock(); + $this->assertTrue($server->checkPreconditions($httpRequest, $httpResponse)); } /** - * @covers \Sabre\DAV\Server::checkPreconditions */ public function testIfUnmodifiedSinceUnModified() { $root = new SimpleCollection('root',array(new ServerPreconditionsNode())); $server = new Server($root); - $httpRequest = new HTTP\Request(array( + $httpRequest = HTTP\Sapi::createFromServerArray(array( 'HTTP_IF_UNMODIFIED_SINCE' => 'Sun, 06 Nov 1994 08:49:37 GMT', 'REQUEST_URI' => '/foo' )); - $server->httpRequest = $httpRequest; - $this->assertTrue($server->checkPreconditions()); + $httpResponse = new HTTP\Response(); + $this->assertTrue($server->checkPreconditions($httpRequest, $httpResponse)); } /** - * @covers \Sabre\DAV\Server::checkPreconditions * @expectedException Sabre\DAV\Exception\PreconditionFailed */ public function testIfUnmodifiedSinceModified() { $root = new SimpleCollection('root',array(new ServerPreconditionsNode())); $server = new Server($root); - $httpRequest = new HTTP\Request(array( + $httpRequest = HTTP\Sapi::createFromServerArray(array( 'HTTP_IF_UNMODIFIED_SINCE' => 'Tue, 06 Nov 1984 08:49:37 GMT', 'REQUEST_URI' => '/foo' )); - $server->httpRequest = $httpRequest; - $server->httpResponse = new HTTP\ResponseMock(); - $server->checkPreconditions(); + $httpResponse = new HTTP\ResponseMock(); + $server->checkPreconditions($httpRequest, $httpResponse); } /** - * @covers \Sabre\DAV\Server::checkPreconditions */ public function testIfUnmodifiedSinceInvalidDate() { $root = new SimpleCollection('root',array(new ServerPreconditionsNode())); $server = new Server($root); - $httpRequest = new HTTP\Request(array( + $httpRequest = HTTP\Sapi::createFromServerArray(array( 'HTTP_IF_UNMODIFIED_SINCE' => 'Sun, 06 Nov 1984 08:49:37 CET', 'REQUEST_URI' => '/foo' )); - $server->httpRequest = $httpRequest; - $server->httpResponse = new HTTP\ResponseMock(); - $this->assertTrue($server->checkPreconditions()); + $httpResponse = new HTTP\ResponseMock(); + $this->assertTrue($server->checkPreconditions($httpRequest, $httpResponse)); } diff --git a/vendor/sabre/dav/tests/Sabre/DAV/ServerPropsTest.php b/vendor/sabre/dav/tests/Sabre/DAV/ServerPropsTest.php index 859a91070..253200be7 100644 --- a/vendor/sabre/dav/tests/Sabre/DAV/ServerPropsTest.php +++ b/vendor/sabre/dav/tests/Sabre/DAV/ServerPropsTest.php @@ -1,6 +1,7 @@ <?php namespace Sabre\DAV; + use Sabre\HTTP; require_once 'Sabre/HTTP/ResponseMock.php'; @@ -16,7 +17,7 @@ class ServerPropsTest extends AbstractServer { function setUp() { - if (file_exists(SABRE_TEMPDIR.'../.sabredav')) unlink(SABRE_TEMPDIR.'../.sabredav'); + if (file_exists(SABRE_TEMPDIR . '../.sabredav')) unlink(SABRE_TEMPDIR . '../.sabredav'); parent::setUp(); file_put_contents(SABRE_TEMPDIR . '/test2.txt', 'Test contents2'); mkdir(SABRE_TEMPDIR . '/col'); @@ -28,64 +29,68 @@ class ServerPropsTest extends AbstractServer { function tearDown() { parent::tearDown(); - if (file_exists(SABRE_TEMPDIR.'../.locksdb')) unlink(SABRE_TEMPDIR.'../.locksdb'); + if (file_exists(SABRE_TEMPDIR . '../.locksdb')) unlink(SABRE_TEMPDIR . '../.locksdb'); } - private function sendRequest($body) { - - $serverVars = array( - 'REQUEST_URI' => '/', - 'REQUEST_METHOD' => 'PROPFIND', - 'HTTP_DEPTH' => '0', - ); + private function sendRequest($body, $path = '/', $headers = ['Depth' => '0']) { - $request = new HTTP\Request($serverVars); - $request->setBody($body); + $request = new HTTP\Request('PROPFIND', $path, $headers, $body); - $this->server->httpRequest = ($request); + $this->server->httpRequest = $request; $this->server->exec(); } - public function testPropFindEmptyBody() { + function testPropFindEmptyBody() { - $hasFired = false; + $this->sendRequest(""); + $this->assertEquals(207, $this->response->status); + + $this->assertEquals([ + 'X-Sabre-Version' => [Version::VERSION], + 'Content-Type' => ['application/xml; charset=utf-8'], + 'DAV' => ['1, 3, extended-mkcol, 2'], + 'Vary' => ['Brief,Prefer'], + ], + $this->response->getHeaders() + ); - $self = $this; - // Also testing the beforeGetPropertiesForPath event. - $this->server->subscribeEvent('beforeGetPropertiesForPath', function($path, $properties, $depth) use ($self, &$hasFired) { + $body = preg_replace("/xmlns(:[A-Za-z0-9_])?=(\"|\')DAV:(\"|\')/", "xmlns\\1=\"urn:DAV\"", $this->response->body); + $xml = simplexml_load_string($body); + $xml->registerXPathNamespace('d', 'urn:DAV'); - $hasFired = true; - $self->assertEquals('', $path); - $self->assertEquals(array(), $properties); - $self->assertEquals(0, $depth); + list($data) = $xml->xpath('/d:multistatus/d:response/d:href'); + $this->assertEquals('/', (string)$data, 'href element should have been /'); - }); + $data = $xml->xpath('/d:multistatus/d:response/d:propstat/d:prop/d:resourcetype'); + $this->assertEquals(1, count($data)); - $this->sendRequest(""); + } - $this->assertTrue($hasFired); + function testPropFindEmptyBodyFile() { - $this->assertEquals('HTTP/1.1 207 Multi-Status',$this->response->status); + $this->sendRequest("", '/test2.txt', []); + $this->assertEquals(207, $this->response->status); - $this->assertEquals(array( - 'Content-Type' => 'application/xml; charset=utf-8', - 'DAV' => '1, 3, extended-mkcol, 2', - 'Vary' => 'Brief,Prefer', - ), - $this->response->headers + $this->assertEquals([ + 'X-Sabre-Version' => [Version::VERSION], + 'Content-Type' => ['application/xml; charset=utf-8'], + 'DAV' => ['1, 3, extended-mkcol, 2'], + 'Vary' => ['Brief,Prefer'], + ], + $this->response->getHeaders() ); - $body = preg_replace("/xmlns(:[A-Za-z0-9_])?=(\"|\')DAV:(\"|\')/","xmlns\\1=\"urn:DAV\"",$this->response->body); + $body = preg_replace("/xmlns(:[A-Za-z0-9_])?=(\"|\')DAV:(\"|\')/", "xmlns\\1=\"urn:DAV\"", $this->response->body); $xml = simplexml_load_string($body); - $xml->registerXPathNamespace('d','urn:DAV'); + $xml->registerXPathNamespace('d', 'urn:DAV'); list($data) = $xml->xpath('/d:multistatus/d:response/d:href'); - $this->assertEquals('/',(string)$data,'href element should have been /'); + $this->assertEquals('/test2.txt', (string)$data, 'href element should have been /test2.txt'); - $data = $xml->xpath('/d:multistatus/d:response/d:propstat/d:prop/d:resourcetype'); - $this->assertEquals(1,count($data)); + $data = $xml->xpath('/d:multistatus/d:response/d:propstat/d:prop/d:getcontentlength'); + $this->assertEquals(1, count($data)); } @@ -100,27 +105,27 @@ class ServerPropsTest extends AbstractServer { $this->sendRequest($xml); - $body = preg_replace("/xmlns(:[A-Za-z0-9_])?=(\"|\')DAV:(\"|\')/","xmlns\\1=\"urn:DAV\"",$this->response->body); + $body = preg_replace("/xmlns(:[A-Za-z0-9_])?=(\"|\')DAV:(\"|\')/", "xmlns\\1=\"urn:DAV\"", $this->response->body); $xml = simplexml_load_string($body); - $xml->registerXPathNamespace('d','urn:DAV'); + $xml->registerXPathNamespace('d', 'urn:DAV'); $data = $xml->xpath('/d:multistatus/d:response/d:propstat/d:prop/d:supportedlock/d:lockentry'); - $this->assertEquals(2,count($data),'We expected two \'d:lockentry\' tags'); + $this->assertEquals(2, count($data), 'We expected two \'d:lockentry\' tags'); $data = $xml->xpath('/d:multistatus/d:response/d:propstat/d:prop/d:supportedlock/d:lockentry/d:lockscope'); - $this->assertEquals(2,count($data),'We expected two \'d:lockscope\' tags'); + $this->assertEquals(2, count($data), 'We expected two \'d:lockscope\' tags'); $data = $xml->xpath('/d:multistatus/d:response/d:propstat/d:prop/d:supportedlock/d:lockentry/d:locktype'); - $this->assertEquals(2,count($data),'We expected two \'d:locktype\' tags'); + $this->assertEquals(2, count($data), 'We expected two \'d:locktype\' tags'); $data = $xml->xpath('/d:multistatus/d:response/d:propstat/d:prop/d:supportedlock/d:lockentry/d:lockscope/d:shared'); - $this->assertEquals(1,count($data),'We expected a \'d:shared\' tag'); + $this->assertEquals(1, count($data), 'We expected a \'d:shared\' tag'); $data = $xml->xpath('/d:multistatus/d:response/d:propstat/d:prop/d:supportedlock/d:lockentry/d:lockscope/d:exclusive'); - $this->assertEquals(1,count($data),'We expected a \'d:exclusive\' tag'); + $this->assertEquals(1, count($data), 'We expected a \'d:exclusive\' tag'); $data = $xml->xpath('/d:multistatus/d:response/d:propstat/d:prop/d:supportedlock/d:lockentry/d:locktype/d:write'); - $this->assertEquals(2,count($data),'We expected two \'d:write\' tags'); + $this->assertEquals(2, count($data), 'We expected two \'d:write\' tags'); } function testLockDiscovery() { @@ -134,12 +139,12 @@ class ServerPropsTest extends AbstractServer { $this->sendRequest($xml); - $body = preg_replace("/xmlns(:[A-Za-z0-9_])?=(\"|\')DAV:(\"|\')/","xmlns\\1=\"urn:DAV\"",$this->response->body); + $body = preg_replace("/xmlns(:[A-Za-z0-9_])?=(\"|\')DAV:(\"|\')/", "xmlns\\1=\"urn:DAV\"", $this->response->body); $xml = simplexml_load_string($body); - $xml->registerXPathNamespace('d','urn:DAV'); + $xml->registerXPathNamespace('d', 'urn:DAV'); $data = $xml->xpath('/d:multistatus/d:response/d:propstat/d:prop/d:lockdiscovery'); - $this->assertEquals(1,count($data),'We expected a \'d:lockdiscovery\' tag'); + $this->assertEquals(1, count($data), 'We expected a \'d:lockdiscovery\' tag'); } @@ -153,31 +158,28 @@ class ServerPropsTest extends AbstractServer { </d:propfind>'; $this->sendRequest($xml); - $body = preg_replace("/xmlns(:[A-Za-z0-9_])?=(\"|\')DAV:(\"|\')/","xmlns\\1=\"urn:DAV\"",$this->response->body); + $body = preg_replace("/xmlns(:[A-Za-z0-9_])?=(\"|\')DAV:(\"|\')/", "xmlns\\1=\"urn:DAV\"", $this->response->body); $xml = simplexml_load_string($body); - $xml->registerXPathNamespace('d','urn:DAV'); - $pathTests = array( + $xml->registerXPathNamespace('d', 'urn:DAV'); + $pathTests = [ '/d:multistatus', '/d:multistatus/d:response', '/d:multistatus/d:response/d:propstat', '/d:multistatus/d:response/d:propstat/d:status', '/d:multistatus/d:response/d:propstat/d:prop', '/d:multistatus/d:response/d:propstat/d:prop/d:macaroni', - ); - foreach($pathTests as $test) { - $this->assertTrue(count($xml->xpath($test))==true,'We expected the ' . $test . ' element to appear in the response, we got: ' . $body); + ]; + foreach ($pathTests as $test) { + $this->assertTrue(count($xml->xpath($test)) == true, 'We expected the ' . $test . ' element to appear in the response, we got: ' . $body); } $val = $xml->xpath('/d:multistatus/d:response/d:propstat/d:status'); - $this->assertEquals(1,count($val),$body); - $this->assertEquals('HTTP/1.1 404 Not Found',(string)$val[0]); + $this->assertEquals(1, count($val), $body); + $this->assertEquals('HTTP/1.1 404 Not Found', (string)$val[0]); } - /** - * @covers Sabre\DAV\Server::parsePropPatchRequest - */ - public function testParsePropPatchRequest() { + function testParsePropPatchRequest() { $body = '<?xml version="1.0"?> <d:propertyupdate xmlns:d="DAV:" xmlns:s="http://sabredav.org/NS/test"> @@ -187,226 +189,12 @@ class ServerPropsTest extends AbstractServer { <d:remove><d:prop><s:someprop3 /></d:prop></d:remove> </d:propertyupdate>'; - $result = $this->server->parsePropPatchRequest($body); - $this->assertEquals(array( - '{http://sabredav.org/NS/test}someprop' => 'somevalue', + $result = $this->server->xml->parse($body); + $this->assertEquals([ + '{http://sabredav.org/NS/test}someprop' => 'somevalue', '{http://sabredav.org/NS/test}someprop2' => null, '{http://sabredav.org/NS/test}someprop3' => null, - ), $result); - - } - - /** - * @covers Sabre\DAV\Server::updateProperties - */ - public function testUpdateProperties() { - - $props = array( - '{http://sabredav.org/NS/test}someprop' => 'somevalue', - ); - - $result = $this->server->updateProperties('/test2.txt',$props); - - $this->assertEquals(array( - '200' => array('{http://sabredav.org/NS/test}someprop' => null), - 'href' => '/test2.txt', - ), $result); - - } - - /** - * @covers Sabre\DAV\Server::updateProperties - * @depends testUpdateProperties - */ - public function testUpdatePropertiesProtected() { - - $props = array( - '{http://sabredav.org/NS/test}someprop' => 'somevalue', - '{DAV:}getcontentlength' => 50, - ); - - $result = $this->server->updateProperties('/test2.txt',$props); - - $this->assertEquals(array( - '424' => array('{http://sabredav.org/NS/test}someprop' => null), - '403' => array('{DAV:}getcontentlength' => null), - 'href' => '/test2.txt', - ), $result); - - } - - /** - * @covers Sabre\DAV\Server::updateProperties - * @depends testUpdateProperties - */ - public function testUpdatePropertiesFail1() { - - $dir = new PropTestDirMock('updatepropsfalse'); - $objectTree = new ObjectTree($dir); - $this->server->tree = $objectTree; - - $props = array( - '{http://sabredav.org/NS/test}someprop' => 'somevalue', - ); - - $result = $this->server->updateProperties('/',$props); - - $this->assertEquals(array( - '403' => array('{http://sabredav.org/NS/test}someprop' => null), - 'href' => '/', - ), $result); - - } - - /** - * @covers Sabre\DAV\Server::updateProperties - * @depends testUpdateProperties - */ - public function testUpdatePropertiesFail2() { - - $dir = new PropTestDirMock('updatepropsarray'); - $objectTree = new ObjectTree($dir); - $this->server->tree = $objectTree; - - $props = array( - '{http://sabredav.org/NS/test}someprop' => 'somevalue', - ); - - $result = $this->server->updateProperties('/',$props); - - $this->assertEquals(array( - '402' => array('{http://sabredav.org/NS/test}someprop' => null), - 'href' => '/', - ), $result); - - } - - /** - * @covers Sabre\DAV\Server::updateProperties - * @depends testUpdateProperties - * @expectedException Sabre\DAV\Exception - */ - public function testUpdatePropertiesFail3() { - - $dir = new PropTestDirMock('updatepropsobj'); - $objectTree = new ObjectTree($dir); - $this->server->tree = $objectTree; - - $props = array( - '{http://sabredav.org/NS/test}someprop' => 'somevalue', - ); - - $result = $this->server->updateProperties('/',$props); - - } - - /** - * @depends testParsePropPatchRequest - * @depends testUpdateProperties - * @covers Sabre\DAV\Server::httpPropPatch - */ - public function testPropPatch() { - - $serverVars = array( - 'REQUEST_URI' => '/', - 'REQUEST_METHOD' => 'PROPPATCH', - ); - - $body = '<?xml version="1.0"?> -<d:propertyupdate xmlns:d="DAV:" xmlns:s="http://www.rooftopsolutions.nl/testnamespace"> - <d:set><d:prop><s:someprop>somevalue</s:someprop></d:prop></d:set> -</d:propertyupdate>'; - - $request = new HTTP\Request($serverVars); - $request->setBody($body); - - $this->server->httpRequest = ($request); - $this->server->exec(); - - $this->assertEquals(array( - 'Content-Type' => 'application/xml; charset=utf-8', - 'Vary' => 'Brief,Prefer', - ), - $this->response->headers - ); - - $this->assertEquals('HTTP/1.1 207 Multi-Status',$this->response->status,'We got the wrong status. Full XML response: ' . $this->response->body); - - $body = preg_replace("/xmlns(:[A-Za-z0-9_])?=(\"|\')DAV:(\"|\')/","xmlns\\1=\"urn:DAV\"",$this->response->body); - $xml = simplexml_load_string($body); - $xml->registerXPathNamespace('d','urn:DAV'); - $xml->registerXPathNamespace('bla','http://www.rooftopsolutions.nl/testnamespace'); - - $data = $xml->xpath('/d:multistatus/d:response/d:propstat/d:prop'); - $this->assertEquals(1,count($data),'We expected one \'d:prop\' element. Response body: ' . $body); - - $data = $xml->xpath('//bla:someprop'); - $this->assertEquals(1,count($data),'We expected one \'s:someprop\' element. Response body: ' . $body); - - $data = $xml->xpath('/d:multistatus/d:response/d:propstat/d:status'); - $this->assertEquals(1,count($data),'We expected one \'s:status\' element. Response body: ' . $body); - - $this->assertEquals('HTTP/1.1 200 OK',(string)$data[0]); - - } - - /** - * @depends testPropPatch - */ - public function testPropPatchAndFetch() { - - $this->testPropPatch(); - $xml = '<?xml version="1.0"?> -<d:propfind xmlns:d="DAV:" xmlns:s="http://www.rooftopsolutions.nl/testnamespace"> - <d:prop> - <s:someprop /> - </d:prop> -</d:propfind>'; - - $this->sendRequest($xml); - - $body = preg_replace("/xmlns(:[A-Za-z0-9_])?=(\"|\')DAV:(\"|\')/","xmlns\\1=\"urn:DAV\"",$this->response->body); - $xml = simplexml_load_string($body); - $xml->registerXPathNamespace('d','urn:DAV'); - $xml->registerXPathNamespace('bla','http://www.rooftopsolutions.nl/testnamespace'); - - $xpath='//bla:someprop'; - $result = $xml->xpath($xpath); - $this->assertEquals(1,count($result),'We couldn\'t find our new property in the response. Full response body:' . "\n" . $body); - $this->assertEquals('somevalue',(string)$result[0],'We couldn\'t find our new property in the response. Full response body:' . "\n" . $body); - - } - -} - -class PropTestDirMock extends SimpleCollection implements IProperties { - - public $type; - - function __construct($type) { - - $this->type =$type; - parent::__construct('root'); - - } - - function updateProperties($updateProperties) { - - switch($this->type) { - case 'updatepropsfalse' : return false; - case 'updatepropsarray' : - $r = array(402 => array()); - foreach($updateProperties as $k=>$v) $r[402][$k] = null; - return $r; - case 'updatepropsobj' : - return new \STDClass(); - } - - } - - function getProperties($requestedPropeties) { - - return array(); + ], $result->properties); } diff --git a/vendor/sabre/dav/tests/Sabre/DAV/ServerRangeTest.php b/vendor/sabre/dav/tests/Sabre/DAV/ServerRangeTest.php index a06fcb0be..bafbef6e4 100644 --- a/vendor/sabre/dav/tests/Sabre/DAV/ServerRangeTest.php +++ b/vendor/sabre/dav/tests/Sabre/DAV/ServerRangeTest.php @@ -1,42 +1,62 @@ <?php namespace Sabre\DAV; -use Sabre\HTTP; -require_once 'Sabre/DAV/AbstractServer.php'; +use DateTime; +use Sabre\HTTP; -class ServerRangeTest extends AbstractServer{ +/** + * This file tests HTTP requests that use the Range: header. + * + * @copyright Copyright (C) fruux GmbH. (https://fruux.com/) + * @author Evert Pot (http://evertpot.com/) + * @license http://sabre.io/license/ Modified BSD License + */ +class ServerRangeTest extends \Sabre\DAVServerTest { - protected function getRootNode() { + protected $setupFiles = true; - return new FSExt\Directory(SABRE_TEMPDIR); + /** + * We need this string a lot + */ + protected $lastModified; - } + function setUp() { - function testRange() { + parent::setUp(); + $this->server->createFile('files/test.txt', 'Test contents'); - $serverVars = array( - 'REQUEST_URI' => '/test.txt', - 'REQUEST_METHOD' => 'GET', - 'HTTP_RANGE' => 'bytes=2-5', + $this->lastModified = HTTP\Util::toHTTPDate( + new DateTime('@' . $this->server->tree->getNodeForPath('files/test.txt')->getLastModified()) ); - $request = new HTTP\Request($serverVars); - $this->server->httpRequest = ($request); - $this->server->exec(); + $stream = popen('echo "Test contents"', 'r'); + $streamingFile = new Mock\StreamingFile( + 'no-seeking.txt', + $stream + ); + $streamingFile->setSize(12); + $this->server->tree->getNodeForPath('files')->addNode($streamingFile); - $this->assertEquals(array( - 'Content-Type' => 'application/octet-stream', - 'Content-Length' => 4, - 'Content-Range' => 'bytes 2-5/13', - 'Last-Modified' => HTTP\Util::toHTTPDate(new \DateTime('@' . filemtime($this->tempDir . '/test.txt'))), - 'ETag' => '"' . md5(file_get_contents(SABRE_TEMPDIR . '/test.txt')). '"', - ), - $this->response->headers - ); + } - $this->assertEquals('HTTP/1.1 206 Partial Content',$this->response->status); - $this->assertEquals('st c', stream_get_contents($this->response->body)); + function testRange() { + + $request = new HTTP\Request('GET', '/files/test.txt', ['Range' => 'bytes=2-5']); + $response = $this->request($request); + + $this->assertEquals([ + 'X-Sabre-Version' => [Version::VERSION], + 'Content-Type' => ['application/octet-stream'], + 'Content-Length' => [4], + 'Content-Range' => ['bytes 2-5/13'], + 'ETag' => ['"' . md5('Test contents') . '"'], + 'Last-Modified' => [$this->lastModified], + ], + $response->getHeaders() + ); + $this->assertEquals(206, $response->getStatus()); + $this->assertEquals('st c', $response->getBodyAsString()); } @@ -45,28 +65,22 @@ class ServerRangeTest extends AbstractServer{ */ function testStartRange() { - $serverVars = array( - 'REQUEST_URI' => '/test.txt', - 'REQUEST_METHOD' => 'GET', - 'HTTP_RANGE' => 'bytes=2-', + $request = new HTTP\Request('GET', '/files/test.txt', ['Range' => 'bytes=2-']); + $response = $this->request($request); + + $this->assertEquals([ + 'X-Sabre-Version' => [Version::VERSION], + 'Content-Type' => ['application/octet-stream'], + 'Content-Length' => [11], + 'Content-Range' => ['bytes 2-12/13'], + 'ETag' => ['"' . md5('Test contents') . '"'], + 'Last-Modified' => [$this->lastModified], + ], + $response->getHeaders() ); - $request = new HTTP\Request($serverVars); - $this->server->httpRequest = ($request); - $this->server->exec(); - - $this->assertEquals(array( - 'Content-Type' => 'application/octet-stream', - 'Content-Length' => 11, - 'Content-Range' => 'bytes 2-12/13', - 'Last-Modified' => HTTP\Util::toHTTPDate(new \DateTime('@' . filemtime($this->tempDir . '/test.txt'))), - 'ETag' => '"' . md5(file_get_contents(SABRE_TEMPDIR . '/test.txt')) . '"', - ), - $this->response->headers - ); - - $this->assertEquals('HTTP/1.1 206 Partial Content',$this->response->status); - $this->assertEquals('st contents', stream_get_contents($this->response->body)); + $this->assertEquals(206, $response->getStatus()); + $this->assertEquals('st contents', $response->getBodyAsString()); } @@ -75,28 +89,22 @@ class ServerRangeTest extends AbstractServer{ */ function testEndRange() { - $serverVars = array( - 'REQUEST_URI' => '/test.txt', - 'REQUEST_METHOD' => 'GET', - 'HTTP_RANGE' => 'bytes=-8', + $request = new HTTP\Request('GET', '/files/test.txt', ['Range' => 'bytes=-8']); + $response = $this->request($request); + + $this->assertEquals([ + 'X-Sabre-Version' => [Version::VERSION], + 'Content-Type' => ['application/octet-stream'], + 'Content-Length' => [8], + 'Content-Range' => ['bytes 5-12/13'], + 'ETag' => ['"' . md5('Test contents') . '"'], + 'Last-Modified' => [$this->lastModified], + ], + $response->getHeaders() ); - $request = new HTTP\Request($serverVars); - $this->server->httpRequest = ($request); - $this->server->exec(); - - $this->assertEquals(array( - 'Content-Type' => 'application/octet-stream', - 'Content-Length' => 8, - 'Content-Range' => 'bytes 5-12/13', - 'Last-Modified' => HTTP\Util::toHTTPDate(new \DateTime('@' . filemtime($this->tempDir . '/test.txt'))), - 'ETag' => '"' . md5(file_get_contents(SABRE_TEMPDIR . '/test.txt')). '"', - ), - $this->response->headers - ); - - $this->assertEquals('HTTP/1.1 206 Partial Content',$this->response->status); - $this->assertEquals('contents', stream_get_contents($this->response->body)); + $this->assertEquals(206, $response->getStatus()); + $this->assertEquals('contents', $response->getBodyAsString()); } @@ -105,17 +113,10 @@ class ServerRangeTest extends AbstractServer{ */ function testTooHighRange() { - $serverVars = array( - 'REQUEST_URI' => '/test.txt', - 'REQUEST_METHOD' => 'GET', - 'HTTP_RANGE' => 'bytes=100-200', - ); + $request = new HTTP\Request('GET', '/files/test.txt', ['Range' => 'bytes=100-200']); + $response = $this->request($request); - $request = new HTTP\Request($serverVars); - $this->server->httpRequest = ($request); - $this->server->exec(); - - $this->assertEquals('HTTP/1.1 416 Requested Range Not Satisfiable',$this->response->status); + $this->assertEquals(416, $response->getStatus()); } @@ -124,151 +125,138 @@ class ServerRangeTest extends AbstractServer{ */ function testCrazyRange() { - $serverVars = array( - 'REQUEST_URI' => '/test.txt', - 'REQUEST_METHOD' => 'GET', - 'HTTP_RANGE' => 'bytes=8-4', - ); + $request = new HTTP\Request('GET', '/files/test.txt', ['Range' => 'bytes=8-4']); + $response = $this->request($request); - $request = new HTTP\Request($serverVars); - $this->server->httpRequest = ($request); - $this->server->exec(); + $this->assertEquals(416, $response->getStatus()); - $this->assertEquals('HTTP/1.1 416 Requested Range Not Satisfiable',$this->response->status); + } + + function testNonSeekableStream() { + + $request = new HTTP\Request('GET', '/files/no-seeking.txt', ['Range' => 'bytes=2-5']); + $response = $this->request($request); + + $this->assertEquals(206, $response->getStatus(), $response); + $this->assertEquals([ + 'X-Sabre-Version' => [Version::VERSION], + 'Content-Type' => ['application/octet-stream'], + 'Content-Length' => [4], + 'Content-Range' => ['bytes 2-5/12'], + // 'ETag' => ['"' . md5('Test contents') . '"'], + 'Last-Modified' => [$this->lastModified], + ], + $response->getHeaders() + ); + + $this->assertEquals('st c', $response->getBodyAsString()); } /** * @depends testRange - * @covers \Sabre\DAV\Server::httpGet */ function testIfRangeEtag() { - $node = $this->server->tree->getNodeForPath('test.txt'); - - $serverVars = array( - 'REQUEST_URI' => '/test.txt', - 'REQUEST_METHOD' => 'GET', - 'HTTP_RANGE' => 'bytes=2-5', - 'HTTP_IF_RANGE' => $node->getETag(), + $request = new HTTP\Request('GET', '/files/test.txt', [ + 'Range' => 'bytes=2-5', + 'If-Range' => '"' . md5('Test contents') . '"', + ]); + $response = $this->request($request); + + $this->assertEquals([ + 'X-Sabre-Version' => [Version::VERSION], + 'Content-Type' => ['application/octet-stream'], + 'Content-Length' => [4], + 'Content-Range' => ['bytes 2-5/13'], + 'ETag' => ['"' . md5('Test contents') . '"'], + 'Last-Modified' => [$this->lastModified], + ], + $response->getHeaders() ); - $request = new HTTP\Request($serverVars); - $this->server->httpRequest = ($request); - $this->server->exec(); - - $this->assertEquals(array( - 'Content-Type' => 'application/octet-stream', - 'Content-Length' => 4, - 'Content-Range' => 'bytes 2-5/13', - 'Last-Modified' => HTTP\Util::toHTTPDate(new \DateTime('@' . filemtime($this->tempDir . '/test.txt'))), - 'ETag' => '"' . md5(file_get_contents(SABRE_TEMPDIR . '/test.txt')) . '"', - ), - $this->response->headers - ); - - $this->assertEquals('HTTP/1.1 206 Partial Content',$this->response->status); - $this->assertEquals('st c', stream_get_contents($this->response->body)); + $this->assertEquals(206, $response->getStatus()); + $this->assertEquals('st c', $response->getBodyAsString()); } /** - * @depends testRange - * @covers \Sabre\DAV\Server::httpGet + * @depends testIfRangeEtag */ function testIfRangeEtagIncorrect() { - $node = $this->server->tree->getNodeForPath('test.txt'); - - $serverVars = array( - 'REQUEST_URI' => '/test.txt', - 'REQUEST_METHOD' => 'GET', - 'HTTP_RANGE' => 'bytes=2-5', - 'HTTP_IF_RANGE' => $node->getETag() . 'blabla', + $request = new HTTP\Request('GET', '/files/test.txt', [ + 'Range' => 'bytes=2-5', + 'If-Range' => '"foobar"', + ]); + $response = $this->request($request); + + $this->assertEquals([ + 'X-Sabre-Version' => [Version::VERSION], + 'Content-Type' => ['application/octet-stream'], + 'Content-Length' => [13], + 'ETag' => ['"' . md5('Test contents') . '"'], + 'Last-Modified' => [$this->lastModified], + ], + $response->getHeaders() ); - $request = new HTTP\Request($serverVars); - $this->server->httpRequest = ($request); - $this->server->exec(); - - $this->assertEquals(array( - 'Content-Type' => 'application/octet-stream', - 'Content-Length' => 13, - 'Last-Modified' => HTTP\Util::toHTTPDate(new \DateTime('@' . filemtime($this->tempDir . '/test.txt'))), - 'ETag' => '"' . md5(file_get_contents(SABRE_TEMPDIR . '/test.txt')) . '"', - ), - $this->response->headers - ); - - $this->assertEquals('HTTP/1.1 200 OK',$this->response->status); - $this->assertEquals('Test contents', stream_get_contents($this->response->body)); + $this->assertEquals(200, $response->getStatus()); + $this->assertEquals('Test contents', $response->getBodyAsString()); } /** - * @depends testRange - * @covers \Sabre\DAV\Server::httpGet + * @depends testIfRangeEtag */ function testIfRangeModificationDate() { - $node = $this->server->tree->getNodeForPath('test.txt'); - - $serverVars = array( - 'REQUEST_URI' => '/test.txt', - 'REQUEST_METHOD' => 'GET', - 'HTTP_RANGE' => 'bytes=2-5', - 'HTTP_IF_RANGE' => 'tomorrow', + $request = new HTTP\Request('GET', '/files/test.txt', [ + 'Range' => 'bytes=2-5', + 'If-Range' => 'tomorrow', + ]); + $response = $this->request($request); + + $this->assertEquals([ + 'X-Sabre-Version' => [Version::VERSION], + 'Content-Type' => ['application/octet-stream'], + 'Content-Length' => [4], + 'Content-Range' => ['bytes 2-5/13'], + 'ETag' => ['"' . md5('Test contents') . '"'], + 'Last-Modified' => [$this->lastModified], + ], + $response->getHeaders() ); - $request = new HTTP\Request($serverVars); - $this->server->httpRequest = ($request); - $this->server->exec(); - - $this->assertEquals(array( - 'Content-Type' => 'application/octet-stream', - 'Content-Length' => 4, - 'Content-Range' => 'bytes 2-5/13', - 'Last-Modified' => HTTP\Util::toHTTPDate(new \DateTime('@' . filemtime($this->tempDir . '/test.txt'))), - 'ETag' => '"' . md5(file_get_contents(SABRE_TEMPDIR . '/test.txt')) . '"', - ), - $this->response->headers - ); - - $this->assertEquals('HTTP/1.1 206 Partial Content',$this->response->status); - $this->assertEquals('st c', stream_get_contents($this->response->body)); + $this->assertEquals(206, $response->getStatus()); + $this->assertEquals('st c', $response->getBodyAsString()); } /** - * @depends testRange - * @covers \Sabre\DAV\Server::httpGet + * @depends testIfRangeModificationDate */ function testIfRangeModificationDateModified() { - $node = $this->server->tree->getNodeForPath('test.txt'); - - $serverVars = array( - 'REQUEST_URI' => '/test.txt', - 'REQUEST_METHOD' => 'GET', - 'HTTP_RANGE' => 'bytes=2-5', - 'HTTP_IF_RANGE' => '-2 years', + $request = new HTTP\Request('GET', '/files/test.txt', [ + 'Range' => 'bytes=2-5', + 'If-Range' => '-2 years', + ]); + $response = $this->request($request); + + $this->assertEquals([ + 'X-Sabre-Version' => [Version::VERSION], + 'Content-Type' => ['application/octet-stream'], + 'Content-Length' => [13], + 'ETag' => ['"' . md5('Test contents') . '"'], + 'Last-Modified' => [$this->lastModified], + ], + $response->getHeaders() ); - $request = new HTTP\Request($serverVars); - $this->server->httpRequest = ($request); - $this->server->exec(); - - $this->assertEquals(array( - 'Content-Type' => 'application/octet-stream', - 'Content-Length' => 13, - 'Last-Modified' => HTTP\Util::toHTTPDate(new \DateTime('@' . filemtime($this->tempDir . '/test.txt'))), - 'ETag' => '"' . md5(file_get_contents(SABRE_TEMPDIR . '/test.txt')) . '"', - ), - $this->response->headers - ); - - $this->assertEquals('HTTP/1.1 200 OK',$this->response->status); - $this->assertEquals('Test contents', stream_get_contents($this->response->body)); + $this->assertEquals(200, $response->getStatus()); + $this->assertEquals('Test contents', $response->getBodyAsString()); } + } diff --git a/vendor/sabre/dav/tests/Sabre/DAV/ServerSimpleTest.php b/vendor/sabre/dav/tests/Sabre/DAV/ServerSimpleTest.php index 21e0ab2ea..66dde9db8 100644 --- a/vendor/sabre/dav/tests/Sabre/DAV/ServerSimpleTest.php +++ b/vendor/sabre/dav/tests/Sabre/DAV/ServerSimpleTest.php @@ -4,17 +4,13 @@ namespace Sabre\DAV; use Sabre\HTTP; -require_once 'Sabre/HTTP/ResponseMock.php'; -require_once 'Sabre/DAV/AbstractServer.php'; -require_once 'Sabre/DAV/Exception.php'; - class ServerSimpleTest extends AbstractServer{ function testConstructArray() { - $nodes = array( + $nodes = [ new SimpleCollection('hello') - ); + ]; $server = new Server($nodes); $this->assertEquals($nodes[0], $server->tree->getNodeForPath('hello')); @@ -26,10 +22,10 @@ class ServerSimpleTest extends AbstractServer{ */ function testConstructIncorrectObj() { - $nodes = array( + $nodes = [ new SimpleCollection('hello'), new \STDClass(), - ); + ]; $server = new Server($nodes); @@ -44,253 +40,108 @@ class ServerSimpleTest extends AbstractServer{ } - function testGet() { - - $serverVars = array( - 'REQUEST_URI' => '/test.txt', - 'REQUEST_METHOD' => 'GET', - ); - - $request = new HTTP\Request($serverVars); - $this->server->httpRequest = ($request); - $this->server->exec(); - - $this->assertEquals(array( - 'Content-Type' => 'application/octet-stream', - 'Content-Length' => 13, - 'Last-Modified' => HTTP\Util::toHTTPDate(new \DateTime('@' . filemtime($this->tempDir . '/test.txt'))), - ), - $this->response->headers - ); - - $this->assertEquals('HTTP/1.1 200 OK',$this->response->status); - $this->assertEquals('Test contents', stream_get_contents($this->response->body)); - - } - function testGetHttp10() { - - $serverVars = array( - 'REQUEST_URI' => '/test.txt', - 'REQUEST_METHOD' => 'GET', - 'SERVER_PROTOCOL' => 'HTTP/1.0', - ); - - $request = new HTTP\Request($serverVars); - $this->server->httpRequest = ($request); - $this->server->exec(); - - $this->assertEquals(array( - 'Content-Type' => 'application/octet-stream', - 'Content-Length' => 13, - 'Last-Modified' => HTTP\Util::toHTTPDate(new \DateTime('@' . filemtime($this->tempDir . '/test.txt'))), - ), - $this->response->headers - ); - - $this->assertEquals('HTTP/1.0 200 OK',$this->response->status); - $this->assertEquals('Test contents', stream_get_contents($this->response->body)); - - } - - function testGetDoesntExist() { - - $serverVars = array( - 'REQUEST_URI' => '/test.txt_randomblbla', - 'REQUEST_METHOD' => 'GET', - ); - - $request = new HTTP\Request($serverVars); - $this->server->httpRequest = ($request); - $this->server->exec(); - $this->assertEquals('HTTP/1.1 404 Not Found',$this->response->status); - - } - - function testGetDoesntExist2() { - - $serverVars = array( - 'REQUEST_URI' => '/test.txt/randomblbla', - 'REQUEST_METHOD' => 'GET', - ); - - $request = new HTTP\Request($serverVars); - $this->server->httpRequest = ($request); - $this->server->exec(); - $this->assertEquals('HTTP/1.1 404 Not Found',$this->response->status); - - } - - /** - * This test should have the exact same result as testGet. - * - * The idea is that double slashes // are converted to single ones / - * - */ - function testGetDoubleSlash() { - - $serverVars = array( - 'REQUEST_URI' => '//test.txt', - 'REQUEST_METHOD' => 'GET', - ); + function testOptions() { - $request = new HTTP\Request($serverVars); - $this->server->httpRequest = ($request); + $request = new HTTP\Request('OPTIONS', '/'); + $this->server->httpRequest = $request; $this->server->exec(); - $this->assertEquals(array( - 'Content-Type' => 'application/octet-stream', - 'Content-Length' => 13, - 'Last-Modified' => HTTP\Util::toHTTPDate(new \DateTime('@' . filemtime($this->tempDir . '/test.txt'))), - ), - $this->response->headers - ); - - $this->assertEquals('HTTP/1.1 200 OK',$this->response->status); - $this->assertEquals('Test contents', stream_get_contents($this->response->body)); - - } - - - function testHEAD() { - - $serverVars = array( - 'REQUEST_URI' => '/test.txt', - 'REQUEST_METHOD' => 'HEAD', - ); - - $request = new HTTP\Request($serverVars); - $this->server->httpRequest = ($request); - $this->server->exec(); + $this->assertEquals([ + 'DAV' => ['1, 3, extended-mkcol'], + 'MS-Author-Via' => ['DAV'], + 'Allow' => ['OPTIONS, GET, HEAD, DELETE, PROPFIND, PUT, PROPPATCH, COPY, MOVE, REPORT'], + 'Accept-Ranges' => ['bytes'], + 'Content-Length' => ['0'], + 'X-Sabre-Version' => [Version::VERSION], + ], $this->response->getHeaders()); - $this->assertEquals(array( - 'Content-Type' => 'application/octet-stream', - 'Content-Length' => 13, - 'Last-Modified' => HTTP\Util::toHTTPDate(new \DateTime('@' . filemtime($this->tempDir . '/test.txt'))), - ), - $this->response->headers - ); - - $this->assertEquals('HTTP/1.1 200 OK',$this->response->status); + $this->assertEquals(200, $this->response->status); $this->assertEquals('', $this->response->body); } - function testOptions() { + function testOptionsUnmapped() { - $serverVars = array( - 'REQUEST_URI' => '/', - 'REQUEST_METHOD' => 'OPTIONS', - ); + $request = new HTTP\Request('OPTIONS', '/unmapped'); + $this->server->httpRequest = $request; - $request = new HTTP\Request($serverVars); - $this->server->httpRequest = ($request); $this->server->exec(); - $this->assertEquals(array( - 'DAV' => '1, 3, extended-mkcol', - 'MS-Author-Via' => 'DAV', - 'Allow' => 'OPTIONS, GET, HEAD, DELETE, PROPFIND, PUT, PROPPATCH, COPY, MOVE, REPORT', - 'Accept-Ranges' => 'bytes', - 'Content-Length' => '0', - 'X-Sabre-Version' => Version::VERSION, - ),$this->response->headers); + $this->assertEquals([ + 'DAV' => ['1, 3, extended-mkcol'], + 'MS-Author-Via' => ['DAV'], + 'Allow' => ['OPTIONS, GET, HEAD, DELETE, PROPFIND, PUT, PROPPATCH, COPY, MOVE, REPORT, MKCOL'], + 'Accept-Ranges' => ['bytes'], + 'Content-Length' => ['0'], + 'X-Sabre-Version' => [Version::VERSION], + ], $this->response->getHeaders()); - $this->assertEquals('HTTP/1.1 200 OK',$this->response->status); + $this->assertEquals(200, $this->response->status); $this->assertEquals('', $this->response->body); - } + function testNonExistantMethod() { - $serverVars = array( + $serverVars = [ 'REQUEST_URI' => '/', 'REQUEST_METHOD' => 'BLABLA', - ); + ]; - $request = new HTTP\Request($serverVars); + $request = HTTP\Sapi::createFromServerArray($serverVars); $this->server->httpRequest = ($request); $this->server->exec(); - $this->assertEquals(array( - 'Content-Type' => 'application/xml; charset=utf-8', - ),$this->response->headers); + $this->assertEquals([ + 'X-Sabre-Version' => [Version::VERSION], + 'Content-Type' => ['application/xml; charset=utf-8'], + ], $this->response->getHeaders()); - $this->assertEquals('HTTP/1.1 501 Not Implemented',$this->response->status); + $this->assertEquals(501, $this->response->status); } - function testGETOnCollection() { - - $serverVars = array( - 'REQUEST_URI' => '/', - 'REQUEST_METHOD' => 'GET', - ); - - $request = new HTTP\Request($serverVars); - $this->server->httpRequest = ($request); - $this->server->exec(); - - $this->assertEquals(array( - 'Content-Type' => 'application/xml; charset=utf-8', - ),$this->response->headers); - - $this->assertEquals('HTTP/1.1 501 Not Implemented',$this->response->status); - - } - - function testHEADOnCollection() { - - $serverVars = array( - 'REQUEST_URI' => '/', - 'REQUEST_METHOD' => 'HEAD', - ); - - $request = new HTTP\Request($serverVars); - $this->server->httpRequest = ($request); - $this->server->exec(); - - $this->assertEquals('HTTP/1.1 200 OK',$this->response->status); - - } - function testBaseUri() { - $serverVars = array( + $serverVars = [ 'REQUEST_URI' => '/blabla/test.txt', 'REQUEST_METHOD' => 'GET', - ); + ]; + $filename = $this->tempDir . '/test.txt'; - $request = new HTTP\Request($serverVars); + $request = HTTP\Sapi::createFromServerArray($serverVars); $this->server->setBaseUri('/blabla/'); - $this->assertEquals('/blabla/',$this->server->getBaseUri()); + $this->assertEquals('/blabla/', $this->server->getBaseUri()); $this->server->httpRequest = ($request); $this->server->exec(); - $this->assertEquals(array( - 'Content-Type' => 'application/octet-stream', - 'Content-Length' => 13, - 'Last-Modified' => HTTP\Util::toHTTPDate(new \DateTime('@' . filemtime($this->tempDir . '/test.txt'))), - ), - $this->response->headers + $this->assertEquals([ + 'X-Sabre-Version' => [Version::VERSION], + 'Content-Type' => ['application/octet-stream'], + 'Content-Length' => [13], + 'Last-Modified' => [HTTP\Util::toHTTPDate(new \DateTime('@' . filemtime($filename)))], + 'ETag' => ['"' . sha1(fileinode($filename) . filesize($filename) . filemtime($filename)) . '"'], + ], + $this->response->getHeaders() ); - $this->assertEquals('HTTP/1.1 200 OK',$this->response->status); + $this->assertEquals(200, $this->response->status); $this->assertEquals('Test contents', stream_get_contents($this->response->body)); } function testBaseUriAddSlash() { - $tests = array( + $tests = [ '/' => '/', '/foo' => '/foo/', '/foo/' => '/foo/', '/foo/bar' => '/foo/bar/', '/foo/bar/' => '/foo/bar/', - ); + ]; - foreach($tests as $test=>$result) { + foreach ($tests as $test => $result) { $this->server->setBaseUri($test); $this->assertEquals($result, $this->server->getBaseUri()); @@ -301,25 +152,25 @@ class ServerSimpleTest extends AbstractServer{ function testCalculateUri() { - $uris = array( + $uris = [ 'http://www.example.org/root/somepath', '/root/somepath', '/root/somepath/', - ); + ]; $this->server->setBaseUri('/root/'); - foreach($uris as $uri) { + foreach ($uris as $uri) { - $this->assertEquals('somepath',$this->server->calculateUri($uri)); + $this->assertEquals('somepath', $this->server->calculateUri($uri)); } $this->server->setBaseUri('/root'); - foreach($uris as $uri) { + foreach ($uris as $uri) { - $this->assertEquals('somepath',$this->server->calculateUri($uri)); + $this->assertEquals('somepath', $this->server->calculateUri($uri)); } @@ -329,72 +180,60 @@ class ServerSimpleTest extends AbstractServer{ function testCalculateUriSpecialChars() { - $uris = array( + $uris = [ 'http://www.example.org/root/%C3%A0fo%C3%B3', '/root/%C3%A0fo%C3%B3', '/root/%C3%A0fo%C3%B3/' - ); + ]; $this->server->setBaseUri('/root/'); - foreach($uris as $uri) { + foreach ($uris as $uri) { - $this->assertEquals("\xc3\xa0fo\xc3\xb3",$this->server->calculateUri($uri)); + $this->assertEquals("\xc3\xa0fo\xc3\xb3", $this->server->calculateUri($uri)); } $this->server->setBaseUri('/root'); - foreach($uris as $uri) { + foreach ($uris as $uri) { - $this->assertEquals("\xc3\xa0fo\xc3\xb3",$this->server->calculateUri($uri)); + $this->assertEquals("\xc3\xa0fo\xc3\xb3", $this->server->calculateUri($uri)); } $this->server->setBaseUri('/'); - foreach($uris as $uri) { + foreach ($uris as $uri) { - $this->assertEquals("root/\xc3\xa0fo\xc3\xb3",$this->server->calculateUri($uri)); + $this->assertEquals("root/\xc3\xa0fo\xc3\xb3", $this->server->calculateUri($uri)); } } - function testBaseUriCheck() { - - $uris = array( - 'http://www.example.org/root/somepath', - '/root/somepath', - '/root/somepath/' - ); - - try { - - $this->server->setBaseUri('root/'); - $this->server->calculateUri('/root/testuri'); - - $this->fail('Expected an exception'); - - } catch (Exception\Forbidden $e) { + /** + * @expectedException \Sabre\DAV\Exception\Forbidden + */ + function testCalculateUriBreakout() { - // This was expected + $uri = '/path1/'; - } + $this->server->setBaseUri('/path2/'); + $this->server->calculateUri($uri); } /** - * @covers \Sabre\DAV\Server::guessBaseUri */ function testGuessBaseUri() { - $serverVars = array( + $serverVars = [ 'REQUEST_URI' => '/index.php/root', 'PATH_INFO' => '/root', - ); + ]; - $httpRequest = new HTTP\Request($serverVars); + $httpRequest = HTTP\Sapi::createFromServerArray($serverVars); $server = new Server(); $server->httpRequest = $httpRequest; @@ -404,16 +243,15 @@ class ServerSimpleTest extends AbstractServer{ /** * @depends testGuessBaseUri - * @covers Sabre\DAV\Server::guessBaseUri */ function testGuessBaseUriPercentEncoding() { - $serverVars = array( + $serverVars = [ 'REQUEST_URI' => '/index.php/dir/path2/path%20with%20spaces', 'PATH_INFO' => '/dir/path2/path with spaces', - ); + ]; - $httpRequest = new HTTP\Request($serverVars); + $httpRequest = HTTP\Sapi::createFromServerArray($serverVars); $server = new Server(); $server->httpRequest = $httpRequest; @@ -423,18 +261,17 @@ class ServerSimpleTest extends AbstractServer{ /** * @depends testGuessBaseUri - * @covers \Sabre\DAV\Server::guessBaseUri */ /* function testGuessBaseUriPercentEncoding2() { $this->markTestIncomplete('This behaviour is not yet implemented'); - $serverVars = array( + $serverVars = [ 'REQUEST_URI' => '/some%20directory+mixed/index.php/dir/path2/path%20with%20spaces', 'PATH_INFO' => '/dir/path2/path with spaces', - ); + ]; - $httpRequest = new HTTP\Request($serverVars); + $httpRequest = HTTP\Sapi::createFromServerArray($serverVars); $server = new Server(); $server->httpRequest = $httpRequest; @@ -444,12 +281,12 @@ class ServerSimpleTest extends AbstractServer{ function testGuessBaseUri2() { - $serverVars = array( + $serverVars = [ 'REQUEST_URI' => '/index.php/root/', 'PATH_INFO' => '/root/', - ); + ]; - $httpRequest = new HTTP\Request($serverVars); + $httpRequest = HTTP\Sapi::createFromServerArray($serverVars); $server = new Server(); $server->httpRequest = $httpRequest; @@ -459,11 +296,11 @@ class ServerSimpleTest extends AbstractServer{ function testGuessBaseUriNoPathInfo() { - $serverVars = array( + $serverVars = [ 'REQUEST_URI' => '/index.php/root', - ); + ]; - $httpRequest = new HTTP\Request($serverVars); + $httpRequest = HTTP\Sapi::createFromServerArray($serverVars); $server = new Server(); $server->httpRequest = $httpRequest; @@ -473,11 +310,11 @@ class ServerSimpleTest extends AbstractServer{ function testGuessBaseUriNoPathInfo2() { - $serverVars = array( + $serverVars = [ 'REQUEST_URI' => '/a/b/c/test.php', - ); + ]; - $httpRequest = new HTTP\Request($serverVars); + $httpRequest = HTTP\Sapi::createFromServerArray($serverVars); $server = new Server(); $server->httpRequest = $httpRequest; @@ -487,17 +324,16 @@ class ServerSimpleTest extends AbstractServer{ /** - * @covers \Sabre\DAV\Server::guessBaseUri * @depends testGuessBaseUri */ function testGuessBaseUriQueryString() { - $serverVars = array( + $serverVars = [ 'REQUEST_URI' => '/index.php/root?query_string=blabla', 'PATH_INFO' => '/root', - ); + ]; - $httpRequest = new HTTP\Request($serverVars); + $httpRequest = HTTP\Sapi::createFromServerArray($serverVars); $server = new Server(); $server->httpRequest = $httpRequest; @@ -506,18 +342,17 @@ class ServerSimpleTest extends AbstractServer{ } /** - * @covers \Sabre\DAV\Server::guessBaseUri * @depends testGuessBaseUri * @expectedException \Sabre\DAV\Exception */ function testGuessBaseUriBadConfig() { - $serverVars = array( + $serverVars = [ 'REQUEST_URI' => '/index.php/root/heyyy', 'PATH_INFO' => '/root', - ); + ]; - $httpRequest = new HTTP\Request($serverVars); + $httpRequest = HTTP\Sapi::createFromServerArray($serverVars); $server = new Server(); $server->httpRequest = $httpRequest; @@ -527,25 +362,25 @@ class ServerSimpleTest extends AbstractServer{ function testTriggerException() { - $serverVars = array( - 'REQUEST_URI' => '/', + $serverVars = [ + 'REQUEST_URI' => '/', 'REQUEST_METHOD' => 'FOO', - ); + ]; - $httpRequest = new HTTP\Request($serverVars); + $httpRequest = HTTP\Sapi::createFromServerArray($serverVars); $this->server->httpRequest = $httpRequest; - $this->server->subscribeEvent('beforeMethod',array($this,'exceptionTrigger')); + $this->server->on('beforeMethod', [$this, 'exceptionTrigger']); $this->server->exec(); - $this->assertEquals(array( - 'Content-Type' => 'application/xml; charset=utf-8', - ),$this->response->headers); + $this->assertEquals([ + 'Content-Type' => ['application/xml; charset=utf-8'], + ], $this->response->getHeaders()); - $this->assertEquals('HTTP/1.1 500 Internal Server Error',$this->response->status); + $this->assertEquals(500, $this->response->status); } - function exceptionTrigger() { + function exceptionTrigger($request, $response) { throw new Exception('Hola'); @@ -553,54 +388,56 @@ class ServerSimpleTest extends AbstractServer{ function testReportNotFound() { - $serverVars = array( + $serverVars = [ 'REQUEST_URI' => '/', 'REQUEST_METHOD' => 'REPORT', - ); + ]; - $request = new HTTP\Request($serverVars); + $request = HTTP\Sapi::createFromServerArray($serverVars); $this->server->httpRequest = ($request); $this->server->httpRequest->setBody('<?xml version="1.0"?><bla:myreport xmlns:bla="http://www.rooftopsolutions.nl/NS"></bla:myreport>'); $this->server->exec(); - $this->assertEquals(array( - 'Content-Type' => 'application/xml; charset=utf-8', - ), - $this->response->headers + $this->assertEquals([ + 'X-Sabre-Version' => [Version::VERSION], + 'Content-Type' => ['application/xml; charset=utf-8'], + ], + $this->response->getHeaders() ); - $this->assertEquals('HTTP/1.1 403 Forbidden',$this->response->status,'We got an incorrect status back. Full response body follows: ' . $this->response->body); + $this->assertEquals(415, $this->response->status, 'We got an incorrect status back. Full response body follows: ' . $this->response->body); } function testReportIntercepted() { - $serverVars = array( + $serverVars = [ 'REQUEST_URI' => '/', 'REQUEST_METHOD' => 'REPORT', - ); + ]; - $request = new HTTP\Request($serverVars); + $request = HTTP\Sapi::createFromServerArray($serverVars); $this->server->httpRequest = ($request); $this->server->httpRequest->setBody('<?xml version="1.0"?><bla:myreport xmlns:bla="http://www.rooftopsolutions.nl/NS"></bla:myreport>'); - $this->server->subscribeEvent('report',array($this,'reportHandler')); + $this->server->on('report', [$this, 'reportHandler']); $this->server->exec(); - $this->assertEquals(array( - 'testheader' => 'testvalue', - ), - $this->response->headers + $this->assertEquals([ + 'X-Sabre-Version' => [Version::VERSION], + 'testheader' => ['testvalue'], + ], + $this->response->getHeaders() ); - $this->assertEquals('HTTP/1.1 418 I\'m a teapot',$this->response->status,'We got an incorrect status back. Full response body follows: ' . $this->response->body); + $this->assertEquals(418, $this->response->status, 'We got an incorrect status back. Full response body follows: ' . $this->response->body); } - function reportHandler($reportName) { + function reportHandler($reportName, $result, $path) { - if ($reportName=='{http://www.rooftopsolutions.nl/NS}myreport') { - $this->server->httpResponse->sendStatus(418); - $this->server->httpResponse->setHeader('testheader','testvalue'); + if ($reportName == '{http://www.rooftopsolutions.nl/NS}myreport') { + $this->server->httpResponse->setStatus(418); + $this->server->httpResponse->setHeader('testheader', 'testvalue'); return false; } else return; @@ -609,16 +446,29 @@ class ServerSimpleTest extends AbstractServer{ function testGetPropertiesForChildren() { - $result = $this->server->getPropertiesForChildren('',array( + $result = $this->server->getPropertiesForChildren('', [ '{DAV:}getcontentlength', - )); + ]); - $expected = array( - 'test.txt' => array('{DAV:}getcontentlength' => 13), - 'dir/' => array(), - ); + $expected = [ + 'test.txt' => ['{DAV:}getcontentlength' => 13], + 'dir/' => [], + ]; + + $this->assertEquals($expected, $result); + + } - $this->assertEquals($expected,$result); + /** + * There are certain cases where no HTTP status may be set. We need to + * intercept these and set it to a default error message. + */ + function testNoHTTPSTatusSet() { + + $this->server->on('method:GET', function() { return false; }, 1); + $this->server->httpRequest = new HTTP\Request('GET', '/'); + $this->server->exec(); + $this->assertEquals(500, $this->response->getStatus()); } diff --git a/vendor/sabre/dav/tests/Sabre/DAV/ServerUpdatePropertiesTest.php b/vendor/sabre/dav/tests/Sabre/DAV/ServerUpdatePropertiesTest.php index a73e8d13f..7fde11b22 100644 --- a/vendor/sabre/dav/tests/Sabre/DAV/ServerUpdatePropertiesTest.php +++ b/vendor/sabre/dav/tests/Sabre/DAV/ServerUpdatePropertiesTest.php @@ -17,10 +17,7 @@ class ServerUpdatePropertiesTest extends \PHPUnit_Framework_TestCase { )); $expected = array( - 'href' => 'foo', - '403' => array( - '{DAV:}foo' => null, - ), + '{DAV:}foo' => 403, ); $this->assertEquals($expected, $result); @@ -33,19 +30,17 @@ class ServerUpdatePropertiesTest extends \PHPUnit_Framework_TestCase { ); $server = new Server($tree); + $server->on('propPatch', function($path, PropPatch $propPatch) { + $propPatch->handleRemaining(function() { return true; }); + }); $result = $server->updateProperties('foo', array( '{DAV:}getetag' => 'bla', '{DAV:}foo' => 'bar' )); $expected = array( - 'href' => 'foo', - '403' => array( - '{DAV:}getetag' => null, - ), - '424' => array( - '{DAV:}foo' => null, - ), + '{DAV:}getetag' => 403, + '{DAV:}foo' => 424, ); $this->assertEquals($expected, $result); @@ -57,7 +52,10 @@ class ServerUpdatePropertiesTest extends \PHPUnit_Framework_TestCase { new SimpleCollection('foo'), ); $server = new Server($tree); - $server->subscribeEvent('updateProperties', array($this,'updatepropfail')); + $server->on('propPatch', function($path, PropPatch $propPatch) { + $propPatch->setResultCode('{DAV:}foo', 404); + $propPatch->handleRemaining(function() { return true; }); + }); $result = $server->updateProperties('foo', array( '{DAV:}foo' => 'bar', @@ -65,36 +63,29 @@ class ServerUpdatePropertiesTest extends \PHPUnit_Framework_TestCase { )); $expected = array( - 'href' => 'foo', - '404' => array( - '{DAV:}foo' => null, - ), - '424' => array( - '{DAV:}foo2' => null, - ), + '{DAV:}foo' => 404, + '{DAV:}foo2' => 424, ); $this->assertEquals($expected, $result); } - function updatePropFail(&$propertyDelta, &$result, $node) { - - $result[404] = array( - '{DAV:}foo' => null, - ); - unset($propertyDelta['{DAV:}foo']); - return false; - - } - - function testUpdatePropertiesEventSuccess() { $tree = array( new SimpleCollection('foo'), ); $server = new Server($tree); - $server->subscribeEvent('updateProperties', array($this,'updatepropsuccess')); + $server->on('propPatch', function($path, PropPatch $propPatch) { + + $propPatch->handle(['{DAV:}foo', '{DAV:}foo2'], function() { + return [ + '{DAV:}foo' => 200, + '{DAV:}foo2' => 201, + ]; + }); + + }); $result = $server->updateProperties('foo', array( '{DAV:}foo' => 'bar', @@ -102,29 +93,11 @@ class ServerUpdatePropertiesTest extends \PHPUnit_Framework_TestCase { )); $expected = array( - 'href' => 'foo', - '200' => array( - '{DAV:}foo' => null, - ), - '201' => array( - '{DAV:}foo2' => null, - ), + '{DAV:}foo' => 200, + '{DAV:}foo2' => 201, ); $this->assertEquals($expected, $result); } - function updatePropSuccess(&$propertyDelta, &$result, $node) { - - $result[200] = array( - '{DAV:}foo' => null, - ); - $result[201] = array( - '{DAV:}foo2' => null, - ); - unset($propertyDelta['{DAV:}foo']); - unset($propertyDelta['{DAV:}foo2']); - return; - - } } diff --git a/vendor/sabre/dav/tests/Sabre/DAV/SimpleFileTest.php b/vendor/sabre/dav/tests/Sabre/DAV/SimpleFileTest.php index de8b05734..9b083b998 100644 --- a/vendor/sabre/dav/tests/Sabre/DAV/SimpleFileTest.php +++ b/vendor/sabre/dav/tests/Sabre/DAV/SimpleFileTest.php @@ -10,8 +10,8 @@ class SimpleFileTest extends \PHPUnit_Framework_TestCase { $this->assertEquals('filename.txt', $file->getName()); $this->assertEquals('contents', $file->get()); - $this->assertEquals('8', $file->getSize()); - $this->assertEquals('"' . md5('contents') . '"', $file->getETag()); + $this->assertEquals(8, $file->getSize()); + $this->assertEquals('"' . sha1('contents') . '"', $file->getETag()); $this->assertEquals('text/plain', $file->getContentType()); } diff --git a/vendor/sabre/dav/tests/Sabre/DAV/TemporaryFileFilterTest.php b/vendor/sabre/dav/tests/Sabre/DAV/TemporaryFileFilterTest.php index d136eeb17..7122f4a01 100644 --- a/vendor/sabre/dav/tests/Sabre/DAV/TemporaryFileFilterTest.php +++ b/vendor/sabre/dav/tests/Sabre/DAV/TemporaryFileFilterTest.php @@ -16,19 +16,14 @@ class TemporaryFileFilterTest extends AbstractServer { function testPutNormal() { - $serverVars = array( - 'REQUEST_URI' => '/testput.txt', - 'REQUEST_METHOD' => 'PUT', - ); + $request = new HTTP\Request('PUT', '/testput.txt', [], 'Testing new file'); - $request = new HTTP\Request($serverVars); - $request->setBody('Testing new file'); $this->server->httpRequest = ($request); $this->server->exec(); $this->assertEquals('', $this->response->body); - $this->assertEquals('HTTP/1.1 201 Created',$this->response->status); - $this->assertEquals('0', $this->response->headers['Content-Length']); + $this->assertEquals(201, $this->response->status); + $this->assertEquals('0', $this->response->getHeader('Content-Length')); $this->assertEquals('Testing new file',file_get_contents(SABRE_TEMPDIR . '/testput.txt')); @@ -37,21 +32,16 @@ class TemporaryFileFilterTest extends AbstractServer { function testPutTemp() { // mimicking an OS/X resource fork - $serverVars = array( - 'REQUEST_URI' => '/._testput.txt', - 'REQUEST_METHOD' => 'PUT', - ); + $request = new HTTP\Request('PUT', '/._testput.txt', [], 'Testing new file'); - $request = new HTTP\Request($serverVars); - $request->setBody('Testing new file'); $this->server->httpRequest = ($request); $this->server->exec(); $this->assertEquals('', $this->response->body); - $this->assertEquals('HTTP/1.1 201 Created',$this->response->status); + $this->assertEquals(201, $this->response->status); $this->assertEquals(array( - 'X-Sabre-Temp' => 'true', - ),$this->response->headers); + 'X-Sabre-Temp' => ['true'], + ),$this->response->getHeaders()); $this->assertFalse(file_exists(SABRE_TEMPDIR . '/._testput.txt'),'._testput.txt should not exist in the regular file structure.'); @@ -60,70 +50,54 @@ class TemporaryFileFilterTest extends AbstractServer { function testPutTempIfNoneMatch() { // mimicking an OS/X resource fork - $serverVars = array( - 'REQUEST_URI' => '/._testput.txt', - 'REQUEST_METHOD' => 'PUT', - 'HTTP_IF_NONE_MATCH' => '*', - ); - - $request = new HTTP\Request($serverVars); - $request->setBody('Testing new file'); + $request = new HTTP\Request('PUT', '/._testput.txt', ['If-None-Match' => '*'], 'Testing new file'); + $this->server->httpRequest = ($request); $this->server->exec(); $this->assertEquals('', $this->response->body); - $this->assertEquals('HTTP/1.1 201 Created',$this->response->status); + $this->assertEquals(201, $this->response->status); $this->assertEquals(array( - 'X-Sabre-Temp' => 'true', - ),$this->response->headers); + 'X-Sabre-Temp' => ['true'], + ),$this->response->getHeaders()); $this->assertFalse(file_exists(SABRE_TEMPDIR . '/._testput.txt'),'._testput.txt should not exist in the regular file structure.'); $this->server->exec(); - $this->assertEquals('HTTP/1.1 412 Precondition failed',$this->response->status); + $this->assertEquals(412, $this->response->status); $this->assertEquals(array( - 'X-Sabre-Temp' => 'true', - 'Content-Type' => 'application/xml; charset=utf-8', - ),$this->response->headers); + 'X-Sabre-Temp' => ['true'], + 'Content-Type' => ['application/xml; charset=utf-8'], + ),$this->response->getHeaders()); } function testPutGet() { // mimicking an OS/X resource fork - $serverVars = array( - 'REQUEST_URI' => '/._testput.txt', - 'REQUEST_METHOD' => 'PUT', - ); - - $request = new HTTP\Request($serverVars); - $request->setBody('Testing new file'); + $request = new HTTP\Request('PUT', '/._testput.txt', [], 'Testing new file'); $this->server->httpRequest = ($request); $this->server->exec(); $this->assertEquals('', $this->response->body); - $this->assertEquals('HTTP/1.1 201 Created',$this->response->status); + $this->assertEquals(201, $this->response->status); $this->assertEquals(array( - 'X-Sabre-Temp' => 'true', - ),$this->response->headers); + 'X-Sabre-Temp' => ['true'], + ),$this->response->getHeaders()); - $serverVars = array( - 'REQUEST_URI' => '/._testput.txt', - 'REQUEST_METHOD' => 'GET', - ); + $request = new HTTP\Request('GET', '/._testput.txt'); - $request = new HTTP\Request($serverVars); - $this->server->httpRequest = ($request); + $this->server->httpRequest = $request; $this->server->exec(); - $this->assertEquals('HTTP/1.1 200 OK',$this->response->status); + $this->assertEquals(200, $this->response->status); $this->assertEquals(array( - 'X-Sabre-Temp' => 'true', - 'Content-Length' => 16, - 'Content-Type' => 'application/octet-stream', - ),$this->response->headers); + 'X-Sabre-Temp' => ['true'], + 'Content-Length' => [16], + 'Content-Type' => ['application/octet-stream'], + ),$this->response->getHeaders()); $this->assertEquals('Testing new file',stream_get_contents($this->response->body)); @@ -132,18 +106,12 @@ class TemporaryFileFilterTest extends AbstractServer { function testLockNonExistant() { mkdir(SABRE_TEMPDIR . '/locksdir'); - $locksBackend = new Locks\Backend\FS(SABRE_TEMPDIR . '/locksdir'); + $locksBackend = new Locks\Backend\File(SABRE_TEMPDIR . '/locks'); $locksPlugin = new Locks\Plugin($locksBackend); $this->server->addPlugin($locksPlugin); // mimicking an OS/X resource fork - $serverVars = array( - 'REQUEST_URI' => '/._testlock.txt', - 'REQUEST_METHOD' => 'LOCK', - ); - - $request = new HTTP\Request($serverVars); - + $request = new HTTP\Request('LOCK', '/._testput.txt'); $request->setBody('<?xml version="1.0"?> <D:lockinfo xmlns:D="DAV:"> <D:lockscope><D:exclusive/></D:lockscope> @@ -156,10 +124,10 @@ class TemporaryFileFilterTest extends AbstractServer { $this->server->httpRequest = ($request); $this->server->exec(); - $this->assertEquals('HTTP/1.1 201 Created',$this->response->status); - $this->assertEquals('application/xml; charset=utf-8',$this->response->headers['Content-Type']); - $this->assertTrue(preg_match('/^<opaquelocktoken:(.*)>$/',$this->response->headers['Lock-Token'])===1,'We did not get a valid Locktoken back (' . $this->response->headers['Lock-Token'] . ')'); - $this->assertEquals('true',$this->response->headers['X-Sabre-Temp']); + $this->assertEquals(201, $this->response->status); + $this->assertEquals('application/xml; charset=utf-8',$this->response->getHeader('Content-Type')); + $this->assertTrue(preg_match('/^<opaquelocktoken:(.*)>$/',$this->response->getHeader('Lock-Token'))===1,'We did not get a valid Locktoken back (' . $this->response->getHeader('Lock-Token') . ')'); + $this->assertEquals('true',$this->response->getHeader('X-Sabre-Temp')); $this->assertFalse(file_exists(SABRE_TEMPDIR . '/._testlock.txt'),'._testlock.txt should not exist in the regular file structure.'); @@ -168,35 +136,25 @@ class TemporaryFileFilterTest extends AbstractServer { function testPutDelete() { // mimicking an OS/X resource fork - $serverVars = array( - 'REQUEST_URI' => '/._testput.txt', - 'REQUEST_METHOD' => 'PUT', - ); + $request = new HTTP\Request('PUT', '/._testput.txt', [], 'Testing new file'); - $request = new HTTP\Request($serverVars); - $request->setBody('Testing new file'); - $this->server->httpRequest = ($request); + $this->server->httpRequest = $request; $this->server->exec(); $this->assertEquals('', $this->response->body); - $this->assertEquals('HTTP/1.1 201 Created',$this->response->status); + $this->assertEquals(201, $this->response->status); $this->assertEquals(array( - 'X-Sabre-Temp' => 'true', - ),$this->response->headers); - - $serverVars = array( - 'REQUEST_URI' => '/._testput.txt', - 'REQUEST_METHOD' => 'DELETE', - ); + 'X-Sabre-Temp' => ['true'], + ),$this->response->getHeaders()); - $request = new HTTP\Request($serverVars); - $this->server->httpRequest = ($request); + $request = new HTTP\Request('DELETE', '/._testput.txt'); + $this->server->httpRequest = $request; $this->server->exec(); - $this->assertEquals('HTTP/1.1 204 No Content',$this->response->status, "Incorrect status code received. Full body:\n". $this->response->body); + $this->assertEquals(204, $this->response->status, "Incorrect status code received. Full body:\n". $this->response->body); $this->assertEquals(array( - 'X-Sabre-Temp' => 'true', - ),$this->response->headers); + 'X-Sabre-Temp' => ['true'], + ),$this->response->getHeaders()); $this->assertEquals('',$this->response->body); @@ -205,37 +163,26 @@ class TemporaryFileFilterTest extends AbstractServer { function testPutPropfind() { // mimicking an OS/X resource fork - $serverVars = array( - 'REQUEST_URI' => '/._testput.txt', - 'REQUEST_METHOD' => 'PUT', - ); - - $request = new HTTP\Request($serverVars); - $request->setBody('Testing new file'); - $this->server->httpRequest = ($request); + $request = new HTTP\Request('PUT', '/._testput.txt', [], 'Testing new file'); + $this->server->httpRequest = $request; $this->server->exec(); $this->assertEquals('', $this->response->body); - $this->assertEquals('HTTP/1.1 201 Created',$this->response->status); + $this->assertEquals(201, $this->response->status); $this->assertEquals(array( - 'X-Sabre-Temp' => 'true', - ),$this->response->headers); + 'X-Sabre-Temp' => ['true'], + ),$this->response->getHeaders()); - $serverVars = array( - 'REQUEST_URI' => '/._testput.txt', - 'REQUEST_METHOD' => 'PROPFIND', - ); + $request = new HTTP\Request('PROPFIND', '/._testput.txt'); - $request = new HTTP\Request($serverVars); - $request->setBody(''); $this->server->httpRequest = ($request); $this->server->exec(); - $this->assertEquals('HTTP/1.1 207 Multi-Status',$this->response->status,'Incorrect status code returned. Body: ' . $this->response->body); + $this->assertEquals(207, $this->response->status,'Incorrect status code returned. Body: ' . $this->response->body); $this->assertEquals(array( - 'X-Sabre-Temp' => 'true', - 'Content-Type' => 'application/xml; charset=utf-8', - ),$this->response->headers); + 'X-Sabre-Temp' => ['true'], + 'Content-Type' => ['application/xml; charset=utf-8'], + ),$this->response->getHeaders()); $body = preg_replace("/xmlns(:[A-Za-z0-9_])?=(\"|\')DAV:(\"|\')/","xmlns\\1=\"urn:DAV\"",$this->response->body); $xml = simplexml_load_string($body); diff --git a/vendor/sabre/dav/tests/Sabre/DAV/TestPlugin.php b/vendor/sabre/dav/tests/Sabre/DAV/TestPlugin.php index 9cf5edbb0..bb5ea6acc 100644 --- a/vendor/sabre/dav/tests/Sabre/DAV/TestPlugin.php +++ b/vendor/sabre/dav/tests/Sabre/DAV/TestPlugin.php @@ -2,31 +2,35 @@ namespace Sabre\DAV; +use + Sabre\HTTP\RequestInterface, + Sabre\HTTP\ResponseInterface; + class TestPlugin extends ServerPlugin { public $beforeMethod; function getFeatures() { - return array('drinking'); + return ['drinking']; } function getHTTPMethods($uri) { - return array('BEER','WINE'); + return ['BEER','WINE']; } function initialize(Server $server) { - $server->subscribeEvent('beforeMethod',array($this,'beforeMethod')); + $server->on('beforeMethod', [$this,'beforeMethod']); } - function beforeMethod($method) { + function beforeMethod(RequestInterface $request, ResponseInterface $response) { - $this->beforeMethod = $method; + $this->beforeMethod = $request->getMethod(); return true; } diff --git a/vendor/sabre/dav/tests/Sabre/DAV/Tree/FilesystemTest.php b/vendor/sabre/dav/tests/Sabre/DAV/Tree/FilesystemTest.php deleted file mode 100644 index 19b08460f..000000000 --- a/vendor/sabre/dav/tests/Sabre/DAV/Tree/FilesystemTest.php +++ /dev/null @@ -1,88 +0,0 @@ -<?php - -namespace Sabre\DAV\Tree; - -use Sabre\DAV; - -/** - * @covers Sabre\DAV\Tree - * @covers Sabre\DAV\Tree\Filesystem - * @covers Sabre\DAV\FS\Node - * @covers Sabre\DAV\FS\File - * @covers Sabre\DAV\FS\Directory - */ -class FilesystemTest extends \PHPUnit_Framework_TestCase { - - function setUp() { - - \Sabre\TestUtil::clearTempDir(); - file_put_contents(SABRE_TEMPDIR. '/file.txt','Body'); - mkdir(SABRE_TEMPDIR.'/dir'); - file_put_contents(SABRE_TEMPDIR.'/dir/subfile.txt','Body'); - - } - - function tearDown() { - - \Sabre\TestUtil::clearTempDir(); - - } - - function testGetNodeForPath_File() { - - $fs = new Filesystem(SABRE_TEMPDIR); - $node = $fs->getNodeForPath('file.txt'); - $this->assertTrue($node instanceof DAV\FS\File); - - } - - /** - * @expectedException \Sabre\DAV\Exception\NotFound - */ - function testGetNodeForPath_DoesntExist() { - - $fs = new Filesystem(SABRE_TEMPDIR); - $node = $fs->getNodeForPath('whoop/file.txt'); - - } - - function testGetNodeForPath_Directory() { - - $fs = new Filesystem(SABRE_TEMPDIR); - $node = $fs->getNodeForPath('dir'); - $this->assertTrue($node instanceof DAV\FS\Directory); - $this->assertEquals('dir', $node->getName()); - $this->assertInternalType('array', $node->getChildren()); - - } - - function testCopy() { - - $fs = new Filesystem(SABRE_TEMPDIR); - $fs->copy('file.txt','file2.txt'); - $this->assertTrue(file_exists(SABRE_TEMPDIR . '/file2.txt')); - $this->assertEquals('Body',file_get_contents(SABRE_TEMPDIR . '/file2.txt')); - - } - - function testCopyDir() { - - $fs = new Filesystem(SABRE_TEMPDIR); - $fs->copy('dir','dir2'); - $this->assertTrue(file_exists(SABRE_TEMPDIR . '/dir2')); - $this->assertEquals('Body',file_get_contents(SABRE_TEMPDIR . '/dir2/subfile.txt')); - - } - - function testMove() { - - $fs = new Filesystem(SABRE_TEMPDIR); - $fs->move('file.txt','file2.txt'); - $this->assertTrue(file_exists(SABRE_TEMPDIR . '/file2.txt')); - $this->assertTrue(!file_exists(SABRE_TEMPDIR . '/file.txt')); - $this->assertEquals('Body',file_get_contents(SABRE_TEMPDIR . '/file2.txt')); - - } - - -} diff --git a/vendor/sabre/dav/tests/Sabre/DAV/TreeTest.php b/vendor/sabre/dav/tests/Sabre/DAV/TreeTest.php index 90df6427e..9516c2390 100644 --- a/vendor/sabre/dav/tests/Sabre/DAV/TreeTest.php +++ b/vendor/sabre/dav/tests/Sabre/DAV/TreeTest.php @@ -2,9 +2,6 @@ namespace Sabre\DAV; -/** - * @covers \Sabre\DAV\Tree - */ class TreeTest extends \PHPUnit_Framework_TestCase { function testNodeExists() { @@ -59,11 +56,31 @@ class TreeTest extends \PHPUnit_Framework_TestCase { $tree = new TreeMock(); $children = $tree->getChildren(''); - $this->assertEquals(1,count($children)); + $this->assertEquals(2,count($children)); $this->assertEquals('hi', $children[0]->getName()); } + function testGetMultipleNodes() { + + $tree = new TreeMock(); + $result = $tree->getMultipleNodes(['hi/sub', 'hi/file']); + $this->assertArrayHasKey('hi/sub', $result); + $this->assertArrayHasKey('hi/file', $result); + + $this->assertEquals('sub', $result['hi/sub']->getName()); + $this->assertEquals('file', $result['hi/file']->getName()); + + } + function testGetMultipleNodes2() { + + $tree = new TreeMock(); + $result = $tree->getMultipleNodes(['multi/1', 'multi/2']); + $this->assertArrayHasKey('multi/1', $result); + $this->assertArrayHasKey('multi/2', $result); + + } + } class TreeMock extends Tree { @@ -72,19 +89,23 @@ class TreeMock extends Tree { function __construct() { - $this->nodes['hi/sub'] = new TreeDirectoryTester('sub'); - $this->nodes['hi/file'] = new TreeFileTester('file'); - $this->nodes['hi/file']->properties = array('test1' => 'value'); - $this->nodes['hi/file']->data = 'foobar'; - $this->nodes['hi'] = new TreeDirectoryTester('hi',array($this->nodes['hi/sub'], $this->nodes['hi/file'])); - $this->nodes[''] = new TreeDirectoryTester('hi', array($this->nodes['hi'])); - - } - - function getNodeForPath($path) { + $file = new TreeFileTester('file'); + $file->properties = ['test1'=>'value']; + $file->data = 'foobar'; - if (isset($this->nodes[$path])) return $this->nodes[$path]; - throw new Exception\NotFound('item not found'); + parent::__construct( + new TreeDirectoryTester('root', [ + new TreeDirectoryTester('hi', [ + new TreeDirectoryTester('sub'), + $file, + ]), + new TreeMultiGetTester('multi', [ + new TreeFileTester('1'), + new TreeFileTester('2'), + new TreeFileTester('3'), + ]) + ]) + ); } @@ -117,6 +138,12 @@ class TreeDirectoryTester extends SimpleCollection { } + function childExists($name) { + + return !!$this->getChild($name); + + } + function delete() { $this->isDeleted = true; @@ -164,12 +191,51 @@ class TreeFileTester extends File implements IProperties { } - function updateProperties($properties) { + /** + * Updates properties on this node. + * + * This method received a PropPatch object, which contains all the + * information about the update. + * + * To update specific properties, call the 'handle' method on this object. + * Read the PropPatch documentation for more information. + * + * @param array $mutations + * @return bool|array + */ + function propPatch(PropPatch $propPatch) { - $this->properties = $properties; - return true; + $this->properties = $propPatch->getMutations(); + $propPatch->setRemainingResultCode(200); } } +class TreeMultiGetTester extends TreeDirectoryTester implements IMultiGet { + + /** + * This method receives a list of paths in it's first argument. + * It must return an array with Node objects. + * + * If any children are not found, you do not have to return them. + * + * @return array + */ + function getMultipleChildren(array $paths) { + + $result = []; + foreach($paths as $path) { + try { + $child = $this->getChild($path); + $result[] = $child; + } catch (Exception\NotFound $e) { + // Do nothing + } + } + + return $result; + + } + +} diff --git a/vendor/sabre/dav/tests/Sabre/DAV/URLUtilTest.php b/vendor/sabre/dav/tests/Sabre/DAV/URLUtilTest.php deleted file mode 100644 index 5d1380865..000000000 --- a/vendor/sabre/dav/tests/Sabre/DAV/URLUtilTest.php +++ /dev/null @@ -1,131 +0,0 @@ -<?php - -namespace Sabre\DAV; - -class URLUtilTest extends \PHPUnit_Framework_TestCase{ - - function testEncodePath() { - - $str = ''; - for($i=0;$i<128;$i++) $str.=chr($i); - - $newStr = URLUtil::encodePath($str); - - $this->assertEquals( - '%00%01%02%03%04%05%06%07%08%09%0a%0b%0c%0d%0e%0f'. - '%10%11%12%13%14%15%16%17%18%19%1a%1b%1c%1d%1e%1f'. - '%20%21%22%23%24%25%26%27()%2a%2b%2c-./'. - '0123456789:%3b%3c%3d%3e%3f'. - '%40ABCDEFGHIJKLMNO' . - 'PQRSTUVWXYZ%5b%5c%5d%5e_' . - '%60abcdefghijklmno' . - 'pqrstuvwxyz%7b%7c%7d~%7f', - $newStr); - - $this->assertEquals($str,URLUtil::decodePath($newStr)); - - } - - function testEncodePathSegment() { - - $str = ''; - for($i=0;$i<128;$i++) $str.=chr($i); - - $newStr = URLUtil::encodePathSegment($str); - - // Note: almost exactly the same as the last test, with the - // exception of the encoding of / (ascii code 2f) - $this->assertEquals( - '%00%01%02%03%04%05%06%07%08%09%0a%0b%0c%0d%0e%0f'. - '%10%11%12%13%14%15%16%17%18%19%1a%1b%1c%1d%1e%1f'. - '%20%21%22%23%24%25%26%27()%2a%2b%2c-.%2f'. - '0123456789:%3b%3c%3d%3e%3f'. - '%40ABCDEFGHIJKLMNO' . - 'PQRSTUVWXYZ%5b%5c%5d%5e_' . - '%60abcdefghijklmno' . - 'pqrstuvwxyz%7b%7c%7d~%7f', - $newStr); - - $this->assertEquals($str,URLUtil::decodePathSegment($newStr)); - - } - - function testDecode() { - - $str = 'Hello%20Test+Test2.txt'; - $newStr = URLUtil::decodePath($str); - $this->assertEquals('Hello Test+Test2.txt',$newStr); - - } - - /** - * @depends testDecode - */ - function testDecodeUmlaut() { - - $str = 'Hello%C3%BC.txt'; - $newStr = URLUtil::decodePath($str); - $this->assertEquals("Hello\xC3\xBC.txt",$newStr); - - } - - /** - * @depends testDecodeUmlaut - */ - function testDecodeUmlautLatin1() { - - $str = 'Hello%FC.txt'; - $newStr = URLUtil::decodePath($str); - $this->assertEquals("Hello\xC3\xBC.txt",$newStr); - - } - - /** - * This testcase was sent by a bug reporter - * - * @depends testDecode - */ - function testDecodeAccentsWindows7() { - - $str = '/webdav/%C3%A0fo%C3%B3'; - $newStr = URLUtil::decodePath($str); - $this->assertEquals(strtolower($str),URLUtil::encodePath($newStr)); - - } - - function testSplitPath() { - - $strings = array( - - // input // expected result - '/foo/bar' => array('/foo','bar'), - '/foo/bar/' => array('/foo','bar'), - 'foo/bar/' => array('foo','bar'), - 'foo/bar' => array('foo','bar'), - 'foo/bar/baz' => array('foo/bar','baz'), - 'foo/bar/baz/' => array('foo/bar','baz'), - 'foo' => array('','foo'), - 'foo/' => array('','foo'), - '/foo/' => array('','foo'), - '/foo' => array('','foo'), - '' => array(null,null), - - // UTF-8 - "/\xC3\xA0fo\xC3\xB3/bar" => array("/\xC3\xA0fo\xC3\xB3",'bar'), - "/\xC3\xA0foo/b\xC3\xBCr/" => array("/\xC3\xA0foo","b\xC3\xBCr"), - "foo/\xC3\xA0\xC3\xBCr" => array("foo","\xC3\xA0\xC3\xBCr"), - - ); - - foreach($strings as $input => $expected) { - - $output = URLUtil::splitPath($input); - $this->assertEquals($expected, $output, 'The expected output for \'' . $input . '\' was incorrect'); - - - } - - - } - -} diff --git a/vendor/sabre/dav/tests/Sabre/DAV/XMLUtilTest.php b/vendor/sabre/dav/tests/Sabre/DAV/XMLUtilTest.php deleted file mode 100644 index 1d2bfd133..000000000 --- a/vendor/sabre/dav/tests/Sabre/DAV/XMLUtilTest.php +++ /dev/null @@ -1,284 +0,0 @@ -<?php - -namespace Sabre\DAV; - -class XMLUtilTest extends \PHPUnit_Framework_TestCase { - - function testToClarkNotation() { - - $dom = new \DOMDocument(); - $dom->loadXML('<?xml version="1.0"?><test1 xmlns="http://www.example.org/">Testdoc</test1>'); - - $this->assertEquals( - '{http://www.example.org/}test1', - XMLUtil::toClarkNotation($dom->firstChild) - ); - - } - - function testToClarkNotation2() { - - $dom = new \DOMDocument(); - $dom->loadXML('<?xml version="1.0"?><s:test1 xmlns:s="http://www.example.org/">Testdoc</s:test1>'); - - $this->assertEquals( - '{http://www.example.org/}test1', - XMLUtil::toClarkNotation($dom->firstChild) - ); - - } - - function testToClarkNotationDAVNamespace() { - - $dom = new \DOMDocument(); - $dom->loadXML('<?xml version="1.0"?><s:test1 xmlns:s="urn:DAV">Testdoc</s:test1>'); - - $this->assertEquals( - '{DAV:}test1', - XMLUtil::toClarkNotation($dom->firstChild) - ); - - } - - function testToClarkNotationNoElem() { - - $dom = new \DOMDocument(); - $dom->loadXML('<?xml version="1.0"?><s:test1 xmlns:s="urn:DAV">Testdoc</s:test1>'); - - $this->assertNull( - XMLUtil::toClarkNotation($dom->firstChild->firstChild) - ); - - } - - function testConvertDAVNamespace() { - - $xml='<?xml version="1.0"?><document xmlns="DAV:">blablabla</document>'; - $this->assertEquals( - '<?xml version="1.0"?><document xmlns="urn:DAV">blablabla</document>', - XMLUtil::convertDAVNamespace($xml) - ); - - } - - function testConvertDAVNamespace2() { - - $xml='<?xml version="1.0"?><s:document xmlns:s="DAV:">blablabla</s:document>'; - $this->assertEquals( - '<?xml version="1.0"?><s:document xmlns:s="urn:DAV">blablabla</s:document>', - XMLUtil::convertDAVNamespace($xml) - ); - - } - - function testConvertDAVNamespace3() { - - $xml='<?xml version="1.0"?><s:document xmlns="http://bla" xmlns:s="DAV:" xmlns:z="http://othernamespace">blablabla</s:document>'; - $this->assertEquals( - '<?xml version="1.0"?><s:document xmlns="http://bla" xmlns:s="urn:DAV" xmlns:z="http://othernamespace">blablabla</s:document>', - XMLUtil::convertDAVNamespace($xml) - ); - - } - - function testConvertDAVNamespace4() { - - $xml='<?xml version="1.0"?><document xmlns=\'DAV:\'>blablabla</document>'; - $this->assertEquals( - '<?xml version="1.0"?><document xmlns=\'urn:DAV\'>blablabla</document>', - XMLUtil::convertDAVNamespace($xml) - ); - - } - - function testConvertDAVNamespaceMixedQuotes() { - - $xml='<?xml version="1.0"?><document xmlns=\'DAV:" xmlns="Another attribute\'>blablabla</document>'; - $this->assertEquals( - $xml, - XMLUtil::convertDAVNamespace($xml) - ); - - } - - /** - * @depends testConvertDAVNamespace - */ - function testLoadDOMDocument() { - - $xml='<?xml version="1.0"?><document></document>'; - $dom = XMLUtil::loadDOMDocument($xml); - $this->assertTrue($dom instanceof \DOMDocument); - - } - - /** - * @depends testLoadDOMDocument - * @expectedException Sabre\DAV\Exception\BadRequest - */ - function testLoadDOMDocumentEmpty() { - - XMLUtil::loadDOMDocument(''); - - } - - /** - * @expectedException Sabre\DAV\Exception\BadRequest - * @depends testConvertDAVNamespace - */ - function testLoadDOMDocumentInvalid() { - - $xml='<?xml version="1.0"?><document></docu'; - $dom = XMLUtil::loadDOMDocument($xml); - - } - - /** - * @depends testLoadDOMDocument - */ - function testLoadDOMDocumentUTF16() { - - $xml='<?xml version="1.0" encoding="UTF-16"?><root xmlns="DAV:">blabla</root>'; - $xml = iconv('UTF-8','UTF-16LE',$xml); - $dom = XMLUtil::loadDOMDocument($xml); - $this->assertEquals('blabla',$dom->firstChild->nodeValue); - - } - - - function testParseProperties() { - - $xml='<?xml version="1.0"?> -<root xmlns="DAV:"> - <prop> - <displayname>Calendars</displayname> - </prop> -</root>'; - - $dom = XMLUtil::loadDOMDocument($xml); - $properties = XMLUtil::parseProperties($dom->firstChild); - - $this->assertEquals(array( - '{DAV:}displayname' => 'Calendars', - ), $properties); - - - - } - - /** - * @depends testParseProperties - */ - function testParsePropertiesEmpty() { - - $xml='<?xml version="1.0"?> -<root xmlns="DAV:" xmlns:s="http://www.rooftopsolutions.nl/example"> - <prop> - <displayname>Calendars</displayname> - </prop> - <prop> - <s:example /> - </prop> -</root>'; - - $dom = XMLUtil::loadDOMDocument($xml); - $properties = XMLUtil::parseProperties($dom->firstChild); - - $this->assertEquals(array( - '{DAV:}displayname' => 'Calendars', - '{http://www.rooftopsolutions.nl/example}example' => null - ), $properties); - - } - - - /** - * @depends testParseProperties - */ - function testParsePropertiesComplex() { - - $xml='<?xml version="1.0"?> -<root xmlns="DAV:"> - <prop> - <displayname>Calendars</displayname> - </prop> - <prop> - <someprop>Complex value <b>right here</b></someprop> - </prop> -</root>'; - - $dom = XMLUtil::loadDOMDocument($xml); - $properties = XMLUtil::parseProperties($dom->firstChild); - - $this->assertEquals(array( - '{DAV:}displayname' => 'Calendars', - '{DAV:}someprop' => 'Complex value right here', - ), $properties); - - } - - - /** - * @depends testParseProperties - */ - function testParsePropertiesNoProperties() { - - $xml='<?xml version="1.0"?> -<root xmlns="DAV:"> - <prop> - </prop> -</root>'; - - $dom = XMLUtil::loadDOMDocument($xml); - $properties = XMLUtil::parseProperties($dom->firstChild); - - $this->assertEquals(array(), $properties); - - } - - function testParsePropertiesMapHref() { - - $xml='<?xml version="1.0"?> -<root xmlns="DAV:"> - <prop> - <displayname>Calendars</displayname> - </prop> - <prop> - <someprop><href>http://sabredav.org/</href></someprop> - </prop> -</root>'; - - $dom = XMLUtil::loadDOMDocument($xml); - $properties = XMLUtil::parseProperties($dom->firstChild,array('{DAV:}someprop'=>'Sabre\\DAV\\Property\\Href')); - - $this->assertEquals(array( - '{DAV:}displayname' => 'Calendars', - '{DAV:}someprop' => new Property\Href('http://sabredav.org/',false), - ), $properties); - - } - - function testParseClarkNotation() { - - $this->assertEquals(array( - 'DAV:', - 'foo', - ), XMLUtil::parseClarkNotation('{DAV:}foo')); - - $this->assertEquals(array( - 'http://example.org/ns/bla', - 'bar-soap', - ), XMLUtil::parseClarkNotation('{http://example.org/ns/bla}bar-soap')); - } - - /** - * @expectedException InvalidArgumentException - */ - function testParseClarkNotationFail() { - - XMLUtil::parseClarkNotation('}foo'); - - } - -} - diff --git a/vendor/sabre/dav/tests/Sabre/DAVACL/ACLMethodTest.php b/vendor/sabre/dav/tests/Sabre/DAVACL/ACLMethodTest.php index 9960180a3..4ecd42717 100644 --- a/vendor/sabre/dav/tests/Sabre/DAVACL/ACLMethodTest.php +++ b/vendor/sabre/dav/tests/Sabre/DAVACL/ACLMethodTest.php @@ -16,17 +16,7 @@ class ACLMethodTest extends \PHPUnit_Framework_TestCase { $server = new DAV\Server(); $server->addPlugin($acl); - $acl->unknownMethod('ACL','test'); - - } - - function testCallbackPassthru() { - - $acl = new Plugin(); - $server = new DAV\Server(); - $server->addPlugin($acl); - - $this->assertNull($acl->unknownMethod('FOO','test')); + $acl->httpAcl($server->httpRequest, $server->httpResponse); } @@ -49,7 +39,7 @@ class ACLMethodTest extends \PHPUnit_Framework_TestCase { $server->httpRequest->setBody($body); $server->addPlugin($acl); - $acl->httpACL('test'); + $acl->httpACL($server->httpRequest, $server->httpResponse); } @@ -61,13 +51,15 @@ class ACLMethodTest extends \PHPUnit_Framework_TestCase { $acl = new Plugin(); $server = new DAV\Server($tree); $server->httpRequest = new HTTP\Request(); + $server->httpRequest->setUrl('/test'); + $body = '<?xml version="1.0"?> <d:acl xmlns:d="DAV:"> </d:acl>'; $server->httpRequest->setBody($body); $server->addPlugin($acl); - $this->assertNull($acl->httpACL('test')); + $this->assertFalse($acl->httpACL($server->httpRequest, $server->httpResponse)); } @@ -81,7 +73,7 @@ class ACLMethodTest extends \PHPUnit_Framework_TestCase { ); $acl = new Plugin(); $server = new DAV\Server($tree); - $server->httpRequest = new HTTP\Request(); + $server->httpRequest = new HTTP\Request('ACL','/test'); $body = '<?xml version="1.0"?> <d:acl xmlns:d="DAV:"> <d:ace> @@ -92,7 +84,7 @@ class ACLMethodTest extends \PHPUnit_Framework_TestCase { $server->httpRequest->setBody($body); $server->addPlugin($acl); - $acl->httpACL('test'); + $acl->httpACL($server->httpRequest, $server->httpResponse); } @@ -109,7 +101,7 @@ class ACLMethodTest extends \PHPUnit_Framework_TestCase { ); $acl = new Plugin(); $server = new DAV\Server($tree); - $server->httpRequest = new HTTP\Request(); + $server->httpRequest = new HTTP\Request('ACL','/test'); $body = '<?xml version="1.0"?> <d:acl xmlns:d="DAV:"> <d:ace> @@ -120,7 +112,7 @@ class ACLMethodTest extends \PHPUnit_Framework_TestCase { $server->httpRequest->setBody($body); $server->addPlugin($acl); - $acl->httpACL('test'); + $acl->httpACL($server->httpRequest, $server->httpResponse); } @@ -134,7 +126,7 @@ class ACLMethodTest extends \PHPUnit_Framework_TestCase { ); $acl = new Plugin(); $server = new DAV\Server($tree); - $server->httpRequest = new HTTP\Request(); + $server->httpRequest = new HTTP\Request('ACL','/test'); $body = '<?xml version="1.0"?> <d:acl xmlns:d="DAV:"> <d:ace> @@ -145,7 +137,7 @@ class ACLMethodTest extends \PHPUnit_Framework_TestCase { $server->httpRequest->setBody($body); $server->addPlugin($acl); - $acl->httpACL('test'); + $acl->httpACL($server->httpRequest, $server->httpResponse); } @@ -159,18 +151,18 @@ class ACLMethodTest extends \PHPUnit_Framework_TestCase { ); $acl = new Plugin(); $server = new DAV\Server($tree); - $server->httpRequest = new HTTP\Request(); + $server->httpRequest = new HTTP\Request('ACL','/test'); $body = '<?xml version="1.0"?> <d:acl xmlns:d="DAV:"> <d:ace> - <d:grant><d:privilege><d:read-acl /></d:privilege></d:grant> + <d:grant><d:privilege><d:all /></d:privilege></d:grant> <d:principal><d:href>/principals/notfound</d:href></d:principal> </d:ace> </d:acl>'; $server->httpRequest->setBody($body); $server->addPlugin($acl); - $acl->httpACL('test'); + $acl->httpACL($server->httpRequest, $server->httpResponse); } @@ -192,7 +184,7 @@ class ACLMethodTest extends \PHPUnit_Framework_TestCase { ); $acl = new Plugin(); $server = new DAV\Server($tree); - $server->httpRequest = new HTTP\Request(); + $server->httpRequest = new HTTP\Request('ACL','/test'); $body = '<?xml version="1.0"?> <d:acl xmlns:d="DAV:"> <d:ace> @@ -203,7 +195,7 @@ class ACLMethodTest extends \PHPUnit_Framework_TestCase { $server->httpRequest->setBody($body); $server->addPlugin($acl); - $acl->httpACL('test'); + $acl->httpACL($server->httpRequest, $server->httpResponse); } @@ -225,7 +217,7 @@ class ACLMethodTest extends \PHPUnit_Framework_TestCase { ); $acl = new Plugin(); $server = new DAV\Server($tree); - $server->httpRequest = new HTTP\Request(); + $server->httpRequest = new HTTP\Request('ACL','/test'); $body = '<?xml version="1.0"?> <d:acl xmlns:d="DAV:"> <d:ace> @@ -236,7 +228,7 @@ class ACLMethodTest extends \PHPUnit_Framework_TestCase { $server->httpRequest->setBody($body); $server->addPlugin($acl); - $acl->httpACL('test'); + $acl->httpACL($server->httpRequest, $server->httpResponse); } @@ -258,7 +250,7 @@ class ACLMethodTest extends \PHPUnit_Framework_TestCase { ); $acl = new Plugin(); $server = new DAV\Server($tree); - $server->httpRequest = new HTTP\Request(); + $server->httpRequest = new HTTP\Request('ACL','/test'); $body = '<?xml version="1.0"?> <d:acl xmlns:d="DAV:"> <d:ace> @@ -269,11 +261,11 @@ class ACLMethodTest extends \PHPUnit_Framework_TestCase { $server->httpRequest->setBody($body); $server->addPlugin($acl); - $acl->httpACL('test'); + $acl->httpACL($server->httpRequest, $server->httpResponse); } - function testSuccessComplex () { + function testSuccessComplex() { $oldACL = array( array( @@ -296,7 +288,7 @@ class ACLMethodTest extends \PHPUnit_Framework_TestCase { ); $acl = new Plugin(); $server = new DAV\Server($tree); - $server->httpRequest = new HTTP\Request(); + $server->httpRequest = new HTTP\Request('ACL','/test'); $body = '<?xml version="1.0"?> <d:acl xmlns:d="DAV:"> <d:ace> @@ -312,7 +304,8 @@ class ACLMethodTest extends \PHPUnit_Framework_TestCase { $server->httpRequest->setBody($body); $server->addPlugin($acl); - $this->assertFalse($acl->unknownMethod('ACL','test')); + + $this->assertFalse($acl->httpAcl($server->httpRequest, $server->httpResponse)); $this->assertEquals(array( array( diff --git a/vendor/sabre/dav/tests/Sabre/DAVACL/AllowAccessTest.php b/vendor/sabre/dav/tests/Sabre/DAVACL/AllowAccessTest.php index 3a9b35b45..14a80003a 100644 --- a/vendor/sabre/dav/tests/Sabre/DAVACL/AllowAccessTest.php +++ b/vendor/sabre/dav/tests/Sabre/DAVACL/AllowAccessTest.php @@ -27,112 +27,104 @@ class AllowAccessTest extends \PHPUnit_Framework_TestCase { function testGet() { - $this->assertTrue($this->server->broadcastEvent('beforeMethod',array('GET','testdir'))); + $this->server->httpRequest->setMethod('GET'); + $this->server->httpRequest->setUrl('/testdir'); + + $this->assertTrue($this->server->emit('beforeMethod', [$this->server->httpRequest, $this->server->httpResponse])); } function testGetDoesntExist() { - $r = $this->server->broadcastEvent('beforeMethod',array('GET','foo')); - $this->assertTrue($r); + $this->server->httpRequest->setMethod('GET'); + $this->server->httpRequest->setUrl('/foo'); + + $this->assertTrue($this->server->emit('beforeMethod', [$this->server->httpRequest, $this->server->httpResponse])); } function testHEAD() { - $this->assertTrue($this->server->broadcastEvent('beforeMethod',array('HEAD','testdir'))); + $this->server->httpRequest->setMethod('HEAD'); + $this->server->httpRequest->setUrl('/testdir'); + + $this->assertTrue($this->server->emit('beforeMethod', [$this->server->httpRequest, $this->server->httpResponse])); } function testOPTIONS() { - $this->assertTrue($this->server->broadcastEvent('beforeMethod',array('OPTIONS','testdir'))); + $this->server->httpRequest->setMethod('OPTIONS'); + $this->server->httpRequest->setUrl('/testdir'); + + $this->assertTrue($this->server->emit('beforeMethod', [$this->server->httpRequest, $this->server->httpResponse])); } function testPUT() { - $this->assertTrue($this->server->broadcastEvent('beforeMethod',array('PUT','testdir'))); + $this->server->httpRequest->setMethod('PUT'); + $this->server->httpRequest->setUrl('/testdir'); + + $this->assertTrue($this->server->emit('beforeMethod', [$this->server->httpRequest, $this->server->httpResponse])); } function testACL() { - $this->assertTrue($this->server->broadcastEvent('beforeMethod',array('ACL','testdir'))); + $this->server->httpRequest->setMethod('ACL'); + $this->server->httpRequest->setUrl('/testdir'); + + $this->assertTrue($this->server->emit('beforeMethod', [$this->server->httpRequest, $this->server->httpResponse])); } function testPROPPATCH() { - $this->assertTrue($this->server->broadcastEvent('beforeMethod',array('PROPPATCH','testdir'))); + $this->server->httpRequest->setMethod('PROPPATCH'); + $this->server->httpRequest->setUrl('/testdir'); + + $this->assertTrue($this->server->emit('beforeMethod', [$this->server->httpRequest, $this->server->httpResponse])); } function testCOPY() { - $this->assertTrue($this->server->broadcastEvent('beforeMethod',array('COPY','testdir'))); + $this->server->httpRequest->setMethod('COPY'); + $this->server->httpRequest->setUrl('/testdir'); + + $this->assertTrue($this->server->emit('beforeMethod', [$this->server->httpRequest, $this->server->httpResponse])); } function testMOVE() { - $this->assertTrue($this->server->broadcastEvent('beforeMethod',array('MOVE','testdir'))); + $this->server->httpRequest->setMethod('MOVE'); + $this->server->httpRequest->setUrl('/testdir'); + + $this->assertTrue($this->server->emit('beforeMethod', [$this->server->httpRequest, $this->server->httpResponse])); } function testLOCK() { - $this->assertTrue($this->server->broadcastEvent('beforeMethod',array('LOCK','testdir'))); + $this->server->httpRequest->setMethod('LOCK'); + $this->server->httpRequest->setUrl('/testdir'); + + $this->assertTrue($this->server->emit('beforeMethod', [$this->server->httpRequest, $this->server->httpResponse])); } function testBeforeBind() { - $this->assertTrue($this->server->broadcastEvent('beforeBind',array('testdir/file'))); + $this->assertTrue($this->server->emit('beforeBind', ['testdir/file'])); } function testBeforeUnbind() { - $this->assertTrue($this->server->broadcastEvent('beforeUnbind',array('testdir'))); - - } - - function testAfterGetProperties() { - - $properties = array( - 'href' => 'foo', - '200' => array( - '{DAV:}displayname' => 'foo', - '{DAV:}getcontentlength' => 500, - ), - '404' => array( - '{DAV:}bar' => null, - ), - '403' => array( - '{DAV:}owner' => null, - ), - ); - - $expected = array( - 'href' => 'foo', - '200' => array( - '{DAV:}displayname' => 'foo', - '{DAV:}getcontentlength' => 500, - ), - '404' => array( - '{DAV:}bar' => null, - ), - '403' => array( - '{DAV:}owner' => null, - ), - ); - - $r = $this->server->broadcastEvent('afterGetProperties',array('testdir',&$properties)); - $this->assertTrue($r); - - $this->assertEquals($expected, $properties); + $this->assertTrue($this->server->emit('beforeUnbind', ['testdir'])); } diff --git a/vendor/sabre/dav/tests/Sabre/DAVACL/BlockAccessTest.php b/vendor/sabre/dav/tests/Sabre/DAVACL/BlockAccessTest.php index 345d2cc5d..be3e9dae9 100644 --- a/vendor/sabre/dav/tests/Sabre/DAVACL/BlockAccessTest.php +++ b/vendor/sabre/dav/tests/Sabre/DAVACL/BlockAccessTest.php @@ -15,9 +15,9 @@ class BlockAccessTest extends \PHPUnit_Framework_TestCase { function setUp() { - $nodes = array( + $nodes = [ new DAV\SimpleCollection('testdir'), - ); + ]; $this->server = new DAV\Server($nodes); $this->plugin = new Plugin(); @@ -31,13 +31,19 @@ class BlockAccessTest extends \PHPUnit_Framework_TestCase { */ function testGet() { - $this->server->broadcastEvent('beforeMethod',array('GET','testdir')); + $this->server->httpRequest->setMethod('GET'); + $this->server->httpRequest->setUrl('/testdir'); + + $this->server->emit('beforeMethod', [$this->server->httpRequest, $this->server->httpResponse]); } function testGetDoesntExist() { - $r = $this->server->broadcastEvent('beforeMethod',array('GET','foo')); + $this->server->httpRequest->setMethod('GET'); + $this->server->httpRequest->setUrl('/foo'); + + $r = $this->server->emit('beforeMethod', [$this->server->httpRequest, $this->server->httpResponse]); $this->assertTrue($r); } @@ -47,7 +53,10 @@ class BlockAccessTest extends \PHPUnit_Framework_TestCase { */ function testHEAD() { - $this->server->broadcastEvent('beforeMethod',array('HEAD','testdir')); + $this->server->httpRequest->setMethod('HEAD'); + $this->server->httpRequest->setUrl('/testdir'); + + $this->server->emit('beforeMethod', [$this->server->httpRequest, $this->server->httpResponse]); } @@ -56,7 +65,10 @@ class BlockAccessTest extends \PHPUnit_Framework_TestCase { */ function testOPTIONS() { - $this->server->broadcastEvent('beforeMethod',array('OPTIONS','testdir')); + $this->server->httpRequest->setMethod('OPTIONS'); + $this->server->httpRequest->setUrl('/testdir'); + + $this->server->emit('beforeMethod', [$this->server->httpRequest, $this->server->httpResponse]); } @@ -65,7 +77,10 @@ class BlockAccessTest extends \PHPUnit_Framework_TestCase { */ function testPUT() { - $this->server->broadcastEvent('beforeMethod',array('PUT','testdir')); + $this->server->httpRequest->setMethod('PUT'); + $this->server->httpRequest->setUrl('/testdir'); + + $this->server->emit('beforeMethod', [$this->server->httpRequest, $this->server->httpResponse]); } @@ -74,7 +89,10 @@ class BlockAccessTest extends \PHPUnit_Framework_TestCase { */ function testPROPPATCH() { - $this->server->broadcastEvent('beforeMethod',array('PROPPATCH','testdir')); + $this->server->httpRequest->setMethod('PROPPATCH'); + $this->server->httpRequest->setUrl('/testdir'); + + $this->server->emit('beforeMethod', [$this->server->httpRequest, $this->server->httpResponse]); } @@ -83,7 +101,10 @@ class BlockAccessTest extends \PHPUnit_Framework_TestCase { */ function testCOPY() { - $this->server->broadcastEvent('beforeMethod',array('COPY','testdir')); + $this->server->httpRequest->setMethod('COPY'); + $this->server->httpRequest->setUrl('/testdir'); + + $this->server->emit('beforeMethod', [$this->server->httpRequest, $this->server->httpResponse]); } @@ -92,7 +113,10 @@ class BlockAccessTest extends \PHPUnit_Framework_TestCase { */ function testMOVE() { - $this->server->broadcastEvent('beforeMethod',array('MOVE','testdir')); + $this->server->httpRequest->setMethod('MOVE'); + $this->server->httpRequest->setUrl('/testdir'); + + $this->server->emit('beforeMethod', [$this->server->httpRequest, $this->server->httpResponse]); } @@ -101,7 +125,10 @@ class BlockAccessTest extends \PHPUnit_Framework_TestCase { */ function testACL() { - $this->server->broadcastEvent('beforeMethod',array('ACL','testdir')); + $this->server->httpRequest->setMethod('ACL'); + $this->server->httpRequest->setUrl('/testdir'); + + $this->server->emit('beforeMethod', [$this->server->httpRequest, $this->server->httpResponse]); } @@ -110,7 +137,10 @@ class BlockAccessTest extends \PHPUnit_Framework_TestCase { */ function testLOCK() { - $this->server->broadcastEvent('beforeMethod',array('LOCK','testdir')); + $this->server->httpRequest->setMethod('LOCK'); + $this->server->httpRequest->setUrl('/testdir'); + + $this->server->emit('beforeMethod', [$this->server->httpRequest, $this->server->httpResponse]); } @@ -119,7 +149,7 @@ class BlockAccessTest extends \PHPUnit_Framework_TestCase { */ function testBeforeBind() { - $this->server->broadcastEvent('beforeBind',array('testdir/file')); + $this->server->emit('beforeBind', ['testdir/file']); } @@ -128,62 +158,48 @@ class BlockAccessTest extends \PHPUnit_Framework_TestCase { */ function testBeforeUnbind() { - $this->server->broadcastEvent('beforeUnbind',array('testdir')); + $this->server->emit('beforeUnbind', ['testdir']); } - function testBeforeGetProperties() { + function testPropFind() { - $requestedProperties = array( + $propFind = new DAV\PropFind('testdir', [ '{DAV:}displayname', '{DAV:}getcontentlength', '{DAV:}bar', '{DAV:}owner', - ); - $returnedProperties = array(); + ]); - $arguments = array( - 'testdir', - new DAV\SimpleCollection('testdir'), - &$requestedProperties, - &$returnedProperties - ); - $r = $this->server->broadcastEvent('beforeGetProperties',$arguments); + $r = $this->server->emit('propFind', [$propFind, new DAV\SimpleCollection('testdir')]); $this->assertTrue($r); - $expected = array( - '403' => array( + $expected = [ + 200 => [], + 404 => [], + 403 => [ '{DAV:}displayname' => null, '{DAV:}getcontentlength' => null, '{DAV:}bar' => null, '{DAV:}owner' => null, - ), - ); + ], + ]; - $this->assertEquals($expected, $returnedProperties); - $this->assertEquals(array(), $requestedProperties); + $this->assertEquals($expected, $propFind->getResultForMultiStatus()); } function testBeforeGetPropertiesNoListing() { $this->plugin->hideNodesFromListings = true; - - $requestedProperties = array( + $propFind = new DAV\PropFind('testdir', [ '{DAV:}displayname', '{DAV:}getcontentlength', '{DAV:}bar', '{DAV:}owner', - ); - $returnedProperties = array(); + ]); - $arguments = array( - 'testdir', - new DAV\SimpleCollection('testdir'), - &$requestedProperties, - &$returnedProperties - ); - $r = $this->server->broadcastEvent('beforeGetProperties',$arguments); + $r = $this->server->emit('propFind', [$propFind, new DAV\SimpleCollection('testdir')]); $this->assertFalse($r); } diff --git a/vendor/sabre/dav/tests/Sabre/DAVACL/ExpandPropertiesTest.php b/vendor/sabre/dav/tests/Sabre/DAVACL/ExpandPropertiesTest.php index 324788d4a..5e99f2e73 100644 --- a/vendor/sabre/dav/tests/Sabre/DAVACL/ExpandPropertiesTest.php +++ b/vendor/sabre/dav/tests/Sabre/DAVACL/ExpandPropertiesTest.php @@ -12,23 +12,24 @@ class ExpandPropertiesTest extends \PHPUnit_Framework_TestCase { function getServer() { $tree = array( - new MockPropertyNode('node1', array( + new DAV\Mock\PropertiesCollection('node1', [], array( '{http://sabredav.org/ns}simple' => 'foo', - '{http://sabredav.org/ns}href' => new DAV\Property\Href('node2'), + '{http://sabredav.org/ns}href' => new DAV\Xml\Property\Href('node2'), '{DAV:}displayname' => 'Node 1', )), - new MockPropertyNode('node2', array( + new DAV\Mock\PropertiesCollection('node2', [], array( '{http://sabredav.org/ns}simple' => 'simple', - '{http://sabredav.org/ns}hreflist' => new DAV\Property\HrefList(array('node1','node3')), + '{http://sabredav.org/ns}hreflist' => new DAV\Xml\Property\Href(['node1','node3']), '{DAV:}displayname' => 'Node 2', )), - new MockPropertyNode('node3', array( + new DAV\Mock\PropertiesCollection('node3', [], array( '{http://sabredav.org/ns}simple' => 'simple', '{DAV:}displayname' => 'Node 3', )), ); $fakeServer = new DAV\Server($tree); + $fakeServer->sapi = new HTTP\SapiMock(); $fakeServer->debugExceptions = true; $fakeServer->httpResponse = new HTTP\ResponseMock(); $plugin = new Plugin(); @@ -58,7 +59,7 @@ class ExpandPropertiesTest extends \PHPUnit_Framework_TestCase { 'REQUEST_URI' => '/node1', ); - $request = new HTTP\Request($serverVars); + $request = HTTP\Sapi::createFromServerArray($serverVars); $request->setBody($xml); $server = $this->getServer(); @@ -66,10 +67,11 @@ class ExpandPropertiesTest extends \PHPUnit_Framework_TestCase { $server->exec(); - $this->assertEquals('HTTP/1.1 207 Multi-Status', $server->httpResponse->status,'Incorrect status code received. Full body: ' . $server->httpResponse->body); + $this->assertEquals(207, $server->httpResponse->status,'Incorrect status code received. Full body: ' . $server->httpResponse->body); $this->assertEquals(array( - 'Content-Type' => 'application/xml; charset=utf-8', - ), $server->httpResponse->headers); + 'X-Sabre-Version' => [DAV\Version::VERSION], + 'Content-Type' => ['application/xml; charset=utf-8'], + ), $server->httpResponse->getHeaders()); $check = array( @@ -120,7 +122,7 @@ class ExpandPropertiesTest extends \PHPUnit_Framework_TestCase { 'REQUEST_URI' => '/node1', ); - $request = new HTTP\Request($serverVars); + $request = HTTP\Sapi::createFromServerArray($serverVars); $request->setBody($xml); $server = $this->getServer(); @@ -128,10 +130,11 @@ class ExpandPropertiesTest extends \PHPUnit_Framework_TestCase { $server->exec(); - $this->assertEquals('HTTP/1.1 207 Multi-Status', $server->httpResponse->status, 'Incorrect response status received. Full response body: ' . $server->httpResponse->body); + $this->assertEquals(207, $server->httpResponse->status, 'Incorrect response status received. Full response body: ' . $server->httpResponse->body); $this->assertEquals(array( - 'Content-Type' => 'application/xml; charset=utf-8', - ), $server->httpResponse->headers); + 'X-Sabre-Version' => [DAV\Version::VERSION], + 'Content-Type' => ['application/xml; charset=utf-8'], + ), $server->httpResponse->getHeaders()); $check = array( @@ -160,7 +163,7 @@ class ExpandPropertiesTest extends \PHPUnit_Framework_TestCase { $count = 1; if (!is_int($v1)) $count = $v2; - $this->assertEquals($count,count($result), 'we expected ' . $count . ' appearances of ' . $xpath . ' . We found ' . count($result)); + $this->assertEquals($count,count($result), 'we expected ' . $count . ' appearances of ' . $xpath . ' . We found ' . count($result) . ' Full response body: ' . $server->httpResponse->getBodyAsString()); } @@ -184,7 +187,7 @@ class ExpandPropertiesTest extends \PHPUnit_Framework_TestCase { 'REQUEST_URI' => '/node2', ); - $request = new HTTP\Request($serverVars); + $request = HTTP\Sapi::createFromServerArray($serverVars); $request->setBody($xml); $server = $this->getServer(); @@ -192,10 +195,11 @@ class ExpandPropertiesTest extends \PHPUnit_Framework_TestCase { $server->exec(); - $this->assertEquals('HTTP/1.1 207 Multi-Status', $server->httpResponse->status); + $this->assertEquals(207, $server->httpResponse->status); $this->assertEquals(array( - 'Content-Type' => 'application/xml; charset=utf-8', - ), $server->httpResponse->headers); + 'X-Sabre-Version' => [DAV\Version::VERSION], + 'Content-Type' => ['application/xml; charset=utf-8'], + ), $server->httpResponse->getHeaders()); $check = array( @@ -251,7 +255,7 @@ class ExpandPropertiesTest extends \PHPUnit_Framework_TestCase { 'REQUEST_URI' => '/node2', ); - $request = new HTTP\Request($serverVars); + $request = HTTP\Sapi::createFromServerArray($serverVars); $request->setBody($xml); $server = $this->getServer(); @@ -259,10 +263,11 @@ class ExpandPropertiesTest extends \PHPUnit_Framework_TestCase { $server->exec(); - $this->assertEquals('HTTP/1.1 207 Multi-Status', $server->httpResponse->status); + $this->assertEquals(207, $server->httpResponse->status); $this->assertEquals(array( - 'Content-Type' => 'application/xml; charset=utf-8', - ), $server->httpResponse->headers); + 'X-Sabre-Version' => [DAV\Version::VERSION], + 'Content-Type' => ['application/xml; charset=utf-8'], + ), $server->httpResponse->getHeaders()); $check = array( @@ -303,56 +308,3 @@ class ExpandPropertiesTest extends \PHPUnit_Framework_TestCase { } } -class MockPropertyNode implements DAV\INode, DAV\IProperties { - - function __construct($name, array $properties) { - - $this->name = $name; - $this->properties = $properties; - - } - - function getName() { - - return $this->name; - - } - - function getProperties($requestedProperties) { - - $returnedProperties = array(); - foreach($requestedProperties as $requestedProperty) { - if (isset($this->properties[$requestedProperty])) { - $returnedProperties[$requestedProperty] = - $this->properties[$requestedProperty]; - } - } - return $returnedProperties; - - } - - function delete() { - - throw new DAV\Exception('Not implemented'); - - } - - function setName($name) { - - throw new DAV\Exception('Not implemented'); - - } - - function getLastModified() { - - return null; - - } - - function updateProperties($properties) { - - throw new DAV\Exception('Not implemented'); - - } - -} diff --git a/vendor/sabre/dav/tests/Sabre/DAVACL/PluginAdminTest.php b/vendor/sabre/dav/tests/Sabre/DAVACL/PluginAdminTest.php index 23c4b6e85..fb7516a78 100644 --- a/vendor/sabre/dav/tests/Sabre/DAVACL/PluginAdminTest.php +++ b/vendor/sabre/dav/tests/Sabre/DAVACL/PluginAdminTest.php @@ -11,7 +11,9 @@ require_once 'Sabre/HTTP/ResponseMock.php'; class PluginAdminTest extends \PHPUnit_Framework_TestCase { - function testNoAdminAccess() { + public $server; + + function setUp() { $principalBackend = new PrincipalBackend\Mock(); @@ -20,13 +22,18 @@ class PluginAdminTest extends \PHPUnit_Framework_TestCase { new PrincipalCollection($principalBackend), ); - $fakeServer = new DAV\Server($tree); - $plugin = new DAV\Auth\Plugin(new DAV\Auth\Backend\Mock(),'realm'); - $fakeServer->addPlugin($plugin); + $this->server = new DAV\Server($tree); + $this->server->sapi = new HTTP\SapiMock(); + $plugin = new DAV\Auth\Plugin(new DAV\Auth\Backend\Mock()); + $this->server->addPlugin($plugin); + } + + function testNoAdminAccess() { + $plugin = new Plugin(); - $fakeServer->addPlugin($plugin); + $this->server->addPlugin($plugin); - $request = new HTTP\Request(array( + $request = HTTP\Sapi::createFromServerArray(array( 'REQUEST_METHOD' => 'OPTIONS', 'HTTP_DEPTH' => 1, 'REQUEST_URI' => '/adminonly', @@ -34,12 +41,12 @@ class PluginAdminTest extends \PHPUnit_Framework_TestCase { $response = new HTTP\ResponseMock(); - $fakeServer->httpRequest = $request; - $fakeServer->httpResponse = $response; + $this->server->httpRequest = $request; + $this->server->httpResponse = $response; - $fakeServer->exec(); + $this->server->exec(); - $this->assertEquals('HTTP/1.1 403 Forbidden', $response->status); + $this->assertEquals(403, $response->status); } @@ -48,23 +55,13 @@ class PluginAdminTest extends \PHPUnit_Framework_TestCase { */ function testAdminAccess() { - $principalBackend = new PrincipalBackend\Mock(); - - $tree = array( - new MockACLNode('adminonly', array()), - new PrincipalCollection($principalBackend), - ); - - $fakeServer = new DAV\Server($tree); - $plugin = new DAV\Auth\Plugin(new DAV\Auth\Backend\Mock(),'realm'); - $fakeServer->addPlugin($plugin); $plugin = new Plugin(); $plugin->adminPrincipals = array( 'principals/admin', ); - $fakeServer->addPlugin($plugin); + $this->server->addPlugin($plugin); - $request = new HTTP\Request(array( + $request = HTTP\Sapi::createFromServerArray(array( 'REQUEST_METHOD' => 'OPTIONS', 'HTTP_DEPTH' => 1, 'REQUEST_URI' => '/adminonly', @@ -72,12 +69,12 @@ class PluginAdminTest extends \PHPUnit_Framework_TestCase { $response = new HTTP\ResponseMock(); - $fakeServer->httpRequest = $request; - $fakeServer->httpResponse = $response; + $this->server->httpRequest = $request; + $this->server->httpResponse = $response; - $fakeServer->exec(); + $this->server->exec(); - $this->assertEquals('HTTP/1.1 200 OK', $response->status); + $this->assertEquals(200, $response->status); } } diff --git a/vendor/sabre/dav/tests/Sabre/DAVACL/PluginPropertiesTest.php b/vendor/sabre/dav/tests/Sabre/DAVACL/PluginPropertiesTest.php index 8c0626e50..e5b7e1a3f 100644 --- a/vendor/sabre/dav/tests/Sabre/DAVACL/PluginPropertiesTest.php +++ b/vendor/sabre/dav/tests/Sabre/DAVACL/PluginPropertiesTest.php @@ -5,42 +5,37 @@ namespace Sabre\DAVACL; use Sabre\DAV; use Sabre\HTTP; - class PluginPropertiesTest extends \PHPUnit_Framework_TestCase { function testPrincipalCollectionSet() { $plugin = new Plugin(); - $plugin->principalCollectionSet = array( + $plugin->principalCollectionSet = [ 'principals1', 'principals2', - ); + ]; - $requestedProperties = array( + $requestedProperties = [ '{DAV:}principal-collection-set', - ); - - $returnedProperties = array( - 200 => array(), - 404 => array(), - ); + ]; - $server = new DAV\Server(); + $server = new DAV\Server(new DAV\SimpleCollection('root')); $server->addPlugin($plugin); - $this->assertNull($plugin->beforeGetProperties('', new DAV\SimpleCollection('root'), $requestedProperties, $returnedProperties)); + $result = $server->getPropertiesForPath('', $requestedProperties); + $result = $result[0]; - $this->assertEquals(1,count($returnedProperties[200])); - $this->assertArrayHasKey('{DAV:}principal-collection-set',$returnedProperties[200]); - $this->assertInstanceOf('Sabre\\DAV\\Property\\HrefList', $returnedProperties[200]['{DAV:}principal-collection-set']); + $this->assertEquals(1,count($result[200])); + $this->assertArrayHasKey('{DAV:}principal-collection-set',$result[200]); + $this->assertInstanceOf('Sabre\\DAV\\Xml\\Property\\Href', $result[200]['{DAV:}principal-collection-set']); - $expected = array( + $expected = [ 'principals1/', 'principals2/', - ); + ]; - $this->assertEquals($expected, $returnedProperties[200]['{DAV:}principal-collection-set']->getHrefs()); + $this->assertEquals($expected, $result[200]['{DAV:}principal-collection-set']->getHrefs()); } @@ -48,50 +43,35 @@ class PluginPropertiesTest extends \PHPUnit_Framework_TestCase { function testCurrentUserPrincipal() { $fakeServer = new DAV\Server(); - $plugin = new DAV\Auth\Plugin(new DAV\Auth\Backend\Mock(),'realm'); + $plugin = new DAV\Auth\Plugin(new DAV\Auth\Backend\Mock()); $fakeServer->addPlugin($plugin); $plugin = new Plugin(); $fakeServer->addPlugin($plugin); - $requestedProperties = array( + $requestedProperties = [ '{DAV:}current-user-principal', - ); - - $returnedProperties = array( - 200 => array(), - 404 => array(), - ); + ]; - $this->assertNull($plugin->beforeGetProperties('', new DAV\SimpleCollection('root'), $requestedProperties, $returnedProperties)); + $result = $fakeServer->getPropertiesForPath('', $requestedProperties); + $result = $result[0]; - $this->assertEquals(1,count($returnedProperties[200])); - $this->assertArrayHasKey('{DAV:}current-user-principal',$returnedProperties[200]); - $this->assertInstanceOf('Sabre\DAVACL\Property\Principal', $returnedProperties[200]['{DAV:}current-user-principal']); - $this->assertEquals(Property\Principal::UNAUTHENTICATED, $returnedProperties[200]['{DAV:}current-user-principal']->getType()); + $this->assertEquals(1,count($result[200])); + $this->assertArrayHasKey('{DAV:}current-user-principal',$result[200]); + $this->assertInstanceOf('Sabre\DAVACL\Xml\Property\Principal', $result[200]['{DAV:}current-user-principal']); + $this->assertEquals(Xml\Property\Principal::UNAUTHENTICATED, $result[200]['{DAV:}current-user-principal']->getType()); // This will force the login - $fakeServer->broadCastEvent('beforeMethod',array('GET','')); - - - $requestedProperties = array( - '{DAV:}current-user-principal', - ); + $fakeServer->emit('beforeMethod', [$fakeServer->httpRequest, $fakeServer->httpResponse]); - $returnedProperties = array( - 200 => array(), - 404 => array(), - ); + $result = $fakeServer->getPropertiesForPath('', $requestedProperties); + $result = $result[0]; - - $this->assertNull($plugin->beforeGetProperties('', new DAV\SimpleCollection('root'), $requestedProperties, $returnedProperties)); - - - $this->assertEquals(1,count($returnedProperties[200])); - $this->assertArrayHasKey('{DAV:}current-user-principal',$returnedProperties[200]); - $this->assertInstanceOf('Sabre\DAVACL\Property\Principal', $returnedProperties[200]['{DAV:}current-user-principal']); - $this->assertEquals(Property\Principal::HREF, $returnedProperties[200]['{DAV:}current-user-principal']->getType()); - $this->assertEquals('principals/admin/', $returnedProperties[200]['{DAV:}current-user-principal']->getHref()); + $this->assertEquals(1,count($result[200])); + $this->assertArrayHasKey('{DAV:}current-user-principal',$result[200]); + $this->assertInstanceOf('Sabre\DAVACL\Xml\Property\Principal', $result[200]['{DAV:}current-user-principal']); + $this->assertEquals(Xml\Property\Principal::HREF, $result[200]['{DAV:}current-user-principal']->getType()); + $this->assertEquals('principals/admin/', $result[200]['{DAV:}current-user-principal']->getHref()); } @@ -101,33 +81,23 @@ class PluginPropertiesTest extends \PHPUnit_Framework_TestCase { $server = new DAV\Server(); $server->addPlugin($plugin); - $requestedProperties = array( + $requestedProperties = [ '{DAV:}supported-privilege-set', - ); + ]; - $returnedProperties = array( - 200 => array(), - 404 => array(), - ); + $result = $server->getPropertiesForPath('', $requestedProperties); + $result = $result[0]; - - $this->assertNull($plugin->beforeGetProperties('', new DAV\SimpleCollection('root'), $requestedProperties, $returnedProperties)); - - $this->assertEquals(1,count($returnedProperties[200])); - $this->assertArrayHasKey('{DAV:}supported-privilege-set',$returnedProperties[200]); - $this->assertInstanceOf('Sabre\\DAVACL\\Property\\SupportedPrivilegeSet', $returnedProperties[200]['{DAV:}supported-privilege-set']); + $this->assertEquals(1,count($result[200])); + $this->assertArrayHasKey('{DAV:}supported-privilege-set',$result[200]); + $this->assertInstanceOf('Sabre\\DAVACL\\Xml\\Property\\SupportedPrivilegeSet', $result[200]['{DAV:}supported-privilege-set']); $server = new DAV\Server(); - $prop = $returnedProperties[200]['{DAV:}supported-privilege-set']; - - $dom = new \DOMDocument('1.0', 'utf-8'); - $root = $dom->createElement('d:root'); - $root->setAttribute('xmlns:d','DAV:'); - $dom->appendChild($root); - $prop->serialize($server, $root); + $prop = $result[200]['{DAV:}supported-privilege-set']; + $result = $server->xml->write('{DAV:}root', $prop); - $xpaths = array( + $xpaths = [ '/d:root' => 1, '/d:root/d:supported-privilege' => 1, '/d:root/d:supported-privilege/d:privilege' => 1, @@ -147,19 +117,19 @@ class PluginPropertiesTest extends \PHPUnit_Framework_TestCase { '/d:root/d:supported-privilege/d:supported-privilege/d:supported-privilege/d:privilege/d:bind' => 1, '/d:root/d:supported-privilege/d:supported-privilege/d:supported-privilege/d:privilege/d:unbind' => 1, '/d:root/d:supported-privilege/d:supported-privilege/d:supported-privilege/d:privilege/d:unlock' => 1, - '/d:root/d:supported-privilege/d:supported-privilege/d:supported-privilege/d:abstract' => 8, - ); + '/d:root/d:supported-privilege/d:supported-privilege/d:supported-privilege/d:abstract' => 0, + ]; // reloading because php dom sucks $dom2 = new \DOMDocument('1.0', 'utf-8'); - $dom2->loadXML($dom->saveXML()); + $dom2->loadXML($result); $dxpath = new \DOMXPath($dom2); $dxpath->registerNamespace('d','DAV:'); foreach($xpaths as $xpath=>$count) { - $this->assertEquals($count, $dxpath->query($xpath)->length, 'Looking for : ' . $xpath . ', we could only find ' . $dxpath->query($xpath)->length . ' elements, while we expected ' . $count); + $this->assertEquals($count, $dxpath->query($xpath)->length, 'Looking for : ' . $xpath . ', we could only find ' . $dxpath->query($xpath)->length . ' elements, while we expected ' . $count. ' Full XML: ' . $result); } @@ -169,42 +139,37 @@ class PluginPropertiesTest extends \PHPUnit_Framework_TestCase { $plugin = new Plugin(); - $nodes = array( - new MockACLNode('foo', array( - array( + $nodes = [ + new MockACLNode('foo', [ + [ 'principal' => 'principals/admin', 'privilege' => '{DAV:}read', - ) - )), - new DAV\SimpleCollection('principals', array( + ] + ]), + new DAV\SimpleCollection('principals', [ $principal = new MockPrincipal('admin','principals/admin'), - )), + ]), - ); + ]; $server = new DAV\Server($nodes); $server->addPlugin($plugin); - $authPlugin = new DAV\Auth\Plugin(new DAV\Auth\Backend\Mock(),'realm'); + $authPlugin = new DAV\Auth\Plugin(new DAV\Auth\Backend\Mock()); $server->addPlugin($authPlugin); // Force login - $authPlugin->beforeMethod('BLA','foo'); + $authPlugin->beforeMethod(new HTTP\Request(), new HTTP\Response()); - $requestedProperties = array( + $requestedProperties = [ '{DAV:}acl', - ); + ]; - $returnedProperties = array( - 200 => array(), - 404 => array(), - ); + $result = $server->getPropertiesForPath('foo', $requestedProperties); + $result = $result[0]; - - $this->assertNull($plugin->beforeGetProperties('foo', $nodes[0], $requestedProperties, $returnedProperties)); - - $this->assertEquals(1,count($returnedProperties[200]),'The {DAV:}acl property did not return from the list. Full list: ' . print_r($returnedProperties,true)); - $this->assertArrayHasKey('{DAV:}acl',$returnedProperties[200]); - $this->assertInstanceOf('Sabre\\DAVACL\\Property\\ACL', $returnedProperties[200]['{DAV:}acl']); + $this->assertEquals(1,count($result[200]),'The {DAV:}acl property did not return from the list. Full list: ' . print_r($result, true)); + $this->assertArrayHasKey('{DAV:}acl',$result[200]); + $this->assertInstanceOf('Sabre\\DAVACL\\Xml\Property\\Acl', $result[200]['{DAV:}acl']); } @@ -212,196 +177,176 @@ class PluginPropertiesTest extends \PHPUnit_Framework_TestCase { $plugin = new Plugin(); - $nodes = array( - new MockACLNode('foo', array( - array( + $nodes = [ + new MockACLNode('foo', [ + [ 'principal' => 'principals/admin', 'privilege' => '{DAV:}read', - ) - )), - new DAV\SimpleCollection('principals', array( + ] + ]), + new DAV\SimpleCollection('principals', [ $principal = new MockPrincipal('admin','principals/admin'), - )), + ]), - ); + ]; $server = new DAV\Server($nodes); $server->addPlugin($plugin); - $authPlugin = new DAV\Auth\Plugin(new DAV\Auth\Backend\Mock(),'realm'); + $authPlugin = new DAV\Auth\Plugin(new DAV\Auth\Backend\Mock()); $server->addPlugin($authPlugin); // Force login - $authPlugin->beforeMethod('BLA','foo'); + $authPlugin->beforeMethod(new HTTP\Request(), new HTTP\Response()); - $requestedProperties = array( + $requestedProperties = [ '{DAV:}acl-restrictions', - ); - - $returnedProperties = array( - 200 => array(), - 404 => array(), - ); + ]; + $result = $server->getPropertiesForPath('foo', $requestedProperties); + $result = $result[0]; - $this->assertNull($plugin->beforeGetProperties('foo', $nodes[0], $requestedProperties, $returnedProperties)); - - $this->assertEquals(1,count($returnedProperties[200]),'The {DAV:}acl-restrictions property did not return from the list. Full list: ' . print_r($returnedProperties,true)); - $this->assertArrayHasKey('{DAV:}acl-restrictions',$returnedProperties[200]); - $this->assertInstanceOf('Sabre\\DAVACL\\Property\\ACLRestrictions', $returnedProperties[200]['{DAV:}acl-restrictions']); + $this->assertEquals(1,count($result[200]),'The {DAV:}acl-restrictions property did not return from the list. Full list: ' . print_r($result, true)); + $this->assertArrayHasKey('{DAV:}acl-restrictions',$result[200]); + $this->assertInstanceOf('Sabre\\DAVACL\\Xml\\Property\\AclRestrictions', $result[200]['{DAV:}acl-restrictions']); } function testAlternateUriSet() { - $tree = array( - new DAV\SimpleCollection('principals', array( + $tree = [ + new DAV\SimpleCollection('principals', [ $principal = new MockPrincipal('user','principals/user'), - )), - ); + ]) + ]; $fakeServer = new DAV\Server($tree); - //$plugin = new DAV\Auth\Plugin(new DAV\Auth\MockBackend(),'realm'); + //$plugin = new DAV\Auth\Plugin(new DAV\Auth\MockBackend()) //$fakeServer->addPlugin($plugin); $plugin = new Plugin(); $fakeServer->addPlugin($plugin); - $requestedProperties = array( + $requestedProperties = [ '{DAV:}alternate-URI-set', - ); - $returnedProperties = array(); - - $result = $plugin->beforeGetProperties('principals/user',$principal,$requestedProperties,$returnedProperties); - - $this->assertNull($result); + ]; + $result = $fakeServer->getPropertiesForPath('principals/user', $requestedProperties); + $result = $result[0]; - $this->assertTrue(isset($returnedProperties[200])); - $this->assertTrue(isset($returnedProperties[200]['{DAV:}alternate-URI-set'])); - $this->assertInstanceOf('Sabre\\DAV\\Property\\HrefList', $returnedProperties[200]['{DAV:}alternate-URI-set']); + $this->assertTrue(isset($result[200])); + $this->assertTrue(isset($result[200]['{DAV:}alternate-URI-set'])); + $this->assertInstanceOf('Sabre\\DAV\\Xml\\Property\\Href', $result[200]['{DAV:}alternate-URI-set']); - $this->assertEquals(array(), $returnedProperties[200]['{DAV:}alternate-URI-set']->getHrefs()); + $this->assertEquals([], $result[200]['{DAV:}alternate-URI-set']->getHrefs()); } function testPrincipalURL() { - $tree = array( - new DAV\SimpleCollection('principals', array( + $tree = [ + new DAV\SimpleCollection('principals', [ $principal = new MockPrincipal('user','principals/user'), - )), - ); + ]), + ]; $fakeServer = new DAV\Server($tree); - //$plugin = new DAV\Auth\Plugin(new DAV\Auth\MockBackend(),'realm'); + //$plugin = new DAV\Auth\Plugin(new DAV\Auth\MockBackend()); //$fakeServer->addPlugin($plugin); $plugin = new Plugin(); $fakeServer->addPlugin($plugin); - $requestedProperties = array( + $requestedProperties = [ '{DAV:}principal-URL', - ); - $returnedProperties = array(); + ]; - $result = $plugin->beforeGetProperties('principals/user',$principal,$requestedProperties,$returnedProperties); + $result = $fakeServer->getPropertiesForPath('principals/user', $requestedProperties); + $result = $result[0]; - $this->assertNull($result); + $this->assertTrue(isset($result[200])); + $this->assertTrue(isset($result[200]['{DAV:}principal-URL'])); + $this->assertInstanceOf('Sabre\\DAV\\Xml\\Property\\Href', $result[200]['{DAV:}principal-URL']); - $this->assertTrue(isset($returnedProperties[200])); - $this->assertTrue(isset($returnedProperties[200]['{DAV:}principal-URL'])); - $this->assertInstanceOf('Sabre\\DAV\\Property\\Href', $returnedProperties[200]['{DAV:}principal-URL']); - - $this->assertEquals('principals/user/', $returnedProperties[200]['{DAV:}principal-URL']->getHref()); + $this->assertEquals('principals/user/', $result[200]['{DAV:}principal-URL']->getHref()); } function testGroupMemberSet() { - $tree = array( - new DAV\SimpleCollection('principals', array( + $tree = [ + new DAV\SimpleCollection('principals', [ $principal = new MockPrincipal('user','principals/user'), - )), - ); + ]), + ]; $fakeServer = new DAV\Server($tree); - //$plugin = new DAV\Auth\Plugin(new DAV\Auth\MockBackend(),'realm'); + //$plugin = new DAV\Auth\Plugin(new DAV\Auth\MockBackend()); //$fakeServer->addPlugin($plugin); $plugin = new Plugin(); $fakeServer->addPlugin($plugin); - $requestedProperties = array( + $requestedProperties = [ '{DAV:}group-member-set', - ); - $returnedProperties = array(); - - $result = $plugin->beforeGetProperties('principals/user',$principal,$requestedProperties,$returnedProperties); + ]; - $this->assertNull($result); + $result = $fakeServer->getPropertiesForPath('principals/user', $requestedProperties); + $result = $result[0]; - $this->assertTrue(isset($returnedProperties[200])); - $this->assertTrue(isset($returnedProperties[200]['{DAV:}group-member-set'])); - $this->assertInstanceOf('Sabre\\DAV\\Property\\HrefList', $returnedProperties[200]['{DAV:}group-member-set']); + $this->assertTrue(isset($result[200])); + $this->assertTrue(isset($result[200]['{DAV:}group-member-set'])); + $this->assertInstanceOf('Sabre\\DAV\\Xml\\Property\\Href', $result[200]['{DAV:}group-member-set']); - $this->assertEquals(array(), $returnedProperties[200]['{DAV:}group-member-set']->getHrefs()); + $this->assertEquals([], $result[200]['{DAV:}group-member-set']->getHrefs()); } function testGroupMemberShip() { - $tree = array( - new DAV\SimpleCollection('principals', array( + $tree = [ + new DAV\SimpleCollection('principals', [ $principal = new MockPrincipal('user','principals/user'), - )), - ); + ]), + ]; $fakeServer = new DAV\Server($tree); - //$plugin = new DAV\Auth\Plugin(new DAV\Auth\MockBackend(),'realm'); - //$fakeServer->addPlugin($plugin); $plugin = new Plugin(); $fakeServer->addPlugin($plugin); - $requestedProperties = array( + $requestedProperties = [ '{DAV:}group-membership', - ); - $returnedProperties = array(); + ]; - $result = $plugin->beforeGetProperties('principals/user',$principal,$requestedProperties,$returnedProperties); + $result = $fakeServer->getPropertiesForPath('principals/user', $requestedProperties); + $result = $result[0]; - $this->assertNull($result); + $this->assertTrue(isset($result[200])); + $this->assertTrue(isset($result[200]['{DAV:}group-membership'])); + $this->assertInstanceOf('Sabre\\DAV\\Xml\\Property\\Href', $result[200]['{DAV:}group-membership']); - $this->assertTrue(isset($returnedProperties[200])); - $this->assertTrue(isset($returnedProperties[200]['{DAV:}group-membership'])); - $this->assertInstanceOf('Sabre\\DAV\\Property\\HrefList', $returnedProperties[200]['{DAV:}group-membership']); - - $this->assertEquals(array(), $returnedProperties[200]['{DAV:}group-membership']->getHrefs()); + $this->assertEquals([], $result[200]['{DAV:}group-membership']->getHrefs()); } function testGetDisplayName() { - $tree = array( - new DAV\SimpleCollection('principals', array( + $tree = [ + new DAV\SimpleCollection('principals', [ $principal = new MockPrincipal('user','principals/user'), - )), - ); + ]), + ]; $fakeServer = new DAV\Server($tree); - //$plugin = new DAV\Auth\Plugin(new DAV\Auth\MockBackend(),'realm'); - //$fakeServer->addPlugin($plugin); $plugin = new Plugin(); $fakeServer->addPlugin($plugin); - $requestedProperties = array( + $requestedProperties = [ '{DAV:}displayname', - ); - $returnedProperties = array(); - - $result = $plugin->beforeGetProperties('principals/user',$principal,$requestedProperties,$returnedProperties); + ]; - $this->assertNull($result); + $result = $fakeServer->getPropertiesForPath('principals/user', $requestedProperties); + $result = $result[0]; - $this->assertTrue(isset($returnedProperties[200])); - $this->assertTrue(isset($returnedProperties[200]['{DAV:}displayname'])); + $this->assertTrue(isset($result[200])); + $this->assertTrue(isset($result[200]['{DAV:}displayname'])); - $this->assertEquals('user', $returnedProperties[200]['{DAV:}displayname']); + $this->assertEquals('user', $result[200]['{DAV:}displayname']); } } diff --git a/vendor/sabre/dav/tests/Sabre/DAVACL/PluginUpdatePropertiesTest.php b/vendor/sabre/dav/tests/Sabre/DAVACL/PluginUpdatePropertiesTest.php index 53568654f..64cedd142 100644 --- a/vendor/sabre/dav/tests/Sabre/DAVACL/PluginUpdatePropertiesTest.php +++ b/vendor/sabre/dav/tests/Sabre/DAVACL/PluginUpdatePropertiesTest.php @@ -10,7 +10,7 @@ require_once 'Sabre/DAVACL/MockPrincipal.php'; class PluginUpdatePropertiesTest extends \PHPUnit_Framework_TestCase { - public function testUpdatePropertiesPassthrough() { + function testUpdatePropertiesPassthrough() { $tree = array( new DAV\SimpleCollection('foo'), @@ -23,17 +23,14 @@ class PluginUpdatePropertiesTest extends \PHPUnit_Framework_TestCase { )); $expected = array( - 'href' => 'foo', - '403' => array( - '{DAV:}foo' => null, - ), + '{DAV:}foo' => 403, ); $this->assertEquals($expected, $result); } - public function testRemoveGroupMembers() { + function testRemoveGroupMembers() { $tree = array( new MockPrincipal('foo','foo'), @@ -46,10 +43,7 @@ class PluginUpdatePropertiesTest extends \PHPUnit_Framework_TestCase { )); $expected = array( - 'href' => 'foo', - '200' => array( - '{DAV:}group-member-set' => null, - ), + '{DAV:}group-member-set' => 204 ); $this->assertEquals($expected, $result); @@ -57,34 +51,31 @@ class PluginUpdatePropertiesTest extends \PHPUnit_Framework_TestCase { } - public function testSetGroupMembers() { + function testSetGroupMembers() { - $tree = array( + $tree = [ new MockPrincipal('foo','foo'), - ); + ]; $server = new DAV\Server($tree); $server->addPlugin(new Plugin()); - $result = $server->updateProperties('foo', array( - '{DAV:}group-member-set' => new DAV\Property\HrefList(array('/bar','/baz'), true), - )); + $result = $server->updateProperties('foo', [ + '{DAV:}group-member-set' => new DAV\Xml\Property\Href(['/bar','/baz'], true), + ]); - $expected = array( - 'href' => 'foo', - '200' => array( - '{DAV:}group-member-set' => null, - ), - ); + $expected = [ + '{DAV:}group-member-set' => 200 + ]; $this->assertEquals($expected, $result); - $this->assertEquals(array('bar','baz'),$tree[0]->getGroupMemberSet()); + $this->assertEquals(['bar', 'baz'],$tree[0]->getGroupMemberSet()); } /** * @expectedException Sabre\DAV\Exception */ - public function testSetBadValue() { + function testSetBadValue() { $tree = array( new MockPrincipal('foo','foo'), @@ -98,28 +89,21 @@ class PluginUpdatePropertiesTest extends \PHPUnit_Framework_TestCase { } - public function testSetBadNode() { + function testSetBadNode() { - $tree = array( + $tree = [ new DAV\SimpleCollection('foo'), - ); + ]; $server = new DAV\Server($tree); $server->addPlugin(new Plugin()); - $result = $server->updateProperties('foo', array( - '{DAV:}group-member-set' => new DAV\Property\HrefList(array('/bar','/baz'),false), - '{DAV:}bar' => 'baz', - )); + $result = $server->updateProperties('foo', [ + '{DAV:}group-member-set' => new DAV\Xml\Property\Href(['/bar','/baz'],false), + ]); - $expected = array( - 'href' => 'foo', - '403' => array( - '{DAV:}group-member-set' => null, - ), - '424' => array( - '{DAV:}bar' => null, - ), - ); + $expected = [ + '{DAV:}group-member-set' => 403, + ]; $this->assertEquals($expected, $result); diff --git a/vendor/sabre/dav/tests/Sabre/DAVACL/PrincipalBackend/AbstractPDOTest.php b/vendor/sabre/dav/tests/Sabre/DAVACL/PrincipalBackend/AbstractPDOTest.php index 3fe75ca0e..3814ebc0d 100644 --- a/vendor/sabre/dav/tests/Sabre/DAVACL/PrincipalBackend/AbstractPDOTest.php +++ b/vendor/sabre/dav/tests/Sabre/DAVACL/PrincipalBackend/AbstractPDOTest.php @@ -128,10 +128,12 @@ abstract class AbstractPDOTest extends \PHPUnit_Framework_TestCase { $pdo = $this->getPDO(); $backend = new PDO($pdo); - $result = $backend->updatePrincipal('principals/user', array( + $propPatch = new DAV\PropPatch([ '{DAV:}displayname' => 'pietje', - '{http://sabredav.org/ns}vcard-url' => 'blabla', - )); + ]); + + $backend->updatePrincipal('principals/user', $propPatch); + $result = $propPatch->commit(); $this->assertTrue($result); @@ -139,7 +141,6 @@ abstract class AbstractPDOTest extends \PHPUnit_Framework_TestCase { 'id' => 1, 'uri' => 'principals/user', '{DAV:}displayname' => 'pietje', - '{http://sabredav.org/ns}vcard-url' => 'blabla', '{http://sabredav.org/ns}email-address' => 'user@example.org', ), $backend->getPrincipalByPath('principals/user')); @@ -150,21 +151,20 @@ abstract class AbstractPDOTest extends \PHPUnit_Framework_TestCase { $pdo = $this->getPDO(); $backend = new PDO($pdo); - $result = $backend->updatePrincipal('principals/user', array( + $propPatch = new DAV\PropPatch([ '{DAV:}displayname' => 'pietje', - '{http://sabredav.org/ns}vcard-url' => 'blabla', '{DAV:}unknown' => 'foo', - )); + ]); + + $backend->updatePrincipal('principals/user', $propPatch); + $result = $propPatch->commit(); + + $this->assertFalse($result); $this->assertEquals(array( - 424 => array( - '{DAV:}displayname' => null, - '{http://sabredav.org/ns}vcard-url' => null, - ), - 403 => array( - '{DAV:}unknown' => null, - ), - ), $result); + '{DAV:}displayname' => 424, + '{DAV:}unknown' => 403 + ), $propPatch->getResult()); $this->assertEquals(array( 'id' => '1', @@ -175,4 +175,24 @@ abstract class AbstractPDOTest extends \PHPUnit_Framework_TestCase { } + function testFindByUriUnknownScheme() { + + $pdo = $this->getPDO(); + $backend = new PDO($pdo); + $this->assertNull($backend->findByUri('http://foo', 'principals')); + + } + + + function testFindByUri() { + + $pdo = $this->getPDO(); + $backend = new PDO($pdo); + $this->assertEquals( + 'principals/user', + $backend->findByUri('mailto:user@example.org', 'principals') + ); + + } + } diff --git a/vendor/sabre/dav/tests/Sabre/DAVACL/PrincipalBackend/Mock.php b/vendor/sabre/dav/tests/Sabre/DAVACL/PrincipalBackend/Mock.php index 354446e34..afb094a39 100644 --- a/vendor/sabre/dav/tests/Sabre/DAVACL/PrincipalBackend/Mock.php +++ b/vendor/sabre/dav/tests/Sabre/DAVACL/PrincipalBackend/Mock.php @@ -4,40 +4,46 @@ namespace Sabre\DAVACL\PrincipalBackend; class Mock extends AbstractBackend { - public $groupMembers = array(); + public $groupMembers = []; public $principals; - function __construct() { + function __construct(array $principals = null) { - $this->principals = array( - array( - 'uri' => 'principals/user1', - '{DAV:}displayname' => 'User 1', + $this->principals = $principals; + + if (is_null($principals)) { + + $this->principals = [ + [ + 'uri' => 'principals/user1', + '{DAV:}displayname' => 'User 1', '{http://sabredav.org/ns}email-address' => 'user1.sabredav@sabredav.org', - '{http://sabredav.org/ns}vcard-url' => 'addressbooks/user1/book1/vcard1.vcf', - ), - array( - 'uri' => 'principals/admin', + '{http://sabredav.org/ns}vcard-url' => 'addressbooks/user1/book1/vcard1.vcf', + ], + [ + 'uri' => 'principals/admin', '{DAV:}displayname' => 'Admin', - ), - array( - 'uri' => 'principals/user2', - '{DAV:}displayname' => 'User 2', + ], + [ + 'uri' => 'principals/user2', + '{DAV:}displayname' => 'User 2', '{http://sabredav.org/ns}email-address' => 'user2.sabredav@sabredav.org', - ), - ); + ], + ]; + } } function getPrincipalsByPrefix($prefix) { - $prefix = trim($prefix,'/') . '/'; - $return = array(); + $prefix = trim($prefix, '/'); + if ($prefix) $prefix .= '/'; + $return = []; - foreach($this->principals as $principal) { + foreach ($this->principals as $principal) { - if (strpos($principal['uri'], $prefix)!==0) continue; + if ($prefix && strpos($principal['uri'], $prefix) !== 0) continue; $return[] = $principal; @@ -55,26 +61,33 @@ class Mock extends AbstractBackend { function getPrincipalByPath($path) { - foreach($this->getPrincipalsByPrefix('principals') as $principal) { + foreach ($this->getPrincipalsByPrefix('principals') as $principal) { if ($principal['uri'] === $path) return $principal; } } - function searchPrincipals($prefixPath, array $searchProperties) { + function searchPrincipals($prefixPath, array $searchProperties, $test = 'allof') { - $matches = array(); - foreach($this->getPrincipalsByPrefix($prefixPath) as $principal) { + $matches = []; + foreach ($this->getPrincipalsByPrefix($prefixPath) as $principal) { - foreach($searchProperties as $key=>$value) { + foreach ($searchProperties as $key => $value) { if (!isset($principal[$key])) { continue 2; } - if (mb_stripos($principal[$key],$value, 0, 'UTF-8')===false) { + if (mb_stripos($principal[$key], $value, 0, 'UTF-8') === false) { continue 2; } + // We have a match for this searchProperty! + if ($test === 'allof') { + continue; + } else { + break; + } + } $matches[] = $principal['uri']; @@ -85,14 +98,14 @@ class Mock extends AbstractBackend { function getGroupMemberSet($path) { - return isset($this->groupMembers[$path]) ? $this->groupMembers[$path] : array(); + return isset($this->groupMembers[$path]) ? $this->groupMembers[$path] : []; } function getGroupMembership($path) { - $membership = array(); - foreach($this->groupMembers as $group=>$members) { + $membership = []; + foreach ($this->groupMembers as $group => $members) { if (in_array($path, $members)) $membership[] = $group; } return $membership; @@ -108,75 +121,46 @@ class Mock extends AbstractBackend { /** * Updates one ore more webdav properties on a principal. * - * The list of mutations is supplied as an array. Each key in the array is - * a propertyname, such as {DAV:}displayname. - * - * Each value is the actual value to be updated. If a value is null, it - * must be deleted. - * - * This method should be atomic. It must either completely succeed, or - * completely fail. Success and failure can simply be returned as 'true' or - * 'false'. - * - * It is also possible to return detailed failure information. In that case - * an array such as this should be returned: + * 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. * - * array( - * 200 => array( - * '{DAV:}prop1' => null, - * ), - * 201 => array( - * '{DAV:}prop2' => null, - * ), - * 403 => array( - * '{DAV:}prop3' => null, - * ), - * 424 => array( - * '{DAV:}prop4' => null, - * ), - * ); + * Calling the handle method is like telling the PropPatch object "I + * promise I can handle updating this property". * - * In this previous example prop1 was successfully updated or deleted, and - * prop2 was succesfully created. - * - * prop3 failed to update due to '403 Forbidden' and because of this prop4 - * also could not be updated with '424 Failed dependency'. - * - * This last example was actually incorrect. While 200 and 201 could appear - * in 1 response, if there's any error (403) the other properties should - * always fail with 423 (failed dependency). - * - * But anyway, if you don't want to scratch your head over this, just - * return true or false. + * Read the PropPatch documenation for more info and examples. * * @param string $path - * @param array $mutations - * @return array|bool + * @param \Sabre\DAV\PropPatch $propPatch */ - public function updatePrincipal($path, $mutations) { + function updatePrincipal($path, \Sabre\DAV\PropPatch $propPatch) { $value = null; - foreach($this->principals as $principalIndex=>$value) { + foreach ($this->principals as $principalIndex => $value) { if ($value['uri'] === $path) { $principal = $value; break; } } - if (!$principal) return false; + if (!$principal) return; + + $propPatch->handleRemaining(function($mutations) use ($principal, $principalIndex) { - foreach($mutations as $prop=>$value) { + foreach ($mutations as $prop => $value) { + + if (is_null($value) && isset($principal[$prop])) { + unset($principal[$prop]); + } else { + $principal[$prop] = $value; + } - if (is_null($value) && isset($principal[$prop])) { - unset($principal[$prop]); - } else { - $principal[$prop] = $value; } - } + $this->principals[$principalIndex] = $principal; - $this->principals[$principalIndex] = $principal; + return true; - return true; + }); } diff --git a/vendor/sabre/dav/tests/Sabre/DAVACL/PrincipalBackend/PDOMySQLTest.php b/vendor/sabre/dav/tests/Sabre/DAVACL/PrincipalBackend/PDOMySQLTest.php index 84ba062ca..83353c86c 100644 --- a/vendor/sabre/dav/tests/Sabre/DAVACL/PrincipalBackend/PDOMySQLTest.php +++ b/vendor/sabre/dav/tests/Sabre/DAVACL/PrincipalBackend/PDOMySQLTest.php @@ -16,25 +16,30 @@ class PDOMySQLTest extends AbstractPDOTest { $pdo = \Sabre\TestUtil::getMySQLDB(); if (!$pdo) $this->markTestSkipped('Could not connect to MySQL database'); $pdo->query("DROP TABLE IF EXISTS principals"); - $pdo->query(" + $pdo->query(<<<SQL create table principals ( - id integer unsigned not null primary key auto_increment, - uri varchar(50), - email varchar(80), - displayname VARCHAR(80), - vcardurl VARCHAR(80), - unique(uri) -);"); + id integer unsigned not null primary key auto_increment, + uri varchar(50), + email varchar(80), + displayname VARCHAR(80), + vcardurl VARCHAR(80), + unique(uri) +) +SQL + ); $pdo->query("INSERT INTO principals (uri,email,displayname) VALUES ('principals/user','user@example.org','User')"); $pdo->query("INSERT INTO principals (uri,email,displayname) VALUES ('principals/group','group@example.org','Group')"); $pdo->query("DROP TABLE IF EXISTS groupmembers"); - $pdo->query("CREATE TABLE groupmembers ( - id INTEGER UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT, - principal_id INTEGER UNSIGNED NOT NULL, - member_id INTEGER UNSIGNED NOT NULL, - UNIQUE(principal_id, member_id) - );"); + $pdo->query(<<<SQL +CREATE TABLE groupmembers ( + id INTEGER UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT, + principal_id INTEGER UNSIGNED NOT NULL, + member_id INTEGER UNSIGNED NOT NULL, + UNIQUE(principal_id, member_id) +) +SQL + ); $pdo->query("INSERT INTO groupmembers (principal_id,member_id) VALUES (2,1)"); diff --git a/vendor/sabre/dav/tests/Sabre/DAVACL/PrincipalBackend/PDOSqliteTest.php b/vendor/sabre/dav/tests/Sabre/DAVACL/PrincipalBackend/PDOSqliteTest.php index 192e188f9..f335ed51f 100644 --- a/vendor/sabre/dav/tests/Sabre/DAVACL/PrincipalBackend/PDOSqliteTest.php +++ b/vendor/sabre/dav/tests/Sabre/DAVACL/PrincipalBackend/PDOSqliteTest.php @@ -22,16 +22,19 @@ class PDOSQLiteTest extends AbstractPDOTest { if (!SABRE_HASSQLITE) $this->markTestSkipped('SQLite driver is not available'); $pdo = new \PDO('sqlite:'.SABRE_TEMPDIR.'/pdobackend'); $pdo->setAttribute(\PDO::ATTR_ERRMODE,\PDO::ERRMODE_EXCEPTION); - $pdo->query('CREATE TABLE principals (id INTEGER PRIMARY KEY ASC, uri TEXT, email VARCHAR(80), displayname VARCHAR(80), vcardurl VARCHAR(80))'); - $pdo->query('INSERT INTO principals VALUES (1, "principals/user","user@example.org","User",null)'); - $pdo->query('INSERT INTO principals VALUES (2, "principals/group","group@example.org","Group",null)'); - - $pdo->query("CREATE TABLE groupmembers ( - id INTEGER PRIMARY KEY ASC, - principal_id INT, - member_id INT, - UNIQUE(principal_id, member_id) - );"); + $pdo->query('CREATE TABLE principals (id INTEGER PRIMARY KEY ASC, uri TEXT, email VARCHAR(80), displayname VARCHAR(80))'); + $pdo->query('INSERT INTO principals VALUES (1, "principals/user","user@example.org","User")'); + $pdo->query('INSERT INTO principals VALUES (2, "principals/group","group@example.org","Group")'); + + $pdo->query(<<<SQL +CREATE TABLE groupmembers ( + id INTEGER PRIMARY KEY ASC, + principal_id INT, + member_id INT, + UNIQUE(principal_id, member_id) +) +SQL + ); $pdo->query("INSERT INTO groupmembers (principal_id,member_id) VALUES (2,1)"); diff --git a/vendor/sabre/dav/tests/Sabre/DAVACL/PrincipalCollectionTest.php b/vendor/sabre/dav/tests/Sabre/DAVACL/PrincipalCollectionTest.php index 10b0c04da..f51d2dcce 100644 --- a/vendor/sabre/dav/tests/Sabre/DAVACL/PrincipalCollectionTest.php +++ b/vendor/sabre/dav/tests/Sabre/DAVACL/PrincipalCollectionTest.php @@ -49,4 +49,13 @@ class PrincipalCollectionTest extends \PHPUnit_Framework_TestCase { } + public function testFindByUri() { + + $backend = new PrincipalBackend\Mock(); + $pc = new PrincipalCollection($backend); + $this->assertEquals('principals/user1', $pc->findByUri('mailto:user1.sabredav@sabredav.org')); + $this->assertNull($pc->findByUri('mailto:fake.user.sabredav@sabredav.org')); + $this->assertNull($pc->findByUri('')); + } + } diff --git a/vendor/sabre/dav/tests/Sabre/DAVACL/PrincipalPropertySearchTest.php b/vendor/sabre/dav/tests/Sabre/DAVACL/PrincipalPropertySearchTest.php index 9c3be4f9a..8e4c86782 100644 --- a/vendor/sabre/dav/tests/Sabre/DAVACL/PrincipalPropertySearchTest.php +++ b/vendor/sabre/dav/tests/Sabre/DAVACL/PrincipalPropertySearchTest.php @@ -17,10 +17,11 @@ class PrincipalPropertySearchTest extends \PHPUnit_Framework_TestCase { $principals = new PrincipalCollection($backend); $dir->addChild($principals); - $fakeServer = new DAV\Server(new DAV\ObjectTree($dir)); + $fakeServer = new DAV\Server($dir); + $fakeServer->sapi = new HTTP\SapiMock(); $fakeServer->httpResponse = new HTTP\ResponseMock(); $fakeServer->debugExceptions = true; - $plugin = new MockPlugin($backend,'realm'); + $plugin = new MockPlugin(); $plugin->allowAccessToNodesWithoutACL = true; $this->assertTrue($plugin instanceof Plugin); @@ -53,7 +54,7 @@ class PrincipalPropertySearchTest extends \PHPUnit_Framework_TestCase { 'REQUEST_URI' => '/principals', ); - $request = new HTTP\Request($serverVars); + $request = HTTP\Sapi::createFromServerArray($serverVars); $request->setBody($xml); $server = $this->getServer(); @@ -61,10 +62,11 @@ class PrincipalPropertySearchTest extends \PHPUnit_Framework_TestCase { $server->exec(); - $this->assertEquals('HTTP/1.1 400 Bad request', $server->httpResponse->status); + $this->assertEquals(400, $server->httpResponse->getStatus(), $server->httpResponse->getBodyAsString()); $this->assertEquals(array( - 'Content-Type' => 'application/xml; charset=utf-8', - ), $server->httpResponse->headers); + 'X-Sabre-Version' => [DAV\Version::VERSION], + 'Content-Type' => ['application/xml; charset=utf-8'], + ), $server->httpResponse->getHeaders()); } @@ -91,7 +93,7 @@ class PrincipalPropertySearchTest extends \PHPUnit_Framework_TestCase { 'REQUEST_URI' => '/principals', ); - $request = new HTTP\Request($serverVars); + $request = HTTP\Sapi::createFromServerArray($serverVars); $request->setBody($xml); $server = $this->getServer(); @@ -99,11 +101,12 @@ class PrincipalPropertySearchTest extends \PHPUnit_Framework_TestCase { $server->exec(); - $this->assertEquals('HTTP/1.1 207 Multi-Status', $server->httpResponse->status); + $this->assertEquals(207, $server->httpResponse->getStatus(), "Full body: " . $server->httpResponse->getBodyAsString()); $this->assertEquals(array( - 'Content-Type' => 'application/xml; charset=utf-8', - 'Vary' => 'Brief,Prefer', - ), $server->httpResponse->headers); + 'X-Sabre-Version' => [DAV\Version::VERSION], + 'Content-Type' => ['application/xml; charset=utf-8'], + 'Vary' => ['Brief,Prefer'], + ), $server->httpResponse->getHeaders()); } @@ -130,7 +133,7 @@ class PrincipalPropertySearchTest extends \PHPUnit_Framework_TestCase { 'REQUEST_URI' => '/', ); - $request = new HTTP\Request($serverVars); + $request = HTTP\Sapi::createFromServerArray($serverVars); $request->setBody($xml); $server = $this->getServer(); @@ -138,11 +141,157 @@ class PrincipalPropertySearchTest extends \PHPUnit_Framework_TestCase { $server->exec(); - $this->assertEquals('HTTP/1.1 207 Multi-Status', $server->httpResponse->status, $server->httpResponse->body); + $this->assertEquals(207, $server->httpResponse->status, $server->httpResponse->body); $this->assertEquals(array( - 'Content-Type' => 'application/xml; charset=utf-8', - 'Vary' => 'Brief,Prefer', - ), $server->httpResponse->headers); + 'X-Sabre-Version' => [DAV\Version::VERSION], + 'Content-Type' => ['application/xml; charset=utf-8'], + 'Vary' => ['Brief,Prefer'], + ), $server->httpResponse->getHeaders()); + + + $check = array( + '/d:multistatus', + '/d:multistatus/d:response' => 2, + '/d:multistatus/d:response/d:href' => 2, + '/d:multistatus/d:response/d:propstat' => 4, + '/d:multistatus/d:response/d:propstat/d:prop' => 4, + '/d:multistatus/d:response/d:propstat/d:prop/d:displayname' => 2, + '/d:multistatus/d:response/d:propstat/d:prop/d:getcontentlength' => 2, + '/d:multistatus/d:response/d:propstat/d:status' => 4, + ); + + $xml = simplexml_load_string($server->httpResponse->body); + $xml->registerXPathNamespace('d','DAV:'); + foreach($check as $v1=>$v2) { + + $xpath = is_int($v1)?$v2:$v1; + + $result = $xml->xpath($xpath); + + $count = 1; + if (!is_int($v1)) $count = $v2; + + $this->assertEquals($count,count($result), 'we expected ' . $count . ' appearances of ' . $xpath . ' . We found ' . count($result) . '. Full response body: ' . $server->httpResponse->body); + + } + + } + + function testAND() { + + $xml = '<?xml version="1.0"?> +<d:principal-property-search xmlns:d="DAV:"> + <d:apply-to-principal-collection-set /> + <d:property-search> + <d:prop> + <d:displayname /> + </d:prop> + <d:match>user</d:match> + </d:property-search> + <d:property-search> + <d:prop> + <d:foo /> + </d:prop> + <d:match>bar</d:match> + </d:property-search> + <d:prop> + <d:displayname /> + <d:getcontentlength /> + </d:prop> +</d:principal-property-search>'; + + $serverVars = array( + 'REQUEST_METHOD' => 'REPORT', + 'HTTP_DEPTH' => '0', + 'REQUEST_URI' => '/', + ); + + $request = HTTP\Sapi::createFromServerArray($serverVars); + $request->setBody($xml); + + $server = $this->getServer(); + $server->httpRequest = $request; + + $server->exec(); + + $this->assertEquals(207, $server->httpResponse->status, $server->httpResponse->body); + $this->assertEquals(array( + 'X-Sabre-Version' => [DAV\Version::VERSION], + 'Content-Type' => ['application/xml; charset=utf-8'], + 'Vary' => ['Brief,Prefer'], + ), $server->httpResponse->getHeaders()); + + + $check = array( + '/d:multistatus', + '/d:multistatus/d:response' => 0, + '/d:multistatus/d:response/d:href' => 0, + '/d:multistatus/d:response/d:propstat' => 0, + '/d:multistatus/d:response/d:propstat/d:prop' => 0, + '/d:multistatus/d:response/d:propstat/d:prop/d:displayname' => 0, + '/d:multistatus/d:response/d:propstat/d:prop/d:getcontentlength' => 0, + '/d:multistatus/d:response/d:propstat/d:status' => 0, + ); + + $xml = simplexml_load_string($server->httpResponse->body); + $xml->registerXPathNamespace('d','DAV:'); + foreach($check as $v1=>$v2) { + + $xpath = is_int($v1)?$v2:$v1; + + $result = $xml->xpath($xpath); + + $count = 1; + if (!is_int($v1)) $count = $v2; + + $this->assertEquals($count,count($result), 'we expected ' . $count . ' appearances of ' . $xpath . ' . We found ' . count($result) . '. Full response body: ' . $server->httpResponse->body); + + } + + } + function testOR() { + + $xml = '<?xml version="1.0"?> +<d:principal-property-search xmlns:d="DAV:" test="anyof"> + <d:apply-to-principal-collection-set /> + <d:property-search> + <d:prop> + <d:displayname /> + </d:prop> + <d:match>user</d:match> + </d:property-search> + <d:property-search> + <d:prop> + <d:foo /> + </d:prop> + <d:match>bar</d:match> + </d:property-search> + <d:prop> + <d:displayname /> + <d:getcontentlength /> + </d:prop> +</d:principal-property-search>'; + + $serverVars = array( + 'REQUEST_METHOD' => 'REPORT', + 'HTTP_DEPTH' => '0', + 'REQUEST_URI' => '/', + ); + + $request = HTTP\Sapi::createFromServerArray($serverVars); + $request->setBody($xml); + + $server = $this->getServer(); + $server->httpRequest = $request; + + $server->exec(); + + $this->assertEquals(207, $server->httpResponse->status, $server->httpResponse->body); + $this->assertEquals(array( + 'X-Sabre-Version' => [DAV\Version::VERSION], + 'Content-Type' => ['application/xml; charset=utf-8'], + 'Vary' => ['Brief,Prefer'], + ), $server->httpResponse->getHeaders()); $check = array( @@ -194,7 +343,7 @@ class PrincipalPropertySearchTest extends \PHPUnit_Framework_TestCase { 'REQUEST_URI' => '/', ); - $request = new HTTP\Request($serverVars); + $request = HTTP\Sapi::createFromServerArray($serverVars); $request->setBody($xml); $server = $this->getServer(); @@ -202,11 +351,12 @@ class PrincipalPropertySearchTest extends \PHPUnit_Framework_TestCase { $server->exec(); - $this->assertEquals('HTTP/1.1 207 Multi-Status', $server->httpResponse->status, $server->httpResponse->body); + $this->assertEquals(207, $server->httpResponse->status, $server->httpResponse->body); $this->assertEquals(array( - 'Content-Type' => 'application/xml; charset=utf-8', - 'Vary' => 'Brief,Prefer', - ), $server->httpResponse->headers); + 'X-Sabre-Version' => [DAV\Version::VERSION], + 'Content-Type' => ['application/xml; charset=utf-8'], + 'Vary' => ['Brief,Prefer'], + ), $server->httpResponse->getHeaders()); $check = array( diff --git a/vendor/sabre/dav/tests/Sabre/DAVACL/PrincipalSearchPropertySetTest.php b/vendor/sabre/dav/tests/Sabre/DAVACL/PrincipalSearchPropertySetTest.php index 412389e8b..952dc174a 100644 --- a/vendor/sabre/dav/tests/Sabre/DAVACL/PrincipalSearchPropertySetTest.php +++ b/vendor/sabre/dav/tests/Sabre/DAVACL/PrincipalSearchPropertySetTest.php @@ -17,9 +17,10 @@ class PrincipalSearchPropertySetTest extends \PHPUnit_Framework_TestCase { $principals = new PrincipalCollection($backend); $dir->addChild($principals); - $fakeServer = new DAV\Server(new DAV\ObjectTree($dir)); + $fakeServer = new DAV\Server($dir); + $fakeServer->sapi = new HTTP\SapiMock(); $fakeServer->httpResponse = new HTTP\ResponseMock(); - $plugin = new Plugin($backend,'realm'); + $plugin = new Plugin(); $this->assertTrue($plugin instanceof Plugin); $fakeServer->addPlugin($plugin); $this->assertEquals($plugin, $fakeServer->getPlugin('acl')); @@ -39,7 +40,7 @@ class PrincipalSearchPropertySetTest extends \PHPUnit_Framework_TestCase { 'REQUEST_URI' => '/principals', ); - $request = new HTTP\Request($serverVars); + $request = HTTP\Sapi::createFromServerArray($serverVars); $request->setBody($xml); $server = $this->getServer(); @@ -47,10 +48,11 @@ class PrincipalSearchPropertySetTest extends \PHPUnit_Framework_TestCase { $server->exec(); - $this->assertEquals('HTTP/1.1 400 Bad request', $server->httpResponse->status); + $this->assertEquals(400, $server->httpResponse->status); $this->assertEquals(array( - 'Content-Type' => 'application/xml; charset=utf-8', - ), $server->httpResponse->headers); + 'X-Sabre-Version' => [DAV\Version::VERSION], + 'Content-Type' => ['application/xml; charset=utf-8'], + ), $server->httpResponse->getHeaders()); } @@ -65,7 +67,7 @@ class PrincipalSearchPropertySetTest extends \PHPUnit_Framework_TestCase { 'REQUEST_URI' => '/principals', ); - $request = new HTTP\Request($serverVars); + $request = HTTP\Sapi::createFromServerArray($serverVars); $request->setBody($xml); $server = $this->getServer(); @@ -73,10 +75,11 @@ class PrincipalSearchPropertySetTest extends \PHPUnit_Framework_TestCase { $server->exec(); - $this->assertEquals('HTTP/1.1 400 Bad request', $server->httpResponse->status, $server->httpResponse->body); + $this->assertEquals(400, $server->httpResponse->status, $server->httpResponse->body); $this->assertEquals(array( - 'Content-Type' => 'application/xml; charset=utf-8', - ), $server->httpResponse->headers); + 'X-Sabre-Version' => [DAV\Version::VERSION], + 'Content-Type' => ['application/xml; charset=utf-8'], + ), $server->httpResponse->getHeaders()); } @@ -91,7 +94,7 @@ class PrincipalSearchPropertySetTest extends \PHPUnit_Framework_TestCase { 'REQUEST_URI' => '/principals', ); - $request = new HTTP\Request($serverVars); + $request = HTTP\Sapi::createFromServerArray($serverVars); $request->setBody($xml); $server = $this->getServer(); @@ -99,10 +102,11 @@ class PrincipalSearchPropertySetTest extends \PHPUnit_Framework_TestCase { $server->exec(); - $this->assertEquals('HTTP/1.1 200 OK', $server->httpResponse->status, $server->httpResponse->body); + $this->assertEquals(200, $server->httpResponse->status, $server->httpResponse->body); $this->assertEquals(array( - 'Content-Type' => 'application/xml; charset=utf-8', - ), $server->httpResponse->headers); + 'X-Sabre-Version' => [DAV\Version::VERSION], + 'Content-Type' => ['application/xml; charset=utf-8'], + ), $server->httpResponse->getHeaders()); $check = array( diff --git a/vendor/sabre/dav/tests/Sabre/DAVACL/PrincipalTest.php b/vendor/sabre/dav/tests/Sabre/DAVACL/PrincipalTest.php index 2d4371138..03fd9d64d 100644 --- a/vendor/sabre/dav/tests/Sabre/DAVACL/PrincipalTest.php +++ b/vendor/sabre/dav/tests/Sabre/DAVACL/PrincipalTest.php @@ -75,8 +75,12 @@ class PrincipalTest extends \PHPUnit_Framework_TestCase { $principalBackend = new PrincipalBackend\Mock(); $principal = new Principal($principalBackend, array('uri' => 'principals/admin')); - $result = $principal->updateProperties(array('{DAV:}yourmom'=>'test')); - $this->assertEquals(true,$result); + + $propPatch = new DAV\PropPatch(array('{DAV:}yourmom' => 'test')); + + $result = $principal->propPatch($propPatch); + $result = $propPatch->commit(); + $this->assertTrue($result); } @@ -175,7 +179,7 @@ class PrincipalTest extends \PHPUnit_Framework_TestCase { $this->assertEquals(array( array( 'privilege' => '{DAV:}read', - 'principal' => 'principals/admin', + 'principal' => '{DAV:}authenticated', 'protected' => true, ) ),$principal->getACL()); diff --git a/vendor/sabre/dav/tests/Sabre/DAVACL/Property/ACLRestrictionsTest.php b/vendor/sabre/dav/tests/Sabre/DAVACL/Property/ACLRestrictionsTest.php deleted file mode 100644 index 72a2f36a4..000000000 --- a/vendor/sabre/dav/tests/Sabre/DAVACL/Property/ACLRestrictionsTest.php +++ /dev/null @@ -1,35 +0,0 @@ -<?php - -namespace Sabre\DAVACL\Property; - -use Sabre\DAV; -use Sabre\HTTP; - -class ACLRestrictionsTest extends \PHPUnit_Framework_TestCase { - - function testConstruct() { - - $prop = new AclRestrictions(); - - } - - function testSerializeEmpty() { - - $dom = new \DOMDocument('1.0'); - $root = $dom->createElementNS('DAV:','d:root'); - - $dom->appendChild($root); - - $acl = new AclRestrictions(); - $acl->serialize(new DAV\Server(), $root); - - $xml = $dom->saveXML(); - $expected = '<?xml version="1.0"?> -<d:root xmlns:d="DAV:"><d:grant-only/><d:no-invert/></d:root> -'; - $this->assertEquals($expected, $xml); - - } - - -} diff --git a/vendor/sabre/dav/tests/Sabre/DAVACL/Property/ACLTest.php b/vendor/sabre/dav/tests/Sabre/DAVACL/Property/ACLTest.php deleted file mode 100644 index 7f2014df3..000000000 --- a/vendor/sabre/dav/tests/Sabre/DAVACL/Property/ACLTest.php +++ /dev/null @@ -1,335 +0,0 @@ -<?php - -namespace Sabre\DAVACL\Property; - -use Sabre\DAV; -use Sabre\HTTP; - - -class ACLTest extends \PHPUnit_Framework_TestCase { - - function testConstruct() { - - $acl = new Acl(array()); - - } - - function testSerializeEmpty() { - - $dom = new \DOMDocument('1.0'); - $root = $dom->createElementNS('DAV:','d:root'); - - $dom->appendChild($root); - - $acl = new Acl(array()); - $acl->serialize(new DAV\Server(), $root); - - $xml = $dom->saveXML(); - $expected = '<?xml version="1.0"?> -<d:root xmlns:d="DAV:"/> -'; - $this->assertEquals($expected, $xml); - - } - - function testSerialize() { - - $dom = new \DOMDocument('1.0'); - $root = $dom->createElementNS('DAV:','d:root'); - - $dom->appendChild($root); - - $privileges = array( - array( - 'principal' => 'principals/evert', - 'privilege' => '{DAV:}write', - 'uri' => 'articles', - ), - array( - 'principal' => 'principals/foo', - 'privilege' => '{DAV:}read', - 'uri' => 'articles', - 'protected' => true, - ), - ); - - $acl = new Acl($privileges); - $acl->serialize(new DAV\Server(), $root); - - $dom->formatOutput = true; - - $xml = $dom->saveXML(); - $expected = '<?xml version="1.0"?> -<d:root xmlns:d="DAV:"> - <d:ace> - <d:principal> - <d:href>/principals/evert/</d:href> - </d:principal> - <d:grant> - <d:privilege> - <d:write/> - </d:privilege> - </d:grant> - </d:ace> - <d:ace> - <d:principal> - <d:href>/principals/foo/</d:href> - </d:principal> - <d:grant> - <d:privilege> - <d:read/> - </d:privilege> - </d:grant> - <d:protected/> - </d:ace> -</d:root> -'; - $this->assertEquals($expected, $xml); - - } - - function testSerializeSpecialPrincipals() { - - $dom = new \DOMDocument('1.0'); - $root = $dom->createElementNS('DAV:','d:root'); - - $dom->appendChild($root); - - $privileges = array( - array( - 'principal' => '{DAV:}authenticated', - 'privilege' => '{DAV:}write', - 'uri' => 'articles', - ), - array( - 'principal' => '{DAV:}unauthenticated', - 'privilege' => '{DAV:}write', - 'uri' => 'articles', - ), - array( - 'principal' => '{DAV:}all', - 'privilege' => '{DAV:}write', - 'uri' => 'articles', - ), - - ); - - $acl = new Acl($privileges); - $acl->serialize(new DAV\Server(), $root); - - $dom->formatOutput = true; - - $xml = $dom->saveXML(); - $expected = '<?xml version="1.0"?> -<d:root xmlns:d="DAV:"> - <d:ace> - <d:principal> - <d:authenticated/> - </d:principal> - <d:grant> - <d:privilege> - <d:write/> - </d:privilege> - </d:grant> - </d:ace> - <d:ace> - <d:principal> - <d:unauthenticated/> - </d:principal> - <d:grant> - <d:privilege> - <d:write/> - </d:privilege> - </d:grant> - </d:ace> - <d:ace> - <d:principal> - <d:all/> - </d:principal> - <d:grant> - <d:privilege> - <d:write/> - </d:privilege> - </d:grant> - </d:ace> -</d:root> -'; - $this->assertEquals($expected, $xml); - - } - - function testUnserialize() { - - $source = '<?xml version="1.0"?> -<d:root xmlns:d="DAV:"> - <d:ace> - <d:principal> - <d:href>/principals/evert/</d:href> - </d:principal> - <d:grant> - <d:privilege> - <d:write/> - </d:privilege> - </d:grant> - </d:ace> - <d:ace> - <d:principal> - <d:href>/principals/foo/</d:href> - </d:principal> - <d:grant> - <d:privilege> - <d:read/> - </d:privilege> - </d:grant> - <d:protected/> - </d:ace> -</d:root> -'; - - $dom = DAV\XMLUtil::loadDOMDocument($source); - $result = Acl::unserialize($dom->firstChild); - - $this->assertInstanceOf('Sabre\\DAVACL\\Property\\ACL', $result); - - $expected = array( - array( - 'principal' => '/principals/evert/', - 'protected' => false, - 'privilege' => '{DAV:}write', - ), - array( - 'principal' => '/principals/foo/', - 'protected' => true, - 'privilege' => '{DAV:}read', - ), - ); - - $this->assertEquals($expected, $result->getPrivileges()); - - - } - - /** - * @expectedException Sabre\DAV\Exception\BadRequest - */ - function testUnserializeNoPrincipal() { - - $source = '<?xml version="1.0"?> -<d:root xmlns:d="DAV:"> - <d:ace> - <d:grant> - <d:privilege> - <d:write/> - </d:privilege> - </d:grant> - </d:ace> -</d:root> -'; - - $dom = DAV\XMLUtil::loadDOMDocument($source); - Acl::unserialize($dom->firstChild); - - } - - function testUnserializeOtherPrincipal() { - - $source = '<?xml version="1.0"?> -<d:root xmlns:d="DAV:"> - <d:ace> - <d:grant> - <d:privilege> - <d:write/> - </d:privilege> - </d:grant> - <d:principal><d:authenticated /></d:principal> - </d:ace> - <d:ace> - <d:grant> - <d:privilege> - <d:write/> - </d:privilege> - </d:grant> - <d:principal><d:unauthenticated /></d:principal> - </d:ace> - <d:ace> - <d:grant> - <d:privilege> - <d:write/> - </d:privilege> - </d:grant> - <d:principal><d:all /></d:principal> - </d:ace> -</d:root> -'; - - $dom = DAV\XMLUtil::loadDOMDocument($source); - $result = Acl::unserialize($dom->firstChild); - - $this->assertInstanceOf('Sabre\\DAVACL\\Property\\Acl', $result); - - $expected = array( - array( - 'principal' => '{DAV:}authenticated', - 'protected' => false, - 'privilege' => '{DAV:}write', - ), - array( - 'principal' => '{DAV:}unauthenticated', - 'protected' => false, - 'privilege' => '{DAV:}write', - ), - array( - 'principal' => '{DAV:}all', - 'protected' => false, - 'privilege' => '{DAV:}write', - ), - ); - - $this->assertEquals($expected, $result->getPrivileges()); - - - } - - /** - * @expectedException Sabre\DAV\Exception\NotImplemented - */ - function testUnserializeDeny() { - - $source = '<?xml version="1.0"?> -<d:root xmlns:d="DAV:"> - <d:ace> - <d:deny> - <d:privilege> - <d:write/> - </d:privilege> - </d:deny> - <d:principal><d:href>/principals/evert</d:href></d:principal> - </d:ace> -</d:root> -'; - - $dom = DAV\XMLUtil::loadDOMDocument($source); - Acl::unserialize($dom->firstChild); - } - - /** - * @expectedException Sabre\DAV\Exception\BadRequest - */ - function testUnserializeMissingPriv() { - - $source = '<?xml version="1.0"?> -<d:root xmlns:d="DAV:"> - <d:ace> - <d:grant> - <d:privilege /> - </d:grant> - <d:principal><d:href>/principals/evert</d:href></d:principal> - </d:ace> -</d:root> -'; - - $dom = DAV\XMLUtil::loadDOMDocument($source); - Acl::unserialize($dom->firstChild); - - } -} diff --git a/vendor/sabre/dav/tests/Sabre/DAVACL/Property/CurrentUserPrivilegeSetTest.php b/vendor/sabre/dav/tests/Sabre/DAVACL/Property/CurrentUserPrivilegeSetTest.php deleted file mode 100644 index e71addb65..000000000 --- a/vendor/sabre/dav/tests/Sabre/DAVACL/Property/CurrentUserPrivilegeSetTest.php +++ /dev/null @@ -1,68 +0,0 @@ -<?php - -namespace Sabre\DAVACL\Property; - -use Sabre\DAV; -use Sabre\HTTP; - - -class CurrentUserPrivilegeSetTest extends \PHPUnit_Framework_TestCase { - - function testSerialize() { - - $privileges = array( - '{DAV:}read', - '{DAV:}write', - ); - $prop = new CurrentUserPrivilegeSet($privileges); - - $server = new DAV\Server(); - $dom = new \DOMDocument('1.0','utf-8'); - $root = $dom->createElementNS('DAV:','d:root'); - $dom->appendChild($root); - - $prop->serialize($server, $root); - - $xpaths = array( - '/d:root' => 1, - '/d:root/d:privilege' => 2, - '/d:root/d:privilege/d:read' => 1, - '/d:root/d:privilege/d:write' => 1, - ); - - // Reloading because PHP DOM sucks - $dom2 = new \DOMDocument('1.0', 'utf-8'); - $dom2->loadXML($dom->saveXML()); - - $dxpath = new \DOMXPath($dom2); - $dxpath->registerNamespace('d','DAV:'); - foreach($xpaths as $xpath=>$count) { - - $this->assertEquals($count, $dxpath->query($xpath)->length, 'Looking for : ' . $xpath . ', we could only find ' . $dxpath->query($xpath)->length . ' elements, while we expected ' . $count); - - } - - } - - function testUnserialize() { - - $source = '<?xml version="1.0"?> -<d:root xmlns:d="DAV:"> - <d:privilege> - <d:write-properties /> - </d:privilege> - <d:privilege> - <d:read /> - </d:privilege> -</d:root> -'; - - $dom = DAV\XMLUtil::loadDOMDocument($source); - $result = CurrentUserPrivilegeSet::unserialize($dom->firstChild, array()); - $this->assertTrue($result->has('{DAV:}read')); - $this->assertTrue($result->has('{DAV:}write-properties')); - $this->assertFalse($result->has('{DAV:}bind')); - - } - -} diff --git a/vendor/sabre/dav/tests/Sabre/DAVACL/Property/PrincipalTest.php b/vendor/sabre/dav/tests/Sabre/DAVACL/Property/PrincipalTest.php deleted file mode 100644 index be12c79ee..000000000 --- a/vendor/sabre/dav/tests/Sabre/DAVACL/Property/PrincipalTest.php +++ /dev/null @@ -1,181 +0,0 @@ -<?php - -namespace Sabre\DAVACL\Property; - -use Sabre\DAV; -use Sabre\HTTP; - -class PrincipalTest extends \PHPUnit_Framework_TestCase { - - function testSimple() { - - $principal = new Principal(Principal::UNAUTHENTICATED); - $this->assertEquals(Principal::UNAUTHENTICATED, $principal->getType()); - $this->assertNull($principal->getHref()); - - $principal = new Principal(Principal::AUTHENTICATED); - $this->assertEquals(Principal::AUTHENTICATED, $principal->getType()); - $this->assertNull($principal->getHref()); - - $principal = new Principal(Principal::HREF,'admin'); - $this->assertEquals(Principal::HREF, $principal->getType()); - $this->assertEquals('admin',$principal->getHref()); - - } - - /** - * @depends testSimple - * @expectedException Sabre\DAV\Exception - */ - function testNoHref() { - - $principal = new Principal(Principal::HREF); - - } - - /** - * @depends testSimple - */ - function testSerializeUnAuthenticated() { - - $prin = new Principal(Principal::UNAUTHENTICATED); - - $doc = new \DOMDocument(); - $root = $doc->createElement('d:principal'); - $root->setAttribute('xmlns:d','DAV:'); - - $doc->appendChild($root); - $objectTree = new DAV\ObjectTree(new DAV\SimpleCollection('rootdir')); - $server = new DAV\Server($objectTree); - - $prin->serialize($server, $root); - - $xml = $doc->saveXML(); - - $this->assertEquals( -'<?xml version="1.0"?> -<d:principal xmlns:d="DAV:">' . -'<d:unauthenticated/>' . -'</d:principal> -', $xml); - - } - - - /** - * @depends testSerializeUnAuthenticated - */ - function testSerializeAuthenticated() { - - $prin = new Principal(Principal::AUTHENTICATED); - - $doc = new \DOMDocument(); - $root = $doc->createElement('d:principal'); - $root->setAttribute('xmlns:d','DAV:'); - - $doc->appendChild($root); - $objectTree = new DAV\ObjectTree(new DAV\SimpleCollection('rootdir')); - $server = new DAV\Server($objectTree); - - $prin->serialize($server, $root); - - $xml = $doc->saveXML(); - - $this->assertEquals( -'<?xml version="1.0"?> -<d:principal xmlns:d="DAV:">' . -'<d:authenticated/>' . -'</d:principal> -', $xml); - - } - - - /** - * @depends testSerializeUnAuthenticated - */ - function testSerializeHref() { - - $prin = new Principal(Principal::HREF,'principals/admin'); - - $doc = new \DOMDocument(); - $root = $doc->createElement('d:principal'); - $root->setAttribute('xmlns:d','DAV:'); - - $doc->appendChild($root); - $objectTree = new DAV\ObjectTree(new DAV\SimpleCollection('rootdir')); - $server = new DAV\Server($objectTree); - - $prin->serialize($server, $root); - - $xml = $doc->saveXML(); - - $this->assertEquals( -'<?xml version="1.0"?> -<d:principal xmlns:d="DAV:">' . -'<d:href>/principals/admin</d:href>' . -'</d:principal> -', $xml); - - } - - function testUnserializeHref() { - - $xml = '<?xml version="1.0"?> -<d:principal xmlns:d="DAV:">' . -'<d:href>/principals/admin</d:href>' . -'</d:principal>'; - - $dom = DAV\XMLUtil::loadDOMDocument($xml); - - $principal = Principal::unserialize($dom->firstChild); - $this->assertEquals(Principal::HREF, $principal->getType()); - $this->assertEquals('/principals/admin', $principal->getHref()); - - } - - function testUnserializeAuthenticated() { - - $xml = '<?xml version="1.0"?> -<d:principal xmlns:d="DAV:">' . -' <d:authenticated />' . -'</d:principal>'; - - $dom = DAV\XMLUtil::loadDOMDocument($xml); - - $principal = Principal::unserialize($dom->firstChild); - $this->assertEquals(Principal::AUTHENTICATED, $principal->getType()); - - } - - function testUnserializeUnauthenticated() { - - $xml = '<?xml version="1.0"?> -<d:principal xmlns:d="DAV:">' . -' <d:unauthenticated />' . -'</d:principal>'; - - $dom = DAV\XMLUtil::loadDOMDocument($xml); - - $principal = Principal::unserialize($dom->firstChild); - $this->assertEquals(Principal::UNAUTHENTICATED, $principal->getType()); - - } - - /** - * @expectedException Sabre\DAV\Exception\BadRequest - */ - function testUnserializeUnknown() { - - $xml = '<?xml version="1.0"?> -<d:principal xmlns:d="DAV:">' . -' <d:foo />' . -'</d:principal>'; - - $dom = DAV\XMLUtil::loadDOMDocument($xml); - - Principal::unserialize($dom->firstChild); - - } - -} diff --git a/vendor/sabre/dav/tests/Sabre/DAVACL/Property/SupportedPrivilegeSetTest.php b/vendor/sabre/dav/tests/Sabre/DAVACL/Property/SupportedPrivilegeSetTest.php deleted file mode 100644 index 943316331..000000000 --- a/vendor/sabre/dav/tests/Sabre/DAVACL/Property/SupportedPrivilegeSetTest.php +++ /dev/null @@ -1,106 +0,0 @@ -<?php - -namespace Sabre\DAVACL\Property; - -use Sabre\DAV; -use Sabre\HTTP; - - - -class SupportedPrivilegeSetTest extends \PHPUnit_Framework_TestCase { - - function testSimple() { - - $prop = new SupportedPrivilegeSet(array( - 'privilege' => '{DAV:}all', - )); - - } - - - /** - * @depends testSimple - */ - function testSerializeSimple() { - - $prop = new SupportedPrivilegeSet(array( - 'privilege' => '{DAV:}all', - )); - - $doc = new \DOMDocument(); - $root = $doc->createElementNS('DAV:', 'd:supported-privilege-set'); - - $doc->appendChild($root); - - $server = new DAV\Server(); - $prop->serialize($server, $root); - - $xml = $doc->saveXML(); - - $this->assertEquals( -'<?xml version="1.0"?> -<d:supported-privilege-set xmlns:d="DAV:">' . -'<d:supported-privilege>' . -'<d:privilege>' . -'<d:all/>' . -'</d:privilege>' . -'</d:supported-privilege>' . -'</d:supported-privilege-set> -', $xml); - - } - - /** - * @depends testSimple - */ - function testSerializeAggregate() { - - $prop = new SupportedPrivilegeSet(array( - 'privilege' => '{DAV:}all', - 'abstract' => true, - 'aggregates' => array( - array( - 'privilege' => '{DAV:}read', - ), - array( - 'privilege' => '{DAV:}write', - 'description' => 'booh', - ), - ), - )); - - $doc = new \DOMDocument(); - $root = $doc->createElementNS('DAV:', 'd:supported-privilege-set'); - - $doc->appendChild($root); - - $server = new DAV\Server(); - $prop->serialize($server, $root); - - $xml = $doc->saveXML(); - - $this->assertEquals( -'<?xml version="1.0"?> -<d:supported-privilege-set xmlns:d="DAV:">' . -'<d:supported-privilege>' . -'<d:privilege>' . -'<d:all/>' . -'</d:privilege>' . -'<d:abstract/>' . -'<d:supported-privilege>' . -'<d:privilege>' . -'<d:read/>' . -'</d:privilege>' . -'</d:supported-privilege>' . -'<d:supported-privilege>' . -'<d:privilege>' . -'<d:write/>' . -'</d:privilege>' . -'<d:description>booh</d:description>' . -'</d:supported-privilege>' . -'</d:supported-privilege>' . -'</d:supported-privilege-set> -', $xml); - - } -} diff --git a/vendor/sabre/dav/tests/Sabre/DAVACL/SimplePluginTest.php b/vendor/sabre/dav/tests/Sabre/DAVACL/SimplePluginTest.php index 04ed5c330..fb73cc16a 100644 --- a/vendor/sabre/dav/tests/Sabre/DAVACL/SimplePluginTest.php +++ b/vendor/sabre/dav/tests/Sabre/DAVACL/SimplePluginTest.php @@ -30,6 +30,11 @@ class SimplePluginTest extends \PHPUnit_Framework_TestCase { $this->assertEquals(array('ACL'), $aclPlugin->getMethods('')); + + $this->assertEquals( + 'acl', + $aclPlugin->getPluginInfo()['name'] + ); } function testGetFlatPrivilegeSet() { @@ -55,15 +60,15 @@ class SimplePluginTest extends \PHPUnit_Framework_TestCase { ), '{DAV:}read-acl' => array( 'privilege' => '{DAV:}read-acl', - 'abstract' => true, + 'abstract' => false, 'aggregates' => array(), - 'concrete' => '{DAV:}read', + 'concrete' => '{DAV:}read-acl', ), '{DAV:}read-current-user-privilege-set' => array( 'privilege' => '{DAV:}read-current-user-privilege-set', - 'abstract' => true, + 'abstract' => false, 'aggregates' => array(), - 'concrete' => '{DAV:}read', + 'concrete' => '{DAV:}read-current-user-privilege-set', ), '{DAV:}write' => array( 'privilege' => '{DAV:}write', @@ -80,39 +85,39 @@ class SimplePluginTest extends \PHPUnit_Framework_TestCase { ), '{DAV:}write-acl' => array( 'privilege' => '{DAV:}write-acl', - 'abstract' => true, + 'abstract' => false, 'aggregates' => array(), - 'concrete' => '{DAV:}write', + 'concrete' => '{DAV:}write-acl', ), '{DAV:}write-properties' => array( 'privilege' => '{DAV:}write-properties', - 'abstract' => true, + 'abstract' => false, 'aggregates' => array(), - 'concrete' => '{DAV:}write', + 'concrete' => '{DAV:}write-properties', ), '{DAV:}write-content' => array( 'privilege' => '{DAV:}write-content', - 'abstract' => true, + 'abstract' => false, 'aggregates' => array(), - 'concrete' => '{DAV:}write', + 'concrete' => '{DAV:}write-content', ), '{DAV:}unlock' => array( 'privilege' => '{DAV:}unlock', - 'abstract' => true, + 'abstract' => false, 'aggregates' => array(), - 'concrete' => '{DAV:}write', + 'concrete' => '{DAV:}unlock', ), '{DAV:}bind' => array( 'privilege' => '{DAV:}bind', - 'abstract' => true, + 'abstract' => false, 'aggregates' => array(), - 'concrete' => '{DAV:}write', + 'concrete' => '{DAV:}bind', ), '{DAV:}unbind' => array( 'privilege' => '{DAV:}unbind', - 'abstract' => true, + 'abstract' => false, 'aggregates' => array(), - 'concrete' => '{DAV:}write', + 'concrete' => '{DAV:}unbind', ), ); @@ -148,11 +153,11 @@ class SimplePluginTest extends \PHPUnit_Framework_TestCase { $server = new DAV\Server($tree); $server->addPlugin($acl); - $auth = new DAV\Auth\Plugin(new DAV\Auth\Backend\Mock(),'SabreDAV'); + $auth = new DAV\Auth\Plugin(new DAV\Auth\Backend\Mock()); $server->addPlugin($auth); //forcing login - $auth->beforeMethod('GET','/'); + $auth->beforeMethod(new HTTP\Request(), new HTTP\Response()); $this->assertEquals(array('principals/admin'),$acl->getCurrentUserPrincipals()); @@ -175,11 +180,11 @@ class SimplePluginTest extends \PHPUnit_Framework_TestCase { $server = new DAV\Server($tree); $server->addPlugin($acl); - $auth = new DAV\Auth\Plugin(new DAV\Auth\Backend\Mock(),'SabreDAV'); + $auth = new DAV\Auth\Plugin(new DAV\Auth\Backend\Mock()); $server->addPlugin($auth); //forcing login - $auth->beforeMethod('GET','/'); + $auth->beforeMethod(new HTTP\Request(), new HTTP\Response()); $expected = array( 'principals/admin', @@ -252,11 +257,11 @@ class SimplePluginTest extends \PHPUnit_Framework_TestCase { $aclPlugin = new Plugin(); $server->addPlugin($aclPlugin); - $auth = new DAV\Auth\Plugin(new DAV\Auth\Backend\Mock(),'SabreDAV'); + $auth = new DAV\Auth\Plugin(new DAV\Auth\Backend\Mock()); $server->addPlugin($auth); //forcing login - $auth->beforeMethod('GET','/'); + $auth->beforeMethod(new HTTP\Request(), new HTTP\Response()); $expected = array( '{DAV:}write', @@ -306,7 +311,7 @@ class SimplePluginTest extends \PHPUnit_Framework_TestCase { $aclPlugin = new Plugin(); $server->addPlugin($aclPlugin); - $auth = new DAV\Auth\Plugin(new DAV\Auth\Backend\Mock(),'SabreDAV'); + $auth = new DAV\Auth\Plugin(new DAV\Auth\Backend\Mock()); $server->addPlugin($auth); //forcing login diff --git a/vendor/sabre/dav/tests/Sabre/DAVACL/VersionTest.php b/vendor/sabre/dav/tests/Sabre/DAVACL/VersionTest.php deleted file mode 100644 index c432527dc..000000000 --- a/vendor/sabre/dav/tests/Sabre/DAVACL/VersionTest.php +++ /dev/null @@ -1,17 +0,0 @@ -<?php - -namespace Sabre\DAVACL; - -class VersionTest extends \PHPUnit_Framework_TestCase { - - function testString() { - - $v = Version::VERSION; - $this->assertEquals(-1, version_compare('1.0.0',$v)); - - $s = Version::STABILITY; - $this->assertTrue($s == 'alpha' || $s == 'beta' || $s =='stable'); - - } - -} diff --git a/vendor/sabre/dav/tests/Sabre/DAVServerTest.php b/vendor/sabre/dav/tests/Sabre/DAVServerTest.php index 207687d90..d329b5b05 100644 --- a/vendor/sabre/dav/tests/Sabre/DAVServerTest.php +++ b/vendor/sabre/dav/tests/Sabre/DAVServerTest.php @@ -2,17 +2,9 @@ namespace Sabre; -require_once 'Sabre/HTTP/ResponseMock.php'; - -require_once 'Sabre/DAV/Auth/Backend/Mock.php'; -require_once 'Sabre/DAV/Mock/File.php'; -require_once 'Sabre/DAV/Mock/Collection.php'; - -require_once 'Sabre/DAVACL/PrincipalBackend/Mock.php'; - -require_once 'Sabre/CalDAV/Backend/Mock.php'; - -require_once 'Sabre/CardDAV/Backend/Mock.php'; +use Sabre\HTTP\Request; +use Sabre\HTTP\Response; +use Sabre\HTTP\Sapi; /** * This class may be used as a basis for other webdav-related unittests. @@ -20,7 +12,7 @@ require_once 'Sabre/CardDAV/Backend/Mock.php'; * This class is supposed to provide a reasonably big framework to quickly get * a testing environment running. * - * @copyright Copyright (C) 2007-2014 fruux GmbH (https://fruux.com/). + * @copyright Copyright (C) fruux GmbH (https://fruux.com/) * @author Evert Pot (http://evertpot.com/) * @license http://sabre.io/license/ Modified BSD License */ @@ -30,22 +22,35 @@ abstract class DAVServerTest extends \PHPUnit_Framework_TestCase { protected $setupCardDAV = false; protected $setupACL = false; protected $setupCalDAVSharing = false; + protected $setupCalDAVScheduling = false; + protected $setupCalDAVSubscriptions = false; + protected $setupCalDAVICSExport = false; + protected $setupLocks = false; + protected $setupFiles = false; + protected $setupPropertyStorage = false; - protected $caldavCalendars = array(); - protected $caldavCalendarObjects = array(); + /** + * An array with calendars. Every calendar should have + * - principaluri + * - uri + */ + protected $caldavCalendars = []; + protected $caldavCalendarObjects = []; - protected $carddavAddressBooks = array(); - protected $carddavCards = array(); + protected $carddavAddressBooks = []; + protected $carddavCards = []; /** * @var Sabre\DAV\Server */ protected $server; - protected $tree = array(); + protected $tree = []; protected $caldavBackend; protected $carddavBackend; protected $principalBackend; + protected $locksBackend; + protected $propertyStorageBackend; /** * @var Sabre\CalDAV\Plugin @@ -67,11 +72,28 @@ abstract class DAVServerTest extends \PHPUnit_Framework_TestCase { */ protected $caldavSharingPlugin; + /** + * CalDAV scheduling plugin + * + * @var CalDAV\Schedule\Plugin + */ + protected $caldavSchedulePlugin; + /** * @var Sabre\DAV\Auth\Plugin */ protected $authPlugin; + /** + * @var Sabre\DAV\Locks\Plugin + */ + protected $locksPlugin; + + /** + * @var Sabre\DAV\PropertyStorage\Plugin + */ + protected $propertyStoragePlugin; + /** * If this string is set, we will automatically log in the user with this * name. @@ -84,6 +106,7 @@ abstract class DAVServerTest extends \PHPUnit_Framework_TestCase { $this->setUpTree(); $this->server = new DAV\Server($this->tree); + $this->server->sapi = new HTTP\SapiMock(); $this->server->debugExceptions = true; if ($this->setupCalDAV) { @@ -94,6 +117,17 @@ abstract class DAVServerTest extends \PHPUnit_Framework_TestCase { $this->caldavSharingPlugin = new CalDAV\SharingPlugin(); $this->server->addPlugin($this->caldavSharingPlugin); } + if ($this->setupCalDAVScheduling) { + $this->caldavSchedulePlugin = new CalDAV\Schedule\Plugin(); + $this->server->addPlugin($this->caldavSchedulePlugin); + } + if ($this->setupCalDAVSubscriptions) { + $this->server->addPlugin(new CalDAV\Subscriptions\Plugin()); + } + if ($this->setupCalDAVICSExport) { + $this->caldavICSExportPlugin = new CalDAV\ICSExportPlugin(); + $this->server->addPlugin($this->caldavICSExportPlugin); + } if ($this->setupCardDAV) { $this->carddavPlugin = new CardDAV\Plugin(); $this->server->addPlugin($this->carddavPlugin); @@ -102,14 +136,26 @@ abstract class DAVServerTest extends \PHPUnit_Framework_TestCase { $this->aclPlugin = new DAVACL\Plugin(); $this->server->addPlugin($this->aclPlugin); } + if ($this->setupLocks) { + $this->locksPlugin = new DAV\Locks\Plugin( + $this->locksBackend + ); + $this->server->addPlugin($this->locksPlugin); + } + if ($this->setupPropertyStorage) { + $this->propertyStoragePlugin = new DAV\PropertyStorage\Plugin( + $this->propertyStorageBackend + ); + $this->server->addPlugin($this->propertyStoragePlugin); + } if ($this->autoLogin) { $authBackend = new DAV\Auth\Backend\Mock(); - $authBackend->defaultUser = $this->autoLogin; - $this->authPlugin = new DAV\Auth\Plugin($authBackend, 'SabreDAV'); + $authBackend->setPrincipal('principals/' . $this->autoLogin); + $this->authPlugin = new DAV\Auth\Plugin($authBackend); $this->server->addPlugin($this->authPlugin); // This will trigger the actual login procedure - $this->authPlugin->beforeMethod('OPTIONS','/'); + $this->authPlugin->beforeMethod(new Request(), new Response()); } } @@ -126,7 +172,7 @@ abstract class DAVServerTest extends \PHPUnit_Framework_TestCase { function request($request) { if (is_array($request)) { - $request = new HTTP\Request($request); + $request = HTTP\Request::createFromServerArray($request); } $this->server->httpRequest = $request; $this->server->httpResponse = new HTTP\ResponseMock(); @@ -136,10 +182,13 @@ abstract class DAVServerTest extends \PHPUnit_Framework_TestCase { } + /** + * Override this to provide your own Tree for your test-case. + */ function setUpTree() { if ($this->setupCalDAV) { - $this->tree[] = new CalDAV\CalendarRootNode( + $this->tree[] = new CalDAV\CalendarRoot( $this->principalBackend, $this->caldavBackend ); @@ -152,17 +201,32 @@ abstract class DAVServerTest extends \PHPUnit_Framework_TestCase { } if ($this->setupCardDAV || $this->setupCalDAV) { - $this->tree[] = new DAVACL\PrincipalCollection( + $this->tree[] = new CalDAV\Principal\Collection( $this->principalBackend ); } + if ($this->setupFiles) { + + $this->tree[] = new DAV\Mock\Collection('files'); + + } } function setUpBackends() { + if ($this->setupCalDAVSharing && is_null($this->caldavBackend)) { + $this->caldavBackend = new CalDAV\Backend\MockSharing($this->caldavCalendars, $this->caldavCalendarObjects); + } + if ($this->setupCalDAVSubscriptions && is_null($this->caldavBackend)) { + $this->caldavBackend = new CalDAV\Backend\MockSubscriptionSupport($this->caldavCalendars, $this->caldavCalendarObjects); + } if ($this->setupCalDAV && is_null($this->caldavBackend)) { - $this->caldavBackend = new CalDAV\Backend\Mock($this->caldavCalendars, $this->caldavCalendarObjects); + if ($this->setupCalDAVScheduling) { + $this->caldavBackend = new CalDAV\Backend\MockScheduling($this->caldavCalendars, $this->caldavCalendarObjects); + } else { + $this->caldavBackend = new CalDAV\Backend\Mock($this->caldavCalendars, $this->caldavCalendarObjects); + } } if ($this->setupCardDAV && is_null($this->carddavBackend)) { $this->carddavBackend = new CardDAV\Backend\Mock($this->carddavAddressBooks, $this->carddavCards); @@ -170,6 +234,12 @@ abstract class DAVServerTest extends \PHPUnit_Framework_TestCase { if ($this->setupCardDAV || $this->setupCalDAV) { $this->principalBackend = new DAVACL\PrincipalBackend\Mock(); } + if ($this->setupLocks) { + $this->locksBackend = new DAV\Locks\Backend\Mock(); + } + if ($this->setupPropertyStorage) { + $this->propertyStorageBackend = new DAV\PropertyStorage\Backend\Mock(); + } } @@ -177,7 +247,7 @@ abstract class DAVServerTest extends \PHPUnit_Framework_TestCase { function assertHTTPStatus($expectedStatus, HTTP\Request $req) { $resp = $this->request($req); - $this->assertEquals($resp->getStatusMessage($expectedStatus), $resp->status,'Incorrect HTTP status received: ' . $resp->body); + $this->assertEquals((int)$expectedStatus, (int)$resp->status, 'Incorrect HTTP status received: ' . $resp->body); } diff --git a/vendor/sabre/dav/tests/Sabre/HTTP/AWSAuthTest.php b/vendor/sabre/dav/tests/Sabre/HTTP/AWSAuthTest.php deleted file mode 100644 index 569ec2e7d..000000000 --- a/vendor/sabre/dav/tests/Sabre/HTTP/AWSAuthTest.php +++ /dev/null @@ -1,242 +0,0 @@ -<?php - -namespace Sabre\HTTP; - -require_once 'Sabre/HTTP/ResponseMock.php'; - -class AWSAuthTest extends \PHPUnit_Framework_TestCase { - - /** - * @var Sabre\HTTP\ResponseMock - */ - private $response; - /** - * @var Sabre\HTTP\AWSAuth - */ - private $auth; - - const REALM = 'SabreDAV unittest'; - - public function setUp() { - - $this->response = new ResponseMock(); - $this->auth = new AWSAuth(); - $this->auth->setRealm(self::REALM); - $this->auth->setHTTPResponse($this->response); - - } - - public function testNoHeader() { - - $request = new Request(array( - 'REQUEST_METHOD' => 'GET', - )); - - $this->auth->setHTTPRequest($request); - - $result = $this->auth->init(); - - $this->assertFalse($result,'No AWS Authorization header was supplied, so we should have gotten false'); - $this->assertEquals(AWSAuth::ERR_NOAWSHEADER,$this->auth->errorCode); - - } - - public function testIncorrectContentMD5() { - - $accessKey = 'accessKey'; - $secretKey = 'secretKey'; - - $request = new Request(array( - 'REQUEST_METHOD' => 'GET', - 'HTTP_AUTHORIZATION' => "AWS $accessKey:sig", - 'HTTP_CONTENT_MD5' => 'garbage', - 'REQUEST_URI' => '/', - )); - - $this->auth->setHTTPRequest($request); - $this->auth->init(); - $result = $this->auth->validate($secretKey); - - $this->assertFalse($result); - $this->assertEquals(AWSAuth::ERR_MD5CHECKSUMWRONG,$this->auth->errorCode); - - } - - public function testNoDate() { - - $accessKey = 'accessKey'; - $secretKey = 'secretKey'; - $content = 'thisisthebody'; - $contentMD5 = base64_encode(md5($content,true)); - - - $request = new Request(array( - 'REQUEST_METHOD' => 'POST', - 'HTTP_AUTHORIZATION' => "AWS $accessKey:sig", - 'HTTP_CONTENT_MD5' => $contentMD5, - )); - - $request->setBody($content); - - $this->auth->setHTTPRequest($request); - $this->auth->init(); - $result = $this->auth->validate($secretKey); - - $this->assertFalse($result); - $this->assertEquals(AWSAuth::ERR_INVALIDDATEFORMAT,$this->auth->errorCode); - - } - - public function testFutureDate() { - - $accessKey = 'accessKey'; - $secretKey = 'secretKey'; - $content = 'thisisthebody'; - $contentMD5 = base64_encode(md5($content,true)); - - $date = new \DateTime('@' . (time() + (60*20))); - $date->setTimeZone(new \DateTimeZone('GMT')); - $date = $date->format('D, d M Y H:i:s \\G\\M\\T'); - - $request = new Request(array( - 'REQUEST_METHOD' => 'POST', - 'HTTP_AUTHORIZATION' => "AWS $accessKey:sig", - 'HTTP_CONTENT_MD5' => $contentMD5, - 'HTTP_DATE' => $date, - )); - - $request->setBody($content); - - $this->auth->setHTTPRequest($request); - $this->auth->init(); - $result = $this->auth->validate($secretKey); - - $this->assertFalse($result); - $this->assertEquals(AWSAuth::ERR_REQUESTTIMESKEWED,$this->auth->errorCode); - - } - - public function testPastDate() { - - $accessKey = 'accessKey'; - $secretKey = 'secretKey'; - $content = 'thisisthebody'; - $contentMD5 = base64_encode(md5($content,true)); - - $date = new \DateTime('@' . (time() - (60*20))); - $date->setTimeZone(new \DateTimeZone('GMT')); - $date = $date->format('D, d M Y H:i:s \\G\\M\\T'); - - $request = new Request(array( - 'REQUEST_METHOD' => 'POST', - 'HTTP_AUTHORIZATION' => "AWS $accessKey:sig", - 'HTTP_CONTENT_MD5' => $contentMD5, - 'HTTP_X_AMZ_DATE' => $date, - )); - - $request->setBody($content); - - $this->auth->setHTTPRequest($request); - $this->auth->init(); - $result = $this->auth->validate($secretKey); - - $this->assertFalse($result); - $this->assertEquals(AWSAuth::ERR_REQUESTTIMESKEWED,$this->auth->errorCode); - - } - - public function testIncorrectSignature() { - - $accessKey = 'accessKey'; - $secretKey = 'secretKey'; - $content = 'thisisthebody'; - - $contentMD5 = base64_encode(md5($content,true)); - - $date = new \DateTime('now'); - $date->setTimeZone(new \DateTimeZone('GMT')); - $date = $date->format('D, d M Y H:i:s \\G\\M\\T'); - - $request = new Request(array( - 'REQUEST_METHOD' => 'POST', - 'HTTP_AUTHORIZATION' => "AWS $accessKey:sig", - 'HTTP_CONTENT_MD5' => $contentMD5, - 'HTTP_X_AMZ_DATE' => $date, - 'REQUEST_URI' => '/', - )); - - $request->setBody($content); - - $this->auth->setHTTPRequest($request); - $this->auth->init(); - $result = $this->auth->validate($secretKey); - - $this->assertFalse($result); - $this->assertEquals(AWSAuth::ERR_INVALIDSIGNATURE,$this->auth->errorCode); - - } - - public function testValidRequest() { - - $accessKey = 'accessKey'; - $secretKey = 'secretKey'; - $content = 'thisisthebody'; - $contentMD5 = base64_encode(md5($content,true)); - - $date = new \DateTime('now'); - $date->setTimeZone(new \DateTimeZone('GMT')); - $date = $date->format('D, d M Y H:i:s \\G\\M\\T'); - - - $sig = base64_encode($this->hmacsha1($secretKey, - "POST\n$contentMD5\n\n$date\nx-amz-date:$date\n/evert" - )); - - $request = new Request(array( - 'REQUEST_METHOD' => 'POST', - 'HTTP_AUTHORIZATION' => "AWS $accessKey:$sig", - 'HTTP_CONTENT_MD5' => $contentMD5, - 'HTTP_X_AMZ_DATE' => $date, - 'REQUEST_URI' => '/evert', - )); - - $request->setBody($content); - - $this->auth->setHTTPRequest($request); - $this->auth->init(); - $result = $this->auth->validate($secretKey); - - $this->assertTrue($result,'Signature did not validate, got errorcode ' . $this->auth->errorCode); - $this->assertEquals($accessKey,$this->auth->getAccessKey()); - - } - - public function test401() { - - $this->auth->requireLogin(); - $test = preg_match('/^AWS$/',$this->response->headers['WWW-Authenticate'],$matches); - $this->assertTrue($test==true,'The WWW-Authenticate response didn\'t match our pattern'); - - } - - /** - * Generates an HMAC-SHA1 signature - * - * @param string $key - * @param string $message - * @return string - */ - private function hmacsha1($key, $message) { - - $blocksize=64; - if (strlen($key)>$blocksize) - $key=pack('H*', sha1($key)); - $key=str_pad($key,$blocksize,chr(0x00)); - $ipad=str_repeat(chr(0x36),$blocksize); - $opad=str_repeat(chr(0x5c),$blocksize); - $hmac = pack('H*',sha1(($key^$opad).pack('H*',sha1(($key^$ipad).$message)))); - return $hmac; - - } - -} diff --git a/vendor/sabre/dav/tests/Sabre/HTTP/BasicAuthTest.php b/vendor/sabre/dav/tests/Sabre/HTTP/BasicAuthTest.php deleted file mode 100644 index 77c5c7179..000000000 --- a/vendor/sabre/dav/tests/Sabre/HTTP/BasicAuthTest.php +++ /dev/null @@ -1,132 +0,0 @@ -<?php - -namespace Sabre\HTTP; - -require_once 'Sabre/HTTP/ResponseMock.php'; - -class BasicAuthTest extends \PHPUnit_Framework_TestCase { - - /** - * @var Sabre\HTTP\ResponseMock - */ - private $response; - /** - * @var Sabre\HTTP\BasicAuth - */ - private $basicAuth; - - function setUp() { - - $this->response = new ResponseMock(); - $this->basicAuth = new BasicAuth(); - $this->basicAuth->setHTTPResponse($this->response); - - } - - function testGetUserPassApache() { - - $server = array( - 'PHP_AUTH_USER' => 'admin', - 'PHP_AUTH_PW' => '1234', - ); - - $request = new Request($server); - $this->basicAuth->setHTTPRequest($request); - - $userPass = $this->basicAuth->getUserPass(); - - $this->assertEquals( - array('admin','1234'), - $userPass, - 'We did not get the username and password we expected' - ); - - } - - function testGetUserPassIIS() { - - $server = array( - 'HTTP_AUTHORIZATION' => 'Basic ' . base64_encode('admin:1234'), - ); - - $request = new Request($server); - $this->basicAuth->setHTTPRequest($request); - - $userPass = $this->basicAuth->getUserPass(); - - $this->assertEquals( - array('admin','1234'), - $userPass, - 'We did not get the username and password we expected' - ); - - } - - function testGetUserPassWithColon() { - - $server = array( - 'HTTP_AUTHORIZATION' => 'Basic ' . base64_encode('admin:1234:5678'), - ); - - $request = new Request($server); - $this->basicAuth->setHTTPRequest($request); - - $userPass = $this->basicAuth->getUserPass(); - - $this->assertEquals( - array('admin','1234:5678'), - $userPass, - 'We did not get the username and password we expected' - ); - - } - - function testGetUserPassApacheEdgeCase() { - - $server = array( - 'REDIRECT_HTTP_AUTHORIZATION' => 'Basic ' . base64_encode('admin:1234'), - ); - - $request = new Request($server); - $this->basicAuth->setHTTPRequest($request); - - $userPass = $this->basicAuth->getUserPass(); - - $this->assertEquals( - array('admin','1234'), - $userPass, - 'We did not get the username and password we expected' - ); - - } - - function testGetUserPassNothing() { - - $this->assertEquals( - false, - $this->basicAuth->getUserPass() - ); - - } - - function testRequireLogin() { - - $this->basicAuth->requireLogin(); - $this->assertEquals('SabreDAV',$this->basicAuth->getRealm()); - $this->assertEquals( - 'HTTP/1.1 401 Unauthorized', - $this->response->status, - 'We expected a 401 status to be set' - ); - - $this->assertEquals( - 'Basic realm="SabreDAV"', - $this->response->headers['WWW-Authenticate'], - 'The WWW-Autenticate header was not set!' - ); - - - - } - -} diff --git a/vendor/sabre/dav/tests/Sabre/HTTP/DigestAuthTest.php b/vendor/sabre/dav/tests/Sabre/HTTP/DigestAuthTest.php deleted file mode 100644 index 576a00d4a..000000000 --- a/vendor/sabre/dav/tests/Sabre/HTTP/DigestAuthTest.php +++ /dev/null @@ -1,228 +0,0 @@ -<?php - -namespace Sabre\HTTP; - -require_once 'Sabre/HTTP/ResponseMock.php'; - -class DigestAuthTest extends \PHPUnit_Framework_TestCase { - - /** - * @var Sabre\HTTP\ResponseMock - */ - private $response; - /** - * @var Sabre\HTTP\DigestAuth - */ - private $auth; - - const REALM = 'SabreDAV unittest'; - - public function setUp() { - - $this->response = new ResponseMock(); - $this->auth = new DigestAuth(); - $this->auth->setRealm(self::REALM); - $this->auth->setHTTPResponse($this->response); - - } - - public function testDigest() { - - list($nonce,$opaque) = $this->getServerTokens(); - - $username = 'admin'; - $password = 12345; - $nc = '00002'; - $cnonce = uniqid(); - - $digestHash = md5( - md5($username . ':' . self::REALM . ':' . $password) . ':' . - $nonce . ':' . - $nc . ':' . - $cnonce . ':' . - 'auth:' . - md5('GET' . ':' . '/') - ); - - $request = new Request(array( - 'REQUEST_METHOD' => 'GET', - 'PHP_AUTH_DIGEST' => 'username="'.$username.'", realm="' . self::REALM . '", nonce="' . $nonce . '", uri="/", response="' . $digestHash . '", opaque="' . $opaque . '", qop=auth,nc='.$nc.',cnonce="' . $cnonce . '"', - )); - - $this->auth->setHTTPRequest($request); - $this->auth->init(); - - $this->assertEquals($username,$this->auth->getUserName()); - $this->assertEquals(self::REALM,$this->auth->getRealm()); - $this->assertTrue($this->auth->validateA1(md5($username . ':' . self::REALM . ':' . $password)),'Authentication is deemed invalid through validateA1'); - $this->assertTrue($this->auth->validatePassword($password),'Authentication is deemed invalid through validatePassword'); - - } - - public function testDigestCGIFormat() { - - list($nonce,$opaque) = $this->getServerTokens(); - - $username = 'admin'; - $password = 12345; - $nc = '00002'; - $cnonce = uniqid(); - - $digestHash = md5( - md5($username . ':' . self::REALM . ':' . $password) . ':' . - $nonce . ':' . - $nc . ':' . - $cnonce . ':' . - 'auth:' . - md5('GET' . ':' . '/') - ); - - $request = new Request(array( - 'REQUEST_METHOD' => 'GET', - 'HTTP_AUTHORIZATION' => 'Digest username="'.$username.'", realm="' . self::REALM . '", nonce="' . $nonce . '", uri="/", response="' . $digestHash . '", opaque="' . $opaque . '", qop=auth,nc='.$nc.',cnonce="' . $cnonce . '"', - )); - - $this->auth->setHTTPRequest($request); - $this->auth->init(); - - $this->assertTrue($this->auth->validateA1(md5($username . ':' . self::REALM . ':' . $password)),'Authentication is deemed invalid through validateA1'); - $this->assertTrue($this->auth->validatePassword($password),'Authentication is deemed invalid through validatePassword'); - - } - - public function testDigestApacheEdgeCase() { - - list($nonce,$opaque) = $this->getServerTokens(); - - $username = 'admin'; - $password = 12345; - $nc = '00002'; - $cnonce = uniqid(); - - $digestHash = md5( - md5($username . ':' . self::REALM . ':' . $password) . ':' . - $nonce . ':' . - $nc . ':' . - $cnonce . ':' . - 'auth:' . - md5('GET' . ':' . '/') - ); - - $request = new Request(array( - 'REQUEST_METHOD' => 'GET', - 'REDIRECT_HTTP_AUTHORIZATION' => 'Digest username="'.$username.'", realm="' . self::REALM . '", nonce="' . $nonce . '", uri="/", response="' . $digestHash . '", opaque="' . $opaque . '", qop=auth,nc='.$nc.',cnonce="' . $cnonce . '"', - )); - - $this->auth->setHTTPRequest($request); - $this->auth->init(); - - $this->assertTrue($this->auth->validateA1(md5($username . ':' . self::REALM . ':' . $password)),'Authentication is deemed invalid through validateA1'); - $this->assertTrue($this->auth->validatePassword($password),'Authentication is deemed invalid through validatePassword'); - - } - - public function testInvalidDigest() { - - list($nonce,$opaque) = $this->getServerTokens(); - - $username = 'admin'; - $password = 12345; - $nc = '00002'; - $cnonce = uniqid(); - - $digestHash = md5( - md5($username . ':' . self::REALM . ':' . $password) . ':' . - $nonce . ':' . - $nc . ':' . - $cnonce . ':' . - 'auth:' . - md5('GET' . ':' . '/') - ); - - $request = new Request(array( - 'REQUEST_METHOD' => 'GET', - 'PHP_AUTH_DIGEST' => 'username="'.$username.'", realm="' . self::REALM . '", nonce="' . $nonce . '", uri="/", response="' . $digestHash . '", opaque="' . $opaque . '", qop=auth,nc='.$nc.',cnonce="' . $cnonce . '"', - )); - - $this->auth->setHTTPRequest($request); - $this->auth->init(); - - $this->assertFalse($this->auth->validateA1(md5($username . ':' . self::REALM . ':' . ($password . 'randomness'))),'Authentication is deemed invalid through validateA1'); - - } - - public function testInvalidDigest2() { - - $request = new Request(array( - 'REQUEST_METHOD' => 'GET', - 'HTTP_AUTHORIZATION' => 'basic blablabla', - )); - - $this->auth->setHTTPRequest($request); - $this->auth->init(); - - $this->assertFalse($this->auth->validateA1(md5('user:realm:password'))); - - } - - - public function testDigestAuthInt() { - - $this->auth->setQOP(DigestAuth::QOP_AUTHINT | DigestAuth::QOP_AUTH); - list($nonce,$opaque) = $this->getServerTokens(DigestAuth::QOP_AUTHINT| DigestAuth::QOP_AUTH); - - $username = 'admin'; - $password = 12345; - $nc = '00003'; - $cnonce = uniqid(); - - $digestHash = md5( - md5($username . ':' . self::REALM . ':' . $password) . ':' . - $nonce . ':' . - $nc . ':' . - $cnonce . ':' . - 'auth-int:' . - md5('POST' . ':' . '/' . ':' . md5('body')) - ); - - $request = new Request(array( - 'REQUEST_METHOD' => 'POST', - 'PHP_AUTH_DIGEST' => 'username="'.$username.'", realm="' . self::REALM . '", nonce="' . $nonce . '", uri="/", response="' . $digestHash . '", opaque="' . $opaque . '", qop=auth-int,nc='.$nc.',cnonce="' . $cnonce . '"', - )); - $request->setBody('body'); - - $this->auth->setHTTPRequest($request); - - $this->auth->init(); - - $this->assertTrue($this->auth->validateA1(md5($username . ':' . self::REALM . ':' . $password)),'Authentication is deemed invalid through validateA1'); - - } - - private function getServerTokens($qop = DigestAuth::QOP_AUTH) { - - $this->auth->requireLogin(); - - switch($qop) { - case DigestAuth::QOP_AUTH : $qopstr='auth'; break; - case DigestAuth::QOP_AUTHINT : $qopstr='auth-int'; break; - default : $qopstr='auth,auth-int'; break; - } - - $test = preg_match('/Digest realm="'.self::REALM.'",qop="'.$qopstr.'",nonce="([0-9a-f]*)",opaque="([0-9a-f]*)"/', - $this->response->headers['WWW-Authenticate'],$matches); - - $this->assertTrue($test==true,'The WWW-Authenticate response didn\'t match our pattern. We received: ' . $this->response->headers['WWW-Authenticate']); - - $nonce = $matches[1]; - $opaque = $matches[2]; - - // Reset our environment - $this->setUp(); - $this->auth->setQOP($qop); - - return array($nonce,$opaque); - - } - -} diff --git a/vendor/sabre/dav/tests/Sabre/HTTP/RequestTest.php b/vendor/sabre/dav/tests/Sabre/HTTP/RequestTest.php deleted file mode 100644 index c52ce351d..000000000 --- a/vendor/sabre/dav/tests/Sabre/HTTP/RequestTest.php +++ /dev/null @@ -1,150 +0,0 @@ -<?php - -namespace Sabre\HTTP; - -/** - * @covers Sabre\HTTP\Request - */ -class RequestTest extends \PHPUnit_Framework_TestCase { - - /** - * @var Sabre\HTTP\Request - */ - private $request; - - function setUp() { - - $server = array( - 'HTTP_HOST' => 'www.example.org', - 'REQUEST_METHOD' => 'PUT', - 'REQUEST_URI' => '/testuri/', - 'CONTENT_TYPE' => 'text/xml', - ); - - $this->request = new Request($server); - - } - - function testGetHeader() { - - $this->assertEquals('www.example.org', $this->request->getHeader('Host')); - $this->assertEquals('text/xml', $this->request->getHeader('Content-Type')); - - } - - function testGetNonExistantHeader() { - - $this->assertNull($this->request->getHeader('doesntexist')); - $this->assertNull($this->request->getHeader('Content-Length')); - - } - - function testGetHeaders() { - - $expected = array( - 'host' => 'www.example.org', - 'content-type' => 'text/xml', - ); - - $this->assertEquals($expected, $this->request->getHeaders()); - - } - - function testGetMethod() { - - $this->assertEquals('PUT', $this->request->getMethod(), 'It seems as if we didn\'t get a valid HTTP Request method back'); - - } - - function testGetUri() { - - $this->assertEquals('/testuri/', $this->request->getUri(), 'We got an invalid uri back'); - - } - - function testSetGetBody() { - - $h = fopen('php://memory','r+'); - fwrite($h,'testing'); - rewind($h); - $this->request->setBody($h); - $this->assertEquals('testing',$this->request->getBody(true),'We didn\'t get our testbody back'); - - } - - function testSetGetBodyStream() { - - $h = fopen('php://memory','r+'); - fwrite($h,'testing'); - rewind($h); - $this->request->setBody($h); - $this->assertEquals('testing',stream_get_contents($this->request->getBody()),'We didn\'t get our testbody back'); - - } - - - function testDefaultInputStream() { - - $h = fopen('php://memory','r+'); - fwrite($h,'testing'); - rewind($h); - - $previousValue = Request::$defaultInputStream; - Request::$defaultInputStream = $h; - - $this->assertEquals('testing',$this->request->getBody(true),'We didn\'t get our testbody back'); - Request::$defaultInputStream = $previousValue; - - } - - function testGetAbsoluteUri() { - - $s = array( - 'HTTP_HOST' => 'sabredav.org', - 'REQUEST_URI' => '/foo' - ); - - $r = new Request($s); - - $this->assertEquals('http://sabredav.org/foo', $r->getAbsoluteUri()); - - $s = array( - 'HTTP_HOST' => 'sabredav.org', - 'REQUEST_URI' => '/foo', - 'HTTPS' => 'on', - ); - - $r = new Request($s); - - $this->assertEquals('https://sabredav.org/foo', $r->getAbsoluteUri()); - - } - - function testGetQueryString() { - - $s = array( - 'QUERY_STRING' => 'bla', - ); - - $r = new Request($s); - $this->assertEquals('bla', $r->getQueryString()); - - $s = array(); - - $r = new Request($s); - $this->assertEquals('', $r->getQueryString()); - - } - - function testGetPostVars() { - - $post = array( - 'bla' => 'foo', - ); - $r = new Request(array(),$post); - $this->assertEquals($post, $r->getPostVars('bla')); - - } - - -} diff --git a/vendor/sabre/dav/tests/Sabre/HTTP/ResponseMock.php b/vendor/sabre/dav/tests/Sabre/HTTP/ResponseMock.php index 16c034099..eb486bf5b 100644 --- a/vendor/sabre/dav/tests/Sabre/HTTP/ResponseMock.php +++ b/vendor/sabre/dav/tests/Sabre/HTTP/ResponseMock.php @@ -2,28 +2,21 @@ namespace Sabre\HTTP; +/** + * HTTP Response Mock object + * + * This class exists to make the transition to sabre/http easier. + * + * @copyright Copyright (C) fruux GmbH (https://fruux.com/) + * @author Evert Pot (http://evertpot.com/) + * @license http://sabre.io/license/ Modified BSD License + */ class ResponseMock extends Response { - public $headers = array(); - public $status = ''; - public $body = ''; - - function setHeader($name,$value,$overwrite = true) { - - $this->headers[$name] = $value; - - } - - function sendStatus($code) { - - $this->status = $this->getStatusMessage($code, $this->defaultHttpVersion); - - } - - function sendBody($body) { - - $this->body = $body; - - } + /** + * Making these public. + */ + public $body; + public $status; } diff --git a/vendor/sabre/dav/tests/Sabre/HTTP/ResponseTest.php b/vendor/sabre/dav/tests/Sabre/HTTP/ResponseTest.php deleted file mode 100644 index f5302c993..000000000 --- a/vendor/sabre/dav/tests/Sabre/HTTP/ResponseTest.php +++ /dev/null @@ -1,70 +0,0 @@ -<?php - -namespace Sabre\HTTP; - -require_once 'Sabre/HTTP/ResponseMock.php'; - -class ResponseTest extends \PHPUnit_Framework_TestCase { - - /** - * @var Sabre\HTTP\ResponseMock - */ - private $response; - - function setUp() { - - $this->response = new ResponseMock(); - - } - - function testGetStatusMessage() { - - $msg = $this->response->getStatusMessage(200); - $this->assertEquals('HTTP/1.1 200 OK',$msg); - - } - - function testSetHeader() { - - $this->response->setHeader('Content-Type','text/html'); - $this->assertEquals('text/html', $this->response->headers['Content-Type']); - - - } - function testSetHeaders() { - - $this->response->setHeaders(array('Content-Type'=>'text/html')); - $this->assertEquals('text/html', $this->response->headers['Content-Type']); - - - } - - function testSendStatus() { - - $this->response->sendStatus(404); - $this->assertEquals('HTTP/1.1 404 Not Found', $this->response->status); - - } - - function testSendBody() { - - ob_start(); - $response = new Response(); - $response->sendBody('hello'); - $this->assertEquals('hello',ob_get_clean()); - - } - - function testSendBodyStream() { - - ob_start(); - $stream = fopen('php://memory','r+'); - fwrite($stream,'hello'); - rewind($stream); - $response = new Response(); - $response->sendBody($stream); - $this->assertEquals('hello',ob_get_clean()); - - } - -} diff --git a/vendor/sabre/dav/tests/Sabre/HTTP/UtilTest.php b/vendor/sabre/dav/tests/Sabre/HTTP/UtilTest.php deleted file mode 100644 index 47a7b98bd..000000000 --- a/vendor/sabre/dav/tests/Sabre/HTTP/UtilTest.php +++ /dev/null @@ -1,78 +0,0 @@ -<?php - -namespace Sabre\HTTP; - -class UtilTest extends \PHPUnit_Framework_TestCase { - - function testParseHTTPDate() { - - $times = array( - 'Wed, 13 Oct 2010 10:26:00 GMT', - 'Wednesday, 13-Oct-10 10:26:00 GMT', - 'Wed Oct 13 10:26:00 2010', - ); - - $expected = 1286965560; - - foreach($times as $time) { - $result = Util::parseHTTPDate($time); - $this->assertEquals($expected, $result->format('U')); - } - - $result = Util::parseHTTPDate('Wed Oct 6 10:26:00 2010'); - $this->assertEquals(1286360760, $result->format('U')); - - } - - function testParseHTTPDateFail() { - - $times = array( - //random string - 'NOW', - // not-GMT timezone - 'Wednesday, 13-Oct-10 10:26:00 UTC', - // No space before the 6 - 'Wed Oct 6 10:26:00 2010', - ); - - foreach($times as $time) { - $this->assertFalse(Util::parseHTTPDate($time), 'We used the string: ' . $time); - } - - } - - function testTimezones() { - - $default = date_default_timezone_get(); - date_default_timezone_set('Europe/Amsterdam'); - - $this->testParseHTTPDate(); - - date_default_timezone_set($default); - - } - - function testToHTTPDate() { - - $dt = new \DateTime('2011-12-10 12:00:00 +0200'); - - $this->assertEquals( - 'Sat, 10 Dec 2011 10:00:00 GMT', - Util::toHTTPDate($dt) - ); - - } - - function testStrtotimeFail() { - - // Strtotime may return -1 when the date cannot be parsed. - // We are simulating this situation by testing a date that actually - // results in -1. (because I have found no other way to break this - // code) - - $time = 'Wed, 13 Oct 1960 10:26:00 GMT'; - - $this->assertNull(Util::parseHTTPDate($time)); - - } -} diff --git a/vendor/sabre/dav/tests/Sabre/HTTP/VersionTest.php b/vendor/sabre/dav/tests/Sabre/HTTP/VersionTest.php deleted file mode 100644 index c7094b3bc..000000000 --- a/vendor/sabre/dav/tests/Sabre/HTTP/VersionTest.php +++ /dev/null @@ -1,17 +0,0 @@ -<?php - -namespace Sabre\HTTP; - -class VersionTest extends \PHPUnit_Framework_TestCase { - - function testString() { - - $v = Version::VERSION; - $this->assertEquals(-1, version_compare('1.0.0',$v)); - - $s = Version::STABILITY; - $this->assertTrue($s == 'alpha' || $s == 'beta' || $s =='stable'); - - } - -} diff --git a/vendor/sabre/dav/tests/Sabre/TestUtil.php b/vendor/sabre/dav/tests/Sabre/TestUtil.php index 5a9062498..20bce1ea0 100644 --- a/vendor/sabre/dav/tests/Sabre/TestUtil.php +++ b/vendor/sabre/dav/tests/Sabre/TestUtil.php @@ -47,5 +47,12 @@ class TestUtil { } + static function getSQLiteDB() { + + $pdo = new \PDO('sqlite:'.SABRE_TEMPDIR.'/pdobackend'); + $pdo->setAttribute(\PDO::ATTR_ERRMODE,\PDO::ERRMODE_EXCEPTION); + return $pdo; + + } } -- cgit v1.2.3