[Pkg-owncloud-commits] [php-sabre-vobject] 327/341: Refactored the freebusygenerator tests, so it's easier to maintain.
David Prévot
taffit at moszumanska.debian.org
Tue Aug 11 13:36:01 UTC 2015
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 9bf8c2e47efd63e8cc674c147735b7d7ed9c6a64
Author: Evert Pot <me at evertpot.com>
Date: Thu Jul 16 22:45:36 2015 -0400
Refactored the freebusygenerator tests, so it's easier to maintain.
---
lib/FreeBusyGenerator.php | 11 +-
tests/VObject/FreeBusyGeneratorTest.php | 403 ++++++++++++++++++++------------
2 files changed, 266 insertions(+), 148 deletions(-)
diff --git a/lib/FreeBusyGenerator.php b/lib/FreeBusyGenerator.php
index 147f491..651746e 100644
--- a/lib/FreeBusyGenerator.php
+++ b/lib/FreeBusyGenerator.php
@@ -571,8 +571,10 @@ class FreeBusyGenerator {
foreach ($fbData->getData() as $busyTime) {
+ $busyType = strtoupper($busyTime['type']);
+
// Ignoring all the FREE parts, because those are already assumed.
- if ($busyTime['type'] === 'FREE') {
+ if ($busyType === 'FREE') {
continue;
}
@@ -583,7 +585,12 @@ class FreeBusyGenerator {
'FREEBUSY',
$busyTime[0]->format('Ymd\\THis\\Z') . '/' . $busyTime[1]->format('Ymd\\THis\\Z')
);
- $prop['FBTYPE'] = $busyTime['type'];
+
+ // Only setting FBTYPE if it's not BUSY, because BUSY is the
+ // default anyway.
+ if ($busyType !== 'BUSY') {
+ $prop['FBTYPE'] = $busyType;
+ }
$vfreebusy->add($prop);
}
diff --git a/tests/VObject/FreeBusyGeneratorTest.php b/tests/VObject/FreeBusyGeneratorTest.php
index fc457d3..58803ed 100644
--- a/tests/VObject/FreeBusyGeneratorTest.php
+++ b/tests/VObject/FreeBusyGeneratorTest.php
@@ -2,11 +2,86 @@
namespace Sabre\VObject;
-class FreeBusyGeneratorTest extends \PHPUnit_Framework_TestCase {
+class FreeBusyGeneratorTest extends TestCase {
- function getInput() {
+ function testGeneratorBaseObject() {
+
+ $obj = new Component\VCalendar();
+ $obj->METHOD = 'PUBLISH';
+
+ $gen = new FreeBusyGenerator();
+ $gen->setObjects([]);
+ $gen->setBaseObject($obj);
+
+ $result = $gen->getResult();
+
+ $this->assertEquals('PUBLISH', $result->METHOD->getValue());
+
+ }
+
+ /**
+ * @expectedException InvalidArgumentException
+ */
+ function testInvalidArg() {
+
+ $gen = new FreeBusyGenerator(
+ new \DateTime('2012-01-01'),
+ new \DateTime('2012-12-31'),
+ new \StdClass()
+ );
+
+ }
+
+ /**
+ * This function takes a list of objects (icalendar objects), and turns
+ * them into a freebusy report.
+ *
+ * Then it takes the expected output and compares it to what we actually
+ * got.
+ *
+ * It only generates the freebusy report for the following time-range:
+ * 2011-01-01 11:00:00 until 2011-01-03 11:11:11
+ *
+ * @param string $expected
+ * @param array $input
+ * @param string|null $timeZone
+ * @param string $vavailability
+ * @return void
+ */
+ function assertFreeBusyReport($expected, $input, $timeZone = null, $vavailability = null) {
+
+ $gen = new FreeBusyGenerator(
+ new \DateTime('20110101T110000Z', new \DateTimeZone('UTC')),
+ new \DateTime('20110103T110000Z', new \DateTimeZone('UTC')),
+ $input,
+ $timeZone
+ );
+
+ if ($vavailability) {
+ $gen->setVAvailability($vavailability);
+ }
- $tests = [];
+ $output = $gen->getResult();
+
+ // Removing DTSTAMP because it changes every time.
+ unset($output->VFREEBUSY->DTSTAMP);
+
+ $expected = <<<ICS
+BEGIN:VCALENDAR
+VERSION:2.0
+BEGIN:VFREEBUSY
+DTSTART:20110101T110000Z
+DTEND:20110103T110000Z
+$expected
+END:VFREEBUSY
+END:VCALENDAR
+ICS;
+
+ $this->assertVObjEquals($expected, $output);
+
+ }
+
+ function testSimple() {
$blob = <<<ICS
BEGIN:VCALENDAR
@@ -18,12 +93,19 @@ END:VEVENT
END:VCALENDAR
ICS;
- $tests[] = [
- $blob,
- "20110101T120000Z/20110101T130000Z"
- ];
- // opaque, shows up
+ $this->assertFreeBusyReport(
+ "FREEBUSY:20110101T120000Z/20110101T130000Z",
+ $blob
+ );
+
+ }
+
+ /**
+ * Testing TRANSP:OPAQUE
+ */
+ function testOpaque() {
+
$blob = <<<ICS
BEGIN:VCALENDAR
BEGIN:VEVENT
@@ -35,10 +117,17 @@ END:VEVENT
END:VCALENDAR
ICS;
- $tests[] = [
- $blob,
- "20110101T130000Z/20110101T140000Z"
- ];
+ $this->assertFreeBusyReport(
+ "FREEBUSY:20110101T130000Z/20110101T140000Z",
+ $blob
+ );
+
+ }
+
+ /**
+ * Testing TRANSP:TRANSPARENT
+ */
+ function testTransparent() {
// transparent, hidden
$blob = <<<ICS
@@ -52,12 +141,19 @@ END:VEVENT
END:VCALENDAR
ICS;
- $tests[] = [
- $blob,
- null,
- ];
+ $this->assertFreeBusyReport(
+ "",
+ $blob
+ );
+
+ }
+
+ /**
+ * Testing STATUS:CANCELLED
+ */
+ function testCancelled() {
- // cancelled, hidden
+ // transparent, hidden
$blob = <<<ICS
BEGIN:VCALENDAR
BEGIN:VEVENT
@@ -69,10 +165,17 @@ END:VEVENT
END:VCALENDAR
ICS;
- $tests[] = [
- $blob,
- null,
- ];
+ $this->assertFreeBusyReport(
+ "",
+ $blob
+ );
+
+ }
+
+ /**
+ * Testing STATUS:TENTATIVE
+ */
+ function testTentative() {
// tentative, shows up
$blob = <<<ICS
@@ -86,10 +189,17 @@ END:VEVENT
END:VCALENDAR
ICS;
- $tests[] = [
- $blob,
- '20110101T180000Z/20110101T190000Z',
- ];
+ $this->assertFreeBusyReport(
+ 'FREEBUSY;FBTYPE=BUSY-TENTATIVE:20110101T180000Z/20110101T190000Z',
+ $blob
+ );
+
+ }
+
+ /**
+ * Testing an event that falls outside of the report time-range.
+ */
+ function testOutsideTimeRange() {
// outside of time-range, hidden
$blob = <<<ICS
@@ -102,10 +212,17 @@ END:VEVENT
END:VCALENDAR
ICS;
- $tests[] = [
- $blob,
- null,
- ];
+ $this->assertFreeBusyReport(
+ '',
+ $blob
+ );
+
+ }
+
+ /**
+ * Testing an event that falls outside of the report time-range.
+ */
+ function testOutsideTimeRange2() {
// outside of time-range, hidden
$blob = <<<ICS
@@ -118,10 +235,17 @@ END:VEVENT
END:VCALENDAR
ICS;
- $tests[] = [
- $blob,
- null,
- ];
+ $this->assertFreeBusyReport(
+ '',
+ $blob
+ );
+
+ }
+
+ /**
+ * Testing an event that uses DURATION
+ */
+ function testDuration() {
// using duration, shows up
$blob = <<<ICS
@@ -134,10 +258,17 @@ END:VEVENT
END:VCALENDAR
ICS;
- $tests[] = [
- $blob,
- '20110101T190000Z/20110101T200000Z',
- ];
+ $this->assertFreeBusyReport(
+ 'FREEBUSY:20110101T190000Z/20110101T200000Z',
+ $blob
+ );
+
+ }
+
+ /**
+ * Testing an all-day event
+ */
+ function testAllDay() {
// Day-long event, shows up
$blob = <<<ICS
@@ -149,11 +280,17 @@ END:VEVENT
END:VCALENDAR
ICS;
- $tests[] = [
- $blob,
- '20110102T000000Z/20110103T000000Z',
- ];
+ $this->assertFreeBusyReport(
+ 'FREEBUSY:20110102T000000Z/20110103T000000Z',
+ $blob
+ );
+ }
+
+ /**
+ * Testing an event that has no end or duration.
+ */
+ function testNoDuration() {
// No duration, does not show up
$blob = <<<ICS
@@ -165,10 +302,17 @@ END:VEVENT
END:VCALENDAR
ICS;
- $tests[] = [
- $blob,
- null,
- ];
+ $this->assertFreeBusyReport(
+ '',
+ $blob
+ );
+
+ }
+
+ /**
+ * Testing feeding the freebusy generator an object instead of a string.
+ */
+ function testObject() {
// encoded as object, shows up
$blob = <<<ICS
@@ -181,10 +325,18 @@ END:VEVENT
END:VCALENDAR
ICS;
- $tests[] = [
- Reader::read($blob),
- '20110101T210000Z/20110101T220000Z',
- ];
+ $this->assertFreeBusyReport(
+ 'FREEBUSY:20110101T210000Z/20110101T220000Z',
+ Reader::read($blob)
+ );
+
+
+ }
+
+ /**
+ * Testing feeding VFREEBUSY objects instead of VEVENT
+ */
+ function testVFreeBusy() {
// Freebusy. Some parts show up
$blob = <<<ICS
@@ -199,14 +351,15 @@ END:VFREEBUSY
END:VCALENDAR
ICS;
- $tests[] = [
- Reader::read($blob),
- [
- '20110103T010000Z/20110103T020000Z',
- '20110103T030000Z/20110103T060000Z',
- ]
- ];
+ $this->assertFreeBusyReport(
+ 'FREEBUSY:20110103T010000Z/20110103T020000Z' . "\n" .
+ 'FREEBUSY:20110103T030000Z/20110103T060000Z',
+ $blob
+ );
+
+ }
+ function testYearlyRecurrence() {
// Yearly recurrence rule, shows up
$blob = <<<ICS
@@ -220,11 +373,14 @@ END:VEVENT
END:VCALENDAR
ICS;
- $tests[] = [
- Reader::read($blob),
- '20110101T220000Z/20110101T230000Z',
- ];
+ $this->assertFreeBusyReport(
+ 'FREEBUSY:20110101T220000Z/20110101T230000Z',
+ $blob
+ );
+ }
+
+ function testYearlyRecurrenceDuration() {
// Yearly recurrence rule + duration, shows up
$blob = <<<ICS
@@ -238,10 +394,14 @@ END:VEVENT
END:VCALENDAR
ICS;
- $tests[] = [
- Reader::read($blob),
- '20110101T230000Z/20110102T000000Z',
- ];
+ $this->assertFreeBusyReport(
+ 'FREEBUSY:20110101T230000Z/20110102T000000Z',
+ $blob
+ );
+
+ }
+
+ function testFloatingTime() {
// Floating time, no timezone
$blob = <<<ICS
@@ -254,10 +414,14 @@ END:VEVENT
END:VCALENDAR
ICS;
- $tests[] = [
- $blob,
- "20110101T120000Z/20110101T130000Z"
- ];
+ $this->assertFreeBusyReport(
+ "FREEBUSY:20110101T120000Z/20110101T130000Z",
+ $blob
+ );
+
+ }
+
+ function testFloatingTimeReferenceTimeZone() {
// Floating time + reference timezone
$blob = <<<ICS
@@ -270,11 +434,15 @@ END:VEVENT
END:VCALENDAR
ICS;
- $tests[] = [
+ $this->assertFreeBusyReport(
+ "FREEBUSY:20110101T170000Z/20110101T180000Z",
$blob,
- "20110101T170000Z/20110101T180000Z",
new \DateTimeZone('America/Toronto')
- ];
+ );
+
+ }
+
+ function testAllDay2() {
// All-day event, slightly outside of the VFREEBUSY range.
$blob = <<<ICS
@@ -286,10 +454,14 @@ END:VEVENT
END:VCALENDAR
ICS;
- $tests[] = [
- $blob,
- "20110101T110000Z/20110102T000000Z"
- ];
+ $this->assertFreeBusyReport(
+ "FREEBUSY:20110101T110000Z/20110102T000000Z",
+ $blob
+ );
+
+ }
+
+ function testAllDayReferenceTimeZone() {
// All-day event + reference timezone
$blob = <<<ICS
@@ -301,11 +473,15 @@ END:VEVENT
END:VCALENDAR
ICS;
- $tests[] = [
+ $this->assertFreeBusyReport(
+ "FREEBUSY:20110101T110000Z/20110102T050000Z",
$blob,
- "20110101T110000Z/20110102T050000Z",
new \DateTimeZone('America/Toronto')
- ];
+ );
+
+ }
+
+ function testNoValidInstances() {
// Recurrence rule with no valid instances
$blob = <<<ICS
@@ -320,76 +496,11 @@ END:VEVENT
END:VCALENDAR
ICS;
- $tests[] = [
- $blob,
- []
- ];
- return $tests;
-
- }
-
- /**
- * @dataProvider getInput
- */
- function testGenerator($input, $expected, $timeZone = null) {
-
- $gen = new FreeBusyGenerator(
- new \DateTime('20110101T110000Z', new \DateTimeZone('UTC')),
- new \DateTime('20110103T110000Z', new \DateTimeZone('UTC')),
- $input,
- $timeZone
- );
-
- $result = $gen->getResult();
- //print_r($result->serialize());die();
-
- $expected = (array)$expected;
-
- if ($input instanceof Document) $input = $input->serialize();
- $debugInfo = "Input:\n$input\n\nExpected:\n" . print_r($expected, true) . "\nActual result:\n" . $result->serialize() . "\n";
-
- $freebusy = $result->VFREEBUSY->select('FREEBUSY');
-
- foreach ($freebusy as $fb) {
-
- $this->assertContains((string)$fb, $expected, "$fb did not appear in our list of expected freebusy strings. This is concerning! Debug info:\n" . $debugInfo);
-
- $k = array_search((string)$fb, $expected);
- unset($expected[$k]);
-
- }
- $this->assertTrue(
- count($expected) === 0,
- 'There were elements in the expected array that were not found in the output: ' . "\n" . print_r($expected, true) . "\n" . $result->serialize()
+ $this->assertFreeBusyReport(
+ "",
+ $blob
);
- }
-
- function testGeneratorBaseObject() {
-
- $obj = new Component\VCalendar();
- $obj->METHOD = 'PUBLISH';
-
- $gen = new FreeBusyGenerator();
- $gen->setObjects([]);
- $gen->setBaseObject($obj);
-
- $result = $gen->getResult();
-
- $this->assertEquals('PUBLISH', $result->METHOD->getValue());
-
- }
-
- /**
- * @expectedException InvalidArgumentException
- */
- function testInvalidArg() {
-
- $gen = new FreeBusyGenerator(
- new \DateTime('2012-01-01'),
- new \DateTime('2012-12-31'),
- new \StdClass()
- );
}
--
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