diff options
Diffstat (limited to 'tests/lib/Collaboration/Collaborators/LookupPluginTest.php')
-rw-r--r-- | tests/lib/Collaboration/Collaborators/LookupPluginTest.php | 95 |
1 files changed, 40 insertions, 55 deletions
diff --git a/tests/lib/Collaboration/Collaborators/LookupPluginTest.php b/tests/lib/Collaboration/Collaborators/LookupPluginTest.php index b54ca3ee4c3..ac9b196ea1e 100644 --- a/tests/lib/Collaboration/Collaborators/LookupPluginTest.php +++ b/tests/lib/Collaboration/Collaborators/LookupPluginTest.php @@ -1,4 +1,5 @@ <?php + /** * SPDX-FileCopyrightText: 2017 Nextcloud GmbH and Nextcloud contributors * SPDX-License-Identifier: AGPL-3.0-or-later @@ -72,17 +73,14 @@ class LookupPluginTest extends TestCase { 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') @@ -101,17 +99,14 @@ class LookupPluginTest extends TestCase { 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'); @@ -123,9 +118,9 @@ class LookupPluginTest extends TestCase { } /** - * @dataProvider searchDataProvider * @param array $searchParams */ + #[\PHPUnit\Framework\Attributes\DataProvider('searchDataProvider')] public function testSearch(array $searchParams): void { $type = new SearchResultType('lookup'); @@ -137,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') @@ -184,11 +176,11 @@ class LookupPluginTest extends TestCase { /** - * @dataProvider dataSearchEnableDisableLookupServer * @param array $searchParams * @param bool $GSEnabled * @param bool $LookupEnabled */ + #[\PHPUnit\Framework\Attributes\DataProvider('dataSearchEnableDisableLookupServer')] public function testSearchEnableDisableLookupServer(array $searchParams, $GSEnabled, $LookupEnabled): void { $type = new SearchResultType('lookup'); @@ -197,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') @@ -239,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'], @@ -258,11 +244,13 @@ class LookupPluginTest extends TestCase { } - public function testSearchLookupServerDisabled(): void { - $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); @@ -274,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', @@ -381,7 +369,6 @@ class LookupPluginTest extends TestCase { 'label' => $fedIDs[0], 'value' => [ 'shareType' => IShare::TYPE_REMOTE, - 'globalScale' => false, 'shareWith' => $fedIDs[0] ], 'extra' => ['federationId' => $fedIDs[0]], @@ -390,7 +377,6 @@ class LookupPluginTest extends TestCase { 'label' => $fedIDs[1], 'value' => [ 'shareType' => IShare::TYPE_REMOTE, - 'globalScale' => false, 'shareWith' => $fedIDs[1] ], 'extra' => ['federationId' => $fedIDs[1]], @@ -399,7 +385,6 @@ class LookupPluginTest extends TestCase { 'label' => $fedIDs[2], 'value' => [ 'shareType' => IShare::TYPE_REMOTE, - 'globalScale' => false, 'shareWith' => $fedIDs[2] ], 'extra' => ['federationId' => $fedIDs[2]], @@ -450,7 +435,7 @@ class LookupPluginTest extends TestCase { ]; } - public function searchDataProvider() { + public static function searchDataProvider(): array { $fedIDs = [ 'foo@enceladus.moon', 'foobar@enceladus.moon', @@ -474,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]], @@ -483,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]], @@ -492,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]], |