|
1 | 1 | <?php |
| 2 | + |
2 | 3 | /** |
3 | 4 | * Created by PhpStorm. |
4 | 5 | * User: christoph |
|
8 | 9 |
|
9 | 10 | namespace lib\Authentication\TwoFactorAuth; |
10 | 11 |
|
| 12 | +use Exception; |
11 | 13 | use OC\Authentication\TwoFactorAuth\ProviderLoader; |
| 14 | +use OCP\App\IAppManager; |
| 15 | +use PHPUnit_Framework_MockObject_MockObject; |
| 16 | +use Test\TestCase; |
| 17 | + |
| 18 | +class ProviderLoaderTest extends TestCase { |
| 19 | + |
| 20 | + /** @var IAppManager|PHPUnit_Framework_MockObject_MockObject */ |
| 21 | + private $appManager; |
| 22 | + |
| 23 | + /** @var IUser|PHPUnit_Framework_MockObject_MockObject */ |
| 24 | + private $user; |
| 25 | + |
| 26 | + /** @var ProviderLoader */ |
| 27 | + private $loader; |
| 28 | + |
| 29 | + protected function setUp() { |
| 30 | + parent::setUp(); |
12 | 31 |
|
13 | | -class ProviderLoaderTest extends \Test\TestCase { |
| 32 | + $this->appManager = $this->createMock(IAppManager::class); |
| 33 | + $this->user = $this->createMock(\OCP\IUser::class); |
| 34 | + |
| 35 | + $this->loader = new ProviderLoader($this->appManager); |
| 36 | + } |
14 | 37 |
|
15 | 38 | /** |
16 | 39 | * @expectedException Exception |
17 | 40 | * @expectedExceptionMessage Could not load two-factor auth provider \OCA\MyFaulty2faApp\DoesNotExist |
18 | 41 | */ |
19 | 42 | public function testFailHardIfProviderCanNotBeLoaded() { |
20 | | - $this->providerLoader->expects($this->once()) |
21 | | - ->method('getProviders') |
| 43 | + $this->appManager->expects($this->once()) |
| 44 | + ->method('getEnabledAppsForUser') |
22 | 45 | ->with($this->user) |
23 | | - ->will($this->returnValue(['faulty2faapp'])); |
24 | | - $this->manager->expects($this->once()) |
25 | | - ->method('loadTwoFactorApp') |
26 | | - ->with('faulty2faapp'); |
27 | | - |
28 | | - $this->providerLoader->expects($this->once()) |
| 46 | + ->willReturn(['mail', 'twofactor_totp']); |
| 47 | + $this->appManager |
29 | 48 | ->method('getAppInfo') |
30 | | - ->with('faulty2faapp') |
31 | | - ->will($this->returnValue([ |
32 | | - 'two-factor-providers' => [ |
33 | | - '\OCA\MyFaulty2faApp\DoesNotExist', |
34 | | - ], |
35 | | - ])); |
36 | | - |
37 | | - $this->manager->getProviderSet($this->user); |
| 49 | + ->will($this->returnValueMap([ |
| 50 | + ['mail', []], |
| 51 | + ['twofactor_totp'], [ |
| 52 | + 'two-factor-providers' => [ |
| 53 | + '\\OCA\\MyFaulty2faApp\\DoesNotExist', |
| 54 | + ], |
| 55 | + ], |
| 56 | + ])); |
| 57 | + |
| 58 | + $this->loader->getProviders($this->user); |
| 59 | + } |
| 60 | + |
| 61 | + public function testGetProviders() { |
| 62 | + |
38 | 63 | } |
39 | 64 |
|
40 | 65 | } |
0 commit comments