summaryrefslogtreecommitdiffstats
path: root/apps/dav/tests
diff options
context:
space:
mode:
authorThomas Citharel <tcit@tcit.fr>2019-01-15 13:59:54 +0100
committerThomas Citharel <tcit@tcit.fr>2019-01-16 13:58:34 +0100
commit3180ddd2023c54c984f6999ade489de3d9b4fb72 (patch)
tree01710ed4b54e5e53a26f3071a0c1e8358cad5761 /apps/dav/tests
parent4864b1865bb7592132443ff8dc0a640ca7ea2cd9 (diff)
downloadnextcloud-server-3180ddd2023c54c984f6999ade489de3d9b4fb72.tar.gz
nextcloud-server-3180ddd2023c54c984f6999ade489de3d9b4fb72.zip
Handle moving calendar to an user who already has the share
Extra: * Fix @ChristophWurst style remarks * Add a Note that share links have changed when calendars has user shares (see #13603) Signed-off-by: Thomas Citharel <tcit@tcit.fr> Fix forgotten test change Signed-off-by: Thomas Citharel <tcit@tcit.fr>
Diffstat (limited to 'apps/dav/tests')
-rw-r--r--apps/dav/tests/unit/Command/ListCalendarsTest.php10
-rw-r--r--apps/dav/tests/unit/Command/MoveCalendarTest.php114
2 files changed, 92 insertions, 32 deletions
diff --git a/apps/dav/tests/unit/Command/ListCalendarsTest.php b/apps/dav/tests/unit/Command/ListCalendarsTest.php
index 8d19c724917..1a0ca8c7954 100644
--- a/apps/dav/tests/unit/Command/ListCalendarsTest.php
+++ b/apps/dav/tests/unit/Command/ListCalendarsTest.php
@@ -36,10 +36,10 @@ use Test\TestCase;
*/
class ListCalendarsTest extends TestCase {
- /** @var \OCP\IUserManager|\PHPUnit_Framework_MockObject_MockObject $userManager */
+ /** @var \OCP\IUserManager|\PHPUnit\Framework\MockObject\MockObject $userManager */
private $userManager;
- /** @var CalDavBackend|\PHPUnit_Framework_MockObject_MockObject $l10n */
+ /** @var CalDavBackend|\PHPUnit\Framework\MockObject\MockObject $l10n */
private $calDav;
/** @var ListCalendars */
@@ -71,7 +71,7 @@ class ListCalendarsTest extends TestCase {
$commandTester = new CommandTester($this->command);
$commandTester->execute([
- 'user' => self::USERNAME,
+ 'uid' => self::USERNAME,
]);
$this->assertContains("User <" . self::USERNAME . "> in unknown", $commandTester->getDisplay());
}
@@ -90,7 +90,7 @@ class ListCalendarsTest extends TestCase {
$commandTester = new CommandTester($this->command);
$commandTester->execute([
- 'user' => self::USERNAME,
+ 'uid' => self::USERNAME,
]);
$this->assertContains("User <" . self::USERNAME . "> has no calendars\n", $commandTester->getDisplay());
}
@@ -131,7 +131,7 @@ class ListCalendarsTest extends TestCase {
$commandTester = new CommandTester($this->command);
$commandTester->execute([
- 'user' => self::USERNAME,
+ 'uid' => self::USERNAME,
]);
$this->assertContains($output, $commandTester->getDisplay());
$this->assertNotContains(BirthdayService::BIRTHDAY_CALENDAR_URI, $commandTester->getDisplay());
diff --git a/apps/dav/tests/unit/Command/MoveCalendarTest.php b/apps/dav/tests/unit/Command/MoveCalendarTest.php
index f7e7840322a..07d789dbfb2 100644
--- a/apps/dav/tests/unit/Command/MoveCalendarTest.php
+++ b/apps/dav/tests/unit/Command/MoveCalendarTest.php
@@ -39,10 +39,10 @@ use Test\TestCase;
*/
class MoveCalendarTest extends TestCase {
- /** @var \OCP\IUserManager|\PHPUnit_Framework_MockObject_MockObject $userManager */
+ /** @var \OCP\IUserManager|\PHPUnit\Framework\MockObject\MockObject $userManager */
private $userManager;
- /** @var \OCP\IGroupManager|\PHPUnit_Framework_MockObject_MockObject $groupManager */
+ /** @var \OCP\IGroupManager|\PHPUnit\Framework\MockObject\MockObject $groupManager */
private $groupManager;
/** @var \OCP\Share\IManager|\PHPUnit_Framework_MockObject_MockObject $shareManager */
@@ -111,8 +111,8 @@ class MoveCalendarTest extends TestCase {
$commandTester = new CommandTester($this->command);
$commandTester->execute([
'name' => $this->command->getName(),
- 'userorigin' => 'user',
- 'userdestination' => 'user2',
+ 'sourceuid' => 'user',
+ 'destinationuid' => 'user2',
]);
}
@@ -139,8 +139,8 @@ class MoveCalendarTest extends TestCase {
$commandTester = new CommandTester($this->command);
$commandTester->execute([
'name' => 'personal',
- 'userorigin' => 'user',
- 'userdestination' => 'user2',
+ 'sourceuid' => 'user',
+ 'destinationuid' => 'user2',
]);
}
@@ -175,8 +175,8 @@ class MoveCalendarTest extends TestCase {
$commandTester = new CommandTester($this->command);
$commandTester->execute([
'name' => 'personal',
- 'userorigin' => 'user',
- 'userdestination' => 'user2',
+ 'sourceuid' => 'user',
+ 'destinationuid' => 'user2',
]);
}
@@ -206,14 +206,11 @@ class MoveCalendarTest extends TestCase {
->with(1234)
->willReturn([]);
- $this->shareManager->expects($this->once())->method('shareWithGroupMembersOnly')
- ->willReturn(true);
-
$commandTester = new CommandTester($this->command);
$commandTester->execute([
'name' => 'personal',
- 'userorigin' => 'user',
- 'userdestination' => 'user2',
+ 'sourceuid' => 'user',
+ 'destinationuid' => 'user2',
]);
$this->assertContains("[OK] Calendar <personal> was moved from user <user> to <user2>", $commandTester->getDisplay());
@@ -256,13 +253,12 @@ class MoveCalendarTest extends TestCase {
$this->shareManager->expects($this->once())->method('shareWithGroupMembersOnly')
->willReturn($shareWithGroupMembersOnly);
+ $this->calDav->expects($this->once())->method('getShares')
+ ->with(1234)
+ ->willReturn([
+ ['href' => 'principal:principals/groups/nextclouders']
+ ]);
if ($shareWithGroupMembersOnly === true) {
- $this->calDav->expects($this->once())->method('getShares')
- ->with(1234)
- ->willReturn([
- ['href' => 'principal:principals/groups/nextclouders']
- ]);
-
$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage("User <user2> is not part of the group <nextclouders> with whom the calendar <personal> was shared. You may use -f to move the calendar while deleting this share.");
}
@@ -270,8 +266,8 @@ class MoveCalendarTest extends TestCase {
$commandTester = new CommandTester($this->command);
$commandTester->execute([
'name' => 'personal',
- 'userorigin' => 'user',
- 'userdestination' => 'user2',
+ 'sourceuid' => 'user',
+ 'destinationuid' => 'user2',
]);
}
@@ -314,8 +310,8 @@ class MoveCalendarTest extends TestCase {
$commandTester = new CommandTester($this->command);
$commandTester->execute([
'name' => 'personal',
- 'userorigin' => 'user',
- 'userdestination' => 'user2',
+ 'sourceuid' => 'user',
+ 'destinationuid' => 'user2',
]);
$this->assertContains("[OK] Calendar <personal> was moved from user <user> to <user2>", $commandTester->getDisplay());
@@ -338,7 +334,7 @@ class MoveCalendarTest extends TestCase {
->willReturn([
'id' => 1234,
'uri' => 'personal',
- '{DAV:}displayname' => 'personal'
+ '{DAV:}displayname' => 'Personal'
]);
$this->calDav->expects($this->at(1))->method('getCalendarByUri')
@@ -351,17 +347,81 @@ class MoveCalendarTest extends TestCase {
$this->calDav->expects($this->once())->method('getShares')
->with(1234)
->willReturn([
- ['href' => 'principal:principals/groups/nextclouders']
+ [
+ 'href' => 'principal:principals/groups/nextclouders',
+ '{DAV:}displayname' => 'Personal'
+ ]
]);
+ $this->calDav->expects($this->once())->method('updateShares');
$commandTester = new CommandTester($this->command);
$commandTester->execute([
'name' => 'personal',
- 'userorigin' => 'user',
- 'userdestination' => 'user2',
+ 'sourceuid' => 'user',
+ 'destinationuid' => 'user2',
'--force' => true
]);
$this->assertContains("[OK] Calendar <personal> was moved from user <user> to <user2>", $commandTester->getDisplay());
}
+
+ public function dataTestMoveWithCalendarAlreadySharedToDestination(): array
+ {
+ return [
+ [true],
+ [false]
+ ];
+ }
+
+ /**
+ * @dataProvider dataTestMoveWithCalendarAlreadySharedToDestination
+ */
+ public function testMoveWithCalendarAlreadySharedToDestination(bool $force)
+ {
+ $this->userManager->expects($this->at(0))
+ ->method('userExists')
+ ->with('user')
+ ->willReturn(true);
+
+ $this->userManager->expects($this->at(1))
+ ->method('userExists')
+ ->with('user2')
+ ->willReturn(true);
+
+ $this->calDav->expects($this->at(0))->method('getCalendarByUri')
+ ->with('principals/users/user', 'personal')
+ ->willReturn([
+ 'id' => 1234,
+ 'uri' => 'personal',
+ '{DAV:}displayname' => 'Personal',
+ ]);
+
+ $this->calDav->expects($this->at(1))->method('getCalendarByUri')
+ ->with('principals/users/user2', 'personal')
+ ->willReturn(null);
+
+ $this->calDav->expects($this->once())->method('getShares')
+ ->with(1234)
+ ->willReturn([
+ [
+ 'href' => 'principal:principals/users/user2',
+ '{DAV:}displayname' => 'Personal'
+ ]
+ ]);
+
+ if ($force === false) {
+ $this->expectException(InvalidArgumentException::class);
+ $this->expectExceptionMessage("The calendar <personal> is already shared to user <user2>.You may use -f to move the calendar while deleting this share.");
+ } else {
+ $this->calDav->expects($this->once())->method('updateShares');
+ }
+
+ $commandTester = new CommandTester($this->command);
+ $commandTester->execute([
+ 'name' => 'personal',
+ 'sourceuid' => 'user',
+ 'destinationuid' => 'user2',
+ '--force' => $force,
+ ]);
+ }
}