ExpandFloatingTimesTest.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. <?php
  2. namespace Sabre\VObject\Recur\EventIterator;
  3. use
  4. DateTime,
  5. DateTimeZone,
  6. Sabre\VObject\Reader;
  7. class ExpandFloatingTimesTest extends \PHPUnit_Framework_TestCase {
  8. function testExpand() {
  9. $input = <<<ICS
  10. BEGIN:VCALENDAR
  11. VERSION:2.0
  12. BEGIN:VEVENT
  13. UID:foo
  14. DTSTART:20150109T090000
  15. DTEND:20150109T100000
  16. RRULE:FREQ=WEEKLY;INTERVAL=1;UNTIL=20191002T070000Z;BYDAY=FR
  17. END:VEVENT
  18. END:VCALENDAR
  19. ICS;
  20. $vcal = Reader::read($input);
  21. $this->assertInstanceOf('Sabre\\VObject\\Component\\VCalendar', $vcal);
  22. $vcal->expand(new DateTime('2015-01-01'), new DateTime('2015-01-31'));
  23. $result = $vcal->serialize();
  24. $output = <<<ICS
  25. BEGIN:VCALENDAR
  26. VERSION:2.0
  27. BEGIN:VEVENT
  28. UID:foo
  29. DTSTART:20150109T090000Z
  30. DTEND:20150109T100000Z
  31. RECURRENCE-ID:20150109T090000Z
  32. END:VEVENT
  33. BEGIN:VEVENT
  34. UID:foo
  35. DTSTART:20150116T090000Z
  36. DTEND:20150116T100000Z
  37. RECURRENCE-ID:20150116T090000Z
  38. END:VEVENT
  39. BEGIN:VEVENT
  40. UID:foo
  41. DTSTART:20150123T090000Z
  42. DTEND:20150123T100000Z
  43. RECURRENCE-ID:20150123T090000Z
  44. END:VEVENT
  45. BEGIN:VEVENT
  46. UID:foo
  47. DTSTART:20150130T090000Z
  48. DTEND:20150130T100000Z
  49. RECURRENCE-ID:20150130T090000Z
  50. END:VEVENT
  51. END:VCALENDAR
  52. ICS;
  53. $this->assertEquals($output, str_replace("\r", "", $result));
  54. }
  55. function testExpandWithReferenceTimezone() {
  56. $input = <<<ICS
  57. BEGIN:VCALENDAR
  58. VERSION:2.0
  59. BEGIN:VEVENT
  60. UID:foo
  61. DTSTART:20150109T090000
  62. DTEND:20150109T100000
  63. RRULE:FREQ=WEEKLY;INTERVAL=1;UNTIL=20191002T070000Z;BYDAY=FR
  64. END:VEVENT
  65. END:VCALENDAR
  66. ICS;
  67. $vcal = Reader::read($input);
  68. $this->assertInstanceOf('Sabre\\VObject\\Component\\VCalendar', $vcal);
  69. $vcal->expand(new DateTime('2015-01-01'), new DateTime('2015-01-31'), new \DateTimeZone('Europe/Berlin'));
  70. $result = $vcal->serialize();
  71. $output = <<<ICS
  72. BEGIN:VCALENDAR
  73. VERSION:2.0
  74. BEGIN:VEVENT
  75. UID:foo
  76. DTSTART:20150109T080000Z
  77. DTEND:20150109T090000Z
  78. RECURRENCE-ID:20150109T080000Z
  79. END:VEVENT
  80. BEGIN:VEVENT
  81. UID:foo
  82. DTSTART:20150116T080000Z
  83. DTEND:20150116T090000Z
  84. RECURRENCE-ID:20150116T080000Z
  85. END:VEVENT
  86. BEGIN:VEVENT
  87. UID:foo
  88. DTSTART:20150123T080000Z
  89. DTEND:20150123T090000Z
  90. RECURRENCE-ID:20150123T080000Z
  91. END:VEVENT
  92. BEGIN:VEVENT
  93. UID:foo
  94. DTSTART:20150130T080000Z
  95. DTEND:20150130T090000Z
  96. RECURRENCE-ID:20150130T080000Z
  97. END:VEVENT
  98. END:VCALENDAR
  99. ICS;
  100. $this->assertEquals($output, str_replace("\r", "", $result));
  101. }
  102. }