Completed
Push — master ( 158b3e...c62fa5 )
by Joas
29:53 queued 14s
created
tests/Unit/BackgroundJob/RememberBackupCodesJobTest.php 1 patch
Indentation   +189 added lines, -189 removed lines patch added patch discarded remove patch
@@ -21,193 +21,193 @@
 block discarded – undo
21 21
 use Test\TestCase;
22 22
 
23 23
 class RememberBackupCodesJobTest extends TestCase {
24
-	private IRegistry&MockObject $registry;
25
-	private IUserManager&MockObject $userManager;
26
-	private ITimeFactory&MockObject $time;
27
-	private IManager&MockObject $notificationManager;
28
-	private IJobList&MockObject $jobList;
29
-	private RememberBackupCodesJob $job;
30
-
31
-	protected function setUp(): void {
32
-		parent::setUp();
33
-
34
-		$this->registry = $this->createMock(IRegistry::class);
35
-		$this->userManager = $this->createMock(IUserManager::class);
36
-		$this->time = $this->createMock(ITimeFactory::class);
37
-		$this->time->method('getTime')
38
-			->willReturn(10000000);
39
-		$this->notificationManager = $this->createMock(IManager::class);
40
-		$this->jobList = $this->createMock(IJobList::class);
41
-
42
-		$this->job = new RememberBackupCodesJob(
43
-			$this->registry,
44
-			$this->userManager,
45
-			$this->time,
46
-			$this->notificationManager,
47
-			$this->jobList
48
-		);
49
-	}
50
-
51
-	public function testInvalidUID(): void {
52
-		$this->userManager->method('get')
53
-			->with('invalidUID')
54
-			->willReturn(null);
55
-
56
-		$this->notificationManager->expects($this->never())
57
-			->method($this->anything());
58
-		$this->jobList->expects($this->once())
59
-			->method('remove')
60
-			->with(
61
-				RememberBackupCodesJob::class,
62
-				['uid' => 'invalidUID']
63
-			);
64
-		$this->jobList->expects($this->never())
65
-			->method('add');
66
-
67
-		self::invokePrivate($this->job, 'run', [['uid' => 'invalidUID']]);
68
-	}
69
-
70
-	public function testBackupCodesGenerated(): void {
71
-		$user = $this->createMock(IUser::class);
72
-		$user->method('getUID')
73
-			->willReturn('validUID');
74
-		$user->method('isEnabled')
75
-			->willReturn(true);
76
-
77
-		$this->userManager->method('get')
78
-			->with('validUID')
79
-			->willReturn($user);
80
-
81
-		$this->registry->method('getProviderStates')
82
-			->with($user)
83
-			->willReturn([
84
-				'backup_codes' => true
85
-			]);
86
-
87
-		$this->jobList->expects($this->once())
88
-			->method('remove')
89
-			->with(
90
-				RememberBackupCodesJob::class,
91
-				['uid' => 'validUID']
92
-			);
93
-
94
-		$this->notificationManager->expects($this->never())
95
-			->method($this->anything());
96
-
97
-		self::invokePrivate($this->job, 'run', [['uid' => 'validUID']]);
98
-	}
99
-
100
-	public function testNoActiveProvider(): void {
101
-		$user = $this->createMock(IUser::class);
102
-		$user->method('getUID')
103
-			->willReturn('validUID');
104
-		$this->userManager->method('get')
105
-			->with('validUID')
106
-			->willReturn($user);
107
-
108
-		$this->registry->method('getProviderStates')
109
-			->with($user)
110
-			->willReturn([
111
-				'backup_codes' => false,
112
-				'foo' => false,
113
-			]);
114
-
115
-		$this->jobList->expects($this->once())
116
-			->method('remove')
117
-			->with(
118
-				RememberBackupCodesJob::class,
119
-				['uid' => 'validUID']
120
-			);
121
-
122
-		$this->notificationManager->expects($this->never())
123
-			->method($this->anything());
124
-
125
-		self::invokePrivate($this->job, 'run', [['uid' => 'validUID']]);
126
-	}
127
-
128
-	public function testNotificationSend(): void {
129
-		$user = $this->createMock(IUser::class);
130
-		$user->method('getUID')
131
-			->willReturn('validUID');
132
-		$user->method('isEnabled')
133
-			->willReturn(true);
134
-		$this->userManager->method('get')
135
-			->with('validUID')
136
-			->willReturn($user);
137
-
138
-		$this->registry->method('getProviderStates')
139
-			->with($user)
140
-			->willReturn([
141
-				'backup_codes' => false,
142
-				'foo' => true,
143
-			]);
144
-
145
-		$this->jobList->expects($this->never())
146
-			->method($this->anything());
147
-
148
-		$date = new \DateTime();
149
-		$date->setTimestamp($this->time->getTime());
150
-
151
-		$this->notificationManager->method('createNotification')
152
-			->willReturn(Server::get(IManager::class)->createNotification());
153
-
154
-		$this->notificationManager->expects($this->once())
155
-			->method('notify')
156
-			->with($this->callback(function (INotification $n) {
157
-				return $n->getApp() === 'twofactor_backupcodes' &&
158
-					$n->getUser() === 'validUID' &&
159
-					$n->getDateTime()->getTimestamp() === 10000000 &&
160
-					$n->getObjectType() === 'create' &&
161
-					$n->getObjectId() === 'codes' &&
162
-					$n->getSubject() === 'create_backupcodes';
163
-			}));
164
-
165
-		self::invokePrivate($this->job, 'run', [['uid' => 'validUID']]);
166
-	}
167
-
168
-	public function testNotificationNotSendForDisabledUser(): void {
169
-		$user = $this->createMock(IUser::class);
170
-		$user->method('getUID')
171
-			->willReturn('validUID');
172
-		$user->method('isEnabled')
173
-			->willReturn(false);
174
-		$this->userManager->method('get')
175
-			->with('validUID')
176
-			->willReturn($user);
177
-
178
-		$this->registry->method('getProviderStates')
179
-			->with($user)
180
-			->willReturn([
181
-				'backup_codes' => false,
182
-				'foo' => true,
183
-			]);
184
-
185
-		$this->jobList->expects($this->once())
186
-			->method('remove')
187
-			->with(
188
-				RememberBackupCodesJob::class,
189
-				['uid' => 'validUID']
190
-			);
191
-
192
-		$date = new \DateTime();
193
-		$date->setTimestamp($this->time->getTime());
194
-
195
-		$this->notificationManager->method('createNotification')
196
-			->willReturn(Server::get(IManager::class)->createNotification());
197
-
198
-		$this->notificationManager->expects($this->once())
199
-			->method('markProcessed')
200
-			->with($this->callback(function (INotification $n) {
201
-				return $n->getApp() === 'twofactor_backupcodes' &&
202
-					$n->getUser() === 'validUID' &&
203
-					$n->getObjectType() === 'create' &&
204
-					$n->getObjectId() === 'codes' &&
205
-					$n->getSubject() === 'create_backupcodes';
206
-			}));
207
-
208
-		$this->notificationManager->expects($this->never())
209
-			->method('notify');
210
-
211
-		self::invokePrivate($this->job, 'run', [['uid' => 'validUID']]);
212
-	}
24
+    private IRegistry&MockObject $registry;
25
+    private IUserManager&MockObject $userManager;
26
+    private ITimeFactory&MockObject $time;
27
+    private IManager&MockObject $notificationManager;
28
+    private IJobList&MockObject $jobList;
29
+    private RememberBackupCodesJob $job;
30
+
31
+    protected function setUp(): void {
32
+        parent::setUp();
33
+
34
+        $this->registry = $this->createMock(IRegistry::class);
35
+        $this->userManager = $this->createMock(IUserManager::class);
36
+        $this->time = $this->createMock(ITimeFactory::class);
37
+        $this->time->method('getTime')
38
+            ->willReturn(10000000);
39
+        $this->notificationManager = $this->createMock(IManager::class);
40
+        $this->jobList = $this->createMock(IJobList::class);
41
+
42
+        $this->job = new RememberBackupCodesJob(
43
+            $this->registry,
44
+            $this->userManager,
45
+            $this->time,
46
+            $this->notificationManager,
47
+            $this->jobList
48
+        );
49
+    }
50
+
51
+    public function testInvalidUID(): void {
52
+        $this->userManager->method('get')
53
+            ->with('invalidUID')
54
+            ->willReturn(null);
55
+
56
+        $this->notificationManager->expects($this->never())
57
+            ->method($this->anything());
58
+        $this->jobList->expects($this->once())
59
+            ->method('remove')
60
+            ->with(
61
+                RememberBackupCodesJob::class,
62
+                ['uid' => 'invalidUID']
63
+            );
64
+        $this->jobList->expects($this->never())
65
+            ->method('add');
66
+
67
+        self::invokePrivate($this->job, 'run', [['uid' => 'invalidUID']]);
68
+    }
69
+
70
+    public function testBackupCodesGenerated(): void {
71
+        $user = $this->createMock(IUser::class);
72
+        $user->method('getUID')
73
+            ->willReturn('validUID');
74
+        $user->method('isEnabled')
75
+            ->willReturn(true);
76
+
77
+        $this->userManager->method('get')
78
+            ->with('validUID')
79
+            ->willReturn($user);
80
+
81
+        $this->registry->method('getProviderStates')
82
+            ->with($user)
83
+            ->willReturn([
84
+                'backup_codes' => true
85
+            ]);
86
+
87
+        $this->jobList->expects($this->once())
88
+            ->method('remove')
89
+            ->with(
90
+                RememberBackupCodesJob::class,
91
+                ['uid' => 'validUID']
92
+            );
93
+
94
+        $this->notificationManager->expects($this->never())
95
+            ->method($this->anything());
96
+
97
+        self::invokePrivate($this->job, 'run', [['uid' => 'validUID']]);
98
+    }
99
+
100
+    public function testNoActiveProvider(): void {
101
+        $user = $this->createMock(IUser::class);
102
+        $user->method('getUID')
103
+            ->willReturn('validUID');
104
+        $this->userManager->method('get')
105
+            ->with('validUID')
106
+            ->willReturn($user);
107
+
108
+        $this->registry->method('getProviderStates')
109
+            ->with($user)
110
+            ->willReturn([
111
+                'backup_codes' => false,
112
+                'foo' => false,
113
+            ]);
114
+
115
+        $this->jobList->expects($this->once())
116
+            ->method('remove')
117
+            ->with(
118
+                RememberBackupCodesJob::class,
119
+                ['uid' => 'validUID']
120
+            );
121
+
122
+        $this->notificationManager->expects($this->never())
123
+            ->method($this->anything());
124
+
125
+        self::invokePrivate($this->job, 'run', [['uid' => 'validUID']]);
126
+    }
127
+
128
+    public function testNotificationSend(): void {
129
+        $user = $this->createMock(IUser::class);
130
+        $user->method('getUID')
131
+            ->willReturn('validUID');
132
+        $user->method('isEnabled')
133
+            ->willReturn(true);
134
+        $this->userManager->method('get')
135
+            ->with('validUID')
136
+            ->willReturn($user);
137
+
138
+        $this->registry->method('getProviderStates')
139
+            ->with($user)
140
+            ->willReturn([
141
+                'backup_codes' => false,
142
+                'foo' => true,
143
+            ]);
144
+
145
+        $this->jobList->expects($this->never())
146
+            ->method($this->anything());
147
+
148
+        $date = new \DateTime();
149
+        $date->setTimestamp($this->time->getTime());
150
+
151
+        $this->notificationManager->method('createNotification')
152
+            ->willReturn(Server::get(IManager::class)->createNotification());
153
+
154
+        $this->notificationManager->expects($this->once())
155
+            ->method('notify')
156
+            ->with($this->callback(function (INotification $n) {
157
+                return $n->getApp() === 'twofactor_backupcodes' &&
158
+                    $n->getUser() === 'validUID' &&
159
+                    $n->getDateTime()->getTimestamp() === 10000000 &&
160
+                    $n->getObjectType() === 'create' &&
161
+                    $n->getObjectId() === 'codes' &&
162
+                    $n->getSubject() === 'create_backupcodes';
163
+            }));
164
+
165
+        self::invokePrivate($this->job, 'run', [['uid' => 'validUID']]);
166
+    }
167
+
168
+    public function testNotificationNotSendForDisabledUser(): void {
169
+        $user = $this->createMock(IUser::class);
170
+        $user->method('getUID')
171
+            ->willReturn('validUID');
172
+        $user->method('isEnabled')
173
+            ->willReturn(false);
174
+        $this->userManager->method('get')
175
+            ->with('validUID')
176
+            ->willReturn($user);
177
+
178
+        $this->registry->method('getProviderStates')
179
+            ->with($user)
180
+            ->willReturn([
181
+                'backup_codes' => false,
182
+                'foo' => true,
183
+            ]);
184
+
185
+        $this->jobList->expects($this->once())
186
+            ->method('remove')
187
+            ->with(
188
+                RememberBackupCodesJob::class,
189
+                ['uid' => 'validUID']
190
+            );
191
+
192
+        $date = new \DateTime();
193
+        $date->setTimestamp($this->time->getTime());
194
+
195
+        $this->notificationManager->method('createNotification')
196
+            ->willReturn(Server::get(IManager::class)->createNotification());
197
+
198
+        $this->notificationManager->expects($this->once())
199
+            ->method('markProcessed')
200
+            ->with($this->callback(function (INotification $n) {
201
+                return $n->getApp() === 'twofactor_backupcodes' &&
202
+                    $n->getUser() === 'validUID' &&
203
+                    $n->getObjectType() === 'create' &&
204
+                    $n->getObjectId() === 'codes' &&
205
+                    $n->getSubject() === 'create_backupcodes';
206
+            }));
207
+
208
+        $this->notificationManager->expects($this->never())
209
+            ->method('notify');
210
+
211
+        self::invokePrivate($this->job, 'run', [['uid' => 'validUID']]);
212
+    }
213 213
 }
Please login to merge, or discard this patch.
apps/workflowengine/tests/Check/RequestRemoteAddressTest.php 2 patches
Indentation   +92 added lines, -92 removed lines patch added patch discarded remove patch
@@ -15,96 +15,96 @@
 block discarded – undo
15 15
 
16 16
 class RequestRemoteAddressTest extends \Test\TestCase {
17 17
 
18
-	protected IRequest&MockObject $request;
19
-
20
-	protected function getL10NMock(): IL10N&MockObject {
21
-		$l = $this->createMock(IL10N::class);
22
-		$l->expects($this->any())
23
-			->method('t')
24
-			->willReturnCallback(function ($string, $args) {
25
-				return sprintf($string, $args);
26
-			});
27
-		return $l;
28
-	}
29
-
30
-	protected function setUp(): void {
31
-		parent::setUp();
32
-
33
-		$this->request = $this->createMock(IRequest::class);
34
-	}
35
-
36
-	public static function dataExecuteCheckIPv4(): array {
37
-		return [
38
-			['127.0.0.1/32', '127.0.0.1', true],
39
-			['127.0.0.1/32', '127.0.0.0', false],
40
-			['127.0.0.1/31', '127.0.0.0', true],
41
-			['127.0.0.1/32', '127.0.0.2', false],
42
-			['127.0.0.1/31', '127.0.0.2', false],
43
-			['127.0.0.1/30', '127.0.0.2', true],
44
-		];
45
-	}
46
-
47
-	/**
48
-	 * @dataProvider dataExecuteCheckIPv4
49
-	 */
50
-	public function testExecuteCheckMatchesIPv4(string $value, string $ip, bool $expected): void {
51
-		$check = new RequestRemoteAddress($this->getL10NMock(), $this->request);
52
-
53
-		$this->request->expects($this->once())
54
-			->method('getRemoteAddress')
55
-			->willReturn($ip);
56
-
57
-		$this->assertEquals($expected, $check->executeCheck('matchesIPv4', $value));
58
-	}
59
-
60
-	/**
61
-	 * @dataProvider dataExecuteCheckIPv4
62
-	 */
63
-	public function testExecuteCheckNotMatchesIPv4(string $value, string $ip, bool $expected): void {
64
-		$check = new RequestRemoteAddress($this->getL10NMock(), $this->request);
65
-
66
-		$this->request->expects($this->once())
67
-			->method('getRemoteAddress')
68
-			->willReturn($ip);
69
-
70
-		$this->assertEquals(!$expected, $check->executeCheck('!matchesIPv4', $value));
71
-	}
72
-
73
-	public static function dataExecuteCheckIPv6(): array {
74
-		return [
75
-			['::1/128', '::1', true],
76
-			['::2/128', '::3', false],
77
-			['::2/127', '::3', true],
78
-			['::1/128', '::2', false],
79
-			['::1/127', '::2', false],
80
-			['::1/126', '::2', true],
81
-			['1234::1/127', '1234::', true],
82
-		];
83
-	}
84
-
85
-	/**
86
-	 * @dataProvider dataExecuteCheckIPv6
87
-	 */
88
-	public function testExecuteCheckMatchesIPv6(string $value, string $ip, bool $expected): void {
89
-		$check = new RequestRemoteAddress($this->getL10NMock(), $this->request);
90
-
91
-		$this->request->expects($this->once())
92
-			->method('getRemoteAddress')
93
-			->willReturn($ip);
94
-
95
-		$this->assertEquals($expected, $check->executeCheck('matchesIPv6', $value));
96
-	}
97
-
98
-	/**
99
-	 * @dataProvider dataExecuteCheckIPv6
100
-	 */
101
-	public function testExecuteCheckNotMatchesIPv6(string $value, string $ip, bool $expected): void {
102
-		$check = new RequestRemoteAddress($this->getL10NMock(), $this->request);
103
-
104
-		$this->request->expects($this->once())
105
-			->method('getRemoteAddress')
106
-			->willReturn($ip);
107
-
108
-		$this->assertEquals(!$expected, $check->executeCheck('!matchesIPv6', $value));
109
-	}
18
+    protected IRequest&MockObject $request;
19
+
20
+    protected function getL10NMock(): IL10N&MockObject {
21
+        $l = $this->createMock(IL10N::class);
22
+        $l->expects($this->any())
23
+            ->method('t')
24
+            ->willReturnCallback(function ($string, $args) {
25
+                return sprintf($string, $args);
26
+            });
27
+        return $l;
28
+    }
29
+
30
+    protected function setUp(): void {
31
+        parent::setUp();
32
+
33
+        $this->request = $this->createMock(IRequest::class);
34
+    }
35
+
36
+    public static function dataExecuteCheckIPv4(): array {
37
+        return [
38
+            ['127.0.0.1/32', '127.0.0.1', true],
39
+            ['127.0.0.1/32', '127.0.0.0', false],
40
+            ['127.0.0.1/31', '127.0.0.0', true],
41
+            ['127.0.0.1/32', '127.0.0.2', false],
42
+            ['127.0.0.1/31', '127.0.0.2', false],
43
+            ['127.0.0.1/30', '127.0.0.2', true],
44
+        ];
45
+    }
46
+
47
+    /**
48
+     * @dataProvider dataExecuteCheckIPv4
49
+     */
50
+    public function testExecuteCheckMatchesIPv4(string $value, string $ip, bool $expected): void {
51
+        $check = new RequestRemoteAddress($this->getL10NMock(), $this->request);
52
+
53
+        $this->request->expects($this->once())
54
+            ->method('getRemoteAddress')
55
+            ->willReturn($ip);
56
+
57
+        $this->assertEquals($expected, $check->executeCheck('matchesIPv4', $value));
58
+    }
59
+
60
+    /**
61
+     * @dataProvider dataExecuteCheckIPv4
62
+     */
63
+    public function testExecuteCheckNotMatchesIPv4(string $value, string $ip, bool $expected): void {
64
+        $check = new RequestRemoteAddress($this->getL10NMock(), $this->request);
65
+
66
+        $this->request->expects($this->once())
67
+            ->method('getRemoteAddress')
68
+            ->willReturn($ip);
69
+
70
+        $this->assertEquals(!$expected, $check->executeCheck('!matchesIPv4', $value));
71
+    }
72
+
73
+    public static function dataExecuteCheckIPv6(): array {
74
+        return [
75
+            ['::1/128', '::1', true],
76
+            ['::2/128', '::3', false],
77
+            ['::2/127', '::3', true],
78
+            ['::1/128', '::2', false],
79
+            ['::1/127', '::2', false],
80
+            ['::1/126', '::2', true],
81
+            ['1234::1/127', '1234::', true],
82
+        ];
83
+    }
84
+
85
+    /**
86
+     * @dataProvider dataExecuteCheckIPv6
87
+     */
88
+    public function testExecuteCheckMatchesIPv6(string $value, string $ip, bool $expected): void {
89
+        $check = new RequestRemoteAddress($this->getL10NMock(), $this->request);
90
+
91
+        $this->request->expects($this->once())
92
+            ->method('getRemoteAddress')
93
+            ->willReturn($ip);
94
+
95
+        $this->assertEquals($expected, $check->executeCheck('matchesIPv6', $value));
96
+    }
97
+
98
+    /**
99
+     * @dataProvider dataExecuteCheckIPv6
100
+     */
101
+    public function testExecuteCheckNotMatchesIPv6(string $value, string $ip, bool $expected): void {
102
+        $check = new RequestRemoteAddress($this->getL10NMock(), $this->request);
103
+
104
+        $this->request->expects($this->once())
105
+            ->method('getRemoteAddress')
106
+            ->willReturn($ip);
107
+
108
+        $this->assertEquals(!$expected, $check->executeCheck('!matchesIPv6', $value));
109
+    }
110 110
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -21,7 +21,7 @@
 block discarded – undo
21 21
 		$l = $this->createMock(IL10N::class);
22 22
 		$l->expects($this->any())
23 23
 			->method('t')
24
-			->willReturnCallback(function ($string, $args) {
24
+			->willReturnCallback(function($string, $args) {
25 25
 				return sprintf($string, $args);
26 26
 			});
27 27
 		return $l;
Please login to merge, or discard this patch.
apps/workflowengine/tests/Check/RequestUserAgentTest.php 2 patches
Indentation   +68 added lines, -68 removed lines patch added patch discarded remove patch
@@ -16,81 +16,81 @@
 block discarded – undo
16 16
 use Test\TestCase;
17 17
 
18 18
 class RequestUserAgentTest extends TestCase {
19
-	protected IRequest&MockObject $request;
20
-	protected RequestUserAgent $check;
19
+    protected IRequest&MockObject $request;
20
+    protected RequestUserAgent $check;
21 21
 
22
-	protected function setUp(): void {
23
-		parent::setUp();
22
+    protected function setUp(): void {
23
+        parent::setUp();
24 24
 
25
-		$this->request = $this->createMock(IRequest::class);
26
-		/** @var IL10N&MockObject $l */
27
-		$l = $this->createMock(IL10N::class);
28
-		$l->expects($this->any())
29
-			->method('t')
30
-			->willReturnCallback(function ($string, $args) {
31
-				return sprintf($string, $args);
32
-			});
25
+        $this->request = $this->createMock(IRequest::class);
26
+        /** @var IL10N&MockObject $l */
27
+        $l = $this->createMock(IL10N::class);
28
+        $l->expects($this->any())
29
+            ->method('t')
30
+            ->willReturnCallback(function ($string, $args) {
31
+                return sprintf($string, $args);
32
+            });
33 33
 
34
-		$this->check = new RequestUserAgent($l, $this->request);
35
-	}
34
+        $this->check = new RequestUserAgent($l, $this->request);
35
+    }
36 36
 
37
-	public static function dataExecuteCheck(): array {
38
-		return [
39
-			['is', 'android', 'Mozilla/5.0 (Android) Nextcloud-android/2.2.0', true],
40
-			['is', 'android', 'Mozilla/5.0 (iOS) Nextcloud-iOS/2.2.0', false],
41
-			['is', 'android', 'Mozilla/5.0 (Linux) mirall/2.2.0', false],
42
-			['is', 'android', 'Mozilla/5.0 (Windows) Nextcloud-Outlook v2.2.0', false],
43
-			['is', 'android', 'Filelink for *cloud/2.2.0', false],
44
-			['!is', 'android', 'Mozilla/5.0 (Android) Nextcloud-android/2.2.0', false],
45
-			['!is', 'android', 'Mozilla/5.0 (iOS) Nextcloud-iOS/2.2.0', true],
46
-			['!is', 'android', 'Mozilla/5.0 (Linux) mirall/2.2.0', true],
47
-			['!is', 'android', 'Mozilla/5.0 (Windows) Nextcloud-Outlook v2.2.0', true],
48
-			['!is', 'android', 'Filelink for *cloud/2.2.0', true],
37
+    public static function dataExecuteCheck(): array {
38
+        return [
39
+            ['is', 'android', 'Mozilla/5.0 (Android) Nextcloud-android/2.2.0', true],
40
+            ['is', 'android', 'Mozilla/5.0 (iOS) Nextcloud-iOS/2.2.0', false],
41
+            ['is', 'android', 'Mozilla/5.0 (Linux) mirall/2.2.0', false],
42
+            ['is', 'android', 'Mozilla/5.0 (Windows) Nextcloud-Outlook v2.2.0', false],
43
+            ['is', 'android', 'Filelink for *cloud/2.2.0', false],
44
+            ['!is', 'android', 'Mozilla/5.0 (Android) Nextcloud-android/2.2.0', false],
45
+            ['!is', 'android', 'Mozilla/5.0 (iOS) Nextcloud-iOS/2.2.0', true],
46
+            ['!is', 'android', 'Mozilla/5.0 (Linux) mirall/2.2.0', true],
47
+            ['!is', 'android', 'Mozilla/5.0 (Windows) Nextcloud-Outlook v2.2.0', true],
48
+            ['!is', 'android', 'Filelink for *cloud/2.2.0', true],
49 49
 
50
-			['is', 'ios', 'Mozilla/5.0 (Android) Nextcloud-android/2.2.0', false],
51
-			['is', 'ios', 'Mozilla/5.0 (iOS) Nextcloud-iOS/2.2.0', true],
52
-			['is', 'ios', 'Mozilla/5.0 (Linux) mirall/2.2.0', false],
53
-			['is', 'ios', 'Mozilla/5.0 (Windows) Nextcloud-Outlook v2.2.0', false],
54
-			['is', 'ios', 'Filelink for *cloud/2.2.0', false],
55
-			['!is', 'ios', 'Mozilla/5.0 (Android) Nextcloud-android/2.2.0', true],
56
-			['!is', 'ios', 'Mozilla/5.0 (iOS) Nextcloud-iOS/2.2.0', false],
57
-			['!is', 'ios', 'Mozilla/5.0 (Linux) mirall/2.2.0', true],
58
-			['!is', 'ios', 'Mozilla/5.0 (Windows) Nextcloud-Outlook v2.2.0', true],
59
-			['!is', 'ios', 'Filelink for *cloud/2.2.0', true],
50
+            ['is', 'ios', 'Mozilla/5.0 (Android) Nextcloud-android/2.2.0', false],
51
+            ['is', 'ios', 'Mozilla/5.0 (iOS) Nextcloud-iOS/2.2.0', true],
52
+            ['is', 'ios', 'Mozilla/5.0 (Linux) mirall/2.2.0', false],
53
+            ['is', 'ios', 'Mozilla/5.0 (Windows) Nextcloud-Outlook v2.2.0', false],
54
+            ['is', 'ios', 'Filelink for *cloud/2.2.0', false],
55
+            ['!is', 'ios', 'Mozilla/5.0 (Android) Nextcloud-android/2.2.0', true],
56
+            ['!is', 'ios', 'Mozilla/5.0 (iOS) Nextcloud-iOS/2.2.0', false],
57
+            ['!is', 'ios', 'Mozilla/5.0 (Linux) mirall/2.2.0', true],
58
+            ['!is', 'ios', 'Mozilla/5.0 (Windows) Nextcloud-Outlook v2.2.0', true],
59
+            ['!is', 'ios', 'Filelink for *cloud/2.2.0', true],
60 60
 
61
-			['is', 'desktop', 'Mozilla/5.0 (Android) Nextcloud-android/2.2.0', false],
62
-			['is', 'desktop', 'Mozilla/5.0 (iOS) Nextcloud-iOS/2.2.0', false],
63
-			['is', 'desktop', 'Mozilla/5.0 (Linux) mirall/2.2.0', true],
64
-			['is', 'desktop', 'Mozilla/5.0 (Windows) Nextcloud-Outlook v2.2.0', false],
65
-			['is', 'desktop', 'Filelink for *cloud/2.2.0', false],
66
-			['!is', 'desktop', 'Mozilla/5.0 (Android) Nextcloud-android/2.2.0', true],
67
-			['!is', 'desktop', 'Mozilla/5.0 (iOS) Nextcloud-iOS/2.2.0', true],
68
-			['!is', 'desktop', 'Mozilla/5.0 (Linux) mirall/2.2.0', false],
69
-			['!is', 'desktop', 'Mozilla/5.0 (Windows) Nextcloud-Outlook v2.2.0', true],
70
-			['!is', 'desktop', 'Filelink for *cloud/2.2.0', true],
61
+            ['is', 'desktop', 'Mozilla/5.0 (Android) Nextcloud-android/2.2.0', false],
62
+            ['is', 'desktop', 'Mozilla/5.0 (iOS) Nextcloud-iOS/2.2.0', false],
63
+            ['is', 'desktop', 'Mozilla/5.0 (Linux) mirall/2.2.0', true],
64
+            ['is', 'desktop', 'Mozilla/5.0 (Windows) Nextcloud-Outlook v2.2.0', false],
65
+            ['is', 'desktop', 'Filelink for *cloud/2.2.0', false],
66
+            ['!is', 'desktop', 'Mozilla/5.0 (Android) Nextcloud-android/2.2.0', true],
67
+            ['!is', 'desktop', 'Mozilla/5.0 (iOS) Nextcloud-iOS/2.2.0', true],
68
+            ['!is', 'desktop', 'Mozilla/5.0 (Linux) mirall/2.2.0', false],
69
+            ['!is', 'desktop', 'Mozilla/5.0 (Windows) Nextcloud-Outlook v2.2.0', true],
70
+            ['!is', 'desktop', 'Filelink for *cloud/2.2.0', true],
71 71
 
72
-			['is', 'mail', 'Mozilla/5.0 (Android) Nextcloud-android/2.2.0', false],
73
-			['is', 'mail', 'Mozilla/5.0 (iOS) Nextcloud-iOS/2.2.0', false],
74
-			['is', 'mail', 'Mozilla/5.0 (Linux) mirall/2.2.0', false],
75
-			['is', 'mail', 'Mozilla/5.0 (Windows) Nextcloud-Outlook v2.2.0', true],
76
-			['is', 'mail', 'Filelink for *cloud/2.2.0', true],
77
-			['!is', 'mail', 'Mozilla/5.0 (Android) Nextcloud-android/2.2.0', true],
78
-			['!is', 'mail', 'Mozilla/5.0 (iOS) Nextcloud-iOS/2.2.0', true],
79
-			['!is', 'mail', 'Mozilla/5.0 (Linux) mirall/2.2.0', true],
80
-			['!is', 'mail', 'Mozilla/5.0 (Windows) Nextcloud-Outlook v2.2.0', false],
81
-			['!is', 'mail', 'Filelink for *cloud/2.2.0', false],
82
-		];
83
-	}
72
+            ['is', 'mail', 'Mozilla/5.0 (Android) Nextcloud-android/2.2.0', false],
73
+            ['is', 'mail', 'Mozilla/5.0 (iOS) Nextcloud-iOS/2.2.0', false],
74
+            ['is', 'mail', 'Mozilla/5.0 (Linux) mirall/2.2.0', false],
75
+            ['is', 'mail', 'Mozilla/5.0 (Windows) Nextcloud-Outlook v2.2.0', true],
76
+            ['is', 'mail', 'Filelink for *cloud/2.2.0', true],
77
+            ['!is', 'mail', 'Mozilla/5.0 (Android) Nextcloud-android/2.2.0', true],
78
+            ['!is', 'mail', 'Mozilla/5.0 (iOS) Nextcloud-iOS/2.2.0', true],
79
+            ['!is', 'mail', 'Mozilla/5.0 (Linux) mirall/2.2.0', true],
80
+            ['!is', 'mail', 'Mozilla/5.0 (Windows) Nextcloud-Outlook v2.2.0', false],
81
+            ['!is', 'mail', 'Filelink for *cloud/2.2.0', false],
82
+        ];
83
+    }
84 84
 
85
-	/**
86
-	 * @dataProvider dataExecuteCheck
87
-	 */
88
-	public function testExecuteCheck(string $operation, string $checkValue, string $actualValue, bool $expected): void {
89
-		$this->request->expects($this->once())
90
-			->method('getHeader')
91
-			->willReturn($actualValue);
85
+    /**
86
+     * @dataProvider dataExecuteCheck
87
+     */
88
+    public function testExecuteCheck(string $operation, string $checkValue, string $actualValue, bool $expected): void {
89
+        $this->request->expects($this->once())
90
+            ->method('getHeader')
91
+            ->willReturn($actualValue);
92 92
 
93
-		/** @var AbstractStringCheck $check */
94
-		$this->assertEquals($expected, $this->check->executeCheck($operation, $checkValue));
95
-	}
93
+        /** @var AbstractStringCheck $check */
94
+        $this->assertEquals($expected, $this->check->executeCheck($operation, $checkValue));
95
+    }
96 96
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -27,7 +27,7 @@
 block discarded – undo
27 27
 		$l = $this->createMock(IL10N::class);
28 28
 		$l->expects($this->any())
29 29
 			->method('t')
30
-			->willReturnCallback(function ($string, $args) {
30
+			->willReturnCallback(function($string, $args) {
31 31
 				return sprintf($string, $args);
32 32
 			});
33 33
 
Please login to merge, or discard this patch.
apps/workflowengine/tests/Check/AbstractStringCheckTest.php 2 patches
Indentation   +109 added lines, -109 removed lines patch added patch discarded remove patch
@@ -13,113 +13,113 @@
 block discarded – undo
13 13
 use PHPUnit\Framework\MockObject\MockObject;
14 14
 
15 15
 class AbstractStringCheckTest extends \Test\TestCase {
16
-	protected function getCheckMock(): AbstractStringCheck|MockObject {
17
-		$l = $this->getMockBuilder(IL10N::class)
18
-			->disableOriginalConstructor()
19
-			->getMock();
20
-		$l->expects($this->any())
21
-			->method('t')
22
-			->willReturnCallback(function ($string, $args) {
23
-				return sprintf($string, $args);
24
-			});
25
-
26
-		$check = $this->getMockBuilder(AbstractStringCheck::class)
27
-			->setConstructorArgs([
28
-				$l,
29
-			])
30
-			->onlyMethods([
31
-				'executeCheck',
32
-				'getActualValue',
33
-			])
34
-			->getMock();
35
-
36
-		return $check;
37
-	}
38
-
39
-	public static function dataExecuteStringCheck(): array {
40
-		return [
41
-			['is', 'same', 'same', true],
42
-			['is', 'different', 'not the same', false],
43
-			['!is', 'same', 'same', false],
44
-			['!is', 'different', 'not the same', true],
45
-
46
-			['matches', '/match/', 'match', true],
47
-			['matches', '/different/', 'not the same', false],
48
-			['!matches', '/match/', 'match', false],
49
-			['!matches', '/different/', 'not the same', true],
50
-		];
51
-	}
52
-
53
-	/**
54
-	 * @dataProvider dataExecuteStringCheck
55
-	 */
56
-	public function testExecuteStringCheck(string $operation, string $checkValue, string $actualValue, bool $expected): void {
57
-		$check = $this->getCheckMock();
58
-
59
-		/** @var AbstractStringCheck $check */
60
-		$this->assertEquals($expected, $this->invokePrivate($check, 'executeStringCheck', [$operation, $checkValue, $actualValue]));
61
-	}
62
-
63
-	public static function dataValidateCheck(): array {
64
-		return [
65
-			['is', '/Invalid(Regex/'],
66
-			['!is', '/Invalid(Regex/'],
67
-			['matches', '/Valid(Regex)/'],
68
-			['!matches', '/Valid(Regex)/'],
69
-		];
70
-	}
71
-
72
-	/**
73
-	 * @dataProvider dataValidateCheck
74
-	 */
75
-	public function testValidateCheck(string $operator, string $value): void {
76
-		$check = $this->getCheckMock();
77
-
78
-		/** @var AbstractStringCheck $check */
79
-		$check->validateCheck($operator, $value);
80
-
81
-		$this->addToAssertionCount(1);
82
-	}
83
-
84
-	public static function dataValidateCheckInvalid(): array {
85
-		return [
86
-			['!!is', '', 1, 'The given operator is invalid'],
87
-			['less', '', 1, 'The given operator is invalid'],
88
-			['matches', '/Invalid(Regex/', 2, 'The given regular expression is invalid'],
89
-			['!matches', '/Invalid(Regex/', 2, 'The given regular expression is invalid'],
90
-		];
91
-	}
92
-
93
-	/**
94
-	 * @dataProvider dataValidateCheckInvalid
95
-	 */
96
-	public function testValidateCheckInvalid(string $operator, string $value, int $exceptionCode, string $exceptionMessage): void {
97
-		$check = $this->getCheckMock();
98
-
99
-		try {
100
-			/** @var AbstractStringCheck $check */
101
-			$check->validateCheck($operator, $value);
102
-		} catch (\UnexpectedValueException $e) {
103
-			$this->assertEquals($exceptionCode, $e->getCode());
104
-			$this->assertEquals($exceptionMessage, $e->getMessage());
105
-		}
106
-	}
107
-
108
-	public static function dataMatch(): array {
109
-		return [
110
-			['/valid/', 'valid', [], true],
111
-			['/valid/', 'valid', [md5('/valid/') => [md5('valid') => false]], false], // Cache hit
112
-		];
113
-	}
114
-
115
-	/**
116
-	 * @dataProvider dataMatch
117
-	 */
118
-	public function testMatch(string $pattern, string $subject, array $matches, bool $expected): void {
119
-		$check = $this->getCheckMock();
120
-
121
-		$this->invokePrivate($check, 'matches', [$matches]);
122
-
123
-		$this->assertEquals($expected, $this->invokePrivate($check, 'match', [$pattern, $subject]));
124
-	}
16
+    protected function getCheckMock(): AbstractStringCheck|MockObject {
17
+        $l = $this->getMockBuilder(IL10N::class)
18
+            ->disableOriginalConstructor()
19
+            ->getMock();
20
+        $l->expects($this->any())
21
+            ->method('t')
22
+            ->willReturnCallback(function ($string, $args) {
23
+                return sprintf($string, $args);
24
+            });
25
+
26
+        $check = $this->getMockBuilder(AbstractStringCheck::class)
27
+            ->setConstructorArgs([
28
+                $l,
29
+            ])
30
+            ->onlyMethods([
31
+                'executeCheck',
32
+                'getActualValue',
33
+            ])
34
+            ->getMock();
35
+
36
+        return $check;
37
+    }
38
+
39
+    public static function dataExecuteStringCheck(): array {
40
+        return [
41
+            ['is', 'same', 'same', true],
42
+            ['is', 'different', 'not the same', false],
43
+            ['!is', 'same', 'same', false],
44
+            ['!is', 'different', 'not the same', true],
45
+
46
+            ['matches', '/match/', 'match', true],
47
+            ['matches', '/different/', 'not the same', false],
48
+            ['!matches', '/match/', 'match', false],
49
+            ['!matches', '/different/', 'not the same', true],
50
+        ];
51
+    }
52
+
53
+    /**
54
+     * @dataProvider dataExecuteStringCheck
55
+     */
56
+    public function testExecuteStringCheck(string $operation, string $checkValue, string $actualValue, bool $expected): void {
57
+        $check = $this->getCheckMock();
58
+
59
+        /** @var AbstractStringCheck $check */
60
+        $this->assertEquals($expected, $this->invokePrivate($check, 'executeStringCheck', [$operation, $checkValue, $actualValue]));
61
+    }
62
+
63
+    public static function dataValidateCheck(): array {
64
+        return [
65
+            ['is', '/Invalid(Regex/'],
66
+            ['!is', '/Invalid(Regex/'],
67
+            ['matches', '/Valid(Regex)/'],
68
+            ['!matches', '/Valid(Regex)/'],
69
+        ];
70
+    }
71
+
72
+    /**
73
+     * @dataProvider dataValidateCheck
74
+     */
75
+    public function testValidateCheck(string $operator, string $value): void {
76
+        $check = $this->getCheckMock();
77
+
78
+        /** @var AbstractStringCheck $check */
79
+        $check->validateCheck($operator, $value);
80
+
81
+        $this->addToAssertionCount(1);
82
+    }
83
+
84
+    public static function dataValidateCheckInvalid(): array {
85
+        return [
86
+            ['!!is', '', 1, 'The given operator is invalid'],
87
+            ['less', '', 1, 'The given operator is invalid'],
88
+            ['matches', '/Invalid(Regex/', 2, 'The given regular expression is invalid'],
89
+            ['!matches', '/Invalid(Regex/', 2, 'The given regular expression is invalid'],
90
+        ];
91
+    }
92
+
93
+    /**
94
+     * @dataProvider dataValidateCheckInvalid
95
+     */
96
+    public function testValidateCheckInvalid(string $operator, string $value, int $exceptionCode, string $exceptionMessage): void {
97
+        $check = $this->getCheckMock();
98
+
99
+        try {
100
+            /** @var AbstractStringCheck $check */
101
+            $check->validateCheck($operator, $value);
102
+        } catch (\UnexpectedValueException $e) {
103
+            $this->assertEquals($exceptionCode, $e->getCode());
104
+            $this->assertEquals($exceptionMessage, $e->getMessage());
105
+        }
106
+    }
107
+
108
+    public static function dataMatch(): array {
109
+        return [
110
+            ['/valid/', 'valid', [], true],
111
+            ['/valid/', 'valid', [md5('/valid/') => [md5('valid') => false]], false], // Cache hit
112
+        ];
113
+    }
114
+
115
+    /**
116
+     * @dataProvider dataMatch
117
+     */
118
+    public function testMatch(string $pattern, string $subject, array $matches, bool $expected): void {
119
+        $check = $this->getCheckMock();
120
+
121
+        $this->invokePrivate($check, 'matches', [$matches]);
122
+
123
+        $this->assertEquals($expected, $this->invokePrivate($check, 'match', [$pattern, $subject]));
124
+    }
125 125
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -13,13 +13,13 @@
 block discarded – undo
13 13
 use PHPUnit\Framework\MockObject\MockObject;
14 14
 
15 15
 class AbstractStringCheckTest extends \Test\TestCase {
16
-	protected function getCheckMock(): AbstractStringCheck|MockObject {
16
+	protected function getCheckMock(): AbstractStringCheck | MockObject {
17 17
 		$l = $this->getMockBuilder(IL10N::class)
18 18
 			->disableOriginalConstructor()
19 19
 			->getMock();
20 20
 		$l->expects($this->any())
21 21
 			->method('t')
22
-			->willReturnCallback(function ($string, $args) {
22
+			->willReturnCallback(function($string, $args) {
23 23
 				return sprintf($string, $args);
24 24
 			});
25 25
 
Please login to merge, or discard this patch.
apps/workflowengine/tests/Check/RequestTimeTest.php 2 patches
Indentation   +117 added lines, -117 removed lines patch added patch discarded remove patch
@@ -14,121 +14,121 @@
 block discarded – undo
14 14
 use PHPUnit\Framework\MockObject\MockObject;
15 15
 
16 16
 class RequestTimeTest extends \Test\TestCase {
17
-	protected ITimeFactory&MockObject $timeFactory;
18
-
19
-	protected function getL10NMock(): IL10N&MockObject {
20
-		$l = $this->createMock(IL10N::class);
21
-		$l->expects($this->any())
22
-			->method('t')
23
-			->willReturnCallback(function ($string, $args) {
24
-				return sprintf($string, $args);
25
-			});
26
-		return $l;
27
-	}
28
-
29
-	protected function setUp(): void {
30
-		parent::setUp();
31
-
32
-		$this->timeFactory = $this->createMock(ITimeFactory::class);
33
-	}
34
-
35
-	public static function dataExecuteCheck(): array {
36
-		return [
37
-			[json_encode(['08:00 Europe/Berlin', '17:00 Europe/Berlin']), 1467870105, false], // 2016-07-07T07:41:45+02:00
38
-			[json_encode(['08:00 Europe/Berlin', '17:00 Europe/Berlin']), 1467873705, true], // 2016-07-07T08:41:45+02:00
39
-			[json_encode(['08:00 Europe/Berlin', '17:00 Europe/Berlin']), 1467902505, true], // 2016-07-07T16:41:45+02:00
40
-			[json_encode(['08:00 Europe/Berlin', '17:00 Europe/Berlin']), 1467906105, false], // 2016-07-07T17:41:45+02:00
41
-			[json_encode(['17:00 Europe/Berlin', '08:00 Europe/Berlin']), 1467870105, true], // 2016-07-07T07:41:45+02:00
42
-			[json_encode(['17:00 Europe/Berlin', '08:00 Europe/Berlin']), 1467873705, false], // 2016-07-07T08:41:45+02:00
43
-			[json_encode(['17:00 Europe/Berlin', '08:00 Europe/Berlin']), 1467902505, false], // 2016-07-07T16:41:45+02:00
44
-			[json_encode(['17:00 Europe/Berlin', '08:00 Europe/Berlin']), 1467906105, true], // 2016-07-07T17:41:45+02:00
45
-
46
-			[json_encode(['08:00 Australia/Adelaide', '17:00 Australia/Adelaide']), 1467843105, false], // 2016-07-07T07:41:45+09:30
47
-			[json_encode(['08:00 Australia/Adelaide', '17:00 Australia/Adelaide']), 1467846705, true], // 2016-07-07T08:41:45+09:30
48
-			[json_encode(['08:00 Australia/Adelaide', '17:00 Australia/Adelaide']), 1467875505, true], // 2016-07-07T16:41:45+09:30
49
-			[json_encode(['08:00 Australia/Adelaide', '17:00 Australia/Adelaide']), 1467879105, false], // 2016-07-07T17:41:45+09:30
50
-			[json_encode(['17:00 Australia/Adelaide', '08:00 Australia/Adelaide']), 1467843105, true], // 2016-07-07T07:41:45+09:30
51
-			[json_encode(['17:00 Australia/Adelaide', '08:00 Australia/Adelaide']), 1467846705, false], // 2016-07-07T08:41:45+09:30
52
-			[json_encode(['17:00 Australia/Adelaide', '08:00 Australia/Adelaide']), 1467875505, false], // 2016-07-07T16:41:45+09:30
53
-			[json_encode(['17:00 Australia/Adelaide', '08:00 Australia/Adelaide']), 1467879105, true], // 2016-07-07T17:41:45+09:30
54
-
55
-			[json_encode(['08:00 Pacific/Niue', '17:00 Pacific/Niue']), 1467916905, false], // 2016-07-07T07:41:45-11:00
56
-			[json_encode(['08:00 Pacific/Niue', '17:00 Pacific/Niue']), 1467920505, true], // 2016-07-07T08:41:45-11:00
57
-			[json_encode(['08:00 Pacific/Niue', '17:00 Pacific/Niue']), 1467949305, true], // 2016-07-07T16:41:45-11:00
58
-			[json_encode(['08:00 Pacific/Niue', '17:00 Pacific/Niue']), 1467952905, false], // 2016-07-07T17:41:45-11:00
59
-			[json_encode(['17:00 Pacific/Niue', '08:00 Pacific/Niue']), 1467916905, true], // 2016-07-07T07:41:45-11:00
60
-			[json_encode(['17:00 Pacific/Niue', '08:00 Pacific/Niue']), 1467920505, false], // 2016-07-07T08:41:45-11:00
61
-			[json_encode(['17:00 Pacific/Niue', '08:00 Pacific/Niue']), 1467949305, false], // 2016-07-07T16:41:45-11:00
62
-			[json_encode(['17:00 Pacific/Niue', '08:00 Pacific/Niue']), 1467952905, true], // 2016-07-07T17:41:45-11:00
63
-		];
64
-	}
65
-
66
-	/**
67
-	 * @dataProvider dataExecuteCheck
68
-	 */
69
-	public function testExecuteCheckIn(string $value, int $timestamp, bool $expected): void {
70
-		$check = new RequestTime($this->getL10NMock(), $this->timeFactory);
71
-
72
-		$this->timeFactory->expects($this->once())
73
-			->method('getTime')
74
-			->willReturn($timestamp);
75
-
76
-		$this->assertEquals($expected, $check->executeCheck('in', $value));
77
-	}
78
-
79
-	/**
80
-	 * @dataProvider dataExecuteCheck
81
-	 */
82
-	public function testExecuteCheckNotIn(string $value, int $timestamp, bool $expected): void {
83
-		$check = new RequestTime($this->getL10NMock(), $this->timeFactory);
84
-
85
-		$this->timeFactory->expects($this->once())
86
-			->method('getTime')
87
-			->willReturn($timestamp);
88
-
89
-		$this->assertEquals(!$expected, $check->executeCheck('!in', $value));
90
-	}
91
-
92
-	public static function dataValidateCheck(): array {
93
-		return [
94
-			['in', '["08:00 Europe/Berlin","17:00 Europe/Berlin"]'],
95
-			['!in', '["08:00 Europe/Berlin","17:00 America/North_Dakota/Beulah"]'],
96
-			['in', '["08:00 America/Port-au-Prince","17:00 America/Argentina/San_Luis"]'],
97
-		];
98
-	}
99
-
100
-	/**
101
-	 * @dataProvider dataValidateCheck
102
-	 */
103
-	public function testValidateCheck(string $operator, string $value): void {
104
-		$check = new RequestTime($this->getL10NMock(), $this->timeFactory);
105
-		$check->validateCheck($operator, $value);
106
-		$this->addToAssertionCount(1);
107
-	}
108
-
109
-	public static function dataValidateCheckInvalid(): array {
110
-		return [
111
-			['!!in', '["08:00 Europe/Berlin","17:00 Europe/Berlin"]', 1, 'The given operator is invalid'],
112
-			['in', '["28:00 Europe/Berlin","17:00 Europe/Berlin"]', 2, 'The given time span is invalid'],
113
-			['in', '["08:00 Europe/Berlin","27:00 Europe/Berlin"]', 2, 'The given time span is invalid'],
114
-			['in', '["08:00 Europa/Berlin","17:00 Europe/Berlin"]', 3, 'The given start time is invalid'],
115
-			['in', '["08:00 Europe/Berlin","17:00 Europa/Berlin"]', 4, 'The given end time is invalid'],
116
-			['in', '["08:00 Europe/Bearlin","17:00 Europe/Berlin"]', 3, 'The given start time is invalid'],
117
-			['in', '["08:00 Europe/Berlin","17:00 Europe/Bearlin"]', 4, 'The given end time is invalid'],
118
-		];
119
-	}
120
-
121
-	/**
122
-	 * @dataProvider dataValidateCheckInvalid
123
-	 */
124
-	public function testValidateCheckInvalid(string $operator, string $value, int $exceptionCode, string $exceptionMessage): void {
125
-		$check = new RequestTime($this->getL10NMock(), $this->timeFactory);
126
-
127
-		try {
128
-			$check->validateCheck($operator, $value);
129
-		} catch (\UnexpectedValueException $e) {
130
-			$this->assertEquals($exceptionCode, $e->getCode());
131
-			$this->assertEquals($exceptionMessage, $e->getMessage());
132
-		}
133
-	}
17
+    protected ITimeFactory&MockObject $timeFactory;
18
+
19
+    protected function getL10NMock(): IL10N&MockObject {
20
+        $l = $this->createMock(IL10N::class);
21
+        $l->expects($this->any())
22
+            ->method('t')
23
+            ->willReturnCallback(function ($string, $args) {
24
+                return sprintf($string, $args);
25
+            });
26
+        return $l;
27
+    }
28
+
29
+    protected function setUp(): void {
30
+        parent::setUp();
31
+
32
+        $this->timeFactory = $this->createMock(ITimeFactory::class);
33
+    }
34
+
35
+    public static function dataExecuteCheck(): array {
36
+        return [
37
+            [json_encode(['08:00 Europe/Berlin', '17:00 Europe/Berlin']), 1467870105, false], // 2016-07-07T07:41:45+02:00
38
+            [json_encode(['08:00 Europe/Berlin', '17:00 Europe/Berlin']), 1467873705, true], // 2016-07-07T08:41:45+02:00
39
+            [json_encode(['08:00 Europe/Berlin', '17:00 Europe/Berlin']), 1467902505, true], // 2016-07-07T16:41:45+02:00
40
+            [json_encode(['08:00 Europe/Berlin', '17:00 Europe/Berlin']), 1467906105, false], // 2016-07-07T17:41:45+02:00
41
+            [json_encode(['17:00 Europe/Berlin', '08:00 Europe/Berlin']), 1467870105, true], // 2016-07-07T07:41:45+02:00
42
+            [json_encode(['17:00 Europe/Berlin', '08:00 Europe/Berlin']), 1467873705, false], // 2016-07-07T08:41:45+02:00
43
+            [json_encode(['17:00 Europe/Berlin', '08:00 Europe/Berlin']), 1467902505, false], // 2016-07-07T16:41:45+02:00
44
+            [json_encode(['17:00 Europe/Berlin', '08:00 Europe/Berlin']), 1467906105, true], // 2016-07-07T17:41:45+02:00
45
+
46
+            [json_encode(['08:00 Australia/Adelaide', '17:00 Australia/Adelaide']), 1467843105, false], // 2016-07-07T07:41:45+09:30
47
+            [json_encode(['08:00 Australia/Adelaide', '17:00 Australia/Adelaide']), 1467846705, true], // 2016-07-07T08:41:45+09:30
48
+            [json_encode(['08:00 Australia/Adelaide', '17:00 Australia/Adelaide']), 1467875505, true], // 2016-07-07T16:41:45+09:30
49
+            [json_encode(['08:00 Australia/Adelaide', '17:00 Australia/Adelaide']), 1467879105, false], // 2016-07-07T17:41:45+09:30
50
+            [json_encode(['17:00 Australia/Adelaide', '08:00 Australia/Adelaide']), 1467843105, true], // 2016-07-07T07:41:45+09:30
51
+            [json_encode(['17:00 Australia/Adelaide', '08:00 Australia/Adelaide']), 1467846705, false], // 2016-07-07T08:41:45+09:30
52
+            [json_encode(['17:00 Australia/Adelaide', '08:00 Australia/Adelaide']), 1467875505, false], // 2016-07-07T16:41:45+09:30
53
+            [json_encode(['17:00 Australia/Adelaide', '08:00 Australia/Adelaide']), 1467879105, true], // 2016-07-07T17:41:45+09:30
54
+
55
+            [json_encode(['08:00 Pacific/Niue', '17:00 Pacific/Niue']), 1467916905, false], // 2016-07-07T07:41:45-11:00
56
+            [json_encode(['08:00 Pacific/Niue', '17:00 Pacific/Niue']), 1467920505, true], // 2016-07-07T08:41:45-11:00
57
+            [json_encode(['08:00 Pacific/Niue', '17:00 Pacific/Niue']), 1467949305, true], // 2016-07-07T16:41:45-11:00
58
+            [json_encode(['08:00 Pacific/Niue', '17:00 Pacific/Niue']), 1467952905, false], // 2016-07-07T17:41:45-11:00
59
+            [json_encode(['17:00 Pacific/Niue', '08:00 Pacific/Niue']), 1467916905, true], // 2016-07-07T07:41:45-11:00
60
+            [json_encode(['17:00 Pacific/Niue', '08:00 Pacific/Niue']), 1467920505, false], // 2016-07-07T08:41:45-11:00
61
+            [json_encode(['17:00 Pacific/Niue', '08:00 Pacific/Niue']), 1467949305, false], // 2016-07-07T16:41:45-11:00
62
+            [json_encode(['17:00 Pacific/Niue', '08:00 Pacific/Niue']), 1467952905, true], // 2016-07-07T17:41:45-11:00
63
+        ];
64
+    }
65
+
66
+    /**
67
+     * @dataProvider dataExecuteCheck
68
+     */
69
+    public function testExecuteCheckIn(string $value, int $timestamp, bool $expected): void {
70
+        $check = new RequestTime($this->getL10NMock(), $this->timeFactory);
71
+
72
+        $this->timeFactory->expects($this->once())
73
+            ->method('getTime')
74
+            ->willReturn($timestamp);
75
+
76
+        $this->assertEquals($expected, $check->executeCheck('in', $value));
77
+    }
78
+
79
+    /**
80
+     * @dataProvider dataExecuteCheck
81
+     */
82
+    public function testExecuteCheckNotIn(string $value, int $timestamp, bool $expected): void {
83
+        $check = new RequestTime($this->getL10NMock(), $this->timeFactory);
84
+
85
+        $this->timeFactory->expects($this->once())
86
+            ->method('getTime')
87
+            ->willReturn($timestamp);
88
+
89
+        $this->assertEquals(!$expected, $check->executeCheck('!in', $value));
90
+    }
91
+
92
+    public static function dataValidateCheck(): array {
93
+        return [
94
+            ['in', '["08:00 Europe/Berlin","17:00 Europe/Berlin"]'],
95
+            ['!in', '["08:00 Europe/Berlin","17:00 America/North_Dakota/Beulah"]'],
96
+            ['in', '["08:00 America/Port-au-Prince","17:00 America/Argentina/San_Luis"]'],
97
+        ];
98
+    }
99
+
100
+    /**
101
+     * @dataProvider dataValidateCheck
102
+     */
103
+    public function testValidateCheck(string $operator, string $value): void {
104
+        $check = new RequestTime($this->getL10NMock(), $this->timeFactory);
105
+        $check->validateCheck($operator, $value);
106
+        $this->addToAssertionCount(1);
107
+    }
108
+
109
+    public static function dataValidateCheckInvalid(): array {
110
+        return [
111
+            ['!!in', '["08:00 Europe/Berlin","17:00 Europe/Berlin"]', 1, 'The given operator is invalid'],
112
+            ['in', '["28:00 Europe/Berlin","17:00 Europe/Berlin"]', 2, 'The given time span is invalid'],
113
+            ['in', '["08:00 Europe/Berlin","27:00 Europe/Berlin"]', 2, 'The given time span is invalid'],
114
+            ['in', '["08:00 Europa/Berlin","17:00 Europe/Berlin"]', 3, 'The given start time is invalid'],
115
+            ['in', '["08:00 Europe/Berlin","17:00 Europa/Berlin"]', 4, 'The given end time is invalid'],
116
+            ['in', '["08:00 Europe/Bearlin","17:00 Europe/Berlin"]', 3, 'The given start time is invalid'],
117
+            ['in', '["08:00 Europe/Berlin","17:00 Europe/Bearlin"]', 4, 'The given end time is invalid'],
118
+        ];
119
+    }
120
+
121
+    /**
122
+     * @dataProvider dataValidateCheckInvalid
123
+     */
124
+    public function testValidateCheckInvalid(string $operator, string $value, int $exceptionCode, string $exceptionMessage): void {
125
+        $check = new RequestTime($this->getL10NMock(), $this->timeFactory);
126
+
127
+        try {
128
+            $check->validateCheck($operator, $value);
129
+        } catch (\UnexpectedValueException $e) {
130
+            $this->assertEquals($exceptionCode, $e->getCode());
131
+            $this->assertEquals($exceptionMessage, $e->getMessage());
132
+        }
133
+    }
134 134
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -20,7 +20,7 @@
 block discarded – undo
20 20
 		$l = $this->createMock(IL10N::class);
21 21
 		$l->expects($this->any())
22 22
 			->method('t')
23
-			->willReturnCallback(function ($string, $args) {
23
+			->willReturnCallback(function($string, $args) {
24 24
 				return sprintf($string, $args);
25 25
 			});
26 26
 		return $l;
Please login to merge, or discard this patch.
apps/dashboard/tests/DashboardServiceTest.php 1 patch
Indentation   +76 added lines, -76 removed lines patch added patch discarded remove patch
@@ -20,81 +20,81 @@
 block discarded – undo
20 20
 
21 21
 class DashboardServiceTest extends TestCase {
22 22
 
23
-	private IConfig&MockObject $config;
24
-	private IUserManager&MockObject $userManager;
25
-	private IAccountManager&MockObject $accountManager;
26
-	private DashboardService $service;
27
-
28
-	protected function setUp(): void {
29
-		parent::setUp();
30
-
31
-		$this->config = $this->createMock(IConfig::class);
32
-		$this->userManager = $this->createMock(IUserManager::class);
33
-		$this->accountManager = $this->createMock(IAccountManager::class);
34
-
35
-		$this->service = new DashboardService(
36
-			$this->config,
37
-			'alice',
38
-			$this->userManager,
39
-			$this->accountManager,
40
-		);
41
-	}
42
-
43
-	public function testGetBirthdate(): void {
44
-		$user = $this->createMock(IUser::class);
45
-		$this->userManager->method('get')
46
-			->willReturn($user);
47
-
48
-		$account = new Account($user);
49
-		$account->setProperty(
50
-			IAccountManager::PROPERTY_BIRTHDATE,
51
-			'2024-12-10T00:00:00.000Z',
52
-			IAccountManager::SCOPE_LOCAL,
53
-			IAccountManager::VERIFIED,
54
-		);
55
-
56
-		$this->accountManager->method('getAccount')
57
-			->willReturn($account);
58
-
59
-		$birthdate = $this->service->getBirthdate();
60
-
61
-		$this->assertEquals('2024-12-10T00:00:00.000Z', $birthdate);
62
-	}
63
-
64
-	public function testGetBirthdatePropertyDoesNotExist(): void {
65
-		$user = $this->createMock(IUser::class);
66
-		$this->userManager->method('get')
67
-			->willReturn($user);
68
-
69
-		$account = new Account($user);
70
-		$this->accountManager->method('getAccount')
71
-			->willReturn($account);
72
-
73
-		$birthdate = $this->service->getBirthdate();
74
-
75
-		$this->assertEquals('', $birthdate);
76
-	}
77
-
78
-	public function testGetBirthdateUserNotFound(): void {
79
-		$this->userManager->method('get')
80
-			->willReturn(null);
81
-
82
-		$birthdate = $this->service->getBirthdate();
83
-
84
-		$this->assertEquals('', $birthdate);
85
-	}
86
-
87
-	public function testGetBirthdateNoUserId(): void {
88
-		$service = new DashboardService(
89
-			$this->config,
90
-			null,
91
-			$this->userManager,
92
-			$this->accountManager,
93
-		);
94
-
95
-		$birthdate = $service->getBirthdate();
96
-
97
-		$this->assertEquals('', $birthdate);
98
-	}
23
+    private IConfig&MockObject $config;
24
+    private IUserManager&MockObject $userManager;
25
+    private IAccountManager&MockObject $accountManager;
26
+    private DashboardService $service;
27
+
28
+    protected function setUp(): void {
29
+        parent::setUp();
30
+
31
+        $this->config = $this->createMock(IConfig::class);
32
+        $this->userManager = $this->createMock(IUserManager::class);
33
+        $this->accountManager = $this->createMock(IAccountManager::class);
34
+
35
+        $this->service = new DashboardService(
36
+            $this->config,
37
+            'alice',
38
+            $this->userManager,
39
+            $this->accountManager,
40
+        );
41
+    }
42
+
43
+    public function testGetBirthdate(): void {
44
+        $user = $this->createMock(IUser::class);
45
+        $this->userManager->method('get')
46
+            ->willReturn($user);
47
+
48
+        $account = new Account($user);
49
+        $account->setProperty(
50
+            IAccountManager::PROPERTY_BIRTHDATE,
51
+            '2024-12-10T00:00:00.000Z',
52
+            IAccountManager::SCOPE_LOCAL,
53
+            IAccountManager::VERIFIED,
54
+        );
55
+
56
+        $this->accountManager->method('getAccount')
57
+            ->willReturn($account);
58
+
59
+        $birthdate = $this->service->getBirthdate();
60
+
61
+        $this->assertEquals('2024-12-10T00:00:00.000Z', $birthdate);
62
+    }
63
+
64
+    public function testGetBirthdatePropertyDoesNotExist(): void {
65
+        $user = $this->createMock(IUser::class);
66
+        $this->userManager->method('get')
67
+            ->willReturn($user);
68
+
69
+        $account = new Account($user);
70
+        $this->accountManager->method('getAccount')
71
+            ->willReturn($account);
72
+
73
+        $birthdate = $this->service->getBirthdate();
74
+
75
+        $this->assertEquals('', $birthdate);
76
+    }
77
+
78
+    public function testGetBirthdateUserNotFound(): void {
79
+        $this->userManager->method('get')
80
+            ->willReturn(null);
81
+
82
+        $birthdate = $this->service->getBirthdate();
83
+
84
+        $this->assertEquals('', $birthdate);
85
+    }
86
+
87
+    public function testGetBirthdateNoUserId(): void {
88
+        $service = new DashboardService(
89
+            $this->config,
90
+            null,
91
+            $this->userManager,
92
+            $this->accountManager,
93
+        );
94
+
95
+        $birthdate = $service->getBirthdate();
96
+
97
+        $this->assertEquals('', $birthdate);
98
+    }
99 99
 
100 100
 }
Please login to merge, or discard this patch.
apps/comments/tests/Unit/AppInfo/ApplicationTest.php 1 patch
Indentation   +30 added lines, -30 removed lines patch added patch discarded remove patch
@@ -29,34 +29,34 @@
 block discarded – undo
29 29
  * @package OCA\Comments\Tests\Unit\AppInfo
30 30
  */
31 31
 class ApplicationTest extends TestCase {
32
-	protected function setUp(): void {
33
-		parent::setUp();
34
-		Server::get(IUserManager::class)->createUser('dummy', '456');
35
-		Server::get(IUserSession::class)->setUser(Server::get(IUserManager::class)->get('dummy'));
36
-	}
37
-
38
-	protected function tearDown(): void {
39
-		Server::get(IUserManager::class)->get('dummy')->delete();
40
-		parent::tearDown();
41
-	}
42
-
43
-	public function test(): void {
44
-		$app = new Application();
45
-		$c = $app->getContainer();
46
-
47
-		$services = [
48
-			NotificationsController::class,
49
-			Filter::class,
50
-			Listener::class,
51
-			Provider::class,
52
-			Setting::class,
53
-			\OCA\Comments\Notification\Listener::class,
54
-			Notifier::class,
55
-		];
56
-
57
-		foreach ($services as $service) {
58
-			$s = $c->get($service);
59
-			$this->assertInstanceOf($service, $s);
60
-		}
61
-	}
32
+    protected function setUp(): void {
33
+        parent::setUp();
34
+        Server::get(IUserManager::class)->createUser('dummy', '456');
35
+        Server::get(IUserSession::class)->setUser(Server::get(IUserManager::class)->get('dummy'));
36
+    }
37
+
38
+    protected function tearDown(): void {
39
+        Server::get(IUserManager::class)->get('dummy')->delete();
40
+        parent::tearDown();
41
+    }
42
+
43
+    public function test(): void {
44
+        $app = new Application();
45
+        $c = $app->getContainer();
46
+
47
+        $services = [
48
+            NotificationsController::class,
49
+            Filter::class,
50
+            Listener::class,
51
+            Provider::class,
52
+            Setting::class,
53
+            \OCA\Comments\Notification\Listener::class,
54
+            Notifier::class,
55
+        ];
56
+
57
+        foreach ($services as $service) {
58
+            $s = $c->get($service);
59
+            $this->assertInstanceOf($service, $s);
60
+        }
61
+    }
62 62
 }
Please login to merge, or discard this patch.
apps/comments/tests/Unit/Collaboration/CommentersSorterTest.php 1 patch
Indentation   +116 added lines, -116 removed lines patch added patch discarded remove patch
@@ -12,128 +12,128 @@
 block discarded – undo
12 12
 use Test\TestCase;
13 13
 
14 14
 class CommentersSorterTest extends TestCase {
15
-	protected ICommentsManager&MockObject $commentsManager;
16
-	protected CommentersSorter $sorter;
15
+    protected ICommentsManager&MockObject $commentsManager;
16
+    protected CommentersSorter $sorter;
17 17
 
18
-	protected function setUp(): void {
19
-		parent::setUp();
18
+    protected function setUp(): void {
19
+        parent::setUp();
20 20
 
21
-		$this->commentsManager = $this->createMock(ICommentsManager::class);
21
+        $this->commentsManager = $this->createMock(ICommentsManager::class);
22 22
 
23
-		$this->sorter = new CommentersSorter($this->commentsManager);
24
-	}
23
+        $this->sorter = new CommentersSorter($this->commentsManager);
24
+    }
25 25
 
26
-	/**
27
-	 * @dataProvider sortDataProvider
28
-	 * @param $data
29
-	 */
30
-	public function testSort($data): void {
31
-		$commentMocks = [];
32
-		foreach ($data['actors'] as $actorType => $actors) {
33
-			foreach ($actors as $actorId => $noOfComments) {
34
-				for ($i = 0;$i < $noOfComments;$i++) {
35
-					$mock = $this->createMock(IComment::class);
36
-					$mock->expects($this->atLeastOnce())
37
-						->method('getActorType')
38
-						->willReturn($actorType);
39
-					$mock->expects($this->atLeastOnce())
40
-						->method('getActorId')
41
-						->willReturn($actorId);
42
-					$commentMocks[] = $mock;
43
-				}
44
-			}
45
-		}
26
+    /**
27
+     * @dataProvider sortDataProvider
28
+     * @param $data
29
+     */
30
+    public function testSort($data): void {
31
+        $commentMocks = [];
32
+        foreach ($data['actors'] as $actorType => $actors) {
33
+            foreach ($actors as $actorId => $noOfComments) {
34
+                for ($i = 0;$i < $noOfComments;$i++) {
35
+                    $mock = $this->createMock(IComment::class);
36
+                    $mock->expects($this->atLeastOnce())
37
+                        ->method('getActorType')
38
+                        ->willReturn($actorType);
39
+                    $mock->expects($this->atLeastOnce())
40
+                        ->method('getActorId')
41
+                        ->willReturn($actorId);
42
+                    $commentMocks[] = $mock;
43
+                }
44
+            }
45
+        }
46 46
 
47
-		$this->commentsManager->expects($this->once())
48
-			->method('getForObject')
49
-			->willReturn($commentMocks);
47
+        $this->commentsManager->expects($this->once())
48
+            ->method('getForObject')
49
+            ->willReturn($commentMocks);
50 50
 
51
-		$workArray = $data['input'];
52
-		$this->sorter->sort($workArray, ['itemType' => 'files', 'itemId' => '24']);
51
+        $workArray = $data['input'];
52
+        $this->sorter->sort($workArray, ['itemType' => 'files', 'itemId' => '24']);
53 53
 
54
-		$this->assertEquals($data['expected'], $workArray);
55
-	}
54
+        $this->assertEquals($data['expected'], $workArray);
55
+    }
56 56
 
57
-	public static function sortDataProvider(): array {
58
-		return [[
59
-			[
60
-				#1 – sort properly and otherwise keep existing order
61
-				'actors' => ['users' => ['celia' => 3, 'darius' => 7, 'faruk' => 5, 'gail' => 5], 'bots' => ['r2-d2' => 8]],
62
-				'input' => [
63
-					'users' =>
64
-						[
65
-							['value' => ['shareWith' => 'alice']],
66
-							['value' => ['shareWith' => 'bob']],
67
-							['value' => ['shareWith' => 'celia']],
68
-							['value' => ['shareWith' => 'darius']],
69
-							['value' => ['shareWith' => 'elena']],
70
-							['value' => ['shareWith' => 'faruk']],
71
-							['value' => ['shareWith' => 'gail']],
72
-						],
73
-					'bots' => [
74
-						['value' => ['shareWith' => 'c-3po']],
75
-						['value' => ['shareWith' => 'r2-d2']],
76
-					]
77
-				],
78
-				'expected' => [
79
-					'users' =>
80
-						[
81
-							['value' => ['shareWith' => 'darius']],
82
-							['value' => ['shareWith' => 'faruk']],
83
-							['value' => ['shareWith' => 'gail']],
84
-							['value' => ['shareWith' => 'celia']],
85
-							['value' => ['shareWith' => 'alice']],
86
-							['value' => ['shareWith' => 'bob']],
87
-							['value' => ['shareWith' => 'elena']],
88
-						],
89
-					'bots' => [
90
-						['value' => ['shareWith' => 'r2-d2']],
91
-						['value' => ['shareWith' => 'c-3po']],
92
-					]
93
-				],
94
-			],
95
-			[
96
-				#2 – no commentors, input equals output
97
-				'actors' => [],
98
-				'input' => [
99
-					'users' =>
100
-						[
101
-							['value' => ['shareWith' => 'alice']],
102
-							['value' => ['shareWith' => 'bob']],
103
-							['value' => ['shareWith' => 'celia']],
104
-							['value' => ['shareWith' => 'darius']],
105
-							['value' => ['shareWith' => 'elena']],
106
-							['value' => ['shareWith' => 'faruk']],
107
-							['value' => ['shareWith' => 'gail']],
108
-						],
109
-					'bots' => [
110
-						['value' => ['shareWith' => 'c-3po']],
111
-						['value' => ['shareWith' => 'r2-d2']],
112
-					]
113
-				],
114
-				'expected' => [
115
-					'users' =>
116
-						[
117
-							['value' => ['shareWith' => 'alice']],
118
-							['value' => ['shareWith' => 'bob']],
119
-							['value' => ['shareWith' => 'celia']],
120
-							['value' => ['shareWith' => 'darius']],
121
-							['value' => ['shareWith' => 'elena']],
122
-							['value' => ['shareWith' => 'faruk']],
123
-							['value' => ['shareWith' => 'gail']],
124
-						],
125
-					'bots' => [
126
-						['value' => ['shareWith' => 'c-3po']],
127
-						['value' => ['shareWith' => 'r2-d2']],
128
-					]
129
-				],
130
-			],
131
-			[
132
-				#3 – no nothing
133
-				'actors' => [],
134
-				'input' => [],
135
-				'expected' => [],
136
-			],
137
-		]];
138
-	}
57
+    public static function sortDataProvider(): array {
58
+        return [[
59
+            [
60
+                #1 – sort properly and otherwise keep existing order
61
+                'actors' => ['users' => ['celia' => 3, 'darius' => 7, 'faruk' => 5, 'gail' => 5], 'bots' => ['r2-d2' => 8]],
62
+                'input' => [
63
+                    'users' =>
64
+                        [
65
+                            ['value' => ['shareWith' => 'alice']],
66
+                            ['value' => ['shareWith' => 'bob']],
67
+                            ['value' => ['shareWith' => 'celia']],
68
+                            ['value' => ['shareWith' => 'darius']],
69
+                            ['value' => ['shareWith' => 'elena']],
70
+                            ['value' => ['shareWith' => 'faruk']],
71
+                            ['value' => ['shareWith' => 'gail']],
72
+                        ],
73
+                    'bots' => [
74
+                        ['value' => ['shareWith' => 'c-3po']],
75
+                        ['value' => ['shareWith' => 'r2-d2']],
76
+                    ]
77
+                ],
78
+                'expected' => [
79
+                    'users' =>
80
+                        [
81
+                            ['value' => ['shareWith' => 'darius']],
82
+                            ['value' => ['shareWith' => 'faruk']],
83
+                            ['value' => ['shareWith' => 'gail']],
84
+                            ['value' => ['shareWith' => 'celia']],
85
+                            ['value' => ['shareWith' => 'alice']],
86
+                            ['value' => ['shareWith' => 'bob']],
87
+                            ['value' => ['shareWith' => 'elena']],
88
+                        ],
89
+                    'bots' => [
90
+                        ['value' => ['shareWith' => 'r2-d2']],
91
+                        ['value' => ['shareWith' => 'c-3po']],
92
+                    ]
93
+                ],
94
+            ],
95
+            [
96
+                #2 – no commentors, input equals output
97
+                'actors' => [],
98
+                'input' => [
99
+                    'users' =>
100
+                        [
101
+                            ['value' => ['shareWith' => 'alice']],
102
+                            ['value' => ['shareWith' => 'bob']],
103
+                            ['value' => ['shareWith' => 'celia']],
104
+                            ['value' => ['shareWith' => 'darius']],
105
+                            ['value' => ['shareWith' => 'elena']],
106
+                            ['value' => ['shareWith' => 'faruk']],
107
+                            ['value' => ['shareWith' => 'gail']],
108
+                        ],
109
+                    'bots' => [
110
+                        ['value' => ['shareWith' => 'c-3po']],
111
+                        ['value' => ['shareWith' => 'r2-d2']],
112
+                    ]
113
+                ],
114
+                'expected' => [
115
+                    'users' =>
116
+                        [
117
+                            ['value' => ['shareWith' => 'alice']],
118
+                            ['value' => ['shareWith' => 'bob']],
119
+                            ['value' => ['shareWith' => 'celia']],
120
+                            ['value' => ['shareWith' => 'darius']],
121
+                            ['value' => ['shareWith' => 'elena']],
122
+                            ['value' => ['shareWith' => 'faruk']],
123
+                            ['value' => ['shareWith' => 'gail']],
124
+                        ],
125
+                    'bots' => [
126
+                        ['value' => ['shareWith' => 'c-3po']],
127
+                        ['value' => ['shareWith' => 'r2-d2']],
128
+                    ]
129
+                ],
130
+            ],
131
+            [
132
+                #3 – no nothing
133
+                'actors' => [],
134
+                'input' => [],
135
+                'expected' => [],
136
+            ],
137
+        ]];
138
+    }
139 139
 }
Please login to merge, or discard this patch.
apps/comments/tests/Unit/Controller/NotificationsTest.php 1 patch
Indentation   +183 added lines, -183 removed lines patch added patch discarded remove patch
@@ -28,187 +28,187 @@
 block discarded – undo
28 28
 use Test\TestCase;
29 29
 
30 30
 class NotificationsTest extends TestCase {
31
-	protected ICommentsManager&MockObject $commentsManager;
32
-	protected IRootFolder&MockObject $rootFolder;
33
-	protected IUserSession&MockObject $session;
34
-	protected IManager&MockObject $notificationManager;
35
-	protected IURLGenerator&MockObject $urlGenerator;
36
-	protected NotificationsController $notificationsController;
37
-
38
-	protected function setUp(): void {
39
-		parent::setUp();
40
-
41
-		$this->commentsManager = $this->createMock(ICommentsManager::class);
42
-		$this->rootFolder = $this->createMock(IRootFolder::class);
43
-		$this->session = $this->createMock(IUserSession::class);
44
-		$this->notificationManager = $this->createMock(IManager::class);
45
-		$this->urlGenerator = $this->createMock(IURLGenerator::class);
46
-
47
-		$this->notificationsController = new NotificationsController(
48
-			'comments',
49
-			$this->createMock(IRequest::class),
50
-			$this->commentsManager,
51
-			$this->rootFolder,
52
-			$this->urlGenerator,
53
-			$this->notificationManager,
54
-			$this->session
55
-		);
56
-	}
57
-
58
-	public function testViewGuestRedirect(): void {
59
-		$this->commentsManager->expects($this->never())
60
-			->method('get');
61
-
62
-		$this->rootFolder->expects($this->never())
63
-			->method('getUserFolder');
64
-
65
-		$this->session->expects($this->once())
66
-			->method('getUser')
67
-			->willReturn(null);
68
-
69
-		$this->notificationManager->expects($this->never())
70
-			->method('createNotification');
71
-		$this->notificationManager->expects($this->never())
72
-			->method('markProcessed');
73
-
74
-		$this->urlGenerator->expects($this->exactly(2))
75
-			->method('linkToRoute')
76
-			->willReturnMap([
77
-				['comments.Notifications.view', ['id' => '42'], 'link-to-comment'],
78
-				['core.login.showLoginForm', ['redirect_url' => 'link-to-comment'], 'link-to-login'],
79
-			]);
80
-
81
-		/** @var RedirectResponse $response */
82
-		$response = $this->notificationsController->view('42');
83
-		$this->assertInstanceOf(RedirectResponse::class, $response);
84
-		$this->assertSame('link-to-login', $response->getRedirectURL());
85
-	}
86
-
87
-	public function testViewSuccess(): void {
88
-		$comment = $this->createMock(IComment::class);
89
-		$comment->expects($this->any())
90
-			->method('getObjectType')
91
-			->willReturn('files');
92
-		$comment->expects($this->any())
93
-			->method('getId')
94
-			->willReturn('1234');
95
-
96
-		$this->commentsManager->expects($this->any())
97
-			->method('get')
98
-			->with('42')
99
-			->willReturn($comment);
100
-
101
-		$file = $this->createMock(Node::class);
102
-		$folder = $this->createMock(Folder::class);
103
-		$user = $this->createMock(IUser::class);
104
-
105
-		$this->rootFolder->expects($this->once())
106
-			->method('getUserFolder')
107
-			->willReturn($folder);
108
-
109
-		$folder->expects($this->once())
110
-			->method('getById')
111
-			->willReturn([$file]);
112
-
113
-		$this->session->expects($this->once())
114
-			->method('getUser')
115
-			->willReturn($user);
116
-
117
-		$user->expects($this->any())
118
-			->method('getUID')
119
-			->willReturn('user');
120
-
121
-		$notification = $this->createMock(INotification::class);
122
-		$notification->expects($this->any())
123
-			->method($this->anything())
124
-			->willReturn($notification);
125
-
126
-		$this->notificationManager->expects($this->once())
127
-			->method('createNotification')
128
-			->willReturn($notification);
129
-		$this->notificationManager->expects($this->once())
130
-			->method('markProcessed')
131
-			->with($notification);
132
-
133
-		$response = $this->notificationsController->view('42');
134
-		$this->assertInstanceOf(RedirectResponse::class, $response);
135
-	}
136
-
137
-	public function testViewInvalidComment(): void {
138
-		$this->commentsManager->expects($this->any())
139
-			->method('get')
140
-			->with('42')
141
-			->will($this->throwException(new NotFoundException()));
142
-
143
-		$this->rootFolder->expects($this->never())
144
-			->method('getUserFolder');
145
-
146
-		$user = $this->createMock(IUser::class);
147
-
148
-		$this->session->expects($this->once())
149
-			->method('getUser')
150
-			->willReturn($user);
151
-
152
-		$user->expects($this->any())
153
-			->method('getUID')
154
-			->willReturn('user');
155
-
156
-		$this->notificationManager->expects($this->never())
157
-			->method('createNotification');
158
-		$this->notificationManager->expects($this->never())
159
-			->method('markProcessed');
160
-
161
-		$response = $this->notificationsController->view('42');
162
-		$this->assertInstanceOf(NotFoundResponse::class, $response);
163
-	}
164
-
165
-	public function testViewNoFile(): void {
166
-		$comment = $this->createMock(IComment::class);
167
-		$comment->expects($this->any())
168
-			->method('getObjectType')
169
-			->willReturn('files');
170
-		$comment->expects($this->any())
171
-			->method('getId')
172
-			->willReturn('1234');
173
-
174
-		$this->commentsManager->expects($this->any())
175
-			->method('get')
176
-			->with('42')
177
-			->willReturn($comment);
178
-
179
-		$folder = $this->createMock(Folder::class);
180
-
181
-		$this->rootFolder->expects($this->once())
182
-			->method('getUserFolder')
183
-			->willReturn($folder);
184
-
185
-		$folder->expects($this->once())
186
-			->method('getById')
187
-			->willReturn([]);
188
-
189
-		$user = $this->createMock(IUser::class);
190
-
191
-		$this->session->expects($this->once())
192
-			->method('getUser')
193
-			->willReturn($user);
194
-
195
-		$user->expects($this->any())
196
-			->method('getUID')
197
-			->willReturn('user');
198
-
199
-		$notification = $this->createMock(INotification::class);
200
-		$notification->expects($this->any())
201
-			->method($this->anything())
202
-			->willReturn($notification);
203
-
204
-		$this->notificationManager->expects($this->once())
205
-			->method('createNotification')
206
-			->willReturn($notification);
207
-		$this->notificationManager->expects($this->once())
208
-			->method('markProcessed')
209
-			->with($notification);
210
-
211
-		$response = $this->notificationsController->view('42');
212
-		$this->assertInstanceOf(NotFoundResponse::class, $response);
213
-	}
31
+    protected ICommentsManager&MockObject $commentsManager;
32
+    protected IRootFolder&MockObject $rootFolder;
33
+    protected IUserSession&MockObject $session;
34
+    protected IManager&MockObject $notificationManager;
35
+    protected IURLGenerator&MockObject $urlGenerator;
36
+    protected NotificationsController $notificationsController;
37
+
38
+    protected function setUp(): void {
39
+        parent::setUp();
40
+
41
+        $this->commentsManager = $this->createMock(ICommentsManager::class);
42
+        $this->rootFolder = $this->createMock(IRootFolder::class);
43
+        $this->session = $this->createMock(IUserSession::class);
44
+        $this->notificationManager = $this->createMock(IManager::class);
45
+        $this->urlGenerator = $this->createMock(IURLGenerator::class);
46
+
47
+        $this->notificationsController = new NotificationsController(
48
+            'comments',
49
+            $this->createMock(IRequest::class),
50
+            $this->commentsManager,
51
+            $this->rootFolder,
52
+            $this->urlGenerator,
53
+            $this->notificationManager,
54
+            $this->session
55
+        );
56
+    }
57
+
58
+    public function testViewGuestRedirect(): void {
59
+        $this->commentsManager->expects($this->never())
60
+            ->method('get');
61
+
62
+        $this->rootFolder->expects($this->never())
63
+            ->method('getUserFolder');
64
+
65
+        $this->session->expects($this->once())
66
+            ->method('getUser')
67
+            ->willReturn(null);
68
+
69
+        $this->notificationManager->expects($this->never())
70
+            ->method('createNotification');
71
+        $this->notificationManager->expects($this->never())
72
+            ->method('markProcessed');
73
+
74
+        $this->urlGenerator->expects($this->exactly(2))
75
+            ->method('linkToRoute')
76
+            ->willReturnMap([
77
+                ['comments.Notifications.view', ['id' => '42'], 'link-to-comment'],
78
+                ['core.login.showLoginForm', ['redirect_url' => 'link-to-comment'], 'link-to-login'],
79
+            ]);
80
+
81
+        /** @var RedirectResponse $response */
82
+        $response = $this->notificationsController->view('42');
83
+        $this->assertInstanceOf(RedirectResponse::class, $response);
84
+        $this->assertSame('link-to-login', $response->getRedirectURL());
85
+    }
86
+
87
+    public function testViewSuccess(): void {
88
+        $comment = $this->createMock(IComment::class);
89
+        $comment->expects($this->any())
90
+            ->method('getObjectType')
91
+            ->willReturn('files');
92
+        $comment->expects($this->any())
93
+            ->method('getId')
94
+            ->willReturn('1234');
95
+
96
+        $this->commentsManager->expects($this->any())
97
+            ->method('get')
98
+            ->with('42')
99
+            ->willReturn($comment);
100
+
101
+        $file = $this->createMock(Node::class);
102
+        $folder = $this->createMock(Folder::class);
103
+        $user = $this->createMock(IUser::class);
104
+
105
+        $this->rootFolder->expects($this->once())
106
+            ->method('getUserFolder')
107
+            ->willReturn($folder);
108
+
109
+        $folder->expects($this->once())
110
+            ->method('getById')
111
+            ->willReturn([$file]);
112
+
113
+        $this->session->expects($this->once())
114
+            ->method('getUser')
115
+            ->willReturn($user);
116
+
117
+        $user->expects($this->any())
118
+            ->method('getUID')
119
+            ->willReturn('user');
120
+
121
+        $notification = $this->createMock(INotification::class);
122
+        $notification->expects($this->any())
123
+            ->method($this->anything())
124
+            ->willReturn($notification);
125
+
126
+        $this->notificationManager->expects($this->once())
127
+            ->method('createNotification')
128
+            ->willReturn($notification);
129
+        $this->notificationManager->expects($this->once())
130
+            ->method('markProcessed')
131
+            ->with($notification);
132
+
133
+        $response = $this->notificationsController->view('42');
134
+        $this->assertInstanceOf(RedirectResponse::class, $response);
135
+    }
136
+
137
+    public function testViewInvalidComment(): void {
138
+        $this->commentsManager->expects($this->any())
139
+            ->method('get')
140
+            ->with('42')
141
+            ->will($this->throwException(new NotFoundException()));
142
+
143
+        $this->rootFolder->expects($this->never())
144
+            ->method('getUserFolder');
145
+
146
+        $user = $this->createMock(IUser::class);
147
+
148
+        $this->session->expects($this->once())
149
+            ->method('getUser')
150
+            ->willReturn($user);
151
+
152
+        $user->expects($this->any())
153
+            ->method('getUID')
154
+            ->willReturn('user');
155
+
156
+        $this->notificationManager->expects($this->never())
157
+            ->method('createNotification');
158
+        $this->notificationManager->expects($this->never())
159
+            ->method('markProcessed');
160
+
161
+        $response = $this->notificationsController->view('42');
162
+        $this->assertInstanceOf(NotFoundResponse::class, $response);
163
+    }
164
+
165
+    public function testViewNoFile(): void {
166
+        $comment = $this->createMock(IComment::class);
167
+        $comment->expects($this->any())
168
+            ->method('getObjectType')
169
+            ->willReturn('files');
170
+        $comment->expects($this->any())
171
+            ->method('getId')
172
+            ->willReturn('1234');
173
+
174
+        $this->commentsManager->expects($this->any())
175
+            ->method('get')
176
+            ->with('42')
177
+            ->willReturn($comment);
178
+
179
+        $folder = $this->createMock(Folder::class);
180
+
181
+        $this->rootFolder->expects($this->once())
182
+            ->method('getUserFolder')
183
+            ->willReturn($folder);
184
+
185
+        $folder->expects($this->once())
186
+            ->method('getById')
187
+            ->willReturn([]);
188
+
189
+        $user = $this->createMock(IUser::class);
190
+
191
+        $this->session->expects($this->once())
192
+            ->method('getUser')
193
+            ->willReturn($user);
194
+
195
+        $user->expects($this->any())
196
+            ->method('getUID')
197
+            ->willReturn('user');
198
+
199
+        $notification = $this->createMock(INotification::class);
200
+        $notification->expects($this->any())
201
+            ->method($this->anything())
202
+            ->willReturn($notification);
203
+
204
+        $this->notificationManager->expects($this->once())
205
+            ->method('createNotification')
206
+            ->willReturn($notification);
207
+        $this->notificationManager->expects($this->once())
208
+            ->method('markProcessed')
209
+            ->with($notification);
210
+
211
+        $response = $this->notificationsController->view('42');
212
+        $this->assertInstanceOf(NotFoundResponse::class, $response);
213
+    }
214 214
 }
Please login to merge, or discard this patch.