1<?php
2
3namespace Sabre\VObject;
4
5class JCalTest extends \PHPUnit_Framework_TestCase {
6
7    function testToJCal() {
8
9        $cal = new Component\VCalendar();
10
11        $event = $cal->add('VEVENT', array(
12            "UID" => "foo",
13            "DTSTART" => new \DateTime("2013-05-26 18:10:00Z"),
14            "DURATION" => "P1D",
15            "CATEGORIES" => array('home', 'testing'),
16            "CREATED" => new \DateTime("2013-05-26 18:10:00Z"),
17
18            "ATTENDEE" => "mailto:armin@example.org",
19            "GEO" => array(51.96668, 7.61876),
20            "SEQUENCE" => 5,
21            "FREEBUSY" => array("20130526T210213Z/PT1H", "20130626T120000Z/20130626T130000Z"),
22            "URL" => "http://example.org/",
23            "TZOFFSETFROM" => "+05:00",
24            "RRULE" => array('FREQ' => 'WEEKLY', 'BYDAY' => array('MO','TU')),
25        ));
26
27        // Modifying DTSTART to be a date-only.
28        $event->dtstart['VALUE'] = 'DATE';
29        $event->add("X-BOOL", true, array('VALUE' => 'BOOLEAN'));
30        $event->add("X-TIME", "08:00:00", array('VALUE' => 'TIME'));
31        $event->add("ATTACH", "attachment", array('VALUE' => 'BINARY'));
32        $event->add("ATTENDEE", "mailto:dominik@example.org", array("CN" => "Dominik", "PARTSTAT" => "DECLINED"));
33
34        $event->add('REQUEST-STATUS', array("2.0", "Success"));
35        $event->add('REQUEST-STATUS', array("3.7", "Invalid Calendar User", "ATTENDEE:mailto:jsmith@example.org"));
36
37        $event->add('DTEND', '20150108T133000');
38
39        $expected = array(
40            "vcalendar",
41            array(
42                array(
43                    "version",
44                    new \StdClass(),
45                    "text",
46                    "2.0"
47                ),
48                array(
49                    "prodid",
50                    new \StdClass(),
51                    "text",
52                    "-//Sabre//Sabre VObject " . Version::VERSION . "//EN",
53                ),
54                array(
55                    "calscale",
56                    new \StdClass(),
57                    "text",
58                    "GREGORIAN"
59                ),
60            ),
61            array(
62                array("vevent",
63                    array(
64                        array(
65                            "uid", new \StdClass(), "text", "foo",
66                        ),
67                        array(
68                            "dtstart", new \StdClass(), "date", "2013-05-26",
69                        ),
70                        array(
71                            "duration", new \StdClass(), "duration", "P1D",
72                        ),
73                        array(
74                            "categories", new \StdClass(), "text", "home", "testing",
75                        ),
76                        array(
77                            "created", new \StdClass(), "date-time", "2013-05-26T18:10:00Z",
78                        ),
79
80                        array(
81                            "attendee", new \StdClass(), "cal-address", "mailto:armin@example.org",
82                        ),
83                        array(
84                            "geo", new \StdClass(), "float", array(51.96668, 7.61876),
85                        ),
86                        array(
87                            "sequence", new \StdClass(), "integer", 5
88                        ),
89                        array(
90                            "freebusy", new \StdClass(), "period",  array("2013-05-26T21:02:13", "PT1H"), array("2013-06-26T12:00:00", "2013-06-26T13:00:00"),
91                        ),
92                        array(
93                            "url", new \StdClass(), "uri", "http://example.org/",
94                        ),
95                        array(
96                            "tzoffsetfrom", new \StdClass(), "utc-offset", "+05:00",
97                        ),
98                        array(
99                            "rrule", new \StdClass(), "recur", array(
100                                'freq' => 'WEEKLY',
101                                'byday' => array('MO', 'TU'),
102                            ),
103                        ),
104                        array(
105                            "x-bool", new \StdClass(), "boolean", true
106                        ),
107                        array(
108                            "x-time", new \StdClass(), "time", "08:00:00",
109                        ),
110                        array(
111                            "attach", new \StdClass(), "binary", base64_encode('attachment')
112                        ),
113                        array(
114                            "attendee",
115                            (object)array(
116                                "cn" => "Dominik",
117                                "partstat" => "DECLINED",
118                            ),
119                            "cal-address",
120                            "mailto:dominik@example.org"
121                        ),
122                        array(
123                            "request-status",
124                            new \StdClass(),
125                            "text",
126                            array("2.0", "Success"),
127                        ),
128                        array(
129                            "request-status",
130                            new \StdClass(),
131                            "text",
132                            array("3.7", "Invalid Calendar User", "ATTENDEE:mailto:jsmith@example.org"),
133                        ),
134                        array(
135                            'dtend',
136                            new \StdClass(),
137                            "date-time",
138                            "2015-01-08T13:30:00",
139                        ),
140                    ),
141                    array(),
142                )
143            ),
144        );
145
146        $this->assertEquals($expected, $cal->jsonSerialize());
147
148    }
149
150}
151