Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/Facade/CalDavClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
use CalDAVClient\Facade\Requests\EventRequestVO;
use CalDAVClient\Facade\Requests\MakeCalendarRequestVO;
use CalDAVClient\Facade\Responses\CalendarDeletedResponse;
use CalDAVClient\Facade\Responses\CalendarHomesResponse;
use CalDAVClient\Facade\Responses\CalendarHomesMultiResponse;
use CalDAVClient\Facade\Responses\CalendarSyncInfoResponse;
use CalDAVClient\Facade\Responses\EventCreatedResponse;
use CalDAVClient\Facade\Responses\EventDeletedResponse;
Expand Down Expand Up @@ -208,7 +208,7 @@ public function getUserPrincipal()

/**
* @param string $principal_url
* @return CalendarHomesResponse
* @return CalendarHomesMultiResponse
* @throws \GuzzleHttp\Exception\GuzzleException
*/
public function getCalendarHome($principal_url)
Expand All @@ -221,7 +221,7 @@ public function getCalendarHome($principal_url)
)
);

return new CalendarHomesResponse($this->server_url, (string)$http_response->getBody(), $http_response->getStatusCode());
return new CalendarHomesMultiResponse($this->server_url, (string)$http_response->getBody(), $http_response->getStatusCode());
}

/**
Expand Down
30 changes: 30 additions & 0 deletions src/Facade/Responses/CalendarHomesMultiResponse.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php namespace CalDAVClient\Facade\Responses;
/**
* Copyright 2017 OpenStack Foundation
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/

/**
* Class CalendarHomesMultiResponse
* @package CalDAVClient\Facade\Responses
*/
final class CalendarHomesMultiResponse extends GenericMultiCalDAVResponse
{

/**
* @return CalendarHomesResponse
*/
protected function buildSingleResponse()
{
return new CalendarHomesResponse();
}

}
4 changes: 2 additions & 2 deletions src/ICalDavClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
use CalDAVClient\Facade\Requests\EventRequestVO;
use CalDAVClient\Facade\Requests\MakeCalendarRequestVO;
use CalDAVClient\Facade\Responses\CalendarDeletedResponse;
use CalDAVClient\Facade\Responses\CalendarHomesResponse;
use CalDAVClient\Facade\Responses\CalendarHomesMultiResponse;
use CalDAVClient\Facade\Responses\CalendarSyncInfoResponse;
use CalDAVClient\Facade\Responses\EventCreatedResponse;
use CalDAVClient\Facade\Responses\EventDeletedResponse;
Expand Down Expand Up @@ -59,7 +59,7 @@ public function getUserPrincipal();

/**
* @param string $principal_url
* @return CalendarHomesResponse
* @return CalendarHomesMultiResponse
*/
public function getCalendarHome($principal_url);

Expand Down
43 changes: 24 additions & 19 deletions tests/FacadeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,26 +86,31 @@ function testCalendarHomes(){
$caldav_path = getenv("CALDAV_SERVER_PATH");

$principal_url = $this->testPrincipal();
$res = self::$client->getCalendarHome($caldav_host . $principal_url);
$url = $res->getCalendarHomeSetUrl();

$this->assertTrue(!empty($url), "Calendar home URL is empty");
// $host = $res->getRealCalDAVHost();
// echo sprintf('calendar home is %s', $url).PHP_EOL;
// echo sprintf('host is %s', $caldav_host).PHP_EOL;

// first, ensures that the 'home' path is relative to the CalDav server
// (this differs between servers)
$path_without_prefix = $url;
if (strpos($path_without_prefix, $caldav_host) === 0) {
$path_without_prefix = substr($path_without_prefix, strlen($caldav_host));
$homes = self::$client->getCalendarHome($caldav_host . $principal_url)->getResponses();
foreach ($homes as $res) {
$url = $res->getCalendarHomeSetUrl();

$this->assertTrue(!empty($url), "Calendar home URL is empty");
// $host = $res->getRealCalDAVHost();
// echo sprintf('calendar home is %s', $url).PHP_EOL;
// echo sprintf('host is %s', $caldav_host).PHP_EOL;

// first, ensures that the 'home' path is relative to the CalDav server
// (this differs between servers)
$path_without_prefix = $url;
if (strpos($path_without_prefix, $caldav_host) === 0) {
$path_without_prefix = substr($path_without_prefix, strlen($caldav_host));
}
if (strpos($path_without_prefix, $caldav_path) === 0) {
$path_without_prefix = substr($path_without_prefix, strlen($caldav_path));
}

// then, turn the URL into an absolute URL so that we always know what to expect
self::$calendar_home = $caldav_host . $caldav_path . $path_without_prefix;

// stop after first response
break;
}
if (strpos($path_without_prefix, $caldav_path) === 0) {
$path_without_prefix = substr($path_without_prefix, strlen($caldav_path));
}

// then, turn the URL into an absolute URL so that we always know what to expect
self::$calendar_home = $caldav_host . $caldav_path . $path_without_prefix;
}

function testGetCalendars(){
Expand Down