annotate vendor/sabre/vobject/tests/VObject/Parser/JsonTest.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\Parser;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
4
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
5 use
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
6 Sabre\VObject;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
7
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
8 class JsonTest 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 function testRoundTripJCard() {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
11
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
12 $input = array(
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
13 "vcard",
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
14 array(
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
15 array(
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
16 "version",
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
17 new \StdClass(),
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
18 "text",
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
19 "4.0"
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
20 ),
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
21 array(
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
22 "prodid",
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
23 new \StdClass(),
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
24 "text",
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
25 "-//Sabre//Sabre VObject " . VObject\Version::VERSION . "//EN",
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
26 ),
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
27 array(
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
28 "uid",
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
29 new \StdClass(),
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
30 "text",
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
31 "foo",
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
32 ),
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
33 array(
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
34 "bday",
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
35 new \StdClass(),
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
36 "date-and-or-time",
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
37 "1985-04-07",
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
38 ),
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
39 array(
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
40 "rev",
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
41 new \StdClass(),
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
42 "timestamp",
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
43 "1995-10-31T22:27:10Z",
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
44 ),
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
45 array(
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
46 "lang",
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
47 new \StdClass(),
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
48 "language-tag",
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
49 "nl",
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
50 ),
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
51 array(
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
52 "n",
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
53 new \StdClass(),
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
54 "text",
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
55 array("Last", "First", "Middle", "", ""),
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
56 ),
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
57 array(
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
58 "tel",
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
59 (object)array(
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
60 "group" => "item1",
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
61 ),
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
62 "text",
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
63 "+1 555 123456",
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
64 ),
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
65 array(
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
66 "x-ab-label",
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
67 (object)array(
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
68 "group" => "item1",
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
69 ),
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
70 "unknown",
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
71 "Walkie Talkie",
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
72 ),
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
73 array(
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
74 "adr",
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
75 new \StdClass(),
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
76 "text",
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
77 array(
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
78 "",
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
79 "",
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
80 array("My Street", "Left Side", "Second Shack"),
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
81 "Hometown",
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
82 "PA",
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
83 "18252",
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
84 "U.S.A",
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
85 ),
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
86 ),
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
87 array(
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
88 "bday",
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
89 (object)array(
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
90 'x-param' => array(1,2),
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
91 ),
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
92 "date",
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
93 "1979-12-25",
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
94 ),
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
95 array(
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
96 "bday",
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
97 new \StdClass(),
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
98 "date-time",
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
99 "1979-12-25T02:00:00",
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
100 ),
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
101 array(
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
102 "x-truncated",
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
103 new \StdClass(),
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
104 "date",
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
105 "--12-25",
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
106 ),
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
107 array(
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
108 "x-time-local",
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
109 new \StdClass(),
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
110 "time",
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
111 "12:30:00"
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
112 ),
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
113 array(
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
114 "x-time-utc",
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
115 new \StdClass(),
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
116 "time",
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
117 "12:30:00Z"
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
118 ),
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
119 array(
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
120 "x-time-offset",
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
121 new \StdClass(),
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
122 "time",
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
123 "12:30:00-08:00"
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
124 ),
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
125 array(
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
126 "x-time-reduced",
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
127 new \StdClass(),
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
128 "time",
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
129 "23"
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
130 ),
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
131 array(
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
132 "x-time-truncated",
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
133 new \StdClass(),
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
134 "time",
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
135 "--30"
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
136 ),
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
137 array(
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
138 "x-karma-points",
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
139 new \StdClass(),
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
140 "integer",
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
141 42
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
142 ),
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
143 array(
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
144 "x-grade",
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
145 new \StdClass(),
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
146 "float",
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
147 1.3
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
148 ),
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
149 array(
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
150 "tz",
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
151 new \StdClass(),
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
152 "utc-offset",
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
153 "-05:00",
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
154 ),
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
155 ),
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
156 );
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
157
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
158 $parser = new Json(json_encode($input));
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
159 $vobj = $parser->parse();
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
160
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
161 $version = VObject\Version::VERSION;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
162
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
163
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
164 $result = $vobj->serialize();
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
165 $expected = <<<VCF
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
166 BEGIN:VCARD
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
167 VERSION:4.0
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
168 PRODID:-//Sabre//Sabre VObject $version//EN
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
169 UID:foo
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
170 BDAY:1985-04-07
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
171 REV:1995-10-31T22:27:10Z
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
172 LANG:nl
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
173 N:Last;First;Middle;;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
174 item1.TEL:+1 555 123456
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
175 item1.X-AB-LABEL:Walkie Talkie
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
176 ADR:;;My Street,Left Side,Second Shack;Hometown;PA;18252;U.S.A
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
177 BDAY;X-PARAM=1,2;VALUE=DATE:1979-12-25
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
178 BDAY;VALUE=DATE-TIME:1979-12-25T02:00:00
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
179 X-TRUNCATED;VALUE=DATE:--12-25
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
180 X-TIME-LOCAL;VALUE=TIME:12:30:00
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
181 X-TIME-UTC;VALUE=TIME:12:30:00Z
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
182 X-TIME-OFFSET;VALUE=TIME:12:30:00-08:00
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
183 X-TIME-REDUCED;VALUE=TIME:23
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
184 X-TIME-TRUNCATED;VALUE=TIME:--30
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
185 X-KARMA-POINTS;VALUE=INTEGER:42
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
186 X-GRADE;VALUE=FLOAT:1.3
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
187 TZ;VALUE=UTC-OFFSET:-05:00
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
188 END:VCARD
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
189
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
190 VCF;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
191 $this->assertEquals($expected, str_replace("\r", "", $result));
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
192
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
193 $this->assertEquals(
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
194 $input,
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
195 $vobj->jsonSerialize()
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
196 );
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
197
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
198 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
199
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
200 function testRoundTripJCal() {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
201
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
202 $input = array(
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
203 "vcalendar",
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
204 array(
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
205 array(
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
206 "version",
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
207 new \StdClass(),
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
208 "text",
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
209 "2.0"
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
210 ),
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
211 array(
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
212 "prodid",
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
213 new \StdClass(),
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
214 "text",
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
215 "-//Sabre//Sabre VObject " . VObject\Version::VERSION . "//EN",
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
216 ),
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
217 array(
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
218 "calscale",
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
219 new \StdClass(),
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
220 "text",
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
221 "GREGORIAN"
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
222 ),
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
223 ),
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
224 array(
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
225 array("vevent",
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
226 array(
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
227 array(
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
228 "uid", new \StdClass(), "text", "foo",
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
229 ),
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
230 array(
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
231 "dtstart", new \StdClass(), "date", "2013-05-26",
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
232 ),
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
233 array(
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
234 "duration", new \StdClass(), "duration", "P1D",
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
235 ),
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
236 array(
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
237 "categories", new \StdClass(), "text", "home", "testing",
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
238 ),
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
239 array(
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
240 "created", new \StdClass(), "date-time", "2013-05-26T18:10:00Z",
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
241 ),
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
242 array(
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
243 "attach", new \StdClass(), "binary", base64_encode('attachment')
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
244 ),
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
245 array(
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
246 "attendee", new \StdClass(), "cal-address", "mailto:armin@example.org",
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
247 ),
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
248 array(
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
249 "geo", new \StdClass(), "float", array(51.96668, 7.61876),
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
250 ),
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
251 array(
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
252 "sequence", new \StdClass(), "integer", 5
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
253 ),
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
254 array(
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
255 "freebusy", new \StdClass(), "period", array("2013-05-26T21:02:13", "PT1H"), array("2013-06-26T12:00:00", "2013-06-26T13:00:00"),
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
256 ),
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
257 array(
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
258 "url", new \StdClass(), "uri", "http://example.org/",
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
259 ),
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
260 array(
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
261 "tzoffsetfrom", new \StdClass(), "utc-offset", "+05:00",
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
262 ),
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
263 array(
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
264 "rrule", new \StdClass(), "recur", array(
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
265 'freq' => 'WEEKLY',
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
266 'byday' => array('MO', 'TU'),
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
267 ),
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
268 ),
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
269 array(
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
270 "x-bool", new \StdClass(), "boolean", true
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
271 ),
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
272 array(
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
273 "x-time", new \StdClass(), "time", "08:00:00",
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
274 ),
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
275 array(
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
276 "attendee",
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
277 (object)array(
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
278 "cn" => "Dominik",
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
279 "partstat" => "DECLINED",
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
280 ),
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
281 "cal-address",
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
282 "mailto:dominik@example.org"
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
283 ),
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
284 array(
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
285 "request-status",
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
286 new \StdClass(),
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
287 "text",
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
288 array("2.0", "Success"),
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
289 ),
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
290 array(
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
291 "request-status",
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
292 new \StdClass(),
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
293 "text",
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
294 array("3.7", "Invalid Calendar User", "ATTENDEE:mailto:jsmith@example.org"),
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
295 ),
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
296 ),
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
297 array(
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
298 array("valarm",
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
299 array(
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
300 array(
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
301 "action", new \StdClass(), "text", "DISPLAY",
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
302 ),
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
303 ),
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
304 array(),
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
305 ),
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
306 ),
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
307 )
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
308 ),
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
309 );
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
310
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
311 $parser = new Json(json_encode($input));
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
312 $vobj = $parser->parse();
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
313 $result = $vobj->serialize();
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
314
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
315 $version = VObject\Version::VERSION;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
316
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
317 $expected = <<<VCF
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
318 BEGIN:VCALENDAR
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
319 VERSION:2.0
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
320 PRODID:-//Sabre//Sabre VObject $version//EN
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
321 CALSCALE:GREGORIAN
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
322 BEGIN:VEVENT
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
323 UID:foo
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
324 DTSTART;VALUE=DATE:20130526
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
325 DURATION:P1D
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
326 CATEGORIES:home,testing
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
327 CREATED:20130526T181000Z
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
328 ATTACH;VALUE=BINARY:YXR0YWNobWVudA==
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
329 ATTENDEE:mailto:armin@example.org
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
330 GEO:51.96668;7.61876
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
331 SEQUENCE:5
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
332 FREEBUSY:20130526T210213/PT1H,20130626T120000/20130626T130000
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
333 URL:http://example.org/
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
334 TZOFFSETFROM:+05:00
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
335 RRULE:FREQ=WEEKLY;BYDAY=MO,TU
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
336 X-BOOL;VALUE=BOOLEAN:TRUE
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
337 X-TIME;VALUE=TIME:08:00:00
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
338 ATTENDEE;CN=Dominik;PARTSTAT=DECLINED:mailto:dominik@example.org
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
339 REQUEST-STATUS:2.0;Success
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
340 REQUEST-STATUS:3.7;Invalid Calendar User;ATTENDEE:mailto:jsmith@example.org
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
341 BEGIN:VALARM
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
342 ACTION:DISPLAY
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
343 END:VALARM
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
344 END:VEVENT
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
345 END:VCALENDAR
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
346
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
347 VCF;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
348 $this->assertEquals($expected, str_replace("\r", "", $result));
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
349
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
350 $this->assertEquals(
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
351 $input,
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
352 $vobj->jsonSerialize()
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
353 );
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
354
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
355 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
356
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
357 function testParseStreamArg() {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
358
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
359 $input = array(
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
360 "vcard",
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
361 array(
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
362 array(
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
363 "FN", new \StdClass(), 'text', "foo",
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
364 ),
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
365 ),
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
366 );
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
367
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
368 $stream = fopen('php://memory','r+');
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
369 fwrite($stream, json_encode($input));
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
370 rewind($stream);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
371
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
372 $result = VObject\Reader::readJson($stream,0);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
373 $this->assertEquals('foo', $result->FN->getValue());
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
374
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
375 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
376
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
377 /**
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
378 * @expectedException \Sabre\VObject\ParseException
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
379 */
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
380 function testParseInvalidData() {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
381
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
382 $json = new Json();
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
383 $input = array(
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
384 "vlist",
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
385 array(
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
386 array(
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
387 "FN", new \StdClass(), 'text', "foo",
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
388 ),
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
389 ),
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
390 );
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
391
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
392 $json->parse(json_encode($input), 0);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
393
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
394 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
395 }