aboutsummaryrefslogtreecommitdiffstats
path: root/apps/dav/tests/unit/Command/MoveCalendarTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'apps/dav/tests/unit/Command/MoveCalendarTest.php')
-rw-r--r--apps/dav/tests/unit/Command/MoveCalendarTest.php265
1 files changed, 96 insertions, 169 deletions
diff --git a/apps/dav/tests/unit/Command/MoveCalendarTest.php b/apps/dav/tests/unit/Command/MoveCalendarTest.php
index 228884cc39c..e9f016961f2 100644
--- a/apps/dav/tests/unit/Command/MoveCalendarTest.php
+++ b/apps/dav/tests/unit/Command/MoveCalendarTest.php
@@ -1,30 +1,11 @@
<?php
+
+declare(strict_types=1);
/**
- * @copyright Copyright (c) 2016 Thomas Citharel <nextcloud@tcit.fr>
- *
- * @author Christoph Wurst <christoph@winzerhof-wurst.at>
- * @author Georg Ehrke <oc.list@georgehrke.com>
- * @author Morris Jobke <hey@morrisjobke.de>
- * @author Roeland Jago Douma <roeland@famdouma.nl>
- * @author Thomas Citharel <nextcloud@tcit.fr>
- *
- * @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
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
+ * SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
*/
-namespace OCA\DAV\Tests\Command;
+namespace OCA\DAV\Tests\unit\Command;
use InvalidArgumentException;
use OCA\DAV\CalDAV\CalDavBackend;
@@ -45,29 +26,14 @@ use Test\TestCase;
* @package OCA\DAV\Tests\Command
*/
class MoveCalendarTest extends TestCase {
- /** @var \OCP\IUserManager|MockObject $userManager */
- private $userManager;
-
- /** @var \OCP\IGroupManager|MockObject $groupManager */
- private $groupManager;
-
- /** @var \OCP\Share\IManager|MockObject $shareManager */
- private $shareManager;
-
- /** @var IConfig|MockObject $l10n */
- private $config;
-
- /** @var IL10N|MockObject $l10n */
- private $l10n;
-
- /** @var CalDavBackend|MockObject $l10n */
- private $calDav;
-
- /** @var MoveCalendar */
- private $command;
-
- /** @var LoggerInterface|MockObject */
- private $logger;
+ private IUserManager&MockObject $userManager;
+ private IGroupManager&MockObject $groupManager;
+ private \OCP\Share\IManager&MockObject $shareManager;
+ private IConfig&MockObject $config;
+ private IL10N&MockObject $l10n;
+ private CalDavBackend&MockObject $calDav;
+ private LoggerInterface&MockObject $logger;
+ private MoveCalendar $command;
protected function setUp(): void {
parent::setUp();
@@ -91,32 +57,23 @@ class MoveCalendarTest extends TestCase {
);
}
- public function dataExecute() {
+ public static function dataExecute(): array {
return [
[false, true],
[true, false]
];
}
- /**
- * @dataProvider dataExecute
- *
- * @param $userOriginExists
- * @param $userDestinationExists
- */
- public function testWithBadUserOrigin($userOriginExists, $userDestinationExists): void {
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataExecute')]
+ public function testWithBadUserOrigin(bool $userOriginExists, bool $userDestinationExists): void {
$this->expectException(\InvalidArgumentException::class);
$this->userManager->expects($this->exactly($userOriginExists ? 2 : 1))
->method('userExists')
- ->withConsecutive(
- ['user'],
- ['user2'],
- )
- ->willReturnOnConsecutiveCalls(
- $userOriginExists,
- $userDestinationExists,
- );
+ ->willReturnMap([
+ ['user', $userOriginExists],
+ ['user2', $userDestinationExists],
+ ]);
$commandTester = new CommandTester($this->command);
$commandTester->execute([
@@ -133,11 +90,10 @@ class MoveCalendarTest extends TestCase {
$this->userManager->expects($this->exactly(2))
->method('userExists')
- ->withConsecutive(
- ['user'],
- ['user2'],
- )
- ->willReturn(true);
+ ->willReturnMap([
+ ['user', true],
+ ['user2', true],
+ ]);
$this->calDav->expects($this->once())->method('getCalendarByUri')
->with('principals/users/user', 'personal')
@@ -158,20 +114,20 @@ class MoveCalendarTest extends TestCase {
$this->userManager->expects($this->exactly(2))
->method('userExists')
- ->withConsecutive(
- ['user'],
- ['user2'],
- )
- ->willReturn(true);
+ ->willReturnMap([
+ ['user', true],
+ ['user2', true],
+ ]);
$this->calDav->expects($this->exactly(2))
->method('getCalendarByUri')
- ->withConsecutive(
- ['principals/users/user', 'personal'],
- ['principals/users/user2', 'personal'],
- )
- ->willReturn([
- 'id' => 1234,
+ ->willReturnMap([
+ ['principals/users/user', 'personal', [
+ 'id' => 1234,
+ ]],
+ ['principals/users/user2', 'personal', [
+ 'id' => 1234,
+ ]],
]);
$commandTester = new CommandTester($this->command);
@@ -185,24 +141,19 @@ class MoveCalendarTest extends TestCase {
public function testMove(): void {
$this->userManager->expects($this->exactly(2))
->method('userExists')
- ->withConsecutive(
- ['user'],
- ['user2'],
- )
- ->willReturn(true);
+ ->willReturnMap([
+ ['user', true],
+ ['user2', true],
+ ]);
$this->calDav->expects($this->exactly(2))
->method('getCalendarByUri')
- ->withConsecutive(
- ['principals/users/user', 'personal'],
- ['principals/users/user2', 'personal'],
- )
- ->willReturnOnConsecutiveCalls(
- [
+ ->willReturnMap([
+ ['principals/users/user', 'personal', [
'id' => 1234,
- ],
- null,
- );
+ ]],
+ ['principals/users/user2', 'personal', null],
+ ]);
$this->calDav->expects($this->once())->method('getShares')
->with(1234)
@@ -215,41 +166,34 @@ class MoveCalendarTest extends TestCase {
'destinationuid' => 'user2',
]);
- $this->assertStringContainsString("[OK] Calendar <personal> was moved from user <user> to <user2>", $commandTester->getDisplay());
+ $this->assertStringContainsString('[OK] Calendar <personal> was moved from user <user> to <user2>', $commandTester->getDisplay());
}
- public function dataTestMoveWithDestinationNotPartOfGroup(): array {
+ public static function dataTestMoveWithDestinationNotPartOfGroup(): array {
return [
[true],
[false]
];
}
- /**
- * @dataProvider dataTestMoveWithDestinationNotPartOfGroup
- */
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataTestMoveWithDestinationNotPartOfGroup')]
public function testMoveWithDestinationNotPartOfGroup(bool $shareWithGroupMembersOnly): void {
$this->userManager->expects($this->exactly(2))
->method('userExists')
- ->withConsecutive(
- ['user'],
- ['user2'],
- )
- ->willReturn(true);
+ ->willReturnMap([
+ ['user', true],
+ ['user2', true],
+ ]);
$this->calDav->expects($this->exactly(2))
->method('getCalendarByUri')
- ->withConsecutive(
- ['principals/users/user', 'personal'],
- ['principals/users/user2', 'personal'],
- )
- ->willReturnOnConsecutiveCalls(
- [
+ ->willReturnMap([
+ ['principals/users/user', 'personal', [
'id' => 1234,
'uri' => 'personal',
- ],
- null,
- );
+ ]],
+ ['principals/users/user2', 'personal', null],
+ ]);
$this->shareManager->expects($this->once())->method('shareWithGroupMembersOnly')
->willReturn($shareWithGroupMembersOnly);
@@ -261,7 +205,7 @@ class MoveCalendarTest extends TestCase {
]);
if ($shareWithGroupMembersOnly === true) {
$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.");
+ $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);
@@ -275,25 +219,20 @@ class MoveCalendarTest extends TestCase {
public function testMoveWithDestinationPartOfGroup(): void {
$this->userManager->expects($this->exactly(2))
->method('userExists')
- ->withConsecutive(
- ['user'],
- ['user2'],
- )
- ->willReturn(true);
+ ->willReturnMap([
+ ['user', true],
+ ['user2', true],
+ ]);
$this->calDav->expects($this->exactly(2))
->method('getCalendarByUri')
- ->withConsecutive(
- ['principals/users/user', 'personal'],
- ['principals/users/user2', 'personal'],
- )
- ->willReturnOnConsecutiveCalls(
- [
+ ->willReturnMap([
+ ['principals/users/user', 'personal', [
'id' => 1234,
'uri' => 'personal',
- ],
- null,
- );
+ ]],
+ ['principals/users/user2', 'personal', null],
+ ]);
$this->shareManager->expects($this->once())->method('shareWithGroupMembersOnly')
->willReturn(true);
@@ -315,32 +254,27 @@ class MoveCalendarTest extends TestCase {
'destinationuid' => 'user2',
]);
- $this->assertStringContainsString("[OK] Calendar <personal> was moved from user <user> to <user2>", $commandTester->getDisplay());
+ $this->assertStringContainsString('[OK] Calendar <personal> was moved from user <user> to <user2>', $commandTester->getDisplay());
}
public function testMoveWithDestinationNotPartOfGroupAndForce(): void {
$this->userManager->expects($this->exactly(2))
->method('userExists')
- ->withConsecutive(
- ['user'],
- ['user2'],
- )
- ->willReturn(true);
+ ->willReturnMap([
+ ['user', true],
+ ['user2', true],
+ ]);
$this->calDav->expects($this->exactly(2))
->method('getCalendarByUri')
- ->withConsecutive(
- ['principals/users/user', 'personal'],
- ['principals/users/user2', 'personal'],
- )
- ->willReturnOnConsecutiveCalls(
- [
+ ->willReturnMap([
+ ['principals/users/user', 'personal', [
'id' => 1234,
'uri' => 'personal',
'{DAV:}displayname' => 'Personal'
- ],
- null,
- );
+ ]],
+ ['principals/users/user2', 'personal', null],
+ ]);
$this->shareManager->expects($this->once())->method('shareWithGroupMembersOnly')
->willReturn(true);
@@ -363,55 +297,48 @@ class MoveCalendarTest extends TestCase {
'--force' => true
]);
- $this->assertStringContainsString("[OK] Calendar <personal> was moved from user <user> to <user2>", $commandTester->getDisplay());
+ $this->assertStringContainsString('[OK] Calendar <personal> was moved from user <user> to <user2>', $commandTester->getDisplay());
}
- public function dataTestMoveWithCalendarAlreadySharedToDestination(): array {
+ public static function dataTestMoveWithCalendarAlreadySharedToDestination(): array {
return [
[true],
[false]
];
}
- /**
- * @dataProvider dataTestMoveWithCalendarAlreadySharedToDestination
- */
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataTestMoveWithCalendarAlreadySharedToDestination')]
public function testMoveWithCalendarAlreadySharedToDestination(bool $force): void {
$this->userManager->expects($this->exactly(2))
->method('userExists')
- ->withConsecutive(
- ['user'],
- ['user2'],
- )
- ->willReturn(true);
+ ->willReturnMap([
+ ['user', true],
+ ['user2', true],
+ ]);
$this->calDav->expects($this->exactly(2))
->method('getCalendarByUri')
- ->withConsecutive(
- ['principals/users/user', 'personal'],
- ['principals/users/user2', 'personal'],
- )
- ->willReturnOnConsecutiveCalls(
- [
+ ->willReturnMap([
+ ['principals/users/user', 'personal', [
'id' => 1234,
'uri' => 'personal',
'{DAV:}displayname' => 'Personal'
- ],
- null,
- );
+ ]],
+ ['principals/users/user2', 'personal', null],
+ ]);
$this->calDav->expects($this->once())->method('getShares')
- ->with(1234)
- ->willReturn([
- [
- 'href' => 'principal:principals/users/user2',
- '{DAV:}displayname' => 'Personal'
- ]
- ]);
+ ->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.");
+ $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');
}