JCalTest.php 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. <?php
  2. namespace Sabre\VObject;
  3. class JCalTest extends \PHPUnit_Framework_TestCase {
  4. function testToJCal() {
  5. $cal = new Component\VCalendar();
  6. $event = $cal->add('VEVENT', array(
  7. "UID" => "foo",
  8. "DTSTART" => new \DateTime("2013-05-26 18:10:00Z"),
  9. "DURATION" => "P1D",
  10. "CATEGORIES" => array('home', 'testing'),
  11. "CREATED" => new \DateTime("2013-05-26 18:10:00Z"),
  12. "ATTENDEE" => "mailto:armin@example.org",
  13. "GEO" => array(51.96668, 7.61876),
  14. "SEQUENCE" => 5,
  15. "FREEBUSY" => array("20130526T210213Z/PT1H", "20130626T120000Z/20130626T130000Z"),
  16. "URL" => "http://example.org/",
  17. "TZOFFSETFROM" => "+05:00",
  18. "RRULE" => array('FREQ' => 'WEEKLY', 'BYDAY' => array('MO','TU')),
  19. ));
  20. // Modifying DTSTART to be a date-only.
  21. $event->dtstart['VALUE'] = 'DATE';
  22. $event->add("X-BOOL", true, array('VALUE' => 'BOOLEAN'));
  23. $event->add("X-TIME", "08:00:00", array('VALUE' => 'TIME'));
  24. $event->add("ATTACH", "attachment", array('VALUE' => 'BINARY'));
  25. $event->add("ATTENDEE", "mailto:dominik@example.org", array("CN" => "Dominik", "PARTSTAT" => "DECLINED"));
  26. $event->add('REQUEST-STATUS', array("2.0", "Success"));
  27. $event->add('REQUEST-STATUS', array("3.7", "Invalid Calendar User", "ATTENDEE:mailto:jsmith@example.org"));
  28. $event->add('DTEND', '20150108T133000');
  29. $expected = array(
  30. "vcalendar",
  31. array(
  32. array(
  33. "version",
  34. new \StdClass(),
  35. "text",
  36. "2.0"
  37. ),
  38. array(
  39. "prodid",
  40. new \StdClass(),
  41. "text",
  42. "-//Sabre//Sabre VObject " . Version::VERSION . "//EN",
  43. ),
  44. array(
  45. "calscale",
  46. new \StdClass(),
  47. "text",
  48. "GREGORIAN"
  49. ),
  50. ),
  51. array(
  52. array("vevent",
  53. array(
  54. array(
  55. "uid", new \StdClass(), "text", "foo",
  56. ),
  57. array(
  58. "dtstart", new \StdClass(), "date", "2013-05-26",
  59. ),
  60. array(
  61. "duration", new \StdClass(), "duration", "P1D",
  62. ),
  63. array(
  64. "categories", new \StdClass(), "text", "home", "testing",
  65. ),
  66. array(
  67. "created", new \StdClass(), "date-time", "2013-05-26T18:10:00Z",
  68. ),
  69. array(
  70. "attendee", new \StdClass(), "cal-address", "mailto:armin@example.org",
  71. ),
  72. array(
  73. "geo", new \StdClass(), "float", array(51.96668, 7.61876),
  74. ),
  75. array(
  76. "sequence", new \StdClass(), "integer", 5
  77. ),
  78. array(
  79. "freebusy", new \StdClass(), "period", array("2013-05-26T21:02:13", "PT1H"), array("2013-06-26T12:00:00", "2013-06-26T13:00:00"),
  80. ),
  81. array(
  82. "url", new \StdClass(), "uri", "http://example.org/",
  83. ),
  84. array(
  85. "tzoffsetfrom", new \StdClass(), "utc-offset", "+05:00",
  86. ),
  87. array(
  88. "rrule", new \StdClass(), "recur", array(
  89. 'freq' => 'WEEKLY',
  90. 'byday' => array('MO', 'TU'),
  91. ),
  92. ),
  93. array(
  94. "x-bool", new \StdClass(), "boolean", true
  95. ),
  96. array(
  97. "x-time", new \StdClass(), "time", "08:00:00",
  98. ),
  99. array(
  100. "attach", new \StdClass(), "binary", base64_encode('attachment')
  101. ),
  102. array(
  103. "attendee",
  104. (object)array(
  105. "cn" => "Dominik",
  106. "partstat" => "DECLINED",
  107. ),
  108. "cal-address",
  109. "mailto:dominik@example.org"
  110. ),
  111. array(
  112. "request-status",
  113. new \StdClass(),
  114. "text",
  115. array("2.0", "Success"),
  116. ),
  117. array(
  118. "request-status",
  119. new \StdClass(),
  120. "text",
  121. array("3.7", "Invalid Calendar User", "ATTENDEE:mailto:jsmith@example.org"),
  122. ),
  123. array(
  124. 'dtend',
  125. new \StdClass(),
  126. "date-time",
  127. "2015-01-08T13:30:00",
  128. ),
  129. ),
  130. array(),
  131. )
  132. ),
  133. );
  134. $this->assertEquals($expected, $cal->jsonSerialize());
  135. }
  136. }