annotate vendor/sabre/vobject/tests/VObject/Component/VJournalTest.php @ 7:430dbd5346f7

vendor sabre as distributed
author Charlie Root
date Sat, 13 Jan 2018 09:06:10 -0500
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
1 <?php
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
2
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
3 namespace Sabre\VObject\Component;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
4
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
5 use Sabre\VObject\Component;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
6 use Sabre\VObject\Reader;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
7
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
8 class VJournalTest extends \PHPUnit_Framework_TestCase {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
9
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
10 /**
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
11 * @dataProvider timeRangeTestData
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
12 */
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
13 public function testInTimeRange(VJournal $vtodo,$start,$end,$outcome) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
14
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
15 $this->assertEquals($outcome, $vtodo->isInTimeRange($start, $end));
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
16
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
17 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
18
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
19 public function testValidate() {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
20
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
21 $input = <<<HI
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
22 BEGIN:VCALENDAR
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
23 VERSION:2.0
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
24 PRODID:YoYo
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
25 BEGIN:VJOURNAL
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
26 UID:12345678
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
27 DTSTAMP:20140402T174100Z
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
28 END:VJOURNAL
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
29 END:VCALENDAR
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
30 HI;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
31
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
32 $obj = Reader::read($input);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
33
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
34 $warnings = $obj->validate();
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
35 $messages = array();
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
36 foreach($warnings as $warning) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
37 $messages[] = $warning['message'];
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
38 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
39
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
40 $this->assertEquals(array(), $messages);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
41
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
42 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
43
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
44 public function testValidateBroken() {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
45
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
46 $input = <<<HI
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
47 BEGIN:VCALENDAR
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
48 VERSION:2.0
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
49 PRODID:YoYo
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
50 BEGIN:VJOURNAL
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
51 UID:12345678
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
52 DTSTAMP:20140402T174100Z
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
53 URL:http://example.org/
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
54 URL:http://example.com/
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
55 END:VJOURNAL
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
56 END:VCALENDAR
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
57 HI;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
58
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
59 $obj = Reader::read($input);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
60
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
61 $warnings = $obj->validate();
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
62 $messages = array();
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
63 foreach($warnings as $warning) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
64 $messages[] = $warning['message'];
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
65 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
66
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
67 $this->assertEquals(
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
68 array("URL MUST NOT appear more than once in a VJOURNAL component"),
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
69 $messages
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
70 );
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
71
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
72 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
73
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
74 public function timeRangeTestData() {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
75
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
76 $calendar = new VCalendar();
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
77
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
78 $tests = array();
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
79
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
80 $vjournal = $calendar->createComponent('VJOURNAL');
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
81 $vjournal->DTSTART = '20111223T120000Z';
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
82 $tests[] = array($vjournal, new \DateTime('2011-01-01'), new \DateTime('2012-01-01'), true);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
83 $tests[] = array($vjournal, new \DateTime('2011-01-01'), new \DateTime('2011-11-01'), false);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
84
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
85 $vjournal2 = $calendar->createComponent('VJOURNAL');
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
86 $vjournal2->DTSTART = '20111223';
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
87 $vjournal2->DTSTART['VALUE'] = 'DATE';
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
88 $tests[] = array($vjournal2, new \DateTime('2011-01-01'), new \DateTime('2012-01-01'), true);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
89 $tests[] = array($vjournal2, new \DateTime('2011-01-01'), new \DateTime('2011-11-01'), false);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
90
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
91 $vjournal3 = $calendar->createComponent('VJOURNAL');
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
92 $tests[] = array($vjournal3, new \DateTime('2011-01-01'), new \DateTime('2012-01-01'), false);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
93 $tests[] = array($vjournal3, new \DateTime('2011-01-01'), new \DateTime('2011-11-01'), false);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
94
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
95 return $tests;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
96 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
97
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
98
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
99
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
100 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
101