[Pkg-owncloud-commits] [php-sabre-vobject] 330/341: New code is now unittested.

David Prévot taffit at moszumanska.debian.org
Tue Aug 11 13:36:02 UTC 2015


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 ecc71bd5b0dce4fb1b25cd11dcb7e0de5a84236a
Author: Evert Pot <me at evertpot.com>
Date:   Fri Jul 17 16:36:01 2015 -0400

    New code is now unittested.
---
 lib/Component/VAvailability.php               |   5 +-
 lib/FreeBusyGenerator.php                     |   4 +-
 tests/VObject/Component/AvailableTest.php     |  73 ++++++++++++++
 tests/VObject/Component/VAvailabilityTest.php | 102 +++++++++++++++++++
 tests/VObject/FreeBusyGeneratorTest.php       | 137 +++++++++++++++++++++++++-
 5 files changed, 316 insertions(+), 5 deletions(-)

diff --git a/lib/Component/VAvailability.php b/lib/Component/VAvailability.php
index 7e40b7c..92382e6 100644
--- a/lib/Component/VAvailability.php
+++ b/lib/Component/VAvailability.php
@@ -2,6 +2,7 @@
 
 namespace Sabre\VObject\Component;
 
+use DateTimeInterface;
 use Sabre\VObject;
 
 /**
@@ -34,8 +35,8 @@ class VAvailability extends VObject\Component {
 
         list($effectiveStart, $effectiveEnd) = $this->getEffectiveStartEnd();
         return (
-            (is_null($start) || $start < $effectiveEnd) &&
-            (is_null($end) || $end > $effectiveStart)
+            (is_null($effectiveStart) || $start < $effectiveEnd) &&
+            (is_null($effectiveEnd) || $end > $effectiveStart)
         );
 
     }
diff --git a/lib/FreeBusyGenerator.php b/lib/FreeBusyGenerator.php
index e3dc2ca..88b63eb 100644
--- a/lib/FreeBusyGenerator.php
+++ b/lib/FreeBusyGenerator.php
@@ -276,7 +276,7 @@ class FreeBusyGenerator {
             if (is_null($compStart) || $compStart < $this->start) {
                 $compStart = $this->start;
             }
-            if (is_null($compEnd) || $compEnd < $this->end) {
+            if (is_null($compEnd) || $compEnd > $this->end) {
                 $compEnd = $this->end;
             }
 
@@ -336,7 +336,7 @@ class FreeBusyGenerator {
             );
 
             // Looping over the AVAILABLE components.
-            foreach ($vavail->AVAILABLE as $available) {
+            if (isset($vavail->AVAILABLE)) foreach ($vavail->AVAILABLE as $available) {
 
                 list($availStart, $availEnd) = $available->getEffectiveStartEnd();
                 $fbData->add(
diff --git a/tests/VObject/Component/AvailableTest.php b/tests/VObject/Component/AvailableTest.php
new file mode 100644
index 0000000..a13f67a
--- /dev/null
+++ b/tests/VObject/Component/AvailableTest.php
@@ -0,0 +1,73 @@
+<?php
+
+namespace Sabre\VObject\Component;
+
+use DateTimeImmutable;
+use DateTimeZone;
+use Sabre\VObject\Reader;
+
+/**
+ * We use `RFCxxx` has a placeholder for the
+ * https://tools.ietf.org/html/draft-daboo-calendar-availability-05 name.
+ */
+class AvailableTest extends \PHPUnit_Framework_TestCase {
+
+    function testAvailableComponent() {
+
+        $vcal = <<<VCAL
+BEGIN:VCALENDAR
+BEGIN:AVAILABLE
+END:AVAILABLE
+END:VCALENDAR
+VCAL;
+        $document = Reader::read($vcal);
+        $this->assertInstanceOf(__NAMESPACE__ . '\Available', $document->AVAILABLE);
+
+    }
+
+    function testGetEffectiveStartEnd() {
+
+        $vcal = <<<VCAL
+BEGIN:VCALENDAR
+BEGIN:AVAILABLE
+DTSTART:20150717T162200Z
+DTEND:20150717T172200Z
+END:AVAILABLE
+END:VCALENDAR
+VCAL;
+
+        $document = Reader::read($vcal);
+        $tz = new DateTimeZone('UTC');
+        $this->assertEquals(
+            [
+                new DateTimeImmutable('2015-07-17 16:22:00', $tz),
+                new DateTimeImmutable('2015-07-17 17:22:00', $tz),
+            ],
+            $document->AVAILABLE->getEffectiveStartEnd()
+        );
+
+    }
+
+    function testGetEffectiveStartEndDuration() {
+
+        $vcal = <<<VCAL
+BEGIN:VCALENDAR
+BEGIN:AVAILABLE
+DTSTART:20150717T162200Z
+DURATION:PT1H
+END:AVAILABLE
+END:VCALENDAR
+VCAL;
+
+        $document = Reader::read($vcal);
+        $tz = new DateTimeZone('UTC');
+        $this->assertEquals(
+            [
+                new DateTimeImmutable('2015-07-17 16:22:00', $tz),
+                new DateTimeImmutable('2015-07-17 17:22:00', $tz),
+            ],
+            $document->AVAILABLE->getEffectiveStartEnd()
+        );
+
+    }
+}
diff --git a/tests/VObject/Component/VAvailabilityTest.php b/tests/VObject/Component/VAvailabilityTest.php
index 5ce1ec7..021100e 100644
--- a/tests/VObject/Component/VAvailabilityTest.php
+++ b/tests/VObject/Component/VAvailabilityTest.php
@@ -2,6 +2,8 @@
 
 namespace Sabre\VObject\Component;
 
+use DateTimeImmutable;
+use DateTimeZone;
 use Sabre\VObject;
 use Sabre\VObject\Reader;
 
@@ -25,6 +27,106 @@ VCAL;
 
     }
 
+    function testGetEffectiveStartEnd() {
+
+        $vcal = <<<VCAL
+BEGIN:VCALENDAR
+BEGIN:VAVAILABILITY
+DTSTART:20150717T162200Z
+DTEND:20150717T172200Z
+END:VAVAILABILITY
+END:VCALENDAR
+VCAL;
+
+        $document = Reader::read($vcal);
+        $tz = new DateTimeZone('UTC');
+        $this->assertEquals(
+            [
+                new DateTimeImmutable('2015-07-17 16:22:00', $tz),
+                new DateTimeImmutable('2015-07-17 17:22:00', $tz),
+            ],
+            $document->VAVAILABILITY->getEffectiveStartEnd()
+        );
+
+    }
+
+    function testGetEffectiveStartDuration() {
+
+        $vcal = <<<VCAL
+BEGIN:VCALENDAR
+BEGIN:VAVAILABILITY
+DTSTART:20150717T162200Z
+DURATION:PT1H
+END:VAVAILABILITY
+END:VCALENDAR
+VCAL;
+
+        $document = Reader::read($vcal);
+        $tz = new DateTimeZone('UTC');
+        $this->assertEquals(
+            [
+                new DateTimeImmutable('2015-07-17 16:22:00', $tz),
+                new DateTimeImmutable('2015-07-17 17:22:00', $tz),
+            ],
+            $document->VAVAILABILITY->getEffectiveStartEnd()
+        );
+
+    }
+
+    function testGetEffectiveStartEndUnbound() {
+
+        $vcal = <<<VCAL
+BEGIN:VCALENDAR
+BEGIN:VAVAILABILITY
+END:VAVAILABILITY
+END:VCALENDAR
+VCAL;
+
+        $document = Reader::read($vcal);
+        $this->assertEquals(
+            [
+                null,
+                null,
+            ],
+            $document->VAVAILABILITY->getEffectiveStartEnd()
+        );
+
+    }
+
+    function testIsInTimeRangeUnbound() {
+
+        $vcal = <<<VCAL
+BEGIN:VCALENDAR
+BEGIN:VAVAILABILITY
+END:VAVAILABILITY
+END:VCALENDAR
+VCAL;
+
+        $document = Reader::read($vcal);
+        $this->assertTrue(
+            $document->VAVAILABILITY->isInTimeRange(new DateTimeImmutable('2015-07-17'), new DateTimeImmutable('2015-07-18'))
+        );
+
+    }
+
+    function testIsInTimeRangeOutside() {
+
+        $vcal = <<<VCAL
+BEGIN:VCALENDAR
+BEGIN:VAVAILABILITY
+DTSTART:20140101T000000Z
+DTEND:20140102T000000Z
+END:VAVAILABILITY
+END:VCALENDAR
+VCAL;
+
+        $document = Reader::read($vcal);
+        $this->assertFalse(
+            $document->VAVAILABILITY->isInTimeRange(new DateTimeImmutable('2015-07-17'), new DateTimeImmutable('2015-07-18'))
+        );
+
+    }
+
     function testRFCxxxSection3_1_availabilityprop_required() {
 
         // UID and DTSTAMP are present.
diff --git a/tests/VObject/FreeBusyGeneratorTest.php b/tests/VObject/FreeBusyGeneratorTest.php
index ad43854..ba0729e 100644
--- a/tests/VObject/FreeBusyGeneratorTest.php
+++ b/tests/VObject/FreeBusyGeneratorTest.php
@@ -547,6 +547,44 @@ ICS;
     }
 
     /**
+     * This VAVAILABILITY object does not overlap at all with the freebusy
+     * report, so it should be ignored.
+     */
+    function testVAvailabilityIrrelevant() {
+
+        $blob = <<<ICS
+BEGIN:VCALENDAR
+BEGIN:VEVENT
+UID:lalala
+DTSTART:20110101T120000Z
+DTEND:20110101T130000Z
+END:VEVENT
+END:VCALENDAR
+ICS;
+
+        $vavail = <<<ICS
+BEGIN:VCALENDAR
+BEGIN:VAVAILABILITY
+DTSTART:20150101T000000Z
+DTEND:20160101T000000Z
+BEGIN:AVAILABLE
+DTSTART:20150101T000000Z
+DTEND:20150101T010000Z
+END:AVAILABLE
+END:VAVAILABILITY
+END:VCALENDAR
+ICS;
+
+        $this->assertFreeBusyReport(
+            "FREEBUSY:20110101T120000Z/20110101T130000Z",
+            $blob,
+            null,
+            $vavail
+        );
+
+    }
+
+    /**
      * This VAVAILABILITY object has a 9am-5pm AVAILABLE object for office
      * hours.
      */
@@ -565,7 +603,7 @@ ICS;
         $vavail = <<<ICS
 BEGIN:VCALENDAR
 BEGIN:VAVAILABILITY
-DTSTART:20110101T000000Z
+DTSTART:20100101T000000Z
 DTEND:20120101T000000Z
 BUSYTYPE:BUSY-TENTATIVE
 BEGIN:AVAILABLE
@@ -588,4 +626,101 @@ ICS;
 
     }
 
+    /**
+     * This test has the same office hours, but has a vacation blocked off for
+     * the relevant time, using a higher priority. (lower number).
+     */
+    function testVAvailabilityOfficeHoursVacation() {
+
+        $blob = <<<ICS
+BEGIN:VCALENDAR
+BEGIN:VEVENT
+UID:lalala
+DTSTART:20110101T120000Z
+DTEND:20110101T130000Z
+END:VEVENT
+END:VCALENDAR
+ICS;
+
+        $vavail = <<<ICS
+BEGIN:VCALENDAR
+BEGIN:VAVAILABILITY
+DTSTART:20100101T000000Z
+DTEND:20120101T000000Z
+BUSYTYPE:BUSY-TENTATIVE
+PRIORITY:2
+BEGIN:AVAILABLE
+DTSTART:20101213T090000Z
+DTEND:20101213T170000Z
+RRULE:FREQ=WEEKLY;BYDAY=MO,TU,WE,TH,FR
+END:AVAILABLE
+END:VAVAILABILITY
+BEGIN:VAVAILABILITY
+PRIORITY:1
+DTSTART:20101214T000000Z
+DTEND:20110107T000000Z
+BUSYTYPE:BUSY
+END:VAVAILABILITY
+END:VCALENDAR
+ICS;
+
+        $this->assertFreeBusyReport(
+            "FREEBUSY:20110101T110000Z/20110103T110000Z",
+            $blob,
+            null,
+            $vavail
+        );
+
+    }
+
+    /**
+     * This test has the same input as the last, except somebody mixed up the
+     * PRIORITY values.
+     *
+     * The end-result is that the vacation VAVAILABILITY is completely ignored.
+     */
+    function testVAvailabilityOfficeHoursVacation2() {
+
+        $blob = <<<ICS
+BEGIN:VCALENDAR
+BEGIN:VEVENT
+UID:lalala
+DTSTART:20110101T120000Z
+DTEND:20110101T130000Z
+END:VEVENT
+END:VCALENDAR
+ICS;
+
+        $vavail = <<<ICS
+BEGIN:VCALENDAR
+BEGIN:VAVAILABILITY
+DTSTART:20100101T000000Z
+DTEND:20120101T000000Z
+BUSYTYPE:BUSY-TENTATIVE
+PRIORITY:1
+BEGIN:AVAILABLE
+DTSTART:20101213T090000Z
+DTEND:20101213T170000Z
+RRULE:FREQ=WEEKLY;BYDAY=MO,TU,WE,TH,FR
+END:AVAILABLE
+END:VAVAILABILITY
+BEGIN:VAVAILABILITY
+PRIORITY:2
+DTSTART:20101214T000000Z
+DTEND:20110107T000000Z
+BUSYTYPE:BUSY
+END:VAVAILABILITY
+END:VCALENDAR
+ICS;
+
+        $this->assertFreeBusyReport(
+            "FREEBUSY;FBTYPE=BUSY-TENTATIVE:20110101T110000Z/20110101T120000Z\n" .
+            "FREEBUSY:20110101T120000Z/20110101T130000Z\n" .
+            "FREEBUSY;FBTYPE=BUSY-TENTATIVE:20110101T130000Z/20110103T090000Z\n",
+            $blob,
+            null,
+            $vavail
+        );
+
+    }
 }

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