providerLoader = $this->createMock(ProviderLoader::class); $this->registry = $this->createMock(IRegistry::class); $this->providerManager = new ProviderManager( $this->providerLoader, $this->registry ); } public function testTryEnableInvalidProvider() { $this->expectException(\OC\Authentication\Exceptions\InvalidProviderException::class); $user = $this->createMock(IUser::class); $this->providerManager->tryEnableProviderFor('none', $user); } public function testTryEnableUnsupportedProvider() { $user = $this->createMock(IUser::class); $provider = $this->createMock(IProvider::class); $this->providerLoader->expects($this->once()) ->method('getProviders') ->with($user) ->willReturn([ 'u2f' => $provider, ]); $this->registry->expects($this->never()) ->method('enableProviderFor'); $res = $this->providerManager->tryEnableProviderFor('u2f', $user); $this->assertFalse($res); } public function testTryEnableProvider() { $user = $this->createMock(IUser::class); $provider = $this->createMock(IActivatableByAdmin::class); $this->providerLoader->expects($this->once()) ->method('getProviders') ->with($user) ->willReturn([ 'u2f' => $provider, ]); $provider->expects($this->once()) ->method('enableFor') ->with($user); $this->registry->expects($this->once()) ->method('enableProviderFor') ->with($provider, $user); $res = $this->providerManager->tryEnableProviderFor('u2f', $user); $this->assertTrue($res); } public function testTryDisableInvalidProvider() { $this->expectException(\OC\Authentication\Exceptions\InvalidProviderException::class); $user = $this->createMock(IUser::class); $this->providerManager->tryDisableProviderFor('none', $user); } public function testTryDisableUnsupportedProvider() { $user = $this->createMock(IUser::class); $provider = $this->createMock(IProvider::class); $this->providerLoader->expects($this->once()) ->method('getProviders') ->with($user) ->willReturn([ 'u2f' => $provider, ]); $this->registry->expects($this->never()) ->method('disableProviderFor'); $res = $this->providerManager->tryDisableProviderFor('u2f', $user); $this->assertFalse($res); } public function testTryDisableProvider() { $user = $this->createMock(IUser::class); $provider = $this->createMock(IDeactivatableByAdmin::class); $this->providerLoader->expects($this->once()) ->method('getProviders') ->with($user) ->willReturn([ 'u2f' => $provider, ]); $provider->expects($this->once()) ->method('disableFor') ->with($user); $this->registry->expects($this->once()) ->method('disableProviderFor') ->with($provider, $user); $res = $this->providerManager->tryDisableProviderFor('u2f', $user); $this->assertTrue($res); } }