aboutsummaryrefslogtreecommitdiffstats
path: root/apps/dav/tests/unit/Command
diff options
context:
space:
mode:
Diffstat (limited to 'apps/dav/tests/unit/Command')
-rw-r--r--apps/dav/tests/unit/Command/DeleteCalendarTest.php71
-rw-r--r--apps/dav/tests/unit/Command/ListAddressbooksTest.php107
-rw-r--r--apps/dav/tests/unit/Command/ListCalendarSharesTest.php172
-rw-r--r--apps/dav/tests/unit/Command/ListCalendarsTest.php58
-rw-r--r--apps/dav/tests/unit/Command/MoveCalendarTest.php332
-rw-r--r--apps/dav/tests/unit/Command/RemoveInvalidSharesTest.php45
6 files changed, 461 insertions, 324 deletions
diff --git a/apps/dav/tests/unit/Command/DeleteCalendarTest.php b/apps/dav/tests/unit/Command/DeleteCalendarTest.php
index db0ee31f6be..2bd269de6dc 100644
--- a/apps/dav/tests/unit/Command/DeleteCalendarTest.php
+++ b/apps/dav/tests/unit/Command/DeleteCalendarTest.php
@@ -2,30 +2,14 @@
declare(strict_types=1);
/**
- *
- * @copyright Copyright (c) 2021, Mattia Narducci (mattianarducci1@gmail.com)
- *
- * @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 <https://www.gnu.org/licenses/>.
- *
+ * SPDX-FileCopyrightText: 2023 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 OCA\DAV\CalDAV\BirthdayService;
-use OCA\DAV\CalDav\CalDavBackend;
+use OCA\DAV\CalDAV\CalDavBackend;
use OCA\DAV\Command\DeleteCalendar;
use OCP\IConfig;
use OCP\IL10N;
@@ -44,23 +28,12 @@ class DeleteCalendarTest extends TestCase {
public const USER = 'user';
public const NAME = 'calendar';
- /** @var CalDavBackend|MockObject */
- private $calDav;
-
- /** @var IConfig|MockObject */
- private $config;
-
- /** @var IL10N|MockObject */
- private $l10n;
-
- /** @var IUserManager|MockObject */
- private $userManager;
-
- /** @var DeleteCalendar */
- private $command;
-
- /** @var MockObject|LoggerInterface */
- private $logger;
+ private CalDavBackend&MockObject $calDav;
+ private IConfig&MockObject $config;
+ private IL10N&MockObject $l10n;
+ private IUserManager&MockObject $userManager;
+ private LoggerInterface&MockObject $logger;
+ private DeleteCalendar $command;
protected function setUp(): void {
parent::setUp();
@@ -80,7 +53,7 @@ class DeleteCalendarTest extends TestCase {
);
}
- public function testInvalidUser() {
+ public function testInvalidUser(): void {
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage(
'User <' . self::USER . '> is unknown.');
@@ -97,7 +70,7 @@ class DeleteCalendarTest extends TestCase {
]);
}
- public function testNoCalendarName() {
+ public function testNoCalendarName(): void {
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage(
'Please specify a calendar name or --birthday');
@@ -113,10 +86,10 @@ class DeleteCalendarTest extends TestCase {
]);
}
- public function testInvalidCalendar() {
+ public function testInvalidCalendar(): void {
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage(
- 'User <' . self::USER . '> has no calendar named <' . self::NAME . '>.');
+ 'User <' . self::USER . '> has no calendar named <' . self::NAME . '>.');
$this->userManager->expects($this->once())
->method('userExists')
@@ -137,12 +110,12 @@ class DeleteCalendarTest extends TestCase {
]);
}
- public function testDelete() {
+ public function testDelete(): void {
$id = 1234;
$calendar = [
'id' => $id,
'principaluri' => 'principals/users/' . self::USER,
- 'uri' => self::NAME
+ 'uri' => self::NAME,
];
$this->userManager->expects($this->once())
@@ -167,7 +140,7 @@ class DeleteCalendarTest extends TestCase {
]);
}
- public function testForceDelete() {
+ public function testForceDelete(): void {
$id = 1234;
$calendar = [
'id' => $id,
@@ -198,12 +171,13 @@ class DeleteCalendarTest extends TestCase {
]);
}
- public function testDeleteBirthday() {
+ public function testDeleteBirthday(): void {
$id = 1234;
$calendar = [
'id' => $id,
'principaluri' => 'principals/users/' . self::USER,
- 'uri' => BirthdayService::BIRTHDAY_CALENDAR_URI
+ 'uri' => BirthdayService::BIRTHDAY_CALENDAR_URI,
+ '{DAV:}displayname' => 'Test',
];
$this->userManager->expects($this->once())
@@ -228,11 +202,12 @@ class DeleteCalendarTest extends TestCase {
]);
}
- public function testBirthdayHasPrecedence() {
+ public function testBirthdayHasPrecedence(): void {
$calendar = [
'id' => 1234,
'principaluri' => 'principals/users/' . self::USER,
- 'uri' => BirthdayService::BIRTHDAY_CALENDAR_URI
+ 'uri' => BirthdayService::BIRTHDAY_CALENDAR_URI,
+ '{DAV:}displayname' => 'Test',
];
$this->userManager->expects($this->once())
->method('userExists')
diff --git a/apps/dav/tests/unit/Command/ListAddressbooksTest.php b/apps/dav/tests/unit/Command/ListAddressbooksTest.php
new file mode 100644
index 00000000000..2768ed576c3
--- /dev/null
+++ b/apps/dav/tests/unit/Command/ListAddressbooksTest.php
@@ -0,0 +1,107 @@
+<?php
+
+declare(strict_types=1);
+/**
+ * SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+namespace OCA\DAV\Tests\unit\Command;
+
+use OCA\DAV\CardDAV\CardDavBackend;
+use OCA\DAV\Command\ListAddressbooks;
+use OCP\IUserManager;
+use PHPUnit\Framework\MockObject\MockObject;
+use Symfony\Component\Console\Tester\CommandTester;
+use Test\TestCase;
+
+/**
+ * Class ListCalendarsTest
+ *
+ * @package OCA\DAV\Tests\Command
+ */
+class ListAddressbooksTest extends TestCase {
+ private IUserManager&MockObject $userManager;
+ private CardDavBackend&MockObject $cardDavBackend;
+ private ListAddressbooks $command;
+
+ public const USERNAME = 'username';
+
+ protected function setUp(): void {
+ parent::setUp();
+
+ $this->userManager = $this->createMock(IUserManager::class);
+ $this->cardDavBackend = $this->createMock(CardDavBackend::class);
+
+ $this->command = new ListAddressbooks(
+ $this->userManager,
+ $this->cardDavBackend
+ );
+ }
+
+ public function testWithBadUser(): void {
+ $this->expectException(\InvalidArgumentException::class);
+
+ $this->userManager->expects($this->once())
+ ->method('userExists')
+ ->with(self::USERNAME)
+ ->willReturn(false);
+
+ $commandTester = new CommandTester($this->command);
+ $commandTester->execute([
+ 'uid' => self::USERNAME,
+ ]);
+ $this->assertStringContainsString('User <' . self::USERNAME . '> in unknown', $commandTester->getDisplay());
+ }
+
+ public function testWithCorrectUserWithNoCalendars(): void {
+ $this->userManager->expects($this->once())
+ ->method('userExists')
+ ->with(self::USERNAME)
+ ->willReturn(true);
+
+ $this->cardDavBackend->expects($this->once())
+ ->method('getAddressBooksForUser')
+ ->with('principals/users/' . self::USERNAME)
+ ->willReturn([]);
+
+ $commandTester = new CommandTester($this->command);
+ $commandTester->execute([
+ 'uid' => self::USERNAME,
+ ]);
+ $this->assertStringContainsString('User <' . self::USERNAME . "> has no addressbooks\n", $commandTester->getDisplay());
+ }
+
+ public static function dataExecute(): array {
+ return [
+ [false, '✓'],
+ [true, 'x']
+ ];
+ }
+
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataExecute')]
+ public function testWithCorrectUser(bool $readOnly, string $output): void {
+ $this->userManager->expects($this->once())
+ ->method('userExists')
+ ->with(self::USERNAME)
+ ->willReturn(true);
+
+ $this->cardDavBackend->expects($this->once())
+ ->method('getAddressBooksForUser')
+ ->with('principals/users/' . self::USERNAME)
+ ->willReturn([
+ [
+ '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}read-only' => $readOnly,
+ 'uri' => 'test',
+ '{DAV:}displayname' => 'dp',
+ '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}owner-principal' => 'owner-principal',
+ '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_NEXTCLOUD . '}owner-displayname' => 'owner-dp',
+ ]
+ ]);
+
+ $commandTester = new CommandTester($this->command);
+ $commandTester->execute([
+ 'uid' => self::USERNAME,
+ ]);
+ $this->assertStringContainsString($output, $commandTester->getDisplay());
+ }
+}
diff --git a/apps/dav/tests/unit/Command/ListCalendarSharesTest.php b/apps/dav/tests/unit/Command/ListCalendarSharesTest.php
new file mode 100644
index 00000000000..e5d4251cbf9
--- /dev/null
+++ b/apps/dav/tests/unit/Command/ListCalendarSharesTest.php
@@ -0,0 +1,172 @@
+<?php
+
+declare(strict_types=1);
+/**
+ * SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+
+namespace OCA\DAV\Tests\unit\Command;
+
+use OCA\DAV\CalDAV\CalDavBackend;
+use OCA\DAV\Command\ListCalendarShares;
+use OCA\DAV\Connector\Sabre\Principal;
+use OCA\DAV\DAV\Sharing\SharingMapper;
+use OCP\IUserManager;
+use PHPUnit\Framework\MockObject\MockObject;
+use Symfony\Component\Console\Tester\CommandTester;
+use Test\TestCase;
+
+class ListCalendarSharesTest extends TestCase {
+
+ private IUserManager&MockObject $userManager;
+ private Principal&MockObject $principal;
+ private CalDavBackend&MockObject $caldav;
+ private SharingMapper $sharingMapper;
+ private ListCalendarShares $command;
+
+ protected function setUp(): void {
+ parent::setUp();
+
+ $this->userManager = $this->createMock(IUserManager::class);
+ $this->principal = $this->createMock(Principal::class);
+ $this->caldav = $this->createMock(CalDavBackend::class);
+ $this->sharingMapper = $this->createMock(SharingMapper::class);
+
+ $this->command = new ListCalendarShares(
+ $this->userManager,
+ $this->principal,
+ $this->caldav,
+ $this->sharingMapper,
+ );
+ }
+
+ public function testUserUnknown(): void {
+ $user = 'bob';
+
+ $this->expectException(\InvalidArgumentException::class);
+ $this->expectExceptionMessage("User $user is unknown");
+
+ $this->userManager->expects($this->once())
+ ->method('userExists')
+ ->with($user)
+ ->willReturn(false);
+
+ $commandTester = new CommandTester($this->command);
+ $commandTester->execute([
+ 'uid' => $user,
+ ]);
+ }
+
+ public function testPrincipalNotFound(): void {
+ $user = 'bob';
+
+ $this->expectException(\InvalidArgumentException::class);
+ $this->expectExceptionMessage("Unable to fetch principal for user $user");
+
+ $this->userManager->expects($this->once())
+ ->method('userExists')
+ ->with($user)
+ ->willReturn(true);
+
+ $this->principal->expects($this->once())
+ ->method('getPrincipalByPath')
+ ->with('principals/users/' . $user)
+ ->willReturn(null);
+
+ $commandTester = new CommandTester($this->command);
+ $commandTester->execute([
+ 'uid' => $user,
+ ]);
+ }
+
+ public function testNoCalendarShares(): void {
+ $user = 'bob';
+
+ $this->userManager->expects($this->once())
+ ->method('userExists')
+ ->with($user)
+ ->willReturn(true);
+
+ $this->principal->expects($this->once())
+ ->method('getPrincipalByPath')
+ ->with('principals/users/' . $user)
+ ->willReturn([
+ 'uri' => 'principals/users/' . $user,
+ ]);
+
+ $this->principal->expects($this->once())
+ ->method('getGroupMembership')
+ ->willReturn([]);
+ $this->principal->expects($this->once())
+ ->method('getCircleMembership')
+ ->willReturn([]);
+
+ $this->sharingMapper->expects($this->once())
+ ->method('getSharesByPrincipals')
+ ->willReturn([]);
+
+ $commandTester = new CommandTester($this->command);
+ $commandTester->execute([
+ 'uid' => $user,
+ ]);
+
+ $this->assertStringContainsString(
+ "User $user has no calendar shares",
+ $commandTester->getDisplay()
+ );
+ }
+
+ public function testFilterByCalendarId(): void {
+ $user = 'bob';
+
+ $this->userManager->expects($this->once())
+ ->method('userExists')
+ ->with($user)
+ ->willReturn(true);
+
+ $this->principal->expects($this->once())
+ ->method('getPrincipalByPath')
+ ->with('principals/users/' . $user)
+ ->willReturn([
+ 'uri' => 'principals/users/' . $user,
+ ]);
+
+ $this->principal->expects($this->once())
+ ->method('getGroupMembership')
+ ->willReturn([]);
+ $this->principal->expects($this->once())
+ ->method('getCircleMembership')
+ ->willReturn([]);
+
+ $this->sharingMapper->expects($this->once())
+ ->method('getSharesByPrincipals')
+ ->willReturn([
+ [
+ 'id' => 1000,
+ 'principaluri' => 'principals/users/bob',
+ 'type' => 'calendar',
+ 'access' => 2,
+ 'resourceid' => 10
+ ],
+ [
+ 'id' => 1001,
+ 'principaluri' => 'principals/users/bob',
+ 'type' => 'calendar',
+ 'access' => 3,
+ 'resourceid' => 11
+ ],
+ ]);
+
+ $commandTester = new CommandTester($this->command);
+ $commandTester->execute([
+ 'uid' => $user,
+ '--calendar-id' => 10,
+ ]);
+
+ $this->assertStringNotContainsString(
+ '1001',
+ $commandTester->getDisplay()
+ );
+ }
+}
diff --git a/apps/dav/tests/unit/Command/ListCalendarsTest.php b/apps/dav/tests/unit/Command/ListCalendarsTest.php
index 6f200da01bf..d398a7c772f 100644
--- a/apps/dav/tests/unit/Command/ListCalendarsTest.php
+++ b/apps/dav/tests/unit/Command/ListCalendarsTest.php
@@ -1,35 +1,17 @@
<?php
+
+declare(strict_types=1);
/**
- * @copyright Copyright (c) 2016 Georg Ehrke <oc.list@georgehrke.com>
- *
- * @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 OCA\DAV\CalDAV\BirthdayService;
use OCA\DAV\CalDAV\CalDavBackend;
use OCA\DAV\Command\ListCalendars;
use OCP\IUserManager;
+use PHPUnit\Framework\MockObject\MockObject;
use Symfony\Component\Console\Tester\CommandTester;
use Test\TestCase;
@@ -39,15 +21,9 @@ use Test\TestCase;
* @package OCA\DAV\Tests\Command
*/
class ListCalendarsTest extends TestCase {
-
- /** @var \OCP\IUserManager|\PHPUnit\Framework\MockObject\MockObject $userManager */
- private $userManager;
-
- /** @var CalDavBackend|\PHPUnit\Framework\MockObject\MockObject $l10n */
- private $calDav;
-
- /** @var ListCalendars */
- private $command;
+ private IUserManager&MockObject $userManager;
+ private CalDavBackend&MockObject $calDav;
+ private ListCalendars $command;
public const USERNAME = 'username';
@@ -63,7 +39,7 @@ class ListCalendarsTest extends TestCase {
);
}
- public function testWithBadUser() {
+ public function testWithBadUser(): void {
$this->expectException(\InvalidArgumentException::class);
$this->userManager->expects($this->once())
@@ -75,10 +51,10 @@ class ListCalendarsTest extends TestCase {
$commandTester->execute([
'uid' => self::USERNAME,
]);
- $this->assertStringContainsString("User <" . self::USERNAME . "> in unknown", $commandTester->getDisplay());
+ $this->assertStringContainsString('User <' . self::USERNAME . '> in unknown', $commandTester->getDisplay());
}
- public function testWithCorrectUserWithNoCalendars() {
+ public function testWithCorrectUserWithNoCalendars(): void {
$this->userManager->expects($this->once())
->method('userExists')
->with(self::USERNAME)
@@ -93,20 +69,18 @@ class ListCalendarsTest extends TestCase {
$commandTester->execute([
'uid' => self::USERNAME,
]);
- $this->assertStringContainsString("User <" . self::USERNAME . "> has no calendars\n", $commandTester->getDisplay());
+ $this->assertStringContainsString('User <' . self::USERNAME . "> has no calendars\n", $commandTester->getDisplay());
}
- public function dataExecute() {
+ public static function dataExecute(): array {
return [
[false, '✓'],
[true, 'x']
];
}
- /**
- * @dataProvider dataExecute
- */
- public function testWithCorrectUser(bool $readOnly, string $output) {
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataExecute')]
+ public function testWithCorrectUser(bool $readOnly, string $output): void {
$this->userManager->expects($this->once())
->method('userExists')
->with(self::USERNAME)
diff --git a/apps/dav/tests/unit/Command/MoveCalendarTest.php b/apps/dav/tests/unit/Command/MoveCalendarTest.php
index 5a858e140ac..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,30 +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();
@@ -92,33 +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) {
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataExecute')]
+ public function testWithBadUserOrigin(bool $userOriginExists, bool $userDestinationExists): void {
$this->expectException(\InvalidArgumentException::class);
- $this->userManager->expects($this->at(0))
+ $this->userManager->expects($this->exactly($userOriginExists ? 2 : 1))
->method('userExists')
- ->with('user')
- ->willReturn($userOriginExists);
-
- if (!$userDestinationExists) {
- $this->userManager->expects($this->at(1))
- ->method('userExists')
- ->with('user2')
- ->willReturn($userDestinationExists);
- }
+ ->willReturnMap([
+ ['user', $userOriginExists],
+ ['user2', $userDestinationExists],
+ ]);
$commandTester = new CommandTester($this->command);
$commandTester->execute([
@@ -129,19 +84,16 @@ class MoveCalendarTest extends TestCase {
}
- public function testMoveWithInexistantCalendar() {
+ public function testMoveWithInexistantCalendar(): void {
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage('User <user> has no calendar named <personal>. You can run occ dav:list-calendars to list calendars URIs for this user.');
- $this->userManager->expects($this->at(0))
+ $this->userManager->expects($this->exactly(2))
->method('userExists')
- ->with('user')
- ->willReturn(true);
-
- $this->userManager->expects($this->at(1))
- ->method('userExists')
- ->with('user2')
- ->willReturn(true);
+ ->willReturnMap([
+ ['user', true],
+ ['user2', true],
+ ]);
$this->calDav->expects($this->once())->method('getCalendarByUri')
->with('principals/users/user', 'personal')
@@ -156,30 +108,26 @@ class MoveCalendarTest extends TestCase {
}
- public function testMoveWithExistingDestinationCalendar() {
+ public function testMoveWithExistingDestinationCalendar(): void {
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage('User <user2> already has a calendar named <personal>.');
- $this->userManager->expects($this->at(0))
- ->method('userExists')
- ->with('user')
- ->willReturn(true);
-
- $this->userManager->expects($this->at(1))
+ $this->userManager->expects($this->exactly(2))
->method('userExists')
- ->with('user2')
- ->willReturn(true);
-
- $this->calDav->expects($this->at(0))->method('getCalendarByUri')
- ->with('principals/users/user', 'personal')
- ->willReturn([
- 'id' => 1234,
+ ->willReturnMap([
+ ['user', true],
+ ['user2', true],
]);
- $this->calDav->expects($this->at(1))->method('getCalendarByUri')
- ->with('principals/users/user2', 'personal')
- ->willReturn([
- 'id' => 1234,
+ $this->calDav->expects($this->exactly(2))
+ ->method('getCalendarByUri')
+ ->willReturnMap([
+ ['principals/users/user', 'personal', [
+ 'id' => 1234,
+ ]],
+ ['principals/users/user2', 'personal', [
+ 'id' => 1234,
+ ]],
]);
$commandTester = new CommandTester($this->command);
@@ -190,26 +138,22 @@ class MoveCalendarTest extends TestCase {
]);
}
- public function testMove() {
- $this->userManager->expects($this->at(0))
+ public function testMove(): void {
+ $this->userManager->expects($this->exactly(2))
->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,
+ ->willReturnMap([
+ ['user', true],
+ ['user2', true],
]);
- $this->calDav->expects($this->at(1))->method('getCalendarByUri')
- ->with('principals/users/user2', 'personal')
- ->willReturn(null);
+ $this->calDav->expects($this->exactly(2))
+ ->method('getCalendarByUri')
+ ->willReturnMap([
+ ['principals/users/user', 'personal', [
+ 'id' => 1234,
+ ]],
+ ['principals/users/user2', 'personal', null],
+ ]);
$this->calDav->expects($this->once())->method('getShares')
->with(1234)
@@ -222,40 +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
- */
- public function testMoveWithDestinationNotPartOfGroup(bool $shareWithGroupMembersOnly) {
- $this->userManager->expects($this->at(0))
- ->method('userExists')
- ->with('user')
- ->willReturn(true);
-
- $this->userManager->expects($this->at(1))
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataTestMoveWithDestinationNotPartOfGroup')]
+ public function testMoveWithDestinationNotPartOfGroup(bool $shareWithGroupMembersOnly): void {
+ $this->userManager->expects($this->exactly(2))
->method('userExists')
- ->with('user2')
- ->willReturn(true);
-
- $this->calDav->expects($this->at(0))->method('getCalendarByUri')
- ->with('principals/users/user', 'personal')
- ->willReturn([
- 'id' => 1234,
- 'uri' => 'personal'
+ ->willReturnMap([
+ ['user', true],
+ ['user2', true],
]);
- $this->calDav->expects($this->at(1))->method('getCalendarByUri')
- ->with('principals/users/user2', 'personal')
- ->willReturn(null);
+ $this->calDav->expects($this->exactly(2))
+ ->method('getCalendarByUri')
+ ->willReturnMap([
+ ['principals/users/user', 'personal', [
+ 'id' => 1234,
+ 'uri' => 'personal',
+ ]],
+ ['principals/users/user2', 'personal', null],
+ ]);
$this->shareManager->expects($this->once())->method('shareWithGroupMembersOnly')
->willReturn($shareWithGroupMembersOnly);
@@ -267,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);
@@ -278,27 +216,23 @@ class MoveCalendarTest extends TestCase {
]);
}
- public function testMoveWithDestinationPartOfGroup() {
- $this->userManager->expects($this->at(0))
+ public function testMoveWithDestinationPartOfGroup(): void {
+ $this->userManager->expects($this->exactly(2))
->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'
+ ->willReturnMap([
+ ['user', true],
+ ['user2', true],
]);
- $this->calDav->expects($this->at(1))->method('getCalendarByUri')
- ->with('principals/users/user2', 'personal')
- ->willReturn(null);
+ $this->calDav->expects($this->exactly(2))
+ ->method('getCalendarByUri')
+ ->willReturnMap([
+ ['principals/users/user', 'personal', [
+ 'id' => 1234,
+ 'uri' => 'personal',
+ ]],
+ ['principals/users/user2', 'personal', null],
+ ]);
$this->shareManager->expects($this->once())->method('shareWithGroupMembersOnly')
->willReturn(true);
@@ -320,31 +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() {
- $this->userManager->expects($this->at(0))
- ->method('userExists')
- ->with('user')
- ->willReturn(true);
-
- $this->userManager->expects($this->at(1))
+ public function testMoveWithDestinationNotPartOfGroupAndForce(): void {
+ $this->userManager->expects($this->exactly(2))
->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'
+ ->willReturnMap([
+ ['user', true],
+ ['user2', true],
]);
- $this->calDav->expects($this->at(1))->method('getCalendarByUri')
- ->with('principals/users/user2', 'personal')
- ->willReturn(null);
+ $this->calDav->expects($this->exactly(2))
+ ->method('getCalendarByUri')
+ ->willReturnMap([
+ ['principals/users/user', 'personal', [
+ 'id' => 1234,
+ 'uri' => 'personal',
+ '{DAV:}displayname' => 'Personal'
+ ]],
+ ['principals/users/user2', 'personal', null],
+ ]);
$this->shareManager->expects($this->once())->method('shareWithGroupMembersOnly')
->willReturn(true);
@@ -367,54 +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
- */
- public function testMoveWithCalendarAlreadySharedToDestination(bool $force) {
- $this->userManager->expects($this->at(0))
- ->method('userExists')
- ->with('user')
- ->willReturn(true);
-
- $this->userManager->expects($this->at(1))
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataTestMoveWithCalendarAlreadySharedToDestination')]
+ public function testMoveWithCalendarAlreadySharedToDestination(bool $force): void {
+ $this->userManager->expects($this->exactly(2))
->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',
+ ->willReturnMap([
+ ['user', true],
+ ['user2', true],
]);
- $this->calDav->expects($this->at(1))->method('getCalendarByUri')
- ->with('principals/users/user2', 'personal')
- ->willReturn(null);
+ $this->calDav->expects($this->exactly(2))
+ ->method('getCalendarByUri')
+ ->willReturnMap([
+ ['principals/users/user', 'personal', [
+ 'id' => 1234,
+ 'uri' => 'personal',
+ '{DAV:}displayname' => 'Personal'
+ ]],
+ ['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');
}
diff --git a/apps/dav/tests/unit/Command/RemoveInvalidSharesTest.php b/apps/dav/tests/unit/Command/RemoveInvalidSharesTest.php
index 66ac40eff83..ec56aa64eb2 100644
--- a/apps/dav/tests/unit/Command/RemoveInvalidSharesTest.php
+++ b/apps/dav/tests/unit/Command/RemoveInvalidSharesTest.php
@@ -1,30 +1,17 @@
<?php
+
+declare(strict_types=1);
/**
- * @copyright Copyright (c) 2018, ownCloud GmbH
- *
- * @author Morris Jobke <hey@morrisjobke.de>
- * @author Roeland Jago Douma <roeland@famdouma.nl>
- *
- * @license AGPL-3.0
- *
- * This code is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License, version 3,
- * as published by the Free Software Foundation.
- *
- * 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, version 3,
- * along with this program. If not, see <http://www.gnu.org/licenses/>
- *
+ * SPDX-FileCopyrightText: 2018-2024 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-FileCopyrightText: 2018 ownCloud GmbH
+ * SPDX-License-Identifier: AGPL-3.0-only
*/
-namespace OCA\DAV\Tests\Unit\Command;
+namespace OCA\DAV\Tests\unit\Command;
use OCA\DAV\Command\RemoveInvalidShares;
use OCA\DAV\Connector\Sabre\Principal;
-use OCP\Migration\IOutput;
+use OCP\IDBConnection;
+use OCP\Server;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Test\TestCase;
@@ -38,7 +25,7 @@ use Test\TestCase;
class RemoveInvalidSharesTest extends TestCase {
protected function setUp(): void {
parent::setUp();
- $db = \OC::$server->getDatabaseConnection();
+ $db = Server::get(IDBConnection::class);
$db->insertIfNotExist('*PREFIX*dav_shares', [
'principaluri' => 'principal:unknown',
@@ -48,20 +35,18 @@ class RemoveInvalidSharesTest extends TestCase {
]);
}
- public function test() {
- $db = \OC::$server->getDatabaseConnection();
- /** @var Principal | \PHPUnit\Framework\MockObject\MockObject $principal */
+ public function test(): void {
+ $db = Server::get(IDBConnection::class);
$principal = $this->createMock(Principal::class);
- /** @var IOutput | \PHPUnit\Framework\MockObject\MockObject $output */
- $output = $this->createMock(IOutput::class);
-
$repair = new RemoveInvalidShares($db, $principal);
$this->invokePrivate($repair, 'run', [$this->createMock(InputInterface::class), $this->createMock(OutputInterface::class)]);
$query = $db->getQueryBuilder();
- $result = $query->select('*')->from('dav_shares')
- ->where($query->expr()->eq('principaluri', $query->createNamedParameter('principal:unknown')))->execute();
+ $query->select('*')
+ ->from('dav_shares')
+ ->where($query->expr()->eq('principaluri', $query->createNamedParameter('principal:unknown')));
+ $result = $query->executeQuery();
$data = $result->fetchAll();
$result->closeCursor();
$this->assertEquals(0, count($data));