aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/sabre/dav/tests/Sabre/CalDAV/ValidateICalTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/sabre/dav/tests/Sabre/CalDAV/ValidateICalTest.php')
-rw-r--r--vendor/sabre/dav/tests/Sabre/CalDAV/ValidateICalTest.php291
1 files changed, 208 insertions, 83 deletions
diff --git a/vendor/sabre/dav/tests/Sabre/CalDAV/ValidateICalTest.php b/vendor/sabre/dav/tests/Sabre/CalDAV/ValidateICalTest.php
index be166d9e6..629df90c1 100644
--- a/vendor/sabre/dav/tests/Sabre/CalDAV/ValidateICalTest.php
+++ b/vendor/sabre/dav/tests/Sabre/CalDAV/ValidateICalTest.php
@@ -21,20 +21,20 @@ class ValidateICalTest extends \PHPUnit_Framework_TestCase {
function setUp() {
- $calendars = array(
- array(
- 'id' => 'calendar1',
- 'principaluri' => 'principals/admin',
- 'uri' => 'calendar1',
- '{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 Xml\Property\SupportedCalendarComponentSet( ['VTODO','VJOURNAL'] ),
- )
- );
+ $calendars = [
+ [
+ 'id' => 'calendar1',
+ 'principaluri' => 'principals/admin',
+ 'uri' => 'calendar1',
+ '{urn:ietf:params:xml:ns:caldav}supported-calendar-component-set' => new Xml\Property\SupportedCalendarComponentSet(['VEVENT', 'VTODO', 'VJOURNAL']),
+ ],
+ [
+ 'id' => 'calendar2',
+ 'principaluri' => 'principals/admin',
+ 'uri' => 'calendar2',
+ '{urn:ietf:params:xml:ns:caldav}supported-calendar-component-set' => new Xml\Property\SupportedCalendarComponentSet(['VTODO', 'VJOURNAL']),
+ ]
+ ];
$this->calBackend = new Backend\Mock($calendars, []);
$principalBackend = new DAVACL\PrincipalBackend\Mock();
@@ -66,10 +66,10 @@ class ValidateICalTest extends \PHPUnit_Framework_TestCase {
function testCreateFile() {
- $request = HTTP\Sapi::createFromServerArray(array(
+ $request = HTTP\Sapi::createFromServerArray([
'REQUEST_METHOD' => 'PUT',
- 'REQUEST_URI' => '/calendars/admin/calendar1/blabla.ics',
- ));
+ 'REQUEST_URI' => '/calendars/admin/calendar1/blabla.ics',
+ ]);
$response = $this->request($request);
@@ -79,66 +79,168 @@ class ValidateICalTest extends \PHPUnit_Framework_TestCase {
function testCreateFileValid() {
- $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\nEND:VEVENT\r\nEND:VCALENDAR\r\n");
+ $request = new HTTP\Request(
+ 'PUT',
+ '/calendars/admin/calendar1/blabla.ics',
+ ['Prefer' => 'handling=strict']
+ );
+
+ $ics = <<<ICS
+BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:foo
+BEGIN:VEVENT
+UID:foo
+DTSTAMP:20160406T052348Z
+DTSTART:20160706T140000Z
+END:VEVENT
+END:VCALENDAR
+ICS;
+
+ $request->setBody($ics);
$response = $this->request($request);
$this->assertEquals(201, $response->status, 'Incorrect status returned! Full response body: ' . $response->body);
- $this->assertEquals(array(
+ $this->assertEquals([
'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());
+ 'Content-Length' => ['0'],
+ 'ETag' => ['"' . md5($ics) . '"'],
+ ], $response->getHeaders());
- $expected = array(
+ $expected = [
'uri' => 'blabla.ics',
- 'calendardata' => "BEGIN:VCALENDAR\r\nBEGIN:VEVENT\r\nUID:foo\r\nEND:VEVENT\r\nEND:VCALENDAR\r\n",
+ 'calendardata' => $ics,
'calendarid' => 'calendar1',
'lastmodified' => null,
+ ];
+
+ $this->assertEquals($expected, $this->calBackend->getCalendarObject('calendar1', 'blabla.ics'));
+
+ }
+
+ function testCreateFileNoVersion() {
+
+ $request = new HTTP\Request(
+ 'PUT',
+ '/calendars/admin/calendar1/blabla.ics',
+ ['Prefer' => 'handling=strict']
);
- $this->assertEquals($expected, $this->calBackend->getCalendarObject('calendar1','blabla.ics'));
+ $ics = <<<ICS
+BEGIN:VCALENDAR
+PRODID:foo
+BEGIN:VEVENT
+UID:foo
+DTSTAMP:20160406T052348Z
+DTSTART:20160706T140000Z
+END:VEVENT
+END:VCALENDAR
+ICS;
+
+ $request->setBody($ics);
+
+ $response = $this->request($request);
+
+ $this->assertEquals(415, $response->status, 'Incorrect status returned! Full response body: ' . $response->body);
}
- function testCreateFileNoComponents() {
+ function testCreateFileNoVersionFixed() {
- $request = HTTP\Sapi::createFromServerArray(array(
- 'REQUEST_METHOD' => 'PUT',
- 'REQUEST_URI' => '/calendars/admin/calendar1/blabla.ics',
- ));
- $request->setBody("BEGIN:VCALENDAR\r\nEND:VCALENDAR\r\n");
+ $request = new HTTP\Request(
+ 'PUT',
+ '/calendars/admin/calendar1/blabla.ics',
+ ['Prefer' => 'handling=lenient']
+ );
+
+ $ics = <<<ICS
+BEGIN:VCALENDAR
+PRODID:foo
+BEGIN:VEVENT
+UID:foo
+DTSTAMP:20160406T052348Z
+DTSTART:20160706T140000Z
+END:VEVENT
+END:VCALENDAR
+ICS;
+
+ $request->setBody($ics);
$response = $this->request($request);
- $this->assertEquals(400, $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([
+ 'X-Sabre-Version' => [DAV\Version::VERSION],
+ 'Content-Length' => ['0'],
+ 'X-Sabre-Ew-Gross' => ['iCalendar validation warning: VERSION MUST appear exactly once in a VCALENDAR component'],
+ ], $response->getHeaders());
+
+ $ics = <<<ICS
+BEGIN:VCALENDAR\r
+VERSION:2.0\r
+PRODID:foo\r
+BEGIN:VEVENT\r
+UID:foo\r
+DTSTAMP:20160406T052348Z\r
+DTSTART:20160706T140000Z\r
+END:VEVENT\r
+END:VCALENDAR\r
+
+ICS;
+
+ $expected = [
+ 'uri' => 'blabla.ics',
+ 'calendardata' => $ics,
+ 'calendarid' => 'calendar1',
+ 'lastmodified' => null,
+ ];
+
+ $this->assertEquals($expected, $this->calBackend->getCalendarObject('calendar1', 'blabla.ics'));
+
+ }
+
+ function testCreateFileNoComponents() {
+
+ $request = new HTTP\Request(
+ 'PUT',
+ '/calendars/admin/calendar1/blabla.ics',
+ ['Prefer' => 'handling=strict']
+ );
+ $ics = <<<ICS
+BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:foo
+END:VCALENDAR
+ICS;
+
+ $request->setBody($ics);
+
+ $response = $this->request($request);
+ $this->assertEquals(403, $response->status, 'Incorrect status returned! Full response body: ' . $response->body);
}
function testCreateFileNoUID() {
- $request = HTTP\Sapi::createFromServerArray(array(
+ $request = HTTP\Sapi::createFromServerArray([
'REQUEST_METHOD' => 'PUT',
- 'REQUEST_URI' => '/calendars/admin/calendar1/blabla.ics',
- ));
+ 'REQUEST_URI' => '/calendars/admin/calendar1/blabla.ics',
+ ]);
$request->setBody("BEGIN:VCALENDAR\r\nBEGIN:VEVENT\r\nEND:VEVENT\r\nEND:VCALENDAR\r\n");
$response = $this->request($request);
- $this->assertEquals(400, $response->status, 'Incorrect status returned! Full response body: ' . $response->body);
+ $this->assertEquals(415, $response->status, 'Incorrect status returned! Full response body: ' . $response->body);
}
function testCreateFileVCard() {
- $request = HTTP\Sapi::createFromServerArray(array(
+ $request = HTTP\Sapi::createFromServerArray([
'REQUEST_METHOD' => 'PUT',
- 'REQUEST_URI' => '/calendars/admin/calendar1/blabla.ics',
- ));
+ 'REQUEST_URI' => '/calendars/admin/calendar1/blabla.ics',
+ ]);
$request->setBody("BEGIN:VCARD\r\nEND:VCARD\r\n");
$response = $this->request($request);
@@ -149,53 +251,53 @@ class ValidateICalTest extends \PHPUnit_Framework_TestCase {
function testCreateFile2Components() {
- $request = HTTP\Sapi::createFromServerArray(array(
+ $request = HTTP\Sapi::createFromServerArray([
'REQUEST_METHOD' => 'PUT',
- 'REQUEST_URI' => '/calendars/admin/calendar1/blabla.ics',
- ));
+ 'REQUEST_URI' => '/calendars/admin/calendar1/blabla.ics',
+ ]);
$request->setBody("BEGIN:VCALENDAR\r\nBEGIN:VEVENT\r\nUID:foo\r\nEND:VEVENT\r\nBEGIN:VJOURNAL\r\nUID:foo\r\nEND:VJOURNAL\r\nEND:VCALENDAR\r\n");
$response = $this->request($request);
- $this->assertEquals(400, $response->status, 'Incorrect status returned! Full response body: ' . $response->body);
+ $this->assertEquals(415, $response->status, 'Incorrect status returned! Full response body: ' . $response->body);
}
function testCreateFile2UIDS() {
- $request = HTTP\Sapi::createFromServerArray(array(
+ $request = HTTP\Sapi::createFromServerArray([
'REQUEST_METHOD' => 'PUT',
- 'REQUEST_URI' => '/calendars/admin/calendar1/blabla.ics',
- ));
+ 'REQUEST_URI' => '/calendars/admin/calendar1/blabla.ics',
+ ]);
$request->setBody("BEGIN:VCALENDAR\r\nBEGIN:VTIMEZONE\r\nEND:VTIMEZONE\r\nBEGIN:VEVENT\r\nUID:foo\r\nEND:VEVENT\r\nBEGIN:VEVENT\r\nUID:bar\r\nEND:VEVENT\r\nEND:VCALENDAR\r\n");
$response = $this->request($request);
- $this->assertEquals(400, $response->status, 'Incorrect status returned! Full response body: ' . $response->body);
+ $this->assertEquals(415, $response->status, 'Incorrect status returned! Full response body: ' . $response->body);
}
function testCreateFileWrongComponent() {
- $request = HTTP\Sapi::createFromServerArray(array(
+ $request = HTTP\Sapi::createFromServerArray([
'REQUEST_METHOD' => 'PUT',
- 'REQUEST_URI' => '/calendars/admin/calendar1/blabla.ics',
- ));
+ 'REQUEST_URI' => '/calendars/admin/calendar1/blabla.ics',
+ ]);
$request->setBody("BEGIN:VCALENDAR\r\nBEGIN:VTIMEZONE\r\nEND:VTIMEZONE\r\nBEGIN:VFREEBUSY\r\nUID:foo\r\nEND:VFREEBUSY\r\nEND:VCALENDAR\r\n");
$response = $this->request($request);
- $this->assertEquals(400, $response->status, 'Incorrect status returned! Full response body: ' . $response->body);
+ $this->assertEquals(403, $response->status, 'Incorrect status returned! Full response body: ' . $response->body);
}
function testUpdateFile() {
- $this->calBackend->createCalendarObject('calendar1','blabla.ics','foo');
- $request = HTTP\Sapi::createFromServerArray(array(
+ $this->calBackend->createCalendarObject('calendar1', 'blabla.ics', 'foo');
+ $request = HTTP\Sapi::createFromServerArray([
'REQUEST_METHOD' => 'PUT',
- 'REQUEST_URI' => '/calendars/admin/calendar1/blabla.ics',
- ));
+ 'REQUEST_URI' => '/calendars/admin/calendar1/blabla.ics',
+ ]);
$response = $this->request($request);
@@ -205,35 +307,45 @@ class ValidateICalTest extends \PHPUnit_Framework_TestCase {
function testUpdateFileParsableBody() {
- $this->calBackend->createCalendarObject('calendar1','blabla.ics','foo');
- $request = HTTP\Sapi::createFromServerArray(array(
- 'REQUEST_METHOD' => 'PUT',
- 'REQUEST_URI' => '/calendars/admin/calendar1/blabla.ics',
- ));
- $body = "BEGIN:VCALENDAR\r\nBEGIN:VEVENT\r\nUID:foo\r\nEND:VEVENT\r\nEND:VCALENDAR\r\n";
- $request->setBody($body);
-
+ $this->calBackend->createCalendarObject('calendar1', 'blabla.ics', 'foo');
+ $request = new HTTP\Request(
+ 'PUT',
+ '/calendars/admin/calendar1/blabla.ics'
+ );
+ $ics = <<<ICS
+BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:foo
+BEGIN:VEVENT
+UID:foo
+DTSTAMP:20160406T052348Z
+DTSTART:20160706T140000Z
+END:VEVENT
+END:VCALENDAR
+ICS;
+
+ $request->setBody($ics);
$response = $this->request($request);
$this->assertEquals(204, $response->status);
- $expected = array(
+ $expected = [
'uri' => 'blabla.ics',
- 'calendardata' => $body,
+ 'calendardata' => $ics,
'calendarid' => 'calendar1',
'lastmodified' => null,
- );
+ ];
- $this->assertEquals($expected, $this->calBackend->getCalendarObject('calendar1','blabla.ics'));
+ $this->assertEquals($expected, $this->calBackend->getCalendarObject('calendar1', 'blabla.ics'));
}
function testCreateFileInvalidComponent() {
- $request = HTTP\Sapi::createFromServerArray(array(
+ $request = HTTP\Sapi::createFromServerArray([
'REQUEST_METHOD' => 'PUT',
- 'REQUEST_URI' => '/calendars/admin/calendar2/blabla.ics',
- ));
+ 'REQUEST_URI' => '/calendars/admin/calendar2/blabla.ics',
+ ]);
$request->setBody("BEGIN:VCALENDAR\r\nBEGIN:VTIMEZONE\r\nEND:VTIMEZONE\r\nBEGIN:VEVENT\r\nUID:foo\r\nEND:VEVENT\r\nEND:VCALENDAR\r\n");
$response = $this->request($request);
@@ -244,11 +356,11 @@ class ValidateICalTest extends \PHPUnit_Framework_TestCase {
function testUpdateFileInvalidComponent() {
- $this->calBackend->createCalendarObject('calendar2','blabla.ics','foo');
- $request = HTTP\Sapi::createFromServerArray(array(
+ $this->calBackend->createCalendarObject('calendar2', 'blabla.ics', 'foo');
+ $request = HTTP\Sapi::createFromServerArray([
'REQUEST_METHOD' => 'PUT',
- 'REQUEST_URI' => '/calendars/admin/calendar2/blabla.ics',
- ));
+ 'REQUEST_URI' => '/calendars/admin/calendar2/blabla.ics',
+ ]);
$request->setBody("BEGIN:VCALENDAR\r\nBEGIN:VTIMEZONE\r\nEND:VTIMEZONE\r\nBEGIN:VEVENT\r\nUID:foo\r\nEND:VEVENT\r\nEND:VCALENDAR\r\n");
$response = $this->request($request);
@@ -266,11 +378,24 @@ class ValidateICalTest extends \PHPUnit_Framework_TestCase {
*/
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");
+ $request = new HTTP\Request(
+ 'PUT',
+ '/calendars/admin/calendar1/blabla.ics'
+ );
+ $ics = <<<ICS
+BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:foo
+BEGIN:VEVENT
+UID:foo
+SUMMARY:Meeting in M\xfcnster
+DTSTAMP:20160406T052348Z
+DTSTART:20160706T140000Z
+END:VEVENT
+END:VCALENDAR
+ICS;
+
+ $request->setBody($ics);
$response = $this->request($request);