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