ILIAS  trunk Revision v11.0_alpha-1753-gb21ca8c4367
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
AgreementTest.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
33 
34 require_once __DIR__ . '/../../ContainerMock.php';
35 
36 class AgreementTest extends TestCase
37 {
38  use ContainerMock;
39 
40  public function testConstruct(): void
41  {
42  $this->assertInstanceOf(Agreement::class, new Agreement(
43  $this->mock(User::class),
44  $this->mock(UI::class),
45  $this->mock(Routing::class),
46  $this->fail(...)
47  ));
48  }
49 
50  public function testShowAgreement(): void
51  {
52  $instance = new Agreement(
53  $this->mockTree(User::class, ['matchingDocument' => new Ok($this->mock(Document::class))]),
54  $this->mock(UI::class),
55  $this->mock(Routing::class),
56  $this->fail(...)
57  );
58 
59  $this->assertInstanceOf(ShowOnScreenMessage::class, $instance->showAgreement('foo', 'bar'));
60  }
61 
62  public function testShowAgreementForm(): void
63  {
64  $instance = new Agreement(
65  $this->mockTree(User::class, ['matchingDocument' => new Ok($this->mock(Document::class))]),
66  $this->mock(UI::class),
67  $this->mock(Routing::class),
68  fn() => $this->mock(Component::class)
69  );
70 
71  $this->assertInstanceOf(ShowOnScreenMessage::class, $instance->showAgreementForm('foo', 'bar'));
72  }
73 
74  public function testNeedsToAgree(): void
75  {
76  $instance = new Agreement(
77  $this->mockTree(User::class, [
78  'cannotAgree' => false,
79  'neverAgreed' => false,
80  'didNotAcceptCurrentVersion' => false,
81  ]),
82  $this->mock(UI::class),
83  $this->mock(Routing::class),
84  $this->fail(...)
85  );
86 
87  $this->assertFalse($instance->needsToAgree());
88  }
89 
90  public function testCannotAgree(): void
91  {
92  $instance = new Agreement(
93  $this->mockTree(User::class, [
94  'cannotAgree' => true,
95  'didNotAcceptCurrentVersion' => true,
96  ]),
97  $this->mock(UI::class),
98  $this->mock(Routing::class),
99  $this->fail(...)
100  );
101 
102  $this->assertFalse($instance->needsToAgree());
103  }
104 
105  public function testDidNotAcceptCurrentVersion(): void
106  {
107  $instance = new Agreement(
108  $this->mockTree(User::class, [
109  'cannotAgree' => false,
110  'needsToAcceptNewDocument' => true,
111  ]),
112  $this->mock(UI::class),
113  $this->mock(Routing::class),
114  $this->fail(...)
115  );
116 
117  $this->assertTrue($instance->needsToAgree());
118  }
119 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
A result encapsulates a value or an error and simplifies the handling of those.
Definition: Ok.php:30