[Pkg-owncloud-commits] [php-sabre-vobject] 49/128: Added a validation rule for calendars with more than 1 master event.
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 ad57610e6ff4fe2744b578f4c15d733834ad8c76
Author: Evert Pot <evert at rooftopsolutions.nl>
Date: Wed Jan 22 20:53:14 2014 -0500
Added a validation rule for calendars with more than 1 master event.
---
lib/Sabre/VObject/Component/VCalendar.php | 28 +++++++++++++-
tests/Sabre/VObject/Component/VCalendarTest.php | 49 +++++++++++++++++++++++++
tests/Sabre/VObject/Splitter/ICalendarTest.php | 1 -
3 files changed, 76 insertions(+), 2 deletions(-)
diff --git a/lib/Sabre/VObject/Component/VCalendar.php b/lib/Sabre/VObject/Component/VCalendar.php
index 25160d6..066492c 100644
--- a/lib/Sabre/VObject/Component/VCalendar.php
+++ b/lib/Sabre/VObject/Component/VCalendar.php
@@ -341,16 +341,42 @@ class VCalendar extends VObject\Document {
}
+ $uidList = array();
+
$componentsFound = 0;
foreach($this->children as $child) {
if($child instanceof Component) {
$componentsFound++;
+
+ if (!in_array($child->name, array('VEVENT', 'VTODO', 'VJOURNAL'))) {
+ continue;
+ }
+
+ $uid = (string)$child->UID;
+ $isMaster = isset($child->{'RECURRENCE-ID'})?0:1;
+ if (isset($uidList[$uid])) {
+ $uidList[$uid]['count']++;
+ if ($isMaster && $uidList[$uid]['hasMaster']) {
+ $warnings[] = array(
+ 'level' => 3,
+ 'message' => 'More than one master object was found for the object with UID ' . $uid,
+ 'node' => $this,
+ );
+ }
+ $uidList[$uid]['hasMaster']+=$isMaster;
+ } else {
+ $uidList[$uid] = array(
+ 'count' => 1,
+ 'hasMaster' => $isMaster,
+ );
+ }
+
}
}
if ($componentsFound===0) {
$warnings[] = array(
- 'level' => 1,
+ 'level' => 3,
'message' => 'An iCalendar object must have at least 1 component.',
'node' => $this,
);
diff --git a/tests/Sabre/VObject/Component/VCalendarTest.php b/tests/Sabre/VObject/Component/VCalendarTest.php
index 5a8de4e..0e123cb 100644
--- a/tests/Sabre/VObject/Component/VCalendarTest.php
+++ b/tests/Sabre/VObject/Component/VCalendarTest.php
@@ -365,4 +365,53 @@ END:VCALENDAR
$this->assertEquals(1, count($vcal->validate()));
}
+
+ function testValidateTwoMasterEvents() {
+
+ $input = 'BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:foo
+METHOD:REQUEST
+BEGIN:VEVENT
+DTSTART;VALUE=DATE:20111202
+UID:foo
+DTSTAMP:20140122T234434Z
+END:VEVENT
+BEGIN:VEVENT
+DTSTART;VALUE=DATE:20111202
+UID:foo
+DTSTAMP:20140122T234434Z
+END:VEVENT
+END:VCALENDAR
+';
+
+ $vcal = VObject\Reader::read($input);
+ $this->assertEquals(1, count($vcal->validate()));
+
+ }
+
+ function testValidateOneMasterEvent() {
+
+ $input = 'BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:foo
+METHOD:REQUEST
+BEGIN:VEVENT
+DTSTART;VALUE=DATE:20111202
+UID:foo
+DTSTAMP:20140122T234434Z
+END:VEVENT
+BEGIN:VEVENT
+DTSTART;VALUE=DATE:20111202
+UID:foo
+DTSTAMP:20140122T234434Z
+RECURRENCE-ID;VALUE=DATE:20111202
+END:VEVENT
+END:VCALENDAR
+';
+
+ $vcal = VObject\Reader::read($input);
+ $this->assertEquals(0, count($vcal->validate()));
+
+ }
}
diff --git a/tests/Sabre/VObject/Splitter/ICalendarTest.php b/tests/Sabre/VObject/Splitter/ICalendarTest.php
index 1d00584..17424a3 100644
--- a/tests/Sabre/VObject/Splitter/ICalendarTest.php
+++ b/tests/Sabre/VObject/Splitter/ICalendarTest.php
@@ -253,7 +253,6 @@ EOT;
}
$this->assertEquals(array(), VObject\Reader::read($return)->validate());
- $this->assertEquals(array(), VObject\Reader::read($return)->validate());
}
function testICalendarImportWithOutVTIMEZONES() {
--
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