diff options
author | Christoph Wurst <christoph@winzerhof-wurst.at> | 2018-08-06 16:20:31 +0300 |
---|---|---|
committer | Christoph Wurst <christoph@winzerhof-wurst.at> | 2018-08-06 16:59:29 +0300 |
commit | ce19d74b9854b518484dc88a24b7258aa8a068f4 (patch) | |
tree | 27ab45195b63b003b62aa6a31d153abf678bf3a6 /tests | |
parent | 5a90c2a51adce307a8451f7957df8a27aa581dba (diff) |
Refactor provider to not use the config ojbect directly
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/Unit/Provider/SmsProviderTest.php | 36 | ||||
-rw-r--r-- | tests/Unit/Service/SetupServiceTest.php | 25 |
2 files changed, 27 insertions, 34 deletions
diff --git a/tests/Unit/Provider/SmsProviderTest.php b/tests/Unit/Provider/SmsProviderTest.php index a2d1dec..cffbba1 100644 --- a/tests/Unit/Provider/SmsProviderTest.php +++ b/tests/Unit/Provider/SmsProviderTest.php @@ -24,6 +24,7 @@ namespace OCA\TwoFactorGateway\Tests\Unit\Provider; use ChristophWurst\Nextcloud\Testing\TestCase; use OCA\TwoFactorGateway\Provider\SmsProvider; +use OCA\TwoFactorGateway\Provider\State; use OCA\TwoFactorGateway\Service\IGateway; use OCA\TwoFactorGateway\Service\SetupService; use OCP\IConfig; @@ -47,9 +48,6 @@ class SmsProviderTest extends TestCase { /** @var ISecureRandom|PHPUnit_Framework_MockObject_MockObject */ private $random; - /** @var IConfig|PHPUnit_Framework_MockObject_MockObject */ - private $config; - /** @var IL10n|PHPUnit_Framework_MockObject_MockObject */ private $l10n; @@ -63,19 +61,39 @@ class SmsProviderTest extends TestCase { $this->setupService = $this->createMock(SetupService::class); $this->session = $this->createMock(ISession::class); $this->random = $this->createMock(ISecureRandom::class); - $this->config = $this->createMock(IConfig::class); $this->l10n = $this->createMock(IL10N::class); - $this->provider = new SmsProvider($this->smsService, $this->setupService, $this->session, $this->random, $this->config, $this->l10n); + $this->provider = new SmsProvider( + $this->smsService, + $this->setupService, + $this->session, + $this->random, + $this->l10n + ); + } + + public function testIsTwoFactorAuthDisabledForUser() { + $user = $this->createMock(IUser::class); + $user->method('getUID')->willReturn('user123'); + $state = new State($user, SmsProvider::STATE_DISABLED, 'signal'); + $this->setupService->expects($this->once()) + ->method('getState') + ->with($user) + ->willReturn($state); + + $enabled = $this->provider->isTwoFactorAuthEnabledForUser($user); + + $this->assertFalse($enabled); } public function testIsTwoFactorAuthEnabledForUser() { $user = $this->createMock(IUser::class); $user->method('getUID')->willReturn('user123'); - $this->config->expects($this->once()) - ->method('getUserValue') - ->with('user123', 'twofactor_gateway', 'verified', 'false') - ->willReturn('true'); + $state = new State($user, SmsProvider::STATE_ENABLED, 'signal'); + $this->setupService->expects($this->once()) + ->method('getState') + ->with($user) + ->willReturn($state); $enabled = $this->provider->isTwoFactorAuthEnabledForUser($user); diff --git a/tests/Unit/Service/SetupServiceTest.php b/tests/Unit/Service/SetupServiceTest.php index fa634cb..511252a 100644 --- a/tests/Unit/Service/SetupServiceTest.php +++ b/tests/Unit/Service/SetupServiceTest.php @@ -58,31 +58,6 @@ class SetupServiceTest extends TestCase { $this->setupService = new SetupService($this->stateStorage, $this->gateway, $this->random); } - public function testGetIdentifierNoneFound() { - /** @var IUser $user */ - $user = $this->createMock(IUser::class); - $state = State::disabled($user); - $this->stateStorage->expects($this->once()) - ->method('get') - ->willReturn($state); - $this->setExpectedException(IdentifierMissingException::class); - - $this->setupService->getChallengePhoneNumber($user); - } - - public function testGetIdentifier() { - /** @var IUser $user */ - $user = $this->createMock(IUser::class); - $state = State::verifying($user, 'websms', '01234', '1234'); - $this->stateStorage->expects($this->once()) - ->method('get') - ->willReturn($state); - - $identifier = $this->setupService->getChallengePhoneNumber($user); - - $this->assertSame('01234', $identifier); - } - public function testStartSetupTransmissionError() { $identifier = '1234'; $user = $this->createMock(IUser::class); |