ILIAS  trunk Revision v11.0_alpha-1753-gb21ca8c4367
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
PublicApiTest.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
24 use ilObjUser;
29 
30 require_once __DIR__ . '/../../ContainerMock.php';
31 
32 class PublicApiTest extends TestCase
33 {
34  use ContainerMock;
35 
36  public function testConstruct(): void
37  {
38  $this->assertInstanceOf(PublicApi::class, new PublicApi(false, $this->fail(...)));
39  }
40 
41  public function testActive(): void
42  {
43  $this->assertTrue((new PublicApi(true, $this->fail(...)))->active());
44  $this->assertFalse((new PublicApi(false, $this->fail(...)))->active());
45  }
46 
47  public function testAgreed(): void
48  {
49  $this->assertTrueFalseForMethod('agreed', fn(bool $b) => ['neverAgreed' => !$b]);
50  }
51 
52  public function testEverAgreed(string $method = 'everAgreed'): void
53  {
54  $this->assertTrueFalseForMethod('agreed', fn(bool $b) => ['neverAgreed' => !$b]);
55  }
56 
57  public function testAgreedToCurrentlyMatchingDocument(): void
58  {
59  $this->assertTrueFalseForMethod('agreedToCurrentlyMatchingDocument', fn(bool $b) => [
60  'needsToAcceptNewDocument' => !$b,
61  ]);
62  }
63 
64  public function testCanAgree(): void
65  {
66  $this->assertTrueFalseForMethod('canAgree', fn(bool $b) => [
67  'cannotAgree' => !$b,
68  ]);
69  }
70 
71  public function testNeedsToAgree(): void
72  {
73  $this->assertSameValues('needsToAgree', [
74  [false, ['cannotAgree' => true, 'needsToAcceptNewDocument' => true]],
75  [true, ['cannotAgree' => false, 'needsToAcceptNewDocument' => true]],
76  [false, ['cannotAgree' => true, 'needsToAcceptNewDocument' => false]],
77  [false, ['cannotAgree' => false, 'needsToAcceptNewDocument' => false]],
78  ]);
79  }
80 
81  public function testAgreeDate(): void
82  {
83  $d = new DateTimeImmutable();
84  $this->assertSameValues('agreeDate', [
85  [$d, ['agreeDate' => ['value' => $d]]],
86  [null, ['agreeDate' => ['value' => null]]],
87  ]);
88  }
89 
90  private function assertTrueFalseForMethod(string $method, callable $dpro_user_tree)
91  {
92  $this->assertSameValues($method, [
93  [true, $dpro_user_tree(true)],
94  [false, $dpro_user_tree(false)]
95  ]);
96  }
97 
98  private function assertSameValues(string $method, array $compare): void
99  {
100  $user = $this->mock(ilObjUser::class);
101  $dpro_user = fn($ret) => $this->mockTree(User::class, $dpro_user_tree($ret));
102 
103  foreach ($compare as $pair) {
104  $this->assertSame($pair[0], (new PublicApi(true, fn() => $this->mockTree(User::class, $pair[1])))->$method($user));
105  }
106  }
107 }
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
assertTrueFalseForMethod(string $method, callable $dpro_user_tree)