recoveryMock->expects($this->any()) ->method('enableAdminRecovery') ->willReturn(true); $this->recoveryMock->expects($this->any()) ->method('disableAdminRecovery') ->willReturn(true); $response = $this->controller->adminRecovery($recoveryPassword, $passConfirm, $enableRecovery); $this->assertEquals($expectedMessage, $response->getData()['data']['message']); $this->assertEquals($expectedStatus, $response->getStatus()); } public function changeRecoveryPasswordProvider() { return [ ['test', 'test', 'oldtestFail', 'Could not change the password. Maybe the old password was not correct.', Http::STATUS_BAD_REQUEST], ['test', 'test', 'oldtest', 'Password successfully changed.', Http::STATUS_OK], ['test', 'notmatch', 'oldtest', 'Repeated recovery key password does not match the provided recovery key password', Http::STATUS_BAD_REQUEST], ['', 'test', 'oldtest', 'Please provide a new recovery password', Http::STATUS_BAD_REQUEST], ['test', 'test', '', 'Please provide the old recovery password', Http::STATUS_BAD_REQUEST] ]; } /** * @dataProvider changeRecoveryPasswordProvider * @param $password * @param $confirmPassword * @param $oldPassword * @param $expectedMessage * @param $expectedStatus */ public function testChangeRecoveryPassword($password, $confirmPassword, $oldPassword, $expectedMessage, $expectedStatus) { $this->recoveryMock->expects($this->any()) ->method('changeRecoveryKeyPassword') ->with($password, $oldPassword) ->willReturnMap([ ['test', 'oldTestFail', false], ['test', 'oldtest', true] ]); $response = $this->controller->changeRecoveryPassword($password, $oldPassword, $confirmPassword); $this->assertEquals($expectedMessage, $response->getData()['data']['message']); $this->assertEquals($expectedStatus, $response->getStatus()); } public function userSetRecoveryProvider() { return [ ['1', 'Recovery Key enabled', Http::STATUS_OK], ['0', 'Could not enable the recovery key, please try again or contact your administrator', Http::STATUS_BAD_REQUEST] ]; } /** * @dataProvider userSetRecoveryProvider * @param $enableRecovery * @param $expectedMessage * @param $expectedStatus */ public function testUserSetRecovery($enableRecovery, $expectedMessage, $expectedStatus) { $this->recoveryMock->expects($this->any()) ->method('setRecoveryForUser') ->with($enableRecovery) ->willReturnMap([ ['1', true], ['0', false] ]); $response = $this->controller->userSetRecovery($enableRecovery); $this->assertEquals($expectedMessage, $response->getData()['data']['message']); $this->assertEquals($expectedStatus, $response->getStatus()); } protected function setUp(): void { parent::setUp(); $this->requestMock = $this->getMockBuilder(IRequest::class) ->disableOriginalConstructor() ->getMock(); $this->configMock = $this->getMockBuilder(IConfig::class) ->disableOriginalConstructor() ->getMock(); $this->l10nMock = $this->getMockBuilder(IL10N::class) ->disableOriginalConstructor() ->getMock(); // Make l10n work in our tests $this->l10nMock->expects($this->any()) ->method('t') ->willReturnArgument(0); $this->recoveryMock = $this->getMockBuilder(Recovery::class) ->disableOriginalConstructor() ->getMock(); $this->controller = new RecoveryController('encryption', $this->requestMock, $this->configMock, $this->l10nMock, $this->recoveryMock); } }