aboutsummaryrefslogtreecommitdiffstats
path: root/apps/federatedfilesharing/tests/AddressHandlerTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'apps/federatedfilesharing/tests/AddressHandlerTest.php')
-rw-r--r--apps/federatedfilesharing/tests/AddressHandlerTest.php138
1 files changed, 47 insertions, 91 deletions
diff --git a/apps/federatedfilesharing/tests/AddressHandlerTest.php b/apps/federatedfilesharing/tests/AddressHandlerTest.php
index 13030e73cb0..279bf485145 100644
--- a/apps/federatedfilesharing/tests/AddressHandlerTest.php
+++ b/apps/federatedfilesharing/tests/AddressHandlerTest.php
@@ -1,71 +1,50 @@
<?php
+
+declare(strict_types=1);
/**
- * @copyright Copyright (c) 2016, ownCloud, Inc.
- *
- * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
- * @author Bjoern Schiessle <bjoern@schiessle.org>
- * @author Björn Schießle <bjoern@schiessle.org>
- * @author Christoph Wurst <christoph@winzerhof-wurst.at>
- * @author Morris Jobke <hey@morrisjobke.de>
- * @author Robin Appelman <robin@icewind.nl>
- * @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: 2016-2024 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
+ * SPDX-License-Identifier: AGPL-3.0-only
*/
namespace OCA\FederatedFileSharing\Tests;
use OC\Federation\CloudIdManager;
use OCA\FederatedFileSharing\AddressHandler;
use OCP\Contacts\IManager;
+use OCP\EventDispatcher\IEventDispatcher;
+use OCP\HintException;
+use OCP\ICacheFactory;
use OCP\IL10N;
use OCP\IURLGenerator;
use OCP\IUserManager;
+use PHPUnit\Framework\MockObject\MockObject;
class AddressHandlerTest extends \Test\TestCase {
- /** @var IManager|\PHPUnit\Framework\MockObject\MockObject */
- protected $contactsManager;
-
- /** @var AddressHandler */
- private $addressHandler;
-
- /** @var IURLGenerator | \PHPUnit\Framework\MockObject\MockObject */
- private $urlGenerator;
-
- /** @var IL10N | \PHPUnit\Framework\MockObject\MockObject */
- private $il10n;
-
- /** @var CloudIdManager */
- private $cloudIdManager;
+ protected IManager&MockObject $contactsManager;
+ private IURLGenerator&MockObject $urlGenerator;
+ private IL10N&MockObject $il10n;
+ private CloudIdManager $cloudIdManager;
+ private AddressHandler $addressHandler;
protected function setUp(): void {
parent::setUp();
- $this->urlGenerator = $this->getMockBuilder(IURLGenerator::class)
- ->getMock();
- $this->il10n = $this->getMockBuilder(IL10N::class)
- ->getMock();
-
+ $this->urlGenerator = $this->createMock(IURLGenerator::class);
+ $this->il10n = $this->createMock(IL10N::class);
$this->contactsManager = $this->createMock(IManager::class);
- $this->cloudIdManager = new CloudIdManager($this->contactsManager, $this->urlGenerator, $this->createMock(IUserManager::class));
+ $this->cloudIdManager = new CloudIdManager(
+ $this->createMock(ICacheFactory::class),
+ $this->createMock(IEventDispatcher::class),
+ $this->contactsManager,
+ $this->urlGenerator,
+ $this->createMock(IUserManager::class),
+ );
$this->addressHandler = new AddressHandler($this->urlGenerator, $this->il10n, $this->cloudIdManager);
}
- public function dataTestSplitUserRemote() {
+ public static function dataTestSplitUserRemote(): array {
$userPrefix = ['user@name', 'username'];
$protocols = ['', 'http://', 'https://'];
$remotes = [
@@ -86,6 +65,11 @@ class AddressHandlerTest extends \Test\TestCase {
foreach ($protocols as $protocol) {
$baseUrl = $user . '@' . $protocol . $remote;
+ if ($protocol === '') {
+ // https:// protocol is expected in the final result
+ $protocol = 'https://';
+ }
+
$testCases[] = [$baseUrl, $user, $protocol . $remote];
$testCases[] = [$baseUrl . '/', $user, $protocol . $remote];
$testCases[] = [$baseUrl . '/index.php', $user, $protocol . $remote];
@@ -96,14 +80,8 @@ class AddressHandlerTest extends \Test\TestCase {
return $testCases;
}
- /**
- * @dataProvider dataTestSplitUserRemote
- *
- * @param string $remote
- * @param string $expectedUser
- * @param string $expectedUrl
- */
- public function testSplitUserRemote($remote, $expectedUser, $expectedUrl) {
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataTestSplitUserRemote')]
+ public function testSplitUserRemote(string $remote, string $expectedUser, string $expectedUrl): void {
$this->contactsManager->expects($this->any())
->method('search')
->willReturn([]);
@@ -113,7 +91,7 @@ class AddressHandlerTest extends \Test\TestCase {
$this->assertSame($expectedUrl, $remoteUrl);
}
- public function dataTestSplitUserRemoteError() {
+ public static function dataTestSplitUserRemoteError(): array {
return [
// Invalid path
['user@'],
@@ -131,33 +109,21 @@ class AddressHandlerTest extends \Test\TestCase {
];
}
- /**
- * @dataProvider dataTestSplitUserRemoteError
- *
- * @param string $id
- */
- public function testSplitUserRemoteError($id) {
- $this->expectException(\OCP\HintException::class);
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataTestSplitUserRemoteError')]
+ public function testSplitUserRemoteError(string $id): void {
+ $this->expectException(HintException::class);
$this->addressHandler->splitUserRemote($id);
}
- /**
- * @dataProvider dataTestCompareAddresses
- *
- * @param string $user1
- * @param string $server1
- * @param string $user2
- * @param string $server2
- * @param bool $expected
- */
- public function testCompareAddresses($user1, $server1, $user2, $server2, $expected) {
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataTestCompareAddresses')]
+ public function testCompareAddresses(string $user1, string $server1, string $user2, string $server2, bool $expected): void {
$this->assertSame($expected,
$this->addressHandler->compareAddresses($user1, $server1, $user2, $server2)
);
}
- public function dataTestCompareAddresses() {
+ public static function dataTestCompareAddresses(): array {
return [
['user1', 'http://server1', 'user1', 'http://server1', true],
['user1', 'https://server1', 'user1', 'http://server1', true],
@@ -177,37 +143,27 @@ class AddressHandlerTest extends \Test\TestCase {
];
}
- /**
- * @dataProvider dataTestRemoveProtocolFromUrl
- *
- * @param string $url
- * @param string $expectedResult
- */
- public function testRemoveProtocolFromUrl($url, $expectedResult) {
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataTestRemoveProtocolFromUrl')]
+ public function testRemoveProtocolFromUrl(string $url, string $expectedResult): void {
$result = $this->addressHandler->removeProtocolFromUrl($url);
$this->assertSame($expectedResult, $result);
}
- public function dataTestRemoveProtocolFromUrl() {
+ public static function dataTestRemoveProtocolFromUrl(): array {
return [
- ['http://owncloud.org', 'owncloud.org'],
- ['https://owncloud.org', 'owncloud.org'],
- ['owncloud.org', 'owncloud.org'],
+ ['http://example.tld', 'example.tld'],
+ ['https://example.tld', 'example.tld'],
+ ['example.tld', 'example.tld'],
];
}
- /**
- * @dataProvider dataTestUrlContainProtocol
- *
- * @param string $url
- * @param bool $expectedResult
- */
- public function testUrlContainProtocol($url, $expectedResult) {
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataTestUrlContainProtocol')]
+ public function testUrlContainProtocol(string $url, bool $expectedResult): void {
$result = $this->addressHandler->urlContainProtocol($url);
$this->assertSame($expectedResult, $result);
}
- public function dataTestUrlContainProtocol() {
+ public static function dataTestUrlContainProtocol(): array {
return [
['http://nextcloud.com', true],
['https://nextcloud.com', true],