CalDavBackendTest.php 60 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2017 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
  5. * SPDX-License-Identifier: AGPL-3.0-only
  6. */
  7. namespace OCA\DAV\Tests\unit\CalDAV;
  8. use DateInterval;
  9. use DateTime;
  10. use DateTimeImmutable;
  11. use DateTimeZone;
  12. use OCA\DAV\CalDAV\CalDavBackend;
  13. use OCA\DAV\CalDAV\Calendar;
  14. use OCA\DAV\DAV\Sharing\Plugin as SharingPlugin;
  15. use OCA\DAV\Events\CalendarDeletedEvent;
  16. use OCP\IConfig;
  17. use OCP\IL10N;
  18. use Sabre\DAV\Exception\NotFound;
  19. use Sabre\DAV\PropPatch;
  20. use Sabre\DAV\Xml\Property\Href;
  21. use Sabre\DAVACL\IACL;
  22. use function time;
  23. /**
  24. * Class CalDavBackendTest
  25. *
  26. * @group DB
  27. *
  28. * @package OCA\DAV\Tests\unit\CalDAV
  29. */
  30. class CalDavBackendTest extends AbstractCalDavBackend {
  31. public function testCalendarOperations(): void {
  32. $calendarId = $this->createTestCalendar();
  33. // update its display name
  34. $patch = new PropPatch([
  35. '{DAV:}displayname' => 'Unit test',
  36. '{urn:ietf:params:xml:ns:caldav}calendar-description' => 'Calendar used for unit testing'
  37. ]);
  38. $this->dispatcher->expects(self::atLeastOnce())
  39. ->method('dispatchTyped');
  40. $this->backend->updateCalendar($calendarId, $patch);
  41. $patch->commit();
  42. $this->assertEquals(1, $this->backend->getCalendarsForUserCount(self::UNIT_TEST_USER));
  43. $calendars = $this->backend->getCalendarsForUser(self::UNIT_TEST_USER);
  44. $this->assertCount(1, $calendars);
  45. $this->assertEquals('Unit test', $calendars[0]['{DAV:}displayname']);
  46. $this->assertEquals('Calendar used for unit testing', $calendars[0]['{urn:ietf:params:xml:ns:caldav}calendar-description']);
  47. $this->assertEquals('User\'s displayname', $calendars[0]['{http://nextcloud.com/ns}owner-displayname']);
  48. // delete the address book
  49. $this->dispatcher->expects(self::atLeastOnce())
  50. ->method('dispatchTyped');
  51. $this->backend->deleteCalendar($calendars[0]['id'], true);
  52. $calendars = $this->backend->getCalendarsForUser(self::UNIT_TEST_USER);
  53. self::assertEmpty($calendars);
  54. }
  55. public function providesSharingData() {
  56. return [
  57. [true, true, true, false, [
  58. [
  59. 'href' => 'principal:' . self::UNIT_TEST_USER1,
  60. 'readOnly' => false
  61. ],
  62. [
  63. 'href' => 'principal:' . self::UNIT_TEST_GROUP,
  64. 'readOnly' => true
  65. ]
  66. ], [
  67. self::UNIT_TEST_USER1,
  68. self::UNIT_TEST_GROUP,
  69. ]],
  70. [true, true, true, false, [
  71. [
  72. 'href' => 'principal:' . self::UNIT_TEST_GROUP,
  73. 'readOnly' => true,
  74. ],
  75. [
  76. 'href' => 'principal:' . self::UNIT_TEST_GROUP2,
  77. 'readOnly' => false,
  78. ],
  79. ], [
  80. self::UNIT_TEST_GROUP,
  81. self::UNIT_TEST_GROUP2,
  82. ]],
  83. [true, true, true, true, [
  84. [
  85. 'href' => 'principal:' . self::UNIT_TEST_GROUP,
  86. 'readOnly' => false,
  87. ],
  88. [
  89. 'href' => 'principal:' . self::UNIT_TEST_GROUP2,
  90. 'readOnly' => true,
  91. ],
  92. ], [
  93. self::UNIT_TEST_GROUP,
  94. self::UNIT_TEST_GROUP2,
  95. ]],
  96. [true, false, false, false, [
  97. [
  98. 'href' => 'principal:' . self::UNIT_TEST_USER1,
  99. 'readOnly' => true
  100. ],
  101. ], [
  102. self::UNIT_TEST_USER1,
  103. ]],
  104. ];
  105. }
  106. /**
  107. * @dataProvider providesSharingData
  108. */
  109. public function testCalendarSharing($userCanRead, $userCanWrite, $groupCanRead, $groupCanWrite, $add, $principals): void {
  110. $logger = $this->createMock(\Psr\Log\LoggerInterface::class);
  111. $config = $this->createMock(IConfig::class);
  112. /** @var IL10N|MockObject $l10n */
  113. $l10n = $this->createMock(IL10N::class);
  114. $l10n->expects($this->any())
  115. ->method('t')
  116. ->willReturnCallback(function ($text, $parameters = []) {
  117. return vsprintf($text, $parameters);
  118. });
  119. $this->userManager->expects($this->any())
  120. ->method('userExists')
  121. ->willReturn(true);
  122. $this->groupManager->expects($this->any())
  123. ->method('groupExists')
  124. ->willReturn(true);
  125. $this->principal->expects(self::atLeastOnce())
  126. ->method('findByUri')
  127. ->willReturnOnConsecutiveCalls(...$principals);
  128. $calendarId = $this->createTestCalendar();
  129. $calendars = $this->backend->getCalendarsForUser(self::UNIT_TEST_USER);
  130. $this->assertCount(1, $calendars);
  131. $calendar = new Calendar($this->backend, $calendars[0], $l10n, $config, $logger);
  132. $this->backend->updateShares($calendar, $add, []);
  133. $calendars = $this->backend->getCalendarsForUser(self::UNIT_TEST_USER1);
  134. $this->assertCount(1, $calendars);
  135. $calendar = new Calendar($this->backend, $calendars[0], $l10n, $config, $logger);
  136. $acl = $calendar->getACL();
  137. $this->assertAcl(self::UNIT_TEST_USER, '{DAV:}read', $acl);
  138. $this->assertAcl(self::UNIT_TEST_USER, '{DAV:}write', $acl);
  139. $this->assertAccess($userCanRead, self::UNIT_TEST_USER1, '{DAV:}read', $acl);
  140. $this->assertAccess($userCanWrite, self::UNIT_TEST_USER1, '{DAV:}write', $acl);
  141. $this->assertEquals(self::UNIT_TEST_USER, $calendar->getOwner());
  142. // test acls on the child
  143. $uri = static::getUniqueID('calobj');
  144. $calData = <<<'EOD'
  145. BEGIN:VCALENDAR
  146. VERSION:2.0
  147. PRODID:ownCloud Calendar
  148. BEGIN:VEVENT
  149. CREATED;VALUE=DATE-TIME:20130910T125139Z
  150. UID:47d15e3ec8
  151. LAST-MODIFIED;VALUE=DATE-TIME:20130910T125139Z
  152. DTSTAMP;VALUE=DATE-TIME:20130910T125139Z
  153. SUMMARY:Test Event
  154. DTSTART;VALUE=DATE-TIME:20130912T130000Z
  155. DTEND;VALUE=DATE-TIME:20130912T140000Z
  156. CLASS:PUBLIC
  157. END:VEVENT
  158. END:VCALENDAR
  159. EOD;
  160. $this->dispatcher->expects(self::atLeastOnce())
  161. ->method('dispatchTyped');
  162. $this->backend->createCalendarObject($calendarId, $uri, $calData);
  163. /** @var IACL $child */
  164. $child = $calendar->getChild($uri);
  165. $acl = $child->getACL();
  166. $this->assertAcl(self::UNIT_TEST_USER, '{DAV:}read', $acl);
  167. $this->assertAcl(self::UNIT_TEST_USER, '{DAV:}write', $acl);
  168. $this->assertAccess($userCanRead, self::UNIT_TEST_USER1, '{DAV:}read', $acl);
  169. $this->assertAccess($userCanWrite, self::UNIT_TEST_USER1, '{DAV:}write', $acl);
  170. // delete the calendar
  171. $this->dispatcher->expects(self::once())
  172. ->method('dispatchTyped')
  173. ->with(self::callback(function ($event) {
  174. return $event instanceof CalendarDeletedEvent;
  175. }));
  176. $this->backend->deleteCalendar($calendars[0]['id'], true);
  177. $calendars = $this->backend->getCalendarsForUser(self::UNIT_TEST_USER);
  178. self::assertEmpty($calendars);
  179. }
  180. public function testCalendarObjectsOperations(): void {
  181. $calendarId = $this->createTestCalendar();
  182. // create a card
  183. $uri = static::getUniqueID('calobj');
  184. $calData = <<<'EOD'
  185. BEGIN:VCALENDAR
  186. VERSION:2.0
  187. PRODID:ownCloud Calendar
  188. BEGIN:VEVENT
  189. CREATED;VALUE=DATE-TIME:20130910T125139Z
  190. UID:47d15e3ec8
  191. LAST-MODIFIED;VALUE=DATE-TIME:20130910T125139Z
  192. DTSTAMP;VALUE=DATE-TIME:20130910T125139Z
  193. SUMMARY:Test Event
  194. DTSTART;VALUE=DATE-TIME:20130912T130000Z
  195. DTEND;VALUE=DATE-TIME:20130912T140000Z
  196. CLASS:PUBLIC
  197. END:VEVENT
  198. END:VCALENDAR
  199. EOD;
  200. $this->dispatcher->expects(self::atLeastOnce())
  201. ->method('dispatchTyped');
  202. $this->backend->createCalendarObject($calendarId, $uri, $calData);
  203. // get all the calendar objects
  204. $calendarObjects = $this->backend->getCalendarObjects($calendarId);
  205. $this->assertCount(1, $calendarObjects);
  206. $this->assertEquals($calendarId, $calendarObjects[0]['calendarid']);
  207. $this->assertArrayHasKey('classification', $calendarObjects[0]);
  208. // get the calendar objects
  209. $calendarObject = $this->backend->getCalendarObject($calendarId, $uri);
  210. $this->assertNotNull($calendarObject);
  211. $this->assertArrayHasKey('id', $calendarObject);
  212. $this->assertArrayHasKey('uri', $calendarObject);
  213. $this->assertArrayHasKey('lastmodified', $calendarObject);
  214. $this->assertArrayHasKey('etag', $calendarObject);
  215. $this->assertArrayHasKey('size', $calendarObject);
  216. $this->assertArrayHasKey('classification', $calendarObject);
  217. $this->assertArrayHasKey('{' . SharingPlugin::NS_NEXTCLOUD . '}deleted-at', $calendarObject);
  218. $this->assertEquals($calData, $calendarObject['calendardata']);
  219. // update the card
  220. $calData = <<<'EOD'
  221. BEGIN:VCALENDAR
  222. VERSION:2.0
  223. PRODID:ownCloud Calendar
  224. BEGIN:VEVENT
  225. CREATED;VALUE=DATE-TIME:20130910T125139Z
  226. UID:47d15e3ec8
  227. LAST-MODIFIED;VALUE=DATE-TIME:20130910T125139Z
  228. DTSTAMP;VALUE=DATE-TIME:20130910T125139Z
  229. SUMMARY:Test Event
  230. DTSTART;VALUE=DATE-TIME:20130912T130000Z
  231. DTEND;VALUE=DATE-TIME:20130912T140000Z
  232. END:VEVENT
  233. END:VCALENDAR
  234. EOD;
  235. $this->dispatcher->expects(self::atLeastOnce())
  236. ->method('dispatchTyped');
  237. $this->backend->updateCalendarObject($calendarId, $uri, $calData);
  238. $calendarObject = $this->backend->getCalendarObject($calendarId, $uri);
  239. $this->assertEquals($calData, $calendarObject['calendardata']);
  240. // delete the card
  241. $this->dispatcher->expects(self::atLeastOnce())
  242. ->method('dispatchTyped');
  243. $this->backend->deleteCalendarObject($calendarId, $uri);
  244. $calendarObjects = $this->backend->getCalendarObjects($calendarId);
  245. $this->assertCount(0, $calendarObjects);
  246. }
  247. public function testMultipleCalendarObjectsWithSameUID(): void {
  248. $this->expectException(\Sabre\DAV\Exception\BadRequest::class);
  249. $this->expectExceptionMessage('Calendar object with uid already exists in this calendar collection.');
  250. $calendarId = $this->createTestCalendar();
  251. $calData = <<<'EOD'
  252. BEGIN:VCALENDAR
  253. VERSION:2.0
  254. PRODID:ownCloud Calendar
  255. BEGIN:VEVENT
  256. CREATED;VALUE=DATE-TIME:20130910T125139Z
  257. UID:47d15e3ec8-1
  258. LAST-MODIFIED;VALUE=DATE-TIME:20130910T125139Z
  259. DTSTAMP;VALUE=DATE-TIME:20130910T125139Z
  260. SUMMARY:Test Event
  261. DTSTART;VALUE=DATE-TIME:20130912T130000Z
  262. DTEND;VALUE=DATE-TIME:20130912T140000Z
  263. CLASS:PUBLIC
  264. END:VEVENT
  265. END:VCALENDAR
  266. EOD;
  267. $uri0 = static::getUniqueID('event');
  268. $uri1 = static::getUniqueID('event');
  269. $this->backend->createCalendarObject($calendarId, $uri0, $calData);
  270. $this->backend->createCalendarObject($calendarId, $uri1, $calData);
  271. }
  272. public function testMultiCalendarObjects(): void {
  273. $calendarId = $this->createTestCalendar();
  274. // create an event
  275. $calData = [];
  276. $calData[] = <<<'EOD'
  277. BEGIN:VCALENDAR
  278. VERSION:2.0
  279. PRODID:ownCloud Calendar
  280. BEGIN:VEVENT
  281. CREATED;VALUE=DATE-TIME:20130910T125139Z
  282. UID:47d15e3ec8-1
  283. LAST-MODIFIED;VALUE=DATE-TIME:20130910T125139Z
  284. DTSTAMP;VALUE=DATE-TIME:20130910T125139Z
  285. SUMMARY:Test Event
  286. DTSTART;VALUE=DATE-TIME:20130912T130000Z
  287. DTEND;VALUE=DATE-TIME:20130912T140000Z
  288. CLASS:PUBLIC
  289. END:VEVENT
  290. END:VCALENDAR
  291. EOD;
  292. $calData[] = <<<'EOD'
  293. BEGIN:VCALENDAR
  294. VERSION:2.0
  295. PRODID:ownCloud Calendar
  296. BEGIN:VEVENT
  297. CREATED;VALUE=DATE-TIME:20130910T125139Z
  298. UID:47d15e3ec8-2
  299. LAST-MODIFIED;VALUE=DATE-TIME:20130910T125139Z
  300. DTSTAMP;VALUE=DATE-TIME:20130910T125139Z
  301. SUMMARY:Test Event
  302. DTSTART;VALUE=DATE-TIME:20130912T130000Z
  303. DTEND;VALUE=DATE-TIME:20130912T140000Z
  304. CLASS:PUBLIC
  305. END:VEVENT
  306. END:VCALENDAR
  307. EOD;
  308. $calData[] = <<<'EOD'
  309. BEGIN:VCALENDAR
  310. VERSION:2.0
  311. PRODID:ownCloud Calendar
  312. BEGIN:VEVENT
  313. CREATED;VALUE=DATE-TIME:20130910T125139Z
  314. UID:47d15e3ec8-3
  315. LAST-MODIFIED;VALUE=DATE-TIME:20130910T125139Z
  316. DTSTAMP;VALUE=DATE-TIME:20130910T125139Z
  317. SUMMARY:Test Event
  318. DTSTART;VALUE=DATE-TIME:20130912T130000Z
  319. DTEND;VALUE=DATE-TIME:20130912T140000Z
  320. CLASS:PUBLIC
  321. END:VEVENT
  322. END:VCALENDAR
  323. EOD;
  324. $uri0 = static::getUniqueID('card');
  325. $this->dispatcher->expects(self::atLeastOnce())
  326. ->method('dispatchTyped');
  327. $this->backend->createCalendarObject($calendarId, $uri0, $calData[0]);
  328. $uri1 = static::getUniqueID('card');
  329. $this->dispatcher->expects(self::atLeastOnce())
  330. ->method('dispatchTyped');
  331. $this->backend->createCalendarObject($calendarId, $uri1, $calData[1]);
  332. $uri2 = static::getUniqueID('card');
  333. $this->dispatcher->expects(self::atLeastOnce())
  334. ->method('dispatchTyped');
  335. $this->backend->createCalendarObject($calendarId, $uri2, $calData[2]);
  336. // get all the cards
  337. $calendarObjects = $this->backend->getCalendarObjects($calendarId);
  338. $this->assertCount(3, $calendarObjects);
  339. // get the cards
  340. $calendarObjects = $this->backend->getMultipleCalendarObjects($calendarId, [$uri1, $uri2]);
  341. $this->assertCount(2, $calendarObjects);
  342. foreach ($calendarObjects as $card) {
  343. $this->assertArrayHasKey('id', $card);
  344. $this->assertArrayHasKey('uri', $card);
  345. $this->assertArrayHasKey('lastmodified', $card);
  346. $this->assertArrayHasKey('etag', $card);
  347. $this->assertArrayHasKey('size', $card);
  348. $this->assertArrayHasKey('classification', $card);
  349. }
  350. usort($calendarObjects, function ($a, $b) {
  351. return $a['id'] - $b['id'];
  352. });
  353. $this->assertEquals($calData[1], $calendarObjects[0]['calendardata']);
  354. $this->assertEquals($calData[2], $calendarObjects[1]['calendardata']);
  355. // delete the card
  356. $this->dispatcher->expects(self::atLeastOnce())
  357. ->method('dispatchTyped');
  358. $this->backend->deleteCalendarObject($calendarId, $uri0);
  359. $this->dispatcher->expects(self::atLeastOnce())
  360. ->method('dispatchTyped');
  361. $this->backend->deleteCalendarObject($calendarId, $uri1);
  362. $this->dispatcher->expects(self::atLeastOnce())
  363. ->method('dispatchTyped');
  364. $this->backend->deleteCalendarObject($calendarId, $uri2);
  365. $calendarObjects = $this->backend->getCalendarObjects($calendarId);
  366. $this->assertCount(0, $calendarObjects);
  367. }
  368. /**
  369. * @dataProvider providesCalendarQueryParameters
  370. */
  371. public function testCalendarQuery($expectedEventsInResult, $propFilters, $compFilter): void {
  372. $calendarId = $this->createTestCalendar();
  373. $events = [];
  374. $events[0] = $this->createEvent($calendarId, '20130912T130000Z', '20130912T140000Z');
  375. $events[1] = $this->createEvent($calendarId, '20130912T150000Z', '20130912T170000Z');
  376. $events[2] = $this->createEvent($calendarId, '20130912T173000Z', '20130912T220000Z');
  377. if (PHP_INT_SIZE > 8) {
  378. $events[3] = $this->createEvent($calendarId, '21130912T130000Z', '22130912T130000Z');
  379. } else {
  380. /* On 32bit we do not support events after 2038 */
  381. $events[3] = $this->createEvent($calendarId, '20370912T130000Z', '20370912T130000Z');
  382. }
  383. $result = $this->backend->calendarQuery($calendarId, [
  384. 'name' => '',
  385. 'prop-filters' => $propFilters,
  386. 'comp-filters' => $compFilter
  387. ]);
  388. $expectedEventsInResult = array_map(function ($index) use ($events) {
  389. return $events[$index];
  390. }, $expectedEventsInResult);
  391. $this->assertEqualsCanonicalizing($expectedEventsInResult, $result);
  392. }
  393. public function testGetCalendarObjectByUID(): void {
  394. $calendarId = $this->createTestCalendar();
  395. $uri = static::getUniqueID('calobj');
  396. $calData = <<<'EOD'
  397. BEGIN:VCALENDAR
  398. VERSION:2.0
  399. PRODID:ownCloud Calendar
  400. BEGIN:VEVENT
  401. CREATED;VALUE=DATE-TIME:20130910T125139Z
  402. UID:47d15e3ec8
  403. LAST-MODIFIED;VALUE=DATE-TIME:20130910T125139Z
  404. DTSTAMP;VALUE=DATE-TIME:20130910T125139Z
  405. SUMMARY:Test Event
  406. DTSTART;VALUE=DATE-TIME:20130912T130000Z
  407. DTEND;VALUE=DATE-TIME:20130912T140000Z
  408. CLASS:PUBLIC
  409. END:VEVENT
  410. END:VCALENDAR
  411. EOD;
  412. $this->backend->createCalendarObject($calendarId, $uri, $calData);
  413. $co = $this->backend->getCalendarObjectByUID(self::UNIT_TEST_USER, '47d15e3ec8');
  414. $this->assertNotNull($co);
  415. }
  416. public function providesCalendarQueryParameters() {
  417. return [
  418. 'all' => [[0, 1, 2, 3], [], []],
  419. 'only-todos' => [[], ['name' => 'VTODO'], []],
  420. 'only-events' => [[0, 1, 2, 3], [], [['name' => 'VEVENT', 'is-not-defined' => false, 'comp-filters' => [], 'time-range' => ['start' => null, 'end' => null], 'prop-filters' => []]],],
  421. 'start' => [[1, 2, 3], [], [['name' => 'VEVENT', 'is-not-defined' => false, 'comp-filters' => [], 'time-range' => ['start' => new DateTime('2013-09-12 14:00:00', new DateTimeZone('UTC')), 'end' => null], 'prop-filters' => []]],],
  422. 'end' => [[0], [], [['name' => 'VEVENT', 'is-not-defined' => false, 'comp-filters' => [], 'time-range' => ['start' => null, 'end' => new DateTime('2013-09-12 14:00:00', new DateTimeZone('UTC'))], 'prop-filters' => []]],],
  423. 'future' => [[3], [], [['name' => 'VEVENT', 'is-not-defined' => false, 'comp-filters' => [], 'time-range' => ['start' => new DateTime('2036-09-12 14:00:00', new DateTimeZone('UTC')), 'end' => null], 'prop-filters' => []]],],
  424. ];
  425. }
  426. public function testSyncSupport(): void {
  427. $calendarId = $this->createTestCalendar();
  428. // fist call without synctoken
  429. $changes = $this->backend->getChangesForCalendar($calendarId, '', 1);
  430. $syncToken = $changes['syncToken'];
  431. // add a change
  432. $event = $this->createEvent($calendarId, '20130912T130000Z', '20130912T140000Z');
  433. // look for changes
  434. $changes = $this->backend->getChangesForCalendar($calendarId, $syncToken, 1);
  435. $this->assertEquals($event, $changes['added'][0]);
  436. }
  437. public function testPublications(): void {
  438. $this->dispatcher->expects(self::atLeastOnce())
  439. ->method('dispatchTyped');
  440. $this->backend->createCalendar(self::UNIT_TEST_USER, 'Example', []);
  441. $calendarInfo = $this->backend->getCalendarsForUser(self::UNIT_TEST_USER)[0];
  442. /** @var IL10N|\PHPUnit\Framework\MockObject\MockObject $l10n */
  443. $l10n = $this->createMock(IL10N::class);
  444. $config = $this->createMock(IConfig::class);
  445. $logger = $this->createMock(\Psr\Log\LoggerInterface::class);
  446. $calendar = new Calendar($this->backend, $calendarInfo, $l10n, $config, $logger);
  447. $calendar->setPublishStatus(true);
  448. $this->assertNotEquals(false, $calendar->getPublishStatus());
  449. $publicCalendars = $this->backend->getPublicCalendars();
  450. $this->assertCount(1, $publicCalendars);
  451. $this->assertEquals(true, $publicCalendars[0]['{http://owncloud.org/ns}public']);
  452. $this->assertEquals('User\'s displayname', $publicCalendars[0]['{http://nextcloud.com/ns}owner-displayname']);
  453. $publicCalendarURI = $publicCalendars[0]['uri'];
  454. $publicCalendar = $this->backend->getPublicCalendar($publicCalendarURI);
  455. $this->assertEquals(true, $publicCalendar['{http://owncloud.org/ns}public']);
  456. $calendar->setPublishStatus(false);
  457. $this->assertEquals(false, $calendar->getPublishStatus());
  458. $this->expectException(NotFound::class);
  459. $this->backend->getPublicCalendar($publicCalendarURI);
  460. }
  461. public function testSubscriptions(): void {
  462. $id = $this->backend->createSubscription(self::UNIT_TEST_USER, 'Subscription', [
  463. '{http://calendarserver.org/ns/}source' => new Href('test-source'),
  464. '{http://apple.com/ns/ical/}calendar-color' => '#1C4587',
  465. '{http://calendarserver.org/ns/}subscribed-strip-todos' => ''
  466. ]);
  467. $subscriptions = $this->backend->getSubscriptionsForUser(self::UNIT_TEST_USER);
  468. $this->assertCount(1, $subscriptions);
  469. $this->assertEquals('#1C4587', $subscriptions[0]['{http://apple.com/ns/ical/}calendar-color']);
  470. $this->assertEquals(true, $subscriptions[0]['{http://calendarserver.org/ns/}subscribed-strip-todos']);
  471. $this->assertEquals($id, $subscriptions[0]['id']);
  472. $patch = new PropPatch([
  473. '{DAV:}displayname' => 'Unit test',
  474. '{http://apple.com/ns/ical/}calendar-color' => '#ac0606',
  475. ]);
  476. $this->backend->updateSubscription($id, $patch);
  477. $patch->commit();
  478. $subscriptions = $this->backend->getSubscriptionsForUser(self::UNIT_TEST_USER);
  479. $this->assertCount(1, $subscriptions);
  480. $this->assertEquals($id, $subscriptions[0]['id']);
  481. $this->assertEquals('Unit test', $subscriptions[0]['{DAV:}displayname']);
  482. $this->assertEquals('#ac0606', $subscriptions[0]['{http://apple.com/ns/ical/}calendar-color']);
  483. $this->backend->deleteSubscription($id);
  484. $subscriptions = $this->backend->getSubscriptionsForUser(self::UNIT_TEST_USER);
  485. $this->assertCount(0, $subscriptions);
  486. }
  487. public function providesSchedulingData() {
  488. $data = <<<EOS
  489. BEGIN:VCALENDAR
  490. VERSION:2.0
  491. PRODID:-//Sabre//Sabre VObject 3.5.0//EN
  492. CALSCALE:GREGORIAN
  493. METHOD:REQUEST
  494. BEGIN:VTIMEZONE
  495. TZID:Europe/Warsaw
  496. BEGIN:DAYLIGHT
  497. TZOFFSETFROM:+0100
  498. TZOFFSETTO:+0200
  499. TZNAME:CEST
  500. DTSTART:19700329T020000
  501. RRULE:FREQ=YEARLY;BYDAY=-1SU;BYMONTH=3
  502. END:DAYLIGHT
  503. BEGIN:STANDARD
  504. TZOFFSETFROM:+0200
  505. TZOFFSETTO:+0100
  506. TZNAME:CET
  507. DTSTART:19701025T030000
  508. RRULE:FREQ=YEARLY;BYDAY=-1SU;BYMONTH=10
  509. END:STANDARD
  510. END:VTIMEZONE
  511. BEGIN:VEVENT
  512. CREATED:20170320T131655Z
  513. LAST-MODIFIED:20170320T135019Z
  514. DTSTAMP:20170320T135019Z
  515. UID:7e908a6d-4c4e-48d7-bd62-59ab80fbf1a3
  516. SUMMARY:TEST Z pg_escape_bytea
  517. ORGANIZER;RSVP=TRUE;PARTSTAT=ACCEPTED;ROLE=CHAIR:mailto:k.klimczak@gromar.e
  518. u
  519. ATTENDEE;RSVP=TRUE;CN=Zuzanna Leszek;PARTSTAT=NEEDS-ACTION;ROLE=REQ-PARTICI
  520. PANT:mailto:z.leszek@gromar.eu
  521. ATTENDEE;RSVP=TRUE;CN=Marcin Pisarski;PARTSTAT=NEEDS-ACTION;ROLE=REQ-PARTIC
  522. IPANT:mailto:m.pisarski@gromar.eu
  523. ATTENDEE;RSVP=TRUE;PARTSTAT=NEEDS-ACTION;ROLE=REQ-PARTICIPANT:mailto:klimcz
  524. ak.k@gmail.com
  525. ATTENDEE;RSVP=TRUE;PARTSTAT=NEEDS-ACTION;ROLE=REQ-PARTICIPANT:mailto:k_klim
  526. czak@tlen.pl
  527. DTSTART;TZID=Europe/Warsaw:20170325T150000
  528. DTEND;TZID=Europe/Warsaw:20170325T160000
  529. TRANSP:OPAQUE
  530. DESCRIPTION:Magiczna treść uzyskana za pomocą magicznego proszku.\n\nę
  531. żźćńłóÓŻŹĆŁĘ€śśśŚŚ\n \,\,))))))))\;\,\n
  532. __))))))))))))))\,\n \\|/ -\\(((((''''((((((((.\n -*-==///
  533. ///(('' . `))))))\,\n /|\\ ))| o \;-. '(((((
  534. \,(\,\n ( `| / ) \;))))'
  535. \,_))^\;(~\n | | | \,))((((_ _____-
  536. -----~~~-. %\,\;(\;(>'\;'~\n o_)\; \; )))(((` ~---
  537. ~ `:: \\ %%~~)(v\;(`('~\n \; ''''````
  538. `: `:::|\\\,__\,%% )\;`'\; ~\n | _
  539. ) / `:|`----' `-'\n ______/\\/~ |
  540. / /\n /~\;\;.____/\;\;' / ___--\
  541. ,-( `\;\;\;/\n / // _\;______\;'------~~~~~ /\;\;/\\ /\n
  542. // | | / \; \\\;\;\,\\\n (<_ | \;
  543. /'\,/-----' _>\n \\_| ||_
  544. //~\;~~~~~~~~~\n `\\_| (\,~~ -Tua Xiong\n
  545. \\~\\\n
  546. ~~\n\n
  547. SEQUENCE:1
  548. X-MOZ-GENERATION:1
  549. END:VEVENT
  550. END:VCALENDAR
  551. EOS;
  552. return [
  553. 'no data' => [''],
  554. 'failing on postgres' => [$data]
  555. ];
  556. }
  557. /**
  558. * @dataProvider providesSchedulingData
  559. * @param $objectData
  560. */
  561. public function testScheduling($objectData): void {
  562. $this->backend->createSchedulingObject(self::UNIT_TEST_USER, 'Sample Schedule', $objectData);
  563. $sos = $this->backend->getSchedulingObjects(self::UNIT_TEST_USER);
  564. $this->assertCount(1, $sos);
  565. $so = $this->backend->getSchedulingObject(self::UNIT_TEST_USER, 'Sample Schedule');
  566. $this->assertNotNull($so);
  567. $this->backend->deleteSchedulingObject(self::UNIT_TEST_USER, 'Sample Schedule');
  568. $sos = $this->backend->getSchedulingObjects(self::UNIT_TEST_USER);
  569. $this->assertCount(0, $sos);
  570. }
  571. /**
  572. * @dataProvider providesCalDataForGetDenormalizedData
  573. */
  574. public function testGetDenormalizedData($expected, $key, $calData): void {
  575. try {
  576. $actual = $this->backend->getDenormalizedData($calData);
  577. $this->assertEquals($expected, $actual[$key]);
  578. } catch (\Throwable $e) {
  579. if (($e->getMessage() === 'Epoch doesn\'t fit in a PHP integer') && (PHP_INT_SIZE < 8)) {
  580. $this->markTestSkipped('This fail on 32bits because of PHP limitations in DateTime');
  581. }
  582. throw $e;
  583. }
  584. }
  585. public function providesCalDataForGetDenormalizedData(): array {
  586. return [
  587. 'first occurrence before unix epoch starts' => [0, 'firstOccurence', "BEGIN:VCALENDAR\r\nVERSION:2.0\r\nPRODID:-//Sabre//Sabre VObject 4.1.1//EN\r\nCALSCALE:GREGORIAN\r\nBEGIN:VEVENT\r\nUID:413F269B-B51B-46B1-AFB6-40055C53A4DC\r\nDTSTAMP:20160309T095056Z\r\nDTSTART;VALUE=DATE:16040222\r\nDTEND;VALUE=DATE:16040223\r\nRRULE:FREQ=YEARLY\r\nSUMMARY:SUMMARY\r\nTRANSP:TRANSPARENT\r\nEND:VEVENT\r\nEND:VCALENDAR\r\n"],
  588. 'no first occurrence because yearly' => [null, 'firstOccurence', "BEGIN:VCALENDAR\r\nVERSION:2.0\r\nPRODID:-//Sabre//Sabre VObject 4.1.1//EN\r\nCALSCALE:GREGORIAN\r\nBEGIN:VEVENT\r\nUID:413F269B-B51B-46B1-AFB6-40055C53A4DC\r\nDTSTAMP:20160309T095056Z\r\nRRULE:FREQ=YEARLY\r\nSUMMARY:SUMMARY\r\nTRANSP:TRANSPARENT\r\nEND:VEVENT\r\nEND:VCALENDAR\r\n"],
  589. 'last occurrence is max when only last VEVENT in group is weekly' => [(new DateTime(CalDavBackend::MAX_DATE))->getTimestamp(), 'lastOccurence', "BEGIN:VCALENDAR\r\nVERSION:2.0\r\nPRODID:-//Sabre//Sabre VObject 4.3.0//EN\r\nCALSCALE:GREGORIAN\r\nBEGIN:VEVENT\r\nDTSTART;TZID=America/Los_Angeles:20200812T103000\r\nDTEND;TZID=America/Los_Angeles:20200812T110000\r\nDTSTAMP:20200927T180638Z\r\nUID:asdfasdfasdf@google.com\r\nRECURRENCE-ID;TZID=America/Los_Angeles:20200811T123000\r\nCREATED:20200626T181848Z\r\nLAST-MODIFIED:20200922T192707Z\r\nSUMMARY:Weekly 1:1\r\nTRANSP:OPAQUE\r\nEND:VEVENT\r\nBEGIN:VEVENT\r\nDTSTART;TZID=America/Los_Angeles:20200728T123000\r\nDTEND;TZID=America/Los_Angeles:20200728T130000\r\nEXDATE;TZID=America/Los_Angeles:20200818T123000\r\nRRULE:FREQ=WEEKLY;BYDAY=TU\r\nDTSTAMP:20200927T180638Z\r\nUID:asdfasdfasdf@google.com\r\nCREATED:20200626T181848Z\r\nDESCRIPTION:Setting up recurring time on our calendars\r\nLAST-MODIFIED:20200922T192707Z\r\nSUMMARY:Weekly 1:1\r\nTRANSP:OPAQUE\r\nEND:VEVENT\r\nEND:VCALENDAR\r\n"],
  590. 'last occurrence before unix epoch starts' => [0, 'lastOccurence', "BEGIN:VCALENDAR\r\nVERSION:2.0\r\nPRODID:-//Sabre//Sabre VObject 4.3.0//EN\r\nCALSCALE:GREGORIAN\r\nBEGIN:VEVENT\r\nDTSTART;VALUE=DATE:19110324\r\nDTEND;VALUE=DATE:19110325\r\nDTSTAMP:20200927T180638Z\r\nUID:asdfasdfasdf@google.com\r\nCREATED:20200626T181848Z\r\nDESCRIPTION:Very old event\r\nLAST-MODIFIED:20200922T192707Z\r\nSUMMARY:Some old event\r\nTRANSP:OPAQUE\r\nEND:VEVENT\r\nEND:VCALENDAR\r\n"],
  591. 'first occurrence is found when not first VEVENT in group' => [(new DateTime('2020-09-01T110000', new DateTimeZone("America/Los_Angeles")))->getTimestamp(), 'firstOccurence', "BEGIN:VCALENDAR\r\nVERSION:2.0\r\nPRODID:-//Sabre//Sabre VObject 4.3.0//EN\r\nCALSCALE:GREGORIAN\r\nBEGIN:VEVENT\r\nDTSTART;TZID=America/Los_Angeles:20201013T110000\r\nDTEND;TZID=America/Los_Angeles:20201013T120000\r\nDTSTAMP:20200927T180638Z\r\nUID:asdf0000@google.com\r\nRECURRENCE-ID;TZID=America/Los_Angeles:20201013T110000\r\nCREATED:20160330T034726Z\r\nLAST-MODIFIED:20200925T042014Z\r\nSTATUS:CONFIRMED\r\nTRANSP:OPAQUE\r\nEND:VEVENT\r\nBEGIN:VEVENT\r\nDTSTART;TZID=America/Los_Angeles:20200901T110000\r\nDTEND;TZID=America/Los_Angeles:20200901T120000\r\nRRULE:FREQ=WEEKLY;BYDAY=TU\r\nEXDATE;TZID=America/Los_Angeles:20200922T110000\r\nEXDATE;TZID=America/Los_Angeles:20200915T110000\r\nEXDATE;TZID=America/Los_Angeles:20200908T110000\r\nDTSTAMP:20200927T180638Z\r\nUID:asdf0000@google.com\r\nCREATED:20160330T034726Z\r\nLAST-MODIFIED:20200915T162810Z\r\nSTATUS:CONFIRMED\r\nTRANSP:OPAQUE\r\nEND:VEVENT\r\nEND:VCALENDAR\r\n"],
  592. 'CLASS:PRIVATE' => [CalDavBackend::CLASSIFICATION_PRIVATE, 'classification', "BEGIN:VCALENDAR\r\nVERSION:2.0\r\nPRODID:-//dmfs.org//mimedir.icalendar//EN\r\nBEGIN:VTIMEZONE\r\nTZID:Europe/Berlin\r\nX-LIC-LOCATION:Europe/Berlin\r\nBEGIN:DAYLIGHT\r\nTZOFFSETFROM:+0100\r\nTZOFFSETTO:+0200\r\nTZNAME:CEST\r\nDTSTART:19700329T020000\r\nRRULE:FREQ=YEARLY;BYMONTH=3;BYDAY=-1SU\r\nEND:DAYLIGHT\r\nBEGIN:STANDARD\r\nTZOFFSETFROM:+0200\r\nTZOFFSETTO:+0100\r\nTZNAME:CET\r\nDTSTART:19701025T030000\r\nRRULE:FREQ=YEARLY;BYMONTH=10;BYDAY=-1SU\r\nEND:STANDARD\r\nEND:VTIMEZONE\r\nBEGIN:VEVENT\r\nDTSTART;TZID=Europe/Berlin:20160419T130000\r\nSUMMARY:Test\r\nCLASS:PRIVATE\r\nTRANSP:OPAQUE\r\nSTATUS:CONFIRMED\r\nDTEND;TZID=Europe/Berlin:20160419T140000\r\nLAST-MODIFIED:20160419T074202Z\r\nDTSTAMP:20160419T074202Z\r\nCREATED:20160419T074202Z\r\nUID:2e468c48-7860-492e-bc52-92fa0daeeccf.1461051722310\r\nEND:VEVENT\r\nEND:VCALENDAR"],
  593. 'CLASS:PUBLIC' => [CalDavBackend::CLASSIFICATION_PUBLIC, 'classification', "BEGIN:VCALENDAR\r\nVERSION:2.0\r\nPRODID:-//dmfs.org//mimedir.icalendar//EN\r\nBEGIN:VTIMEZONE\r\nTZID:Europe/Berlin\r\nX-LIC-LOCATION:Europe/Berlin\r\nBEGIN:DAYLIGHT\r\nTZOFFSETFROM:+0100\r\nTZOFFSETTO:+0200\r\nTZNAME:CEST\r\nDTSTART:19700329T020000\r\nRRULE:FREQ=YEARLY;BYMONTH=3;BYDAY=-1SU\r\nEND:DAYLIGHT\r\nBEGIN:STANDARD\r\nTZOFFSETFROM:+0200\r\nTZOFFSETTO:+0100\r\nTZNAME:CET\r\nDTSTART:19701025T030000\r\nRRULE:FREQ=YEARLY;BYMONTH=10;BYDAY=-1SU\r\nEND:STANDARD\r\nEND:VTIMEZONE\r\nBEGIN:VEVENT\r\nDTSTART;TZID=Europe/Berlin:20160419T130000\r\nSUMMARY:Test\r\nCLASS:PUBLIC\r\nTRANSP:OPAQUE\r\nSTATUS:CONFIRMED\r\nDTEND;TZID=Europe/Berlin:20160419T140000\r\nLAST-MODIFIED:20160419T074202Z\r\nDTSTAMP:20160419T074202Z\r\nCREATED:20160419T074202Z\r\nUID:2e468c48-7860-492e-bc52-92fa0daeeccf.1461051722310\r\nEND:VEVENT\r\nEND:VCALENDAR"],
  594. 'CLASS:CONFIDENTIAL' => [CalDavBackend::CLASSIFICATION_CONFIDENTIAL, 'classification', "BEGIN:VCALENDAR\r\nVERSION:2.0\r\nPRODID:-//dmfs.org//mimedir.icalendar//EN\r\nBEGIN:VTIMEZONE\r\nTZID:Europe/Berlin\r\nX-LIC-LOCATION:Europe/Berlin\r\nBEGIN:DAYLIGHT\r\nTZOFFSETFROM:+0100\r\nTZOFFSETTO:+0200\r\nTZNAME:CEST\r\nDTSTART:19700329T020000\r\nRRULE:FREQ=YEARLY;BYMONTH=3;BYDAY=-1SU\r\nEND:DAYLIGHT\r\nBEGIN:STANDARD\r\nTZOFFSETFROM:+0200\r\nTZOFFSETTO:+0100\r\nTZNAME:CET\r\nDTSTART:19701025T030000\r\nRRULE:FREQ=YEARLY;BYMONTH=10;BYDAY=-1SU\r\nEND:STANDARD\r\nEND:VTIMEZONE\r\nBEGIN:VEVENT\r\nDTSTART;TZID=Europe/Berlin:20160419T130000\r\nSUMMARY:Test\r\nCLASS:CONFIDENTIAL\r\nTRANSP:OPAQUE\r\nSTATUS:CONFIRMED\r\nDTEND;TZID=Europe/Berlin:20160419T140000\r\nLAST-MODIFIED:20160419T074202Z\r\nDTSTAMP:20160419T074202Z\r\nCREATED:20160419T074202Z\r\nUID:2e468c48-7860-492e-bc52-92fa0daeeccf.1461051722310\r\nEND:VEVENT\r\nEND:VCALENDAR"],
  595. 'no class set -> public' => [CalDavBackend::CLASSIFICATION_PUBLIC, 'classification', "BEGIN:VCALENDAR\r\nVERSION:2.0\r\nPRODID:-//dmfs.org//mimedir.icalendar//EN\r\nBEGIN:VTIMEZONE\r\nTZID:Europe/Berlin\r\nX-LIC-LOCATION:Europe/Berlin\r\nBEGIN:DAYLIGHT\r\nTZOFFSETFROM:+0100\r\nTZOFFSETTO:+0200\r\nTZNAME:CEST\r\nDTSTART:19700329T020000\r\nRRULE:FREQ=YEARLY;BYMONTH=3;BYDAY=-1SU\r\nEND:DAYLIGHT\r\nBEGIN:STANDARD\r\nTZOFFSETFROM:+0200\r\nTZOFFSETTO:+0100\r\nTZNAME:CET\r\nDTSTART:19701025T030000\r\nRRULE:FREQ=YEARLY;BYMONTH=10;BYDAY=-1SU\r\nEND:STANDARD\r\nEND:VTIMEZONE\r\nBEGIN:VEVENT\r\nDTSTART;TZID=Europe/Berlin:20160419T130000\r\nSUMMARY:Test\r\nTRANSP:OPAQUE\r\nDTEND;TZID=Europe/Berlin:20160419T140000\r\nLAST-MODIFIED:20160419T074202Z\r\nDTSTAMP:20160419T074202Z\r\nCREATED:20160419T074202Z\r\nUID:2e468c48-7860-492e-bc52-92fa0daeeccf.1461051722310\r\nEND:VEVENT\r\nEND:VCALENDAR"],
  596. 'unknown class -> private' => [CalDavBackend::CLASSIFICATION_PRIVATE, 'classification', "BEGIN:VCALENDAR\r\nVERSION:2.0\r\nPRODID:-//dmfs.org//mimedir.icalendar//EN\r\nBEGIN:VTIMEZONE\r\nTZID:Europe/Berlin\r\nX-LIC-LOCATION:Europe/Berlin\r\nBEGIN:DAYLIGHT\r\nTZOFFSETFROM:+0100\r\nTZOFFSETTO:+0200\r\nTZNAME:CEST\r\nDTSTART:19700329T020000\r\nRRULE:FREQ=YEARLY;BYMONTH=3;BYDAY=-1SU\r\nEND:DAYLIGHT\r\nBEGIN:STANDARD\r\nTZOFFSETFROM:+0200\r\nTZOFFSETTO:+0100\r\nTZNAME:CET\r\nDTSTART:19701025T030000\r\nRRULE:FREQ=YEARLY;BYMONTH=10;BYDAY=-1SU\r\nEND:STANDARD\r\nEND:VTIMEZONE\r\nBEGIN:VEVENT\r\nDTSTART;TZID=Europe/Berlin:20160419T130000\r\nSUMMARY:Test\r\nCLASS:VERTRAULICH\r\nTRANSP:OPAQUE\r\nSTATUS:CONFIRMED\r\nDTEND;TZID=Europe/Berlin:20160419T140000\r\nLAST-MODIFIED:20160419T074202Z\r\nDTSTAMP:20160419T074202Z\r\nCREATED:20160419T074202Z\r\nUID:2e468c48-7860-492e-bc52-92fa0daeeccf.1461051722310\r\nEND:VEVENT\r\nEND:VCALENDAR"],
  597. ];
  598. }
  599. public function testCalendarSearch(): void {
  600. $calendarId = $this->createTestCalendar();
  601. $uri = static::getUniqueID('calobj');
  602. $calData = <<<EOD
  603. BEGIN:VCALENDAR
  604. VERSION:2.0
  605. PRODID:ownCloud Calendar
  606. BEGIN:VEVENT
  607. CREATED;VALUE=DATE-TIME:20130910T125139Z
  608. UID:47d15e3ec8
  609. LAST-MODIFIED;VALUE=DATE-TIME:20130910T125139Z
  610. DTSTAMP;VALUE=DATE-TIME:20130910T125139Z
  611. SUMMARY:Test Event
  612. DTSTART;VALUE=DATE-TIME:20130912T130000Z
  613. DTEND;VALUE=DATE-TIME:20130912T140000Z
  614. CLASS:PUBLIC
  615. END:VEVENT
  616. END:VCALENDAR
  617. EOD;
  618. $this->backend->createCalendarObject($calendarId, $uri, $calData);
  619. $search1 = $this->backend->calendarSearch(self::UNIT_TEST_USER, [
  620. 'comps' => [
  621. 'VEVENT',
  622. 'VTODO'
  623. ],
  624. 'props' => [
  625. 'SUMMARY',
  626. 'LOCATION'
  627. ],
  628. 'search-term' => 'Test',
  629. ]);
  630. $this->assertEquals(count($search1), 1);
  631. // update the card
  632. $calData = <<<'EOD'
  633. BEGIN:VCALENDAR
  634. VERSION:2.0
  635. PRODID:ownCloud Calendar
  636. BEGIN:VEVENT
  637. CREATED;VALUE=DATE-TIME:20130910T125139Z
  638. UID:47d15e3ec8
  639. LAST-MODIFIED;VALUE=DATE-TIME:20130910T125139Z
  640. DTSTAMP;VALUE=DATE-TIME:20130910T125139Z
  641. SUMMARY:123 Event 🙈
  642. DTSTART;VALUE=DATE-TIME:20130912T130000Z
  643. DTEND;VALUE=DATE-TIME:20130912T140000Z
  644. ATTENDEE;CN=test:mailto:foo@bar.com
  645. END:VEVENT
  646. END:VCALENDAR
  647. EOD;
  648. $this->backend->updateCalendarObject($calendarId, $uri, $calData);
  649. $search2 = $this->backend->calendarSearch(self::UNIT_TEST_USER, [
  650. 'comps' => [
  651. 'VEVENT',
  652. 'VTODO'
  653. ],
  654. 'props' => [
  655. 'SUMMARY',
  656. 'LOCATION'
  657. ],
  658. 'search-term' => 'Test',
  659. ]);
  660. $this->assertEquals(count($search2), 0);
  661. $search3 = $this->backend->calendarSearch(self::UNIT_TEST_USER, [
  662. 'comps' => [
  663. 'VEVENT',
  664. 'VTODO'
  665. ],
  666. 'props' => [
  667. 'SUMMARY',
  668. 'LOCATION'
  669. ],
  670. 'params' => [
  671. [
  672. 'property' => 'ATTENDEE',
  673. 'parameter' => 'CN'
  674. ]
  675. ],
  676. 'search-term' => 'Test',
  677. ]);
  678. $this->assertEquals(count($search3), 1);
  679. // t matches both summary and attendee's CN, but we want unique results
  680. $search4 = $this->backend->calendarSearch(self::UNIT_TEST_USER, [
  681. 'comps' => [
  682. 'VEVENT',
  683. 'VTODO'
  684. ],
  685. 'props' => [
  686. 'SUMMARY',
  687. 'LOCATION'
  688. ],
  689. 'params' => [
  690. [
  691. 'property' => 'ATTENDEE',
  692. 'parameter' => 'CN'
  693. ]
  694. ],
  695. 'search-term' => 't',
  696. ]);
  697. $this->assertEquals(count($search4), 1);
  698. $this->backend->deleteCalendarObject($calendarId, $uri);
  699. $search5 = $this->backend->calendarSearch(self::UNIT_TEST_USER, [
  700. 'comps' => [
  701. 'VEVENT',
  702. 'VTODO'
  703. ],
  704. 'props' => [
  705. 'SUMMARY',
  706. 'LOCATION'
  707. ],
  708. 'params' => [
  709. [
  710. 'property' => 'ATTENDEE',
  711. 'parameter' => 'CN'
  712. ]
  713. ],
  714. 'search-term' => 't',
  715. ]);
  716. $this->assertEquals(count($search5), 0);
  717. }
  718. /**
  719. * @dataProvider searchDataProvider
  720. */
  721. public function testSearch(bool $isShared, array $searchOptions, int $count): void {
  722. $calendarId = $this->createTestCalendar();
  723. $uris = [];
  724. $calData = [];
  725. $uris[] = static::getUniqueID('calobj');
  726. $calData[] = <<<EOD
  727. BEGIN:VCALENDAR
  728. VERSION:2.0
  729. PRODID:Nextcloud Calendar
  730. BEGIN:VEVENT
  731. CREATED;VALUE=DATE-TIME:20130910T125139Z
  732. UID:47d15e3ec8-1
  733. LAST-MODIFIED;VALUE=DATE-TIME:20130910T125139Z
  734. DTSTAMP;VALUE=DATE-TIME:20130910T125139Z
  735. SUMMARY:Test Event
  736. DTSTART;VALUE=DATE-TIME:20130912T130000Z
  737. DTEND;VALUE=DATE-TIME:20130912T140000Z
  738. CLASS:PUBLIC
  739. END:VEVENT
  740. END:VCALENDAR
  741. EOD;
  742. $uris[] = static::getUniqueID('calobj');
  743. $calData[] = <<<EOD
  744. BEGIN:VCALENDAR
  745. VERSION:2.0
  746. PRODID:Nextcloud Calendar
  747. BEGIN:VEVENT
  748. CREATED;VALUE=DATE-TIME:20130910T125139Z
  749. UID:47d15e3ec8-2
  750. LAST-MODIFIED;VALUE=DATE-TIME:20130910T125139Z
  751. DTSTAMP;VALUE=DATE-TIME:20130910T125139Z
  752. SUMMARY:123
  753. LOCATION:Test
  754. DTSTART;VALUE=DATE-TIME:20130912T130000Z
  755. DTEND;VALUE=DATE-TIME:20130912T140000Z
  756. CLASS:PUBLIC
  757. END:VEVENT
  758. END:VCALENDAR
  759. EOD;
  760. $uris[] = static::getUniqueID('calobj');
  761. $calData[] = <<<EOD
  762. BEGIN:VCALENDAR
  763. VERSION:2.0
  764. PRODID:Nextcloud Calendar
  765. BEGIN:VEVENT
  766. CREATED;VALUE=DATE-TIME:20130910T125139Z
  767. UID:47d15e3ec8-3
  768. LAST-MODIFIED;VALUE=DATE-TIME:20130910T125139Z
  769. DTSTAMP;VALUE=DATE-TIME:20130910T125139Z
  770. SUMMARY:123
  771. ATTENDEE;CN=test:mailto:foo@bar.com
  772. DTSTART;VALUE=DATE-TIME:20130912T130000Z
  773. DTEND;VALUE=DATE-TIME:20130912T140000Z
  774. CLASS:PRIVATE
  775. END:VEVENT
  776. END:VCALENDAR
  777. EOD;
  778. $uris[] = static::getUniqueID('calobj');
  779. $calData[] = <<<EOD
  780. BEGIN:VCALENDAR
  781. VERSION:2.0
  782. PRODID:Nextcloud Calendar
  783. BEGIN:VEVENT
  784. CREATED;VALUE=DATE-TIME:20130910T125139Z
  785. UID:47d15e3ec8-4
  786. LAST-MODIFIED;VALUE=DATE-TIME:20130910T125139Z
  787. DTSTAMP;VALUE=DATE-TIME:20130910T125139Z
  788. SUMMARY:123
  789. ATTENDEE;CN=foobar:mailto:test@bar.com
  790. DTSTART;VALUE=DATE-TIME:20130912T130000Z
  791. DTEND;VALUE=DATE-TIME:20130912T140000Z
  792. CLASS:CONFIDENTIAL
  793. END:VEVENT
  794. END:VCALENDAR
  795. EOD;
  796. $uriCount = count($uris);
  797. for ($i = 0; $i < $uriCount; $i++) {
  798. $this->backend->createCalendarObject($calendarId,
  799. $uris[$i], $calData[$i]);
  800. }
  801. $calendarInfo = [
  802. 'id' => $calendarId,
  803. 'principaluri' => 'user1',
  804. '{http://owncloud.org/ns}owner-principal' => $isShared ? 'user2' : 'user1',
  805. ];
  806. $result = $this->backend->search($calendarInfo, 'Test',
  807. ['SUMMARY', 'LOCATION', 'ATTENDEE'], $searchOptions, null, null);
  808. $this->assertCount($count, $result);
  809. }
  810. public function searchDataProvider() {
  811. return [
  812. [false, [], 4],
  813. [true, ['timerange' => ['start' => new DateTime('2013-09-12 13:00:00'), 'end' => new DateTime('2013-09-12 14:00:00')]], 2],
  814. [true, ['timerange' => ['start' => new DateTime('2013-09-12 15:00:00'), 'end' => new DateTime('2013-09-12 16:00:00')]], 0],
  815. ];
  816. }
  817. public function testSameUriSameIdForDifferentCalendarTypes(): void {
  818. $calendarId = $this->createTestCalendar();
  819. $subscriptionId = $this->createTestSubscription();
  820. $uri = static::getUniqueID('calobj');
  821. $calData = <<<EOD
  822. BEGIN:VCALENDAR
  823. VERSION:2.0
  824. PRODID:ownCloud Calendar
  825. BEGIN:VEVENT
  826. CREATED;VALUE=DATE-TIME:20130910T125139Z
  827. UID:47d15e3ec8
  828. LAST-MODIFIED;VALUE=DATE-TIME:20130910T125139Z
  829. DTSTAMP;VALUE=DATE-TIME:20130910T125139Z
  830. SUMMARY:Test Event
  831. DTSTART;VALUE=DATE-TIME:20130912T130000Z
  832. DTEND;VALUE=DATE-TIME:20130912T140000Z
  833. CLASS:PUBLIC
  834. END:VEVENT
  835. END:VCALENDAR
  836. EOD;
  837. $calData2 = <<<EOD
  838. BEGIN:VCALENDAR
  839. VERSION:2.0
  840. PRODID:ownCloud Calendar
  841. BEGIN:VEVENT
  842. CREATED;VALUE=DATE-TIME:20130910T125139Z
  843. UID:47d15e3ec8
  844. LAST-MODIFIED;VALUE=DATE-TIME:20130910T125139Z
  845. DTSTAMP;VALUE=DATE-TIME:20130910T125139Z
  846. SUMMARY:Test Event 123
  847. DTSTART;VALUE=DATE-TIME:20130912T130000Z
  848. DTEND;VALUE=DATE-TIME:20130912T140000Z
  849. CLASS:PUBLIC
  850. END:VEVENT
  851. END:VCALENDAR
  852. EOD;
  853. $this->backend->createCalendarObject($calendarId, $uri, $calData);
  854. $this->backend->createCalendarObject($subscriptionId, $uri, $calData2, CalDavBackend::CALENDAR_TYPE_SUBSCRIPTION);
  855. $this->assertEquals($calData, $this->backend->getCalendarObject($calendarId, $uri, CalDavBackend::CALENDAR_TYPE_CALENDAR)['calendardata']);
  856. $this->assertEquals($calData2, $this->backend->getCalendarObject($subscriptionId, $uri, CalDavBackend::CALENDAR_TYPE_SUBSCRIPTION)['calendardata']);
  857. }
  858. public function testPurgeAllCachedEventsForSubscription(): void {
  859. $subscriptionId = $this->createTestSubscription();
  860. $uri = static::getUniqueID('calobj');
  861. $calData = <<<EOD
  862. BEGIN:VCALENDAR
  863. VERSION:2.0
  864. PRODID:ownCloud Calendar
  865. BEGIN:VEVENT
  866. CREATED;VALUE=DATE-TIME:20130910T125139Z
  867. UID:47d15e3ec8
  868. LAST-MODIFIED;VALUE=DATE-TIME:20130910T125139Z
  869. DTSTAMP;VALUE=DATE-TIME:20130910T125139Z
  870. SUMMARY:Test Event
  871. DTSTART;VALUE=DATE-TIME:20130912T130000Z
  872. DTEND;VALUE=DATE-TIME:20130912T140000Z
  873. CLASS:PUBLIC
  874. END:VEVENT
  875. END:VCALENDAR
  876. EOD;
  877. $this->backend->createCalendarObject($subscriptionId, $uri, $calData, CalDavBackend::CALENDAR_TYPE_SUBSCRIPTION);
  878. $this->backend->purgeAllCachedEventsForSubscription($subscriptionId);
  879. $this->assertEquals(null, $this->backend->getCalendarObject($subscriptionId, $uri, CalDavBackend::CALENDAR_TYPE_SUBSCRIPTION));
  880. }
  881. public function testCalendarMovement(): void {
  882. $this->backend->createCalendar(self::UNIT_TEST_USER, 'Example', []);
  883. $this->assertCount(1, $this->backend->getCalendarsForUser(self::UNIT_TEST_USER));
  884. $calendarInfoUser = $this->backend->getCalendarsForUser(self::UNIT_TEST_USER)[0];
  885. $this->backend->moveCalendar('Example', self::UNIT_TEST_USER, self::UNIT_TEST_USER1);
  886. $this->assertCount(0, $this->backend->getCalendarsForUser(self::UNIT_TEST_USER));
  887. $this->assertCount(1, $this->backend->getCalendarsForUser(self::UNIT_TEST_USER1));
  888. $calendarInfoUser1 = $this->backend->getCalendarsForUser(self::UNIT_TEST_USER1)[0];
  889. $this->assertEquals($calendarInfoUser['id'], $calendarInfoUser1['id']);
  890. $this->assertEquals($calendarInfoUser['uri'], $calendarInfoUser1['uri']);
  891. }
  892. public function testSearchPrincipal(): void {
  893. $myPublic = <<<EOD
  894. BEGIN:VCALENDAR
  895. VERSION:2.0
  896. PRODID:-//dmfs.org//mimedir.icalendar//EN
  897. BEGIN:VTIMEZONE
  898. TZID:Europe/Berlin
  899. X-LIC-LOCATION:Europe/Berlin
  900. BEGIN:DAYLIGHT
  901. TZOFFSETFROM:+0100
  902. TZOFFSETTO:+0200
  903. TZNAME:CEST
  904. DTSTART:19700329T020000
  905. RRULE:FREQ=YEARLY;BYMONTH=3;BYDAY=-1SU
  906. END:DAYLIGHT
  907. BEGIN:STANDARD
  908. TZOFFSETFROM:+0200
  909. TZOFFSETTO:+0100
  910. TZNAME:CET
  911. DTSTART:19701025T030000
  912. RRULE:FREQ=YEARLY;BYMONTH=10;BYDAY=-1SU
  913. END:STANDARD
  914. END:VTIMEZONE
  915. BEGIN:VEVENT
  916. DTSTART;TZID=Europe/Berlin:20160419T130000
  917. SUMMARY:My Test (public)
  918. CLASS:PUBLIC
  919. TRANSP:OPAQUE
  920. STATUS:CONFIRMED
  921. DTEND;TZID=Europe/Berlin:20160419T140000
  922. LAST-MODIFIED:20160419T074202Z
  923. DTSTAMP:20160419T074202Z
  924. CREATED:20160419T074202Z
  925. UID:2e468c48-7860-492e-bc52-92fa0daeeccf.1461051722310-1
  926. END:VEVENT
  927. END:VCALENDAR
  928. EOD;
  929. $myPrivate = <<<EOD
  930. BEGIN:VCALENDAR
  931. VERSION:2.0
  932. PRODID:-//dmfs.org//mimedir.icalendar//EN
  933. BEGIN:VTIMEZONE
  934. TZID:Europe/Berlin
  935. X-LIC-LOCATION:Europe/Berlin
  936. BEGIN:DAYLIGHT
  937. TZOFFSETFROM:+0100
  938. TZOFFSETTO:+0200
  939. TZNAME:CEST
  940. DTSTART:19700329T020000
  941. RRULE:FREQ=YEARLY;BYMONTH=3;BYDAY=-1SU
  942. END:DAYLIGHT
  943. BEGIN:STANDARD
  944. TZOFFSETFROM:+0200
  945. TZOFFSETTO:+0100
  946. TZNAME:CET
  947. DTSTART:19701025T030000
  948. RRULE:FREQ=YEARLY;BYMONTH=10;BYDAY=-1SU
  949. END:STANDARD
  950. END:VTIMEZONE
  951. BEGIN:VEVENT
  952. DTSTART;TZID=Europe/Berlin:20160419T130000
  953. SUMMARY:My Test (private)
  954. CLASS:PRIVATE
  955. TRANSP:OPAQUE
  956. STATUS:CONFIRMED
  957. DTEND;TZID=Europe/Berlin:20160419T140000
  958. LAST-MODIFIED:20160419T074202Z
  959. DTSTAMP:20160419T074202Z
  960. CREATED:20160419T074202Z
  961. UID:2e468c48-7860-492e-bc52-92fa0daeeccf.1461051722310-2
  962. END:VEVENT
  963. END:VCALENDAR
  964. EOD;
  965. $myConfidential = <<<EOD
  966. BEGIN:VCALENDAR
  967. VERSION:2.0
  968. PRODID:-//dmfs.org//mimedir.icalendar//EN
  969. BEGIN:VTIMEZONE
  970. TZID:Europe/Berlin
  971. X-LIC-LOCATION:Europe/Berlin
  972. BEGIN:DAYLIGHT
  973. TZOFFSETFROM:+0100
  974. TZOFFSETTO:+0200
  975. TZNAME:CEST
  976. DTSTART:19700329T020000
  977. RRULE:FREQ=YEARLY;BYMONTH=3;BYDAY=-1SU
  978. END:DAYLIGHT
  979. BEGIN:STANDARD
  980. TZOFFSETFROM:+0200
  981. TZOFFSETTO:+0100
  982. TZNAME:CET
  983. DTSTART:19701025T030000
  984. RRULE:FREQ=YEARLY;BYMONTH=10;BYDAY=-1SU
  985. END:STANDARD
  986. END:VTIMEZONE
  987. BEGIN:VEVENT
  988. DTSTART;TZID=Europe/Berlin:20160419T130000
  989. SUMMARY:My Test (confidential)
  990. CLASS:CONFIDENTIAL
  991. TRANSP:OPAQUE
  992. STATUS:CONFIRMED
  993. DTEND;TZID=Europe/Berlin:20160419T140000
  994. LAST-MODIFIED:20160419T074202Z
  995. DTSTAMP:20160419T074202Z
  996. CREATED:20160419T074202Z
  997. UID:2e468c48-7860-492e-bc52-92fa0daeeccf.1461051722310-3
  998. END:VEVENT
  999. END:VCALENDAR
  1000. EOD;
  1001. $sharerPublic = <<<EOD
  1002. BEGIN:VCALENDAR
  1003. VERSION:2.0
  1004. PRODID:-//dmfs.org//mimedir.icalendar//EN
  1005. BEGIN:VTIMEZONE
  1006. TZID:Europe/Berlin
  1007. X-LIC-LOCATION:Europe/Berlin
  1008. BEGIN:DAYLIGHT
  1009. TZOFFSETFROM:+0100
  1010. TZOFFSETTO:+0200
  1011. TZNAME:CEST
  1012. DTSTART:19700329T020000
  1013. RRULE:FREQ=YEARLY;BYMONTH=3;BYDAY=-1SU
  1014. END:DAYLIGHT
  1015. BEGIN:STANDARD
  1016. TZOFFSETFROM:+0200
  1017. TZOFFSETTO:+0100
  1018. TZNAME:CET
  1019. DTSTART:19701025T030000
  1020. RRULE:FREQ=YEARLY;BYMONTH=10;BYDAY=-1SU
  1021. END:STANDARD
  1022. END:VTIMEZONE
  1023. BEGIN:VEVENT
  1024. DTSTART;TZID=Europe/Berlin:20160419T130000
  1025. SUMMARY:Sharer Test (public)
  1026. CLASS:PUBLIC
  1027. TRANSP:OPAQUE
  1028. STATUS:CONFIRMED
  1029. DTEND;TZID=Europe/Berlin:20160419T140000
  1030. LAST-MODIFIED:20160419T074202Z
  1031. DTSTAMP:20160419T074202Z
  1032. CREATED:20160419T074202Z
  1033. UID:2e468c48-7860-492e-bc52-92fa0daeeccf.1461051722310-4
  1034. END:VEVENT
  1035. END:VCALENDAR
  1036. EOD;
  1037. $sharerPrivate = <<<EOD
  1038. BEGIN:VCALENDAR
  1039. VERSION:2.0
  1040. PRODID:-//dmfs.org//mimedir.icalendar//EN
  1041. BEGIN:VTIMEZONE
  1042. TZID:Europe/Berlin
  1043. X-LIC-LOCATION:Europe/Berlin
  1044. BEGIN:DAYLIGHT
  1045. TZOFFSETFROM:+0100
  1046. TZOFFSETTO:+0200
  1047. TZNAME:CEST
  1048. DTSTART:19700329T020000
  1049. RRULE:FREQ=YEARLY;BYMONTH=3;BYDAY=-1SU
  1050. END:DAYLIGHT
  1051. BEGIN:STANDARD
  1052. TZOFFSETFROM:+0200
  1053. TZOFFSETTO:+0100
  1054. TZNAME:CET
  1055. DTSTART:19701025T030000
  1056. RRULE:FREQ=YEARLY;BYMONTH=10;BYDAY=-1SU
  1057. END:STANDARD
  1058. END:VTIMEZONE
  1059. BEGIN:VEVENT
  1060. DTSTART;TZID=Europe/Berlin:20160419T130000
  1061. SUMMARY:Sharer Test (private)
  1062. CLASS:PRIVATE
  1063. TRANSP:OPAQUE
  1064. STATUS:CONFIRMED
  1065. DTEND;TZID=Europe/Berlin:20160419T140000
  1066. LAST-MODIFIED:20160419T074202Z
  1067. DTSTAMP:20160419T074202Z
  1068. CREATED:20160419T074202Z
  1069. UID:2e468c48-7860-492e-bc52-92fa0daeeccf.1461051722310-5
  1070. END:VEVENT
  1071. END:VCALENDAR
  1072. EOD;
  1073. $sharerConfidential = <<<EOD
  1074. BEGIN:VCALENDAR
  1075. VERSION:2.0
  1076. PRODID:-//dmfs.org//mimedir.icalendar//EN
  1077. BEGIN:VTIMEZONE
  1078. TZID:Europe/Berlin
  1079. X-LIC-LOCATION:Europe/Berlin
  1080. BEGIN:DAYLIGHT
  1081. TZOFFSETFROM:+0100
  1082. TZOFFSETTO:+0200
  1083. TZNAME:CEST
  1084. DTSTART:19700329T020000
  1085. RRULE:FREQ=YEARLY;BYMONTH=3;BYDAY=-1SU
  1086. END:DAYLIGHT
  1087. BEGIN:STANDARD
  1088. TZOFFSETFROM:+0200
  1089. TZOFFSETTO:+0100
  1090. TZNAME:CET
  1091. DTSTART:19701025T030000
  1092. RRULE:FREQ=YEARLY;BYMONTH=10;BYDAY=-1SU
  1093. END:STANDARD
  1094. END:VTIMEZONE
  1095. BEGIN:VEVENT
  1096. DTSTART;TZID=Europe/Berlin:20160419T130000
  1097. SUMMARY:Sharer Test (confidential)
  1098. CLASS:CONFIDENTIAL
  1099. TRANSP:OPAQUE
  1100. STATUS:CONFIRMED
  1101. DTEND;TZID=Europe/Berlin:20160419T140000
  1102. LAST-MODIFIED:20160419T074202Z
  1103. DTSTAMP:20160419T074202Z
  1104. CREATED:20160419T074202Z
  1105. UID:2e468c48-7860-492e-bc52-92fa0daeeccf.1461051722310-6
  1106. END:VEVENT
  1107. END:VCALENDAR
  1108. EOD;
  1109. $l10n = $this->createMock(IL10N::class);
  1110. $l10n
  1111. ->expects($this->any())
  1112. ->method('t')
  1113. ->willReturnCallback(function ($text, $parameters = []) {
  1114. return vsprintf($text, $parameters);
  1115. });
  1116. $config = $this->createMock(IConfig::class);
  1117. $this->userManager->expects($this->any())
  1118. ->method('userExists')
  1119. ->willReturn(true);
  1120. $this->groupManager->expects($this->any())
  1121. ->method('groupExists')
  1122. ->willReturn(true);
  1123. $this->principal->expects(self::atLeastOnce())
  1124. ->method('findByUri')
  1125. ->willReturn(self::UNIT_TEST_USER);
  1126. $me = self::UNIT_TEST_USER;
  1127. $sharer = self::UNIT_TEST_USER1;
  1128. $this->backend->createCalendar($me, 'calendar-uri-me', []);
  1129. $this->backend->createCalendar($sharer, 'calendar-uri-sharer', []);
  1130. $myCalendars = $this->backend->getCalendarsForUser($me);
  1131. $this->assertCount(1, $myCalendars);
  1132. $sharerCalendars = $this->backend->getCalendarsForUser($sharer);
  1133. $this->assertCount(1, $sharerCalendars);
  1134. $logger = $this->createMock(\Psr\Log\LoggerInterface::class);
  1135. $sharerCalendar = new Calendar($this->backend, $sharerCalendars[0], $l10n, $config, $logger);
  1136. $this->backend->updateShares($sharerCalendar, [
  1137. [
  1138. 'href' => 'principal:' . $me,
  1139. 'readOnly' => false,
  1140. ],
  1141. ], []);
  1142. $this->assertCount(2, $this->backend->getCalendarsForUser($me));
  1143. $this->backend->createCalendarObject($myCalendars[0]['id'], 'event0.ics', $myPublic);
  1144. $this->backend->createCalendarObject($myCalendars[0]['id'], 'event1.ics', $myPrivate);
  1145. $this->backend->createCalendarObject($myCalendars[0]['id'], 'event2.ics', $myConfidential);
  1146. $this->backend->createCalendarObject($sharerCalendars[0]['id'], 'event3.ics', $sharerPublic);
  1147. $this->backend->createCalendarObject($sharerCalendars[0]['id'], 'event4.ics', $sharerPrivate);
  1148. $this->backend->createCalendarObject($sharerCalendars[0]['id'], 'event5.ics', $sharerConfidential);
  1149. $mySearchResults = $this->backend->searchPrincipalUri($me, 'Test', ['VEVENT'], ['SUMMARY'], []);
  1150. $sharerSearchResults = $this->backend->searchPrincipalUri($sharer, 'Test', ['VEVENT'], ['SUMMARY'], []);
  1151. $this->assertCount(4, $mySearchResults);
  1152. $this->assertCount(3, $sharerSearchResults);
  1153. $this->assertEquals($myPublic, $mySearchResults[0]['calendardata']);
  1154. $this->assertEquals($myPrivate, $mySearchResults[1]['calendardata']);
  1155. $this->assertEquals($myConfidential, $mySearchResults[2]['calendardata']);
  1156. $this->assertEquals($sharerPublic, $mySearchResults[3]['calendardata']);
  1157. $this->assertEquals($sharerPublic, $sharerSearchResults[0]['calendardata']);
  1158. $this->assertEquals($sharerPrivate, $sharerSearchResults[1]['calendardata']);
  1159. $this->assertEquals($sharerConfidential, $sharerSearchResults[2]['calendardata']);
  1160. }
  1161. /**
  1162. * @throws \OCP\DB\Exception
  1163. * @throws \Sabre\DAV\Exception\BadRequest
  1164. */
  1165. public function testPruneOutdatedSyncTokens(): void {
  1166. $calendarId = $this->createTestCalendar();
  1167. $changes = $this->backend->getChangesForCalendar($calendarId, '', 1);
  1168. $syncToken = $changes['syncToken'];
  1169. $uri = static::getUniqueID('calobj');
  1170. $calData = <<<EOD
  1171. BEGIN:VCALENDAR
  1172. VERSION:2.0
  1173. PRODID:Nextcloud Calendar
  1174. BEGIN:VEVENT
  1175. CREATED;VALUE=DATE-TIME:20130910T125139Z
  1176. UID:47d15e3ec8
  1177. LAST-MODIFIED;VALUE=DATE-TIME:20130910T125139Z
  1178. DTSTAMP;VALUE=DATE-TIME:20130910T125139Z
  1179. SUMMARY:Test Event
  1180. DTSTART;VALUE=DATE-TIME:20130912T130000Z
  1181. DTEND;VALUE=DATE-TIME:20130912T140000Z
  1182. CLASS:PUBLIC
  1183. END:VEVENT
  1184. END:VCALENDAR
  1185. EOD;
  1186. $this->backend->createCalendarObject($calendarId, $uri, $calData);
  1187. // update the card
  1188. $calData = <<<'EOD'
  1189. BEGIN:VCALENDAR
  1190. VERSION:2.0
  1191. PRODID:Nextcloud Calendar
  1192. BEGIN:VEVENT
  1193. CREATED;VALUE=DATE-TIME:20130910T125139Z
  1194. UID:47d15e3ec8
  1195. LAST-MODIFIED;VALUE=DATE-TIME:20130910T125139Z
  1196. DTSTAMP;VALUE=DATE-TIME:20130910T125139Z
  1197. SUMMARY:123 Event 🙈
  1198. DTSTART;VALUE=DATE-TIME:20130912T130000Z
  1199. DTEND;VALUE=DATE-TIME:20130912T140000Z
  1200. ATTENDEE;CN=test:mailto:foo@bar.com
  1201. END:VEVENT
  1202. END:VCALENDAR
  1203. EOD;
  1204. $this->backend->updateCalendarObject($calendarId, $uri, $calData);
  1205. // Keep everything
  1206. $deleted = $this->backend->pruneOutdatedSyncTokens(0, 0);
  1207. self::assertSame(0, $deleted);
  1208. $deleted = $this->backend->pruneOutdatedSyncTokens(0, time());
  1209. // At least one from the object creation and one from the object update
  1210. $this->assertGreaterThanOrEqual(2, $deleted);
  1211. $changes = $this->backend->getChangesForCalendar($calendarId, $syncToken, 1);
  1212. $this->assertEmpty($changes['added']);
  1213. $this->assertEmpty($changes['modified']);
  1214. $this->assertEmpty($changes['deleted']);
  1215. // Test that objects remain
  1216. // Currently changes are empty
  1217. $changes = $this->backend->getChangesForCalendar($calendarId, $syncToken, 100);
  1218. $this->assertEquals(0, count($changes['added'] + $changes['modified'] + $changes['deleted']));
  1219. // Create card
  1220. $uri = static::getUniqueID('calobj');
  1221. $calData = <<<EOD
  1222. BEGIN:VCALENDAR
  1223. VERSION:2.0
  1224. PRODID:Nextcloud Calendar
  1225. BEGIN:VEVENT
  1226. CREATED;VALUE=DATE-TIME:20230910T125139Z
  1227. UID:47d15e3ec9
  1228. LAST-MODIFIED;VALUE=DATE-TIME:20230910T125139Z
  1229. DTSTAMP;VALUE=DATE-TIME:20230910T125139Z
  1230. SUMMARY:Test Event
  1231. DTSTART;VALUE=DATE-TIME:20230912T130000Z
  1232. DTEND;VALUE=DATE-TIME:20230912T140000Z
  1233. CLASS:PUBLIC
  1234. END:VEVENT
  1235. END:VCALENDAR
  1236. EOD;
  1237. $this->backend->createCalendarObject($calendarId, $uri, $calData);
  1238. // We now have one add
  1239. $changes = $this->backend->getChangesForCalendar($calendarId, $syncToken, 100);
  1240. $this->assertEquals(1, count($changes['added']));
  1241. $this->assertEmpty($changes['modified']);
  1242. $this->assertEmpty($changes['deleted']);
  1243. // update the card
  1244. $calData = <<<'EOD'
  1245. BEGIN:VCALENDAR
  1246. VERSION:2.0
  1247. PRODID:Nextcloud Calendar
  1248. BEGIN:VEVENT
  1249. CREATED;VALUE=DATE-TIME:20230910T125139Z
  1250. UID:47d15e3ec9
  1251. LAST-MODIFIED;VALUE=DATE-TIME:20230910T125139Z
  1252. DTSTAMP;VALUE=DATE-TIME:20230910T125139Z
  1253. SUMMARY:123 Event 🙈
  1254. DTSTART;VALUE=DATE-TIME:20230912T130000Z
  1255. DTEND;VALUE=DATE-TIME:20230912T140000Z
  1256. ATTENDEE;CN=test:mailto:foo@bar.com
  1257. END:VEVENT
  1258. END:VCALENDAR
  1259. EOD;
  1260. $this->backend->updateCalendarObject($calendarId, $uri, $calData);
  1261. // One add, one modify, but shortened to modify
  1262. $changes = $this->backend->getChangesForCalendar($calendarId, $syncToken, 100);
  1263. $this->assertEmpty($changes['added']);
  1264. $this->assertEquals(1, count($changes['modified']));
  1265. $this->assertEmpty($changes['deleted']);
  1266. // Delete all but last change
  1267. $deleted = $this->backend->pruneOutdatedSyncTokens(1, time());
  1268. $this->assertEquals(1, $deleted); // We had two changes before, now one
  1269. // Only update should remain
  1270. $changes = $this->backend->getChangesForCalendar($calendarId, $syncToken, 100);
  1271. $this->assertEmpty($changes['added']);
  1272. $this->assertEquals(1, count($changes['modified']));
  1273. $this->assertEmpty($changes['deleted']);
  1274. // Check that no crash occurs when prune is called without current changes
  1275. $deleted = $this->backend->pruneOutdatedSyncTokens(1, time());
  1276. self::assertSame(0, $deleted);
  1277. }
  1278. public function testSearchAndExpandRecurrences() {
  1279. $calendarId = $this->createTestCalendar();
  1280. $calendarInfo = [
  1281. 'id' => $calendarId,
  1282. 'principaluri' => 'user1',
  1283. '{http://owncloud.org/ns}owner-principal' => 'user1',
  1284. ];
  1285. $calData = <<<'EOD'
  1286. BEGIN:VCALENDAR
  1287. PRODID:-//IDN nextcloud.com//Calendar app 4.5.0-alpha.2//EN
  1288. CALSCALE:GREGORIAN
  1289. VERSION:2.0
  1290. BEGIN:VEVENT
  1291. CREATED:20230921T133401Z
  1292. DTSTAMP:20230921T133448Z
  1293. LAST-MODIFIED:20230921T133448Z
  1294. SEQUENCE:2
  1295. UID:7b7d5d12-683c-48ce-973a-b3e1cb0bae2a
  1296. DTSTART;VALUE=DATE:20230912
  1297. DTEND;VALUE=DATE:20230913
  1298. STATUS:CONFIRMED
  1299. SUMMARY:Daily Event
  1300. RRULE:FREQ=DAILY
  1301. END:VEVENT
  1302. END:VCALENDAR
  1303. EOD;
  1304. $uri = static::getUniqueID('calobj');
  1305. $this->backend->createCalendarObject($calendarId, $uri, $calData);
  1306. $start = new DateTimeImmutable('2023-09-20T00:00:00Z');
  1307. $end = $start->add(new DateInterval('P14D'));
  1308. $results = $this->backend->search(
  1309. $calendarInfo,
  1310. '',
  1311. [],
  1312. [
  1313. 'timerange' => [
  1314. 'start' => $start,
  1315. 'end' => $end,
  1316. ]
  1317. ],
  1318. null,
  1319. null,
  1320. );
  1321. $this->assertCount(1, $results);
  1322. $this->assertCount(14, $results[0]['objects']);
  1323. foreach ($results as $result) {
  1324. foreach ($result['objects'] as $object) {
  1325. $this->assertEquals($object['UID'][0], '7b7d5d12-683c-48ce-973a-b3e1cb0bae2a');
  1326. $this->assertEquals($object['SUMMARY'][0], 'Daily Event');
  1327. $this->assertGreaterThanOrEqual(
  1328. $start->getTimestamp(),
  1329. $object['DTSTART'][0]->getTimestamp(),
  1330. 'Recurrence starting before requested start',
  1331. );
  1332. $this->assertLessThanOrEqual(
  1333. $end->getTimestamp(),
  1334. $object['DTSTART'][0]->getTimestamp(),
  1335. 'Recurrence starting after requested end',
  1336. );
  1337. }
  1338. }
  1339. }
  1340. public function testRestoreChanges(): void {
  1341. $calendarId = $this->createTestCalendar();
  1342. $uri1 = static::getUniqueID('calobj1') . '.ics';
  1343. $calData = <<<EOD
  1344. BEGIN:VCALENDAR
  1345. VERSION:2.0
  1346. PRODID:Nextcloud Calendar
  1347. BEGIN:VEVENT
  1348. CREATED;VALUE=DATE-TIME:20130910T125139Z
  1349. UID:47d15e3ec8
  1350. LAST-MODIFIED;VALUE=DATE-TIME:20130910T125139Z
  1351. DTSTAMP;VALUE=DATE-TIME:20130910T125139Z
  1352. SUMMARY:Test Event
  1353. DTSTART;VALUE=DATE-TIME:20130912T130000Z
  1354. DTEND;VALUE=DATE-TIME:20130912T140000Z
  1355. CLASS:PUBLIC
  1356. END:VEVENT
  1357. END:VCALENDAR
  1358. EOD;
  1359. $this->backend->createCalendarObject($calendarId, $uri1, $calData);
  1360. $calData = <<<EOD
  1361. BEGIN:VCALENDAR
  1362. VERSION:2.0
  1363. PRODID:Nextcloud Calendar
  1364. BEGIN:VEVENT
  1365. CREATED;VALUE=DATE-TIME:20130910T125139Z
  1366. UID:47d15e3ec8
  1367. LAST-MODIFIED;VALUE=DATE-TIME:20130910T125139Z
  1368. DTSTAMP;VALUE=DATE-TIME:20130910T125139Z
  1369. SUMMARY:Test Event – UPDATED
  1370. DTSTART;VALUE=DATE-TIME:20130912T130000Z
  1371. DTEND;VALUE=DATE-TIME:20130912T140000Z
  1372. CLASS:PUBLIC
  1373. SEQUENCE:1
  1374. END:VEVENT
  1375. END:VCALENDAR
  1376. EOD;
  1377. $this->backend->updateCalendarObject($calendarId, $uri1, $calData);
  1378. $uri2 = static::getUniqueID('calobj2') . '.ics';
  1379. $calData = <<<EOD
  1380. BEGIN:VCALENDAR
  1381. VERSION:2.0
  1382. PRODID:Nextcloud Calendar
  1383. BEGIN:VEVENT
  1384. CREATED;VALUE=DATE-TIME:20130910T125139Z
  1385. UID:47d15e3ec9
  1386. LAST-MODIFIED;VALUE=DATE-TIME:20130910T125139Z
  1387. DTSTAMP;VALUE=DATE-TIME:20130910T125139Z
  1388. SUMMARY:Test Event
  1389. DTSTART;VALUE=DATE-TIME:20130912T130000Z
  1390. DTEND;VALUE=DATE-TIME:20130912T140000Z
  1391. CLASS:PUBLIC
  1392. END:VEVENT
  1393. END:VCALENDAR
  1394. EOD;
  1395. $this->backend->createCalendarObject($calendarId, $uri2, $calData);
  1396. $changesBefore = $this->backend->getChangesForCalendar($calendarId, null, 1);
  1397. $this->backend->deleteCalendarObject($calendarId, $uri2);
  1398. $uri3 = static::getUniqueID('calobj3') . '.ics';
  1399. $calData = <<<EOD
  1400. BEGIN:VCALENDAR
  1401. VERSION:2.0
  1402. PRODID:Nextcloud Calendar
  1403. BEGIN:VEVENT
  1404. CREATED;VALUE=DATE-TIME:20130910T125139Z
  1405. UID:47d15e3e10
  1406. LAST-MODIFIED;VALUE=DATE-TIME:20130910T125139Z
  1407. DTSTAMP;VALUE=DATE-TIME:20130910T125139Z
  1408. SUMMARY:Test Event
  1409. DTSTART;VALUE=DATE-TIME:20130912T130000Z
  1410. DTEND;VALUE=DATE-TIME:20130912T140000Z
  1411. CLASS:PUBLIC
  1412. END:VEVENT
  1413. END:VCALENDAR
  1414. EOD;
  1415. $this->backend->createCalendarObject($calendarId, $uri3, $calData);
  1416. $deleteChanges = $this->db->getQueryBuilder();
  1417. $deleteChanges->delete('calendarchanges')
  1418. ->where($deleteChanges->expr()->eq('calendarid', $deleteChanges->createNamedParameter($calendarId)));
  1419. $deleteChanges->executeStatement();
  1420. $this->backend->restoreChanges($calendarId);
  1421. $changesAfter = $this->backend->getChangesForCalendar($calendarId, $changesBefore['syncToken'], 1);
  1422. self::assertEquals([], $changesAfter['added']);
  1423. self::assertEqualsCanonicalizing([$uri1, $uri3], $changesAfter['modified']);
  1424. self::assertEquals([$uri2], $changesAfter['deleted']);
  1425. }
  1426. public function testSearchWithLimitAndTimeRange() {
  1427. $calendarId = $this->createTestCalendar();
  1428. $calendarInfo = [
  1429. 'id' => $calendarId,
  1430. 'principaluri' => 'user1',
  1431. '{http://owncloud.org/ns}owner-principal' => 'user1',
  1432. ];
  1433. $testFiles = [
  1434. __DIR__ . '/../../misc/caldav-search-limit-timerange-1.ics',
  1435. __DIR__ . '/../../misc/caldav-search-limit-timerange-2.ics',
  1436. __DIR__ . '/../../misc/caldav-search-limit-timerange-3.ics',
  1437. __DIR__ . '/../../misc/caldav-search-limit-timerange-4.ics',
  1438. __DIR__ . '/../../misc/caldav-search-limit-timerange-5.ics',
  1439. __DIR__ . '/../../misc/caldav-search-limit-timerange-6.ics',
  1440. ];
  1441. foreach ($testFiles as $testFile) {
  1442. $objectUri = static::getUniqueID('search-limit-timerange-');
  1443. $calendarData = \file_get_contents($testFile);
  1444. $this->backend->createCalendarObject($calendarId, $objectUri, $calendarData);
  1445. }
  1446. $start = new DateTimeImmutable('2024-05-06T00:00:00Z');
  1447. $end = $start->add(new DateInterval('P14D'));
  1448. $results = $this->backend->search(
  1449. $calendarInfo,
  1450. '',
  1451. [],
  1452. [
  1453. 'timerange' => [
  1454. 'start' => $start,
  1455. 'end' => $end,
  1456. ]
  1457. ],
  1458. 4,
  1459. null,
  1460. );
  1461. $this->assertCount(2, $results);
  1462. $this->assertEquals('Cake Tasting', $results[0]['objects'][0]['SUMMARY'][0]);
  1463. $this->assertGreaterThanOrEqual(
  1464. $start->getTimestamp(),
  1465. $results[0]['objects'][0]['DTSTART'][0]->getTimestamp(),
  1466. 'Recurrence starting before requested start',
  1467. );
  1468. $this->assertEquals('Pasta Day', $results[1]['objects'][0]['SUMMARY'][0]);
  1469. $this->assertGreaterThanOrEqual(
  1470. $start->getTimestamp(),
  1471. $results[1]['objects'][0]['DTSTART'][0]->getTimestamp(),
  1472. 'Recurrence starting before requested start',
  1473. );
  1474. }
  1475. public function testSearchWithLimitAndTimeRangeShouldNotReturnMoreObjectsThenLimit() {
  1476. $calendarId = $this->createTestCalendar();
  1477. $calendarInfo = [
  1478. 'id' => $calendarId,
  1479. 'principaluri' => 'user1',
  1480. '{http://owncloud.org/ns}owner-principal' => 'user1',
  1481. ];
  1482. $testFiles = [
  1483. __DIR__ . '/../../misc/caldav-search-limit-timerange-1.ics',
  1484. __DIR__ . '/../../misc/caldav-search-limit-timerange-2.ics',
  1485. __DIR__ . '/../../misc/caldav-search-limit-timerange-3.ics',
  1486. __DIR__ . '/../../misc/caldav-search-limit-timerange-4.ics',
  1487. __DIR__ . '/../../misc/caldav-search-limit-timerange-5.ics',
  1488. __DIR__ . '/../../misc/caldav-search-limit-timerange-6.ics',
  1489. ];
  1490. foreach ($testFiles as $testFile) {
  1491. $objectUri = static::getUniqueID('search-limit-timerange-');
  1492. $calendarData = \file_get_contents($testFile);
  1493. $this->backend->createCalendarObject($calendarId, $objectUri, $calendarData);
  1494. }
  1495. $start = new DateTimeImmutable('2024-05-06T00:00:00Z');
  1496. $end = $start->add(new DateInterval('P14D'));
  1497. $results = $this->backend->search(
  1498. $calendarInfo,
  1499. '',
  1500. [],
  1501. [
  1502. 'timerange' => [
  1503. 'start' => $start,
  1504. 'end' => $end,
  1505. ]
  1506. ],
  1507. 1,
  1508. null,
  1509. );
  1510. $this->assertCount(1, $results);
  1511. $this->assertEquals('Cake Tasting', $results[0]['objects'][0]['SUMMARY'][0]);
  1512. $this->assertGreaterThanOrEqual(
  1513. $start->getTimestamp(),
  1514. $results[0]['objects'][0]['DTSTART'][0]->getTimestamp(),
  1515. 'Recurrence starting before requested start',
  1516. );
  1517. }
  1518. public function testSearchWithLimitAndTimeRangeShouldReturnObjectsInTheSameOrder() {
  1519. $calendarId = $this->createTestCalendar();
  1520. $calendarInfo = [
  1521. 'id' => $calendarId,
  1522. 'principaluri' => 'user1',
  1523. '{http://owncloud.org/ns}owner-principal' => 'user1',
  1524. ];
  1525. $testFiles = [
  1526. __DIR__ . '/../../misc/caldav-search-limit-timerange-1.ics',
  1527. __DIR__ . '/../../misc/caldav-search-limit-timerange-2.ics',
  1528. __DIR__ . '/../../misc/caldav-search-limit-timerange-3.ics',
  1529. __DIR__ . '/../../misc/caldav-search-limit-timerange-4.ics',
  1530. __DIR__ . '/../../misc/caldav-search-limit-timerange-6.ics', // <-- intentional!
  1531. __DIR__ . '/../../misc/caldav-search-limit-timerange-5.ics',
  1532. ];
  1533. foreach ($testFiles as $testFile) {
  1534. $objectUri = static::getUniqueID('search-limit-timerange-');
  1535. $calendarData = \file_get_contents($testFile);
  1536. $this->backend->createCalendarObject($calendarId, $objectUri, $calendarData);
  1537. }
  1538. $start = new DateTimeImmutable('2024-05-06T00:00:00Z');
  1539. $end = $start->add(new DateInterval('P14D'));
  1540. $results = $this->backend->search(
  1541. $calendarInfo,
  1542. '',
  1543. [],
  1544. [
  1545. 'timerange' => [
  1546. 'start' => $start,
  1547. 'end' => $end,
  1548. ]
  1549. ],
  1550. 2,
  1551. null,
  1552. );
  1553. $this->assertCount(2, $results);
  1554. $this->assertEquals('Cake Tasting', $results[0]['objects'][0]['SUMMARY'][0]);
  1555. $this->assertGreaterThanOrEqual(
  1556. $start->getTimestamp(),
  1557. $results[0]['objects'][0]['DTSTART'][0]->getTimestamp(),
  1558. 'Recurrence starting before requested start',
  1559. );
  1560. $this->assertEquals('Pasta Day', $results[1]['objects'][0]['SUMMARY'][0]);
  1561. $this->assertGreaterThanOrEqual(
  1562. $start->getTimestamp(),
  1563. $results[1]['objects'][0]['DTSTART'][0]->getTimestamp(),
  1564. 'Recurrence starting before requested start',
  1565. );
  1566. }
  1567. public function testSearchShouldReturnObjectsInTheSameOrderMissingDate() {
  1568. $calendarId = $this->createTestCalendar();
  1569. $calendarInfo = [
  1570. 'id' => $calendarId,
  1571. 'principaluri' => 'user1',
  1572. '{http://owncloud.org/ns}owner-principal' => 'user1',
  1573. ];
  1574. $testFiles = [
  1575. __DIR__ . '/../../misc/caldav-search-limit-timerange-6.ics', // <-- intentional!
  1576. __DIR__ . '/../../misc/caldav-search-limit-timerange-5.ics',
  1577. __DIR__ . '/../../misc/caldav-search-missing-start-1.ics',
  1578. __DIR__ . '/../../misc/caldav-search-missing-start-2.ics',
  1579. ];
  1580. foreach ($testFiles as $testFile) {
  1581. $objectUri = static::getUniqueID('search-return-objects-in-same-order-');
  1582. $calendarData = \file_get_contents($testFile);
  1583. $this->backend->createCalendarObject($calendarId, $objectUri, $calendarData);
  1584. }
  1585. $results = $this->backend->search(
  1586. $calendarInfo,
  1587. '',
  1588. [],
  1589. [],
  1590. 4,
  1591. null,
  1592. );
  1593. $this->assertCount(4, $results);
  1594. $this->assertEquals('Cake Tasting', $results[0]['objects'][0]['SUMMARY'][0]);
  1595. $this->assertEquals('Pasta Day', $results[1]['objects'][0]['SUMMARY'][0]);
  1596. $this->assertEquals('Missing DTSTART 1', $results[2]['objects'][0]['SUMMARY'][0]);
  1597. $this->assertEquals('Missing DTSTART 2', $results[3]['objects'][0]['SUMMARY'][0]);
  1598. }
  1599. }