JCalTest.php 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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. $expected = array(
  29. "vcalendar",
  30. array(
  31. array(
  32. "version",
  33. new \StdClass(),
  34. "text",
  35. "2.0"
  36. ),
  37. array(
  38. "prodid",
  39. new \StdClass(),
  40. "text",
  41. "-//Sabre//Sabre VObject " . Version::VERSION . "//EN",
  42. ),
  43. array(
  44. "calscale",
  45. new \StdClass(),
  46. "text",
  47. "GREGORIAN"
  48. ),
  49. ),
  50. array(
  51. array("vevent",
  52. array(
  53. array(
  54. "uid", new \StdClass(), "text", "foo",
  55. ),
  56. array(
  57. "dtstart", new \StdClass(), "date", "2013-05-26",
  58. ),
  59. array(
  60. "duration", new \StdClass(), "duration", "P1D",
  61. ),
  62. array(
  63. "categories", new \StdClass(), "text", "home", "testing",
  64. ),
  65. array(
  66. "created", new \StdClass(), "date-time", "2013-05-26T18:10:00Z",
  67. ),
  68. array(
  69. "attendee", new \StdClass(), "cal-address", "mailto:armin@example.org",
  70. ),
  71. array(
  72. "geo", new \StdClass(), "float", array(51.96668, 7.61876),
  73. ),
  74. array(
  75. "sequence", new \StdClass(), "integer", 5
  76. ),
  77. array(
  78. "freebusy", new \StdClass(), "period", array("2013-05-26T21:02:13", "PT1H"), array("2013-06-26T12:00:00", "2013-06-26T13:00:00"),
  79. ),
  80. array(
  81. "url", new \StdClass(), "uri", "http://example.org/",
  82. ),
  83. array(
  84. "tzoffsetfrom", new \StdClass(), "utc-offset", "+05:00",
  85. ),
  86. array(
  87. "rrule", new \StdClass(), "recur", array(
  88. 'freq' => 'WEEKLY',
  89. 'byday' => array('MO', 'TU'),
  90. ),
  91. ),
  92. array(
  93. "x-bool", new \StdClass(), "boolean", true
  94. ),
  95. array(
  96. "x-time", new \StdClass(), "time", "08:00:00",
  97. ),
  98. array(
  99. "attach", new \StdClass(), "binary", base64_encode('attachment')
  100. ),
  101. array(
  102. "attendee",
  103. (object)array(
  104. "cn" => "Dominik",
  105. "partstat" => "DECLINED",
  106. ),
  107. "cal-address",
  108. "mailto:dominik@example.org"
  109. ),
  110. array(
  111. "request-status",
  112. new \StdClass(),
  113. "text",
  114. array("2.0", "Success"),
  115. ),
  116. array(
  117. "request-status",
  118. new \StdClass(),
  119. "text",
  120. array("3.7", "Invalid Calendar User", "ATTENDEE:mailto:jsmith@example.org"),
  121. ),
  122. ),
  123. array(),
  124. )
  125. ),
  126. );
  127. $this->assertEquals($expected, $cal->jsonSerialize());
  128. }
  129. }