1414use OCA \Encryption \Crypto \Crypt ;
1515use OCA \Encryption \KeyManager ;
1616use OCA \Encryption \Recovery ;
17+ use OCP \Config \IUserConfig ;
1718use OCP \Encryption \IFile ;
18- use OCP \IConfig ;
19+ use OCP \IAppConfig ;
1920use OCP \IUser ;
2021use OCP \IUserSession ;
2122use PHPUnit \Framework \MockObject \MockObject ;
@@ -29,7 +30,8 @@ class RecoveryTest extends TestCase {
2930 private IUserSession &MockObject $ userSessionMock ;
3031 private IUser &MockObject $ user ;
3132 private KeyManager &MockObject $ keyManagerMock ;
32- private IConfig &MockObject $ configMock ;
33+ private IAppConfig &MockObject $ appConfigMock ;
34+ private IUserConfig &MockObject $ userConfigMock ;
3335 private Crypt &MockObject $ cryptMock ;
3436
3537 private Recovery $ instance ;
@@ -56,7 +58,7 @@ public function testEnableAdminRecoverySuccessful(): void {
5658
5759 $ this ->assertTrue ($ this ->instance ->enableAdminRecovery ('password ' ));
5860 $ this ->assertArrayHasKey ('recoveryAdminEnabled ' , self ::$ tempStorage );
59- $ this ->assertEquals ( 1 , self ::$ tempStorage ['recoveryAdminEnabled ' ]);
61+ $ this ->assertTrue ( self ::$ tempStorage ['recoveryAdminEnabled ' ]);
6062
6163 $ this ->assertTrue ($ this ->instance ->enableAdminRecovery ('password ' ));
6264 }
@@ -83,7 +85,7 @@ public function testEnableAdminRecoveryCouldNotCheckPassword(): void {
8385
8486 $ this ->assertTrue ($ this ->instance ->enableAdminRecovery ('password ' ));
8587 $ this ->assertArrayHasKey ('recoveryAdminEnabled ' , self ::$ tempStorage );
86- $ this ->assertEquals ( 1 , self ::$ tempStorage ['recoveryAdminEnabled ' ]);
88+ $ this ->assertTrue ( self ::$ tempStorage ['recoveryAdminEnabled ' ]);
8789
8890 $ this ->assertFalse ($ this ->instance ->enableAdminRecovery ('password ' ));
8991 }
@@ -140,32 +142,32 @@ public function testDisableAdminRecovery(): void {
140142
141143 $ this ->assertArrayHasKey ('recoveryAdminEnabled ' , self ::$ tempStorage );
142144 $ this ->assertTrue ($ this ->instance ->disableAdminRecovery ('password ' ));
143- $ this ->assertEquals ( 0 , self ::$ tempStorage ['recoveryAdminEnabled ' ]);
145+ $ this ->assertFalse ( self ::$ tempStorage ['recoveryAdminEnabled ' ]);
144146
145147 $ this ->assertFalse ($ this ->instance ->disableAdminRecovery ('password ' ));
146148 }
147149
148150 public function testIsRecoveryEnabledForUser (): void {
149- $ this ->configMock ->expects ($ this ->exactly (2 ))
150- ->method ('getUserValue ' )
151- ->willReturnOnConsecutiveCalls (' 1 ' , ' 0 ' );
151+ $ this ->userConfigMock ->expects ($ this ->exactly (2 ))
152+ ->method ('getValueBool ' )
153+ ->willReturnOnConsecutiveCalls (true , false );
152154
153155 $ this ->assertTrue ($ this ->instance ->isRecoveryEnabledForUser ());
154156 $ this ->assertFalse ($ this ->instance ->isRecoveryEnabledForUser ('admin ' ));
155157 }
156158
157159 public function testIsRecoveryKeyEnabled (): void {
158160 $ this ->assertFalse ($ this ->instance ->isRecoveryKeyEnabled ());
159- self ::$ tempStorage ['recoveryAdminEnabled ' ] = ' 1 ' ;
161+ self ::$ tempStorage ['recoveryAdminEnabled ' ] = true ;
160162 $ this ->assertTrue ($ this ->instance ->isRecoveryKeyEnabled ());
161163 }
162164
163165 public function testSetRecoveryFolderForUser (): void {
164166 $ this ->viewMock ->expects ($ this ->exactly (2 ))
165167 ->method ('getDirectoryContent ' )
166168 ->willReturn ([]);
167- $ this ->assertTrue ($ this ->instance ->setRecoveryForUser (0 ));
168- $ this ->assertTrue ($ this ->instance ->setRecoveryForUser (' 1 ' ));
169+ $ this ->assertTrue ($ this ->instance ->setRecoveryForUser (false ));
170+ $ this ->assertTrue ($ this ->instance ->setRecoveryForUser (true ));
169171 }
170172
171173 public function testRecoverUserFiles (): void {
@@ -239,52 +241,41 @@ protected function setUp(): void {
239241
240242 $ this ->cryptMock = $ this ->getMockBuilder (Crypt::class)->disableOriginalConstructor ()->getMock ();
241243 $ this ->keyManagerMock = $ this ->getMockBuilder (KeyManager::class)->disableOriginalConstructor ()->getMock ();
242- $ this ->configMock = $ this ->createMock (IConfig::class);
244+ $ this ->appConfigMock = $ this ->createMock (IAppConfig::class);
245+ $ this ->userConfigMock = $ this ->createMock (IUserConfig::class);
243246 $ this ->fileMock = $ this ->createMock (IFile::class);
244247 $ this ->viewMock = $ this ->createMock (View::class);
245248
246- $ this ->configMock ->expects ($ this ->any ())
247- ->method ('setAppValue ' )
248- ->willReturnCallback ([$ this , 'setValueTester ' ]);
249+ $ this ->appConfigMock ->expects ($ this ->any ())
250+ ->method ('setValueBool ' )
251+ ->willReturnCallback (function (string $ app , string $ key , bool $ value ): bool {
252+ self ::$ tempStorage [$ key ] = $ value ;
253+ return true ;
254+ });
249255
250- $ this ->configMock ->expects ($ this ->any ())
251- ->method ('getAppValue ' )
256+ $ this ->appConfigMock ->expects ($ this ->any ())
257+ ->method ('getValueBool ' )
252258 ->willReturnCallback ([$ this , 'getValueTester ' ]);
253259
254260 $ this ->instance = new Recovery ($ this ->userSessionMock ,
255261 $ this ->cryptMock ,
256262 $ this ->keyManagerMock ,
257- $ this ->configMock ,
263+ $ this ->appConfigMock ,
264+ $ this ->userConfigMock ,
258265 $ this ->fileMock ,
259266 $ this ->viewMock );
260267 }
261268
262269
263- /**
264- * @param $app
265- * @param $key
266- * @param $value
267- */
268- public function setValueTester ($ app , $ key , $ value ) {
270+ public function setValueTester (string $ app , string $ key , bool $ value ): void {
269271 self ::$ tempStorage [$ key ] = $ value ;
270272 }
271273
272- /**
273- * @param $key
274- */
275- public function removeValueTester ($ key ) {
274+ public function removeValueTester (string $ key ): void {
276275 unset(self ::$ tempStorage [$ key ]);
277276 }
278277
279- /**
280- * @param $app
281- * @param $key
282- * @return mixed
283- */
284- public function getValueTester ($ app , $ key ) {
285- if (!empty (self ::$ tempStorage [$ key ])) {
286- return self ::$ tempStorage [$ key ];
287- }
288- return null ;
278+ public function getValueTester (string $ app , string $ key , bool $ default = false ): bool {
279+ return self ::$ tempStorage [$ key ] ?? $ default ;
289280 }
290281}
0 commit comments