function testEncode() { $card = new Component\VCard(); $card->add('N', array('van der Harten', array('Rene', 'J.'), "", 'Sir', 'R.D.O.N.'), array('SORT-AS' => array('Harten', 'Rene'))); $expected = implode("\r\n", array("BEGIN:VCARD", "VERSION:3.0", "PRODID:-//Sabre//Sabre VObject " . Version::VERSION . '//EN', "N;SORT-AS=Harten,Rene:van der Harten;Rene,J.;;Sir;R.D.O.N.", "END:VCARD", "")); $this->assertEquals($expected, $card->serialize()); }
function testVCard21Parameter() { $vcard = new Component\VCard(array(), false); $vcard->VERSION = '2.1'; $vcard->PHOTO = 'random_stuff'; $vcard->PHOTO->add(null, 'BASE64'); $vcard->UID = 'foo-bar'; $result = $vcard->serialize(); $expected = array("BEGIN:VCARD", "VERSION:2.1", "PHOTO;BASE64:" . base64_encode('random_stuff'), "UID:foo-bar", "END:VCARD", ""); $this->assertEquals(implode("\r\n", $expected), $result); }
function testToJCard() { $card = new Component\VCard(array("VERSION" => "4.0", "UID" => "foo", "BDAY" => "19850407", "REV" => "19951031T222710Z", "LANG" => "nl", "N" => array("Last", "First", "Middle", "", ""), "item1.TEL" => "+1 555 123456", "item1.X-AB-LABEL" => "Walkie Talkie", "ADR" => array("", "", array("My Street", "Left Side", "Second Shack"), "Hometown", "PA", "18252", "U.S.A"))); $card->add('BDAY', '1979-12-25', array('VALUE' => 'DATE', 'X-PARAM' => array(1, 2))); $card->add('BDAY', '1979-12-25T02:00:00', array('VALUE' => 'DATE-TIME')); $card->add('X-TRUNCATED', '--1225', array('VALUE' => 'DATE')); $card->add('X-TIME-LOCAL', '123000', array('VALUE' => 'TIME')); $card->add('X-TIME-UTC', '12:30:00Z', array('VALUE' => 'TIME')); $card->add('X-TIME-OFFSET', '12:30:00-08:00', array('VALUE' => 'TIME')); $card->add('X-TIME-REDUCED', '23', array('VALUE' => 'TIME')); $card->add('X-TIME-TRUNCATED', '--30', array('VALUE' => 'TIME')); $card->add('X-KARMA-POINTS', '42', array('VALUE' => 'INTEGER')); $card->add('X-GRADE', '1.3', array('VALUE' => 'FLOAT')); $card->add('TZ', '-05:00', array('VALUE' => 'UTC-OFFSET')); $expected = array("vcard", array(array("version", new \StdClass(), "text", "4.0"), array("prodid", new \StdClass(), "text", "-//Sabre//Sabre VObject " . Version::VERSION . "//EN"), array("uid", new \StdClass(), "text", "foo"), array("bday", new \StdClass(), "date-and-or-time", "1985-04-07"), array("rev", new \StdClass(), "timestamp", "1995-10-31T22:27:10Z"), array("lang", new \StdClass(), "language-tag", "nl"), array("n", new \StdClass(), "text", array("Last", "First", "Middle", "", "")), array("tel", (object) array("group" => "item1"), "text", "+1 555 123456"), array("x-ab-label", (object) array("group" => "item1"), "unknown", "Walkie Talkie"), array("adr", new \StdClass(), "text", array("", "", array("My Street", "Left Side", "Second Shack"), "Hometown", "PA", "18252", "U.S.A")), array("bday", (object) array('x-param' => array(1, 2)), "date", "1979-12-25"), array("bday", new \StdClass(), "date-time", "1979-12-25T02:00:00"), array("x-truncated", new \StdClass(), "date", "--12-25"), array("x-time-local", new \StdClass(), "time", "12:30:00"), array("x-time-utc", new \StdClass(), "time", "12:30:00Z"), array("x-time-offset", new \StdClass(), "time", "12:30:00-08:00"), array("x-time-reduced", new \StdClass(), "time", "23"), array("x-time-truncated", new \StdClass(), "time", "--30"), array("x-karma-points", new \StdClass(), "integer", 42), array("x-grade", new \StdClass(), "float", 1.3), array("tz", new \StdClass(), "utc-offset", "-05:00"))); $this->assertEquals($expected, $card->jsonSerialize()); }
/** * Converts a URI property to a BINARY property. * * In vCard 4.0 attachments are encoded as data: uri. Even though these may * be valid in vCard 3.0 as well, we should convert those to BINARY if * possible, to improve compatibility. * * @param Component\VCard $output * @param Property\Uri $property The input property. * @param $parameters List of parameters that will eventually be added to * the new property. * @return Property\Binary|null */ protected function convertUriToBinary(Component\VCard $output, Property\Uri $newProperty, array &$parameters) { $value = $newProperty->getValue(); // Only converting data: uris if (substr($value, 0, 5) !== 'data:') { return $newProperty; } $newProperty = $output->createProperty($newProperty->name, null, array(), 'BINARY'); $mimeType = substr($value, 5, strpos($value, ',') - 5); if (strpos($mimeType, ';')) { $mimeType = substr($mimeType, 0, strpos($mimeType, ';')); $newProperty->setValue(base64_decode(substr($value, strpos($value, ',') + 1))); } else { $newProperty->setValue(substr($value, strpos($value, ',') + 1)); } unset($value); $newProperty['ENCODING'] = 'b'; switch ($mimeType) { case 'image/jpeg': $newProperty['TYPE'] = 'JPEG'; break; case 'image/png': $newProperty['TYPE'] = 'PNG'; break; case 'image/gif': $newProperty['TYPE'] = 'GIF'; break; } return $newProperty; }