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