1
0

EventComparisonServiceTest.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * @copyright 2023 Daniel Kesselberg <mail@danielkesselberg.de>
  5. *
  6. * @author 2023 Daniel Kesselberg <mail@danielkesselberg.de>
  7. *
  8. * @license GNU AGPL version 3 or any later version
  9. *
  10. * This program is free software: you can redistribute it and/or modify
  11. * it under the terms of the GNU Affero General Public License as
  12. * published by the Free Software Foundation, either version 3 of the
  13. * License, or (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU Affero General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Affero General Public License
  21. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  22. *
  23. */
  24. namespace OCA\DAV\Tests\unit\CalDAV;
  25. use OCA\DAV\CalDAV\EventComparisonService;
  26. use Sabre\VObject\Component\VCalendar;
  27. use Sabre\VObject\Component\VEvent;
  28. use Test\TestCase;
  29. class EventComparisonServiceTest extends TestCase
  30. {
  31. /** @var EventComparisonService */
  32. private $eventComparisonService;
  33. protected function setUp(): void
  34. {
  35. $this->eventComparisonService = new EventComparisonService();
  36. }
  37. public function testNoModifiedEvent(): void
  38. {
  39. $vCalendarOld = new VCalendar();
  40. $vCalendarNew = new VCalendar();
  41. $vEventOld = $vCalendarOld->add('VEVENT', [
  42. 'UID' => 'uid-1234',
  43. 'LAST-MODIFIED' => 123456,
  44. 'SEQUENCE' => 2,
  45. 'SUMMARY' => 'Fellowship meeting',
  46. 'DTSTART' => new \DateTime('2016-01-01 00:00:00'),
  47. 'RRULE' => 'FREQ=DAILY;INTERVAL=1;UNTIL=20160201T000000Z',
  48. ]);
  49. $vEventOld->add('ORGANIZER', 'mailto:gandalf@wiz.ard');
  50. $vEventOld->add('ATTENDEE', 'mailto:' . 'frodo@hobb.it', ['RSVP' => 'TRUE', 'CN' => 'Frodo']);
  51. $vEventNew = $vCalendarNew->add('VEVENT', [
  52. 'UID' => 'uid-1234',
  53. 'LAST-MODIFIED' => 123456,
  54. 'SEQUENCE' => 2,
  55. 'SUMMARY' => 'Fellowship meeting',
  56. 'DTSTART' => new \DateTime('2016-01-01 00:00:00'),
  57. 'RRULE' => 'FREQ=DAILY;INTERVAL=1;UNTIL=20160201T000000Z',
  58. ]);
  59. $vEventNew->add('ORGANIZER', 'mailto:gandalf@wiz.ard');
  60. $vEventNew->add('ATTENDEE', 'mailto:' . 'frodo@hobb.it', ['RSVP' => 'TRUE', 'CN' => 'Frodo']);
  61. $result = $this->eventComparisonService->findModified($vCalendarNew, $vCalendarOld);
  62. $this->assertEmpty($result['old']);
  63. $this->assertEmpty($result['new']);
  64. }
  65. public function testNewEvent(): void
  66. {
  67. $vCalendarOld = null;
  68. $vCalendarNew = new VCalendar();
  69. $vEventNew = $vCalendarNew->add('VEVENT', [
  70. 'UID' => 'uid-1234',
  71. 'LAST-MODIFIED' => 123456,
  72. 'SEQUENCE' => 2,
  73. 'SUMMARY' => 'Fellowship meeting',
  74. 'DTSTART' => new \DateTime('2016-01-01 00:00:00'),
  75. 'RRULE' => 'FREQ=DAILY;INTERVAL=1;UNTIL=20160201T000000Z',
  76. ]);
  77. $vEventNew->add('ORGANIZER', 'mailto:gandalf@wiz.ard');
  78. $vEventNew->add('ATTENDEE', 'mailto:' . 'frodo@hobb.it', ['RSVP' => 'TRUE', 'CN' => 'Frodo']);
  79. $result = $this->eventComparisonService->findModified($vCalendarNew, $vCalendarOld);
  80. $this->assertNull($result['old']);
  81. $this->assertEquals([$vEventNew], $result['new']);
  82. }
  83. public function testModifiedUnmodifiedEvent(): void
  84. {
  85. $vCalendarOld = new VCalendar();
  86. $vCalendarNew = new VCalendar();
  87. $vEventOld1 = $vCalendarOld->add('VEVENT', [
  88. 'UID' => 'uid-1234',
  89. 'LAST-MODIFIED' => 123456,
  90. 'SEQUENCE' => 2,
  91. 'SUMMARY' => 'Fellowship meeting',
  92. 'DTSTART' => new \DateTime('2016-01-01 00:00:00'),
  93. ]);
  94. $vEventOld1->add('ORGANIZER', 'mailto:gandalf@wiz.ard');
  95. $vEventOld1->add('ATTENDEE', 'mailto:' . 'frodo@hobb.it', ['RSVP' => 'TRUE', 'CN' => 'Frodo']);
  96. $vEventOld2 = $vCalendarOld->add('VEVENT', [
  97. 'UID' => 'uid-1235',
  98. 'LAST-MODIFIED' => 123456,
  99. 'SEQUENCE' => 2,
  100. 'SUMMARY' => 'Fellowship meeting',
  101. 'DTSTART' => new \DateTime('2016-01-01 00:00:00'),
  102. ]);
  103. $vEventOld2->add('ORGANIZER', 'mailto:gandalf@wiz.ard');
  104. $vEventOld2->add('ATTENDEE', 'mailto:' . 'frodo@hobb.it', ['RSVP' => 'TRUE', 'CN' => 'Frodo']);
  105. $vEventNew1 = $vCalendarNew->add('VEVENT', [
  106. 'UID' => 'uid-1234',
  107. 'LAST-MODIFIED' => 123456,
  108. 'SEQUENCE' => 2,
  109. 'SUMMARY' => 'Fellowship meeting',
  110. 'DTSTART' => new \DateTime('2016-01-01 00:00:00'),
  111. ]);
  112. $vEventNew1->add('ORGANIZER', 'mailto:gandalf@wiz.ard');
  113. $vEventNew1->add('ATTENDEE', 'mailto:' . 'frodo@hobb.it', ['RSVP' => 'TRUE', 'CN' => 'Frodo']);
  114. $vEventNew2 = $vCalendarNew->add('VEVENT', [
  115. 'UID' => 'uid-1235',
  116. 'LAST-MODIFIED' => 123457,
  117. 'SEQUENCE' => 3,
  118. 'SUMMARY' => 'Fellowship meeting 2',
  119. 'DTSTART' => new \DateTime('2016-01-01 00:00:00'),
  120. ]);
  121. $vEventNew2->add('ORGANIZER', 'mailto:gandalf@wiz.ard');
  122. $vEventNew2->add('ATTENDEE', 'mailto:' . 'frodo@hobb.it', ['RSVP' => 'TRUE', 'CN' => 'Frodo']);
  123. $result = $this->eventComparisonService->findModified($vCalendarNew, $vCalendarOld);
  124. $this->assertEquals([$vEventOld2], $result['old']);
  125. $this->assertEquals([$vEventNew2], $result['new']);
  126. }
  127. }