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