[Pkg-owncloud-commits] [php-sabre-vobject] 24/30: Added some validation and repair rules to RRULE.

David Prévot taffit at moszumanska.debian.org
Sun Mar 13 00:53:04 UTC 2016


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 21c67b759df419124ade90bb5b267c04d739d5c0
Author: Evert Pot <me at evertpot.com>
Date:   Sat Mar 12 18:50:43 2016 -0500

    Added some validation and repair rules to RRULE.
    
    Updates #295.
---
 CHANGELOG.md                                   |   3 +-
 lib/Property/ICalendar/Recur.php               |  61 ++++++++++++++
 tests/VObject/Property/ICalendar/RecurTest.php | 110 ++++++++++++++++++++++++-
 3 files changed, 170 insertions(+), 4 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index 48da9b3..ec0cd3a 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -109,7 +109,8 @@ ChangeLog
   objects.
 * #244: The `Float` and `Integer` classes have been renamed to `FloatValue`
   and `IntegerValue` to allow PHP 7 compatibility.
-=======
+
+
 3.5.0 (2016-01-11)
 -----------------
 
diff --git a/lib/Property/ICalendar/Recur.php b/lib/Property/ICalendar/Recur.php
index b157d48..a3c36dc 100644
--- a/lib/Property/ICalendar/Recur.php
+++ b/lib/Property/ICalendar/Recur.php
@@ -229,4 +229,65 @@ class Recur extends Property {
         return $newValue;
     }
 
+    /**
+     * Validates the node for correctness.
+     *
+     * The following options are supported:
+     *   Node::REPAIR - May attempt to automatically repair the problem.
+     *
+     * This method returns an array with detected problems.
+     * Every element has the following properties:
+     *
+     *  * level - problem level.
+     *  * message - A human-readable string describing the issue.
+     *  * node - A reference to the problematic node.
+     *
+     * The level means:
+     *   1 - The issue was repaired (only happens if REPAIR was turned on)
+     *   2 - An inconsequential issue
+     *   3 - A severe issue.
+     *
+     * @param int $options
+     *
+     * @return array
+     */
+    function validate($options = 0) {
+
+        $repair = ($options & self::REPAIR);
+
+        $warnings = parent::validate($options);
+        $values = $this->getParts();
+
+        foreach ($values as $key => $value) {
+
+            if (empty($value)) {
+                $warnings[] = [
+                    'level'   => $repair ? 3 : 1,
+                    'message' => 'Invalid value for ' . $key . ' in ' . $this->name,
+                    'node'    => $this
+                ];
+                if ($repair) {
+                    unset($values[$key]);
+                }
+            }
+
+        }
+        if (!isset($values['FREQ'])) {
+            $warnings[] = [
+                'level'   => $repair ? 3 : 1,
+                'message' => 'FREQ is required in ' . $this->name,
+                'node'    => $this
+            ];
+            if ($repair) {
+                $this->parent->remove($this);
+            }
+        }
+        if ($repair) {
+            $this->setValue($values);
+        }
+
+        return $warnings;
+
+    }
+
 }
diff --git a/tests/VObject/Property/ICalendar/RecurTest.php b/tests/VObject/Property/ICalendar/RecurTest.php
index 0c59d46..d34214b 100644
--- a/tests/VObject/Property/ICalendar/RecurTest.php
+++ b/tests/VObject/Property/ICalendar/RecurTest.php
@@ -4,8 +4,9 @@ namespace Sabre\VObject\Property\ICalendar;
 
 use Sabre\VObject\Component\VCalendar;
 use Sabre\VObject\Reader;
+use Sabre\VObject\TestCase;
 
-class RecurTest extends \PHPUnit_Framework_TestCase {
+class RecurTest extends TestCase {
 
     function testParts() {
 
@@ -48,7 +49,7 @@ DTSTART;TZID=Europe/Berlin:20160301T150000
 DTEND;TZID=Europe/Berlin:20160301T170000
 SUMMARY:test
 RRULE:FREQ=DAILY;COUNT=3
-ORGANIZER;CN=robert pipo:mailto:robert at pipo.com
+ORGANIZER;CN=robert pipo:mailto:robert at example.org
 END:VEVENT
 END:VCALENDAR
 ';
@@ -82,7 +83,7 @@ DTSTART;TZID=Europe/Berlin:20160301T150000
 DTEND;TZID=Europe/Berlin:20160301T170000
 SUMMARY:test
 RRULE:FREQ=DAILY;UNTIL=20160305T230000Z
-ORGANIZER;CN=robert pipo:mailto:robert at pipo.com
+ORGANIZER;CN=robert pipo:mailto:robert at example.org
 END:VEVENT
 END:VCALENDAR
 ';
@@ -92,4 +93,107 @@ END:VCALENDAR
         $untilJsonString = $rrule->getJsonValue()[0]['until'];
         $this->assertEquals('2016-03-05T23:00:00Z', $untilJsonString);
     }
+
+
+    function testValidateStripEmpties() {
+
+        $input = 'BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:foobar
+BEGIN:VEVENT
+UID:908d53c0-e1a3-4883-b69f-530954d6bd62
+TRANSP:OPAQUE
+DTSTART;TZID=Europe/Berlin:20160301T150000
+DTEND;TZID=Europe/Berlin:20160301T170000
+SUMMARY:test
+RRULE:FREQ=DAILY;BYMONTH=;UNTIL=20160305T230000Z
+ORGANIZER;CN=robert pipo:mailto:robert at example.org
+DTSTAMP:20160312T183800Z
+END:VEVENT
+END:VCALENDAR
+';
+
+        $vcal = Reader::read($input);
+        $this->assertEquals(
+            1,
+            count($vcal->validate())
+        );
+        $this->assertEquals(
+            1,
+            count($vcal->validate($vcal::REPAIR))
+        );
+
+        $expected = 'BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:foobar
+BEGIN:VEVENT
+UID:908d53c0-e1a3-4883-b69f-530954d6bd62
+TRANSP:OPAQUE
+DTSTART;TZID=Europe/Berlin:20160301T150000
+DTEND;TZID=Europe/Berlin:20160301T170000
+SUMMARY:test
+RRULE:FREQ=DAILY;UNTIL=20160305T230000Z
+ORGANIZER;CN=robert pipo:mailto:robert at example.org
+DTSTAMP:20160312T183800Z
+END:VEVENT
+END:VCALENDAR
+';
+
+        $this->assertVObjEquals(
+            $expected,
+            $vcal
+        );
+
+    }
+
+    function testValidateStripNoFreq() {
+
+        $input = 'BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:foobar
+BEGIN:VEVENT
+UID:908d53c0-e1a3-4883-b69f-530954d6bd62
+TRANSP:OPAQUE
+DTSTART;TZID=Europe/Berlin:20160301T150000
+DTEND;TZID=Europe/Berlin:20160301T170000
+SUMMARY:test
+RRULE:UNTIL=20160305T230000Z
+ORGANIZER;CN=robert pipo:mailto:robert at example.org
+DTSTAMP:20160312T183800Z
+END:VEVENT
+END:VCALENDAR
+';
+
+        $vcal = Reader::read($input);
+        $this->assertEquals(
+            1,
+            count($vcal->validate())
+        );
+        $this->assertEquals(
+            1,
+            count($vcal->validate($vcal::REPAIR))
+        );
+
+        $expected = 'BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:foobar
+BEGIN:VEVENT
+UID:908d53c0-e1a3-4883-b69f-530954d6bd62
+TRANSP:OPAQUE
+DTSTART;TZID=Europe/Berlin:20160301T150000
+DTEND;TZID=Europe/Berlin:20160301T170000
+SUMMARY:test
+ORGANIZER;CN=robert pipo:mailto:robert at example.org
+DTSTAMP:20160312T183800Z
+END:VEVENT
+END:VCALENDAR
+';
+
+        $this->assertVObjEquals(
+            $expected,
+            $vcal
+        );
+
+    }
+
 }

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



More information about the Pkg-owncloud-commits mailing list