From a6bca34677ef1806b0d9113e4952eb8216e4add4 Mon Sep 17 00:00:00 2001 From: Lance Pioch Date: Sun, 13 May 2018 15:57:07 -0400 Subject: [PATCH] Add more exception tests --- .../Base/SecurityControllerTest.php | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/tests/Unit/Http/Controllers/Base/SecurityControllerTest.php b/tests/Unit/Http/Controllers/Base/SecurityControllerTest.php index 72435791b..363a59801 100644 --- a/tests/Unit/Http/Controllers/Base/SecurityControllerTest.php +++ b/tests/Unit/Http/Controllers/Base/SecurityControllerTest.php @@ -98,6 +98,36 @@ class SecurityControllerTest extends ControllerTestCase $this->assertResponseJsonEquals(['qrImage' => 'qrCodeImage'], $response); } + /** + * Test TOTP setting controller when no exception is thrown by the service. + */ + public function testSetTotpControllerSuccess() + { + $model = $this->generateRequestUserModel(); + + $this->request->shouldReceive('input')->with('token')->once()->andReturn('testToken'); + $this->toggleTwoFactorService->shouldReceive('handle')->with($model, 'testToken')->once(); + + $response = $this->getController()->setTotp($this->request); + $this->assertIsResponse($response); + $this->assertSame('true', $response->getContent()); + } + + /** + * Test TOTP setting controller when an exception is thrown by the service. + */ + public function testSetTotpControllerWhenExceptionIsThrown() + { + $model = $this->generateRequestUserModel(); + + $this->request->shouldReceive('input')->with('token')->once()->andReturn('testToken'); + $this->toggleTwoFactorService->shouldReceive('handle')->with($model, 'testToken')->once()->andThrow(new TwoFactorAuthenticationTokenInvalid()); + + $response = $this->getController()->setTotp($this->request); + $this->assertIsResponse($response); + $this->assertSame('false', $response->getContent()); + } + /** * Test the disable totp controller when no exception is thrown by the service. */