aboutsummaryrefslogtreecommitdiffstats
path: root/apps/dav/tests
diff options
context:
space:
mode:
authorThomas Citharel <tcit@tcit.fr>2022-05-12 09:58:33 +0200
committerThomas Citharel <tcit@tcit.fr>2022-05-12 15:28:36 +0200
commit8d7154318fb063d0e79bb344749e4be9ce26ef0b (patch)
tree96b0a685a7eecd2fc001c0900689177a070865ef /apps/dav/tests
parent33ffaad14bd15c8f6ed370b28bc83feec4f69980 (diff)
downloadnextcloud-server-8d7154318fb063d0e79bb344749e4be9ce26ef0b.tar.gz
nextcloud-server-8d7154318fb063d0e79bb344749e4be9ce26ef0b.zip
Put calendar invites into the user's first available calendar
If there's no default calendar and we can't find anything with URI 'personal', instead of creating a new one, start by using the first "real personal calendar" available. If not, then we create the default one. Signed-off-by: Thomas Citharel <tcit@tcit.fr>
Diffstat (limited to 'apps/dav/tests')
-rw-r--r--apps/dav/tests/unit/CalDAV/Schedule/PluginTest.php60
1 files changed, 52 insertions, 8 deletions
diff --git a/apps/dav/tests/unit/CalDAV/Schedule/PluginTest.php b/apps/dav/tests/unit/CalDAV/Schedule/PluginTest.php
index 2518cc3d91a..93a98aa059f 100644
--- a/apps/dav/tests/unit/CalDAV/Schedule/PluginTest.php
+++ b/apps/dav/tests/unit/CalDAV/Schedule/PluginTest.php
@@ -27,11 +27,15 @@
namespace OCA\DAV\Tests\unit\CalDAV\Schedule;
use OCA\DAV\CalDAV\CalDavBackend;
+use OCA\DAV\CalDAV\Calendar;
use OCA\DAV\CalDAV\CalendarHome;
use OCA\DAV\CalDAV\Plugin as CalDAVPlugin;
use OCA\DAV\CalDAV\Schedule\Plugin;
+use OCA\DAV\CalDAV\Trashbin\Plugin as TrashbinPlugin;
use OCP\IConfig;
+use OCP\IL10N;
use PHPUnit\Framework\MockObject\MockObject;
+use Psr\Log\LoggerInterface;
use Sabre\DAV\PropFind;
use Sabre\DAV\Server;
use Sabre\DAV\Tree;
@@ -183,6 +187,15 @@ class PluginTest extends TestCase {
false,
CalDavBackend::PERSONAL_CALENDAR_URI,
CalDavBackend::PERSONAL_CALENDAR_NAME,
+ false,
+ true
+ ],
+ [
+ 'principals/users/myuser',
+ 'calendars/myuser',
+ false,
+ CalDavBackend::PERSONAL_CALENDAR_URI,
+ CalDavBackend::PERSONAL_CALENDAR_NAME,
false
],
[
@@ -201,6 +214,7 @@ class PluginTest extends TestCase {
CalDavBackend::PERSONAL_CALENDAR_NAME,
true,
false,
+ false,
],
[
'principals/users/myuser',
@@ -240,14 +254,14 @@ class PluginTest extends TestCase {
/**
* @dataProvider propFindDefaultCalendarUrlProvider
* @param string $principalUri
- * @param string $calendarHome
+ * @param string|null $calendarHome
* @param bool $isResource
* @param string $calendarUri
* @param string $displayName
* @param bool $exists
* @param bool $propertiesForPath
*/
- public function testPropFindDefaultCalendarUrl(string $principalUri, ?string $calendarHome, bool $isResource, string $calendarUri, string $displayName, bool $exists, bool $propertiesForPath = true) {
+ public function testPropFindDefaultCalendarUrl(string $principalUri, ?string $calendarHome, bool $isResource, string $calendarUri, string $displayName, bool $exists, bool $hasExistingCalendars = false, bool $propertiesForPath = true) {
/** @var PropFind $propFind */
$propFind = new PropFind(
$principalUri,
@@ -290,6 +304,7 @@ class PluginTest extends TestCase {
$this->assertNull($propFind->get(Plugin::SCHEDULE_DEFAULT_CALENDAR_URL));
return;
}
+
if (!$isResource) {
$this->config->expects($this->once())
->method('getUserValue')
@@ -303,18 +318,47 @@ class PluginTest extends TestCase {
->with($calendarUri)
->willReturn($exists);
+ $calendarBackend = $this->createMock(CalDavBackend::class);
+ $calendarUri = $hasExistingCalendars ? 'custom' : $calendarUri;
+ $displayName = $hasExistingCalendars ? 'Custom Calendar' : $displayName;
+
+ $existingCalendars = $hasExistingCalendars ? [
+ new Calendar(
+ $calendarBackend,
+ ['uri' => 'deleted', '{DAV:}displayname' => 'A deleted calendar', TrashbinPlugin::PROPERTY_DELETED_AT => 42],
+ $this->createMock(IL10N::class),
+ $this->config,
+ $this->createMock(LoggerInterface::class)
+ ),
+ new Calendar(
+ $calendarBackend,
+ ['uri' => $calendarUri, '{DAV:}displayname' => $displayName],
+ $this->createMock(IL10N::class),
+ $this->config,
+ $this->createMock(LoggerInterface::class)
+ )
+ ] : [];
+
if (!$exists) {
- $calendarBackend = $this->createMock(CalDavBackend::class);
- $calendarBackend->expects($this->once())
+ if (!$hasExistingCalendars) {
+ $calendarBackend->expects($this->once())
->method('createCalendar')
->with($principalUri, $calendarUri, [
'{DAV:}displayname' => $displayName,
]);
- $calendarHomeObject->expects($this->once())
- ->method('getCalDAVBackend')
- ->with()
- ->willReturn($calendarBackend);
+ $calendarHomeObject->expects($this->once())
+ ->method('getCalDAVBackend')
+ ->with()
+ ->willReturn($calendarBackend);
+ }
+
+ if (!$isResource) {
+ $calendarHomeObject->expects($this->once())
+ ->method('getChildren')
+ ->with()
+ ->willReturn($existingCalendars);
+ }
}
/** @var Tree|MockObject $tree */