19 declare(strict_types=1);
41 require_once __DIR__ .
'/../ContainerMock.php';
49 $this->assertInstanceOf(User::class,
new User(
50 $this->mock(ilObjUser::class),
51 $this->mock(Settings::class),
52 $this->mock(UserSettings::class),
53 $this->mock(Provide::class),
54 $this->mock(Clock::class)
62 $user = $this->mock(ilObjUser::class);
63 $user->expects(self::exactly(5))->method(
'getId')->willReturnOnConsecutiveCalls(0,
ANONYMOUS_USER_ID, 9, 1, 68);
67 $this->mock(Settings::class),
68 $this->mock(UserSettings::class),
69 $this->mock(Provide::class),
70 $this->mock(Clock::class)
73 $this->assertFalse($instance->isLoggedIn());
74 $this->assertFalse($instance->isLoggedIn());
75 $this->assertTrue($instance->isLoggedIn());
76 $this->assertTrue($instance->isLoggedIn());
77 $this->assertTrue($instance->isLoggedIn());
85 $user = $this->mock(ilObjUser::class);
90 $this->mock(Settings::class),
91 $this->mock(UserSettings::class),
92 $this->mock(Provide::class),
93 $this->mock(Clock::class)
96 $this->assertTrue($instance->cannotAgree());
97 $this->assertTrue($instance->cannotAgree());
98 $this->assertTrue($instance->cannotAgree());
99 $this->assertFalse($instance->cannotAgree());
100 $this->assertFalse($instance->cannotAgree());
105 $setting = $this->mock(Setting::class);
108 $user_settings = $this->mock(UserSettings::class);
109 $user_settings->expects(self::exactly(2))->method(
'agreeDate')->willReturn(
$setting);
111 $instance =
new User(
112 $this->mock(ilObjUser::class),
113 $this->mock(Settings::class),
115 $this->mock(Provide::class),
116 $this->mock(Clock::class)
119 $this->assertTrue($instance->neverAgreed());
120 $this->assertFalse($instance->neverAgreed());
125 $setting = $this->mock(Setting::class);
127 $instance =
new User(
128 $this->mock(ilObjUser::class),
129 $this->mock(Settings::class),
130 $this->mockMethod(UserSettings::class,
'withdrawalRequested', [],
$setting),
131 $this->mock(Provide::class),
132 $this->mock(Clock::class)
135 $this->assertSame(
$setting, $instance->withdrawalRequested());
140 $setting = $this->mock(Setting::class);
142 $instance =
new User(
143 $this->mock(ilObjUser::class),
144 $this->mock(Settings::class),
145 $this->mockMethod(UserSettings::class,
'agreeDate', [],
$setting),
146 $this->mock(Provide::class),
147 $this->mock(Clock::class)
150 $this->assertSame(
$setting, $instance->agreeDate());
155 $user = $this->mock(ilObjUser::class);
156 $document = $this->mock(Document::class);
158 $instance =
new User(
160 $this->mockTree(Settings::class, [
'validateOnLogin' => [
'value' =>
true]]),
161 $this->mock(UserSettings::class),
162 $this->mockTree(Provide::class, [
163 'document' => $this->mockMethod(ProvideDocument::class,
'chooseDocumentFor', [$user],
new Ok($document)),
164 'history' => $this->mockMethod(ProvideHistory::class,
'alreadyAccepted', [$user, $document],
false),
166 $this->mock(Clock::class)
169 $this->assertTrue($instance->didNotAcceptCurrentVersion());
174 $instance =
new User(
175 $this->mock(ilObjUser::class),
176 $this->mock(Settings::class),
177 $this->mockTree(UserSettings::class, [
'agreeDate' => [
'value' =>
null]]),
178 $this->mock(Provide::class),
179 $this->mock(Clock::class)
182 $this->assertTrue($instance->needsToAcceptNewDocument());
187 $user = $this->mock(ilObjUser::class);
188 $history = $this->mockMethod(ProvideHistory::class,
'currentDocumentOfAcceptedVersion', [$user],
new Error(
'Not found.'));
190 $instance =
new User(
192 $this->mockTree(Settings::class, [
'validateOnLogin' => [
'value' =>
true]]),
193 $this->mockTree(UserSettings::class, [
'agreeDate' => [
'value' =>
new DateTimeImmutable()]]),
194 $this->mockTree(Provide::class, [
'history' => $history]),
195 $this->mock(Clock::class)
198 $this->assertTrue($instance->needsToAcceptNewDocument());
203 $user = $this->mock(ilObjUser::class);
204 $document = $this->mock(Document::class);
205 $history = $this->mockMethod(ProvideHistory::class,
'currentDocumentOfAcceptedVersion', [$user],
new Ok($document));
207 $instance =
new User(
209 $this->mockTree(Settings::class, [
'validateOnLogin' => [
'value' =>
true]]),
210 $this->mockTree(UserSettings::class, [
'agreeDate' => [
'value' =>
new DateTimeImmutable()]]),
211 $this->mockTree(Provide::class, [
212 'document' => $this->mockMethod(ProvideDocument::class,
'documentMatches', [$document, $user],
true),
213 'history' => $history,
215 $this->mock(Clock::class)
218 $this->assertFalse($instance->needsToAcceptNewDocument());
223 $document = $this->mock(Document::class);
224 $user = $this->mock(ilObjUser::class);
226 $instance =
new User(
228 $this->mock(Settings::class),
229 $this->mock(UserSettings::class),
230 $this->mockTree(Provide::class, [
231 'document' => $this->mockMethod(ProvideDocument::class,
'documentMatches', [$document, $user],
true),
233 $this->mock(Clock::class)
236 $this->assertFalse($instance->doesntMatch($document));
241 $user = $this->mock(ilObjUser::class);
242 $result = $this->mock(Result::class);
244 $instance =
new User(
246 $this->mock(Settings::class),
247 $this->mock(UserSettings::class),
248 $this->mockTree(Provide::class, [
249 'document' => $this->mockMethod(ProvideDocument::class,
'chooseDocumentFor', [$user], $result),
251 $this->mock(Clock::class)
254 $this->assertSame($result, $instance->matchingDocument());
262 $result = $this->mock(Result::class);
264 $user = $this->mockTree(ilObjUser::class, [
'getId' => 67]);
266 $instance =
new User(
268 $this->mock(Settings::class),
269 $this->mockTree(UserSettings::class, [
'agreeDate' => [
'value' =>
new DateTimeImmutable()]]),
270 $this->mockTree(Provide::class, [
'history' => $this->mockMethod(ProvideHistory::class,
'acceptedVersion', [$user], $result)]),
271 $this->mock(Clock::class)
274 $this->assertSame($result, $instance->acceptedVersion());
282 $user = $this->mockTree(ilObjUser::class, [
'getId' => 67]);
284 $instance =
new User(
286 $this->mock(Settings::class),
287 $this->mockTree(UserSettings::class, [
'agreeDate' => [
'value' =>
null]]),
288 $this->mock(Provide::class),
289 $this->mock(Clock::class)
292 $result = $instance->acceptedVersion();
293 $this->assertFalse($result->isOk());
294 $this->assertSame(
'User never agreed.', $result->error());
299 $user = $this->mock(ilObjUser::class);
300 $document = $this->mock(Document::class);
303 $history = $this->mock(ProvideHistory::class);
304 $history->expects(self::once())->method(
'acceptDocument')->with($user, $document);
306 $setting = $this->mock(Setting::class);
307 $setting->expects(self::once())->method(
'update')->with($date);
309 $instance =
new User(
311 $this->mock(Settings::class),
312 $this->mockTree(UserSettings::class, [
'agreeDate' =>
$setting]),
313 $this->mockTree(Provide::class, [
314 'document' => $this->mockMethod(ProvideDocument::class,
'chooseDocumentFor', [$user],
new Ok($document)),
315 'history' => $history,
317 $this->mockTree(Clock::class, [
'now' => $date])
320 $instance->acceptMatchingDocument();
325 $instance =
new User(
326 $this->mockTree(ilObjUser::class, [
'getAuthMode' =>
'default']),
328 $this->mock(UserSettings::class),
329 $this->mock(Provide::class),
330 $this->mock(Clock::class)
333 $this->assertTrue($instance->isLDAPUser());
341 $instance =
new User(
342 $this->mockTree(ilObjUser::class, [
'getAuthMode' =>
'default']),
343 $this->mockTree(Settings::class, [
'authMode' => [
'value' => (
string) $auth_mode]]),
344 $this->mock(UserSettings::class),
345 $this->mock(Provide::class),
346 $this->mock(Clock::class)
349 $this->assertSame($is_external_account, $instance->isExternalAccount());
354 $instance =
new User(
355 $this->mockTree(ilObjUser::class, [
356 'getFullname' =>
'foo',
358 'getExternalAccount' =>
'baz',
360 $this->mock(Settings::class),
361 $this->mock(UserSettings::class),
362 $this->mock(Provide::class),
363 $this->mock(Clock::class)
366 $this->assertSame(
'', $instance->format(
''));
367 $this->assertSame(
"hej foo bar\nbaz", $instance->format(
'hej %s %s[BR]%s'));
372 $user = $this->mock(ilObjUser::class);
374 $instance =
new User(
376 $this->mock(Settings::class),
377 $this->mock(UserSettings::class),
378 $this->mock(Provide::class),
379 $this->mock(Clock::class)
382 $this->assertSame($user, $instance->raw());
387 $user = $this->mock(ilObjUser::class);
388 $history = $this->mock(ProvideHistory::class);
389 $doc = $this->mock(Document::class);
390 $history->expects(self::once())->method(
'acceptDocument')->with($user, $doc);
392 $instance =
new User(
394 $this->mock(Settings::class),
395 $this->mock(UserSettings::class),
396 $this->mockTree(Provide::class, [
397 'document' => [
'repository' => [
'all' => [$doc]]],
398 'history' => $history,
400 $this->mock(Clock::class)
403 $instance->acceptAnyDocument();
417 if (!defined($name)) {
418 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.