Skip to content

Commit a6bca34

Browse files
committed
Add more exception tests
1 parent 038e5e1 commit a6bca34

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

tests/Unit/Http/Controllers/Base/SecurityControllerTest.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,36 @@ public function testGenerateTotpController()
9898
$this->assertResponseJsonEquals(['qrImage' => 'qrCodeImage'], $response);
9999
}
100100

101+
/**
102+
* Test TOTP setting controller when no exception is thrown by the service.
103+
*/
104+
public function testSetTotpControllerSuccess()
105+
{
106+
$model = $this->generateRequestUserModel();
107+
108+
$this->request->shouldReceive('input')->with('token')->once()->andReturn('testToken');
109+
$this->toggleTwoFactorService->shouldReceive('handle')->with($model, 'testToken')->once();
110+
111+
$response = $this->getController()->setTotp($this->request);
112+
$this->assertIsResponse($response);
113+
$this->assertSame('true', $response->getContent());
114+
}
115+
116+
/**
117+
* Test TOTP setting controller when an exception is thrown by the service.
118+
*/
119+
public function testSetTotpControllerWhenExceptionIsThrown()
120+
{
121+
$model = $this->generateRequestUserModel();
122+
123+
$this->request->shouldReceive('input')->with('token')->once()->andReturn('testToken');
124+
$this->toggleTwoFactorService->shouldReceive('handle')->with($model, 'testToken')->once()->andThrow(new TwoFactorAuthenticationTokenInvalid());
125+
126+
$response = $this->getController()->setTotp($this->request);
127+
$this->assertIsResponse($response);
128+
$this->assertSame('false', $response->getContent());
129+
}
130+
101131
/**
102132
* Test the disable totp controller when no exception is thrown by the service.
103133
*/

0 commit comments

Comments
 (0)