19 declare(strict_types=1);
42 require_once __DIR__ .
'/../ContainerMock.php';
50 $this->assertInstanceOf(User::class,
new User(
51 $this->mock(ilObjUser::class),
52 $this->mock(Settings::class),
53 $this->mock(UserSettings::class),
54 $this->mock(Provide::class),
55 $this->mock(Clock::class)
63 $user = $this->mock(ilObjUser::class);
64 $user->expects(self::exactly(5))->method(
'getId')->willReturnOnConsecutiveCalls(0,
ANONYMOUS_USER_ID, 9, 1, 68);
68 $this->mock(Settings::class),
69 $this->mock(UserSettings::class),
70 $this->mock(Provide::class),
71 $this->mock(Clock::class)
74 $this->assertFalse($instance->isLoggedIn());
75 $this->assertFalse($instance->isLoggedIn());
76 $this->assertTrue($instance->isLoggedIn());
77 $this->assertTrue($instance->isLoggedIn());
78 $this->assertTrue($instance->isLoggedIn());
86 $user = $this->mock(ilObjUser::class);
91 $this->mock(Settings::class),
92 $this->mock(UserSettings::class),
93 $this->mock(Provide::class),
94 $this->mock(Clock::class)
97 $this->assertTrue($instance->cannotAgree());
98 $this->assertTrue($instance->cannotAgree());
99 $this->assertTrue($instance->cannotAgree());
100 $this->assertFalse($instance->cannotAgree());
101 $this->assertFalse($instance->cannotAgree());
106 $setting = $this->mock(Setting::class);
109 $user_settings = $this->mock(UserSettings::class);
110 $user_settings->expects(self::exactly(2))->method(
'agreeDate')->willReturn(
$setting);
112 $instance =
new User(
113 $this->mock(ilObjUser::class),
114 $this->mock(Settings::class),
116 $this->mock(Provide::class),
117 $this->mock(Clock::class)
120 $this->assertTrue($instance->neverAgreed());
121 $this->assertFalse($instance->neverAgreed());
126 $setting = $this->mock(Setting::class);
128 $instance =
new User(
129 $this->mock(ilObjUser::class),
130 $this->mock(Settings::class),
131 $this->mockMethod(UserSettings::class,
'withdrawalRequested', [],
$setting),
132 $this->mock(Provide::class),
133 $this->mock(Clock::class)
136 $this->assertSame(
$setting, $instance->withdrawalRequested());
141 $setting = $this->mock(Setting::class);
143 $instance =
new User(
144 $this->mock(ilObjUser::class),
145 $this->mock(Settings::class),
146 $this->mockMethod(UserSettings::class,
'agreeDate', [],
$setting),
147 $this->mock(Provide::class),
148 $this->mock(Clock::class)
151 $this->assertSame(
$setting, $instance->agreeDate());
156 $user = $this->mock(ilObjUser::class);
157 $document = $this->mock(Document::class);
159 $instance =
new User(
161 $this->mockTree(Settings::class, [
'validateOnLogin' => [
'value' =>
true]]),
162 $this->mock(UserSettings::class),
163 $this->mockTree(Provide::class, [
164 'document' => $this->mockMethod(ProvideDocument::class,
'chooseDocumentFor', [$user],
new Ok($document)),
165 'history' => $this->mockMethod(ProvideHistory::class,
'alreadyAccepted', [$user, $document],
false),
167 $this->mock(Clock::class)
170 $this->assertTrue($instance->didNotAcceptCurrentVersion());
175 $instance =
new User(
176 $this->mock(ilObjUser::class),
177 $this->mock(Settings::class),
178 $this->mockTree(UserSettings::class, [
'agreeDate' => [
'value' =>
null]]),
179 $this->mock(Provide::class),
180 $this->mock(Clock::class)
183 $this->assertTrue($instance->needsToAcceptNewDocument());
188 $user = $this->mock(ilObjUser::class);
189 $history = $this->mockMethod(ProvideHistory::class,
'currentDocumentOfAcceptedVersion', [$user],
new Error(
'Not found.'));
191 $instance =
new User(
193 $this->mockTree(Settings::class, [
'validateOnLogin' => [
'value' =>
true]]),
194 $this->mockTree(UserSettings::class, [
'agreeDate' => [
'value' =>
new DateTimeImmutable()]]),
195 $this->mockTree(Provide::class, [
'history' => $history]),
196 $this->mock(Clock::class)
199 $this->assertTrue($instance->needsToAcceptNewDocument());
204 $user = $this->mock(ilObjUser::class);
205 $document = $this->mock(Document::class);
206 $history = $this->mockMethod(ProvideHistory::class,
'currentDocumentOfAcceptedVersion', [$user],
new Ok($document));
208 $instance =
new User(
210 $this->mockTree(Settings::class, [
'validateOnLogin' => [
'value' =>
true]]),
211 $this->mockTree(UserSettings::class, [
'agreeDate' => [
'value' =>
new DateTimeImmutable()]]),
212 $this->mockTree(Provide::class, [
213 'document' => $this->mockMethod(ProvideDocument::class,
'documentMatches', [$document, $user],
true),
214 'history' => $history,
216 $this->mock(Clock::class)
219 $this->assertFalse($instance->needsToAcceptNewDocument());
224 $document = $this->mock(Document::class);
225 $user = $this->mock(ilObjUser::class);
227 $instance =
new User(
229 $this->mock(Settings::class),
230 $this->mock(UserSettings::class),
231 $this->mockTree(Provide::class, [
232 'document' => $this->mockMethod(ProvideDocument::class,
'documentMatches', [$document, $user],
true),
234 $this->mock(Clock::class)
237 $this->assertFalse($instance->doesntMatch($document));
242 $user = $this->mock(ilObjUser::class);
243 $result = $this->mock(Result::class);
245 $instance =
new User(
247 $this->mock(Settings::class),
248 $this->mock(UserSettings::class),
249 $this->mockTree(Provide::class, [
250 'document' => $this->mockMethod(ProvideDocument::class,
'chooseDocumentFor', [$user], $result),
252 $this->mock(Clock::class)
255 $this->assertSame($result, $instance->matchingDocument());
263 $result = $this->mock(Result::class);
265 $user = $this->mockTree(ilObjUser::class, [
'getId' => 67]);
267 $instance =
new User(
269 $this->mock(Settings::class),
270 $this->mockTree(UserSettings::class, [
'agreeDate' => [
'value' =>
new DateTimeImmutable()]]),
271 $this->mockTree(Provide::class, [
'history' => $this->mockMethod(ProvideHistory::class,
'acceptedVersion', [$user], $result)]),
272 $this->mock(Clock::class)
275 $this->assertSame($result, $instance->acceptedVersion());
283 $user = $this->mockTree(ilObjUser::class, [
'getId' => 67]);
285 $instance =
new User(
287 $this->mock(Settings::class),
288 $this->mockTree(UserSettings::class, [
'agreeDate' => [
'value' =>
null]]),
289 $this->mock(Provide::class),
290 $this->mock(Clock::class)
293 $result = $instance->acceptedVersion();
294 $this->assertFalse($result->isOk());
295 $this->assertSame(
'User never agreed.', $result->error());
300 $user = $this->mock(ilObjUser::class);
301 $document = $this->mock(Document::class);
304 $history = $this->mock(ProvideHistory::class);
305 $history->expects(self::once())->method(
'acceptDocument')->with($user, $document);
307 $setting = $this->mock(Setting::class);
308 $setting->expects(self::once())->method(
'update')->with($date);
310 $instance =
new User(
312 $this->mock(Settings::class),
313 $this->mockTree(UserSettings::class, [
'agreeDate' =>
$setting]),
314 $this->mockTree(Provide::class, [
315 'document' => $this->mockMethod(ProvideDocument::class,
'chooseDocumentFor', [$user],
new Ok($document)),
316 'history' => $history,
318 $this->mockTree(Clock::class, [
'now' => $date])
321 $instance->acceptMatchingDocument();
326 $instance =
new User(
327 $this->mockTree(ilObjUser::class, [
'getAuthMode' =>
'default']),
329 $this->mock(UserSettings::class),
330 $this->mock(Provide::class),
331 $this->mock(Clock::class)
334 $this->assertTrue($instance->isLDAPUser());
337 #[DataProvider('externalAuthModes')] 340 $instance =
new User(
341 $this->mockTree(ilObjUser::class, [
'getAuthMode' =>
'default']),
342 $this->mockTree(Settings::class, [
'authMode' => [
'value' => (
string) $auth_mode]]),
343 $this->mock(UserSettings::class),
344 $this->mock(Provide::class),
345 $this->mock(Clock::class)
348 $this->assertSame($is_external_account, $instance->isExternalAccount());
353 $instance =
new User(
354 $this->mockTree(ilObjUser::class, [
355 'getFullname' =>
'foo',
357 'getExternalAccount' =>
'baz',
359 $this->mock(Settings::class),
360 $this->mock(UserSettings::class),
361 $this->mock(Provide::class),
362 $this->mock(Clock::class)
365 $this->assertSame(
'', $instance->format(
''));
366 $this->assertSame(
"hej foo bar\nbaz", $instance->format(
'hej %s %s[BR]%s'));
371 $user = $this->mock(ilObjUser::class);
373 $instance =
new User(
375 $this->mock(Settings::class),
376 $this->mock(UserSettings::class),
377 $this->mock(Provide::class),
378 $this->mock(Clock::class)
381 $this->assertSame($user, $instance->raw());
386 $user = $this->mock(ilObjUser::class);
387 $history = $this->mock(ProvideHistory::class);
388 $doc = $this->mock(Document::class);
389 $history->expects(self::once())->method(
'acceptDocument')->with($user, $doc);
391 $instance =
new User(
393 $this->mock(Settings::class),
394 $this->mock(UserSettings::class),
395 $this->mockTree(Provide::class, [
396 'document' => [
'repository' => [
'all' => [$doc]]],
397 'history' => $history,
399 $this->mock(Clock::class)
402 $instance->acceptAnyDocument();
416 if (!defined($name)) {
417 define($name, $value);
const SYSTEM_USER_ID
This file contains constants for PHPStan analyis, see: https://phpstan.org/config-reference#constants...
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
A result encapsulates a value or an error and simplifies the handling of those.
const int AUTH_PROVIDER_LTI