[Pkg-owncloud-commits] [php-sabre-vobject] 97/128: Lots of new unittests and small bugfixes.
David Prévot
taffit at moszumanska.debian.org
Tue May 20 23:11:06 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 f5b3f051c6ccaae6ba4a05e1dc91fc546e2fd3d5
Author: Evert Pot <evert at rooftopsolutions.nl>
Date: Wed Apr 2 19:24:10 2014 -0400
Lots of new unittests and small bugfixes.
---
lib/Sabre/VObject/Component/VCalendar.php | 3 +-
lib/Sabre/VObject/Property/ICalendar/Date.php | 6 -
lib/Sabre/VObject/Property/Uri.php | 3 -
lib/Sabre/VObject/Property/VCard/DateAndOrTime.php | 14 +-
tests/Sabre/VObject/Component/VTimeZoneTest.php | 34 +++++
tests/Sabre/VObject/Component/VTodoTest.php | 54 +++++++-
tests/Sabre/VObject/ComponentTest.php | 69 ++++++++++
tests/Sabre/VObject/Property/BinaryTest.php | 19 +++
.../VObject/Property/VCard/DateAndOrTimeTest.php | 150 ++++++++++++++++++++-
9 files changed, 335 insertions(+), 17 deletions(-)
diff --git a/lib/Sabre/VObject/Component/VCalendar.php b/lib/Sabre/VObject/Component/VCalendar.php
index 066492c..016366e 100644
--- a/lib/Sabre/VObject/Component/VCalendar.php
+++ b/lib/Sabre/VObject/Component/VCalendar.php
@@ -32,11 +32,12 @@ class VCalendar extends VObject\Document {
* @var array
*/
static public $componentMap = array(
+ 'VALARM' => 'Sabre\\VObject\\Component\\VAlarm',
'VEVENT' => 'Sabre\\VObject\\Component\\VEvent',
'VFREEBUSY' => 'Sabre\\VObject\\Component\\VFreeBusy',
'VJOURNAL' => 'Sabre\\VObject\\Component\\VJournal',
+ 'VTIMEZONE' => 'Sabre\\VObject\\Component\\VTimeZone',
'VTODO' => 'Sabre\\VObject\\Component\\VTodo',
- 'VALARM' => 'Sabre\\VObject\\Component\\VAlarm',
);
/**
diff --git a/lib/Sabre/VObject/Property/ICalendar/Date.php b/lib/Sabre/VObject/Property/ICalendar/Date.php
index fda9c0e..755399c 100644
--- a/lib/Sabre/VObject/Property/ICalendar/Date.php
+++ b/lib/Sabre/VObject/Property/ICalendar/Date.php
@@ -2,12 +2,6 @@
namespace Sabre\VObject\Property\ICalendar;
-use
- Sabre\VObject\Property,
- Sabre\VObject\Parser\MimeDir,
- Sabre\VObject\DateTimeParser,
- Sabre\VObject\TimeZoneUtil;
-
/**
* DateTime property
*
diff --git a/lib/Sabre/VObject/Property/Uri.php b/lib/Sabre/VObject/Property/Uri.php
index 68fd416..e235c07 100644
--- a/lib/Sabre/VObject/Property/Uri.php
+++ b/lib/Sabre/VObject/Property/Uri.php
@@ -62,9 +62,6 @@ class Uri extends Property {
$newVal = '';
foreach($matches as $match) {
switch($match) {
- case '\\\\' :
- $newVal.='\\';
- break;
case '\:' :
$newVal.=':';
break;
diff --git a/lib/Sabre/VObject/Property/VCard/DateAndOrTime.php b/lib/Sabre/VObject/Property/VCard/DateAndOrTime.php
index 322daa3..7100205 100644
--- a/lib/Sabre/VObject/Property/VCard/DateAndOrTime.php
+++ b/lib/Sabre/VObject/Property/VCard/DateAndOrTime.php
@@ -50,8 +50,11 @@ class DateAndOrTime extends Property {
*/
public function setParts(array $parts) {
+ if (count($parts)>1) {
+ throw new \InvalidArgumentException('Only one value allowed');
+ }
if (isset($parts[0]) && $parts[0] instanceof \DateTime) {
- $this->setDateTimes($parts);
+ $this->setDateTime($parts[0]);
} else {
parent::setParts($parts);
}
@@ -71,7 +74,7 @@ class DateAndOrTime extends Property {
public function setValue($value) {
if ($value instanceof \DateTime) {
- $this->setDateTime(array($value));
+ $this->setDateTime($value);
} else {
parent::setValue($value);
}
@@ -125,12 +128,13 @@ class DateAndOrTime extends Property {
$dts = array();
$now = new DateTime();
- $tzFormat = $nowParts->getTimezone()->getOffset()===0?'\\Z':'O';
- $nowParts = DateTimeParser::parseVCardDateTime($now->format('Ymd\\This' + $tzFormat));
+
+ $tzFormat = $now->getTimezone()->getOffset($now)===0?'\\Z':'O';
+ $nowParts = DateTimeParser::parseVCardDateTime($now->format('Ymd\\This' . $tzFormat));
$value = $this->getValue();
- $dateParts = DateTimeParser::parseVCardDateTime($part);
+ $dateParts = DateTimeParser::parseVCardDateTime($this->getValue());
// This sets all the missing parts to the current date/time.
// So if the year was missing for a birthday, we're making it 'this
diff --git a/tests/Sabre/VObject/Component/VTimeZoneTest.php b/tests/Sabre/VObject/Component/VTimeZoneTest.php
new file mode 100644
index 0000000..794b221
--- /dev/null
+++ b/tests/Sabre/VObject/Component/VTimeZoneTest.php
@@ -0,0 +1,34 @@
+<?php
+
+namespace Sabre\VObject\Component;
+
+use Sabre\VObject;
+use Sabre\VObject\Reader;
+
+class VTimeZoneTest extends \PHPUnit_Framework_TestCase {
+
+ public function testValidate() {
+
+ $input = <<<HI
+BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:YoYo
+BEGIN:VTIMEZONE
+TZID:America/Toronto
+END:VTIMEZONE
+END:VCALENDAR
+HI;
+
+ $obj = Reader::read($input);
+
+ $warnings = $obj->validate();
+ $messages = array();
+ foreach($warnings as $warning) {
+ $messages[] = $warning['message'];
+ }
+
+ $this->assertEquals(array(), $messages);
+
+ }
+
+}
diff --git a/tests/Sabre/VObject/Component/VTodoTest.php b/tests/Sabre/VObject/Component/VTodoTest.php
index d2f2369..53bf5f2 100644
--- a/tests/Sabre/VObject/Component/VTodoTest.php
+++ b/tests/Sabre/VObject/Component/VTodoTest.php
@@ -2,7 +2,9 @@
namespace Sabre\VObject\Component;
-use Sabre\VObject\Component;
+use
+ Sabre\VObject\Component,
+ Sabre\VObject\Reader;
class VTodoTest extends \PHPUnit_Framework_TestCase {
@@ -65,5 +67,55 @@ class VTodoTest extends \PHPUnit_Framework_TestCase {
}
+ public function testValidate() {
+
+ $input = <<<HI
+BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:YoYo
+BEGIN:VTODO
+UID:1234-21355-123156
+DTSTAMP:20140402T183400Z
+END:VTODO
+END:VCALENDAR
+HI;
+
+ $obj = Reader::read($input);
+
+ $warnings = $obj->validate();
+ $messages = array();
+ foreach($warnings as $warning) {
+ $messages[] = $warning['message'];
+ }
+
+ $this->assertEquals(array(), $messages);
+
+ }
+
+ public function testValidateInvalid() {
+
+ $input = <<<HI
+BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:YoYo
+BEGIN:VTODO
+END:VTODO
+END:VCALENDAR
+HI;
+
+ $obj = Reader::read($input);
+
+ $warnings = $obj->validate();
+ $messages = array();
+ foreach($warnings as $warning) {
+ $messages[] = $warning['message'];
+ }
+
+ $this->assertEquals(array(
+ "UID MUST appear exactly once in a VTODO component",
+ "DTSTAMP MUST appear exactly once in a VTODO component",
+ ), $messages);
+
+ }
}
diff --git a/tests/Sabre/VObject/ComponentTest.php b/tests/Sabre/VObject/ComponentTest.php
index 6387e49..b0c17a4 100644
--- a/tests/Sabre/VObject/ComponentTest.php
+++ b/tests/Sabre/VObject/ComponentTest.php
@@ -466,4 +466,73 @@ class ComponentTest extends \PHPUnit_Framework_TestCase {
$comp->remove($prop);
}
+
+ /**
+ * @dataProvider ruleData
+ */
+ function testValidateRules($componentList, $errorCount) {
+
+ $vcard = new Component\VCard();
+
+ $component = new FakeComponent($vcard,'Hi', array(), $defaults = false );
+ foreach($componentList as $v) {
+ $component->add($v,'Hello.');
+ }
+
+ $this->assertEquals($errorCount, count($component->validate()));
+
+ }
+
+ function testValidateRepair() {
+
+ $vcard = new Component\VCard();
+
+ $component = new FakeComponent($vcard,'Hi', array(), $defaults = false );
+ $component->validate(Component::REPAIR);
+ $this->assertEquals('yow', $component->BAR->getValue());
+
+ }
+
+ function ruleData() {
+
+ return array(
+
+ array(array(), 2),
+ array(array('FOO'), 3),
+ array(array('BAR'), 1),
+ array(array('BAZ'), 1),
+ array(array('BAR','BAZ'), 0),
+ array(array('BAR','BAZ','ZIM',), 0),
+ array(array('BAR','BAZ','ZIM','GIR'), 0),
+ array(array('BAR','BAZ','ZIM','GIR','GIR'), 1),
+
+ );
+
+ }
+
+}
+
+class FakeComponent extends Component {
+
+ public function getValidationRules() {
+
+ return array(
+ 'FOO' => '0',
+ 'BAR' => '1',
+ 'BAZ' => '+',
+ 'ZIM' => '*',
+ 'GIR' => '?',
+ );
+
+ }
+
+ public function getDefaults() {
+
+ return array(
+ 'BAR' => 'yow',
+ );
+
+ }
+
}
+
diff --git a/tests/Sabre/VObject/Property/BinaryTest.php b/tests/Sabre/VObject/Property/BinaryTest.php
new file mode 100644
index 0000000..0d5bb43
--- /dev/null
+++ b/tests/Sabre/VObject/Property/BinaryTest.php
@@ -0,0 +1,19 @@
+<?php
+
+namespace Sabre\VObject\Property;
+
+use Sabre\VObject;
+
+class BinaryTest extends \PHPUnit_Framework_TestCase {
+
+ /**
+ * @expectedException \InvalidArgumentException
+ */
+ function testMimeDir() {
+
+ $vcard = new VObject\Component\VCard();
+ $vcard->add('PHOTO', array('a','b'));
+
+ }
+
+}
diff --git a/tests/Sabre/VObject/Property/VCard/DateAndOrTimeTest.php b/tests/Sabre/VObject/Property/VCard/DateAndOrTimeTest.php
index beebd8c..6a90174 100644
--- a/tests/Sabre/VObject/Property/VCard/DateAndOrTimeTest.php
+++ b/tests/Sabre/VObject/Property/VCard/DateAndOrTimeTest.php
@@ -2,7 +2,9 @@
namespace Sabre\VObject\Property\VCard;
-use Sabre\VObject;
+use
+ Sabre\VObject,
+ Sabre\VObject\Reader;
class DateAndOrTimeTest extends \PHPUnit_Framework_TestCase {
@@ -81,5 +83,151 @@ class DateAndOrTimeTest extends \PHPUnit_Framework_TestCase {
}
+ public function testSetParts() {
+
+ $vcard = new VObject\Component\VCard();
+
+ $prop = $vcard->createProperty('BDAY');
+ $prop->setParts(array(
+ new \DateTime('2014-04-02 18:37:00')
+ ));
+
+ $this->assertEquals('20140402T183700Z', $prop->getValue());
+
+ }
+
+ /**
+ * @expectedException InvalidArgumentException
+ */
+ public function testSetPartsTooMany() {
+
+ $vcard = new VObject\Component\VCard();
+
+ $prop = $vcard->createProperty('BDAY');
+ $prop->setParts(array(
+ 1,
+ 2
+ ));
+
+ }
+
+ public function testSetPartsString() {
+
+ $vcard = new VObject\Component\VCard();
+
+ $prop = $vcard->createProperty('BDAY');
+ $prop->setParts(array(
+ "20140402T183700Z"
+ ));
+
+ $this->assertEquals('20140402T183700Z', $prop->getValue());
+
+ }
+
+ public function testSetValueDateTime() {
+
+ $vcard = new VObject\Component\VCard();
+
+ $prop = $vcard->createProperty('BDAY');
+ $prop->setValue(
+ new \DateTime('2014-04-02 18:37:00')
+ );
+
+ $this->assertEquals('20140402T183700Z', $prop->getValue());
+
+ }
+
+ public function testSetDateTimeOffset() {
+
+ $vcard = new VObject\Component\VCard();
+
+ $prop = $vcard->createProperty('BDAY');
+ $prop->setValue(
+ new \DateTime('2014-04-02 18:37:00', new \DateTimeZone('America/Toronto'))
+ );
+
+ $this->assertEquals('20140402T183700-0400', $prop->getValue());
+
+ }
+
+ public function testGetDateTime() {
+
+ $datetime = new \DateTime('2014-04-02 18:37:00', new \DateTimeZone('America/Toronto'));
+
+ $vcard = new VObject\Component\VCard();
+ $prop = $vcard->createProperty('BDAY', $datetime);
+
+ $dt = $prop->getDateTime();
+ $this->assertEquals($datetime, $dt);
+
+ }
+
+ public function testGetDateIncomplete() {
+
+ $datetime = '--0407';
+
+ $vcard = new VObject\Component\VCard();
+ $prop = $vcard->add('BDAY', $datetime);
+
+ $dt = $prop->getDateTime();
+ // Note: if the year changes between the last line and the next line of
+ // code, this test may fail.
+ //
+ // If that happens, head outside and have a drink.
+ $current = new \DateTime('now');
+ $year = $current->format('Y');
+
+ $this->assertEquals($year . '0407', $dt->format('Ymd'));
+
+ }
+
+ public function testGetDateIncompleteFromVCard() {
+
+ $vcard = <<<VCF
+BEGIN:VCARD
+VERSION:4.0
+BDAY:--0407
+END:VCARD
+VCF;
+ $vcard = Reader::read($vcard);
+ $prop = $vcard->BDAY;
+
+ $dt = $prop->getDateTime();
+ // Note: if the year changes between the last line and the next line of
+ // code, this test may fail.
+ //
+ // If that happens, head outside and have a drink.
+ $current = new \DateTime('now');
+ $year = $current->format('Y');
+
+ $this->assertEquals($year . '0407', $dt->format('Ymd'));
+
+ }
+
+ public function testValidate() {
+
+ $datetime = '--0407';
+
+ $vcard = new VObject\Component\VCard();
+ $prop = $vcard->add('BDAY', $datetime);
+
+ $this->assertEquals(array(), $prop->validate());
+
+ }
+
+ public function testValidateBroken() {
+
+ $datetime = '123';
+
+ $vcard = new VObject\Component\VCard();
+ $prop = $vcard->add('BDAY', $datetime);
+
+ $this->assertEquals(array(array(
+ 'level' => 3,
+ 'message' => 'The supplied value (123) is not a correct DATE-AND-OR-TIME property',
+ 'node' => $prop,
+ )), $prop->validate());
+
+ }
}
--
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