11<?php
22
3+ declare (strict_types=1 );
4+
35/**
46 * SPDX-FileCopyrightText: 2017 Nextcloud GmbH and Nextcloud contributors
57 * SPDX-License-Identifier: AGPL-3.0-or-later
1315use OCP \Collaboration \Collaborators \SearchResultType ;
1416use OCP \Federation \ICloudId ;
1517use OCP \Federation \ICloudIdManager ;
18+ use OCP \GlobalScale \IConfig as GlobalScaleConfig ;
1619use OCP \Http \Client \IClient ;
1720use OCP \Http \Client \IClientService ;
1821use OCP \Http \Client \IResponse ;
2528use Test \TestCase ;
2629
2730class LookupPluginTest extends TestCase {
28- /** @var IConfig|MockObject */
29- protected $ config ;
30- /** @var IClientService|MockObject */
31- protected $ clientService ;
32- /** @var IUserSession|MockObject */
33- protected $ userSession ;
34- /** @var ICloudIdManager|MockObject */
35- protected $ cloudIdManager ;
36- /** @var LookupPlugin */
37- protected $ plugin ;
38- /** @var LoggerInterface|MockObject */
39- protected $ logger ;
31+ protected IConfig &MockObject $ config ;
32+ protected GlobalScaleConfig &MockObject $ globalScaleConfig ;
33+ protected IClientService &MockObject $ clientService ;
34+ protected IUserSession &MockObject $ userSession ;
35+ protected ICloudIdManager &MockObject $ cloudIdManager ;
36+ protected LookupPlugin $ plugin ;
37+ protected LoggerInterface &MockObject $ logger ;
4038
4139 #[\Override]
4240 protected function setUp (): void {
@@ -45,6 +43,7 @@ protected function setUp(): void {
4543 $ this ->userSession = $ this ->createMock (IUserSession::class);
4644 $ this ->cloudIdManager = $ this ->createMock (ICloudIdManager::class);
4745 $ this ->config = $ this ->createMock (IConfig::class);
46+ $ this ->globalScaleConfig = $ this ->createMock (GlobalScaleConfig::class);
4847 $ this ->logger = $ this ->createMock (LoggerInterface::class);
4948 $ this ->clientService = $ this ->createMock (IClientService::class);
5049 $ cloudId = $ this ->createMock (ICloudId::class);
@@ -72,7 +71,8 @@ protected function setUp(): void {
7271 $ this ->userSession ,
7372 $ this ->cloudIdManager ,
7473 $ this ->logger ,
75- null
74+ null ,
75+ $ this ->globalScaleConfig ,
7676 );
7777 }
7878
@@ -81,13 +81,16 @@ public function testSearchNoLookupServerURI(): void {
8181 ->method ('getAppValue ' )
8282 ->with ('files_sharing ' , 'lookupServerEnabled ' , 'no ' )
8383 ->willReturn ('yes ' );
84- $ this ->config ->expects ($ this ->exactly ( 2 ))
84+ $ this ->config ->expects ($ this ->once ( ))
8585 ->method ('getSystemValueBool ' )
8686 ->willReturnMap ([
87- ['gs.enabled ' , false , true ],
8887 ['has_internet_connection ' , true , true ],
8988 ]);
9089
90+ $ this ->globalScaleConfig ->expects ($ this ->once ())
91+ ->method ('isGlobalScaleEnabled ' )
92+ ->willReturn (true );
93+
9194 $ this ->config ->expects ($ this ->once ())
9295 ->method ('getSystemValueString ' )
9396 ->with ('lookup_server ' , 'https://lookup.nextcloud.com ' )
@@ -107,13 +110,16 @@ public function testSearchNoInternet(): void {
107110 ->method ('getAppValue ' )
108111 ->with ('files_sharing ' , 'lookupServerEnabled ' , 'no ' )
109112 ->willReturn ('yes ' );
110- $ this ->config ->expects ($ this ->exactly (2 ))
113+ $ this ->config ->expects ($ this ->exactly (1 ))
111114 ->method ('getSystemValueBool ' )
112115 ->willReturnMap ([
113- ['gs.enabled ' , false , false ],
114116 ['has_internet_connection ' , true , false ],
115117 ]);
116118
119+ $ this ->globalScaleConfig ->expects ($ this ->exactly (1 ))
120+ ->method ('isGlobalScaleEnabled ' )
121+ ->willReturn (false );
122+
117123 $ this ->clientService ->expects ($ this ->never ())
118124 ->method ('newClient ' );
119125
@@ -140,13 +146,16 @@ public function testSearch(array $searchParams): void {
140146 ->method ('getAppValue ' )
141147 ->with ('files_sharing ' , 'lookupServerEnabled ' , 'no ' )
142148 ->willReturn ('yes ' );
143- $ this ->config ->expects ($ this ->exactly ( 2 ))
149+ $ this ->config ->expects ($ this ->once ( ))
144150 ->method ('getSystemValueBool ' )
145151 ->willReturnMap ([
146- ['gs.enabled ' , false , true ],
147152 ['has_internet_connection ' , true , true ],
148153 ]);
149154
155+ $ this ->globalScaleConfig ->expects ($ this ->once ())
156+ ->method ('isGlobalScaleEnabled ' )
157+ ->willReturn (true );
158+
150159 $ this ->config ->expects ($ this ->once ())
151160 ->method ('getSystemValueString ' )
152161 ->with ('lookup_server ' , 'https://lookup.nextcloud.com ' )
@@ -202,12 +211,15 @@ public function testSearchEnableDisableLookupServer(array $searchParams, $GSEnab
202211 ->method ('addResultSet ' )
203212 ->with ($ type , $ searchParams ['expectedResult ' ], []);
204213
205- $ this ->config ->expects ($ this ->exactly ( 2 ))
214+ $ this ->config ->expects ($ this ->once ( ))
206215 ->method ('getSystemValueBool ' )
207216 ->willReturnMap ([
208- ['gs.enabled ' , false , $ GSEnabled ],
209217 ['has_internet_connection ' , true , true ],
210218 ]);
219+
220+ $ this ->globalScaleConfig ->expects ($ this ->once ())
221+ ->method ('isGlobalScaleEnabled ' )
222+ ->willReturn ($ GSEnabled );
211223 $ this ->config ->expects ($ this ->once ())
212224 ->method ('getSystemValueString ' )
213225 ->with ('lookup_server ' , 'https://lookup.nextcloud.com ' )
@@ -232,12 +244,15 @@ public function testSearchEnableDisableLookupServer(array $searchParams, $GSEnab
232244 ->willReturn ($ client );
233245 } else {
234246 $ searchResult ->expects ($ this ->never ())->method ('addResultSet ' );
235- $ this ->config ->expects ($ this ->exactly ( 2 ))
247+ $ this ->config ->expects ($ this ->once ( ))
236248 ->method ('getSystemValueBool ' )
237249 ->willReturnMap ([
238- ['gs.enabled ' , false , $ GSEnabled ],
239250 ['has_internet_connection ' , true , true ],
240251 ]);
252+
253+ $ this ->globalScaleConfig ->expects ($ this ->once ())
254+ ->method ('isGlobalScaleEnabled ' )
255+ ->willReturn ($ GSEnabled );
241256 }
242257 $ moreResults = $ this ->plugin ->search (
243258 $ searchParams ['search ' ],
@@ -251,13 +266,16 @@ public function testSearchEnableDisableLookupServer(array $searchParams, $GSEnab
251266
252267
253268 public function testSearchGSDisabled (): void {
254- $ this ->config ->expects ($ this ->atLeastOnce ())
269+ $ this ->config ->expects ($ this ->once ())
255270 ->method ('getSystemValueBool ' )
256271 ->willReturnMap ([
257272 ['has_internet_connection ' , true , true ],
258- ['gs.enabled ' , false , false ],
259273 ]);
260274
275+ $ this ->globalScaleConfig ->expects ($ this ->once ())
276+ ->method ('isGlobalScaleEnabled ' )
277+ ->willReturn (false );
278+
261279 /** @var ISearchResult|MockObject $searchResult */
262280 $ searchResult = $ this ->createMock (ISearchResult::class);
263281 $ searchResult ->expects ($ this ->never ())
0 commit comments