CalendarTest.php 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2020 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 OCA\DAV\CalDAV\BirthdayService;
  9. use OCA\DAV\CalDAV\CalDavBackend;
  10. use OCA\DAV\CalDAV\Calendar;
  11. use OCP\IConfig;
  12. use OCP\IL10N;
  13. use PHPUnit\Framework\MockObject\MockObject;
  14. use Psr\Log\LoggerInterface;
  15. use Sabre\DAV\PropPatch;
  16. use Sabre\VObject\Reader;
  17. use Test\TestCase;
  18. class CalendarTest extends TestCase {
  19. /** @var IL10N */
  20. protected $l10n;
  21. /** @var IConfig */
  22. protected $config;
  23. /** @var MockObject|LoggerInterface */
  24. protected $logger;
  25. protected function setUp(): void {
  26. parent::setUp();
  27. $this->l10n = $this->getMockBuilder(IL10N::class)
  28. ->disableOriginalConstructor()->getMock();
  29. $this->config = $this->createMock(IConfig::class);
  30. $this->logger = $this->createMock(LoggerInterface::class);
  31. $this->l10n
  32. ->expects($this->any())
  33. ->method('t')
  34. ->willReturnCallback(function ($text, $parameters = []) {
  35. return vsprintf($text, $parameters);
  36. });
  37. }
  38. public function testDelete(): void {
  39. /** @var MockObject | CalDavBackend $backend */
  40. $backend = $this->getMockBuilder(CalDavBackend::class)->disableOriginalConstructor()->getMock();
  41. $backend->expects($this->once())->method('updateShares');
  42. $backend->expects($this->any())->method('getShares')->willReturn([
  43. ['href' => 'principal:user2']
  44. ]);
  45. $calendarInfo = [
  46. '{http://owncloud.org/ns}owner-principal' => 'user1',
  47. 'principaluri' => 'user2',
  48. 'id' => 666,
  49. 'uri' => 'cal',
  50. ];
  51. $c = new Calendar($backend, $calendarInfo, $this->l10n, $this->config, $this->logger);
  52. $c->delete();
  53. }
  54. public function testDeleteFromGroup(): void {
  55. /** @var MockObject | CalDavBackend $backend */
  56. $backend = $this->getMockBuilder(CalDavBackend::class)->disableOriginalConstructor()->getMock();
  57. $backend->expects($this->once())->method('updateShares');
  58. $backend->expects($this->any())->method('getShares')->willReturn([
  59. ['href' => 'principal:group2']
  60. ]);
  61. $calendarInfo = [
  62. '{http://owncloud.org/ns}owner-principal' => 'user1',
  63. 'principaluri' => 'user2',
  64. 'id' => 666,
  65. 'uri' => 'cal',
  66. ];
  67. $c = new Calendar($backend, $calendarInfo, $this->l10n, $this->config, $this->logger);
  68. $c->delete();
  69. }
  70. public function testDeleteOwn(): void {
  71. /** @var MockObject | CalDavBackend $backend */
  72. $backend = $this->createMock(CalDavBackend::class);
  73. $backend->expects($this->never())->method('updateShares');
  74. $backend->expects($this->never())->method('getShares');
  75. $this->config->expects($this->never())->method('setUserValue');
  76. $backend->expects($this->once())->method('deleteCalendar')
  77. ->with(666);
  78. $calendarInfo = [
  79. '{http://owncloud.org/ns}owner-principal' => 'user1',
  80. 'principaluri' => 'user1',
  81. 'id' => 666,
  82. 'uri' => 'cal',
  83. ];
  84. $c = new Calendar($backend, $calendarInfo, $this->l10n, $this->config, $this->logger);
  85. $c->delete();
  86. }
  87. public function testDeleteBirthdayCalendar(): void {
  88. /** @var MockObject | CalDavBackend $backend */
  89. $backend = $this->createMock(CalDavBackend::class);
  90. $backend->expects($this->once())->method('deleteCalendar')
  91. ->with(666);
  92. $this->config->expects($this->once())
  93. ->method('setUserValue')
  94. ->with('user1', 'dav', 'generateBirthdayCalendar', 'no');
  95. $calendarInfo = [
  96. '{http://owncloud.org/ns}owner-principal' => 'principals/users/user1',
  97. 'principaluri' => 'principals/users/user1',
  98. 'id' => 666,
  99. 'uri' => 'contact_birthdays',
  100. ];
  101. $c = new Calendar($backend, $calendarInfo, $this->l10n, $this->config, $this->logger);
  102. $c->delete();
  103. }
  104. public function dataPropPatch() {
  105. return [
  106. ['user1', 'user2', [], true],
  107. ['user1', 'user2', [
  108. '{http://owncloud.org/ns}calendar-enabled' => true,
  109. ], true],
  110. ['user1', 'user2', [
  111. '{DAV:}displayname' => true,
  112. ], true],
  113. ['user1', 'user2', [
  114. '{DAV:}displayname' => true,
  115. '{http://owncloud.org/ns}calendar-enabled' => true,
  116. ], true],
  117. ['user1', 'user1', [], false],
  118. ['user1', 'user1', [
  119. '{http://owncloud.org/ns}calendar-enabled' => true,
  120. ], false],
  121. ['user1', 'user1', [
  122. '{DAV:}displayname' => true,
  123. ], false],
  124. ['user1', 'user1', [
  125. '{DAV:}displayname' => true,
  126. '{http://owncloud.org/ns}calendar-enabled' => true,
  127. ], false],
  128. ];
  129. }
  130. /**
  131. * @dataProvider dataPropPatch
  132. */
  133. public function testPropPatch($ownerPrincipal, $principalUri, $mutations, $shared): void {
  134. /** @var MockObject | CalDavBackend $backend */
  135. $backend = $this->getMockBuilder(CalDavBackend::class)->disableOriginalConstructor()->getMock();
  136. $calendarInfo = [
  137. '{http://owncloud.org/ns}owner-principal' => $ownerPrincipal,
  138. 'principaluri' => $principalUri,
  139. 'id' => 666,
  140. 'uri' => 'default'
  141. ];
  142. $c = new Calendar($backend, $calendarInfo, $this->l10n, $this->config, $this->logger);
  143. $propPatch = new PropPatch($mutations);
  144. if (!$shared) {
  145. $backend->expects($this->once())
  146. ->method('updateCalendar')
  147. ->with(666, $propPatch);
  148. }
  149. $c->propPatch($propPatch);
  150. $this->addToAssertionCount(1);
  151. }
  152. /**
  153. * @dataProvider providesReadOnlyInfo
  154. */
  155. public function testAcl($expectsWrite, $readOnlyValue, $hasOwnerSet, $uri = 'default'): void {
  156. /** @var MockObject | CalDavBackend $backend */
  157. $backend = $this->getMockBuilder(CalDavBackend::class)->disableOriginalConstructor()->getMock();
  158. $backend->expects($this->any())->method('applyShareAcl')->willReturnArgument(1);
  159. $calendarInfo = [
  160. 'principaluri' => 'user2',
  161. 'id' => 666,
  162. 'uri' => $uri
  163. ];
  164. if (!is_null($readOnlyValue)) {
  165. $calendarInfo['{http://owncloud.org/ns}read-only'] = $readOnlyValue;
  166. }
  167. if ($hasOwnerSet) {
  168. $calendarInfo['{http://owncloud.org/ns}owner-principal'] = 'user1';
  169. }
  170. $c = new Calendar($backend, $calendarInfo, $this->l10n, $this->config, $this->logger);
  171. $acl = $c->getACL();
  172. $childAcl = $c->getChildACL();
  173. $expectedAcl = [[
  174. 'privilege' => '{DAV:}read',
  175. 'principal' => $hasOwnerSet ? 'user1' : 'user2',
  176. 'protected' => true
  177. ], [
  178. 'privilege' => '{DAV:}read',
  179. 'principal' => ($hasOwnerSet ? 'user1' : 'user2') . '/calendar-proxy-write',
  180. 'protected' => true,
  181. ], [
  182. 'privilege' => '{DAV:}read',
  183. 'principal' => ($hasOwnerSet ? 'user1' : 'user2') . '/calendar-proxy-read',
  184. 'protected' => true,
  185. ]];
  186. if ($uri === BirthdayService::BIRTHDAY_CALENDAR_URI) {
  187. $expectedAcl[] = [
  188. 'privilege' => '{DAV:}write-properties',
  189. 'principal' => $hasOwnerSet ? 'user1' : 'user2',
  190. 'protected' => true
  191. ];
  192. $expectedAcl[] = [
  193. 'privilege' => '{DAV:}write-properties',
  194. 'principal' => ($hasOwnerSet ? 'user1' : 'user2') . '/calendar-proxy-write',
  195. 'protected' => true
  196. ];
  197. } else {
  198. $expectedAcl[] = [
  199. 'privilege' => '{DAV:}write',
  200. 'principal' => $hasOwnerSet ? 'user1' : 'user2',
  201. 'protected' => true
  202. ];
  203. $expectedAcl[] = [
  204. 'privilege' => '{DAV:}write',
  205. 'principal' => ($hasOwnerSet ? 'user1' : 'user2') . '/calendar-proxy-write',
  206. 'protected' => true
  207. ];
  208. }
  209. $expectedAcl[] = [
  210. 'privilege' => '{DAV:}write-properties',
  211. 'principal' => ($hasOwnerSet ? 'user1' : 'user2') . '/calendar-proxy-read',
  212. 'protected' => true
  213. ];
  214. if ($hasOwnerSet) {
  215. $expectedAcl[] = [
  216. 'privilege' => '{DAV:}read',
  217. 'principal' => 'user2',
  218. 'protected' => true
  219. ];
  220. if ($expectsWrite) {
  221. $expectedAcl[] = [
  222. 'privilege' => '{DAV:}write',
  223. 'principal' => 'user2',
  224. 'protected' => true
  225. ];
  226. } else {
  227. $expectedAcl[] = [
  228. 'privilege' => '{DAV:}write-properties',
  229. 'principal' => 'user2',
  230. 'protected' => true
  231. ];
  232. }
  233. }
  234. $this->assertEquals($expectedAcl, $acl);
  235. $this->assertEquals($expectedAcl, $childAcl);
  236. }
  237. public function providesReadOnlyInfo() {
  238. return [
  239. 'read-only property not set' => [true, null, true],
  240. 'read-only property is false' => [true, false, true],
  241. 'read-only property is true' => [false, true, true],
  242. 'read-only property not set and no owner' => [true, null, false],
  243. 'read-only property is false and no owner' => [true, false, false],
  244. 'read-only property is true and no owner' => [false, true, false],
  245. 'birthday calendar' => [false, false, false, BirthdayService::BIRTHDAY_CALENDAR_URI]
  246. ];
  247. }
  248. /**
  249. * @dataProvider providesConfidentialClassificationData
  250. * @param int $expectedChildren
  251. * @param bool $isShared
  252. */
  253. public function testPrivateClassification($expectedChildren, $isShared): void {
  254. $calObject0 = ['uri' => 'event-0', 'classification' => CalDavBackend::CLASSIFICATION_PUBLIC];
  255. $calObject1 = ['uri' => 'event-1', 'classification' => CalDavBackend::CLASSIFICATION_CONFIDENTIAL];
  256. $calObject2 = ['uri' => 'event-2', 'classification' => CalDavBackend::CLASSIFICATION_PRIVATE];
  257. /** @var MockObject | CalDavBackend $backend */
  258. $backend = $this->getMockBuilder(CalDavBackend::class)->disableOriginalConstructor()->getMock();
  259. $backend->expects($this->any())->method('getCalendarObjects')->willReturn([
  260. $calObject0, $calObject1, $calObject2
  261. ]);
  262. $backend->expects($this->any())->method('getMultipleCalendarObjects')
  263. ->with(666, ['event-0', 'event-1', 'event-2'])
  264. ->willReturn([
  265. $calObject0, $calObject1, $calObject2
  266. ]);
  267. $backend->expects($this->any())->method('getCalendarObject')
  268. ->willReturn($calObject2)->with(666, 'event-2');
  269. $backend->expects($this->any())->method('applyShareAcl')->willReturnArgument(1);
  270. $calendarInfo = [
  271. 'principaluri' => 'user2',
  272. 'id' => 666,
  273. 'uri' => 'cal',
  274. ];
  275. if ($isShared) {
  276. $calendarInfo['{http://owncloud.org/ns}owner-principal'] = 'user1';
  277. }
  278. $c = new Calendar($backend, $calendarInfo, $this->l10n, $this->config, $this->logger);
  279. $children = $c->getChildren();
  280. $this->assertEquals($expectedChildren, count($children));
  281. $children = $c->getMultipleChildren(['event-0', 'event-1', 'event-2']);
  282. $this->assertEquals($expectedChildren, count($children));
  283. $this->assertEquals(!$isShared, $c->childExists('event-2'));
  284. }
  285. /**
  286. * @dataProvider providesConfidentialClassificationData
  287. * @param int $expectedChildren
  288. * @param bool $isShared
  289. */
  290. public function testConfidentialClassification($expectedChildren, $isShared): void {
  291. $start = '20160609';
  292. $end = '20160610';
  293. $calData = <<<EOD
  294. BEGIN:VCALENDAR
  295. PRODID:-//ownCloud calendar v1.2.2
  296. BEGIN:VEVENT
  297. CREATED:20160602T133732
  298. DTSTAMP:20160602T133732
  299. LAST-MODIFIED:20160602T133732
  300. UID:wej2z68l9h
  301. SUMMARY:Test Event
  302. LOCATION:Somewhere ...
  303. ATTENDEE;ROLE=REQ-PARTICIPANT;PARTSTAT=NEEDS-ACTION;CUTYPE=INDIVIDUAL;CN=de
  304. epdiver:MAILTO:thomas.mueller@tmit.eu
  305. ORGANIZER;CN=deepdiver:MAILTO:thomas.mueller@tmit.eu
  306. DESCRIPTION:maybe ....
  307. DTSTART;TZID=Europe/Berlin;VALUE=DATE:$start
  308. DTEND;TZID=Europe/Berlin;VALUE=DATE:$end
  309. RRULE:FREQ=DAILY
  310. BEGIN:VALARM
  311. ACTION:AUDIO
  312. TRIGGER:-PT15M
  313. END:VALARM
  314. END:VEVENT
  315. BEGIN:VTIMEZONE
  316. TZID:Europe/Berlin
  317. BEGIN:DAYLIGHT
  318. DTSTART:19810329T020000
  319. RRULE:FREQ=YEARLY;BYMONTH=3;BYDAY=-1SU
  320. TZNAME:MESZ
  321. TZOFFSETFROM:+0100
  322. TZOFFSETTO:+0200
  323. END:DAYLIGHT
  324. BEGIN:STANDARD
  325. DTSTART:19961027T030000
  326. RRULE:FREQ=YEARLY;BYMONTH=10;BYDAY=-1SU
  327. TZNAME:MEZ
  328. TZOFFSETFROM:+0200
  329. TZOFFSETTO:+0100
  330. END:STANDARD
  331. END:VTIMEZONE
  332. END:VCALENDAR
  333. EOD;
  334. $calObject0 = ['uri' => 'event-0', 'classification' => CalDavBackend::CLASSIFICATION_PUBLIC];
  335. $calObject1 = ['uri' => 'event-1', 'classification' => CalDavBackend::CLASSIFICATION_CONFIDENTIAL, 'calendardata' => $calData];
  336. $calObject2 = ['uri' => 'event-2', 'classification' => CalDavBackend::CLASSIFICATION_PRIVATE];
  337. /** @var MockObject | CalDavBackend $backend */
  338. $backend = $this->getMockBuilder(CalDavBackend::class)->disableOriginalConstructor()->getMock();
  339. $backend->expects($this->any())->method('getCalendarObjects')->willReturn([
  340. $calObject0, $calObject1, $calObject2
  341. ]);
  342. $backend->expects($this->any())->method('getMultipleCalendarObjects')
  343. ->with(666, ['event-0', 'event-1', 'event-2'])
  344. ->willReturn([
  345. $calObject0, $calObject1, $calObject2
  346. ]);
  347. $backend->expects($this->any())->method('getCalendarObject')
  348. ->willReturn($calObject1)->with(666, 'event-1');
  349. $backend->expects($this->any())->method('applyShareAcl')->willReturnArgument(1);
  350. $calendarInfo = [
  351. '{http://owncloud.org/ns}owner-principal' => $isShared ? 'user1' : 'user2',
  352. 'principaluri' => 'user2',
  353. 'id' => 666,
  354. 'uri' => 'cal',
  355. ];
  356. $c = new Calendar($backend, $calendarInfo, $this->l10n, $this->config, $this->logger);
  357. $this->assertEquals(count($c->getChildren()), $expectedChildren);
  358. // test private event
  359. $privateEvent = $c->getChild('event-1');
  360. $calData = $privateEvent->get();
  361. $event = Reader::read($calData);
  362. $this->assertEquals($start, $event->VEVENT->DTSTART->getValue());
  363. $this->assertEquals($end, $event->VEVENT->DTEND->getValue());
  364. if ($isShared) {
  365. $this->assertEquals('Busy', $event->VEVENT->SUMMARY->getValue());
  366. $this->assertArrayNotHasKey('ATTENDEE', $event->VEVENT);
  367. $this->assertArrayNotHasKey('LOCATION', $event->VEVENT);
  368. $this->assertArrayNotHasKey('DESCRIPTION', $event->VEVENT);
  369. $this->assertArrayNotHasKey('ORGANIZER', $event->VEVENT);
  370. } else {
  371. $this->assertEquals('Test Event', $event->VEVENT->SUMMARY->getValue());
  372. }
  373. // Test l10n
  374. $l10n = $this->createMock(IL10N::class);
  375. if ($isShared) {
  376. $l10n->expects($this->once())
  377. ->method('t')
  378. ->with('Busy')
  379. ->willReturn("Translated busy");
  380. } else {
  381. $l10n->expects($this->never())
  382. ->method('t');
  383. }
  384. $c = new Calendar($backend, $calendarInfo, $l10n, $this->config, $this->logger);
  385. $calData = $c->getChild('event-1')->get();
  386. $event = Reader::read($calData);
  387. if ($isShared) {
  388. $this->assertEquals('Translated busy', $event->VEVENT->SUMMARY->getValue());
  389. } else {
  390. $this->assertEquals('Test Event', $event->VEVENT->SUMMARY->getValue());
  391. }
  392. }
  393. public function providesConfidentialClassificationData() {
  394. return [
  395. [3, false],
  396. [2, true]
  397. ];
  398. }
  399. public function testRemoveVAlarms() {
  400. $publicObjectData = <<<EOD
  401. BEGIN:VCALENDAR
  402. VERSION:2.0
  403. PRODID:-//Nextcloud calendar v1.5.6
  404. CALSCALE:GREGORIAN
  405. BEGIN:VEVENT
  406. CREATED:20171022T125130
  407. DTSTAMP:20171022T125130
  408. LAST-MODIFIED:20171022T125130
  409. UID:PPL24TH8UGOWE94XET87ER
  410. SUMMARY:Foo bar blub
  411. CLASS:PUBLIC
  412. STATUS:CONFIRMED
  413. DTSTART;VALUE=DATE:20171024
  414. DTEND;VALUE=DATE:20171025
  415. BEGIN:VALARM
  416. ACTION:AUDIO
  417. TRIGGER:-PT15M
  418. END:VALARM
  419. END:VEVENT
  420. END:VCALENDAR
  421. EOD;
  422. $confidentialObjectData = <<<EOD
  423. BEGIN:VCALENDAR
  424. VERSION:2.0
  425. PRODID:-//Nextcloud calendar v1.5.6
  426. CALSCALE:GREGORIAN
  427. BEGIN:VEVENT
  428. CREATED:20171022T125130
  429. DTSTAMP:20171022T125130
  430. LAST-MODIFIED:20171022T125130
  431. UID:PPL24TH8UGOWE94XET87ER
  432. SUMMARY:Foo bar blub
  433. CLASS:CONFIDENTIAL
  434. STATUS:CONFIRMED
  435. DTSTART;VALUE=DATE:20171024
  436. DTEND;VALUE=DATE:20171025
  437. BEGIN:VALARM
  438. ACTION:AUDIO
  439. TRIGGER:-PT15M
  440. END:VALARM
  441. END:VEVENT
  442. END:VCALENDAR
  443. EOD;
  444. $publicObjectDataWithoutVAlarm = <<<EOD
  445. BEGIN:VCALENDAR
  446. VERSION:2.0
  447. PRODID:-//Nextcloud calendar v1.5.6
  448. CALSCALE:GREGORIAN
  449. BEGIN:VEVENT
  450. CREATED:20171022T125130
  451. DTSTAMP:20171022T125130
  452. LAST-MODIFIED:20171022T125130
  453. UID:PPL24TH8UGOWE94XET87ER
  454. SUMMARY:Foo bar blub
  455. CLASS:PUBLIC
  456. STATUS:CONFIRMED
  457. DTSTART;VALUE=DATE:20171024
  458. DTEND;VALUE=DATE:20171025
  459. END:VEVENT
  460. END:VCALENDAR
  461. EOD;
  462. $confidentialObjectCleaned = <<<EOD
  463. BEGIN:VCALENDAR
  464. VERSION:2.0
  465. PRODID:-//Nextcloud calendar v1.5.6
  466. CALSCALE:GREGORIAN
  467. BEGIN:VEVENT
  468. CREATED:20171022T125130
  469. UID:PPL24TH8UGOWE94XET87ER
  470. SUMMARY:Busy
  471. CLASS:CONFIDENTIAL
  472. DTSTART;VALUE=DATE:20171024
  473. DTEND;VALUE=DATE:20171025
  474. END:VEVENT
  475. END:VCALENDAR
  476. EOD;
  477. $publicObject = ['uri' => 'event-0',
  478. 'classification' => CalDavBackend::CLASSIFICATION_PUBLIC,
  479. 'calendardata' => $publicObjectData];
  480. $confidentialObject = ['uri' => 'event-1',
  481. 'classification' => CalDavBackend::CLASSIFICATION_CONFIDENTIAL,
  482. 'calendardata' => $confidentialObjectData];
  483. /** @var MockObject | CalDavBackend $backend */
  484. $backend = $this->createMock(CalDavBackend::class);
  485. $backend->expects($this->any())
  486. ->method('getCalendarObjects')
  487. ->willReturn([$publicObject, $confidentialObject]);
  488. $backend->expects($this->any())
  489. ->method('getMultipleCalendarObjects')
  490. ->with(666, ['event-0', 'event-1'])
  491. ->willReturn([$publicObject, $confidentialObject]);
  492. $backend->expects($this->any())
  493. ->method('getCalendarObject')
  494. ->willReturnCallback(function ($cId, $uri) use ($publicObject, $confidentialObject) {
  495. switch ($uri) {
  496. case 'event-0':
  497. return $publicObject;
  498. case 'event-1':
  499. return $confidentialObject;
  500. default:
  501. throw new \Exception('unexpected uri');
  502. }
  503. });
  504. $backend->expects($this->any())
  505. ->method('applyShareAcl')
  506. ->willReturnArgument(1);
  507. $calendarInfoOwner = [
  508. '{http://owncloud.org/ns}owner-principal' => 'user1',
  509. 'principaluri' => 'user1',
  510. 'id' => 666,
  511. 'uri' => 'cal',
  512. ];
  513. $calendarInfoSharedRW = [
  514. '{http://owncloud.org/ns}owner-principal' => 'user1',
  515. 'principaluri' => 'user2',
  516. 'id' => 666,
  517. 'uri' => 'cal',
  518. ];
  519. $calendarInfoSharedRO = [
  520. '{http://owncloud.org/ns}owner-principal' => 'user1',
  521. '{http://owncloud.org/ns}read-only' => true,
  522. 'principaluri' => 'user2',
  523. 'id' => 666,
  524. 'uri' => 'cal',
  525. ];
  526. $ownerCalendar = new Calendar($backend, $calendarInfoOwner, $this->l10n, $this->config, $this->logger);
  527. $rwCalendar = new Calendar($backend, $calendarInfoSharedRW, $this->l10n, $this->config, $this->logger);
  528. $roCalendar = new Calendar($backend, $calendarInfoSharedRO, $this->l10n, $this->config, $this->logger);
  529. $this->assertCount(2, $ownerCalendar->getChildren());
  530. $this->assertCount(2, $rwCalendar->getChildren());
  531. $this->assertCount(2, $roCalendar->getChildren());
  532. // calendar data shall not be altered for the owner
  533. $this->assertEquals($ownerCalendar->getChild('event-0')->get(), $publicObjectData);
  534. $this->assertEquals($ownerCalendar->getChild('event-1')->get(), $confidentialObjectData);
  535. // valarms shall not be removed for read-write shares
  536. $this->assertEquals(
  537. $this->fixLinebreak($rwCalendar->getChild('event-0')->get()),
  538. $this->fixLinebreak($publicObjectData));
  539. $this->assertEquals(
  540. $this->fixLinebreak($rwCalendar->getChild('event-1')->get()),
  541. $this->fixLinebreak($confidentialObjectCleaned));
  542. // valarms shall be removed for read-only shares
  543. $this->assertEquals(
  544. $this->fixLinebreak($roCalendar->getChild('event-0')->get()),
  545. $this->fixLinebreak($publicObjectDataWithoutVAlarm));
  546. $this->assertEquals(
  547. $this->fixLinebreak($roCalendar->getChild('event-1')->get()),
  548. $this->fixLinebreak($confidentialObjectCleaned));
  549. }
  550. private function fixLinebreak($str) {
  551. return preg_replace('~(*BSR_ANYCRLF)\R~', "\r\n", $str);
  552. }
  553. }