use OCA\DAV\Connector\Sabre\ExceptionLoggerPlugin;
use OCA\DAV\Connector\Sabre\MaintenancePlugin;
use OCA\DAV\Connector\Sabre\Principal;
+use Psr\Log\LoggerInterface;
$authBackend = new Auth(
\OC::$server->getSession(),
$principalCollection = new \Sabre\CalDAV\Principal\Collection($principalBackend);
$principalCollection->disableListing = !$debugging; // Disable listing
-$addressBookRoot = new CalendarRoot($principalBackend, $calDavBackend);
+$addressBookRoot = new CalendarRoot($principalBackend, $calDavBackend, 'principals', \OC::$server->get(LoggerInterface::class));
$addressBookRoot->disableListing = !$debugging; // Disable listing
$nodes = [
use OCA\DAV\Events\SubscriptionCreatedEvent;
use OCA\DAV\Events\SubscriptionDeletedEvent;
use OCA\DAV\Events\SubscriptionUpdatedEvent;
+use OCP\DB\Exception;
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\IConfig;
*
* @param string $principalUri
* @return array
- * @throws \OCP\DB\Exception
+ * @throws Exception
*/
public function getDeletedCalendarObjectsByPrincipal(string $principalUri): array {
$query = $this->db->getQueryBuilder();
return '"' . $extraData['etag'] . '"';
}
+ /**
+ * Moves a calendar object from calendar to calendar.
+ *
+ * @param int $sourceCalendarId
+ * @param int $targetCalendarId
+ * @param int $objectId
+ * @param string $principalUri
+ * @param int $calendarType
+ * @return bool
+ * @throws Exception
+ */
+ public function moveCalendarObject(int $sourceCalendarId, int $targetCalendarId, int $objectId, string $principalUri, int $calendarType = self::CALENDAR_TYPE_CALENDAR): bool {
+ $object = $this->getCalendarObjectById($principalUri, $objectId);
+ if (empty($object)) {
+ return false;
+ }
+
+ $query = $this->db->getQueryBuilder();
+ $query->update('calendarobjects')
+ ->set('calendarid', $query->createNamedParameter($targetCalendarId, IQueryBuilder::PARAM_INT))
+ ->where($query->expr()->eq('id', $query->createNamedParameter($objectId, IQueryBuilder::PARAM_INT), IQueryBuilder::PARAM_INT))
+ ->andWhere($query->expr()->eq('calendartype', $query->createNamedParameter($calendarType, IQueryBuilder::PARAM_INT), IQueryBuilder::PARAM_INT))
+ ->executeStatement();
+
+ $this->purgeProperties($sourceCalendarId, $objectId);
+ $this->updateProperties($targetCalendarId, $object['uri'], $object['calendardata'], $calendarType);
+
+ $this->addChange($sourceCalendarId, $object['uri'], 1, $calendarType);
+ $this->addChange($targetCalendarId, $object['uri'], 3, $calendarType);
+
+ $object = $this->getCalendarObjectById($principalUri, $objectId);
+ // Calendar Object wasn't found - possibly because it was deleted in the meantime by a different client
+ if (empty($object)) {
+ return false;
+ }
+
+ $calendarRow = $this->getCalendarById($targetCalendarId);
+ // the calendar this event is being moved to does not exist any longer
+ if (empty($calendarRow)) {
+ return false;
+ }
+
+ if ($calendarType === self::CALENDAR_TYPE_CALENDAR) {
+ $shares = $this->getShares($targetCalendarId);
+ $this->dispatcher->dispatchTyped(new CalendarObjectUpdatedEvent($targetCalendarId, $calendarRow, $shares, $object));
+ }
+ return true;
+ }
+
+
/**
* @param int $calendarObjectId
* @param int $classification
use OCA\DAV\CalDAV\Trashbin\Plugin as TrashbinPlugin;
use OCA\DAV\DAV\Sharing\IShareable;
use OCA\DAV\Exception\UnsupportedLimitOnInitialSyncException;
+use OCP\DB\Exception;
use OCP\IConfig;
use OCP\IL10N;
+use Psr\Log\LoggerInterface;
use Sabre\CalDAV\Backend\BackendInterface;
use Sabre\DAV\Exception\Forbidden;
use Sabre\DAV\Exception\NotFound;
+use Sabre\DAV\IMoveTarget;
+use Sabre\DAV\INode;
use Sabre\DAV\PropPatch;
/**
* @package OCA\DAV\CalDAV
* @property CalDavBackend $caldavBackend
*/
-class Calendar extends \Sabre\CalDAV\Calendar implements IRestorable, IShareable {
+class Calendar extends \Sabre\CalDAV\Calendar implements IRestorable, IShareable, IMoveTarget {
/** @var IConfig */
private $config;
/** @var bool */
private $useTrashbin = true;
+ /** @var LoggerInterface */
+ private $logger;
+
/**
* Calendar constructor.
*
* @param IL10N $l10n
* @param IConfig $config
*/
- public function __construct(BackendInterface $caldavBackend, $calendarInfo, IL10N $l10n, IConfig $config) {
+ public function __construct(BackendInterface $caldavBackend, $calendarInfo, IL10N $l10n, IConfig $config, LoggerInterface $logger) {
// Convert deletion date to ISO8601 string
if (isset($calendarInfo[TrashbinPlugin::PROPERTY_DELETED_AT])) {
$calendarInfo[TrashbinPlugin::PROPERTY_DELETED_AT] = (new DateTimeImmutable())
$this->config = $config;
$this->l10n = $l10n;
+ $this->logger = $logger;
}
/**
return parent::getChanges($syncToken, $syncLevel, $limit);
}
+ /**
+ * @inheritDoc
+ */
public function restore(): void {
$this->caldavBackend->restoreCalendar((int) $this->calendarInfo['id']);
}
public function disableTrashbin(): void {
$this->useTrashbin = false;
}
+
+ /**
+ * @inheritDoc
+ */
+ public function moveInto($targetName, $sourcePath, INode $sourceNode) {
+ if (!($sourceNode instanceof CalendarObject)) {
+ return false;
+ }
+
+ try {
+ return $this->caldavBackend->moveCalendarObject($sourceNode->getCalendarId(), (int)$this->calendarInfo['id'], $sourceNode->getId(), $sourceNode->getPrincipalUri());
+ } catch (Exception $e) {
+ $this->logger->error('Could not move calendar object: ' . $e->getMessage(), ['exception' => $e]);
+ return false;
+ }
+ }
}
use OCA\DAV\CalDAV\Integration\ExternalCalendar;
use OCA\DAV\CalDAV\Integration\ICalendarProvider;
use OCA\DAV\CalDAV\Trashbin\TrashbinHome;
+use Psr\Log\LoggerInterface;
use Sabre\CalDAV\Backend\BackendInterface;
use Sabre\CalDAV\Backend\NotificationSupport;
use Sabre\CalDAV\Backend\SchedulingSupport;
/** @var bool */
private $returnCachedSubscriptions = false;
- public function __construct(BackendInterface $caldavBackend, $principalInfo) {
+ /** @var LoggerInterface */
+ private $logger;
+
+ public function __construct(BackendInterface $caldavBackend, $principalInfo, LoggerInterface $logger) {
parent::__construct($caldavBackend, $principalInfo);
$this->l10n = \OC::$server->getL10N('dav');
$this->config = \OC::$server->getConfig();
\OC::$server,
\OC::$server->getAppManager()
);
+ $this->logger = $logger;
}
/**
$calendars = $this->caldavBackend->getCalendarsForUser($this->principalInfo['uri']);
$objects = [];
foreach ($calendars as $calendar) {
- $objects[] = new Calendar($this->caldavBackend, $calendar, $this->l10n, $this->config);
+ $objects[] = new Calendar($this->caldavBackend, $calendar, $this->l10n, $this->config, $this->logger);
}
if ($this->caldavBackend instanceof SchedulingSupport) {
// Calendars
foreach ($this->caldavBackend->getCalendarsForUser($this->principalInfo['uri']) as $calendar) {
if ($calendar['uri'] === $name) {
- return new Calendar($this->caldavBackend, $calendar, $this->l10n, $this->config);
+ return new Calendar($this->caldavBackend, $calendar, $this->l10n, $this->config, $this->logger);
}
}
use OCP\Calendar\IManager;
use OCP\IConfig;
use OCP\IL10N;
+use Psr\Log\LoggerInterface;
class CalendarManager {
/** @var IConfig */
private $config;
+ /** @var LoggerInterface */
+ private $logger;
+
/**
* CalendarManager constructor.
*
* @param IL10N $l10n
* @param IConfig $config
*/
- public function __construct(CalDavBackend $backend, IL10N $l10n, IConfig $config) {
+ public function __construct(CalDavBackend $backend, IL10N $l10n, IConfig $config, LoggerInterface $logger) {
$this->backend = $backend;
$this->l10n = $l10n;
$this->config = $config;
+ $this->logger = $logger;
}
/**
*/
private function register(IManager $cm, array $calendars) {
foreach ($calendars as $calendarInfo) {
- $calendar = new Calendar($this->backend, $calendarInfo, $this->l10n, $this->config);
+ $calendar = new Calendar($this->backend, $calendarInfo, $this->l10n, $this->config, $this->logger);
$cm->registerCalendar(new CalendarImpl(
$calendar,
$calendarInfo,
}
return true;
}
+
+ public function getCalendarId(): int {
+ return (int)$this->objectData['calendarId'];
+ }
+
+ public function getPrincipalUri(): string {
+ return $this->objectData['principaluri'];
+ }
}
use OCP\Calendar\ICalendarProvider;
use OCP\IConfig;
use OCP\IL10N;
+use Psr\Log\LoggerInterface;
class CalendarProvider implements ICalendarProvider {
/** @var IConfig */
private $config;
- public function __construct(CalDavBackend $calDavBackend, IL10N $l10n, IConfig $config) {
+ /** @var LoggerInterface */
+ private $logger;
+
+ public function __construct(CalDavBackend $calDavBackend, IL10N $l10n, IConfig $config, LoggerInterface $logger) {
$this->calDavBackend = $calDavBackend;
$this->l10n = $l10n;
$this->config = $config;
+ $this->logger = $logger;
}
public function getCalendars(string $principalUri, array $calendarUris = []): array {
$iCalendars = [];
foreach ($calendarInfos as $calendarInfo) {
- $calendar = new Calendar($this->calDavBackend, $calendarInfo, $this->l10n, $this->config);
+ $calendar = new Calendar($this->calDavBackend, $calendarInfo, $this->l10n, $this->config, $this->logger);
$iCalendars[] = new CalendarImpl(
$calendar,
$calendarInfo,
*/
namespace OCA\DAV\CalDAV;
+use Psr\Log\LoggerInterface;
+use Sabre\CalDAV\Backend;
+use Sabre\DAVACL\PrincipalBackend;
+
class CalendarRoot extends \Sabre\CalDAV\CalendarRoot {
+
+ /** @var LoggerInterface */
+ private $logger;
+
+ public function __construct(PrincipalBackend\BackendInterface $principalBackend, Backend\BackendInterface $caldavBackend, $principalPrefix = 'principals', LoggerInterface $logger) {
+ parent::__construct($principalBackend, $caldavBackend, $principalPrefix);
+ $this->logger = $logger;
+ }
+
public function getChildForPrincipal(array $principal) {
- return new CalendarHome($this->caldavBackend, $principal);
+ return new CalendarHome($this->caldavBackend, $principal, $this->logger);
}
public function getName() {
use OCP\IConfig;
use OCP\IL10N;
+use Psr\Log\LoggerInterface;
use Sabre\DAV\Collection;
class PublicCalendarRoot extends Collection {
/** @var \OCP\IConfig */
protected $config;
+ /** @var LoggerInterface */
+ private $logger;
+
/**
* PublicCalendarRoot constructor.
*
* @param IConfig $config
*/
public function __construct(CalDavBackend $caldavBackend, IL10N $l10n,
- IConfig $config) {
+ IConfig $config, LoggerInterface $logger) {
$this->caldavBackend = $caldavBackend;
$this->l10n = $l10n;
$this->config = $config;
+ $this->logger = $logger;
}
/**
*/
public function getChild($name) {
$calendar = $this->caldavBackend->getPublicCalendar($name);
- return new PublicCalendar($this->caldavBackend, $calendar, $this->l10n, $this->config);
+ return new PublicCalendar($this->caldavBackend, $calendar, $this->l10n, $this->config, $this->logger);
}
/**
use OCP\IConfig;
use OCP\IL10N;
use OCP\IUserManager;
+use Psr\Log\LoggerInterface;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
/** @var IUserManager */
private $userManager;
+ /** @var LoggerInterface */
+ private $logger;
+
/**
* @param CalDavBackend $calDav
* @param IConfig $config
CalDavBackend $calDav,
IConfig $config,
IL10N $l10n,
- IUserManager $userManager
+ IUserManager $userManager,
+ LoggerInterface $logger
) {
parent::__construct();
$this->calDav = $calDav;
$this->config = $config;
$this->l10n = $l10n;
$this->userManager = $userManager;
+ $this->logger = $logger;
}
protected function configure(): void {
$this->calDav,
$calendarInfo,
$this->l10n,
- $this->config);
+ $this->config,
+ $this->logger
+ );
$force = $input->getOption('force');
if ($force) {
use OCP\IL10N;
use OCP\IUserManager;
use OCP\Share\IManager as IShareManager;
+use Psr\Log\LoggerInterface;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
/** @var CalDavBackend */
private $calDav;
+ /** @var LoggerInterface */
+ private $logger;
+
public const URI_USERS = 'principals/users/';
/**
IShareManager $shareManager,
IConfig $config,
IL10N $l10n,
- CalDavBackend $calDav
+ CalDavBackend $calDav,
+ LoggerInterface $logger
) {
parent::__construct();
$this->userManager = $userManager;
$this->config = $config;
$this->l10n = $l10n;
$this->calDav = $calDav;
+ $this->logger = $logger;
}
protected function configure() {
*/
if ($this->shareManager->shareWithGroupMembersOnly() === true && 'groups' === $prefix && !$this->groupManager->isInGroup($userDestination, $userOrGroup)) {
if ($force) {
- $this->calDav->updateShares(new Calendar($this->calDav, $calendar, $this->l10n, $this->config), [], ['href' => 'principal:principals/groups/' . $userOrGroup]);
+ $this->calDav->updateShares(new Calendar($this->calDav, $calendar, $this->l10n, $this->config, $this->logger), [], ['href' => 'principal:principals/groups/' . $userOrGroup]);
} else {
throw new \InvalidArgumentException("User <$userDestination> is not part of the group <$userOrGroup> with whom the calendar <" . $calendar['uri'] . "> was shared. You may use -f to move the calendar while deleting this share.");
}
*/
if ($userOrGroup === $userDestination) {
if ($force) {
- $this->calDav->updateShares(new Calendar($this->calDav, $calendar, $this->l10n, $this->config), [], ['href' => 'principal:principals/users/' . $userOrGroup]);
+ $this->calDav->updateShares(new Calendar($this->calDav, $calendar, $this->l10n, $this->config, $this->logger), [], ['href' => 'principal:principals/users/' . $userOrGroup]);
} else {
throw new \InvalidArgumentException("The calendar <" . $calendar['uri'] . "> is already shared to user <$userDestination>.You may use -f to move the calendar while deleting this share.");
}
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\IConfig;
+use Psr\Log\LoggerInterface;
use Sabre\DAV\SimpleCollection;
class RootCollection extends SimpleCollection {
$l10n = \OC::$server->getL10N('dav');
$random = \OC::$server->getSecureRandom();
$logger = \OC::$server->getLogger();
+ $psrLogger = \OC::$server->get(LoggerInterface::class);
$userManager = \OC::$server->getUserManager();
$userSession = \OC::$server->getUserSession();
$groupManager = \OC::$server->getGroupManager();
$legacyDispatcher,
$config
);
- $userCalendarRoot = new CalendarRoot($userPrincipalBackend, $caldavBackend, 'principals/users');
+ $userCalendarRoot = new CalendarRoot($userPrincipalBackend, $caldavBackend, 'principals/users', $psrLogger);
$userCalendarRoot->disableListing = $disableListing;
- $resourceCalendarRoot = new CalendarRoot($calendarResourcePrincipalBackend, $caldavBackend, 'principals/calendar-resources');
+ $resourceCalendarRoot = new CalendarRoot($calendarResourcePrincipalBackend, $caldavBackend, 'principals/calendar-resources', $psrLogger);
$resourceCalendarRoot->disableListing = $disableListing;
- $roomCalendarRoot = new CalendarRoot($calendarRoomPrincipalBackend, $caldavBackend, 'principals/calendar-rooms');
+ $roomCalendarRoot = new CalendarRoot($calendarRoomPrincipalBackend, $caldavBackend, 'principals/calendar-rooms', $psrLogger);
$roomCalendarRoot->disableListing = $disableListing;
- $publicCalendarRoot = new PublicCalendarRoot($caldavBackend, $l10n, $config);
+ $publicCalendarRoot = new PublicCalendarRoot($caldavBackend, $l10n, $config, $psrLogger);
$publicCalendarRoot->disableListing = $disableListing;
$systemTagCollection = new SystemTag\SystemTagsByIdCollection(
return vsprintf($text, $parameters);
});
+ $logger = $this->createMock(\Psr\Log\LoggerInterface::class);
+
$config = $this->createMock(IConfig::class);
$this->userManager->expects($this->any())
$calendarId = $this->createTestCalendar();
$calendars = $this->backend->getCalendarsForUser(self::UNIT_TEST_USER);
$this->assertCount(1, $calendars);
- $calendar = new Calendar($this->backend, $calendars[0], $l10n, $config);
+ $calendar = new Calendar($this->backend, $calendars[0], $l10n, $config, $logger);
$this->legacyDispatcher->expects($this->at(0))
->method('dispatch')
->with('\OCA\DAV\CalDAV\CalDavBackend::updateShares');
$this->backend->updateShares($calendar, $add, []);
$calendars = $this->backend->getCalendarsForUser(self::UNIT_TEST_USER1);
$this->assertCount(1, $calendars);
- $calendar = new Calendar($this->backend, $calendars[0], $l10n, $config);
+ $calendar = new Calendar($this->backend, $calendars[0], $l10n, $config, $logger);
$acl = $calendar->getACL();
$this->assertAcl(self::UNIT_TEST_USER, '{DAV:}read', $acl);
$this->assertAcl(self::UNIT_TEST_USER, '{DAV:}write', $acl);
/** @var IL10N|\PHPUnit\Framework\MockObject\MockObject $l10n */
$l10n = $this->createMock(IL10N::class);
$config = $this->createMock(IConfig::class);
-
- $calendar = new Calendar($this->backend, $calendarInfo, $l10n, $config);
+ $logger = $this->createMock(\Psr\Log\LoggerInterface::class);
+ $calendar = new Calendar($this->backend, $calendarInfo, $l10n, $config, $logger);
$calendar->setPublishStatus(true);
$this->assertNotEquals(false, $calendar->getPublishStatus());
$sharerCalendars = $this->backend->getCalendarsForUser($sharer);
$this->assertCount(1, $sharerCalendars);
- $sharerCalendar = new Calendar($this->backend, $sharerCalendars[0], $l10n, $config);
+
+ $logger = $this->createMock(\Psr\Log\LoggerInterface::class);
+ $sharerCalendar = new Calendar($this->backend, $sharerCalendars[0], $l10n, $config, $logger);
$this->backend->updateShares($sharerCalendar, [
[
'href' => 'principal:' . $me,
use OCA\DAV\CalDAV\Integration\ICalendarProvider;
use OCA\DAV\CalDAV\Outbox;
use OCA\DAV\CalDAV\Trashbin\TrashbinHome;
+use PHPUnit\Framework\MockObject\MockObject;
+use Psr\Log\LoggerInterface;
use Sabre\CalDAV\Schedule\Inbox;
use Sabre\DAV\MkCol;
use Test\TestCase;
class CalendarHomeTest extends TestCase {
- /** @var CalDavBackend | \PHPUnit\Framework\MockObject\MockObject */
+ /** @var CalDavBackend | MockObject */
private $backend;
/** @var array */
/** @var CalendarHome */
private $calendarHome;
+ /** @var MockObject|LoggerInterface */
+ private $logger;
+
protected function setUp(): void {
parent::setUp();
'uri' => 'user-principal-123',
];
$this->pluginManager = $this->createMock(PluginManager::class);
+ $this->logger = $this->createMock(LoggerInterface::class);
- $this->calendarHome = new CalendarHome($this->backend,
- $this->principalInfo);
+ $this->calendarHome = new CalendarHome(
+ $this->backend,
+ $this->principalInfo,
+ $this->logger
+ );
// Replace PluginManager with our mock
$reflection = new \ReflectionClass($this->calendarHome);
}
public function testCreateCalendarValidName() {
- /** @var MkCol | \PHPUnit\Framework\MockObject\MockObject $mkCol */
+ /** @var MkCol | MockObject $mkCol */
$mkCol = $this->createMock(MkCol::class);
$mkCol->method('getResourceType')
$this->expectException(\Sabre\DAV\Exception\MethodNotAllowed::class);
$this->expectExceptionMessage('The resource you tried to create has a reserved name');
- /** @var MkCol | \PHPUnit\Framework\MockObject\MockObject $mkCol */
+ /** @var MkCol | MockObject $mkCol */
$mkCol = $this->createMock(MkCol::class);
$this->calendarHome->createExtendedCollection('contact_birthdays', $mkCol);
$this->expectException(\Sabre\DAV\Exception\MethodNotAllowed::class);
$this->expectExceptionMessage('The resource you tried to create has a reserved name');
- /** @var MkCol | \PHPUnit\Framework\MockObject\MockObject $mkCol */
+ /** @var MkCol | MockObject $mkCol */
$mkCol = $this->createMock(MkCol::class);
$this->calendarHome->createExtendedCollection('app-generated--example--foo-1', $mkCol);
use OCP\Calendar\IManager;
use OCP\IConfig;
use OCP\IL10N;
+use PHPUnit\Framework\MockObject\MockObject;
+use Psr\Log\LoggerInterface;
class CalendarManagerTest extends \Test\TestCase {
- /** @var CalDavBackend | \PHPUnit\Framework\MockObject\MockObject */
+ /** @var CalDavBackend | MockObject */
private $backend;
- /** @var IL10N | \PHPUnit\Framework\MockObject\MockObject */
+ /** @var IL10N | MockObject */
private $l10n;
- /** @var IConfig|\PHPUnit\Framework\MockObject\MockObject */
+ /** @var IConfig|MockObject */
private $config;
/** @var CalendarManager */
private $manager;
+ /** @var MockObject|LoggerInterface */
+ private $logger;
+
protected function setUp(): void {
parent::setUp();
$this->backend = $this->createMock(CalDavBackend::class);
$this->l10n = $this->createMock(IL10N::class);
$this->config = $this->createMock(IConfig::class);
- $this->manager = new CalendarManager($this->backend,
- $this->l10n, $this->config);
+ $this->logger = $this->createMock(LoggerInterface::class);
+ $this->manager = new CalendarManager(
+ $this->backend,
+ $this->l10n,
+ $this->config,
+ $this->logger
+ );
}
public function testSetupCalendarProvider() {
['id' => 456, 'uri' => 'blablub2'],
]);
- /** @var IManager | \PHPUnit\Framework\MockObject\MockObject $calendarManager */
+ /** @var IManager | MockObject $calendarManager */
$calendarManager = $this->createMock(Manager::class);
$calendarManager->expects($this->at(0))
->method('registerCalendar')
use OCA\DAV\CalDAV\Calendar;
use OCP\IConfig;
use OCP\IL10N;
+use PHPUnit\Framework\MockObject\MockObject;
+use Psr\Log\LoggerInterface;
use Sabre\DAV\PropPatch;
use Sabre\VObject\Reader;
use Test\TestCase;
/** @var IConfig */
protected $config;
+ /** @var MockObject|LoggerInterface */
+ protected $logger;
+
protected function setUp(): void {
parent::setUp();
$this->l10n = $this->getMockBuilder(IL10N::class)
->disableOriginalConstructor()->getMock();
$this->config = $this->createMock(IConfig::class);
+ $this->logger = $this->createMock(LoggerInterface::class);
$this->l10n
->expects($this->any())
->method('t')
}
public function testDelete() {
- /** @var \PHPUnit\Framework\MockObject\MockObject | CalDavBackend $backend */
+ /** @var MockObject | CalDavBackend $backend */
$backend = $this->getMockBuilder(CalDavBackend::class)->disableOriginalConstructor()->getMock();
$backend->expects($this->once())->method('updateShares');
$backend->expects($this->any())->method('getShares')->willReturn([
'id' => 666,
'uri' => 'cal',
];
- $c = new Calendar($backend, $calendarInfo, $this->l10n, $this->config);
+ $c = new Calendar($backend, $calendarInfo, $this->l10n, $this->config, $this->logger);
$c->delete();
}
public function testDeleteFromGroup() {
$this->expectException(\Sabre\DAV\Exception\Forbidden::class);
- /** @var \PHPUnit\Framework\MockObject\MockObject | CalDavBackend $backend */
+ /** @var MockObject | CalDavBackend $backend */
$backend = $this->getMockBuilder(CalDavBackend::class)->disableOriginalConstructor()->getMock();
$backend->expects($this->never())->method('updateShares');
$backend->expects($this->any())->method('getShares')->willReturn([
'id' => 666,
'uri' => 'cal',
];
- $c = new Calendar($backend, $calendarInfo, $this->l10n, $this->config);
+ $c = new Calendar($backend, $calendarInfo, $this->l10n, $this->config, $this->logger);
$c->delete();
}
public function testDeleteOwn() {
- /** @var \PHPUnit\Framework\MockObject\MockObject | CalDavBackend $backend */
+ /** @var MockObject | CalDavBackend $backend */
$backend = $this->createMock(CalDavBackend::class);
$backend->expects($this->never())->method('updateShares');
$backend->expects($this->never())->method('getShares');
'id' => 666,
'uri' => 'cal',
];
- $c = new Calendar($backend, $calendarInfo, $this->l10n, $this->config);
+ $c = new Calendar($backend, $calendarInfo, $this->l10n, $this->config, $this->logger);
$c->delete();
}
public function testDeleteBirthdayCalendar() {
- /** @var \PHPUnit\Framework\MockObject\MockObject | CalDavBackend $backend */
+ /** @var MockObject | CalDavBackend $backend */
$backend = $this->createMock(CalDavBackend::class);
$backend->expects($this->once())->method('deleteCalendar')
->with(666);
'uri' => 'contact_birthdays',
];
- $c = new Calendar($backend, $calendarInfo, $this->l10n, $this->config);
+ $c = new Calendar($backend, $calendarInfo, $this->l10n, $this->config, $this->logger);
$c->delete();
}
* @dataProvider dataPropPatch
*/
public function testPropPatch($ownerPrincipal, $principalUri, $mutations, $shared) {
- /** @var \PHPUnit\Framework\MockObject\MockObject | CalDavBackend $backend */
+ /** @var MockObject | CalDavBackend $backend */
$backend = $this->getMockBuilder(CalDavBackend::class)->disableOriginalConstructor()->getMock();
$calendarInfo = [
'{http://owncloud.org/ns}owner-principal' => $ownerPrincipal,
'id' => 666,
'uri' => 'default'
];
- $c = new Calendar($backend, $calendarInfo, $this->l10n, $this->config);
+ $c = new Calendar($backend, $calendarInfo, $this->l10n, $this->config, $this->logger);
$propPatch = new PropPatch($mutations);
if (!$shared) {
* @dataProvider providesReadOnlyInfo
*/
public function testAcl($expectsWrite, $readOnlyValue, $hasOwnerSet, $uri = 'default') {
- /** @var \PHPUnit\Framework\MockObject\MockObject | CalDavBackend $backend */
+ /** @var MockObject | CalDavBackend $backend */
$backend = $this->getMockBuilder(CalDavBackend::class)->disableOriginalConstructor()->getMock();
$backend->expects($this->any())->method('applyShareAcl')->willReturnArgument(1);
$calendarInfo = [
if ($hasOwnerSet) {
$calendarInfo['{http://owncloud.org/ns}owner-principal'] = 'user1';
}
- $c = new Calendar($backend, $calendarInfo, $this->l10n, $this->config);
+ $c = new Calendar($backend, $calendarInfo, $this->l10n, $this->config, $this->logger);
$acl = $c->getACL();
$childAcl = $c->getChildACL();
$calObject1 = ['uri' => 'event-1', 'classification' => CalDavBackend::CLASSIFICATION_CONFIDENTIAL];
$calObject2 = ['uri' => 'event-2', 'classification' => CalDavBackend::CLASSIFICATION_PRIVATE];
- /** @var \PHPUnit\Framework\MockObject\MockObject | CalDavBackend $backend */
+ /** @var MockObject | CalDavBackend $backend */
$backend = $this->getMockBuilder(CalDavBackend::class)->disableOriginalConstructor()->getMock();
$backend->expects($this->any())->method('getCalendarObjects')->willReturn([
$calObject0, $calObject1, $calObject2
if ($isShared) {
$calendarInfo['{http://owncloud.org/ns}owner-principal'] = 'user1';
}
- $c = new Calendar($backend, $calendarInfo, $this->l10n, $this->config);
+ $c = new Calendar($backend, $calendarInfo, $this->l10n, $this->config, $this->logger);
$children = $c->getChildren();
$this->assertEquals($expectedChildren, count($children));
$children = $c->getMultipleChildren(['event-0', 'event-1', 'event-2']);
$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 */
+ /** @var MockObject | CalDavBackend $backend */
$backend = $this->getMockBuilder(CalDavBackend::class)->disableOriginalConstructor()->getMock();
$backend->expects($this->any())->method('getCalendarObjects')->willReturn([
$calObject0, $calObject1, $calObject2
'id' => 666,
'uri' => 'cal',
];
- $c = new Calendar($backend, $calendarInfo, $this->l10n, $this->config);
+ $c = new Calendar($backend, $calendarInfo, $this->l10n, $this->config, $this->logger);
$this->assertEquals(count($c->getChildren()), $expectedChildren);
$l10n->expects($this->never())
->method('t');
}
- $c = new Calendar($backend, $calendarInfo, $l10n, $this->config);
+ $c = new Calendar($backend, $calendarInfo, $l10n, $this->config, $this->logger);
$calData = $c->getChild('event-1')->get();
$event = Reader::read($calData);
'classification' => CalDavBackend::CLASSIFICATION_CONFIDENTIAL,
'calendardata' => $confidentialObjectData];
- /** @var \PHPUnit\Framework\MockObject\MockObject | CalDavBackend $backend */
+ /** @var MockObject | CalDavBackend $backend */
$backend = $this->createMock(CalDavBackend::class);
$backend->expects($this->any())
->method('getCalendarObjects')
'uri' => 'cal',
];
- $ownerCalendar = new Calendar($backend, $calendarInfoOwner, $this->l10n, $this->config);
- $rwCalendar = new Calendar($backend, $calendarInfoSharedRW, $this->l10n, $this->config);
- $roCalendar = new Calendar($backend, $calendarInfoSharedRO, $this->l10n, $this->config);
+ $ownerCalendar = new Calendar($backend, $calendarInfoOwner, $this->l10n, $this->config, $this->logger);
+ $rwCalendar = new Calendar($backend, $calendarInfoSharedRW, $this->l10n, $this->config, $this->logger);
+ $roCalendar = new Calendar($backend, $calendarInfoSharedRO, $this->l10n, $this->config, $this->logger);
- $this->assertEquals(count($ownerCalendar->getChildren()), 2);
- $this->assertEquals(count($rwCalendar->getChildren()), 2);
- $this->assertEquals(count($roCalendar->getChildren()), 2);
+ $this->assertCount(2, $ownerCalendar->getChildren());
+ $this->assertCount(2, $rwCalendar->getChildren());
+ $this->assertCount(2, $roCalendar->getChildren());
// calendar data shall not be altered for the owner
$this->assertEquals($ownerCalendar->getChild('event-0')->get(), $publicObjectData);
use OCP\ILogger;
use OCP\IUserManager;
use OCP\Security\ISecureRandom;
+use Psr\Log\LoggerInterface;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Test\TestCase;
$this->groupManager = $this->createMock(IGroupManager::class);
$this->random = \OC::$server->getSecureRandom();
$this->logger = $this->createMock(ILogger::class);
+ $this->psrLogger = $this->createMock(LoggerInterface::class);
$dispatcher = $this->createMock(IEventDispatcher::class);
$legacyDispatcher = $this->createMock(EventDispatcherInterface::class);
$config = $this->createMock(IConfig::class);
$this->config = $this->createMock(IConfig::class);
$this->publicCalendarRoot = new PublicCalendarRoot($this->backend,
- $this->l10n, $this->config);
+ $this->l10n, $this->config, $this->psrLogger);
}
protected function tearDown(): void {
$this->backend->createCalendar(self::UNIT_TEST_USER, 'Example', []);
$calendarInfo = $this->backend->getCalendarsForUser(self::UNIT_TEST_USER)[0];
- $calendar = new PublicCalendar($this->backend, $calendarInfo, $this->l10n, $this->config);
+ $calendar = new PublicCalendar($this->backend, $calendarInfo, $this->l10n, $this->config, $this->psrLogger);
$publicUri = $calendar->setPublishStatus(true);
$calendarInfo = $this->backend->getPublicCalendar($publicUri);
- $calendar = new PublicCalendar($this->backend, $calendarInfo, $this->l10n, $this->config);
+ $calendar = new PublicCalendar($this->backend, $calendarInfo, $this->l10n, $this->config, $this->psrLogger);
return $calendar;
}
use OCA\DAV\CalDAV\CalDavBackend;
use OCA\DAV\CalDAV\PublicCalendar;
use OCP\IConfig;
+use PHPUnit\Framework\MockObject\MockObject;
+use Psr\Log\LoggerInterface;
use Sabre\VObject\Reader;
class PublicCalendarTest extends CalendarTest {
$calObject1 = ['uri' => 'event-1', 'classification' => CalDavBackend::CLASSIFICATION_CONFIDENTIAL];
$calObject2 = ['uri' => 'event-2', 'classification' => CalDavBackend::CLASSIFICATION_PRIVATE];
- /** @var \PHPUnit\Framework\MockObject\MockObject | CalDavBackend $backend */
+ /** @var MockObject | CalDavBackend $backend */
$backend = $this->getMockBuilder(CalDavBackend::class)->disableOriginalConstructor()->getMock();
$backend->expects($this->any())->method('getCalendarObjects')->willReturn([
$calObject0, $calObject1, $calObject2
'id' => 666,
'uri' => 'cal',
];
- /** @var \PHPUnit\Framework\MockObject\MockObject | IConfig $config */
+ /** @var MockObject | IConfig $config */
$config = $this->createMock(IConfig::class);
-
- $c = new PublicCalendar($backend, $calendarInfo, $this->l10n, $config);
+ /** @var MockObject | LoggerInterface $logger */
+ $logger = $this->createMock(LoggerInterface::class);
+ $c = new PublicCalendar($backend, $calendarInfo, $this->l10n, $config,$logger);
$children = $c->getChildren();
$this->assertEquals(2, count($children));
$children = $c->getMultipleChildren(['event-0', 'event-1', 'event-2']);
$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 */
+ /** @var MockObject | CalDavBackend $backend */
$backend = $this->getMockBuilder(CalDavBackend::class)->disableOriginalConstructor()->getMock();
$backend->expects($this->any())->method('getCalendarObjects')->willReturn([
$calObject0, $calObject1, $calObject2
'id' => 666,
'uri' => 'cal',
];
- /** @var \PHPUnit\Framework\MockObject\MockObject | IConfig $config */
+ /** @var MockObject | IConfig $config */
$config = $this->createMock(IConfig::class);
- $c = new PublicCalendar($backend, $calendarInfo, $this->l10n, $config);
+ /** @var MockObject | LoggerInterface $logger */
+ $logger = $this->createMock(LoggerInterface::class);
+ $c = new PublicCalendar($backend, $calendarInfo, $this->l10n, $config,$logger);
$this->assertEquals(count($c->getChildren()), 2);
use OCP\IL10N;
use OCP\IUserManager;
use PHPUnit\Framework\MockObject\MockObject;
+use Psr\Log\LoggerInterface;
use Symfony\Component\Console\Tester\CommandTester;
use Test\TestCase;
/** @var DeleteCalendar */
private $command;
+
+ /** @var MockObject|LoggerInterface */
+ private $logger;
protected function setUp(): void {
parent::setUp();
$this->config = $this->createMock(IConfig::class);
$this->l10n = $this->createMock(IL10N::class);
$this->userManager = $this->createMock(IUserManager::class);
+ $this->logger = $this->createMock(LoggerInterface::class);
$this->command = new DeleteCalendar(
$this->calDav,
$this->config,
$this->l10n,
$this->userManager,
+ $this->logger
);
}
use OCP\IL10N;
use OCP\IUserManager;
use OCP\Share\IManager;
+use PHPUnit\Framework\MockObject\MockObject;
+use Psr\Log\LoggerInterface;
use Symfony\Component\Console\Tester\CommandTester;
use Test\TestCase;
*/
class MoveCalendarTest extends TestCase {
- /** @var \OCP\IUserManager|\PHPUnit\Framework\MockObject\MockObject $userManager */
+ /** @var \OCP\IUserManager|MockObject $userManager */
private $userManager;
- /** @var \OCP\IGroupManager|\PHPUnit\Framework\MockObject\MockObject $groupManager */
+ /** @var \OCP\IGroupManager|MockObject $groupManager */
private $groupManager;
- /** @var \OCP\Share\IManager|\PHPUnit\Framework\MockObject\MockObject $shareManager */
+ /** @var \OCP\Share\IManager|MockObject $shareManager */
private $shareManager;
- /** @var IConfig|\PHPUnit\Framework\MockObject\MockObject $l10n */
+ /** @var IConfig|MockObject $l10n */
private $config;
- /** @var IL10N|\PHPUnit\Framework\MockObject\MockObject $l10n */
+ /** @var IL10N|MockObject $l10n */
private $l10n;
- /** @var CalDavBackend|\PHPUnit\Framework\MockObject\MockObject $l10n */
+ /** @var CalDavBackend|MockObject $l10n */
private $calDav;
/** @var MoveCalendar */
private $command;
+ /** @var LoggerInterface|MockObject */
+ private $logger;
+
protected function setUp(): void {
parent::setUp();
$this->config = $this->createMock(IConfig::class);
$this->l10n = $this->createMock(IL10N::class);
$this->calDav = $this->createMock(CalDavBackend::class);
+ $this->logger = $this->createMock(LoggerInterface::class);
$this->command = new MoveCalendar(
$this->userManager,
$this->shareManager,
$this->config,
$this->l10n,
- $this->calDav
+ $this->calDav,
+ $this->logger
);
}