summaryrefslogtreecommitdiff
path: root/vendor/eluceo/ical/tests/Eluceo
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/eluceo/ical/tests/Eluceo')
-rw-r--r--vendor/eluceo/ical/tests/Eluceo/iCal/Component/CalendarIntegrationTest.php64
-rw-r--r--vendor/eluceo/ical/tests/Eluceo/iCal/ComponentTest.php45
-rw-r--r--vendor/eluceo/ical/tests/Eluceo/iCal/ParameterBagTest.php35
-rw-r--r--vendor/eluceo/ical/tests/Eluceo/iCal/Property/ArrayValueTest.php26
-rw-r--r--vendor/eluceo/ical/tests/Eluceo/iCal/Property/Event/DescriptionTest.php17
-rw-r--r--vendor/eluceo/ical/tests/Eluceo/iCal/Property/Event/OrganizerTest.php63
-rw-r--r--vendor/eluceo/ical/tests/Eluceo/iCal/Property/Event/RecurrenceRuleTest.php21
-rw-r--r--vendor/eluceo/ical/tests/Eluceo/iCal/Property/StringValueTest.php63
-rw-r--r--vendor/eluceo/ical/tests/Eluceo/iCal/PropertyBagTest.php18
-rw-r--r--vendor/eluceo/ical/tests/Eluceo/iCal/PropertyTest.php42
10 files changed, 394 insertions, 0 deletions
diff --git a/vendor/eluceo/ical/tests/Eluceo/iCal/Component/CalendarIntegrationTest.php b/vendor/eluceo/ical/tests/Eluceo/iCal/Component/CalendarIntegrationTest.php
new file mode 100644
index 00000000..eb869af8
--- /dev/null
+++ b/vendor/eluceo/ical/tests/Eluceo/iCal/Component/CalendarIntegrationTest.php
@@ -0,0 +1,64 @@
+<?php
+
+namespace Eluceo\iCal\Component;
+
+class CalendarIntegrationTest extends \PHPUnit_Framework_TestCase
+{
+ /**
+ * @coversNothing
+ */
+ public function testExample3()
+ {
+ $timeZone = new \DateTimeZone('Europe/Berlin');
+
+ // 1. Create new calendar
+ $vCalendar = new \Eluceo\iCal\Component\Calendar('www.example.com');
+
+ // 2. Create an event
+ $vEvent = new \Eluceo\iCal\Component\Event('123456');
+ $vEvent->setDtStart(new \DateTime('2012-12-31', $timeZone));
+ $vEvent->setDtEnd(new \DateTime('2012-12-31', $timeZone));
+ $vEvent->setNoTime(true);
+ $vEvent->setIsPrivate(true);
+ $vEvent->setSummary('New Year’s Eve');
+
+ // Set recurrence rule
+ $recurrenceRule = new \Eluceo\iCal\Property\Event\RecurrenceRule();
+ $recurrenceRule->setFreq(\Eluceo\iCal\Property\Event\RecurrenceRule::FREQ_YEARLY);
+ $recurrenceRule->setInterval(1);
+ $vEvent->setRecurrenceRule($recurrenceRule);
+
+ // Adding Timezone (optional)
+ $vEvent->setUseTimezone(true);
+
+ // 3. Add event to calendar
+ $vCalendar->addComponent($vEvent);
+
+ $lines = array(
+ '/BEGIN:VCALENDAR/',
+ '/VERSION:2\.0/',
+ '/PRODID:www\.example\.com/',
+ '/X-PUBLISHED-TTL:P1W/',
+ '/BEGIN:VEVENT/',
+ '/UID:123456/',
+ '/DTSTART;TZID=Europe\/Berlin;VALUE=DATE:20121231/',
+ '/SEQUENCE:0/',
+ '/TRANSP:OPAQUE/',
+ '/DTEND;TZID=Europe\/Berlin;VALUE=DATE:20121231/',
+ '/SUMMARY:New Year’s Eve/',
+ '/CLASS:PRIVATE/',
+ '/RRULE:FREQ=YEARLY;INTERVAL=1/',
+ '/X-MICROSOFT-CDO-ALLDAYEVENT:TRUE/',
+ '/DTSTAMP:20\d{6}T\d{6}Z/',
+ '/END:VEVENT/',
+ '/END:VCALENDAR/',
+ );
+
+ foreach (explode("\n", $vCalendar->render()) as $key => $line)
+ {
+ $this->assertTrue(isset($lines[$key]), 'Too many lines... ' . $line);
+
+ $this->assertRegExp($lines[$key], $line);
+ }
+ }
+}
diff --git a/vendor/eluceo/ical/tests/Eluceo/iCal/ComponentTest.php b/vendor/eluceo/ical/tests/Eluceo/iCal/ComponentTest.php
new file mode 100644
index 00000000..5cac7c5d
--- /dev/null
+++ b/vendor/eluceo/ical/tests/Eluceo/iCal/ComponentTest.php
@@ -0,0 +1,45 @@
+<?php
+
+namespace Eluceo\iCal;
+
+class ComponentTest extends \PHPUnit_Framework_TestCase
+{
+ public function testFoldWithMultibyte()
+ {
+ $input = "x" . str_repeat("あいうえお", 5);
+
+ $vCalendar = new \Eluceo\iCal\Component\Calendar('www.example.com');
+ $vEvent = new \Eluceo\iCal\Component\Event();
+ $vEvent->setDtStart(new \DateTime('2014-12-24'));
+ $vEvent->setDtEnd(new \DateTime('2014-12-24'));
+ $vEvent->setDescription($input);
+
+ $vAlarm = new \Eluceo\iCal\Component\Alarm;
+ $vAlarm->setAction(\Eluceo\iCal\Component\Alarm::ACTION_DISPLAY);
+ $vAlarm->setDescription($input);
+ $vAlarm->setTrigger('PT0S', true);
+ $vEvent->addComponent($vAlarm);
+
+ $vCalendar->addComponent($vEvent);
+
+ $output = $vCalendar->render();
+ $output = preg_replace('/\r\n /u', '', $output);
+ $this->assertContains($input, $output);
+ }
+
+ public function testDescriptionWithNewLines()
+ {
+ $input = "new string \n new line \n new line \n new string";
+
+ $vCalendar = new \Eluceo\iCal\Component\Calendar('www.example.com');
+ $vEvent = new \Eluceo\iCal\Component\Event();
+ $vEvent->setDtStart(new \DateTime('2014-12-24'));
+ $vEvent->setDtEnd(new \DateTime('2014-12-24'));
+ $vEvent->setDescription($input);
+
+ $vCalendar->addComponent($vEvent);
+
+ $output = $vCalendar->render();
+ $this->assertContains(str_replace("\n", "\\n", $input), $output);
+ }
+}
diff --git a/vendor/eluceo/ical/tests/Eluceo/iCal/ParameterBagTest.php b/vendor/eluceo/ical/tests/Eluceo/iCal/ParameterBagTest.php
new file mode 100644
index 00000000..0fb6e84c
--- /dev/null
+++ b/vendor/eluceo/ical/tests/Eluceo/iCal/ParameterBagTest.php
@@ -0,0 +1,35 @@
+<?php
+
+namespace Eluceo\iCal;
+
+class ParameterBagTest extends \PHPUnit_Framework_TestCase
+{
+ public function testEscapeParamValue()
+ {
+ $propertyObject = new ParameterBag;
+
+ $this->assertEquals(
+ 'test string',
+ $propertyObject->escapeParamValue('test string'),
+ 'No escaping necessary'
+ );
+
+ $this->assertEquals(
+ '"Containing \\"double-quotes\\""',
+ $propertyObject->escapeParamValue('Containing "double-quotes"'),
+ 'Text contains double quotes'
+ );
+
+ $this->assertEquals(
+ '"Containing forbidden chars like a ;"',
+ $propertyObject->escapeParamValue('Containing forbidden chars like a ;'),
+ 'Text with semicolon'
+ );
+
+ $this->assertEquals(
+ '"Containing forbidden chars like a :"',
+ $propertyObject->escapeParamValue('Containing forbidden chars like a :'),
+ 'Text with colon'
+ );
+ }
+}
diff --git a/vendor/eluceo/ical/tests/Eluceo/iCal/Property/ArrayValueTest.php b/vendor/eluceo/ical/tests/Eluceo/iCal/Property/ArrayValueTest.php
new file mode 100644
index 00000000..1d1b3331
--- /dev/null
+++ b/vendor/eluceo/ical/tests/Eluceo/iCal/Property/ArrayValueTest.php
@@ -0,0 +1,26 @@
+<?php
+
+namespace Eluceo\iCal\Property;
+
+class ArrayValueTest extends \PHPUnit_Framework_TestCase
+{
+ /**
+ * @dataProvider arrayValuesProvider
+ */
+ public function testArrayValue($values, $expectedOutput)
+ {
+ $arrayValue = new ArrayValue($values);
+
+ $this->assertEquals($expectedOutput, $arrayValue->getEscapedValue());
+ }
+
+ public function arrayValuesProvider()
+ {
+ return array(
+ array(array(), ''),
+ array(array('Lorem'), 'Lorem'),
+ array(array('Lorem', 'Ipsum'), 'Lorem,Ipsum'),
+ array(array('Lorem', '"doublequotes"'), 'Lorem,\"doublequotes\"'),
+ );
+ }
+}
diff --git a/vendor/eluceo/ical/tests/Eluceo/iCal/Property/Event/DescriptionTest.php b/vendor/eluceo/ical/tests/Eluceo/iCal/Property/Event/DescriptionTest.php
new file mode 100644
index 00000000..0ad16bcc
--- /dev/null
+++ b/vendor/eluceo/ical/tests/Eluceo/iCal/Property/Event/DescriptionTest.php
@@ -0,0 +1,17 @@
+<?php
+
+namespace Eluceo\iCal\Property\Event;
+
+class DescriptionTest extends \PHPUnit_Framework_TestCase
+{
+ public function testAllowsNewLines()
+ {
+ $testString = "New String \n New Line";
+ $description = new Description($testString);
+
+ $this->assertEquals(
+ str_replace("\n", "\\n", $testString),
+ $description->getEscapedValue()
+ );
+ }
+}
diff --git a/vendor/eluceo/ical/tests/Eluceo/iCal/Property/Event/OrganizerTest.php b/vendor/eluceo/ical/tests/Eluceo/iCal/Property/Event/OrganizerTest.php
new file mode 100644
index 00000000..71acdce9
--- /dev/null
+++ b/vendor/eluceo/ical/tests/Eluceo/iCal/Property/Event/OrganizerTest.php
@@ -0,0 +1,63 @@
+<?php
+/**
+ * Eluceo\iCal\Property\Event\OrganizerTest
+ *
+ * @author Giulio Troccoli <giulio@troccoli.it>
+ */
+
+namespace Eluceo\iCal\Property\Event;
+
+/**
+ * OrganizerTest
+ */
+class OrganizerTest extends \PHPUnit_Framework_TestCase
+{
+ public function testOrganizerValueOnly()
+ {
+ $value = "MAILTO:name.lastname@example.com";
+ $expected = "ORGANIZER:$value";
+
+ $vCalendar = $this->createCalendarWithOrganizer(
+ new \Eluceo\iCal\Property\Event\Organizer($value)
+ );
+
+ foreach (explode("\n", $vCalendar->render()) as $line)
+ {
+ if (preg_match('/^ORGANIZER[:;](.*)$/', $line)) {
+ $this->assertEquals($expected, trim($line));
+ }
+ }
+ }
+
+ public function testOrganizerValueAndParameter()
+ {
+ $value = "MAILTO:name.lastname@example.com";
+ $param = "Name LastName";
+ $expected = "ORGANIZER;CN=$param:$value";
+
+ $vCalendar = $this->createCalendarWithOrganizer(
+ new \Eluceo\iCal\Property\Event\Organizer($value, array('CN' => $param))
+ );
+
+ foreach (explode("\n", $vCalendar->render()) as $line)
+ {
+ if (preg_match('/^ORGANIZER[:;](.*)$/', $line)) {
+ $this->assertEquals($expected, trim($line));
+ }
+ }
+
+ }
+
+ /**
+ * @param Organizer $vOrganizer
+ * @return \Eluceo\iCal\Component\Calendar
+ */
+ private function createCalendarWithOrganizer(\Eluceo\iCal\Property\Event\Organizer $vOrganizer)
+ {
+ $vCalendar = new \Eluceo\iCal\Component\Calendar('www.example.com');
+ $vEvent = new \Eluceo\iCal\Component\Event('123456');
+ $vEvent->setOrganizer($vOrganizer);
+ $vCalendar->addComponent($vEvent);
+ return $vCalendar;
+ }
+}
diff --git a/vendor/eluceo/ical/tests/Eluceo/iCal/Property/Event/RecurrenceRuleTest.php b/vendor/eluceo/ical/tests/Eluceo/iCal/Property/Event/RecurrenceRuleTest.php
new file mode 100644
index 00000000..a44b2580
--- /dev/null
+++ b/vendor/eluceo/ical/tests/Eluceo/iCal/Property/Event/RecurrenceRuleTest.php
@@ -0,0 +1,21 @@
+<?php
+
+namespace Eluceo\iCal\Property\Event;
+
+class RecurrenceRuleTest extends \PHPUnit_Framework_TestCase
+{
+ /**
+ * Example taken from http://www.kanzaki.com/docs/ical/rrule.html
+ */
+ public function testUntil()
+ {
+ $rule = new RecurrenceRule();
+ $rule->setFreq(RecurrenceRule::FREQ_DAILY);
+ $rule->setInterval(null);
+ $rule->setUntil(new \DateTime('1997-12-24'));
+ $this->assertEquals(
+ 'FREQ=DAILY;UNTIL=19971224T000000Z',
+ $rule->getEscapedValue()
+ );
+ }
+}
diff --git a/vendor/eluceo/ical/tests/Eluceo/iCal/Property/StringValueTest.php b/vendor/eluceo/ical/tests/Eluceo/iCal/Property/StringValueTest.php
new file mode 100644
index 00000000..afa70df1
--- /dev/null
+++ b/vendor/eluceo/ical/tests/Eluceo/iCal/Property/StringValueTest.php
@@ -0,0 +1,63 @@
+<?php
+
+namespace Eluceo\iCal\Property;
+
+use Eluceo\iCal\Property\StringValue;
+
+class StringValueTest extends \PHPUnit_Framework_TestCase
+{
+ public function testNoEscapeNeeded()
+ {
+ $stringValue = new StringValue('LOREM');
+
+ $this->assertEquals(
+ 'LOREM',
+ $stringValue->getEscapedValue(),
+ 'No escaping necessary'
+ );
+ }
+
+ public function testValueContainsBackslash()
+ {
+ $stringValue = new StringValue('text contains backslash: \\');
+
+ $this->assertEquals(
+ 'text contains backslash: \\\\',
+ $stringValue->getEscapedValue(),
+ 'Text contains backslash'
+ );
+ }
+
+ public function testEscapingDoubleQuotes()
+ {
+ $stringValue = new StringValue('text with "doublequotes" will be escaped');
+
+ $this->assertEquals(
+ 'text with \\"doublequotes\\" will be escaped',
+ $stringValue->getEscapedValue(),
+ 'Escaping double quotes'
+ );
+ }
+
+ public function testEscapingSemicolonAndComma()
+ {
+ $stringValue = new StringValue('text with , and ; will also be escaped');
+
+ $this->assertEquals(
+ 'text with \\, and \\; will also be escaped',
+ $stringValue->getEscapedValue(),
+ 'Escaping ; and ,'
+ );
+ }
+
+ public function testNewLineEscaping()
+ {
+ $stringValue = new StringValue("Text with new\n line");
+
+ $this->assertEquals(
+ 'Text with new\\n line',
+ $stringValue->getEscapedValue(),
+ 'Escape new line to text'
+ );
+ }
+}
diff --git a/vendor/eluceo/ical/tests/Eluceo/iCal/PropertyBagTest.php b/vendor/eluceo/ical/tests/Eluceo/iCal/PropertyBagTest.php
new file mode 100644
index 00000000..a7f8d8ce
--- /dev/null
+++ b/vendor/eluceo/ical/tests/Eluceo/iCal/PropertyBagTest.php
@@ -0,0 +1,18 @@
+<?php
+
+namespace Eluceo\iCal;
+
+class PropertyBagTest extends \PHPUnit_Framework_TestCase
+{
+ /**
+ * @todo Use Mocks instead of a real object!
+ */
+ public function testPropertyAlreadyExistsOnAddingProperty()
+ {
+ $this->setExpectedException('\\Exception', "Property with name 'propName' already exists");
+
+ $propertyBag = new PropertyBag();
+ $propertyBag->add(new Property('propName', ''));
+ $propertyBag->add(new Property('propName', ''));
+ }
+}
diff --git a/vendor/eluceo/ical/tests/Eluceo/iCal/PropertyTest.php b/vendor/eluceo/ical/tests/Eluceo/iCal/PropertyTest.php
new file mode 100644
index 00000000..b30f5a3a
--- /dev/null
+++ b/vendor/eluceo/ical/tests/Eluceo/iCal/PropertyTest.php
@@ -0,0 +1,42 @@
+<?php
+
+namespace Eluceo\iCal;
+
+class PropertyTest extends \PHPUnit_Framework_TestCase
+{
+ public function testPropertyWithSingleValue()
+ {
+ $property = new Property('DTSTAMP', '20131020T153112');
+ $this->assertEquals(
+ 'DTSTAMP:20131020T153112',
+ $property->toLine()
+ );
+ }
+
+ public function testPropertyWithValueAndParams()
+ {
+ $property = new Property('DTSTAMP', '20131020T153112', array('TZID' => 'Europe/Berlin'));
+ $this->assertEquals(
+ 'DTSTAMP;TZID=Europe/Berlin:20131020T153112',
+ $property->toLine()
+ );
+ }
+
+ public function testPropertyWithEscapedSingleValue()
+ {
+ $property = new Property('SOMEPROP', 'Escape me!"');
+ $this->assertEquals(
+ 'SOMEPROP:Escape me!\\"',
+ $property->toLine()
+ );
+ }
+
+ public function testPropertyWithEscapedValues()
+ {
+ $property = new Property('SOMEPROP', 'Escape me!"', array('TEST' => 'Lorem "test" ipsum'));
+ $this->assertEquals(
+ 'SOMEPROP;TEST="Lorem \\"test\\" ipsum":Escape me!\\"',
+ $property->toLine()
+ );
+ }
+}