Completed
Push — master ( d21bf9...85c141 )
by
unknown
24:49 queued 16s
created
apps/user_ldap/tests/WizardTest.php 2 patches
Indentation   +400 added lines, -400 removed lines patch added patch discarded remove patch
@@ -23,404 +23,404 @@
 block discarded – undo
23 23
  * @package OCA\User_LDAP\Tests
24 24
  */
25 25
 class WizardTest extends TestCase {
26
-	protected function setUp(): void {
27
-		parent::setUp();
28
-		//we need to make sure the consts are defined, otherwise tests will fail
29
-		//on systems without php5_ldap
30
-		$ldapConsts = ['LDAP_OPT_PROTOCOL_VERSION',
31
-			'LDAP_OPT_REFERRALS', 'LDAP_OPT_NETWORK_TIMEOUT'];
32
-		foreach ($ldapConsts as $const) {
33
-			if (!defined($const)) {
34
-				define($const, 42);
35
-			}
36
-		}
37
-	}
38
-
39
-	private function getWizardAndMocks(): array {
40
-		static $confMethods;
41
-
42
-		if (is_null($confMethods)) {
43
-			$confMethods = get_class_methods('\OCA\User_LDAP\Configuration');
44
-		}
45
-		/** @var ILDAPWrapper&MockObject $lw */
46
-		$lw = $this->createMock(ILDAPWrapper::class);
47
-
48
-		/** @var Configuration&MockObject $conf */
49
-		$conf = $this->getMockBuilder(Configuration::class)
50
-			->onlyMethods($confMethods)
51
-			->setConstructorArgs(['', true])
52
-			->getMock();
53
-
54
-		/** @var Access&MockObject $access */
55
-		$access = $this->createMock(Access::class);
56
-
57
-		return [new Wizard($conf, $lw, $access), $conf, $lw, $access];
58
-	}
59
-
60
-	private function prepareLdapWrapperForConnections(MockObject $ldap) {
61
-		$ldap->expects($this->once())
62
-			->method('connect')
63
-			//dummy value
64
-			->willReturn(ldap_connect('ldap://example.com'));
65
-
66
-		$ldap->expects($this->exactly(3))
67
-			->method('setOption')
68
-			->willReturn(true);
69
-
70
-		$ldap->expects($this->once())
71
-			->method('bind')
72
-			->willReturn(true);
73
-	}
74
-
75
-	public function testCumulativeSearchOnAttributeLimited(): void {
76
-		[$wizard, $configuration, $ldap] = $this->getWizardAndMocks();
77
-
78
-		$configuration->expects($this->any())
79
-			->method('__get')
80
-			->willReturnCallback(function ($name) {
81
-				if ($name === 'ldapBase') {
82
-					return ['base'];
83
-				}
84
-				return null;
85
-			});
86
-
87
-		$this->prepareLdapWrapperForConnections($ldap);
88
-
89
-		$ldap->expects($this->any())
90
-			->method('isResource')
91
-			->willReturn(true);
92
-
93
-		$ldap->expects($this->exactly(2))
94
-			->method('search')
95
-			//dummy value, usually invalid
96
-			->willReturn(true);
97
-
98
-		$ldap->expects($this->exactly(2))
99
-			->method('countEntries')
100
-			//an is_resource check will follow, so we need to return a dummy resource
101
-			->willReturn(23);
102
-
103
-		//5 DNs per filter means 2x firstEntry and 8x nextEntry
104
-		$ldap->expects($this->exactly(2))
105
-			->method('firstEntry')
106
-			//dummy value, usually invalid
107
-			->willReturn(true);
108
-
109
-		$ldap->expects($this->exactly(8))
110
-			->method('nextEntry')
111
-			//dummy value, usually invalid
112
-			->willReturn(true);
113
-
114
-		$ldap->expects($this->exactly(10))
115
-			->method('getAttributes')
116
-			//dummy value, usually invalid
117
-			->willReturn(['cn' => ['foo'], 'count' => 1]);
118
-
119
-		global $uidnumber;
120
-		$uidnumber = 1;
121
-		$ldap->expects($this->exactly(10))
122
-			->method('getDN')
123
-			//dummy value, usually invalid
124
-			->willReturnCallback(function ($a, $b) {
125
-				global $uidnumber;
126
-				return $uidnumber++;
127
-			});
128
-
129
-		// The following expectations are the real test
130
-		$filters = ['f1', 'f2', '*'];
131
-		$wizard->cumulativeSearchOnAttribute($filters, 'cn', 5);
132
-		unset($uidnumber);
133
-	}
134
-
135
-	public function testCumulativeSearchOnAttributeUnlimited(): void {
136
-		[$wizard, $configuration, $ldap] = $this->getWizardAndMocks();
137
-
138
-		$configuration->expects($this->any())
139
-			->method('__get')
140
-			->willReturnCallback(function ($name) {
141
-				if ($name === 'ldapBase') {
142
-					return ['base'];
143
-				}
144
-				return null;
145
-			});
146
-
147
-		$this->prepareLdapWrapperForConnections($ldap);
148
-
149
-		$ldap->expects($this->any())
150
-			->method('isResource')
151
-			->willReturnCallback(function ($r) {
152
-				if ($r instanceof \LDAP\Connection) {
153
-					return true;
154
-				}
155
-				if ($r % 24 === 0) {
156
-					global $uidnumber;
157
-					$uidnumber++;
158
-					return false;
159
-				}
160
-				return true;
161
-			});
162
-
163
-		$ldap->expects($this->exactly(2))
164
-			->method('search')
165
-			//dummy value, usually invalid
166
-			->willReturn(true);
167
-
168
-		$ldap->expects($this->exactly(2))
169
-			->method('countEntries')
170
-			//an is_resource check will follow, so we need to return a dummy resource
171
-			->willReturn(23);
172
-
173
-		//5 DNs per filter means 2x firstEntry and 8x nextEntry
174
-		$ldap->expects($this->exactly(2))
175
-			->method('firstEntry')
176
-			//dummy value, usually invalid
177
-			->willReturnCallback(function ($r) {
178
-				global $uidnumber;
179
-				return $uidnumber;
180
-			});
181
-
182
-		$ldap->expects($this->exactly(46))
183
-			->method('nextEntry')
184
-			//dummy value, usually invalid
185
-			->willReturnCallback(function ($r) {
186
-				global $uidnumber;
187
-				return $uidnumber;
188
-			});
189
-
190
-		$ldap->expects($this->exactly(46))
191
-			->method('getAttributes')
192
-			//dummy value, usually invalid
193
-			->willReturn(['cn' => ['foo'], 'count' => 1]);
194
-
195
-		global $uidnumber;
196
-		$uidnumber = 1;
197
-		$ldap->expects($this->exactly(46))
198
-			->method('getDN')
199
-			//dummy value, usually invalid
200
-			->willReturnCallback(function ($a, $b) {
201
-				global $uidnumber;
202
-				return $uidnumber++;
203
-			});
204
-
205
-		// The following expectations are the real test
206
-		$filters = ['f1', 'f2', '*'];
207
-		$wizard->cumulativeSearchOnAttribute($filters, 'cn', 0);
208
-		unset($uidnumber);
209
-	}
210
-
211
-	public function testDetectEmailAttributeAlreadySet(): void {
212
-		[$wizard, $configuration, $ldap, $access]
213
-			= $this->getWizardAndMocks();
214
-
215
-		$configuration->expects($this->any())
216
-			->method('__get')
217
-			->willReturnCallback(function ($name) {
218
-				if ($name === 'ldapEmailAttribute') {
219
-					return 'myEmailAttribute';
220
-				} else {
221
-					//for requirement checks
222
-					return 'let me pass';
223
-				}
224
-			});
225
-
226
-		$access->expects($this->once())
227
-			->method('countUsers')
228
-			->willReturn(42);
229
-
230
-		$wizard->detectEmailAttribute();
231
-	}
232
-
233
-	public function testDetectEmailAttributeOverrideSet(): void {
234
-		[$wizard, $configuration, $ldap, $access]
235
-			= $this->getWizardAndMocks();
236
-
237
-		$configuration->expects($this->any())
238
-			->method('__get')
239
-			->willReturnCallback(function ($name) {
240
-				if ($name === 'ldapEmailAttribute') {
241
-					return 'myEmailAttribute';
242
-				} else {
243
-					//for requirement checks
244
-					return 'let me pass';
245
-				}
246
-			});
247
-
248
-		$access->expects($this->exactly(3))
249
-			->method('combineFilterWithAnd')
250
-			->willReturnCallback(function ($filterParts) {
251
-				return str_replace('=*', '', array_pop($filterParts));
252
-			});
253
-
254
-		$access->expects($this->exactly(3))
255
-			->method('countUsers')
256
-			->willReturnCallback(function ($filter) {
257
-				if ($filter === 'myEmailAttribute') {
258
-					return 0;
259
-				} elseif ($filter === 'mail') {
260
-					return 3;
261
-				} elseif ($filter === 'mailPrimaryAddress') {
262
-					return 17;
263
-				}
264
-				throw new \Exception('Untested filter: ' . $filter);
265
-			});
266
-
267
-		$result = $wizard->detectEmailAttribute()->getResultArray();
268
-		$this->assertSame('mailPrimaryAddress',
269
-			$result['changes']['ldap_email_attr']);
270
-	}
271
-
272
-	public function testDetectEmailAttributeFind(): void {
273
-		[$wizard, $configuration, $ldap, $access]
274
-			= $this->getWizardAndMocks();
275
-
276
-		$configuration->expects($this->any())
277
-			->method('__get')
278
-			->willReturnCallback(function ($name) {
279
-				if ($name === 'ldapEmailAttribute') {
280
-					return '';
281
-				} else {
282
-					//for requirement checks
283
-					return 'let me pass';
284
-				}
285
-			});
286
-
287
-		$access->expects($this->exactly(2))
288
-			->method('combineFilterWithAnd')
289
-			->willReturnCallback(function ($filterParts) {
290
-				return str_replace('=*', '', array_pop($filterParts));
291
-			});
292
-
293
-		$access->expects($this->exactly(2))
294
-			->method('countUsers')
295
-			->willReturnCallback(function ($filter) {
296
-				if ($filter === 'myEmailAttribute') {
297
-					return 0;
298
-				} elseif ($filter === 'mail') {
299
-					return 3;
300
-				} elseif ($filter === 'mailPrimaryAddress') {
301
-					return 17;
302
-				}
303
-				throw new \Exception('Untested filter: ' . $filter);
304
-			});
305
-
306
-		$result = $wizard->detectEmailAttribute()->getResultArray();
307
-		$this->assertSame('mailPrimaryAddress',
308
-			$result['changes']['ldap_email_attr']);
309
-	}
310
-
311
-	public function testDetectEmailAttributeFindNothing(): void {
312
-		[$wizard, $configuration, $ldap, $access]
313
-			= $this->getWizardAndMocks();
314
-
315
-		$configuration->expects($this->any())
316
-			->method('__get')
317
-			->willReturnCallback(function ($name) {
318
-				if ($name === 'ldapEmailAttribute') {
319
-					return 'myEmailAttribute';
320
-				} else {
321
-					//for requirement checks
322
-					return 'let me pass';
323
-				}
324
-			});
325
-
326
-		$access->expects($this->exactly(3))
327
-			->method('combineFilterWithAnd')
328
-			->willReturnCallback(function ($filterParts) {
329
-				return str_replace('=*', '', array_pop($filterParts));
330
-			});
331
-
332
-		$access->expects($this->exactly(3))
333
-			->method('countUsers')
334
-			->willReturnCallback(function ($filter) {
335
-				if ($filter === 'myEmailAttribute') {
336
-					return 0;
337
-				} elseif ($filter === 'mail') {
338
-					return 0;
339
-				} elseif ($filter === 'mailPrimaryAddress') {
340
-					return 0;
341
-				}
342
-				throw new \Exception('Untested filter: ' . $filter);
343
-			});
344
-
345
-		$result = $wizard->detectEmailAttribute();
346
-		$this->assertFalse($result->hasChanges());
347
-	}
348
-
349
-	public function testCumulativeSearchOnAttributeSkipReadDN(): void {
350
-		// tests that there is no infinite loop, when skipping already processed
351
-		// DNs (they can be returned multiple times for multiple filters )
352
-		[$wizard, $configuration, $ldap] = $this->getWizardAndMocks();
353
-
354
-		$configuration->expects($this->any())
355
-			->method('__get')
356
-			->willReturnCallback(function ($name) {
357
-				if ($name === 'ldapBase') {
358
-					return ['base'];
359
-				}
360
-				return null;
361
-			});
362
-
363
-		$this->prepareLdapWrapperForConnections($ldap);
364
-
365
-		$ldap->expects($this->any())
366
-			->method('isResource')
367
-			->willReturnCallback(function ($res) {
368
-				return (bool)$res;
369
-			});
370
-
371
-		$ldap->expects($this->any())
372
-			->method('search')
373
-			//dummy value, usually invalid
374
-			->willReturn(true);
375
-
376
-		$ldap->expects($this->any())
377
-			->method('countEntries')
378
-			//an is_resource check will follow, so we need to return a dummy resource
379
-			->willReturn(7);
380
-
381
-		//5 DNs per filter means 2x firstEntry and 8x nextEntry
382
-		$ldap->expects($this->any())
383
-			->method('firstEntry')
384
-			//dummy value, usually invalid
385
-			->willReturn(1);
386
-
387
-		global $mark;
388
-		$mark = false;
389
-		// entries return order: 1, 2, 3, 4, 4, 5, 6
390
-		$ldap->expects($this->any())
391
-			->method('nextEntry')
392
-			//dummy value, usually invalid
393
-			->willReturnCallback(function ($a, $prev) {
394
-				$current = $prev + 1;
395
-				if ($current === 7) {
396
-					return false;
397
-				}
398
-				global $mark;
399
-				if ($prev === 4 && !$mark) {
400
-					$mark = true;
401
-					return 4;
402
-				}
403
-				return $current;
404
-			});
405
-
406
-		$ldap->expects($this->any())
407
-			->method('getAttributes')
408
-			//dummy value, usually invalid
409
-			->willReturnCallback(function ($a, $entry) {
410
-				return ['cn' => [$entry], 'count' => 1];
411
-			});
412
-
413
-		$ldap->expects($this->any())
414
-			->method('getDN')
415
-			//dummy value, usually invalid
416
-			->willReturnCallback(function ($a, $b) {
417
-				return $b;
418
-			});
419
-
420
-		// The following expectations are the real test
421
-		$filters = ['f1', 'f2', '*'];
422
-		$resultArray = $wizard->cumulativeSearchOnAttribute($filters, 'cn', 0);
423
-		$this->assertCount(6, $resultArray);
424
-		unset($mark);
425
-	}
26
+    protected function setUp(): void {
27
+        parent::setUp();
28
+        //we need to make sure the consts are defined, otherwise tests will fail
29
+        //on systems without php5_ldap
30
+        $ldapConsts = ['LDAP_OPT_PROTOCOL_VERSION',
31
+            'LDAP_OPT_REFERRALS', 'LDAP_OPT_NETWORK_TIMEOUT'];
32
+        foreach ($ldapConsts as $const) {
33
+            if (!defined($const)) {
34
+                define($const, 42);
35
+            }
36
+        }
37
+    }
38
+
39
+    private function getWizardAndMocks(): array {
40
+        static $confMethods;
41
+
42
+        if (is_null($confMethods)) {
43
+            $confMethods = get_class_methods('\OCA\User_LDAP\Configuration');
44
+        }
45
+        /** @var ILDAPWrapper&MockObject $lw */
46
+        $lw = $this->createMock(ILDAPWrapper::class);
47
+
48
+        /** @var Configuration&MockObject $conf */
49
+        $conf = $this->getMockBuilder(Configuration::class)
50
+            ->onlyMethods($confMethods)
51
+            ->setConstructorArgs(['', true])
52
+            ->getMock();
53
+
54
+        /** @var Access&MockObject $access */
55
+        $access = $this->createMock(Access::class);
56
+
57
+        return [new Wizard($conf, $lw, $access), $conf, $lw, $access];
58
+    }
59
+
60
+    private function prepareLdapWrapperForConnections(MockObject $ldap) {
61
+        $ldap->expects($this->once())
62
+            ->method('connect')
63
+            //dummy value
64
+            ->willReturn(ldap_connect('ldap://example.com'));
65
+
66
+        $ldap->expects($this->exactly(3))
67
+            ->method('setOption')
68
+            ->willReturn(true);
69
+
70
+        $ldap->expects($this->once())
71
+            ->method('bind')
72
+            ->willReturn(true);
73
+    }
74
+
75
+    public function testCumulativeSearchOnAttributeLimited(): void {
76
+        [$wizard, $configuration, $ldap] = $this->getWizardAndMocks();
77
+
78
+        $configuration->expects($this->any())
79
+            ->method('__get')
80
+            ->willReturnCallback(function ($name) {
81
+                if ($name === 'ldapBase') {
82
+                    return ['base'];
83
+                }
84
+                return null;
85
+            });
86
+
87
+        $this->prepareLdapWrapperForConnections($ldap);
88
+
89
+        $ldap->expects($this->any())
90
+            ->method('isResource')
91
+            ->willReturn(true);
92
+
93
+        $ldap->expects($this->exactly(2))
94
+            ->method('search')
95
+            //dummy value, usually invalid
96
+            ->willReturn(true);
97
+
98
+        $ldap->expects($this->exactly(2))
99
+            ->method('countEntries')
100
+            //an is_resource check will follow, so we need to return a dummy resource
101
+            ->willReturn(23);
102
+
103
+        //5 DNs per filter means 2x firstEntry and 8x nextEntry
104
+        $ldap->expects($this->exactly(2))
105
+            ->method('firstEntry')
106
+            //dummy value, usually invalid
107
+            ->willReturn(true);
108
+
109
+        $ldap->expects($this->exactly(8))
110
+            ->method('nextEntry')
111
+            //dummy value, usually invalid
112
+            ->willReturn(true);
113
+
114
+        $ldap->expects($this->exactly(10))
115
+            ->method('getAttributes')
116
+            //dummy value, usually invalid
117
+            ->willReturn(['cn' => ['foo'], 'count' => 1]);
118
+
119
+        global $uidnumber;
120
+        $uidnumber = 1;
121
+        $ldap->expects($this->exactly(10))
122
+            ->method('getDN')
123
+            //dummy value, usually invalid
124
+            ->willReturnCallback(function ($a, $b) {
125
+                global $uidnumber;
126
+                return $uidnumber++;
127
+            });
128
+
129
+        // The following expectations are the real test
130
+        $filters = ['f1', 'f2', '*'];
131
+        $wizard->cumulativeSearchOnAttribute($filters, 'cn', 5);
132
+        unset($uidnumber);
133
+    }
134
+
135
+    public function testCumulativeSearchOnAttributeUnlimited(): void {
136
+        [$wizard, $configuration, $ldap] = $this->getWizardAndMocks();
137
+
138
+        $configuration->expects($this->any())
139
+            ->method('__get')
140
+            ->willReturnCallback(function ($name) {
141
+                if ($name === 'ldapBase') {
142
+                    return ['base'];
143
+                }
144
+                return null;
145
+            });
146
+
147
+        $this->prepareLdapWrapperForConnections($ldap);
148
+
149
+        $ldap->expects($this->any())
150
+            ->method('isResource')
151
+            ->willReturnCallback(function ($r) {
152
+                if ($r instanceof \LDAP\Connection) {
153
+                    return true;
154
+                }
155
+                if ($r % 24 === 0) {
156
+                    global $uidnumber;
157
+                    $uidnumber++;
158
+                    return false;
159
+                }
160
+                return true;
161
+            });
162
+
163
+        $ldap->expects($this->exactly(2))
164
+            ->method('search')
165
+            //dummy value, usually invalid
166
+            ->willReturn(true);
167
+
168
+        $ldap->expects($this->exactly(2))
169
+            ->method('countEntries')
170
+            //an is_resource check will follow, so we need to return a dummy resource
171
+            ->willReturn(23);
172
+
173
+        //5 DNs per filter means 2x firstEntry and 8x nextEntry
174
+        $ldap->expects($this->exactly(2))
175
+            ->method('firstEntry')
176
+            //dummy value, usually invalid
177
+            ->willReturnCallback(function ($r) {
178
+                global $uidnumber;
179
+                return $uidnumber;
180
+            });
181
+
182
+        $ldap->expects($this->exactly(46))
183
+            ->method('nextEntry')
184
+            //dummy value, usually invalid
185
+            ->willReturnCallback(function ($r) {
186
+                global $uidnumber;
187
+                return $uidnumber;
188
+            });
189
+
190
+        $ldap->expects($this->exactly(46))
191
+            ->method('getAttributes')
192
+            //dummy value, usually invalid
193
+            ->willReturn(['cn' => ['foo'], 'count' => 1]);
194
+
195
+        global $uidnumber;
196
+        $uidnumber = 1;
197
+        $ldap->expects($this->exactly(46))
198
+            ->method('getDN')
199
+            //dummy value, usually invalid
200
+            ->willReturnCallback(function ($a, $b) {
201
+                global $uidnumber;
202
+                return $uidnumber++;
203
+            });
204
+
205
+        // The following expectations are the real test
206
+        $filters = ['f1', 'f2', '*'];
207
+        $wizard->cumulativeSearchOnAttribute($filters, 'cn', 0);
208
+        unset($uidnumber);
209
+    }
210
+
211
+    public function testDetectEmailAttributeAlreadySet(): void {
212
+        [$wizard, $configuration, $ldap, $access]
213
+            = $this->getWizardAndMocks();
214
+
215
+        $configuration->expects($this->any())
216
+            ->method('__get')
217
+            ->willReturnCallback(function ($name) {
218
+                if ($name === 'ldapEmailAttribute') {
219
+                    return 'myEmailAttribute';
220
+                } else {
221
+                    //for requirement checks
222
+                    return 'let me pass';
223
+                }
224
+            });
225
+
226
+        $access->expects($this->once())
227
+            ->method('countUsers')
228
+            ->willReturn(42);
229
+
230
+        $wizard->detectEmailAttribute();
231
+    }
232
+
233
+    public function testDetectEmailAttributeOverrideSet(): void {
234
+        [$wizard, $configuration, $ldap, $access]
235
+            = $this->getWizardAndMocks();
236
+
237
+        $configuration->expects($this->any())
238
+            ->method('__get')
239
+            ->willReturnCallback(function ($name) {
240
+                if ($name === 'ldapEmailAttribute') {
241
+                    return 'myEmailAttribute';
242
+                } else {
243
+                    //for requirement checks
244
+                    return 'let me pass';
245
+                }
246
+            });
247
+
248
+        $access->expects($this->exactly(3))
249
+            ->method('combineFilterWithAnd')
250
+            ->willReturnCallback(function ($filterParts) {
251
+                return str_replace('=*', '', array_pop($filterParts));
252
+            });
253
+
254
+        $access->expects($this->exactly(3))
255
+            ->method('countUsers')
256
+            ->willReturnCallback(function ($filter) {
257
+                if ($filter === 'myEmailAttribute') {
258
+                    return 0;
259
+                } elseif ($filter === 'mail') {
260
+                    return 3;
261
+                } elseif ($filter === 'mailPrimaryAddress') {
262
+                    return 17;
263
+                }
264
+                throw new \Exception('Untested filter: ' . $filter);
265
+            });
266
+
267
+        $result = $wizard->detectEmailAttribute()->getResultArray();
268
+        $this->assertSame('mailPrimaryAddress',
269
+            $result['changes']['ldap_email_attr']);
270
+    }
271
+
272
+    public function testDetectEmailAttributeFind(): void {
273
+        [$wizard, $configuration, $ldap, $access]
274
+            = $this->getWizardAndMocks();
275
+
276
+        $configuration->expects($this->any())
277
+            ->method('__get')
278
+            ->willReturnCallback(function ($name) {
279
+                if ($name === 'ldapEmailAttribute') {
280
+                    return '';
281
+                } else {
282
+                    //for requirement checks
283
+                    return 'let me pass';
284
+                }
285
+            });
286
+
287
+        $access->expects($this->exactly(2))
288
+            ->method('combineFilterWithAnd')
289
+            ->willReturnCallback(function ($filterParts) {
290
+                return str_replace('=*', '', array_pop($filterParts));
291
+            });
292
+
293
+        $access->expects($this->exactly(2))
294
+            ->method('countUsers')
295
+            ->willReturnCallback(function ($filter) {
296
+                if ($filter === 'myEmailAttribute') {
297
+                    return 0;
298
+                } elseif ($filter === 'mail') {
299
+                    return 3;
300
+                } elseif ($filter === 'mailPrimaryAddress') {
301
+                    return 17;
302
+                }
303
+                throw new \Exception('Untested filter: ' . $filter);
304
+            });
305
+
306
+        $result = $wizard->detectEmailAttribute()->getResultArray();
307
+        $this->assertSame('mailPrimaryAddress',
308
+            $result['changes']['ldap_email_attr']);
309
+    }
310
+
311
+    public function testDetectEmailAttributeFindNothing(): void {
312
+        [$wizard, $configuration, $ldap, $access]
313
+            = $this->getWizardAndMocks();
314
+
315
+        $configuration->expects($this->any())
316
+            ->method('__get')
317
+            ->willReturnCallback(function ($name) {
318
+                if ($name === 'ldapEmailAttribute') {
319
+                    return 'myEmailAttribute';
320
+                } else {
321
+                    //for requirement checks
322
+                    return 'let me pass';
323
+                }
324
+            });
325
+
326
+        $access->expects($this->exactly(3))
327
+            ->method('combineFilterWithAnd')
328
+            ->willReturnCallback(function ($filterParts) {
329
+                return str_replace('=*', '', array_pop($filterParts));
330
+            });
331
+
332
+        $access->expects($this->exactly(3))
333
+            ->method('countUsers')
334
+            ->willReturnCallback(function ($filter) {
335
+                if ($filter === 'myEmailAttribute') {
336
+                    return 0;
337
+                } elseif ($filter === 'mail') {
338
+                    return 0;
339
+                } elseif ($filter === 'mailPrimaryAddress') {
340
+                    return 0;
341
+                }
342
+                throw new \Exception('Untested filter: ' . $filter);
343
+            });
344
+
345
+        $result = $wizard->detectEmailAttribute();
346
+        $this->assertFalse($result->hasChanges());
347
+    }
348
+
349
+    public function testCumulativeSearchOnAttributeSkipReadDN(): void {
350
+        // tests that there is no infinite loop, when skipping already processed
351
+        // DNs (they can be returned multiple times for multiple filters )
352
+        [$wizard, $configuration, $ldap] = $this->getWizardAndMocks();
353
+
354
+        $configuration->expects($this->any())
355
+            ->method('__get')
356
+            ->willReturnCallback(function ($name) {
357
+                if ($name === 'ldapBase') {
358
+                    return ['base'];
359
+                }
360
+                return null;
361
+            });
362
+
363
+        $this->prepareLdapWrapperForConnections($ldap);
364
+
365
+        $ldap->expects($this->any())
366
+            ->method('isResource')
367
+            ->willReturnCallback(function ($res) {
368
+                return (bool)$res;
369
+            });
370
+
371
+        $ldap->expects($this->any())
372
+            ->method('search')
373
+            //dummy value, usually invalid
374
+            ->willReturn(true);
375
+
376
+        $ldap->expects($this->any())
377
+            ->method('countEntries')
378
+            //an is_resource check will follow, so we need to return a dummy resource
379
+            ->willReturn(7);
380
+
381
+        //5 DNs per filter means 2x firstEntry and 8x nextEntry
382
+        $ldap->expects($this->any())
383
+            ->method('firstEntry')
384
+            //dummy value, usually invalid
385
+            ->willReturn(1);
386
+
387
+        global $mark;
388
+        $mark = false;
389
+        // entries return order: 1, 2, 3, 4, 4, 5, 6
390
+        $ldap->expects($this->any())
391
+            ->method('nextEntry')
392
+            //dummy value, usually invalid
393
+            ->willReturnCallback(function ($a, $prev) {
394
+                $current = $prev + 1;
395
+                if ($current === 7) {
396
+                    return false;
397
+                }
398
+                global $mark;
399
+                if ($prev === 4 && !$mark) {
400
+                    $mark = true;
401
+                    return 4;
402
+                }
403
+                return $current;
404
+            });
405
+
406
+        $ldap->expects($this->any())
407
+            ->method('getAttributes')
408
+            //dummy value, usually invalid
409
+            ->willReturnCallback(function ($a, $entry) {
410
+                return ['cn' => [$entry], 'count' => 1];
411
+            });
412
+
413
+        $ldap->expects($this->any())
414
+            ->method('getDN')
415
+            //dummy value, usually invalid
416
+            ->willReturnCallback(function ($a, $b) {
417
+                return $b;
418
+            });
419
+
420
+        // The following expectations are the real test
421
+        $filters = ['f1', 'f2', '*'];
422
+        $resultArray = $wizard->cumulativeSearchOnAttribute($filters, 'cn', 0);
423
+        $this->assertCount(6, $resultArray);
424
+        unset($mark);
425
+    }
426 426
 }
Please login to merge, or discard this patch.
Spacing   +26 added lines, -26 removed lines patch added patch discarded remove patch
@@ -77,7 +77,7 @@  discard block
 block discarded – undo
77 77
 
78 78
 		$configuration->expects($this->any())
79 79
 			->method('__get')
80
-			->willReturnCallback(function ($name) {
80
+			->willReturnCallback(function($name) {
81 81
 				if ($name === 'ldapBase') {
82 82
 					return ['base'];
83 83
 				}
@@ -121,7 +121,7 @@  discard block
 block discarded – undo
121 121
 		$ldap->expects($this->exactly(10))
122 122
 			->method('getDN')
123 123
 			//dummy value, usually invalid
124
-			->willReturnCallback(function ($a, $b) {
124
+			->willReturnCallback(function($a, $b) {
125 125
 				global $uidnumber;
126 126
 				return $uidnumber++;
127 127
 			});
@@ -137,7 +137,7 @@  discard block
 block discarded – undo
137 137
 
138 138
 		$configuration->expects($this->any())
139 139
 			->method('__get')
140
-			->willReturnCallback(function ($name) {
140
+			->willReturnCallback(function($name) {
141 141
 				if ($name === 'ldapBase') {
142 142
 					return ['base'];
143 143
 				}
@@ -148,7 +148,7 @@  discard block
 block discarded – undo
148 148
 
149 149
 		$ldap->expects($this->any())
150 150
 			->method('isResource')
151
-			->willReturnCallback(function ($r) {
151
+			->willReturnCallback(function($r) {
152 152
 				if ($r instanceof \LDAP\Connection) {
153 153
 					return true;
154 154
 				}
@@ -174,7 +174,7 @@  discard block
 block discarded – undo
174 174
 		$ldap->expects($this->exactly(2))
175 175
 			->method('firstEntry')
176 176
 			//dummy value, usually invalid
177
-			->willReturnCallback(function ($r) {
177
+			->willReturnCallback(function($r) {
178 178
 				global $uidnumber;
179 179
 				return $uidnumber;
180 180
 			});
@@ -182,7 +182,7 @@  discard block
 block discarded – undo
182 182
 		$ldap->expects($this->exactly(46))
183 183
 			->method('nextEntry')
184 184
 			//dummy value, usually invalid
185
-			->willReturnCallback(function ($r) {
185
+			->willReturnCallback(function($r) {
186 186
 				global $uidnumber;
187 187
 				return $uidnumber;
188 188
 			});
@@ -197,7 +197,7 @@  discard block
 block discarded – undo
197 197
 		$ldap->expects($this->exactly(46))
198 198
 			->method('getDN')
199 199
 			//dummy value, usually invalid
200
-			->willReturnCallback(function ($a, $b) {
200
+			->willReturnCallback(function($a, $b) {
201 201
 				global $uidnumber;
202 202
 				return $uidnumber++;
203 203
 			});
@@ -214,7 +214,7 @@  discard block
 block discarded – undo
214 214
 
215 215
 		$configuration->expects($this->any())
216 216
 			->method('__get')
217
-			->willReturnCallback(function ($name) {
217
+			->willReturnCallback(function($name) {
218 218
 				if ($name === 'ldapEmailAttribute') {
219 219
 					return 'myEmailAttribute';
220 220
 				} else {
@@ -236,7 +236,7 @@  discard block
 block discarded – undo
236 236
 
237 237
 		$configuration->expects($this->any())
238 238
 			->method('__get')
239
-			->willReturnCallback(function ($name) {
239
+			->willReturnCallback(function($name) {
240 240
 				if ($name === 'ldapEmailAttribute') {
241 241
 					return 'myEmailAttribute';
242 242
 				} else {
@@ -247,13 +247,13 @@  discard block
 block discarded – undo
247 247
 
248 248
 		$access->expects($this->exactly(3))
249 249
 			->method('combineFilterWithAnd')
250
-			->willReturnCallback(function ($filterParts) {
250
+			->willReturnCallback(function($filterParts) {
251 251
 				return str_replace('=*', '', array_pop($filterParts));
252 252
 			});
253 253
 
254 254
 		$access->expects($this->exactly(3))
255 255
 			->method('countUsers')
256
-			->willReturnCallback(function ($filter) {
256
+			->willReturnCallback(function($filter) {
257 257
 				if ($filter === 'myEmailAttribute') {
258 258
 					return 0;
259 259
 				} elseif ($filter === 'mail') {
@@ -261,7 +261,7 @@  discard block
 block discarded – undo
261 261
 				} elseif ($filter === 'mailPrimaryAddress') {
262 262
 					return 17;
263 263
 				}
264
-				throw new \Exception('Untested filter: ' . $filter);
264
+				throw new \Exception('Untested filter: '.$filter);
265 265
 			});
266 266
 
267 267
 		$result = $wizard->detectEmailAttribute()->getResultArray();
@@ -275,7 +275,7 @@  discard block
 block discarded – undo
275 275
 
276 276
 		$configuration->expects($this->any())
277 277
 			->method('__get')
278
-			->willReturnCallback(function ($name) {
278
+			->willReturnCallback(function($name) {
279 279
 				if ($name === 'ldapEmailAttribute') {
280 280
 					return '';
281 281
 				} else {
@@ -286,13 +286,13 @@  discard block
 block discarded – undo
286 286
 
287 287
 		$access->expects($this->exactly(2))
288 288
 			->method('combineFilterWithAnd')
289
-			->willReturnCallback(function ($filterParts) {
289
+			->willReturnCallback(function($filterParts) {
290 290
 				return str_replace('=*', '', array_pop($filterParts));
291 291
 			});
292 292
 
293 293
 		$access->expects($this->exactly(2))
294 294
 			->method('countUsers')
295
-			->willReturnCallback(function ($filter) {
295
+			->willReturnCallback(function($filter) {
296 296
 				if ($filter === 'myEmailAttribute') {
297 297
 					return 0;
298 298
 				} elseif ($filter === 'mail') {
@@ -300,7 +300,7 @@  discard block
 block discarded – undo
300 300
 				} elseif ($filter === 'mailPrimaryAddress') {
301 301
 					return 17;
302 302
 				}
303
-				throw new \Exception('Untested filter: ' . $filter);
303
+				throw new \Exception('Untested filter: '.$filter);
304 304
 			});
305 305
 
306 306
 		$result = $wizard->detectEmailAttribute()->getResultArray();
@@ -314,7 +314,7 @@  discard block
 block discarded – undo
314 314
 
315 315
 		$configuration->expects($this->any())
316 316
 			->method('__get')
317
-			->willReturnCallback(function ($name) {
317
+			->willReturnCallback(function($name) {
318 318
 				if ($name === 'ldapEmailAttribute') {
319 319
 					return 'myEmailAttribute';
320 320
 				} else {
@@ -325,13 +325,13 @@  discard block
 block discarded – undo
325 325
 
326 326
 		$access->expects($this->exactly(3))
327 327
 			->method('combineFilterWithAnd')
328
-			->willReturnCallback(function ($filterParts) {
328
+			->willReturnCallback(function($filterParts) {
329 329
 				return str_replace('=*', '', array_pop($filterParts));
330 330
 			});
331 331
 
332 332
 		$access->expects($this->exactly(3))
333 333
 			->method('countUsers')
334
-			->willReturnCallback(function ($filter) {
334
+			->willReturnCallback(function($filter) {
335 335
 				if ($filter === 'myEmailAttribute') {
336 336
 					return 0;
337 337
 				} elseif ($filter === 'mail') {
@@ -339,7 +339,7 @@  discard block
 block discarded – undo
339 339
 				} elseif ($filter === 'mailPrimaryAddress') {
340 340
 					return 0;
341 341
 				}
342
-				throw new \Exception('Untested filter: ' . $filter);
342
+				throw new \Exception('Untested filter: '.$filter);
343 343
 			});
344 344
 
345 345
 		$result = $wizard->detectEmailAttribute();
@@ -353,7 +353,7 @@  discard block
 block discarded – undo
353 353
 
354 354
 		$configuration->expects($this->any())
355 355
 			->method('__get')
356
-			->willReturnCallback(function ($name) {
356
+			->willReturnCallback(function($name) {
357 357
 				if ($name === 'ldapBase') {
358 358
 					return ['base'];
359 359
 				}
@@ -364,8 +364,8 @@  discard block
 block discarded – undo
364 364
 
365 365
 		$ldap->expects($this->any())
366 366
 			->method('isResource')
367
-			->willReturnCallback(function ($res) {
368
-				return (bool)$res;
367
+			->willReturnCallback(function($res) {
368
+				return (bool) $res;
369 369
 			});
370 370
 
371 371
 		$ldap->expects($this->any())
@@ -390,7 +390,7 @@  discard block
 block discarded – undo
390 390
 		$ldap->expects($this->any())
391 391
 			->method('nextEntry')
392 392
 			//dummy value, usually invalid
393
-			->willReturnCallback(function ($a, $prev) {
393
+			->willReturnCallback(function($a, $prev) {
394 394
 				$current = $prev + 1;
395 395
 				if ($current === 7) {
396 396
 					return false;
@@ -406,14 +406,14 @@  discard block
 block discarded – undo
406 406
 		$ldap->expects($this->any())
407 407
 			->method('getAttributes')
408 408
 			//dummy value, usually invalid
409
-			->willReturnCallback(function ($a, $entry) {
409
+			->willReturnCallback(function($a, $entry) {
410 410
 				return ['cn' => [$entry], 'count' => 1];
411 411
 			});
412 412
 
413 413
 		$ldap->expects($this->any())
414 414
 			->method('getDN')
415 415
 			//dummy value, usually invalid
416
-			->willReturnCallback(function ($a, $b) {
416
+			->willReturnCallback(function($a, $b) {
417 417
 				return $b;
418 418
 			});
419 419
 
Please login to merge, or discard this patch.
apps/user_ldap/tests/LDAPTest.php 1 patch
Indentation   +50 added lines, -50 removed lines patch added patch discarded remove patch
@@ -12,63 +12,63 @@
 block discarded – undo
12 12
 use Test\TestCase;
13 13
 
14 14
 class LDAPTest extends TestCase {
15
-	private LDAP&MockObject $ldap;
15
+    private LDAP&MockObject $ldap;
16 16
 
17
-	protected function setUp(): void {
18
-		parent::setUp();
19
-		$this->ldap = $this->getMockBuilder(LDAP::class)
20
-			->onlyMethods(['invokeLDAPMethod'])
21
-			->getMock();
22
-	}
17
+    protected function setUp(): void {
18
+        parent::setUp();
19
+        $this->ldap = $this->getMockBuilder(LDAP::class)
20
+            ->onlyMethods(['invokeLDAPMethod'])
21
+            ->getMock();
22
+    }
23 23
 
24
-	public static function errorProvider(): array {
25
-		return [
26
-			[
27
-				'ldap_search(): Partial search results returned: Sizelimit exceeded at /srv/http/nextcloud/master/apps/user_ldap/lib/LDAP.php#292',
28
-				false
29
-			],
30
-			[
31
-				'Some other error', true
32
-			]
33
-		];
34
-	}
24
+    public static function errorProvider(): array {
25
+        return [
26
+            [
27
+                'ldap_search(): Partial search results returned: Sizelimit exceeded at /srv/http/nextcloud/master/apps/user_ldap/lib/LDAP.php#292',
28
+                false
29
+            ],
30
+            [
31
+                'Some other error', true
32
+            ]
33
+        ];
34
+    }
35 35
 
36
-	/**
37
-	 * @dataProvider errorProvider
38
-	 */
39
-	public function testSearchWithErrorHandler(string $errorMessage, bool $passThrough): void {
40
-		$wasErrorHandlerCalled = false;
41
-		$errorHandler = function ($number, $message, $file, $line) use (&$wasErrorHandlerCalled): void {
42
-			$wasErrorHandlerCalled = true;
43
-		};
36
+    /**
37
+     * @dataProvider errorProvider
38
+     */
39
+    public function testSearchWithErrorHandler(string $errorMessage, bool $passThrough): void {
40
+        $wasErrorHandlerCalled = false;
41
+        $errorHandler = function ($number, $message, $file, $line) use (&$wasErrorHandlerCalled): void {
42
+            $wasErrorHandlerCalled = true;
43
+        };
44 44
 
45
-		set_error_handler($errorHandler);
45
+        set_error_handler($errorHandler);
46 46
 
47
-		$this->ldap
48
-			->expects($this->once())
49
-			->method('invokeLDAPMethod')
50
-			->with('search', $this->anything(), $this->anything(), $this->anything(), $this->anything(), $this->anything())
51
-			->willReturnCallback(function () use ($errorMessage): void {
52
-				trigger_error($errorMessage);
53
-			});
47
+        $this->ldap
48
+            ->expects($this->once())
49
+            ->method('invokeLDAPMethod')
50
+            ->with('search', $this->anything(), $this->anything(), $this->anything(), $this->anything(), $this->anything())
51
+            ->willReturnCallback(function () use ($errorMessage): void {
52
+                trigger_error($errorMessage);
53
+            });
54 54
 
55
-		$fakeResource = ldap_connect();
56
-		$this->ldap->search($fakeResource, 'base', 'filter', []);
57
-		$this->assertSame($wasErrorHandlerCalled, $passThrough);
55
+        $fakeResource = ldap_connect();
56
+        $this->ldap->search($fakeResource, 'base', 'filter', []);
57
+        $this->assertSame($wasErrorHandlerCalled, $passThrough);
58 58
 
59
-		restore_error_handler();
60
-	}
59
+        restore_error_handler();
60
+    }
61 61
 
62
-	public function testModReplace(): void {
63
-		$link = $this->createMock(LDAP::class);
64
-		$userDN = 'CN=user';
65
-		$password = 'MyPassword';
66
-		$this->ldap
67
-			->expects($this->once())
68
-			->method('invokeLDAPMethod')
69
-			->with('mod_replace', $link, $userDN, ['userPassword' => $password])
70
-			->willReturn(true);
62
+    public function testModReplace(): void {
63
+        $link = $this->createMock(LDAP::class);
64
+        $userDN = 'CN=user';
65
+        $password = 'MyPassword';
66
+        $this->ldap
67
+            ->expects($this->once())
68
+            ->method('invokeLDAPMethod')
69
+            ->with('mod_replace', $link, $userDN, ['userPassword' => $password])
70
+            ->willReturn(true);
71 71
 
72
-		$this->assertTrue($this->ldap->modReplace($link, $userDN, $password));
73
-	}
72
+        $this->assertTrue($this->ldap->modReplace($link, $userDN, $password));
73
+    }
74 74
 }
Please login to merge, or discard this patch.
apps/user_ldap/tests/HelperTest.php 1 patch
Indentation   +82 added lines, -82 removed lines patch added patch discarded remove patch
@@ -17,86 +17,86 @@
 block discarded – undo
17 17
  * @group DB
18 18
  */
19 19
 class HelperTest extends \Test\TestCase {
20
-	private IConfig&MockObject $config;
21
-
22
-	private Helper $helper;
23
-
24
-	protected function setUp(): void {
25
-		parent::setUp();
26
-
27
-		$this->config = $this->createMock(IConfig::class);
28
-		$this->helper = new Helper($this->config, Server::get(IDBConnection::class));
29
-	}
30
-
31
-	public function testGetServerConfigurationPrefixes(): void {
32
-		$this->config->method('getAppKeys')
33
-			->with($this->equalTo('user_ldap'))
34
-			->willReturn([
35
-				'foo',
36
-				'ldap_configuration_active',
37
-				's1ldap_configuration_active',
38
-			]);
39
-
40
-		$result = $this->helper->getServerConfigurationPrefixes(false);
41
-
42
-		$this->assertEquals(['', 's1'], $result);
43
-	}
44
-
45
-	public function testGetServerConfigurationPrefixesActive(): void {
46
-		$this->config->method('getAppKeys')
47
-			->with($this->equalTo('user_ldap'))
48
-			->willReturn([
49
-				'foo',
50
-				'ldap_configuration_active',
51
-				's1ldap_configuration_active',
52
-			]);
53
-
54
-		$this->config->method('getAppValue')
55
-			->willReturnCallback(function ($app, $key, $default) {
56
-				if ($app !== 'user_ldap') {
57
-					$this->fail('wrong app');
58
-				}
59
-				if ($key === 's1ldap_configuration_active') {
60
-					return '1';
61
-				}
62
-				return $default;
63
-			});
64
-
65
-		$result = $this->helper->getServerConfigurationPrefixes(true);
66
-
67
-		$this->assertEquals(['s1'], $result);
68
-	}
69
-
70
-	public function testGetServerConfigurationHost(): void {
71
-		$this->config->method('getAppKeys')
72
-			->with($this->equalTo('user_ldap'))
73
-			->willReturn([
74
-				'foo',
75
-				'ldap_host',
76
-				's1ldap_host',
77
-				's02ldap_host',
78
-			]);
79
-
80
-		$this->config->method('getAppValue')
81
-			->willReturnCallback(function ($app, $key, $default) {
82
-				if ($app !== 'user_ldap') {
83
-					$this->fail('wrong app');
84
-				}
85
-				if ($key === 'ldap_host') {
86
-					return 'example.com';
87
-				}
88
-				if ($key === 's1ldap_host') {
89
-					return 'foo.bar.com';
90
-				}
91
-				return $default;
92
-			});
93
-
94
-		$result = $this->helper->getServerConfigurationHosts();
95
-
96
-		$this->assertEquals([
97
-			'' => 'example.com',
98
-			's1' => 'foo.bar.com',
99
-			's02' => '',
100
-		], $result);
101
-	}
20
+    private IConfig&MockObject $config;
21
+
22
+    private Helper $helper;
23
+
24
+    protected function setUp(): void {
25
+        parent::setUp();
26
+
27
+        $this->config = $this->createMock(IConfig::class);
28
+        $this->helper = new Helper($this->config, Server::get(IDBConnection::class));
29
+    }
30
+
31
+    public function testGetServerConfigurationPrefixes(): void {
32
+        $this->config->method('getAppKeys')
33
+            ->with($this->equalTo('user_ldap'))
34
+            ->willReturn([
35
+                'foo',
36
+                'ldap_configuration_active',
37
+                's1ldap_configuration_active',
38
+            ]);
39
+
40
+        $result = $this->helper->getServerConfigurationPrefixes(false);
41
+
42
+        $this->assertEquals(['', 's1'], $result);
43
+    }
44
+
45
+    public function testGetServerConfigurationPrefixesActive(): void {
46
+        $this->config->method('getAppKeys')
47
+            ->with($this->equalTo('user_ldap'))
48
+            ->willReturn([
49
+                'foo',
50
+                'ldap_configuration_active',
51
+                's1ldap_configuration_active',
52
+            ]);
53
+
54
+        $this->config->method('getAppValue')
55
+            ->willReturnCallback(function ($app, $key, $default) {
56
+                if ($app !== 'user_ldap') {
57
+                    $this->fail('wrong app');
58
+                }
59
+                if ($key === 's1ldap_configuration_active') {
60
+                    return '1';
61
+                }
62
+                return $default;
63
+            });
64
+
65
+        $result = $this->helper->getServerConfigurationPrefixes(true);
66
+
67
+        $this->assertEquals(['s1'], $result);
68
+    }
69
+
70
+    public function testGetServerConfigurationHost(): void {
71
+        $this->config->method('getAppKeys')
72
+            ->with($this->equalTo('user_ldap'))
73
+            ->willReturn([
74
+                'foo',
75
+                'ldap_host',
76
+                's1ldap_host',
77
+                's02ldap_host',
78
+            ]);
79
+
80
+        $this->config->method('getAppValue')
81
+            ->willReturnCallback(function ($app, $key, $default) {
82
+                if ($app !== 'user_ldap') {
83
+                    $this->fail('wrong app');
84
+                }
85
+                if ($key === 'ldap_host') {
86
+                    return 'example.com';
87
+                }
88
+                if ($key === 's1ldap_host') {
89
+                    return 'foo.bar.com';
90
+                }
91
+                return $default;
92
+            });
93
+
94
+        $result = $this->helper->getServerConfigurationHosts();
95
+
96
+        $this->assertEquals([
97
+            '' => 'example.com',
98
+            's1' => 'foo.bar.com',
99
+            's02' => '',
100
+        ], $result);
101
+    }
102 102
 }
Please login to merge, or discard this patch.
apps/user_ldap/tests/User/DeletedUsersIndexTest.php 1 patch
Indentation   +75 added lines, -75 removed lines patch added patch discarded remove patch
@@ -23,79 +23,79 @@
 block discarded – undo
23 23
  * @package OCA\User_LDAP\Tests\User
24 24
  */
25 25
 class DeletedUsersIndexTest extends \Test\TestCase {
26
-	protected DeletedUsersIndex $dui;
27
-	protected IConfig $config;
28
-	protected IDBConnection $db;
29
-	protected UserMapping&MockObject $mapping;
30
-	protected IManager&MockObject $shareManager;
31
-
32
-	protected function setUp(): void {
33
-		parent::setUp();
34
-
35
-		// no mocks for those as tests go against DB
36
-		$this->config = Server::get(IConfig::class);
37
-		$this->db = Server::get(IDBConnection::class);
38
-
39
-		// ensure a clean database
40
-		$this->config->deleteAppFromAllUsers('user_ldap');
41
-
42
-		$this->mapping = $this->createMock(UserMapping::class);
43
-		$this->shareManager = $this->createMock(IManager::class);
44
-
45
-		$this->dui = new DeletedUsersIndex($this->config, $this->mapping, $this->shareManager);
46
-	}
47
-
48
-	protected function tearDown(): void {
49
-		$this->config->deleteAppFromAllUsers('user_ldap');
50
-		parent::tearDown();
51
-	}
52
-
53
-	public function testMarkAndFetchUser(): void {
54
-		$uids = [
55
-			'cef3775c-71d2-48eb-8984-39a4051b0b95',
56
-			'8c4bbb40-33ed-42d0-9b14-85b0ab76c1cc',
57
-		];
58
-
59
-		// ensure test works on a pristine state
60
-		$this->assertFalse($this->dui->hasUsers());
61
-
62
-		$this->dui->markUser($uids[0]);
63
-
64
-		$this->assertTrue($this->dui->hasUsers());
65
-
66
-		$this->dui->markUser($uids[1]);
67
-
68
-		$deletedUsers = $this->dui->getUsers();
69
-		$this->assertSame(2, count($deletedUsers));
70
-
71
-		// ensure the different uids were used
72
-		foreach ($deletedUsers as $deletedUser) {
73
-			$this->assertTrue(in_array($deletedUser->getOCName(), $uids));
74
-			$i = array_search($deletedUser->getOCName(), $uids);
75
-			$this->assertNotFalse($i);
76
-			unset($uids[$i]);
77
-		}
78
-		$this->assertEmpty($uids);
79
-	}
80
-
81
-	public function testUnmarkUser(): void {
82
-		$uids = [
83
-			'22a162c7-a9ee-487c-9f33-0563795583fb',
84
-			'1fb4e0da-4a75-47f3-8fa7-becc7e35c9c5',
85
-		];
86
-
87
-		// we know this works, because of "testMarkAndFetchUser"
88
-		$this->dui->markUser($uids[0]);
89
-		// this returns a working instance of OfflineUser
90
-		$testUser = $this->dui->getUsers()[0];
91
-		$testUser->unmark();
92
-
93
-		// the DUI caches the users, to clear mark someone else
94
-		$this->dui->markUser($uids[1]);
95
-
96
-		$deletedUsers = $this->dui->getUsers();
97
-		foreach ($deletedUsers as $deletedUser) {
98
-			$this->assertNotSame($testUser->getOCName(), $deletedUser->getOCName());
99
-		}
100
-	}
26
+    protected DeletedUsersIndex $dui;
27
+    protected IConfig $config;
28
+    protected IDBConnection $db;
29
+    protected UserMapping&MockObject $mapping;
30
+    protected IManager&MockObject $shareManager;
31
+
32
+    protected function setUp(): void {
33
+        parent::setUp();
34
+
35
+        // no mocks for those as tests go against DB
36
+        $this->config = Server::get(IConfig::class);
37
+        $this->db = Server::get(IDBConnection::class);
38
+
39
+        // ensure a clean database
40
+        $this->config->deleteAppFromAllUsers('user_ldap');
41
+
42
+        $this->mapping = $this->createMock(UserMapping::class);
43
+        $this->shareManager = $this->createMock(IManager::class);
44
+
45
+        $this->dui = new DeletedUsersIndex($this->config, $this->mapping, $this->shareManager);
46
+    }
47
+
48
+    protected function tearDown(): void {
49
+        $this->config->deleteAppFromAllUsers('user_ldap');
50
+        parent::tearDown();
51
+    }
52
+
53
+    public function testMarkAndFetchUser(): void {
54
+        $uids = [
55
+            'cef3775c-71d2-48eb-8984-39a4051b0b95',
56
+            '8c4bbb40-33ed-42d0-9b14-85b0ab76c1cc',
57
+        ];
58
+
59
+        // ensure test works on a pristine state
60
+        $this->assertFalse($this->dui->hasUsers());
61
+
62
+        $this->dui->markUser($uids[0]);
63
+
64
+        $this->assertTrue($this->dui->hasUsers());
65
+
66
+        $this->dui->markUser($uids[1]);
67
+
68
+        $deletedUsers = $this->dui->getUsers();
69
+        $this->assertSame(2, count($deletedUsers));
70
+
71
+        // ensure the different uids were used
72
+        foreach ($deletedUsers as $deletedUser) {
73
+            $this->assertTrue(in_array($deletedUser->getOCName(), $uids));
74
+            $i = array_search($deletedUser->getOCName(), $uids);
75
+            $this->assertNotFalse($i);
76
+            unset($uids[$i]);
77
+        }
78
+        $this->assertEmpty($uids);
79
+    }
80
+
81
+    public function testUnmarkUser(): void {
82
+        $uids = [
83
+            '22a162c7-a9ee-487c-9f33-0563795583fb',
84
+            '1fb4e0da-4a75-47f3-8fa7-becc7e35c9c5',
85
+        ];
86
+
87
+        // we know this works, because of "testMarkAndFetchUser"
88
+        $this->dui->markUser($uids[0]);
89
+        // this returns a working instance of OfflineUser
90
+        $testUser = $this->dui->getUsers()[0];
91
+        $testUser->unmark();
92
+
93
+        // the DUI caches the users, to clear mark someone else
94
+        $this->dui->markUser($uids[1]);
95
+
96
+        $deletedUsers = $this->dui->getUsers();
97
+        foreach ($deletedUsers as $deletedUser) {
98
+            $this->assertNotSame($testUser->getOCName(), $deletedUser->getOCName());
99
+        }
100
+    }
101 101
 }
Please login to merge, or discard this patch.
apps/user_ldap/tests/User/UserTest.php 2 patches
Indentation   +1150 added lines, -1150 removed lines patch added patch discarded remove patch
@@ -32,1154 +32,1154 @@
 block discarded – undo
32 32
  * @package OCA\User_LDAP\Tests\User
33 33
  */
34 34
 class UserTest extends \Test\TestCase {
35
-	protected Access&MockObject $access;
36
-	protected Connection&MockObject $connection;
37
-	protected IConfig&MockObject $config;
38
-	protected INotificationManager&MockObject $notificationManager;
39
-	protected IUserManager&MockObject $userManager;
40
-	protected Image&MockObject $image;
41
-	protected IAvatarManager&MockObject $avatarManager;
42
-	protected LoggerInterface&MockObject $logger;
43
-	protected string $uid = 'alice';
44
-	protected string $dn = 'uid=alice,dc=foo,dc=bar';
45
-	protected User $user;
46
-
47
-	protected function setUp(): void {
48
-		parent::setUp();
49
-
50
-		$this->connection = $this->getMockBuilder(Connection::class)
51
-			->setConstructorArgs([$this->createMock(ILDAPWrapper::class)])
52
-			->getMock();
53
-
54
-		$this->access = $this->createMock(Access::class);
55
-		$this->access->connection = $this->connection;
56
-		$this->access->expects($this->any())
57
-			->method('getConnection')
58
-			->willReturn($this->connection);
59
-
60
-		$this->config = $this->createMock(IConfig::class);
61
-		$this->logger = $this->createMock(LoggerInterface::class);
62
-		$this->avatarManager = $this->createMock(IAvatarManager::class);
63
-		$this->image = $this->createMock(Image::class);
64
-		$this->userManager = $this->createMock(IUserManager::class);
65
-		$this->notificationManager = $this->createMock(INotificationManager::class);
66
-
67
-		$this->user = new User(
68
-			$this->uid,
69
-			$this->dn,
70
-			$this->access,
71
-			$this->config,
72
-			$this->image,
73
-			$this->logger,
74
-			$this->avatarManager,
75
-			$this->userManager,
76
-			$this->notificationManager
77
-		);
78
-	}
79
-
80
-	public function testGetDNandUsername(): void {
81
-		$this->assertSame($this->dn, $this->user->getDN());
82
-		$this->assertSame($this->uid, $this->user->getUsername());
83
-	}
84
-
85
-	public function testUpdateEmailProvided(): void {
86
-		$this->connection->expects($this->once())
87
-			->method('__get')
88
-			->with($this->equalTo('ldapEmailAttribute'))
89
-			->willReturn('email');
90
-
91
-		$this->access->expects($this->once())
92
-			->method('readAttribute')
93
-			->with($this->equalTo($this->dn),
94
-				$this->equalTo('email'))
95
-			->willReturn(['[email protected]']);
96
-
97
-		$coreUser = $this->createMock(IUser::class);
98
-		$coreUser->expects($this->once())
99
-			->method('setSystemEMailAddress')
100
-			->with('[email protected]');
101
-
102
-		$this->userManager->expects($this->any())
103
-			->method('get')
104
-			->willReturn($coreUser);
105
-
106
-		$this->user->updateEmail();
107
-	}
108
-
109
-	public function testUpdateEmailNotProvided(): void {
110
-		$this->connection->expects($this->once())
111
-			->method('__get')
112
-			->with($this->equalTo('ldapEmailAttribute'))
113
-			->willReturn('email');
114
-
115
-		$this->access->expects($this->once())
116
-			->method('readAttribute')
117
-			->with($this->equalTo($this->dn),
118
-				$this->equalTo('email'))
119
-			->willReturn(false);
120
-
121
-		$this->config->expects($this->never())
122
-			->method('setUserValue');
123
-
124
-		$this->user->updateEmail();
125
-	}
126
-
127
-	public function testUpdateEmailNotConfigured(): void {
128
-		$this->connection->expects($this->once())
129
-			->method('__get')
130
-			->with($this->equalTo('ldapEmailAttribute'))
131
-			->willReturn('');
132
-
133
-		$this->access->expects($this->never())
134
-			->method('readAttribute');
135
-
136
-		$this->config->expects($this->never())
137
-			->method('setUserValue');
138
-
139
-		$this->user->updateEmail();
140
-	}
141
-
142
-	public function testUpdateQuotaAllProvided(): void {
143
-		$this->connection->expects($this->exactly(2))
144
-			->method('__get')
145
-			->willReturnMap([
146
-				['ldapQuotaAttribute', 'myquota'],
147
-				['ldapQuotaDefault', '']
148
-			]);
149
-
150
-		$this->access->expects($this->once())
151
-			->method('readAttribute')
152
-			->with($this->equalTo($this->dn),
153
-				$this->equalTo('myquota'))
154
-			->willReturn(['42 GB']);
155
-
156
-		$coreUser = $this->createMock(IUser::class);
157
-		$coreUser->expects($this->once())
158
-			->method('setQuota')
159
-			->with('42 GB');
160
-
161
-		$this->userManager->expects($this->atLeastOnce())
162
-			->method('get')
163
-			->with($this->uid)
164
-			->willReturn($coreUser);
165
-
166
-		$this->user->updateQuota();
167
-	}
168
-
169
-	public function testUpdateQuotaToDefaultAllProvided(): void {
170
-		$this->connection->expects($this->exactly(2))
171
-			->method('__get')
172
-			->willReturnMap([
173
-				['ldapQuotaAttribute', 'myquota'],
174
-				['ldapQuotaDefault', '']
175
-			]);
176
-
177
-		$this->access->expects($this->once())
178
-			->method('readAttribute')
179
-			->with($this->equalTo($this->dn),
180
-				$this->equalTo('myquota'))
181
-			->willReturn(['default']);
182
-
183
-		$coreUser = $this->createMock(IUser::class);
184
-		$coreUser->expects($this->once())
185
-			->method('setQuota')
186
-			->with('default');
187
-
188
-		$this->userManager->expects($this->once())
189
-			->method('get')
190
-			->with($this->uid)
191
-			->willReturn($coreUser);
192
-
193
-		$this->user->updateQuota();
194
-	}
195
-
196
-	public function testUpdateQuotaToNoneAllProvided(): void {
197
-		$this->connection->expects($this->exactly(2))
198
-			->method('__get')
199
-			->willReturnMap([
200
-				['ldapQuotaAttribute', 'myquota'],
201
-				['ldapQuotaDefault', '']
202
-			]);
203
-
204
-		$this->access->expects($this->once())
205
-			->method('readAttribute')
206
-			->with($this->equalTo($this->dn),
207
-				$this->equalTo('myquota'))
208
-			->willReturn(['none']);
209
-
210
-		$coreUser = $this->createMock(IUser::class);
211
-		$coreUser->expects($this->once())
212
-			->method('setQuota')
213
-			->with('none');
214
-
215
-		$this->userManager->expects($this->once())
216
-			->method('get')
217
-			->with($this->uid)
218
-			->willReturn($coreUser);
219
-
220
-		$this->user->updateQuota();
221
-	}
222
-
223
-	public function testUpdateQuotaDefaultProvided(): void {
224
-		$this->connection->expects($this->exactly(2))
225
-			->method('__get')
226
-			->willReturnMap([
227
-				['ldapQuotaAttribute', 'myquota'],
228
-				['ldapQuotaDefault', '25 GB'],
229
-			]);
230
-
231
-		$this->access->expects($this->once())
232
-			->method('readAttribute')
233
-			->with($this->equalTo($this->dn),
234
-				$this->equalTo('myquota'))
235
-			->willReturn(false);
236
-
237
-		$coreUser = $this->createMock(IUser::class);
238
-		$coreUser->expects($this->once())
239
-			->method('setQuota')
240
-			->with('25 GB');
241
-
242
-		$this->userManager->expects($this->once())
243
-			->method('get')
244
-			->with($this->uid)
245
-			->willReturn($coreUser);
246
-
247
-		$this->user->updateQuota();
248
-	}
249
-
250
-	public function testUpdateQuotaIndividualProvided(): void {
251
-		$this->connection->expects($this->exactly(2))
252
-			->method('__get')
253
-			->willReturnMap([
254
-				['ldapQuotaAttribute', 'myquota'],
255
-				['ldapQuotaDefault', '']
256
-			]);
257
-
258
-		$this->access->expects($this->once())
259
-			->method('readAttribute')
260
-			->with($this->equalTo($this->dn),
261
-				$this->equalTo('myquota'))
262
-			->willReturn(['27 GB']);
263
-
264
-		$coreUser = $this->createMock(IUser::class);
265
-		$coreUser->expects($this->once())
266
-			->method('setQuota')
267
-			->with('27 GB');
268
-
269
-		$this->userManager->expects($this->once())
270
-			->method('get')
271
-			->with($this->uid)
272
-			->willReturn($coreUser);
273
-
274
-		$this->user->updateQuota();
275
-	}
276
-
277
-	public function testUpdateQuotaNoneProvided(): void {
278
-		$this->connection->expects($this->exactly(2))
279
-			->method('__get')
280
-			->willReturnMap([
281
-				['ldapQuotaAttribute', 'myquota'],
282
-				['ldapQuotaDefault', '']
283
-			]);
284
-
285
-		$this->access->expects($this->once())
286
-			->method('readAttribute')
287
-			->with($this->equalTo($this->dn),
288
-				$this->equalTo('myquota'))
289
-			->willReturn(false);
290
-
291
-		$coreUser = $this->createMock(IUser::class);
292
-		$coreUser->expects($this->never())
293
-			->method('setQuota');
294
-
295
-		$this->userManager->expects($this->never())
296
-			->method('get')
297
-			->with($this->uid);
298
-
299
-		$this->config->expects($this->never())
300
-			->method('setUserValue');
301
-
302
-		$this->user->updateQuota();
303
-	}
304
-
305
-	public function testUpdateQuotaNoneConfigured(): void {
306
-		$this->connection->expects($this->exactly(2))
307
-			->method('__get')
308
-			->willReturnMap([
309
-				['ldapQuotaAttribute', ''],
310
-				['ldapQuotaDefault', '']
311
-			]);
312
-
313
-		$coreUser = $this->createMock(IUser::class);
314
-		$coreUser->expects($this->never())
315
-			->method('setQuota');
316
-
317
-		$this->userManager->expects($this->never())
318
-			->method('get');
319
-
320
-		$this->access->expects($this->never())
321
-			->method('readAttribute');
322
-
323
-		$this->config->expects($this->never())
324
-			->method('setUserValue');
325
-
326
-		$this->user->updateQuota();
327
-	}
328
-
329
-	public function testUpdateQuotaFromValue(): void {
330
-		$readQuota = '19 GB';
331
-
332
-		$this->connection->expects($this->exactly(2))
333
-			->method('__get')
334
-			->willReturnMap([
335
-				['ldapQuotaAttribute', 'myquota'],
336
-				['ldapQuotaDefault', '']
337
-			]);
338
-
339
-		$this->access->expects($this->never())
340
-			->method('readAttribute');
341
-
342
-		$user = $this->createMock(IUser::class);
343
-		$user->expects($this->once())
344
-			->method('setQuota')
345
-			->with($readQuota);
346
-
347
-		$this->userManager->expects($this->once())
348
-			->method('get')
349
-			->with($this->uid)
350
-			->willReturn($user);
351
-
352
-		$this->user->updateQuota($readQuota);
353
-	}
354
-
355
-	/**
356
-	 * Unparseable quota will fallback to use the LDAP default
357
-	 */
358
-	public function testUpdateWrongQuotaAllProvided(): void {
359
-		$this->connection->expects($this->exactly(2))
360
-			->method('__get')
361
-			->willReturnMap([
362
-				['ldapQuotaAttribute', 'myquota'],
363
-				['ldapQuotaDefault', '23 GB']
364
-			]);
365
-
366
-		$this->access->expects($this->once())
367
-			->method('readAttribute')
368
-			->with($this->equalTo($this->dn),
369
-				$this->equalTo('myquota'))
370
-			->willReturn(['42 GBwos']);
371
-
372
-		$coreUser = $this->createMock(IUser::class);
373
-		$coreUser->expects($this->once())
374
-			->method('setQuota')
375
-			->with('23 GB');
376
-
377
-		$this->userManager->expects($this->once())
378
-			->method('get')
379
-			->with($this->uid)
380
-			->willReturn($coreUser);
381
-
382
-		$this->user->updateQuota();
383
-	}
384
-
385
-	/**
386
-	 * No user quota and wrong default will set 'default' as quota
387
-	 */
388
-	public function testUpdateWrongDefaultQuotaProvided(): void {
389
-		$this->connection->expects($this->exactly(2))
390
-			->method('__get')
391
-			->willReturnMap([
392
-				['ldapQuotaAttribute', 'myquota'],
393
-				['ldapQuotaDefault', '23 GBwowowo']
394
-			]);
395
-
396
-		$this->access->expects($this->once())
397
-			->method('readAttribute')
398
-			->with($this->equalTo($this->dn),
399
-				$this->equalTo('myquota'))
400
-			->willReturn(false);
401
-
402
-		$coreUser = $this->createMock(IUser::class);
403
-		$coreUser->expects($this->never())
404
-			->method('setQuota');
405
-
406
-		$this->userManager->expects($this->never())
407
-			->method('get');
408
-
409
-		$this->user->updateQuota();
410
-	}
411
-
412
-	/**
413
-	 * Wrong user quota and wrong default will set 'default' as quota
414
-	 */
415
-	public function testUpdateWrongQuotaAndDefaultAllProvided(): void {
416
-		$this->connection->expects($this->exactly(2))
417
-			->method('__get')
418
-			->willReturnMap([
419
-				['ldapQuotaAttribute', 'myquota'],
420
-				['ldapQuotaDefault', '23 GBwowowo']
421
-			]);
422
-
423
-		$this->access->expects($this->once())
424
-			->method('readAttribute')
425
-			->with($this->equalTo($this->dn),
426
-				$this->equalTo('myquota'))
427
-			->willReturn(['23 flush']);
428
-
429
-		$coreUser = $this->createMock(IUser::class);
430
-		$coreUser->expects($this->never())
431
-			->method('setQuota');
432
-
433
-		$this->userManager->expects($this->never())
434
-			->method('get');
435
-
436
-		$this->user->updateQuota();
437
-	}
438
-
439
-	/**
440
-	 * No quota attribute set and wrong default will set 'default' as quota
441
-	 */
442
-	public function testUpdateWrongDefaultQuotaNotProvided(): void {
443
-		$this->connection->expects($this->exactly(2))
444
-			->method('__get')
445
-			->willReturnMap([
446
-				['ldapQuotaAttribute', ''],
447
-				['ldapQuotaDefault', '23 GBwowowo']
448
-			]);
449
-
450
-		$this->access->expects($this->never())
451
-			->method('readAttribute');
452
-
453
-		$coreUser = $this->createMock(IUser::class);
454
-		$coreUser->expects($this->never())
455
-			->method('setQuota');
456
-
457
-		$this->userManager->expects($this->never())
458
-			->method('get');
459
-
460
-		$this->user->updateQuota();
461
-	}
462
-
463
-	//the testUpdateAvatar series also implicitly tests getAvatarImage
464
-	public function XtestUpdateAvatarJpegPhotoProvided() {
465
-		$this->access->expects($this->once())
466
-			->method('readAttribute')
467
-			->with($this->equalTo($this->dn),
468
-				$this->equalTo('jpegphoto'))
469
-			->willReturn(['this is a photo']);
470
-
471
-		$this->image->expects($this->once())
472
-			->method('loadFromBase64')
473
-			->willReturn('imageResource');
474
-		$this->image->expects($this->once())
475
-			->method('valid')
476
-			->willReturn(true);
477
-		$this->image->expects($this->once())
478
-			->method('width')
479
-			->willReturn(128);
480
-		$this->image->expects($this->once())
481
-			->method('height')
482
-			->willReturn(128);
483
-		$this->image->expects($this->once())
484
-			->method('centerCrop')
485
-			->willReturn(true);
486
-		$this->image->expects($this->once())
487
-			->method('data')
488
-			->willReturn('this is a photo');
489
-
490
-		$this->config->expects($this->once())
491
-			->method('getUserValue')
492
-			->with($this->uid, 'user_ldap', 'lastAvatarChecksum', '')
493
-			->willReturn('');
494
-		$this->config->expects($this->once())
495
-			->method('setUserValue')
496
-			->with($this->uid, 'user_ldap', 'lastAvatarChecksum', md5('this is a photo'));
497
-
498
-		$avatar = $this->createMock(IAvatar::class);
499
-		$avatar->expects($this->once())
500
-			->method('set')
501
-			->with($this->image);
502
-
503
-		$this->avatarManager->expects($this->once())
504
-			->method('getAvatar')
505
-			->with($this->equalTo($this->uid))
506
-			->willReturn($avatar);
507
-
508
-		$this->connection->expects($this->any())
509
-			->method('resolveRule')
510
-			->with('avatar')
511
-			->willReturn(['jpegphoto', 'thumbnailphoto']);
512
-
513
-		$this->user->updateAvatar();
514
-	}
515
-
516
-	public function testUpdateAvatarKnownJpegPhotoProvided(): void {
517
-		$this->access->expects($this->once())
518
-			->method('readAttribute')
519
-			->with($this->equalTo($this->dn),
520
-				$this->equalTo('jpegphoto'))
521
-			->willReturn(['this is a photo']);
522
-
523
-		$this->image->expects($this->once())
524
-			->method('loadFromBase64')
525
-			->willReturn('imageResource');
526
-		$this->image->expects($this->never())
527
-			->method('valid');
528
-		$this->image->expects($this->never())
529
-			->method('width');
530
-		$this->image->expects($this->never())
531
-			->method('height');
532
-		$this->image->expects($this->never())
533
-			->method('centerCrop');
534
-		$this->image->expects($this->once())
535
-			->method('data')
536
-			->willReturn('this is a photo');
537
-
538
-		$this->config->expects($this->once())
539
-			->method('getUserValue')
540
-			->with($this->uid, 'user_ldap', 'lastAvatarChecksum', '')
541
-			->willReturn(md5('this is a photo'));
542
-		$this->config->expects($this->never())
543
-			->method('setUserValue');
544
-
545
-		$avatar = $this->createMock(IAvatar::class);
546
-		$avatar->expects($this->never())
547
-			->method('set');
548
-		$avatar->expects($this->any())
549
-			->method('exists')
550
-			->willReturn(true);
551
-		$avatar->expects($this->any())
552
-			->method('isCustomAvatar')
553
-			->willReturn(true);
554
-
555
-		$this->avatarManager->expects($this->any())
556
-			->method('getAvatar')
557
-			->with($this->uid)
558
-			->willReturn($avatar);
559
-
560
-		$this->connection->expects($this->any())
561
-			->method('resolveRule')
562
-			->with('avatar')
563
-			->willReturn(['jpegphoto', 'thumbnailphoto']);
564
-
565
-		$this->assertTrue($this->user->updateAvatar());
566
-	}
567
-
568
-	public function XtestUpdateAvatarThumbnailPhotoProvided() {
569
-		$this->access->expects($this->any())
570
-			->method('readAttribute')
571
-			->willReturnCallback(function ($dn, $attr) {
572
-				if ($dn === $this->dn
573
-					&& $attr === 'jpegphoto') {
574
-					return false;
575
-				} elseif ($dn === $this->dn
576
-					&& $attr === 'thumbnailphoto') {
577
-					return ['this is a photo'];
578
-				}
579
-				return null;
580
-			});
581
-
582
-		$this->image->expects($this->once())
583
-			->method('loadFromBase64')
584
-			->willReturn('imageResource');
585
-		$this->image->expects($this->once())
586
-			->method('valid')
587
-			->willReturn(true);
588
-		$this->image->expects($this->once())
589
-			->method('width')
590
-			->willReturn(128);
591
-		$this->image->expects($this->once())
592
-			->method('height')
593
-			->willReturn(128);
594
-		$this->image->expects($this->once())
595
-			->method('centerCrop')
596
-			->willReturn(true);
597
-		$this->image->expects($this->once())
598
-			->method('data')
599
-			->willReturn('this is a photo');
600
-
601
-		$this->config->expects($this->once())
602
-			->method('getUserValue')
603
-			->with($this->uid, 'user_ldap', 'lastAvatarChecksum', '')
604
-			->willReturn('');
605
-		$this->config->expects($this->once())
606
-			->method('setUserValue')
607
-			->with($this->uid, 'user_ldap', 'lastAvatarChecksum', md5('this is a photo'));
608
-
609
-		$avatar = $this->createMock(IAvatar::class);
610
-		$avatar->expects($this->once())
611
-			->method('set')
612
-			->with($this->image);
613
-
614
-		$this->avatarManager->expects($this->once())
615
-			->method('getAvatar')
616
-			->with($this->equalTo($this->uid))
617
-			->willReturn($avatar);
618
-
619
-		$this->connection->expects($this->any())
620
-			->method('resolveRule')
621
-			->with('avatar')
622
-			->willReturn(['jpegphoto', 'thumbnailphoto']);
623
-
624
-		$this->user->updateAvatar();
625
-	}
626
-
627
-	public function testUpdateAvatarCorruptPhotoProvided(): void {
628
-		$this->access->expects($this->any())
629
-			->method('readAttribute')
630
-			->willReturnCallback(function ($dn, $attr) {
631
-				if ($dn === $this->dn
632
-					&& $attr === 'jpegphoto') {
633
-					return false;
634
-				} elseif ($dn === $this->dn
635
-					&& $attr === 'thumbnailphoto') {
636
-					return ['this is a photo'];
637
-				}
638
-				return null;
639
-			});
640
-
641
-		$this->image->expects($this->once())
642
-			->method('loadFromBase64')
643
-			->willReturn(false);
644
-		$this->image->expects($this->never())
645
-			->method('valid');
646
-		$this->image->expects($this->never())
647
-			->method('width');
648
-		$this->image->expects($this->never())
649
-			->method('height');
650
-		$this->image->expects($this->never())
651
-			->method('centerCrop');
652
-		$this->image->expects($this->never())
653
-			->method('data');
654
-
655
-		$this->config->expects($this->never())
656
-			->method('getUserValue');
657
-		$this->config->expects($this->never())
658
-			->method('setUserValue');
659
-
660
-		$avatar = $this->createMock(IAvatar::class);
661
-		$avatar->expects($this->never())
662
-			->method('set');
663
-
664
-		$this->avatarManager->expects($this->never())
665
-			->method('getAvatar');
666
-
667
-		$this->connection->expects($this->any())
668
-			->method('resolveRule')
669
-			->with('avatar')
670
-			->willReturn(['jpegphoto', 'thumbnailphoto']);
671
-
672
-		$this->user->updateAvatar();
673
-	}
674
-
675
-	public function XtestUpdateAvatarUnsupportedThumbnailPhotoProvided() {
676
-		$this->access->expects($this->any())
677
-			->method('readAttribute')
678
-			->willReturnCallback(function ($dn, $attr) {
679
-				if ($dn === $this->dn
680
-					&& $attr === 'jpegphoto') {
681
-					return false;
682
-				} elseif ($dn === $this->dn
683
-					&& $attr === 'thumbnailphoto') {
684
-					return ['this is a photo'];
685
-				}
686
-				return null;
687
-			});
688
-
689
-		$this->image->expects($this->once())
690
-			->method('loadFromBase64')
691
-			->willReturn('imageResource');
692
-		$this->image->expects($this->once())
693
-			->method('valid')
694
-			->willReturn(true);
695
-		$this->image->expects($this->once())
696
-			->method('width')
697
-			->willReturn(128);
698
-		$this->image->expects($this->once())
699
-			->method('height')
700
-			->willReturn(128);
701
-		$this->image->expects($this->once())
702
-			->method('centerCrop')
703
-			->willReturn(true);
704
-		$this->image->expects($this->once())
705
-			->method('data')
706
-			->willReturn('this is a photo');
707
-
708
-		$this->config->expects($this->once())
709
-			->method('getUserValue')
710
-			->with($this->uid, 'user_ldap', 'lastAvatarChecksum', '')
711
-			->willReturn('');
712
-		$this->config->expects($this->never())
713
-			->method('setUserValue');
714
-
715
-		$avatar = $this->createMock(IAvatar::class);
716
-		$avatar->expects($this->once())
717
-			->method('set')
718
-			->with($this->image)
719
-			->willThrowException(new \Exception());
720
-
721
-		$this->avatarManager->expects($this->once())
722
-			->method('getAvatar')
723
-			->with($this->equalTo($this->uid))
724
-			->willReturn($avatar);
725
-
726
-		$this->connection->expects($this->any())
727
-			->method('resolveRule')
728
-			->with('avatar')
729
-			->willReturn(['jpegphoto', 'thumbnailphoto']);
730
-
731
-		$this->assertFalse($this->user->updateAvatar());
732
-	}
733
-
734
-	public function testUpdateAvatarNotProvided(): void {
735
-		$this->access->expects($this->any())
736
-			->method('readAttribute')
737
-			->willReturnCallback(function ($dn, $attr) {
738
-				if ($dn === $this->dn
739
-					&& $attr === 'jpegPhoto') {
740
-					return false;
741
-				} elseif ($dn === $this->dn
742
-					&& $attr === 'thumbnailPhoto') {
743
-					return false;
744
-				}
745
-				return null;
746
-			});
747
-
748
-		$this->image->expects($this->never())
749
-			->method('valid');
750
-		$this->image->expects($this->never())
751
-			->method('width');
752
-		$this->image->expects($this->never())
753
-			->method('height');
754
-		$this->image->expects($this->never())
755
-			->method('centerCrop');
756
-		$this->image->expects($this->never())
757
-			->method('data');
758
-
759
-		$this->config->expects($this->never())
760
-			->method('getUserValue');
761
-		$this->config->expects($this->never())
762
-			->method('setUserValue');
763
-
764
-		$this->avatarManager->expects($this->never())
765
-			->method('getAvatar');
766
-
767
-		$this->connection->expects($this->any())
768
-			->method('resolveRule')
769
-			->with('avatar')
770
-			->willReturn(['jpegphoto', 'thumbnailphoto']);
771
-
772
-		$this->user->updateAvatar();
773
-	}
774
-
775
-	public static function extStorageHomeDataProvider(): array {
776
-		return [
777
-			[ 'myFolder', null ],
778
-			[ '', null, false ],
779
-			[ 'myFolder', 'myFolder' ],
780
-		];
781
-	}
782
-
783
-	/**
784
-	 * @dataProvider extStorageHomeDataProvider
785
-	 */
786
-	public function testUpdateExtStorageHome(string $expected, ?string $valueFromLDAP = null, bool $isSet = true): void {
787
-		if ($valueFromLDAP === null) {
788
-			$this->connection->expects($this->once())
789
-				->method('__get')
790
-				->willReturnMap([
791
-					['ldapExtStorageHomeAttribute', 'homeDirectory'],
792
-				]);
793
-
794
-			$return = [];
795
-			if ($isSet) {
796
-				$return[] = $expected;
797
-			}
798
-			$this->access->expects($this->once())
799
-				->method('readAttribute')
800
-				->with($this->dn, 'homeDirectory')
801
-				->willReturn($return);
802
-		}
803
-
804
-		if ($expected !== '') {
805
-			$this->config->expects($this->once())
806
-				->method('setUserValue')
807
-				->with($this->uid, 'user_ldap', 'extStorageHome', $expected);
808
-		} else {
809
-			$this->config->expects($this->once())
810
-				->method('deleteUserValue')
811
-				->with($this->uid, 'user_ldap', 'extStorageHome');
812
-		}
813
-
814
-		$actual = $this->user->updateExtStorageHome($valueFromLDAP);
815
-		$this->assertSame($expected, $actual);
816
-	}
817
-
818
-	public function testMarkLogin(): void {
819
-		$this->config->expects($this->once())
820
-			->method('setUserValue')
821
-			->with($this->equalTo($this->uid),
822
-				$this->equalTo('user_ldap'),
823
-				$this->equalTo(User::USER_PREFKEY_FIRSTLOGIN),
824
-				$this->equalTo(1))
825
-			->willReturn(true);
826
-
827
-		$this->user->markLogin();
828
-	}
829
-
830
-	public function testGetAvatarImageProvided(): void {
831
-		$this->access->expects($this->once())
832
-			->method('readAttribute')
833
-			->with($this->equalTo($this->dn),
834
-				$this->equalTo('jpegphoto'))
835
-			->willReturn(['this is a photo']);
836
-		$this->connection->expects($this->any())
837
-			->method('resolveRule')
838
-			->with('avatar')
839
-			->willReturn(['jpegphoto', 'thumbnailphoto']);
840
-
841
-		$photo = $this->user->getAvatarImage();
842
-		$this->assertSame('this is a photo', $photo);
843
-		//make sure readAttribute is not called again but the already fetched
844
-		//photo is returned
845
-		$this->user->getAvatarImage();
846
-	}
847
-
848
-	public function testGetAvatarImageDisabled(): void {
849
-		$this->access->expects($this->never())
850
-			->method('readAttribute')
851
-			->with($this->equalTo($this->dn), $this->anything());
852
-		$this->connection->expects($this->any())
853
-			->method('resolveRule')
854
-			->with('avatar')
855
-			->willReturn([]);
856
-
857
-		$this->assertFalse($this->user->getAvatarImage());
858
-	}
859
-
860
-	public static function imageDataProvider(): array {
861
-		return [
862
-			[ false, false ],
863
-			[ 'corruptData', false ],
864
-			[ 'validData', true ],
865
-		];
866
-	}
867
-
868
-	public function testProcessAttributes(): void {
869
-		$requiredMethods = [
870
-			'updateQuota',
871
-			'updateEmail',
872
-			'composeAndStoreDisplayName',
873
-			'storeLDAPUserName',
874
-			'getHomePath',
875
-			'updateAvatar',
876
-			'updateExtStorageHome',
877
-		];
878
-
879
-		/** @var User&MockObject $userMock */
880
-		$userMock = $this->getMockBuilder(User::class)
881
-			->setConstructorArgs([
882
-				$this->uid,
883
-				$this->dn,
884
-				$this->access,
885
-				$this->config,
886
-				$this->image,
887
-				$this->logger,
888
-				$this->avatarManager,
889
-				$this->userManager,
890
-				$this->notificationManager
891
-			])
892
-			->onlyMethods($requiredMethods)
893
-			->getMock();
894
-
895
-		$this->connection->setConfiguration([
896
-			'homeFolderNamingRule' => 'homeDirectory'
897
-		]);
898
-		$this->connection->expects($this->any())
899
-			->method('__get')
900
-			->willReturnCallback(function ($name) {
901
-				if ($name === 'homeFolderNamingRule') {
902
-					return 'attr:homeDirectory';
903
-				}
904
-				return $name;
905
-			});
906
-		$this->connection->expects($this->any())
907
-			->method('resolveRule')
908
-			->with('avatar')
909
-			->willReturn(['jpegphoto', 'thumbnailphoto']);
910
-
911
-		$record = [
912
-			strtolower($this->connection->ldapQuotaAttribute) => ['4096'],
913
-			strtolower($this->connection->ldapEmailAttribute) => ['[email protected]'],
914
-			strtolower($this->connection->ldapUserDisplayName) => ['Aaaaalice'],
915
-			strtolower($this->connection->ldapExtStorageHomeAttribute) => ['homeDirectory'],
916
-			'uid' => [$this->uid],
917
-			'homedirectory' => ['Alice\'s Folder'],
918
-			'memberof' => ['cn=groupOne', 'cn=groupTwo'],
919
-			'jpegphoto' => ['here be an image']
920
-		];
921
-
922
-		foreach ($requiredMethods as $method) {
923
-			$userMock->expects($this->once())
924
-				->method($method);
925
-		}
926
-		\OC_Hook::clear();//disconnect irrelevant hooks
927
-		$userMock->processAttributes($record);
928
-		/** @noinspection PhpUnhandledExceptionInspection */
929
-		\OC_Hook::emit('OC_User', 'post_login', ['uid' => $this->uid]);
930
-	}
931
-
932
-	public static function emptyHomeFolderAttributeValueProvider(): array {
933
-		return [
934
-			'empty' => [''],
935
-			'prefixOnly' => ['attr:'],
936
-		];
937
-	}
938
-
939
-	/**
940
-	 * @dataProvider emptyHomeFolderAttributeValueProvider
941
-	 */
942
-	public function testGetHomePathNotConfigured(string $attributeValue): void {
943
-		$this->connection->expects($this->any())
944
-			->method('__get')
945
-			->with($this->equalTo('homeFolderNamingRule'))
946
-			->willReturn($attributeValue);
947
-
948
-		$this->access->expects($this->never())
949
-			->method('readAttribute');
950
-
951
-		$this->config->expects($this->never())
952
-			->method('getAppValue');
953
-
954
-		/** @noinspection PhpUnhandledExceptionInspection */
955
-		$this->assertFalse($this->user->getHomePath());
956
-	}
957
-
958
-	public function testGetHomePathConfiguredNotAvailableAllowed(): void {
959
-		$this->connection->expects($this->any())
960
-			->method('__get')
961
-			->with($this->equalTo('homeFolderNamingRule'))
962
-			->willReturn('attr:foobar');
963
-
964
-		$this->access->expects($this->once())
965
-			->method('readAttribute')
966
-			->willReturn(false);
967
-
968
-		$this->access->expects($this->once())
969
-			->method('username2dn')
970
-			->willReturn($this->dn);
971
-
972
-		// asks for "enforce_home_folder_naming_rule"
973
-		$this->config->expects($this->once())
974
-			->method('getAppValue')
975
-			->willReturn(false);
976
-
977
-		/** @noinspection PhpUnhandledExceptionInspection */
978
-		$this->assertFalse($this->user->getHomePath());
979
-	}
980
-
981
-
982
-	public function testGetHomePathConfiguredNotAvailableNotAllowed(): void {
983
-		$this->expectException(\Exception::class);
984
-
985
-		$this->connection->expects($this->any())
986
-			->method('__get')
987
-			->with($this->equalTo('homeFolderNamingRule'))
988
-			->willReturn('attr:foobar');
989
-
990
-		$this->access->expects($this->once())
991
-			->method('readAttribute')
992
-			->willReturn(false);
993
-
994
-		$this->access->expects($this->once())
995
-			->method('username2dn')
996
-			->willReturn($this->dn);
997
-
998
-		// asks for "enforce_home_folder_naming_rule"
999
-		$this->config->expects($this->once())
1000
-			->method('getAppValue')
1001
-			->willReturn(true);
1002
-
1003
-		$this->user->getHomePath();
1004
-	}
1005
-
1006
-	public static function displayNameProvider(): array {
1007
-		return [
1008
-			['Roland Deschain', '', 'Roland Deschain', false],
1009
-			['Roland Deschain', '', 'Roland Deschain', true],
1010
-			['Roland Deschain', '[email protected]', 'Roland Deschain ([email protected])', false],
1011
-			['Roland Deschain', '[email protected]', 'Roland Deschain ([email protected])', true],
1012
-		];
1013
-	}
1014
-
1015
-	/**
1016
-	 * @dataProvider displayNameProvider
1017
-	 */
1018
-	public function testComposeAndStoreDisplayName(string $part1, string $part2, string $expected, bool $expectTriggerChange): void {
1019
-		$this->config->expects($this->once())
1020
-			->method('setUserValue');
1021
-		$oldName = $expectTriggerChange ? 'xxGunslingerxx' : null;
1022
-		$this->config->expects($this->once())
1023
-			->method('getUserValue')
1024
-			->with($this->user->getUsername(), 'user_ldap', 'displayName', null)
1025
-			->willReturn($oldName);
1026
-
1027
-		$ncUserObj = $this->createMock(\OC\User\User::class);
1028
-		if ($expectTriggerChange) {
1029
-			$ncUserObj->expects($this->once())
1030
-				->method('triggerChange')
1031
-				->with('displayName', $expected);
1032
-		} else {
1033
-			$ncUserObj->expects($this->never())
1034
-				->method('triggerChange');
1035
-		}
1036
-		$this->userManager->expects($this->once())
1037
-			->method('get')
1038
-			->willReturn($ncUserObj);
1039
-
1040
-		$displayName = $this->user->composeAndStoreDisplayName($part1, $part2);
1041
-		$this->assertSame($expected, $displayName);
1042
-	}
1043
-
1044
-	public function testComposeAndStoreDisplayNameNoOverwrite(): void {
1045
-		$displayName = 'Randall Flagg';
1046
-		$this->config->expects($this->never())
1047
-			->method('setUserValue');
1048
-		$this->config->expects($this->once())
1049
-			->method('getUserValue')
1050
-			->willReturn($displayName);
1051
-
1052
-		$this->userManager->expects($this->never())
1053
-			->method('get'); // Implicit: no triggerChange can be called
1054
-
1055
-		$composedDisplayName = $this->user->composeAndStoreDisplayName($displayName);
1056
-		$this->assertSame($composedDisplayName, $displayName);
1057
-	}
1058
-
1059
-	public function testHandlePasswordExpiryWarningDefaultPolicy(): void {
1060
-		$this->connection->expects($this->any())
1061
-			->method('__get')
1062
-			->willReturnCallback(function ($name) {
1063
-				if ($name === 'ldapDefaultPPolicyDN') {
1064
-					return 'cn=default,ou=policies,dc=foo,dc=bar';
1065
-				}
1066
-				if ($name === 'turnOnPasswordChange') {
1067
-					return '1';
1068
-				}
1069
-				return $name;
1070
-			});
1071
-
1072
-		$this->access->expects($this->any())
1073
-			->method('search')
1074
-			->willReturnCallback(function ($filter, $base) {
1075
-				if ($base === $this->dn) {
1076
-					return [
1077
-						[
1078
-							'pwdchangedtime' => [(new \DateTime())->sub(new \DateInterval('P28D'))->format('Ymdhis') . 'Z'],
1079
-							'pwdgraceusetime' => [],
1080
-						],
1081
-					];
1082
-				}
1083
-				if ($base === 'cn=default,ou=policies,dc=foo,dc=bar') {
1084
-					return [
1085
-						[
1086
-							'pwdmaxage' => ['2592000'],
1087
-							'pwdexpirewarning' => ['2591999'],
1088
-						],
1089
-					];
1090
-				}
1091
-				return [];
1092
-			});
1093
-
1094
-		$notification = $this->getMockBuilder(INotification::class)
1095
-			->disableOriginalConstructor()
1096
-			->getMock();
1097
-		$notification->expects($this->any())
1098
-			->method('setApp')
1099
-			->willReturn($notification);
1100
-		$notification->expects($this->any())
1101
-			->method('setUser')
1102
-			->willReturn($notification);
1103
-		$notification->expects($this->any())
1104
-			->method('setObject')
1105
-			->willReturn($notification);
1106
-		$notification->expects($this->any())
1107
-			->method('setDateTime')
1108
-			->willReturn($notification);
1109
-
1110
-		$this->notificationManager->expects($this->exactly(2))
1111
-			->method('createNotification')
1112
-			->willReturn($notification);
1113
-		$this->notificationManager->expects($this->exactly(1))
1114
-			->method('notify');
1115
-
1116
-		\OC_Hook::clear();//disconnect irrelevant hooks
1117
-		Util::connectHook('OC_User', 'post_login', $this->user, 'handlePasswordExpiry');
1118
-		/** @noinspection PhpUnhandledExceptionInspection */
1119
-		\OC_Hook::emit('OC_User', 'post_login', ['uid' => $this->uid]);
1120
-	}
1121
-
1122
-	public function testHandlePasswordExpiryWarningCustomPolicy(): void {
1123
-		$this->connection->expects($this->any())
1124
-			->method('__get')
1125
-			->willReturnCallback(function ($name) {
1126
-				if ($name === 'ldapDefaultPPolicyDN') {
1127
-					return 'cn=default,ou=policies,dc=foo,dc=bar';
1128
-				}
1129
-				if ($name === 'turnOnPasswordChange') {
1130
-					return '1';
1131
-				}
1132
-				return $name;
1133
-			});
1134
-
1135
-		$this->access->expects($this->any())
1136
-			->method('search')
1137
-			->willReturnCallback(function ($filter, $base) {
1138
-				if ($base === $this->dn) {
1139
-					return [
1140
-						[
1141
-							'pwdpolicysubentry' => ['cn=custom,ou=policies,dc=foo,dc=bar'],
1142
-							'pwdchangedtime' => [(new \DateTime())->sub(new \DateInterval('P28D'))->format('Ymdhis') . 'Z'],
1143
-							'pwdgraceusetime' => [],
1144
-						]
1145
-					];
1146
-				}
1147
-				if ($base === 'cn=custom,ou=policies,dc=foo,dc=bar') {
1148
-					return [
1149
-						[
1150
-							'pwdmaxage' => ['2592000'],
1151
-							'pwdexpirewarning' => ['2591999'],
1152
-						]
1153
-					];
1154
-				}
1155
-				return [];
1156
-			});
1157
-
1158
-		$notification = $this->getMockBuilder(INotification::class)
1159
-			->disableOriginalConstructor()
1160
-			->getMock();
1161
-		$notification->expects($this->any())
1162
-			->method('setApp')
1163
-			->willReturn($notification);
1164
-		$notification->expects($this->any())
1165
-			->method('setUser')
1166
-			->willReturn($notification);
1167
-		$notification->expects($this->any())
1168
-			->method('setObject')
1169
-			->willReturn($notification);
1170
-		$notification->expects($this->any())
1171
-			->method('setDateTime')
1172
-			->willReturn($notification);
1173
-
1174
-		$this->notificationManager->expects($this->exactly(2))
1175
-			->method('createNotification')
1176
-			->willReturn($notification);
1177
-		$this->notificationManager->expects($this->exactly(1))
1178
-			->method('notify');
1179
-
1180
-		\OC_Hook::clear();//disconnect irrelevant hooks
1181
-		Util::connectHook('OC_User', 'post_login', $this->user, 'handlePasswordExpiry');
1182
-		/** @noinspection PhpUnhandledExceptionInspection */
1183
-		\OC_Hook::emit('OC_User', 'post_login', ['uid' => $this->uid]);
1184
-	}
35
+    protected Access&MockObject $access;
36
+    protected Connection&MockObject $connection;
37
+    protected IConfig&MockObject $config;
38
+    protected INotificationManager&MockObject $notificationManager;
39
+    protected IUserManager&MockObject $userManager;
40
+    protected Image&MockObject $image;
41
+    protected IAvatarManager&MockObject $avatarManager;
42
+    protected LoggerInterface&MockObject $logger;
43
+    protected string $uid = 'alice';
44
+    protected string $dn = 'uid=alice,dc=foo,dc=bar';
45
+    protected User $user;
46
+
47
+    protected function setUp(): void {
48
+        parent::setUp();
49
+
50
+        $this->connection = $this->getMockBuilder(Connection::class)
51
+            ->setConstructorArgs([$this->createMock(ILDAPWrapper::class)])
52
+            ->getMock();
53
+
54
+        $this->access = $this->createMock(Access::class);
55
+        $this->access->connection = $this->connection;
56
+        $this->access->expects($this->any())
57
+            ->method('getConnection')
58
+            ->willReturn($this->connection);
59
+
60
+        $this->config = $this->createMock(IConfig::class);
61
+        $this->logger = $this->createMock(LoggerInterface::class);
62
+        $this->avatarManager = $this->createMock(IAvatarManager::class);
63
+        $this->image = $this->createMock(Image::class);
64
+        $this->userManager = $this->createMock(IUserManager::class);
65
+        $this->notificationManager = $this->createMock(INotificationManager::class);
66
+
67
+        $this->user = new User(
68
+            $this->uid,
69
+            $this->dn,
70
+            $this->access,
71
+            $this->config,
72
+            $this->image,
73
+            $this->logger,
74
+            $this->avatarManager,
75
+            $this->userManager,
76
+            $this->notificationManager
77
+        );
78
+    }
79
+
80
+    public function testGetDNandUsername(): void {
81
+        $this->assertSame($this->dn, $this->user->getDN());
82
+        $this->assertSame($this->uid, $this->user->getUsername());
83
+    }
84
+
85
+    public function testUpdateEmailProvided(): void {
86
+        $this->connection->expects($this->once())
87
+            ->method('__get')
88
+            ->with($this->equalTo('ldapEmailAttribute'))
89
+            ->willReturn('email');
90
+
91
+        $this->access->expects($this->once())
92
+            ->method('readAttribute')
93
+            ->with($this->equalTo($this->dn),
94
+                $this->equalTo('email'))
95
+            ->willReturn(['[email protected]']);
96
+
97
+        $coreUser = $this->createMock(IUser::class);
98
+        $coreUser->expects($this->once())
99
+            ->method('setSystemEMailAddress')
100
+            ->with('[email protected]');
101
+
102
+        $this->userManager->expects($this->any())
103
+            ->method('get')
104
+            ->willReturn($coreUser);
105
+
106
+        $this->user->updateEmail();
107
+    }
108
+
109
+    public function testUpdateEmailNotProvided(): void {
110
+        $this->connection->expects($this->once())
111
+            ->method('__get')
112
+            ->with($this->equalTo('ldapEmailAttribute'))
113
+            ->willReturn('email');
114
+
115
+        $this->access->expects($this->once())
116
+            ->method('readAttribute')
117
+            ->with($this->equalTo($this->dn),
118
+                $this->equalTo('email'))
119
+            ->willReturn(false);
120
+
121
+        $this->config->expects($this->never())
122
+            ->method('setUserValue');
123
+
124
+        $this->user->updateEmail();
125
+    }
126
+
127
+    public function testUpdateEmailNotConfigured(): void {
128
+        $this->connection->expects($this->once())
129
+            ->method('__get')
130
+            ->with($this->equalTo('ldapEmailAttribute'))
131
+            ->willReturn('');
132
+
133
+        $this->access->expects($this->never())
134
+            ->method('readAttribute');
135
+
136
+        $this->config->expects($this->never())
137
+            ->method('setUserValue');
138
+
139
+        $this->user->updateEmail();
140
+    }
141
+
142
+    public function testUpdateQuotaAllProvided(): void {
143
+        $this->connection->expects($this->exactly(2))
144
+            ->method('__get')
145
+            ->willReturnMap([
146
+                ['ldapQuotaAttribute', 'myquota'],
147
+                ['ldapQuotaDefault', '']
148
+            ]);
149
+
150
+        $this->access->expects($this->once())
151
+            ->method('readAttribute')
152
+            ->with($this->equalTo($this->dn),
153
+                $this->equalTo('myquota'))
154
+            ->willReturn(['42 GB']);
155
+
156
+        $coreUser = $this->createMock(IUser::class);
157
+        $coreUser->expects($this->once())
158
+            ->method('setQuota')
159
+            ->with('42 GB');
160
+
161
+        $this->userManager->expects($this->atLeastOnce())
162
+            ->method('get')
163
+            ->with($this->uid)
164
+            ->willReturn($coreUser);
165
+
166
+        $this->user->updateQuota();
167
+    }
168
+
169
+    public function testUpdateQuotaToDefaultAllProvided(): void {
170
+        $this->connection->expects($this->exactly(2))
171
+            ->method('__get')
172
+            ->willReturnMap([
173
+                ['ldapQuotaAttribute', 'myquota'],
174
+                ['ldapQuotaDefault', '']
175
+            ]);
176
+
177
+        $this->access->expects($this->once())
178
+            ->method('readAttribute')
179
+            ->with($this->equalTo($this->dn),
180
+                $this->equalTo('myquota'))
181
+            ->willReturn(['default']);
182
+
183
+        $coreUser = $this->createMock(IUser::class);
184
+        $coreUser->expects($this->once())
185
+            ->method('setQuota')
186
+            ->with('default');
187
+
188
+        $this->userManager->expects($this->once())
189
+            ->method('get')
190
+            ->with($this->uid)
191
+            ->willReturn($coreUser);
192
+
193
+        $this->user->updateQuota();
194
+    }
195
+
196
+    public function testUpdateQuotaToNoneAllProvided(): void {
197
+        $this->connection->expects($this->exactly(2))
198
+            ->method('__get')
199
+            ->willReturnMap([
200
+                ['ldapQuotaAttribute', 'myquota'],
201
+                ['ldapQuotaDefault', '']
202
+            ]);
203
+
204
+        $this->access->expects($this->once())
205
+            ->method('readAttribute')
206
+            ->with($this->equalTo($this->dn),
207
+                $this->equalTo('myquota'))
208
+            ->willReturn(['none']);
209
+
210
+        $coreUser = $this->createMock(IUser::class);
211
+        $coreUser->expects($this->once())
212
+            ->method('setQuota')
213
+            ->with('none');
214
+
215
+        $this->userManager->expects($this->once())
216
+            ->method('get')
217
+            ->with($this->uid)
218
+            ->willReturn($coreUser);
219
+
220
+        $this->user->updateQuota();
221
+    }
222
+
223
+    public function testUpdateQuotaDefaultProvided(): void {
224
+        $this->connection->expects($this->exactly(2))
225
+            ->method('__get')
226
+            ->willReturnMap([
227
+                ['ldapQuotaAttribute', 'myquota'],
228
+                ['ldapQuotaDefault', '25 GB'],
229
+            ]);
230
+
231
+        $this->access->expects($this->once())
232
+            ->method('readAttribute')
233
+            ->with($this->equalTo($this->dn),
234
+                $this->equalTo('myquota'))
235
+            ->willReturn(false);
236
+
237
+        $coreUser = $this->createMock(IUser::class);
238
+        $coreUser->expects($this->once())
239
+            ->method('setQuota')
240
+            ->with('25 GB');
241
+
242
+        $this->userManager->expects($this->once())
243
+            ->method('get')
244
+            ->with($this->uid)
245
+            ->willReturn($coreUser);
246
+
247
+        $this->user->updateQuota();
248
+    }
249
+
250
+    public function testUpdateQuotaIndividualProvided(): void {
251
+        $this->connection->expects($this->exactly(2))
252
+            ->method('__get')
253
+            ->willReturnMap([
254
+                ['ldapQuotaAttribute', 'myquota'],
255
+                ['ldapQuotaDefault', '']
256
+            ]);
257
+
258
+        $this->access->expects($this->once())
259
+            ->method('readAttribute')
260
+            ->with($this->equalTo($this->dn),
261
+                $this->equalTo('myquota'))
262
+            ->willReturn(['27 GB']);
263
+
264
+        $coreUser = $this->createMock(IUser::class);
265
+        $coreUser->expects($this->once())
266
+            ->method('setQuota')
267
+            ->with('27 GB');
268
+
269
+        $this->userManager->expects($this->once())
270
+            ->method('get')
271
+            ->with($this->uid)
272
+            ->willReturn($coreUser);
273
+
274
+        $this->user->updateQuota();
275
+    }
276
+
277
+    public function testUpdateQuotaNoneProvided(): void {
278
+        $this->connection->expects($this->exactly(2))
279
+            ->method('__get')
280
+            ->willReturnMap([
281
+                ['ldapQuotaAttribute', 'myquota'],
282
+                ['ldapQuotaDefault', '']
283
+            ]);
284
+
285
+        $this->access->expects($this->once())
286
+            ->method('readAttribute')
287
+            ->with($this->equalTo($this->dn),
288
+                $this->equalTo('myquota'))
289
+            ->willReturn(false);
290
+
291
+        $coreUser = $this->createMock(IUser::class);
292
+        $coreUser->expects($this->never())
293
+            ->method('setQuota');
294
+
295
+        $this->userManager->expects($this->never())
296
+            ->method('get')
297
+            ->with($this->uid);
298
+
299
+        $this->config->expects($this->never())
300
+            ->method('setUserValue');
301
+
302
+        $this->user->updateQuota();
303
+    }
304
+
305
+    public function testUpdateQuotaNoneConfigured(): void {
306
+        $this->connection->expects($this->exactly(2))
307
+            ->method('__get')
308
+            ->willReturnMap([
309
+                ['ldapQuotaAttribute', ''],
310
+                ['ldapQuotaDefault', '']
311
+            ]);
312
+
313
+        $coreUser = $this->createMock(IUser::class);
314
+        $coreUser->expects($this->never())
315
+            ->method('setQuota');
316
+
317
+        $this->userManager->expects($this->never())
318
+            ->method('get');
319
+
320
+        $this->access->expects($this->never())
321
+            ->method('readAttribute');
322
+
323
+        $this->config->expects($this->never())
324
+            ->method('setUserValue');
325
+
326
+        $this->user->updateQuota();
327
+    }
328
+
329
+    public function testUpdateQuotaFromValue(): void {
330
+        $readQuota = '19 GB';
331
+
332
+        $this->connection->expects($this->exactly(2))
333
+            ->method('__get')
334
+            ->willReturnMap([
335
+                ['ldapQuotaAttribute', 'myquota'],
336
+                ['ldapQuotaDefault', '']
337
+            ]);
338
+
339
+        $this->access->expects($this->never())
340
+            ->method('readAttribute');
341
+
342
+        $user = $this->createMock(IUser::class);
343
+        $user->expects($this->once())
344
+            ->method('setQuota')
345
+            ->with($readQuota);
346
+
347
+        $this->userManager->expects($this->once())
348
+            ->method('get')
349
+            ->with($this->uid)
350
+            ->willReturn($user);
351
+
352
+        $this->user->updateQuota($readQuota);
353
+    }
354
+
355
+    /**
356
+     * Unparseable quota will fallback to use the LDAP default
357
+     */
358
+    public function testUpdateWrongQuotaAllProvided(): void {
359
+        $this->connection->expects($this->exactly(2))
360
+            ->method('__get')
361
+            ->willReturnMap([
362
+                ['ldapQuotaAttribute', 'myquota'],
363
+                ['ldapQuotaDefault', '23 GB']
364
+            ]);
365
+
366
+        $this->access->expects($this->once())
367
+            ->method('readAttribute')
368
+            ->with($this->equalTo($this->dn),
369
+                $this->equalTo('myquota'))
370
+            ->willReturn(['42 GBwos']);
371
+
372
+        $coreUser = $this->createMock(IUser::class);
373
+        $coreUser->expects($this->once())
374
+            ->method('setQuota')
375
+            ->with('23 GB');
376
+
377
+        $this->userManager->expects($this->once())
378
+            ->method('get')
379
+            ->with($this->uid)
380
+            ->willReturn($coreUser);
381
+
382
+        $this->user->updateQuota();
383
+    }
384
+
385
+    /**
386
+     * No user quota and wrong default will set 'default' as quota
387
+     */
388
+    public function testUpdateWrongDefaultQuotaProvided(): void {
389
+        $this->connection->expects($this->exactly(2))
390
+            ->method('__get')
391
+            ->willReturnMap([
392
+                ['ldapQuotaAttribute', 'myquota'],
393
+                ['ldapQuotaDefault', '23 GBwowowo']
394
+            ]);
395
+
396
+        $this->access->expects($this->once())
397
+            ->method('readAttribute')
398
+            ->with($this->equalTo($this->dn),
399
+                $this->equalTo('myquota'))
400
+            ->willReturn(false);
401
+
402
+        $coreUser = $this->createMock(IUser::class);
403
+        $coreUser->expects($this->never())
404
+            ->method('setQuota');
405
+
406
+        $this->userManager->expects($this->never())
407
+            ->method('get');
408
+
409
+        $this->user->updateQuota();
410
+    }
411
+
412
+    /**
413
+     * Wrong user quota and wrong default will set 'default' as quota
414
+     */
415
+    public function testUpdateWrongQuotaAndDefaultAllProvided(): void {
416
+        $this->connection->expects($this->exactly(2))
417
+            ->method('__get')
418
+            ->willReturnMap([
419
+                ['ldapQuotaAttribute', 'myquota'],
420
+                ['ldapQuotaDefault', '23 GBwowowo']
421
+            ]);
422
+
423
+        $this->access->expects($this->once())
424
+            ->method('readAttribute')
425
+            ->with($this->equalTo($this->dn),
426
+                $this->equalTo('myquota'))
427
+            ->willReturn(['23 flush']);
428
+
429
+        $coreUser = $this->createMock(IUser::class);
430
+        $coreUser->expects($this->never())
431
+            ->method('setQuota');
432
+
433
+        $this->userManager->expects($this->never())
434
+            ->method('get');
435
+
436
+        $this->user->updateQuota();
437
+    }
438
+
439
+    /**
440
+     * No quota attribute set and wrong default will set 'default' as quota
441
+     */
442
+    public function testUpdateWrongDefaultQuotaNotProvided(): void {
443
+        $this->connection->expects($this->exactly(2))
444
+            ->method('__get')
445
+            ->willReturnMap([
446
+                ['ldapQuotaAttribute', ''],
447
+                ['ldapQuotaDefault', '23 GBwowowo']
448
+            ]);
449
+
450
+        $this->access->expects($this->never())
451
+            ->method('readAttribute');
452
+
453
+        $coreUser = $this->createMock(IUser::class);
454
+        $coreUser->expects($this->never())
455
+            ->method('setQuota');
456
+
457
+        $this->userManager->expects($this->never())
458
+            ->method('get');
459
+
460
+        $this->user->updateQuota();
461
+    }
462
+
463
+    //the testUpdateAvatar series also implicitly tests getAvatarImage
464
+    public function XtestUpdateAvatarJpegPhotoProvided() {
465
+        $this->access->expects($this->once())
466
+            ->method('readAttribute')
467
+            ->with($this->equalTo($this->dn),
468
+                $this->equalTo('jpegphoto'))
469
+            ->willReturn(['this is a photo']);
470
+
471
+        $this->image->expects($this->once())
472
+            ->method('loadFromBase64')
473
+            ->willReturn('imageResource');
474
+        $this->image->expects($this->once())
475
+            ->method('valid')
476
+            ->willReturn(true);
477
+        $this->image->expects($this->once())
478
+            ->method('width')
479
+            ->willReturn(128);
480
+        $this->image->expects($this->once())
481
+            ->method('height')
482
+            ->willReturn(128);
483
+        $this->image->expects($this->once())
484
+            ->method('centerCrop')
485
+            ->willReturn(true);
486
+        $this->image->expects($this->once())
487
+            ->method('data')
488
+            ->willReturn('this is a photo');
489
+
490
+        $this->config->expects($this->once())
491
+            ->method('getUserValue')
492
+            ->with($this->uid, 'user_ldap', 'lastAvatarChecksum', '')
493
+            ->willReturn('');
494
+        $this->config->expects($this->once())
495
+            ->method('setUserValue')
496
+            ->with($this->uid, 'user_ldap', 'lastAvatarChecksum', md5('this is a photo'));
497
+
498
+        $avatar = $this->createMock(IAvatar::class);
499
+        $avatar->expects($this->once())
500
+            ->method('set')
501
+            ->with($this->image);
502
+
503
+        $this->avatarManager->expects($this->once())
504
+            ->method('getAvatar')
505
+            ->with($this->equalTo($this->uid))
506
+            ->willReturn($avatar);
507
+
508
+        $this->connection->expects($this->any())
509
+            ->method('resolveRule')
510
+            ->with('avatar')
511
+            ->willReturn(['jpegphoto', 'thumbnailphoto']);
512
+
513
+        $this->user->updateAvatar();
514
+    }
515
+
516
+    public function testUpdateAvatarKnownJpegPhotoProvided(): void {
517
+        $this->access->expects($this->once())
518
+            ->method('readAttribute')
519
+            ->with($this->equalTo($this->dn),
520
+                $this->equalTo('jpegphoto'))
521
+            ->willReturn(['this is a photo']);
522
+
523
+        $this->image->expects($this->once())
524
+            ->method('loadFromBase64')
525
+            ->willReturn('imageResource');
526
+        $this->image->expects($this->never())
527
+            ->method('valid');
528
+        $this->image->expects($this->never())
529
+            ->method('width');
530
+        $this->image->expects($this->never())
531
+            ->method('height');
532
+        $this->image->expects($this->never())
533
+            ->method('centerCrop');
534
+        $this->image->expects($this->once())
535
+            ->method('data')
536
+            ->willReturn('this is a photo');
537
+
538
+        $this->config->expects($this->once())
539
+            ->method('getUserValue')
540
+            ->with($this->uid, 'user_ldap', 'lastAvatarChecksum', '')
541
+            ->willReturn(md5('this is a photo'));
542
+        $this->config->expects($this->never())
543
+            ->method('setUserValue');
544
+
545
+        $avatar = $this->createMock(IAvatar::class);
546
+        $avatar->expects($this->never())
547
+            ->method('set');
548
+        $avatar->expects($this->any())
549
+            ->method('exists')
550
+            ->willReturn(true);
551
+        $avatar->expects($this->any())
552
+            ->method('isCustomAvatar')
553
+            ->willReturn(true);
554
+
555
+        $this->avatarManager->expects($this->any())
556
+            ->method('getAvatar')
557
+            ->with($this->uid)
558
+            ->willReturn($avatar);
559
+
560
+        $this->connection->expects($this->any())
561
+            ->method('resolveRule')
562
+            ->with('avatar')
563
+            ->willReturn(['jpegphoto', 'thumbnailphoto']);
564
+
565
+        $this->assertTrue($this->user->updateAvatar());
566
+    }
567
+
568
+    public function XtestUpdateAvatarThumbnailPhotoProvided() {
569
+        $this->access->expects($this->any())
570
+            ->method('readAttribute')
571
+            ->willReturnCallback(function ($dn, $attr) {
572
+                if ($dn === $this->dn
573
+                    && $attr === 'jpegphoto') {
574
+                    return false;
575
+                } elseif ($dn === $this->dn
576
+                    && $attr === 'thumbnailphoto') {
577
+                    return ['this is a photo'];
578
+                }
579
+                return null;
580
+            });
581
+
582
+        $this->image->expects($this->once())
583
+            ->method('loadFromBase64')
584
+            ->willReturn('imageResource');
585
+        $this->image->expects($this->once())
586
+            ->method('valid')
587
+            ->willReturn(true);
588
+        $this->image->expects($this->once())
589
+            ->method('width')
590
+            ->willReturn(128);
591
+        $this->image->expects($this->once())
592
+            ->method('height')
593
+            ->willReturn(128);
594
+        $this->image->expects($this->once())
595
+            ->method('centerCrop')
596
+            ->willReturn(true);
597
+        $this->image->expects($this->once())
598
+            ->method('data')
599
+            ->willReturn('this is a photo');
600
+
601
+        $this->config->expects($this->once())
602
+            ->method('getUserValue')
603
+            ->with($this->uid, 'user_ldap', 'lastAvatarChecksum', '')
604
+            ->willReturn('');
605
+        $this->config->expects($this->once())
606
+            ->method('setUserValue')
607
+            ->with($this->uid, 'user_ldap', 'lastAvatarChecksum', md5('this is a photo'));
608
+
609
+        $avatar = $this->createMock(IAvatar::class);
610
+        $avatar->expects($this->once())
611
+            ->method('set')
612
+            ->with($this->image);
613
+
614
+        $this->avatarManager->expects($this->once())
615
+            ->method('getAvatar')
616
+            ->with($this->equalTo($this->uid))
617
+            ->willReturn($avatar);
618
+
619
+        $this->connection->expects($this->any())
620
+            ->method('resolveRule')
621
+            ->with('avatar')
622
+            ->willReturn(['jpegphoto', 'thumbnailphoto']);
623
+
624
+        $this->user->updateAvatar();
625
+    }
626
+
627
+    public function testUpdateAvatarCorruptPhotoProvided(): void {
628
+        $this->access->expects($this->any())
629
+            ->method('readAttribute')
630
+            ->willReturnCallback(function ($dn, $attr) {
631
+                if ($dn === $this->dn
632
+                    && $attr === 'jpegphoto') {
633
+                    return false;
634
+                } elseif ($dn === $this->dn
635
+                    && $attr === 'thumbnailphoto') {
636
+                    return ['this is a photo'];
637
+                }
638
+                return null;
639
+            });
640
+
641
+        $this->image->expects($this->once())
642
+            ->method('loadFromBase64')
643
+            ->willReturn(false);
644
+        $this->image->expects($this->never())
645
+            ->method('valid');
646
+        $this->image->expects($this->never())
647
+            ->method('width');
648
+        $this->image->expects($this->never())
649
+            ->method('height');
650
+        $this->image->expects($this->never())
651
+            ->method('centerCrop');
652
+        $this->image->expects($this->never())
653
+            ->method('data');
654
+
655
+        $this->config->expects($this->never())
656
+            ->method('getUserValue');
657
+        $this->config->expects($this->never())
658
+            ->method('setUserValue');
659
+
660
+        $avatar = $this->createMock(IAvatar::class);
661
+        $avatar->expects($this->never())
662
+            ->method('set');
663
+
664
+        $this->avatarManager->expects($this->never())
665
+            ->method('getAvatar');
666
+
667
+        $this->connection->expects($this->any())
668
+            ->method('resolveRule')
669
+            ->with('avatar')
670
+            ->willReturn(['jpegphoto', 'thumbnailphoto']);
671
+
672
+        $this->user->updateAvatar();
673
+    }
674
+
675
+    public function XtestUpdateAvatarUnsupportedThumbnailPhotoProvided() {
676
+        $this->access->expects($this->any())
677
+            ->method('readAttribute')
678
+            ->willReturnCallback(function ($dn, $attr) {
679
+                if ($dn === $this->dn
680
+                    && $attr === 'jpegphoto') {
681
+                    return false;
682
+                } elseif ($dn === $this->dn
683
+                    && $attr === 'thumbnailphoto') {
684
+                    return ['this is a photo'];
685
+                }
686
+                return null;
687
+            });
688
+
689
+        $this->image->expects($this->once())
690
+            ->method('loadFromBase64')
691
+            ->willReturn('imageResource');
692
+        $this->image->expects($this->once())
693
+            ->method('valid')
694
+            ->willReturn(true);
695
+        $this->image->expects($this->once())
696
+            ->method('width')
697
+            ->willReturn(128);
698
+        $this->image->expects($this->once())
699
+            ->method('height')
700
+            ->willReturn(128);
701
+        $this->image->expects($this->once())
702
+            ->method('centerCrop')
703
+            ->willReturn(true);
704
+        $this->image->expects($this->once())
705
+            ->method('data')
706
+            ->willReturn('this is a photo');
707
+
708
+        $this->config->expects($this->once())
709
+            ->method('getUserValue')
710
+            ->with($this->uid, 'user_ldap', 'lastAvatarChecksum', '')
711
+            ->willReturn('');
712
+        $this->config->expects($this->never())
713
+            ->method('setUserValue');
714
+
715
+        $avatar = $this->createMock(IAvatar::class);
716
+        $avatar->expects($this->once())
717
+            ->method('set')
718
+            ->with($this->image)
719
+            ->willThrowException(new \Exception());
720
+
721
+        $this->avatarManager->expects($this->once())
722
+            ->method('getAvatar')
723
+            ->with($this->equalTo($this->uid))
724
+            ->willReturn($avatar);
725
+
726
+        $this->connection->expects($this->any())
727
+            ->method('resolveRule')
728
+            ->with('avatar')
729
+            ->willReturn(['jpegphoto', 'thumbnailphoto']);
730
+
731
+        $this->assertFalse($this->user->updateAvatar());
732
+    }
733
+
734
+    public function testUpdateAvatarNotProvided(): void {
735
+        $this->access->expects($this->any())
736
+            ->method('readAttribute')
737
+            ->willReturnCallback(function ($dn, $attr) {
738
+                if ($dn === $this->dn
739
+                    && $attr === 'jpegPhoto') {
740
+                    return false;
741
+                } elseif ($dn === $this->dn
742
+                    && $attr === 'thumbnailPhoto') {
743
+                    return false;
744
+                }
745
+                return null;
746
+            });
747
+
748
+        $this->image->expects($this->never())
749
+            ->method('valid');
750
+        $this->image->expects($this->never())
751
+            ->method('width');
752
+        $this->image->expects($this->never())
753
+            ->method('height');
754
+        $this->image->expects($this->never())
755
+            ->method('centerCrop');
756
+        $this->image->expects($this->never())
757
+            ->method('data');
758
+
759
+        $this->config->expects($this->never())
760
+            ->method('getUserValue');
761
+        $this->config->expects($this->never())
762
+            ->method('setUserValue');
763
+
764
+        $this->avatarManager->expects($this->never())
765
+            ->method('getAvatar');
766
+
767
+        $this->connection->expects($this->any())
768
+            ->method('resolveRule')
769
+            ->with('avatar')
770
+            ->willReturn(['jpegphoto', 'thumbnailphoto']);
771
+
772
+        $this->user->updateAvatar();
773
+    }
774
+
775
+    public static function extStorageHomeDataProvider(): array {
776
+        return [
777
+            [ 'myFolder', null ],
778
+            [ '', null, false ],
779
+            [ 'myFolder', 'myFolder' ],
780
+        ];
781
+    }
782
+
783
+    /**
784
+     * @dataProvider extStorageHomeDataProvider
785
+     */
786
+    public function testUpdateExtStorageHome(string $expected, ?string $valueFromLDAP = null, bool $isSet = true): void {
787
+        if ($valueFromLDAP === null) {
788
+            $this->connection->expects($this->once())
789
+                ->method('__get')
790
+                ->willReturnMap([
791
+                    ['ldapExtStorageHomeAttribute', 'homeDirectory'],
792
+                ]);
793
+
794
+            $return = [];
795
+            if ($isSet) {
796
+                $return[] = $expected;
797
+            }
798
+            $this->access->expects($this->once())
799
+                ->method('readAttribute')
800
+                ->with($this->dn, 'homeDirectory')
801
+                ->willReturn($return);
802
+        }
803
+
804
+        if ($expected !== '') {
805
+            $this->config->expects($this->once())
806
+                ->method('setUserValue')
807
+                ->with($this->uid, 'user_ldap', 'extStorageHome', $expected);
808
+        } else {
809
+            $this->config->expects($this->once())
810
+                ->method('deleteUserValue')
811
+                ->with($this->uid, 'user_ldap', 'extStorageHome');
812
+        }
813
+
814
+        $actual = $this->user->updateExtStorageHome($valueFromLDAP);
815
+        $this->assertSame($expected, $actual);
816
+    }
817
+
818
+    public function testMarkLogin(): void {
819
+        $this->config->expects($this->once())
820
+            ->method('setUserValue')
821
+            ->with($this->equalTo($this->uid),
822
+                $this->equalTo('user_ldap'),
823
+                $this->equalTo(User::USER_PREFKEY_FIRSTLOGIN),
824
+                $this->equalTo(1))
825
+            ->willReturn(true);
826
+
827
+        $this->user->markLogin();
828
+    }
829
+
830
+    public function testGetAvatarImageProvided(): void {
831
+        $this->access->expects($this->once())
832
+            ->method('readAttribute')
833
+            ->with($this->equalTo($this->dn),
834
+                $this->equalTo('jpegphoto'))
835
+            ->willReturn(['this is a photo']);
836
+        $this->connection->expects($this->any())
837
+            ->method('resolveRule')
838
+            ->with('avatar')
839
+            ->willReturn(['jpegphoto', 'thumbnailphoto']);
840
+
841
+        $photo = $this->user->getAvatarImage();
842
+        $this->assertSame('this is a photo', $photo);
843
+        //make sure readAttribute is not called again but the already fetched
844
+        //photo is returned
845
+        $this->user->getAvatarImage();
846
+    }
847
+
848
+    public function testGetAvatarImageDisabled(): void {
849
+        $this->access->expects($this->never())
850
+            ->method('readAttribute')
851
+            ->with($this->equalTo($this->dn), $this->anything());
852
+        $this->connection->expects($this->any())
853
+            ->method('resolveRule')
854
+            ->with('avatar')
855
+            ->willReturn([]);
856
+
857
+        $this->assertFalse($this->user->getAvatarImage());
858
+    }
859
+
860
+    public static function imageDataProvider(): array {
861
+        return [
862
+            [ false, false ],
863
+            [ 'corruptData', false ],
864
+            [ 'validData', true ],
865
+        ];
866
+    }
867
+
868
+    public function testProcessAttributes(): void {
869
+        $requiredMethods = [
870
+            'updateQuota',
871
+            'updateEmail',
872
+            'composeAndStoreDisplayName',
873
+            'storeLDAPUserName',
874
+            'getHomePath',
875
+            'updateAvatar',
876
+            'updateExtStorageHome',
877
+        ];
878
+
879
+        /** @var User&MockObject $userMock */
880
+        $userMock = $this->getMockBuilder(User::class)
881
+            ->setConstructorArgs([
882
+                $this->uid,
883
+                $this->dn,
884
+                $this->access,
885
+                $this->config,
886
+                $this->image,
887
+                $this->logger,
888
+                $this->avatarManager,
889
+                $this->userManager,
890
+                $this->notificationManager
891
+            ])
892
+            ->onlyMethods($requiredMethods)
893
+            ->getMock();
894
+
895
+        $this->connection->setConfiguration([
896
+            'homeFolderNamingRule' => 'homeDirectory'
897
+        ]);
898
+        $this->connection->expects($this->any())
899
+            ->method('__get')
900
+            ->willReturnCallback(function ($name) {
901
+                if ($name === 'homeFolderNamingRule') {
902
+                    return 'attr:homeDirectory';
903
+                }
904
+                return $name;
905
+            });
906
+        $this->connection->expects($this->any())
907
+            ->method('resolveRule')
908
+            ->with('avatar')
909
+            ->willReturn(['jpegphoto', 'thumbnailphoto']);
910
+
911
+        $record = [
912
+            strtolower($this->connection->ldapQuotaAttribute) => ['4096'],
913
+            strtolower($this->connection->ldapEmailAttribute) => ['[email protected]'],
914
+            strtolower($this->connection->ldapUserDisplayName) => ['Aaaaalice'],
915
+            strtolower($this->connection->ldapExtStorageHomeAttribute) => ['homeDirectory'],
916
+            'uid' => [$this->uid],
917
+            'homedirectory' => ['Alice\'s Folder'],
918
+            'memberof' => ['cn=groupOne', 'cn=groupTwo'],
919
+            'jpegphoto' => ['here be an image']
920
+        ];
921
+
922
+        foreach ($requiredMethods as $method) {
923
+            $userMock->expects($this->once())
924
+                ->method($method);
925
+        }
926
+        \OC_Hook::clear();//disconnect irrelevant hooks
927
+        $userMock->processAttributes($record);
928
+        /** @noinspection PhpUnhandledExceptionInspection */
929
+        \OC_Hook::emit('OC_User', 'post_login', ['uid' => $this->uid]);
930
+    }
931
+
932
+    public static function emptyHomeFolderAttributeValueProvider(): array {
933
+        return [
934
+            'empty' => [''],
935
+            'prefixOnly' => ['attr:'],
936
+        ];
937
+    }
938
+
939
+    /**
940
+     * @dataProvider emptyHomeFolderAttributeValueProvider
941
+     */
942
+    public function testGetHomePathNotConfigured(string $attributeValue): void {
943
+        $this->connection->expects($this->any())
944
+            ->method('__get')
945
+            ->with($this->equalTo('homeFolderNamingRule'))
946
+            ->willReturn($attributeValue);
947
+
948
+        $this->access->expects($this->never())
949
+            ->method('readAttribute');
950
+
951
+        $this->config->expects($this->never())
952
+            ->method('getAppValue');
953
+
954
+        /** @noinspection PhpUnhandledExceptionInspection */
955
+        $this->assertFalse($this->user->getHomePath());
956
+    }
957
+
958
+    public function testGetHomePathConfiguredNotAvailableAllowed(): void {
959
+        $this->connection->expects($this->any())
960
+            ->method('__get')
961
+            ->with($this->equalTo('homeFolderNamingRule'))
962
+            ->willReturn('attr:foobar');
963
+
964
+        $this->access->expects($this->once())
965
+            ->method('readAttribute')
966
+            ->willReturn(false);
967
+
968
+        $this->access->expects($this->once())
969
+            ->method('username2dn')
970
+            ->willReturn($this->dn);
971
+
972
+        // asks for "enforce_home_folder_naming_rule"
973
+        $this->config->expects($this->once())
974
+            ->method('getAppValue')
975
+            ->willReturn(false);
976
+
977
+        /** @noinspection PhpUnhandledExceptionInspection */
978
+        $this->assertFalse($this->user->getHomePath());
979
+    }
980
+
981
+
982
+    public function testGetHomePathConfiguredNotAvailableNotAllowed(): void {
983
+        $this->expectException(\Exception::class);
984
+
985
+        $this->connection->expects($this->any())
986
+            ->method('__get')
987
+            ->with($this->equalTo('homeFolderNamingRule'))
988
+            ->willReturn('attr:foobar');
989
+
990
+        $this->access->expects($this->once())
991
+            ->method('readAttribute')
992
+            ->willReturn(false);
993
+
994
+        $this->access->expects($this->once())
995
+            ->method('username2dn')
996
+            ->willReturn($this->dn);
997
+
998
+        // asks for "enforce_home_folder_naming_rule"
999
+        $this->config->expects($this->once())
1000
+            ->method('getAppValue')
1001
+            ->willReturn(true);
1002
+
1003
+        $this->user->getHomePath();
1004
+    }
1005
+
1006
+    public static function displayNameProvider(): array {
1007
+        return [
1008
+            ['Roland Deschain', '', 'Roland Deschain', false],
1009
+            ['Roland Deschain', '', 'Roland Deschain', true],
1010
+            ['Roland Deschain', '[email protected]', 'Roland Deschain ([email protected])', false],
1011
+            ['Roland Deschain', '[email protected]', 'Roland Deschain ([email protected])', true],
1012
+        ];
1013
+    }
1014
+
1015
+    /**
1016
+     * @dataProvider displayNameProvider
1017
+     */
1018
+    public function testComposeAndStoreDisplayName(string $part1, string $part2, string $expected, bool $expectTriggerChange): void {
1019
+        $this->config->expects($this->once())
1020
+            ->method('setUserValue');
1021
+        $oldName = $expectTriggerChange ? 'xxGunslingerxx' : null;
1022
+        $this->config->expects($this->once())
1023
+            ->method('getUserValue')
1024
+            ->with($this->user->getUsername(), 'user_ldap', 'displayName', null)
1025
+            ->willReturn($oldName);
1026
+
1027
+        $ncUserObj = $this->createMock(\OC\User\User::class);
1028
+        if ($expectTriggerChange) {
1029
+            $ncUserObj->expects($this->once())
1030
+                ->method('triggerChange')
1031
+                ->with('displayName', $expected);
1032
+        } else {
1033
+            $ncUserObj->expects($this->never())
1034
+                ->method('triggerChange');
1035
+        }
1036
+        $this->userManager->expects($this->once())
1037
+            ->method('get')
1038
+            ->willReturn($ncUserObj);
1039
+
1040
+        $displayName = $this->user->composeAndStoreDisplayName($part1, $part2);
1041
+        $this->assertSame($expected, $displayName);
1042
+    }
1043
+
1044
+    public function testComposeAndStoreDisplayNameNoOverwrite(): void {
1045
+        $displayName = 'Randall Flagg';
1046
+        $this->config->expects($this->never())
1047
+            ->method('setUserValue');
1048
+        $this->config->expects($this->once())
1049
+            ->method('getUserValue')
1050
+            ->willReturn($displayName);
1051
+
1052
+        $this->userManager->expects($this->never())
1053
+            ->method('get'); // Implicit: no triggerChange can be called
1054
+
1055
+        $composedDisplayName = $this->user->composeAndStoreDisplayName($displayName);
1056
+        $this->assertSame($composedDisplayName, $displayName);
1057
+    }
1058
+
1059
+    public function testHandlePasswordExpiryWarningDefaultPolicy(): void {
1060
+        $this->connection->expects($this->any())
1061
+            ->method('__get')
1062
+            ->willReturnCallback(function ($name) {
1063
+                if ($name === 'ldapDefaultPPolicyDN') {
1064
+                    return 'cn=default,ou=policies,dc=foo,dc=bar';
1065
+                }
1066
+                if ($name === 'turnOnPasswordChange') {
1067
+                    return '1';
1068
+                }
1069
+                return $name;
1070
+            });
1071
+
1072
+        $this->access->expects($this->any())
1073
+            ->method('search')
1074
+            ->willReturnCallback(function ($filter, $base) {
1075
+                if ($base === $this->dn) {
1076
+                    return [
1077
+                        [
1078
+                            'pwdchangedtime' => [(new \DateTime())->sub(new \DateInterval('P28D'))->format('Ymdhis') . 'Z'],
1079
+                            'pwdgraceusetime' => [],
1080
+                        ],
1081
+                    ];
1082
+                }
1083
+                if ($base === 'cn=default,ou=policies,dc=foo,dc=bar') {
1084
+                    return [
1085
+                        [
1086
+                            'pwdmaxage' => ['2592000'],
1087
+                            'pwdexpirewarning' => ['2591999'],
1088
+                        ],
1089
+                    ];
1090
+                }
1091
+                return [];
1092
+            });
1093
+
1094
+        $notification = $this->getMockBuilder(INotification::class)
1095
+            ->disableOriginalConstructor()
1096
+            ->getMock();
1097
+        $notification->expects($this->any())
1098
+            ->method('setApp')
1099
+            ->willReturn($notification);
1100
+        $notification->expects($this->any())
1101
+            ->method('setUser')
1102
+            ->willReturn($notification);
1103
+        $notification->expects($this->any())
1104
+            ->method('setObject')
1105
+            ->willReturn($notification);
1106
+        $notification->expects($this->any())
1107
+            ->method('setDateTime')
1108
+            ->willReturn($notification);
1109
+
1110
+        $this->notificationManager->expects($this->exactly(2))
1111
+            ->method('createNotification')
1112
+            ->willReturn($notification);
1113
+        $this->notificationManager->expects($this->exactly(1))
1114
+            ->method('notify');
1115
+
1116
+        \OC_Hook::clear();//disconnect irrelevant hooks
1117
+        Util::connectHook('OC_User', 'post_login', $this->user, 'handlePasswordExpiry');
1118
+        /** @noinspection PhpUnhandledExceptionInspection */
1119
+        \OC_Hook::emit('OC_User', 'post_login', ['uid' => $this->uid]);
1120
+    }
1121
+
1122
+    public function testHandlePasswordExpiryWarningCustomPolicy(): void {
1123
+        $this->connection->expects($this->any())
1124
+            ->method('__get')
1125
+            ->willReturnCallback(function ($name) {
1126
+                if ($name === 'ldapDefaultPPolicyDN') {
1127
+                    return 'cn=default,ou=policies,dc=foo,dc=bar';
1128
+                }
1129
+                if ($name === 'turnOnPasswordChange') {
1130
+                    return '1';
1131
+                }
1132
+                return $name;
1133
+            });
1134
+
1135
+        $this->access->expects($this->any())
1136
+            ->method('search')
1137
+            ->willReturnCallback(function ($filter, $base) {
1138
+                if ($base === $this->dn) {
1139
+                    return [
1140
+                        [
1141
+                            'pwdpolicysubentry' => ['cn=custom,ou=policies,dc=foo,dc=bar'],
1142
+                            'pwdchangedtime' => [(new \DateTime())->sub(new \DateInterval('P28D'))->format('Ymdhis') . 'Z'],
1143
+                            'pwdgraceusetime' => [],
1144
+                        ]
1145
+                    ];
1146
+                }
1147
+                if ($base === 'cn=custom,ou=policies,dc=foo,dc=bar') {
1148
+                    return [
1149
+                        [
1150
+                            'pwdmaxage' => ['2592000'],
1151
+                            'pwdexpirewarning' => ['2591999'],
1152
+                        ]
1153
+                    ];
1154
+                }
1155
+                return [];
1156
+            });
1157
+
1158
+        $notification = $this->getMockBuilder(INotification::class)
1159
+            ->disableOriginalConstructor()
1160
+            ->getMock();
1161
+        $notification->expects($this->any())
1162
+            ->method('setApp')
1163
+            ->willReturn($notification);
1164
+        $notification->expects($this->any())
1165
+            ->method('setUser')
1166
+            ->willReturn($notification);
1167
+        $notification->expects($this->any())
1168
+            ->method('setObject')
1169
+            ->willReturn($notification);
1170
+        $notification->expects($this->any())
1171
+            ->method('setDateTime')
1172
+            ->willReturn($notification);
1173
+
1174
+        $this->notificationManager->expects($this->exactly(2))
1175
+            ->method('createNotification')
1176
+            ->willReturn($notification);
1177
+        $this->notificationManager->expects($this->exactly(1))
1178
+            ->method('notify');
1179
+
1180
+        \OC_Hook::clear();//disconnect irrelevant hooks
1181
+        Util::connectHook('OC_User', 'post_login', $this->user, 'handlePasswordExpiry');
1182
+        /** @noinspection PhpUnhandledExceptionInspection */
1183
+        \OC_Hook::emit('OC_User', 'post_login', ['uid' => $this->uid]);
1184
+    }
1185 1185
 }
Please login to merge, or discard this patch.
Spacing   +20 added lines, -20 removed lines patch added patch discarded remove patch
@@ -568,7 +568,7 @@  discard block
 block discarded – undo
568 568
 	public function XtestUpdateAvatarThumbnailPhotoProvided() {
569 569
 		$this->access->expects($this->any())
570 570
 			->method('readAttribute')
571
-			->willReturnCallback(function ($dn, $attr) {
571
+			->willReturnCallback(function($dn, $attr) {
572 572
 				if ($dn === $this->dn
573 573
 					&& $attr === 'jpegphoto') {
574 574
 					return false;
@@ -627,7 +627,7 @@  discard block
 block discarded – undo
627 627
 	public function testUpdateAvatarCorruptPhotoProvided(): void {
628 628
 		$this->access->expects($this->any())
629 629
 			->method('readAttribute')
630
-			->willReturnCallback(function ($dn, $attr) {
630
+			->willReturnCallback(function($dn, $attr) {
631 631
 				if ($dn === $this->dn
632 632
 					&& $attr === 'jpegphoto') {
633 633
 					return false;
@@ -675,7 +675,7 @@  discard block
 block discarded – undo
675 675
 	public function XtestUpdateAvatarUnsupportedThumbnailPhotoProvided() {
676 676
 		$this->access->expects($this->any())
677 677
 			->method('readAttribute')
678
-			->willReturnCallback(function ($dn, $attr) {
678
+			->willReturnCallback(function($dn, $attr) {
679 679
 				if ($dn === $this->dn
680 680
 					&& $attr === 'jpegphoto') {
681 681
 					return false;
@@ -734,7 +734,7 @@  discard block
 block discarded – undo
734 734
 	public function testUpdateAvatarNotProvided(): void {
735 735
 		$this->access->expects($this->any())
736 736
 			->method('readAttribute')
737
-			->willReturnCallback(function ($dn, $attr) {
737
+			->willReturnCallback(function($dn, $attr) {
738 738
 				if ($dn === $this->dn
739 739
 					&& $attr === 'jpegPhoto') {
740 740
 					return false;
@@ -774,9 +774,9 @@  discard block
 block discarded – undo
774 774
 
775 775
 	public static function extStorageHomeDataProvider(): array {
776 776
 		return [
777
-			[ 'myFolder', null ],
778
-			[ '', null, false ],
779
-			[ 'myFolder', 'myFolder' ],
777
+			['myFolder', null],
778
+			['', null, false],
779
+			['myFolder', 'myFolder'],
780 780
 		];
781 781
 	}
782 782
 
@@ -859,9 +859,9 @@  discard block
 block discarded – undo
859 859
 
860 860
 	public static function imageDataProvider(): array {
861 861
 		return [
862
-			[ false, false ],
863
-			[ 'corruptData', false ],
864
-			[ 'validData', true ],
862
+			[false, false],
863
+			['corruptData', false],
864
+			['validData', true],
865 865
 		];
866 866
 	}
867 867
 
@@ -897,7 +897,7 @@  discard block
 block discarded – undo
897 897
 		]);
898 898
 		$this->connection->expects($this->any())
899 899
 			->method('__get')
900
-			->willReturnCallback(function ($name) {
900
+			->willReturnCallback(function($name) {
901 901
 				if ($name === 'homeFolderNamingRule') {
902 902
 					return 'attr:homeDirectory';
903 903
 				}
@@ -923,7 +923,7 @@  discard block
 block discarded – undo
923 923
 			$userMock->expects($this->once())
924 924
 				->method($method);
925 925
 		}
926
-		\OC_Hook::clear();//disconnect irrelevant hooks
926
+		\OC_Hook::clear(); //disconnect irrelevant hooks
927 927
 		$userMock->processAttributes($record);
928 928
 		/** @noinspection PhpUnhandledExceptionInspection */
929 929
 		\OC_Hook::emit('OC_User', 'post_login', ['uid' => $this->uid]);
@@ -1059,7 +1059,7 @@  discard block
 block discarded – undo
1059 1059
 	public function testHandlePasswordExpiryWarningDefaultPolicy(): void {
1060 1060
 		$this->connection->expects($this->any())
1061 1061
 			->method('__get')
1062
-			->willReturnCallback(function ($name) {
1062
+			->willReturnCallback(function($name) {
1063 1063
 				if ($name === 'ldapDefaultPPolicyDN') {
1064 1064
 					return 'cn=default,ou=policies,dc=foo,dc=bar';
1065 1065
 				}
@@ -1071,11 +1071,11 @@  discard block
 block discarded – undo
1071 1071
 
1072 1072
 		$this->access->expects($this->any())
1073 1073
 			->method('search')
1074
-			->willReturnCallback(function ($filter, $base) {
1074
+			->willReturnCallback(function($filter, $base) {
1075 1075
 				if ($base === $this->dn) {
1076 1076
 					return [
1077 1077
 						[
1078
-							'pwdchangedtime' => [(new \DateTime())->sub(new \DateInterval('P28D'))->format('Ymdhis') . 'Z'],
1078
+							'pwdchangedtime' => [(new \DateTime())->sub(new \DateInterval('P28D'))->format('Ymdhis').'Z'],
1079 1079
 							'pwdgraceusetime' => [],
1080 1080
 						],
1081 1081
 					];
@@ -1113,7 +1113,7 @@  discard block
 block discarded – undo
1113 1113
 		$this->notificationManager->expects($this->exactly(1))
1114 1114
 			->method('notify');
1115 1115
 
1116
-		\OC_Hook::clear();//disconnect irrelevant hooks
1116
+		\OC_Hook::clear(); //disconnect irrelevant hooks
1117 1117
 		Util::connectHook('OC_User', 'post_login', $this->user, 'handlePasswordExpiry');
1118 1118
 		/** @noinspection PhpUnhandledExceptionInspection */
1119 1119
 		\OC_Hook::emit('OC_User', 'post_login', ['uid' => $this->uid]);
@@ -1122,7 +1122,7 @@  discard block
 block discarded – undo
1122 1122
 	public function testHandlePasswordExpiryWarningCustomPolicy(): void {
1123 1123
 		$this->connection->expects($this->any())
1124 1124
 			->method('__get')
1125
-			->willReturnCallback(function ($name) {
1125
+			->willReturnCallback(function($name) {
1126 1126
 				if ($name === 'ldapDefaultPPolicyDN') {
1127 1127
 					return 'cn=default,ou=policies,dc=foo,dc=bar';
1128 1128
 				}
@@ -1134,12 +1134,12 @@  discard block
 block discarded – undo
1134 1134
 
1135 1135
 		$this->access->expects($this->any())
1136 1136
 			->method('search')
1137
-			->willReturnCallback(function ($filter, $base) {
1137
+			->willReturnCallback(function($filter, $base) {
1138 1138
 				if ($base === $this->dn) {
1139 1139
 					return [
1140 1140
 						[
1141 1141
 							'pwdpolicysubentry' => ['cn=custom,ou=policies,dc=foo,dc=bar'],
1142
-							'pwdchangedtime' => [(new \DateTime())->sub(new \DateInterval('P28D'))->format('Ymdhis') . 'Z'],
1142
+							'pwdchangedtime' => [(new \DateTime())->sub(new \DateInterval('P28D'))->format('Ymdhis').'Z'],
1143 1143
 							'pwdgraceusetime' => [],
1144 1144
 						]
1145 1145
 					];
@@ -1177,7 +1177,7 @@  discard block
 block discarded – undo
1177 1177
 		$this->notificationManager->expects($this->exactly(1))
1178 1178
 			->method('notify');
1179 1179
 
1180
-		\OC_Hook::clear();//disconnect irrelevant hooks
1180
+		\OC_Hook::clear(); //disconnect irrelevant hooks
1181 1181
 		Util::connectHook('OC_User', 'post_login', $this->user, 'handlePasswordExpiry');
1182 1182
 		/** @noinspection PhpUnhandledExceptionInspection */
1183 1183
 		\OC_Hook::emit('OC_User', 'post_login', ['uid' => $this->uid]);
Please login to merge, or discard this patch.
apps/user_ldap/tests/User/OfflineUserTest.php 1 patch
Indentation   +41 added lines, -41 removed lines patch added patch discarded remove patch
@@ -17,51 +17,51 @@
 block discarded – undo
17 17
 use Test\TestCase;
18 18
 
19 19
 class OfflineUserTest extends TestCase {
20
-	protected UserMapping&MockObject $mapping;
21
-	protected string $uid;
22
-	protected IConfig&MockObject $config;
23
-	protected IManager&MockObject $shareManager;
24
-	protected OfflineUser $offlineUser;
20
+    protected UserMapping&MockObject $mapping;
21
+    protected string $uid;
22
+    protected IConfig&MockObject $config;
23
+    protected IManager&MockObject $shareManager;
24
+    protected OfflineUser $offlineUser;
25 25
 
26
-	public function setUp(): void {
27
-		$this->uid = 'deborah';
28
-		$this->config = $this->createMock(IConfig::class);
29
-		$this->mapping = $this->createMock(UserMapping::class);
30
-		$this->shareManager = $this->createMock(IManager::class);
26
+    public function setUp(): void {
27
+        $this->uid = 'deborah';
28
+        $this->config = $this->createMock(IConfig::class);
29
+        $this->mapping = $this->createMock(UserMapping::class);
30
+        $this->shareManager = $this->createMock(IManager::class);
31 31
 
32
-		$this->offlineUser = new OfflineUser(
33
-			$this->uid,
34
-			$this->config,
35
-			$this->mapping,
36
-			$this->shareManager
37
-		);
38
-	}
32
+        $this->offlineUser = new OfflineUser(
33
+            $this->uid,
34
+            $this->config,
35
+            $this->mapping,
36
+            $this->shareManager
37
+        );
38
+    }
39 39
 
40
-	public static function shareOwnerProvider(): array {
41
-		return [
42
-			[[], false],
43
-			[[IShare::TYPE_USER], true],
44
-			[[IShare::TYPE_GROUP, IShare::TYPE_LINK], true],
45
-			[[IShare::TYPE_EMAIL, IShare::TYPE_REMOTE, IShare::TYPE_CIRCLE], true],
46
-			[[IShare::TYPE_GUEST, IShare::TYPE_REMOTE_GROUP, IShare::TYPE_ROOM], true],
47
-		];
48
-	}
40
+    public static function shareOwnerProvider(): array {
41
+        return [
42
+            [[], false],
43
+            [[IShare::TYPE_USER], true],
44
+            [[IShare::TYPE_GROUP, IShare::TYPE_LINK], true],
45
+            [[IShare::TYPE_EMAIL, IShare::TYPE_REMOTE, IShare::TYPE_CIRCLE], true],
46
+            [[IShare::TYPE_GUEST, IShare::TYPE_REMOTE_GROUP, IShare::TYPE_ROOM], true],
47
+        ];
48
+    }
49 49
 
50
-	/**
51
-	 * @dataProvider shareOwnerProvider
52
-	 */
53
-	public function testHasActiveShares(array $existingShareTypes, bool $expected): void {
54
-		$shareMock = $this->createMock(IShare::class);
50
+    /**
51
+     * @dataProvider shareOwnerProvider
52
+     */
53
+    public function testHasActiveShares(array $existingShareTypes, bool $expected): void {
54
+        $shareMock = $this->createMock(IShare::class);
55 55
 
56
-		$this->shareManager->expects($this->atLeastOnce())
57
-			->method('getSharesBy')
58
-			->willReturnCallback(function (string $uid, int $shareType) use ($existingShareTypes, $shareMock) {
59
-				if (in_array($shareType, $existingShareTypes)) {
60
-					return [$shareMock];
61
-				}
62
-				return [];
63
-			});
56
+        $this->shareManager->expects($this->atLeastOnce())
57
+            ->method('getSharesBy')
58
+            ->willReturnCallback(function (string $uid, int $shareType) use ($existingShareTypes, $shareMock) {
59
+                if (in_array($shareType, $existingShareTypes)) {
60
+                    return [$shareMock];
61
+                }
62
+                return [];
63
+            });
64 64
 
65
-		$this->assertSame($expected, $this->offlineUser->getHasActiveShares());
66
-	}
65
+        $this->assertSame($expected, $this->offlineUser->getHasActiveShares());
66
+    }
67 67
 }
Please login to merge, or discard this patch.
apps/user_ldap/tests/User/ManagerTest.php 1 patch
Indentation   +175 added lines, -175 removed lines patch added patch discarded remove patch
@@ -31,179 +31,179 @@
 block discarded – undo
31 31
  * @package OCA\User_LDAP\Tests\User
32 32
  */
33 33
 class ManagerTest extends \Test\TestCase {
34
-	protected Access&MockObject $access;
35
-	protected IConfig&MockObject $config;
36
-	protected LoggerInterface&MockObject $logger;
37
-	protected IAvatarManager&MockObject $avatarManager;
38
-	protected Image&MockObject $image;
39
-	protected IDBConnection&MockObject $dbc;
40
-	protected IUserManager&MockObject $ncUserManager;
41
-	protected INotificationManager&MockObject $notificationManager;
42
-	protected ILDAPWrapper&MockObject $ldapWrapper;
43
-	protected Connection $connection;
44
-	protected IManager&MockObject $shareManager;
45
-	protected Manager $manager;
46
-
47
-	protected function setUp(): void {
48
-		parent::setUp();
49
-
50
-		$this->access = $this->createMock(Access::class);
51
-		$this->config = $this->createMock(IConfig::class);
52
-		$this->logger = $this->createMock(LoggerInterface::class);
53
-		$this->avatarManager = $this->createMock(IAvatarManager::class);
54
-		$this->image = $this->createMock(Image::class);
55
-		$this->ncUserManager = $this->createMock(IUserManager::class);
56
-		$this->notificationManager = $this->createMock(INotificationManager::class);
57
-		$this->ldapWrapper = $this->createMock(ILDAPWrapper::class);
58
-		$this->shareManager = $this->createMock(IManager::class);
59
-
60
-		$this->connection = new Connection($this->ldapWrapper, '', null);
61
-
62
-		$this->access->expects($this->any())
63
-			->method('getConnection')
64
-			->willReturn($this->connection);
65
-
66
-		/** @noinspection PhpUnhandledExceptionInspection */
67
-		$this->manager = new Manager(
68
-			$this->config,
69
-			$this->logger,
70
-			$this->avatarManager,
71
-			$this->image,
72
-			$this->ncUserManager,
73
-			$this->notificationManager,
74
-			$this->shareManager
75
-		);
76
-
77
-		$this->manager->setLdapAccess($this->access);
78
-	}
79
-
80
-	public static function dnProvider(): array {
81
-		return [
82
-			['cn=foo,dc=foobar,dc=bar'],
83
-			['uid=foo,o=foobar,c=bar'],
84
-			['ab=cde,f=ghei,mno=pq'],
85
-		];
86
-	}
87
-
88
-	/**
89
-	 * @dataProvider dnProvider
90
-	 */
91
-	public function testGetByDNExisting(string $inputDN): void {
92
-		$uid = '563418fc-423b-1033-8d1c-ad5f418ee02e';
93
-
94
-		$this->access->expects($this->once())
95
-			->method('stringResemblesDN')
96
-			->with($this->equalTo($inputDN))
97
-			->willReturn(true);
98
-		$this->access->expects($this->once())
99
-			->method('dn2username')
100
-			->with($this->equalTo($inputDN))
101
-			->willReturn($uid);
102
-		$this->access->expects($this->never())
103
-			->method('username2dn');
104
-
105
-		/** @noinspection PhpUnhandledExceptionInspection */
106
-		$this->manager->get($inputDN);
107
-
108
-		// Now we fetch the user again. If this leads to a failing test,
109
-		// runtime caching the manager is broken.
110
-		/** @noinspection PhpUnhandledExceptionInspection */
111
-		$user = $this->manager->get($inputDN);
112
-
113
-		$this->assertInstanceOf(User::class, $user);
114
-	}
115
-
116
-	public function testGetByDNNotExisting(): void {
117
-		$inputDN = 'cn=gone,dc=foobar,dc=bar';
118
-
119
-		$this->access->expects($this->once())
120
-			->method('stringResemblesDN')
121
-			->with($this->equalTo($inputDN))
122
-			->willReturn(true);
123
-		$this->access->expects($this->once())
124
-			->method('dn2username')
125
-			->with($this->equalTo($inputDN))
126
-			->willReturn(false);
127
-		$this->access->expects($this->once())
128
-			->method('username2dn')
129
-			->with($this->equalTo($inputDN))
130
-			->willReturn(false);
131
-
132
-		/** @noinspection PhpUnhandledExceptionInspection */
133
-		$user = $this->manager->get($inputDN);
134
-
135
-		$this->assertNull($user);
136
-	}
137
-
138
-	public function testGetByUidExisting(): void {
139
-		$dn = 'cn=foo,dc=foobar,dc=bar';
140
-		$uid = '563418fc-423b-1033-8d1c-ad5f418ee02e';
141
-
142
-		$this->access->expects($this->never())
143
-			->method('dn2username');
144
-		$this->access->expects($this->once())
145
-			->method('username2dn')
146
-			->with($this->equalTo($uid))
147
-			->willReturn($dn);
148
-		$this->access->expects($this->once())
149
-			->method('stringResemblesDN')
150
-			->with($this->equalTo($uid))
151
-			->willReturn(false);
152
-
153
-		/** @noinspection PhpUnhandledExceptionInspection */
154
-		$this->manager->get($uid);
155
-
156
-		// Now we fetch the user again. If this leads to a failing test,
157
-		// runtime caching the manager is broken.
158
-		/** @noinspection PhpUnhandledExceptionInspection */
159
-		$user = $this->manager->get($uid);
160
-
161
-		$this->assertInstanceOf(User::class, $user);
162
-	}
163
-
164
-	public function testGetByUidNotExisting(): void {
165
-		$uid = 'gone';
166
-
167
-		$this->access->expects($this->never())
168
-			->method('dn2username');
169
-		$this->access->expects($this->exactly(1))
170
-			->method('username2dn')
171
-			->with($this->equalTo($uid))
172
-			->willReturn(false);
173
-
174
-		/** @noinspection PhpUnhandledExceptionInspection */
175
-		$user = $this->manager->get($uid);
176
-
177
-		$this->assertNull($user);
178
-	}
179
-
180
-	public static function attributeRequestProvider(): array {
181
-		return [
182
-			[false],
183
-			[true],
184
-		];
185
-	}
186
-
187
-	/**
188
-	 * @dataProvider attributeRequestProvider
189
-	 */
190
-	public function testGetAttributes($minimal): void {
191
-		$this->connection->setConfiguration([
192
-			'ldapEmailAttribute' => 'MAIL',
193
-			'ldapUserAvatarRule' => 'default',
194
-			'ldapQuotaAttribute' => '',
195
-			'ldapUserDisplayName2' => 'Mail',
196
-		]);
197
-
198
-		$attributes = $this->manager->getAttributes($minimal);
199
-
200
-		$this->assertContains('dn', $attributes);
201
-		$this->assertContains(strtolower($this->access->getConnection()->ldapEmailAttribute), $attributes);
202
-		$this->assertNotContains($this->access->getConnection()->ldapEmailAttribute, $attributes); #cases check
203
-		$this->assertNotContains('', $attributes);
204
-		$this->assertSame(!$minimal, in_array('jpegphoto', $attributes));
205
-		$this->assertSame(!$minimal, in_array('thumbnailphoto', $attributes));
206
-		$valueCounts = array_count_values($attributes);
207
-		$this->assertSame(1, $valueCounts['mail']);
208
-	}
34
+    protected Access&MockObject $access;
35
+    protected IConfig&MockObject $config;
36
+    protected LoggerInterface&MockObject $logger;
37
+    protected IAvatarManager&MockObject $avatarManager;
38
+    protected Image&MockObject $image;
39
+    protected IDBConnection&MockObject $dbc;
40
+    protected IUserManager&MockObject $ncUserManager;
41
+    protected INotificationManager&MockObject $notificationManager;
42
+    protected ILDAPWrapper&MockObject $ldapWrapper;
43
+    protected Connection $connection;
44
+    protected IManager&MockObject $shareManager;
45
+    protected Manager $manager;
46
+
47
+    protected function setUp(): void {
48
+        parent::setUp();
49
+
50
+        $this->access = $this->createMock(Access::class);
51
+        $this->config = $this->createMock(IConfig::class);
52
+        $this->logger = $this->createMock(LoggerInterface::class);
53
+        $this->avatarManager = $this->createMock(IAvatarManager::class);
54
+        $this->image = $this->createMock(Image::class);
55
+        $this->ncUserManager = $this->createMock(IUserManager::class);
56
+        $this->notificationManager = $this->createMock(INotificationManager::class);
57
+        $this->ldapWrapper = $this->createMock(ILDAPWrapper::class);
58
+        $this->shareManager = $this->createMock(IManager::class);
59
+
60
+        $this->connection = new Connection($this->ldapWrapper, '', null);
61
+
62
+        $this->access->expects($this->any())
63
+            ->method('getConnection')
64
+            ->willReturn($this->connection);
65
+
66
+        /** @noinspection PhpUnhandledExceptionInspection */
67
+        $this->manager = new Manager(
68
+            $this->config,
69
+            $this->logger,
70
+            $this->avatarManager,
71
+            $this->image,
72
+            $this->ncUserManager,
73
+            $this->notificationManager,
74
+            $this->shareManager
75
+        );
76
+
77
+        $this->manager->setLdapAccess($this->access);
78
+    }
79
+
80
+    public static function dnProvider(): array {
81
+        return [
82
+            ['cn=foo,dc=foobar,dc=bar'],
83
+            ['uid=foo,o=foobar,c=bar'],
84
+            ['ab=cde,f=ghei,mno=pq'],
85
+        ];
86
+    }
87
+
88
+    /**
89
+     * @dataProvider dnProvider
90
+     */
91
+    public function testGetByDNExisting(string $inputDN): void {
92
+        $uid = '563418fc-423b-1033-8d1c-ad5f418ee02e';
93
+
94
+        $this->access->expects($this->once())
95
+            ->method('stringResemblesDN')
96
+            ->with($this->equalTo($inputDN))
97
+            ->willReturn(true);
98
+        $this->access->expects($this->once())
99
+            ->method('dn2username')
100
+            ->with($this->equalTo($inputDN))
101
+            ->willReturn($uid);
102
+        $this->access->expects($this->never())
103
+            ->method('username2dn');
104
+
105
+        /** @noinspection PhpUnhandledExceptionInspection */
106
+        $this->manager->get($inputDN);
107
+
108
+        // Now we fetch the user again. If this leads to a failing test,
109
+        // runtime caching the manager is broken.
110
+        /** @noinspection PhpUnhandledExceptionInspection */
111
+        $user = $this->manager->get($inputDN);
112
+
113
+        $this->assertInstanceOf(User::class, $user);
114
+    }
115
+
116
+    public function testGetByDNNotExisting(): void {
117
+        $inputDN = 'cn=gone,dc=foobar,dc=bar';
118
+
119
+        $this->access->expects($this->once())
120
+            ->method('stringResemblesDN')
121
+            ->with($this->equalTo($inputDN))
122
+            ->willReturn(true);
123
+        $this->access->expects($this->once())
124
+            ->method('dn2username')
125
+            ->with($this->equalTo($inputDN))
126
+            ->willReturn(false);
127
+        $this->access->expects($this->once())
128
+            ->method('username2dn')
129
+            ->with($this->equalTo($inputDN))
130
+            ->willReturn(false);
131
+
132
+        /** @noinspection PhpUnhandledExceptionInspection */
133
+        $user = $this->manager->get($inputDN);
134
+
135
+        $this->assertNull($user);
136
+    }
137
+
138
+    public function testGetByUidExisting(): void {
139
+        $dn = 'cn=foo,dc=foobar,dc=bar';
140
+        $uid = '563418fc-423b-1033-8d1c-ad5f418ee02e';
141
+
142
+        $this->access->expects($this->never())
143
+            ->method('dn2username');
144
+        $this->access->expects($this->once())
145
+            ->method('username2dn')
146
+            ->with($this->equalTo($uid))
147
+            ->willReturn($dn);
148
+        $this->access->expects($this->once())
149
+            ->method('stringResemblesDN')
150
+            ->with($this->equalTo($uid))
151
+            ->willReturn(false);
152
+
153
+        /** @noinspection PhpUnhandledExceptionInspection */
154
+        $this->manager->get($uid);
155
+
156
+        // Now we fetch the user again. If this leads to a failing test,
157
+        // runtime caching the manager is broken.
158
+        /** @noinspection PhpUnhandledExceptionInspection */
159
+        $user = $this->manager->get($uid);
160
+
161
+        $this->assertInstanceOf(User::class, $user);
162
+    }
163
+
164
+    public function testGetByUidNotExisting(): void {
165
+        $uid = 'gone';
166
+
167
+        $this->access->expects($this->never())
168
+            ->method('dn2username');
169
+        $this->access->expects($this->exactly(1))
170
+            ->method('username2dn')
171
+            ->with($this->equalTo($uid))
172
+            ->willReturn(false);
173
+
174
+        /** @noinspection PhpUnhandledExceptionInspection */
175
+        $user = $this->manager->get($uid);
176
+
177
+        $this->assertNull($user);
178
+    }
179
+
180
+    public static function attributeRequestProvider(): array {
181
+        return [
182
+            [false],
183
+            [true],
184
+        ];
185
+    }
186
+
187
+    /**
188
+     * @dataProvider attributeRequestProvider
189
+     */
190
+    public function testGetAttributes($minimal): void {
191
+        $this->connection->setConfiguration([
192
+            'ldapEmailAttribute' => 'MAIL',
193
+            'ldapUserAvatarRule' => 'default',
194
+            'ldapQuotaAttribute' => '',
195
+            'ldapUserDisplayName2' => 'Mail',
196
+        ]);
197
+
198
+        $attributes = $this->manager->getAttributes($minimal);
199
+
200
+        $this->assertContains('dn', $attributes);
201
+        $this->assertContains(strtolower($this->access->getConnection()->ldapEmailAttribute), $attributes);
202
+        $this->assertNotContains($this->access->getConnection()->ldapEmailAttribute, $attributes); #cases check
203
+        $this->assertNotContains('', $attributes);
204
+        $this->assertSame(!$minimal, in_array('jpegphoto', $attributes));
205
+        $this->assertSame(!$minimal, in_array('thumbnailphoto', $attributes));
206
+        $valueCounts = array_count_values($attributes);
207
+        $this->assertSame(1, $valueCounts['mail']);
208
+    }
209 209
 }
Please login to merge, or discard this patch.
apps/user_ldap/tests/UserLDAPPluginTest.php 2 patches
Indentation   +204 added lines, -204 removed lines patch added patch discarded remove patch
@@ -11,280 +11,280 @@
 block discarded – undo
11 11
 use OCA\User_LDAP\UserPluginManager;
12 12
 
13 13
 class UserLDAPPluginTest extends \Test\TestCase {
14
-	private function getUserPluginManager(): UserPluginManager {
15
-		return new UserPluginManager();
16
-	}
14
+    private function getUserPluginManager(): UserPluginManager {
15
+        return new UserPluginManager();
16
+    }
17 17
 
18
-	public function testImplementsActions(): void {
19
-		$pluginManager = $this->getUserPluginManager();
18
+    public function testImplementsActions(): void {
19
+        $pluginManager = $this->getUserPluginManager();
20 20
 
21
-		$plugin = $this->getMockBuilder(LDAPUserPluginDummy::class)
22
-			->onlyMethods(['respondToActions'])
23
-			->getMock();
21
+        $plugin = $this->getMockBuilder(LDAPUserPluginDummy::class)
22
+            ->onlyMethods(['respondToActions'])
23
+            ->getMock();
24 24
 
25
-		$plugin->expects($this->any())
26
-			->method('respondToActions')
27
-			->willReturn(Backend::CREATE_USER);
25
+        $plugin->expects($this->any())
26
+            ->method('respondToActions')
27
+            ->willReturn(Backend::CREATE_USER);
28 28
 
29
-		$plugin2 = $this->getMockBuilder(LDAPUserPluginDummy::class)
30
-			->onlyMethods(['respondToActions'])
31
-			->getMock();
29
+        $plugin2 = $this->getMockBuilder(LDAPUserPluginDummy::class)
30
+            ->onlyMethods(['respondToActions'])
31
+            ->getMock();
32 32
 
33
-		$plugin2->expects($this->any())
34
-			->method('respondToActions')
35
-			->willReturn(Backend::PROVIDE_AVATAR);
33
+        $plugin2->expects($this->any())
34
+            ->method('respondToActions')
35
+            ->willReturn(Backend::PROVIDE_AVATAR);
36 36
 
37
-		$pluginManager->register($plugin);
38
-		$pluginManager->register($plugin2);
37
+        $pluginManager->register($plugin);
38
+        $pluginManager->register($plugin2);
39 39
 
40
-		$this->assertEquals($pluginManager->getImplementedActions(), Backend::CREATE_USER | Backend::PROVIDE_AVATAR);
41
-		$this->assertTrue($pluginManager->implementsActions(Backend::CREATE_USER));
42
-		$this->assertTrue($pluginManager->implementsActions(Backend::PROVIDE_AVATAR));
43
-	}
40
+        $this->assertEquals($pluginManager->getImplementedActions(), Backend::CREATE_USER | Backend::PROVIDE_AVATAR);
41
+        $this->assertTrue($pluginManager->implementsActions(Backend::CREATE_USER));
42
+        $this->assertTrue($pluginManager->implementsActions(Backend::PROVIDE_AVATAR));
43
+    }
44 44
 
45
-	public function testCreateUser(): void {
46
-		$pluginManager = $this->getUserPluginManager();
45
+    public function testCreateUser(): void {
46
+        $pluginManager = $this->getUserPluginManager();
47 47
 
48
-		$plugin = $this->getMockBuilder(LDAPUserPluginDummy::class)
49
-			->onlyMethods(['respondToActions', 'createUser'])
50
-			->getMock();
48
+        $plugin = $this->getMockBuilder(LDAPUserPluginDummy::class)
49
+            ->onlyMethods(['respondToActions', 'createUser'])
50
+            ->getMock();
51 51
 
52
-		$plugin->expects($this->any())
53
-			->method('respondToActions')
54
-			->willReturn(Backend::CREATE_USER);
52
+        $plugin->expects($this->any())
53
+            ->method('respondToActions')
54
+            ->willReturn(Backend::CREATE_USER);
55 55
 
56
-		$plugin->expects($this->once())
57
-			->method('createUser')
58
-			->with(
59
-				$this->equalTo('user'),
60
-				$this->equalTo('password')
61
-			);
56
+        $plugin->expects($this->once())
57
+            ->method('createUser')
58
+            ->with(
59
+                $this->equalTo('user'),
60
+                $this->equalTo('password')
61
+            );
62 62
 
63
-		$pluginManager->register($plugin);
64
-		$pluginManager->createUser('user', 'password');
65
-	}
63
+        $pluginManager->register($plugin);
64
+        $pluginManager->createUser('user', 'password');
65
+    }
66 66
 
67 67
 
68
-	public function testCreateUserNotRegistered(): void {
69
-		$this->expectException(\Exception::class);
70
-		$this->expectExceptionMessage('No plugin implements createUser in this LDAP Backend.');
68
+    public function testCreateUserNotRegistered(): void {
69
+        $this->expectException(\Exception::class);
70
+        $this->expectExceptionMessage('No plugin implements createUser in this LDAP Backend.');
71 71
 
72
-		$pluginManager = $this->getUserPluginManager();
73
-		$pluginManager->createUser('foo', 'bar');
74
-	}
72
+        $pluginManager = $this->getUserPluginManager();
73
+        $pluginManager->createUser('foo', 'bar');
74
+    }
75 75
 
76
-	public function testSetPassword(): void {
77
-		$pluginManager = $this->getUserPluginManager();
76
+    public function testSetPassword(): void {
77
+        $pluginManager = $this->getUserPluginManager();
78 78
 
79
-		$plugin = $this->getMockBuilder(LDAPUserPluginDummy::class)
80
-			->onlyMethods(['respondToActions', 'setPassword'])
81
-			->getMock();
79
+        $plugin = $this->getMockBuilder(LDAPUserPluginDummy::class)
80
+            ->onlyMethods(['respondToActions', 'setPassword'])
81
+            ->getMock();
82 82
 
83
-		$plugin->expects($this->any())
84
-			->method('respondToActions')
85
-			->willReturn(Backend::SET_PASSWORD);
83
+        $plugin->expects($this->any())
84
+            ->method('respondToActions')
85
+            ->willReturn(Backend::SET_PASSWORD);
86 86
 
87
-		$plugin->expects($this->once())
88
-			->method('setPassword')
89
-			->with(
90
-				$this->equalTo('user'),
91
-				$this->equalTo('password')
92
-			);
87
+        $plugin->expects($this->once())
88
+            ->method('setPassword')
89
+            ->with(
90
+                $this->equalTo('user'),
91
+                $this->equalTo('password')
92
+            );
93 93
 
94
-		$pluginManager->register($plugin);
95
-		$pluginManager->setPassword('user', 'password');
96
-	}
94
+        $pluginManager->register($plugin);
95
+        $pluginManager->setPassword('user', 'password');
96
+    }
97 97
 
98 98
 
99
-	public function testSetPasswordNotRegistered(): void {
100
-		$this->expectException(\Exception::class);
101
-		$this->expectExceptionMessage('No plugin implements setPassword in this LDAP Backend.');
99
+    public function testSetPasswordNotRegistered(): void {
100
+        $this->expectException(\Exception::class);
101
+        $this->expectExceptionMessage('No plugin implements setPassword in this LDAP Backend.');
102 102
 
103
-		$pluginManager = $this->getUserPluginManager();
104
-		$pluginManager->setPassword('foo', 'bar');
105
-	}
103
+        $pluginManager = $this->getUserPluginManager();
104
+        $pluginManager->setPassword('foo', 'bar');
105
+    }
106 106
 
107
-	public function testGetHome(): void {
108
-		$pluginManager = $this->getUserPluginManager();
107
+    public function testGetHome(): void {
108
+        $pluginManager = $this->getUserPluginManager();
109 109
 
110
-		$plugin = $this->getMockBuilder(LDAPUserPluginDummy::class)
111
-			->onlyMethods(['respondToActions', 'getHome'])
112
-			->getMock();
110
+        $plugin = $this->getMockBuilder(LDAPUserPluginDummy::class)
111
+            ->onlyMethods(['respondToActions', 'getHome'])
112
+            ->getMock();
113 113
 
114
-		$plugin->expects($this->any())
115
-			->method('respondToActions')
116
-			->willReturn(Backend::GET_HOME);
114
+        $plugin->expects($this->any())
115
+            ->method('respondToActions')
116
+            ->willReturn(Backend::GET_HOME);
117 117
 
118
-		$plugin->expects($this->once())
119
-			->method('getHome')
120
-			->with(
121
-				$this->equalTo('uid')
122
-			);
118
+        $plugin->expects($this->once())
119
+            ->method('getHome')
120
+            ->with(
121
+                $this->equalTo('uid')
122
+            );
123 123
 
124
-		$pluginManager->register($plugin);
125
-		$pluginManager->getHome('uid');
126
-	}
124
+        $pluginManager->register($plugin);
125
+        $pluginManager->getHome('uid');
126
+    }
127 127
 
128 128
 
129
-	public function testGetHomeNotRegistered(): void {
130
-		$this->expectException(\Exception::class);
131
-		$this->expectExceptionMessage('No plugin implements getHome in this LDAP Backend.');
129
+    public function testGetHomeNotRegistered(): void {
130
+        $this->expectException(\Exception::class);
131
+        $this->expectExceptionMessage('No plugin implements getHome in this LDAP Backend.');
132 132
 
133
-		$pluginManager = $this->getUserPluginManager();
134
-		$pluginManager->getHome('foo');
135
-	}
133
+        $pluginManager = $this->getUserPluginManager();
134
+        $pluginManager->getHome('foo');
135
+    }
136 136
 
137
-	public function testGetDisplayName(): void {
138
-		$pluginManager = $this->getUserPluginManager();
137
+    public function testGetDisplayName(): void {
138
+        $pluginManager = $this->getUserPluginManager();
139 139
 
140
-		$plugin = $this->getMockBuilder(LDAPUserPluginDummy::class)
141
-			->onlyMethods(['respondToActions', 'getDisplayName'])
142
-			->getMock();
140
+        $plugin = $this->getMockBuilder(LDAPUserPluginDummy::class)
141
+            ->onlyMethods(['respondToActions', 'getDisplayName'])
142
+            ->getMock();
143 143
 
144
-		$plugin->expects($this->any())
145
-			->method('respondToActions')
146
-			->willReturn(Backend::GET_DISPLAYNAME);
144
+        $plugin->expects($this->any())
145
+            ->method('respondToActions')
146
+            ->willReturn(Backend::GET_DISPLAYNAME);
147 147
 
148
-		$plugin->expects($this->once())
149
-			->method('getDisplayName')
150
-			->with(
151
-				$this->equalTo('uid')
152
-			);
148
+        $plugin->expects($this->once())
149
+            ->method('getDisplayName')
150
+            ->with(
151
+                $this->equalTo('uid')
152
+            );
153 153
 
154
-		$pluginManager->register($plugin);
155
-		$pluginManager->getDisplayName('uid');
156
-	}
154
+        $pluginManager->register($plugin);
155
+        $pluginManager->getDisplayName('uid');
156
+    }
157 157
 
158 158
 
159
-	public function testGetDisplayNameNotRegistered(): void {
160
-		$this->expectException(\Exception::class);
161
-		$this->expectExceptionMessage('No plugin implements getDisplayName in this LDAP Backend.');
159
+    public function testGetDisplayNameNotRegistered(): void {
160
+        $this->expectException(\Exception::class);
161
+        $this->expectExceptionMessage('No plugin implements getDisplayName in this LDAP Backend.');
162 162
 
163
-		$pluginManager = $this->getUserPluginManager();
164
-		$pluginManager->getDisplayName('foo');
165
-	}
163
+        $pluginManager = $this->getUserPluginManager();
164
+        $pluginManager->getDisplayName('foo');
165
+    }
166 166
 
167
-	public function testSetDisplayName(): void {
168
-		$pluginManager = $this->getUserPluginManager();
167
+    public function testSetDisplayName(): void {
168
+        $pluginManager = $this->getUserPluginManager();
169 169
 
170
-		$plugin = $this->getMockBuilder(LDAPUserPluginDummy::class)
171
-			->onlyMethods(['respondToActions', 'setDisplayName'])
172
-			->getMock();
170
+        $plugin = $this->getMockBuilder(LDAPUserPluginDummy::class)
171
+            ->onlyMethods(['respondToActions', 'setDisplayName'])
172
+            ->getMock();
173 173
 
174
-		$plugin->expects($this->any())
175
-			->method('respondToActions')
176
-			->willReturn(Backend::SET_DISPLAYNAME);
174
+        $plugin->expects($this->any())
175
+            ->method('respondToActions')
176
+            ->willReturn(Backend::SET_DISPLAYNAME);
177 177
 
178
-		$plugin->expects($this->once())
179
-			->method('setDisplayName')
180
-			->with(
181
-				$this->equalTo('user'),
182
-				$this->equalTo('password')
183
-			);
178
+        $plugin->expects($this->once())
179
+            ->method('setDisplayName')
180
+            ->with(
181
+                $this->equalTo('user'),
182
+                $this->equalTo('password')
183
+            );
184 184
 
185
-		$pluginManager->register($plugin);
186
-		$pluginManager->setDisplayName('user', 'password');
187
-	}
185
+        $pluginManager->register($plugin);
186
+        $pluginManager->setDisplayName('user', 'password');
187
+    }
188 188
 
189 189
 
190
-	public function testSetDisplayNameNotRegistered(): void {
191
-		$this->expectException(\Exception::class);
192
-		$this->expectExceptionMessage('No plugin implements setDisplayName in this LDAP Backend.');
190
+    public function testSetDisplayNameNotRegistered(): void {
191
+        $this->expectException(\Exception::class);
192
+        $this->expectExceptionMessage('No plugin implements setDisplayName in this LDAP Backend.');
193 193
 
194
-		$pluginManager = $this->getUserPluginManager();
195
-		$pluginManager->setDisplayName('foo', 'bar');
196
-	}
194
+        $pluginManager = $this->getUserPluginManager();
195
+        $pluginManager->setDisplayName('foo', 'bar');
196
+    }
197 197
 
198
-	public function testCanChangeAvatar(): void {
199
-		$pluginManager = $this->getUserPluginManager();
198
+    public function testCanChangeAvatar(): void {
199
+        $pluginManager = $this->getUserPluginManager();
200 200
 
201
-		$plugin = $this->getMockBuilder(LDAPUserPluginDummy::class)
202
-			->onlyMethods(['respondToActions', 'canChangeAvatar'])
203
-			->getMock();
201
+        $plugin = $this->getMockBuilder(LDAPUserPluginDummy::class)
202
+            ->onlyMethods(['respondToActions', 'canChangeAvatar'])
203
+            ->getMock();
204 204
 
205
-		$plugin->expects($this->any())
206
-			->method('respondToActions')
207
-			->willReturn(Backend::PROVIDE_AVATAR);
205
+        $plugin->expects($this->any())
206
+            ->method('respondToActions')
207
+            ->willReturn(Backend::PROVIDE_AVATAR);
208 208
 
209
-		$plugin->expects($this->once())
210
-			->method('canChangeAvatar')
211
-			->with(
212
-				$this->equalTo('uid')
213
-			);
209
+        $plugin->expects($this->once())
210
+            ->method('canChangeAvatar')
211
+            ->with(
212
+                $this->equalTo('uid')
213
+            );
214 214
 
215
-		$pluginManager->register($plugin);
216
-		$pluginManager->canChangeAvatar('uid');
217
-	}
215
+        $pluginManager->register($plugin);
216
+        $pluginManager->canChangeAvatar('uid');
217
+    }
218 218
 
219 219
 
220
-	public function testCanChangeAvatarNotRegistered(): void {
221
-		$this->expectException(\Exception::class);
222
-		$this->expectExceptionMessage('No plugin implements canChangeAvatar in this LDAP Backend.');
220
+    public function testCanChangeAvatarNotRegistered(): void {
221
+        $this->expectException(\Exception::class);
222
+        $this->expectExceptionMessage('No plugin implements canChangeAvatar in this LDAP Backend.');
223 223
 
224
-		$pluginManager = $this->getUserPluginManager();
225
-		$pluginManager->canChangeAvatar('foo');
226
-	}
224
+        $pluginManager = $this->getUserPluginManager();
225
+        $pluginManager->canChangeAvatar('foo');
226
+    }
227 227
 
228
-	public function testCountUsers(): void {
229
-		$pluginManager = $this->getUserPluginManager();
228
+    public function testCountUsers(): void {
229
+        $pluginManager = $this->getUserPluginManager();
230 230
 
231
-		$plugin = $this->getMockBuilder(LDAPUserPluginDummy::class)
232
-			->onlyMethods(['respondToActions', 'countUsers'])
233
-			->getMock();
231
+        $plugin = $this->getMockBuilder(LDAPUserPluginDummy::class)
232
+            ->onlyMethods(['respondToActions', 'countUsers'])
233
+            ->getMock();
234 234
 
235
-		$plugin->expects($this->any())
236
-			->method('respondToActions')
237
-			->willReturn(Backend::COUNT_USERS);
235
+        $plugin->expects($this->any())
236
+            ->method('respondToActions')
237
+            ->willReturn(Backend::COUNT_USERS);
238 238
 
239
-		$plugin->expects($this->once())
240
-			->method('countUsers');
239
+        $plugin->expects($this->once())
240
+            ->method('countUsers');
241 241
 
242
-		$pluginManager->register($plugin);
243
-		$pluginManager->countUsers();
244
-	}
242
+        $pluginManager->register($plugin);
243
+        $pluginManager->countUsers();
244
+    }
245 245
 
246 246
 
247
-	public function testCountUsersNotRegistered(): void {
248
-		$this->expectException(\Exception::class);
249
-		$this->expectExceptionMessage('No plugin implements countUsers in this LDAP Backend.');
247
+    public function testCountUsersNotRegistered(): void {
248
+        $this->expectException(\Exception::class);
249
+        $this->expectExceptionMessage('No plugin implements countUsers in this LDAP Backend.');
250 250
 
251
-		$pluginManager = $this->getUserPluginManager();
252
-		$pluginManager->countUsers();
253
-	}
251
+        $pluginManager = $this->getUserPluginManager();
252
+        $pluginManager->countUsers();
253
+    }
254 254
 
255
-	public function testDeleteUser(): void {
256
-		$pluginManager = $this->getUserPluginManager();
255
+    public function testDeleteUser(): void {
256
+        $pluginManager = $this->getUserPluginManager();
257 257
 
258
-		$plugin = $this->getMockBuilder(LDAPUserPluginDummy::class)
259
-			->onlyMethods(['respondToActions', 'canDeleteUser','deleteUser'])
260
-			->getMock();
258
+        $plugin = $this->getMockBuilder(LDAPUserPluginDummy::class)
259
+            ->onlyMethods(['respondToActions', 'canDeleteUser','deleteUser'])
260
+            ->getMock();
261 261
 
262
-		$plugin->expects($this->any())
263
-			->method('respondToActions')
264
-			->willReturn(0);
262
+        $plugin->expects($this->any())
263
+            ->method('respondToActions')
264
+            ->willReturn(0);
265 265
 
266
-		$plugin->expects($this->any())
267
-			->method('canDeleteUser')
268
-			->willReturn(true);
266
+        $plugin->expects($this->any())
267
+            ->method('canDeleteUser')
268
+            ->willReturn(true);
269 269
 
270
-		$plugin->expects($this->once())
271
-			->method('deleteUser')
272
-			->with(
273
-				$this->equalTo('uid')
274
-			);
270
+        $plugin->expects($this->once())
271
+            ->method('deleteUser')
272
+            ->with(
273
+                $this->equalTo('uid')
274
+            );
275 275
 
276
-		$this->assertFalse($pluginManager->canDeleteUser());
277
-		$pluginManager->register($plugin);
278
-		$this->assertTrue($pluginManager->canDeleteUser());
279
-		$pluginManager->deleteUser('uid');
280
-	}
276
+        $this->assertFalse($pluginManager->canDeleteUser());
277
+        $pluginManager->register($plugin);
278
+        $this->assertTrue($pluginManager->canDeleteUser());
279
+        $pluginManager->deleteUser('uid');
280
+    }
281 281
 
282 282
 
283
-	public function testDeleteUserNotRegistered(): void {
284
-		$this->expectException(\Exception::class);
285
-		$this->expectExceptionMessage('No plugin implements deleteUser in this LDAP Backend.');
283
+    public function testDeleteUserNotRegistered(): void {
284
+        $this->expectException(\Exception::class);
285
+        $this->expectExceptionMessage('No plugin implements deleteUser in this LDAP Backend.');
286 286
 
287
-		$pluginManager = $this->getUserPluginManager();
288
-		$pluginManager->deleteUser('foo');
289
-	}
287
+        $pluginManager = $this->getUserPluginManager();
288
+        $pluginManager->deleteUser('foo');
289
+    }
290 290
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -256,7 +256,7 @@
 block discarded – undo
256 256
 		$pluginManager = $this->getUserPluginManager();
257 257
 
258 258
 		$plugin = $this->getMockBuilder(LDAPUserPluginDummy::class)
259
-			->onlyMethods(['respondToActions', 'canDeleteUser','deleteUser'])
259
+			->onlyMethods(['respondToActions', 'canDeleteUser', 'deleteUser'])
260 260
 			->getMock();
261 261
 
262 262
 		$plugin->expects($this->any())
Please login to merge, or discard this patch.
apps/user_ldap/tests/Settings/SectionTest.php 1 patch
Indentation   +41 added lines, -41 removed lines patch added patch discarded remove patch
@@ -14,45 +14,45 @@
 block discarded – undo
14 14
 use Test\TestCase;
15 15
 
16 16
 class SectionTest extends TestCase {
17
-	private IURLGenerator&MockObject $url;
18
-	private IL10N&MockObject $l;
19
-	private Section $section;
20
-
21
-	protected function setUp(): void {
22
-		parent::setUp();
23
-		$this->url = $this->createMock(IURLGenerator::class);
24
-		$this->l = $this->createMock(IL10N::class);
25
-
26
-		$this->section = new Section(
27
-			$this->url,
28
-			$this->l
29
-		);
30
-	}
31
-
32
-	public function testGetID(): void {
33
-		$this->assertSame('ldap', $this->section->getID());
34
-	}
35
-
36
-	public function testGetName(): void {
37
-		$this->l
38
-			->expects($this->once())
39
-			->method('t')
40
-			->with('LDAP/AD integration')
41
-			->willReturn('LDAP/AD integration');
42
-
43
-		$this->assertSame('LDAP/AD integration', $this->section->getName());
44
-	}
45
-
46
-	public function testGetPriority(): void {
47
-		$this->assertSame(25, $this->section->getPriority());
48
-	}
49
-
50
-	public function testGetIcon(): void {
51
-		$this->url->expects($this->once())
52
-			->method('imagePath')
53
-			->with('user_ldap', 'app-dark.svg')
54
-			->willReturn('icon');
55
-
56
-		$this->assertSame('icon', $this->section->getIcon());
57
-	}
17
+    private IURLGenerator&MockObject $url;
18
+    private IL10N&MockObject $l;
19
+    private Section $section;
20
+
21
+    protected function setUp(): void {
22
+        parent::setUp();
23
+        $this->url = $this->createMock(IURLGenerator::class);
24
+        $this->l = $this->createMock(IL10N::class);
25
+
26
+        $this->section = new Section(
27
+            $this->url,
28
+            $this->l
29
+        );
30
+    }
31
+
32
+    public function testGetID(): void {
33
+        $this->assertSame('ldap', $this->section->getID());
34
+    }
35
+
36
+    public function testGetName(): void {
37
+        $this->l
38
+            ->expects($this->once())
39
+            ->method('t')
40
+            ->with('LDAP/AD integration')
41
+            ->willReturn('LDAP/AD integration');
42
+
43
+        $this->assertSame('LDAP/AD integration', $this->section->getName());
44
+    }
45
+
46
+    public function testGetPriority(): void {
47
+        $this->assertSame(25, $this->section->getPriority());
48
+    }
49
+
50
+    public function testGetIcon(): void {
51
+        $this->url->expects($this->once())
52
+            ->method('imagePath')
53
+            ->with('user_ldap', 'app-dark.svg')
54
+            ->willReturn('icon');
55
+
56
+        $this->assertSame('icon', $this->section->getIcon());
57
+    }
58 58
 }
Please login to merge, or discard this patch.