ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
WiringTest.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
36 
37 require_once __DIR__ . '/ContainerMock.php';
38 
39 class WiringTest extends TestCase
40 {
41  use ContainerMock;
42 
43  public function testConstruct(): void
44  {
45  $this->assertInstanceOf(Wiring::class, new Wiring($this->mock(SlotConstructor::class), $this->mock(Map::class)));
46  }
47 
48  public function testAfterLogin(): void
49  {
50  $map = $this->mock(Map::class);
51  $proc = $this->fail(...);
52 
53  $instance = new Wiring($this->mock(SlotConstructor::class), $this->mockMethod(Map::class, 'add', ['after-login', $proc], $map));
54  $this->assertSame($map, $instance->afterLogin($proc)->map());
55  }
56 
57  public function testShowInFooter(): void
58  {
59  $map = $this->mock(Map::class);
60  $proc = $this->fail(...);
61 
62  $instance = new Wiring($this->mockTree(SlotConstructor::class, ['id' => 'foo']), $this->mockMethod(Map::class, 'set', ['footer', 'foo', $proc], $map));
63  $this->assertSame($map, $instance->showInFooter($proc)->map());
64  }
65 
66  public function testCanWithdraw(): void
67  {
68  $withdraw_process = $this->mock(WithdrawProcess::class);
69 
70  $instance = new Wiring($this->mock(SlotConstructor::class), new Map());
71 
72  $map = $instance->canWithdraw($withdraw_process)->map()->value();
73 
74  $this->assertSame([
75  'withdraw',
76  'logout',
77  'intercept',
78  'logout-text',
79  'show-on-login-page',
80  ], array_keys($map));
81 
82  $this->assertTrue(array_is_list($map['intercept']));
83  $this->assertTrue(array_is_list($map['show-on-login-page']));
84  $this->assertFalse(array_is_list($map['withdraw']));
85  $this->assertFalse(array_is_list($map['logout']));
86  $this->assertFalse(array_is_list($map['logout-text']));
87  }
88 
89  public function testShowOnLoginPage(): void
90  {
91  $proc = $this->fail(...);
92  $instance = new Wiring($this->mockTree(SlotConstructor::class, ['id' => 'foo']), new Map());
93  $this->assertSame(['show-on-login-page' => ['foo' => $proc]], $instance->showOnLoginPage($proc)->map()->value());
94  }
95 
96  public function testHasAgreement(): void
97  {
98  $instance = new Wiring($this->mock(SlotConstructor::class), new Map());
99  $map = $instance->hasAgreement($this->mock(Agreement::class), 'bar')->map()->value();
100 
101  $this->assertSame([
102  'public-page',
103  'agreement-form',
104  'intercept',
105  'goto',
106  ], array_keys($map));
107 
108  $this->assertFalse(array_is_list($map['public-page']));
109  $this->assertFalse(array_is_list($map['agreement-form']));
110  $this->assertTrue(array_is_list($map['intercept']));
111  $this->assertTrue(array_is_list($map['goto']));
112  }
113 
114  public function testHasHistory(): void
115  {
116  $document = $this->mock(ProvideDocument::class);
117  $history = $this->mock(ProvideHistory::class);
118  $slot = $this->mockMethod(SlotConstructor::class, 'history', [$document], $history);
119  $slot->method('id')->willReturn('foo');
120  $map = $this->mockTree(Map::class, ['value' => ['document' => ['foo' => $document]]]);
121  $map->expects(self::once())->method('set')->with('history', 'foo', $history)->willReturn($map);
122 
123  $instance = new Wiring($slot, $map);
124  $this->assertSame($map, $instance->hasHistory()->map());
125  }
126 
127  public function testOnSelfRegistration(): void
128  {
129  $map = $this->mock(Map::class);
130  $self_registration = $this->mock(SelfRegistration::class);
131 
132  $instance = new Wiring($this->mock(SlotConstructor::class), $this->mockMethod(Map::class, 'add', ['self-registration', $self_registration], $map));
133  $this->assertSame($map, $instance->onSelfRegistration($self_registration)->map());
134  }
135 
136  public function testHasOnlineStatusFilter(): void
137  {
138  $map = $this->mock(Map::class);
139  $proc = $this->fail(...);
140 
141  $instance = new Wiring($this->mock(SlotConstructor::class), $this->mockMethod(Map::class, 'add', ['filter-online-users', $proc], $map));
142  $this->assertSame($map, $instance->hasOnlineStatusFilter($proc)->map());
143  }
144 
145  public function testCanReadInternalMails(): void
146  {
147  $map = $this->mock(Map::class);
148  $constraint = $this->mock(Constraint::class);
149 
150  $instance = new Wiring($this->mock(SlotConstructor::class), $this->mockMethod(Map::class, 'add', ['constrain-internal-mail', $constraint], $map));
151  $this->assertSame($map, $instance->canReadInternalMails($constraint)->map());
152  }
153 
154  public function testCanUseSoapApi(): void
155  {
156  $map = $this->mock(Map::class);
157  $constraint = $this->mock(Constraint::class);
158 
159  $instance = new Wiring($this->mock(SlotConstructor::class), $this->mockMethod(Map::class, 'add', ['use-soap-api', $constraint], $map));
160  $this->assertSame($map, $instance->canUseSoapApi($constraint)->map());
161  }
162 
163  public function testHasDocuments(): void
164  {
165  $instance = new Wiring($this->mock(SlotConstructor::class), new Map());
166  $map = $instance->hasDocuments([], new SelectionMap())->map()->value();
167 
168  $this->assertSame([
169  'document',
170  'writable-document',
171  ], array_keys($map));
172 
173  $this->assertFalse(array_is_list($map['document']));
174  $this->assertFalse(array_is_list($map['writable-document']));
175  }
176 
177  public function testHasUserManagementFields(): void
178  {
179  $map = $this->mock(Map::class);
180  $proc = $this->fail(...);
181 
182  $instance = new Wiring(
183  $this->mockTree(SlotConstructor::class, ['id' => 'foo']),
184  $this->mockMethod(Map::class, 'set', ['user-management-fields', 'foo', $proc], $map)
185  );
186 
187  $this->assertSame($map, $instance->hasUserManagementFields($proc)->map());
188  }
189 
190  public function testHasPublicApi(): void
191  {
192  $map = $this->mock(Map::class);
193  $public_api = $this->mock(PublicApi::class);
194 
195  $instance = new Wiring(
196  $this->mockTree(SlotConstructor::class, ['id' => 'foo']),
197  $this->mockMethod(Map::class, 'set', ['public-api', 'foo', $public_api], $map)
198  );
199 
200  $this->assertSame($map, $instance->hasPublicApi($public_api)->map());
201  }
202 
203  public function testHasPublicPage(): void
204  {
205  $map = $this->mock(Map::class);
206  $public_page = fn() => null;
207 
208  $instance = new Wiring(
209  $this->mockTree(SlotConstructor::class, ['id' => 'foo']),
210  $this->mockMethod(Map::class, 'set', ['public-page', 'foo', $public_page], $map)
211  );
212 
213  $this->assertSame($map, $instance->hasPublicPage($public_page)->map());
214  }
215 
216  public function testHasPublicPageWithGotoLink(): void
217  {
218  $m = $this->mock(Map::class);
219  $map = $this->mockMethod(Map::class, 'add', ['goto'], $m);
220  $public_page = fn() => null;
221 
222  $instance = new Wiring(
223  $this->mockTree(SlotConstructor::class, ['id' => 'foo']),
224  $this->mockMethod(Map::class, 'set', ['public-page', 'foo', $public_page], $map)
225  );
226 
227  $this->assertSame($m, $instance->hasPublicPage($public_page, 'foo')->map());
228  }
229 
230  public function testMap(): void
231  {
232  $map = $this->mock(Map::class);
233  $this->assertSame($map, (new Wiring($this->mock(SlotConstructor::class), $map))->map());
234  }
235 }