2016-08-18 18:04:04 +03:00
|
|
|
<?php
|
2017-11-06 17:56:42 +03:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
*
|
2020-04-29 12:57:22 +03:00
|
|
|
* @author Christoph Wurst <christoph@winzerhof-wurst.at>
|
2017-11-06 22:15:27 +03:00
|
|
|
* @author Georg Ehrke <oc.list@georgehrke.com>
|
2017-11-06 17:56:42 +03:00
|
|
|
* @author Joas Schilling <coding@schilljs.com>
|
|
|
|
* @author Lukas Reschke <lukas@statuscode.ch>
|
|
|
|
* @author Morris Jobke <hey@morrisjobke.de>
|
2019-12-03 21:57:53 +03:00
|
|
|
* @author Roeland Jago Douma <roeland@famdouma.nl>
|
2020-03-31 11:49:10 +03:00
|
|
|
* @author Thomas Citharel <nextcloud@tcit.fr>
|
2017-11-06 17:56:42 +03:00
|
|
|
* @author Thomas Müller <thomas.mueller@tmit.eu>
|
2019-12-03 21:57:53 +03:00
|
|
|
* @author Vinicius Cubas Brand <vinicius@eita.org.br>
|
2017-11-06 17:56:42 +03:00
|
|
|
*
|
|
|
|
* @license GNU AGPL version 3 or any later version
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License as
|
|
|
|
* published by the Free Software Foundation, either version 3 of the
|
|
|
|
* License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* 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
|
2019-12-03 21:57:53 +03:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2017-11-06 17:56:42 +03:00
|
|
|
*
|
|
|
|
*/
|
2019-11-22 22:52:10 +03:00
|
|
|
|
2016-08-18 18:04:04 +03:00
|
|
|
namespace OCA\DAV\Tests\unit\CalDAV;
|
|
|
|
|
2019-11-22 22:52:10 +03:00
|
|
|
use OCA\DAV\CalDAV\CalDavBackend;
|
2016-08-18 18:04:04 +03:00
|
|
|
use OCA\DAV\CalDAV\Calendar;
|
2017-04-09 19:51:14 +03:00
|
|
|
use OCA\DAV\CalDAV\PublicCalendar;
|
2019-11-22 22:52:10 +03:00
|
|
|
use OCA\DAV\CalDAV\PublicCalendarRoot;
|
2016-08-30 20:21:32 +03:00
|
|
|
use OCA\DAV\Connector\Sabre\Principal;
|
2020-07-28 10:35:51 +03:00
|
|
|
use OCP\EventDispatcher\IEventDispatcher;
|
2017-10-20 16:09:52 +03:00
|
|
|
use OCP\IConfig;
|
2017-10-05 13:32:46 +03:00
|
|
|
use OCP\IGroupManager;
|
2016-08-18 18:04:04 +03:00
|
|
|
use OCP\IL10N;
|
2017-10-22 13:16:58 +03:00
|
|
|
use OCP\ILogger;
|
2016-08-30 20:21:32 +03:00
|
|
|
use OCP\IUserManager;
|
2016-09-03 11:52:05 +03:00
|
|
|
use OCP\Security\ISecureRandom;
|
2016-10-13 16:34:26 +03:00
|
|
|
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
2016-08-18 18:04:04 +03:00
|
|
|
use Test\TestCase;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Class PublicCalendarRootTest
|
|
|
|
*
|
|
|
|
* @group DB
|
|
|
|
*
|
|
|
|
* @package OCA\DAV\Tests\unit\CalDAV
|
|
|
|
*/
|
|
|
|
class PublicCalendarRootTest extends TestCase {
|
2020-04-10 17:54:27 +03:00
|
|
|
public const UNIT_TEST_USER = '';
|
2016-08-18 18:04:04 +03:00
|
|
|
/** @var CalDavBackend */
|
|
|
|
private $backend;
|
|
|
|
/** @var PublicCalendarRoot */
|
|
|
|
private $publicCalendarRoot;
|
|
|
|
/** @var IL10N */
|
|
|
|
private $l10n;
|
2020-08-11 22:32:18 +03:00
|
|
|
/** @var Principal|\PHPUnit\Framework\MockObject\MockObject */
|
2016-08-30 20:21:32 +03:00
|
|
|
private $principal;
|
2020-08-11 22:32:18 +03:00
|
|
|
/** @var IUserManager|\PHPUnit\Framework\MockObject\MockObject */
|
2016-10-13 12:04:22 +03:00
|
|
|
protected $userManager;
|
2020-08-11 22:32:18 +03:00
|
|
|
/** @var IGroupManager|\PHPUnit\Framework\MockObject\MockObject */
|
2017-10-05 13:32:46 +03:00
|
|
|
protected $groupManager;
|
2017-10-20 16:09:52 +03:00
|
|
|
/** @var IConfig */
|
|
|
|
protected $config;
|
2016-10-13 12:04:22 +03:00
|
|
|
|
2016-09-03 11:52:05 +03:00
|
|
|
/** @var ISecureRandom */
|
|
|
|
private $random;
|
2017-10-22 13:16:58 +03:00
|
|
|
/** @var ILogger */
|
|
|
|
private $logger;
|
2016-08-18 18:04:04 +03:00
|
|
|
|
2019-11-27 17:27:18 +03:00
|
|
|
protected function setUp(): void {
|
2016-08-18 18:04:04 +03:00
|
|
|
parent::setUp();
|
|
|
|
|
|
|
|
$db = \OC::$server->getDatabaseConnection();
|
2016-10-13 12:04:22 +03:00
|
|
|
$this->principal = $this->createMock('OCA\DAV\Connector\Sabre\Principal');
|
|
|
|
$this->userManager = $this->createMock(IUserManager::class);
|
2017-10-05 13:32:46 +03:00
|
|
|
$this->groupManager = $this->createMock(IGroupManager::class);
|
2016-09-03 11:52:05 +03:00
|
|
|
$this->random = \OC::$server->getSecureRandom();
|
2017-10-22 13:16:58 +03:00
|
|
|
$this->logger = $this->createMock(ILogger::class);
|
2020-07-28 10:35:51 +03:00
|
|
|
$dispatcher = $this->createMock(IEventDispatcher::class);
|
|
|
|
$legacyDispatcher = $this->createMock(EventDispatcherInterface::class);
|
2016-08-18 18:04:04 +03:00
|
|
|
|
2017-06-08 10:08:24 +03:00
|
|
|
$this->principal->expects($this->any())->method('getGroupMembership')
|
|
|
|
->withAnyParameters()
|
|
|
|
->willReturn([]);
|
|
|
|
|
2017-09-30 00:43:04 +03:00
|
|
|
$this->principal->expects($this->any())->method('getCircleMembership')
|
|
|
|
->withAnyParameters()
|
|
|
|
->willReturn([]);
|
|
|
|
|
2016-08-30 20:21:32 +03:00
|
|
|
$this->backend = new CalDavBackend(
|
|
|
|
$db,
|
|
|
|
$this->principal,
|
|
|
|
$this->userManager,
|
2017-10-05 13:32:46 +03:00
|
|
|
$this->groupManager,
|
2016-10-13 12:04:22 +03:00
|
|
|
$this->random,
|
2017-10-22 13:16:58 +03:00
|
|
|
$this->logger,
|
2020-07-28 10:35:51 +03:00
|
|
|
$dispatcher,
|
|
|
|
$legacyDispatcher
|
2016-08-30 20:21:32 +03:00
|
|
|
);
|
2017-10-24 16:26:53 +03:00
|
|
|
$this->l10n = $this->getMockBuilder(IL10N::class)
|
2016-08-18 18:04:04 +03:00
|
|
|
->disableOriginalConstructor()->getMock();
|
2017-10-20 16:09:52 +03:00
|
|
|
$this->config = $this->createMock(IConfig::class);
|
|
|
|
|
|
|
|
$this->publicCalendarRoot = new PublicCalendarRoot($this->backend,
|
|
|
|
$this->l10n, $this->config);
|
2016-08-18 18:04:04 +03:00
|
|
|
}
|
|
|
|
|
2019-11-27 17:27:18 +03:00
|
|
|
protected function tearDown(): void {
|
2016-09-03 11:52:05 +03:00
|
|
|
parent::tearDown();
|
|
|
|
|
|
|
|
if (is_null($this->backend)) {
|
|
|
|
return;
|
|
|
|
}
|
2017-06-08 10:08:24 +03:00
|
|
|
$this->principal->expects($this->any())->method('getGroupMembership')
|
|
|
|
->withAnyParameters()
|
|
|
|
->willReturn([]);
|
2017-09-30 00:43:04 +03:00
|
|
|
|
|
|
|
$this->principal->expects($this->any())->method('getCircleMembership')
|
|
|
|
->withAnyParameters()
|
|
|
|
->willReturn([]);
|
|
|
|
|
2016-09-03 11:52:05 +03:00
|
|
|
$books = $this->backend->getCalendarsForUser(self::UNIT_TEST_USER);
|
|
|
|
foreach ($books as $book) {
|
|
|
|
$this->backend->deleteCalendar($book['id']);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-18 18:04:04 +03:00
|
|
|
public function testGetName() {
|
|
|
|
$name = $this->publicCalendarRoot->getName();
|
|
|
|
$this->assertEquals('public-calendars', $name);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetChild() {
|
|
|
|
$calendar = $this->createPublicCalendar();
|
|
|
|
|
2016-09-03 11:52:05 +03:00
|
|
|
$publicCalendars = $this->backend->getPublicCalendars();
|
|
|
|
$this->assertEquals(1, count($publicCalendars));
|
|
|
|
$this->assertEquals(true, $publicCalendars[0]['{http://owncloud.org/ns}public']);
|
|
|
|
|
|
|
|
$publicCalendarURI = $publicCalendars[0]['uri'];
|
2016-08-18 18:04:04 +03:00
|
|
|
|
|
|
|
$calendarResult = $this->publicCalendarRoot->getChild($publicCalendarURI);
|
|
|
|
$this->assertEquals($calendar, $calendarResult);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetChildren() {
|
2016-09-03 11:52:05 +03:00
|
|
|
$this->createPublicCalendar();
|
2016-08-18 18:04:04 +03:00
|
|
|
$calendarResults = $this->publicCalendarRoot->getChildren();
|
2017-04-05 23:43:05 +03:00
|
|
|
$this->assertSame([], $calendarResults);
|
2016-08-18 18:04:04 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return Calendar
|
|
|
|
*/
|
|
|
|
protected function createPublicCalendar() {
|
|
|
|
$this->backend->createCalendar(self::UNIT_TEST_USER, 'Example', []);
|
|
|
|
|
|
|
|
$calendarInfo = $this->backend->getCalendarsForUser(self::UNIT_TEST_USER)[0];
|
2017-10-20 16:09:52 +03:00
|
|
|
$calendar = new PublicCalendar($this->backend, $calendarInfo, $this->l10n, $this->config);
|
2016-09-03 11:52:05 +03:00
|
|
|
$publicUri = $calendar->setPublishStatus(true);
|
2016-08-18 18:04:04 +03:00
|
|
|
|
2016-09-03 11:52:05 +03:00
|
|
|
$calendarInfo = $this->backend->getPublicCalendar($publicUri);
|
2017-10-20 16:09:52 +03:00
|
|
|
$calendar = new PublicCalendar($this->backend, $calendarInfo, $this->l10n, $this->config);
|
2016-08-18 18:04:04 +03:00
|
|
|
|
|
|
|
return $calendar;
|
|
|
|
}
|
|
|
|
}
|