diff options
Diffstat (limited to 'tests/lib/Collaboration/Collaborators/RemotePluginTest.php')
-rw-r--r-- | tests/lib/Collaboration/Collaborators/RemotePluginTest.php | 70 |
1 files changed, 33 insertions, 37 deletions
diff --git a/tests/lib/Collaboration/Collaborators/RemotePluginTest.php b/tests/lib/Collaboration/Collaborators/RemotePluginTest.php index 1345df13379..a9a5e05dfe4 100644 --- a/tests/lib/Collaboration/Collaborators/RemotePluginTest.php +++ b/tests/lib/Collaboration/Collaborators/RemotePluginTest.php @@ -1,24 +1,8 @@ <?php + /** - * @copyright Copyright (c) 2017 Arthur Schiwon <blizzz@arthur-schiwon.de> - * - * @author Arthur Schiwon <blizzz@arthur-schiwon.de> - * - * @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: 2017 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later */ namespace Test\Collaboration\Collaborators; @@ -28,8 +12,11 @@ use OC\Collaboration\Collaborators\SearchResult; use OC\Federation\CloudIdManager; use OCP\Collaboration\Collaborators\SearchResultType; use OCP\Contacts\IManager; +use OCP\EventDispatcher\IEventDispatcher; use OCP\Federation\ICloudIdManager; +use OCP\ICacheFactory; use OCP\IConfig; +use OCP\IURLGenerator; use OCP\IUser; use OCP\IUserManager; use OCP\IUserSession; @@ -37,23 +24,22 @@ use OCP\Share\IShare; use Test\TestCase; class RemotePluginTest extends TestCase { - /** @var IUserManager|\PHPUnit\Framework\MockObject\MockObject */ protected $userManager; - /** @var IConfig|\PHPUnit\Framework\MockObject\MockObject */ + /** @var IConfig|\PHPUnit\Framework\MockObject\MockObject */ protected $config; - /** @var IManager|\PHPUnit\Framework\MockObject\MockObject */ + /** @var IManager|\PHPUnit\Framework\MockObject\MockObject */ protected $contactsManager; - /** @var ICloudIdManager|\PHPUnit\Framework\MockObject\MockObject */ + /** @var ICloudIdManager|\PHPUnit\Framework\MockObject\MockObject */ protected $cloudIdManager; - /** @var RemotePlugin */ + /** @var RemotePlugin */ protected $plugin; - /** @var SearchResult */ + /** @var SearchResult */ protected $searchResult; protected function setUp(): void { @@ -62,7 +48,13 @@ class RemotePluginTest extends TestCase { $this->userManager = $this->createMock(IUserManager::class); $this->config = $this->createMock(IConfig::class); $this->contactsManager = $this->createMock(IManager::class); - $this->cloudIdManager = new CloudIdManager($this->contactsManager); + $this->cloudIdManager = new CloudIdManager( + $this->createMock(ICacheFactory::class), + $this->createMock(IEventDispatcher::class), + $this->contactsManager, + $this->createMock(IURLGenerator::class), + $this->createMock(IUserManager::class), + ); $this->searchResult = new SearchResult(); } @@ -79,7 +71,6 @@ class RemotePluginTest extends TestCase { } /** - * @dataProvider dataGetRemote * * @param string $searchTerm * @param array $contacts @@ -88,7 +79,8 @@ class RemotePluginTest extends TestCase { * @param bool $exactIdMatch * @param bool $reachedEnd */ - public function testSearch($searchTerm, array $contacts, $shareeEnumeration, array $expected, $exactIdMatch, $reachedEnd) { + #[\PHPUnit\Framework\Attributes\DataProvider('dataGetRemote')] + public function testSearch($searchTerm, array $contacts, $shareeEnumeration, array $expected, $exactIdMatch, $reachedEnd): void { $this->config->expects($this->any()) ->method('getAppValue') ->willReturnCallback( @@ -120,37 +112,36 @@ class RemotePluginTest extends TestCase { } /** - * @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($remote, $expectedUser, $expectedUrl): void { $this->instantiatePlugin(); $this->contactsManager->expects($this->any()) ->method('search') ->willReturn([]); - list($remoteUser, $remoteUrl) = $this->plugin->splitUserRemote($remote); + [$remoteUser, $remoteUrl] = $this->plugin->splitUserRemote($remote); $this->assertSame($expectedUser, $remoteUser); $this->assertSame($expectedUrl, $remoteUrl); } /** - * @dataProvider dataTestSplitUserRemoteError - * * @param string $id */ - public function testSplitUserRemoteError($id) { + #[\PHPUnit\Framework\Attributes\DataProvider('dataTestSplitUserRemoteError')] + public function testSplitUserRemoteError($id): void { $this->expectException(\Exception::class); $this->instantiatePlugin(); $this->plugin->splitUserRemote($id); } - public function dataGetRemote() { + public static function dataGetRemote() { return [ ['test', [], true, ['remotes' => [], 'exact' => ['remotes' => []]], false, true], ['test', [], false, ['remotes' => [], 'exact' => ['remotes' => []]], false, true], @@ -383,7 +374,7 @@ class RemotePluginTest extends TestCase { ]; } - public function dataTestSplitUserRemote() { + public static function dataTestSplitUserRemote(): array { $userPrefix = ['user@name', 'username']; $protocols = ['', 'http://', 'https://']; $remotes = [ @@ -404,6 +395,11 @@ class RemotePluginTest extends TestCase { foreach ($protocols as $protocol) { $baseUrl = $user . '@' . $protocol . $remote; + if ($protocol === 'https://') { + // https:// protocol is not expected in the final result + $protocol = ''; + } + $testCases[] = [$baseUrl, $user, $protocol . $remote]; $testCases[] = [$baseUrl . '/', $user, $protocol . $remote]; $testCases[] = [$baseUrl . '/index.php', $user, $protocol . $remote]; @@ -414,7 +410,7 @@ class RemotePluginTest extends TestCase { return $testCases; } - public function dataTestSplitUserRemoteError() { + public static function dataTestSplitUserRemoteError(): array { return [ // Invalid path ['user@'], |