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);
@@ -71,7 +70,8 @@ protected function setUp(): void {
7170 $ this ->userSession ,
7271 $ this ->cloudIdManager ,
7372 $ this ->logger ,
74- null
73+ null ,
74+ $ this ->globalScaleConfig ,
7575 );
7676 }
7777
@@ -80,13 +80,16 @@ public function testSearchNoLookupServerURI(): void {
8080 ->method ('getAppValue ' )
8181 ->with ('files_sharing ' , 'lookupServerEnabled ' , 'no ' )
8282 ->willReturn ('yes ' );
83- $ this ->config ->expects ($ this ->exactly ( 2 ))
83+ $ this ->config ->expects ($ this ->once ( ))
8484 ->method ('getSystemValueBool ' )
8585 ->willReturnMap ([
86- ['gs.enabled ' , false , true ],
8786 ['has_internet_connection ' , true , true ],
8887 ]);
8988
89+ $ this ->globalScaleConfig ->expects ($ this ->once ())
90+ ->method ('isGlobalScaleEnabled ' )
91+ ->willReturn (true );
92+
9093 $ this ->config ->expects ($ this ->once ())
9194 ->method ('getSystemValueString ' )
9295 ->with ('lookup_server ' , 'https://lookup.nextcloud.com ' )
@@ -106,13 +109,16 @@ public function testSearchNoInternet(): void {
106109 ->method ('getAppValue ' )
107110 ->with ('files_sharing ' , 'lookupServerEnabled ' , 'no ' )
108111 ->willReturn ('yes ' );
109- $ this ->config ->expects ($ this ->exactly (2 ))
112+ $ this ->config ->expects ($ this ->exactly (1 ))
110113 ->method ('getSystemValueBool ' )
111114 ->willReturnMap ([
112- ['gs.enabled ' , false , false ],
113115 ['has_internet_connection ' , true , false ],
114116 ]);
115117
118+ $ this ->globalScaleConfig ->expects ($ this ->exactly (1 ))
119+ ->method ('isGlobalScaleEnabled ' )
120+ ->willReturn (false );
121+
116122 $ this ->clientService ->expects ($ this ->never ())
117123 ->method ('newClient ' );
118124
@@ -139,13 +145,16 @@ public function testSearch(array $searchParams): void {
139145 ->method ('getAppValue ' )
140146 ->with ('files_sharing ' , 'lookupServerEnabled ' , 'no ' )
141147 ->willReturn ('yes ' );
142- $ this ->config ->expects ($ this ->exactly ( 2 ))
148+ $ this ->config ->expects ($ this ->once ( ))
143149 ->method ('getSystemValueBool ' )
144150 ->willReturnMap ([
145- ['gs.enabled ' , false , true ],
146151 ['has_internet_connection ' , true , true ],
147152 ]);
148153
154+ $ this ->globalScaleConfig ->expects ($ this ->once ())
155+ ->method ('isGlobalScaleEnabled ' )
156+ ->willReturn (true );
157+
149158 $ this ->config ->expects ($ this ->once ())
150159 ->method ('getSystemValueString ' )
151160 ->with ('lookup_server ' , 'https://lookup.nextcloud.com ' )
@@ -200,12 +209,15 @@ public function testSearchEnableDisableLookupServer(array $searchParams, $GSEnab
200209 ->method ('addResultSet ' )
201210 ->with ($ type , $ searchParams ['expectedResult ' ], []);
202211
203- $ this ->config ->expects ($ this ->exactly ( 2 ))
212+ $ this ->config ->expects ($ this ->once ( ))
204213 ->method ('getSystemValueBool ' )
205214 ->willReturnMap ([
206- ['gs.enabled ' , false , $ GSEnabled ],
207215 ['has_internet_connection ' , true , true ],
208216 ]);
217+
218+ $ this ->globalScaleConfig ->expects ($ this ->once ())
219+ ->method ('isGlobalScaleEnabled ' )
220+ ->willReturn ($ GSEnabled );
209221 $ this ->config ->expects ($ this ->once ())
210222 ->method ('getSystemValueString ' )
211223 ->with ('lookup_server ' , 'https://lookup.nextcloud.com ' )
@@ -230,12 +242,15 @@ public function testSearchEnableDisableLookupServer(array $searchParams, $GSEnab
230242 ->willReturn ($ client );
231243 } else {
232244 $ searchResult ->expects ($ this ->never ())->method ('addResultSet ' );
233- $ this ->config ->expects ($ this ->exactly ( 2 ))
245+ $ this ->config ->expects ($ this ->once ( ))
234246 ->method ('getSystemValueBool ' )
235247 ->willReturnMap ([
236- ['gs.enabled ' , false , $ GSEnabled ],
237248 ['has_internet_connection ' , true , true ],
238249 ]);
250+
251+ $ this ->globalScaleConfig ->expects ($ this ->once ())
252+ ->method ('isGlobalScaleEnabled ' )
253+ ->willReturn ($ GSEnabled );
239254 }
240255 $ moreResults = $ this ->plugin ->search (
241256 $ searchParams ['search ' ],
@@ -248,13 +263,16 @@ public function testSearchEnableDisableLookupServer(array $searchParams, $GSEnab
248263 }
249264
250265 public function testSearchGSDisabled (): void {
251- $ this ->config ->expects ($ this ->atLeastOnce ())
266+ $ this ->config ->expects ($ this ->once ())
252267 ->method ('getSystemValueBool ' )
253268 ->willReturnMap ([
254269 ['has_internet_connection ' , true , true ],
255- ['gs.enabled ' , false , false ],
256270 ]);
257271
272+ $ this ->globalScaleConfig ->expects ($ this ->once ())
273+ ->method ('isGlobalScaleEnabled ' )
274+ ->willReturn (false );
275+
258276 /** @var ISearchResult|MockObject $searchResult */
259277 $ searchResult = $ this ->createMock (ISearchResult::class);
260278 $ searchResult ->expects ($ this ->never ())
0 commit comments