Skip to content

Commit

Permalink
test: fix and update SettingsController tests for redirect response
Browse files Browse the repository at this point in the history
Signed-off-by: ernolf <[email protected]>
  • Loading branch information
ernolf committed Jul 28, 2024
1 parent 3abee28 commit 0449118
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions tests/Unit/Controller/SettingsControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ protected function setUp(): void {
$this->request = $this->createMock(IRequest::class);
$this->userSession = $this->createMock(IUserSession::class);
$this->totp = $this->createMock(ITotp::class);
$this->defaults = $this->createMock(Defaults::class); // Optional, falls Defaults nicht mehr direkt gemockt werden muss
$this->urlGenerator = $this->createMock(IURLGenerator::class); // Stelle sicher, dass dies vorhanden ist
$this->defaults = $this->createMock(Defaults::class);
$this->urlGenerator = $this->createMock(IURLGenerator::class);

$this->controller = new SettingsController(
'twofactor_totp',
Expand All @@ -72,7 +72,7 @@ public function testDisabledState() {
->willReturn(false);

$expected = new JSONResponse([
'state' => false,
'state' => ITotp::STATE_DISABLED,
]);

$this->assertEquals($expected, $this->controller->state());
Expand Down Expand Up @@ -110,11 +110,15 @@ public function testEnableSecret() {
->with($user, '123456')
->willReturn(true);

$expected = new JSONResponse([
'state' => ITotp::STATE_ENABLED,
]);
$expectedUrl = $this->urlGenerator->linkToRoute('twofactor_totp.settings.state');
$this->urlGenerator->expects($this->once())
->method('linkToRoute')
->with('twofactor_totp.settings.state')
->willReturn($expectedUrl);

$expectedRedirectResponse = new RedirectResponse($expectedUrl);

$this->assertEquals($expected, $this->controller->enable(ITotp::STATE_ENABLED, '123456'));
$this->assertEquals($expectedRedirectResponse, $this->controller->enable(ITotp::STATE_ENABLED, '123456'));
}

public function testDisableSecret() {
Expand Down

0 comments on commit 0449118

Please sign in to comment.