PublicCalendarTest.php 5.9 KB

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