EventComparisonServiceTest.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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 Test\TestCase;
  28. class EventComparisonServiceTest extends TestCase {
  29. /** @var EventComparisonService */
  30. private $eventComparisonService;
  31. protected function setUp(): void {
  32. $this->eventComparisonService = new EventComparisonService();
  33. }
  34. public function testNoModifiedEvent(): void {
  35. $vCalendarOld = new VCalendar();
  36. $vCalendarNew = new VCalendar();
  37. $vEventOld = $vCalendarOld->add('VEVENT', [
  38. 'UID' => 'uid-1234',
  39. 'LAST-MODIFIED' => 123456,
  40. 'SEQUENCE' => 2,
  41. 'SUMMARY' => 'Fellowship meeting',
  42. 'DTSTART' => new \DateTime('2016-01-01 00:00:00'),
  43. 'RRULE' => 'FREQ=DAILY;INTERVAL=1;UNTIL=20160201T000000Z',
  44. ]);
  45. $vEventOld->add('ORGANIZER', 'mailto:gandalf@wiz.ard');
  46. $vEventOld->add('ATTENDEE', 'mailto:' . 'frodo@hobb.it', ['RSVP' => 'TRUE', 'CN' => 'Frodo']);
  47. $vEventNew = $vCalendarNew->add('VEVENT', [
  48. 'UID' => 'uid-1234',
  49. 'LAST-MODIFIED' => 123456,
  50. 'SEQUENCE' => 2,
  51. 'SUMMARY' => 'Fellowship meeting',
  52. 'DTSTART' => new \DateTime('2016-01-01 00:00:00'),
  53. 'RRULE' => 'FREQ=DAILY;INTERVAL=1;UNTIL=20160201T000000Z',
  54. ]);
  55. $vEventNew->add('ORGANIZER', 'mailto:gandalf@wiz.ard');
  56. $vEventNew->add('ATTENDEE', 'mailto:' . 'frodo@hobb.it', ['RSVP' => 'TRUE', 'CN' => 'Frodo']);
  57. $result = $this->eventComparisonService->findModified($vCalendarNew, $vCalendarOld);
  58. $this->assertEmpty($result['old']);
  59. $this->assertEmpty($result['new']);
  60. }
  61. public function testNewEvent(): void {
  62. $vCalendarOld = null;
  63. $vCalendarNew = new VCalendar();
  64. $vEventNew = $vCalendarNew->add('VEVENT', [
  65. 'UID' => 'uid-1234',
  66. 'LAST-MODIFIED' => 123456,
  67. 'SEQUENCE' => 2,
  68. 'SUMMARY' => 'Fellowship meeting',
  69. 'DTSTART' => new \DateTime('2016-01-01 00:00:00'),
  70. 'RRULE' => 'FREQ=DAILY;INTERVAL=1;UNTIL=20160201T000000Z',
  71. ]);
  72. $vEventNew->add('ORGANIZER', 'mailto:gandalf@wiz.ard');
  73. $vEventNew->add('ATTENDEE', 'mailto:' . 'frodo@hobb.it', ['RSVP' => 'TRUE', 'CN' => 'Frodo']);
  74. $result = $this->eventComparisonService->findModified($vCalendarNew, $vCalendarOld);
  75. $this->assertNull($result['old']);
  76. $this->assertEquals([$vEventNew], $result['new']);
  77. }
  78. public function testModifiedUnmodifiedEvent(): void {
  79. $vCalendarOld = new VCalendar();
  80. $vCalendarNew = new VCalendar();
  81. $vEventOld1 = $vCalendarOld->add('VEVENT', [
  82. 'UID' => 'uid-1234',
  83. 'LAST-MODIFIED' => 123456,
  84. 'SEQUENCE' => 2,
  85. 'SUMMARY' => 'Fellowship meeting',
  86. 'DTSTART' => new \DateTime('2016-01-01 00:00:00'),
  87. ]);
  88. $vEventOld1->add('ORGANIZER', 'mailto:gandalf@wiz.ard');
  89. $vEventOld1->add('ATTENDEE', 'mailto:' . 'frodo@hobb.it', ['RSVP' => 'TRUE', 'CN' => 'Frodo']);
  90. $vEventOld2 = $vCalendarOld->add('VEVENT', [
  91. 'UID' => 'uid-1235',
  92. 'LAST-MODIFIED' => 123456,
  93. 'SEQUENCE' => 2,
  94. 'SUMMARY' => 'Fellowship meeting',
  95. 'DTSTART' => new \DateTime('2016-01-01 00:00:00'),
  96. ]);
  97. $vEventOld2->add('ORGANIZER', 'mailto:gandalf@wiz.ard');
  98. $vEventOld2->add('ATTENDEE', 'mailto:' . 'frodo@hobb.it', ['RSVP' => 'TRUE', 'CN' => 'Frodo']);
  99. $vEventNew1 = $vCalendarNew->add('VEVENT', [
  100. 'UID' => 'uid-1234',
  101. 'LAST-MODIFIED' => 123456,
  102. 'SEQUENCE' => 2,
  103. 'SUMMARY' => 'Fellowship meeting',
  104. 'DTSTART' => new \DateTime('2016-01-01 00:00:00'),
  105. ]);
  106. $vEventNew1->add('ORGANIZER', 'mailto:gandalf@wiz.ard');
  107. $vEventNew1->add('ATTENDEE', 'mailto:' . 'frodo@hobb.it', ['RSVP' => 'TRUE', 'CN' => 'Frodo']);
  108. $vEventNew2 = $vCalendarNew->add('VEVENT', [
  109. 'UID' => 'uid-1235',
  110. 'LAST-MODIFIED' => 123457,
  111. 'SEQUENCE' => 3,
  112. 'SUMMARY' => 'Fellowship meeting 2',
  113. 'DTSTART' => new \DateTime('2016-01-01 00:00:00'),
  114. ]);
  115. $vEventNew2->add('ORGANIZER', 'mailto:gandalf@wiz.ard');
  116. $vEventNew2->add('ATTENDEE', 'mailto:' . 'frodo@hobb.it', ['RSVP' => 'TRUE', 'CN' => 'Frodo']);
  117. $result = $this->eventComparisonService->findModified($vCalendarNew, $vCalendarOld);
  118. $this->assertEquals([$vEventOld2], $result['old']);
  119. $this->assertEquals([$vEventNew2], $result['new']);
  120. }
  121. }