ILIAS  trunk Revision v11.0_alpha-1769-g99a433fe2dc
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
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)
 externalAuthModes More...
 
 testFormat ()
 
 testRaw ()
 
 testAcceptAnyDocument ()
 

Static Public Member Functions

static externalAuthModes ()
 

Private Member Functions

 ensureDefined (string $name, $value)
 

Detailed Description

Definition at line 43 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 406 of file UserTest.php.

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

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

◆ testAcceptAnyDocument()

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

Definition at line 385 of file UserTest.php.

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

◆ testAcceptedVersion()

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

Definition at line 257 of file UserTest.php.

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

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

◆ testAcceptMatchingDocument()

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

Definition at line 297 of file UserTest.php.

References ILIAS\$setting.

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

◆ testAcceptVersionError()

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

Definition at line 277 of file UserTest.php.

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

277  : void
278  {
279  $this->ensureDefined('ANONYMOUS_USER_ID', 13);
280  $this->ensureDefined('SYSTEM_USER_ID', 9);
281 
282  $user = $this->mockTree(ilObjUser::class, ['getId' => 67]);
283 
284  $instance = new User(
285  $user,
286  $this->mock(Settings::class),
287  $this->mockTree(UserSettings::class, ['agreeDate' => ['value' => null]]),
288  $this->mock(Provide::class),
289  $this->mock(Clock::class)
290  );
291 
292  $result = $instance->acceptedVersion();
293  $this->assertFalse($result->isOk());
294  $this->assertSame('User never agreed.', $result->error());
295  }
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
+ Here is the call graph for this function:

◆ testAgreeDate()

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

Definition at line 138 of file UserTest.php.

References ILIAS\$setting.

138  : void
139  {
140  $setting = $this->mock(Setting::class);
141 
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)
148  );
149 
150  $this->assertSame($setting, $instance->agreeDate());
151  }
ilSetting $setting
Definition: class.ilias.php:68

◆ testCannotAgree()

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

Definition at line 80 of file UserTest.php.

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

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

◆ testConstruct()

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

Definition at line 47 of file UserTest.php.

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

◆ testDidNotAcceptCurrentVersion()

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

Definition at line 153 of file UserTest.php.

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

◆ testDoesntMatch()

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

Definition at line 221 of file UserTest.php.

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

◆ testFormat()

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

Definition at line 352 of file UserTest.php.

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

◆ testIsExternalUser()

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

externalAuthModes

Definition at line 339 of file UserTest.php.

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

◆ testIsLDAPUser()

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

Definition at line 323 of file UserTest.php.

References ilAuthUtils\AUTH_LDAP.

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

◆ testIsLoggedIn()

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

Definition at line 58 of file UserTest.php.

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

58  : void
59  {
60  $this->ensureDefined('ANONYMOUS_USER_ID', 13);
61 
62  $user = $this->mock(ilObjUser::class);
63  $user->expects(self::exactly(5))->method('getId')->willReturnOnConsecutiveCalls(0, ANONYMOUS_USER_ID, 9, 1, 68);
64 
65  $instance = new User(
66  $user,
67  $this->mock(Settings::class),
68  $this->mock(UserSettings::class),
69  $this->mock(Provide::class),
70  $this->mock(Clock::class)
71  );
72 
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());
78  }
const ANONYMOUS_USER_ID
Definition: constants.php:27
+ Here is the call graph for this function:

◆ testMatchingDocument()

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

Definition at line 239 of file UserTest.php.

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

◆ testNeedsToAcceptNewDocumentReturnsFalse()

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

Definition at line 201 of file UserTest.php.

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

◆ testNeedsToAcceptNewDocumentReturnsTrue()

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

Definition at line 185 of file UserTest.php.

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

◆ testNeedsToAcceptNewDocumentWhereNeverAgreed()

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

Definition at line 172 of file UserTest.php.

References null.

172  : void
173  {
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)
180  );
181 
182  $this->assertTrue($instance->needsToAcceptNewDocument());
183  }
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null

◆ testNeverAgreed()

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

Definition at line 103 of file UserTest.php.

References ILIAS\$setting, and null.

103  : void
104  {
105  $setting = $this->mock(Setting::class);
106  $setting->expects(self::exactly(2))->method('value')->willReturnOnConsecutiveCalls(null, new DateTimeImmutable());
107 
108  $user_settings = $this->mock(UserSettings::class);
109  $user_settings->expects(self::exactly(2))->method('agreeDate')->willReturn($setting);
110 
111  $instance = new User(
112  $this->mock(ilObjUser::class),
113  $this->mock(Settings::class),
114  $user_settings,
115  $this->mock(Provide::class),
116  $this->mock(Clock::class)
117  );
118 
119  $this->assertTrue($instance->neverAgreed());
120  $this->assertFalse($instance->neverAgreed());
121  }
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
ilSetting $setting
Definition: class.ilias.php:68

◆ testRaw()

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

Definition at line 370 of file UserTest.php.

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

◆ testWithdrawalRequested()

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

Definition at line 123 of file UserTest.php.

References ILIAS\$setting.

123  : void
124  {
125  $setting = $this->mock(Setting::class);
126 
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)
133  );
134 
135  $this->assertSame($setting, $instance->withdrawalRequested());
136  }
ilSetting $setting
Definition: class.ilias.php:68

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