[Pkg-owncloud-commits] [php-sabredav] 01/75: add calendars timezone information on expand in ICSExportPlugin

David Prévot taffit at moszumanska.debian.org
Thu Feb 26 18:51:46 UTC 2015


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

taffit pushed a commit to branch master
in repository php-sabredav.

commit a02d3ba126459fcd9b2ea55d965be1b663df868f
Author: Armin Hackmann <armin at fruux.com>
Date:   Wed Jan 14 15:19:03 2015 +0100

    add calendars timezone information on expand in ICSExportPlugin
---
 lib/CalDAV/ICSExportPlugin.php                     | 19 +++++++++-
 .../Sabre/CalDAV/ExpandEventsFloatingTimeTest.php  | 40 ++++++++++++++++++++++
 tests/Sabre/DAVServerTest.php                      |  5 +++
 3 files changed, 63 insertions(+), 1 deletion(-)

diff --git a/lib/CalDAV/ICSExportPlugin.php b/lib/CalDAV/ICSExportPlugin.php
index 7696315..6f5953d 100644
--- a/lib/CalDAV/ICSExportPlugin.php
+++ b/lib/CalDAV/ICSExportPlugin.php
@@ -3,6 +3,7 @@
 namespace Sabre\CalDAV;
 
 use
+    DateTimeZone,
     Sabre\DAV,
     Sabre\VObject,
     Sabre\HTTP\RequestInterface,
@@ -211,7 +212,23 @@ class ICSExportPlugin extends DAV\ServerPlugin {
         );
 
         if ($expand) {
-            $mergedCalendar->expand($start, $end);
+            $calendarTimeZone = null;
+            // We're expanding, and for that we need to figure out the
+            // calendar's timezone.
+            $tzProp = '{' . Plugin::NS_CALDAV . '}calendar-timezone';
+            $tzResult = $this->server->getProperties($path, [$tzProp]);
+            if (isset($tzResult[$tzProp])) {
+                // This property contains a VCALENDAR with a single
+                // VTIMEZONE.
+                $vtimezoneObj = VObject\Reader::read($tzResult[$tzProp]);
+                $calendarTimeZone = $vtimezoneObj->VTIMEZONE->getTimeZone();
+                unset($vtimezoneObj);
+            } else {
+                // Defaulting to UTC.
+                $calendarTimeZone = new DateTimeZone('UTC');
+            }
+
+            $mergedCalendar->expand($start, $end, $calendarTimeZone);
         }
 
         $response->setHeader('Content-Type', $format);
diff --git a/tests/Sabre/CalDAV/ExpandEventsFloatingTimeTest.php b/tests/Sabre/CalDAV/ExpandEventsFloatingTimeTest.php
index b58f194..906f2ef 100644
--- a/tests/Sabre/CalDAV/ExpandEventsFloatingTimeTest.php
+++ b/tests/Sabre/CalDAV/ExpandEventsFloatingTimeTest.php
@@ -12,6 +12,8 @@ class ExpandEventsFloatingTimeTest extends \Sabre\DAVServerTest {
 
     protected $setupCalDAV = true;
 
+    protected $setupCalDAVICSExport = true;
+
     protected $caldavCalendars = array(
         array(
             'id' => 1,
@@ -166,5 +168,43 @@ END:VCALENDAR
         }
     }
 
+    function testExpandExport() {
+
+        $request = new HTTP\Request('GET', '/calendars/user1/calendar1?export&start=1&end=2000000000&expand=1', [
+            'Depth' => 1,
+            'Content-Type' => 'application/xml',
+        ]);
+
+        $response = $this->request($request);
+
+        $this->assertEquals(200, $response->getStatus());
+
+        // Everts super awesome xml parser.
+        $body = substr(
+            $response->body,
+            $start = strpos($response->body, 'BEGIN:VCALENDAR'),
+            strpos($response->body, 'END:VCALENDAR') - $start + 13
+        );
+        $body = str_replace('
','',$body);
+
+        $vObject = VObject\Reader::read($body);
+
+        // check if DTSTARTs and DTENDs are correct
+        foreach ($vObject->VEVENT as $vevent) {
+            /** @var $vevent Sabre\VObject\Component\VEvent */
+            foreach ($vevent->children as $child) {
+                /** @var $child Sabre\VObject\Property */
+
+                if ($child->name == 'DTSTART') {
+                    // DTSTART should be the UTC equivalent of given floating time
+                    $this->assertEquals($child->getValue(), '20141108T043000Z');
+                } elseif ($child->name == 'DTEND') {
+                    // DTEND should be the UTC equivalent of given floating time
+                    $this->assertEquals($child->getValue(), '20141108T063000Z');
+                }
+            }
+        }
+    }
+
 }
 
diff --git a/tests/Sabre/DAVServerTest.php b/tests/Sabre/DAVServerTest.php
index 982082a..6237210 100644
--- a/tests/Sabre/DAVServerTest.php
+++ b/tests/Sabre/DAVServerTest.php
@@ -25,6 +25,7 @@ abstract class DAVServerTest extends \PHPUnit_Framework_TestCase {
     protected $setupCalDAVSharing = false;
     protected $setupCalDAVScheduling = false;
     protected $setupCalDAVSubscriptions = false;
+    protected $setupCalDAVICSExport = false;
     protected $setupLocks = false;
     protected $setupFiles = false;
 
@@ -117,6 +118,10 @@ abstract class DAVServerTest extends \PHPUnit_Framework_TestCase {
         if ($this->setupCalDAVSubscriptions) {
             $this->server->addPlugin(new CalDAV\Subscriptions\Plugin());
         }
+        if ($this->setupCalDAVICSExport) {
+            $this->caldavICSExportPlugin = new CalDAV\ICSExportPlugin();
+            $this->server->addPlugin($this->caldavICSExportPlugin);
+        }
         if ($this->setupCardDAV) {
             $this->carddavPlugin = new CardDAV\Plugin();
             $this->server->addPlugin($this->carddavPlugin);

-- 
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