ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
AgreementTest.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
35 
36 require_once __DIR__ . '/../../ContainerMock.php';
37 
38 class AgreementTest extends TestCase
39 {
40  use ContainerMock;
41 
42  public function testConstruct(): void
43  {
44  $this->assertInstanceOf(Agreement::class, new Agreement(
45  $this->mock(User::class),
46  $this->mock(Settings::class),
47  $this->mock(UI::class),
48  $this->mock(Routing::class),
49  $this->fail(...)
50  ));
51  }
52 
53  public function testShowAgreement(): void
54  {
55  $instance = new Agreement(
56  $this->mockTree(User::class, ['matchingDocument' => new Ok($this->mock(Document::class))]),
57  $this->mock(Settings::class),
58  $this->mock(UI::class),
59  $this->mock(Routing::class),
60  $this->fail(...)
61  );
62 
63  $this->assertInstanceOf(ShowOnScreenMessage::class, $instance->showAgreement('foo', 'bar'));
64  }
65 
66  public function testShowAgreementForm(): void
67  {
68  $instance = new Agreement(
69  $this->mockTree(User::class, ['matchingDocument' => new Ok($this->mock(Document::class))]),
70  $this->mock(Settings::class),
71  $this->mock(UI::class),
72  $this->mock(Routing::class),
73  fn() => $this->mock(Component::class)
74  );
75 
76  $this->assertInstanceOf(ShowOnScreenMessage::class, $instance->showAgreementForm('foo', 'bar'));
77  }
78 
79  public function testNeedsToAgree(): void
80  {
81  $instance = new Agreement(
82  $this->mockTree(User::class, [
83  'cannotAgree' => false,
84  'neverAgreed' => false,
85  'didNotAcceptCurrentVersion' => false,
86  ]),
87  $this->mock(Settings::class),
88  $this->mock(UI::class),
89  $this->mock(Routing::class),
90  $this->fail(...)
91  );
92 
93  $this->assertFalse($instance->needsToAgree());
94  }
95 
96  public function testCannotAgree(): void
97  {
98  $instance = new Agreement(
99  $this->mockTree(User::class, [
100  'cannotAgree' => true,
101  'didNotAcceptCurrentVersion' => true,
102  ]),
103  $this->mock(Settings::class),
104  $this->mock(UI::class),
105  $this->mock(Routing::class),
106  $this->fail(...)
107  );
108 
109  $this->assertFalse($instance->needsToAgree());
110  }
111 
112  public function testDidNotAcceptCurrentVersion(): void
113  {
114  $instance = new Agreement(
115  $this->mockTree(User::class, [
116  'cannotAgree' => false,
117  'needsToAcceptNewDocument' => true,
118  ]),
119  $this->mock(Settings::class),
120  $this->mock(UI::class),
121  $this->mock(Routing::class),
122  $this->fail(...)
123  );
124 
125  $this->assertTrue($instance->needsToAgree());
126  }
127 }
A result encapsulates a value or an error and simplifies the handling of those.
Definition: Ok.php:16