CalDavBackendTest.php 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. * @copyright Copyright (c) 2017 Georg Ehrke
  5. *
  6. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  7. * @author dartcafe <github@dartcafe.de>
  8. * @author Georg Ehrke <oc.list@georgehrke.com>
  9. * @author Joas Schilling <coding@schilljs.com>
  10. * @author Robin Appelman <robin@icewind.nl>
  11. * @author Roeland Jago Douma <roeland@famdouma.nl>
  12. * @author Thomas Citharel <nextcloud@tcit.fr>
  13. * @author Thomas Müller <thomas.mueller@tmit.eu>
  14. *
  15. * @license AGPL-3.0
  16. *
  17. * This code is free software: you can redistribute it and/or modify
  18. * it under the terms of the GNU Affero General Public License, version 3,
  19. * as published by the Free Software Foundation.
  20. *
  21. * This program is distributed in the hope that it will be useful,
  22. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  23. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  24. * GNU Affero General Public License for more details.
  25. *
  26. * You should have received a copy of the GNU Affero General Public License, version 3,
  27. * along with this program. If not, see <http://www.gnu.org/licenses/>
  28. *
  29. */
  30. namespace OCA\DAV\Tests\unit\CalDAV;
  31. use DateTime;
  32. use DateTimeZone;
  33. use OCA\DAV\CalDAV\CalDavBackend;
  34. use OCA\DAV\CalDAV\Calendar;
  35. use OCP\IConfig;
  36. use OCP\IL10N;
  37. use Sabre\DAV\Exception\NotFound;
  38. use Sabre\DAV\PropPatch;
  39. use Sabre\DAV\Xml\Property\Href;
  40. use Sabre\DAVACL\IACL;
  41. /**
  42. * Class CalDavBackendTest
  43. *
  44. * @group DB
  45. *
  46. * @package OCA\DAV\Tests\unit\CalDAV
  47. */
  48. class CalDavBackendTest extends AbstractCalDavBackend {
  49. public function testCalendarOperations() {
  50. $calendarId = $this->createTestCalendar();
  51. // update it's display name
  52. $patch = new PropPatch([
  53. '{DAV:}displayname' => 'Unit test',
  54. '{urn:ietf:params:xml:ns:caldav}calendar-description' => 'Calendar used for unit testing'
  55. ]);
  56. $this->dispatcher->expects($this->at(0))
  57. ->method('dispatch')
  58. ->with('\OCA\DAV\CalDAV\CalDavBackend::updateCalendar');
  59. $this->backend->updateCalendar($calendarId, $patch);
  60. $patch->commit();
  61. $this->assertEquals(1, $this->backend->getCalendarsForUserCount(self::UNIT_TEST_USER));
  62. $calendars = $this->backend->getCalendarsForUser(self::UNIT_TEST_USER);
  63. $this->assertCount(1, $calendars);
  64. $this->assertEquals('Unit test', $calendars[0]['{DAV:}displayname']);
  65. $this->assertEquals('Calendar used for unit testing', $calendars[0]['{urn:ietf:params:xml:ns:caldav}calendar-description']);
  66. $this->assertEquals('User\'s displayname', $calendars[0]['{http://nextcloud.com/ns}owner-displayname']);
  67. // delete the address book
  68. $this->dispatcher->expects($this->at(0))
  69. ->method('dispatch')
  70. ->with('\OCA\DAV\CalDAV\CalDavBackend::deleteCalendar');
  71. $this->backend->deleteCalendar($calendars[0]['id']);
  72. $calendars = $this->backend->getCalendarsForUser(self::UNIT_TEST_USER);
  73. $this->assertCount(0, $calendars);
  74. }
  75. public function providesSharingData() {
  76. return [
  77. [true, true, true, false, [
  78. [
  79. 'href' => 'principal:' . self::UNIT_TEST_USER1,
  80. 'readOnly' => false
  81. ],
  82. [
  83. 'href' => 'principal:' . self::UNIT_TEST_GROUP,
  84. 'readOnly' => true
  85. ]
  86. ]],
  87. [true, true, true, false, [
  88. [
  89. 'href' => 'principal:' . self::UNIT_TEST_GROUP,
  90. 'readOnly' => true,
  91. ],
  92. [
  93. 'href' => 'principal:' . self::UNIT_TEST_GROUP2,
  94. 'readOnly' => false,
  95. ],
  96. ]],
  97. [true, true, true, true, [
  98. [
  99. 'href' => 'principal:' . self::UNIT_TEST_GROUP,
  100. 'readOnly' => false,
  101. ],
  102. [
  103. 'href' => 'principal:' . self::UNIT_TEST_GROUP2,
  104. 'readOnly' => true,
  105. ],
  106. ]],
  107. [true, false, false, false, [
  108. [
  109. 'href' => 'principal:' . self::UNIT_TEST_USER1,
  110. 'readOnly' => true
  111. ],
  112. ]],
  113. ];
  114. }
  115. /**
  116. * @dataProvider providesSharingData
  117. */
  118. public function testCalendarSharing($userCanRead, $userCanWrite, $groupCanRead, $groupCanWrite, $add) {
  119. /** @var IL10N|\PHPUnit_Framework_MockObject_MockObject $l10n */
  120. $l10n = $this->createMock(IL10N::class);
  121. $l10n
  122. ->expects($this->any())
  123. ->method('t')
  124. ->willReturnCallback(function ($text, $parameters = []) {
  125. return vsprintf($text, $parameters);
  126. });
  127. $config = $this->createMock(IConfig::class);
  128. $this->userManager->expects($this->any())
  129. ->method('userExists')
  130. ->willReturn(true);
  131. $this->groupManager->expects($this->any())
  132. ->method('groupExists')
  133. ->willReturn(true);
  134. $calendarId = $this->createTestCalendar();
  135. $calendars = $this->backend->getCalendarsForUser(self::UNIT_TEST_USER);
  136. $this->assertCount(1, $calendars);
  137. $calendar = new Calendar($this->backend, $calendars[0], $l10n, $config);
  138. $this->dispatcher->expects($this->at(0))
  139. ->method('dispatch')
  140. ->with('\OCA\DAV\CalDAV\CalDavBackend::updateShares');
  141. $this->backend->updateShares($calendar, $add, []);
  142. $calendars = $this->backend->getCalendarsForUser(self::UNIT_TEST_USER1);
  143. $this->assertCount(1, $calendars);
  144. $calendar = new Calendar($this->backend, $calendars[0], $l10n, $config);
  145. $acl = $calendar->getACL();
  146. $this->assertAcl(self::UNIT_TEST_USER, '{DAV:}read', $acl);
  147. $this->assertAcl(self::UNIT_TEST_USER, '{DAV:}write', $acl);
  148. $this->assertAccess($userCanRead, self::UNIT_TEST_USER1, '{DAV:}read', $acl);
  149. $this->assertAccess($userCanWrite, self::UNIT_TEST_USER1, '{DAV:}write', $acl);
  150. $this->assertEquals(self::UNIT_TEST_USER, $calendar->getOwner());
  151. // test acls on the child
  152. $uri = static::getUniqueID('calobj');
  153. $calData = <<<'EOD'
  154. BEGIN:VCALENDAR
  155. VERSION:2.0
  156. PRODID:ownCloud Calendar
  157. BEGIN:VEVENT
  158. CREATED;VALUE=DATE-TIME:20130910T125139Z
  159. UID:47d15e3ec8
  160. LAST-MODIFIED;VALUE=DATE-TIME:20130910T125139Z
  161. DTSTAMP;VALUE=DATE-TIME:20130910T125139Z
  162. SUMMARY:Test Event
  163. DTSTART;VALUE=DATE-TIME:20130912T130000Z
  164. DTEND;VALUE=DATE-TIME:20130912T140000Z
  165. CLASS:PUBLIC
  166. END:VEVENT
  167. END:VCALENDAR
  168. EOD;
  169. $this->dispatcher->expects($this->at(0))
  170. ->method('dispatch')
  171. ->with('\OCA\DAV\CalDAV\CalDavBackend::createCalendarObject');
  172. $this->backend->createCalendarObject($calendarId, $uri, $calData);
  173. /** @var IACL $child */
  174. $child = $calendar->getChild($uri);
  175. $acl = $child->getACL();
  176. $this->assertAcl(self::UNIT_TEST_USER, '{DAV:}read', $acl);
  177. $this->assertAcl(self::UNIT_TEST_USER, '{DAV:}write', $acl);
  178. $this->assertAccess($userCanRead, self::UNIT_TEST_USER1, '{DAV:}read', $acl);
  179. $this->assertAccess($userCanWrite, self::UNIT_TEST_USER1, '{DAV:}write', $acl);
  180. // delete the address book
  181. $this->dispatcher->expects($this->at(0))
  182. ->method('dispatch')
  183. ->with('\OCA\DAV\CalDAV\CalDavBackend::deleteCalendar');
  184. $this->backend->deleteCalendar($calendars[0]['id']);
  185. $calendars = $this->backend->getCalendarsForUser(self::UNIT_TEST_USER);
  186. $this->assertCount(0, $calendars);
  187. }
  188. public function testCalendarObjectsOperations() {
  189. $calendarId = $this->createTestCalendar();
  190. // create a card
  191. $uri = static::getUniqueID('calobj');
  192. $calData = <<<'EOD'
  193. BEGIN:VCALENDAR
  194. VERSION:2.0
  195. PRODID:ownCloud Calendar
  196. BEGIN:VEVENT
  197. CREATED;VALUE=DATE-TIME:20130910T125139Z
  198. UID:47d15e3ec8
  199. LAST-MODIFIED;VALUE=DATE-TIME:20130910T125139Z
  200. DTSTAMP;VALUE=DATE-TIME:20130910T125139Z
  201. SUMMARY:Test Event
  202. DTSTART;VALUE=DATE-TIME:20130912T130000Z
  203. DTEND;VALUE=DATE-TIME:20130912T140000Z
  204. CLASS:PUBLIC
  205. END:VEVENT
  206. END:VCALENDAR
  207. EOD;
  208. $this->dispatcher->expects($this->at(0))
  209. ->method('dispatch')
  210. ->with('\OCA\DAV\CalDAV\CalDavBackend::createCalendarObject');
  211. $this->backend->createCalendarObject($calendarId, $uri, $calData);
  212. // get all the cards
  213. $calendarObjects = $this->backend->getCalendarObjects($calendarId);
  214. $this->assertCount(1, $calendarObjects);
  215. $this->assertEquals($calendarId, $calendarObjects[0]['calendarid']);
  216. $this->assertArrayHasKey('classification', $calendarObjects[0]);
  217. // get the cards
  218. $calendarObject = $this->backend->getCalendarObject($calendarId, $uri);
  219. $this->assertNotNull($calendarObject);
  220. $this->assertArrayHasKey('id', $calendarObject);
  221. $this->assertArrayHasKey('uri', $calendarObject);
  222. $this->assertArrayHasKey('lastmodified', $calendarObject);
  223. $this->assertArrayHasKey('etag', $calendarObject);
  224. $this->assertArrayHasKey('size', $calendarObject);
  225. $this->assertArrayHasKey('classification', $calendarObject);
  226. $this->assertEquals($calData, $calendarObject['calendardata']);
  227. // update the card
  228. $calData = <<<'EOD'
  229. BEGIN:VCALENDAR
  230. VERSION:2.0
  231. PRODID:ownCloud Calendar
  232. BEGIN:VEVENT
  233. CREATED;VALUE=DATE-TIME:20130910T125139Z
  234. UID:47d15e3ec8
  235. LAST-MODIFIED;VALUE=DATE-TIME:20130910T125139Z
  236. DTSTAMP;VALUE=DATE-TIME:20130910T125139Z
  237. SUMMARY:Test Event
  238. DTSTART;VALUE=DATE-TIME:20130912T130000Z
  239. DTEND;VALUE=DATE-TIME:20130912T140000Z
  240. END:VEVENT
  241. END:VCALENDAR
  242. EOD;
  243. $this->dispatcher->expects($this->at(0))
  244. ->method('dispatch')
  245. ->with('\OCA\DAV\CalDAV\CalDavBackend::updateCalendarObject');
  246. $this->backend->updateCalendarObject($calendarId, $uri, $calData);
  247. $calendarObject = $this->backend->getCalendarObject($calendarId, $uri);
  248. $this->assertEquals($calData, $calendarObject['calendardata']);
  249. // delete the card
  250. $this->dispatcher->expects($this->at(0))
  251. ->method('dispatch')
  252. ->with('\OCA\DAV\CalDAV\CalDavBackend::deleteCalendarObject');
  253. $this->backend->deleteCalendarObject($calendarId, $uri);
  254. $calendarObjects = $this->backend->getCalendarObjects($calendarId);
  255. $this->assertCount(0, $calendarObjects);
  256. }
  257. public function testMultipleCalendarObjectsWithSameUID() {
  258. $this->expectException(\Sabre\DAV\Exception\BadRequest::class);
  259. $this->expectExceptionMessage('Calendar object with uid already exists in this calendar collection.');
  260. $calendarId = $this->createTestCalendar();
  261. $calData = <<<'EOD'
  262. BEGIN:VCALENDAR
  263. VERSION:2.0
  264. PRODID:ownCloud Calendar
  265. BEGIN:VEVENT
  266. CREATED;VALUE=DATE-TIME:20130910T125139Z
  267. UID:47d15e3ec8-1
  268. LAST-MODIFIED;VALUE=DATE-TIME:20130910T125139Z
  269. DTSTAMP;VALUE=DATE-TIME:20130910T125139Z
  270. SUMMARY:Test Event
  271. DTSTART;VALUE=DATE-TIME:20130912T130000Z
  272. DTEND;VALUE=DATE-TIME:20130912T140000Z
  273. CLASS:PUBLIC
  274. END:VEVENT
  275. END:VCALENDAR
  276. EOD;
  277. $uri0 = static::getUniqueID('event');
  278. $uri1 = static::getUniqueID('event');
  279. $this->backend->createCalendarObject($calendarId, $uri0, $calData);
  280. $this->backend->createCalendarObject($calendarId, $uri1, $calData);
  281. }
  282. public function testMultiCalendarObjects() {
  283. $calendarId = $this->createTestCalendar();
  284. // create an event
  285. $calData = [];
  286. $calData[] = <<<'EOD'
  287. BEGIN:VCALENDAR
  288. VERSION:2.0
  289. PRODID:ownCloud Calendar
  290. BEGIN:VEVENT
  291. CREATED;VALUE=DATE-TIME:20130910T125139Z
  292. UID:47d15e3ec8-1
  293. LAST-MODIFIED;VALUE=DATE-TIME:20130910T125139Z
  294. DTSTAMP;VALUE=DATE-TIME:20130910T125139Z
  295. SUMMARY:Test Event
  296. DTSTART;VALUE=DATE-TIME:20130912T130000Z
  297. DTEND;VALUE=DATE-TIME:20130912T140000Z
  298. CLASS:PUBLIC
  299. END:VEVENT
  300. END:VCALENDAR
  301. EOD;
  302. $calData[] = <<<'EOD'
  303. BEGIN:VCALENDAR
  304. VERSION:2.0
  305. PRODID:ownCloud Calendar
  306. BEGIN:VEVENT
  307. CREATED;VALUE=DATE-TIME:20130910T125139Z
  308. UID:47d15e3ec8-2
  309. LAST-MODIFIED;VALUE=DATE-TIME:20130910T125139Z
  310. DTSTAMP;VALUE=DATE-TIME:20130910T125139Z
  311. SUMMARY:Test Event
  312. DTSTART;VALUE=DATE-TIME:20130912T130000Z
  313. DTEND;VALUE=DATE-TIME:20130912T140000Z
  314. CLASS:PUBLIC
  315. END:VEVENT
  316. END:VCALENDAR
  317. EOD;
  318. $calData[] = <<<'EOD'
  319. BEGIN:VCALENDAR
  320. VERSION:2.0
  321. PRODID:ownCloud Calendar
  322. BEGIN:VEVENT
  323. CREATED;VALUE=DATE-TIME:20130910T125139Z
  324. UID:47d15e3ec8-3
  325. LAST-MODIFIED;VALUE=DATE-TIME:20130910T125139Z
  326. DTSTAMP;VALUE=DATE-TIME:20130910T125139Z
  327. SUMMARY:Test Event
  328. DTSTART;VALUE=DATE-TIME:20130912T130000Z
  329. DTEND;VALUE=DATE-TIME:20130912T140000Z
  330. CLASS:PUBLIC
  331. END:VEVENT
  332. END:VCALENDAR
  333. EOD;
  334. $uri0 = static::getUniqueID('card');
  335. $this->dispatcher->expects($this->at(0))
  336. ->method('dispatch')
  337. ->with('\OCA\DAV\CalDAV\CalDavBackend::createCalendarObject');
  338. $this->backend->createCalendarObject($calendarId, $uri0, $calData[0]);
  339. $uri1 = static::getUniqueID('card');
  340. $this->dispatcher->expects($this->at(0))
  341. ->method('dispatch')
  342. ->with('\OCA\DAV\CalDAV\CalDavBackend::createCalendarObject');
  343. $this->backend->createCalendarObject($calendarId, $uri1, $calData[1]);
  344. $uri2 = static::getUniqueID('card');
  345. $this->dispatcher->expects($this->at(0))
  346. ->method('dispatch')
  347. ->with('\OCA\DAV\CalDAV\CalDavBackend::createCalendarObject');
  348. $this->backend->createCalendarObject($calendarId, $uri2, $calData[2]);
  349. // get all the cards
  350. $calendarObjects = $this->backend->getCalendarObjects($calendarId);
  351. $this->assertCount(3, $calendarObjects);
  352. // get the cards
  353. $calendarObjects = $this->backend->getMultipleCalendarObjects($calendarId, [$uri1, $uri2]);
  354. $this->assertCount(2, $calendarObjects);
  355. foreach ($calendarObjects as $card) {
  356. $this->assertArrayHasKey('id', $card);
  357. $this->assertArrayHasKey('uri', $card);
  358. $this->assertArrayHasKey('lastmodified', $card);
  359. $this->assertArrayHasKey('etag', $card);
  360. $this->assertArrayHasKey('size', $card);
  361. $this->assertArrayHasKey('classification', $card);
  362. }
  363. usort($calendarObjects, function ($a, $b) {
  364. return $a['id'] - $b['id'];
  365. });
  366. $this->assertEquals($calData[1], $calendarObjects[0]['calendardata']);
  367. $this->assertEquals($calData[2], $calendarObjects[1]['calendardata']);
  368. // delete the card
  369. $this->dispatcher->expects($this->at(0))
  370. ->method('dispatch')
  371. ->with('\OCA\DAV\CalDAV\CalDavBackend::deleteCalendarObject');
  372. $this->backend->deleteCalendarObject($calendarId, $uri0);
  373. $this->dispatcher->expects($this->at(0))
  374. ->method('dispatch')
  375. ->with('\OCA\DAV\CalDAV\CalDavBackend::deleteCalendarObject');
  376. $this->backend->deleteCalendarObject($calendarId, $uri1);
  377. $this->dispatcher->expects($this->at(0))
  378. ->method('dispatch')
  379. ->with('\OCA\DAV\CalDAV\CalDavBackend::deleteCalendarObject');
  380. $this->backend->deleteCalendarObject($calendarId, $uri2);
  381. $calendarObjects = $this->backend->getCalendarObjects($calendarId);
  382. $this->assertCount(0, $calendarObjects);
  383. }
  384. /**
  385. * @dataProvider providesCalendarQueryParameters
  386. */
  387. public function testCalendarQuery($expectedEventsInResult, $propFilters, $compFilter) {
  388. $calendarId = $this->createTestCalendar();
  389. $events = [];
  390. $events[0] = $this->createEvent($calendarId, '20130912T130000Z', '20130912T140000Z');
  391. $events[1] = $this->createEvent($calendarId, '20130912T150000Z', '20130912T170000Z');
  392. $events[2] = $this->createEvent($calendarId, '20130912T173000Z', '20130912T220000Z');
  393. $events[3] = $this->createEvent($calendarId, '21130912T130000Z', '22130912T130000Z');
  394. $result = $this->backend->calendarQuery($calendarId, [
  395. 'name' => '',
  396. 'prop-filters' => $propFilters,
  397. 'comp-filters' => $compFilter
  398. ]);
  399. $expectedEventsInResult = array_map(function ($index) use ($events) {
  400. return $events[$index];
  401. }, $expectedEventsInResult);
  402. $this->assertEqualsCanonicalizing($expectedEventsInResult, $result);
  403. }
  404. public function testGetCalendarObjectByUID() {
  405. $calendarId = $this->createTestCalendar();
  406. $uri = static::getUniqueID('calobj');
  407. $calData = <<<'EOD'
  408. BEGIN:VCALENDAR
  409. VERSION:2.0
  410. PRODID:ownCloud Calendar
  411. BEGIN:VEVENT
  412. CREATED;VALUE=DATE-TIME:20130910T125139Z
  413. UID:47d15e3ec8
  414. LAST-MODIFIED;VALUE=DATE-TIME:20130910T125139Z
  415. DTSTAMP;VALUE=DATE-TIME:20130910T125139Z
  416. SUMMARY:Test Event
  417. DTSTART;VALUE=DATE-TIME:20130912T130000Z
  418. DTEND;VALUE=DATE-TIME:20130912T140000Z
  419. CLASS:PUBLIC
  420. END:VEVENT
  421. END:VCALENDAR
  422. EOD;
  423. $this->backend->createCalendarObject($calendarId, $uri, $calData);
  424. $co = $this->backend->getCalendarObjectByUID(self::UNIT_TEST_USER, '47d15e3ec8');
  425. $this->assertNotNull($co);
  426. }
  427. public function providesCalendarQueryParameters() {
  428. return [
  429. 'all' => [[0, 1, 2, 3], [], []],
  430. 'only-todos' => [[], ['name' => 'VTODO'], []],
  431. 'only-events' => [[0, 1, 2, 3], [], [['name' => 'VEVENT', 'is-not-defined' => false, 'comp-filters' => [], 'time-range' => ['start' => null, 'end' => null], 'prop-filters' => []]],],
  432. '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' => []]],],
  433. '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' => []]],],
  434. 'future' => [[3], [], [['name' => 'VEVENT', 'is-not-defined' => false, 'comp-filters' => [], 'time-range' => ['start' => new DateTime('2099-09-12 14:00:00', new DateTimeZone('UTC')), 'end' => null], 'prop-filters' => []]],],
  435. ];
  436. }
  437. public function testSyncSupport() {
  438. $calendarId = $this->createTestCalendar();
  439. // fist call without synctoken
  440. $changes = $this->backend->getChangesForCalendar($calendarId, '', 1);
  441. $syncToken = $changes['syncToken'];
  442. // add a change
  443. $event = $this->createEvent($calendarId, '20130912T130000Z', '20130912T140000Z');
  444. // look for changes
  445. $changes = $this->backend->getChangesForCalendar($calendarId, $syncToken, 1);
  446. $this->assertEquals($event, $changes['added'][0]);
  447. }
  448. public function testPublications() {
  449. $this->dispatcher->expects($this->at(0))
  450. ->method('dispatch')
  451. ->with('\OCA\DAV\CalDAV\CalDavBackend::createCalendar');
  452. $this->backend->createCalendar(self::UNIT_TEST_USER, 'Example', []);
  453. $calendarInfo = $this->backend->getCalendarsForUser(self::UNIT_TEST_USER)[0];
  454. /** @var IL10N|\PHPUnit_Framework_MockObject_MockObject $l10n */
  455. $l10n = $this->createMock(IL10N::class);
  456. $config = $this->createMock(IConfig::class);
  457. $calendar = new Calendar($this->backend, $calendarInfo, $l10n, $config);
  458. $calendar->setPublishStatus(true);
  459. $this->assertNotEquals(false, $calendar->getPublishStatus());
  460. $publicCalendars = $this->backend->getPublicCalendars();
  461. $this->assertCount(1, $publicCalendars);
  462. $this->assertEquals(true, $publicCalendars[0]['{http://owncloud.org/ns}public']);
  463. $this->assertEquals('User\'s displayname', $publicCalendars[0]['{http://nextcloud.com/ns}owner-displayname']);
  464. $publicCalendarURI = $publicCalendars[0]['uri'];
  465. $publicCalendar = $this->backend->getPublicCalendar($publicCalendarURI);
  466. $this->assertEquals(true, $publicCalendar['{http://owncloud.org/ns}public']);
  467. $calendar->setPublishStatus(false);
  468. $this->assertEquals(false, $calendar->getPublishStatus());
  469. $this->expectException(NotFound::class);
  470. $this->backend->getPublicCalendar($publicCalendarURI);
  471. }
  472. public function testSubscriptions() {
  473. $id = $this->backend->createSubscription(self::UNIT_TEST_USER, 'Subscription', [
  474. '{http://calendarserver.org/ns/}source' => new Href('test-source'),
  475. '{http://apple.com/ns/ical/}calendar-color' => '#1C4587',
  476. '{http://calendarserver.org/ns/}subscribed-strip-todos' => ''
  477. ]);
  478. $subscriptions = $this->backend->getSubscriptionsForUser(self::UNIT_TEST_USER);
  479. $this->assertCount(1, $subscriptions);
  480. $this->assertEquals('#1C4587', $subscriptions[0]['{http://apple.com/ns/ical/}calendar-color']);
  481. $this->assertEquals(true, $subscriptions[0]['{http://calendarserver.org/ns/}subscribed-strip-todos']);
  482. $this->assertEquals($id, $subscriptions[0]['id']);
  483. $patch = new PropPatch([
  484. '{DAV:}displayname' => 'Unit test',
  485. '{http://apple.com/ns/ical/}calendar-color' => '#ac0606',
  486. ]);
  487. $this->backend->updateSubscription($id, $patch);
  488. $patch->commit();
  489. $subscriptions = $this->backend->getSubscriptionsForUser(self::UNIT_TEST_USER);
  490. $this->assertCount(1, $subscriptions);
  491. $this->assertEquals($id, $subscriptions[0]['id']);
  492. $this->assertEquals('Unit test', $subscriptions[0]['{DAV:}displayname']);
  493. $this->assertEquals('#ac0606', $subscriptions[0]['{http://apple.com/ns/ical/}calendar-color']);
  494. $this->backend->deleteSubscription($id);
  495. $subscriptions = $this->backend->getSubscriptionsForUser(self::UNIT_TEST_USER);
  496. $this->assertCount(0, $subscriptions);
  497. }
  498. public function providesSchedulingData() {
  499. $data =<<<EOS
  500. BEGIN:VCALENDAR
  501. VERSION:2.0
  502. PRODID:-//Sabre//Sabre VObject 3.5.0//EN
  503. CALSCALE:GREGORIAN
  504. METHOD:REQUEST
  505. BEGIN:VTIMEZONE
  506. TZID:Europe/Warsaw
  507. BEGIN:DAYLIGHT
  508. TZOFFSETFROM:+0100
  509. TZOFFSETTO:+0200
  510. TZNAME:CEST
  511. DTSTART:19700329T020000
  512. RRULE:FREQ=YEARLY;BYDAY=-1SU;BYMONTH=3
  513. END:DAYLIGHT
  514. BEGIN:STANDARD
  515. TZOFFSETFROM:+0200
  516. TZOFFSETTO:+0100
  517. TZNAME:CET
  518. DTSTART:19701025T030000
  519. RRULE:FREQ=YEARLY;BYDAY=-1SU;BYMONTH=10
  520. END:STANDARD
  521. END:VTIMEZONE
  522. BEGIN:VEVENT
  523. CREATED:20170320T131655Z
  524. LAST-MODIFIED:20170320T135019Z
  525. DTSTAMP:20170320T135019Z
  526. UID:7e908a6d-4c4e-48d7-bd62-59ab80fbf1a3
  527. SUMMARY:TEST Z pg_escape_bytea
  528. ORGANIZER;RSVP=TRUE;PARTSTAT=ACCEPTED;ROLE=CHAIR:mailto:k.klimczak@gromar.e
  529. u
  530. ATTENDEE;RSVP=TRUE;CN=Zuzanna Leszek;PARTSTAT=NEEDS-ACTION;ROLE=REQ-PARTICI
  531. PANT:mailto:z.leszek@gromar.eu
  532. ATTENDEE;RSVP=TRUE;CN=Marcin Pisarski;PARTSTAT=NEEDS-ACTION;ROLE=REQ-PARTIC
  533. IPANT:mailto:m.pisarski@gromar.eu
  534. ATTENDEE;RSVP=TRUE;PARTSTAT=NEEDS-ACTION;ROLE=REQ-PARTICIPANT:mailto:klimcz
  535. ak.k@gmail.com
  536. ATTENDEE;RSVP=TRUE;PARTSTAT=NEEDS-ACTION;ROLE=REQ-PARTICIPANT:mailto:k_klim
  537. czak@tlen.pl
  538. DTSTART;TZID=Europe/Warsaw:20170325T150000
  539. DTEND;TZID=Europe/Warsaw:20170325T160000
  540. TRANSP:OPAQUE
  541. DESCRIPTION:Magiczna treść uzyskana za pomocą magicznego proszku.\n\nę
  542. żźćńłóÓŻŹĆŁĘ€śśśŚŚ\n \,\,))))))))\;\,\n
  543. __))))))))))))))\,\n \\|/ -\\(((((''''((((((((.\n -*-==///
  544. ///(('' . `))))))\,\n /|\\ ))| o \;-. '(((((
  545. \,(\,\n ( `| / ) \;))))'
  546. \,_))^\;(~\n | | | \,))((((_ _____-
  547. -----~~~-. %\,\;(\;(>'\;'~\n o_)\; \; )))(((` ~---
  548. ~ `:: \\ %%~~)(v\;(`('~\n \; ''''````
  549. `: `:::|\\\,__\,%% )\;`'\; ~\n | _
  550. ) / `:|`----' `-'\n ______/\\/~ |
  551. / /\n /~\;\;.____/\;\;' / ___--\
  552. ,-( `\;\;\;/\n / // _\;______\;'------~~~~~ /\;\;/\\ /\n
  553. // | | / \; \\\;\;\,\\\n (<_ | \;
  554. /'\,/-----' _>\n \\_| ||_
  555. //~\;~~~~~~~~~\n `\\_| (\,~~ -Tua Xiong\n
  556. \\~\\\n
  557. ~~\n\n
  558. SEQUENCE:1
  559. X-MOZ-GENERATION:1
  560. END:VEVENT
  561. END:VCALENDAR
  562. EOS;
  563. return [
  564. 'no data' => [''],
  565. 'failing on postgres' => [$data]
  566. ];
  567. }
  568. /**
  569. * @dataProvider providesSchedulingData
  570. * @param $objectData
  571. */
  572. public function testScheduling($objectData) {
  573. $this->backend->createSchedulingObject(self::UNIT_TEST_USER, 'Sample Schedule', $objectData);
  574. $sos = $this->backend->getSchedulingObjects(self::UNIT_TEST_USER);
  575. $this->assertCount(1, $sos);
  576. $so = $this->backend->getSchedulingObject(self::UNIT_TEST_USER, 'Sample Schedule');
  577. $this->assertNotNull($so);
  578. $this->backend->deleteSchedulingObject(self::UNIT_TEST_USER, 'Sample Schedule');
  579. $sos = $this->backend->getSchedulingObjects(self::UNIT_TEST_USER);
  580. $this->assertCount(0, $sos);
  581. }
  582. /**
  583. * @dataProvider providesCalDataForGetDenormalizedData
  584. */
  585. public function testGetDenormalizedData($expected, $key, $calData) {
  586. $actual = $this->backend->getDenormalizedData($calData);
  587. $this->assertEquals($expected, $actual[$key]);
  588. }
  589. public function providesCalDataForGetDenormalizedData() {
  590. return [
  591. '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"],
  592. '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"],
  593. '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"],
  594. '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"],
  595. '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"],
  596. '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"],
  597. '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"],
  598. ];
  599. }
  600. public function testCalendarSearch() {
  601. $calendarId = $this->createTestCalendar();
  602. $uri = static::getUniqueID('calobj');
  603. $calData = <<<EOD
  604. BEGIN:VCALENDAR
  605. VERSION:2.0
  606. PRODID:ownCloud Calendar
  607. BEGIN:VEVENT
  608. CREATED;VALUE=DATE-TIME:20130910T125139Z
  609. UID:47d15e3ec8
  610. LAST-MODIFIED;VALUE=DATE-TIME:20130910T125139Z
  611. DTSTAMP;VALUE=DATE-TIME:20130910T125139Z
  612. SUMMARY:Test Event
  613. DTSTART;VALUE=DATE-TIME:20130912T130000Z
  614. DTEND;VALUE=DATE-TIME:20130912T140000Z
  615. CLASS:PUBLIC
  616. END:VEVENT
  617. END:VCALENDAR
  618. EOD;
  619. $this->backend->createCalendarObject($calendarId, $uri, $calData);
  620. $search1 = $this->backend->calendarSearch(self::UNIT_TEST_USER, [
  621. 'comps' => [
  622. 'VEVENT',
  623. 'VTODO'
  624. ],
  625. 'props' => [
  626. 'SUMMARY',
  627. 'LOCATION'
  628. ],
  629. 'search-term' => 'Test',
  630. ]);
  631. $this->assertEquals(count($search1), 1);
  632. // update the card
  633. $calData = <<<'EOD'
  634. BEGIN:VCALENDAR
  635. VERSION:2.0
  636. PRODID:ownCloud Calendar
  637. BEGIN:VEVENT
  638. CREATED;VALUE=DATE-TIME:20130910T125139Z
  639. UID:47d15e3ec8
  640. LAST-MODIFIED;VALUE=DATE-TIME:20130910T125139Z
  641. DTSTAMP;VALUE=DATE-TIME:20130910T125139Z
  642. SUMMARY:123 Event 🙈
  643. DTSTART;VALUE=DATE-TIME:20130912T130000Z
  644. DTEND;VALUE=DATE-TIME:20130912T140000Z
  645. ATTENDEE;CN=test:mailto:foo@bar.com
  646. END:VEVENT
  647. END:VCALENDAR
  648. EOD;
  649. $this->backend->updateCalendarObject($calendarId, $uri, $calData);
  650. $search2 = $this->backend->calendarSearch(self::UNIT_TEST_USER, [
  651. 'comps' => [
  652. 'VEVENT',
  653. 'VTODO'
  654. ],
  655. 'props' => [
  656. 'SUMMARY',
  657. 'LOCATION'
  658. ],
  659. 'search-term' => 'Test',
  660. ]);
  661. $this->assertEquals(count($search2), 0);
  662. $search3 = $this->backend->calendarSearch(self::UNIT_TEST_USER, [
  663. 'comps' => [
  664. 'VEVENT',
  665. 'VTODO'
  666. ],
  667. 'props' => [
  668. 'SUMMARY',
  669. 'LOCATION'
  670. ],
  671. 'params' => [
  672. [
  673. 'property' => 'ATTENDEE',
  674. 'parameter' => 'CN'
  675. ]
  676. ],
  677. 'search-term' => 'Test',
  678. ]);
  679. $this->assertEquals(count($search3), 1);
  680. // t matches both summary and attendee's CN, but we want unique results
  681. $search4 = $this->backend->calendarSearch(self::UNIT_TEST_USER, [
  682. 'comps' => [
  683. 'VEVENT',
  684. 'VTODO'
  685. ],
  686. 'props' => [
  687. 'SUMMARY',
  688. 'LOCATION'
  689. ],
  690. 'params' => [
  691. [
  692. 'property' => 'ATTENDEE',
  693. 'parameter' => 'CN'
  694. ]
  695. ],
  696. 'search-term' => 't',
  697. ]);
  698. $this->assertEquals(count($search4), 1);
  699. $this->backend->deleteCalendarObject($calendarId, $uri);
  700. $search5 = $this->backend->calendarSearch(self::UNIT_TEST_USER, [
  701. 'comps' => [
  702. 'VEVENT',
  703. 'VTODO'
  704. ],
  705. 'props' => [
  706. 'SUMMARY',
  707. 'LOCATION'
  708. ],
  709. 'params' => [
  710. [
  711. 'property' => 'ATTENDEE',
  712. 'parameter' => 'CN'
  713. ]
  714. ],
  715. 'search-term' => 't',
  716. ]);
  717. $this->assertEquals(count($search5), 0);
  718. }
  719. /**
  720. * @dataProvider searchDataProvider
  721. */
  722. public function testSearch(bool $isShared, array $searchOptions, int $count) {
  723. $calendarId = $this->createTestCalendar();
  724. $uris = [];
  725. $calData = [];
  726. $uris[] = static::getUniqueID('calobj');
  727. $calData[] = <<<EOD
  728. BEGIN:VCALENDAR
  729. VERSION:2.0
  730. PRODID:Nextcloud Calendar
  731. BEGIN:VEVENT
  732. CREATED;VALUE=DATE-TIME:20130910T125139Z
  733. UID:47d15e3ec8-1
  734. LAST-MODIFIED;VALUE=DATE-TIME:20130910T125139Z
  735. DTSTAMP;VALUE=DATE-TIME:20130910T125139Z
  736. SUMMARY:Test Event
  737. DTSTART;VALUE=DATE-TIME:20130912T130000Z
  738. DTEND;VALUE=DATE-TIME:20130912T140000Z
  739. CLASS:PUBLIC
  740. END:VEVENT
  741. END:VCALENDAR
  742. EOD;
  743. $uris[] = static::getUniqueID('calobj');
  744. $calData[] = <<<EOD
  745. BEGIN:VCALENDAR
  746. VERSION:2.0
  747. PRODID:Nextcloud Calendar
  748. BEGIN:VEVENT
  749. CREATED;VALUE=DATE-TIME:20130910T125139Z
  750. UID:47d15e3ec8-2
  751. LAST-MODIFIED;VALUE=DATE-TIME:20130910T125139Z
  752. DTSTAMP;VALUE=DATE-TIME:20130910T125139Z
  753. SUMMARY:123
  754. LOCATION:Test
  755. DTSTART;VALUE=DATE-TIME:20130912T130000Z
  756. DTEND;VALUE=DATE-TIME:20130912T140000Z
  757. CLASS:PUBLIC
  758. END:VEVENT
  759. END:VCALENDAR
  760. EOD;
  761. $uris[] = static::getUniqueID('calobj');
  762. $calData[] = <<<EOD
  763. BEGIN:VCALENDAR
  764. VERSION:2.0
  765. PRODID:Nextcloud Calendar
  766. BEGIN:VEVENT
  767. CREATED;VALUE=DATE-TIME:20130910T125139Z
  768. UID:47d15e3ec8-3
  769. LAST-MODIFIED;VALUE=DATE-TIME:20130910T125139Z
  770. DTSTAMP;VALUE=DATE-TIME:20130910T125139Z
  771. SUMMARY:123
  772. ATTENDEE;CN=test:mailto:foo@bar.com
  773. DTSTART;VALUE=DATE-TIME:20130912T130000Z
  774. DTEND;VALUE=DATE-TIME:20130912T140000Z
  775. CLASS:PRIVATE
  776. END:VEVENT
  777. END:VCALENDAR
  778. EOD;
  779. $uris[] = static::getUniqueID('calobj');
  780. $calData[] = <<<EOD
  781. BEGIN:VCALENDAR
  782. VERSION:2.0
  783. PRODID:Nextcloud Calendar
  784. BEGIN:VEVENT
  785. CREATED;VALUE=DATE-TIME:20130910T125139Z
  786. UID:47d15e3ec8-4
  787. LAST-MODIFIED;VALUE=DATE-TIME:20130910T125139Z
  788. DTSTAMP;VALUE=DATE-TIME:20130910T125139Z
  789. SUMMARY:123
  790. ATTENDEE;CN=foobar:mailto:test@bar.com
  791. DTSTART;VALUE=DATE-TIME:20130912T130000Z
  792. DTEND;VALUE=DATE-TIME:20130912T140000Z
  793. CLASS:CONFIDENTIAL
  794. END:VEVENT
  795. END:VCALENDAR
  796. EOD;
  797. $uriCount = count($uris);
  798. for ($i=0; $i < $uriCount; $i++) {
  799. $this->backend->createCalendarObject($calendarId,
  800. $uris[$i], $calData[$i]);
  801. }
  802. $calendarInfo = [
  803. 'id' => $calendarId,
  804. 'principaluri' => 'user1',
  805. '{http://owncloud.org/ns}owner-principal' => $isShared ? 'user2' : 'user1',
  806. ];
  807. $result = $this->backend->search($calendarInfo, 'Test',
  808. ['SUMMARY', 'LOCATION', 'ATTENDEE'], $searchOptions, null, null);
  809. $this->assertCount($count, $result);
  810. }
  811. public function searchDataProvider() {
  812. return [
  813. [false, [], 4],
  814. [true, ['timerange' => ['start' => new DateTime('2013-09-12 13:00:00'), 'end' => new DateTime('2013-09-12 14:00:00')]], 2],
  815. [true, ['timerange' => ['start' => new DateTime('2013-09-12 15:00:00'), 'end' => new DateTime('2013-09-12 16:00:00')]], 0],
  816. ];
  817. }
  818. public function testSameUriSameIdForDifferentCalendarTypes() {
  819. $calendarId = $this->createTestCalendar();
  820. $subscriptionId = $this->createTestSubscription();
  821. $uri = static::getUniqueID('calobj');
  822. $calData = <<<EOD
  823. BEGIN:VCALENDAR
  824. VERSION:2.0
  825. PRODID:ownCloud Calendar
  826. BEGIN:VEVENT
  827. CREATED;VALUE=DATE-TIME:20130910T125139Z
  828. UID:47d15e3ec8
  829. LAST-MODIFIED;VALUE=DATE-TIME:20130910T125139Z
  830. DTSTAMP;VALUE=DATE-TIME:20130910T125139Z
  831. SUMMARY:Test Event
  832. DTSTART;VALUE=DATE-TIME:20130912T130000Z
  833. DTEND;VALUE=DATE-TIME:20130912T140000Z
  834. CLASS:PUBLIC
  835. END:VEVENT
  836. END:VCALENDAR
  837. EOD;
  838. $calData2 = <<<EOD
  839. BEGIN:VCALENDAR
  840. VERSION:2.0
  841. PRODID:ownCloud Calendar
  842. BEGIN:VEVENT
  843. CREATED;VALUE=DATE-TIME:20130910T125139Z
  844. UID:47d15e3ec8
  845. LAST-MODIFIED;VALUE=DATE-TIME:20130910T125139Z
  846. DTSTAMP;VALUE=DATE-TIME:20130910T125139Z
  847. SUMMARY:Test Event 123
  848. DTSTART;VALUE=DATE-TIME:20130912T130000Z
  849. DTEND;VALUE=DATE-TIME:20130912T140000Z
  850. CLASS:PUBLIC
  851. END:VEVENT
  852. END:VCALENDAR
  853. EOD;
  854. $this->backend->createCalendarObject($calendarId, $uri, $calData);
  855. $this->backend->createCalendarObject($subscriptionId, $uri, $calData2, CalDavBackend::CALENDAR_TYPE_SUBSCRIPTION);
  856. $this->assertEquals($calData, $this->backend->getCalendarObject($calendarId, $uri, CalDavBackend::CALENDAR_TYPE_CALENDAR)['calendardata']);
  857. $this->assertEquals($calData2, $this->backend->getCalendarObject($subscriptionId, $uri, CalDavBackend::CALENDAR_TYPE_SUBSCRIPTION)['calendardata']);
  858. }
  859. public function testPurgeAllCachedEventsForSubscription() {
  860. $subscriptionId = $this->createTestSubscription();
  861. $uri = static::getUniqueID('calobj');
  862. $calData = <<<EOD
  863. BEGIN:VCALENDAR
  864. VERSION:2.0
  865. PRODID:ownCloud Calendar
  866. BEGIN:VEVENT
  867. CREATED;VALUE=DATE-TIME:20130910T125139Z
  868. UID:47d15e3ec8
  869. LAST-MODIFIED;VALUE=DATE-TIME:20130910T125139Z
  870. DTSTAMP;VALUE=DATE-TIME:20130910T125139Z
  871. SUMMARY:Test Event
  872. DTSTART;VALUE=DATE-TIME:20130912T130000Z
  873. DTEND;VALUE=DATE-TIME:20130912T140000Z
  874. CLASS:PUBLIC
  875. END:VEVENT
  876. END:VCALENDAR
  877. EOD;
  878. $this->backend->createCalendarObject($subscriptionId, $uri, $calData, CalDavBackend::CALENDAR_TYPE_SUBSCRIPTION);
  879. $this->backend->purgeAllCachedEventsForSubscription($subscriptionId);
  880. $this->assertEquals(null, $this->backend->getCalendarObject($subscriptionId, $uri, CalDavBackend::CALENDAR_TYPE_SUBSCRIPTION));
  881. }
  882. public function testCalendarMovement() {
  883. $this->backend->createCalendar(self::UNIT_TEST_USER, 'Example', []);
  884. $this->assertCount(1, $this->backend->getCalendarsForUser(self::UNIT_TEST_USER));
  885. $calendarInfoUser = $this->backend->getCalendarsForUser(self::UNIT_TEST_USER)[0];
  886. $this->backend->moveCalendar('Example', self::UNIT_TEST_USER, self::UNIT_TEST_USER1);
  887. $this->assertCount(0, $this->backend->getCalendarsForUser(self::UNIT_TEST_USER));
  888. $this->assertCount(1, $this->backend->getCalendarsForUser(self::UNIT_TEST_USER1));
  889. $calendarInfoUser1 = $this->backend->getCalendarsForUser(self::UNIT_TEST_USER1)[0];
  890. $this->assertEquals($calendarInfoUser['id'], $calendarInfoUser1['id']);
  891. $this->assertEquals($calendarInfoUser['uri'], $calendarInfoUser1['uri']);
  892. }
  893. }