JCardTest.php 5.8 KB

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