ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ILIAS\LegalDocuments\test\ConsumerToolbox\UserTest Class Reference
+ Inheritance diagram for ILIAS\LegalDocuments\test\ConsumerToolbox\UserTest:
+ Collaboration diagram for ILIAS\LegalDocuments\test\ConsumerToolbox\UserTest:

Public Member Functions

 testConstruct ()
 
 testIsLoggedIn ()
 
 testCannotAgree ()
 
 testNeverAgreed ()
 
 testWithdrawalRequested ()
 
 testAgreeDate ()
 
 testDidNotAcceptCurrentVersion ()
 
 testNeedsToAcceptNewDocumentWhereNeverAgreed ()
 
 testNeedsToAcceptNewDocumentReturnsTrue ()
 
 testNeedsToAcceptNewDocumentReturnsFalse ()
 
 testDoesntMatch ()
 
 testMatchingDocument ()
 
 testAcceptedVersion ()
 
 testAcceptVersionError ()
 
 testAcceptMatchingDocument ()
 
 testIsLDAPUser ()
 
 testIsExternalUser (int $auth_mode, bool $is_external_account)
 
 testFormat ()
 
 testRaw ()
 
 testAcceptAnyDocument ()
 

Static Public Member Functions

static externalAuthModes ()
 

Private Member Functions

 ensureDefined (string $name, $value)
 

Detailed Description

Definition at line 44 of file UserTest.php.

Member Function Documentation

◆ ensureDefined()

ILIAS\LegalDocuments\test\ConsumerToolbox\UserTest::ensureDefined ( string  $name,
  $value 
)
private

◆ externalAuthModes()

static ILIAS\LegalDocuments\test\ConsumerToolbox\UserTest::externalAuthModes ( )
static

Definition at line 405 of file UserTest.php.

405 : array
406 {
407 return [
408 'lti' => [ilAuthUtils::AUTH_PROVIDER_LTI, true],
409 'ecs' => [ilAuthUtils::AUTH_ECS, true],
410 'ldap' => [ilAuthUtils::AUTH_LDAP, false],
411 ];
412 }
const int AUTH_ECS
const int AUTH_LDAP
const int AUTH_PROVIDER_LTI

References ilAuthUtils\AUTH_ECS, ilAuthUtils\AUTH_LDAP, and ilAuthUtils\AUTH_PROVIDER_LTI.

◆ testAcceptAnyDocument()

ILIAS\LegalDocuments\test\ConsumerToolbox\UserTest::testAcceptAnyDocument ( )

Definition at line 384 of file UserTest.php.

384 : void
385 {
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);
390
391 $instance = new User(
392 $user,
393 $this->mock(Settings::class),
394 $this->mock(UserSettings::class),
395 $this->mockTree(Provide::class, [
396 'document' => ['repository' => ['all' => [$doc]]],
397 'history' => $history,
398 ]),
399 $this->mock(Clock::class)
400 );
401
402 $instance->acceptAnyDocument();
403 }

◆ testAcceptedVersion()

ILIAS\LegalDocuments\test\ConsumerToolbox\UserTest::testAcceptedVersion ( )

Definition at line 258 of file UserTest.php.

258 : void
259 {
260 $this->ensureDefined('ANONYMOUS_USER_ID', 13);
261 $this->ensureDefined('SYSTEM_USER_ID', 9);
262
263 $result = $this->mock(Result::class);
264
265 $user = $this->mockTree(ilObjUser::class, ['getId' => 67]);
266
267 $instance = new User(
268 $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)
273 );
274
275 $this->assertSame($result, $instance->acceptedVersion());
276 }

References ILIAS\LegalDocuments\test\ConsumerToolbox\UserTest\ensureDefined().

+ Here is the call graph for this function:

◆ testAcceptMatchingDocument()

ILIAS\LegalDocuments\test\ConsumerToolbox\UserTest::testAcceptMatchingDocument ( )

Definition at line 298 of file UserTest.php.

298 : void
299 {
300 $user = $this->mock(ilObjUser::class);
301 $document = $this->mock(Document::class);
302 $date = new DateTimeImmutable();
303
304 $history = $this->mock(ProvideHistory::class);
305 $history->expects(self::once())->method('acceptDocument')->with($user, $document);
306
307 $setting = $this->mock(Setting::class);
308 $setting->expects(self::once())->method('update')->with($date);
309
310 $instance = new User(
311 $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,
317 ]),
318 $this->mockTree(Clock::class, ['now' => $date])
319 );
320
321 $instance->acceptMatchingDocument();
322 }
ilSetting $setting
Definition: class.ilias.php:68

References ILIAS\$setting.

◆ testAcceptVersionError()

ILIAS\LegalDocuments\test\ConsumerToolbox\UserTest::testAcceptVersionError ( )

Definition at line 278 of file UserTest.php.

278 : void
279 {
280 $this->ensureDefined('ANONYMOUS_USER_ID', 13);
281 $this->ensureDefined('SYSTEM_USER_ID', 9);
282
283 $user = $this->mockTree(ilObjUser::class, ['getId' => 67]);
284
285 $instance = new User(
286 $user,
287 $this->mock(Settings::class),
288 $this->mockTree(UserSettings::class, ['agreeDate' => ['value' => null]]),
289 $this->mock(Provide::class),
290 $this->mock(Clock::class)
291 );
292
293 $result = $instance->acceptedVersion();
294 $this->assertFalse($result->isOk());
295 $this->assertSame('User never agreed.', $result->error());
296 }

References ILIAS\LegalDocuments\test\ConsumerToolbox\UserTest\ensureDefined().

+ Here is the call graph for this function:

◆ testAgreeDate()

ILIAS\LegalDocuments\test\ConsumerToolbox\UserTest::testAgreeDate ( )

Definition at line 139 of file UserTest.php.

139 : void
140 {
141 $setting = $this->mock(Setting::class);
142
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)
149 );
150
151 $this->assertSame($setting, $instance->agreeDate());
152 }

References ILIAS\$setting.

◆ testCannotAgree()

ILIAS\LegalDocuments\test\ConsumerToolbox\UserTest::testCannotAgree ( )

Definition at line 81 of file UserTest.php.

81 : void
82 {
83 $this->ensureDefined('ANONYMOUS_USER_ID', 13);
84 $this->ensureDefined('SYSTEM_USER_ID', 9);
85
86 $user = $this->mock(ilObjUser::class);
87 $user->expects(self::exactly(5))->method('getId')->willReturnOnConsecutiveCalls(0, ANONYMOUS_USER_ID, SYSTEM_USER_ID, 1, 68);
88
89 $instance = new User(
90 $user,
91 $this->mock(Settings::class),
92 $this->mock(UserSettings::class),
93 $this->mock(Provide::class),
94 $this->mock(Clock::class)
95 );
96
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());
102 }
const SYSTEM_USER_ID
This file contains constants for PHPStan analyis, see: https://phpstan.org/config-reference#constants...
Definition: constants.php:26
const ANONYMOUS_USER_ID
Definition: constants.php:27

References ANONYMOUS_USER_ID, ILIAS\LegalDocuments\test\ConsumerToolbox\UserTest\ensureDefined(), and SYSTEM_USER_ID.

+ Here is the call graph for this function:

◆ testConstruct()

ILIAS\LegalDocuments\test\ConsumerToolbox\UserTest::testConstruct ( )

Definition at line 48 of file UserTest.php.

48 : void
49 {
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)
56 ));
57 }

◆ testDidNotAcceptCurrentVersion()

ILIAS\LegalDocuments\test\ConsumerToolbox\UserTest::testDidNotAcceptCurrentVersion ( )

Definition at line 154 of file UserTest.php.

154 : void
155 {
156 $user = $this->mock(ilObjUser::class);
157 $document = $this->mock(Document::class);
158
159 $instance = new User(
160 $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),
166 ]),
167 $this->mock(Clock::class)
168 );
169
170 $this->assertTrue($instance->didNotAcceptCurrentVersion());
171 }

◆ testDoesntMatch()

ILIAS\LegalDocuments\test\ConsumerToolbox\UserTest::testDoesntMatch ( )

Definition at line 222 of file UserTest.php.

222 : void
223 {
224 $document = $this->mock(Document::class);
225 $user = $this->mock(ilObjUser::class);
226
227 $instance = new User(
228 $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),
233 ]),
234 $this->mock(Clock::class)
235 );
236
237 $this->assertFalse($instance->doesntMatch($document));
238 }

◆ testFormat()

ILIAS\LegalDocuments\test\ConsumerToolbox\UserTest::testFormat ( )

Definition at line 351 of file UserTest.php.

351 : void
352 {
353 $instance = new User(
354 $this->mockTree(ilObjUser::class, [
355 'getFullname' => 'foo',
356 'getLogin' => 'bar',
357 'getExternalAccount' => 'baz',
358 ]),
359 $this->mock(Settings::class),
360 $this->mock(UserSettings::class),
361 $this->mock(Provide::class),
362 $this->mock(Clock::class)
363 );
364
365 $this->assertSame('', $instance->format(''));
366 $this->assertSame("hej foo bar\nbaz", $instance->format('hej %s %s[BR]%s'));
367 }

◆ testIsExternalUser()

ILIAS\LegalDocuments\test\ConsumerToolbox\UserTest::testIsExternalUser ( int  $auth_mode,
bool  $is_external_account 
)

Definition at line 338 of file UserTest.php.

338 : void
339 {
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)
346 );
347
348 $this->assertSame($is_external_account, $instance->isExternalAccount());
349 }

◆ testIsLDAPUser()

ILIAS\LegalDocuments\test\ConsumerToolbox\UserTest::testIsLDAPUser ( )

Definition at line 324 of file UserTest.php.

324 : void
325 {
326 $instance = new User(
327 $this->mockTree(ilObjUser::class, ['getAuthMode' => 'default']),
328 $this->mockTree(Settings::class, ['authMode' => ['value' => (string) ilAuthUtils::AUTH_LDAP]]),
329 $this->mock(UserSettings::class),
330 $this->mock(Provide::class),
331 $this->mock(Clock::class)
332 );
333
334 $this->assertTrue($instance->isLDAPUser());
335 }

References ilAuthUtils\AUTH_LDAP.

◆ testIsLoggedIn()

ILIAS\LegalDocuments\test\ConsumerToolbox\UserTest::testIsLoggedIn ( )

Definition at line 59 of file UserTest.php.

59 : void
60 {
61 $this->ensureDefined('ANONYMOUS_USER_ID', 13);
62
63 $user = $this->mock(ilObjUser::class);
64 $user->expects(self::exactly(5))->method('getId')->willReturnOnConsecutiveCalls(0, ANONYMOUS_USER_ID, 9, 1, 68);
65
66 $instance = new User(
67 $user,
68 $this->mock(Settings::class),
69 $this->mock(UserSettings::class),
70 $this->mock(Provide::class),
71 $this->mock(Clock::class)
72 );
73
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());
79 }

References ANONYMOUS_USER_ID, and ILIAS\LegalDocuments\test\ConsumerToolbox\UserTest\ensureDefined().

+ Here is the call graph for this function:

◆ testMatchingDocument()

ILIAS\LegalDocuments\test\ConsumerToolbox\UserTest::testMatchingDocument ( )

Definition at line 240 of file UserTest.php.

240 : void
241 {
242 $user = $this->mock(ilObjUser::class);
243 $result = $this->mock(Result::class);
244
245 $instance = new User(
246 $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),
251 ]),
252 $this->mock(Clock::class)
253 );
254
255 $this->assertSame($result, $instance->matchingDocument());
256 }

◆ testNeedsToAcceptNewDocumentReturnsFalse()

ILIAS\LegalDocuments\test\ConsumerToolbox\UserTest::testNeedsToAcceptNewDocumentReturnsFalse ( )

Definition at line 202 of file UserTest.php.

202 : void
203 {
204 $user = $this->mock(ilObjUser::class);
205 $document = $this->mock(Document::class);
206 $history = $this->mockMethod(ProvideHistory::class, 'currentDocumentOfAcceptedVersion', [$user], new Ok($document));
207
208 $instance = new User(
209 $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,
215 ]),
216 $this->mock(Clock::class)
217 );
218
219 $this->assertFalse($instance->needsToAcceptNewDocument());
220 }

◆ testNeedsToAcceptNewDocumentReturnsTrue()

ILIAS\LegalDocuments\test\ConsumerToolbox\UserTest::testNeedsToAcceptNewDocumentReturnsTrue ( )

Definition at line 186 of file UserTest.php.

186 : void
187 {
188 $user = $this->mock(ilObjUser::class);
189 $history = $this->mockMethod(ProvideHistory::class, 'currentDocumentOfAcceptedVersion', [$user], new Error('Not found.'));
190
191 $instance = new User(
192 $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)
197 );
198
199 $this->assertTrue($instance->needsToAcceptNewDocument());
200 }

◆ testNeedsToAcceptNewDocumentWhereNeverAgreed()

ILIAS\LegalDocuments\test\ConsumerToolbox\UserTest::testNeedsToAcceptNewDocumentWhereNeverAgreed ( )

Definition at line 173 of file UserTest.php.

173 : void
174 {
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)
181 );
182
183 $this->assertTrue($instance->needsToAcceptNewDocument());
184 }

◆ testNeverAgreed()

ILIAS\LegalDocuments\test\ConsumerToolbox\UserTest::testNeverAgreed ( )

Definition at line 104 of file UserTest.php.

104 : void
105 {
106 $setting = $this->mock(Setting::class);
107 $setting->expects(self::exactly(2))->method('value')->willReturnOnConsecutiveCalls(null, new DateTimeImmutable());
108
109 $user_settings = $this->mock(UserSettings::class);
110 $user_settings->expects(self::exactly(2))->method('agreeDate')->willReturn($setting);
111
112 $instance = new User(
113 $this->mock(ilObjUser::class),
114 $this->mock(Settings::class),
115 $user_settings,
116 $this->mock(Provide::class),
117 $this->mock(Clock::class)
118 );
119
120 $this->assertTrue($instance->neverAgreed());
121 $this->assertFalse($instance->neverAgreed());
122 }

References ILIAS\$setting.

◆ testRaw()

ILIAS\LegalDocuments\test\ConsumerToolbox\UserTest::testRaw ( )

Definition at line 369 of file UserTest.php.

369 : void
370 {
371 $user = $this->mock(ilObjUser::class);
372
373 $instance = new User(
374 $user,
375 $this->mock(Settings::class),
376 $this->mock(UserSettings::class),
377 $this->mock(Provide::class),
378 $this->mock(Clock::class)
379 );
380
381 $this->assertSame($user, $instance->raw());
382 }

◆ testWithdrawalRequested()

ILIAS\LegalDocuments\test\ConsumerToolbox\UserTest::testWithdrawalRequested ( )

Definition at line 124 of file UserTest.php.

124 : void
125 {
126 $setting = $this->mock(Setting::class);
127
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)
134 );
135
136 $this->assertSame($setting, $instance->withdrawalRequested());
137 }

References ILIAS\$setting.


The documentation for this class was generated from the following file: