summaryrefslogtreecommitdiffstats
path: root/apps/dav/tests/unit/Command
diff options
context:
space:
mode:
authorThomas Citharel <tcit@tcit.fr>2019-01-03 18:31:10 +0100
committerThomas Citharel <tcit@tcit.fr>2019-01-16 13:58:34 +0100
commit4864b1865bb7592132443ff8dc0a640ca7ea2cd9 (patch)
treeefaf7688db1b3bd9eb6de805038f7113f34e0c5d /apps/dav/tests/unit/Command
parent4a2238c75be9b0ed4be17869878c04cb812d276f (diff)
downloadnextcloud-server-4864b1865bb7592132443ff8dc0a640ca7ea2cd9.tar.gz
nextcloud-server-4864b1865bb7592132443ff8dc0a640ca7ea2cd9.zip
Don't check group shares if shareWithGroupMembersOnly is false
Signed-off-by: Thomas Citharel <tcit@tcit.fr> Remove the system user check Signed-off-by: Thomas Citharel <tcit@tcit.fr>
Diffstat (limited to 'apps/dav/tests/unit/Command')
-rw-r--r--apps/dav/tests/unit/Command/MoveCalendarTest.php58
1 files changed, 37 insertions, 21 deletions
diff --git a/apps/dav/tests/unit/Command/MoveCalendarTest.php b/apps/dav/tests/unit/Command/MoveCalendarTest.php
index 5e5c1f150ee..f7e7840322a 100644
--- a/apps/dav/tests/unit/Command/MoveCalendarTest.php
+++ b/apps/dav/tests/unit/Command/MoveCalendarTest.php
@@ -27,6 +27,7 @@ use OCP\IConfig;
use OCP\IGroupManager;
use OCP\IL10N;
use OCP\IUserManager;
+use OCP\Share\IManager;
use Symfony\Component\Console\Tester\CommandTester;
use Test\TestCase;
@@ -44,6 +45,9 @@ class MoveCalendarTest extends TestCase {
/** @var \OCP\IGroupManager|\PHPUnit_Framework_MockObject_MockObject $groupManager */
private $groupManager;
+ /** @var \OCP\Share\IManager|\PHPUnit_Framework_MockObject_MockObject $shareManager */
+ private $shareManager;
+
/** @var IConfig|\PHPUnit_Framework_MockObject_MockObject $l10n */
private $config;
@@ -61,6 +65,7 @@ class MoveCalendarTest extends TestCase {
$this->userManager = $this->createMock(IUserManager::class);
$this->groupManager = $this->createMock(IGroupManager::class);
+ $this->shareManager = $this->createMock(IManager::class);
$this->config = $this->createMock(IConfig::class);
$this->l10n = $this->createMock(IL10N::class);
$this->calDav = $this->createMock(CalDavBackend::class);
@@ -68,6 +73,7 @@ class MoveCalendarTest extends TestCase {
$this->command = new MoveCalendar(
$this->userManager,
$this->groupManager,
+ $this->shareManager,
$this->config,
$this->l10n,
$this->calDav
@@ -112,20 +118,6 @@ class MoveCalendarTest extends TestCase {
/**
* @expectedException InvalidArgumentException
- * @expectedExceptionMessage User can't be system
- */
- public function testTryToMoveToOrFromSystem()
- {
- $commandTester = new CommandTester($this->command);
- $commandTester->execute([
- 'name' => $this->command->getName(),
- 'userorigin' => 'system',
- 'userdestination' => 'user2',
- ]);
- }
-
- /**
- * @expectedException InvalidArgumentException
* @expectedExceptionMessage User <user> has no calendar named <personal>. You can run occ dav:list-calendars to list calendars URIs for this user.
*/
public function testMoveWithInexistantCalendar()
@@ -214,6 +206,9 @@ 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',
@@ -224,11 +219,18 @@ class MoveCalendarTest extends TestCase {
$this->assertContains("[OK] Calendar <personal> was moved from user <user> to <user2>", $commandTester->getDisplay());
}
+ public function dataTestMoveWithDestinationNotPartOfGroup(): array
+ {
+ return [
+ [true],
+ [false]
+ ];
+ }
+
/**
- * @expectedException InvalidArgumentException
- * @expectedExceptionMessage 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.
+ * @dataProvider dataTestMoveWithDestinationNotPartOfGroup
*/
- public function testMoveWithDestinationNotPartOfGroup()
+ public function testMoveWithDestinationNotPartOfGroup(bool $shareWithGroupMembersOnly)
{
$this->userManager->expects($this->at(0))
->method('userExists')
@@ -251,12 +253,20 @@ class MoveCalendarTest extends TestCase {
->with('principals/users/user2', 'personal')
->willReturn(null);
- $this->calDav->expects($this->once())->method('getShares')
- ->with(1234)
- ->willReturn([
- ['href' => 'principal:principals/groups/nextclouders']
+ $this->shareManager->expects($this->once())->method('shareWithGroupMembersOnly')
+ ->willReturn($shareWithGroupMembersOnly);
+
+ 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.");
+ }
+
$commandTester = new CommandTester($this->command);
$commandTester->execute([
'name' => 'personal',
@@ -288,6 +298,9 @@ class MoveCalendarTest extends TestCase {
->with('principals/users/user2', 'personal')
->willReturn(null);
+ $this->shareManager->expects($this->once())->method('shareWithGroupMembersOnly')
+ ->willReturn(true);
+
$this->calDav->expects($this->once())->method('getShares')
->with(1234)
->willReturn([
@@ -332,6 +345,9 @@ class MoveCalendarTest extends TestCase {
->with('principals/users/user2', 'personal')
->willReturn(null);
+ $this->shareManager->expects($this->once())->method('shareWithGroupMembersOnly')
+ ->willReturn(true);
+
$this->calDav->expects($this->once())->method('getShares')
->with(1234)
->willReturn([