aboutsummaryrefslogtreecommitdiffstats
path: root/tests/lib/Collaboration/Collaborators/LookupPluginTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'tests/lib/Collaboration/Collaborators/LookupPluginTest.php')
-rw-r--r--tests/lib/Collaboration/Collaborators/LookupPluginTest.php176
1 files changed, 84 insertions, 92 deletions
diff --git a/tests/lib/Collaboration/Collaborators/LookupPluginTest.php b/tests/lib/Collaboration/Collaborators/LookupPluginTest.php
index 0a1febe33a5..ac9b196ea1e 100644
--- a/tests/lib/Collaboration/Collaborators/LookupPluginTest.php
+++ b/tests/lib/Collaboration/Collaborators/LookupPluginTest.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;
@@ -33,25 +17,25 @@ use OCP\Http\Client\IClient;
use OCP\Http\Client\IClientService;
use OCP\Http\Client\IResponse;
use OCP\IConfig;
-use OCP\ILogger;
use OCP\IUser;
use OCP\IUserSession;
use OCP\Share\IShare;
+use PHPUnit\Framework\MockObject\MockObject;
+use Psr\Log\LoggerInterface;
use Test\TestCase;
class LookupPluginTest extends TestCase {
-
- /** @var IConfig|\PHPUnit\Framework\MockObject\MockObject */
+ /** @var IConfig|MockObject */
protected $config;
- /** @var IClientService|\PHPUnit\Framework\MockObject\MockObject */
+ /** @var IClientService|MockObject */
protected $clientService;
- /** @var IUserSession|\PHPUnit\Framework\MockObject\MockObject */
+ /** @var IUserSession|MockObject */
protected $userSession;
- /** @var ICloudIdManager|\PHPUnit\Framework\MockObject\MockObject */
+ /** @var ICloudIdManager|MockObject */
protected $cloudIdManager;
- /** @var LookupPlugin */
+ /** @var LookupPlugin */
protected $plugin;
- /** @var ILogger|\PHPUnit\Framework\MockObject\MockObject */
+ /** @var LoggerInterface|MockObject */
protected $logger;
protected function setUp(): void {
@@ -60,7 +44,7 @@ class LookupPluginTest extends TestCase {
$this->userSession = $this->createMock(IUserSession::class);
$this->cloudIdManager = $this->createMock(ICloudIdManager::class);
$this->config = $this->createMock(IConfig::class);
- $this->logger = $this->createMock(ILogger::class);
+ $this->logger = $this->createMock(LoggerInterface::class);
$this->clientService = $this->createMock(IClientService::class);
$cloudId = $this->createMock(ICloudId::class);
$cloudId->expects($this->any())->method('getRemote')->willReturn('myNextcloud.net');
@@ -86,66 +70,61 @@ class LookupPluginTest extends TestCase {
);
}
- public function testSearchNoLookupServerURI() {
+ public function testSearchNoLookupServerURI(): void {
$this->config->expects($this->once())
->method('getAppValue')
- ->with('files_sharing', 'lookupServerEnabled', 'yes')
+ ->with('files_sharing', 'lookupServerEnabled', 'no')
->willReturn('yes');
- $this->config->expects($this->at(0))
- ->method('getSystemValue')
- ->with('gs.enabled', false)
- ->willReturn(false);
-
- $this->config->expects($this->at(2))
- ->method('getSystemValue')
- ->with('has_internet_connection', true)
- ->willReturn(true);
- $this->config->expects($this->at(3))
- ->method('getSystemValue')
+ $this->config->expects($this->exactly(2))
+ ->method('getSystemValueBool')
+ ->willReturnMap([
+ ['gs.enabled', false, true],
+ ['has_internet_connection', true, true],
+ ]);
+
+ $this->config->expects($this->once())
+ ->method('getSystemValueString')
->with('lookup_server', 'https://lookup.nextcloud.com')
->willReturn('');
$this->clientService->expects($this->never())
->method('newClient');
- /** @var ISearchResult|\PHPUnit\Framework\MockObject\MockObject $searchResult */
+ /** @var ISearchResult|MockObject $searchResult */
$searchResult = $this->createMock(ISearchResult::class);
$this->plugin->search('foobar', 10, 0, $searchResult);
}
- public function testSearchNoInternet() {
+ public function testSearchNoInternet(): void {
$this->config->expects($this->once())
->method('getAppValue')
- ->with('files_sharing', 'lookupServerEnabled', 'yes')
+ ->with('files_sharing', 'lookupServerEnabled', 'no')
->willReturn('yes');
- $this->config->expects($this->at(0))
- ->method('getSystemValue')
- ->with('gs.enabled', false)
- ->willReturn(false);
-
- $this->config->expects($this->at(2))
- ->method('getSystemValue')
- ->with('has_internet_connection', true)
- ->willReturn(false);
+ $this->config->expects($this->exactly(2))
+ ->method('getSystemValueBool')
+ ->willReturnMap([
+ ['gs.enabled', false, false],
+ ['has_internet_connection', true, false],
+ ]);
$this->clientService->expects($this->never())
->method('newClient');
- /** @var ISearchResult|\PHPUnit\Framework\MockObject\MockObject $searchResult */
+ /** @var ISearchResult|MockObject $searchResult */
$searchResult = $this->createMock(ISearchResult::class);
$this->plugin->search('foobar', 10, 0, $searchResult);
}
/**
- * @dataProvider searchDataProvider
* @param array $searchParams
*/
- public function testSearch(array $searchParams) {
+ #[\PHPUnit\Framework\Attributes\DataProvider('searchDataProvider')]
+ public function testSearch(array $searchParams): void {
$type = new SearchResultType('lookup');
- /** @var ISearchResult|\PHPUnit\Framework\MockObject\MockObject $searchResult */
+ /** @var ISearchResult|MockObject $searchResult */
$searchResult = $this->createMock(ISearchResult::class);
$searchResult->expects($this->once())
->method('addResultSet')
@@ -153,19 +132,17 @@ class LookupPluginTest extends TestCase {
$this->config->expects($this->once())
->method('getAppValue')
- ->with('files_sharing', 'lookupServerEnabled', 'yes')
+ ->with('files_sharing', 'lookupServerEnabled', 'no')
->willReturn('yes');
- $this->config->expects($this->at(0))
- ->method('getSystemValue')
- ->with('gs.enabled', false)
- ->willReturn(false);
-
- $this->config->expects($this->at(2))
- ->method('getSystemValue')
- ->with('has_internet_connection', true)
- ->willReturn(true);
- $this->config->expects($this->at(3))
- ->method('getSystemValue')
+ $this->config->expects($this->exactly(2))
+ ->method('getSystemValueBool')
+ ->willReturnMap([
+ ['gs.enabled', false, true],
+ ['has_internet_connection', true, true],
+ ]);
+
+ $this->config->expects($this->once())
+ ->method('getSystemValueString')
->with('lookup_server', 'https://lookup.nextcloud.com')
->willReturn($searchParams['server']);
@@ -199,36 +176,34 @@ class LookupPluginTest extends TestCase {
/**
- * @dataProvider dataSearchEnableDisableLookupServer
* @param array $searchParams
* @param bool $GSEnabled
* @param bool $LookupEnabled
*/
- public function testSearchEnableDisableLookupServer(array $searchParams, $GSEnabled, $LookupEnabled) {
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataSearchEnableDisableLookupServer')]
+ public function testSearchEnableDisableLookupServer(array $searchParams, $GSEnabled, $LookupEnabled): void {
$type = new SearchResultType('lookup');
- /** @var ISearchResult|\PHPUnit\Framework\MockObject\MockObject $searchResult */
+ /** @var ISearchResult|MockObject $searchResult */
$searchResult = $this->createMock(ISearchResult::class);
$this->config->expects($this->once())
->method('getAppValue')
- ->with('files_sharing', 'lookupServerEnabled', 'yes')
+ ->with('files_sharing', 'lookupServerEnabled', 'no')
->willReturn($LookupEnabled ? 'yes' : 'no');
- $this->config->expects($this->at(0))
- ->method('getSystemValue')
- ->with('gs.enabled', false)
- ->willReturn($GSEnabled);
- if ($GSEnabled || $LookupEnabled) {
+ if ($GSEnabled) {
$searchResult->expects($this->once())
->method('addResultSet')
->with($type, $searchParams['expectedResult'], []);
- $this->config->expects($this->at(2))
- ->method('getSystemValue')
- ->with('has_internet_connection', true)
- ->willReturn(true);
- $this->config->expects($this->at(3))
- ->method('getSystemValue')
+ $this->config->expects($this->exactly(2))
+ ->method('getSystemValueBool')
+ ->willReturnMap([
+ ['gs.enabled', false, $GSEnabled],
+ ['has_internet_connection', true, true],
+ ]);
+ $this->config->expects($this->once())
+ ->method('getSystemValueString')
->with('lookup_server', 'https://lookup.nextcloud.com')
->willReturn($searchParams['server']);
@@ -251,6 +226,12 @@ class LookupPluginTest extends TestCase {
->willReturn($client);
} else {
$searchResult->expects($this->never())->method('addResultSet');
+ $this->config->expects($this->exactly(2))
+ ->method('getSystemValueBool')
+ ->willReturnMap([
+ ['gs.enabled', false, $GSEnabled],
+ ['has_internet_connection', true, true],
+ ]);
}
$moreResults = $this->plugin->search(
$searchParams['search'],
@@ -263,13 +244,15 @@ class LookupPluginTest extends TestCase {
}
- public function testSearchLookupServerDisabled() {
- $this->config->expects($this->once())
- ->method('getAppValue')
- ->with('files_sharing', 'lookupServerEnabled', 'yes')
- ->willReturn('no');
+ public function testSearchGSDisabled(): void {
+ $this->config->expects($this->atLeastOnce())
+ ->method('getSystemValueBool')
+ ->willReturnMap([
+ ['has_internet_connection', true, true],
+ ['gs.enabled', false, false],
+ ]);
- /** @var ISearchResult|\PHPUnit\Framework\MockObject\MockObject $searchResult */
+ /** @var ISearchResult|MockObject $searchResult */
$searchResult = $this->createMock(ISearchResult::class);
$searchResult->expects($this->never())
->method('addResultSet');
@@ -279,7 +262,7 @@ class LookupPluginTest extends TestCase {
$this->assertFalse($this->plugin->search('irr', 10, 0, $searchResult));
}
- public function dataSearchEnableDisableLookupServer() {
+ public static function dataSearchEnableDisableLookupServer(): array {
$fedIDs = [
'foo@enceladus.moon',
'foobar@enceladus.moon',
@@ -302,6 +285,7 @@ class LookupPluginTest extends TestCase {
'label' => $fedIDs[0],
'value' => [
'shareType' => IShare::TYPE_REMOTE,
+ 'globalScale' => true,
'shareWith' => $fedIDs[0]
],
'extra' => ['federationId' => $fedIDs[0]],
@@ -310,6 +294,7 @@ class LookupPluginTest extends TestCase {
'label' => $fedIDs[1],
'value' => [
'shareType' => IShare::TYPE_REMOTE,
+ 'globalScale' => true,
'shareWith' => $fedIDs[1]
],
'extra' => ['federationId' => $fedIDs[1]],
@@ -318,6 +303,7 @@ class LookupPluginTest extends TestCase {
'label' => $fedIDs[2],
'value' => [
'shareType' => IShare::TYPE_REMOTE,
+ 'globalScale' => true,
'shareWith' => $fedIDs[2]
],
'extra' => ['federationId' => $fedIDs[2]],
@@ -341,6 +327,7 @@ class LookupPluginTest extends TestCase {
'label' => $fedIDs[0],
'value' => [
'shareType' => IShare::TYPE_REMOTE,
+ 'globalScale' => true,
'shareWith' => $fedIDs[0]
],
'extra' => ['federationId' => $fedIDs[0]],
@@ -349,6 +336,7 @@ class LookupPluginTest extends TestCase {
'label' => $fedIDs[1],
'value' => [
'shareType' => IShare::TYPE_REMOTE,
+ 'globalScale' => true,
'shareWith' => $fedIDs[1]
],
'extra' => ['federationId' => $fedIDs[1]],
@@ -357,6 +345,7 @@ class LookupPluginTest extends TestCase {
'label' => $fedIDs[2],
'value' => [
'shareType' => IShare::TYPE_REMOTE,
+ 'globalScale' => true,
'shareWith' => $fedIDs[2]
],
'extra' => ['federationId' => $fedIDs[2]],
@@ -446,7 +435,7 @@ class LookupPluginTest extends TestCase {
];
}
- public function searchDataProvider() {
+ public static function searchDataProvider(): array {
$fedIDs = [
'foo@enceladus.moon',
'foobar@enceladus.moon',
@@ -470,6 +459,7 @@ class LookupPluginTest extends TestCase {
'label' => $fedIDs[0],
'value' => [
'shareType' => IShare::TYPE_REMOTE,
+ 'globalScale' => true,
'shareWith' => $fedIDs[0]
],
'extra' => ['federationId' => $fedIDs[0]],
@@ -478,6 +468,7 @@ class LookupPluginTest extends TestCase {
'label' => $fedIDs[1],
'value' => [
'shareType' => IShare::TYPE_REMOTE,
+ 'globalScale' => true,
'shareWith' => $fedIDs[1]
],
'extra' => ['federationId' => $fedIDs[1]],
@@ -486,6 +477,7 @@ class LookupPluginTest extends TestCase {
'label' => $fedIDs[2],
'value' => [
'shareType' => IShare::TYPE_REMOTE,
+ 'globalScale' => true,
'shareWith' => $fedIDs[2]
],
'extra' => ['federationId' => $fedIDs[2]],