CalDavBackendTest.php 36 KB

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