[Pkg-owncloud-commits] [php-sabre-vobject] 60/106: The first event can now be overwritten.

David Prévot taffit at moszumanska.debian.org
Fri Aug 22 15:11:03 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 1aab7d402212f972957ebfd7390d746fb62c3da3
Author: Evert Pot <evert at rooftopsolutions.nl>
Date:   Wed Aug 6 17:47:35 2014 -0400

    The first event can now be overwritten.
    
    Fixes #18, #75, #58.
---
 lib/Sabre/VObject/RecurrenceIterator.php           |   8 +-
 tests/Sabre/VObject/Issue48Test.php                |   6 +-
 .../RecurrenceIterator/IncorrectExpandTest.php     |   1 +
 .../RecurrenceIterator/MissingOverriddenTest.php   |   1 +
 .../RecurrenceIterator/OverrideFirstEventTest.php  | 122 +++++++++++++++++++++
 5 files changed, 134 insertions(+), 4 deletions(-)

diff --git a/lib/Sabre/VObject/RecurrenceIterator.php b/lib/Sabre/VObject/RecurrenceIterator.php
index 98e5158..dc1f470 100644
--- a/lib/Sabre/VObject/RecurrenceIterator.php
+++ b/lib/Sabre/VObject/RecurrenceIterator.php
@@ -245,7 +245,8 @@ class RecurrenceIterator implements \Iterator {
      */
     public function key() {
 
-        return $this->counter;
+        // The counter is always 1 ahead.
+        return $this->counter - 1;
 
     }
 
@@ -277,9 +278,12 @@ class RecurrenceIterator implements \Iterator {
         $this->counter = 0;
         $this->overriddenEventsIndex = $index;
         $this->currentOverriddenEvent = null;
+
         $this->nextDate = null;
         $this->currentDate = clone $this->startDate;
 
+        $this->next();
+
     }
 
     /**
@@ -304,11 +308,11 @@ class RecurrenceIterator implements \Iterator {
                     $nextDate = null;
                     break;
                 }
-                $this->rruleParser->next();
                 $nextDate = $this->rruleParser->current();
                 if (!$nextDate) {
                     break;
                 }
+                $this->rruleParser->next();
             } while(isset($this->exceptions[$nextDate->getTimeStamp()]));
 
         }
diff --git a/tests/Sabre/VObject/Issue48Test.php b/tests/Sabre/VObject/Issue48Test.php
index 980d432..cf873f0 100644
--- a/tests/Sabre/VObject/Issue48Test.php
+++ b/tests/Sabre/VObject/Issue48Test.php
@@ -36,11 +36,13 @@ ICS;
 
         $tz = new DateTimeZone('Europe/Moscow');
 
-        $this->assertEquals(array(
+        $expected = [
             new DateTime('2013-07-10 11:00:00', $tz),
             new DateTime('2013-07-12 11:00:00', $tz),
             new DateTime('2013-07-13 11:00:00', $tz),
-        ), $result);
+        ];
+
+        $this->assertEquals($expected, $result);
 
     }
 
diff --git a/tests/Sabre/VObject/RecurrenceIterator/IncorrectExpandTest.php b/tests/Sabre/VObject/RecurrenceIterator/IncorrectExpandTest.php
index d6c93d0..1410bcc 100644
--- a/tests/Sabre/VObject/RecurrenceIterator/IncorrectExpandTest.php
+++ b/tests/Sabre/VObject/RecurrenceIterator/IncorrectExpandTest.php
@@ -45,6 +45,7 @@ BEGIN:VEVENT
 UID:foo
 DTSTART:20130711T050000Z
 DTEND:20130711T053000Z
+RECURRENCE-ID:20130711T050000Z
 END:VEVENT
 BEGIN:VEVENT
 UID:foo
diff --git a/tests/Sabre/VObject/RecurrenceIterator/MissingOverriddenTest.php b/tests/Sabre/VObject/RecurrenceIterator/MissingOverriddenTest.php
index 1de517b..59a44b2 100644
--- a/tests/Sabre/VObject/RecurrenceIterator/MissingOverriddenTest.php
+++ b/tests/Sabre/VObject/RecurrenceIterator/MissingOverriddenTest.php
@@ -45,6 +45,7 @@ UID:foo
 DTSTART:20130727T120000Z
 DURATION:PT1H
 SUMMARY:A
+RECURRENCE-ID:20130727T120000Z
 END:VEVENT
 BEGIN:VEVENT
 RECURRENCE-ID:20130728T120000Z
diff --git a/tests/Sabre/VObject/RecurrenceIterator/OverrideFirstEventTest.php b/tests/Sabre/VObject/RecurrenceIterator/OverrideFirstEventTest.php
new file mode 100644
index 0000000..5751493
--- /dev/null
+++ b/tests/Sabre/VObject/RecurrenceIterator/OverrideFirstEventTest.php
@@ -0,0 +1,122 @@
+<?php
+
+namespace Sabre\VObject\RecurrenceIterator;
+
+use Sabre\VObject\Reader;
+use DateTime;
+
+class OverrideFirstEventTest extends \PHPUnit_Framework_TestCase {
+
+    function testOverrideFirstEvent() {
+
+        $input =  <<<ICS
+BEGIN:VCALENDAR
+BEGIN:VEVENT
+UID:foobar
+DTSTART:20140803T120000Z
+RRULE:FREQ=WEEKLY
+SUMMARY:Original
+END:VEVENT
+BEGIN:VEVENT
+UID:foobar
+RECURRENCE-ID:20140803T120000Z
+DTSTART:20140803T120000Z
+SUMMARY:Overridden
+END:VEVENT
+END:VCALENDAR
+ICS;
+
+        $vcal = Reader::read($input);
+        $vcal->expand(new DateTime('2014-08-01'), new DateTime('2014-09-01'));
+
+        $expected = <<<ICS
+BEGIN:VCALENDAR
+BEGIN:VEVENT
+UID:foobar
+RECURRENCE-ID:20140803T120000Z
+DTSTART:20140803T120000Z
+SUMMARY:Overridden
+END:VEVENT
+BEGIN:VEVENT
+UID:foobar
+DTSTART:20140810T120000Z
+SUMMARY:Original
+RECURRENCE-ID:20140810T120000Z
+END:VEVENT
+BEGIN:VEVENT
+UID:foobar
+DTSTART:20140817T120000Z
+SUMMARY:Original
+RECURRENCE-ID:20140817T120000Z
+END:VEVENT
+BEGIN:VEVENT
+UID:foobar
+DTSTART:20140824T120000Z
+SUMMARY:Original
+RECURRENCE-ID:20140824T120000Z
+END:VEVENT
+BEGIN:VEVENT
+UID:foobar
+DTSTART:20140831T120000Z
+SUMMARY:Original
+RECURRENCE-ID:20140831T120000Z
+END:VEVENT
+END:VCALENDAR
+
+ICS;
+
+        $newIcs = $vcal->serialize();
+        $newIcs = str_replace("\r\n","\n", $newIcs);
+        $this->assertEquals(
+            $expected,
+            $newIcs
+        );
+
+
+    }
+
+    function testRemoveFirstEvent() {
+
+        $input =  <<<ICS
+BEGIN:VCALENDAR
+BEGIN:VEVENT
+UID:foobar
+DTSTART:20140803T120000Z
+RRULE:FREQ=WEEKLY
+EXDATE:20140803T120000Z
+SUMMARY:Original
+END:VEVENT
+END:VCALENDAR
+ICS;
+
+        $vcal = Reader::read($input);
+        $vcal->expand(new DateTime('2014-08-01'), new DateTime('2014-08-19'));
+
+        $expected = <<<ICS
+BEGIN:VCALENDAR
+BEGIN:VEVENT
+UID:foobar
+DTSTART:20140810T120000Z
+SUMMARY:Original
+RECURRENCE-ID:20140810T120000Z
+END:VEVENT
+BEGIN:VEVENT
+UID:foobar
+DTSTART:20140817T120000Z
+SUMMARY:Original
+RECURRENCE-ID:20140817T120000Z
+END:VEVENT
+END:VCALENDAR
+
+ICS;
+
+        $newIcs = $vcal->serialize();
+        $newIcs = str_replace("\r\n","\n", $newIcs);
+        $this->assertEquals(
+            $expected,
+            $newIcs
+        );
+
+
+    }
+}

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