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