1<?php
2
3namespace Sabre\VObject;
4
5class JCardTest extends \PHPUnit_Framework_TestCase {
6
7    function testToJCard() {
8
9        $card = new Component\VCard(array(
10            "VERSION" => "4.0",
11            "UID" => "foo",
12            "BDAY" => "19850407",
13            "REV"  => "19951031T222710Z",
14            "LANG" => "nl",
15            "N" => array("Last", "First", "Middle", "", ""),
16            "item1.TEL" => "+1 555 123456",
17            "item1.X-AB-LABEL" => "Walkie Talkie",
18            "ADR" => array(
19                "",
20                "",
21                array("My Street", "Left Side", "Second Shack"),
22                "Hometown",
23                "PA",
24                "18252",
25                "U.S.A",
26            ),
27        ));
28
29        $card->add('BDAY', '1979-12-25', array('VALUE' => 'DATE', 'X-PARAM' => array(1,2)));
30        $card->add('BDAY', '1979-12-25T02:00:00', array('VALUE' => 'DATE-TIME'));
31
32
33        $card->add('X-TRUNCATED', '--1225', array('VALUE' => 'DATE'));
34        $card->add('X-TIME-LOCAL', '123000', array('VALUE' => 'TIME'));
35        $card->add('X-TIME-UTC', '12:30:00Z', array('VALUE' => 'TIME'));
36        $card->add('X-TIME-OFFSET', '12:30:00-08:00', array('VALUE' => 'TIME'));
37        $card->add('X-TIME-REDUCED', '23', array('VALUE' => 'TIME'));
38        $card->add('X-TIME-TRUNCATED', '--30', array('VALUE' => 'TIME'));
39
40        $card->add('X-KARMA-POINTS', '42', array('VALUE' => 'INTEGER'));
41        $card->add('X-GRADE', '1.3', array('VALUE' => 'FLOAT'));
42
43        $card->add('TZ', '-05:00', array('VALUE' => 'UTC-OFFSET'));
44
45        $expected = array(
46            "vcard",
47            array(
48                array(
49                    "version",
50                    new \StdClass(),
51                    "text",
52                    "4.0"
53                ),
54                array(
55                    "prodid",
56                    new \StdClass(),
57                    "text",
58                    "-//Sabre//Sabre VObject " . Version::VERSION . "//EN",
59                ),
60                array(
61                    "uid",
62                    new \StdClass(),
63                    "text",
64                    "foo",
65                ),
66                array(
67                    "bday",
68                    new \StdClass(),
69                    "date-and-or-time",
70                    "1985-04-07",
71                ),
72                array(
73                    "rev",
74                    new \StdClass(),
75                    "timestamp",
76                    "1995-10-31T22:27:10Z",
77                ),
78                array(
79                    "lang",
80                    new \StdClass(),
81                    "language-tag",
82                    "nl",
83                ),
84                array(
85                    "n",
86                    new \StdClass(),
87                    "text",
88                    array("Last", "First", "Middle", "", ""),
89                ),
90                array(
91                    "tel",
92                    (object)array(
93                        "group" => "item1",
94                    ),
95                    "text",
96                    "+1 555 123456",
97                ),
98                array(
99                    "x-ab-label",
100                    (object)array(
101                        "group" => "item1",
102                    ),
103                    "unknown",
104                    "Walkie Talkie",
105                ),
106                array(
107                    "adr",
108                    new \StdClass(),
109                    "text",
110                        array(
111                            "",
112                            "",
113                            array("My Street", "Left Side", "Second Shack"),
114                            "Hometown",
115                            "PA",
116                            "18252",
117                            "U.S.A",
118                        ),
119                ),
120                array(
121                    "bday",
122                    (object)array(
123                        'x-param' => array(1,2),
124                    ),
125                    "date",
126                    "1979-12-25",
127                ),
128                array(
129                    "bday",
130                    new \StdClass(),
131                    "date-time",
132                    "1979-12-25T02:00:00",
133                ),
134                array(
135                    "x-truncated",
136                    new \StdClass(),
137                    "date",
138                    "--12-25",
139                ),
140                array(
141                    "x-time-local",
142                    new \StdClass(),
143                    "time",
144                    "12:30:00"
145                ),
146                array(
147                    "x-time-utc",
148                    new \StdClass(),
149                    "time",
150                    "12:30:00Z"
151                ),
152                array(
153                    "x-time-offset",
154                    new \StdClass(),
155                    "time",
156                    "12:30:00-08:00"
157                ),
158                array(
159                    "x-time-reduced",
160                    new \StdClass(),
161                    "time",
162                    "23"
163                ),
164                array(
165                    "x-time-truncated",
166                    new \StdClass(),
167                    "time",
168                    "--30"
169                ),
170                array(
171                    "x-karma-points",
172                    new \StdClass(),
173                    "integer",
174                    42
175                ),
176                array(
177                    "x-grade",
178                    new \StdClass(),
179                    "float",
180                    1.3
181                ),
182                array(
183                    "tz",
184                    new \StdClass(),
185                    "utc-offset",
186                    "-05:00",
187                ),
188            ),
189        );
190
191        $this->assertEquals($expected, $card->jsonSerialize());
192
193    }
194
195}
196