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,23 +142,23 @@ 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
@@ -238,51 +240,31 @@ protected function setUp(): void {
238240
239241 $ this ->cryptMock = $ this ->getMockBuilder (Crypt::class)->disableOriginalConstructor ()->getMock ();
240242 $ this ->keyManagerMock = $ this ->getMockBuilder (KeyManager::class)->disableOriginalConstructor ()->getMock ();
241- $ this ->configMock = $ this ->createMock (IConfig::class);
243+ $ this ->appConfigMock = $ this ->createMock (IAppConfig::class);
244+ $ this ->userConfigMock = $ this ->createMock (IUserConfig::class);
242245 $ this ->fileMock = $ this ->createMock (IFile::class);
243246 $ this ->viewMock = $ this ->createMock (View::class);
244247
245- $ this ->configMock ->expects ($ this ->any ())
246- ->method ('setAppValue ' )
247- ->willReturnCallback ([$ this , 'setValueTester ' ]);
248+ $ this ->appConfigMock ->expects ($ this ->any ())
249+ ->method ('setValueBool ' )
250+ ->willReturnCallback (function (string $ app , string $ key , bool $ value ): bool {
251+ self ::$ tempStorage [$ key ] = $ value ;
252+ return true ;
253+ });
248254
249- $ this ->configMock ->expects ($ this ->any ())
250- ->method ('getAppValue ' )
251- ->willReturnCallback ([$ this , 'getValueTester ' ]);
255+ $ this ->appConfigMock ->expects ($ this ->any ())
256+ ->method ('getValueBool ' )
257+ ->willReturnCallback (function (string $ app , string $ key , bool $ default = false ): bool {
258+ return self ::$ tempStorage [$ key ] ?? $ default ;
259+ });
252260
253261 $ this ->instance = new Recovery ($ this ->userSessionMock ,
254262 $ this ->cryptMock ,
255263 $ this ->keyManagerMock ,
256- $ this ->configMock ,
264+ $ this ->appConfigMock ,
265+ $ this ->userConfigMock ,
257266 $ this ->fileMock ,
258267 $ this ->viewMock );
259268 }
260269
261- /**
262- * @param $app
263- * @param $key
264- * @param $value
265- */
266- public function setValueTester ($ app , $ key , $ value ) {
267- self ::$ tempStorage [$ key ] = $ value ;
268- }
269-
270- /**
271- * @param $key
272- */
273- public function removeValueTester ($ key ) {
274- unset(self ::$ tempStorage [$ key ]);
275- }
276-
277- /**
278- * @param $app
279- * @param $key
280- * @return mixed
281- */
282- public function getValueTester ($ app , $ key ) {
283- if (!empty (self ::$ tempStorage [$ key ])) {
284- return self ::$ tempStorage [$ key ];
285- }
286- return null ;
287- }
288270}
0 commit comments