diff options
Diffstat (limited to 'tests/lib/Collaboration/Collaborators/LookupPluginTest.php')
-rw-r--r-- | tests/lib/Collaboration/Collaborators/LookupPluginTest.php | 130 |
1 files changed, 49 insertions, 81 deletions
diff --git a/tests/lib/Collaboration/Collaborators/LookupPluginTest.php b/tests/lib/Collaboration/Collaborators/LookupPluginTest.php index 3eb28a861a5..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; @@ -41,15 +25,15 @@ use Psr\Log\LoggerInterface; use Test\TestCase; class LookupPluginTest extends TestCase { - /** @var IConfig|MockObject */ + /** @var IConfig|MockObject */ protected $config; - /** @var IClientService|MockObject */ + /** @var IClientService|MockObject */ protected $clientService; /** @var IUserSession|MockObject */ protected $userSession; /** @var ICloudIdManager|MockObject */ protected $cloudIdManager; - /** @var LookupPlugin */ + /** @var LookupPlugin */ protected $plugin; /** @var LoggerInterface|MockObject */ protected $logger; @@ -86,20 +70,17 @@ 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->exactly(2)) ->method('getSystemValueBool') - ->withConsecutive( - ['gs.enabled', false], - ['has_internet_connection', true], - )->willReturnOnConsecutiveCalls( - false, - true, - ); + ->willReturnMap([ + ['gs.enabled', false, true], + ['has_internet_connection', true, true], + ]); $this->config->expects($this->once()) ->method('getSystemValueString') @@ -115,20 +96,17 @@ class LookupPluginTest extends TestCase { $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->exactly(2)) ->method('getSystemValueBool') - ->withConsecutive( - ['gs.enabled', false], - ['has_internet_connection', true], - )->willReturnOnConsecutiveCalls( - false, - false, - ); + ->willReturnMap([ + ['gs.enabled', false, false], + ['has_internet_connection', true, false], + ]); $this->clientService->expects($this->never()) ->method('newClient'); @@ -140,10 +118,10 @@ class LookupPluginTest extends TestCase { } /** - * @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|MockObject $searchResult */ @@ -154,17 +132,14 @@ 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->exactly(2)) ->method('getSystemValueBool') - ->withConsecutive( - ['gs.enabled', false], - ['has_internet_connection', true], - )->willReturnOnConsecutiveCalls( - false, - true, - ); + ->willReturnMap([ + ['gs.enabled', false, true], + ['has_internet_connection', true, true], + ]); $this->config->expects($this->once()) ->method('getSystemValueString') @@ -201,12 +176,12 @@ 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|MockObject $searchResult */ @@ -214,22 +189,19 @@ class LookupPluginTest extends TestCase { $this->config->expects($this->once()) ->method('getAppValue') - ->with('files_sharing', 'lookupServerEnabled', 'yes') + ->with('files_sharing', 'lookupServerEnabled', 'no') ->willReturn($LookupEnabled ? 'yes' : 'no'); - if ($GSEnabled || $LookupEnabled) { + if ($GSEnabled) { $searchResult->expects($this->once()) ->method('addResultSet') ->with($type, $searchParams['expectedResult'], []); $this->config->expects($this->exactly(2)) ->method('getSystemValueBool') - ->withConsecutive( - ['gs.enabled', false], - ['has_internet_connection', true], - )->willReturnOnConsecutiveCalls( - $GSEnabled, - true, - ); + ->willReturnMap([ + ['gs.enabled', false, $GSEnabled], + ['has_internet_connection', true, true], + ]); $this->config->expects($this->once()) ->method('getSystemValueString') ->with('lookup_server', 'https://lookup.nextcloud.com') @@ -256,13 +228,10 @@ class LookupPluginTest extends TestCase { $searchResult->expects($this->never())->method('addResultSet'); $this->config->expects($this->exactly(2)) ->method('getSystemValueBool') - ->withConsecutive( - ['gs.enabled', false], - ['has_internet_connection', true], - )->willReturnOnConsecutiveCalls( - $GSEnabled, - true, - ); + ->willReturnMap([ + ['gs.enabled', false, $GSEnabled], + ['has_internet_connection', true, true], + ]); } $moreResults = $this->plugin->search( $searchParams['search'], @@ -275,11 +244,13 @@ 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|MockObject $searchResult */ $searchResult = $this->createMock(ISearchResult::class); @@ -291,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', @@ -398,7 +369,6 @@ class LookupPluginTest extends TestCase { 'label' => $fedIDs[0], 'value' => [ 'shareType' => IShare::TYPE_REMOTE, - 'globalScale' => false, 'shareWith' => $fedIDs[0] ], 'extra' => ['federationId' => $fedIDs[0]], @@ -407,7 +377,6 @@ class LookupPluginTest extends TestCase { 'label' => $fedIDs[1], 'value' => [ 'shareType' => IShare::TYPE_REMOTE, - 'globalScale' => false, 'shareWith' => $fedIDs[1] ], 'extra' => ['federationId' => $fedIDs[1]], @@ -416,7 +385,6 @@ class LookupPluginTest extends TestCase { 'label' => $fedIDs[2], 'value' => [ 'shareType' => IShare::TYPE_REMOTE, - 'globalScale' => false, 'shareWith' => $fedIDs[2] ], 'extra' => ['federationId' => $fedIDs[2]], @@ -467,7 +435,7 @@ class LookupPluginTest extends TestCase { ]; } - public function searchDataProvider() { + public static function searchDataProvider(): array { $fedIDs = [ 'foo@enceladus.moon', 'foobar@enceladus.moon', @@ -491,7 +459,7 @@ class LookupPluginTest extends TestCase { 'label' => $fedIDs[0], 'value' => [ 'shareType' => IShare::TYPE_REMOTE, - 'globalScale' => false, + 'globalScale' => true, 'shareWith' => $fedIDs[0] ], 'extra' => ['federationId' => $fedIDs[0]], @@ -500,7 +468,7 @@ class LookupPluginTest extends TestCase { 'label' => $fedIDs[1], 'value' => [ 'shareType' => IShare::TYPE_REMOTE, - 'globalScale' => false, + 'globalScale' => true, 'shareWith' => $fedIDs[1] ], 'extra' => ['federationId' => $fedIDs[1]], @@ -509,7 +477,7 @@ class LookupPluginTest extends TestCase { 'label' => $fedIDs[2], 'value' => [ 'shareType' => IShare::TYPE_REMOTE, - 'globalScale' => false, + 'globalScale' => true, 'shareWith' => $fedIDs[2] ], 'extra' => ['federationId' => $fedIDs[2]], |