ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
AgreementTest.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
27use ILIAS\LegalDocuments\test\ContainerMock;
28use PHPUnit\Framework\TestCase;
33
34require_once __DIR__ . '/../../ContainerMock.php';
35
36class 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}
A result encapsulates a value or an error and simplifies the handling of those.
Definition: Ok.php:31
A component is the most general form of an entity in the UI.
Definition: Component.php:28