[Pkg-owncloud-commits] [php-sabre-vobject] 43/128: Added a TON of new validation rules.

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 24aea5304f7fcbb17fc05217ad367af3933ca398
Author: Evert Pot <evert at rooftopsolutions.nl>
Date:   Wed Jan 22 19:56:30 2014 -0500

    Added a TON of new validation rules.
---
 lib/Sabre/VObject/Component.php                 | 113 +++++++++++++++++++++--
 lib/Sabre/VObject/Component/VAlarm.php          |  28 ++++++
 lib/Sabre/VObject/Component/VCalendar.php       |  69 +++++++-------
 lib/Sabre/VObject/Component/VCard.php           | 117 +++++++++++++++++++-----
 lib/Sabre/VObject/Component/VEvent.php          |  52 +++++++++++
 lib/Sabre/VObject/Component/VFreeBusy.php       |  34 +++++++
 lib/Sabre/VObject/Component/VJournal.php        |  46 +++++++++-
 lib/Sabre/VObject/Component/VTimeZone.php       |  53 +++++++++++
 lib/Sabre/VObject/Component/VTodo.php           |  55 +++++++++++
 lib/Sabre/VObject/Node.php                      |  18 ++--
 lib/Sabre/VObject/Splitter/ICalendar.php        |   8 +-
 tests/Sabre/VObject/CliTest.php                 |   8 +-
 tests/Sabre/VObject/Component/VCalendarTest.php |  12 +++
 tests/Sabre/VObject/Component/VCardTest.php     |  30 +++---
 tests/Sabre/VObject/Property/TextTest.php       |   1 +
 tests/Sabre/VObject/Splitter/ICalendarTest.php  |  25 ++++-
 16 files changed, 563 insertions(+), 106 deletions(-)

diff --git a/lib/Sabre/VObject/Component.php b/lib/Sabre/VObject/Component.php
index 72428cb..5ca1f17 100644
--- a/lib/Sabre/VObject/Component.php
+++ b/lib/Sabre/VObject/Component.php
@@ -444,29 +444,122 @@ class Component extends Node {
     }
 
     /**
+     * A simple list of validation rules.
+     *
+     * This is simply a list of properties, and how many times they either
+     * must or must not appear.
+     *
+     * Possible values per property:
+     *   * 0 - Must not appear.
+     *   * 1 - Must appear exactly once.
+     *   * + - Must appear at least once.
+     *   * * - Can appear any number of times.
+     *   * ? - May appear, but not more than once.
+     *
+     * It is also possible to specify defaults and severity levels for
+     * violating the rule.
+     *
+     * See the VEVENT implementation for getValidationRules for a more complex
+     * example.
+     *
+     * @var array
+     */
+    public function getValidationRules() {
+
+        return array();
+
+    }
+
+    /**
      * Validates the node for correctness.
      *
      * The following options are supported:
-     *   - Node::REPAIR - If something is broken, an automatic repair may
-     *                    be attempted.
+     *   Node::REPAIR - May attempt to automatically repair the problem.
+     *
+     * This method returns an array with detected problems.
+     * Every element has the following properties:
      *
-     * An array is returned with warnings.
+     *  * level - problem level.
+     *  * message - A human-readable string describing the issue.
+     *  * node - A reference to the problematic node.
      *
-     * Every item in the array has the following properties:
-     *    * level - (number between 1 and 3 with severity information)
-     *    * message - (human readable message)
-     *    * node - (reference to the offending 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) {
 
-        $result = array();
+        $rules = $this->getValidationRules();
+        $defaults = $this->getDefaults();
+
+        $propertyCounters = array();
+
+        $messages = array();
+
         foreach($this->children as $child) {
-            $result = array_merge($result, $child->validate($options));
+            $name = strtoupper($child->name);
+            if (!isset($propertyCounters[$name])) {
+                $propertyCounters[$name] = 1;
+            } else {
+                $propertyCounters[$name]++;
+            }
+            $messages = array_merge($messages, $child->validate($options));
         }
-        return $result;
+
+        foreach($rules as $propName => $rule) {
+
+            switch($rule) {
+                case '0' :
+                    if (isset($propertyCounters[$propName])) {
+                        $messages[] = array(
+                            'level' => 3,
+                            'message' => $propName . ' MUST NOT appear in a ' . $this->name . ' component',
+                            'node' => $this,
+                        );
+                    }
+                    break;
+                case '1' :
+                    if (!isset($propertyCounters[$propName]) || $propertyCounters[$propName]!==1) {
+                        $repaired = false;
+                        if ($options & self::REPAIR && isset($defaults[$propName])) {
+                            $this->add($propName, $defaults[$propName]);
+                        }
+                        $messages[] = array(
+                            'level' => $repaired?1:3,
+                            'message' => $propName . ' MUST appear exactly once in a ' . $this->name . ' component',
+                            'node' => $this,
+                        );
+                    }
+                    break;
+                case '+' :
+                    if (!isset($propertyCounters[$propName]) || $propertyCounters[$propName] < 1) {
+                        $messages[] = array(
+                            'level' => 3,
+                            'message' => $propName . ' MUST appear at least once in a ' . $this->name . ' component',
+                            'node' => $this,
+                        );
+                    }
+                    break;
+                case '*' :
+                    break;
+                case '?' :
+                    if (isset($propertyCounters[$propName]) && $propertyCounters[$propName] > 1) {
+                        $messages[] = array(
+                            'level' => 3,
+                            'message' => $propName . ' MUST NOT appear more than once in a ' . $this->name . ' component',
+                            'node' => $this,
+                        );
+                    }
+                    break;
+
+            }
+
+        }
+        return $messages;
 
     }
 
diff --git a/lib/Sabre/VObject/Component/VAlarm.php b/lib/Sabre/VObject/Component/VAlarm.php
index 2f86c44..3f9be91 100644
--- a/lib/Sabre/VObject/Component/VAlarm.php
+++ b/lib/Sabre/VObject/Component/VAlarm.php
@@ -105,4 +105,32 @@ class VAlarm extends VObject\Component {
 
     }
 
+    /**
+     * A simple list of validation rules.
+     *
+     * This is simply a list of properties, and how many times they either
+     * must or must not appear.
+     *
+     * Possible values per property:
+     *   * 0 - Must not appear.
+     *   * 1 - Must appear exactly once.
+     *   * + - Must appear at least once.
+     *   * * - Can appear any number of times.
+     *
+     * @var array
+     */
+    public function getValidationRules() {
+
+        return array(
+            'ACTION' => 1,
+            'TRIGGER' => 1,
+
+            'DURATION' => '?',
+            'REPEAT' => '?',
+
+            'ATTACH' => '?',
+        );
+
+    }
+
 }
diff --git a/lib/Sabre/VObject/Component/VCalendar.php b/lib/Sabre/VObject/Component/VCalendar.php
index 6ae2068..1a6f618 100644
--- a/lib/Sabre/VObject/Component/VCalendar.php
+++ b/lib/Sabre/VObject/Component/VCalendar.php
@@ -290,6 +290,32 @@ class VCalendar extends VObject\Document {
     }
 
     /**
+     * A simple list of validation rules.
+     *
+     * This is simply a list of properties, and how many times they either
+     * must or must not appear.
+     *
+     * Possible values per property:
+     *   * 0 - Must not appear.
+     *   * 1 - Must appear exactly once.
+     *   * + - Must appear at least once.
+     *   * * - Can appear any number of times.
+     *
+     * @var array
+     */
+    public function getValidationRules() {
+
+        return array(
+            'PRODID' => 1,
+            'VERSION' => 1,
+
+            'CALSCALE' => '?',
+            'METHOD' => '?',
+        );
+
+    }
+
+    /**
      * Validates the node for correctness.
      * An array is returned with warnings.
      *
@@ -302,45 +328,17 @@ class VCalendar extends VObject\Document {
      */
     public function validate($options = 0) {
 
-        $warnings = array();
+        $warnings = parent::validate();
 
-        $version = $this->select('VERSION');
-        if (count($version)!==1) {
-            $warnings[] = array(
-                'level' => 1,
-                'message' => 'The VERSION property must appear in the VCALENDAR component exactly 1 time',
-                'node' => $this,
-            );
-        } else {
-            if ((string)$this->VERSION !== '2.0') {
+        if ($ver = $this->VERSION) {
+            if ((string)$ver !== '2.0') {
                 $warnings[] = array(
-                    'level' => 1,
+                    'level' => 3,
                     'message' => 'Only iCalendar version 2.0 as defined in rfc5545 is supported.',
                     'node' => $this,
                 );
             }
-        }
-        $version = $this->select('PRODID');
-        if (count($version)!==1) {
-            $warnings[] = array(
-                'level' => 2,
-                'message' => 'The PRODID property must appear in the VCALENDAR component exactly 1 time',
-                'node' => $this,
-            );
-        }
-        if (count($this->CALSCALE) > 1) {
-            $warnings[] = array(
-                'level' => 2,
-                'message' => 'The CALSCALE property must not be specified more than once.',
-                'node' => $this,
-            );
-        }
-        if (count($this->METHOD) > 1) {
-            $warnings[] = array(
-                'level' => 2,
-                'message' => 'The METHOD property must not be specified more than once.',
-                'node' => $this,
-            );
+
         }
 
         $componentsFound = 0;
@@ -358,10 +356,7 @@ class VCalendar extends VObject\Document {
             );
         }
 
-        return array_merge(
-            $warnings,
-            parent::validate()
-        );
+        return $warnings;
 
     }
 
diff --git a/lib/Sabre/VObject/Component/VCard.php b/lib/Sabre/VObject/Component/VCard.php
index 69eb8d4..186b6f1 100644
--- a/lib/Sabre/VObject/Component/VCard.php
+++ b/lib/Sabre/VObject/Component/VCard.php
@@ -172,21 +172,23 @@ class VCard extends VObject\Document {
      */
     const DEFAULT_VERSION = self::VCARD21;
 
-
-
     /**
      * Validates the node for correctness.
      *
      * The following options are supported:
-     *   - Node::REPAIR - If something is broken, and automatic repair may
-     *                    be attempted.
+     *   Node::REPAIR - May attempt to automatically repair the problem.
      *
-     * An array is returned with warnings.
+     * This method returns an array with detected problems.
+     * Every element has the following properties:
      *
-     * Every item in the array has the following properties:
-     *    * level - (number between 1 and 3 with severity information)
-     *    * message - (human readable message)
-     *    * node - (reference to the offending node)
+     *  * 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
@@ -202,20 +204,11 @@ class VCard extends VObject\Document {
         );
 
         $version = $this->select('VERSION');
-        if (count($version)!==1) {
-            $warnings[] = array(
-                'level' => 1,
-                'message' => 'The VERSION property must appear in the VCARD component exactly 1 time',
-                'node' => $this,
-            );
-            if ($options & self::REPAIR) {
-                $this->VERSION = $versionMap[self::DEFAULT_VERSION];
-            }
-        } else {
+        if (count($version)===1) {
             $version = (string)$this->VERSION;
             if ($version!=='2.1' && $version!=='3.0' && $version!=='4.0') {
                 $warnings[] = array(
-                    'level' => 1,
+                    'level' => 3,
                     'message' => 'Only vcard version 4.0 (RFC6350), version 3.0 (RFC2426) or version 2.1 (icm-vcard-2.1) are supported.',
                     'node' => $this,
                 );
@@ -227,11 +220,8 @@ class VCard extends VObject\Document {
         }
         $fn = $this->select('FN');
         if (count($fn)!==1) {
-            $warnings[] = array(
-                'level' => 1,
-                'message' => 'The FN property must appear in the VCARD component exactly 1 time',
-                'node' => $this,
-            );
+
+            $repaired = false;
             if (($options & self::REPAIR) && count($fn) === 0) {
                 // We're going to try to see if we can use the contents of the
                 // N property.
@@ -242,13 +232,20 @@ class VCard extends VObject\Document {
                     } else {
                         $this->FN = $value[0];
                     }
+                    $repaired = true;
 
                 // Otherwise, the ORG property may work
                 } elseif (isset($this->ORG)) {
                     $this->FN = (string)$this->ORG;
+                    $repaired = true;
                 }
 
             }
+            $warnings[] = array(
+                'level' => $repaired?1:3,
+                'message' => 'The FN property must appear in the VCARD component exactly 1 time',
+                'node' => $this,
+            );
         }
 
         return array_merge(
@@ -259,6 +256,76 @@ class VCard extends VObject\Document {
     }
 
     /**
+     * A simple list of validation rules.
+     *
+     * This is simply a list of properties, and how many times they either
+     * must or must not appear.
+     *
+     * Possible values per property:
+     *   * 0 - Must not appear.
+     *   * 1 - Must appear exactly once.
+     *   * + - Must appear at least once.
+     *   * * - Can appear any number of times.
+     *
+     * @var array
+     */
+    public function getValidationRules() {
+
+        return array(
+            'ADR'          => '*',
+            'ANNIVERSARY'  => '?',
+            'BDAY'         => '?',
+            'CALADRURI'    => '*',
+            'CALURI'       => '*',
+            'CATEGORIES'   => '*',
+            'CLIENTPIDMAP' => '*',
+            'EMAIL'        => '*',
+            'FBURL'        => '*',
+            'IMPP'         => '*',
+            'GENDER'       => '?',
+            'GEO'          => '*',
+            'KEY'          => '*',
+            'KIND'         => '?',
+            'LANG'         => '*',
+            'LOGO'         => '*',
+            'MEMBER'       => '*',
+            'N'            => '?',
+            'NICKNAME'     => '*',
+            'NOTE'         => '*',
+            'ORG'          => '*',
+            'PHOTO'        => '*',
+            'PRODID'       => '?',
+            'RELATED'      => '*',
+            'REV'          => '?',
+            'ROLE'         => '*',
+            'SOUND'        => '*',
+            'SOURCE'       => '*',
+            'TEL'          => '*',
+            'TITLE'        => '*',
+            'TZ'           => '*',
+            'URL'          => '*',
+            'VERSION'      => '1',
+            'XML'          => '*',
+
+            // FN is commented out, because it's already handled by the
+            // validate function, which may also try to repair it.
+            // 'FN'           => '+',
+
+            // vcard actually specifies this as '?', but in most cases not
+            // having a UID is highly undesirable. So here we're going against
+            // the spec and make it required.
+            //
+            // I would be interested to hear if this is problematic for
+            // anyone, or at least a usecase where this is undesirable.
+            //
+            // If so, I may have to add a facility that allows us to check
+            // specifically for validity in the context of 'DAV'.
+            'UID'          => '1',
+        );
+
+    }
+
+    /**
      * Returns a preferred field.
      *
      * VCards can indicate wether a field such as ADR, TEL or EMAIL is
diff --git a/lib/Sabre/VObject/Component/VEvent.php b/lib/Sabre/VObject/Component/VEvent.php
index 0ce2045..695f2ce 100644
--- a/lib/Sabre/VObject/Component/VEvent.php
+++ b/lib/Sabre/VObject/Component/VEvent.php
@@ -67,4 +67,56 @@ class VEvent extends VObject\Component {
 
     }
 
+    /**
+     * A simple list of validation rules.
+     *
+     * This is simply a list of properties, and how many times they either
+     * must or must not appear.
+     *
+     * Possible values per property:
+     *   * 0 - Must not appear.
+     *   * 1 - Must appear exactly once.
+     *   * + - Must appear at least once.
+     *   * * - Can appear any number of times.
+     *
+     * @var array
+     */
+    public function getValidationRules() {
+
+        return array(
+            'UID' => 1,
+            'DTSTAMP' => 1,
+            'DTSTART' => '?',
+            'CLASS' => '?',
+            'CREATED' => '?',
+            'DESCRIPTION' => '?',
+            'GEO' => '?',
+            'LAST-MODIFICATION' => '?',
+            'LOCATION' => '?',
+            'ORGANIZER' => '?',
+            'PRIORITY' => '?',
+            'SEQUENCE' => '?',
+            'STATUS' => '?',
+            'SUMMARY' => '?',
+            'TRANSP' => '?',
+            'URL' => '?',
+            'RECURRENCE-ID' => '?',
+            'RRULE' => '?',
+            'DTEND' => '?',
+            'DURATION' => '?',
+
+            'ATTACH' => '*',
+            'ATTENDEE' => '*',
+            'CATEGORIES' => '*',
+            'COMMENT' => '*',
+            'CONTACT' => '*',
+            'EXDATE' => '*',
+            'REQUEST-STATUS' => '*',
+            'RELATED' => '*',
+            'RESOURCES' => '*',
+            'RDATE' => '*',
+        );
+
+    }
+
 }
diff --git a/lib/Sabre/VObject/Component/VFreeBusy.php b/lib/Sabre/VObject/Component/VFreeBusy.php
index 7afe9fd..8eb2a0c 100644
--- a/lib/Sabre/VObject/Component/VFreeBusy.php
+++ b/lib/Sabre/VObject/Component/VFreeBusy.php
@@ -64,5 +64,39 @@ class VFreeBusy extends VObject\Component {
 
     }
 
+    /**
+     * A simple list of validation rules.
+     *
+     * This is simply a list of properties, and how many times they either
+     * must or must not appear.
+     *
+     * Possible values per property:
+     *   * 0 - Must not appear.
+     *   * 1 - Must appear exactly once.
+     *   * + - Must appear at least once.
+     *   * * - Can appear any number of times.
+     *
+     * @var array
+     */
+    public function getValidationRules() {
+
+        return array(
+            'UID' => 1,
+            'DTSTAMP' => 1,
+
+            'CONTACT' => '?',
+            'DTSTART' => '?',
+            'DTEND' => '?',
+            'ORGANIZER' => '?',
+            'URL' => '?',
+
+            'ATTENDEE' => '*',
+            'COMMENT' => '*',
+            'FREEBUSY' => '*',
+            'REQUEST-STATUS' => '*',
+        );
+
+    }
+
 }
 
diff --git a/lib/Sabre/VObject/Component/VJournal.php b/lib/Sabre/VObject/Component/VJournal.php
index 0e561a1..5e9afad 100644
--- a/lib/Sabre/VObject/Component/VJournal.php
+++ b/lib/Sabre/VObject/Component/VJournal.php
@@ -40,7 +40,51 @@ class VJournal extends VObject\Component {
         }
         return false;
 
-
     }
 
+    /**
+     * A simple list of validation rules.
+     *
+     * This is simply a list of properties, and how many times they either
+     * must or must not appear.
+     *
+     * Possible values per property:
+     *   * 0 - Must not appear.
+     *   * 1 - Must appear exactly once.
+     *   * + - Must appear at least once.
+     *   * * - Can appear any number of times.
+     *
+     * @var array
+     */
+    public function getValidationRules() {
+
+        return array(
+            'UID' => 1,
+            'DTSTAMP' => 1,
+
+            'CLASS' => '?',
+            'CREATED' => '?',
+            'DTSTART' => '?',
+            'LAST-MODIFICATION' => '?',
+            'ORGANIZER' => '?',
+            'RECURRENCE-ID' => '?',
+            'SEQUENCE' => '?',
+            'STATUS' => '?',
+            'SUMMARY' => '?',
+            'URL' => '?',
+
+            'RRULE' => '?',
+
+            'ATTACH' => '*',
+            'ATTENDEE' => '*',
+            'CATEGORIES' => '*',
+            'COMMENT' => '*',
+            'CONTACT' => '*',
+            'DESCRIPTION' => '*',
+            'EXDATE' => '*',
+            'RELATED' => '*',
+            'RDATE' => '*',
+        );
+
+    }
 }
diff --git a/lib/Sabre/VObject/Component/VTimeZone.php b/lib/Sabre/VObject/Component/VTimeZone.php
new file mode 100644
index 0000000..5440ed8
--- /dev/null
+++ b/lib/Sabre/VObject/Component/VTimeZone.php
@@ -0,0 +1,53 @@
+<?php
+
+namespace Sabre\VObject\Component;
+
+use Sabre\VObject;
+
+/**
+ * The VTimeZone component
+ *
+ * This component adds functionality to a component, specific for VTIMEZONE
+ * components.
+ *
+ * @copyright Copyright (C) 2007-2013 fruux GmbH (https://fruux.com/).
+ * @author Evert Pot (http://evertpot.com/)
+ * @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
+ */
+class VTimeZone extends VObject\Component {
+
+    /**
+     * A simple list of validation rules.
+     *
+     * This is simply a list of properties, and how many times they either
+     * must or must not appear.
+     *
+     * Possible values per property:
+     *   * 0 - Must not appear.
+     *   * 1 - Must appear exactly once.
+     *   * + - Must appear at least once.
+     *   * * - Can appear any number of times.
+     *
+     * @var array
+     */
+    public function getValidationRules() {
+
+        return array(
+            'TZID' => 1,
+
+            'LAST-MODIFICATION' => '?',
+            'TZURL' => '?',
+
+            // At least 1 STANDARD or DAYLIGHT must appear, or more. But both
+            // cannot appear in the same VTIMEZONE.
+            //
+            // The validator is not specific yet to pick this up, so these
+            // rules are too loose.
+            'STANDARD' => '*',
+            'DAYLIGHT' => '*',
+        );
+
+    }
+
+}
+
diff --git a/lib/Sabre/VObject/Component/VTodo.php b/lib/Sabre/VObject/Component/VTodo.php
index b1579cf..6bc6078 100644
--- a/lib/Sabre/VObject/Component/VTodo.php
+++ b/lib/Sabre/VObject/Component/VTodo.php
@@ -65,4 +65,59 @@ class VTodo extends VObject\Component {
 
     }
 
+    /**
+     * A simple list of validation rules.
+     *
+     * This is simply a list of properties, and how many times they either
+     * must or must not appear.
+     *
+     * Possible values per property:
+     *   * 0 - Must not appear.
+     *   * 1 - Must appear exactly once.
+     *   * + - Must appear at least once.
+     *   * * - Can appear any number of times.
+     *
+     * @var array
+     */
+    public function getValidationRules() {
+
+        return array(
+            'UID' => 1,
+            'DTSTAMP' => 1,
+
+            'CLASS' => '?',
+            'COMPLETED' => '?',
+            'CREATED' => '?',
+            'DESCRIPTION' => '?',
+            'DTSTART' => '?',
+            'GEO' => '?',
+            'LAST-MODIFICATION' => '?',
+            'LOCATION' => '?',
+            'ORGANIZER' => '?',
+            'PERCENT' => '?',
+            'PRIORITY' => '?',
+            'RECURRENCE-ID' => '?',
+            'SEQUENCE' => '?',
+            'STATUS' => '?',
+            'SUMMARY' => '?',
+            'URL' => '?',
+
+            'RRULE' => '?',
+            'DUE' => '?',
+            'DURATION' => '?',
+
+            'ATTACH' => '*',
+            'ATTENDEE' => '*',
+            'CATEGORIES' => '*',
+            'COMMENT' => '*',
+            'CONTACT' => '*',
+            'EXDATE' => '*',
+            'REQUEST-STATUS' => '*',
+            'RELATED' => '*',
+            'RESOURCES' => '*',
+            'RDATE' => '*',
+        );
+
+    }
+
 }
diff --git a/lib/Sabre/VObject/Node.php b/lib/Sabre/VObject/Node.php
index 3260a8c..62245b3 100644
--- a/lib/Sabre/VObject/Node.php
+++ b/lib/Sabre/VObject/Node.php
@@ -86,15 +86,19 @@ abstract class Node implements \IteratorAggregate, \ArrayAccess, \Countable {
      * Validates the node for correctness.
      *
      * The following options are supported:
-     *   - Node::REPAIR - If something is broken, and automatic repair may
-     *                    be attempted.
+     *   Node::REPAIR - May attempt to automatically repair the problem.
      *
-     * An array is returned with warnings.
+     * This method returns an array with detected problems.
+     * Every element has the following properties:
      *
-     * Every item in the array has the following properties:
-     *    * level - (number between 1 and 3 with severity information)
-     *    * message - (human readable message)
-     *    * node - (reference to the offending node)
+     *  * 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
diff --git a/lib/Sabre/VObject/Splitter/ICalendar.php b/lib/Sabre/VObject/Splitter/ICalendar.php
index 62e5048..f7604fa 100644
--- a/lib/Sabre/VObject/Splitter/ICalendar.php
+++ b/lib/Sabre/VObject/Splitter/ICalendar.php
@@ -62,12 +62,10 @@ class ICalendar implements SplitterInterface {
             }
 
             // Get component UID for recurring Events search
-            if($component->UID) {
-                $uid = (string)$component->UID;
-            } else {
-                // Generating a random UID
-                $uid = sha1(microtime()) . '-vobjectimport';
+            if(!$component->UID) {
+                $component->UID = sha1(microtime()) . '-vobjectimport';
             }
+            $uid = (string)$component->UID;
 
             // Take care of recurring events
             if (!array_key_exists($uid, $this->objects)) {
diff --git a/tests/Sabre/VObject/CliTest.php b/tests/Sabre/VObject/CliTest.php
index 23e5319..221f5f2 100644
--- a/tests/Sabre/VObject/CliTest.php
+++ b/tests/Sabre/VObject/CliTest.php
@@ -440,6 +440,7 @@ VCARD
 BEGIN:VCARD
 VERSION:4.0
 PRODID:-//Sabre//Sabre VObject 3.1.0//EN
+UID:foo
 FN:Cowboy Henk
 END:VCARD
 
@@ -447,10 +448,11 @@ VCARD
     );
         rewind($inputStream);
         $this->cli->stdin = $inputStream;
-        // vCard 2.1 is not supported yet, so this returns a failure.
+        $result = $this->cli->main(array('vobject', 'validate', '-'));
+
         $this->assertEquals(
             0,
-            $this->cli->main(array('vobject', 'validate', '-'))
+            $result
         );
 
     }
@@ -530,6 +532,8 @@ BEGIN:VCALENDAR
 VERSION:2.0
 PRODID:-//Sabre//Sabre VObject 3.1.0//EN
 BEGIN:VEVENT
+UID:foo
+DTSTAMP:20140122T233226Z
 END:VEVENT
 END:VCALENDAR
 
diff --git a/tests/Sabre/VObject/Component/VCalendarTest.php b/tests/Sabre/VObject/Component/VCalendarTest.php
index bc284b0..5a8de4e 100644
--- a/tests/Sabre/VObject/Component/VCalendarTest.php
+++ b/tests/Sabre/VObject/Component/VCalendarTest.php
@@ -260,6 +260,8 @@ VERSION:2.0
 PRODID:foo
 BEGIN:VEVENT
 DTSTART;VALUE=DATE:20111202
+DTSTAMP:20140122T233226Z
+UID:foo
 END:VEVENT
 END:VCALENDAR
 ';
@@ -276,6 +278,8 @@ CALSCALE:GREGORIAN
 PRODID:foo
 BEGIN:VEVENT
 DTSTART;VALUE=DATE:20111202
+UID:foo
+DTSTAMP:20140122T234434Z
 END:VEVENT
 END:VCALENDAR
 ';
@@ -293,6 +297,8 @@ VERSION:3.0
 PRODID:foo
 BEGIN:VEVENT
 DTSTART;VALUE=DATE:20111202
+UID:foo
+DTSTAMP:20140122T234434Z
 END:VEVENT
 END:VCALENDAR
 ';
@@ -309,6 +315,8 @@ CALSCALE:GREGORIAN
 VERSION:2.0
 BEGIN:VEVENT
 DTSTART;VALUE=DATE:20111202
+UID:foo
+DTSTAMP:20140122T234434Z
 END:VEVENT
 END:VCALENDAR
 ';
@@ -327,6 +335,8 @@ CALSCALE:GREGORIAN
 CALSCALE:GREGORIAN
 BEGIN:VEVENT
 DTSTART;VALUE=DATE:20111202
+UID:foo
+DTSTAMP:20140122T234434Z
 END:VEVENT
 END:VCALENDAR
 ';
@@ -345,6 +355,8 @@ METHOD:REQUEST
 METHOD:REQUEST
 BEGIN:VEVENT
 DTSTART;VALUE=DATE:20111202
+UID:foo
+DTSTAMP:20140122T234434Z
 END:VEVENT
 END:VCALENDAR
 ';
diff --git a/tests/Sabre/VObject/Component/VCardTest.php b/tests/Sabre/VObject/Component/VCardTest.php
index 787d072..032f275 100644
--- a/tests/Sabre/VObject/Component/VCardTest.php
+++ b/tests/Sabre/VObject/Component/VCardTest.php
@@ -37,61 +37,61 @@ class VCardTest extends \PHPUnit_Framework_TestCase {
 
         // Correct
         $tests[] = array(
-            "BEGIN:VCARD\r\nVERSION:4.0\r\nFN:John Doe\r\nEND:VCARD\r\n",
+            "BEGIN:VCARD\r\nVERSION:4.0\r\nFN:John Doe\r\nUID:foo\r\nEND:VCARD\r\n",
             array(),
-            "BEGIN:VCARD\r\nVERSION:4.0\r\nFN:John Doe\r\nEND:VCARD\r\n",
+            "BEGIN:VCARD\r\nVERSION:4.0\r\nFN:John Doe\r\nUID:foo\r\nEND:VCARD\r\n",
         );
 
         // No VERSION
         $tests[] = array(
-            "BEGIN:VCARD\r\nFN:John Doe\r\nEND:VCARD\r\n",
+            "BEGIN:VCARD\r\nFN:John Doe\r\nUID:foo\r\nEND:VCARD\r\n",
             array(
-                'The VERSION property must appear in the VCARD component exactly 1 time',
+                'VERSION MUST appear exactly once in a VCARD component',
             ),
-            "BEGIN:VCARD\r\nVERSION:2.1\r\nFN:John Doe\r\nEND:VCARD\r\n",
+            "BEGIN:VCARD\r\nVERSION:3.0\r\nFN:John Doe\r\nUID:foo\r\nEND:VCARD\r\n",
         );
 
         // Unknown version
         $tests[] = array(
-            "BEGIN:VCARD\r\nVERSION:2.2\r\nFN:John Doe\r\nEND:VCARD\r\n",
+            "BEGIN:VCARD\r\nVERSION:2.2\r\nFN:John Doe\r\nUID:foo\r\nEND:VCARD\r\n",
             array(
                 'Only vcard version 4.0 (RFC6350), version 3.0 (RFC2426) or version 2.1 (icm-vcard-2.1) are supported.',
             ),
-            "BEGIN:VCARD\r\nVERSION:2.1\r\nFN:John Doe\r\nEND:VCARD\r\n",
+            "BEGIN:VCARD\r\nVERSION:2.1\r\nFN:John Doe\r\nUID:foo\r\nEND:VCARD\r\n",
         );
 
         // No FN
         $tests[] = array(
-            "BEGIN:VCARD\r\nVERSION:4.0\r\nEND:VCARD\r\n",
+            "BEGIN:VCARD\r\nVERSION:4.0\r\nUID:foo\r\nEND:VCARD\r\n",
             array(
                 'The FN property must appear in the VCARD component exactly 1 time',
             ),
-            "BEGIN:VCARD\r\nVERSION:4.0\r\nEND:VCARD\r\n",
+            "BEGIN:VCARD\r\nVERSION:4.0\r\nUID:foo\r\nEND:VCARD\r\n",
         );
         // No FN, N fallback
         $tests[] = array(
-            "BEGIN:VCARD\r\nVERSION:4.0\r\nN:Doe;John;;;;;\r\nEND:VCARD\r\n",
+            "BEGIN:VCARD\r\nVERSION:4.0\r\nUID:foo\r\nN:Doe;John;;;;;\r\nEND:VCARD\r\n",
             array(
                 'The FN property must appear in the VCARD component exactly 1 time',
             ),
-            "BEGIN:VCARD\r\nVERSION:4.0\r\nN:Doe;John;;;;;\r\nFN:John Doe\r\nEND:VCARD\r\n",
+            "BEGIN:VCARD\r\nVERSION:4.0\r\nUID:foo\r\nN:Doe;John;;;;;\r\nFN:John Doe\r\nEND:VCARD\r\n",
         );
         // No FN, N fallback, no first name
         $tests[] = array(
-            "BEGIN:VCARD\r\nVERSION:4.0\r\nN:Doe;;;;;;\r\nEND:VCARD\r\n",
+            "BEGIN:VCARD\r\nVERSION:4.0\r\nUID:foo\r\nN:Doe;;;;;;\r\nEND:VCARD\r\n",
             array(
                 'The FN property must appear in the VCARD component exactly 1 time',
             ),
-            "BEGIN:VCARD\r\nVERSION:4.0\r\nN:Doe;;;;;;\r\nFN:Doe\r\nEND:VCARD\r\n",
+            "BEGIN:VCARD\r\nVERSION:4.0\r\nUID:foo\r\nN:Doe;;;;;;\r\nFN:Doe\r\nEND:VCARD\r\n",
         );
 
         // No FN, ORG fallback
         $tests[] = array(
-            "BEGIN:VCARD\r\nVERSION:4.0\r\nORG:Acme Co.\r\nEND:VCARD\r\n",
+            "BEGIN:VCARD\r\nVERSION:4.0\r\nUID:foo\r\nORG:Acme Co.\r\nEND:VCARD\r\n",
             array(
                 'The FN property must appear in the VCARD component exactly 1 time',
             ),
-            "BEGIN:VCARD\r\nVERSION:4.0\r\nORG:Acme Co.\r\nFN:Acme Co.\r\nEND:VCARD\r\n",
+            "BEGIN:VCARD\r\nVERSION:4.0\r\nUID:foo\r\nORG:Acme Co.\r\nFN:Acme Co.\r\nEND:VCARD\r\n",
         );
         return $tests;
 
diff --git a/tests/Sabre/VObject/Property/TextTest.php b/tests/Sabre/VObject/Property/TextTest.php
index a548da3..8f698f7 100644
--- a/tests/Sabre/VObject/Property/TextTest.php
+++ b/tests/Sabre/VObject/Property/TextTest.php
@@ -76,6 +76,7 @@ class TextTest extends \PHPUnit_Framework_TestCase {
         $vcard = <<<IN
 BEGIN:VCARD
 VERSION:4.0
+UID:foo
 FN:Hi!
 N:A
 END:VCARD
diff --git a/tests/Sabre/VObject/Splitter/ICalendarTest.php b/tests/Sabre/VObject/Splitter/ICalendarTest.php
index bc1719a..1d00584 100644
--- a/tests/Sabre/VObject/Splitter/ICalendarTest.php
+++ b/tests/Sabre/VObject/Splitter/ICalendarTest.php
@@ -27,6 +27,7 @@ class ICalendarTest extends \PHPUnit_Framework_TestCase {
 BEGIN:VCALENDAR
 BEGIN:VEVENT
 UID:foo
+DTSTAMP:20140122T233226Z
 END:VEVENT
 END:VCALENDAR
 EOT;
@@ -46,6 +47,7 @@ EOT;
 BEGIN:VCALENDAR
 BEGIN:VEVENT
 UID:foo
+DTSTAMP:20140122T233226Z
 END:VEVENT
 END:VCALENDAR
 EOT;
@@ -76,12 +78,14 @@ EOT;
         $event[] = <<<EOT
 BEGIN:VEVENT
 UID:foo1
+DTSTAMP:20140122T233226Z
 END:VEVENT
 EOT;
 
 $event[] = <<<EOT
 BEGIN:VEVENT
 UID:foo2
+DTSTAMP:20140122T233226Z
 END:VEVENT
 EOT;
 
@@ -126,6 +130,7 @@ VERSION:2.0
 PRODID:-//Sabre//Sabre VObject $this->version//EN
 CALSCALE:GREGORIAN
 BEGIN:VEVENT
+DTSTAMP:20140122T233226Z
 END:VEVENT
 END:VCALENDAR
 
@@ -136,12 +141,20 @@ EOT;
 
         $return = "";
         while($object=$objects->getNext()) {
-            $expected = str_replace("\n", "\r\n", $data);
-            $this->assertEquals($expected, $object->serialize());
             $return .= $object->serialize();
         }
 
-        $this->assertEquals(array(), VObject\Reader::read($return)->validate());
+        $messages = VObject\Reader::read($return)->validate();
+
+        if ($messages) {
+            $messages = array_map(
+                function($item) { return $item['message']; },
+                $messages
+            );
+            $this->fail('Validation errors: ' . implode("\n", $messages));
+        } else {
+            $this->assertEquals(array(), $messages);
+        }
     }
 
     function testICalendarImportMultipleVTIMEZONESAndMultipleValidEvents() {
@@ -186,18 +199,21 @@ EOT;
         $event[] = <<<EOT
 BEGIN:VEVENT
 UID:foo1
+DTSTAMP:20140122T232710Z
 END:VEVENT
 EOT;
 
         $event[] = <<<EOT
 BEGIN:VEVENT
 UID:foo2
+DTSTAMP:20140122T232710Z
 END:VEVENT
 EOT;
 
         $event[] = <<<EOT
 BEGIN:VEVENT
 UID:foo3
+DTSTAMP:20140122T232710Z
 END:VEVENT
 EOT;
 
@@ -277,7 +293,8 @@ EOT;
             $return .= $object->serialize();
         }
 
-        $this->assertEquals(array(), VObject\Reader::read($return)->validate());
+        $messages = VObject\Reader::read($return)->validate();
+        $this->assertEquals(array(), $messages);
     }
 
 }

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