[Pkg-owncloud-commits] [php-sabre-vobject] 01/19: More tests for VTODO.
David Prévot
taffit at moszumanska.debian.org
Sun Jun 15 02:08:53 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 987560a1c174d7e701a9204795a25bb5cd2fcfd0
Author: Evert Pot <evert at rooftopsolutions.nl>
Date: Tue May 20 13:32:55 2014 -0400
More tests for VTODO.
---
ChangeLog.md | 7 ++++
lib/Sabre/VObject/Component/VTodo.php | 53 ++++++++++++++++++++++++++
lib/Sabre/VObject/Version.php | 2 +-
tests/Sabre/VObject/Component/VTodoTest.php | 59 +++++++++++++++++++++++++++++
4 files changed, 120 insertions(+), 1 deletion(-)
diff --git a/ChangeLog.md b/ChangeLog.md
index d671fc0..935d96f 100644
--- a/ChangeLog.md
+++ b/ChangeLog.md
@@ -1,6 +1,13 @@
ChangeLog
=========
+3.2.3 (2014-??-??)
+------------------
+
+* Validator now checks if DUE and DTSTART are of the same type in VTODO, and
+ ensures that DUE is always after DTSTART.
+
+
3.2.2 (2014-05-07)
------------------
* Minor tweak in unittests to make it run on PHP 5.5.12. Json-prettifying
diff --git a/lib/Sabre/VObject/Component/VTodo.php b/lib/Sabre/VObject/Component/VTodo.php
index 7751297..9152356 100644
--- a/lib/Sabre/VObject/Component/VTodo.php
+++ b/lib/Sabre/VObject/Component/VTodo.php
@@ -120,4 +120,57 @@ class VTodo extends VObject\Component {
}
+ /**
+ * 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) {
+
+ $result = parent::validate($options);
+ if (isset($this->DUE) && isset($this->DTSTART)) {
+
+ $due = $this->DUE;
+ $dtStart = $this->DTSTART;
+
+ if ($due->getValueType() !== $dtStart->getValueType()) {
+
+ $result[] = array(
+ 'level' => 3,
+ 'message' => 'The value type (DATE or DATE-TIME) must be identical for DUE and DTSTART',
+ 'node' => $due,
+ );
+
+ } elseif ($due->getDateTime() < $dtStart->getDateTime()) {
+
+ $result[] = array(
+ 'level' => 3,
+ 'message' => 'DUE must occur after DTSTART',
+ 'node' => $due,
+ );
+
+ }
+
+ }
+
+ return $result;
+
+ }
+
}
diff --git a/lib/Sabre/VObject/Version.php b/lib/Sabre/VObject/Version.php
index 7978c51..0c1a5ff 100644
--- a/lib/Sabre/VObject/Version.php
+++ b/lib/Sabre/VObject/Version.php
@@ -14,6 +14,6 @@ class Version {
/**
* Full version number
*/
- const VERSION = '3.2.2';
+ const VERSION = '3.2.3';
}
diff --git a/tests/Sabre/VObject/Component/VTodoTest.php b/tests/Sabre/VObject/Component/VTodoTest.php
index 53bf5f2..e536e7b 100644
--- a/tests/Sabre/VObject/Component/VTodoTest.php
+++ b/tests/Sabre/VObject/Component/VTodoTest.php
@@ -117,5 +117,64 @@ HI;
), $messages);
}
+
+ public function testValidateDUEDTSTARTMisMatch() {
+
+ $input = <<<HI
+BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:YoYo
+BEGIN:VTODO
+UID:FOO
+DTSTART;VALUE=DATE-TIME:20140520T131600Z
+DUE;VALUE=DATE:20140520
+DTSTAMP;VALUE=DATE-TIME:20140520T131600Z
+END:VTODO
+END:VCALENDAR
+HI;
+
+ $obj = Reader::read($input);
+
+ $warnings = $obj->validate();
+ $messages = array();
+ foreach($warnings as $warning) {
+ $messages[] = $warning['message'];
+ }
+
+ $this->assertEquals(array(
+ "The value type (DATE or DATE-TIME) must be identical for DUE and DTSTART",
+ ), $messages);
+
+ }
+
+ public function testValidateDUEbeforeDTSTART() {
+
+ $input = <<<HI
+BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:YoYo
+BEGIN:VTODO
+UID:FOO
+DTSTART;VALUE=DATE:20140520
+DUE;VALUE=DATE:20140518
+DTSTAMP;VALUE=DATE-TIME:20140520T131600Z
+END:VTODO
+END:VCALENDAR
+HI;
+
+ $obj = Reader::read($input);
+
+ $warnings = $obj->validate();
+ $messages = array();
+ foreach($warnings as $warning) {
+ $messages[] = $warning['message'];
+ }
+
+ $this->assertEquals(array(
+ "DUE must occur after DTSTART",
+ ), $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