From f29748a5e11bc1a86e47ce97dd00f6aaff183c36 Mon Sep 17 00:00:00 2001 From: Konrad Abicht Date: Thu, 11 Feb 2021 09:49:39 +0100 Subject: [PATCH] added unit tests for LoginFlowV2Service::getByLoginToken Signed-off-by: Konrad Abicht --- .../Service/LoginFlowV2ServiceUnitTest.php | 42 ++++++++++++++++--- 1 file changed, 37 insertions(+), 5 deletions(-) diff --git a/tests/Core/Service/LoginFlowV2ServiceUnitTest.php b/tests/Core/Service/LoginFlowV2ServiceUnitTest.php index ed87380897..511c9be327 100644 --- a/tests/Core/Service/LoginFlowV2ServiceUnitTest.php +++ b/tests/Core/Service/LoginFlowV2ServiceUnitTest.php @@ -74,8 +74,7 @@ class LoginFlowV2ServiceUnitTest extends TestCase { * * Code was moved to separate function to keep setUp function small and clear. */ - private function setupSubjectUnderTest(): void - { + private function setupSubjectUnderTest(): void { $this->config = $this->getMockBuilder(IConfig::class) ->disableOriginalConstructor()->getMock(); @@ -115,7 +114,7 @@ class LoginFlowV2ServiceUnitTest extends TestCase { // Create the private and public key $res = openssl_pkey_new([ 'digest_alg' => 'md5', // take fast algorithm for testing purposes - 'private_key_bits' => 4096, + 'private_key_bits' => 512, 'private_key_type' => OPENSSL_KEYTYPE_RSA, ]); @@ -142,7 +141,7 @@ class LoginFlowV2ServiceUnitTest extends TestCase { /* * Cannot be mocked, because functions like getLoginName are magic functions. - * To be able to call it, we have to use the real class here. + * To be able to set internal properties, we have to use the real class here. */ $loginFlowV2 = new LoginFlowV2(); $loginFlowV2->setLoginName('test'); @@ -184,7 +183,7 @@ class LoginFlowV2ServiceUnitTest extends TestCase { /* * Cannot be mocked, because functions like getLoginName are magic functions. - * To be able to call it, we have to use the real class here. + * To be able to set internal properties, we have to use the real class here. */ $loginFlowV2 = new LoginFlowV2(); $loginFlowV2->setLoginName('test_login'); @@ -212,4 +211,37 @@ class LoginFlowV2ServiceUnitTest extends TestCase { $credentials->jsonSerialize() ); } + + /* + * Tests for getByLoginToken + */ + + public function testGetByLoginToken() { + $loginFlowV2 = new LoginFlowV2(); + $loginFlowV2->setLoginName('test_login'); + $loginFlowV2->setServer('test_server'); + $loginFlowV2->setAppPassword('test'); + + $this->mapper->expects($this->once()) + ->method('getByLoginToken') + ->willReturn($loginFlowV2); + + $result = $this->subjectUnderTest->getByLoginToken('test_token'); + + $this->assertTrue($result instanceof LoginFlowV2); + $this->assertEquals('test_server', $result->getServer()); + $this->assertEquals('test_login', $result->getLoginName()); + $this->assertEquals('test', $result->getAppPassword()); + } + + public function testGetByLoginTokenLoginTokenInvalid() { + $this->expectException(LoginFlowV2NotFoundException::class); + $this->expectExceptionMessage('Login token invalid'); + + $this->mapper->expects($this->once()) + ->method('getByLoginToken') + ->willThrowException(new DoesNotExistException('')); + + $this->subjectUnderTest->getByLoginToken('test_token'); + } }