[Pkg-owncloud-commits] [php-sabre-vobject] 48/128: Also testing iCalendar DATE and DATE-TIME.

David Prévot taffit at moszumanska.debian.org
Tue May 20 23:11:01 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 880cea7d65cb1048fd6969c40d8d37b6df76294c
Author: Evert Pot <evert at rooftopsolutions.nl>
Date:   Wed Jan 22 20:41:02 2014 -0500

    Also testing iCalendar DATE and DATE-TIME.
    
    Issue #74.
---
 lib/Sabre/VObject/Property/ICalendar/DateTime.php  | 46 ++++++++++++++++++++++
 .../VObject/Property/ICalendar/DateTimeTest.php    |  8 ++++
 2 files changed, 54 insertions(+)

diff --git a/lib/Sabre/VObject/Property/ICalendar/DateTime.php b/lib/Sabre/VObject/Property/ICalendar/DateTime.php
index 872962a..921039a 100644
--- a/lib/Sabre/VObject/Property/ICalendar/DateTime.php
+++ b/lib/Sabre/VObject/Property/ICalendar/DateTime.php
@@ -305,4 +305,50 @@ class DateTime extends Property {
         $this->setDateTimes($this->getDateTimes());
 
     }
+
+    /**
+     * 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
+     */
+    public function validate($options = 0) {
+
+        $messages = parent::validate($options);
+        $valueType = $this->getValueType();
+        $value = $this->getValue();
+        try {
+            switch($valueType) {
+                case 'DATE' :
+                    $foo = DateTimeParser::parseDate($value);
+                    break;
+                case 'DATE-TIME' :
+                    $foo = DateTimeParser::parseDateTime($value);
+                    break;
+            }
+        } catch (\LogicException $e) {
+            $messages[] = array(
+                'level' => 3,
+                'message' => 'The supplied value (' . $value . ') is not a correct ' . $valueType,
+                'node' => $this,
+            );
+        }
+        return $messages;
+
+    }
 }
diff --git a/tests/Sabre/VObject/Property/ICalendar/DateTimeTest.php b/tests/Sabre/VObject/Property/ICalendar/DateTimeTest.php
index 62d4533..ec05d05 100644
--- a/tests/Sabre/VObject/Property/ICalendar/DateTimeTest.php
+++ b/tests/Sabre/VObject/Property/ICalendar/DateTimeTest.php
@@ -304,5 +304,13 @@ class DateTimeTest extends \PHPUnit_Framework_TestCase {
 
     }
 
+    function testValidate() {
+
+        $exDate = $this->vcal->createProperty('EXDATE', '-00011130T143000Z');
+        $messages = $exDate->validate();
+        $this->assertEquals(1, count($messages));
+        $this->assertEquals(3, $messages[0]['level']);
+
+    }
 
 }

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