From dcdca93c0e3fe14186783f4cfd77d0724c133320 Mon Sep 17 00:00:00 2001 From: Edward Akerboom Date: Tue, 27 Mar 2018 11:58:52 +0200 Subject: [PATCH 1/3] Add $depth parameter in getCalendar request This allows the user to retrieve all the objects in the calendar. --- src/Facade/CalDavClient.php | 5 +++-- src/Facade/Responses/ETagEntityMultiResponse.php | 12 ++++++++++++ src/Facade/Responses/GetCalendarResponse.php | 2 +- 3 files changed, 16 insertions(+), 3 deletions(-) create mode 100644 src/Facade/Responses/ETagEntityMultiResponse.php diff --git a/src/Facade/CalDavClient.php b/src/Facade/CalDavClient.php index 52da5ba..a4458de 100644 --- a/src/Facade/CalDavClient.php +++ b/src/Facade/CalDavClient.php @@ -260,16 +260,17 @@ public function getCalendars($calendar_home_set_url) /** * @param string $calendar_url + * @param int $depth Defaults to 0 to obtain calendar metadata. Set to 1 to obtain (all) calendar contents as well. * @return GetCalendarResponse */ - public function getCalendar($calendar_url) + public function getCalendar($calendar_url, $depth = 0) { $http_response = $this->makeRequest( RequestFactory::createPropFindRequest ( $calendar_url, CalDAVRequestFactory::getInstance()->build(CalDAVRequestFactory::CalendarRequestType)->getContent(), - 0 + $depth ) ); diff --git a/src/Facade/Responses/ETagEntityMultiResponse.php b/src/Facade/Responses/ETagEntityMultiResponse.php new file mode 100644 index 0000000..9745024 --- /dev/null +++ b/src/Facade/Responses/ETagEntityMultiResponse.php @@ -0,0 +1,12 @@ + Date: Thu, 17 May 2018 15:34:56 +0200 Subject: [PATCH 2/3] Add missing GetCalendarMultiResponse --- .../Responses/GetCalendarMultiResponse.php | 30 +++++++++++++++++++ src/Facade/Responses/GetCalendarResponse.php | 3 +- src/Facade/Responses/GetCalendarsResponse.php | 2 +- 3 files changed, 32 insertions(+), 3 deletions(-) create mode 100644 src/Facade/Responses/GetCalendarMultiResponse.php diff --git a/src/Facade/Responses/GetCalendarMultiResponse.php b/src/Facade/Responses/GetCalendarMultiResponse.php new file mode 100644 index 0000000..d97d2e7 --- /dev/null +++ b/src/Facade/Responses/GetCalendarMultiResponse.php @@ -0,0 +1,30 @@ +found_props['getctag']) ? $this->found_props['getctag'] : null; } - } \ No newline at end of file diff --git a/src/Facade/Responses/GetCalendarsResponse.php b/src/Facade/Responses/GetCalendarsResponse.php index 34dbc6d..60e9ca0 100644 --- a/src/Facade/Responses/GetCalendarsResponse.php +++ b/src/Facade/Responses/GetCalendarsResponse.php @@ -26,7 +26,7 @@ final class GetCalendarsResponse extends GenericMultiCalDAVResponse */ protected function buildSingleResponse() { - return new GetCalendarResponse(); + return new GetCalendarMultiResponse(); } } From b9dd92caf9c0fe829ba60d4b4de26084a6b30330 Mon Sep 17 00:00:00 2001 From: Edward Akerboom Date: Wed, 13 Jun 2018 16:47:55 +0200 Subject: [PATCH 3/3] Fix tests for CalendarMultiResponse --- src/Facade/CalDavClient.php | 7 ++++--- .../GenericSinglePROPFINDCalDAVResponse.php | 2 +- src/Facade/Responses/GetCalendarMultiResponse.php | 2 +- src/ICalDavClient.php | 4 ++-- tests/FacadeTest.php | 12 ++++++++---- 5 files changed, 16 insertions(+), 11 deletions(-) diff --git a/src/Facade/CalDavClient.php b/src/Facade/CalDavClient.php index a4458de..8103d05 100644 --- a/src/Facade/CalDavClient.php +++ b/src/Facade/CalDavClient.php @@ -24,7 +24,7 @@ use CalDAVClient\Facade\Responses\EventCreatedResponse; use CalDAVClient\Facade\Responses\EventDeletedResponse; use CalDAVClient\Facade\Responses\EventUpdatedResponse; -use CalDAVClient\Facade\Responses\GetCalendarResponse; +use CalDAVClient\Facade\Responses\GetCalendarMultiResponse; use CalDAVClient\Facade\Responses\GetCalendarsResponse; use CalDAVClient\Facade\Responses\ResourceCollectionResponse; use CalDAVClient\Facade\Responses\UserPrincipalResponse; @@ -261,7 +261,8 @@ public function getCalendars($calendar_home_set_url) /** * @param string $calendar_url * @param int $depth Defaults to 0 to obtain calendar metadata. Set to 1 to obtain (all) calendar contents as well. - * @return GetCalendarResponse + * @return GetCalendarMultiResponse + * @throws \GuzzleHttp\Exception\GuzzleException */ public function getCalendar($calendar_url, $depth = 0) { @@ -274,7 +275,7 @@ public function getCalendar($calendar_url, $depth = 0) ) ); - return new GetCalendarResponse($this->server_url, (string)$http_response->getBody(), $http_response->getStatusCode()); + return new GetCalendarMultiResponse($this->server_url, (string)$http_response->getBody(), $http_response->getStatusCode()); } diff --git a/src/Facade/Responses/GenericSinglePROPFINDCalDAVResponse.php b/src/Facade/Responses/GenericSinglePROPFINDCalDAVResponse.php index bf73454..4738b99 100644 --- a/src/Facade/Responses/GenericSinglePROPFINDCalDAVResponse.php +++ b/src/Facade/Responses/GenericSinglePROPFINDCalDAVResponse.php @@ -94,6 +94,6 @@ public function getHRef() */ public function isSuccessFull() { - return $this->code == HttpResponse::HttpCodeMultiResponse; + return ($this->code == HttpResponse::HttpCodeMultiResponse || $this->code == HttpResponse::HttpCodeOk); } } \ No newline at end of file diff --git a/src/Facade/Responses/GetCalendarMultiResponse.php b/src/Facade/Responses/GetCalendarMultiResponse.php index d97d2e7..7ae98a4 100644 --- a/src/Facade/Responses/GetCalendarMultiResponse.php +++ b/src/Facade/Responses/GetCalendarMultiResponse.php @@ -20,7 +20,7 @@ final class GetCalendarMultiResponse extends GenericMultiCalDAVResponse { /** - * @return GenericSinglePROPFINDCalDAVResponse + * @return GetCalendarResponse */ protected function buildSingleResponse() { diff --git a/src/ICalDavClient.php b/src/ICalDavClient.php index a706c05..21359d9 100644 --- a/src/ICalDavClient.php +++ b/src/ICalDavClient.php @@ -21,7 +21,7 @@ use CalDAVClient\Facade\Responses\EventCreatedResponse; use CalDAVClient\Facade\Responses\EventDeletedResponse; use CalDAVClient\Facade\Responses\EventUpdatedResponse; -use CalDAVClient\Facade\Responses\GetCalendarResponse; +use CalDAVClient\Facade\Responses\GetCalendarMultiResponse; use CalDAVClient\Facade\Responses\GetCalendarsResponse; use CalDAVClient\Facade\Responses\ResourceCollectionResponse; use CalDAVClient\Facade\Responses\UserPrincipalResponse; @@ -86,7 +86,7 @@ public function getCalendars($calendar_home_set_url); /** * @param string $calendar_url - * @return GetCalendarResponse + * @return GetCalendarMultiResponse */ public function getCalendar($calendar_url); diff --git a/tests/FacadeTest.php b/tests/FacadeTest.php index 2bb50e8..e83ff60 100644 --- a/tests/FacadeTest.php +++ b/tests/FacadeTest.php @@ -75,10 +75,14 @@ function testGetCalendars(){ } function testGetCalendar(){ - $res = self::$client->getCalendar(getenv('CALDAV_SERVER_URL').'/8244464267/calendars/openstack-summit-sidney-2017/'); - $this->assertTrue($res->isSuccessFull()); - $this->assertTrue(!empty($res->getDisplayName())); - $this->assertTrue(!empty($res->getSyncToken())); + $responses = self::$client->getCalendar($this->getCalendarUrl())->getResponses(); + + foreach ($responses as $res) { + $this->assertTrue($res->isSuccessFull(), "Calendar request not successful"); + $this->assertTrue(!empty($res->getDisplayName()), "Display name not set"); + $this->assertTrue(!empty($res->getSyncToken()), "Sync-token empty"); + } + return $responses[0]; } function testSyncCalendar(){