PublicCalendarTest.php 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2017, Georg Ehrke
  4. *
  5. * @author Georg Ehrke <oc.list@georgehrke.com>
  6. * @author Joas Schilling <coding@schilljs.com>
  7. * @author Morris Jobke <hey@morrisjobke.de>
  8. * @author Roeland Jago Douma <roeland@famdouma.nl>
  9. *
  10. * @license GNU AGPL version 3 or any later version
  11. *
  12. * This program is free software: you can redistribute it and/or modify
  13. * it under the terms of the GNU Affero General Public License as
  14. * published by the Free Software Foundation, either version 3 of the
  15. * License, or (at your option) any later version.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU Affero General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU Affero General Public License
  23. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  24. *
  25. */
  26. namespace OCA\DAV\Tests\unit\CalDAV;
  27. use OCA\DAV\CalDAV\CalDavBackend;
  28. use OCA\DAV\CalDAV\PublicCalendar;
  29. use OCP\IConfig;
  30. use PHPUnit\Framework\MockObject\MockObject;
  31. use Psr\Log\LoggerInterface;
  32. use Sabre\VObject\Reader;
  33. class PublicCalendarTest extends CalendarTest {
  34. /**
  35. * @dataProvider providesConfidentialClassificationData
  36. * @param int $expectedChildren
  37. * @param bool $isShared
  38. */
  39. public function testPrivateClassification($expectedChildren, $isShared): void {
  40. $calObject0 = ['uri' => 'event-0', 'classification' => CalDavBackend::CLASSIFICATION_PUBLIC];
  41. $calObject1 = ['uri' => 'event-1', 'classification' => CalDavBackend::CLASSIFICATION_CONFIDENTIAL];
  42. $calObject2 = ['uri' => 'event-2', 'classification' => CalDavBackend::CLASSIFICATION_PRIVATE];
  43. /** @var MockObject | CalDavBackend $backend */
  44. $backend = $this->getMockBuilder(CalDavBackend::class)->disableOriginalConstructor()->getMock();
  45. $backend->expects($this->any())->method('getCalendarObjects')->willReturn([
  46. $calObject0, $calObject1, $calObject2
  47. ]);
  48. $backend->expects($this->any())->method('getMultipleCalendarObjects')
  49. ->with(666, ['event-0', 'event-1', 'event-2'])
  50. ->willReturn([
  51. $calObject0, $calObject1, $calObject2
  52. ]);
  53. $backend->expects($this->any())->method('getCalendarObject')
  54. ->willReturn($calObject2)->with(666, 'event-2');
  55. $backend->expects($this->any())->method('applyShareAcl')->willReturnArgument(1);
  56. $calendarInfo = [
  57. '{http://owncloud.org/ns}owner-principal' => 'user2',
  58. 'principaluri' => 'user2',
  59. 'id' => 666,
  60. 'uri' => 'cal',
  61. ];
  62. /** @var MockObject | IConfig $config */
  63. $config = $this->createMock(IConfig::class);
  64. /** @var MockObject | LoggerInterface $logger */
  65. $logger = $this->createMock(LoggerInterface::class);
  66. $c = new PublicCalendar($backend, $calendarInfo, $this->l10n, $config, $logger);
  67. $children = $c->getChildren();
  68. $this->assertEquals(2, count($children));
  69. $children = $c->getMultipleChildren(['event-0', 'event-1', 'event-2']);
  70. $this->assertEquals(2, count($children));
  71. $this->assertFalse($c->childExists('event-2'));
  72. }
  73. /**
  74. * @dataProvider providesConfidentialClassificationData
  75. * @param int $expectedChildren
  76. * @param bool $isShared
  77. */
  78. public function testConfidentialClassification($expectedChildren, $isShared): void {
  79. $start = '20160609';
  80. $end = '20160610';
  81. $calData = <<<EOD
  82. BEGIN:VCALENDAR
  83. PRODID:-//ownCloud calendar v1.2.2
  84. BEGIN:VEVENT
  85. CREATED:20160602T133732
  86. DTSTAMP:20160602T133732
  87. LAST-MODIFIED:20160602T133732
  88. UID:wej2z68l9h
  89. SUMMARY:Test Event
  90. LOCATION:Somewhere ...
  91. ATTENDEE;ROLE=REQ-PARTICIPANT;PARTSTAT=NEEDS-ACTION;CUTYPE=INDIVIDUAL;CN=de
  92. epdiver:MAILTO:thomas.mueller@tmit.eu
  93. ORGANIZER;CN=deepdiver:MAILTO:thomas.mueller@tmit.eu
  94. DESCRIPTION:maybe ....
  95. DTSTART;TZID=Europe/Berlin;VALUE=DATE:$start
  96. DTEND;TZID=Europe/Berlin;VALUE=DATE:$end
  97. RRULE:FREQ=DAILY
  98. BEGIN:VALARM
  99. ACTION:AUDIO
  100. TRIGGER:-PT15M
  101. END:VALARM
  102. END:VEVENT
  103. BEGIN:VTIMEZONE
  104. TZID:Europe/Berlin
  105. BEGIN:DAYLIGHT
  106. DTSTART:19810329T020000
  107. RRULE:FREQ=YEARLY;BYMONTH=3;BYDAY=-1SU
  108. TZNAME:MESZ
  109. TZOFFSETFROM:+0100
  110. TZOFFSETTO:+0200
  111. END:DAYLIGHT
  112. BEGIN:STANDARD
  113. DTSTART:19961027T030000
  114. RRULE:FREQ=YEARLY;BYMONTH=10;BYDAY=-1SU
  115. TZNAME:MEZ
  116. TZOFFSETFROM:+0200
  117. TZOFFSETTO:+0100
  118. END:STANDARD
  119. END:VTIMEZONE
  120. END:VCALENDAR
  121. EOD;
  122. $calObject0 = ['uri' => 'event-0', 'classification' => CalDavBackend::CLASSIFICATION_PUBLIC];
  123. $calObject1 = ['uri' => 'event-1', 'classification' => CalDavBackend::CLASSIFICATION_CONFIDENTIAL, 'calendardata' => $calData];
  124. $calObject2 = ['uri' => 'event-2', 'classification' => CalDavBackend::CLASSIFICATION_PRIVATE];
  125. /** @var MockObject | CalDavBackend $backend */
  126. $backend = $this->getMockBuilder(CalDavBackend::class)->disableOriginalConstructor()->getMock();
  127. $backend->expects($this->any())->method('getCalendarObjects')->willReturn([
  128. $calObject0, $calObject1, $calObject2
  129. ]);
  130. $backend->expects($this->any())->method('getMultipleCalendarObjects')
  131. ->with(666, ['event-0', 'event-1', 'event-2'])
  132. ->willReturn([
  133. $calObject0, $calObject1, $calObject2
  134. ]);
  135. $backend->expects($this->any())->method('getCalendarObject')
  136. ->willReturn($calObject1)->with(666, 'event-1');
  137. $backend->expects($this->any())->method('applyShareAcl')->willReturnArgument(1);
  138. $calendarInfo = [
  139. '{http://owncloud.org/ns}owner-principal' => 'user1',
  140. 'principaluri' => 'user2',
  141. 'id' => 666,
  142. 'uri' => 'cal',
  143. ];
  144. /** @var MockObject | IConfig $config */
  145. $config = $this->createMock(IConfig::class);
  146. /** @var MockObject | LoggerInterface $logger */
  147. $logger = $this->createMock(LoggerInterface::class);
  148. $c = new PublicCalendar($backend, $calendarInfo, $this->l10n, $config, $logger);
  149. $this->assertEquals(count($c->getChildren()), 2);
  150. // test private event
  151. $privateEvent = $c->getChild('event-1');
  152. $calData = $privateEvent->get();
  153. $event = Reader::read($calData);
  154. $this->assertEquals($start, $event->VEVENT->DTSTART->getValue());
  155. $this->assertEquals($end, $event->VEVENT->DTEND->getValue());
  156. $this->assertEquals('Busy', $event->VEVENT->SUMMARY->getValue());
  157. $this->assertArrayNotHasKey('ATTENDEE', $event->VEVENT);
  158. $this->assertArrayNotHasKey('LOCATION', $event->VEVENT);
  159. $this->assertArrayNotHasKey('DESCRIPTION', $event->VEVENT);
  160. $this->assertArrayNotHasKey('ORGANIZER', $event->VEVENT);
  161. }
  162. }