2013-10-21 22:46:31 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Sabre\CalDAV;
|
|
|
|
|
|
|
|
use Sabre\DAV;
|
|
|
|
use Sabre\HTTP;
|
|
|
|
use Sabre\VObject;
|
|
|
|
use Sabre\DAVACL;
|
|
|
|
|
2016-05-28 15:46:24 +00:00
|
|
|
class ICSExportPluginTest extends \Sabre\DAVServerTest {
|
2013-10-21 22:46:31 +00:00
|
|
|
|
2016-05-28 15:46:24 +00:00
|
|
|
protected $setupCalDAV = true;
|
|
|
|
|
|
|
|
protected $icsExportPlugin;
|
2013-10-21 22:46:31 +00:00
|
|
|
|
2016-05-11 00:26:44 +00:00
|
|
|
function setUp() {
|
|
|
|
|
2016-05-28 15:46:24 +00:00
|
|
|
parent::setUp();
|
|
|
|
$this->icsExportPlugin = new ICSExportPlugin();
|
|
|
|
$this->server->addPlugin(
|
|
|
|
$this->icsExportPlugin
|
|
|
|
);
|
2016-05-11 00:26:44 +00:00
|
|
|
|
2016-05-28 15:46:24 +00:00
|
|
|
$id = $this->caldavBackend->createCalendar(
|
|
|
|
'principals/admin',
|
|
|
|
'UUID-123467',
|
|
|
|
[
|
|
|
|
'{DAV:}displayname' => 'Hello!',
|
|
|
|
'{http://apple.com/ns/ical/}calendar-color' => '#AA0000FF',
|
|
|
|
]
|
|
|
|
);
|
2016-05-11 00:26:44 +00:00
|
|
|
|
2016-05-28 15:46:24 +00:00
|
|
|
$this->caldavBackend->createCalendarObject(
|
|
|
|
$id,
|
|
|
|
'event-1',
|
|
|
|
<<<ICS
|
|
|
|
BEGIN:VCALENDAR
|
|
|
|
BEGIN:VTIMEZONE
|
|
|
|
TZID:Europe/Amsterdam
|
|
|
|
END:VTIMEZONE
|
|
|
|
BEGIN:VEVENT
|
|
|
|
UID:event-1
|
|
|
|
DTSTART;TZID=Europe/Amsterdam:20151020T000000
|
|
|
|
END:VEVENT
|
|
|
|
END:VCALENDAR
|
|
|
|
ICS
|
|
|
|
);
|
|
|
|
$this->caldavBackend->createCalendarObject(
|
|
|
|
$id,
|
|
|
|
'todo-1',
|
|
|
|
<<<ICS
|
|
|
|
BEGIN:VCALENDAR
|
|
|
|
BEGIN:VTODO
|
|
|
|
UID:todo-1
|
|
|
|
END:VTODO
|
|
|
|
END:VCALENDAR
|
|
|
|
ICS
|
|
|
|
);
|
2013-10-21 22:46:31 +00:00
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-05-28 15:46:24 +00:00
|
|
|
function testInit() {
|
2013-10-21 22:46:31 +00:00
|
|
|
|
2016-05-28 15:46:24 +00:00
|
|
|
$this->assertEquals(
|
|
|
|
$this->icsExportPlugin,
|
|
|
|
$this->server->getPlugin('ics-export')
|
|
|
|
);
|
|
|
|
$this->assertEquals($this->icsExportPlugin, $this->server->getPlugin('ics-export'));
|
|
|
|
$this->assertEquals('ics-export', $this->icsExportPlugin->getPluginInfo()['name']);
|
2013-10-21 22:46:31 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-05-28 15:46:24 +00:00
|
|
|
function testBeforeMethod() {
|
2013-10-21 22:46:31 +00:00
|
|
|
|
2016-05-28 15:46:24 +00:00
|
|
|
$request = new HTTP\Request(
|
|
|
|
'GET',
|
|
|
|
'/calendars/admin/UUID-123467?export'
|
|
|
|
);
|
2013-10-21 22:46:31 +00:00
|
|
|
|
2016-05-28 15:46:24 +00:00
|
|
|
$response = $this->request($request);
|
2013-10-21 22:46:31 +00:00
|
|
|
|
2016-05-28 15:46:24 +00:00
|
|
|
$this->assertEquals(200, $response->getStatus());
|
|
|
|
$this->assertEquals('text/calendar', $response->getHeader('Content-Type'));
|
2013-10-21 22:46:31 +00:00
|
|
|
|
2016-05-28 15:46:24 +00:00
|
|
|
$obj = VObject\Reader::read($response->body);
|
2013-10-21 22:46:31 +00:00
|
|
|
|
2016-05-28 15:46:24 +00:00
|
|
|
$this->assertEquals(8, 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"});
|
2013-10-21 22:46:31 +00:00
|
|
|
|
2016-05-28 15:46:24 +00:00
|
|
|
}
|
|
|
|
function testBeforeMethodNoVersion() {
|
2013-10-21 22:46:31 +00:00
|
|
|
|
2016-05-28 15:46:24 +00:00
|
|
|
$request = new HTTP\Request(
|
|
|
|
'GET',
|
|
|
|
'/calendars/admin/UUID-123467?export'
|
|
|
|
);
|
2013-10-21 22:46:31 +00:00
|
|
|
DAV\Server::$exposeVersion = false;
|
2016-05-28 15:46:24 +00:00
|
|
|
$response = $this->request($request);
|
2013-10-21 22:46:31 +00:00
|
|
|
DAV\Server::$exposeVersion = true;
|
|
|
|
|
2016-05-28 15:46:24 +00:00
|
|
|
$this->assertEquals(200, $response->getStatus());
|
|
|
|
$this->assertEquals('text/calendar', $response->getHeader('Content-Type'));
|
2013-10-21 22:46:31 +00:00
|
|
|
|
2016-05-28 15:46:24 +00:00
|
|
|
$obj = VObject\Reader::read($response->body);
|
2013-10-21 22:46:31 +00:00
|
|
|
|
2016-05-28 15:46:24 +00:00
|
|
|
$this->assertEquals(8, count($obj->children()));
|
|
|
|
$this->assertEquals(1, count($obj->VERSION));
|
|
|
|
$this->assertEquals(1, count($obj->CALSCALE));
|
|
|
|
$this->assertEquals(1, count($obj->PRODID));
|
|
|
|
$this->assertFalse(strpos((string)$obj->PRODID, DAV\Version::VERSION) !== false);
|
|
|
|
$this->assertEquals(1, count($obj->VTIMEZONE));
|
|
|
|
$this->assertEquals(1, count($obj->VEVENT));
|
2013-10-21 22:46:31 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function testBeforeMethodNoExport() {
|
|
|
|
|
2016-05-28 15:46:24 +00:00
|
|
|
$request = new HTTP\Request(
|
|
|
|
'GET',
|
|
|
|
'/calendars/admin/UUID-123467'
|
|
|
|
);
|
|
|
|
$response = new HTTP\Response();
|
|
|
|
$this->assertNull($this->icsExportPlugin->httpGet($request, $response));
|
2013-10-21 22:46:31 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function testACLIntegrationBlocked() {
|
|
|
|
|
2016-05-28 15:46:24 +00:00
|
|
|
$aclPlugin = new DAVACL\Plugin();
|
|
|
|
$aclPlugin->allowUnauthenticatedAccess = false;
|
|
|
|
$this->server->addPlugin(
|
|
|
|
$aclPlugin
|
2013-10-21 22:46:31 +00:00
|
|
|
);
|
|
|
|
|
2016-05-28 15:46:24 +00:00
|
|
|
$request = new HTTP\Request(
|
|
|
|
'GET',
|
|
|
|
'/calendars/admin/UUID-123467?export'
|
|
|
|
);
|
2016-05-11 00:26:44 +00:00
|
|
|
|
2016-05-28 15:46:24 +00:00
|
|
|
$this->request($request, 403);
|
2013-10-21 22:46:31 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function testACLIntegrationNotBlocked() {
|
|
|
|
|
2016-05-28 15:46:24 +00:00
|
|
|
$aclPlugin = new DAVACL\Plugin();
|
|
|
|
$aclPlugin->allowUnauthenticatedAccess = false;
|
|
|
|
$this->server->addPlugin(
|
|
|
|
$aclPlugin
|
2013-10-21 22:46:31 +00:00
|
|
|
);
|
2016-05-28 15:46:24 +00:00
|
|
|
$this->server->addPlugin(
|
|
|
|
new Plugin()
|
2013-10-21 22:46:31 +00:00
|
|
|
);
|
|
|
|
|
2016-05-28 15:46:24 +00:00
|
|
|
$this->autoLogin('admin');
|
2013-10-21 22:46:31 +00:00
|
|
|
|
2016-05-28 15:46:24 +00:00
|
|
|
$request = new HTTP\Request(
|
|
|
|
'GET',
|
|
|
|
'/calendars/admin/UUID-123467?export'
|
|
|
|
);
|
2013-10-21 22:46:31 +00:00
|
|
|
|
2016-05-28 15:46:24 +00:00
|
|
|
$response = $this->request($request, 200);
|
|
|
|
$this->assertEquals('text/calendar', $response->getHeader('Content-Type'));
|
2013-10-21 22:46:31 +00:00
|
|
|
|
2016-05-28 15:46:24 +00:00
|
|
|
$obj = VObject\Reader::read($response->body);
|
2013-10-21 22:46:31 +00:00
|
|
|
|
2016-05-28 15:46:24 +00:00
|
|
|
$this->assertEquals(8, 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));
|
2013-10-21 22:46:31 +00:00
|
|
|
|
|
|
|
}
|
2016-05-11 00:26:44 +00:00
|
|
|
|
|
|
|
function testBadStartParam() {
|
|
|
|
|
2016-05-28 15:46:24 +00:00
|
|
|
$request = new HTTP\Request(
|
|
|
|
'GET',
|
|
|
|
'/calendars/admin/UUID-123467?export&start=foo'
|
2016-05-11 00:26:44 +00:00
|
|
|
);
|
2016-05-28 15:46:24 +00:00
|
|
|
$this->request($request, 400);
|
2016-05-11 00:26:44 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function testBadEndParam() {
|
|
|
|
|
2016-05-28 15:46:24 +00:00
|
|
|
$request = new HTTP\Request(
|
|
|
|
'GET',
|
|
|
|
'/calendars/admin/UUID-123467?export&end=foo'
|
2016-05-11 00:26:44 +00:00
|
|
|
);
|
2016-05-28 15:46:24 +00:00
|
|
|
$this->request($request, 400);
|
2016-05-11 00:26:44 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function testFilterStartEnd() {
|
|
|
|
|
2016-05-28 15:46:24 +00:00
|
|
|
$request = new HTTP\Request(
|
|
|
|
'GET',
|
|
|
|
'/calendars/admin/UUID-123467?export&start=1&end=2'
|
2016-05-11 00:26:44 +00:00
|
|
|
);
|
2016-05-28 15:46:24 +00:00
|
|
|
$response = $this->request($request, 200);
|
2016-05-11 00:26:44 +00:00
|
|
|
|
2016-05-28 15:46:24 +00:00
|
|
|
$obj = VObject\Reader::read($response->getBody());
|
2016-05-11 00:26:44 +00:00
|
|
|
|
2016-05-28 15:46:24 +00:00
|
|
|
$this->assertEquals(0, count($obj->VTIMEZONE));
|
|
|
|
$this->assertEquals(0, count($obj->VEVENT));
|
2016-05-11 00:26:44 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function testExpandNoStart() {
|
|
|
|
|
2016-05-28 15:46:24 +00:00
|
|
|
$request = new HTTP\Request(
|
|
|
|
'GET',
|
|
|
|
'/calendars/admin/UUID-123467?export&expand=1&end=2'
|
2016-05-11 00:26:44 +00:00
|
|
|
);
|
2016-05-28 15:46:24 +00:00
|
|
|
$this->request($request, 400);
|
2016-05-11 00:26:44 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function testExpand() {
|
|
|
|
|
2016-05-28 15:46:24 +00:00
|
|
|
$request = new HTTP\Request(
|
|
|
|
'GET',
|
|
|
|
'/calendars/admin/UUID-123467?export&start=1&end=2000000000&expand=1'
|
2016-05-11 00:26:44 +00:00
|
|
|
);
|
2016-05-28 15:46:24 +00:00
|
|
|
$response = $this->request($request, 200);
|
2016-05-11 00:26:44 +00:00
|
|
|
|
2016-05-28 15:46:24 +00:00
|
|
|
$obj = VObject\Reader::read($response->getBody());
|
2016-05-11 00:26:44 +00:00
|
|
|
|
2016-05-28 15:46:24 +00:00
|
|
|
$this->assertEquals(0, count($obj->VTIMEZONE));
|
|
|
|
$this->assertEquals(1, count($obj->VEVENT));
|
2016-05-11 00:26:44 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function testJCal() {
|
|
|
|
|
2016-05-28 15:46:24 +00:00
|
|
|
$request = new HTTP\Request(
|
|
|
|
'GET',
|
|
|
|
'/calendars/admin/UUID-123467?export',
|
|
|
|
['Accept' => 'application/calendar+json']
|
2016-05-11 00:26:44 +00:00
|
|
|
);
|
|
|
|
|
2016-05-28 15:46:24 +00:00
|
|
|
$response = $this->request($request, 200);
|
|
|
|
$this->assertEquals('application/calendar+json', $response->getHeader('Content-Type'));
|
2016-05-11 00:26:44 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function testJCalInUrl() {
|
|
|
|
|
2016-05-28 15:46:24 +00:00
|
|
|
$request = new HTTP\Request(
|
|
|
|
'GET',
|
|
|
|
'/calendars/admin/UUID-123467?export&accept=jcal'
|
2016-05-11 00:26:44 +00:00
|
|
|
);
|
|
|
|
|
2016-05-28 15:46:24 +00:00
|
|
|
$response = $this->request($request, 200);
|
|
|
|
$this->assertEquals('application/calendar+json', $response->getHeader('Content-Type'));
|
2016-05-11 00:26:44 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function testNegotiateDefault() {
|
|
|
|
|
2016-05-28 15:46:24 +00:00
|
|
|
$request = new HTTP\Request(
|
|
|
|
'GET',
|
|
|
|
'/calendars/admin/UUID-123467?export',
|
|
|
|
['Accept' => 'text/plain']
|
2016-05-11 00:26:44 +00:00
|
|
|
);
|
|
|
|
|
2016-05-28 15:46:24 +00:00
|
|
|
$response = $this->request($request, 200);
|
|
|
|
$this->assertEquals('text/calendar', $response->getHeader('Content-Type'));
|
2016-05-11 00:26:44 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function testFilterComponentVEVENT() {
|
|
|
|
|
2016-05-28 15:46:24 +00:00
|
|
|
$request = new HTTP\Request(
|
|
|
|
'GET',
|
|
|
|
'/calendars/admin/UUID-123467?export&componentType=VEVENT'
|
2016-05-11 00:26:44 +00:00
|
|
|
);
|
|
|
|
|
2016-05-28 15:46:24 +00:00
|
|
|
$response = $this->request($request, 200);
|
2016-05-11 00:26:44 +00:00
|
|
|
|
2016-05-28 15:46:24 +00:00
|
|
|
$obj = VObject\Reader::read($response->body);
|
|
|
|
$this->assertEquals(1, count($obj->VTIMEZONE));
|
|
|
|
$this->assertEquals(1, count($obj->VEVENT));
|
|
|
|
$this->assertEquals(0, count($obj->VTODO));
|
2016-05-11 00:26:44 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function testFilterComponentVTODO() {
|
|
|
|
|
2016-05-28 15:46:24 +00:00
|
|
|
$request = new HTTP\Request(
|
|
|
|
'GET',
|
|
|
|
'/calendars/admin/UUID-123467?export&componentType=VTODO'
|
|
|
|
);
|
2016-05-11 00:26:44 +00:00
|
|
|
|
2016-05-28 15:46:24 +00:00
|
|
|
$response = $this->request($request, 200);
|
2016-05-11 00:26:44 +00:00
|
|
|
|
2016-05-28 15:46:24 +00:00
|
|
|
$obj = VObject\Reader::read($response->body);
|
2016-05-11 00:26:44 +00:00
|
|
|
|
2016-05-28 15:46:24 +00:00
|
|
|
$this->assertEquals(0, count($obj->VTIMEZONE));
|
|
|
|
$this->assertEquals(0, count($obj->VEVENT));
|
|
|
|
$this->assertEquals(1, count($obj->VTODO));
|
2016-05-11 00:26:44 +00:00
|
|
|
|
2016-05-28 15:46:24 +00:00
|
|
|
}
|
2016-05-11 00:26:44 +00:00
|
|
|
|
2016-05-28 15:46:24 +00:00
|
|
|
function testFilterComponentBadComponent() {
|
2016-05-11 00:26:44 +00:00
|
|
|
|
2016-05-28 15:46:24 +00:00
|
|
|
$request = new HTTP\Request(
|
|
|
|
'GET',
|
|
|
|
'/calendars/admin/UUID-123467?export&componentType=VVOODOO'
|
|
|
|
);
|
2016-05-11 00:26:44 +00:00
|
|
|
|
2016-05-28 15:46:24 +00:00
|
|
|
$response = $this->request($request, 400);
|
2016-05-11 00:26:44 +00:00
|
|
|
|
2016-05-28 15:46:24 +00:00
|
|
|
}
|
2016-05-11 00:26:44 +00:00
|
|
|
|
2016-05-28 15:46:24 +00:00
|
|
|
function testContentDisposition() {
|
2016-05-11 00:26:44 +00:00
|
|
|
|
2016-05-28 15:46:24 +00:00
|
|
|
$request = new HTTP\Request(
|
|
|
|
'GET',
|
|
|
|
'/calendars/admin/UUID-123467?export'
|
|
|
|
);
|
2016-05-11 00:26:44 +00:00
|
|
|
|
2016-05-28 15:46:24 +00:00
|
|
|
$response = $this->request($request, 200);
|
|
|
|
$this->assertEquals('text/calendar', $response->getHeader('Content-Type'));
|
|
|
|
$this->assertEquals(
|
|
|
|
'attachment; filename="UUID-123467-' . date('Y-m-d') . '.ics"',
|
|
|
|
$response->getHeader('Content-Disposition')
|
|
|
|
);
|
2016-05-11 00:26:44 +00:00
|
|
|
|
2016-05-28 15:46:24 +00:00
|
|
|
}
|
2016-05-11 00:26:44 +00:00
|
|
|
|
2016-05-28 15:46:24 +00:00
|
|
|
function testContentDispositionJson() {
|
2016-05-11 00:26:44 +00:00
|
|
|
|
2016-05-28 15:46:24 +00:00
|
|
|
$request = new HTTP\Request(
|
|
|
|
'GET',
|
|
|
|
'/calendars/admin/UUID-123467?export',
|
|
|
|
['Accept' => 'application/calendar+json']
|
|
|
|
);
|
2016-05-11 00:26:44 +00:00
|
|
|
|
2016-05-28 15:46:24 +00:00
|
|
|
$response = $this->request($request, 200);
|
|
|
|
$this->assertEquals('application/calendar+json', $response->getHeader('Content-Type'));
|
|
|
|
$this->assertEquals(
|
|
|
|
'attachment; filename="UUID-123467-' . date('Y-m-d') . '.json"',
|
|
|
|
$response->getHeader('Content-Disposition')
|
|
|
|
);
|
2016-05-11 00:26:44 +00:00
|
|
|
|
2016-05-28 15:46:24 +00:00
|
|
|
}
|
2016-05-11 00:26:44 +00:00
|
|
|
|
2016-05-28 15:46:24 +00:00
|
|
|
function testContentDispositionBadChars() {
|
2016-05-11 00:26:44 +00:00
|
|
|
|
2016-05-28 15:46:24 +00:00
|
|
|
$this->caldavBackend->createCalendar(
|
|
|
|
'principals/admin',
|
|
|
|
'UUID-b_ad"(ch)ars',
|
|
|
|
[
|
|
|
|
'{DAV:}displayname' => 'Test bad characters',
|
|
|
|
'{http://apple.com/ns/ical/}calendar-color' => '#AA0000FF',
|
|
|
|
]
|
|
|
|
);
|
2016-05-11 00:26:44 +00:00
|
|
|
|
2016-05-28 15:46:24 +00:00
|
|
|
$request = new HTTP\Request(
|
|
|
|
'GET',
|
|
|
|
'/calendars/admin/UUID-b_ad"(ch)ars?export',
|
|
|
|
['Accept' => 'application/calendar+json']
|
|
|
|
);
|
2016-05-11 00:26:44 +00:00
|
|
|
|
2016-05-28 15:46:24 +00:00
|
|
|
$response = $this->request($request, 200);
|
|
|
|
$this->assertEquals('application/calendar+json', $response->getHeader('Content-Type'));
|
|
|
|
$this->assertEquals(
|
|
|
|
'attachment; filename="UUID-b_adchars-' . date('Y-m-d') . '.json"',
|
|
|
|
$response->getHeader('Content-Disposition')
|
|
|
|
);
|
2016-05-11 00:26:44 +00:00
|
|
|
|
|
|
|
}
|
2016-05-28 15:46:24 +00:00
|
|
|
|
2013-10-21 22:46:31 +00:00
|
|
|
}
|