* * @license AGPL-3.0 * * This code is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License, version 3, * as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License, version 3, * along with this program. If not, see * */ namespace OCA\DAV\Tests\unit\CalDAV; use OCA\DAV\CalDAV\PublicCalendar; use OCA\DAV\CalDAV\CalDavBackend; use Sabre\VObject\Reader; class PublicCalendarTest extends CalendarTest { /** * @dataProvider providesConfidentialClassificationData * @param int $expectedChildren * @param bool $isShared */ public function testPrivateClassification($expectedChildren, $isShared) { $calObject0 = ['uri' => 'event-0', 'classification' => CalDavBackend::CLASSIFICATION_PUBLIC]; $calObject1 = ['uri' => 'event-1', 'classification' => CalDavBackend::CLASSIFICATION_CONFIDENTIAL]; $calObject2 = ['uri' => 'event-2', 'classification' => CalDavBackend::CLASSIFICATION_PRIVATE]; /** @var \PHPUnit_Framework_MockObject_MockObject | CalDavBackend $backend */ $backend = $this->getMockBuilder(CalDavBackend::class)->disableOriginalConstructor()->getMock(); $backend->expects($this->any())->method('getCalendarObjects')->willReturn([ $calObject0, $calObject1, $calObject2 ]); $backend->expects($this->any())->method('getMultipleCalendarObjects') ->with(666, ['event-0', 'event-1', 'event-2']) ->willReturn([ $calObject0, $calObject1, $calObject2 ]); $backend->expects($this->any())->method('getCalendarObject') ->willReturn($calObject2)->with(666, 'event-2'); $calendarInfo = [ '{http://owncloud.org/ns}owner-principal' => 'user2', 'principaluri' => 'user2', 'id' => 666, 'uri' => 'cal', ]; $c = new PublicCalendar($backend, $calendarInfo, $this->l10n); $children = $c->getChildren(); $this->assertEquals(2, count($children)); $children = $c->getMultipleChildren(['event-0', 'event-1', 'event-2']); $this->assertEquals(2, count($children)); $this->assertFalse($c->childExists('event-2')); } /** * @dataProvider providesConfidentialClassificationData * @param int $expectedChildren * @param bool $isShared */ public function testConfidentialClassification($expectedChildren, $isShared) { $start = '20160609'; $end = '20160610'; $calData = << 'event-0', 'classification' => CalDavBackend::CLASSIFICATION_PUBLIC]; $calObject1 = ['uri' => 'event-1', 'classification' => CalDavBackend::CLASSIFICATION_CONFIDENTIAL, 'calendardata' => $calData]; $calObject2 = ['uri' => 'event-2', 'classification' => CalDavBackend::CLASSIFICATION_PRIVATE]; /** @var \PHPUnit_Framework_MockObject_MockObject | CalDavBackend $backend */ $backend = $this->getMockBuilder(CalDavBackend::class)->disableOriginalConstructor()->getMock(); $backend->expects($this->any())->method('getCalendarObjects')->willReturn([ $calObject0, $calObject1, $calObject2 ]); $backend->expects($this->any())->method('getMultipleCalendarObjects') ->with(666, ['event-0', 'event-1', 'event-2']) ->willReturn([ $calObject0, $calObject1, $calObject2 ]); $backend->expects($this->any())->method('getCalendarObject') ->willReturn($calObject1)->with(666, 'event-1'); $calendarInfo = [ '{http://owncloud.org/ns}owner-principal' => 'user1', 'principaluri' => 'user2', 'id' => 666, 'uri' => 'cal', ]; $c = new PublicCalendar($backend, $calendarInfo, $this->l10n); $this->assertEquals(count($c->getChildren()), 2); // test private event $privateEvent = $c->getChild('event-1'); $calData = $privateEvent->get(); $event = Reader::read($calData); $this->assertEquals($start, $event->VEVENT->DTSTART->getValue()); $this->assertEquals($end, $event->VEVENT->DTEND->getValue()); $this->assertEquals('Busy', $event->VEVENT->SUMMARY->getValue()); $this->assertArrayNotHasKey('ATTENDEE', $event->VEVENT); $this->assertArrayNotHasKey('LOCATION', $event->VEVENT); $this->assertArrayNotHasKey('DESCRIPTION', $event->VEVENT); $this->assertArrayNotHasKey('ORGANIZER', $event->VEVENT); } }