Completed
Push — master ( 38c8ea...c9712b )
by Joas
40:21
created
tests/lib/Authentication/TwoFactorAuth/ProviderLoaderTest.php 1 patch
Indentation   +97 added lines, -97 removed lines patch added patch discarded remove patch
@@ -20,101 +20,101 @@
 block discarded – undo
20 20
 use Test\TestCase;
21 21
 
22 22
 class ProviderLoaderTest extends TestCase {
23
-	/** @var IAppManager|MockObject */
24
-	private $appManager;
25
-
26
-	/** @var IUser|MockObject */
27
-	private $user;
28
-
29
-	/** @var RegistrationContext|MockObject */
30
-	private $registrationContext;
31
-
32
-	/** @var ProviderLoader */
33
-	private $loader;
34
-
35
-	protected function setUp(): void {
36
-		parent::setUp();
37
-
38
-		$this->appManager = $this->createMock(IAppManager::class);
39
-		$this->user = $this->createMock(IUser::class);
40
-
41
-		$this->registrationContext = $this->createMock(RegistrationContext::class);
42
-		$coordinator = $this->createMock(Coordinator::class);
43
-		$coordinator->method('getRegistrationContext')
44
-			->willReturn($this->registrationContext);
45
-
46
-		$this->loader = new ProviderLoader($this->appManager, $coordinator);
47
-	}
48
-
49
-
50
-	public function testFailHardIfProviderCanNotBeLoaded(): void {
51
-		$this->expectException(\Exception::class);
52
-		$this->expectExceptionMessage('Could not load two-factor auth provider \\OCA\\MyFaulty2faApp\\DoesNotExist');
53
-
54
-		$this->appManager->expects($this->once())
55
-			->method('getEnabledAppsForUser')
56
-			->with($this->user)
57
-			->willReturn(['mail', 'twofactor_totp']);
58
-		$this->appManager
59
-			->method('getAppInfo')
60
-			->willReturnMap([
61
-				['mail', false, null, []],
62
-				['twofactor_totp', false, null, [
63
-					'two-factor-providers' => [
64
-						'\\OCA\\MyFaulty2faApp\\DoesNotExist',
65
-					],
66
-				]],
67
-			]);
68
-
69
-		$this->loader->getProviders($this->user);
70
-	}
71
-
72
-	public function testGetProviders(): void {
73
-		$provider = $this->createMock(IProvider::class);
74
-		$provider->method('getId')->willReturn('test');
75
-		\OC::$server->registerService('\\OCA\\TwoFactorTest\\Provider', function () use ($provider) {
76
-			return $provider;
77
-		});
78
-		$this->appManager->expects($this->once())
79
-			->method('getEnabledAppsForUser')
80
-			->with($this->user)
81
-			->willReturn(['twofactor_test']);
82
-		$this->appManager
83
-			->method('getAppInfo')
84
-			->with('twofactor_test')
85
-			->willReturn(['two-factor-providers' => [
86
-				'\\OCA\\TwoFactorTest\\Provider',
87
-			]]);
88
-
89
-		$providers = $this->loader->getProviders($this->user);
90
-
91
-		$this->assertCount(1, $providers);
92
-		$this->assertArrayHasKey('test', $providers);
93
-		$this->assertSame($provider, $providers['test']);
94
-	}
95
-
96
-	public function testGetProvidersBootstrap(): void {
97
-		$provider = $this->createMock(IProvider::class);
98
-		$provider->method('getId')->willReturn('test');
99
-
100
-		\OC::$server->registerService('\\OCA\\TwoFactorTest\\Provider', function () use ($provider) {
101
-			return $provider;
102
-		});
103
-
104
-		$this->appManager->expects($this->once())
105
-			->method('getEnabledAppsForUser')
106
-			->with($this->user)
107
-			->willReturn([]);
108
-
109
-		$this->registrationContext->method('getTwoFactorProviders')
110
-			->willReturn([
111
-				new ServiceRegistration('twofactor_test', '\\OCA\\TwoFactorTest\\Provider')
112
-			]);
113
-
114
-		$providers = $this->loader->getProviders($this->user);
115
-
116
-		$this->assertCount(1, $providers);
117
-		$this->assertArrayHasKey('test', $providers);
118
-		$this->assertSame($provider, $providers['test']);
119
-	}
23
+    /** @var IAppManager|MockObject */
24
+    private $appManager;
25
+
26
+    /** @var IUser|MockObject */
27
+    private $user;
28
+
29
+    /** @var RegistrationContext|MockObject */
30
+    private $registrationContext;
31
+
32
+    /** @var ProviderLoader */
33
+    private $loader;
34
+
35
+    protected function setUp(): void {
36
+        parent::setUp();
37
+
38
+        $this->appManager = $this->createMock(IAppManager::class);
39
+        $this->user = $this->createMock(IUser::class);
40
+
41
+        $this->registrationContext = $this->createMock(RegistrationContext::class);
42
+        $coordinator = $this->createMock(Coordinator::class);
43
+        $coordinator->method('getRegistrationContext')
44
+            ->willReturn($this->registrationContext);
45
+
46
+        $this->loader = new ProviderLoader($this->appManager, $coordinator);
47
+    }
48
+
49
+
50
+    public function testFailHardIfProviderCanNotBeLoaded(): void {
51
+        $this->expectException(\Exception::class);
52
+        $this->expectExceptionMessage('Could not load two-factor auth provider \\OCA\\MyFaulty2faApp\\DoesNotExist');
53
+
54
+        $this->appManager->expects($this->once())
55
+            ->method('getEnabledAppsForUser')
56
+            ->with($this->user)
57
+            ->willReturn(['mail', 'twofactor_totp']);
58
+        $this->appManager
59
+            ->method('getAppInfo')
60
+            ->willReturnMap([
61
+                ['mail', false, null, []],
62
+                ['twofactor_totp', false, null, [
63
+                    'two-factor-providers' => [
64
+                        '\\OCA\\MyFaulty2faApp\\DoesNotExist',
65
+                    ],
66
+                ]],
67
+            ]);
68
+
69
+        $this->loader->getProviders($this->user);
70
+    }
71
+
72
+    public function testGetProviders(): void {
73
+        $provider = $this->createMock(IProvider::class);
74
+        $provider->method('getId')->willReturn('test');
75
+        \OC::$server->registerService('\\OCA\\TwoFactorTest\\Provider', function () use ($provider) {
76
+            return $provider;
77
+        });
78
+        $this->appManager->expects($this->once())
79
+            ->method('getEnabledAppsForUser')
80
+            ->with($this->user)
81
+            ->willReturn(['twofactor_test']);
82
+        $this->appManager
83
+            ->method('getAppInfo')
84
+            ->with('twofactor_test')
85
+            ->willReturn(['two-factor-providers' => [
86
+                '\\OCA\\TwoFactorTest\\Provider',
87
+            ]]);
88
+
89
+        $providers = $this->loader->getProviders($this->user);
90
+
91
+        $this->assertCount(1, $providers);
92
+        $this->assertArrayHasKey('test', $providers);
93
+        $this->assertSame($provider, $providers['test']);
94
+    }
95
+
96
+    public function testGetProvidersBootstrap(): void {
97
+        $provider = $this->createMock(IProvider::class);
98
+        $provider->method('getId')->willReturn('test');
99
+
100
+        \OC::$server->registerService('\\OCA\\TwoFactorTest\\Provider', function () use ($provider) {
101
+            return $provider;
102
+        });
103
+
104
+        $this->appManager->expects($this->once())
105
+            ->method('getEnabledAppsForUser')
106
+            ->with($this->user)
107
+            ->willReturn([]);
108
+
109
+        $this->registrationContext->method('getTwoFactorProviders')
110
+            ->willReturn([
111
+                new ServiceRegistration('twofactor_test', '\\OCA\\TwoFactorTest\\Provider')
112
+            ]);
113
+
114
+        $providers = $this->loader->getProviders($this->user);
115
+
116
+        $this->assertCount(1, $providers);
117
+        $this->assertArrayHasKey('test', $providers);
118
+        $this->assertSame($provider, $providers['test']);
119
+    }
120 120
 }
Please login to merge, or discard this patch.
tests/lib/Authentication/TwoFactorAuth/MandatoryTwoFactorTest.php 1 patch
Indentation   +158 added lines, -158 removed lines patch added patch discarded remove patch
@@ -18,162 +18,162 @@
 block discarded – undo
18 18
 use Test\TestCase;
19 19
 
20 20
 class MandatoryTwoFactorTest extends TestCase {
21
-	/** @var IConfig|MockObject */
22
-	private $config;
23
-
24
-	/** @var IGroupManager|MockObject */
25
-	private $groupManager;
26
-
27
-	/** @var MandatoryTwoFactor */
28
-	private $mandatoryTwoFactor;
29
-
30
-	protected function setUp(): void {
31
-		parent::setUp();
32
-
33
-		$this->config = $this->createMock(IConfig::class);
34
-		$this->groupManager = $this->createMock(IGroupManager::class);
35
-
36
-		$this->mandatoryTwoFactor = new MandatoryTwoFactor($this->config, $this->groupManager);
37
-	}
38
-
39
-	public function testIsNotEnforced(): void {
40
-		$this->config
41
-			->method('getSystemValue')
42
-			->willReturnMap([
43
-				['twofactor_enforced', 'false', 'false'],
44
-				['twofactor_enforced_groups', [], []],
45
-				['twofactor_enforced_excluded_groups', [], []],
46
-			]);
47
-
48
-		$state = $this->mandatoryTwoFactor->getState();
49
-
50
-		$this->assertFalse($state->isEnforced());
51
-	}
52
-
53
-	public function testIsEnforced(): void {
54
-		$this->config
55
-			->method('getSystemValue')
56
-			->willReturnMap([
57
-				['twofactor_enforced', 'false', 'true'],
58
-				['twofactor_enforced_groups', [], []],
59
-				['twofactor_enforced_excluded_groups', [], []],
60
-			]);
61
-
62
-		$state = $this->mandatoryTwoFactor->getState();
63
-
64
-		$this->assertTrue($state->isEnforced());
65
-	}
66
-
67
-	public function testIsNotEnforcedForAnybody(): void {
68
-		$user = $this->createMock(IUser::class);
69
-		$user->method('getUID')->willReturn('user123');
70
-		$this->config
71
-			->method('getSystemValue')
72
-			->willReturnMap([
73
-				['twofactor_enforced', 'false', 'false'],
74
-				['twofactor_enforced_groups', [], []],
75
-				['twofactor_enforced_excluded_groups', [], []],
76
-			]);
77
-
78
-		$isEnforced = $this->mandatoryTwoFactor->isEnforcedFor($user);
79
-
80
-		$this->assertFalse($isEnforced);
81
-	}
82
-
83
-	public function testIsEnforcedForAGroupMember(): void {
84
-		$user = $this->createMock(IUser::class);
85
-		$user->method('getUID')->willReturn('user123');
86
-		$this->config
87
-			->method('getSystemValue')
88
-			->willReturnMap([
89
-				['twofactor_enforced', 'false', 'true'],
90
-				['twofactor_enforced_groups', [], ['twofactorers']],
91
-				['twofactor_enforced_excluded_groups', [], []],
92
-			]);
93
-		$this->groupManager->method('isInGroup')
94
-			->willReturnCallback(function ($user, $group) {
95
-				return $user === 'user123' && $group === 'twofactorers';
96
-			});
97
-
98
-		$isEnforced = $this->mandatoryTwoFactor->isEnforcedFor($user);
99
-
100
-		$this->assertTrue($isEnforced);
101
-	}
102
-
103
-	public function testIsEnforcedForOtherGroups(): void {
104
-		$user = $this->createMock(IUser::class);
105
-		$user->method('getUID')->willReturn('user123');
106
-		$this->config
107
-			->method('getSystemValue')
108
-			->willReturnMap([
109
-				['twofactor_enforced', 'false', 'true'],
110
-				['twofactor_enforced_groups', [], ['twofactorers']],
111
-				['twofactor_enforced_excluded_groups', [], []],
112
-			]);
113
-		$this->groupManager->method('isInGroup')
114
-			->willReturn(false);
115
-
116
-		$isEnforced = $this->mandatoryTwoFactor->isEnforcedFor($user);
117
-
118
-		$this->assertFalse($isEnforced);
119
-	}
120
-
121
-	public function testIsEnforcedButMemberOfExcludedGroup(): void {
122
-		$user = $this->createMock(IUser::class);
123
-		$user->method('getUID')->willReturn('user123');
124
-		$this->config
125
-			->method('getSystemValue')
126
-			->willReturnMap([
127
-				['twofactor_enforced', 'false', 'true'],
128
-				['twofactor_enforced_groups', [], []],
129
-				['twofactor_enforced_excluded_groups', [], ['yoloers']],
130
-			]);
131
-		$this->groupManager->method('isInGroup')
132
-			->willReturnCallback(function ($user, $group) {
133
-				return $user === 'user123' && $group === 'yoloers';
134
-			});
135
-
136
-		$isEnforced = $this->mandatoryTwoFactor->isEnforcedFor($user);
137
-
138
-		$this->assertFalse($isEnforced);
139
-	}
140
-
141
-	public function testSetEnforced(): void {
142
-		$this->config
143
-			->expects($this->exactly(3))
144
-			->method('setSystemValue')
145
-			->willReturnMap([
146
-				['twofactor_enforced', 'true'],
147
-				['twofactor_enforced_groups', []],
148
-				['twofactor_enforced_excluded_groups', []],
149
-			]);
150
-
151
-		$this->mandatoryTwoFactor->setState(new EnforcementState(true));
152
-	}
153
-
154
-	public function testSetEnforcedForGroups(): void {
155
-		$this->config
156
-			->expects($this->exactly(3))
157
-			->method('setSystemValue')
158
-			->willReturnMap([
159
-				['twofactor_enforced', 'true'],
160
-				['twofactor_enforced_groups', ['twofactorers']],
161
-				['twofactor_enforced_excluded_groups', ['yoloers']],
162
-			]);
163
-
164
-		$this->mandatoryTwoFactor->setState(new EnforcementState(true, ['twofactorers'], ['yoloers']));
165
-	}
166
-
167
-	public function testSetNotEnforced(): void {
168
-		$this->config
169
-			->expects($this->exactly(3))
170
-			->method('setSystemValue')
171
-			->willReturnMap([
172
-				['twofactor_enforced', 'false'],
173
-				['twofactor_enforced_groups', []],
174
-				['twofactor_enforced_excluded_groups', []],
175
-			]);
176
-
177
-		$this->mandatoryTwoFactor->setState(new EnforcementState(false));
178
-	}
21
+    /** @var IConfig|MockObject */
22
+    private $config;
23
+
24
+    /** @var IGroupManager|MockObject */
25
+    private $groupManager;
26
+
27
+    /** @var MandatoryTwoFactor */
28
+    private $mandatoryTwoFactor;
29
+
30
+    protected function setUp(): void {
31
+        parent::setUp();
32
+
33
+        $this->config = $this->createMock(IConfig::class);
34
+        $this->groupManager = $this->createMock(IGroupManager::class);
35
+
36
+        $this->mandatoryTwoFactor = new MandatoryTwoFactor($this->config, $this->groupManager);
37
+    }
38
+
39
+    public function testIsNotEnforced(): void {
40
+        $this->config
41
+            ->method('getSystemValue')
42
+            ->willReturnMap([
43
+                ['twofactor_enforced', 'false', 'false'],
44
+                ['twofactor_enforced_groups', [], []],
45
+                ['twofactor_enforced_excluded_groups', [], []],
46
+            ]);
47
+
48
+        $state = $this->mandatoryTwoFactor->getState();
49
+
50
+        $this->assertFalse($state->isEnforced());
51
+    }
52
+
53
+    public function testIsEnforced(): void {
54
+        $this->config
55
+            ->method('getSystemValue')
56
+            ->willReturnMap([
57
+                ['twofactor_enforced', 'false', 'true'],
58
+                ['twofactor_enforced_groups', [], []],
59
+                ['twofactor_enforced_excluded_groups', [], []],
60
+            ]);
61
+
62
+        $state = $this->mandatoryTwoFactor->getState();
63
+
64
+        $this->assertTrue($state->isEnforced());
65
+    }
66
+
67
+    public function testIsNotEnforcedForAnybody(): void {
68
+        $user = $this->createMock(IUser::class);
69
+        $user->method('getUID')->willReturn('user123');
70
+        $this->config
71
+            ->method('getSystemValue')
72
+            ->willReturnMap([
73
+                ['twofactor_enforced', 'false', 'false'],
74
+                ['twofactor_enforced_groups', [], []],
75
+                ['twofactor_enforced_excluded_groups', [], []],
76
+            ]);
77
+
78
+        $isEnforced = $this->mandatoryTwoFactor->isEnforcedFor($user);
79
+
80
+        $this->assertFalse($isEnforced);
81
+    }
82
+
83
+    public function testIsEnforcedForAGroupMember(): void {
84
+        $user = $this->createMock(IUser::class);
85
+        $user->method('getUID')->willReturn('user123');
86
+        $this->config
87
+            ->method('getSystemValue')
88
+            ->willReturnMap([
89
+                ['twofactor_enforced', 'false', 'true'],
90
+                ['twofactor_enforced_groups', [], ['twofactorers']],
91
+                ['twofactor_enforced_excluded_groups', [], []],
92
+            ]);
93
+        $this->groupManager->method('isInGroup')
94
+            ->willReturnCallback(function ($user, $group) {
95
+                return $user === 'user123' && $group === 'twofactorers';
96
+            });
97
+
98
+        $isEnforced = $this->mandatoryTwoFactor->isEnforcedFor($user);
99
+
100
+        $this->assertTrue($isEnforced);
101
+    }
102
+
103
+    public function testIsEnforcedForOtherGroups(): void {
104
+        $user = $this->createMock(IUser::class);
105
+        $user->method('getUID')->willReturn('user123');
106
+        $this->config
107
+            ->method('getSystemValue')
108
+            ->willReturnMap([
109
+                ['twofactor_enforced', 'false', 'true'],
110
+                ['twofactor_enforced_groups', [], ['twofactorers']],
111
+                ['twofactor_enforced_excluded_groups', [], []],
112
+            ]);
113
+        $this->groupManager->method('isInGroup')
114
+            ->willReturn(false);
115
+
116
+        $isEnforced = $this->mandatoryTwoFactor->isEnforcedFor($user);
117
+
118
+        $this->assertFalse($isEnforced);
119
+    }
120
+
121
+    public function testIsEnforcedButMemberOfExcludedGroup(): void {
122
+        $user = $this->createMock(IUser::class);
123
+        $user->method('getUID')->willReturn('user123');
124
+        $this->config
125
+            ->method('getSystemValue')
126
+            ->willReturnMap([
127
+                ['twofactor_enforced', 'false', 'true'],
128
+                ['twofactor_enforced_groups', [], []],
129
+                ['twofactor_enforced_excluded_groups', [], ['yoloers']],
130
+            ]);
131
+        $this->groupManager->method('isInGroup')
132
+            ->willReturnCallback(function ($user, $group) {
133
+                return $user === 'user123' && $group === 'yoloers';
134
+            });
135
+
136
+        $isEnforced = $this->mandatoryTwoFactor->isEnforcedFor($user);
137
+
138
+        $this->assertFalse($isEnforced);
139
+    }
140
+
141
+    public function testSetEnforced(): void {
142
+        $this->config
143
+            ->expects($this->exactly(3))
144
+            ->method('setSystemValue')
145
+            ->willReturnMap([
146
+                ['twofactor_enforced', 'true'],
147
+                ['twofactor_enforced_groups', []],
148
+                ['twofactor_enforced_excluded_groups', []],
149
+            ]);
150
+
151
+        $this->mandatoryTwoFactor->setState(new EnforcementState(true));
152
+    }
153
+
154
+    public function testSetEnforcedForGroups(): void {
155
+        $this->config
156
+            ->expects($this->exactly(3))
157
+            ->method('setSystemValue')
158
+            ->willReturnMap([
159
+                ['twofactor_enforced', 'true'],
160
+                ['twofactor_enforced_groups', ['twofactorers']],
161
+                ['twofactor_enforced_excluded_groups', ['yoloers']],
162
+            ]);
163
+
164
+        $this->mandatoryTwoFactor->setState(new EnforcementState(true, ['twofactorers'], ['yoloers']));
165
+    }
166
+
167
+    public function testSetNotEnforced(): void {
168
+        $this->config
169
+            ->expects($this->exactly(3))
170
+            ->method('setSystemValue')
171
+            ->willReturnMap([
172
+                ['twofactor_enforced', 'false'],
173
+                ['twofactor_enforced_groups', []],
174
+                ['twofactor_enforced_excluded_groups', []],
175
+            ]);
176
+
177
+        $this->mandatoryTwoFactor->setState(new EnforcementState(false));
178
+    }
179 179
 }
Please login to merge, or discard this patch.
tests/lib/Authentication/TwoFactorAuth/ProviderSetTest.php 1 patch
Indentation   +57 added lines, -57 removed lines patch added patch discarded remove patch
@@ -15,61 +15,61 @@
 block discarded – undo
15 15
 use Test\TestCase;
16 16
 
17 17
 class ProviderSetTest extends TestCase {
18
-	/** @var ProviderSet */
19
-	private $providerSet;
20
-
21
-	public function testIndexesProviders(): void {
22
-		$p1 = $this->createMock(IProvider::class);
23
-		$p1->method('getId')->willReturn('p1');
24
-		$p2 = $this->createMock(IProvider::class);
25
-		$p2->method('getId')->willReturn('p2');
26
-		$expected = [
27
-			'p1' => $p1,
28
-			'p2' => $p2,
29
-		];
30
-
31
-		$set = new ProviderSet([$p2, $p1], false);
32
-
33
-		$this->assertEquals($expected, $set->getProviders());
34
-	}
35
-
36
-	public function testGet3rdPartyProviders(): void {
37
-		$p1 = $this->createMock(IProvider::class);
38
-		$p1->method('getId')->willReturn('p1');
39
-		$p2 = $this->createMock(IProvider::class);
40
-		$p2->method('getId')->willReturn('p2');
41
-		$p3 = $this->createMock(BackupCodesProvider::class);
42
-		$p3->method('getId')->willReturn('p3');
43
-		$expected = [
44
-			'p1' => $p1,
45
-			'p2' => $p2,
46
-		];
47
-
48
-		$set = new ProviderSet([$p2, $p1], false);
49
-
50
-		$this->assertEquals($expected, $set->getPrimaryProviders());
51
-	}
52
-
53
-	public function testGetProvider(): void {
54
-		$p1 = $this->createMock(IProvider::class);
55
-		$p1->method('getId')->willReturn('p1');
56
-
57
-		$set = new ProviderSet([$p1], false);
58
-		$provider = $set->getProvider('p1');
59
-
60
-		$this->assertEquals($p1, $provider);
61
-	}
62
-
63
-	public function testGetProviderNotFound(): void {
64
-		$set = new ProviderSet([], false);
65
-		$provider = $set->getProvider('p1');
66
-
67
-		$this->assertNull($provider);
68
-	}
69
-
70
-	public function testIsProviderMissing(): void {
71
-		$set = new ProviderSet([], true);
72
-
73
-		$this->assertTrue($set->isProviderMissing());
74
-	}
18
+    /** @var ProviderSet */
19
+    private $providerSet;
20
+
21
+    public function testIndexesProviders(): void {
22
+        $p1 = $this->createMock(IProvider::class);
23
+        $p1->method('getId')->willReturn('p1');
24
+        $p2 = $this->createMock(IProvider::class);
25
+        $p2->method('getId')->willReturn('p2');
26
+        $expected = [
27
+            'p1' => $p1,
28
+            'p2' => $p2,
29
+        ];
30
+
31
+        $set = new ProviderSet([$p2, $p1], false);
32
+
33
+        $this->assertEquals($expected, $set->getProviders());
34
+    }
35
+
36
+    public function testGet3rdPartyProviders(): void {
37
+        $p1 = $this->createMock(IProvider::class);
38
+        $p1->method('getId')->willReturn('p1');
39
+        $p2 = $this->createMock(IProvider::class);
40
+        $p2->method('getId')->willReturn('p2');
41
+        $p3 = $this->createMock(BackupCodesProvider::class);
42
+        $p3->method('getId')->willReturn('p3');
43
+        $expected = [
44
+            'p1' => $p1,
45
+            'p2' => $p2,
46
+        ];
47
+
48
+        $set = new ProviderSet([$p2, $p1], false);
49
+
50
+        $this->assertEquals($expected, $set->getPrimaryProviders());
51
+    }
52
+
53
+    public function testGetProvider(): void {
54
+        $p1 = $this->createMock(IProvider::class);
55
+        $p1->method('getId')->willReturn('p1');
56
+
57
+        $set = new ProviderSet([$p1], false);
58
+        $provider = $set->getProvider('p1');
59
+
60
+        $this->assertEquals($p1, $provider);
61
+    }
62
+
63
+    public function testGetProviderNotFound(): void {
64
+        $set = new ProviderSet([], false);
65
+        $provider = $set->getProvider('p1');
66
+
67
+        $this->assertNull($provider);
68
+    }
69
+
70
+    public function testIsProviderMissing(): void {
71
+        $set = new ProviderSet([], true);
72
+
73
+        $this->assertTrue($set->isProviderMissing());
74
+    }
75 75
 }
Please login to merge, or discard this patch.
tests/lib/Authentication/TwoFactorAuth/EnforcementStateTest.php 1 patch
Indentation   +22 added lines, -22 removed lines patch added patch discarded remove patch
@@ -17,34 +17,34 @@
 block discarded – undo
17 17
 use Test\TestCase;
18 18
 
19 19
 class EnforcementStateTest extends TestCase {
20
-	public function testIsEnforced(): void {
21
-		$state = new EnforcementState(true);
20
+    public function testIsEnforced(): void {
21
+        $state = new EnforcementState(true);
22 22
 
23
-		$this->assertTrue($state->isEnforced());
24
-	}
23
+        $this->assertTrue($state->isEnforced());
24
+    }
25 25
 
26
-	public function testGetEnforcedGroups(): void {
27
-		$state = new EnforcementState(true, ['twofactorers']);
26
+    public function testGetEnforcedGroups(): void {
27
+        $state = new EnforcementState(true, ['twofactorers']);
28 28
 
29
-		$this->assertEquals(['twofactorers'], $state->getEnforcedGroups());
30
-	}
29
+        $this->assertEquals(['twofactorers'], $state->getEnforcedGroups());
30
+    }
31 31
 
32
-	public function testGetExcludedGroups(): void {
33
-		$state = new EnforcementState(true, [], ['yoloers']);
32
+    public function testGetExcludedGroups(): void {
33
+        $state = new EnforcementState(true, [], ['yoloers']);
34 34
 
35
-		$this->assertEquals(['yoloers'], $state->getExcludedGroups());
36
-	}
35
+        $this->assertEquals(['yoloers'], $state->getExcludedGroups());
36
+    }
37 37
 
38
-	public function testJsonSerialize(): void {
39
-		$state = new EnforcementState(true, ['twofactorers'], ['yoloers']);
40
-		$expected = [
41
-			'enforced' => true,
42
-			'enforcedGroups' => ['twofactorers'],
43
-			'excludedGroups' => ['yoloers'],
44
-		];
38
+    public function testJsonSerialize(): void {
39
+        $state = new EnforcementState(true, ['twofactorers'], ['yoloers']);
40
+        $expected = [
41
+            'enforced' => true,
42
+            'enforcedGroups' => ['twofactorers'],
43
+            'excludedGroups' => ['yoloers'],
44
+        ];
45 45
 
46
-		$json = $state->jsonSerialize();
46
+        $json = $state->jsonSerialize();
47 47
 
48
-		$this->assertEquals($expected, $json);
49
-	}
48
+        $this->assertEquals($expected, $json);
49
+    }
50 50
 }
Please login to merge, or discard this patch.
tests/lib/Authentication/Events/RemoteWipeStartedTest.php 1 patch
Indentation   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -14,10 +14,10 @@
 block discarded – undo
14 14
 use Test\TestCase;
15 15
 
16 16
 class RemoteWipeStartedTest extends TestCase {
17
-	public function testGetToken(): void {
18
-		$token = $this->createMock(IToken::class);
19
-		$event = new RemoteWipeStarted($token);
17
+    public function testGetToken(): void {
18
+        $token = $this->createMock(IToken::class);
19
+        $event = new RemoteWipeStarted($token);
20 20
 
21
-		$this->assertSame($token, $event->getToken());
22
-	}
21
+        $this->assertSame($token, $event->getToken());
22
+    }
23 23
 }
Please login to merge, or discard this patch.
tests/lib/Authentication/Events/RemoteWipeFinishedTest.php 1 patch
Indentation   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -14,10 +14,10 @@
 block discarded – undo
14 14
 use Test\TestCase;
15 15
 
16 16
 class RemoteWipeFinishedTest extends TestCase {
17
-	public function testGetToken(): void {
18
-		$token = $this->createMock(IToken::class);
19
-		$event = new RemoteWipeFinished($token);
17
+    public function testGetToken(): void {
18
+        $token = $this->createMock(IToken::class);
19
+        $event = new RemoteWipeFinished($token);
20 20
 
21
-		$this->assertSame($token, $event->getToken());
22
-	}
21
+        $this->assertSame($token, $event->getToken());
22
+    }
23 23
 }
Please login to merge, or discard this patch.
tests/lib/Authentication/LoginCredentials/CredentialsTest.php 1 patch
Indentation   +24 added lines, -24 removed lines patch added patch discarded remove patch
@@ -11,37 +11,37 @@
 block discarded – undo
11 11
 use Test\TestCase;
12 12
 
13 13
 class CredentialsTest extends TestCase {
14
-	/** @var string */
15
-	private $uid;
14
+    /** @var string */
15
+    private $uid;
16 16
 
17
-	/** @var string */
18
-	private $user;
17
+    /** @var string */
18
+    private $user;
19 19
 
20
-	/** @var string */
21
-	private $password;
20
+    /** @var string */
21
+    private $password;
22 22
 
23
-	/** @var Credentials */
24
-	private $credentials;
23
+    /** @var Credentials */
24
+    private $credentials;
25 25
 
26
-	protected function setUp(): void {
27
-		parent::setUp();
26
+    protected function setUp(): void {
27
+        parent::setUp();
28 28
 
29
-		$this->uid = 'user123';
30
-		$this->user = 'User123';
31
-		$this->password = '123456';
29
+        $this->uid = 'user123';
30
+        $this->user = 'User123';
31
+        $this->password = '123456';
32 32
 
33
-		$this->credentials = new Credentials($this->uid, $this->user, $this->password);
34
-	}
33
+        $this->credentials = new Credentials($this->uid, $this->user, $this->password);
34
+    }
35 35
 
36
-	public function testGetUID(): void {
37
-		$this->assertEquals($this->uid, $this->credentials->getUID());
38
-	}
36
+    public function testGetUID(): void {
37
+        $this->assertEquals($this->uid, $this->credentials->getUID());
38
+    }
39 39
 
40
-	public function testGetUserName(): void {
41
-		$this->assertEquals($this->user, $this->credentials->getLoginName());
42
-	}
40
+    public function testGetUserName(): void {
41
+        $this->assertEquals($this->user, $this->credentials->getLoginName());
42
+    }
43 43
 
44
-	public function testGetPassword(): void {
45
-		$this->assertEquals($this->password, $this->credentials->getPassword());
46
-	}
44
+    public function testGetPassword(): void {
45
+        $this->assertEquals($this->password, $this->credentials->getPassword());
46
+    }
47 47
 }
Please login to merge, or discard this patch.
tests/lib/Authentication/Listeners/RemoteWipeActivityListenerTest.php 1 patch
Indentation   +112 added lines, -112 removed lines patch added patch discarded remove patch
@@ -22,116 +22,116 @@
 block discarded – undo
22 22
 use Test\TestCase;
23 23
 
24 24
 class RemoteWipeActivityListenerTest extends TestCase {
25
-	/** @var IActivityManager|MockObject */
26
-	private $activityManager;
27
-
28
-	/** @var LoggerInterface|MockObject */
29
-	private $logger;
30
-
31
-	/** @var IEventListener */
32
-	private $listener;
33
-
34
-	protected function setUp(): void {
35
-		parent::setUp();
36
-
37
-		$this->activityManager = $this->createMock(IActivityManager::class);
38
-		$this->logger = $this->createMock(LoggerInterface::class);
39
-
40
-		$this->listener = new RemoteWipeActivityListener(
41
-			$this->activityManager,
42
-			$this->logger
43
-		);
44
-	}
45
-
46
-	public function testHandleUnrelated(): void {
47
-		$event = new Event();
48
-
49
-		$this->listener->handle($event);
50
-
51
-		$this->addToAssertionCount(1);
52
-	}
53
-
54
-	public function testHandleRemoteWipeStarted(): void {
55
-		/** @var IToken|MockObject $token */
56
-		$token = $this->createMock(IToken::class);
57
-		$event = new RemoteWipeStarted($token);
58
-		$activityEvent = $this->createMock(IActivityEvent::class);
59
-		$this->activityManager->expects($this->once())
60
-			->method('generateEvent')
61
-			->willReturn($activityEvent);
62
-		$activityEvent->expects($this->once())
63
-			->method('setApp')
64
-			->with('core')
65
-			->willReturnSelf();
66
-		$activityEvent->expects($this->once())
67
-			->method('setType')
68
-			->with('security')
69
-			->willReturnSelf();
70
-		$token->method('getUID')->willReturn('user123');
71
-		$activityEvent->expects($this->once())
72
-			->method('setAuthor')
73
-			->with('user123')
74
-			->willReturnSelf();
75
-		$activityEvent->expects($this->once())
76
-			->method('setAffectedUser')
77
-			->with('user123')
78
-			->willReturnSelf();
79
-		$token->method('getName')->willReturn('Token 1');
80
-		$activityEvent->expects($this->once())
81
-			->method('setSubject')
82
-			->with('remote_wipe_start', ['name' => 'Token 1'])
83
-			->willReturnSelf();
84
-		$this->activityManager->expects($this->once())
85
-			->method('publish');
86
-
87
-		$this->listener->handle($event);
88
-	}
89
-
90
-	public function testHandleRemoteWipeStartedCanNotPublish(): void {
91
-		$token = $this->createMock(IToken::class);
92
-		$event = new RemoteWipeStarted($token);
93
-		$this->activityManager->expects($this->once())
94
-			->method('generateEvent');
95
-		$this->activityManager->expects($this->once())
96
-			->method('publish')
97
-			->willThrowException(new \BadMethodCallException());
98
-
99
-		$this->listener->handle($event);
100
-	}
101
-
102
-	public function testHandleRemoteWipeFinished(): void {
103
-		/** @var IToken|MockObject $token */
104
-		$token = $this->createMock(IToken::class);
105
-		$event = new RemoteWipeFinished($token);
106
-		$activityEvent = $this->createMock(IActivityEvent::class);
107
-		$this->activityManager->expects($this->once())
108
-			->method('generateEvent')
109
-			->willReturn($activityEvent);
110
-		$activityEvent->expects($this->once())
111
-			->method('setApp')
112
-			->with('core')
113
-			->willReturnSelf();
114
-		$activityEvent->expects($this->once())
115
-			->method('setType')
116
-			->with('security')
117
-			->willReturnSelf();
118
-		$token->method('getUID')->willReturn('user123');
119
-		$activityEvent->expects($this->once())
120
-			->method('setAuthor')
121
-			->with('user123')
122
-			->willReturnSelf();
123
-		$activityEvent->expects($this->once())
124
-			->method('setAffectedUser')
125
-			->with('user123')
126
-			->willReturnSelf();
127
-		$token->method('getName')->willReturn('Token 1');
128
-		$activityEvent->expects($this->once())
129
-			->method('setSubject')
130
-			->with('remote_wipe_finish', ['name' => 'Token 1'])
131
-			->willReturnSelf();
132
-		$this->activityManager->expects($this->once())
133
-			->method('publish');
134
-
135
-		$this->listener->handle($event);
136
-	}
25
+    /** @var IActivityManager|MockObject */
26
+    private $activityManager;
27
+
28
+    /** @var LoggerInterface|MockObject */
29
+    private $logger;
30
+
31
+    /** @var IEventListener */
32
+    private $listener;
33
+
34
+    protected function setUp(): void {
35
+        parent::setUp();
36
+
37
+        $this->activityManager = $this->createMock(IActivityManager::class);
38
+        $this->logger = $this->createMock(LoggerInterface::class);
39
+
40
+        $this->listener = new RemoteWipeActivityListener(
41
+            $this->activityManager,
42
+            $this->logger
43
+        );
44
+    }
45
+
46
+    public function testHandleUnrelated(): void {
47
+        $event = new Event();
48
+
49
+        $this->listener->handle($event);
50
+
51
+        $this->addToAssertionCount(1);
52
+    }
53
+
54
+    public function testHandleRemoteWipeStarted(): void {
55
+        /** @var IToken|MockObject $token */
56
+        $token = $this->createMock(IToken::class);
57
+        $event = new RemoteWipeStarted($token);
58
+        $activityEvent = $this->createMock(IActivityEvent::class);
59
+        $this->activityManager->expects($this->once())
60
+            ->method('generateEvent')
61
+            ->willReturn($activityEvent);
62
+        $activityEvent->expects($this->once())
63
+            ->method('setApp')
64
+            ->with('core')
65
+            ->willReturnSelf();
66
+        $activityEvent->expects($this->once())
67
+            ->method('setType')
68
+            ->with('security')
69
+            ->willReturnSelf();
70
+        $token->method('getUID')->willReturn('user123');
71
+        $activityEvent->expects($this->once())
72
+            ->method('setAuthor')
73
+            ->with('user123')
74
+            ->willReturnSelf();
75
+        $activityEvent->expects($this->once())
76
+            ->method('setAffectedUser')
77
+            ->with('user123')
78
+            ->willReturnSelf();
79
+        $token->method('getName')->willReturn('Token 1');
80
+        $activityEvent->expects($this->once())
81
+            ->method('setSubject')
82
+            ->with('remote_wipe_start', ['name' => 'Token 1'])
83
+            ->willReturnSelf();
84
+        $this->activityManager->expects($this->once())
85
+            ->method('publish');
86
+
87
+        $this->listener->handle($event);
88
+    }
89
+
90
+    public function testHandleRemoteWipeStartedCanNotPublish(): void {
91
+        $token = $this->createMock(IToken::class);
92
+        $event = new RemoteWipeStarted($token);
93
+        $this->activityManager->expects($this->once())
94
+            ->method('generateEvent');
95
+        $this->activityManager->expects($this->once())
96
+            ->method('publish')
97
+            ->willThrowException(new \BadMethodCallException());
98
+
99
+        $this->listener->handle($event);
100
+    }
101
+
102
+    public function testHandleRemoteWipeFinished(): void {
103
+        /** @var IToken|MockObject $token */
104
+        $token = $this->createMock(IToken::class);
105
+        $event = new RemoteWipeFinished($token);
106
+        $activityEvent = $this->createMock(IActivityEvent::class);
107
+        $this->activityManager->expects($this->once())
108
+            ->method('generateEvent')
109
+            ->willReturn($activityEvent);
110
+        $activityEvent->expects($this->once())
111
+            ->method('setApp')
112
+            ->with('core')
113
+            ->willReturnSelf();
114
+        $activityEvent->expects($this->once())
115
+            ->method('setType')
116
+            ->with('security')
117
+            ->willReturnSelf();
118
+        $token->method('getUID')->willReturn('user123');
119
+        $activityEvent->expects($this->once())
120
+            ->method('setAuthor')
121
+            ->with('user123')
122
+            ->willReturnSelf();
123
+        $activityEvent->expects($this->once())
124
+            ->method('setAffectedUser')
125
+            ->with('user123')
126
+            ->willReturnSelf();
127
+        $token->method('getName')->willReturn('Token 1');
128
+        $activityEvent->expects($this->once())
129
+            ->method('setSubject')
130
+            ->with('remote_wipe_finish', ['name' => 'Token 1'])
131
+            ->willReturnSelf();
132
+        $this->activityManager->expects($this->once())
133
+            ->method('publish');
134
+
135
+        $this->listener->handle($event);
136
+    }
137 137
 }
Please login to merge, or discard this patch.
tests/lib/Authentication/Listeners/RemoteWipeEmailListenerTest.php 1 patch
Indentation   +195 added lines, -195 removed lines patch added patch discarded remove patch
@@ -27,199 +27,199 @@
 block discarded – undo
27 27
 use Test\TestCase;
28 28
 
29 29
 class RemoteWipeEmailListenerTest extends TestCase {
30
-	/** @var IMailer|MockObject */
31
-	private $mailer;
32
-
33
-	/** @var IUserManager|MockObject */
34
-	private $userManager;
35
-
36
-	/** @var IFactory|MockObject */
37
-	private $l10nFactory;
38
-
39
-	/** @var IL10N|MockObject */
40
-	private $l10n;
41
-
42
-	/** @var LoggerInterface|MockObject */
43
-	private $logger;
44
-
45
-	/** @var IEventListener */
46
-	private $listener;
47
-
48
-	protected function setUp(): void {
49
-		parent::setUp();
50
-
51
-		$this->mailer = $this->createMock(IMailer::class);
52
-		$this->userManager = $this->createMock(IUserManager::class);
53
-		$this->l10nFactory = $this->createMock(IFactory::class);
54
-		$this->l10n = $this->createMock(IL10N::class);
55
-		$this->logger = $this->createMock(LoggerInterface::class);
56
-
57
-		$this->l10nFactory->method('get')->with('core')->willReturn($this->l10n);
58
-		$this->l10n->method('t')->willReturnArgument(0);
59
-
60
-		$this->listener = new RemoteWipeEmailListener(
61
-			$this->mailer,
62
-			$this->userManager,
63
-			$this->l10nFactory,
64
-			$this->logger
65
-		);
66
-	}
67
-
68
-
69
-	public function testHandleUnrelated(): void {
70
-		$event = new Event();
71
-		$this->mailer->expects($this->never())->method('send');
72
-
73
-		$this->listener->handle($event);
74
-	}
75
-
76
-	public function testHandleRemoteWipeStartedInvalidUser(): void {
77
-		/** @var IToken|MockObject $token */
78
-		$token = $this->createMock(IToken::class);
79
-		$event = new RemoteWipeStarted($token);
80
-		$token->method('getUID')->willReturn('nope');
81
-		$this->userManager->expects($this->once())
82
-			->method('get')
83
-			->with('nope')
84
-			->willReturn(null);
85
-		$this->mailer->expects($this->never())->method('send');
86
-
87
-		$this->listener->handle($event);
88
-	}
89
-
90
-	public function testHandleRemoteWipeStartedNoEmailSet(): void {
91
-		/** @var IToken|MockObject $token */
92
-		$token = $this->createMock(IToken::class);
93
-		$event = new RemoteWipeStarted($token);
94
-		$token->method('getUID')->willReturn('nope');
95
-		$user = $this->createMock(IUser::class);
96
-		$this->userManager->expects($this->once())
97
-			->method('get')
98
-			->with('nope')
99
-			->willReturn($user);
100
-		$user->method('getEMailAddress')->willReturn(null);
101
-		$this->mailer->expects($this->never())->method('send');
102
-
103
-		$this->listener->handle($event);
104
-	}
105
-
106
-	public function testHandleRemoteWipeStartedTransmissionError(): void {
107
-		/** @var IToken|MockObject $token */
108
-		$token = $this->createMock(IToken::class);
109
-		$event = new RemoteWipeStarted($token);
110
-		$token->method('getUID')->willReturn('nope');
111
-		$user = $this->createMock(IUser::class);
112
-		$this->userManager->expects($this->once())
113
-			->method('get')
114
-			->with('nope')
115
-			->willReturn($user);
116
-		$user->method('getEMailAddress')->willReturn('[email protected]');
117
-		$this->mailer->expects($this->once())
118
-			->method('send')
119
-			->willThrowException(new Exception());
120
-		$this->logger->expects($this->once())
121
-			->method('error');
122
-
123
-		$this->listener->handle($event);
124
-	}
125
-
126
-	public function testHandleRemoteWipeStarted(): void {
127
-		/** @var IToken|MockObject $token */
128
-		$token = $this->createMock(IToken::class);
129
-		$event = new RemoteWipeStarted($token);
130
-		$token->method('getUID')->willReturn('nope');
131
-		$user = $this->createMock(IUser::class);
132
-		$this->userManager->expects($this->once())
133
-			->method('get')
134
-			->with('nope')
135
-			->willReturn($user);
136
-		$user->method('getEMailAddress')->willReturn('[email protected]');
137
-		$message = $this->createMock(IMessage::class);
138
-		$this->mailer->expects($this->once())
139
-			->method('createMessage')
140
-			->willReturn($message);
141
-		$message->expects($this->once())
142
-			->method('setTo')
143
-			->with($this->equalTo(['[email protected]']));
144
-		$this->mailer->expects($this->once())
145
-			->method('send')
146
-			->with($message);
147
-
148
-		$this->listener->handle($event);
149
-	}
150
-
151
-	public function testHandleRemoteWipeFinishedInvalidUser(): void {
152
-		/** @var IToken|MockObject $token */
153
-		$token = $this->createMock(IToken::class);
154
-		$event = new RemoteWipeFinished($token);
155
-		$token->method('getUID')->willReturn('nope');
156
-		$this->userManager->expects($this->once())
157
-			->method('get')
158
-			->with('nope')
159
-			->willReturn(null);
160
-		$this->mailer->expects($this->never())->method('send');
161
-
162
-		$this->listener->handle($event);
163
-	}
164
-
165
-	public function testHandleRemoteWipeFinishedNoEmailSet(): void {
166
-		/** @var IToken|MockObject $token */
167
-		$token = $this->createMock(IToken::class);
168
-		$event = new RemoteWipeFinished($token);
169
-		$token->method('getUID')->willReturn('nope');
170
-		$user = $this->createMock(IUser::class);
171
-		$this->userManager->expects($this->once())
172
-			->method('get')
173
-			->with('nope')
174
-			->willReturn($user);
175
-		$user->method('getEMailAddress')->willReturn(null);
176
-		$this->mailer->expects($this->never())->method('send');
177
-
178
-		$this->listener->handle($event);
179
-	}
180
-
181
-	public function testHandleRemoteWipeFinishedTransmissionError(): void {
182
-		/** @var IToken|MockObject $token */
183
-		$token = $this->createMock(IToken::class);
184
-		$event = new RemoteWipeFinished($token);
185
-		$token->method('getUID')->willReturn('nope');
186
-		$user = $this->createMock(IUser::class);
187
-		$this->userManager->expects($this->once())
188
-			->method('get')
189
-			->with('nope')
190
-			->willReturn($user);
191
-		$user->method('getEMailAddress')->willReturn('[email protected]');
192
-		$this->mailer->expects($this->once())
193
-			->method('send')
194
-			->willThrowException(new Exception());
195
-		$this->logger->expects($this->once())
196
-			->method('error');
197
-
198
-		$this->listener->handle($event);
199
-	}
200
-
201
-	public function testHandleRemoteWipeFinished(): void {
202
-		/** @var IToken|MockObject $token */
203
-		$token = $this->createMock(IToken::class);
204
-		$event = new RemoteWipeFinished($token);
205
-		$token->method('getUID')->willReturn('nope');
206
-		$user = $this->createMock(IUser::class);
207
-		$this->userManager->expects($this->once())
208
-			->method('get')
209
-			->with('nope')
210
-			->willReturn($user);
211
-		$user->method('getEMailAddress')->willReturn('[email protected]');
212
-		$message = $this->createMock(IMessage::class);
213
-		$this->mailer->expects($this->once())
214
-			->method('createMessage')
215
-			->willReturn($message);
216
-		$message->expects($this->once())
217
-			->method('setTo')
218
-			->with($this->equalTo(['[email protected]']));
219
-		$this->mailer->expects($this->once())
220
-			->method('send')
221
-			->with($message);
222
-
223
-		$this->listener->handle($event);
224
-	}
30
+    /** @var IMailer|MockObject */
31
+    private $mailer;
32
+
33
+    /** @var IUserManager|MockObject */
34
+    private $userManager;
35
+
36
+    /** @var IFactory|MockObject */
37
+    private $l10nFactory;
38
+
39
+    /** @var IL10N|MockObject */
40
+    private $l10n;
41
+
42
+    /** @var LoggerInterface|MockObject */
43
+    private $logger;
44
+
45
+    /** @var IEventListener */
46
+    private $listener;
47
+
48
+    protected function setUp(): void {
49
+        parent::setUp();
50
+
51
+        $this->mailer = $this->createMock(IMailer::class);
52
+        $this->userManager = $this->createMock(IUserManager::class);
53
+        $this->l10nFactory = $this->createMock(IFactory::class);
54
+        $this->l10n = $this->createMock(IL10N::class);
55
+        $this->logger = $this->createMock(LoggerInterface::class);
56
+
57
+        $this->l10nFactory->method('get')->with('core')->willReturn($this->l10n);
58
+        $this->l10n->method('t')->willReturnArgument(0);
59
+
60
+        $this->listener = new RemoteWipeEmailListener(
61
+            $this->mailer,
62
+            $this->userManager,
63
+            $this->l10nFactory,
64
+            $this->logger
65
+        );
66
+    }
67
+
68
+
69
+    public function testHandleUnrelated(): void {
70
+        $event = new Event();
71
+        $this->mailer->expects($this->never())->method('send');
72
+
73
+        $this->listener->handle($event);
74
+    }
75
+
76
+    public function testHandleRemoteWipeStartedInvalidUser(): void {
77
+        /** @var IToken|MockObject $token */
78
+        $token = $this->createMock(IToken::class);
79
+        $event = new RemoteWipeStarted($token);
80
+        $token->method('getUID')->willReturn('nope');
81
+        $this->userManager->expects($this->once())
82
+            ->method('get')
83
+            ->with('nope')
84
+            ->willReturn(null);
85
+        $this->mailer->expects($this->never())->method('send');
86
+
87
+        $this->listener->handle($event);
88
+    }
89
+
90
+    public function testHandleRemoteWipeStartedNoEmailSet(): void {
91
+        /** @var IToken|MockObject $token */
92
+        $token = $this->createMock(IToken::class);
93
+        $event = new RemoteWipeStarted($token);
94
+        $token->method('getUID')->willReturn('nope');
95
+        $user = $this->createMock(IUser::class);
96
+        $this->userManager->expects($this->once())
97
+            ->method('get')
98
+            ->with('nope')
99
+            ->willReturn($user);
100
+        $user->method('getEMailAddress')->willReturn(null);
101
+        $this->mailer->expects($this->never())->method('send');
102
+
103
+        $this->listener->handle($event);
104
+    }
105
+
106
+    public function testHandleRemoteWipeStartedTransmissionError(): void {
107
+        /** @var IToken|MockObject $token */
108
+        $token = $this->createMock(IToken::class);
109
+        $event = new RemoteWipeStarted($token);
110
+        $token->method('getUID')->willReturn('nope');
111
+        $user = $this->createMock(IUser::class);
112
+        $this->userManager->expects($this->once())
113
+            ->method('get')
114
+            ->with('nope')
115
+            ->willReturn($user);
116
+        $user->method('getEMailAddress')->willReturn('[email protected]');
117
+        $this->mailer->expects($this->once())
118
+            ->method('send')
119
+            ->willThrowException(new Exception());
120
+        $this->logger->expects($this->once())
121
+            ->method('error');
122
+
123
+        $this->listener->handle($event);
124
+    }
125
+
126
+    public function testHandleRemoteWipeStarted(): void {
127
+        /** @var IToken|MockObject $token */
128
+        $token = $this->createMock(IToken::class);
129
+        $event = new RemoteWipeStarted($token);
130
+        $token->method('getUID')->willReturn('nope');
131
+        $user = $this->createMock(IUser::class);
132
+        $this->userManager->expects($this->once())
133
+            ->method('get')
134
+            ->with('nope')
135
+            ->willReturn($user);
136
+        $user->method('getEMailAddress')->willReturn('[email protected]');
137
+        $message = $this->createMock(IMessage::class);
138
+        $this->mailer->expects($this->once())
139
+            ->method('createMessage')
140
+            ->willReturn($message);
141
+        $message->expects($this->once())
142
+            ->method('setTo')
143
+            ->with($this->equalTo(['[email protected]']));
144
+        $this->mailer->expects($this->once())
145
+            ->method('send')
146
+            ->with($message);
147
+
148
+        $this->listener->handle($event);
149
+    }
150
+
151
+    public function testHandleRemoteWipeFinishedInvalidUser(): void {
152
+        /** @var IToken|MockObject $token */
153
+        $token = $this->createMock(IToken::class);
154
+        $event = new RemoteWipeFinished($token);
155
+        $token->method('getUID')->willReturn('nope');
156
+        $this->userManager->expects($this->once())
157
+            ->method('get')
158
+            ->with('nope')
159
+            ->willReturn(null);
160
+        $this->mailer->expects($this->never())->method('send');
161
+
162
+        $this->listener->handle($event);
163
+    }
164
+
165
+    public function testHandleRemoteWipeFinishedNoEmailSet(): void {
166
+        /** @var IToken|MockObject $token */
167
+        $token = $this->createMock(IToken::class);
168
+        $event = new RemoteWipeFinished($token);
169
+        $token->method('getUID')->willReturn('nope');
170
+        $user = $this->createMock(IUser::class);
171
+        $this->userManager->expects($this->once())
172
+            ->method('get')
173
+            ->with('nope')
174
+            ->willReturn($user);
175
+        $user->method('getEMailAddress')->willReturn(null);
176
+        $this->mailer->expects($this->never())->method('send');
177
+
178
+        $this->listener->handle($event);
179
+    }
180
+
181
+    public function testHandleRemoteWipeFinishedTransmissionError(): void {
182
+        /** @var IToken|MockObject $token */
183
+        $token = $this->createMock(IToken::class);
184
+        $event = new RemoteWipeFinished($token);
185
+        $token->method('getUID')->willReturn('nope');
186
+        $user = $this->createMock(IUser::class);
187
+        $this->userManager->expects($this->once())
188
+            ->method('get')
189
+            ->with('nope')
190
+            ->willReturn($user);
191
+        $user->method('getEMailAddress')->willReturn('[email protected]');
192
+        $this->mailer->expects($this->once())
193
+            ->method('send')
194
+            ->willThrowException(new Exception());
195
+        $this->logger->expects($this->once())
196
+            ->method('error');
197
+
198
+        $this->listener->handle($event);
199
+    }
200
+
201
+    public function testHandleRemoteWipeFinished(): void {
202
+        /** @var IToken|MockObject $token */
203
+        $token = $this->createMock(IToken::class);
204
+        $event = new RemoteWipeFinished($token);
205
+        $token->method('getUID')->willReturn('nope');
206
+        $user = $this->createMock(IUser::class);
207
+        $this->userManager->expects($this->once())
208
+            ->method('get')
209
+            ->with('nope')
210
+            ->willReturn($user);
211
+        $user->method('getEMailAddress')->willReturn('[email protected]');
212
+        $message = $this->createMock(IMessage::class);
213
+        $this->mailer->expects($this->once())
214
+            ->method('createMessage')
215
+            ->willReturn($message);
216
+        $message->expects($this->once())
217
+            ->method('setTo')
218
+            ->with($this->equalTo(['[email protected]']));
219
+        $this->mailer->expects($this->once())
220
+            ->method('send')
221
+            ->with($message);
222
+
223
+        $this->listener->handle($event);
224
+    }
225 225
 }
Please login to merge, or discard this patch.