[Pkg-owncloud-commits] [php-sabre-vobject] 56/106: Freebusy-related tests work again. Lots of other tiny bugs.

David Prévot taffit at moszumanska.debian.org
Fri Aug 22 15:11:02 UTC 2014


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

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

commit df98ff1f21659cfb8a653d3334d45b57f1444144
Author: Evert Pot <evert at rooftopsolutions.nl>
Date:   Sun Aug 3 01:29:55 2014 -0400

    Freebusy-related tests work again. Lots of other tiny bugs.
---
 lib/Sabre/VObject/Component.php               | 46 +++++++++++++++++----------
 lib/Sabre/VObject/RecurrenceIterator.php      | 23 +++++++++++---
 tests/Sabre/VObject/FreeBusyGeneratorTest.php |  2 +-
 3 files changed, 50 insertions(+), 21 deletions(-)

diff --git a/lib/Sabre/VObject/Component.php b/lib/Sabre/VObject/Component.php
index 2e5c9cf..0276f10 100644
--- a/lib/Sabre/VObject/Component.php
+++ b/lib/Sabre/VObject/Component.php
@@ -53,24 +53,38 @@ class Component extends Node {
         $this->root = $root;
 
         if ($defaults) {
-            $defaultProps = $this->getDefaults();
-        }
-
-        foreach($children as $k=>$child) {
-            if ($child instanceof Node) {
+            // This is a terribly convoluted way to do this, but this ensures
+            // that the order of properties as they are specified in both
+            // defaults and the childrens list, are inserted in the object in a
+            // natural way.
+            $list = $this->getDefaults();
+            $nodes = array();
+            foreach($children as $key=>$value) {
+                if ($value instanceof Node) {
+                    if (isset($list[$value->name])) {
+                        unset($list[$value->name]);
+                    }
+                    $nodes[] = $value;
+                } else {
+                    $list[$key] = $value;
+                }
+            }
+            foreach($list as $key=>$value) {
+                $this->add($key, $value);
+            }
+            foreach($nodes as $node) {
+                $this->add($node);
+            }
+        } else {
+            foreach($children as $k=>$child) {
+                if ($child instanceof Node) {
 
-                // Component or Property
-                $this->add($child);
-            } else {
+                    // Component or Property
+                    $this->add($child);
+                } else {
 
-                // Property key=>value
-                $this->add($k, $child);
-            }
-        }
-        if ($defaults) {
-            foreach($this->getDefaults() as $key=>$value) {
-                if (!isset($this->$key)) {
-                    $this->add($key, $value);
+                    // Property key=>value
+                    $this->add($k, $child);
                 }
             }
         }
diff --git a/lib/Sabre/VObject/RecurrenceIterator.php b/lib/Sabre/VObject/RecurrenceIterator.php
index b5beb1a..34f16ae 100644
--- a/lib/Sabre/VObject/RecurrenceIterator.php
+++ b/lib/Sabre/VObject/RecurrenceIterator.php
@@ -102,7 +102,16 @@ class RecurrenceIterator implements \Iterator {
         }
 
         if (!$this->masterEvent) {
-            throw new InvalidArgumentException('This VCALENDAR did not have a master event with UID: ' . $uid);
+            // No base event was found. CalDAV does allow cases where only
+            // overridden instances are stored.
+            //
+            // In this barticular case, we're just going to grab the first
+            // event and use that instead. This may not always give the
+            // desired result.
+            if (!count($this->overriddenEvents)) {
+                throw new InvalidArgumentException('This VCALENDAR did not have an event with UID: ' . $uid);
+            }
+            $this->masterEvent = array_shift($this->overriddenEvents);
         }
 
         // master event.
@@ -136,11 +145,13 @@ class RecurrenceIterator implements \Iterator {
                 $this->startDate->getTimeStamp();
         } elseif (isset($this->masterEvent->DURATION)) {
             $duration = $this->masterEvent->DURATION->getDateInterval();
-            $this->eventDuration =
-                $this->startDate->add($duration)->getTimeStamp() -
-                $this->startDate->getTimeStamp();
+            $end = clone $this->startDate;
+            $end->add($duration);
+            $this->eventDuration = $end->getTimeStamp() - $this->startDate->getTimeStamp();
         } elseif ($this->masterEvent->DTSTART->getValueType() === 'DATE') {
             $this->eventDuration = 3600 * 24;
+        } else {
+            $this->eventDuration = 0;
         }
 
         $this->rruleParser = new RRuleParser($rrule, $this->startDate);
@@ -263,6 +274,7 @@ class RecurrenceIterator implements \Iterator {
             $index[$stamp] = $key;
         }
         ksort($index);
+        $this->counter = 0;
         $this->overriddenEventsIndex = $index;
         $this->currentOverriddenEvent = null;
         $this->nextDate = null;
@@ -294,6 +306,9 @@ class RecurrenceIterator implements \Iterator {
                 }
                 $this->rruleParser->next();
                 $nextDate = $this->rruleParser->current();
+                if (!$nextDate) {
+                    break;
+                }
             } while(isset($this->exceptions[$nextDate->getTimeStamp()]));
 
         }
diff --git a/tests/Sabre/VObject/FreeBusyGeneratorTest.php b/tests/Sabre/VObject/FreeBusyGeneratorTest.php
index 5a0c6a9..a1272f9 100644
--- a/tests/Sabre/VObject/FreeBusyGeneratorTest.php
+++ b/tests/Sabre/VObject/FreeBusyGeneratorTest.php
@@ -218,7 +218,7 @@ ICS;
 
         foreach($result->VFREEBUSY->FREEBUSY as $fb) {
 
-            $this->assertContains((string)$fb, $expected);
+            $this->assertContains((string)$fb, $expected, "$fb did not appear in our list of expected freebusy strings. This is concerning!");
 
             $k = array_search((string)$fb, $expected);
             unset($expected[$k]);

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



More information about the Pkg-owncloud-commits mailing list