123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243 |
- <?php
- namespace Sabre\CalDAV;
- use Sabre\HTTP\Request;
- class JCalTransformTest extends \Sabre\DAVServerTest {
- protected $setupCalDAV = true;
- protected $caldavCalendars = [
- [
- 'id' => 1,
- 'principaluri' => 'principals/user1',
- 'uri' => 'foo',
- ]
- ];
- protected $caldavCalendarObjects = [
- 1 => [
- 'bar.ics' => [
- 'uri' => 'bar.ics',
- 'calendarid' => 1,
- 'calendardata' => "BEGIN:VCALENDAR\r\nBEGIN:VEVENT\r\nEND:VEVENT\r\nEND:VCALENDAR\r\n",
- 'lastmodified' => null
- ]
- ],
- ];
- function testGet() {
- $headers = [
- 'Accept' => 'application/calendar+json',
- ];
- $request = new Request('GET', '/calendars/user1/foo/bar.ics', $headers);
- $response = $this->request($request);
- $body = $response->getBodyAsString();
- $this->assertEquals(200, $response->getStatus(), "Incorrect status code: " . $body);
- $response = json_decode($body,true);
- if (json_last_error() !== JSON_ERROR_NONE) {
- $this->fail('Json decoding error: ' . json_last_error_msg());
- }
- $this->assertEquals(
- [
- 'vcalendar',
- [],
- [
- [
- 'vevent',
- [],
- [],
- ],
- ],
- ],
- $response
- );
- }
- function testMultiGet() {
- $xml = <<<XML
- <?xml version="1.0"?>
- <c:calendar-multiget xmlns:c="urn:ietf:params:xml:ns:caldav" xmlns:d="DAV:">
- <d:prop>
- <c:calendar-data content-type="application/calendar+json" />
- </d:prop>
- <d:href>/calendars/user1/foo/bar.ics</d:href>
- </c:calendar-multiget>
- XML;
- $headers = [];
- $request = new Request('REPORT', '/calendars/user1/foo', $headers, $xml);
- $response = $this->request($request);
- $this->assertEquals(207, $response->getStatus(), 'Full rsponse: ' . $response->getBodyAsString());
- $multiStatus = $this->server->xml->parse(
- $response->getBodyAsString()
- );
- $responses = $multiStatus->getResponses();
- $this->assertEquals(1, count($responses));
- $response = $responses[0]->getResponseProperties()[200]["{urn:ietf:params:xml:ns:caldav}calendar-data"];
- $jresponse = json_decode($response,true);
- if (json_last_error()) {
- $this->fail('Json decoding error: ' . json_last_error_msg() . '. Full response: ' . $response);
- }
- $this->assertEquals(
- [
- 'vcalendar',
- [],
- [
- [
- 'vevent',
- [],
- [],
- ],
- ],
- ],
- $jresponse
- );
- }
- function testCalendarQueryDepth1() {
- $xml = <<<XML
- <?xml version="1.0"?>
- <c:calendar-query xmlns:c="urn:ietf:params:xml:ns:caldav" xmlns:d="DAV:">
- <d:prop>
- <c:calendar-data content-type="application/calendar+json" />
- </d:prop>
- <c:filter>
- <c:comp-filter name="VCALENDAR" />
- </c:filter>
- </c:calendar-query>
- XML;
- $headers = [
- 'Depth' => '1',
- ];
- $request = new Request('REPORT', '/calendars/user1/foo', $headers, $xml);
- $response = $this->request($request);
- $this->assertEquals(207, $response->getStatus(), "Invalid response code. Full body: " . $response->getBodyAsString());
- $multiStatus = $this->server->xml->parse(
- $response->getBodyAsString()
- );
- $responses = $multiStatus->getResponses();
- $this->assertEquals(1, count($responses));
- $response = $responses[0]->getResponseProperties()[200]["{urn:ietf:params:xml:ns:caldav}calendar-data"];
- $response = json_decode($response,true);
- if (json_last_error()) {
- $this->fail('Json decoding error: ' . json_last_error_msg());
- }
- $this->assertEquals(
- [
- 'vcalendar',
- [],
- [
- [
- 'vevent',
- [],
- [],
- ],
- ],
- ],
- $response
- );
- }
- function testCalendarQueryDepth0() {
- $xml = <<<XML
- <?xml version="1.0"?>
- <c:calendar-query xmlns:c="urn:ietf:params:xml:ns:caldav" xmlns:d="DAV:">
- <d:prop>
- <c:calendar-data content-type="application/calendar+json" />
- </d:prop>
- <c:filter>
- <c:comp-filter name="VCALENDAR" />
- </c:filter>
- </c:calendar-query>
- XML;
- $headers = [
- 'Depth' => '0',
- ];
- $request = new Request('REPORT', '/calendars/user1/foo/bar.ics', $headers, $xml);
- $response = $this->request($request);
- $this->assertEquals(207, $response->getStatus(), "Invalid response code. Full body: " . $response->getBodyAsString());
- $multiStatus = $this->server->xml->parse(
- $response->getBodyAsString()
- );
- $responses = $multiStatus->getResponses();
- $this->assertEquals(1, count($responses));
- $response = $responses[0]->getResponseProperties()[200]["{urn:ietf:params:xml:ns:caldav}calendar-data"];
- $response = json_decode($response,true);
- if (json_last_error()) {
- $this->fail('Json decoding error: ' . json_last_error_msg());
- }
- $this->assertEquals(
- [
- 'vcalendar',
- [],
- [
- [
- 'vevent',
- [],
- [],
- ],
- ],
- ],
- $response
- );
- }
- function testValidateICalendar() {
- $input = [
- 'vcalendar',
- [],
- [
- [
- 'vevent',
- [
- ['uid', (object)[], 'text', 'foo'],
- ],
- [],
- ],
- ],
- ];
- $input = json_encode($input);
- $this->caldavPlugin->beforeWriteContent(
- 'calendars/user1/foo/bar.ics',
- $this->server->tree->getNodeForPath('calendars/user1/foo/bar.ics'),
- $input,
- $modified
- );
- $this->assertEquals("BEGIN:VCALENDAR\r\nBEGIN:VEVENT\r\nUID:foo\r\nEND:VEVENT\r\nEND:VCALENDAR\r\n", $input);
- }
- }
|