[Pkg-owncloud-commits] [php-sabredav] 100/163: CalDAV testing is on 100% again.

David Prévot taffit at moszumanska.debian.org
Tue May 20 18:54:58 UTC 2014


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to annotated tag upstream/2.0.0_beta1
in repository php-sabredav.

commit 904fc08222c098cdace2e7156931952a89f7cd4e
Author: Evert Pot <evert at rooftopsolutions.nl>
Date:   Tue Apr 29 00:23:34 2014 -0400

    CalDAV testing is on 100% again.
---
 lib/Sabre/CalDAV/Plugin.php              |   2 +-
 tests/Sabre/CalDAV/JCalTransformTest.php | 181 ++++++++++++++++++++++++++++++-
 2 files changed, 178 insertions(+), 5 deletions(-)

diff --git a/lib/Sabre/CalDAV/Plugin.php b/lib/Sabre/CalDAV/Plugin.php
index 905a799..e543473 100644
--- a/lib/Sabre/CalDAV/Plugin.php
+++ b/lib/Sabre/CalDAV/Plugin.php
@@ -584,7 +584,7 @@ class Plugin extends DAV\ServerPlugin {
         $xpath = new \DOMXPath($dom);
         $xpath->registerNameSpace('cal',Plugin::NS_CALDAV);
         $xpath->registerNameSpace('dav','urn:DAV');
-        $needsJson = $xpath->evaluate("boolean(/cal:calendar-multiget/dav:prop/cal:calendar-data[@content-type='application/calendar+json'])");
+        $needsJson = $xpath->evaluate("boolean(/cal:calendar-query/dav:prop/cal:calendar-data[@content-type='application/calendar+json'])");
 
         $node = $this->server->tree->getNodeForPath($this->server->getRequestUri());
         $depth = $this->server->getHTTPDepth(0);
diff --git a/tests/Sabre/CalDAV/JCalTransformTest.php b/tests/Sabre/CalDAV/JCalTransformTest.php
index d7a180e..dd69d83 100644
--- a/tests/Sabre/CalDAV/JCalTransformTest.php
+++ b/tests/Sabre/CalDAV/JCalTransformTest.php
@@ -12,7 +12,7 @@ class JCalTransformTest extends \Sabre\DAVServerTest {
             'id' => 1,
             'principaluri' => 'principals/user1',
             'uri' => 'foo',
-        ] 
+        ]
     ];
     protected $caldavCalendarObjects = [
         1 => [
@@ -20,10 +20,44 @@ class JCalTransformTest extends \Sabre\DAVServerTest {
                 '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
@@ -37,7 +71,7 @@ class JCalTransformTest extends \Sabre\DAVServerTest {
 XML;
 
         $headers = [];
-        $request = new Request('REPORT', '/calendars/foo', $headers, $xml);
+        $request = new Request('REPORT', '/calendars/user1/foo', $headers, $xml);
 
         $response = $this->request($request);
 
@@ -45,7 +79,64 @@ XML;
 
         $body = $response->getBodyAsString();
 
-        // Getting from the xml body to the actual returned data is 
+        // Getting from the xml body to the actual returned data is
+        // unfortunately very convoluted.
+        $responses = \Sabre\DAV\Property\ResponseList::unserialize(
+            \Sabre\DAV\XMLUtil::loadDOMDocument($body)->firstChild
+        , $this->server->propertyMap);
+
+        $responses = $responses->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 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());
+
+        $body = $response->getBodyAsString();
+
+        // Getting from the xml body to the actual returned data is
         // unfortunately very convoluted.
         $responses = \Sabre\DAV\Property\ResponseList::unserialize(
             \Sabre\DAV\XMLUtil::loadDOMDocument($body)->firstChild
@@ -55,7 +146,6 @@ XML;
         $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());
@@ -77,4 +167,87 @@ XML;
 
     }
 
+    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());
+
+        $body = $response->getBodyAsString();
+
+        // Getting from the xml body to the actual returned data is
+        // unfortunately very convoluted.
+        $responses = \Sabre\DAV\Property\ResponseList::unserialize(
+            \Sabre\DAV\XMLUtil::loadDOMDocument($body)->firstChild
+        , $this->server->propertyMap);
+
+        $responses = $responses->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);
+
+    }
+
 }

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/php-sabredav.git



More information about the Pkg-owncloud-commits mailing list